]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/cintltst/callcoll.c
ICU-66108.tar.gz
[apple/icu.git] / icuSources / test / cintltst / callcoll.c
index 4bf383feef5d16986e9e445899f99a6179c76921..3df50f7415468c79bcefe9993b96c0063cc4a35d 100644 (file)
@@ -1,6 +1,8 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2008, International Business Machines Corporation and
+ * Copyright (c) 1997-2014, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /*******************************************************************************
@@ -52,7 +54,6 @@
 #include "calldata.h"
 #include "cstring.h"
 #include "cmemory.h"
-#include "ucol_imp.h"
 
 /* set to 1 to test offsets in backAndForth() */
 #define TEST_OFFSETS 0
@@ -92,6 +93,8 @@ static void TestFCDCrash(void);
 
 static void TestJ5298(void);
 
+static void TestBadKey(void);
+
 const UCollationResult results[] = {
     UCOL_LESS,
     UCOL_LESS, /*UCOL_GREATER,*/
@@ -148,13 +151,14 @@ static char* U_EXPORT2 sortKeyToString(const UCollator *coll, const uint8_t *sor
     int32_t strength = UCOL_PRIMARY;
     uint32_t res_size = 0;
     UBool doneCase = FALSE;
+    UErrorCode errorCode = U_ZERO_ERROR;
 
     char *current = buffer;
     const uint8_t *currentSk = sortkey;
 
     uprv_strcpy(current, "[");
 
-    while(strength <= UCOL_QUATERNARY && strength <= coll->strength) {
+    while(strength <= UCOL_QUATERNARY && strength <= ucol_getStrength(coll)) {
         if(strength > UCOL_PRIMARY) {
             uprv_strcat(current, " . ");
         }
@@ -162,20 +166,20 @@ static char* U_EXPORT2 sortKeyToString(const UCollator *coll, const uint8_t *sor
             uprv_appendByteToHexString(current, *currentSk++);
             uprv_strcat(current, " ");
         }
-        if(coll->caseLevel == UCOL_ON && strength == UCOL_SECONDARY && doneCase == FALSE) {
+        if(ucol_getAttribute(coll, UCOL_CASE_LEVEL, &errorCode) == UCOL_ON && strength == UCOL_SECONDARY && doneCase == FALSE) {
             doneCase = TRUE;
-        } else if(coll->caseLevel == UCOL_OFF || doneCase == TRUE || strength != UCOL_SECONDARY) {
+        } else if(ucol_getAttribute(coll, UCOL_CASE_LEVEL, &errorCode) == UCOL_OFF || doneCase == TRUE || strength != UCOL_SECONDARY) {
             strength ++;
         }
         if (*currentSk) {
             uprv_appendByteToHexString(current, *currentSk++); /* This should print '01' */
         }
-        if(strength == UCOL_QUATERNARY && coll->alternateHandling == UCOL_NON_IGNORABLE) {
+        if(strength == UCOL_QUATERNARY && ucol_getAttribute(coll, UCOL_ALTERNATE_HANDLING, &errorCode) == UCOL_NON_IGNORABLE) {
             break;
         }
     }
 
-    if(coll->strength == UCOL_IDENTICAL) {
+    if(ucol_getStrength(coll) == UCOL_IDENTICAL) {
         uprv_strcat(current, " . ");
         while(*currentSk != 0) {
             uprv_appendByteToHexString(current, *currentSk++);
@@ -208,13 +212,14 @@ void addAllCollTest(TestNode** root)
     addTest(root, &TestJitterbug1098, "tscoll/callcoll/TestJitterbug1098");
     addTest(root, &TestFCDCrash, "tscoll/callcoll/TestFCDCrash");
     addTest(root, &TestJ5298, "tscoll/callcoll/TestJ5298");
+    addTest(root, &TestBadKey, "tscoll/callcoll/TestBadKey");
 }
 
 UBool hasCollationElements(const char *locName) {
 
   UErrorCode status = U_ZERO_ERROR;
 
-  UResourceBundle *loc = ures_open(U_ICUDATA_COLL, locName, &status);;
+  UResourceBundle *loc = ures_open(U_ICUDATA_NAME U_TREE_SEPARATOR_STRING "coll", locName, &status);
 
   if(U_SUCCESS(status)) {
     status = U_ZERO_ERROR;
@@ -279,49 +284,84 @@ static void doTestVariant(UCollator* myCollation, const UChar source[], const UC
     UColAttributeValue norm = ucol_getAttribute(myCollation, UCOL_NORMALIZATION_MODE, &status);
 
     UCharIterator sIter, tIter;
+
+    compareResult  = ucol_strcoll(myCollation, source, sLen, target, tLen);
+    if (compareResult != result) {
+        log_err("ucol_strcoll with explicit length returned wrong result (%i exp. %i): %s, %s\n",
+            compareResult, result, aescstrdup(source,-1), aescstrdup(target,-1));
+    }
+    compareResulta = ucol_strcoll(myCollation, source, -1,   target, -1); 
+    if (compareResulta != result) {
+        log_err("ucol_strcoll with null terminated strings returned wrong result (%i exp. %i): %s, %s\n",
+            compareResult, result, aescstrdup(source,-1), aescstrdup(target,-1));
+    }
+
     uiter_setString(&sIter, source, sLen);
     uiter_setString(&tIter, target, tLen);
     compareResultIter = ucol_strcollIter(myCollation, &sIter, &tIter, &status);
     if(compareResultIter != result) {
-      log_err("different results in iterative comparison for UTF-16 encoded strings. %s, %s\n", aescstrdup(source,-1), aescstrdup(target,-1));
+        log_err("different results in iterative comparison for UTF-16 encoded strings. %s, %s\n", aescstrdup(source,-1), aescstrdup(target,-1));
     }
 
-    /* convert the strings to UTF-8 and do try comparing with char iterator */
-    if(QUICK <= 0) { /*!QUICK*/
-      char utf8Source[256], utf8Target[256];
-      int32_t utf8SourceLen = 0, utf8TargetLen = 0;
-      u_strToUTF8(utf8Source, 256, &utf8SourceLen, source, sLen, &status);
-      if(U_FAILURE(status)) { /* probably buffer is not big enough */
-        log_verbose("Src UTF-8 buffer too small! Will not compare!\n");
-      } else {
-        u_strToUTF8(utf8Target, 256, &utf8TargetLen, target, tLen, &status);
-        if(U_SUCCESS(status)) { /* probably buffer is not big enough */
-          UCollationResult compareResultUTF8 = result, compareResultUTF8Norm = result;
-          /*UCharIterator sIter, tIter;*/
-          /*log_verbose("Strings converted to UTF-8:%s, %s\n", aescstrdup(source,-1), aescstrdup(target,-1));*/
-          uiter_setUTF8(&sIter, utf8Source, utf8SourceLen);
-          uiter_setUTF8(&tIter, utf8Target, utf8TargetLen);
-       /*uiter_setString(&sIter, source, sLen);
-      uiter_setString(&tIter, target, tLen);*/
-          compareResultUTF8 = ucol_strcollIter(myCollation, &sIter, &tIter, &status);
-          ucol_setAttribute(myCollation, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
-          sIter.move(&sIter, 0, UITER_START);
-          tIter.move(&tIter, 0, UITER_START);
-          compareResultUTF8Norm = ucol_strcollIter(myCollation, &sIter, &tIter, &status);
-          ucol_setAttribute(myCollation, UCOL_NORMALIZATION_MODE, norm, &status);
-          if(compareResultUTF8 != compareResultIter) {
-            log_err("different results in iterative comparison for UTF-16 and UTF-8 encoded strings. %s, %s\n", aescstrdup(source,-1), aescstrdup(target,-1));
-          }
-          if(compareResultUTF8 != compareResultUTF8Norm) {
-            log_err("different results in iterative when normalization is turned on with UTF-8 strings. %s, %s\n", aescstrdup(source,-1), aescstrdup(target,-1));
-          }
+    /* convert the strings to UTF-8 and do try comparing with char iterator and ucol_strcollUTF8 */
+    {
+        char utf8Source[256], utf8Target[256];
+        int32_t utf8SourceLen = 0, utf8TargetLen = 0;
+
+        u_strToUTF8(utf8Source, 256, &utf8SourceLen, source, sLen, &status);
+        if(U_FAILURE(status)) { /* probably buffer is not big enough */
+            log_verbose("Src UTF-8 buffer too small! Will not compare!\n");
         } else {
-          log_verbose("Target UTF-8 buffer too small! Did not compare!\n");
-        }
-        if(U_FAILURE(status)) {
-          log_verbose("UTF-8 strcoll failed! Ignoring result\n");
+            u_strToUTF8(utf8Target, 256, &utf8TargetLen, target, tLen, &status);
+            if(U_SUCCESS(status)) {
+                {
+                    /* ucol_strcollUTF8 */
+                    compareResulta = ucol_strcollUTF8(myCollation, utf8Source, utf8SourceLen, utf8Target, utf8TargetLen, &status);
+                    if (U_FAILURE(status)) {
+                        log_err("Error in ucol_strcollUTF8 with explicit length\n");
+                        status = U_ZERO_ERROR;
+                    } else if (compareResulta != result) {
+                        log_err("ucol_strcollUTF8 with explicit length returned wrong result (%i exp. %i): %s, %s\n",
+                            compareResulta, result, aescstrdup(source,-1), aescstrdup(target,-1));
+                    }
+                    compareResulta = ucol_strcollUTF8(myCollation, utf8Source, -1, utf8Target, -1, &status);
+                    if (U_FAILURE(status)) {
+                        log_err("Error in ucol_strcollUTF8 with null terminated strings\n");
+                        status = U_ZERO_ERROR;
+                    } else if (compareResulta != result) {
+                        log_err("ucol_strcollUTF8 with null terminated strings returned wrong result (%i exp. %i): %s, %s\n",
+                            compareResulta, result, aescstrdup(source,-1), aescstrdup(target,-1));
+                    }
+                }
+
+                {
+                    /* char iterator over UTF8 */
+                    UCollationResult compareResultUTF8Iter = result, compareResultUTF8IterNorm = result;
+
+                    uiter_setUTF8(&sIter, utf8Source, utf8SourceLen);
+                    uiter_setUTF8(&tIter, utf8Target, utf8TargetLen);
+                    compareResultUTF8Iter = ucol_strcollIter(myCollation, &sIter, &tIter, &status);
+
+                    ucol_setAttribute(myCollation, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
+                    sIter.move(&sIter, 0, UITER_START);
+                    tIter.move(&tIter, 0, UITER_START);
+                    compareResultUTF8IterNorm = ucol_strcollIter(myCollation, &sIter, &tIter, &status);
+
+                    ucol_setAttribute(myCollation, UCOL_NORMALIZATION_MODE, norm, &status);
+                    if(compareResultUTF8Iter != compareResultIter) {
+                        log_err("different results in iterative comparison for UTF-16 and UTF-8 encoded strings. %s, %s\n", aescstrdup(source,-1), aescstrdup(target,-1));
+                    }
+                    if(compareResultUTF8Iter != compareResultUTF8IterNorm) {
+                        log_err("different results in iterative when normalization is turned on with UTF-8 strings. %s, %s\n", aescstrdup(source,-1), aescstrdup(target,-1));
+                    }
+                }
+            } else {
+                log_verbose("Target UTF-8 buffer too small! Did not compare!\n");
+            }
+            if(U_FAILURE(status)) {
+                log_verbose("UTF-8 strcoll failed! Ignoring result\n");
+            }
         }
-      }
     }
 
     /* testing the partial sortkeys */
@@ -329,7 +369,7 @@ static void doTestVariant(UCollator* myCollation, const UChar source[], const UC
       int32_t i = 0;
       int32_t partialSizes[] = { 3, 1, 2, 4, 8, 20, 80 }; /* just size 3 in the quick mode */
       int32_t partialSizesSize = 1;
-      if(QUICK <= 0) {
+      if(getTestOption(QUICK_OPTION) <= 0) {
         partialSizesSize = 7;
       }
       /*log_verbose("partial sortkey test piecesize=");*/
@@ -344,7 +384,7 @@ static void doTestVariant(UCollator* myCollation, const UChar source[], const UC
             aescstrdup(source,-1), aescstrdup(target,-1), partialSizes[i]);
         }
 
-        if(QUICK <= 0 && norm != UCOL_ON) {
+        if(getTestOption(QUICK_OPTION) <= 0 && norm != UCOL_ON) {
           /*log_verbose("N ");*/
           ucol_setAttribute(myCollation, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
           partialNormalizedSKResult = compareUsingPartials(myCollation, source, sLen, target, tLen, partialSizes[i], &status);
@@ -358,18 +398,12 @@ static void doTestVariant(UCollator* myCollation, const UChar source[], const UC
       /*log_verbose("\n");*/
     }
 
-    
-    compareResult  = ucol_strcoll(myCollation, source, sLen, target, tLen);
-    compareResulta = ucol_strcoll(myCollation, source, -1,   target, -1); 
-    if (compareResult != compareResulta) {
-        log_err("ucol_strcoll result from null terminated and explicit length strings differs.\n");
-    }
-
     sortklen1=ucol_getSortKey(myCollation, source, sLen,  NULL, 0);
     sortklen2=ucol_getSortKey(myCollation, target, tLen,  NULL, 0);
 
     sortklenmax = (sortklen1>sortklen2?sortklen1:sortklen2);
     sortklenmin = (sortklen1<sortklen2?sortklen1:sortklen2);
+    (void)sortklenmin;  /* Suppress set but not used warning. */
 
     sortKey1 =(uint8_t*)malloc(sizeof(uint8_t) * (sortklenmax+1));
     sortKey1a=(uint8_t*)malloc(sizeof(uint8_t) * (sortklenmax+1));
@@ -382,7 +416,7 @@ static void doTestVariant(UCollator* myCollation, const UChar source[], const UC
     ucol_getSortKey(myCollation, target, -1,   sortKey2a, sortklen2+1);
 
     /* Check that sort key generated with null terminated string is identical  */
-    /*  to that generted with a length specified.                              */
+    /*  to that generated with a length specified.                              */
     if (uprv_strcmp((const char *)sortKey1, (const char *)sortKey1a) != 0 ||
         uprv_strcmp((const char *)sortKey2, (const char *)sortKey2a) != 0 ) {
         log_err("Sort Keys from null terminated and explicit length strings differ.\n");
@@ -390,8 +424,8 @@ static void doTestVariant(UCollator* myCollation, const UChar source[], const UC
 
     /*memcmp(sortKey1, sortKey2,sortklenmax);*/
     temp= uprv_strcmp((const char *)sortKey1, (const char *)sortKey2);
-    gSortklen1 = uprv_strlen((const char *)sortKey1)+1;
-    gSortklen2 = uprv_strlen((const char *)sortKey2)+1;
+    gSortklen1 = (int)uprv_strlen((const char *)sortKey1)+1;
+    gSortklen2 = (int)uprv_strlen((const char *)sortKey2)+1;
     if(sortklen1 != gSortklen1){
         log_err("SortKey length does not match Expected: %i Got: %i\n",sortklen1, gSortklen1);
         log_verbose("Generated sortkey: %s\n", sortKeyToString(myCollation, sortKey1, buffer, &len));
@@ -491,53 +525,56 @@ void
 backAndForth(UCollationElements *iter)
 {
     /* Run through the iterator forwards and stick it into an array */
-    int32_t index, o;
+    int32_t idx, o;
     UErrorCode status = U_ZERO_ERROR;
     int32_t orderLength = 0;
     OrderAndOffset *orders = getOrders(iter, &orderLength);
 
 
     /* Now go through it backwards and make sure we get the same values */
-    index = orderLength;
+    idx = orderLength;
     ucol_reset(iter);
 
     /* synwee : changed */
     while ((o = ucol_previous(iter, &status)) != UCOL_NULLORDER) {
-      int32_t offset = ucol_getOffset(iter);
+#if TEST_OFFSETS
+      int32_t offset = 
+#endif
+        ucol_getOffset(iter);
 
-      index -= 1;
-      if (o != orders[index].order) {
+      idx -= 1;
+      if (o != orders[idx].order) {
         if (o == 0)
-          index ++;
+          idx ++;
         else {
-          while (index > 0 && orders[-- index].order == 0) {
+          while (idx > 0 && orders[-- idx].order == 0) {
             /* nothing... */
           }
 
-          if (o != orders[index].order) {
-              log_err("Mismatched order at index %d: 0x%0:8X vs. 0x%0:8X\n", index,
-                orders[index].order, o);
+          if (o != orders[idx].order) {
+              log_err("Mismatched order at index %d: 0x%8.8X vs. 0x%8.8X\n", idx,
+                orders[idx].order, o);
             goto bail;
           }
         }
       }
 
 #if TEST_OFFSETS
-      if (offset != orders[index].offset) {
-        log_err("Mismatched offset at index %d: %d vs. %d\n", index,
-            orders[index].offset, offset);
+      if (offset != orders[idx].offset) {
+        log_err("Mismatched offset at index %d: %d vs. %d\n", idx,
+            orders[idx].offset, offset);
         goto bail;
       }
 #endif
 
     }
 
-    while (index != 0 && orders[index - 1].order == 0) {
-      index -= 1;
+    while (idx != 0 && orders[idx - 1].order == 0) {
+      idx -= 1;
     }
 
-    if (index != 0) {
-        log_err("Didn't get back to beginning - index is %d\n", index);
+    if (idx != 0) {
+        log_err("Didn't get back to beginning - index is %d\n", idx);
 
         ucol_reset(iter);
         log_err("\nnext: ");
@@ -647,7 +684,7 @@ void genericRulesStarterWithOptionsAndResult(const char *rules, const char * con
 
     genericOrderingTestWithResult(coll, s, size, result);
   } else {
-    log_err("Unable to open collator with rules %s\n", rules);
+    log_err_status(status, "Unable to open collator with rules %s\n", rules);
   }
   ucol_close(coll);
 }
@@ -669,7 +706,7 @@ void genericLocaleStarterWithOptionsAndResult(const char *locale, const char * c
 
     genericOrderingTestWithResult(coll, s, size, result);
   } else {
-    log_err("Unable to open collator for locale %s\n", locale);
+    log_err_status(status, "Unable to open collator for locale %s\n", locale);
   }
   ucol_close(coll);
 }
@@ -708,12 +745,12 @@ static void TestTertiary()
     UErrorCode status=U_ZERO_ERROR;
     static const char str[]="& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 ";
     UChar rules[sizeof(str)];
-    len = strlen(str);
+    len = (int32_t)strlen(str);
     u_uastrcpy(rules, str);
 
     myCollation=ucol_openRules(rules, len, UCOL_OFF, UCOL_DEFAULT_STRENGTH, NULL, &status);
     if(U_FAILURE(status)){
-        log_err("ERROR: in creation of rule based collator :%s\n", myErrorName(status));
+        log_err_status(status, "ERROR: in creation of rule based collator :%s\n", myErrorName(status));
         return;
     }
    
@@ -733,12 +770,12 @@ static void TestPrimary( )
     UErrorCode status=U_ZERO_ERROR;
     static const char str[]="& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 ";   
     UChar rules[sizeof(str)];
-    len = strlen(str);
+    len = (int32_t)strlen(str);
     u_uastrcpy(rules, str);
 
     myCollation=ucol_openRules(rules, len, UCOL_OFF, UCOL_DEFAULT_STRENGTH,NULL, &status);
     if(U_FAILURE(status)){
-        log_err("ERROR: in creation of rule based collator :%s\n", myErrorName(status));
+        log_err_status(status, "ERROR: in creation of rule based collator :%s\n", myErrorName(status));
         return;
     }
     ucol_setStrength(myCollation, UCOL_PRIMARY);
@@ -760,12 +797,12 @@ static void TestSecondary()
     UErrorCode status=U_ZERO_ERROR;
     static const char str[]="& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 ";
     UChar rules[sizeof(str)];
-    len = strlen(str);
+    len = (int32_t)strlen(str);
     u_uastrcpy(rules, str);
 
     myCollation=ucol_openRules(rules, len, UCOL_OFF, UCOL_DEFAULT_STRENGTH,NULL, &status);
     if(U_FAILURE(status)){
-        log_err("ERROR: in creation of rule based collator :%s\n", myErrorName(status));
+        log_err_status(status, "ERROR: in creation of rule based collator :%s\n", myErrorName(status));
         return;
     }
     ucol_setStrength(myCollation, UCOL_SECONDARY);
@@ -785,12 +822,12 @@ static void TestIdentical()
     UErrorCode status=U_ZERO_ERROR;
     static const char str[]="& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 ";
     UChar rules[sizeof(str)];
-    len = strlen(str);
+    len = (int32_t)strlen(str);
     u_uastrcpy(rules, str);
 
     myCollation=ucol_openRules(rules, len, UCOL_OFF, UCOL_IDENTICAL, NULL,&status);
     if(U_FAILURE(status)){
-        log_err("ERROR: in creation of rule based collator :%s\n", myErrorName(status));
+        log_err_status(status, "ERROR: in creation of rule based collator :%s\n", myErrorName(status));
         return;
     }
     for(i= 34; i<37; i++)
@@ -809,12 +846,12 @@ static void TestExtra()
     UErrorCode status = U_ZERO_ERROR;
     static const char str[]="& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 ";
     UChar rules[sizeof(str)];
-    len = strlen(str);
+    len = (int32_t)strlen(str);
     u_uastrcpy(rules, str);
 
     myCollation=ucol_openRules(rules, len, UCOL_OFF, UCOL_DEFAULT_STRENGTH,NULL, &status);
     if(U_FAILURE(status)){
-        log_err("ERROR: in creation of rule based collator :%s\n", myErrorName(status));
+        log_err_status(status, "ERROR: in creation of rule based collator :%s\n", myErrorName(status));
         return;
     }
     ucol_setStrength(myCollation, UCOL_TERTIARY);
@@ -850,7 +887,7 @@ static void TestJB581(void)
 
     myCollator = ucol_open("en_US", &status);
     if (U_FAILURE(status)){
-        log_err("ERROR: Failed to create the collator : %s\n", u_errorName(status));
+        log_err_status(status, "ERROR: Failed to create the collator : %s\n", u_errorName(status));
         return;
     }
     result = ucol_strcoll(myCollator, source, -1, target, -1);
@@ -869,6 +906,7 @@ static void TestJB581(void)
     }
     /* Now, do the same comparison with keys */
     sourceKeyOut = ucol_getSortKey(myCollator, source, -1, sourceKeyArray, 100);
+    (void)sourceKeyOut;    /* Suppress set but not used warning. */
     targetKeyOut = ucol_getSortKey(myCollator, target, -1, targetKeyArray, 100);
     bufferLen = ((targetKeyOut > 100) ? 100 : targetKeyOut);
     if (memcmp(sourceKeyArray, targetKeyArray, bufferLen) != 0)
@@ -893,7 +931,7 @@ static void TestJB1401(void)
     
     myCollator = ucol_open("en_US", &status);
     if (U_FAILURE(status)){
-        log_err("ERROR: Failed to create the collator : %s\n", u_errorName(status));
+        log_err_status(status, "ERROR: Failed to create the collator : %s\n", u_errorName(status));
         return;
     }
     ucol_setAttribute(myCollator, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
@@ -979,6 +1017,13 @@ static void TestJB1401(void)
 */
 static void TestVariableTop(void)
 {
+#if 0
+    /*
+     * Starting with ICU 53, setting the variable top via a pseudo relation string
+     * is not supported any more.
+     * It was replaced by the [maxVariable symbol] setting.
+     * See ICU tickets #9958 and #8032.
+     */
     static const char       str[]          = "&z = [variable top]";
           int         len          = strlen(str);
           UChar      rules[sizeof(str)];
@@ -994,7 +1039,7 @@ static void TestVariableTop(void)
 
     enCollation = ucol_open("en_US", &status);
     if (U_FAILURE(status)) {
-        log_err("ERROR: in creation of collator :%s\n", 
+        log_err_status(status, "ERROR: in creation of collator :%s\n", 
                 myErrorName(status));
         return;
     }
@@ -1045,6 +1090,7 @@ static void TestVariableTop(void)
     ucol_close(myCollation);
     enCollation = NULL;
     myCollation = NULL;
+#endif
 }
 
 /**
@@ -1056,7 +1102,7 @@ static void TestSurrogates(void)
 {
     static const char       str[]          = 
                               "&z<'\\uD800\\uDC00'<'\\uD800\\uDC0A\\u0308'<A";
-          int         len          = strlen(str);
+          int         len          = (int)strlen(str);
           int         rlen         = 0;
           UChar      rules[sizeof(str)];
           UCollator  *myCollation;
@@ -1075,7 +1121,7 @@ static void TestSurrogates(void)
     
     enCollation = ucol_open("en_US", &status);
     if (U_FAILURE(status)) {
-        log_err("ERROR: in creation of collator :%s\n", 
+        log_err_status(status, "ERROR: in creation of collator :%s\n", 
                 myErrorName(status));
         return;
     }
@@ -1134,13 +1180,13 @@ TestInvalidRules(){
         "& C < ch, cH, & Ch[variable top]"
     };
     static const char* preContextArr[MAX_ERROR_STATES] = {
-        "his should fail",
-        "& C < ch, cH",
+        " C < ch, cH, Ch",
+        "& C < ch, cH",
 
     };
     static const char* postContextArr[MAX_ERROR_STATES] = {
-        "<d",
-        " Ch[variable t"
+        "[this should fa",
+        ", & Ch[variable"
     };
     int i;
 
@@ -1151,19 +1197,22 @@ TestInvalidRules(){
         UParseError parseError;
         UErrorCode status = U_ZERO_ERROR;
         UCollator* coll=0;
-        u_charsToUChars(rulesArr[i],rules,uprv_strlen(rulesArr[i])+1);
-        u_charsToUChars(preContextArr[i],preContextExp,uprv_strlen(preContextArr[i])+1);
-        u_charsToUChars(postContextArr[i],postContextExp,uprv_strlen(postContextArr[i])+1);
+        u_charsToUChars(rulesArr[i], rules, (int32_t)uprv_strlen(rulesArr[i]) + 1);
+        u_charsToUChars(preContextArr[i], preContextExp, (int32_t)uprv_strlen(preContextArr[i]) + 1);
+        u_charsToUChars(postContextArr[i], postContextExp, (int32_t)uprv_strlen(postContextArr[i]) + 1);
         /* clean up stuff in parseError */
-        u_memset(parseError.preContext,0x0000,U_PARSE_CONTEXT_LEN);      
-        u_memset(parseError.postContext,0x0000,U_PARSE_CONTEXT_LEN);
+        u_memset(parseError.preContext, 0x0000, U_PARSE_CONTEXT_LEN);
+        u_memset(parseError.postContext, 0x0000, U_PARSE_CONTEXT_LEN);
         /* open the rules and test */
-        coll = ucol_openRules(rules,u_strlen(rules),UCOL_OFF,UCOL_DEFAULT_STRENGTH,&parseError,&status);
+        coll = ucol_openRules(rules, u_strlen(rules), UCOL_OFF, UCOL_DEFAULT_STRENGTH, &parseError, &status);
+        (void)coll;   /* Suppress set but not used warning. */
         if(u_strcmp(parseError.preContext,preContextExp)!=0){
-            log_err("preContext in UParseError for ucol_openRules does not match\n");
+            log_err_status(status, "preContext in UParseError for ucol_openRules does not match: \"%s\"\n",
+                           aescstrdup(parseError.preContext, -1));
         }
         if(u_strcmp(parseError.postContext,postContextExp)!=0){
-            log_err("postContext in UParseError for ucol_openRules does not match\n");
+            log_err_status(status, "postContext in UParseError for ucol_openRules does not match: \"%s\"\n",
+                           aescstrdup(parseError.postContext, -1));
         }
     }  
 }
@@ -1182,7 +1231,7 @@ TestJitterbug1098(){
          "&\\'<\\\\",
          "&\\\"<'\\'",
          "&'\"'<\\'",
-         '\0'
+         NULL
 
     };
     const UCollationResult results1098[] = {
@@ -1205,7 +1254,7 @@ TestJitterbug1098(){
         u_uastrcpy(rule, rules[i]);
         c1 = ucol_openRules(rule, u_strlen(rule), UCOL_OFF, UCOL_DEFAULT_STRENGTH, &parseError, &status);
         if(U_FAILURE(status)){
-            log_err("Could not parse the rules syntax. Error: %s\n", u_errorName(status));
+            log_err_status(status, "Could not parse the rules syntax. Error: %s\n", u_errorName(status));
 
             if (status == U_PARSE_ERROR) {
                 u_UCharsToChars(parseError.preContext,preContext,20);
@@ -1232,7 +1281,7 @@ TestFCDCrash(void) {
     UErrorCode status = U_ZERO_ERROR;
     UCollator *coll = ucol_open("es", &status);
     if(U_FAILURE(status)) {
-        log_err("Couldn't open collator\n");
+        log_err_status(status, "Couldn't open collator -> %s\n", u_errorName(status));
         return;
     }
     ucol_close(coll);
@@ -1240,7 +1289,7 @@ TestFCDCrash(void) {
     ctest_resetICU();
     coll = ucol_open("de_DE", &status);
     if(U_FAILURE(status)) {
-        log_err("Couldn't open collator\n");
+        log_err_status(status, "Couldn't open collator -> %s\n", u_errorName(status));
         return;
     }
     ucol_setAttribute(coll, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
@@ -1274,6 +1323,11 @@ static void TestJ5298(void)
     const char *keywordValue = NULL;
     log_verbose("Number of collator locales returned : %i \n", ucol_countAvailable());
     values = ucol_getKeywordValues("collation", &status);
+    while ((keywordValue = uenum_next(values, NULL, &status)) != NULL) {
+        if (strncmp(keywordValue, "private-", 8) == 0) {
+            log_err("ucol_getKeywordValues() returns private collation keyword: %s\n", keywordValue);
+        }
+    }
     for (i = 0; i < ucol_countAvailable(); i++) {
         uenum_reset(values, &status);
         while ((keywordValue = uenum_next(values, NULL, &status)) != NULL) {
@@ -1292,5 +1346,38 @@ static void TestJ5298(void)
     uenum_close(values);
     log_verbose("\n");
 }
-#endif /* #if !UCONFIG_NO_COLLATION */
 
+static const char* badKeyLocales[] = {
+       "@calendar=japanese;collation=search", // ucol_open OK
+       "@calendar=japanese", // ucol_open OK
+       "en@calendar=x", // ucol_open OK
+       "ja@calendar=x", // ucol_open OK
+       "en@collation=x", // ucol_open OK
+       "ja@collation=x", // ucol_open OK
+       "en@calendar=\x81", // ucol_open OK
+       "ja@collation=private-kana", // ucol_open fails, verify it does not crash
+       "en@collation=\x80", // (x80 undef in ASCII,EBCDIC) ucol_open fails, verify it does not crash
+       "ja@calendar=japanese;collation=\x81", // ucol_open fails, verify it does not crash
+       NULL
+};
+
+// Mainly this is to check that we don't have a crash, but we check
+// for correct NULL return and FAILURE/SUCCESS status as a bonus.
+static void TestBadKey(void)
+{
+    const char* badLoc;
+    const char** badLocsPtr = badKeyLocales;
+    while ((badLoc = *badLocsPtr++) != NULL) {
+        UErrorCode status = U_ZERO_ERROR;
+        UCollator* uc = ucol_open(badLoc, &status);
+        if ( U_SUCCESS(status) ) {
+            if (uc == NULL) {
+                log_err("ucol_open sets SUCCESS but returns NULL, locale: %s\n", badLoc);
+            }
+            ucol_close(uc);
+        } else if (uc != NULL) {
+            log_err("ucol_open sets FAILURE but returns non-NULL, locale: %s\n", badLoc);
+        }
+    }
+}
+#endif /* #if !UCONFIG_NO_COLLATION */