+static void TestDefaultKeyword(void) {
+ /* Tests for code coverage. */
+ UErrorCode status = U_ZERO_ERROR;
+ const char *loc = "zh_TW@collation=default";
+ UCollator *coll = ucol_open(loc, &status);
+ if(U_FAILURE(status)) {
+ log_info("Warning: ucol_open(%s, ...) returned %s, at least it didn't crash.\n", loc, u_errorName(status));
+ } else if (status != U_USING_FALLBACK_WARNING) {
+ /* Hmm, skip the following test for CLDR 1.9 data and/or ICU 4.6, no longer seems to apply */
+ #if 0
+ log_err("ucol_open(%s, ...) should return an error or some sort of U_USING_FALLBACK_WARNING, but returned %s\n", loc, u_errorName(status));
+ #endif
+ }
+ ucol_close(coll);
+}
+
+static UBool uenum_contains(UEnumeration *e, const char *s, UErrorCode *status) {
+ const char *t;
+ uenum_reset(e, status);
+ while(((t = uenum_next(e, NULL, status)) != NULL) && U_SUCCESS(*status)) {
+ if(uprv_strcmp(s, t) == 0) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+static void TestGetKeywordValuesForLocale(void) {
+#define MAX_NUMBER_OF_KEYWORDS 9
+ const char *PREFERRED[][MAX_NUMBER_OF_KEYWORDS+1] = {
+ { "und", "standard", "eor", "search", NULL, NULL, NULL, NULL, NULL, NULL },
+ { "en_US", "standard", "eor", "search", NULL, NULL, NULL, NULL, NULL, NULL },
+ { "en_029", "standard", "eor", "search", NULL, NULL, NULL, NULL, NULL, NULL },
+ { "de_DE", "standard", "phonebook", "search", "eor", NULL, NULL, NULL, NULL, NULL },
+ { "de_Latn_DE", "standard", "phonebook", "search", "eor", NULL, NULL, NULL, NULL, NULL },
+ { "zh", "pinyin", "stroke", "eor", "search", "standard", NULL },
+ { "zh_Hans", "pinyin", "stroke", "eor", "search", "standard", NULL },
+ { "zh_CN", "pinyin", "stroke", "eor", "search", "standard", NULL },
+ { "zh_Hant", "stroke", "pinyin", "eor", "search", "standard", NULL },
+ { "zh_TW", "stroke", "pinyin", "eor", "search", "standard", NULL },
+ { "zh__PINYIN", "pinyin", "stroke", "eor", "search", "standard", NULL },
+ { "es_ES", "standard", "search", "traditional", "eor", NULL, NULL, NULL, NULL, NULL },
+ { "es__TRADITIONAL","traditional", "search", "standard", "eor", NULL, NULL, NULL, NULL, NULL },
+ { "und@collation=phonebook", "standard", "eor", "search", NULL, NULL, NULL, NULL, NULL, NULL },
+ { "de_DE@collation=pinyin", "standard", "phonebook", "search", "eor", NULL, NULL, NULL, NULL, NULL },
+ { "zzz@collation=xxx", "standard", "eor", "search", NULL, NULL, NULL, NULL, NULL, NULL }
+ };
+
+ UErrorCode status = U_ZERO_ERROR;
+ UEnumeration *keywordValues = NULL;
+ int32_t i, n, size;
+ const char *locale = NULL, *value = NULL;
+ UBool errorOccurred = FALSE;
+
+ for (i = 0; i < UPRV_LENGTHOF(PREFERRED) && !errorOccurred; i++) {
+ locale = PREFERRED[i][0];
+ value = NULL;
+ size = 0;
+
+ keywordValues = ucol_getKeywordValuesForLocale("collation", locale, TRUE, &status);
+ if (keywordValues == NULL || U_FAILURE(status)) {
+ log_err_status(status, "Error getting keyword values: %s\n", u_errorName(status));
+ break;
+ }
+ size = uenum_count(keywordValues, &status);
+ (void)size;
+
+ for (n = 0; (value = PREFERRED[i][n+1]) != NULL; n++) {
+ if (!uenum_contains(keywordValues, value, &status)) {
+ if (U_SUCCESS(status)) {
+ log_err("Keyword value \"%s\" missing for locale: %s\n", value, locale);
+ } else {
+ log_err("While getting keyword value from locale: %s got this error: %s\n", locale, u_errorName(status));
+ errorOccurred = TRUE;
+ break;
+ }
+ }
+ }
+ uenum_close(keywordValues);
+ keywordValues = NULL;
+ }
+ uenum_close(keywordValues);
+}
+
+static void TestStrcollNull(void) {
+ UErrorCode status = U_ZERO_ERROR;
+ UCollator *coll;
+
+ const UChar u16asc[] = {0x0049, 0x0042, 0x004D, 0};
+ const int32_t u16ascLen = 3;
+
+ const UChar u16han[] = {0x5c71, 0x5ddd, 0};
+ const int32_t u16hanLen = 2;
+
+ const char *u8asc = "\x49\x42\x4D";
+ const int32_t u8ascLen = 3;
+
+ const char *u8han = "\xE5\xB1\xB1\xE5\xB7\x9D";
+ const int32_t u8hanLen = 6;
+
+ coll = ucol_open(NULL, &status);
+ if (U_FAILURE(status)) {
+ log_err_status(status, "Default Collator creation failed.: %s\n", myErrorName(status));
+ return;
+ }
+
+ /* UChar API */
+ if (ucol_strcoll(coll, NULL, 0, NULL, 0) != 0) {
+ log_err("ERROR : ucol_strcoll NULL/0 and NULL/0");
+ }
+
+ if (ucol_strcoll(coll, NULL, -1, NULL, 0) != 0) {
+ /* No error arg, should return equal without crash */
+ log_err("ERROR : ucol_strcoll NULL/-1 and NULL/0");
+ }
+
+ if (ucol_strcoll(coll, u16asc, -1, NULL, 10) != 0) {
+ /* No error arg, should return equal without crash */
+ log_err("ERROR : ucol_strcoll u16asc/u16ascLen and NULL/10");
+ }
+
+ if (ucol_strcoll(coll, u16asc, -1, NULL, 0) <= 0) {
+ log_err("ERROR : ucol_strcoll u16asc/-1 and NULL/0");
+ }
+ if (ucol_strcoll(coll, NULL, 0, u16asc, -1) >= 0) {
+ log_err("ERROR : ucol_strcoll NULL/0 and u16asc/-1");
+ }
+ if (ucol_strcoll(coll, u16asc, u16ascLen, NULL, 0) <= 0) {
+ log_err("ERROR : ucol_strcoll u16asc/u16ascLen and NULL/0");
+ }
+
+ if (ucol_strcoll(coll, u16han, -1, NULL, 0) <= 0) {
+ log_err("ERROR : ucol_strcoll u16han/-1 and NULL/0");
+ }
+ if (ucol_strcoll(coll, NULL, 0, u16han, -1) >= 0) {
+ log_err("ERROR : ucol_strcoll NULL/0 and u16han/-1");
+ }
+ if (ucol_strcoll(coll, NULL, 0, u16han, u16hanLen) >= 0) {
+ log_err("ERROR : ucol_strcoll NULL/0 and u16han/u16hanLen");
+ }
+
+ /* UTF-8 API */
+ status = U_ZERO_ERROR;
+ if (ucol_strcollUTF8(coll, NULL, 0, NULL, 0, &status) != 0 || U_FAILURE(status)) {
+ log_err("ERROR : ucol_strcollUTF8 NULL/0 and NULL/0");
+ }
+ status = U_ZERO_ERROR;
+ ucol_strcollUTF8(coll, NULL, -1, NULL, 0, &status);
+ if (status != U_ILLEGAL_ARGUMENT_ERROR) {
+ log_err("ERROR: ucol_strcollUTF8 NULL/-1 and NULL/0, should return U_ILLEGAL_ARGUMENT_ERROR");
+ }
+ status = U_ZERO_ERROR;
+ ucol_strcollUTF8(coll, u8asc, u8ascLen, NULL, 10, &status);
+ if (status != U_ILLEGAL_ARGUMENT_ERROR) {
+ log_err("ERROR: ucol_strcollUTF8 u8asc/u8ascLen and NULL/10, should return U_ILLEGAL_ARGUMENT_ERROR");
+ }
+
+ status = U_ZERO_ERROR;
+ if (ucol_strcollUTF8(coll, u8asc, -1, NULL, 0, &status) <= 0 || U_FAILURE(status)) {
+ log_err("ERROR : ucol_strcollUTF8 u8asc/-1 and NULL/0");
+ }
+ status = U_ZERO_ERROR;
+ if (ucol_strcollUTF8(coll, NULL, 0, u8asc, -1, &status) >= 0 || U_FAILURE(status)) {
+ log_err("ERROR : ucol_strcollUTF8 NULL/0 and u8asc/-1");
+ }
+ status = U_ZERO_ERROR;
+ if (ucol_strcollUTF8(coll, u8asc, u8ascLen, NULL, 0, &status) <= 0 || U_FAILURE(status)) {
+ log_err("ERROR : ucol_strcollUTF8 u8asc/u8ascLen and NULL/0");
+ }
+
+ status = U_ZERO_ERROR;
+ if (ucol_strcollUTF8(coll, u8han, -1, NULL, 0, &status) <= 0 || U_FAILURE(status)) {
+ log_err("ERROR : ucol_strcollUTF8 u8han/-1 and NULL/0");
+ }
+ status = U_ZERO_ERROR;
+ if (ucol_strcollUTF8(coll, NULL, 0, u8han, -1, &status) >= 0 || U_FAILURE(status)) {
+ log_err("ERROR : ucol_strcollUTF8 NULL/0 and u8han/-1");
+ }
+ status = U_ZERO_ERROR;
+ if (ucol_strcollUTF8(coll, NULL, 0, u8han, u8hanLen, &status) >= 0 || U_FAILURE(status)) {
+ log_err("ERROR : ucol_strcollUTF8 NULL/0 and u8han/u8hanLen");
+ }
+
+ ucol_close(coll);
+}
+