Changeset View
Changeset View
Standalone View
Standalone View
src/test/netbase_tests.cpp
// Copyright (c) 2012-2016 The Bitcoin Core developers | // Copyright (c) 2012-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "netbase.h" | #include "netbase.h" | ||||
#include "test/test_bitcoin.h" | #include "test/test_bitcoin.h" | ||||
#include <string> | #include <string> | ||||
#include <boost/assign/list_of.hpp> | |||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
BOOST_FIXTURE_TEST_SUITE(netbase_tests, BasicTestingSetup) | BOOST_FIXTURE_TEST_SUITE(netbase_tests, BasicTestingSetup) | ||||
static CNetAddr ResolveIP(const char *ip) { | static CNetAddr ResolveIP(const char *ip) { | ||||
CNetAddr addr; | CNetAddr addr; | ||||
LookupHost(ip, addr, false); | LookupHost(ip, addr, false); | ||||
return addr; | return addr; | ||||
▲ Show 20 Lines • Show All 253 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(subnet_test) { | ||||
BOOST_CHECK_EQUAL( | BOOST_CHECK_EQUAL( | ||||
subnet.ToString(), | subnet.ToString(), | ||||
"1:2:3:4:5:6:7:8/ffff:ffff:ffff:fffe:ffff:ffff:ffff:ff0f"); | "1:2:3:4:5:6:7:8/ffff:ffff:ffff:fffe:ffff:ffff:ffff:ff0f"); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(netbase_getgroup) { | BOOST_AUTO_TEST_CASE(netbase_getgroup) { | ||||
BOOST_CHECK(ResolveIP("127.0.0.1").GetGroup() == | BOOST_CHECK(ResolveIP("127.0.0.1").GetGroup() == | ||||
boost::assign::list_of(0)); // Local -> !Routable() | std::vector<uint8_t>({0})); // Local -> !Routable() | ||||
deadalnix: I think you can do
std::vector<uint8_t>{0}
But I haven't followed the latest C++… | |||||
CCulianuAuthorUnsubmitted Not Done Inline ActionsYeah you can and it will be much more readable, good point. CCulianu: Yeah you can and it will be much more readable, good point.
| |||||
deadalnixUnsubmitted Not Done Inline ActionsIt works. deadalnix: It works. | |||||
BOOST_CHECK(ResolveIP("257.0.0.1").GetGroup() == | BOOST_CHECK(ResolveIP("257.0.0.1").GetGroup() == | ||||
boost::assign::list_of(0)); // !Valid -> !Routable() | std::vector<uint8_t>({0})); // !Valid -> !Routable() | ||||
BOOST_CHECK(ResolveIP("10.0.0.1").GetGroup() == | BOOST_CHECK(ResolveIP("10.0.0.1").GetGroup() == | ||||
boost::assign::list_of(0)); // RFC1918 -> !Routable() | std::vector<uint8_t>({0})); // RFC1918 -> !Routable() | ||||
BOOST_CHECK(ResolveIP("169.254.1.1").GetGroup() == | BOOST_CHECK(ResolveIP("169.254.1.1").GetGroup() == | ||||
boost::assign::list_of(0)); // RFC3927 -> !Routable() | std::vector<uint8_t>({0})); // RFC3927 -> !Routable() | ||||
BOOST_CHECK(ResolveIP("1.2.3.4").GetGroup() == | BOOST_CHECK(ResolveIP("1.2.3.4").GetGroup() == | ||||
boost::assign::list_of((uint8_t)NET_IPV4)(1)(2)); // IPv4 | std::vector<uint8_t>({uint8_t(NET_IPV4), 1, 2})); // IPv4 | ||||
deadalnixUnsubmitted Not Done Inline ActionsC++ style constructor instead of C style casts. deadalnix: C++ style constructor instead of C style casts. | |||||
CCulianuAuthorUnsubmitted Not Done Inline ActionsWhat do you think of this? Note due to the BOOST_CHECK macro, I had to do: Vec8({1,2,3,4}) rather than the more succinct: Vec8{1,2,3,4} CCulianu: What do you think of this? Note due to the BOOST_CHECK macro, I had to do:
Vec8({1,2,3… | |||||
BOOST_CHECK(ResolveIP("::FFFF:0:102:304").GetGroup() == | BOOST_CHECK(ResolveIP("::FFFF:0:102:304").GetGroup() == | ||||
boost::assign::list_of((uint8_t)NET_IPV4)(1)(2)); // RFC6145 | std::vector<uint8_t>({uint8_t(NET_IPV4), 1, 2})); // RFC6145 | ||||
BOOST_CHECK(ResolveIP("64:FF9B::102:304").GetGroup() == | BOOST_CHECK(ResolveIP("64:FF9B::102:304").GetGroup() == | ||||
boost::assign::list_of((uint8_t)NET_IPV4)(1)(2)); // RFC6052 | std::vector<uint8_t>({(uint8_t)NET_IPV4, 1, 2})); // RFC6052 | ||||
BOOST_CHECK(ResolveIP("2002:102:304:9999:9999:9999:9999:9999").GetGroup() == | BOOST_CHECK(ResolveIP("2002:102:304:9999:9999:9999:9999:9999").GetGroup() == | ||||
boost::assign::list_of((uint8_t)NET_IPV4)(1)(2)); // RFC3964 | std::vector<uint8_t>({(uint8_t)NET_IPV4, 1, 2})); // RFC3964 | ||||
BOOST_CHECK(ResolveIP("2001:0:9999:9999:9999:9999:FEFD:FCFB").GetGroup() == | BOOST_CHECK(ResolveIP("2001:0:9999:9999:9999:9999:FEFD:FCFB").GetGroup() == | ||||
boost::assign::list_of((uint8_t)NET_IPV4)(1)(2)); // RFC4380 | std::vector<uint8_t>({(uint8_t)NET_IPV4, 1, 2})); // RFC4380 | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
ResolveIP("FD87:D87E:EB43:edb1:8e4:3588:e546:35ca").GetGroup() == | ResolveIP("FD87:D87E:EB43:edb1:8e4:3588:e546:35ca").GetGroup() == | ||||
boost::assign::list_of((uint8_t)NET_TOR)(239)); // Tor | std::vector<uint8_t>({(uint8_t)NET_TOR, 239})); // Tor | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
ResolveIP("2001:470:abcd:9999:9999:9999:9999:9999").GetGroup() == | ResolveIP("2001:470:abcd:9999:9999:9999:9999:9999").GetGroup() == | ||||
boost::assign::list_of((uint8_t)NET_IPV6)(32)(1)(4)(112)( | std::vector<uint8_t>( | ||||
175)); // he.net | {(uint8_t)NET_IPV6, 32, 1, 4, 112, 175})); // he.net | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
ResolveIP("2001:2001:9999:9999:9999:9999:9999:9999").GetGroup() == | ResolveIP("2001:2001:9999:9999:9999:9999:9999:9999").GetGroup() == | ||||
boost::assign::list_of((uint8_t)NET_IPV6)(32)(1)(32)(1)); // IPv6 | std::vector<uint8_t>({(uint8_t)NET_IPV6, 32, 1, 32, 1})); // IPv6 | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |
I think you can do
But I haven't followed the latest C++ crazyness. Also, put the comment on the line before the code. It'll get better formatting it also make blame clearer.