From b01b8f0cab5c464f46aa9bf44d009e86b5f5bcfe Mon Sep 17 00:00:00 2001 From: Madhu K Date: Wed, 26 Jul 2000 02:05:15 +0000 Subject: [PATCH] ICU-447 Added tests for utf8 X-SVN-Rev: 2041 --- icu4c/source/test/cintltst/Makefile.in | 2 +- icu4c/source/test/cintltst/calltest.c | 2 + icu4c/source/test/cintltst/cintltst.dsp | 11 + icu4c/source/test/cintltst/utf8tst.c | 606 ++++++++++++++++++++++++ 4 files changed, 620 insertions(+), 1 deletion(-) create mode 100644 icu4c/source/test/cintltst/utf8tst.c diff --git a/icu4c/source/test/cintltst/Makefile.in b/icu4c/source/test/cintltst/Makefile.in index 7e75b42d400..d144fd2fac3 100644 --- a/icu4c/source/test/cintltst/Makefile.in +++ b/icu4c/source/test/cintltst/Makefile.in @@ -69,7 +69,7 @@ cfrtst.o cg7coll.o chashtst.o cintltst.o citertst.o cjaptst.o cloctst.o cmsgtst. cnmdptst.o cnormtst.o cnumtst.o cregrtst.o crestst.o creststn.o cturtst.o \ cucdtst.o cutiltst.o encoll.o nucnvtst.o susctest.o nccbtst.o \ cbiditst.o cbididat.o eurocreg.o udatatst.o utf16tst.o utransts.o \ -ncnvfbts.o ncnvtst.o putiltst.o cstrtest.o mstrmtst.o +ncnvfbts.o ncnvtst.o putiltst.o cstrtest.o mstrmtst.o utf8tst.o DEPS = $(OBJECTS:.o=.d) diff --git a/icu4c/source/test/cintltst/calltest.c b/icu4c/source/test/cintltst/calltest.c index 4fd152f6818..ee25f440867 100644 --- a/icu4c/source/test/cintltst/calltest.c +++ b/icu4c/source/test/cintltst/calltest.c @@ -24,12 +24,14 @@ void addCollTest(TestNode** root); void addComplexTest(TestNode** root); void addUDataTest(TestNode** root); void addUTF16Test(TestNode** root); +void addUTF8Test(TestNode** root); void addUTransTest(TestNode** root); void addPUtilTest(TestNode** root); void addAllTests(TestNode** root) { addUTF16Test(root); + addUTF8Test(root); addUtility(root); addBreakIter(root); addFormatTest(root); diff --git a/icu4c/source/test/cintltst/cintltst.dsp b/icu4c/source/test/cintltst/cintltst.dsp index 1a90dd1c111..1a1582b31aa 100644 --- a/icu4c/source/test/cintltst/cintltst.dsp +++ b/icu4c/source/test/cintltst/cintltst.dsp @@ -284,6 +284,17 @@ SOURCE=.\utf16tst.c # End Source File # Begin Source File +SOURCE=.\utf8tst.c + +!IF "$(CFG)" == "cintltst - Win32 Release" + +!ELSEIF "$(CFG)" == "cintltst - Win32 Debug" + +!ENDIF + +# End Source File +# Begin Source File + SOURCE=.\utransts.c # End Source File # End Group diff --git a/icu4c/source/test/cintltst/utf8tst.c b/icu4c/source/test/cintltst/utf8tst.c new file mode 100644 index 00000000000..b35c008272d --- /dev/null +++ b/icu4c/source/test/cintltst/utf8tst.c @@ -0,0 +1,606 @@ +/******************************************************************** + * COPYRIGHT: + * Copyright (c) 1998-1999, International Business Machines Corporation and + * others. All Rights Reserved. + ********************************************************************/ +/* +* File test.c +* +* Modification History: +* +* Date Name Description +* 07/24/2000 Madhu Creation +******************************************************************************* +*/ + +#include "unicode/utypes.h" +#include "unicode/utf8.h" +#include "cmemory.h" +#include "cintltst.h" +#include + + +static void printUChars(uint8_t *uchars, int16_t len); + +static void TestCodeUnitValues(); +static void TestCharLength(); +static void TestGetChar(); +static void TestNextPrevChar(); +static void TestFwdBack(); +static void TestSetChar(); +static void TestAppendChar(); + + + +void +addUTF8Test(TestNode** root) +{ + addTest(root, &TestCodeUnitValues, "utf8tst/TestCodeUnitValues"); + addTest(root, &TestCharLength, "utf8tst/TestCharLength" ); + addTest(root, &TestGetChar, "utf8tst/TestGetChar" ); + addTest(root, &TestNextPrevChar, "utf8tst/TestNextPrevChar" ); + addTest(root, &TestFwdBack, "utf8tst/TestFwdBack" ); + addTest(root, &TestSetChar, "utf8tst/TestSetChar" ); + addTest(root, &TestAppendChar, "utf8tst/TestAppendChar" ); +} + +void TestCodeUnitValues() +{ + static uint8_t codeunit[]={0x00, 0x65, 0x7e, 0x7f, 0xc0, 0xc4, 0xf0, 0xfd, 0x80, 0x81, 0xbc, 0xbf,}; + + int16_t i; + for(i=0; i 0; --offset){ + setOffset=offset; + UTF8_PREV_CHAR_UNSAFE(input, setOffset, c); + if(setOffset != movedOffset[i+3]){ + log_err("ERROR: UTF8_PREV_CHAR_UNSAFE failed to move the offset correctly at %d\n ExpectedOffset:%d Got %d\n", + offset, movedOffset[i+3], setOffset); + } + if(c != result[i+3]){ + log_err("ERROR: UTF8_PREV_CHAR_UNSAFE failed for offset=%ld. Expected:%lx Got:%lx\n", offset, result[i+3], c); + } + setOffset=offset; + UTF8_PREV_CHAR_SAFE(input, 0, setOffset, c, FALSE); + if(setOffset != movedOffset[i+4]){ + log_err("ERROR: UTF8_PREV_CHAR_SAFE failed to move the offset correctly at %d\n ExpectedOffset:%d Got %d\n", + offset, movedOffset[i+4], setOffset); + } + if(c != result[i+4]){ + log_err("ERROR: UTF8_PREV_CHAR_SAFE failed for input=%ld. Expected:%lx Got:%lx\n", offset, result[i+4], c); + } + setOffset=offset; + UTF8_PREV_CHAR_SAFE(input, 0, setOffset, c, TRUE); + if(setOffset != movedOffset[i+5]){ + log_err("ERROR: UTF8_PREV_CHAR_SAFE(strict) failed to move the offset correctly at %d\n ExpectedOffset:%d Got %d\n", + offset, movedOffset[i+5], setOffset); + } + if(c != result[i+5]){ + log_err("ERROR: UTF8_PREV_CHAR_SAFE(strict) failed for input=%ld. Expected:%lx Got:%lx\n", offset, result[i+5], c); + } + /*call the API instead of MACRO + setOffset=offset; + (c)=(input)[--(setOffset)]; + if(UTF8_IS_TRAIL((c))) { + (c)=utf8_prevCharSafeBody(input, 0, &(setOffset), c, TRUE); + } + if(setOffset != movedOffset[i+5]){ + log_err("ERROR: utf8_prevCharSafeBody(strict) failed to move the offset correctly at %d\n ExpectedOffset:%d Got %d\n", + offset, movedOffset[i+5], setOffset); + } + if(c != result[i+5]){ + log_err("ERROR: utf8_prevCharSafeBody(strict) failed for input=%ld. Expected:%lx Got:%lx\n", offset, result[i+5], c); + } + */ + i=i+6; + } + +} +void TestFwdBack(){ + static uint8_t input[]={0x61, 0xF0, 0x90, 0x90, 0x81, 0xff, 0x62, 0xc0, 0x80, 0x7f, 0x8f, 0xc0, 0x63, 0x81, 0x90, 0x90, 0xF0, 0x00}; + static uint16_t fwd_unsafe[] ={1, 5, 6, 7, 9, 10, 11, 13, 14, 15, 16, 20, }; + static uint16_t fwd_safe[] ={1, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}; + static uint16_t back_unsafe[]={17, 16, 12, 11, 9, 7, 6, 5, 1}; + static uint16_t back_safe[] ={17, 16, 15, 14, 13, 12, 11, 10, 9, 7, 6, 5, 1, 0}; + + static uint16_t Nvalue[]= {0, 1, 2, 3, 1, 2, 1, 5}; + static uint16_t fwd_N_unsafe[] ={0, 1, 6, 10, 11, 14, 15}; + static uint16_t fwd_N_safe[] ={0, 1, 6, 10, 11, 13, 14, 18}; /*safe macro keeps it at the end of the string */ + static uint16_t back_N_unsafe[]={18, 17, 12, 7, 6, 1, 0}; + static uint16_t back_N_safe[] ={18, 17, 15, 12, 11, 9, 7, 0}; + + + uint32_t offunsafe=0, offsafe=0; + uint32_t i=0; + while(offunsafe < sizeof(input)){ + UTF8_FWD_1_UNSAFE(input, offunsafe); + if(offunsafe != fwd_unsafe[i]){ + log_err("ERROR: Forward_unsafe offset expected:%d, Got:%d\n", fwd_unsafe[i], offunsafe); + } + i++; + } + i=0; + while(offsafe < sizeof(input)){ + UTF8_FWD_1_SAFE(input, offsafe, sizeof(input)); + if(offsafe != fwd_safe[i]){ + log_err("ERROR: Forward_safe offset expected:%d, Got:%d\n", fwd_safe[i], offsafe); + } + i++; + } + offunsafe=sizeof(input); + i=0; + while(offunsafe > 0){ + UTF8_BACK_1_UNSAFE(input, offunsafe); + if(offunsafe != back_unsafe[i]){ + log_err("ERROR: Backward_unsafe offset expected:%d, Got:%d\n", back_unsafe[i], offunsafe); + } + i++; + } + i=0; + offsafe=sizeof(input); + while(offsafe > 0){ + UTF8_BACK_1_SAFE(input, 0, offsafe); + if(offsafe != back_safe[i]){ + log_err("ERROR: Backward_safe offset expected:%d, Got:%d\n", back_unsafe[i], offsafe); + } + i++; + } + offunsafe=0; + offsafe=0; + for(i=0; i