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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user