/******************************************************************** * COPYRIGHT: * Copyright (c) 1997-1999, 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/ubidi.h" #include "cbiditst.h" /* prototypes ---------------------------------------------------------------*/ extern void doBiDiTest(void); static void doTests(UBiDi *pBiDi, UBiDi *pLine); static void doTest(UBiDi *pBiDi, int testNumber, BiDiTestData *test, UTextOffset lineStart); static void testReordering(UBiDi *pBiDi, int testNumber); static char *levelString; static UChar * getStringFromDirProps(const uint8_t *dirProps, UTextOffset length); /* regression tests ---------------------------------------------------------*/ extern void addComplexTest(TestNode** root) { addTest(root, doBiDiTest, "complex/bidi/regression"); } extern void doBiDiTest() { UBiDi *pBiDi, *pLine=NULL; UErrorCode errorCode=U_ZERO_ERROR; log_verbose("*** bidi regression test ***\n"); pBiDi=ubidi_openSized(MAX_STRING_LENGTH, 0, &errorCode); if(pBiDi!=NULL) { pLine=ubidi_open(); if(pLine!=NULL) { doTests(pBiDi, pLine); } else { log_err("ubidi_open() returned NULL, out of memory\n"); } } else { log_err("ubidi_openSized() returned NULL, errorCode %s\n", myErrorName(errorCode)); } if(pLine!=NULL) { ubidi_close(pLine); } if(pBiDi!=NULL) { ubidi_close(pBiDi); } log_verbose("*** bidi regression test finished ***\n"); } static void doTests(UBiDi *pBiDi, UBiDi *pLine) { int i; UChar *s; UErrorCode errorCode; UTextOffset lineStart; UBiDiLevel paraLevel; for(i=0; itext+lineStart; const UBiDiLevel *levels=test->levels; const uint8_t *visualMap=test->visualMap; UTextOffset i, len=ubidi_getLength(pBiDi), logicalIndex, runCount; UErrorCode errorCode=U_ZERO_ERROR; UBiDiLevel level, level2; 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; i