-
Notifications
You must be signed in to change notification settings - Fork 314
/
base64_test.cc
54 lines (42 loc) · 1.11 KB
/
base64_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "prometheus/detail/base64.h"
#include <gtest/gtest.h>
#include <string>
namespace prometheus {
namespace {
struct TestVector {
const std::string decoded;
const std::string encoded;
};
const TestVector testVector[] = {
{"", ""},
{"f", "Zg=="},
{"fo", "Zm8="},
{"foo", "Zm9v"},
{"foob", "Zm9vYg=="},
{"fooba", "Zm9vYmE="},
{"foobar", "Zm9vYmFy"},
};
using namespace testing;
TEST(Base64Test, encodeTest) {
for (const auto& test_case : testVector) {
std::string encoded = detail::base64_encode(test_case.decoded);
EXPECT_EQ(test_case.encoded, encoded);
}
}
TEST(Base64Test, decodeTest) {
for (const auto& test_case : testVector) {
std::string decoded = detail::base64_decode(test_case.encoded);
EXPECT_EQ(test_case.decoded, decoded);
}
}
TEST(Base64Test, rejectInvalidSymbols) {
EXPECT_ANY_THROW(detail::base64_decode("...."));
}
TEST(Base64Test, rejectInvalidInputSize) {
EXPECT_ANY_THROW(detail::base64_decode("ABC"));
}
TEST(Base64Test, rejectInvalidPadding) {
EXPECT_ANY_THROW(detail::base64_decode("A==="));
}
} // namespace
} // namespace prometheus