1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2011 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#include "include/core/SkRefCnt.h" 9cb93a386Sopenharmony_ci#include "tests/Test.h" 10cb93a386Sopenharmony_ci#include "tools/SkMetaData.h" 11cb93a386Sopenharmony_ci 12cb93a386Sopenharmony_ciDEF_TEST(MetaData, reporter) { 13cb93a386Sopenharmony_ci SkMetaData m1; 14cb93a386Sopenharmony_ci 15cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !m1.findS32("int")); 16cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !m1.findScalar("scalar")); 17cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !m1.removeS32("int")); 18cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !m1.removeScalar("scalar")); 19cb93a386Sopenharmony_ci 20cb93a386Sopenharmony_ci m1.setS32("int", 12345); 21cb93a386Sopenharmony_ci m1.setScalar("scalar", SK_Scalar1 * 42); 22cb93a386Sopenharmony_ci m1.setPtr("ptr", &m1); 23cb93a386Sopenharmony_ci m1.setBool("true", true); 24cb93a386Sopenharmony_ci m1.setBool("false", false); 25cb93a386Sopenharmony_ci 26cb93a386Sopenharmony_ci int32_t n; 27cb93a386Sopenharmony_ci SkScalar s; 28cb93a386Sopenharmony_ci 29cb93a386Sopenharmony_ci m1.setScalar("scalar", SK_Scalar1/2); 30cb93a386Sopenharmony_ci 31cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, m1.findS32("int", &n) && n == 12345); 32cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, m1.findScalar("scalar", &s) && s == SK_Scalar1/2); 33cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, m1.hasBool("true", true)); 34cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, m1.hasBool("false", false)); 35cb93a386Sopenharmony_ci 36cb93a386Sopenharmony_ci SkMetaData::Iter iter(m1); 37cb93a386Sopenharmony_ci const char* name; 38cb93a386Sopenharmony_ci 39cb93a386Sopenharmony_ci static const struct { 40cb93a386Sopenharmony_ci const char* fName; 41cb93a386Sopenharmony_ci SkMetaData::Type fType; 42cb93a386Sopenharmony_ci int fCount; 43cb93a386Sopenharmony_ci } gElems[] = { 44cb93a386Sopenharmony_ci { "int", SkMetaData::kS32_Type, 1 }, 45cb93a386Sopenharmony_ci { "scalar", SkMetaData::kScalar_Type, 1 }, 46cb93a386Sopenharmony_ci { "ptr", SkMetaData::kPtr_Type, 1 }, 47cb93a386Sopenharmony_ci { "true", SkMetaData::kBool_Type, 1 }, 48cb93a386Sopenharmony_ci { "false", SkMetaData::kBool_Type, 1 } 49cb93a386Sopenharmony_ci }; 50cb93a386Sopenharmony_ci 51cb93a386Sopenharmony_ci int loop = 0; 52cb93a386Sopenharmony_ci int count; 53cb93a386Sopenharmony_ci SkMetaData::Type t; 54cb93a386Sopenharmony_ci while ((name = iter.next(&t, &count)) != nullptr) 55cb93a386Sopenharmony_ci { 56cb93a386Sopenharmony_ci int match = 0; 57cb93a386Sopenharmony_ci for (unsigned i = 0; i < SK_ARRAY_COUNT(gElems); i++) 58cb93a386Sopenharmony_ci { 59cb93a386Sopenharmony_ci if (!strcmp(name, gElems[i].fName)) 60cb93a386Sopenharmony_ci { 61cb93a386Sopenharmony_ci match += 1; 62cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, gElems[i].fType == t); 63cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, gElems[i].fCount == count); 64cb93a386Sopenharmony_ci } 65cb93a386Sopenharmony_ci } 66cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, match == 1); 67cb93a386Sopenharmony_ci loop += 1; 68cb93a386Sopenharmony_ci } 69cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, loop == SK_ARRAY_COUNT(gElems)); 70cb93a386Sopenharmony_ci 71cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, m1.removeS32("int")); 72cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, m1.removeScalar("scalar")); 73cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, m1.removeBool("true")); 74cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, m1.removeBool("false")); 75cb93a386Sopenharmony_ci 76cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !m1.findS32("int")); 77cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !m1.findScalar("scalar")); 78cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !m1.findBool("true")); 79cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !m1.findBool("false")); 80cb93a386Sopenharmony_ci} 81