Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: gm/gm_expectations.h

Issue 15883004: GM: create GmResultDigest that encapsulates digest type ("bitmap-64bitMD5") and value (12345) (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: type_properly_encapsulated_within_GmResultDigest Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | gm/gm_expectations.cpp » ('j') | gm/gm_expectations.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
epoger 2013/05/23 19:18:31 Toplevel comment: The main reason for making this
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"
11 #include "SkBitmap.h" 11 #include "SkBitmap.h"
(...skipping 11 matching lines...) Expand all
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 {
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, in the form
69 * ["bitmap-64bitMD5", 12345].
70 */
71 GmResultDigest(const Json::Value &jsonTypeValuePair);
epoger 2013/05/23 19:18:31 As of patchset 3, the digest type (e.g., "bitmap-6
72
73 /**
74 * Returns true if this and other GmResultDigest could
75 * represent identical results.
76 */
77 bool equals(const GmResultDigest &other) const;
78
79 /**
80 * Returns a JSON type/value pair representing this result,
81 * such as ["bitmap-64bitMD5", 12345].
82 */
83 Json::Value asJsonTypeValuePair() const;
84
85 private:
86 uint64_t fHashDigest;
87 };
88
89 /**
90 * Test expectations (allowed image results, etc.)
64 */ 91 */
65 class Expectations { 92 class Expectations {
66 public: 93 public:
67 /** 94 /**
68 * No expectations at all. 95 * No expectations at all.
69 */ 96 */
70 Expectations(bool ignoreFailure=kDefaultIgnoreFailure); 97 Expectations(bool ignoreFailure=kDefaultIgnoreFailure);
71 98
72 /** 99 /**
73 * Expect exactly one image (appropriate for the case when we 100 * Expect exactly one image (appropriate for the case when we
74 * are comparing against a single PNG file). 101 * are comparing against a single PNG file).
75 */ 102 */
76 Expectations(const SkBitmap& bitmap, bool ignoreFailure=kDefaultIgnoreFa ilure); 103 Expectations(const SkBitmap& bitmap, bool ignoreFailure=kDefaultIgnoreFa ilure);
77 104
78 /** 105 /**
79 * Create Expectations from a JSON element as found within the 106 * Create Expectations from a JSON element as found within the
80 * kJsonKey_ExpectedResults section. 107 * kJsonKey_ExpectedResults section.
81 * 108 *
82 * It's fine if the jsonElement is null or empty; in that case, we just 109 * It's fine if the jsonElement is null or empty; in that case, we just
83 * don't have any expectations. 110 * don't have any expectations.
84 */ 111 */
85 Expectations(Json::Value jsonElement); 112 Expectations(Json::Value jsonElement);
86 113
87 /** 114 /**
88 * Returns true iff we want to ignore failed expectations. 115 * Returns true iff we want to ignore failed expectations.
89 */ 116 */
90 bool ignoreFailure() const { return this->fIgnoreFailure; } 117 bool ignoreFailure() const { return this->fIgnoreFailure; }
91 118
92 /** 119 /**
93 * Returns true iff there are no allowed checksums. 120 * Returns true iff there are no allowed results.
94 */ 121 */
95 bool empty() const { return this->fAllowedBitmapChecksums.empty(); } 122 bool empty() const { return this->fAllowedResultDigests.empty(); }
96 123
97 /** 124 /**
98 * Returns true iff actualChecksum matches any allowedChecksum, 125 * Returns true iff resultDigest matches any allowed result,
99 * regardless of fIgnoreFailure. (The caller can check 126 * regardless of fIgnoreFailure. (The caller can check
100 * that separately.) 127 * that separately.)
101 */ 128 */
102 bool match(Checksum actualChecksum) const; 129 bool match(GmResultDigest resultDigest) const;
103 130
104 /** 131 /**
105 * If this Expectation is based on a single SkBitmap, return a 132 * If this Expectation is based on a single SkBitmap, return a
106 * pointer to that SkBitmap. Otherwise (if the Expectation is 133 * pointer to that SkBitmap. Otherwise (if the Expectation is
107 * empty, or if it was based on a list of checksums rather 134 * empty, or if it was based on a list of checksums rather
108 * than a single bitmap), returns NULL. 135 * than a single bitmap), returns NULL.
109 */ 136 */
110 const SkBitmap *asBitmap() const { 137 const SkBitmap *asBitmap() const {
111 return (SkBitmap::kNo_Config == fBitmap.config()) ? NULL : &fBitmap; 138 return (SkBitmap::kNo_Config == fBitmap.config()) ? NULL : &fBitmap;
112 } 139 }
113 140
114 /** 141 /**
115 * Return a JSON representation of the expectations. 142 * Return a JSON representation of the expectations.
116 */ 143 */
117 Json::Value asJsonValue() const; 144 Json::Value asJsonValue() const;
118 145
119 private: 146 private:
120 const static bool kDefaultIgnoreFailure = false; 147 const static bool kDefaultIgnoreFailure = false;
121 148
122 SkTArray<Checksum> fAllowedBitmapChecksums; 149 SkTArray<GmResultDigest> fAllowedResultDigests;
123 bool fIgnoreFailure; 150 bool fIgnoreFailure;
124 SkBitmap fBitmap; 151 SkBitmap fBitmap;
125 }; 152 };
126 153
127 /** 154 /**
128 * Abstract source of Expectations objects for individual tests. 155 * Abstract source of Expectations objects for individual tests.
129 */ 156 */
130 class ExpectationsSource : public SkRefCnt { 157 class ExpectationsSource : public SkRefCnt {
131 public: 158 public:
132 virtual Expectations get(const char *testName) = 0; 159 virtual Expectations get(const char *testName) = 0;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 * Returns true if successful. 243 * Returns true if successful.
217 */ 244 */
218 static bool Parse(const char *jsonPath, Json::Value *jsonRoot); 245 static bool Parse(const char *jsonPath, Json::Value *jsonRoot);
219 246
220 Json::Value fJsonRoot; 247 Json::Value fJsonRoot;
221 Json::Value fJsonExpectedResults; 248 Json::Value fJsonExpectedResults;
222 }; 249 };
223 250
224 } 251 }
225 #endif 252 #endif
OLDNEW
« no previous file with comments | « no previous file | gm/gm_expectations.cpp » ('j') | gm/gm_expectations.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698