ICU-13344 problem with SETNATIVEINDEX macro.
authorAndy Heninger <andy.heninger@gmail.com>
Wed, 6 Sep 2017 21:44:58 +0000 (21:44 +0000)
committerAndy Heninger <andy.heninger@gmail.com>
Wed, 6 Sep 2017 21:44:58 +0000 (21:44 +0000)
X-SVN-Rev: 40372

icu4c/source/common/unicode/utext.h
icu4c/source/test/intltest/utxttest.cpp
icu4c/source/test/intltest/utxttest.h

index 80ce8afaa568f004095cfd6da5f95500112ed804..65688d74af01be5d02e7b9803dc1cc547a1379ec 100644 (file)
@@ -768,7 +768,7 @@ utext_extract(UText *ut,
   */
 #define UTEXT_SETNATIVEINDEX(ut, ix)                       \
     { int64_t __offset = (ix) - (ut)->chunkNativeStart; \
-      if (__offset>=0 && __offset<=(int64_t)(ut)->nativeIndexingLimit) { \
+      if (__offset>=0 && __offset<(int64_t)(ut)->nativeIndexingLimit && (ut)->chunkContents[__offset]<0xdc00) { \
           (ut)->chunkOffset=(int32_t)__offset; \
       } else { \
           utext_setNativeIndex((ut), (ix)); } }
index 91d86a8db9870e9f9765a0d582f420b9112158e8..622e0633803831c3a74013fbf3fe58af256de518 100644 (file)
@@ -50,27 +50,18 @@ UTextTest::~UTextTest() {
 void
 UTextTest::runIndexedTest(int32_t index, UBool exec,
                           const char* &name, char* /*par*/) {
-    switch (index) {
-        case 0: name = "TextTest";
-            if (exec) TextTest();    break;
-        case 1: name = "ErrorTest";
-            if (exec) ErrorTest();   break;
-        case 2: name = "FreezeTest";
-            if (exec) FreezeTest();  break;
-        case 3: name = "Ticket5560";
-            if (exec) Ticket5560();  break;
-        case 4: name = "Ticket6847";
-            if (exec) Ticket6847();  break;
-        case 5: name = "Ticket10562";
-            if (exec) Ticket10562();  break;
-        case 6: name = "Ticket10983";
-            if (exec) Ticket10983();  break;
-        case 7: name = "Ticket12130";
-            if (exec) Ticket12130(); break;
-        case 8: name = "Ticket12888";
-            if (exec) Ticket12888(); break;
-        default: name = "";          break;
-    }
+    TESTCASE_AUTO_BEGIN;
+    TESTCASE_AUTO(TextTest);
+    TESTCASE_AUTO(ErrorTest);
+    TESTCASE_AUTO(FreezeTest);
+    TESTCASE_AUTO(Ticket5560);
+    TESTCASE_AUTO(Ticket6847);
+    TESTCASE_AUTO(Ticket10562);
+    TESTCASE_AUTO(Ticket10983);
+    TESTCASE_AUTO(Ticket12130);
+    TESTCASE_AUTO(Ticket12888);
+    TESTCASE_AUTO(Ticket13344);
+    TESTCASE_AUTO_END;
 }
 
 //
@@ -1645,3 +1636,28 @@ void UTextTest::Ticket12888() {
         prevIndex = currentIndex;
     }
 }
+
+// Ticket 13344 The macro form of UTEXT_SETNATIVEINDEX failed when target was a trail surrogate
+//              of a supplementary character.
+
+void UTextTest::Ticket13344() {
+    UErrorCode status = U_ZERO_ERROR;
+    const char16_t *str = u"abc\U0010abcd xyz";
+    LocalUTextPointer ut(utext_openUChars(NULL, str, -1, &status));
+
+    assertSuccess("UTextTest::Ticket13344-status", status);
+    UTEXT_SETNATIVEINDEX(ut.getAlias(), 3);
+    assertEquals("UTextTest::Ticket13344-lead", (int64_t)3, utext_getNativeIndex(ut.getAlias()));
+    UTEXT_SETNATIVEINDEX(ut.getAlias(), 4);
+    assertEquals("UTextTest::Ticket13344-trail", (int64_t)3, utext_getNativeIndex(ut.getAlias()));
+    UTEXT_SETNATIVEINDEX(ut.getAlias(), 5);
+    assertEquals("UTextTest::Ticket13344-bmp", (int64_t)5, utext_getNativeIndex(ut.getAlias()));
+
+    utext_setNativeIndex(ut.getAlias(), 3);
+    assertEquals("UTextTest::Ticket13344-lead-2", (int64_t)3, utext_getNativeIndex(ut.getAlias()));
+    utext_setNativeIndex(ut.getAlias(), 4);
+    assertEquals("UTextTest::Ticket13344-trail-2", (int64_t)3, utext_getNativeIndex(ut.getAlias()));
+    utext_setNativeIndex(ut.getAlias(), 5);
+    assertEquals("UTextTest::Ticket13344-bmp-2", (int64_t)5, utext_getNativeIndex(ut.getAlias()));
+}
+
index 26bb93cbd14c1f80ac3c9f7cfcc52523f30d69ac..c0b3145351c24e2abaa99be4639a65abbc4b351b 100644 (file)
@@ -39,6 +39,7 @@ public:
     void Ticket10983();
     void Ticket12130();
     void Ticket12888();
+    void Ticket13344();
 
 private:
     struct m {                              // Map between native indices & code points.