Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
MetaDataTest.cpp File Reference
#include "include/core/SkScalar.h"
#include "tests/Test.h"
#include "tools/SkMetaData.h"
#include <array>
#include <cstddef>
#include <cstdint>
#include <cstring>

Go to the source code of this file.

Functions

 DEF_TEST (MetaData, reporter)
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( MetaData  ,
reporter   
)

Definition at line 17 of file MetaDataTest.cpp.

17 {
18 SkMetaData m1;
19
20 REPORTER_ASSERT(reporter, !m1.findS32("int"));
21 REPORTER_ASSERT(reporter, !m1.findScalar("scalar"));
24
25 m1.setS32("int", 12345);
26 m1.setScalar("scalar", SK_Scalar1 * 42);
27 m1.setPtr("ptr", &m1);
28 m1.setBool("true", true);
29 m1.setBool("false", false);
30
31 int32_t n;
32 SkScalar s;
33
34 m1.setScalar("scalar", SK_Scalar1/2);
35
36 REPORTER_ASSERT(reporter, m1.findS32("int", &n) && n == 12345);
37 REPORTER_ASSERT(reporter, m1.findScalar("scalar", &s) && s == SK_Scalar1/2);
38 REPORTER_ASSERT(reporter, m1.hasBool("true", true));
39 REPORTER_ASSERT(reporter, m1.hasBool("false", false));
40
41 SkMetaData::Iter iter(m1);
42 const char* name;
43
44 static const struct {
45 const char* fName;
46 SkMetaData::Type fType;
47 int fCount;
48 } gElems[] = {
49 { "int", SkMetaData::kS32_Type, 1 },
50 { "scalar", SkMetaData::kScalar_Type, 1 },
51 { "ptr", SkMetaData::kPtr_Type, 1 },
52 { "true", SkMetaData::kBool_Type, 1 },
53 { "false", SkMetaData::kBool_Type, 1 }
54 };
55
56 size_t loop = 0;
57 int count;
59 while ((name = iter.next(&t, &count)) != nullptr)
60 {
61 int match = 0;
62 for (unsigned i = 0; i < std::size(gElems); i++)
63 {
64 if (!strcmp(name, gElems[i].fName))
65 {
66 match += 1;
67 REPORTER_ASSERT(reporter, gElems[i].fType == t);
68 REPORTER_ASSERT(reporter, gElems[i].fCount == count);
69 }
70 }
72 loop += 1;
73 }
74 REPORTER_ASSERT(reporter, loop == std::size(gElems));
75
80
81 REPORTER_ASSERT(reporter, !m1.findS32("int"));
82 REPORTER_ASSERT(reporter, !m1.findScalar("scalar"));
83 REPORTER_ASSERT(reporter, !m1.findBool("true"));
84 REPORTER_ASSERT(reporter, !m1.findBool("false"));
85}
static bool match(const char *needle, const char *haystack)
Definition DM.cpp:1132
const char * fName
reporter
int count
#define SK_Scalar1
Definition SkScalar.h:18
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
bool hasBool(const char name[], bool value) const
Definition SkMetaData.h:40
bool removeBool(const char name[])
bool findScalar(const char name[], SkScalar *value=nullptr) const
void setS32(const char name[], int32_t value)
void setPtr(const char name[], void *value)
bool removeScalar(const char name[])
bool removeS32(const char name[])
void setBool(const char name[], bool value)
void setScalar(const char name[], SkScalar value)
bool findBool(const char name[], bool *value=nullptr) const
bool findS32(const char name[], int32_t *value=nullptr) const
float SkScalar
Definition extension.cpp:12
struct MyStruct s
const char * name
Definition fuchsia.cc:50