]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/intltest/restsnew.cpp
ICU-64232.0.1.tar.gz
[apple/icu.git] / icuSources / test / intltest / restsnew.cpp
index 5483cddbe2a2610b8562bea02657f107773145e9..1c19fc8e91deeae7b9a574a7b1a8dfc700efb81d 100644 (file)
@@ -195,6 +195,8 @@ void NewResourceBundleTest::runIndexedTest( int32_t index, UBool exec, const cha
 #endif
 
     case 5: name = "TestGetByFallback";  if(exec) TestGetByFallback(); break;
+    case 6: name = "TestFilter";  if(exec) TestFilter(); break;
+
         default: name = ""; break; //needed to end loop
     }
 }
@@ -1198,5 +1200,148 @@ NewResourceBundleTest::TestGetByFallback() {
     status = U_ZERO_ERROR;
 
 }
+
+
+#define REQUIRE_SUCCESS(status) { \
+    if (status.errIfFailureAndReset("line %d", __LINE__)) { \
+        return; \
+    } \
+}
+
+#define REQUIRE_ERROR(expected, status) { \
+    if (!status.expectErrorAndReset(expected, "line %d", __LINE__)) { \
+        return; \
+    } \
+}
+
+/**
+ * Tests the --filterDir option in genrb.
+ *
+ * Input resource text file: test/testdata/filtertest.txt
+ * Input filter rule file: test/testdata/filters/filtertest.txt
+ *
+ * The resource bundle should contain no keys matched by the filter
+ * and should contain all other keys.
+ */
+void NewResourceBundleTest::TestFilter() {
+    IcuTestErrorCode status(*this, "TestFilter");
+
+    ResourceBundle rb(loadTestData(status), "filtertest", status);
+    REQUIRE_SUCCESS(status);
+    assertEquals("rb", rb.getType(), URES_TABLE);
+
+    ResourceBundle alabama = rb.get("alabama", status);
+    REQUIRE_SUCCESS(status);
+    assertEquals("alabama", alabama.getType(), URES_TABLE);
+
+    {
+        ResourceBundle alaska = alabama.get("alaska", status);
+        REQUIRE_SUCCESS(status);
+        assertEquals("alaska", alaska.getType(), URES_TABLE);
+
+        {
+            ResourceBundle arizona = alaska.get("arizona", status);
+            REQUIRE_SUCCESS(status);
+            assertEquals("arizona", arizona.getType(), URES_STRING);
+            assertEquals("arizona", u"arkansas", arizona.getString(status));
+            REQUIRE_SUCCESS(status);
+
+            // Filter: california should not be included
+            ResourceBundle california = alaska.get("california", status);
+            REQUIRE_ERROR(U_MISSING_RESOURCE_ERROR, status);
+        }
+
+        // Filter: connecticut should not be included
+        ResourceBundle connecticut = alabama.get("connecticut", status);
+        REQUIRE_ERROR(U_MISSING_RESOURCE_ERROR, status);
+    }
+
+    ResourceBundle fornia = rb.get("fornia", status);
+    REQUIRE_SUCCESS(status);
+    assertEquals("fornia", fornia.getType(), URES_TABLE);
+
+    {
+        ResourceBundle hawaii = fornia.get("hawaii", status);
+        REQUIRE_SUCCESS(status);
+        assertEquals("hawaii", hawaii.getType(), URES_STRING);
+        assertEquals("hawaii", u"idaho", hawaii.getString(status));
+        REQUIRE_SUCCESS(status);
+
+        // Filter: illinois should not be included
+        ResourceBundle illinois = fornia.get("illinois", status);
+        REQUIRE_ERROR(U_MISSING_RESOURCE_ERROR, status);
+    }
+
+    ResourceBundle mississippi = rb.get("mississippi", status);
+    REQUIRE_SUCCESS(status);
+    assertEquals("mississippi", mississippi.getType(), URES_TABLE);
+
+    {
+        ResourceBundle louisiana = mississippi.get("louisiana", status);
+        REQUIRE_SUCCESS(status);
+        assertEquals("louisiana", louisiana.getType(), URES_TABLE);
+
+        {
+            ResourceBundle maine = louisiana.get("maine", status);
+            REQUIRE_SUCCESS(status);
+            assertEquals("maine", maine.getType(), URES_STRING);
+            assertEquals("maine", u"maryland", maine.getString(status));
+            REQUIRE_SUCCESS(status);
+
+            ResourceBundle iowa = louisiana.get("iowa", status);
+            REQUIRE_SUCCESS(status);
+            assertEquals("iowa", iowa.getType(), URES_STRING);
+            assertEquals("iowa", u"kansas", iowa.getString(status));
+            REQUIRE_SUCCESS(status);
+
+            // Filter: missouri should not be included
+            ResourceBundle missouri = louisiana.get("missouri", status);
+            REQUIRE_ERROR(U_MISSING_RESOURCE_ERROR, status);
+        }
+
+        ResourceBundle michigan = mississippi.get("michigan", status);
+        REQUIRE_SUCCESS(status);
+        assertEquals("michigan", michigan.getType(), URES_TABLE);
+
+        {
+            ResourceBundle maine = michigan.get("maine", status);
+            REQUIRE_SUCCESS(status);
+            assertEquals("maine", maine.getType(), URES_STRING);
+            assertEquals("maine", u"minnesota", maine.getString(status));
+            REQUIRE_SUCCESS(status);
+
+            // Filter: iowa should not be included
+            ResourceBundle iowa = michigan.get("iowa", status);
+            REQUIRE_ERROR(U_MISSING_RESOURCE_ERROR, status);
+
+            ResourceBundle missouri = michigan.get("missouri", status);
+            REQUIRE_SUCCESS(status);
+            assertEquals("missouri", missouri.getType(), URES_STRING);
+            assertEquals("missouri", u"nebraska", missouri.getString(status));
+            REQUIRE_SUCCESS(status);
+        }
+
+        ResourceBundle nevada = mississippi.get("nevada", status);
+        REQUIRE_SUCCESS(status);
+        assertEquals("nevada", nevada.getType(), URES_TABLE);
+
+        {
+            ResourceBundle maine = nevada.get("maine", status);
+            REQUIRE_SUCCESS(status);
+            assertEquals("maine", maine.getType(), URES_STRING);
+            assertEquals("maine", u"new-hampshire", maine.getString(status));
+            REQUIRE_SUCCESS(status);
+
+            // Filter: iowa should not be included
+            ResourceBundle iowa = nevada.get("iowa", status);
+            REQUIRE_ERROR(U_MISSING_RESOURCE_ERROR, status);
+
+            // Filter: missouri should not be included
+            ResourceBundle missouri = nevada.get("missouri", status);
+            REQUIRE_ERROR(U_MISSING_RESOURCE_ERROR, status);
+        }
+    }
+}
+
 //eof