OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 #ifndef gm_expectations_DEFINED | 7 #ifndef gm_expectations_DEFINED |
8 #define gm_expectations_DEFINED | 8 #define gm_expectations_DEFINED |
9 | 9 |
10 #include "gm.h" | 10 #include "gm.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #pragma warning(disable : 4530) | 23 #pragma warning(disable : 4530) |
24 #endif | 24 #endif |
25 #include "json/reader.h" | 25 #include "json/reader.h" |
26 #include "json/value.h" | 26 #include "json/value.h" |
27 #ifdef SK_BUILD_FOR_WIN | 27 #ifdef SK_BUILD_FOR_WIN |
28 #pragma warning(pop) | 28 #pragma warning(pop) |
29 #endif | 29 #endif |
30 | 30 |
31 namespace skiagm { | 31 namespace skiagm { |
32 | 32 |
33 // The actual type we use to represent a checksum is hidden in here. | |
34 typedef Json::UInt64 Checksum; | |
35 static inline Json::Value asJsonValue(Checksum checksum) { | |
36 return checksum; | |
37 } | |
38 static inline Checksum asChecksum(Json::Value jsonValue) { | |
39 return jsonValue.asUInt64(); | |
40 } | |
41 | |
42 void gm_fprintf(FILE *stream, const char format[], ...); | 33 void gm_fprintf(FILE *stream, const char format[], ...); |
43 | 34 |
44 /** | 35 /** |
45 * Assembles rootPath and relativePath into a single path, like this: | 36 * Assembles rootPath and relativePath into a single path, like this: |
46 * rootPath/relativePath | 37 * rootPath/relativePath |
47 * | 38 * |
48 * Uses SkPATH_SEPARATOR, to work on all platforms. | 39 * Uses SkPATH_SEPARATOR, to work on all platforms. |
49 * | 40 * |
50 * TODO(epoger): This should probably move into SkOSFile.h | 41 * TODO(epoger): This should probably move into SkOSFile.h |
51 */ | 42 */ |
52 SkString SkPathJoin(const char *rootPath, const char *relativePath); | 43 SkString SkPathJoin(const char *rootPath, const char *relativePath); |
53 | 44 |
54 Json::Value ActualResultAsJsonValue(const SkHashDigest& result); | |
55 | |
56 Json::Value CreateJsonTree(Json::Value expectedResults, | 45 Json::Value CreateJsonTree(Json::Value expectedResults, |
57 Json::Value actualResultsFailed, | 46 Json::Value actualResultsFailed, |
58 Json::Value actualResultsFailureIgnored, | 47 Json::Value actualResultsFailureIgnored, |
59 Json::Value actualResultsNoComparison, | 48 Json::Value actualResultsNoComparison, |
60 Json::Value actualResultsSucceeded); | 49 Json::Value actualResultsSucceeded); |
61 | 50 |
62 /** | 51 /** |
63 * Test expectations (allowed image checksums, etc.) | 52 * The digest of a GM test result. |
| 53 * |
| 54 * Currently, this is always a uint64_t hash digest of an SkBitmap... |
| 55 * but we will add other flavors soon. |
| 56 */ |
| 57 class GmResultDigest { |
| 58 public: |
| 59 /** |
| 60 * Create a ResultDigest representing an actual image result. |
| 61 */ |
| 62 GmResultDigest(const SkBitmap &bitmap); |
| 63 |
| 64 /** |
| 65 * Create a ResultDigest representing an allowed result |
| 66 * checksum within JSON expectations file, in the form |
| 67 * ["bitmap-64bitMD5", 12345]. |
| 68 */ |
| 69 GmResultDigest(const Json::Value &jsonTypeValuePair); |
| 70 |
| 71 /** |
| 72 * Returns true if this GmResultDigest was fully and successfully |
| 73 * created. |
| 74 */ |
| 75 bool isValid() const; |
| 76 |
| 77 /** |
| 78 * Returns true if this and other GmResultDigest could |
| 79 * represent identical results. |
| 80 */ |
| 81 bool equals(const GmResultDigest &other) const; |
| 82 |
| 83 /** |
| 84 * Returns a JSON type/value pair representing this result, |
| 85 * such as ["bitmap-64bitMD5", 12345]. |
| 86 */ |
| 87 Json::Value asJsonTypeValuePair() const; |
| 88 |
| 89 private: |
| 90 bool fIsValid; // always check this first--if it's false, other fields a
re meaningless |
| 91 uint64_t fHashDigest; |
| 92 }; |
| 93 |
| 94 /** |
| 95 * Test expectations (allowed image results, etc.) |
64 */ | 96 */ |
65 class Expectations { | 97 class Expectations { |
66 public: | 98 public: |
67 /** | 99 /** |
68 * No expectations at all. | 100 * No expectations at all. |
69 */ | 101 */ |
70 Expectations(bool ignoreFailure=kDefaultIgnoreFailure); | 102 Expectations(bool ignoreFailure=kDefaultIgnoreFailure); |
71 | 103 |
72 /** | 104 /** |
73 * Expect exactly one image (appropriate for the case when we | 105 * Expect exactly one image (appropriate for the case when we |
74 * are comparing against a single PNG file). | 106 * are comparing against a single PNG file). |
75 */ | 107 */ |
76 Expectations(const SkBitmap& bitmap, bool ignoreFailure=kDefaultIgnoreFa
ilure); | 108 Expectations(const SkBitmap& bitmap, bool ignoreFailure=kDefaultIgnoreFa
ilure); |
77 | 109 |
78 /** | 110 /** |
79 * Create Expectations from a JSON element as found within the | 111 * Create Expectations from a JSON element as found within the |
80 * kJsonKey_ExpectedResults section. | 112 * kJsonKey_ExpectedResults section. |
81 * | 113 * |
82 * It's fine if the jsonElement is null or empty; in that case, we just | 114 * It's fine if the jsonElement is null or empty; in that case, we just |
83 * don't have any expectations. | 115 * don't have any expectations. |
84 */ | 116 */ |
85 Expectations(Json::Value jsonElement); | 117 Expectations(Json::Value jsonElement); |
86 | 118 |
87 /** | 119 /** |
88 * Returns true iff we want to ignore failed expectations. | 120 * Returns true iff we want to ignore failed expectations. |
89 */ | 121 */ |
90 bool ignoreFailure() const { return this->fIgnoreFailure; } | 122 bool ignoreFailure() const { return this->fIgnoreFailure; } |
91 | 123 |
92 /** | 124 /** |
93 * Returns true iff there are no allowed checksums. | 125 * Returns true iff there are no allowed results. |
94 */ | 126 */ |
95 bool empty() const { return this->fAllowedBitmapChecksums.empty(); } | 127 bool empty() const { return this->fAllowedResultDigests.empty(); } |
96 | 128 |
97 /** | 129 /** |
98 * Returns true iff actualChecksum matches any allowedChecksum, | 130 * Returns true iff resultDigest matches any allowed result, |
99 * regardless of fIgnoreFailure. (The caller can check | 131 * regardless of fIgnoreFailure. (The caller can check |
100 * that separately.) | 132 * that separately.) |
101 */ | 133 */ |
102 bool match(Checksum actualChecksum) const; | 134 bool match(GmResultDigest resultDigest) const; |
103 | 135 |
104 /** | 136 /** |
105 * If this Expectation is based on a single SkBitmap, return a | 137 * If this Expectation is based on a single SkBitmap, return a |
106 * pointer to that SkBitmap. Otherwise (if the Expectation is | 138 * pointer to that SkBitmap. Otherwise (if the Expectation is |
107 * empty, or if it was based on a list of checksums rather | 139 * empty, or if it was based on a list of checksums rather |
108 * than a single bitmap), returns NULL. | 140 * than a single bitmap), returns NULL. |
109 */ | 141 */ |
110 const SkBitmap *asBitmap() const { | 142 const SkBitmap *asBitmap() const { |
111 return (SkBitmap::kNo_Config == fBitmap.config()) ? NULL : &fBitmap; | 143 return (SkBitmap::kNo_Config == fBitmap.config()) ? NULL : &fBitmap; |
112 } | 144 } |
113 | 145 |
114 /** | 146 /** |
115 * Return a JSON representation of the expectations. | 147 * Return a JSON representation of the expectations. |
116 */ | 148 */ |
117 Json::Value asJsonValue() const; | 149 Json::Value asJsonValue() const; |
118 | 150 |
119 private: | 151 private: |
120 const static bool kDefaultIgnoreFailure = false; | 152 const static bool kDefaultIgnoreFailure = false; |
121 | 153 |
122 SkTArray<Checksum> fAllowedBitmapChecksums; | 154 SkTArray<GmResultDigest> fAllowedResultDigests; |
123 bool fIgnoreFailure; | 155 bool fIgnoreFailure; |
124 SkBitmap fBitmap; | 156 SkBitmap fBitmap; |
125 }; | 157 }; |
126 | 158 |
127 /** | 159 /** |
128 * Abstract source of Expectations objects for individual tests. | 160 * Abstract source of Expectations objects for individual tests. |
129 */ | 161 */ |
130 class ExpectationsSource : public SkRefCnt { | 162 class ExpectationsSource : public SkRefCnt { |
131 public: | 163 public: |
132 virtual Expectations get(const char *testName) = 0; | 164 virtual Expectations get(const char *testName) = 0; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 * Returns true if successful. | 248 * Returns true if successful. |
217 */ | 249 */ |
218 static bool Parse(const char *jsonPath, Json::Value *jsonRoot); | 250 static bool Parse(const char *jsonPath, Json::Value *jsonRoot); |
219 | 251 |
220 Json::Value fJsonRoot; | 252 Json::Value fJsonRoot; |
221 Json::Value fJsonExpectedResults; | 253 Json::Value fJsonExpectedResults; |
222 }; | 254 }; |
223 | 255 |
224 } | 256 } |
225 #endif | 257 #endif |
OLD | NEW |