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 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); | 45 Json::Value ActualResultAsJsonValue(uint64_t result); |
| 55 | 46 |
| 56 Json::Value CreateJsonTree(Json::Value expectedResults, | 47 Json::Value CreateJsonTree(Json::Value expectedResults, |
| 57 Json::Value actualResultsFailed, | 48 Json::Value actualResultsFailed, |
| 58 Json::Value actualResultsFailureIgnored, | 49 Json::Value actualResultsFailureIgnored, |
| 59 Json::Value actualResultsNoComparison, | 50 Json::Value actualResultsNoComparison, |
| 60 Json::Value actualResultsSucceeded); | 51 Json::Value actualResultsSucceeded); |
| 61 | 52 |
| 62 /** | 53 /** |
| 63 * Test expectations (allowed image checksums, etc.) | 54 * The digest of a GM test result. |
| 55 * | |
| 56 * Currently, this is always a uint64_t hash digest of an SkBitmap... | |
| 57 * but we will add other flavors soon. | |
| 58 */ | |
| 59 class GmResultDigest { | |
|
epoger
2013/05/23 18:19:12
In patchset 2, we replace the Checksum typedef wit
| |
| 60 public: | |
| 61 /** | |
| 62 * Create a ResultDigest representing an actual image result. | |
| 63 */ | |
| 64 GmResultDigest(const SkBitmap &bitmap); | |
| 65 | |
| 66 /** | |
| 67 * Create a ResultDigest representing an allowed result | |
| 68 * checksum within JSON expectations file. | |
| 69 * | |
| 70 * TODO(epoger): Replace this constructor with one that takes | |
| 71 * a JSON type/value pair, such as ["bitmap-64bitMD5", 12345]. | |
| 72 */ | |
| 73 GmResultDigest(uint64_t checksum); | |
| 74 | |
| 75 /** | |
| 76 * Returns true if this and other GmResultDigest could | |
| 77 * represent identical results. | |
| 78 */ | |
| 79 bool equals(const GmResultDigest &other) const; | |
| 80 | |
| 81 /** | |
| 82 * Returns a JSON type/value pair representing this result, | |
| 83 * such as ["bitmap-64bitMD5", 12345]. | |
| 84 */ | |
| 85 Json::Value asJsonTypeValuePair() const; | |
| 86 | |
| 87 /** | |
| 88 * Returns the value of this GmResultDigest (perhaps a bitmap hash?) | |
| 89 * as a Json::Value. | |
| 90 * | |
| 91 * TODO(epoger): delete this method; make callers use | |
| 92 * asJsonTypeValuePair() instead, so that the callers won't | |
| 93 * make any assumptions about what type of ResultDigest this | |
| 94 * is. | |
| 95 */ | |
| 96 Json::Value getValueAsJsonValue() const; | |
| 97 | |
| 98 private: | |
| 99 uint64_t fHashDigest; | |
| 100 }; | |
| 101 | |
| 102 /** | |
| 103 * Test expectations (allowed image results, etc.) | |
| 64 */ | 104 */ |
| 65 class Expectations { | 105 class Expectations { |
| 66 public: | 106 public: |
| 67 /** | 107 /** |
| 68 * No expectations at all. | 108 * No expectations at all. |
| 69 */ | 109 */ |
| 70 Expectations(bool ignoreFailure=kDefaultIgnoreFailure); | 110 Expectations(bool ignoreFailure=kDefaultIgnoreFailure); |
| 71 | 111 |
| 72 /** | 112 /** |
| 73 * Expect exactly one image (appropriate for the case when we | 113 * Expect exactly one image (appropriate for the case when we |
| 74 * are comparing against a single PNG file). | 114 * are comparing against a single PNG file). |
| 75 */ | 115 */ |
| 76 Expectations(const SkBitmap& bitmap, bool ignoreFailure=kDefaultIgnoreFa ilure); | 116 Expectations(const SkBitmap& bitmap, bool ignoreFailure=kDefaultIgnoreFa ilure); |
| 77 | 117 |
| 78 /** | 118 /** |
| 79 * Create Expectations from a JSON element as found within the | 119 * Create Expectations from a JSON element as found within the |
| 80 * kJsonKey_ExpectedResults section. | 120 * kJsonKey_ExpectedResults section. |
| 81 * | 121 * |
| 82 * It's fine if the jsonElement is null or empty; in that case, we just | 122 * It's fine if the jsonElement is null or empty; in that case, we just |
| 83 * don't have any expectations. | 123 * don't have any expectations. |
| 84 */ | 124 */ |
| 85 Expectations(Json::Value jsonElement); | 125 Expectations(Json::Value jsonElement); |
| 86 | 126 |
| 87 /** | 127 /** |
| 88 * Returns true iff we want to ignore failed expectations. | 128 * Returns true iff we want to ignore failed expectations. |
| 89 */ | 129 */ |
| 90 bool ignoreFailure() const { return this->fIgnoreFailure; } | 130 bool ignoreFailure() const { return this->fIgnoreFailure; } |
| 91 | 131 |
| 92 /** | 132 /** |
| 93 * Returns true iff there are no allowed checksums. | 133 * Returns true iff there are no allowed results. |
| 94 */ | 134 */ |
| 95 bool empty() const { return this->fAllowedBitmapChecksums.empty(); } | 135 bool empty() const { return this->fAllowedResultDigests.empty(); } |
| 96 | 136 |
| 97 /** | 137 /** |
| 98 * Returns true iff actualChecksum matches any allowedChecksum, | 138 * Returns true iff resultDigest matches any allowed result, |
| 99 * regardless of fIgnoreFailure. (The caller can check | 139 * regardless of fIgnoreFailure. (The caller can check |
| 100 * that separately.) | 140 * that separately.) |
| 101 */ | 141 */ |
| 102 bool match(Checksum actualChecksum) const; | 142 bool match(GmResultDigest resultDigest) const; |
| 103 | 143 |
| 104 /** | 144 /** |
| 105 * If this Expectation is based on a single SkBitmap, return a | 145 * If this Expectation is based on a single SkBitmap, return a |
| 106 * pointer to that SkBitmap. Otherwise (if the Expectation is | 146 * pointer to that SkBitmap. Otherwise (if the Expectation is |
| 107 * empty, or if it was based on a list of checksums rather | 147 * empty, or if it was based on a list of checksums rather |
| 108 * than a single bitmap), returns NULL. | 148 * than a single bitmap), returns NULL. |
| 109 */ | 149 */ |
| 110 const SkBitmap *asBitmap() const { | 150 const SkBitmap *asBitmap() const { |
| 111 return (SkBitmap::kNo_Config == fBitmap.config()) ? NULL : &fBitmap; | 151 return (SkBitmap::kNo_Config == fBitmap.config()) ? NULL : &fBitmap; |
| 112 } | 152 } |
| 113 | 153 |
| 114 /** | 154 /** |
| 115 * Return a JSON representation of the expectations. | 155 * Return a JSON representation of the expectations. |
| 116 */ | 156 */ |
| 117 Json::Value asJsonValue() const; | 157 Json::Value asJsonValue() const; |
| 118 | 158 |
| 119 private: | 159 private: |
| 120 const static bool kDefaultIgnoreFailure = false; | 160 const static bool kDefaultIgnoreFailure = false; |
| 121 | 161 |
| 122 SkTArray<Checksum> fAllowedBitmapChecksums; | 162 SkTArray<GmResultDigest> fAllowedResultDigests; |
| 123 bool fIgnoreFailure; | 163 bool fIgnoreFailure; |
| 124 SkBitmap fBitmap; | 164 SkBitmap fBitmap; |
| 125 }; | 165 }; |
| 126 | 166 |
| 127 /** | 167 /** |
| 128 * Abstract source of Expectations objects for individual tests. | 168 * Abstract source of Expectations objects for individual tests. |
| 129 */ | 169 */ |
| 130 class ExpectationsSource : public SkRefCnt { | 170 class ExpectationsSource : public SkRefCnt { |
| 131 public: | 171 public: |
| 132 virtual Expectations get(const char *testName) = 0; | 172 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. | 256 * Returns true if successful. |
| 217 */ | 257 */ |
| 218 static bool Parse(const char *jsonPath, Json::Value *jsonRoot); | 258 static bool Parse(const char *jsonPath, Json::Value *jsonRoot); |
| 219 | 259 |
| 220 Json::Value fJsonRoot; | 260 Json::Value fJsonRoot; |
| 221 Json::Value fJsonExpectedResults; | 261 Json::Value fJsonExpectedResults; |
| 222 }; | 262 }; |
| 223 | 263 |
| 224 } | 264 } |
| 225 #endif | 265 #endif |
| OLD | NEW |