test constants

This commit is contained in:
subtly 2015-04-16 20:53:12 -04:00
parent 5999c04eb5
commit 14adc795ac
2 changed files with 50 additions and 0 deletions

27
net.cpp
View File

@ -343,3 +343,30 @@ BOOST_AUTO_TEST_CASE(test_udp_once)
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(netTypes)
BOOST_AUTO_TEST_CASE(unspecifiedNode)
{
Node n = UnspecifiedNode;
BOOST_REQUIRE(!n);
Node node(Public(sha3("0")), NodeIPEndpoint(bi::address(), 0, 0));
BOOST_REQUIRE(node);
BOOST_REQUIRE(n != node);
Node nodeEq(Public(sha3("0")), NodeIPEndpoint(bi::address(), 0, 0));
BOOST_REQUIRE_EQUAL(node, nodeEq);
}
BOOST_AUTO_TEST_CASE(nodeTableReturnsUnspecifiedNode)
{
ba::io_service io;
NodeTable t(io, KeyPair::create(), NodeIPEndpoint(bi::address::from_string("127.0.0.1"), 30303, 30303));
if (Node n = t.node(NodeId()))
BOOST_REQUIRE(false);
else
BOOST_REQUIRE(n == UnspecifiedNode);
}
BOOST_AUTO_TEST_SUITE_END()

View File

@ -112,6 +112,29 @@ BOOST_AUTO_TEST_CASE(save_nodes)
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(peerTypes)
BOOST_AUTO_TEST_CASE(emptySharedPeer)
{
shared_ptr<Peer> p;
BOOST_REQUIRE(!p);
std::map<NodeId, std::shared_ptr<Peer>> peers;
p = peers[NodeId()];
BOOST_REQUIRE(!p);
p.reset(new Peer(UnspecifiedNode));
BOOST_REQUIRE(!p->id);
BOOST_REQUIRE(!*p);
p.reset(new Peer(Node(NodeId(EmptySHA3), UnspecifiedNodeIPEndpoint)));
BOOST_REQUIRE(!(!*p));
BOOST_REQUIRE(*p);
BOOST_REQUIRE(p);
}
BOOST_AUTO_TEST_SUITE_END()
int peerTest(int argc, char** argv) int peerTest(int argc, char** argv)
{ {
Public remoteAlias; Public remoteAlias;