MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / BOOST_AUTO_TEST_CASE

Function BOOST_AUTO_TEST_CASE

src/test/base32_tests.cpp:16–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14BOOST_AUTO_TEST_SUITE(base32_tests)
15
16BOOST_AUTO_TEST_CASE(base32_testvectors)
17{
18 static const std::string vstrIn[] = {"","f","fo","foo","foob","fooba","foobar"};
19 static const std::string vstrOut[] = {"","my======","mzxq====","mzxw6===","mzxw6yq=","mzxw6ytb","mzxw6ytboi======"};
20 static const std::string vstrOutNoPadding[] = {"","my","mzxq","mzxw6","mzxw6yq","mzxw6ytb","mzxw6ytboi"};
21 for (unsigned int i=0; i<std::size(vstrIn); i++)
22 {
23 std::string strEnc = EncodeBase32(vstrIn[i]);
24 BOOST_CHECK_EQUAL(strEnc, vstrOut[i]);
25 strEnc = EncodeBase32(vstrIn[i], false);
26 BOOST_CHECK_EQUAL(strEnc, vstrOutNoPadding[i]);
27 auto dec = DecodeBase32(vstrOut[i]);
28 BOOST_REQUIRE(dec);
29 BOOST_CHECK_MESSAGE(std::ranges::equal(*dec, vstrIn[i]), vstrOut[i]);
30 }
31
32 BOOST_CHECK(!DecodeBase32("AWSX3VPPinvalid")); // invalid size
33 BOOST_CHECK( DecodeBase32("AWSX3VPP")); // valid
34
35 // Decoding strings with embedded NUL characters should fail
36 BOOST_CHECK(!DecodeBase32("invalid\0"sv)); // correct size, invalid due to \0
37 BOOST_CHECK(!DecodeBase32("AWSX3VPP\0invalid"sv)); // correct size, invalid due to \0
38}
39
40BOOST_AUTO_TEST_CASE(base32_padding)
41{

Callers

nothing calls this directly

Calls 3

sizeFunction · 0.85
EncodeBase32Function · 0.85
DecodeBase32Function · 0.85

Tested by

no test coverage detected