2015-06-27 01:15:23 +02:00
|
|
|
#include "olm/base64.hh"
|
2015-06-15 18:48:09 +02:00
|
|
|
#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;
|
|
|
|
|
2015-06-27 01:15:23 +02:00
|
|
|
std::size_t output_length = olm::encode_base64_length(input_length);
|
2015-06-15 18:48:09 +02:00
|
|
|
assert_equals(std::size_t(15), output_length);
|
|
|
|
|
|
|
|
std::uint8_t output[output_length];
|
2015-06-27 01:15:23 +02:00
|
|
|
olm::encode_base64(input, input_length, output);
|
2015-06-15 18:48:09 +02:00
|
|
|
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;
|
|
|
|
|
2015-06-27 01:15:23 +02:00
|
|
|
std::size_t output_length = olm::decode_base64_length(input_length);
|
2015-06-15 18:48:09 +02:00
|
|
|
assert_equals(std::size_t(11), output_length);
|
|
|
|
|
|
|
|
std::uint8_t output[output_length];
|
2015-06-27 01:15:23 +02:00
|
|
|
olm::decode_base64(input, input_length, output);
|
2015-06-15 18:48:09 +02:00
|
|
|
assert_equals(expected_output, output, output_length);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|