]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/intltest/restsnew.cpp
ICU-59117.0.1.tar.gz
[apple/icu.git] / icuSources / test / intltest / restsnew.cpp
index 8aa604b0a3bd08d50f9f0856a37a422fefce2cec..5483cddbe2a2610b8562bea02657f107773145e9 100644 (file)
@@ -1,10 +1,13 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /********************************************************************
- * Copyright (c) 1997-2008, International Business Machines
+ * 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/resbund.h"
@@ -106,7 +109,7 @@ param[] =
     { "ne",         0,   U_USING_DEFAULT_WARNING,  e_Root,      { TRUE, FALSE, FALSE }, { TRUE, FALSE, FALSE } }
 };
 
-static int32_t bundles_count = sizeof(param) / sizeof(param[0]);
+static int32_t bundles_count = UPRV_LENGTHOF(param);
 
 //***************************************************************************************
 
@@ -170,7 +173,7 @@ NewResourceBundleTest::~NewResourceBundleTest()
 {
     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;
         }
@@ -181,11 +184,16 @@ void NewResourceBundleTest::runIndexedTest( int32_t index, UBool exec, const cha
 {
     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 = "TestIteration"; if (exec) TestIteration(); break;
     case 3: name = "TestOtherAPI";  if(exec) TestOtherAPI(); break;
     case 4: name = "TestNewTypes";  if(exec) TestNewTypes(); break;
+#else
+    case 0: case 1: case 2: case 3: case 4: name = "skip"; break;
+#endif
+
     case 5: name = "TestGetByFallback";  if(exec) TestGetByFallback(); break;
         default: name = ""; break; //needed to end loop
     }
@@ -200,7 +208,7 @@ NewResourceBundleTest::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;
     }
 
@@ -234,7 +242,7 @@ NewResourceBundleTest::TestConstruction()
     testdatapath=loadTestData(err);
     if(U_FAILURE(err))
     {
-        dataerrln("[DATA] Could not load testdata.dat %s " + UnicodeString(u_errorName(err)));
+        dataerrln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err)));
         return;
     }
 
@@ -309,7 +317,7 @@ NewResourceBundleTest::TestIteration()
     testdatapath=loadTestData(err);
     if(U_FAILURE(err))
     {
-        dataerrln("[DATA] Could not load testdata.dat %s " + UnicodeString(u_errorName(err)));
+        dataerrln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err)));
         return;
     }
 
@@ -325,7 +333,7 @@ NewResourceBundleTest::TestIteration()
     UnicodeString action;
 
 
-    for(i=0; i<sizeof(data)/sizeof(data[0]); i=i+2){
+    for(i=0; i<UPRV_LENGTHOF(data); i=i+2){
         action = "te_IN";
         action +=".get(";
         action += data[i];
@@ -428,7 +436,7 @@ NewResourceBundleTest::TestOtherAPI(){
 
     if(U_FAILURE(err))
     {
-        dataerrln("[DATA] Could not load testdata.dat %s " + UnicodeString(u_errorName(err)));
+        dataerrln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err)));
         return;
     }
 
@@ -463,7 +471,7 @@ NewResourceBundleTest::TestOtherAPI(){
     ResourceBundle defaultresource(err);
     ResourceBundle explicitdefaultresource(NULL, Locale::getDefault(), err);
     if(U_FAILURE(err)){
-        errln("Construction of default resourcebundle failed");
+        errcheckln(err, "Construction of default resourcebundle failed - %s", u_errorName(err));
         return;
     }
     // You can't compare the default locale to the resolved locale in the
@@ -536,7 +544,7 @@ NewResourceBundleTest::TestOtherAPI(){
         UnicodeString action;
 
 
-        for(i=0; i<sizeof(data)/sizeof(data[0]); i=i+2){
+        for(i=0; i<UPRV_LENGTHOF(data); i=i+2){
             action = "te_IN";
             action +=".get(";
             action += data[i];
@@ -592,6 +600,20 @@ NewResourceBundleTest::TestOtherAPI(){
                 }
             }
         }
+
+        // Check that ures_getUnicodeString() & variants return a bogus string if failure.
+        // Same relevant code path whether the failure code is passed in
+        // or comes from a lookup error.
+        UErrorCode failure = U_INTERNAL_PROGRAM_ERROR;
+        assertTrue("ures_getUnicodeString(failure).isBogus()",
+                   ures_getUnicodeString(testCAPI, &failure).isBogus());
+        assertTrue("ures_getNextUnicodeString(failure).isBogus()",
+                   ures_getNextUnicodeString(testCAPI, NULL, &failure).isBogus());
+        assertTrue("ures_getUnicodeStringByIndex(failure).isBogus()",
+                   ures_getUnicodeStringByIndex(testCAPI, 999, &failure).isBogus());
+        assertTrue("ures_getUnicodeStringByKey(failure).isBogus()",
+                   ures_getUnicodeStringByKey(testCAPI, "bogus key", &failure).isBogus());
+
         ures_close(temp);
         ures_close(rowbundle);
         ures_close(bundle);
@@ -636,7 +658,7 @@ NewResourceBundleTest::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;
     }
 
@@ -1017,7 +1039,7 @@ NewResourceBundleTest::TestNewTypes() {
 
     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;
     }
 
@@ -1025,7 +1047,7 @@ NewResourceBundleTest::TestNewTypes() {
     ResourceBundle bundle(testdatapath, Locale("te_IN"),status);
 
     UnicodeString emptyStr = theBundle.getStringEx("emptystring", status);
-    if(!emptyStr.length()==0) {
+    if(emptyStr.length() != 0) {
       logln("Empty string returned invalid value\n");
     }
 
@@ -1164,7 +1186,7 @@ NewResourceBundleTest::TestGetByFallback() {
 
     heRes.getWithFallback("calendar", status).getWithFallback("islamic-civil", status).getWithFallback("eras", status);
     if(U_FAILURE(status)) {
-        errln("Didn't get Islamic Eras. I know they are there!\n");
+        dataerrln("Didn't get Islamic Eras. I know they are there! - %s", u_errorName(status));
     }
     status = U_ZERO_ERROR;