From 110e82b4a1c73ebf76e9ca039e137dd59ccb5b87 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Sun, 2 Aug 2020 10:31:03 +0200 Subject: [PATCH] [#1308] Added address hash test --- src/lib/asiolink/tests/Makefile.am | 1 + .../asiolink/tests/hash_address_unittest.cc | 58 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/lib/asiolink/tests/hash_address_unittest.cc diff --git a/src/lib/asiolink/tests/Makefile.am b/src/lib/asiolink/tests/Makefile.am index d19c0ed094..c1e48c27b6 100644 --- a/src/lib/asiolink/tests/Makefile.am +++ b/src/lib/asiolink/tests/Makefile.am @@ -20,6 +20,7 @@ TESTS += run_unittests run_unittests_SOURCES = run_unittests.cc run_unittests_SOURCES += addr_utilities_unittest.cc run_unittests_SOURCES += io_address_unittest.cc +run_unittests_SOURCES += hash_address_unittest.cc run_unittests_SOURCES += io_endpoint_unittest.cc run_unittests_SOURCES += io_socket_unittest.cc run_unittests_SOURCES += interval_timer_unittest.cc diff --git a/src/lib/asiolink/tests/hash_address_unittest.cc b/src/lib/asiolink/tests/hash_address_unittest.cc new file mode 100644 index 0000000000..50fa43fa7f --- /dev/null +++ b/src/lib/asiolink/tests/hash_address_unittest.cc @@ -0,0 +1,58 @@ +// Copyright (C) 2020 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include +#include +#include +#include +#include +#include +#include + +// In fact the goal i.e. is to check if the file compiles. + +using namespace isc::asiolink; + +typedef boost::hash hash_address; + +TEST(HashAddressTest, unorderedSet) { + std::unordered_set set; + EXPECT_TRUE(set.empty()); + EXPECT_EQ(0, set.size()); + + IOAddress addr("192.168.2.1"); + EXPECT_EQ(set.end(), set.find(addr)); + EXPECT_EQ(0, set.count(addr)); + + EXPECT_NO_THROW(set.insert(addr)); + EXPECT_FALSE(set.empty()); + EXPECT_EQ(1, set.size()); + EXPECT_NE(set.end(), set.find(addr)); + EXPECT_EQ(1, set.count(addr)); + + EXPECT_NO_THROW(set.clear()); + EXPECT_TRUE(set.empty()); +} + +TEST(HashAddressTest, unorderedMap) { + std::unordered_map map; + EXPECT_TRUE(map.empty()); + EXPECT_EQ(0, map.size()); + + IOAddress addr("192.168.2.1"); + EXPECT_EQ(map.end(), map.find(addr)); + EXPECT_EQ(0, map.count(addr)); + + std::string str("my-address"); + EXPECT_NO_THROW(map[addr] = str); + EXPECT_FALSE(map.empty()); + EXPECT_EQ(1, map.size()); + EXPECT_NE(map.end(), map.find(addr)); + EXPECT_EQ(1, map.count(addr)); + + EXPECT_NO_THROW(map.clear()); + EXPECT_TRUE(map.empty()); +}