1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-28 20:44:26 +01:00

Don't convert IPv6Address to string when hashing

This commit is contained in:
Matias Fontanini
2017-10-01 20:33:06 -07:00
parent a6817528bc
commit db0fb7f20d
2 changed files with 24 additions and 5 deletions

View File

@@ -5,10 +5,10 @@
#include <sstream>
#include <stdint.h>
#include <tins/ipv6_address.h>
#include <tins/macros.h>
using namespace Tins;
const uint8_t empty_addr[IPv6Address::address_size] = { 0 };
void test_to_string(const std::string& str) {
@@ -123,3 +123,17 @@ TEST(IPv6AddressTest, MaskAddress) {
IPv6Address("deaf:beef:adad:beef::") & IPv6Address("ffff:e000::")
);
}
#if TINS_IS_CXX11
TEST(IPv6AddressTest, HashTest) {
using std::hash;
const auto hasher = [](const IPv6Address& address) {
return hash<IPv6Address>()(address);
};
EXPECT_NE(hasher("dead:beef::"), hasher("dead:beef::1"));
EXPECT_NE(hasher("dead:beef::"), hasher("feed:dead::1"));
EXPECT_EQ(hasher("dead:beef::"), hasher("dead:beef::"));
}
#endif