aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-06-15 17:48:09 +0100
committerMark Haines <mark.haines@matrix.org>2015-06-15 17:48:09 +0100
commit7cdde735604de3d1be54fc535df3985b89eebd0a (patch)
treefdea841c191ede16f3eb50074879d9161cec6b64 /tests
parent026e4394bb333e978a37f5821f0a1c3dca6acb1d (diff)
Add base64 encoders and decoders
Diffstat (limited to 'tests')
-rw-r--r--tests/test_base64.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/test_base64.cpp b/tests/test_base64.cpp
new file mode 100644
index 0000000..2340656
--- /dev/null
+++ b/tests/test_base64.cpp
@@ -0,0 +1,38 @@
+
+#include "axolotl/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 = axolotl::encode_base64_length(input_length);
+assert_equals(std::size_t(15), output_length);
+
+std::uint8_t output[output_length];
+axolotl::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 = axolotl::decode_base64_length(input_length);
+assert_equals(std::size_t(11), output_length);
+
+std::uint8_t output[output_length];
+axolotl::decode_base64(input, input_length, output);
+assert_equals(expected_output, output, output_length);
+}
+
+
+}