Flutter Engine
 
Loading...
Searching...
No Matches
catalog_unittests.cc File Reference
#include "flutter/tools/licenses_cpp/src/catalog.h"
#include "gtest/gtest.h"

Go to the source code of this file.

Functions

 TEST (CatalogTest, Simple)
 
 TEST (CatalogTest, MultipleMatchOverlapping)
 
 TEST (CatalogTest, MultipleSelectorsFail)
 
 TEST (CatalogTest, OnlyOneSelectorsFail)
 
 TEST (CatalogTest, MultipleMatchNoOverlap)
 
 TEST (CatalogTest, NoSelectorMatch)
 
 TEST (CatalogTest, NoSelectionMatch)
 
 TEST (CatalogTest, SimpleParseEntry)
 
 TEST (CatalogTest, SkiaLicense)
 
 TEST (CatalogTest, SkiaLicenseIgnoreWhitespace)
 
 TEST (CatalogTest, SkiaLicenseIgnoreTrailing)
 
 TEST (CatalogTest, ExtractsGroups)
 

Variables

static const char * kEntry
 
static const char * kSkiaLicense
 

Function Documentation

◆ TEST() [1/12]

TEST ( CatalogTest  ,
ExtractsGroups   
)

Definition at line 237 of file catalog_unittests.cc.

239 {
240 std::string entry_text = R"entry(entry
241start.*stop.*last
242start(.*)stop(.*)last
243)entry";
244 std::stringstream ss;
245 ss << entry_text;
246 absl::StatusOr<Catalog::Entry> entry = Catalog::ParseEntry(ss);
247 ASSERT_TRUE(entry.ok()) << entry.status();
248 absl::StatusOr<Catalog> catalog = Catalog::Make({*entry});
249 ASSERT_TRUE(catalog.ok());
250
251 std::string text = "start hello stop world last";
252
253 absl::StatusOr<std::vector<Catalog::Match>> match = catalog->FindMatch(text);
254 EXPECT_TRUE(match.ok()) << match.status();
255 ASSERT_EQ(match->size(), 1u);
static absl::StatusOr< Entry > ParseEntry(std::istream &is)
VisibleForTesting.
Definition catalog.cc:243
static absl::StatusOr< Catalog > Make(const std::vector< Entry > &entries)
Make a Catalog for testing.
Definition catalog.cc:151
std::u16string text

◆ TEST() [2/12]

TEST ( CatalogTest  ,
MultipleMatchNoOverlap   
)

Definition at line 123 of file catalog_unittests.cc.

123 {
124 absl::StatusOr<Catalog> catalog =
125 Catalog::Make({{"foo", ".*foo", ".*foo"}, {"bar", "bar.*", "bar.*"}});
126 ASSERT_TRUE(catalog.ok()) << catalog.status();
127 absl::StatusOr<std::vector<Catalog::Match>> has_match =
128 catalog->FindMatch("hello foo bar world");
129 ASSERT_TRUE(has_match.ok()) << has_match.status();
130}

References Catalog::Make().

◆ TEST() [3/12]

TEST ( CatalogTest  ,
MultipleMatchOverlapping   
)

Definition at line 81 of file catalog_unittests.cc.

81 {
82 absl::StatusOr<Catalog> catalog = Catalog::Make(
83 {{"matcher1", ".*foo.*", ".*foo.*"}, {"matcher2", ".*oo.*", ".*oo.*"}});
84 ASSERT_TRUE(catalog.ok()) << catalog.status();
85 absl::StatusOr<std::vector<Catalog::Match>> has_match =
86 catalog->FindMatch("foo");
87 ASSERT_FALSE(has_match.ok());
88 ASSERT_TRUE(RE2::PartialMatch(has_match.status().message(),
89 "Selected matchers overlap"))
90 << has_match.status().message();
91 ASSERT_TRUE(RE2::PartialMatch(has_match.status().message(), "matcher1"))
92 << has_match.status().message();
93 ASSERT_TRUE(RE2::PartialMatch(has_match.status().message(), "matcher2"))
94 << has_match.status().message();
95}

References Catalog::Make().

◆ TEST() [4/12]

TEST ( CatalogTest  ,
MultipleSelectorsFail   
)

Definition at line 97 of file catalog_unittests.cc.

97 {
98 absl::StatusOr<Catalog> catalog = Catalog::Make(
99 {{"matcher1", ".*foo.*", "blah"}, {"matcher2", ".*oo.*", "blah"}});
100 ASSERT_TRUE(catalog.ok()) << catalog.status();
101 absl::StatusOr<std::vector<Catalog::Match>> has_match =
102 catalog->FindMatch("foo");
103 ASSERT_FALSE(has_match.ok());
104 ASSERT_TRUE(RE2::PartialMatch(has_match.status().message(), "matcher1"))
105 << has_match.status().message();
106 ASSERT_TRUE(RE2::PartialMatch(has_match.status().message(), "matcher2"))
107 << has_match.status().message();
108}

References Catalog::Make().

◆ TEST() [5/12]

TEST ( CatalogTest  ,
NoSelectionMatch   
)

Definition at line 141 of file catalog_unittests.cc.

141 {
142 absl::StatusOr<Catalog> catalog =
143 Catalog::Make({{"foobar", ".*foo.*", ".*bar.*"}});
144 ASSERT_TRUE(catalog.ok());
145 absl::StatusOr<std::vector<Catalog::Match>> match = catalog->FindMatch("foo");
146 ASSERT_FALSE(match.ok());
147 ASSERT_EQ(match.status().code(), absl::StatusCode::kNotFound);
148}

References Catalog::Make().

◆ TEST() [6/12]

TEST ( CatalogTest  ,
NoSelectorMatch   
)

Definition at line 132 of file catalog_unittests.cc.

132 {
133 absl::StatusOr<Catalog> catalog =
134 Catalog::Make({{"foobar", ".*bar.*", ".*foo.*"}});
135 ASSERT_TRUE(catalog.ok());
136 absl::StatusOr<std::vector<Catalog::Match>> match = catalog->FindMatch("foo");
137 ASSERT_FALSE(match.ok());
138 ASSERT_EQ(match.status().code(), absl::StatusCode::kNotFound);
139}

References Catalog::Make().

◆ TEST() [7/12]

TEST ( CatalogTest  ,
OnlyOneSelectorsFail   
)

Definition at line 110 of file catalog_unittests.cc.

110 {
111 absl::StatusOr<Catalog> catalog = Catalog::Make(
112 {{"matcher1", ".*foo.*", ".*foo.*"}, {"matcher2", ".*oo.*", "blah"}});
113 ASSERT_TRUE(catalog.ok()) << catalog.status();
114 absl::StatusOr<std::vector<Catalog::Match>> has_match =
115 catalog->FindMatch("foo");
116 ASSERT_FALSE(has_match.ok());
117 ASSERT_TRUE(RE2::PartialMatch(has_match.status().message(), "matcher1"))
118 << has_match.status().message();
119 ASSERT_TRUE(RE2::PartialMatch(has_match.status().message(), "matcher2"))
120 << has_match.status().message();
121}

References Catalog::Make().

◆ TEST() [8/12]

TEST ( CatalogTest  ,
Simple   
)

Definition at line 72 of file catalog_unittests.cc.

72 {
73 absl::StatusOr<Catalog> catalog =
74 Catalog::Make({{"foobar", ".*foo.*", ".*foo.*"}});
75 ASSERT_TRUE(catalog.ok());
76 absl::StatusOr<std::vector<Catalog::Match>> match = catalog->FindMatch("foo");
77 ASSERT_TRUE(match.ok());
78 ASSERT_EQ(match->front().GetMatcher(), "foobar");
79}

References Catalog::Make().

◆ TEST() [9/12]

TEST ( CatalogTest  ,
SimpleParseEntry   
)

Definition at line 150 of file catalog_unittests.cc.

150 {
151 std::stringstream ss;
152 ss << "foobar\n";
153 ss << "unique\n";
154 ss << R"match(Multiline
155matcher
156.*)match";
157
158 absl::StatusOr<Catalog::Entry> entry = Catalog::ParseEntry(ss);
159 EXPECT_TRUE(entry.ok()) << entry.status();
160 if (entry.ok()) {
161 EXPECT_EQ(entry->name, "foobar");
162 EXPECT_EQ(entry->unique, "unique");
163 EXPECT_EQ(entry->matcher, R"match(Multiline\s+matcher\s+.*)match");

References Catalog::ParseEntry().

◆ TEST() [10/12]

TEST ( CatalogTest  ,
SkiaLicense   
)

Definition at line 165 of file catalog_unittests.cc.

167 {
168 std::stringstream ss;
169 ss << kEntry;
170 absl::StatusOr<Catalog::Entry> entry = Catalog::ParseEntry(ss);
171 ASSERT_TRUE(entry.ok()) << entry.status();
172 absl::StatusOr<Catalog> catalog = Catalog::Make({*entry});
173 ASSERT_TRUE(catalog.ok());
174 absl::StatusOr<std::vector<Catalog::Match>> match =
175 catalog->FindMatch(kSkiaLicense);
static const char * kEntry
static const char * kSkiaLicense

◆ TEST() [11/12]

TEST ( CatalogTest  ,
SkiaLicenseIgnoreTrailing   
)

Definition at line 220 of file catalog_unittests.cc.

222 {
223 std::stringstream ss;
224 ss << kEntry;
225 absl::StatusOr<Catalog::Entry> entry = Catalog::ParseEntry(ss);
226 ASSERT_TRUE(entry.ok()) << entry.status();
227 absl::StatusOr<Catalog> catalog = Catalog::Make({*entry});
228 ASSERT_TRUE(catalog.ok());
229
230 std::string no_end(kSkiaLicense);
231 ASSERT_EQ(no_end.back(), '\n');
232 no_end.pop_back();
233
234 absl::StatusOr<std::vector<Catalog::Match>> match =
235 catalog->FindMatch(no_end);

◆ TEST() [12/12]

TEST ( CatalogTest  ,
SkiaLicenseIgnoreWhitespace   
)

Definition at line 203 of file catalog_unittests.cc.

205 {
206 std::stringstream ss;
207 ss << kEntry;
208 absl::StatusOr<Catalog::Entry> entry = Catalog::ParseEntry(ss);
209 ASSERT_TRUE(entry.ok()) << entry.status();
210 absl::StatusOr<Catalog> catalog = Catalog::Make({*entry});
211 ASSERT_TRUE(catalog.ok());
212
213 std::string no_newline_license = RemoveNewlines(kSkiaLicense);
214
215 absl::StatusOr<std::vector<Catalog::Match>> match =
216 catalog->FindMatch(no_newline_license);
217 ASSERT_TRUE(match.ok()) << match.status();
218 ASSERT_EQ(match->size(), 1u);

Variable Documentation

◆ kEntry

const char* kEntry
static

Definition at line 7 of file catalog_unittests.cc.

◆ kSkiaLicense

const char* kSkiaLicense
static

Definition at line 40 of file catalog_unittests.cc.