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
20
#include <
qa_utils/wx_utils/unit_test_utils.h
>
21
22
#include <
core/base64.h
>
23
24
#include <cstdint>
25
#include <string>
26
#include <vector>
27
28
29
static
std::vector<uint8_t>
bytes
(
const
std::string& aText )
30
{
31
return
std::vector<uint8_t>( aText.begin(), aText.end() );
32
}
33
34
35
static
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
43
BOOST_AUTO_TEST_SUITE
( Base64 )
44
45
46
BOOST_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
58
BOOST_AUTO_TEST_CASE
( RoundTrip )
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
77
BOOST_AUTO_TEST_SUITE_END
()
base64.h
base64::encode
void encode(const std::vector< uint8_t > &aInput, std::vector< uint8_t > &aOutput)
Definition
base64.cpp:76
base64::decode
void decode(const std::vector< uint8_t > &aInput, std::vector< uint8_t > &aOutput)
Definition
base64.cpp:113
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:80
bytes
static std::vector< uint8_t > bytes(const std::string &aText)
Definition
test_base64.cpp:29
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(DecodeKnownVectors)
Definition
test_base64.cpp:46
decoded
static std::string decoded(const std::string &aBase64)
Definition
test_base64.cpp:35
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK_EQUAL_COLLECTIONS
BOOST_CHECK_EQUAL_COLLECTIONS(mixed.begin(), mixed.end(), expMixed.begin(), expMixed.end())
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
unit_test_utils.h
src
qa
tests
common
test_base64.cpp
Generated on Tue Oct 27 2026 00:06:38 for KiCad PCB EDA Suite by
1.13.2