]> granicus.if.org Git - icu/commitdiff
ICU-10030 fix crasher when no subregions, also err check, and modernize test infrastr...
authorSteven R. Loomis <srl@icu-project.org>
Fri, 8 Mar 2013 19:23:41 +0000 (19:23 +0000)
committerSteven R. Loomis <srl@icu-project.org>
Fri, 8 Mar 2013 19:23:41 +0000 (19:23 +0000)
X-SVN-Rev: 33401

icu4c/source/i18n/region.cpp
icu4c/source/test/intltest/regiontst.cpp
icu4c/source/test/intltest/regiontst.h

index b63abe25f91754a0995ae3e525c6ece79ccedce4..1485c078e3eeeba8e4d88233457c8ff46cae1e40 100644 (file)
@@ -644,7 +644,7 @@ Region::getType() const {
 
 RegionNameEnumeration::RegionNameEnumeration(UVector *fNameList, UErrorCode& status) {
     pos=0;
-    if (fNameList) {
+    if (fNameList && U_SUCCESS(status)) {
         fRegionNames = new UVector(uprv_deleteUObject, uhash_compareUnicodeString, fNameList->size(),status);
         for ( int32_t i = 0 ; i < fNameList->size() ; i++ ) {
             UnicodeString* this_region_name = (UnicodeString *)fNameList->elementAt(i);
@@ -658,8 +658,15 @@ RegionNameEnumeration::RegionNameEnumeration(UVector *fNameList, UErrorCode& sta
 }
 
 const UnicodeString*
-RegionNameEnumeration::snext(UErrorCode& /*status*/) { 
-    return (const UnicodeString *)fRegionNames->elementAt(pos++);
+RegionNameEnumeration::snext(UErrorCode& status) { 
+  if (U_FAILURE(status) || (fRegionNames==NULL)) {
+    return NULL;
+  }
+  const UnicodeString* nextStr = (const UnicodeString *)fRegionNames->elementAt(pos);
+  if (nextStr!=NULL) {
+    pos++;
+  }
+  return nextStr;
 }
 
 void
index a1c3dd2fc146369b6540c8ab23cc66983cdf2555..2626571210985433f859b54a065d791eccf2e336 100644 (file)
@@ -341,25 +341,24 @@ RegionTest::RegionTest() {
 RegionTest::~RegionTest() {
 }
 
-#define CASE(id,test) case id: name = #test; if (exec) { logln(#test "---"); logln((UnicodeString)""); test(); } break;
-
 void 
 RegionTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* par )
 {
-    optionv = (par && *par=='v');
-    switch (index) {
-        CASE(0, TestKnownRegions)
-        CASE(1, TestGetInstanceString)
-        CASE(2, TestGetInstanceInt)
-        CASE(3, TestGetContainedRegions)
-        CASE(4, TestGetContainedRegionsWithType)
-        CASE(5, TestGetContainingRegion)
-        CASE(6, TestGetContainingRegionWithType)
-        CASE(7, TestGetPreferredValues)
-        CASE(8, TestContains);
-        CASE(9, TestAvailableTerritories)
-        default: name = ""; break;
-    }
+   optionv = (par && *par=='v');
+
+   TESTCASE_AUTO_BEGIN;
+   TESTCASE_AUTO(TestKnownRegions);
+   TESTCASE_AUTO(TestGetInstanceString);
+   TESTCASE_AUTO(TestGetInstanceInt);
+   TESTCASE_AUTO(TestGetContainedRegions);
+   TESTCASE_AUTO(TestGetContainedRegionsWithType);
+   TESTCASE_AUTO(TestGetContainingRegion);
+   TESTCASE_AUTO(TestGetContainingRegionWithType);
+   TESTCASE_AUTO(TestGetPreferredValues);
+   TESTCASE_AUTO(TestContains);
+   TESTCASE_AUTO(TestAvailableTerritories);
+   TESTCASE_AUTO(TestNoContainedRegions);
+   TESTCASE_AUTO_END;
 }
 
 
@@ -692,6 +691,17 @@ void RegionTest::TestAvailableTerritories() {
     delete availableTerritories;
     delete containedInWorld;
 }
+
+void RegionTest::TestNoContainedRegions(void) {
+  UErrorCode status = U_ZERO_ERROR;
+  const char *emptyStr = Region::getInstance("BM",status)->getContainedRegions()->next(NULL, status);
+  if (U_FAILURE(status)||(emptyStr!=NULL)) {
+    errln("Error, 'BM' should have no subregions, but returned str=%p, err=%s\n", emptyStr, u_errorName(status));
+  } else {
+    logln("Success - BM has no subregions\n");
+  }
+}
+
 #endif /* #if !UCONFIG_NO_FORMATTING */
 
 //eof
index c81fcaea61a6acbf153e0700a63228c0f0632cb0..4f192e20d55c66864e6bf21b68772547f38b6c71 100644 (file)
@@ -35,6 +35,7 @@ public:
     void TestGetPreferredValues(void);
     void TestContains(void);
     void TestAvailableTerritories(void);
+    void TestNoContainedRegions(void);
 
 private: