base64_test.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 
4 
5 TEST(Base64Test, EncodingTest) {
6  constexpr char arr[] = {'A', 'B', 'C', 'D'};
7  const std::string_view sv(arr, sizeof(arr));
8  const std::string b64encoded = foxglove::base64Encode(sv);
9  EXPECT_EQ(b64encoded, "QUJDRA==");
10 }
11 
12 TEST(Base64Test, DecodeTest) {
13  const std::vector<unsigned char> expectedVal = {0x00, 0xFF, 0x01, 0xFE};
14  EXPECT_EQ(foxglove::base64Decode("AP8B/g=="), expectedVal);
15 }
16 
17 TEST(Base64Test, DecodeInvalidStringTest) {
18  // String length not multiple of 4
19  EXPECT_THROW(foxglove::base64Decode("faefa"), std::runtime_error);
20  // Invalid characters
21  EXPECT_THROW(foxglove::base64Decode("fa^ef a"), std::runtime_error);
22 }
23 
24 int main(int argc, char** argv) {
25  testing::InitGoogleTest(&argc, argv);
26  return RUN_ALL_TESTS();
27 }
int main(int argc, char **argv)
Definition: base64_test.cpp:24
TEST(Base64Test, EncodingTest)
Definition: base64_test.cpp:5
std::string base64Encode(const std::string_view &input)
Definition: base64.cpp:10
std::vector< unsigned char > base64Decode(const std::string &input)
Definition: base64.cpp:47


foxglove_bridge
Author(s): Foxglove
autogenerated on Mon Jul 3 2023 02:12:22