From 2ea40a51a95f77c295025d80f9787142b967bdd7 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 7 Jan 2008 04:39:18 +0000 Subject: [PATCH] added tests for big_number (peer_id/node_id/sha1_hash) --- test/test_primitives.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/test_primitives.cpp b/test/test_primitives.cpp index b860781fd..9693e6442 100644 --- a/test/test_primitives.cpp +++ b/test/test_primitives.cpp @@ -329,6 +329,44 @@ int test_main() } } + // test peer_id/sha1_hash type + + sha1_hash h1(0); + sha1_hash h2(0); + TEST_CHECK(h1 == h2); + TEST_CHECK(!(h1 != h2)); + TEST_CHECK(!(h1 < h2)); + TEST_CHECK(!(h1 < h2)); + TEST_CHECK(h1.is_all_zeros()); + + h1 = boost::lexical_cast("0123456789012345678901234567890123456789"); + h2 = boost::lexical_cast("0113456789012345678901234567890123456789"); + + TEST_CHECK(h2 < h1); + TEST_CHECK(h2 == h2); + TEST_CHECK(h1 == h1); + h2.clear(); + TEST_CHECK(h2.is_all_zeros()); + + h2 = boost::lexical_cast("ffffffffff0000000000ffffffffff0000000000"); + h1 = boost::lexical_cast("fffff00000fffff00000fffff00000fffff00000"); + h1 &= h2; + TEST_CHECK(h1 == boost::lexical_cast("fffff000000000000000fffff000000000000000")); + + h2 = boost::lexical_cast("ffffffffff0000000000ffffffffff0000000000"); + h1 = boost::lexical_cast("fffff00000fffff00000fffff00000fffff00000"); + h1 |= h2; + TEST_CHECK(h1 == boost::lexical_cast("fffffffffffffff00000fffffffffffffff00000")); + + h2 = boost::lexical_cast("0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f"); + h1 ^= h2; + std::cerr << h1 << std::endl; + TEST_CHECK(h1 == boost::lexical_cast("f0f0f0f0f0f0f0ff0f0ff0f0f0f0f0f0f0ff0f0f")); + TEST_CHECK(h1 != h2); + + h2 = sha1_hash(" "); + TEST_CHECK(h2 == boost::lexical_cast("2020202020202020202020202020202020202020")); + return 0; }