From 03240bb273b3f570029e5e1da272df37d5b103ef Mon Sep 17 00:00:00 2001 From: mohsaka <135669458+mohsaka@users.noreply.github.com> Date: Fri, 28 Jun 2024 13:28:21 -0700 Subject: [PATCH] Format --- .../functions/prestosql/IPAddressFunctions.h | 95 ++++----- .../tests/IPAddressFunctionsTest.cpp | 193 ++++++++++-------- 2 files changed, 149 insertions(+), 139 deletions(-) diff --git a/velox/functions/prestosql/IPAddressFunctions.h b/velox/functions/prestosql/IPAddressFunctions.h index cfd498ca4a6ec..a2542a25f3616 100644 --- a/velox/functions/prestosql/IPAddressFunctions.h +++ b/velox/functions/prestosql/IPAddressFunctions.h @@ -43,7 +43,7 @@ struct IPAddressFunction { boost::uuids::random_generator generator_; }; -inline bool isIPV4(int128_t ip){ +inline bool isIPV4(int128_t ip) { int128_t ipV4 = 0x0000FFFF00000000; int128_t mask = 0xFFFFFFFFFFFFFFFF; mask = (mask << 64) | 0xFFFFFFFF00000000; @@ -93,28 +93,26 @@ struct IPPrefixFunction { result = std::make_shared(canonicalAddrInt, prefix); } - FOLLY_ALWAYS_INLINE void call( + FOLLY_ALWAYS_INLINE void call( out_type& result, const arg_type& ip, const arg_type prefixBits) { - - boost::asio::ip::address_v6::bytes_type addrBytes; - auto addr = boost::asio::ip::make_address(ip); - int128_t intAddr; - if (addr.is_v4()) { - addrBytes = boost::asio::ip::make_address_v6( - boost::asio::ip::v4_mapped, addr.to_v4()) - .to_bytes(); - } else { - addrBytes = addr.to_v6().to_bytes(); - } + boost::asio::ip::address_v6::bytes_type addrBytes; + auto addr = boost::asio::ip::make_address(ip); + int128_t intAddr; + if (addr.is_v4()) { + addrBytes = boost::asio::ip::make_address_v6( + boost::asio::ip::v4_mapped, addr.to_v4()) + .to_bytes(); + } else { + addrBytes = addr.to_v6().to_bytes(); + } - bigEndianByteArray(addrBytes); - memcpy(&intAddr, &addrBytes, 16); + bigEndianByteArray(addrBytes); + memcpy(&intAddr, &addrBytes, 16); - call(result, intAddr, prefixBits); - - } + call(result, intAddr, prefixBits); + } }; template @@ -129,26 +127,26 @@ struct IPSubnetMinFunction { } }; -inline int128_t getIPSubnetMax(int128_t ip, uint8_t prefix){ - // Presto stores prefixBits in one signed byte. Cast to unsigned - uint128_t mask = 1; - int128_t result; - boost::asio::ip::address_v6::bytes_type addrBytes; - memcpy(&result, &ip, 16); +inline int128_t getIPSubnetMax(int128_t ip, uint8_t prefix) { + // Presto stores prefixBits in one signed byte. Cast to unsigned + uint128_t mask = 1; + int128_t result; + boost::asio::ip::address_v6::bytes_type addrBytes; + memcpy(&result, &ip, 16); - if (isIPV4(ip)) { - if (prefix < 32) { - result |= (mask << 32 - prefix) - 1; - } - } else { - // Special case. Return all bits set to 1; - if (prefix == 0) { - result = -1; - } else if (prefix < 128) { - result |= (mask << 128 - prefix) - 1; - } + if (isIPV4(ip)) { + if (prefix < 32) { + result |= (mask << 32 - prefix) - 1; } - return result; + } else { + // Special case. Return all bits set to 1; + if (prefix == 0) { + result = -1; + } else if (prefix < 128) { + result |= (mask << 128 - prefix) - 1; + } + } + return result; } template @@ -158,8 +156,7 @@ struct IPSubnetMaxFunction { FOLLY_ALWAYS_INLINE void call( out_type& result, const arg_type& ipPrefix) { - - result = getIPSubnetMax(ipPrefix->ip, (uint8_t)ipPrefix->prefix); + result = getIPSubnetMax(ipPrefix->ip, (uint8_t)ipPrefix->prefix); } }; @@ -170,9 +167,8 @@ struct IPSubnetRangeFunction { FOLLY_ALWAYS_INLINE void call( out_type>& result, const arg_type& ipPrefix) { - - result.push_back(ipPrefix->ip); - result.push_back(getIPSubnetMax(ipPrefix->ip, (uint8_t)ipPrefix->prefix)); + result.push_back(ipPrefix->ip); + result.push_back(getIPSubnetMax(ipPrefix->ip, (uint8_t)ipPrefix->prefix)); } }; @@ -180,14 +176,13 @@ template struct IPSubnetOfFunction { VELOX_DEFINE_FUNCTION_TYPES(T); FOLLY_ALWAYS_INLINE void call( - out_type& result, - const arg_type& ipPrefix, - const arg_type& ip) { - + out_type& result, + const arg_type& ipPrefix, + const arg_type& ip) { uint128_t mask = 1; uint8_t prefix = (uint8_t)ipPrefix->prefix; int128_t checkIP = ip; - + if (isIPV4(ipPrefix->ip)) { if (prefix < 32) { checkIP &= ((mask << 32 - prefix) - 1) ^ -1; @@ -201,13 +196,11 @@ struct IPSubnetOfFunction { } FOLLY_ALWAYS_INLINE void call( - out_type& result, - const arg_type& ipPrefix, - const arg_type& ipPrefix2) { - + out_type& result, + const arg_type& ipPrefix, + const arg_type& ipPrefix2) { call(result, ipPrefix, ipPrefix2->ip); result = result && (ipPrefix2->prefix >= ipPrefix->prefix); - } }; diff --git a/velox/functions/prestosql/tests/IPAddressFunctionsTest.cpp b/velox/functions/prestosql/tests/IPAddressFunctionsTest.cpp index 10bca2241b363..27cf543713e3c 100644 --- a/velox/functions/prestosql/tests/IPAddressFunctionsTest.cpp +++ b/velox/functions/prestosql/tests/IPAddressFunctionsTest.cpp @@ -68,10 +68,12 @@ class IPAddressTest : public functions::test::FunctionBaseTest { } std::optional getIsSubnetOfIP( - const std::optional prefix, + const std::optional prefix, const std::optional ip) { auto result = evaluateOnce( - "is_subnet_of(cast(c0 as ipprefix), cast(c1 as ipaddress))", prefix, ip); + "is_subnet_of(cast(c0 as ipprefix), cast(c1 as ipaddress))", + prefix, + ip); return result; } @@ -79,10 +81,11 @@ class IPAddressTest : public functions::test::FunctionBaseTest { const std::optional prefix, const std::optional prefix2) { auto result = evaluateOnce( - "is_subnet_of(cast(c0 as ipprefix), cast(c1 as ipprefix))", prefix, prefix2); + "is_subnet_of(cast(c0 as ipprefix), cast(c1 as ipprefix))", + prefix, + prefix2); return result; } - }; TEST_F(IPAddressTest, castAsVarchar) { @@ -133,7 +136,8 @@ TEST_F(IPAddressTest, IPPrefixv4) { TEST_F(IPAddressTest, IPPrefixv4UsingVarchar) { EXPECT_EQ("10.0.0.0/8", getIPPrefixUsingVarchar("10.135.23.12", 8)); EXPECT_EQ("192.128.0.0/9", getIPPrefixUsingVarchar("192.168.255.255", 9)); - EXPECT_EQ("192.168.255.255/32", getIPPrefixUsingVarchar("192.168.255.255", 32)); + EXPECT_EQ( + "192.168.255.255/32", getIPPrefixUsingVarchar("192.168.255.255", 32)); EXPECT_EQ("0.0.0.0/0", getIPPrefixUsingVarchar("192.168.255.255", 0)); EXPECT_THROW(getIPPrefixUsingVarchar("12.483.09.1", 8), VeloxUserError); @@ -181,16 +185,20 @@ TEST_F(IPAddressTest, IPPrefixv6UsingVarchar) { EXPECT_EQ( "2001:db8:85a3:1:1:8a2e:370:7334/128", getIPPrefixUsingVarchar("2001:0db8:85a3:0001:0001:8a2e:0370:7334", 128)); - EXPECT_EQ("::/0", getIPPrefixUsingVarchar("2001:0db8:85a3:0001:0001:8a2e:0370:7334", 0)); + EXPECT_EQ( + "::/0", + getIPPrefixUsingVarchar("2001:0db8:85a3:0001:0001:8a2e:0370:7334", 0)); EXPECT_THROW( getIPPrefixUsingVarchar("q001:0db8:85a3:0001:0001:8a2e:0370:7334", 8), VeloxUserError); EXPECT_THROW( - getIPPrefixUsingVarchar("2001:0db8:85a3:542e:0001:0001:8a2e:0370:7334", 8), + getIPPrefixUsingVarchar( + "2001:0db8:85a3:542e:0001:0001:8a2e:0370:7334", 8), VeloxUserError); EXPECT_THROW( - getIPPrefixUsingVarchar("2001:0db8:85a3:0001:0001:8a2e:0370", 8), VeloxUserError); + getIPPrefixUsingVarchar("2001:0db8:85a3:0001:0001:8a2e:0370", 8), + VeloxUserError); EXPECT_THROW( getIPPrefixUsingVarchar("2001:0db8:85a3:0001:0001:8a2e:0370:7334", -1), VeloxUserError); @@ -200,40 +208,39 @@ TEST_F(IPAddressTest, IPPrefixv6UsingVarchar) { } TEST_F(IPAddressTest, IPPrefixPrestoTests) { - EXPECT_EQ(getIPPrefix("1.2.3.4", 24), "1.2.3.0/24"); - EXPECT_EQ(getIPPrefix( "1.2.3.4", 32), "1.2.3.4/32"); - EXPECT_EQ(getIPPrefix( "1.2.3.4", 0), "0.0.0.0/0"); - EXPECT_EQ(getIPPrefix( "::ffff:1.2.3.4", 24), "1.2.3.0/24"); - EXPECT_EQ(getIPPrefix( "64:ff9b::17", 64), "64:ff9b::/64"); - EXPECT_EQ(getIPPrefix( "64:ff9b::17", 127), "64:ff9b::16/127"); - EXPECT_EQ(getIPPrefix( "64:ff9b::17", 128), "64:ff9b::17/128"); - EXPECT_EQ(getIPPrefix( "64:ff9b::17", 0), "::/0"); - EXPECT_THROW(getIPPrefix( "::ffff:1.2.3.4", -1), VeloxUserError); - EXPECT_THROW(getIPPrefix( "::ffff:1.2.3.4", 33), VeloxUserError); - EXPECT_THROW(getIPPrefix( "64:ff9b::10", -1), VeloxUserError); - EXPECT_THROW(getIPPrefix( "64:ff9b::10", 129), VeloxUserError); + EXPECT_EQ(getIPPrefix("1.2.3.4", 24), "1.2.3.0/24"); + EXPECT_EQ(getIPPrefix("1.2.3.4", 32), "1.2.3.4/32"); + EXPECT_EQ(getIPPrefix("1.2.3.4", 0), "0.0.0.0/0"); + EXPECT_EQ(getIPPrefix("::ffff:1.2.3.4", 24), "1.2.3.0/24"); + EXPECT_EQ(getIPPrefix("64:ff9b::17", 64), "64:ff9b::/64"); + EXPECT_EQ(getIPPrefix("64:ff9b::17", 127), "64:ff9b::16/127"); + EXPECT_EQ(getIPPrefix("64:ff9b::17", 128), "64:ff9b::17/128"); + EXPECT_EQ(getIPPrefix("64:ff9b::17", 0), "::/0"); + EXPECT_THROW(getIPPrefix("::ffff:1.2.3.4", -1), VeloxUserError); + EXPECT_THROW(getIPPrefix("::ffff:1.2.3.4", 33), VeloxUserError); + EXPECT_THROW(getIPPrefix("64:ff9b::10", -1), VeloxUserError); + EXPECT_THROW(getIPPrefix("64:ff9b::10", 129), VeloxUserError); } TEST_F(IPAddressTest, IPPrefixVarcharPrestoTests) { - EXPECT_EQ(getIPPrefixUsingVarchar("1.2.3.4", 24), "1.2.3.0/24"); - EXPECT_EQ(getIPPrefixUsingVarchar("1.2.3.4", 32), "1.2.3.4/32"); - EXPECT_EQ(getIPPrefixUsingVarchar("1.2.3.4", 0), "0.0.0.0/0"); - EXPECT_EQ(getIPPrefixUsingVarchar("::ffff:1.2.3.4", 24), "1.2.3.0/24"); - EXPECT_EQ(getIPPrefixUsingVarchar("64:ff9b::17", 64), "64:ff9b::/64"); - EXPECT_EQ(getIPPrefixUsingVarchar("64:ff9b::17", 127), "64:ff9b::16/127"); - EXPECT_EQ(getIPPrefixUsingVarchar("64:ff9b::17", 128), "64:ff9b::17/128"); - EXPECT_EQ(getIPPrefixUsingVarchar("64:ff9b::17", 0), "::/0"); - EXPECT_THROW(getIPPrefixUsingVarchar("::ffff:1.2.3.4", -1), VeloxUserError); - EXPECT_THROW(getIPPrefixUsingVarchar("::ffff:1.2.3.4", 33), VeloxUserError); - EXPECT_THROW(getIPPrefixUsingVarchar("64:ff9b::10", -1), VeloxUserError); - EXPECT_THROW(getIPPrefixUsingVarchar("64:ff9b::10", 129), VeloxUserError); - EXPECT_THROW(getIPPrefixUsingVarchar("localhost", 24), VeloxUserError); - EXPECT_THROW(getIPPrefixUsingVarchar("64::ff9b::10", 24), VeloxUserError); - EXPECT_THROW(getIPPrefixUsingVarchar("64:face:book::10", 24), VeloxUserError); - EXPECT_THROW(getIPPrefixUsingVarchar("123.456.789.012", 24), VeloxUserError); + EXPECT_EQ(getIPPrefixUsingVarchar("1.2.3.4", 24), "1.2.3.0/24"); + EXPECT_EQ(getIPPrefixUsingVarchar("1.2.3.4", 32), "1.2.3.4/32"); + EXPECT_EQ(getIPPrefixUsingVarchar("1.2.3.4", 0), "0.0.0.0/0"); + EXPECT_EQ(getIPPrefixUsingVarchar("::ffff:1.2.3.4", 24), "1.2.3.0/24"); + EXPECT_EQ(getIPPrefixUsingVarchar("64:ff9b::17", 64), "64:ff9b::/64"); + EXPECT_EQ(getIPPrefixUsingVarchar("64:ff9b::17", 127), "64:ff9b::16/127"); + EXPECT_EQ(getIPPrefixUsingVarchar("64:ff9b::17", 128), "64:ff9b::17/128"); + EXPECT_EQ(getIPPrefixUsingVarchar("64:ff9b::17", 0), "::/0"); + EXPECT_THROW(getIPPrefixUsingVarchar("::ffff:1.2.3.4", -1), VeloxUserError); + EXPECT_THROW(getIPPrefixUsingVarchar("::ffff:1.2.3.4", 33), VeloxUserError); + EXPECT_THROW(getIPPrefixUsingVarchar("64:ff9b::10", -1), VeloxUserError); + EXPECT_THROW(getIPPrefixUsingVarchar("64:ff9b::10", 129), VeloxUserError); + EXPECT_THROW(getIPPrefixUsingVarchar("localhost", 24), VeloxUserError); + EXPECT_THROW(getIPPrefixUsingVarchar("64::ff9b::10", 24), VeloxUserError); + EXPECT_THROW(getIPPrefixUsingVarchar("64:face:book::10", 24), VeloxUserError); + EXPECT_THROW(getIPPrefixUsingVarchar("123.456.789.012", 24), VeloxUserError); } - TEST_F(IPAddressTest, castRoundTripPrefix) { auto strings = makeFlatVector( {"87a0:ce14:8989::/48", "7800::/5", "192.0.0.0/5"}); @@ -268,12 +275,12 @@ TEST_F(IPAddressTest, IPSubnetMin) { } TEST_F(IPAddressTest, IPSubnetMinPrestoTests) { - EXPECT_EQ(getIPSubnetMin("1.2.3.4/24"), "1.2.3.0"); - EXPECT_EQ(getIPSubnetMin("1.2.3.4/32"), "1.2.3.4"); - EXPECT_EQ(getIPSubnetMin("64:ff9b::17/64"), "64:ff9b::"); - EXPECT_EQ(getIPSubnetMin("64:ff9b::17/127"), "64:ff9b::16"); - EXPECT_EQ(getIPSubnetMin("64:ff9b::17/128"), "64:ff9b::17"); - EXPECT_EQ(getIPSubnetMin("64:ff9b::17/0"), "::"); + EXPECT_EQ(getIPSubnetMin("1.2.3.4/24"), "1.2.3.0"); + EXPECT_EQ(getIPSubnetMin("1.2.3.4/32"), "1.2.3.4"); + EXPECT_EQ(getIPSubnetMin("64:ff9b::17/64"), "64:ff9b::"); + EXPECT_EQ(getIPSubnetMin("64:ff9b::17/127"), "64:ff9b::16"); + EXPECT_EQ(getIPSubnetMin("64:ff9b::17/128"), "64:ff9b::17"); + EXPECT_EQ(getIPSubnetMin("64:ff9b::17/0"), "::"); } TEST_F(IPAddressTest, IPSubnetMax) { @@ -301,14 +308,16 @@ TEST_F(IPAddressTest, IPSubnetMax) { } TEST_F(IPAddressTest, IPSubnetMaxPrestoTests) { - EXPECT_EQ(getIPSubnetMax("1.2.3.128/26"),"1.2.3.191"); - EXPECT_EQ(getIPSubnetMax("192.168.128.4/32"), "192.168.128.4"); - EXPECT_EQ(getIPSubnetMax("10.1.16.3/9"), "10.127.255.255"); - EXPECT_EQ(getIPSubnetMax("2001:db8::16/127"), "2001:db8::17"); - EXPECT_EQ(getIPSubnetMax("2001:db8::16/128"), "2001:db8::16"); - EXPECT_EQ(getIPSubnetMax("64:ff9b::17/64"), "64:ff9b::ffff:ffff:ffff:ffff"); - EXPECT_EQ(getIPSubnetMax("64:ff9b::17/72"), "64:ff9b::ff:ffff:ffff:ffff"); - EXPECT_EQ(getIPSubnetMax("64:ff9b::17/0"), "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); + EXPECT_EQ(getIPSubnetMax("1.2.3.128/26"), "1.2.3.191"); + EXPECT_EQ(getIPSubnetMax("192.168.128.4/32"), "192.168.128.4"); + EXPECT_EQ(getIPSubnetMax("10.1.16.3/9"), "10.127.255.255"); + EXPECT_EQ(getIPSubnetMax("2001:db8::16/127"), "2001:db8::17"); + EXPECT_EQ(getIPSubnetMax("2001:db8::16/128"), "2001:db8::16"); + EXPECT_EQ(getIPSubnetMax("64:ff9b::17/64"), "64:ff9b::ffff:ffff:ffff:ffff"); + EXPECT_EQ(getIPSubnetMax("64:ff9b::17/72"), "64:ff9b::ff:ffff:ffff:ffff"); + EXPECT_EQ( + getIPSubnetMax("64:ff9b::17/0"), + "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); } TEST_F(IPAddressTest, IPSubnetRange) { @@ -334,8 +343,10 @@ TEST_F(IPAddressTest, IPSubnetRange) { "2001:db8:85a3:ffff:ffff:ffff:ffff:ffff", getIPSubnetRangeMax("2001:0db8:85a3:0001:0001:8a2e:0370:7334/48")); - EXPECT_EQ("::", getIPSubnetRangeMin("2001:0db8:85a3:0001:0001:8a2e:0370:7334/0")); - EXPECT_EQ("::", getIPSubnetRangeMin("2001:0db8:85a3:0001:0001:8a2e:0370:7334/1")); + EXPECT_EQ( + "::", getIPSubnetRangeMin("2001:0db8:85a3:0001:0001:8a2e:0370:7334/0")); + EXPECT_EQ( + "::", getIPSubnetRangeMin("2001:0db8:85a3:0001:0001:8a2e:0370:7334/1")); EXPECT_EQ( "2001:db8:85a3:1:1:8a2e:370:7334", getIPSubnetRangeMin("2001:0db8:85a3:0001:0001:8a2e:0370:7334/127")); @@ -357,54 +368,60 @@ TEST_F(IPAddressTest, IPSubnetRange) { getIPSubnetRangeMax("2001:0db8:85a3:0001:0001:8a2e:0370:7334/128")); } -TEST_F(IPAddressTest, IPSubnetRangePrestoTests){ - EXPECT_EQ(getIPSubnetRangeMin("1.2.3.160/24"), "1.2.3.0"); - EXPECT_EQ(getIPSubnetRangeMin("1.2.3.128/31"), "1.2.3.128"); - EXPECT_EQ(getIPSubnetRangeMin("10.1.6.46/32"), "10.1.6.46"); - EXPECT_EQ(getIPSubnetRangeMin("10.1.6.46/0"), "0.0.0.0"); - EXPECT_EQ(getIPSubnetRangeMin("64:ff9b::17/64"), "64:ff9b::"); - EXPECT_EQ(getIPSubnetRangeMin("64:ff9b::52f4/120"), "64:ff9b::5200"); - EXPECT_EQ(getIPSubnetRangeMin("64:ff9b::17/128"), "64:ff9b::17"); - - EXPECT_EQ(getIPSubnetRangeMax("1.2.3.160/24"), "1.2.3.255"); - EXPECT_EQ(getIPSubnetRangeMax("1.2.3.128/31"), "1.2.3.129"); - EXPECT_EQ(getIPSubnetRangeMax("10.1.6.46/32"), "10.1.6.46"); - EXPECT_EQ(getIPSubnetRangeMax("10.1.6.46/0"), "255.255.255.255"); - EXPECT_EQ(getIPSubnetRangeMax("64:ff9b::17/64"), "64:ff9b::ffff:ffff:ffff:ffff"); - EXPECT_EQ(getIPSubnetRangeMax("64:ff9b::52f4/120"), "64:ff9b::52ff"); - EXPECT_EQ(getIPSubnetRangeMax("64:ff9b::17/128"), "64:ff9b::17"); +TEST_F(IPAddressTest, IPSubnetRangePrestoTests) { + EXPECT_EQ(getIPSubnetRangeMin("1.2.3.160/24"), "1.2.3.0"); + EXPECT_EQ(getIPSubnetRangeMin("1.2.3.128/31"), "1.2.3.128"); + EXPECT_EQ(getIPSubnetRangeMin("10.1.6.46/32"), "10.1.6.46"); + EXPECT_EQ(getIPSubnetRangeMin("10.1.6.46/0"), "0.0.0.0"); + EXPECT_EQ(getIPSubnetRangeMin("64:ff9b::17/64"), "64:ff9b::"); + EXPECT_EQ(getIPSubnetRangeMin("64:ff9b::52f4/120"), "64:ff9b::5200"); + EXPECT_EQ(getIPSubnetRangeMin("64:ff9b::17/128"), "64:ff9b::17"); + + EXPECT_EQ(getIPSubnetRangeMax("1.2.3.160/24"), "1.2.3.255"); + EXPECT_EQ(getIPSubnetRangeMax("1.2.3.128/31"), "1.2.3.129"); + EXPECT_EQ(getIPSubnetRangeMax("10.1.6.46/32"), "10.1.6.46"); + EXPECT_EQ(getIPSubnetRangeMax("10.1.6.46/0"), "255.255.255.255"); + EXPECT_EQ( + getIPSubnetRangeMax("64:ff9b::17/64"), "64:ff9b::ffff:ffff:ffff:ffff"); + EXPECT_EQ(getIPSubnetRangeMax("64:ff9b::52f4/120"), "64:ff9b::52ff"); + EXPECT_EQ(getIPSubnetRangeMax("64:ff9b::17/128"), "64:ff9b::17"); } TEST_F(IPAddressTest, IPSubnetOfIPAddress) { - EXPECT_EQ(getIsSubnetOfIP("1.2.3.128/26","1.2.3.129"), true); + EXPECT_EQ(getIsSubnetOfIP("1.2.3.128/26", "1.2.3.129"), true); EXPECT_EQ(getIsSubnetOfIP("64:fa9b::17/64", "64:ffff::17"), false); } TEST_F(IPAddressTest, IPSubnetOfIPPrefix) { - EXPECT_EQ(getIsSubnetOfIPPrefix("192.168.3.131/26", "192.168.3.144/30"), true); + EXPECT_EQ( + getIsSubnetOfIPPrefix("192.168.3.131/26", "192.168.3.144/30"), true); EXPECT_EQ(getIsSubnetOfIPPrefix("64:ff9b::17/64", "64:ffff::17/64"), false); EXPECT_EQ(getIsSubnetOfIPPrefix("64:ff9b::17/32", "64:ffff::17/24"), false); EXPECT_EQ(getIsSubnetOfIPPrefix("64:ffff::17/24", "64:ff9b::17/32"), true); - EXPECT_EQ(getIsSubnetOfIPPrefix("192.168.3.131/26", "192.168.3.131/26"), true); + EXPECT_EQ( + getIsSubnetOfIPPrefix("192.168.3.131/26", "192.168.3.131/26"), true); } TEST_F(IPAddressTest, IPSubnetOfPrestoTests) { - EXPECT_EQ(getIsSubnetOfIP("1.2.3.128/26", "1.2.3.129"), true); - EXPECT_EQ(getIsSubnetOfIP("1.2.3.128/26", "1.2.5.1"), false); - EXPECT_EQ(getIsSubnetOfIP("1.2.3.128/32", "1.2.3.128"), true); - EXPECT_EQ(getIsSubnetOfIP("1.2.3.128/0", "192.168.5.1"), true); - EXPECT_EQ(getIsSubnetOfIP("64:ff9b::17/64", "64:ff9b::ffff:ff"), true); - EXPECT_EQ(getIsSubnetOfIP("64:ff9b::17/64", "64:ffff::17"), false); - - EXPECT_EQ(getIsSubnetOfIPPrefix("192.168.3.131/26", "192.168.3.144/30"), true); - EXPECT_EQ(getIsSubnetOfIPPrefix("1.2.3.128/26", "1.2.5.1/30"), false); - EXPECT_EQ(getIsSubnetOfIPPrefix("1.2.3.128/26", "1.2.3.128/26"), true); - EXPECT_EQ(getIsSubnetOfIPPrefix("64:ff9b::17/64", "64:ff9b::ff:25/80"), true); - EXPECT_EQ(getIsSubnetOfIPPrefix("64:ff9b::17/64", "64:ffff::17/64"), false); - EXPECT_EQ(getIsSubnetOfIPPrefix("2804:431:b000::/37", "2804:431:b000::/38"), true); - EXPECT_EQ(getIsSubnetOfIPPrefix("2804:431:b000::/38", "2804:431:b000::/37"), false); - EXPECT_EQ(getIsSubnetOfIPPrefix("170.0.52.0/22", "170.0.52.0/24"), true); - EXPECT_EQ(getIsSubnetOfIPPrefix("170.0.52.0/24", "170.0.52.0/22"), false); + EXPECT_EQ(getIsSubnetOfIP("1.2.3.128/26", "1.2.3.129"), true); + EXPECT_EQ(getIsSubnetOfIP("1.2.3.128/26", "1.2.5.1"), false); + EXPECT_EQ(getIsSubnetOfIP("1.2.3.128/32", "1.2.3.128"), true); + EXPECT_EQ(getIsSubnetOfIP("1.2.3.128/0", "192.168.5.1"), true); + EXPECT_EQ(getIsSubnetOfIP("64:ff9b::17/64", "64:ff9b::ffff:ff"), true); + EXPECT_EQ(getIsSubnetOfIP("64:ff9b::17/64", "64:ffff::17"), false); + + EXPECT_EQ( + getIsSubnetOfIPPrefix("192.168.3.131/26", "192.168.3.144/30"), true); + EXPECT_EQ(getIsSubnetOfIPPrefix("1.2.3.128/26", "1.2.5.1/30"), false); + EXPECT_EQ(getIsSubnetOfIPPrefix("1.2.3.128/26", "1.2.3.128/26"), true); + EXPECT_EQ(getIsSubnetOfIPPrefix("64:ff9b::17/64", "64:ff9b::ff:25/80"), true); + EXPECT_EQ(getIsSubnetOfIPPrefix("64:ff9b::17/64", "64:ffff::17/64"), false); + EXPECT_EQ( + getIsSubnetOfIPPrefix("2804:431:b000::/37", "2804:431:b000::/38"), true); + EXPECT_EQ( + getIsSubnetOfIPPrefix("2804:431:b000::/38", "2804:431:b000::/37"), false); + EXPECT_EQ(getIsSubnetOfIPPrefix("170.0.52.0/22", "170.0.52.0/24"), true); + EXPECT_EQ(getIsSubnetOfIPPrefix("170.0.52.0/24", "170.0.52.0/22"), false); } } // namespace