OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 | 7 |
8 #include "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkBitmapHasher.h" | 9 #include "SkBitmapHasher.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 * Figure out a way to share the definitions instead. | 23 * Figure out a way to share the definitions instead. |
24 * | 24 * |
25 * Note that, as of https://codereview.chromium.org/226293002 , the JSON | 25 * Note that, as of https://codereview.chromium.org/226293002 , the JSON |
26 * schema used here has started to differ from the one in gm_expectations.cpp . | 26 * schema used here has started to differ from the one in gm_expectations.cpp . |
27 * TODO(epoger): Consider getting GM and render_pictures to use the same JSON | 27 * TODO(epoger): Consider getting GM and render_pictures to use the same JSON |
28 * output module. | 28 * output module. |
29 */ | 29 */ |
30 const static char kJsonKey_ActualResults[] = "actual-results"; | 30 const static char kJsonKey_ActualResults[] = "actual-results"; |
31 const static char kJsonKey_Descriptions[] = "descriptions"; | 31 const static char kJsonKey_Descriptions[] = "descriptions"; |
32 const static char kJsonKey_ExpectedResults[] = "expected-results"; | 32 const static char kJsonKey_ExpectedResults[] = "expected-results"; |
| 33 const static char kJsonKey_ImageBaseGSUrl[] = "image-base-gs-url"; |
33 const static char kJsonKey_Header[] = "header"; | 34 const static char kJsonKey_Header[] = "header"; |
34 const static char kJsonKey_Header_Type[] = "type"; | 35 const static char kJsonKey_Header_Type[] = "type"; |
35 const static char kJsonKey_Header_Revision[] = "revision"; | 36 const static char kJsonKey_Header_Revision[] = "revision"; |
36 const static char kJsonKey_Image_ChecksumAlgorithm[] = "checksumAlgorithm"; | 37 const static char kJsonKey_Image_ChecksumAlgorithm[] = "checksumAlgorithm"; |
37 const static char kJsonKey_Image_ChecksumValue[] = "checksumValue"; | 38 const static char kJsonKey_Image_ChecksumValue[] = "checksumValue"; |
38 const static char kJsonKey_Image_ComparisonResult[] = "comparisonResult"; | 39 const static char kJsonKey_Image_ComparisonResult[] = "comparisonResult"; |
39 const static char kJsonKey_Image_Filepath[] = "filepath"; | 40 const static char kJsonKey_Image_Filepath[] = "filepath"; |
40 const static char kJsonKey_Image_IgnoreFailure[] = "ignoreFailure"; | 41 const static char kJsonKey_Image_IgnoreFailure[] = "ignoreFailure"; |
41 const static char kJsonKey_Source_TiledImages[] = "tiled-images"; | 42 const static char kJsonKey_Source_TiledImages[] = "tiled-images"; |
42 const static char kJsonKey_Source_WholeImage[] = "whole-image"; | 43 const static char kJsonKey_Source_WholeImage[] = "whole-image"; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 fActualResults[sourceName][kJsonKey_Source_WholeImage] = actualImage
; | 176 fActualResults[sourceName][kJsonKey_Source_WholeImage] = actualImage
; |
176 } else { | 177 } else { |
177 fActualResults[sourceName][kJsonKey_Source_TiledImages][*tileNumber]
= actualImage; | 178 fActualResults[sourceName][kJsonKey_Source_TiledImages][*tileNumber]
= actualImage; |
178 } | 179 } |
179 } | 180 } |
180 | 181 |
181 void ImageResultsAndExpectations::addDescription(const char *key, const char
*value) { | 182 void ImageResultsAndExpectations::addDescription(const char *key, const char
*value) { |
182 fDescriptions[key] = value; | 183 fDescriptions[key] = value; |
183 } | 184 } |
184 | 185 |
| 186 void ImageResultsAndExpectations::setImageBaseGSUrl(const char *imageBaseGSU
rl) { |
| 187 fImageBaseGSUrl = imageBaseGSUrl; |
| 188 } |
| 189 |
185 bool ImageResultsAndExpectations::matchesExpectation(const char *sourceName, | 190 bool ImageResultsAndExpectations::matchesExpectation(const char *sourceName, |
186 const ImageDigest &dige
st, | 191 const ImageDigest &dige
st, |
187 const int *tileNumber)
{ | 192 const int *tileNumber)
{ |
188 if (fExpectedResults.isNull()) { | 193 if (fExpectedResults.isNull()) { |
189 return false; | 194 return false; |
190 } | 195 } |
191 | 196 |
192 Json::Value expectedImage; | 197 Json::Value expectedImage; |
193 if (NULL == tileNumber) { | 198 if (NULL == tileNumber) { |
194 expectedImage = fExpectedResults[sourceName][kJsonKey_Source_WholeIm
age]; | 199 expectedImage = fExpectedResults[sourceName][kJsonKey_Source_WholeIm
age]; |
(...skipping 11 matching lines...) Expand all Loading... |
206 } | 211 } |
207 | 212 |
208 void ImageResultsAndExpectations::writeToFile(const char *filename) const { | 213 void ImageResultsAndExpectations::writeToFile(const char *filename) const { |
209 Json::Value header; | 214 Json::Value header; |
210 header[kJsonKey_Header_Type] = kJsonValue_Header_Type; | 215 header[kJsonKey_Header_Type] = kJsonValue_Header_Type; |
211 header[kJsonKey_Header_Revision] = kJsonValue_Header_Revision; | 216 header[kJsonKey_Header_Revision] = kJsonValue_Header_Revision; |
212 Json::Value root; | 217 Json::Value root; |
213 root[kJsonKey_ActualResults] = fActualResults; | 218 root[kJsonKey_ActualResults] = fActualResults; |
214 root[kJsonKey_Descriptions] = fDescriptions; | 219 root[kJsonKey_Descriptions] = fDescriptions; |
215 root[kJsonKey_Header] = header; | 220 root[kJsonKey_Header] = header; |
| 221 root[kJsonKey_ImageBaseGSUrl] = fImageBaseGSUrl; |
216 std::string jsonStdString = root.toStyledString(); | 222 std::string jsonStdString = root.toStyledString(); |
217 SkFILEWStream stream(filename); | 223 SkFILEWStream stream(filename); |
218 stream.write(jsonStdString.c_str(), jsonStdString.length()); | 224 stream.write(jsonStdString.c_str(), jsonStdString.length()); |
219 } | 225 } |
220 | 226 |
221 /*static*/ bool ImageResultsAndExpectations::Parse(SkFILE *filePtr, | 227 /*static*/ bool ImageResultsAndExpectations::Parse(SkFILE *filePtr, |
222 Json::Value *jsonRoot) { | 228 Json::Value *jsonRoot) { |
223 SkAutoDataUnref dataRef(SkData::NewFromFILE(filePtr)); | 229 SkAutoDataUnref dataRef(SkData::NewFromFILE(filePtr)); |
224 if (NULL == dataRef.get()) { | 230 if (NULL == dataRef.get()) { |
225 return false; | 231 return false; |
226 } | 232 } |
227 | 233 |
228 const char *bytes = reinterpret_cast<const char *>(dataRef.get()->data()
); | 234 const char *bytes = reinterpret_cast<const char *>(dataRef.get()->data()
); |
229 size_t size = dataRef.get()->size(); | 235 size_t size = dataRef.get()->size(); |
230 Json::Reader reader; | 236 Json::Reader reader; |
231 if (!reader.parse(bytes, bytes+size, *jsonRoot)) { | 237 if (!reader.parse(bytes, bytes+size, *jsonRoot)) { |
232 return false; | 238 return false; |
233 } | 239 } |
234 | 240 |
235 return true; | 241 return true; |
236 } | 242 } |
237 | 243 |
238 } // namespace sk_tools | 244 } // namespace sk_tools |
OLD | NEW |