LCOV - code coverage report
Current view: top level - src/test - base64_tests.cpp (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 20 20 100.0 %
Date: 2021-06-29 14:35:33 Functions: 1 1 100.0 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 2 2 100.0 %

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2011-2020 The Bitcoin Core developers
#       2                 :            : // Distributed under the MIT software license, see the accompanying
#       3                 :            : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#       4                 :            : 
#       5                 :            : #include <test/util/setup_common.h>
#       6                 :            : #include <util/strencodings.h>
#       7                 :            : 
#       8                 :            : #include <boost/test/unit_test.hpp>
#       9                 :            : #include <string>
#      10                 :            : 
#      11                 :            : using namespace std::literals;
#      12                 :            : 
#      13                 :            : BOOST_FIXTURE_TEST_SUITE(base64_tests, BasicTestingSetup)
#      14                 :            : 
#      15                 :            : BOOST_AUTO_TEST_CASE(base64_testvectors)
#      16                 :          2 : {
#      17                 :          2 :     static const std::string vstrIn[]  = {"","f","fo","foo","foob","fooba","foobar"};
#      18                 :          2 :     static const std::string vstrOut[] = {"","Zg==","Zm8=","Zm9v","Zm9vYg==","Zm9vYmE=","Zm9vYmFy"};
#      19         [ +  + ]:         16 :     for (unsigned int i=0; i<std::size(vstrIn); i++)
#      20                 :         14 :     {
#      21                 :         14 :         std::string strEnc = EncodeBase64(vstrIn[i]);
#      22                 :         14 :         BOOST_CHECK_EQUAL(strEnc, vstrOut[i]);
#      23                 :         14 :         std::string strDec = DecodeBase64(strEnc);
#      24                 :         14 :         BOOST_CHECK_EQUAL(strDec, vstrIn[i]);
#      25                 :         14 :     }
#      26                 :            : 
#      27                 :            :     // Decoding strings with embedded NUL characters should fail
#      28                 :          2 :     bool failure;
#      29                 :          2 :     (void)DecodeBase64("invalid\0"s, &failure);
#      30                 :          2 :     BOOST_CHECK(failure);
#      31                 :          2 :     (void)DecodeBase64("nQB/pZw="s, &failure);
#      32                 :          2 :     BOOST_CHECK(!failure);
#      33                 :          2 :     (void)DecodeBase64("nQB/pZw=\0invalid"s, &failure);
#      34                 :          2 :     BOOST_CHECK(failure);
#      35                 :          2 :     (void)DecodeBase64("nQB/pZw=invalid\0"s, &failure);
#      36                 :          2 :     BOOST_CHECK(failure);
#      37                 :          2 : }
#      38                 :            : 
#      39                 :            : BOOST_AUTO_TEST_SUITE_END()

Generated by: LCOV version 1.14