diff --git a/icu4c/source/test/cintltst/cbiditst.c b/icu4c/source/test/cintltst/cbiditst.c index 81497c0f571..6f23681466c 100644 --- a/icu4c/source/test/cintltst/cbiditst.c +++ b/icu4c/source/test/cintltst/cbiditst.c @@ -15,9 +15,14 @@ #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" +#define LENGTHOF(array) (sizeof(array)/sizeof((array)[0])) + /* prototypes ---------------------------------------------------------------*/ extern void @@ -46,6 +51,9 @@ static char *levelString; static UChar * getStringFromDirProps(const uint8_t *dirProps, UTextOffset length); +extern void +doArabicShapingTest(); + static void printUnicode(const UChar *s, int32_t length, const UBiDiLevel *levels); @@ -55,6 +63,7 @@ extern void addComplexTest(TestNode** root) { addTest(root, doBiDiTest, "complex/bidi"); addTest(root, doInverseBiDiTest, "complex/invbidi"); + addTest(root, doArabicShapingTest, "complex/arabic-shaping"); } extern void @@ -366,7 +375,7 @@ static const UChar string3[]={ 0x31, 0x32, 0x33, 0x20, 0x5d0, 0x5d1, 0x5d2, 0x20, 0x34, 0x35, 0x36 }, string4[]={ 0x61, 0x62, 0x20, 0x61, 0x62, 0x20, 0x661, 0x662 }; -#define STRING_TEST_CASE(s) { (s), sizeof(s)/U_SIZEOF_UCHAR } +#define STRING_TEST_CASE(s) { (s), LENGTHOF(s) } static const struct { const UChar *s; @@ -392,14 +401,14 @@ doInverseBiDiTest() { return; } - log_info("inverse BiDi: testInverseBiDi(L) with %u test cases ---\n", sizeof(testCases)/sizeof(testCases[0])); - for(i=0; iarabic */ + 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 */ + /* test illegal arguments */ + /* test that letter shaping sets "unsupported" */ + /* ### to be done */ +} + /* helpers ------------------------------------------------------------------ */ static char *levelString="...............................................................";