2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "include/core/SkRefCnt.h"
9 #include "tests/Test.h"
10 #include "tools/SkMetaData.h"
12 DEF_TEST(MetaData, reporter) {
15 REPORTER_ASSERT(reporter, !m1.findS32("int"));
16 REPORTER_ASSERT(reporter, !m1.findScalar("scalar"));
17 REPORTER_ASSERT(reporter, !m1.removeS32("int"));
18 REPORTER_ASSERT(reporter, !m1.removeScalar("scalar"));
20 m1.setS32("int", 12345);
21 m1.setScalar("scalar", SK_Scalar1 * 42);
22 m1.setPtr("ptr", &m1);
23 m1.setBool("true", true);
24 m1.setBool("false", false);
29 m1.setScalar("scalar", SK_Scalar1/2);
31 REPORTER_ASSERT(reporter, m1.findS32("int", &n) && n == 12345);
32 REPORTER_ASSERT(reporter, m1.findScalar("scalar", &s) && s == SK_Scalar1/2);
33 REPORTER_ASSERT(reporter, m1.hasBool("true", true));
34 REPORTER_ASSERT(reporter, m1.hasBool("false", false));
36 SkMetaData::Iter iter(m1);
41 SkMetaData::Type fType;
44 { "int", SkMetaData::kS32_Type, 1 },
45 { "scalar", SkMetaData::kScalar_Type, 1 },
46 { "ptr", SkMetaData::kPtr_Type, 1 },
47 { "true", SkMetaData::kBool_Type, 1 },
48 { "false", SkMetaData::kBool_Type, 1 }
54 while ((name = iter.next(&t, &count)) != nullptr)
57 for (unsigned i = 0; i < SK_ARRAY_COUNT(gElems); i++)
59 if (!strcmp(name, gElems[i].fName))
62 REPORTER_ASSERT(reporter, gElems[i].fType == t);
63 REPORTER_ASSERT(reporter, gElems[i].fCount == count);
66 REPORTER_ASSERT(reporter, match == 1);
69 REPORTER_ASSERT(reporter, loop == SK_ARRAY_COUNT(gElems));
71 REPORTER_ASSERT(reporter, m1.removeS32("int"));
72 REPORTER_ASSERT(reporter, m1.removeScalar("scalar"));
73 REPORTER_ASSERT(reporter, m1.removeBool("true"));
74 REPORTER_ASSERT(reporter, m1.removeBool("false"));
76 REPORTER_ASSERT(reporter, !m1.findS32("int"));
77 REPORTER_ASSERT(reporter, !m1.findScalar("scalar"));
78 REPORTER_ASSERT(reporter, !m1.findBool("true"));
79 REPORTER_ASSERT(reporter, !m1.findBool("false"));