Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / icu / source / test / cintltst / citertst.c
index df66e4f..e8e2cff 100644 (file)
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT:
- * Copyright (c) 1997-2011, International Business Machines Corporation and
+ * Copyright (c) 1997-2013, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /********************************************************************************
@@ -862,6 +862,7 @@ static void TestMaxExpansion()
       }
 
       U16_APPEND(supplementary, stringOffset, 2, unassigned, isError);
+      (void)isError;    /* Suppress set but not used warning. */
       ucol_setText(iter, supplementary, 2, &status);
       sorder = ucol_previous(iter, &status);
 
@@ -1686,6 +1687,8 @@ static UBool checkCEValidity(const UCollator *coll, const UChar *codepoints,
     return result;
 }
 
+static const UChar IMPORT[] = { 0x5B, 0x69, 0x6D, 0x70, 0x6F, 0x72, 0x74, 0 };  /* "[import" */
+
 static void TestCEValidity()
 {
     /* testing UCA collation elements */
@@ -1766,6 +1769,14 @@ static void TestCEValidity()
         UColTokenParser src;
         uint32_t strength = 0;
         uint16_t specs = 0;
+
+        (void)specs;        /* Suppress set but not used warnings. */
+        (void)strength;
+        (void)prefixLen;
+        (void)prefixOffset;
+        (void)exLen;
+        (void)exOffset;
+
         if(getTestOption(QUICK_OPTION)) {
             loc = locale[count];
         } else {
@@ -1775,6 +1786,7 @@ static void TestCEValidity()
                 continue;
             }
         }
+        status = U_ZERO_ERROR; // clear status from previous loop iteration
 
         uprv_memset(&src, 0, sizeof(UColTokenParser));
 
@@ -1782,14 +1794,21 @@ static void TestCEValidity()
 
         coll      = ucol_open(loc, &status);
         if (U_FAILURE(status)) {
-            log_err("%s collator creation failed\n", loc);
+            log_err("%s collator creation failed with status %s\n", loc, u_errorName(status));
             return;
         }
 
         src.opts = &opts;
         rules = ucol_getRules(coll, &ruleLen);
 
-        if (ruleLen > 0) {
+        /*
+         * We have not set up the UColTokenParser with a callback function
+         * to fetch [import] sub-rules,
+         * so skip testing tailorings that import others.
+         * TODO: Ticket #8047: Change TestCEValidity to use ucol_getTailoredSet()
+         *                     rather than the internal collation rule parser
+         */
+        if (ruleLen > 0 && u_strstr(rules, IMPORT) == NULL) {
             rulesCopy = (UChar *)uprv_malloc((ruleLen +
                 UCOL_TOK_EXTRA_RULE_SPACE_SIZE) * sizeof(UChar));
             uprv_memcpy(rulesCopy, rules, ruleLen * sizeof(UChar));
@@ -1800,7 +1819,7 @@ static void TestCEValidity()
 
                /* Note that as a result of tickets 7015 or 6912, ucol_tok_parseNextToken can cause the pointer to
                   the rules copy in src.source to get reallocated, freeing the original pointer in rulesCopy */
-            while ((current = ucol_tok_parseNextToken(&src, startOfRules, &parseError,&status)) != NULL) {
+            while ((current = ucol_tok_parseNextToken(&src, startOfRules, &parseError,&status)) != NULL && U_SUCCESS(status)) {
               strength = src.parsedToken.strength;
               chOffset = src.parsedToken.charsOffset;
               chLen = src.parsedToken.charsLen;
@@ -1816,7 +1835,11 @@ static void TestCEValidity()
                 codepoints[chLen] = 0;
                 checkCEValidity(coll, codepoints, chLen);
             }
+            if (U_FAILURE(status)) {
+                log_err("%s collator, ucol_tok_parseNextToken failed with status %s\n", loc, u_errorName(status));
+            }
             uprv_free(src.source);
+            uprv_free(src.reorderCodes);
         }
 
         ucol_close(coll);
@@ -1967,19 +1990,34 @@ static void TestSortKeyValidity(void)
         UColTokenParser src;
         uint32_t strength = 0;
         uint16_t specs = 0;
+        status = U_ZERO_ERROR; // clear status from previous loop iteration
+
+        (void)specs;
+        (void)strength;
+        (void)prefixLen;
+        (void)prefixOffset;
+        (void)exLen;
+        (void)exOffset;
 
         uprv_memset(&src, 0, sizeof(UColTokenParser));
 
         coll      = ucol_open(locale[count], &status);
         if (U_FAILURE(status)) {
-            log_err("%s collator creation failed\n", locale[count]);
+            log_err("%s collator creation failed with status %s\n", locale[count], u_errorName(status));
             return;
         }
 
         src.opts = &opts;
         rules = ucol_getRules(coll, &ruleLen);
 
-        if (ruleLen > 0) {
+        /*
+         * We have not set up the UColTokenParser with a callback function
+         * to fetch [import] sub-rules,
+         * so skip testing tailorings that import others.
+         * TODO: Ticket #8047: Change TestSortKeyValidity to use ucol_getTailoredSet()
+         *                     rather than the internal collation rule parser
+         */
+        if (ruleLen > 0 && u_strstr(rules, IMPORT) == NULL) {
             rulesCopy = (UChar *)uprv_malloc((ruleLen +
                 UCOL_TOK_EXTRA_RULE_SPACE_SIZE) * sizeof(UChar));
             uprv_memcpy(rulesCopy, rules, ruleLen * sizeof(UChar));
@@ -1990,7 +2028,7 @@ static void TestSortKeyValidity(void)
 
                /* Note that as a result of tickets 7015 or 6912, ucol_tok_parseNextToken can cause the pointer to
                   the rules copy in src.source to get reallocated, freeing the original pointer in rulesCopy */
-            while ((current = ucol_tok_parseNextToken(&src, startOfRules,&parseError, &status)) != NULL) {
+            while ((current = ucol_tok_parseNextToken(&src, startOfRules,&parseError, &status)) != NULL && U_SUCCESS(status)) {
                 strength = src.parsedToken.strength;
                 chOffset = src.parsedToken.charsOffset;
                 chLen = src.parsedToken.charsLen;
@@ -2010,7 +2048,11 @@ static void TestSortKeyValidity(void)
                 }
                 checkSortKeyValidity(coll, codepoints, chLen);
             }
+            if (U_FAILURE(status)) {
+                log_err("%s collator, ucol_tok_parseNextToken failed with status %s\n", locale[count], u_errorName(status));
+            }
             uprv_free(src.source);
+            uprv_free(src.reorderCodes);
         }
 
         ucol_close(coll);
@@ -2151,7 +2193,7 @@ static void TestSearchCollatorElements(void)
             }
             ucol_close(ucol);
         } else {
-            log_err("error, locale %s, ucol_open failed: %s\n", tsceItemPtr->locale, u_errorName(status) );
+            log_data_err("error, locale %s, ucol_open failed: %s\n", tsceItemPtr->locale, u_errorName(status) );
         }
     }
 }