From c7a1c2b0d28461c541c900ec6d020358a5f12d41 Mon Sep 17 00:00:00 2001 From: Carl Allendorph Date: Sat, 19 Apr 2014 09:30:44 -0700 Subject: [PATCH] converted RLP test to a separate boost test case. --- test/main.cpp | 1 - test/rlp.cpp | 87 +++++++++++++++++++++++---------------------------- 2 files changed, 40 insertions(+), 48 deletions(-) diff --git a/test/main.cpp b/test/main.cpp index 4cfb71ced..fc8eecd52 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -46,7 +46,6 @@ BOOST_AUTO_TEST_CASE(basic_tests) int r = 0; r += hexPrefixTest(); - r += rlpTest(); r += trieTest(); r += vmTest(); r += cryptoTest(); // TODO: Put in tests repo. diff --git a/test/rlp.cpp b/test/rlp.cpp index f6c244423..e13965daf 100644 --- a/test/rlp.cpp +++ b/test/rlp.cpp @@ -24,66 +24,59 @@ #include "JsonSpiritHeaders.h" #include #include +#include + using namespace std; using namespace eth; namespace js = json_spirit; -namespace eth -{ - -template <> class UnitTest<2> +namespace eth { -public: - static void buildRLP(js::mValue& _v, RLPStream& _rlp) + namespace test { - if (_v.type() == js::array_type) + static void buildRLP(js::mValue& _v, RLPStream& _rlp) { - RLPStream s; - for (auto& i: _v.get_array()) - buildRLP(i, s); - _rlp.appendList(s.out()); - } - else if (_v.type() == js::int_type) - _rlp.append(_v.get_uint64()); - else if (_v.type() == js::str_type) - { - auto s = _v.get_str(); - if (s.size() && s[0] == '#') - _rlp.append(bigint(s.substr(1))); - else - _rlp.append(s); - } - } - - int operator()() - { - js::mValue v; - string s = asString(contents("../../tests/rlptest.json")); - js::read_string(s, v); - bool passed = true; - for (auto& i: v.get_obj()) - { - js::mObject& o = i.second.get_obj(); - cnote << i.first; - RLPStream s; - buildRLP(o["in"], s); - if (!o["out"].is_null() && o["out"].get_str() != toHex(s.out())) + if (_v.type() == js::array_type) { - cwarn << "Test failed."; - cwarn << "Test says:" << o["out"].get_str(); - cwarn << "Impl says:" << toHex(s.out()); - passed = false; + RLPStream s; + for (auto& i: _v.get_array()) + buildRLP(i, s); + _rlp.appendList(s.out()); + } + else if (_v.type() == js::int_type) + _rlp.append(_v.get_uint64()); + else if (_v.type() == js::str_type) + { + auto s = _v.get_str(); + if (s.size() && s[0] == '#') + _rlp.append(bigint(s.substr(1))); + else + _rlp.append(s); } } - return passed ? 0 : 1; } +} -}; - -} -int rlpTest() +BOOST_AUTO_TEST_CASE(rlp_test) { cnote << "Testing RLP..."; - return UnitTest<2>()(); + js::mValue v; + string s = asString(contents("../../tests/rlptest.json")); + BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of 'rlptest.json' is empty. Have you cloned the 'tests' repo branch develop?"); + js::read_string(s, v); + for (auto& i: v.get_obj()) + { + js::mObject& o = i.second.get_obj(); + cnote << i.first; + RLPStream s; + eth::test::buildRLP(o["in"], s); + BOOST_REQUIRE(!o["out"].is_null()); + BOOST_CHECK(o["out"].get_str() == toHex(s.out()) ); + } + } + + + +