Skip to content

v0.2.47..v0.2.48 changeset PreserveTypesTagMergerTest.cpp

Garret Voltz edited this page Sep 27, 2019 · 1 revision
diff --git a/hoot-core-test/src/test/cpp/hoot/core/schema/PreserveTypesTagMergerTest.cpp b/hoot-core-test/src/test/cpp/hoot/core/schema/PreserveTypesTagMergerTest.cpp
index 4103569..c62f974 100644
--- a/hoot-core-test/src/test/cpp/hoot/core/schema/PreserveTypesTagMergerTest.cpp
+++ b/hoot-core-test/src/test/cpp/hoot/core/schema/PreserveTypesTagMergerTest.cpp
@@ -51,6 +51,8 @@ class PreserveTypesTagMergerTest : public HootTestFixture
   CPPUNIT_TEST(overwrite1Test);
   CPPUNIT_TEST(overwrite1OverlappingKeysTest);
   CPPUNIT_TEST(skipTagsTest);
+  CPPUNIT_TEST(ancestorTest);
+  CPPUNIT_TEST(ancestorGenericTest);
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -217,6 +219,81 @@ public:
     Tags merged = uut.mergeTags(t1, t2, ElementType::Way);
     CPPUNIT_ASSERT_EQUAL(expected, merged);
   }
+
+  void ancestorTest()
+  {
+    PreserveTypesTagMerger uut;
+    Tags expected;
+    Tags merged;
+
+    // amenity=church_hall is a more specific instance of amenity=hall, so only the
+    // amenity=church_hall type tag should be kept. This should work when merging in either
+    // direction.
+
+    Tags t1;
+    t1["amenity"] = "hall";
+    t1["name"] = "Hall 1";
+
+    Tags t2;
+    t2["amenity"] = "church_hall";
+    t2["name"] = "Hall 2";
+
+    expected["amenity"] = "church_hall";
+    expected["name"] = "Hall 1";
+    expected["alt_name"] = "Hall 2";
+
+    uut.setOverwrite1(false);
+    merged = uut.mergeTags(t1, t2, ElementType::Way);
+    CPPUNIT_ASSERT_EQUAL(expected, merged);
+
+    expected.clear();
+    expected["amenity"] = "church_hall";
+    expected["name"] = "Hall 2";
+    expected["alt_name"] = "Hall 1";
+
+    uut.setOverwrite1(true);
+    merged = uut.mergeTags(t1, t2, ElementType::Way);
+    CPPUNIT_ASSERT_EQUAL(expected, merged);
+  }
+
+  void ancestorGenericTest()
+  {
+    PreserveTypesTagMerger uut;
+    Tags expected;
+    Tags merged;
+
+    // building=mosque is a more specific instance of building=yes, so only the building=mosque type
+    // tag should be kept. This should work when merging in either direction. Note that this
+    // ancestral relationship between generic (building=yes) and non-generic features
+    // (building=mosque) doesn't currently work as part of the schema and was added as a custom
+    // behavior to PreserveTypesTagMerger. We may want to look into why it doesn't work by default
+    // when calling OsmSchema::isAncestor at some point.
+
+    Tags t1;
+    t1["building"] = "yes";
+    t1["name"] = "Building 1";
+
+    Tags t2;
+    t2["building"] = "mosque";
+    t2["name"] = "Building 2";
+
+    expected["building"] = "mosque";
+    expected["name"] = "Building 1";
+    expected["alt_name"] = "Building 2";
+
+    uut.setOverwrite1(false);
+    merged = uut.mergeTags(t1, t2, ElementType::Way);
+    CPPUNIT_ASSERT_EQUAL(expected, merged);
+
+    expected.clear();
+    expected["building"] = "mosque";
+    expected["name"] = "Building 2";
+    expected["alt_name"] = "Building 1";
+
+    uut.setOverwrite1(true);
+    merged = uut.mergeTags(t1, t2, ElementType::Way);
+    CPPUNIT_ASSERT_EQUAL(expected, merged);
+  }
 };
 
 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(PreserveTypesTagMergerTest, "quick");
Clone this wiki locally