Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
ParseColorTest.cpp File Reference
#include "include/core/SkColor.h"
#include "include/core/SkString.h"
#include "include/utils/SkParse.h"
#include "tests/Test.h"
#include <cstring>

Go to the source code of this file.

Functions

static bool is_valid_name (const SkString &name)
 
 DEF_TEST (ParseNamedColor, reporter)
 

Variables

struct { 
 
   const char *   fName 
 
   SkColor   fColor 
 
gNamedColors [] 
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( ParseNamedColor  ,
reporter   
)

Definition at line 168 of file ParseColorTest.cpp.

168 {
170
171 for (const auto& c : gNamedColors) {
172 // check the real name
173 REPORTER_ASSERT(reporter, SkParse::FindNamedColor(c.fName , strlen(c.fName), &color)
174 == c.fName + strlen(c.fName));
175 REPORTER_ASSERT(reporter, color == c.fColor);
176
177 // check partial prefixes
178 for (int l = strlen(c.fName) - 1; l >= 0; --l) {
179 SkString s(c.fName, l);
180 // some substrings are valid color names
181 if (is_valid_name(s)) continue;
182
183 REPORTER_ASSERT(reporter, SkParse::FindNamedColor(s.c_str(), l, &color) == nullptr);
184 }
185
186 // check suffixes
187 SkString s(c.fName, strlen(c.fName));
188 s.append("A");
189 REPORTER_ASSERT(reporter, SkParse::FindNamedColor(s.c_str(), s.size(), &color) == nullptr);
190 }
191
192 // some oddballs
194 REPORTER_ASSERT(reporter, SkParse::FindNamedColor("aaa", 3, &color) == nullptr);
195 REPORTER_ASSERT(reporter, SkParse::FindNamedColor("zzz", 3, &color) == nullptr);
196 REPORTER_ASSERT(reporter, SkParse::FindNamedColor("aaaaaaaaaaaa", 12, &color) == nullptr);
197 REPORTER_ASSERT(reporter, SkParse::FindNamedColor("zzzzzzzzzzzz", 12, &color) == nullptr);
198}
reporter
SkColor4f color
static constexpr struct @440 gNamedColors[]
static bool is_valid_name(const SkString &name)
uint32_t SkColor
Definition SkColor.h:37
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
static const char * FindNamedColor(const char str[], size_t len, SkColor *color)
struct MyStruct s

◆ is_valid_name()

static bool is_valid_name ( const SkString name)
static

Definition at line 161 of file ParseColorTest.cpp.

161 {
162 for (const auto& c : gNamedColors) {
163 if (name.equals(c.fName)) return true;
164 }
165 return false;
166}
const char * name
Definition fuchsia.cc:50

Variable Documentation

◆ fColor

SkColor fColor

Definition at line 17 of file ParseColorTest.cpp.

◆ fName

const char* fName

Definition at line 16 of file ParseColorTest.cpp.

◆ [struct]

constexpr struct { ... } gNamedColors[]