aboutsummaryrefslogtreecommitdiff
path: root/tests/test_base64.cpp
blob: 5bae2f93bd5ac93754db24c2bed3aae9a284bcb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "olm/base64.hh"
#include "unittest.hh"

int main() {

{ /* Base64 encode test */
TestCase test_case("Base64 encode test");

std::uint8_t input[] = "Hello World";
std::uint8_t expected_output[] = "SGVsbG8gV29ybGQ";
std::size_t input_length = sizeof(input) - 1;

std::size_t output_length = olm::encode_base64_length(input_length);
assert_equals(std::size_t(15), output_length);

std::uint8_t output[output_length];
olm::encode_base64(input, input_length, output);
assert_equals(expected_output, output, output_length);
}

{ /* Base64 decode test */
TestCase test_case("Base64 decode test");

std::uint8_t input[] = "SGVsbG8gV29ybGQ";
std::uint8_t expected_output[] = "Hello World";
std::size_t input_length = sizeof(input) - 1;

std::size_t output_length = olm::decode_base64_length(input_length);
assert_equals(std::size_t(11), output_length);

std::uint8_t output[output_length];
olm::decode_base64(input, input_length, output);
assert_equals(expected_output, output, output_length);
}

}