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:
committed by
Tomek Mrugalski
parent
03c9c10d0c
commit
b0b0ec6d12
@@ -1420,17 +1420,45 @@ TEST(Element, sortStrings) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(Element, sortMaps) {
|
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 e2(Element::fromJSON(R"({"id": 2, "subnet": "10.0.1.0/24"})"));
|
||||||
ElementPtr l(Element::createList());
|
ElementPtr l;
|
||||||
l->add(e2);
|
|
||||||
|
// Test sorting by "id". Order shouldn't change.
|
||||||
|
l = Element::createList();
|
||||||
l->add(e1);
|
l->add(e1);
|
||||||
EXPECT_EQ(*l->get(0), *e2);
|
l->add(e2);
|
||||||
EXPECT_EQ(*l->get(1), *e1);
|
|
||||||
boost::dynamic_pointer_cast<ListElement>(l)->sort("id");
|
boost::dynamic_pointer_cast<ListElement>(l)->sort("id");
|
||||||
ASSERT_EQ(l->size(), 2);
|
ASSERT_EQ(l->size(), 2);
|
||||||
EXPECT_EQ(*l->get(0), *e1);
|
EXPECT_EQ(*l->get(0), *e1);
|
||||||
EXPECT_EQ(*l->get(1), *e2);
|
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) {
|
TEST(Element, removeEmptyContainersRecursively) {
|
||||||
|
Reference in New Issue
Block a user