5#include "flutter/fml/base32.h"
9#include "gtest/gtest.h"
11TEST(Base32Test, CanEncode) {
15 ASSERT_EQ(
result.second,
"NBSWY3DP");
21 ASSERT_EQ(
result.second,
"NBSWYTDP");
27 ASSERT_EQ(
result.second,
"");
33 ASSERT_EQ(
result.second,
"GE");
39 ASSERT_EQ(
result.second,
"NBSWYTDP");
45 ASSERT_EQ(
result.second,
"777H7AEB");
49TEST(Base32Test, CanEncodeDecodeStrings) {
50 std::vector<std::string> strings = {
"hello",
"helLo",
"",
"1",
"\0"};
51 for (
size_t i = 0;
i < strings.size();
i += 1) {
53 ASSERT_TRUE(encode_result.first);
55 ASSERT_TRUE(decode_result.first);
56 const std::string& decoded = decode_result.second;
57 std::string decoded_string(decoded.data(), decoded.size());
58 ASSERT_EQ(strings[
i], decoded_string);
62TEST(Base32Test, DecodeReturnsFalseForInvalideInput) {
64 std::vector<std::string> invalid_inputs = {
"a",
"1",
"9",
"B"};
65 for (
const std::string& input : invalid_inputs) {
67 if (decode_result.first) {
68 std::cout <<
"Base32Decode should return false on " << input << std::endl;
70 ASSERT_FALSE(decode_result.first);
74TEST(Base32Test, CanDecodeSkSLKeys) {
75 std::vector<std::string>
inputs = {
76 "CAZAAAACAAAAADQAAAABKAAAAAJQAAIA7777777777776EYAAEAP777777777777AAAAAABA"
77 "ABTAAAAAAAAAAAAAAABAAAAAGQAGGAA",
78 "CAZAAAICAAAAAAAAAAADOAAAAAJQAAIA777777Y4AAKAAEYAAEAP777777777777EAAGMAAA"
79 "AAAAAAAAAAACQACNAAAAAAAAAAAAAAACAAAAAPAAMMAA",
80 "CAZACAACAAAABAYACAAAAAAAAAJQAAIADQABIAH777777777777RQAAOAAAAAAAAAAAAAABE"
81 "AANQAAAAAAAAAAAAAAYAAJYAAAAAAAANAAAQAAAAAAAEAAAHAAAAAAAAAAAAAAANAAAQAAAA"
82 "AAAFIADKAAAAAAAAAAAAAAACAAAAAZAAMMAA"};
83 for (
const std::string& input :
inputs) {
85 if (!decode_result.first) {
86 std::cout <<
"Base32Decode should return true on " << input << std::endl;
88 ASSERT_TRUE(decode_result.first);
90 ASSERT_TRUE(encode_result.first);
91 ASSERT_EQ(encode_result.second, input);
TEST(Base32Test, CanEncode)
std::pair< bool, std::string > Base32Decode(const std::string &input)
std::pair< bool, std::string > Base32Encode(std::string_view input)