Changeset View
Changeset View
Standalone View
Standalone View
src/test/serialize_tests.cpp
Show First 20 Lines • Show All 311 Lines • ▼ Show 20 Lines | static bool isCanonicalException(const std::ios_base::failure &ex) { | ||||
// The string returned by what() can be different for different platforms. | // The string returned by what() can be different for different platforms. | ||||
// Instead of directly comparing the ex.what() with an expected string, | // Instead of directly comparing the ex.what() with an expected string, | ||||
// create an instance of exception to see if ex.what() matches the expected | // create an instance of exception to see if ex.what() matches the expected | ||||
// explanatory string returned by the exception instance. | // explanatory string returned by the exception instance. | ||||
return strcmp(expectedException.what(), ex.what()) == 0; | return strcmp(expectedException.what(), ex.what()) == 0; | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(vector_bool) { | |||||
std::vector<uint8_t> vec1{1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, | |||||
1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1}; | |||||
std::vector<bool> vec2{1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, | |||||
1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1}; | |||||
BOOST_CHECK(vec1 == std::vector<uint8_t>(vec2.begin(), vec2.end())); | |||||
BOOST_CHECK(SerializeHash(vec1) == SerializeHash(vec2)); | |||||
} | |||||
BOOST_AUTO_TEST_CASE(noncanonical) { | BOOST_AUTO_TEST_CASE(noncanonical) { | ||||
// Write some non-canonical CompactSize encodings, and make sure an | // Write some non-canonical CompactSize encodings, and make sure an | ||||
// exception is thrown when read back. | // exception is thrown when read back. | ||||
CDataStream ss(SER_DISK, 0); | CDataStream ss(SER_DISK, 0); | ||||
std::vector<char>::size_type n; | std::vector<char>::size_type n; | ||||
// zero encoded with three bytes: | // zero encoded with three bytes: | ||||
ss.write("\xfd\x00\x00", 3); | ss.write("\xfd\x00\x00", 3); | ||||
▲ Show 20 Lines • Show All 111 Lines • Show Last 20 Lines |