From ecc6cf1a3b097b9b5b047282063a0b6779631b83 Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Wed, 23 Sep 2020 08:40:38 +0200 Subject: test: fix creation of std::string objects with \0s A string literal `"abc"` contains a terminating `\0`, so that is 4 bytes. There is no need to write `"abc\0"` unless two terminating `\0`s are necessary. `std::string` objects do not internally contain a terminating `\0`, so `std::string("abc")` creates a string with size 3 and is the same as `std::string("abc", 3)`. In `"\01"` the `01` part is interpreted as one number (1) and that is the same as `"\1"` which is a string like `{1, 0}` whereas `"\0z"` is a string like `{0, 'z', 0}`. To create a string like `{0, '1', 0}` one must use `"\0" "1"`. Adjust the tests accordingly. --- src/test/net_tests.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/test/net_tests.cpp') diff --git a/src/test/net_tests.cpp b/src/test/net_tests.cpp index 85ebc89673..de4a2d5b60 100644 --- a/src/test/net_tests.cpp +++ b/src/test/net_tests.cpp @@ -23,6 +23,8 @@ #include #include +using namespace std::literals; + class CAddrManSerializationMock : public CAddrMan { public: @@ -104,8 +106,8 @@ BOOST_AUTO_TEST_CASE(caddrdb_read) BOOST_CHECK(Lookup("250.7.1.1", addr1, 8333, false)); BOOST_CHECK(Lookup("250.7.2.2", addr2, 9999, false)); BOOST_CHECK(Lookup("250.7.3.3", addr3, 9999, false)); - BOOST_CHECK(Lookup(std::string("250.7.3.3", 9), addr3, 9999, false)); - BOOST_CHECK(!Lookup(std::string("250.7.3.3\0example.com", 21), addr3, 9999, false)); + BOOST_CHECK(Lookup("250.7.3.3"s, addr3, 9999, false)); + BOOST_CHECK(!Lookup("250.7.3.3\0example.com"s, addr3, 9999, false)); // Add three addresses to new table. CService source; -- cgit v1.2.3