]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/cintltst/utexttst.c
ICU-57163.0.1.tar.gz
[apple/icu.git] / icuSources / test / cintltst / utexttst.c
index be5941df40316b7e731c0d083ae706ee4441d1e5..bc715134fba040aba747acab36a2dd623a9b65ae 100644 (file)
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 2005-2006, International Business Machines Corporation and
+ * Copyright (c) 2005-2013, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /*
@@ -58,6 +58,7 @@ addUTextTest(TestNode** root)
 static void TestAPI(void) {
     UErrorCode      status = U_ZERO_ERROR;
     UBool           gFailed = FALSE;
+    (void)gFailed;   /* Suppress set but not used warning. */
 
     /* Open    */
     {
@@ -180,6 +181,28 @@ static void TestAPI(void) {
         utext_close(uta);
     }
 
+    {
+        /*
+         * UText opened on a NULL string with zero length
+         */
+        UText    *uta;
+        UChar32   c;
+
+        status = U_ZERO_ERROR;
+        uta = utext_openUChars(NULL, NULL, 0, &status);
+        TEST_SUCCESS(status);
+        c = UTEXT_NEXT32(uta);
+        TEST_ASSERT(c == U_SENTINEL);
+        utext_close(uta);
+
+        uta = utext_openUTF8(NULL, NULL, 0, &status);
+        TEST_SUCCESS(status);
+        c = UTEXT_NEXT32(uta);
+        TEST_ASSERT(c == U_SENTINEL);
+        utext_close(uta);
+    }
+
+
     {
         /*
          * extract
@@ -188,6 +211,10 @@ static void TestAPI(void) {
         UChar     uString[]  = {0x41, 0x42, 0x43, 0};
         UChar     buf[100];
         int32_t   i;
+        /* Test pinning of input bounds */
+        UChar     uString2[]  = {0x41, 0x42, 0x43, 0x44, 0x45,
+                                 0x46, 0x47, 0x48, 0x49, 0x4A, 0};
+        UChar *   uString2Ptr = uString2 + 5;
 
         status = U_ZERO_ERROR;
         uta = utext_openUChars(NULL, uString, -1, &status);
@@ -206,6 +233,20 @@ static void TestAPI(void) {
         i = u_strcmp(uString, buf);
         TEST_ASSERT(i == 0);
         utext_close(uta);
+
+        /* Test pinning of input bounds */
+        status = U_ZERO_ERROR;
+        uta = utext_openUChars(NULL, uString2Ptr, -1, &status);
+        TEST_SUCCESS(status);
+
+        status = U_ZERO_ERROR;
+        memset(buf, 0, sizeof(buf));
+        i = utext_extract(uta, -3, 20, buf, 100, &status);
+        TEST_SUCCESS(status);
+        TEST_ASSERT(i == u_strlen(uString2Ptr));
+        i = u_strcmp(uString2Ptr, buf);
+        TEST_ASSERT(i == 0);
+        utext_close(uta);
     }
 
     {