From 9f4ec56042fd20a325b78101f1626249f8ef1f4f Mon Sep 17 00:00:00 2001 From: Ram Viswanadha Date: Tue, 2 Apr 2002 03:36:54 +0000 Subject: [PATCH] ICU-1811 Improve code coverage of ubidi X-SVN-Rev: 8337 --- icu4c/source/test/cintltst/cbiditst.c | 153 ++++++++++++++++++++++++++ icu4c/source/test/cintltst/ccolltst.c | 8 +- icu4c/source/test/cintltst/cintltst.c | 8 +- icu4c/source/test/cintltst/cintltst.h | 2 +- icu4c/source/test/cintltst/cstrcase.c | 4 +- 5 files changed, 164 insertions(+), 11 deletions(-) diff --git a/icu4c/source/test/cintltst/cbiditst.c b/icu4c/source/test/cintltst/cbiditst.c index 2fbd977027..14673d50b6 100644 --- a/icu4c/source/test/cintltst/cbiditst.c +++ b/icu4c/source/test/cintltst/cbiditst.c @@ -20,6 +20,7 @@ #include "unicode/ushape.h" #include "cmemory.h" #include "cbiditst.h" +#include "cstring.h" #define LENGTHOF(array) (sizeof(array)/sizeof((array)[0])) @@ -61,6 +62,8 @@ doTashkeelSpecialVLTRArabicShapingTest(void); static void doLOGICALArabicDeShapingTest(void); +static void TestReorder(void); + /* helpers ------------------------------------------------------------------ */ static const char *levelString="..............................................................."; @@ -83,6 +86,7 @@ addComplexTest(TestNode** root) { addTest(root, doLamAlefSpecialVLTRArabicShapingTest, "complex/arabic-shaping/lamalef"); addTest(root, doTashkeelSpecialVLTRArabicShapingTest, "complex/arabic-shaping/tashkeel"); addTest(root, doLOGICALArabicDeShapingTest, "complex/arabic-shaping/unshaping"); + addTest(root, TestReorder,"complex/bidi/TestReorder"); } static void @@ -150,6 +154,154 @@ doTests(UBiDi *pBiDi, UBiDi *pLine) { } } } +static void TestReorder(){ + char* logicalOrder[] ={ + "DEL(\\u062F\\u0625)ADD(\\u062F.\\u0625.\\u200F)", + "DEL(\\u0645\\u0627\\u064A\\u0648) ADD(\\u0623\\u064A\\u0627\\u0631)", + "DEL(\\u0644\\u0644)ADD(\\u0644.\\u0644.\\u0029\\u0644)\\u0644.\\u200F", + "DEL(\\u0631\\u064A)ADD(\\u0631.\\u064A.) \\u0631.\\u064A.\\u200F", + "DAY 2 \\u0646 \\u0627\\u0644\\u0627\\u062B\\u0646\\u064A\\u0646 DAYABBR", + "DAY 3 \\u062B \\u0627\\u0644\\u062B\\u0644\\u0627\\u062B\\u0627\\u0621 DAYABBR", + "DAY 4 \\u0631 \\u0627\\u0644\\u0623\\u0631\\u0628\\u0639\\u0627\\u0621 DAYABBR", + "DAY 5 \\u062E \\u0627\\u0644\\u062E\\u0645\\u064A\\u0633 DAYABBR", + "DAY 6 \\u062C \\u0627\\u0644\\u062C\\u0645\\u0639\\u0629 DAYABBR", + "DAY 7 \\u0633 \\u0627\\u0644\\u0633\\u0628\\u062A DAYABBR", + "HELLO\\u0627\\u0644\\u0633\\u0628\\u062A", + }; + char* visualOrder[]={ + "DEL(\\u0625\\u062F)ADD(\\u200F.\\u0625.\\u062F)", + "DEL(\\u0648\\u064A\\u0627\\u0645) ADD(\\u0631\\u0627\\u064A\\u0623)", + "DEL(\\u0644\\u0644)ADD(\\u0644\\u0029.\\u0644.\\u0644)\\u200F.\\u0644", + /* I am doutful about this... + * what I would expect is : + * DEL(\\u064A\\u0631)ADD(.\\u064A.\\u0631) \\u200F.\\u064A.\\u0631 + */ + "DEL(\\u064A\\u0631)ADD(\\u200F.\\u064A.\\u0631 (.\\u064A.\\u0631", + "DAY 2 \\u0646\\u064A\\u0646\\u062B\\u0627\\u0644\\u0627 \\u0646 DAYABBR", + "DAY 3 \\u0621\\u0627\\u062B\\u0627\\u0644\\u062B\\u0644\\u0627 \\u062B DAYABBR", + "DAY 4 \\u0621\\u0627\\u0639\\u0628\\u0631\\u0623\\u0644\\u0627 \\u0631 DAYABBR", + "DAY 5 \\u0633\\u064A\\u0645\\u062E\\u0644\\u0627 \\u062E DAYABBR", + "DAY 6 \\u0629\\u0639\\u0645\\u062C\\u0644\\u0627 \\u062C DAYABBR", + "DAY 7 \\u062A\\u0628\\u0633\\u0644\\u0627 \\u0633 DAYABBR", + "HELLO\\u062A\\u0628\\u0633\\u0644\\u0627", + }; + char* visualOrder1[]={ + ")\\u062F.\\u0625.\\u200F(DDA)\\u062F\\u0625(LED", + ")\\u0623\\u064A\\u0627\\u0631(DDA )\\u0645\\u0627\\u064A\\u0648(LED", + "\\u0644.\\u0644.(\\u0644(\\u0644.\\u200F(DDA)\\u0644\\u0644(LED", + "\\u0631.\\u064A.( \\u0631.\\u064A.\\u200F(DDA)\\u0631\\u064A(LED", + "RBBAYAD \\u0646 \\u0627\\u0644\\u0627\\u062B\\u0646\\u064A\\u0646 2 YAD", + "RBBAYAD \\u062B \\u0627\\u0644\\u062B\\u0644\\u0627\\u062B\\u0627\\u0621 3 YAD", + "RBBAYAD \\u0631 \\u0627\\u0644\\u0623\\u0631\\u0628\\u0639\\u0627\\u0621 4 YAD", + "RBBAYAD \\u062E \\u0627\\u0644\\u062E\\u0645\\u064A\\u0633 5 YAD", + "RBBAYAD \\u062C \\u0627\\u0644\\u062C\\u0645\\u0639\\u0629 6 YAD", + "RBBAYAD \\u0633 \\u0627\\u0644\\u0633\\u0628\\u062A 7 YAD", + "\\u0627\\u0644\\u0633\\u0628\\u062AOLLEH", + }; + + char* visualOrder2[]={ + "\\u200E)\\u200E\\u062F.\\u0625.\\u200F\\u200E(DDA)\\u200E\\u062F\\u0625\\u200E(LED", + "\\u200E)\\u200E\\u0623\\u064A\\u0627\\u0631\\u200E(DDA )\\u200E\\u0645\\u0627\\u064A\\u0648\\u200E(LED", + "\\u0644.\\u0644.)\\u0644)\\u0644.\\u200F\\u200E(DDA)\\u200E\\u0644\\u0644\\u200E(LED", + "\\u0631.\\u064A.) \\u0631.\\u064A.\\u200F\\u200E(DDA)\\u200E\\u0631\\u064A\\u200E(LED", + "RBBAYAD \\u200E\\u0646 \\u0627\\u0644\\u0627\\u062B\\u0646\\u064A\\u0646\\u200E 2 YAD", + "RBBAYAD \\u200E\\u062B \\u0627\\u0644\\u062B\\u0644\\u0627\\u062B\\u0627\\u0621\\u200E 3 YAD", + "RBBAYAD \\u200E\\u0631 \\u0627\\u0644\\u0623\\u0631\\u0628\\u0639\\u0627\\u0621\\u200E 4 YAD", + "RBBAYAD \\u200E\\u062E \\u0627\\u0644\\u062E\\u0645\\u064A\\u0633\\u200E 5 YAD", + "RBBAYAD \\u200E\\u062C \\u0627\\u0644\\u062C\\u0645\\u0639\\u0629\\u200E 6 YAD", + "RBBAYAD \\u200E\\u0633 \\u0627\\u0644\\u0633\\u0628\\u062A\\u200E 7 YAD", + "\\u0627\\u0644\\u0633\\u0628\\u062AOLLEH", + }; + + + UErrorCode ec = U_ZERO_ERROR; + UBiDi* bidi = ubidi_open(); + int i=0; + for(;i<(sizeof(logicalOrder)/sizeof(logicalOrder[0]));i++){ + int32_t srcSize = uprv_strlen(logicalOrder[i]); + UChar* src = (UChar*) uprv_malloc(sizeof(UChar)*srcSize ); + UChar* dest = (UChar*) uprv_malloc(sizeof(UChar)*srcSize); + char* chars=NULL; + int32_t destSize = srcSize; + ec = U_ZERO_ERROR; + u_unescape(logicalOrder[i],src,srcSize); + srcSize= u_strlen(src); + ubidi_setPara(bidi,src,srcSize,UBIDI_DEFAULT_LTR ,NULL,&ec); + if(U_FAILURE(ec)){ + log_err("ubidi_setPara(tests[%d], paraLevel %d) failed with errorCode %s\n", + i, UBIDI_DEFAULT_LTR, u_errorName(ec)); + } + destSize=ubidi_writeReordered(bidi,dest,destSize,UBIDI_DO_MIRRORING,&ec); + chars = aescstrdup(dest,-1); + if(destSize!=srcSize){ + log_err("ubidi_writeReordered() destSize and srcSize do not match\n"); + }else if(uprv_strncmp(visualOrder[i],chars,destSize)!=0){ + log_err("ubidi_writeReordered() did not give expected results. Expected: %s Got: %s At Index: %d\n",visualOrder[i],chars,i); + + + } + uprv_free(src); + uprv_free(dest); + } + for(i=0;i<(sizeof(logicalOrder)/sizeof(logicalOrder[0]));i++){ + int32_t srcSize = uprv_strlen(logicalOrder[i]); + UChar* src = (UChar*) uprv_malloc(sizeof(UChar)*srcSize ); + UChar* dest = (UChar*) uprv_malloc(sizeof(UChar)*srcSize); + char* chars=NULL; + int32_t destSize = srcSize; + ec = U_ZERO_ERROR; + u_unescape(logicalOrder[i],src,srcSize); + srcSize=u_strlen(src); + ubidi_setPara(bidi,src,srcSize,UBIDI_DEFAULT_LTR ,NULL,&ec); + if(U_FAILURE(ec)){ + log_err("ubidi_setPara(tests[%d], paraLevel %d) failed with errorCode %s\n", + i, UBIDI_DEFAULT_LTR, u_errorName(ec)); + } + destSize=ubidi_writeReordered(bidi,dest,destSize,UBIDI_DO_MIRRORING+UBIDI_OUTPUT_REVERSE,&ec); + chars = aescstrdup(dest,destSize); + if(destSize!=srcSize){ + log_err("ubidi_writeReordered() destSize and srcSize do not match\n"); + }else if(uprv_strncmp(visualOrder1[i],chars,destSize)!=0){ + log_err("ubidi_writeReordered() did not give expected results for UBIDI_DO_MIRRORING+UBIDI_OUTPUT_REVERSE. Expected: %s Got: %s At Index: %d\n",visualOrder[i],chars,i); + + + } + + uprv_free(src); + uprv_free(dest); + } + for(i=0;i<(sizeof(logicalOrder)/sizeof(logicalOrder[0]));i++){ + int32_t srcSize = uprv_strlen(logicalOrder[i]); + UChar* src = (UChar*) uprv_malloc(sizeof(UChar)*srcSize ); + UChar* dest = (UChar*) uprv_malloc(sizeof(UChar)*srcSize); + char* chars=NULL; + int32_t destSize = srcSize; + ec = U_ZERO_ERROR; + u_unescape(logicalOrder[i],src,srcSize); + srcSize=u_strlen(src); + ubidi_setPara(bidi,src,srcSize,UBIDI_DEFAULT_LTR ,NULL,&ec); + ubidi_setInverse(bidi,TRUE); + if(U_FAILURE(ec)){ + log_err("ubidi_setPara(tests[%d], paraLevel %d) failed with errorCode %s\n", + i, UBIDI_DEFAULT_LTR, u_errorName(ec)); + } + destSize=ubidi_writeReordered(bidi,dest,destSize,UBIDI_INSERT_LRM_FOR_NUMERIC+UBIDI_OUTPUT_REVERSE,&ec); + chars = aescstrdup(dest,destSize); + + /*if(destSize!=srcSize){ + log_err("ubidi_writeReordered() destSize and srcSize do not match. Dest Size = %d Source Size = %d\n",destSize,srcSize ); + }else*/ + if(uprv_strncmp(visualOrder2[i],chars,destSize)!=0){ + log_err("ubidi_writeReordered() did not give expected results for UBIDI_INSERT_LRM_FOR_NUMERIC+UBIDI_OUTPUT_REVERSE. Expected: %s Got: %s At Index: %d\n",visualOrder[i],chars,i); + + + } + + uprv_free(src); + uprv_free(dest); + } + +} static void doTest(UBiDi *pBiDi, int testNumber, BiDiTestData *test, int32_t lineStart) { @@ -385,6 +537,7 @@ testReordering(UBiDi *pBiDi, int testNumber) { } } + /* inverse BiDi ------------------------------------------------------------- */ static const UChar diff --git a/icu4c/source/test/cintltst/ccolltst.c b/icu4c/source/test/cintltst/ccolltst.c index e87f67f95b..0b704af4f9 100644 --- a/icu4c/source/test/cintltst/ccolltst.c +++ b/icu4c/source/test/cintltst/ccolltst.c @@ -82,7 +82,7 @@ void reportCResult( const UChar source[], const UChar target[], appendCompareResult(compareResult, sResult); appendCompareResult(expectedResult, sExpect); - log_err("Compare(%s , %s) returned: %s expected: %s\n", aescstrdup(source), aescstrdup(target), + log_err("Compare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1), austrdup(sResult), austrdup(sExpect) ); } @@ -91,7 +91,7 @@ void reportCResult( const UChar source[], const UChar target[], appendCompareResult(incResult, sResult); appendCompareResult(expectedResult, sExpect); - log_err("incCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source), aescstrdup(target), + log_err("incCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1), austrdup(sResult), austrdup(sExpect) ); } @@ -101,7 +101,7 @@ void reportCResult( const UChar source[], const UChar target[], appendCompareResult(keyResult, sResult); appendCompareResult(expectedResult, sExpect); - log_err("KeyCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source), aescstrdup(target), + log_err("KeyCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1), austrdup(sResult), austrdup(sExpect) ); @@ -113,7 +113,7 @@ void reportCResult( const UChar source[], const UChar target[], appendCompareResult(keyResult, sResult); appendCompareResult(compareResult, sExpect); - log_err("difference between sortkey and compare result for (%s , %s) Keys: %s compare %s\n", aescstrdup(source), aescstrdup(target), + log_err("difference between sortkey and compare result for (%s , %s) Keys: %s compare %s\n", aescstrdup(source,-1), aescstrdup(target,-1), austrdup(sResult), austrdup(sExpect) ); diff --git a/icu4c/source/test/cintltst/cintltst.c b/icu4c/source/test/cintltst/cintltst.c index 994454559e..2597b178f5 100644 --- a/icu4c/source/test/cintltst/cintltst.c +++ b/icu4c/source/test/cintltst/cintltst.c @@ -282,15 +282,15 @@ char *austrdup(const UChar* unichars) return newString; } -char *aescstrdup(const UChar* unichars){ - int length; +char *aescstrdup(const UChar* unichars,int32_t length){ char *newString,*targetLimit,*target; UConverterFromUCallback cb; const void *p; UErrorCode errorCode = U_ZERO_ERROR; UConverter* conv = ucnv_open("US-ASCII",&errorCode); - - length = u_strlen( unichars); + if(length==-1){ + length = u_strlen( unichars); + } newString = (char*)ctst_malloc ( sizeof(char) * 8 * (length +1)); target = newString; targetLimit = newString+sizeof(char) * 8 * (length +1); diff --git a/icu4c/source/test/cintltst/cintltst.h b/icu4c/source/test/cintltst/cintltst.h index 12e4091c9d..1658a4fd61 100644 --- a/icu4c/source/test/cintltst/cintltst.h +++ b/icu4c/source/test/cintltst/cintltst.h @@ -46,7 +46,7 @@ U_CFUNC void ctest_pathnameInContext(char* fullname, int32_t maxsize, const char */ U_CFUNC char *austrdup(const UChar* unichars); -U_CFUNC char *aescstrdup(const UChar* unichars); +U_CFUNC char *aescstrdup(const UChar* unichars, int32_t length); U_CFUNC void *ctst_malloc(size_t size); U_CFUNC void ctst_freeAll(); diff --git a/icu4c/source/test/cintltst/cstrcase.c b/icu4c/source/test/cintltst/cstrcase.c index 706965fcab..697f7aad7d 100644 --- a/icu4c/source/test/cintltst/cstrcase.c +++ b/icu4c/source/test/cintltst/cstrcase.c @@ -56,8 +56,8 @@ TestCaseLower() { u_errorName(errorCode), uprv_memcmp(lowerRoot, buffer, length*U_SIZEOF_UCHAR)==0 && buffer[length]==0 ? "yes" : "no", - aescstrdup(lowerRoot), - aescstrdup(buffer)); + aescstrdup(lowerRoot,-1), + aescstrdup(buffer,-1)); } /* lowercase with turkish locale and in the same buffer */