Line data Source code
1 : // Copyright (c) 2012-2013 The Bitcoin Core developers 2 : // Distributed under the MIT/X11 software license, see the accompanying 3 : // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 : 5 : #include "utilstrencodings.h" 6 : #include "test/test_pivx.h" 7 : 8 : #include <boost/test/unit_test.hpp> 9 : 10 : BOOST_FIXTURE_TEST_SUITE(base32_tests, BasicTestingSetup) 11 : 12 2 : BOOST_AUTO_TEST_CASE(base32_testvectors) 13 : { 14 1 : static const std::string vstrIn[] = {"","f","fo","foo","foob","fooba","foobar"}; 15 1 : static const std::string vstrOut[] = {"","my======","mzxq====","mzxw6===","mzxw6yq=","mzxw6ytb","mzxw6ytboi======"}; 16 1 : static const std::string vstrOutNoPadding[] = {"","my","mzxq","mzxw6","mzxw6yq","mzxw6ytb","mzxw6ytboi"}; 17 8 : for (unsigned int i=0; i<sizeof(vstrIn)/sizeof(vstrIn[0]); i++) 18 : { 19 14 : std::string strEnc = EncodeBase32(vstrIn[i]); 20 7 : BOOST_CHECK_EQUAL(strEnc, vstrOut[i]); 21 7 : strEnc = EncodeBase32(vstrIn[i], false); 22 7 : BOOST_CHECK_EQUAL(strEnc, vstrOutNoPadding[i]); 23 14 : std::string strDec = DecodeBase32(vstrOut[i]); 24 14 : BOOST_CHECK(strDec == vstrIn[i]); 25 : } 26 1 : } 27 : 28 : BOOST_AUTO_TEST_SUITE_END()