epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | */ |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkRefCnt.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "tests/Test.h" |
Mike Klein | 52337de | 2019-07-25 09:00:52 -0500 | [diff] [blame] | 10 | #include "tools/SkMetaData.h" |
reed@google.com | e733071 | 2011-03-30 18:23:21 +0000 | [diff] [blame] | 11 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 12 | DEF_TEST(MetaData, reporter) { |
reed@google.com | e733071 | 2011-03-30 18:23:21 +0000 | [diff] [blame] | 13 | SkMetaData m1; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 14 | |
reed@google.com | e733071 | 2011-03-30 18:23:21 +0000 | [diff] [blame] | 15 | REPORTER_ASSERT(reporter, !m1.findS32("int")); |
| 16 | REPORTER_ASSERT(reporter, !m1.findScalar("scalar")); |
reed@google.com | e733071 | 2011-03-30 18:23:21 +0000 | [diff] [blame] | 17 | REPORTER_ASSERT(reporter, !m1.removeS32("int")); |
| 18 | REPORTER_ASSERT(reporter, !m1.removeScalar("scalar")); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 19 | |
reed@google.com | e733071 | 2011-03-30 18:23:21 +0000 | [diff] [blame] | 20 | m1.setS32("int", 12345); |
| 21 | m1.setScalar("scalar", SK_Scalar1 * 42); |
reed@google.com | e733071 | 2011-03-30 18:23:21 +0000 | [diff] [blame] | 22 | m1.setPtr("ptr", &m1); |
| 23 | m1.setBool("true", true); |
| 24 | m1.setBool("false", false); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 25 | |
reed@google.com | e733071 | 2011-03-30 18:23:21 +0000 | [diff] [blame] | 26 | int32_t n; |
| 27 | SkScalar s; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 28 | |
reed@google.com | e733071 | 2011-03-30 18:23:21 +0000 | [diff] [blame] | 29 | m1.setScalar("scalar", SK_Scalar1/2); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 30 | |
reed@google.com | e733071 | 2011-03-30 18:23:21 +0000 | [diff] [blame] | 31 | REPORTER_ASSERT(reporter, m1.findS32("int", &n) && n == 12345); |
| 32 | REPORTER_ASSERT(reporter, m1.findScalar("scalar", &s) && s == SK_Scalar1/2); |
reed@google.com | e733071 | 2011-03-30 18:23:21 +0000 | [diff] [blame] | 33 | REPORTER_ASSERT(reporter, m1.hasBool("true", true)); |
| 34 | REPORTER_ASSERT(reporter, m1.hasBool("false", false)); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 35 | |
reed@google.com | e733071 | 2011-03-30 18:23:21 +0000 | [diff] [blame] | 36 | SkMetaData::Iter iter(m1); |
| 37 | const char* name; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 38 | |
reed@google.com | e733071 | 2011-03-30 18:23:21 +0000 | [diff] [blame] | 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 }, |
reed@google.com | e733071 | 2011-03-30 18:23:21 +0000 | [diff] [blame] | 47 | { "true", SkMetaData::kBool_Type, 1 }, |
| 48 | { "false", SkMetaData::kBool_Type, 1 } |
| 49 | }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 50 | |
reed@google.com | e733071 | 2011-03-30 18:23:21 +0000 | [diff] [blame] | 51 | int loop = 0; |
| 52 | int count; |
| 53 | SkMetaData::Type t; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 54 | while ((name = iter.next(&t, &count)) != nullptr) |
reed@google.com | e733071 | 2011-03-30 18:23:21 +0000 | [diff] [blame] | 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)); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 70 | |
reed@google.com | e733071 | 2011-03-30 18:23:21 +0000 | [diff] [blame] | 71 | REPORTER_ASSERT(reporter, m1.removeS32("int")); |
| 72 | REPORTER_ASSERT(reporter, m1.removeScalar("scalar")); |
reed@google.com | e733071 | 2011-03-30 18:23:21 +0000 | [diff] [blame] | 73 | REPORTER_ASSERT(reporter, m1.removeBool("true")); |
| 74 | REPORTER_ASSERT(reporter, m1.removeBool("false")); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 75 | |
reed@google.com | e733071 | 2011-03-30 18:23:21 +0000 | [diff] [blame] | 76 | REPORTER_ASSERT(reporter, !m1.findS32("int")); |
| 77 | REPORTER_ASSERT(reporter, !m1.findScalar("scalar")); |
reed@google.com | e733071 | 2011-03-30 18:23:21 +0000 | [diff] [blame] | 78 | REPORTER_ASSERT(reporter, !m1.findBool("true")); |
| 79 | REPORTER_ASSERT(reporter, !m1.findBool("false")); |
reed@google.com | e733071 | 2011-03-30 18:23:21 +0000 | [diff] [blame] | 80 | } |