diff options
author | laanwj <126646+laanwj@users.noreply.github.com> | 2022-02-09 15:17:21 +0100 |
---|---|---|
committer | laanwj <126646+laanwj@users.noreply.github.com> | 2022-02-09 16:04:43 +0100 |
commit | 5e8e0b3d7f6055e326bda61e60712b530e8920f0 (patch) | |
tree | 47e37bdfacdef0689cf095aa12098251146b35b0 /src/test | |
parent | 6ac637f97f0ccdf0c6ab8565f68d37aeffe62090 (diff) | |
parent | fa1b227a727a5056c6fbc7e4f33c19aeb5207718 (diff) |
Merge bitcoin/bitcoin#24253: Remove broken and unused CDataStream methods
fa1b227a727a5056c6fbc7e4f33c19aeb5207718 Remove broken and unused CDataStream methods (MarcoFalke)
faee5f8dc23cd2fcfb6ad62a1d46ad3020ef0c5c test: Create fresh CDataStream each time (MarcoFalke)
fa71114926490e84c9222d315a95684d250e8e34 test: Inline expected_xor (MarcoFalke)
Pull request description:
The `insert` and `erase` methods have many issues:
* They are unused
* They are confusing and hard to read, as they implement "special cases" for optimization, that isn't needed
* They are broken (See https://github.com/bitcoin/bitcoin/pull/24231)
* Fixing them leads to mingw compile errors (See https://github.com/bitcoin/bitcoin/pull/24231#issuecomment-1029286985)
Fix all issues by removing them
ACKs for top commit:
laanwj:
Code review ACK fa1b227a727a5056c6fbc7e4f33c19aeb5207718
Tree-SHA512: 9d9e5d42e6ffc5ae82bdb67cfb5b50b45977ae674acee6ff99092560aebf2fc7e4584ded614e190db0663226fa198e34350517cd7ee57d518de22e9568bc349a
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/serialize_tests.cpp | 45 | ||||
-rw-r--r-- | src/test/streams_tests.cpp | 43 |
2 files changed, 17 insertions, 71 deletions
diff --git a/src/test/serialize_tests.cpp b/src/test/serialize_tests.cpp index 8b8133b689..2441847f99 100644 --- a/src/test/serialize_tests.cpp +++ b/src/test/serialize_tests.cpp @@ -215,51 +215,6 @@ BOOST_AUTO_TEST_CASE(noncanonical) BOOST_CHECK_EXCEPTION(ReadCompactSize(ss), std::ios_base::failure, isCanonicalException); } -BOOST_AUTO_TEST_CASE(insert_delete) -{ - constexpr auto B2I{[](std::byte b) { return std::to_integer<uint8_t>(b); }}; - - // Test inserting/deleting bytes. - CDataStream ss(SER_DISK, 0); - BOOST_CHECK_EQUAL(ss.size(), 0U); - - ss.write(MakeByteSpan("\x00\x01\x02\xff").first(4)); - BOOST_CHECK_EQUAL(ss.size(), 4U); - - uint8_t c{11}; - - // Inserting at beginning/end/middle: - ss.insert(ss.begin(), std::byte{c}); - BOOST_CHECK_EQUAL(ss.size(), 5U); - BOOST_CHECK_EQUAL(B2I(ss[0]), c); - BOOST_CHECK_EQUAL(B2I(ss[1]), 0); - - ss.insert(ss.end(), std::byte{c}); - BOOST_CHECK_EQUAL(ss.size(), 6U); - BOOST_CHECK_EQUAL(B2I(ss[4]), 0xff); - BOOST_CHECK_EQUAL(B2I(ss[5]), c); - - ss.insert(ss.begin() + 2, std::byte{c}); - BOOST_CHECK_EQUAL(ss.size(), 7U); - BOOST_CHECK_EQUAL(B2I(ss[2]), c); - - // Delete at beginning/end/middle - ss.erase(ss.begin()); - BOOST_CHECK_EQUAL(ss.size(), 6U); - BOOST_CHECK_EQUAL(B2I(ss[0]), 0); - - ss.erase(ss.begin()+ss.size()-1); - BOOST_CHECK_EQUAL(ss.size(), 5U); - BOOST_CHECK_EQUAL(B2I(ss[4]), 0xff); - - ss.erase(ss.begin()+1); - BOOST_CHECK_EQUAL(ss.size(), 4U); - BOOST_CHECK_EQUAL(B2I(ss[0]), 0); - BOOST_CHECK_EQUAL(B2I(ss[1]), 1); - BOOST_CHECK_EQUAL(B2I(ss[2]), 2); - BOOST_CHECK_EQUAL(B2I(ss[3]), 0xff); -} - BOOST_AUTO_TEST_CASE(class_methods) { int intval(100); diff --git a/src/test/streams_tests.cpp b/src/test/streams_tests.cpp index 6a69fe9840..0925e2e9ee 100644 --- a/src/test/streams_tests.cpp +++ b/src/test/streams_tests.cpp @@ -8,6 +8,8 @@ #include <boost/test/unit_test.hpp> +using namespace std::string_literals; + BOOST_FIXTURE_TEST_SUITE(streams_tests, BasicTestingSetup) BOOST_AUTO_TEST_CASE(streams_vector_writer) @@ -162,46 +164,35 @@ BOOST_AUTO_TEST_CASE(bitstream_reader_writer) BOOST_AUTO_TEST_CASE(streams_serializedata_xor) { std::vector<std::byte> in; - std::vector<char> expected_xor; - CDataStream ds(in, 0, 0); // Degenerate case - ds.Xor({0x00, 0x00}); - BOOST_CHECK_EQUAL( - std::string(expected_xor.begin(), expected_xor.end()), - ds.str()); + { + CDataStream ds{in, 0, 0}; + ds.Xor({0x00, 0x00}); + BOOST_CHECK_EQUAL(""s, ds.str()); + } in.push_back(std::byte{0x0f}); in.push_back(std::byte{0xf0}); - expected_xor.push_back('\xf0'); - expected_xor.push_back('\x0f'); // Single character key - - ds.clear(); - ds.insert(ds.begin(), in.begin(), in.end()); - - ds.Xor({0xff}); - BOOST_CHECK_EQUAL( - std::string(expected_xor.begin(), expected_xor.end()), - ds.str()); + { + CDataStream ds{in, 0, 0}; + ds.Xor({0xff}); + BOOST_CHECK_EQUAL("\xf0\x0f"s, ds.str()); + } // Multi character key in.clear(); - expected_xor.clear(); in.push_back(std::byte{0xf0}); in.push_back(std::byte{0x0f}); - expected_xor.push_back('\x0f'); - expected_xor.push_back('\x00'); - - ds.clear(); - ds.insert(ds.begin(), in.begin(), in.end()); - ds.Xor({0xff, 0x0f}); - BOOST_CHECK_EQUAL( - std::string(expected_xor.begin(), expected_xor.end()), - ds.str()); + { + CDataStream ds{in, 0, 0}; + ds.Xor({0xff, 0x0f}); + BOOST_CHECK_EQUAL("\x0f\x00"s, ds.str()); + } } BOOST_AUTO_TEST_CASE(streams_buffered_file) |