KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_base64.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <core/base64.h>
23
24#include <cstdint>
25#include <string>
26#include <vector>
27
28
29static std::vector<uint8_t> bytes( const std::string& aText )
30{
31 return std::vector<uint8_t>( aText.begin(), aText.end() );
32}
33
34
35static std::string decoded( const std::string& aBase64 )
36{
37 std::vector<uint8_t> out;
38 base64::decode( bytes( aBase64 ), out );
39 return std::string( out.begin(), out.end() );
40}
41
42
44
45
46BOOST_AUTO_TEST_CASE( DecodeKnownVectors )
47{
48 BOOST_CHECK_EQUAL( decoded( "" ), "" );
49 BOOST_CHECK_EQUAL( decoded( "TWFu" ), "Man" );
50 BOOST_CHECK_EQUAL( decoded( "TWE" ), "Ma" );
51 BOOST_CHECK_EQUAL( decoded( "TQ" ), "M" );
52 BOOST_CHECK_EQUAL( decoded( "TWE=" ), "Ma" );
53 BOOST_CHECK_EQUAL( decoded( "TQ==" ), "M" );
54 BOOST_CHECK_EQUAL( decoded( "aGVsbG8gd29ybGQ" ), "hello world" );
55}
56
57
59{
60 std::vector<uint8_t> input;
61
62 for( int len = 0; len < 64; len++ )
63 {
64 std::vector<uint8_t> encoded;
65 std::vector<uint8_t> output;
66
67 base64::encode( input, encoded );
68 base64::decode( encoded, output );
69
70 BOOST_CHECK_EQUAL_COLLECTIONS( output.begin(), output.end(), input.begin(), input.end() );
71
72 input.push_back( static_cast<uint8_t>( len * 37 + 11 ) );
73 }
74}
75
76
void encode(const std::vector< uint8_t > &aInput, std::vector< uint8_t > &aOutput)
Definition base64.cpp:76
void decode(const std::vector< uint8_t > &aInput, std::vector< uint8_t > &aOutput)
Definition base64.cpp:113
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
static std::vector< uint8_t > bytes(const std::string &aText)
BOOST_AUTO_TEST_CASE(DecodeKnownVectors)
static std::string decoded(const std::string &aBase64)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK_EQUAL_COLLECTIONS(mixed.begin(), mixed.end(), expMixed.begin(), expMixed.end())
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")