+static void TestGetKeywordValuesForLocale(void) {
+#define PREFERRED_SIZE 15
+#define MAX_NUMBER_OF_KEYWORDS 4
+ const char *PREFERRED[PREFERRED_SIZE][MAX_NUMBER_OF_KEYWORDS] = {
+ { "root", "USD", "USN", NULL },
+ { "und", "USD", "USN", NULL },
+ /* { "und_ZZ", "USD", NULL, NULL }, -- temporarily remove as this locale now has 15 entries */
+ { "en_US", "USD", "USN", NULL },
+ { "en_029", "USD", "USN", NULL },
+ { "en_TH", "THB", NULL, NULL },
+ { "de", "EUR", NULL, NULL },
+ { "de_DE", "EUR", NULL, NULL },
+ { "ar", "EGP", NULL, NULL },
+ { "ar_PS", "ILS", "JOD", NULL },
+ { "en@currency=CAD", "USD", "USN", NULL },
+ { "fr@currency=zzz", "EUR", NULL, NULL },
+ { "de_DE@currency=DEM", "EUR", NULL, NULL },
+ { "en_US@rg=THZZZZ", "THB", NULL, NULL },
+ { "de@rg=USZZZZ", "USD", "USN", NULL },
+ { "en_US@currency=CAD;rg=THZZZZ", "THB", NULL, NULL },
+ };
+ const int32_t EXPECTED_SIZE[PREFERRED_SIZE] = {
+ 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 1
+ };
+ /* ucurr_forLocale results for same locales; "" if no result expected */
+ const char *FORLOCALE[PREFERRED_SIZE] = {
+ "", "", "USD", "",
+ "THB", "", "EUR", "",
+ "ILS", "CAD", "ZZZ", "DEM",
+ "THB", "USD", "CAD"
+ };
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t i, j, size;
+ UEnumeration *pref, *all;
+ const char *loc = NULL;
+ UBool matchPref, matchAll;
+ const char *value = NULL;
+ int32_t valueLength = 0;
+
+ UList *ALLList = NULL;
+
+ UEnumeration *ALL = ucurr_getKeywordValuesForLocale("currency", uloc_getDefault(), FALSE, &status);
+ if (ALL == NULL) {
+ log_err_status(status, "ERROR getting keyword value for default locale. -> %s\n", u_errorName(status));
+ return;
+ }
+
+ for (i = 0; i < PREFERRED_SIZE; i++) {
+ UChar getCurrU[4];
+ int32_t getCurrLen;
+
+ status = U_ZERO_ERROR;
+ pref = NULL;
+ all = NULL;
+ loc = PREFERRED[i][0];
+ pref = ucurr_getKeywordValuesForLocale("currency", loc, TRUE, &status);
+ matchPref = FALSE;
+ matchAll = FALSE;
+
+ size = uenum_count(pref, &status);
+
+ if (size == EXPECTED_SIZE[i]) {
+ matchPref = TRUE;
+ for (j = 0; j < size; j++) {
+ if ((value = uenum_next(pref, &valueLength, &status)) != NULL && U_SUCCESS(status)) {
+ if (uprv_strcmp(value, PREFERRED[i][j+1]) != 0) {
+ log_err("ERROR: locale %s got keywords #%d %s expected %s\n", loc, j, value, PREFERRED[i][j+1]);
+
+ matchPref = FALSE;
+ break;
+ }
+ } else {
+ matchPref = FALSE;
+ log_err("ERROR getting keyword value for locale \"%s\"\n", loc);
+ break;
+ }
+ }
+ } else {
+ log_err("FAIL: size of locale \"%s\" %d does not match expected size %d\n", loc, size, EXPECTED_SIZE[i]);
+ }
+
+ if (!matchPref) {
+ log_err("FAIL: Preferred values for locale \"%s\" does not match expected.\n", loc);
+ break;
+ }
+ uenum_close(pref);
+
+ all = ucurr_getKeywordValuesForLocale("currency", loc, FALSE, &status);
+
+ size = uenum_count(all, &status);
+
+ if (U_SUCCESS(status) && size == uenum_count(ALL, &status)) {
+ matchAll = TRUE;
+ ALLList = ulist_getListFromEnum(ALL);
+ for (j = 0; j < size; j++) {
+ if ((value = uenum_next(all, &valueLength, &status)) != NULL && U_SUCCESS(status)) {
+ if (!ulist_containsString(ALLList, value, uprv_strlen(value))) {
+ log_err("Locale %s have %s not in ALL\n", loc, value);
+ matchAll = FALSE;
+ break;
+ }
+ } else {
+ matchAll = FALSE;
+ log_err("ERROR getting \"all\" keyword value for locale \"%s\"\n", loc);
+ break;
+ }
+ }
+ if (!matchAll) {
+ log_err("FAIL: All values for locale \"%s\" does not match expected.\n", loc);
+ }
+ } else {
+ if(U_FAILURE(status)) {
+ log_err("ERROR: %s\n", u_errorName(status));
+ } else if(size!=uenum_count(ALL, &status)) {
+ log_err("ERROR: got size of %d, wanted %d\n", size, uenum_count(ALL, &status));
+ }
+ }
+
+ uenum_close(all);
+
+ status = U_ZERO_ERROR;
+ getCurrLen = ucurr_forLocale(loc, getCurrU, 4, &status);
+ if(U_FAILURE(status)) {
+ if (FORLOCALE[i][0] != 0) {
+ log_err("ERROR: ucurr_forLocale %s, status %s\n", loc, u_errorName(status));
+ }
+ } else if (getCurrLen != 3) {
+ if (FORLOCALE[i][0] != 0 || getCurrLen != -1) {
+ log_err("ERROR: ucurr_forLocale %s, returned len %d\n", loc, getCurrLen);
+ }
+ } else {
+ char getCurrB[4];
+ u_UCharsToChars(getCurrU, getCurrB, 4);
+ if ( uprv_strncmp(getCurrB, FORLOCALE[i], 4) != 0 ) {
+ log_err("ERROR: ucurr_forLocale %s, expected %s, got %s\n", loc, FORLOCALE[i], getCurrB);
+ }
+ }
+ }
+
+ uenum_close(ALL);
+
+}
+