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(), and result.

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 
42  {
43  auto result = fml::Base32Encode("\xff\xfe\x7f\x80\x81");
44  ASSERT_TRUE(result.first);
45  ASSERT_EQ(result.second, "777H7AEB");
46  }
47 }
GAsyncResult * result
std::pair< bool, std::string > Base32Encode(std::string_view input)
Definition: base32.cc:14

◆ TEST() [2/4]

TEST ( Base32Test  ,
CanEncodeDecodeStrings   
)

Definition at line 49 of file base32_unittest.cc.

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

49  {
50  std::vector<std::string> strings = {"hello", "helLo", "", "1", "\0"};
51  for (size_t i = 0; i < strings.size(); i += 1) {
52  auto encode_result = fml::Base32Encode(strings[i]);
53  ASSERT_TRUE(encode_result.first);
54  auto decode_result = fml::Base32Decode(encode_result.second);
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);
59  }
60 }
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 62 of file base32_unittest.cc.

References fml::Base32Decode().

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

◆ TEST() [4/4]

TEST ( Base32Test  ,
CanDecodeSkSLKeys   
)

Definition at line 74 of file base32_unittest.cc.

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

74  {
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) {
84  auto decode_result = fml::Base32Decode(input);
85  if (!decode_result.first) {
86  std::cout << "Base32Decode should return true on " << input << std::endl;
87  }
88  ASSERT_TRUE(decode_result.first);
89  auto encode_result = fml::Base32Encode(decode_result.second);
90  ASSERT_TRUE(encode_result.first);
91  ASSERT_EQ(encode_result.second, input);
92  }
93 }
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