/******************************************************************** * COPYRIGHT: * Copyright (c) 1997-2004, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ /* file name: cbiditst.cpp * encoding: US-ASCII * tab size: 8 (not used) * indentation:4 * * created on: 1999sep27 * created by: Markus W. Scherer */ #include "cintltst.h" #include "unicode/utypes.h" #include "unicode/uchar.h" #include "unicode/ustring.h" #include "unicode/ubidi.h" #include "unicode/ushape.h" #include "cmemory.h" #include "cbiditst.h" #include "cstring.h" #define LENGTHOF(array) (sizeof(array)/sizeof((array)[0])) /* prototypes ---------------------------------------------------------------*/ static void charFromDirPropTest(void); static void doBiDiTest(void); static void doTests(UBiDi *pBiDi, UBiDi *pLine, UBool countRunsFirst); static void doTest(UBiDi *pBiDi, int testNumber, BiDiTestData *test, int32_t lineStart, UBool countRunsFirst); static void testReordering(UBiDi *pBiDi, int testNumber); static void doInverseBiDiTest(void); static void testManyInverseBiDi(UBiDi *pBiDi, UBiDiLevel direction); static void testInverseBiDi(UBiDi *pBiDi, const UChar *src, int32_t srcLength, UBiDiLevel direction, UErrorCode *pErrorCode); static void testWriteReverse(void); static void doArabicShapingTest(void); static void doLamAlefSpecialVLTRArabicShapingTest(void); static void doTashkeelSpecialVLTRArabicShapingTest(void); static void doLOGICALArabicDeShapingTest(void); static void TestReorder(void); /* helpers ------------------------------------------------------------------ */ static const char *levelString="..............................................................."; static void initCharFromDirProps(void); static UChar * getStringFromDirProps(const uint8_t *dirProps, int32_t length); static void printUnicode(const UChar *s, int32_t length, const UBiDiLevel *levels); /* regression tests ---------------------------------------------------------*/ void addComplexTest(TestNode** root); void addComplexTest(TestNode** root) { addTest(root, charFromDirPropTest, "complex/bidi/charFromDirPropTest"); addTest(root, doBiDiTest, "complex/bidi/BiDiTest"); addTest(root, doInverseBiDiTest, "complex/bidi/inverse"); addTest(root, TestReorder,"complex/bidi/TestReorder"); addTest(root, doArabicShapingTest, "complex/arabic-shaping/ArabicShapingTest"); addTest(root, doLamAlefSpecialVLTRArabicShapingTest, "complex/arabic-shaping/lamalef"); addTest(root, doTashkeelSpecialVLTRArabicShapingTest, "complex/arabic-shaping/tashkeel"); addTest(root, doLOGICALArabicDeShapingTest, "complex/arabic-shaping/unshaping"); } /* verify that the exemplar characters have the expected bidi classes */ static void charFromDirPropTest(void) { int32_t i; initCharFromDirProps(); for(i=0; itext+lineStart; const UBiDiLevel *levels=test->levels; const uint8_t *visualMap=test->visualMap; int32_t i, len=ubidi_getLength(pBiDi), logicalIndex, runCount = 0; UErrorCode errorCode=U_ZERO_ERROR; UBiDiLevel level, level2; if (countRunsFirst) { log_verbose("Calling ubidi_countRuns() first.\n"); runCount = ubidi_countRuns(pBiDi, &errorCode); if(U_FAILURE(errorCode)) { log_err("ubidi_countRuns(tests[%d]): error %s\n", testNumber, myErrorName(errorCode)); return; } } else { log_verbose("Calling ubidi_getLogicalMap() first.\n"); } testReordering(pBiDi, testNumber); for(i=0; i0) { log_verbose(","); } log_verbose(" %d", ubidi_getLevelAt(pBiDi, i)); } log_verbose("\n--reordered:"); for(i=0; i0) { log_verbose(","); } log_verbose(" %d", ubidi_getVisualIndex(pBiDi, i, &errorCode)); } log_verbose("\n"); if(test->direction!=ubidi_getDirection(pBiDi)) { log_err("ubidi_getDirection(tests[%d]): wrong direction %d\n", testNumber, ubidi_getDirection(pBiDi)); } if(test->resultLevel!=ubidi_getParaLevel(pBiDi)) { log_err("ubidi_getParaLevel(tests[%d]): wrong paragraph level %d\n", testNumber, ubidi_getParaLevel(pBiDi)); } for(i=0; i0); } else { logicalStart+=runLength; /* logicalLimit */ do { /* RTL */ visualMap4[visualIndex++]=--logicalStart; } while(--runLength>0); } } /* print all the maps */ log_verbose("logical maps:\n"); for(i=0; ilogical->visual did not roundtrip the text;\n" " turn on verbose mode to see details\n"); } } static void testWriteReverse() { /* U+064e and U+0650 are combining marks (Mn) */ static const UChar forward[]={ 0x200f, 0x627, 0x64e, 0x650, 0x20, 0x28, 0x31, 0x29 }, reverseKeepCombining[]={ 0x29, 0x31, 0x28, 0x20, 0x627, 0x64e, 0x650, 0x200f }, reverseRemoveControlsKeepCombiningDoMirror[]={ 0x28, 0x31, 0x29, 0x20, 0x627, 0x64e, 0x650 }; static UChar reverse[10]; UErrorCode errorCode; int32_t length; /* test ubidi_writeReverse() with "interesting" options */ errorCode=U_ZERO_ERROR; length=ubidi_writeReverse(forward, LENGTHOF(forward), reverse, LENGTHOF(reverse), UBIDI_KEEP_BASE_COMBINING, &errorCode); if(U_FAILURE(errorCode) || length!=LENGTHOF(reverseKeepCombining) || uprv_memcmp(reverse, reverseKeepCombining, length*U_SIZEOF_UCHAR)!=0) { log_err("failure in ubidi_writeReverse(UBIDI_KEEP_BASE_COMBINING): length=%d (should be %d), error code %s\n", length, LENGTHOF(reverseKeepCombining), u_errorName(errorCode)); } uprv_memset(reverse, 0xa5, LENGTHOF(reverse)*U_SIZEOF_UCHAR); errorCode=U_ZERO_ERROR; length=ubidi_writeReverse(forward, LENGTHOF(forward), reverse, LENGTHOF(reverse), UBIDI_REMOVE_BIDI_CONTROLS|UBIDI_DO_MIRRORING|UBIDI_KEEP_BASE_COMBINING, &errorCode); if(U_FAILURE(errorCode) || length!=LENGTHOF(reverseRemoveControlsKeepCombiningDoMirror) || uprv_memcmp(reverse, reverseRemoveControlsKeepCombiningDoMirror, length*U_SIZEOF_UCHAR)!=0) { log_err("failure in ubidi_writeReverse(UBIDI_REMOVE_BIDI_CONTROLS|UBIDI_DO_MIRRORING|UBIDI_KEEP_BASE_COMBINING):\n" " length=%d (should be %d), error code %s\n", length, LENGTHOF(reverseRemoveControlsKeepCombiningDoMirror), u_errorName(errorCode)); } } /* arabic shaping ----------------------------------------------------------- */ static void doArabicShapingTest() { static const UChar source[]={ 0x31, /* en:1 */ 0x627, /* arabic:alef */ 0x32, /* en:2 */ 0x6f3, /* an:3 */ 0x61, /* latin:a */ 0x34, /* en:4 */ 0 }, en2an[]={ 0x661, 0x627, 0x662, 0x6f3, 0x61, 0x664, 0 }, an2en[]={ 0x31, 0x627, 0x32, 0x33, 0x61, 0x34, 0 }, logical_alen2an_init_lr[]={ 0x31, 0x627, 0x662, 0x6f3, 0x61, 0x34, 0 }, logical_alen2an_init_al[]={ 0x6f1, 0x627, 0x6f2, 0x6f3, 0x61, 0x34, 0 }, reverse_alen2an_init_lr[]={ 0x661, 0x627, 0x32, 0x6f3, 0x61, 0x34, 0 }, reverse_alen2an_init_al[]={ 0x6f1, 0x627, 0x32, 0x6f3, 0x61, 0x6f4, 0 }; UChar dest[8]; UErrorCode errorCode; int32_t length; /* test number shaping */ /* european->arabic */ errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, LENGTHOF(dest), U_SHAPE_DIGITS_EN2AN|U_SHAPE_DIGIT_TYPE_AN, &errorCode); if(U_FAILURE(errorCode) || length!=LENGTHOF(source) || uprv_memcmp(dest, en2an, length*U_SIZEOF_UCHAR)!=0) { log_err("failure in u_shapeArabic(en2an)\n"); } /* arabic->european */ errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, -1, dest, LENGTHOF(dest), U_SHAPE_DIGITS_AN2EN|U_SHAPE_DIGIT_TYPE_AN_EXTENDED, &errorCode); if(U_FAILURE(errorCode) || length!=u_strlen(source) || uprv_memcmp(dest, an2en, length*U_SIZEOF_UCHAR)!=0) { log_err("failure in u_shapeArabic(an2en)\n"); } /* european->arabic with context, logical order, initial state not AL */ errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, LENGTHOF(dest), U_SHAPE_DIGITS_ALEN2AN_INIT_LR|U_SHAPE_DIGIT_TYPE_AN, &errorCode); if(U_FAILURE(errorCode) || length!=LENGTHOF(source) || uprv_memcmp(dest, logical_alen2an_init_lr, length*U_SIZEOF_UCHAR)!=0) { log_err("failure in u_shapeArabic(logical_alen2an_init_lr)\n"); } /* european->arabic with context, logical order, initial state AL */ errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, LENGTHOF(dest), U_SHAPE_DIGITS_ALEN2AN_INIT_AL|U_SHAPE_DIGIT_TYPE_AN_EXTENDED, &errorCode); if(U_FAILURE(errorCode) || length!=LENGTHOF(source) || uprv_memcmp(dest, logical_alen2an_init_al, length*U_SIZEOF_UCHAR)!=0) { log_err("failure in u_shapeArabic(logical_alen2an_init_al)\n"); } /* european->arabic with context, reverse order, initial state not AL */ errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, LENGTHOF(dest), U_SHAPE_DIGITS_ALEN2AN_INIT_LR|U_SHAPE_DIGIT_TYPE_AN|U_SHAPE_TEXT_DIRECTION_VISUAL_LTR, &errorCode); if(U_FAILURE(errorCode) || length!=LENGTHOF(source) || uprv_memcmp(dest, reverse_alen2an_init_lr, length*U_SIZEOF_UCHAR)!=0) { log_err("failure in u_shapeArabic(reverse_alen2an_init_lr)\n"); } /* european->arabic with context, reverse order, initial state AL */ errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, LENGTHOF(dest), U_SHAPE_DIGITS_ALEN2AN_INIT_AL|U_SHAPE_DIGIT_TYPE_AN_EXTENDED|U_SHAPE_TEXT_DIRECTION_VISUAL_LTR, &errorCode); if(U_FAILURE(errorCode) || length!=LENGTHOF(source) || uprv_memcmp(dest, reverse_alen2an_init_al, length*U_SIZEOF_UCHAR)!=0) { log_err("failure in u_shapeArabic(reverse_alen2an_init_al)\n"); } /* test noop */ errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, LENGTHOF(dest), 0, &errorCode); if(U_FAILURE(errorCode) || length!=LENGTHOF(source) || uprv_memcmp(dest, source, length*U_SIZEOF_UCHAR)!=0) { log_err("failure in u_shapeArabic(noop)\n"); } errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, 0, dest, LENGTHOF(dest), U_SHAPE_DIGITS_EN2AN|U_SHAPE_DIGIT_TYPE_AN, &errorCode); if(U_FAILURE(errorCode) || length!=0) { log_err("failure in u_shapeArabic(en2an, sourceLength=0), returned %d/%s\n", u_errorName(errorCode), LENGTHOF(source)); } /* preflight digit shaping */ errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), NULL, 0, U_SHAPE_DIGITS_EN2AN|U_SHAPE_DIGIT_TYPE_AN, &errorCode); if(errorCode!=U_BUFFER_OVERFLOW_ERROR || length!=LENGTHOF(source)) { log_err("failure in u_shapeArabic(en2an preflighting), returned %d/%s instead of %d/U_BUFFER_OVERFLOW_ERROR\n", length, u_errorName(errorCode), LENGTHOF(source)); } /* test illegal arguments */ errorCode=U_ZERO_ERROR; length=u_shapeArabic(NULL, LENGTHOF(source), dest, LENGTHOF(dest), U_SHAPE_DIGITS_EN2AN|U_SHAPE_DIGIT_TYPE_AN, &errorCode); if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR) { log_err("failure in u_shapeArabic(source=NULL), returned %s instead of U_ILLEGAL_ARGUMENT_ERROR\n", u_errorName(errorCode)); } errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, -2, dest, LENGTHOF(dest), U_SHAPE_DIGITS_EN2AN|U_SHAPE_DIGIT_TYPE_AN, &errorCode); if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR) { log_err("failure in u_shapeArabic(sourceLength=-2), returned %s instead of U_ILLEGAL_ARGUMENT_ERROR\n", u_errorName(errorCode)); } errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), NULL, LENGTHOF(dest), U_SHAPE_DIGITS_EN2AN|U_SHAPE_DIGIT_TYPE_AN, &errorCode); if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR) { log_err("failure in u_shapeArabic(dest=NULL), returned %s instead of U_ILLEGAL_ARGUMENT_ERROR\n", u_errorName(errorCode)); } errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, -1, U_SHAPE_DIGITS_EN2AN|U_SHAPE_DIGIT_TYPE_AN, &errorCode); if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR) { log_err("failure in u_shapeArabic(destSize=-1), returned %s instead of U_ILLEGAL_ARGUMENT_ERROR\n", u_errorName(errorCode)); } errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, LENGTHOF(dest), U_SHAPE_DIGITS_RESERVED|U_SHAPE_DIGIT_TYPE_AN, &errorCode); if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR) { log_err("failure in u_shapeArabic(U_SHAPE_DIGITS_RESERVED), returned %s instead of U_ILLEGAL_ARGUMENT_ERROR\n", u_errorName(errorCode)); } errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, LENGTHOF(dest), U_SHAPE_DIGITS_EN2AN|U_SHAPE_DIGIT_TYPE_RESERVED, &errorCode); if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR) { log_err("failure in u_shapeArabic(U_SHAPE_DIGIT_TYPE_RESERVED), returned %s instead of U_ILLEGAL_ARGUMENT_ERROR\n", u_errorName(errorCode)); } errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), (UChar *)(source+2), LENGTHOF(dest), /* overlap source and destination */ U_SHAPE_DIGITS_EN2AN|U_SHAPE_DIGIT_TYPE_AN, &errorCode); if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR) { log_err("failure in u_shapeArabic(U_SHAPE_DIGIT_TYPE_RESERVED), returned %s instead of U_ILLEGAL_ARGUMENT_ERROR\n", u_errorName(errorCode)); } } static void doLamAlefSpecialVLTRArabicShapingTest() { static const UChar source[]={ /*a*/ 0x20 ,0x646,0x622,0x644,0x627,0x20, /*b*/ 0x646,0x623,0x64E,0x644,0x627,0x20, /*c*/ 0x646,0x627,0x670,0x644,0x627,0x20, /*d*/ 0x646,0x622,0x653,0x644,0x627,0x20, /*e*/ 0x646,0x625,0x655,0x644,0x627,0x20, /*f*/ 0x646,0x622,0x654,0x644,0x627,0x20, /*g*/ 0xFEFC,0x639 }, shape_near[]={ 0x20,0xfee5,0x20,0xfef5,0xfe8d,0x20,0xfee5,0x20,0xfe76,0xfef7,0xfe8d,0x20, 0xfee5,0x20,0x670,0xfefb,0xfe8d,0x20,0xfee5,0x20,0x653,0xfef5,0xfe8d,0x20, 0xfee5,0x20,0x655,0xfef9,0xfe8d,0x20,0xfee5,0x20,0x654,0xfef5,0xfe8d,0x20, 0xfefc,0xfecb }, shape_at_end[]={ 0x20,0xfee5,0xfef5,0xfe8d,0x20,0xfee5,0xfe76,0xfef7,0xfe8d,0x20,0xfee5,0x670, 0xfefb,0xfe8d,0x20,0xfee5,0x653,0xfef5,0xfe8d,0x20,0xfee5,0x655,0xfef9,0xfe8d, 0x20,0xfee5,0x654,0xfef5,0xfe8d,0x20,0xfefc,0xfecb,0x20,0x20,0x20,0x20,0x20,0x20 }, shape_at_begin[]={ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0xfee5,0xfef5,0xfe8d,0x20,0xfee5,0xfe76, 0xfef7,0xfe8d,0x20,0xfee5,0x670,0xfefb,0xfe8d,0x20,0xfee5,0x653,0xfef5,0xfe8d, 0x20,0xfee5,0x655,0xfef9,0xfe8d,0x20,0xfee5,0x654,0xfef5,0xfe8d,0x20,0xfefc,0xfecb }, shape_grow_shrink[]={ 0x20,0xfee5,0xfef5,0xfe8d,0x20,0xfee5,0xfe76,0xfef7,0xfe8d,0x20,0xfee5, 0x670,0xfefb,0xfe8d,0x20,0xfee5,0x653,0xfef5,0xfe8d,0x20,0xfee5,0x655,0xfef9, 0xfe8d,0x20,0xfee5,0x654,0xfef5,0xfe8d,0x20,0xfefc,0xfecb }, shape_excepttashkeel_near[]={ 0x20,0xfee5,0x20,0xfef5,0xfe8d,0x20,0xfee5,0x20,0xfe76,0xfef7,0xfe8d,0x20, 0xfee5,0x20,0x670,0xfefb,0xfe8d,0x20,0xfee5,0x20,0x653,0xfef5,0xfe8d,0x20, 0xfee5,0x20,0x655,0xfef9,0xfe8d,0x20,0xfee5,0x20,0x654,0xfef5,0xfe8d,0x20, 0xfefc,0xfecb }, shape_excepttashkeel_at_end[]={ 0x20,0xfee5,0xfef5,0xfe8d,0x20,0xfee5,0xfe76,0xfef7,0xfe8d,0x20,0xfee5, 0x670,0xfefb,0xfe8d,0x20,0xfee5,0x653,0xfef5,0xfe8d,0x20,0xfee5,0x655,0xfef9, 0xfe8d,0x20,0xfee5,0x654,0xfef5,0xfe8d,0x20,0xfefc,0xfecb,0x20,0x20,0x20, 0x20,0x20,0x20 }, shape_excepttashkeel_at_begin[]={ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0xfee5,0xfef5,0xfe8d,0x20,0xfee5,0xfe76, 0xfef7,0xfe8d,0x20,0xfee5,0x670,0xfefb,0xfe8d,0x20,0xfee5,0x653,0xfef5,0xfe8d, 0x20,0xfee5,0x655,0xfef9,0xfe8d,0x20,0xfee5,0x654,0xfef5,0xfe8d,0x20,0xfefc,0xfecb }, shape_excepttashkeel_grow_shrink[]={ 0x20,0xfee5,0xfef5,0xfe8d,0x20,0xfee5,0xfe76,0xfef7,0xfe8d,0x20,0xfee5,0x670, 0xfefb,0xfe8d,0x20,0xfee5,0x653,0xfef5,0xfe8d,0x20,0xfee5,0x655,0xfef9,0xfe8d, 0x20,0xfee5,0x654,0xfef5,0xfe8d,0x20,0xfefc,0xfecb }; UChar dest[38]; UErrorCode errorCode; int32_t length; errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, LENGTHOF(dest), U_SHAPE_LETTERS_SHAPE|U_SHAPE_LENGTH_FIXED_SPACES_NEAR| U_SHAPE_TEXT_DIRECTION_VISUAL_LTR, &errorCode); if(U_FAILURE(errorCode) || length!=LENGTHOF(shape_near) || uprv_memcmp(dest, shape_near, length*U_SIZEOF_UCHAR)!=0) { log_err("failure in u_shapeArabic(LAMALEF shape_near)\n"); } errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, LENGTHOF(dest), U_SHAPE_LETTERS_SHAPE|U_SHAPE_LENGTH_FIXED_SPACES_AT_END| U_SHAPE_TEXT_DIRECTION_VISUAL_LTR, &errorCode); if(U_FAILURE(errorCode) || length!=LENGTHOF(shape_at_end) || uprv_memcmp(dest, shape_at_end, length*U_SIZEOF_UCHAR)!=0) { log_err("failure in u_shapeArabic(LAMALEF shape_at_end)\n"); } errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, LENGTHOF(dest), U_SHAPE_LETTERS_SHAPE|U_SHAPE_LENGTH_FIXED_SPACES_AT_BEGINNING| U_SHAPE_TEXT_DIRECTION_VISUAL_LTR, &errorCode); if(U_FAILURE(errorCode) || length!=LENGTHOF(shape_at_begin) || uprv_memcmp(dest, shape_at_begin, length*U_SIZEOF_UCHAR)!=0) { log_err("failure in u_shapeArabic(LAMALEF shape_at_begin)\n"); } errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, LENGTHOF(dest), U_SHAPE_LETTERS_SHAPE|U_SHAPE_LENGTH_GROW_SHRINK| U_SHAPE_TEXT_DIRECTION_VISUAL_LTR, &errorCode); if(U_FAILURE(errorCode) || uprv_memcmp(dest, shape_grow_shrink, length*U_SIZEOF_UCHAR)!=0) { log_err("failure in u_shapeArabic(LAMALEF shape_grow_shrink)\n"); } /* ==================== U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED ==================== */ errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, LENGTHOF(dest), U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED|U_SHAPE_LENGTH_FIXED_SPACES_NEAR| U_SHAPE_TEXT_DIRECTION_VISUAL_LTR, &errorCode); if(U_FAILURE(errorCode) || length!=LENGTHOF(shape_excepttashkeel_near) || uprv_memcmp(dest, shape_excepttashkeel_near, length*U_SIZEOF_UCHAR)!=0) { log_err("failure in u_shapeArabic(LAMALEF shape_excepttashkeel_near)\n"); } errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, LENGTHOF(dest), U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED|U_SHAPE_LENGTH_FIXED_SPACES_AT_END| U_SHAPE_TEXT_DIRECTION_VISUAL_LTR, &errorCode); if(U_FAILURE(errorCode) || length!=LENGTHOF(shape_excepttashkeel_at_end) || uprv_memcmp(dest,shape_excepttashkeel_at_end , length*U_SIZEOF_UCHAR)!=0) { log_err("failure in u_shapeArabic(LAMALEF shape_excepttashkeel_at_end)\n"); } errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, LENGTHOF(dest), U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED|U_SHAPE_LENGTH_FIXED_SPACES_AT_BEGINNING| U_SHAPE_TEXT_DIRECTION_VISUAL_LTR, &errorCode); if(U_FAILURE(errorCode) || length!=LENGTHOF(shape_excepttashkeel_at_begin) || uprv_memcmp(dest, shape_excepttashkeel_at_begin, length*U_SIZEOF_UCHAR)!=0) { log_err("failure in u_shapeArabic(LAMALEF shape_excepttashkeel_at_begin)\n"); } errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, LENGTHOF(dest), U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED|U_SHAPE_LENGTH_GROW_SHRINK| U_SHAPE_TEXT_DIRECTION_VISUAL_LTR, &errorCode); if(U_FAILURE(errorCode) || uprv_memcmp(dest, shape_excepttashkeel_grow_shrink, length*U_SIZEOF_UCHAR)!=0) { log_err("failure in u_shapeArabic(LAMALEF shape_excepttashkeel_grow_shrink)\n"); } } static void doTashkeelSpecialVLTRArabicShapingTest() { static const UChar source[]={ 0x64A,0x628,0x631,0x639,0x20, 0x64A,0x628,0x651,0x631,0x64E,0x639,0x20, 0x64C,0x64A,0x628,0x631,0x64F,0x639,0x20, 0x628,0x670,0x631,0x670,0x639,0x20, 0x628,0x653,0x631,0x653,0x639,0x20, 0x628,0x654,0x631,0x654,0x639,0x20, 0x628,0x655,0x631,0x655,0x639,0x20, }, shape_near[]={ 0xfef2,0xfe91,0xfeae,0xfecb,0x20,0xfef2,0xfe91,0xfe7c,0xfeae,0xfe77,0xfecb, 0x20,0xfe72,0xfef2,0xfe91,0xfeae,0xfe79,0xfecb,0x20,0xfe8f,0x670,0xfeae,0x670, 0xfecb,0x20,0xfe8f,0x653,0xfeae,0x653,0xfecb,0x20,0xfe8f,0x654,0xfeae,0x654, 0xfecb,0x20,0xfe8f,0x655,0xfeae,0x655,0xfecb,0x20 }, shape_excepttashkeel_near[]={ 0xfef2,0xfe91,0xfeae,0xfecb,0x20,0xfef2,0xfe91,0xfe7c,0xfeae,0xfe76,0xfecb,0x20, 0xfe72,0xfef2,0xfe91,0xfeae,0xfe78,0xfecb,0x20,0xfe8f,0x670,0xfeae,0x670,0xfecb, 0x20,0xfe8f,0x653,0xfeae,0x653,0xfecb,0x20,0xfe8f,0x654,0xfeae,0x654,0xfecb,0x20, 0xfe8f,0x655,0xfeae,0x655,0xfecb,0x20 }; UChar dest[43]; UErrorCode errorCode; int32_t length; errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, LENGTHOF(dest), U_SHAPE_LETTERS_SHAPE|U_SHAPE_LENGTH_FIXED_SPACES_NEAR| U_SHAPE_TEXT_DIRECTION_VISUAL_LTR, &errorCode); if(U_FAILURE(errorCode) || length!=LENGTHOF(shape_near) || uprv_memcmp(dest, shape_near, length*U_SIZEOF_UCHAR)!=0) { log_err("failure in u_shapeArabic(TASHKEEL shape_near)\n"); } errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, LENGTHOF(dest), U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED|U_SHAPE_LENGTH_FIXED_SPACES_NEAR| U_SHAPE_TEXT_DIRECTION_VISUAL_LTR, &errorCode); if(U_FAILURE(errorCode) || length!=LENGTHOF(shape_excepttashkeel_near) || uprv_memcmp(dest, shape_excepttashkeel_near, length*U_SIZEOF_UCHAR)!=0) { log_err("failure in u_shapeArabic(TASHKEEL shape_excepttashkeel_near)\n"); } } static void doLOGICALArabicDeShapingTest() { static const UChar source[]={ 0x0020,0x0020,0x0020,0xFE8D,0xFEF5,0x0020,0xFEE5,0x0020,0xFE8D,0xFEF7,0x0020, 0xFED7,0xFEFC,0x0020,0xFEE1,0x0020,0xFE8D,0xFEDF,0xFECC,0xFEAE,0xFE91,0xFEF4, 0xFE94,0x0020,0xFE8D,0xFEDF,0xFEA4,0xFEAE,0xFE93,0x0020,0x0020,0x0020,0x0020 }, unshape_near[]={ 0x20,0x20,0x20,0x627,0x644,0x622,0x646,0x20,0x627,0x644,0x623,0x642,0x644,0x627, 0x645,0x20,0x627,0x644,0x639,0x631,0x628,0x64a,0x629,0x20,0x627,0x644,0x62d,0x631, 0x629,0x20,0x20,0x20,0x20 }, unshape_at_end[]={ 0x20,0x20,0x20,0x627,0x644,0x622,0x20,0x646,0x20,0x627,0x644,0x623,0x20,0x642, 0x644,0x627,0x20,0x645,0x20,0x627,0x644,0x639,0x631,0x628,0x64a,0x629,0x20,0x627, 0x644,0x62d,0x631,0x629,0x20 }, unshape_at_begin[]={ 0x627,0x644,0x622,0x20,0x646,0x20,0x627,0x644,0x623,0x20,0x642,0x644,0x627,0x20, 0x645,0x20,0x627,0x644,0x639,0x631,0x628,0x64a,0x629,0x20,0x627,0x644,0x62d,0x631, 0x629,0x20,0x20,0x20,0x20 }, unshape_grow_shrink[]={ 0x20,0x20,0x20,0x627,0x644,0x622,0x20,0x646,0x20,0x627,0x644,0x623,0x20,0x642, 0x644,0x627,0x20,0x645,0x20,0x627,0x644,0x639,0x631,0x628,0x64a,0x629,0x20,0x627, 0x644,0x62d,0x631,0x629,0x20,0x20,0x20,0x20 }; UChar dest[36]; UErrorCode errorCode; int32_t length; errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, LENGTHOF(dest), U_SHAPE_LETTERS_UNSHAPE|U_SHAPE_LENGTH_FIXED_SPACES_NEAR| U_SHAPE_TEXT_DIRECTION_LOGICAL, &errorCode); if(U_FAILURE(errorCode) || length!=LENGTHOF(unshape_near) || uprv_memcmp(dest, unshape_near, length*U_SIZEOF_UCHAR)!=0) { log_err("failure in u_shapeArabic(unshape_near)\n"); } errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, LENGTHOF(dest), U_SHAPE_LETTERS_UNSHAPE|U_SHAPE_LENGTH_FIXED_SPACES_AT_END| U_SHAPE_TEXT_DIRECTION_LOGICAL, &errorCode); if(U_FAILURE(errorCode) || length!=LENGTHOF(unshape_at_end) || uprv_memcmp(dest, unshape_at_end, length*U_SIZEOF_UCHAR)!=0) { log_err("failure in u_shapeArabic(unshape_at_end)\n"); } errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, LENGTHOF(dest), U_SHAPE_LETTERS_UNSHAPE|U_SHAPE_LENGTH_FIXED_SPACES_AT_BEGINNING| U_SHAPE_TEXT_DIRECTION_LOGICAL, &errorCode); if(U_FAILURE(errorCode) || length!=LENGTHOF(unshape_at_begin) || uprv_memcmp(dest, unshape_at_begin, length*U_SIZEOF_UCHAR)!=0) { log_err("failure in u_shapeArabic(unshape_at_begin)\n"); } errorCode=U_ZERO_ERROR; length=u_shapeArabic(source, LENGTHOF(source), dest, LENGTHOF(dest), U_SHAPE_LETTERS_UNSHAPE|U_SHAPE_LENGTH_GROW_SHRINK| U_SHAPE_TEXT_DIRECTION_LOGICAL, &errorCode); if(U_FAILURE(errorCode) || uprv_memcmp(dest, unshape_grow_shrink, length*U_SIZEOF_UCHAR)!=0) { log_err("failure in u_shapeArabic(unshape_grow_shrink)\n"); } } /* helpers ------------------------------------------------------------------ */ static void initCharFromDirProps() { static const UVersionInfo ucd401={ 4, 0, 1, 0 }; static UVersionInfo ucdVersion={ 0, 0, 0, 0 }; /* lazy initialization */ if(ucdVersion[0]>0) { return; } u_getUnicodeVersion(ucdVersion); if(memcmp(ucdVersion, ucd401, sizeof(UVersionInfo))>=0) { /* Unicode 4.0.1 changes bidi classes for +-/ */ charFromDirProp[U_EUROPEAN_NUMBER_SEPARATOR]=0x2b; /* change ES character from / to + */ } } /* return a string with characters according to the desired directional properties */ static UChar * getStringFromDirProps(const uint8_t *dirProps, int32_t length) { static UChar s[MAX_STRING_LENGTH]; int32_t i; initCharFromDirProps(); /* this part would have to be modified for UTF-x */ for(i=0; i