Thu Nguyen | e42fb48 | 2024-10-15 14:43:11 +0000 | [diff] [blame] | 1 | #include <libcper/base64.h> |
Ed Tanous | a7d2cdd | 2024-07-15 11:07:27 -0700 | [diff] [blame] | 2 | |
| 3 | #include "gtest/gtest.h" |
| 4 | #include "gmock/gmock.h" |
| 5 | |
| 6 | TEST(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 | |
| 16 | TEST(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 | } |