Index: tests/ValueTest.cpp |
diff --git a/tests/ValueTest.cpp b/tests/ValueTest.cpp |
index 220ef2f9aeceb43d318a2c2f3c250a837c9c25d4..931c26d49f4cb2fba3dbf1ecfea7b55d9e2a51dc 100644 |
--- a/tests/ValueTest.cpp |
+++ b/tests/ValueTest.cpp |
@@ -5,5 +5,43 @@ |
* found in the LICENSE file. |
*/ |
-#include "Test.h" |
#include "SkValue.h" |
+#include "Test.h" |
+ |
+static const SkValue::Type example_type = SkValue::Type(0x80000001); |
+ |
+enum { kExampleS32, kExampleF32, kExampleU32, kExampleObject}; |
+ |
+#define EXAMPLES(FN) \ |
mtklein
2016/01/15 20:42:20
Let's expand this out?
|
+ FN(kExampleS32, S32, s32, -123) \ |
+ FN(kExampleF32, F32, f32, 0.5f) \ |
+ FN(kExampleU32, U32, u32, 1234) \ |
+ |
+static SkValue make_example(skiatest::Reporter* r, int level = 4) { |
+ auto value = SkValue::Object(example_type); |
+ value.set(kExampleU32, SkValue::FromU32(1000)); |
+ |
+ #define FN(KEY, FNAME, MNAME, VALUE) \ |
+ value.set(KEY, SkValue::From##FNAME(VALUE)); |
+ EXAMPLES(FN) |
+ #undef FN |
+ if (level > 0) { |
+ value.set(kExampleObject, make_example(r, 0)); |
+ value.set(kExampleObject, make_example(r, level - 1)); // replace |
+ } |
+ return value; |
+} |
+ |
+DEF_TEST(Value, r) { |
+ SkValue val = make_example(r); |
+ REPORTER_ASSERT(r, example_type == val.type()); |
+ val.set(4321, SkValue()); |
+ SkValue valCopy = val; |
+ REPORTER_ASSERT(r, example_type == valCopy.type()); |
+ #define FN(KEY, FNAME, MNAME, VALUE) { \ |
+ const SkValue* v = val.get(KEY); \ |
+ REPORTER_ASSERT(r, v && VALUE == v->MNAME()); \ |
+ } |
+ EXAMPLES(FN) |
+ #undef FN |
+} |