Chromium Code Reviews| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 * The digest of a GM test result. | 42 * The digest of a GM test result. |
| 43 * | 43 * |
| 44 * Currently, this is always a uint64_t hash digest of an SkBitmap... | 44 * Currently, this is always a uint64_t hash digest of an SkBitmap... |
| 45 * but we will add other flavors soon. | 45 * but we will add other flavors soon. |
| 46 */ | 46 */ |
| 47 class GmResultDigest { | 47 class GmResultDigest { |
| 48 public: | 48 public: |
| 49 /** | 49 /** |
| 50 * Create a ResultDigest representing an actual image result. | 50 * Create a ResultDigest representing an actual image result. |
| 51 */ | 51 */ |
| 52 GmResultDigest(const SkBitmap &bitmap); | 52 explicit GmResultDigest(const SkBitmap &bitmap); |
|
epoger
2013/10/11 18:45:19
Why make these explicit-only?
mtklein
2013/10/11 19:05:20
Readability, though I notice Skia style guide does
bsalomon
2013/10/11 19:50:54
Update the style guide! We definitely prefer to us
mtklein
2013/10/14 15:16:18
Done.
| |
| 53 | 53 |
| 54 /** | 54 /** |
| 55 * Create a ResultDigest representing an allowed result | 55 * Create a ResultDigest representing an allowed result |
| 56 * checksum within JSON expectations file, in the form | 56 * checksum within JSON expectations file, in the form |
| 57 * ["bitmap-64bitMD5", 12345]. | 57 * ["bitmap-64bitMD5", 12345]. |
| 58 */ | 58 */ |
| 59 GmResultDigest(const Json::Value &jsonTypeValuePair); | 59 explicit GmResultDigest(const Json::Value &jsonTypeValuePair); |
| 60 | 60 |
| 61 /** | 61 /** |
| 62 * Returns true if this GmResultDigest was fully and successfully | 62 * Returns true if this GmResultDigest was fully and successfully |
| 63 * created. | 63 * created. |
| 64 */ | 64 */ |
| 65 bool isValid() const; | 65 bool isValid() const; |
| 66 | 66 |
| 67 /** | 67 /** |
| 68 * Returns true if this and other GmResultDigest could | 68 * Returns true if this and other GmResultDigest could |
| 69 * represent identical results. | 69 * represent identical results. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 89 private: | 89 private: |
| 90 bool fIsValid; // always check this first--if it's false, other fields a re meaningless | 90 bool fIsValid; // always check this first--if it's false, other fields a re meaningless |
| 91 uint64_t fHashDigest; | 91 uint64_t fHashDigest; |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 /** | 94 /** |
| 95 * Encapsulates an SkBitmap and its GmResultDigest, guaranteed to keep them in sync. | 95 * Encapsulates an SkBitmap and its GmResultDigest, guaranteed to keep them in sync. |
| 96 */ | 96 */ |
| 97 class BitmapAndDigest { | 97 class BitmapAndDigest { |
| 98 public: | 98 public: |
| 99 BitmapAndDigest(const SkBitmap &bitmap) : fBitmap(bitmap), fDigest(bitma p) {} | 99 explicit BitmapAndDigest(const SkBitmap &bitmap) : fBitmap(bitmap), fDig est(bitmap) {} |
| 100 | 100 |
| 101 const SkBitmap fBitmap; | 101 const SkBitmap fBitmap; |
| 102 const GmResultDigest fDigest; | 102 const GmResultDigest fDigest; |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 /** | 105 /** |
| 106 * Test expectations (allowed image results, etc.) | 106 * Test expectations (allowed image results, etc.) |
| 107 */ | 107 */ |
| 108 class Expectations { | 108 class Expectations { |
| 109 public: | 109 public: |
| 110 /** | 110 /** |
| 111 * No expectations at all. | 111 * No expectations at all. |
| 112 */ | 112 */ |
| 113 Expectations(bool ignoreFailure=kDefaultIgnoreFailure); | 113 explicit Expectations(bool ignoreFailure=kDefaultIgnoreFailure); |
| 114 | 114 |
| 115 /** | 115 /** |
| 116 * Expect exactly one image (appropriate for the case when we | 116 * Expect exactly one image (appropriate for the case when we |
| 117 * are comparing against a single PNG file). | 117 * are comparing against a single PNG file). |
| 118 */ | 118 */ |
| 119 Expectations(const SkBitmap& bitmap, bool ignoreFailure=kDefaultIgnoreFa ilure); | 119 Expectations(const SkBitmap& bitmap, bool ignoreFailure=kDefaultIgnoreFa ilure); |
| 120 | 120 |
| 121 /** | 121 /** |
| 122 * Create Expectations from a JSON element as found within the | 122 * Create Expectations from a JSON element as found within the |
| 123 * kJsonKey_ExpectedResults section. | 123 * kJsonKey_ExpectedResults section. |
| 124 * | 124 * |
| 125 * It's fine if the jsonElement is null or empty; in that case, we just | 125 * It's fine if the jsonElement is null or empty; in that case, we just |
| 126 * don't have any expectations. | 126 * don't have any expectations. |
| 127 */ | 127 */ |
| 128 Expectations(Json::Value jsonElement); | 128 explicit Expectations(Json::Value jsonElement); |
| 129 | 129 |
| 130 /** | 130 /** |
| 131 * Returns true iff we want to ignore failed expectations. | 131 * Returns true iff we want to ignore failed expectations. |
| 132 */ | 132 */ |
| 133 bool ignoreFailure() const { return this->fIgnoreFailure; } | 133 bool ignoreFailure() const { return this->fIgnoreFailure; } |
| 134 | 134 |
| 135 /** | 135 /** |
| 136 * Override default setting of fIgnoreFailure. | 136 * Override default setting of fIgnoreFailure. |
| 137 */ | 137 */ |
| 138 void setIgnoreFailure(bool val) { this->fIgnoreFailure = val; } | 138 void setIgnoreFailure(bool val) { this->fIgnoreFailure = val; } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 SkBitmap fBitmap; | 172 SkBitmap fBitmap; |
| 173 }; | 173 }; |
| 174 | 174 |
| 175 /** | 175 /** |
| 176 * Abstract source of Expectations objects for individual tests. | 176 * Abstract source of Expectations objects for individual tests. |
| 177 */ | 177 */ |
| 178 class ExpectationsSource : public SkRefCnt { | 178 class ExpectationsSource : public SkRefCnt { |
| 179 public: | 179 public: |
| 180 SK_DECLARE_INST_COUNT(ExpectationsSource) | 180 SK_DECLARE_INST_COUNT(ExpectationsSource) |
| 181 | 181 |
| 182 virtual Expectations get(const char *testName) = 0; | 182 virtual Expectations get(const char *testName) const = 0; |
| 183 | 183 |
| 184 private: | 184 private: |
| 185 typedef SkRefCnt INHERITED; | 185 typedef SkRefCnt INHERITED; |
| 186 }; | 186 }; |
| 187 | 187 |
| 188 /** | 188 /** |
| 189 * Return Expectations based on individual image files on disk. | 189 * Return Expectations based on individual image files on disk. |
| 190 */ | 190 */ |
| 191 class IndividualImageExpectationsSource : public ExpectationsSource { | 191 class IndividualImageExpectationsSource : public ExpectationsSource { |
| 192 public: | 192 public: |
| 193 /** | 193 /** |
| 194 * Create an ExpectationsSource that will return Expectations based on | 194 * Create an ExpectationsSource that will return Expectations based on |
| 195 * image files found within rootDir. | 195 * image files found within rootDir. |
| 196 * | 196 * |
| 197 * rootDir: directory under which to look for image files | 197 * rootDir: directory under which to look for image files |
| 198 * (this string will be copied to storage within this object) | 198 * (this string will be copied to storage within this object) |
| 199 */ | 199 */ |
| 200 IndividualImageExpectationsSource(const char *rootDir) : fRootDir(rootDi r) {} | 200 explicit IndividualImageExpectationsSource(const char *rootDir) : fRootD ir(rootDir) {} |
| 201 | 201 |
| 202 Expectations get(const char *testName) SK_OVERRIDE ; | 202 Expectations get(const char *testName) const SK_OVERRIDE ; |
| 203 | 203 |
| 204 private: | 204 private: |
| 205 const SkString fRootDir; | 205 const SkString fRootDir; |
| 206 }; | 206 }; |
| 207 | 207 |
| 208 /** | 208 /** |
| 209 * Return Expectations based on JSON summary file. | 209 * Return Expectations based on JSON summary file. |
| 210 */ | 210 */ |
| 211 class JsonExpectationsSource : public ExpectationsSource { | 211 class JsonExpectationsSource : public ExpectationsSource { |
| 212 public: | 212 public: |
| 213 /** | 213 /** |
| 214 * Create an ExpectationsSource that will return Expectations based on | 214 * Create an ExpectationsSource that will return Expectations based on |
| 215 * a JSON file. | 215 * a JSON file. |
| 216 * | 216 * |
| 217 * jsonPath: path to JSON file to read | 217 * jsonPath: path to JSON file to read |
| 218 */ | 218 */ |
| 219 JsonExpectationsSource(const char *jsonPath); | 219 explicit JsonExpectationsSource(const char *jsonPath); |
| 220 | 220 |
| 221 Expectations get(const char *testName) SK_OVERRIDE; | 221 Expectations get(const char *testName) const SK_OVERRIDE; |
| 222 | 222 |
| 223 private: | 223 private: |
| 224 | 224 |
| 225 /** | 225 /** |
| 226 * Read as many bytes as possible (up to maxBytes) from the stream into | 226 * Read as many bytes as possible (up to maxBytes) from the stream into |
| 227 * an SkData object. | 227 * an SkData object. |
| 228 * | 228 * |
| 229 * If the returned SkData contains fewer than maxBytes, then EOF has bee n | 229 * If the returned SkData contains fewer than maxBytes, then EOF has bee n |
| 230 * reached and no more data would be available from subsequent calls. | 230 * reached and no more data would be available from subsequent calls. |
| 231 * (If EOF has already been reached, then this call will return an empty | 231 * (If EOF has already been reached, then this call will return an empty |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 * Returns true if successful. | 269 * Returns true if successful. |
| 270 */ | 270 */ |
| 271 static bool Parse(const char *jsonPath, Json::Value *jsonRoot); | 271 static bool Parse(const char *jsonPath, Json::Value *jsonRoot); |
| 272 | 272 |
| 273 Json::Value fJsonRoot; | 273 Json::Value fJsonRoot; |
| 274 Json::Value fJsonExpectedResults; | 274 Json::Value fJsonExpectedResults; |
| 275 }; | 275 }; |
| 276 | 276 |
| 277 } | 277 } |
| 278 #endif | 278 #endif |
| OLD | NEW |