2023-08-31 17:35:12 +02:00
|
|
|
/* Unit tests for base64 encoding/decoding.
|
2019-05-30 12:44:11 +02:00
|
|
|
*
|
2023-08-31 11:17:07 +02:00
|
|
|
* Author: Steffen Vogel <post@steffenvogel.de>
|
|
|
|
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2023-08-28 12:31:18 +02:00
|
|
|
*/
|
2019-05-30 12:44:11 +02:00
|
|
|
|
|
|
|
#include <criterion/criterion.h>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <villas/utils.hpp>
|
|
|
|
|
|
|
|
using namespace villas::utils::base64;
|
|
|
|
|
2020-09-11 15:16:53 +02:00
|
|
|
// cppcheck-suppress unknownMacro
|
2019-05-30 12:44:11 +02:00
|
|
|
TestSuite(base64, .description = "Base64 En/decoder");
|
|
|
|
|
2023-09-07 13:19:19 +02:00
|
|
|
static std::vector<byte> vec(const char *str) {
|
|
|
|
return std::vector<byte>((byte *)str, (byte *)str + strlen(str));
|
2019-05-30 12:44:11 +02:00
|
|
|
}
|
|
|
|
|
2023-09-07 13:19:19 +02:00
|
|
|
Test(base64, encoding) {
|
|
|
|
cr_assert(encode(vec("pohy0Aiy1ZaVa5aik2yaiy3ifoh3oole")) ==
|
|
|
|
"cG9oeTBBaXkxWmFWYTVhaWsyeWFpeTNpZm9oM29vbGU=");
|
2019-05-30 12:44:11 +02:00
|
|
|
}
|
|
|
|
|
2023-09-07 13:19:19 +02:00
|
|
|
Test(base64, decoding) {
|
|
|
|
cr_assert(decode("cG9oeTBBaXkxWmFWYTVhaWsyeWFpeTNpZm9oM29vbGU=") ==
|
|
|
|
vec("pohy0Aiy1ZaVa5aik2yaiy3ifoh3oole"));
|
2019-05-30 12:44:11 +02:00
|
|
|
}
|