2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-30 21:45:37 +00:00

[#1077] better Element.sortMaps unit test

This commit is contained in:
Andrei Pavel
2021-07-22 22:29:28 +03:00
committed by Tomek Mrugalski
parent 03c9c10d0c
commit b0b0ec6d12

View File

@@ -1420,17 +1420,45 @@ TEST(Element, sortStrings) {
}
TEST(Element, sortMaps) {
ElementPtr e1(Element::fromJSON(R"({"id": 1, "subnet": "10.0.1.0/24"})"));
ElementPtr e1(Element::fromJSON(R"({"id": 1, "subnet": "10.0.2.0/24"})"));
ElementPtr e2(Element::fromJSON(R"({"id": 2, "subnet": "10.0.1.0/24"})"));
ElementPtr l(Element::createList());
l->add(e2);
ElementPtr l;
// Test sorting by "id". Order shouldn't change.
l = Element::createList();
l->add(e1);
EXPECT_EQ(*l->get(0), *e2);
EXPECT_EQ(*l->get(1), *e1);
l->add(e2);
boost::dynamic_pointer_cast<ListElement>(l)->sort("id");
ASSERT_EQ(l->size(), 2);
EXPECT_EQ(*l->get(0), *e1);
EXPECT_EQ(*l->get(1), *e2);
// Test sorting by "id". Order should change.
l = Element::createList();
l->add(e2);
l->add(e1);
boost::dynamic_pointer_cast<ListElement>(l)->sort("id");
ASSERT_EQ(l->size(), 2);
EXPECT_EQ(*l->get(0), *e1);
EXPECT_EQ(*l->get(1), *e2);
// Test sorting by "subnet". Order should change.
l = Element::createList();
l->add(e1);
l->add(e2);
boost::dynamic_pointer_cast<ListElement>(l)->sort("subnet");
ASSERT_EQ(l->size(), 2);
EXPECT_EQ(*l->get(0), *e2);
EXPECT_EQ(*l->get(1), *e1);
// Test sorting by "subnet". Order shouldn't change.
l = Element::createList();
l->add(e2);
l->add(e1);
boost::dynamic_pointer_cast<ListElement>(l)->sort("subnet");
ASSERT_EQ(l->size(), 2);
EXPECT_EQ(*l->get(0), *e2);
EXPECT_EQ(*l->get(1), *e1);
}
TEST(Element, removeEmptyContainersRecursively) {