diff options
author | mel-lain <mel-lain@yandex-team.ru> | 2022-02-10 16:50:27 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:27 +0300 |
commit | 08975a5c39bf978bb9aabc6507fc6bc97bbc1fb8 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/ipv6_address/ut | |
parent | 2ddbcd02513ed9f0ec4ebb679e962b7884a388ca (diff) | |
download | ydb-08975a5c39bf978bb9aabc6507fc6bc97bbc1fb8.tar.gz |
Restoring authorship annotation for <mel-lain@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/ipv6_address/ut')
-rw-r--r-- | library/cpp/ipv6_address/ut/ipv6_address_ut.cpp | 126 | ||||
-rw-r--r-- | library/cpp/ipv6_address/ut/ya.make | 14 |
2 files changed, 70 insertions, 70 deletions
diff --git a/library/cpp/ipv6_address/ut/ipv6_address_ut.cpp b/library/cpp/ipv6_address/ut/ipv6_address_ut.cpp index e1d6d15503..73bb7cffdd 100644 --- a/library/cpp/ipv6_address/ut/ipv6_address_ut.cpp +++ b/library/cpp/ipv6_address/ut/ipv6_address_ut.cpp @@ -1,83 +1,83 @@ #include <library/cpp/testing/unittest/registar.h> #include <library/cpp/ipv6_address/ipv6_address.h> #include <unordered_set> - + class TIpv6AddressTest: public TTestBase { - UNIT_TEST_SUITE(TIpv6AddressTest); - UNIT_TEST(ParseHostAndMayBePortFromString_data); + UNIT_TEST_SUITE(TIpv6AddressTest); + UNIT_TEST(ParseHostAndMayBePortFromString_data); UNIT_TEST(CheckAddressValidity) - UNIT_TEST_SUITE_END(); - -private: - void ParseHostAndMayBePortFromString_data(); + UNIT_TEST_SUITE_END(); + +private: + void ParseHostAndMayBePortFromString_data(); void CheckAddressValidity(); void HashCompileTest(); -}; - -UNIT_TEST_SUITE_REGISTRATION(TIpv6AddressTest); - -using TResult = std::tuple<THostAddressAndPort, TString, TIpPort>; - -TResult IpRes(TString Ip, TIpPort Port) { +}; + +UNIT_TEST_SUITE_REGISTRATION(TIpv6AddressTest); + +using TResult = std::tuple<THostAddressAndPort, TString, TIpPort>; + +TResult IpRes(TString Ip, TIpPort Port) { bool Ok; - THostAddressAndPort HostAddressAndPort; - HostAddressAndPort.Ip = TIpv6Address::FromString(Ip, Ok); - Y_VERIFY(Ok); - HostAddressAndPort.Port = Port; - return TResult(HostAddressAndPort, {}, {}); -} -TResult HostRes(TString HostName, TIpPort Port) { - return TResult({}, HostName, Port); -} - + THostAddressAndPort HostAddressAndPort; + HostAddressAndPort.Ip = TIpv6Address::FromString(Ip, Ok); + Y_VERIFY(Ok); + HostAddressAndPort.Port = Port; + return TResult(HostAddressAndPort, {}, {}); +} +TResult HostRes(TString HostName, TIpPort Port) { + return TResult({}, HostName, Port); +} + void ParseHostAndMayBePortFromString(TString RawStr, TIpPort DefaultPort, - const TResult ExpectedResult, + const TResult ExpectedResult, const bool ExpectedOk) { bool Ok = false; - const TResult ActualResult = ParseHostAndMayBePortFromString(RawStr, DefaultPort, Ok); - - UNIT_ASSERT(Ok == ExpectedOk); + const TResult ActualResult = ParseHostAndMayBePortFromString(RawStr, DefaultPort, Ok); + + UNIT_ASSERT(Ok == ExpectedOk); if (Ok == false) - return; - - UNIT_ASSERT(ActualResult == ExpectedResult); -} - + return; + + UNIT_ASSERT(ActualResult == ExpectedResult); +} + void CheckIpDefPortAgainstIpPortDefPort_v4OrHost(TString Ip, TIpPort Port, - const TResult ExpectedResult, + const TResult ExpectedResult, const bool ExpectedOk) { - ParseHostAndMayBePortFromString(Ip, Port, ExpectedResult, ExpectedOk); - - TString New = Ip + ":" + ToString(Port); - ParseHostAndMayBePortFromString(New, Port + 12, ExpectedResult, ExpectedOk); -} - -void CheckIpDefPortAgainstIpPortDefPort_v6(TString Ip, TIpPort Port, const TResult ExpectedResult, const bool ExpectedOk) { - ParseHostAndMayBePortFromString(Ip, Port, ExpectedResult, ExpectedOk); - - TString New = "[" + Ip + "]" + ":" + ToString(Port); - ParseHostAndMayBePortFromString(New, Port + 12, ExpectedResult, ExpectedOk); -} - -void CheckIpDefPortAgainstIpPortDefPort(TString Ip, TIpPort Port, const TResult ExpectedResult, const bool ExpectedOk) { + ParseHostAndMayBePortFromString(Ip, Port, ExpectedResult, ExpectedOk); + + TString New = Ip + ":" + ToString(Port); + ParseHostAndMayBePortFromString(New, Port + 12, ExpectedResult, ExpectedOk); +} + +void CheckIpDefPortAgainstIpPortDefPort_v6(TString Ip, TIpPort Port, const TResult ExpectedResult, const bool ExpectedOk) { + ParseHostAndMayBePortFromString(Ip, Port, ExpectedResult, ExpectedOk); + + TString New = "[" + Ip + "]" + ":" + ToString(Port); + ParseHostAndMayBePortFromString(New, Port + 12, ExpectedResult, ExpectedOk); +} + +void CheckIpDefPortAgainstIpPortDefPort(TString Ip, TIpPort Port, const TResult ExpectedResult, const bool ExpectedOk) { if (Ip.find(':') == TString::npos) { - CheckIpDefPortAgainstIpPortDefPort_v4OrHost(Ip, Port, ExpectedResult, ExpectedOk); - } else { - CheckIpDefPortAgainstIpPortDefPort_v6(Ip, Port, ExpectedResult, ExpectedOk); - } -} - -void TIpv6AddressTest::ParseHostAndMayBePortFromString_data() { - CheckIpDefPortAgainstIpPortDefPort("1.2.3.4", 123, IpRes("1.2.3.4", 123), true); - ParseHostAndMayBePortFromString("[1.2.3.4]", 123, {}, false); - - ParseHostAndMayBePortFromString("[2001::7348]", 123, IpRes("2001::7348", 123), true); - CheckIpDefPortAgainstIpPortDefPort("2001::7348", 123, IpRes("2001::7348", 123), true); - - CheckIpDefPortAgainstIpPortDefPort("ya.ru", 123, HostRes("ya.ru", 123), true); -} + CheckIpDefPortAgainstIpPortDefPort_v4OrHost(Ip, Port, ExpectedResult, ExpectedOk); + } else { + CheckIpDefPortAgainstIpPortDefPort_v6(Ip, Port, ExpectedResult, ExpectedOk); + } +} + +void TIpv6AddressTest::ParseHostAndMayBePortFromString_data() { + CheckIpDefPortAgainstIpPortDefPort("1.2.3.4", 123, IpRes("1.2.3.4", 123), true); + ParseHostAndMayBePortFromString("[1.2.3.4]", 123, {}, false); + + ParseHostAndMayBePortFromString("[2001::7348]", 123, IpRes("2001::7348", 123), true); + CheckIpDefPortAgainstIpPortDefPort("2001::7348", 123, IpRes("2001::7348", 123), true); + + CheckIpDefPortAgainstIpPortDefPort("ya.ru", 123, HostRes("ya.ru", 123), true); +} void TIpv6AddressTest::CheckAddressValidity() { bool Ok; diff --git a/library/cpp/ipv6_address/ut/ya.make b/library/cpp/ipv6_address/ut/ya.make index 424ca8701a..bd22899379 100644 --- a/library/cpp/ipv6_address/ut/ya.make +++ b/library/cpp/ipv6_address/ut/ya.make @@ -1,9 +1,9 @@ OWNER(g:zora) - + UNITTEST_FOR(library/cpp/ipv6_address) - -SRCS( - ipv6_address_ut.cpp -) - -END() + +SRCS( + ipv6_address_ut.cpp +) + +END() |