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 * TODO(epoger): Combine this with tools/image_expectations.h, or eliminate one
of the two. | 7 * TODO(epoger): Combine this with tools/image_expectations.h, or eliminate one
of the two. |
8 */ | 8 */ |
9 #ifndef gm_expectations_DEFINED | 9 #ifndef gm_expectations_DEFINED |
10 #define gm_expectations_DEFINED | 10 #define gm_expectations_DEFINED |
11 | 11 |
12 #include "gm.h" | 12 #include "gm.h" |
13 #include "SkBitmap.h" | 13 #include "SkBitmap.h" |
14 #include "SkBitmapHasher.h" | 14 #include "SkBitmapHasher.h" |
15 #include "SkData.h" | 15 #include "SkData.h" |
16 #include "SkJSONCPP.h" | 16 #include "SkJSONCPP.h" |
17 #include "SkOSFile.h" | 17 #include "SkOSFile.h" |
18 #include "SkRefCnt.h" | 18 #include "SkRefCnt.h" |
19 #include "SkStream.h" | 19 #include "SkStream.h" |
20 #include "SkTArray.h" | 20 #include "SkTArray.h" |
21 | 21 |
22 | 22 |
23 namespace skiagm { | 23 namespace skiagm { |
24 | 24 |
| 25 #ifdef SK_BUILD_JSON_WRITER |
25 Json::Value CreateJsonTree(Json::Value expectedResults, | 26 Json::Value CreateJsonTree(Json::Value expectedResults, |
26 Json::Value actualResultsFailed, | 27 Json::Value actualResultsFailed, |
27 Json::Value actualResultsFailureIgnored, | 28 Json::Value actualResultsFailureIgnored, |
28 Json::Value actualResultsNoComparison, | 29 Json::Value actualResultsNoComparison, |
29 Json::Value actualResultsSucceeded); | 30 Json::Value actualResultsSucceeded); |
30 | 31 #endif |
31 /** | 32 /** |
32 * The digest of a GM test result. | 33 * The digest of a GM test result. |
33 * | 34 * |
34 * Currently, this is always a uint64_t hash digest of an SkBitmap... | 35 * Currently, this is always a uint64_t hash digest of an SkBitmap... |
35 * but we will add other flavors soon. | 36 * but we will add other flavors soon. |
36 */ | 37 */ |
37 class GmResultDigest { | 38 class GmResultDigest { |
38 public: | 39 public: |
39 /** | 40 /** |
40 * Create a ResultDigest representing an actual image result. | 41 * Create a ResultDigest representing an actual image result. |
41 */ | 42 */ |
42 explicit GmResultDigest(const SkBitmap &bitmap); | 43 explicit GmResultDigest(const SkBitmap &bitmap); |
43 | 44 |
| 45 #ifdef SK_BUILD_JSON_WRITER |
44 /** | 46 /** |
45 * Create a ResultDigest representing an allowed result | 47 * Create a ResultDigest representing an allowed result |
46 * checksum within JSON expectations file, in the form | 48 * checksum within JSON expectations file, in the form |
47 * ["bitmap-64bitMD5", 12345]. | 49 * ["bitmap-64bitMD5", 12345]. |
48 */ | 50 */ |
49 explicit GmResultDigest(const Json::Value &jsonTypeValuePair); | 51 explicit GmResultDigest(const Json::Value &jsonTypeValuePair); |
| 52 #endif |
50 | 53 |
51 /** | 54 /** |
52 * Returns true if this GmResultDigest was fully and successfully | 55 * Returns true if this GmResultDigest was fully and successfully |
53 * created. | 56 * created. |
54 */ | 57 */ |
55 bool isValid() const; | 58 bool isValid() const; |
56 | 59 |
57 /** | 60 /** |
58 * Returns true if this and other GmResultDigest could | 61 * Returns true if this and other GmResultDigest could |
59 * represent identical results. | 62 * represent identical results. |
60 */ | 63 */ |
61 bool equals(const GmResultDigest &other) const; | 64 bool equals(const GmResultDigest &other) const; |
62 | 65 |
| 66 #ifdef SK_BUILD_JSON_WRITER |
63 /** | 67 /** |
64 * Returns a JSON type/value pair representing this result, | 68 * Returns a JSON type/value pair representing this result, |
65 * such as ["bitmap-64bitMD5", 12345]. | 69 * such as ["bitmap-64bitMD5", 12345]. |
66 */ | 70 */ |
67 Json::Value asJsonTypeValuePair() const; | 71 Json::Value asJsonTypeValuePair() const; |
| 72 #endif |
68 | 73 |
69 /** | 74 /** |
70 * Returns the hashtype, such as "bitmap-64bitMD5", as an SkString. | 75 * Returns the hashtype, such as "bitmap-64bitMD5", as an SkString. |
71 */ | 76 */ |
72 SkString getHashType() const; | 77 SkString getHashType() const; |
73 | 78 |
74 /** | 79 /** |
75 * Returns the hash digest value, such as "12345", as an SkString. | 80 * Returns the hash digest value, such as "12345", as an SkString. |
76 */ | 81 */ |
77 SkString getDigestValue() const; | 82 SkString getDigestValue() const; |
(...skipping 28 matching lines...) Expand all Loading... |
106 * Expect exactly one image (appropriate for the case when we | 111 * Expect exactly one image (appropriate for the case when we |
107 * are comparing against a single PNG file). | 112 * are comparing against a single PNG file). |
108 */ | 113 */ |
109 explicit Expectations(const SkBitmap& bitmap, bool ignoreFailure=kDefaul
tIgnoreFailure); | 114 explicit Expectations(const SkBitmap& bitmap, bool ignoreFailure=kDefaul
tIgnoreFailure); |
110 | 115 |
111 /** | 116 /** |
112 * Expect exactly one image, whose digest has already been computed. | 117 * Expect exactly one image, whose digest has already been computed. |
113 */ | 118 */ |
114 explicit Expectations(const BitmapAndDigest& bitmapAndDigest); | 119 explicit Expectations(const BitmapAndDigest& bitmapAndDigest); |
115 | 120 |
| 121 #ifdef SK_BUILD_JSON_WRITER |
116 /** | 122 /** |
117 * Create Expectations from a JSON element as found within the | 123 * Create Expectations from a JSON element as found within the |
118 * kJsonKey_ExpectedResults section. | 124 * kJsonKey_ExpectedResults section. |
119 * | 125 * |
120 * It's fine if the jsonElement is null or empty; in that case, we just | 126 * It's fine if the jsonElement is null or empty; in that case, we just |
121 * don't have any expectations. | 127 * don't have any expectations. |
122 */ | 128 */ |
123 explicit Expectations(Json::Value jsonElement); | 129 explicit Expectations(Json::Value jsonElement); |
| 130 #endif |
124 | 131 |
125 /** | 132 /** |
126 * Returns true iff we want to ignore failed expectations. | 133 * Returns true iff we want to ignore failed expectations. |
127 */ | 134 */ |
128 bool ignoreFailure() const { return this->fIgnoreFailure; } | 135 bool ignoreFailure() const { return this->fIgnoreFailure; } |
129 | 136 |
130 /** | 137 /** |
131 * Override default setting of fIgnoreFailure. | 138 * Override default setting of fIgnoreFailure. |
132 */ | 139 */ |
133 void setIgnoreFailure(bool val) { this->fIgnoreFailure = val; } | 140 void setIgnoreFailure(bool val) { this->fIgnoreFailure = val; } |
(...skipping 13 matching lines...) Expand all Loading... |
147 /** | 154 /** |
148 * If this Expectation is based on a single SkBitmap, return a | 155 * If this Expectation is based on a single SkBitmap, return a |
149 * pointer to that SkBitmap. Otherwise (if the Expectation is | 156 * pointer to that SkBitmap. Otherwise (if the Expectation is |
150 * empty, or if it was based on a list of checksums rather | 157 * empty, or if it was based on a list of checksums rather |
151 * than a single bitmap), returns NULL. | 158 * than a single bitmap), returns NULL. |
152 */ | 159 */ |
153 const SkBitmap *asBitmap() const { | 160 const SkBitmap *asBitmap() const { |
154 return (SkBitmap::kNo_Config == fBitmap.config()) ? NULL : &fBitmap; | 161 return (SkBitmap::kNo_Config == fBitmap.config()) ? NULL : &fBitmap; |
155 } | 162 } |
156 | 163 |
| 164 #ifdef SK_BUILD_JSON_WRITER |
157 /** | 165 /** |
158 * Return a JSON representation of the expectations. | 166 * Return a JSON representation of the expectations. |
159 */ | 167 */ |
160 Json::Value asJsonValue() const; | 168 Json::Value asJsonValue() const; |
| 169 #endif |
161 | 170 |
162 private: | 171 private: |
163 const static bool kDefaultIgnoreFailure = false; | 172 const static bool kDefaultIgnoreFailure = false; |
164 | 173 |
165 SkTArray<GmResultDigest> fAllowedResultDigests; | 174 SkTArray<GmResultDigest> fAllowedResultDigests; |
166 bool fIgnoreFailure; | 175 bool fIgnoreFailure; |
167 SkBitmap fBitmap; | 176 SkBitmap fBitmap; |
168 }; | 177 }; |
169 | 178 |
170 /** | 179 /** |
(...skipping 22 matching lines...) Expand all Loading... |
193 * (this string will be copied to storage within this object) | 202 * (this string will be copied to storage within this object) |
194 */ | 203 */ |
195 explicit IndividualImageExpectationsSource(const char *rootDir) : fRootD
ir(rootDir) {} | 204 explicit IndividualImageExpectationsSource(const char *rootDir) : fRootD
ir(rootDir) {} |
196 | 205 |
197 Expectations get(const char *testName) const SK_OVERRIDE ; | 206 Expectations get(const char *testName) const SK_OVERRIDE ; |
198 | 207 |
199 private: | 208 private: |
200 const SkString fRootDir; | 209 const SkString fRootDir; |
201 }; | 210 }; |
202 | 211 |
| 212 #ifdef SK_BUILD_JSON_WRITER |
203 /** | 213 /** |
204 * Return Expectations based on JSON summary file. | 214 * Return Expectations based on JSON summary file. |
205 */ | 215 */ |
206 class JsonExpectationsSource : public ExpectationsSource { | 216 class JsonExpectationsSource : public ExpectationsSource { |
207 public: | 217 public: |
208 /** | 218 /** |
209 * Create an ExpectationsSource that will return Expectations based on | 219 * Create an ExpectationsSource that will return Expectations based on |
210 * a JSON file. | 220 * a JSON file. |
211 * | 221 * |
212 * jsonPath: path to JSON file to read | 222 * jsonPath: path to JSON file to read |
213 */ | 223 */ |
214 explicit JsonExpectationsSource(const char *jsonPath); | 224 explicit JsonExpectationsSource(const char *jsonPath); |
215 | 225 |
216 Expectations get(const char *testName) const SK_OVERRIDE; | 226 Expectations get(const char *testName) const SK_OVERRIDE; |
217 | 227 |
218 private: | 228 private: |
219 | 229 |
220 /** | 230 /** |
221 * Read the file contents from jsonPath and parse them into jsonRoot. | 231 * Read the file contents from jsonPath and parse them into jsonRoot. |
222 * | 232 * |
223 * Returns true if successful. | 233 * Returns true if successful. |
224 */ | 234 */ |
225 static bool Parse(const char *jsonPath, Json::Value *jsonRoot); | 235 static bool Parse(const char *jsonPath, Json::Value *jsonRoot); |
226 | 236 |
227 Json::Value fJsonRoot; | 237 Json::Value fJsonRoot; |
228 Json::Value fJsonExpectedResults; | 238 Json::Value fJsonExpectedResults; |
229 }; | 239 }; |
| 240 #endif // SK_BUILD_JSON_WRITER |
230 | 241 |
231 } | 242 } |
232 #endif | 243 #endif |
OLD | NEW |