OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkValue.h" | |
8 #include "Test.h" | 9 #include "Test.h" |
9 #include "SkValue.h" | 10 |
11 static const SkValue::Type example_type = SkValue::Type(0x80000001); | |
12 | |
13 enum { kExampleS32, kExampleF32, kExampleU32, kExampleObject}; | |
14 | |
15 #define EXAMPLES(FN) \ | |
mtklein
2016/01/15 20:42:20
Let's expand this out?
| |
16 FN(kExampleS32, S32, s32, -123) \ | |
17 FN(kExampleF32, F32, f32, 0.5f) \ | |
18 FN(kExampleU32, U32, u32, 1234) \ | |
19 | |
20 static SkValue make_example(skiatest::Reporter* r, int level = 4) { | |
21 auto value = SkValue::Object(example_type); | |
22 value.set(kExampleU32, SkValue::FromU32(1000)); | |
23 | |
24 #define FN(KEY, FNAME, MNAME, VALUE) \ | |
25 value.set(KEY, SkValue::From##FNAME(VALUE)); | |
26 EXAMPLES(FN) | |
27 #undef FN | |
28 if (level > 0) { | |
29 value.set(kExampleObject, make_example(r, 0)); | |
30 value.set(kExampleObject, make_example(r, level - 1)); // replace | |
31 } | |
32 return value; | |
33 } | |
34 | |
35 DEF_TEST(Value, r) { | |
36 SkValue val = make_example(r); | |
37 REPORTER_ASSERT(r, example_type == val.type()); | |
38 val.set(4321, SkValue()); | |
39 SkValue valCopy = val; | |
40 REPORTER_ASSERT(r, example_type == valCopy.type()); | |
41 #define FN(KEY, FNAME, MNAME, VALUE) { \ | |
42 const SkValue* v = val.get(KEY); \ | |
43 REPORTER_ASSERT(r, v && VALUE == v->MNAME()); \ | |
44 } | |
45 EXAMPLES(FN) | |
46 #undef FN | |
47 } | |
OLD | NEW |