Flutter Engine
base32_unittest.cc File Reference
#include "flutter/fml/base32.h"
#include <iostream>
#include "gtest/gtest.h"

Go to the source code of this file.

Functions

 TEST (Base32Test, CanEncode)
 
 TEST (Base32Test, CanEncodeDecodeStrings)
 
 TEST (Base32Test, DecodeReturnsFalseForInvalideInput)
 
 TEST (Base32Test, CanDecodeSkSLKeys)
 

Function Documentation

◆ TEST() [1/4]

TEST ( Base32Test  ,
CanEncode   
)

Definition at line 11 of file base32_unittest.cc.

References fml::Base32Encode().

11  {
12  {
13  auto result = fml::Base32Encode("hello");
14  ASSERT_TRUE(result.first);
15  ASSERT_EQ(result.second, "NBSWY3DP");
16  }
17 
18  {
19  auto result = fml::Base32Encode("helLo");
20  ASSERT_TRUE(result.first);
21  ASSERT_EQ(result.second, "NBSWYTDP");
22  }
23 
24  {
25  auto result = fml::Base32Encode("");
26  ASSERT_TRUE(result.first);
27  ASSERT_EQ(result.second, "");
28  }
29 
30  {
31  auto result = fml::Base32Encode("1");
32  ASSERT_TRUE(result.first);
33  ASSERT_EQ(result.second, "GE");
34  }
35 
36  {
37  auto result = fml::Base32Encode("helLo");
38  ASSERT_TRUE(result.first);
39  ASSERT_EQ(result.second, "NBSWYTDP");
40  }
41 }
std::pair< bool, std::string > Base32Encode(std::string_view input)
Definition: base32.cc:14

◆ TEST() [2/4]

TEST ( Base32Test  ,
CanEncodeDecodeStrings   
)

Definition at line 43 of file base32_unittest.cc.

References fml::Base32Decode(), and fml::Base32Encode().

43  {
44  std::vector<std::string> strings = {"hello", "helLo", "", "1", "\0"};
45  for (size_t i = 0; i < strings.size(); i += 1) {
46  auto encode_result = fml::Base32Encode(strings[i]);
47  ASSERT_TRUE(encode_result.first);
48  auto decode_result = fml::Base32Decode(encode_result.second);
49  ASSERT_TRUE(decode_result.first);
50  const std::string& decoded = decode_result.second;
51  std::string decoded_string(decoded.data(), decoded.size());
52  ASSERT_EQ(strings[i], decoded_string);
53  }
54 }
std::pair< bool, std::string > Base32Encode(std::string_view input)
Definition: base32.cc:14
std::pair< bool, std::string > Base32Decode(const std::string &input)
Definition: base32.cc:54

◆ TEST() [3/4]

TEST ( Base32Test  ,
DecodeReturnsFalseForInvalideInput   
)

Definition at line 56 of file base32_unittest.cc.

References fml::Base32Decode().

56  {
57  // "B" is invalid because it has a non-zero padding.
58  std::vector<std::string> invalid_inputs = {"a", "1", "9", "B"};
59  for (const std::string& input : invalid_inputs) {
60  auto decode_result = fml::Base32Decode(input);
61  if (decode_result.first) {
62  std::cout << "Base32Decode should return false on " << input << std::endl;
63  }
64  ASSERT_FALSE(decode_result.first);
65  }
66 }
std::pair< bool, std::string > Base32Decode(const std::string &input)
Definition: base32.cc:54

◆ TEST() [4/4]

TEST ( Base32Test  ,
CanDecodeSkSLKeys   
)

Definition at line 68 of file base32_unittest.cc.

References fml::Base32Decode(), and fml::Base32Encode().

68  {
69  std::vector<std::string> inputs = {
70  "CAZAAAACAAAAADQAAAABKAAAAAJQAAIA7777777777776EYAAEAP777777777777AAAAAABA"
71  "ABTAAAAAAAAAAAAAAABAAAAAGQAGGAA",
72  "CAZAAAICAAAAAAAAAAADOAAAAAJQAAIA777777Y4AAKAAEYAAEAP777777777777EAAGMAAA"
73  "AAAAAAAAAAACQACNAAAAAAAAAAAAAAACAAAAAPAAMMAA",
74  "CAZACAACAAAABAYACAAAAAAAAAJQAAIADQABIAH777777777777RQAAOAAAAAAAAAAAAAABE"
75  "AANQAAAAAAAAAAAAAAYAAJYAAAAAAAANAAAQAAAAAAAEAAAHAAAAAAAAAAAAAAANAAAQAAAA"
76  "AAAFIADKAAAAAAAAAAAAAAACAAAAAZAAMMAA"};
77  for (const std::string& input : inputs) {
78  auto decode_result = fml::Base32Decode(input);
79  if (!decode_result.first) {
80  std::cout << "Base32Decode should return true on " << input << std::endl;
81  }
82  ASSERT_TRUE(decode_result.first);
83  auto encode_result = fml::Base32Encode(decode_result.second);
84  ASSERT_TRUE(encode_result.first);
85  ASSERT_EQ(encode_result.second, input);
86  }
87 }
std::pair< bool, std::string > Base32Encode(std::string_view input)
Definition: base32.cc:14
std::pair< bool, std::string > Base32Decode(const std::string &input)
Definition: base32.cc:54