aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-11-04 09:03:04 +0100
committerMarcoFalke <falke.marco@gmail.com>2021-11-09 17:42:13 +0100
commitfaa3ec2304051be7cfbe301cfbfbda3faf7514fc (patch)
treed4bd1d6efd163452352e275beec7674de246d9af /src/test
parentfa18038f519db76befb9a7bd0b1540143bfeb12b (diff)
downloadbitcoin-faa3ec2304051be7cfbe301cfbfbda3faf7514fc.tar.xz
span: Add std::byte helpers
Also, add Span<std::byte> interface to strencondings.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/base64_tests.cpp10
-rw-r--r--src/test/util_tests.cpp23
2 files changed, 28 insertions, 5 deletions
diff --git a/src/test/base64_tests.cpp b/src/test/base64_tests.cpp
index 9d1dfd46f1..c5fce7bec0 100644
--- a/src/test/base64_tests.cpp
+++ b/src/test/base64_tests.cpp
@@ -23,6 +23,16 @@ BOOST_AUTO_TEST_CASE(base64_testvectors)
BOOST_CHECK_EQUAL(strDec, vstrIn[i]);
}
+ {
+ const std::vector<uint8_t> in_u{0xff, 0x01, 0xff};
+ const std::vector<std::byte> in_b{std::byte{0xff}, std::byte{0x01}, std::byte{0xff}};
+ const std::string in_s{"\xff\x01\xff"};
+ const std::string out_exp{"/wH/"};
+ BOOST_CHECK_EQUAL(EncodeBase64(in_u), out_exp);
+ BOOST_CHECK_EQUAL(EncodeBase64(in_b), out_exp);
+ BOOST_CHECK_EQUAL(EncodeBase64(in_s), out_exp);
+ }
+
// Decoding strings with embedded NUL characters should fail
bool failure;
(void)DecodeBase64("invalid\0"s, &failure);
diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp
index b1300d06ba..108bcecc66 100644
--- a/src/test/util_tests.cpp
+++ b/src/test/util_tests.cpp
@@ -151,12 +151,25 @@ BOOST_AUTO_TEST_CASE(util_HexStr)
HexStr(Span<const unsigned char>(ParseHex_expected, ParseHex_expected)),
"");
- std::vector<unsigned char> ParseHex_vec(ParseHex_expected, ParseHex_expected + 5);
+ {
+ const std::vector<char> in_s{ParseHex_expected, ParseHex_expected + 5};
+ const Span<const uint8_t> in_u{MakeUCharSpan(in_s)};
+ const Span<const std::byte> in_b{MakeByteSpan(in_s)};
+ const std::string out_exp{"04678afdb0"};
+
+ BOOST_CHECK_EQUAL(HexStr(in_u), out_exp);
+ BOOST_CHECK_EQUAL(HexStr(in_s), out_exp);
+ BOOST_CHECK_EQUAL(HexStr(in_b), out_exp);
+ }
+}
- BOOST_CHECK_EQUAL(
- HexStr(ParseHex_vec),
- "04678afdb0"
- );
+BOOST_AUTO_TEST_CASE(span_write_bytes)
+{
+ std::array mut_arr{uint8_t{0xaa}, uint8_t{0xbb}};
+ const auto mut_bytes{MakeWritableByteSpan(mut_arr)};
+ mut_bytes[1] = std::byte{0x11};
+ BOOST_CHECK_EQUAL(mut_arr.at(0), 0xaa);
+ BOOST_CHECK_EQUAL(mut_arr.at(1), 0x11);
}
BOOST_AUTO_TEST_CASE(util_Join)