]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/cintltst/cbiditst.c
ICU-59117.0.1.tar.gz
[apple/icu.git] / icuSources / test / cintltst / cbiditst.c
index 6c7b4b288c4e7bee0d5d59b7bbb5dba8d17c0a65..a902da7a49307e20836d32eec94f5d325be67fcc 100644 (file)
@@ -1,10 +1,12 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /********************************************************************
  * COPYRIGHT:
  * Copyright (c) 1997-2014, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /*   file name:  cbiditst.c
-*   encoding:   US-ASCII
+*   encoding:   UTF-8
 *   tab size:   8 (not used)
 *   indentation:4
 *
@@ -88,6 +90,7 @@ static void testContext(void);
 static void doTailTest(void);
 
 static void testBracketOverflow(void);
+static void TestExplicitLevel0();
 
 /* new BIDI API */
 static void testReorderingMode(void);
@@ -136,6 +139,7 @@ addComplexTest(TestNode** root) {
     addTest(root, testGetBaseDirection, "complex/bidi/testGetBaseDirection");
     addTest(root, testContext, "complex/bidi/testContext");
     addTest(root, testBracketOverflow, "complex/bidi/TestBracketOverflow");
+    addTest(root, &TestExplicitLevel0, "complex/bidi/TestExplicitLevel0");
 
     addTest(root, doArabicShapingTest, "complex/arabic-shaping/ArabicShapingTest");
     addTest(root, doLamAlefSpecialVLTRArabicShapingTest, "complex/arabic-shaping/lamalef");
@@ -4920,3 +4924,24 @@ testBracketOverflow(void) {
     ubidi_close(bidi);
 }
 
+static void TestExplicitLevel0() {
+    // The following used to fail with an error, see ICU ticket #12922.
+    static const UChar text[2] = { 0x202d, 0x05d0 };
+    static UBiDiLevel embeddings[2] = { 0, 0 };
+    UErrorCode errorCode = U_ZERO_ERROR;
+    UBiDi *bidi = ubidi_open();
+    ubidi_setPara(bidi, text, 2, UBIDI_DEFAULT_LTR , embeddings, &errorCode);
+    if (U_FAILURE(errorCode)) {
+        log_err("ubidi_setPara() - %s", u_errorName(errorCode));
+    } else {
+        UBiDiLevel level0 = ubidi_getLevelAt(bidi, 0);
+        UBiDiLevel level1 = ubidi_getLevelAt(bidi, 1);
+        if (level0 != 1 || level1 != 1) {
+            log_err("resolved levels != 1: { %d, %d }\n", level0, level1);
+        }
+        if (embeddings[0] != 1 || embeddings[1] != 1) {
+            log_err("modified embeddings[] levels != 1: { %d, %d }\n", embeddings[0], embeddings[1]);
+        }
+    }
+    ubidi_close(bidi);
+}