]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/cintltst/currtest.c
ICU-491.11.1.tar.gz
[apple/icu.git] / icuSources / test / cintltst / currtest.c
index 15ee318c0d887e72e6bd111fd55678164ef9c270..15b30a5a36e36d33e448571c83aa5b3073445f7a 100644 (file)
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT:
- * Copyright (c) 2005-2008, International Business Machines Corporation and
+ * Copyright (c) 2005-2012, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 #include "unicode/utypes.h"
@@ -163,7 +163,7 @@ static void TestFractionDigitOverride(void) {
     const char expectedSecond[] = "123,46\\u00A0Ft";
     const char expectedThird[] = "123,456\\u00A0Ft";
     if (U_FAILURE(status)) {
-       log_err("Error: unum_open returned %s\n", myErrorName(status));
+       log_data_err("Error: unum_open returned %s (Are you missing data?)\n", myErrorName(status));
        return;
     }
     /* Make sure that you can format normal fraction digits. */
@@ -203,7 +203,7 @@ static void TestPrefixSuffix(void) {
        status = U_ZERO_ERROR;
        parser = unum_open(UNUM_CURRENCY, NULL, -1, "en_US", NULL, &status);
     if (U_FAILURE(status)) {
-       log_err("Error: unum_open returned %s\n", u_errorName(status));
+       log_data_err("Error: unum_open returned %s (Are you missing data?)\n", u_errorName(status));
        return;
     }
 
@@ -227,6 +227,37 @@ static void TestPrefixSuffix(void) {
     unum_close(parser);
 }
 
+typedef struct {
+    const char* alphaCode;
+    int32_t     numericCode;
+} NumCodeTestEntry;
+
+static const NumCodeTestEntry NUMCODE_TESTDATA[] = {
+    {"USD", 840},
+    {"Usd", 840},   /* mixed casing */
+    {"EUR", 978},
+    {"JPY", 392},
+    {"XFU", 0},     /* XFU: no numeric code  */
+    {"ZZZ", 0},     /* ZZZ: undefined ISO currency code */
+    {"bogus", 0},   /* bogus code */
+    {0, 0},
+};
+
+static void TestNumericCode(void) {
+    UChar code[4];
+    int32_t i;
+    int32_t numCode;
+
+    for (i = 0; NUMCODE_TESTDATA[i].alphaCode; i++) {
+        u_charsToUChars(NUMCODE_TESTDATA[i].alphaCode, code, sizeof(code)/sizeof(code[0]));
+        numCode = ucurr_getNumericCode(code);
+        if (numCode != NUMCODE_TESTDATA[i].numericCode) {
+            log_data_err("Error: ucurr_getNumericCode returned %d for currency %s, expected - %d\n",
+                numCode, NUMCODE_TESTDATA[i].alphaCode, NUMCODE_TESTDATA[i].numericCode);
+        }
+    }
+}
+
 void addCurrencyTest(TestNode** root);
 
 #define TESTCASE(x) addTest(root, &x, "tsformat/currtest/" #x)
@@ -238,6 +269,7 @@ void addCurrencyTest(TestNode** root)
     TESTCASE(TestEnumListCount);
     TESTCASE(TestFractionDigitOverride);
     TESTCASE(TestPrefixSuffix);
+    TESTCASE(TestNumericCode);
 }
 
 #endif /* #if !UCONFIG_NO_FORMATTING */