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

[#1308] Added address hash test

This commit is contained in:
Francis Dupont
2020-08-02 10:31:03 +02:00
committed by Tomek Mrugalski
parent 69af08bd09
commit 110e82b4a1
2 changed files with 59 additions and 0 deletions

View File

@@ -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

View File

@@ -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 <config.h>
#include <asiolink/io_address.h>
#include <gtest/gtest.h>
#include <boost/functional/hash.hpp>
#include <string>
#include <unordered_map>
#include <unordered_set>
// In fact the goal i.e. is to check if the file compiles.
using namespace isc::asiolink;
typedef boost::hash<IOAddress> hash_address;
TEST(HashAddressTest, unorderedSet) {
std::unordered_set<IOAddress, hash_address> 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<IOAddress, std::string, hash_address> 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());
}