]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/intltest/restest.cpp
ICU-66108.tar.gz
[apple/icu.git] / icuSources / test / intltest / restest.cpp
index 0f9175b02245badeed892eab162c893fe952d897..3a2243ad3c1105b479cdbaff296fbd56a1231f8a 100644 (file)
@@ -1,11 +1,14 @@
+// © 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-2016, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 
 #include "unicode/utypes.h"
 
+#include "cmemory.h"
 #include "cstring.h"
 #include "unicode/unistr.h"
 #include "unicode/uniset.h"
@@ -21,7 +24,6 @@
 
 static const UChar kErrorUChars[] = { 0x45, 0x52, 0x52, 0x4f, 0x52, 0 };
 static const int32_t kErrorLength = 5;
-static const int32_t kERROR_COUNT = -1234567;
 
 //***************************************************************************************
 
@@ -35,11 +37,35 @@ enum E_Where
 
 //***************************************************************************************
 
-#define CONFIRM_EQ(actual, expected, myAction) if ((expected)==(actual)) { record_pass(myAction); } else { record_fail(myAction + (UnicodeString)" returned " + (actual) + (UnicodeString)" instead of " + (expected) + "\n");}
-#define CONFIRM_GE(actual, expected, myAction) if ((actual)>=(expected)) { record_pass(myAction); } else { record_fail(myAction + (UnicodeString)" returned " + (actual) + (UnicodeString)" instead of x >= " + (expected) + "\n");}
-#define CONFIRM_NE(actual, expected, myAction) if ((expected)!=(actual)) { record_pass(myAction); } else { record_fail(myAction + (UnicodeString)" returned " + (actual) + (UnicodeString)" instead of x != " + (expected) + "\n");}
-
-#define CONFIRM_UErrorCode(actual, expected, myAction) if ((expected)==(actual)) { record_pass(myAction); } else { record_fail(myAction + (UnicodeString)" returned " + u_errorName(actual) + " instead of " + u_errorName(expected) + "\n"); }
+#define CONFIRM_EQ(actual, expected, myAction) UPRV_BLOCK_MACRO_BEGIN { \
+    if ((expected)==(actual)) { \
+        record_pass(myAction); \
+    } else { \
+        record_fail(myAction + (UnicodeString)" returned " + (actual) + (UnicodeString)" instead of " + (expected) + "\n"); \
+    } \
+} UPRV_BLOCK_MACRO_END
+#define CONFIRM_GE(actual, expected, myAction) UPRV_BLOCK_MACRO_BEGIN { \
+    if ((actual)>=(expected)) { \
+        record_pass(myAction); \
+    } else { \
+        record_fail(myAction + (UnicodeString)" returned " + (actual) + (UnicodeString)" instead of x >= " + (expected) + "\n"); \
+    } \
+} UPRV_BLOCK_MACRO_END
+#define CONFIRM_NE(actual, expected, myAction) UPRV_BLOCK_MACRO_BEGIN { \
+    if ((expected)!=(actual)) { \
+        record_pass(myAction); \
+    } else { \
+        record_fail(myAction + (UnicodeString)" returned " + (actual) + (UnicodeString)" instead of x != " + (expected) + "\n"); \
+    } \
+} UPRV_BLOCK_MACRO_END
+
+#define CONFIRM_UErrorCode(actual, expected, myAction) UPRV_BLOCK_MACRO_BEGIN { \
+    if ((expected)==(actual)) { \
+        record_pass(myAction); \
+    } else { \
+        record_fail(myAction + (UnicodeString)" returned " + u_errorName(actual) + " instead of " + u_errorName(expected) + "\n"); \
+    } \
+} UPRV_BLOCK_MACRO_END
 
 //***************************************************************************************
 
@@ -108,7 +134,7 @@ param[] =
     { "ne",         NULL,   U_USING_DEFAULT_WARNING,  e_Root,      { TRUE, FALSE, FALSE }, { TRUE, FALSE, FALSE } }
 };
 
-static const int32_t bundles_count = sizeof(param) / sizeof(param[0]);
+static const int32_t bundles_count = UPRV_LENGTHOF(param);
 
 //***************************************************************************************
 
@@ -172,7 +198,7 @@ ResourceBundleTest::~ResourceBundleTest()
 {
     if (param[5].locale) {
         int idx;
-        for (idx = 0; idx < (int)(sizeof(param)/sizeof(param[0])); idx++) {
+        for (idx = 0; idx < UPRV_LENGTHOF(param); idx++) {
             delete param[idx].locale;
             param[idx].locale = NULL;
         }
@@ -183,11 +209,16 @@ void ResourceBundleTest::runIndexedTest( int32_t index, UBool exec, const char*
 {
     if (exec) logln("TestSuite ResourceBundleTest: ");
     switch (index) {
+#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
     case 0: name = "TestResourceBundles"; if (exec) TestResourceBundles(); break;
     case 1: name = "TestConstruction"; if (exec) TestConstruction(); break;
-    case 2: name = "TestExemplar"; if (exec) TestExemplar(); break;
-    case 3: name = "TestGetSize"; if (exec) TestGetSize(); break;
-    case 4: name = "TestGetLocaleByType"; if (exec) TestGetLocaleByType(); break;
+    case 2: name = "TestGetSize"; if (exec) TestGetSize(); break;
+    case 3: name = "TestGetLocaleByType"; if (exec) TestGetLocaleByType(); break;
+#else
+    case 0: case 1: case 2: case 3: name = "skip"; break;
+#endif
+
+    case 4: name = "TestExemplar"; if (exec) TestExemplar(); break;
         default: name = ""; break; //needed to end loop
     }
 }
@@ -202,7 +233,7 @@ ResourceBundleTest::TestResourceBundles()
     loadTestData(status);
     if(U_FAILURE(status))
     {
-        dataerrln("[DATA] Could not load testdata.dat %s " + UnicodeString(u_errorName(status)));
+        dataerrln("Could not load testdata.dat %s " + UnicodeString(u_errorName(status)));
         return;
     }
 
@@ -235,7 +266,7 @@ ResourceBundleTest::TestConstruction()
     const char* testdatapath=loadTestData(err);
     if(U_FAILURE(err))
     {
-        dataerrln("[DATA] Could not load testdata.dat " + UnicodeString(testdatapath) +  ", " + UnicodeString(u_errorName(err)));
+        dataerrln("Could not load testdata.dat " + UnicodeString(testdatapath) +  ", " + UnicodeString(u_errorName(err)));
         return;
     }
 
@@ -319,7 +350,7 @@ ResourceBundleTest::testTag(const char* frag,
     testdatapath=loadTestData(status);
     if(U_FAILURE(status))
     {
-        dataerrln("[DATA] Could not load testdata.dat %s " + UnicodeString(u_errorName(status)));
+        dataerrln("Could not load testdata.dat %s " + UnicodeString(u_errorName(status)));
         return FALSE;
     }
 
@@ -534,7 +565,7 @@ ResourceBundleTest::TestGetSize(void)
     
     if(U_FAILURE(status))
     {
-        dataerrln("[DATA] Could not load testdata.dat %s\n", u_errorName(status));
+        dataerrln("Could not load testdata.dat %s\n", u_errorName(status));
         return;
     }
     
@@ -545,7 +576,7 @@ ResourceBundleTest::TestGetSize(void)
         return;
     }
     
-    for(i = 0; i < (int32_t)(sizeof(test)/sizeof(test[0])); i++) {
+    for(i = 0; i < UPRV_LENGTHOF(test); i++) {
         ResourceBundle res = rb.get(test[i].key, status);
         if(U_FAILURE(status))
         {
@@ -588,11 +619,11 @@ ResourceBundleTest::TestGetLocaleByType(void)
     
     if(U_FAILURE(status))
     {
-        dataerrln("[DATA] Could not load testdata.dat %s\n", u_errorName(status));
+        dataerrln("Could not load testdata.dat %s\n", u_errorName(status));
         return;
     }
     
-    for(i = 0; i < (int32_t)(sizeof(test)/sizeof(test[0])); i++) {
+    for(i = 0; i < UPRV_LENGTHOF(test); i++) {
         ResourceBundle rb(testdatapath, test[i].requestedLocale, status);
         if(U_FAILURE(status))
         {
@@ -608,11 +639,12 @@ ResourceBundleTest::TestGetLocaleByType(void)
             status = U_ZERO_ERROR;
             continue;
         }
-        
+
         locale = res.getLocale(ULOC_REQUESTED_LOCALE, status);
-        if(locale != Locale::getDefault()) {
+        if(U_SUCCESS(status) && locale != Locale::getDefault()) {
             err("Expected requested locale to be %s. Got %s\n", test[i].requestedLocale, locale.getName());
         }
+        status = U_ZERO_ERROR;
         locale = res.getLocale(ULOC_VALID_LOCALE, status);
         if(strcmp(locale.getName(), test[i].validLocale) != 0) {
             err("Expected valid locale to be %s. Got %s\n", test[i].requestedLocale, locale.getName());
@@ -623,6 +655,3 @@ ResourceBundleTest::TestGetLocaleByType(void)
         }
     }
 }
-
-//eof
-