blob: 6040c004d447fbfb30119b6d7cb9b108572336bb [file] [log] [blame]
Thu Nguyene42fb482024-10-15 14:43:11 +00001#include <libcper/base64.h>
Ed Tanousa7d2cdd2024-07-15 11:07:27 -07002
3#include "gtest/gtest.h"
4#include "gmock/gmock.h"
5
6TEST(Base64Encode, Good)
7{
8 int32_t encoded_len = 0;
9 std::array<uint8_t, 1> data = { 'f' };
10 char *encoded = base64_encode(data.data(), data.size(), &encoded_len);
11 EXPECT_EQ(encoded_len, 4);
12 ASSERT_EQ(std::string_view(encoded, encoded_len), "Zg==");
13 free(encoded);
14}
15
16TEST(Base64Decode, Good)
17{
18 int32_t decoded_len = 0;
19 std::string_view data{ "Zg==" };
20 UINT8 *decoded = base64_decode(data.data(), data.size(), &decoded_len);
21 EXPECT_EQ(decoded_len, 1);
22 ASSERT_EQ(decoded[0], 'f');
23 free(decoded);
24}