1 /* 2 * Copyright 2011 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "include/core/SkRefCnt.h" 9 #include "tests/Test.h" 10 #include "tools/SkMetaData.h" 11 DEF_TEST(MetaData,reporter)12 DEF_TEST(MetaData, reporter) { 13 SkMetaData m1; 14 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")); 19 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); 25 26 int32_t n; 27 SkScalar s; 28 29 m1.setScalar("scalar", SK_Scalar1/2); 30 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)); 35 36 SkMetaData::Iter iter(m1); 37 const char* name; 38 39 static const struct { 40 const char* fName; 41 SkMetaData::Type fType; 42 int fCount; 43 } gElems[] = { 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 } 49 }; 50 51 int loop = 0; 52 int count; 53 SkMetaData::Type t; 54 while ((name = iter.next(&t, &count)) != nullptr) 55 { 56 int match = 0; 57 for (unsigned i = 0; i < SK_ARRAY_COUNT(gElems); i++) 58 { 59 if (!strcmp(name, gElems[i].fName)) 60 { 61 match += 1; 62 REPORTER_ASSERT(reporter, gElems[i].fType == t); 63 REPORTER_ASSERT(reporter, gElems[i].fCount == count); 64 } 65 } 66 REPORTER_ASSERT(reporter, match == 1); 67 loop += 1; 68 } 69 REPORTER_ASSERT(reporter, loop == SK_ARRAY_COUNT(gElems)); 70 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")); 75 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")); 80 } 81