]> 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 e6240c0907ef1bf5cb457918063fa8cf345c387b..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-2014, 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;
         }
@@ -330,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];
@@ -541,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];
@@ -597,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);