| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 115 |
| 116 bool Expectation::empty() const { return this->fIsEmpty; } | 116 bool Expectation::empty() const { return this->fIsEmpty; } |
| 117 | 117 |
| 118 bool Expectation::matches(ImageDigest &imageDigest) { | 118 bool Expectation::matches(ImageDigest &imageDigest) { |
| 119 return !(this->fIsEmpty) && (this->fImageDigest.equals(imageDigest)); | 119 return !(this->fIsEmpty) && (this->fImageDigest.equals(imageDigest)); |
| 120 } | 120 } |
| 121 | 121 |
| 122 // ImageResultsAndExpectations class... | 122 // ImageResultsAndExpectations class... |
| 123 | 123 |
| 124 bool ImageResultsAndExpectations::readExpectationsFile(const char *jsonPath)
{ | 124 bool ImageResultsAndExpectations::readExpectationsFile(const char *jsonPath)
{ |
| 125 if (NULL == jsonPath) { | 125 if (nullptr == jsonPath) { |
| 126 SkDebugf("JSON expectations filename not specified\n"); | 126 SkDebugf("JSON expectations filename not specified\n"); |
| 127 return false; | 127 return false; |
| 128 } | 128 } |
| 129 SkFILE* filePtr = sk_fopen(jsonPath, kRead_SkFILE_Flag); | 129 SkFILE* filePtr = sk_fopen(jsonPath, kRead_SkFILE_Flag); |
| 130 if (NULL == filePtr) { | 130 if (nullptr == filePtr) { |
| 131 SkDebugf("JSON expectations file '%s' does not exist\n", jsonPath); | 131 SkDebugf("JSON expectations file '%s' does not exist\n", jsonPath); |
| 132 return false; | 132 return false; |
| 133 } | 133 } |
| 134 size_t size = sk_fgetsize(filePtr); | 134 size_t size = sk_fgetsize(filePtr); |
| 135 if (0 == size) { | 135 if (0 == size) { |
| 136 SkDebugf("JSON expectations file '%s' is empty, so no expectations\n
", jsonPath); | 136 SkDebugf("JSON expectations file '%s' is empty, so no expectations\n
", jsonPath); |
| 137 sk_fclose(filePtr); | 137 sk_fclose(filePtr); |
| 138 fExpectedResults.clear(); | 138 fExpectedResults.clear(); |
| 139 return true; | 139 return true; |
| 140 } | 140 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } else if (expectation.matches(digest)) { | 181 } else if (expectation.matches(digest)) { |
| 182 comparisonResult = kJsonValue_Image_ComparisonResult_Succeeded; | 182 comparisonResult = kJsonValue_Image_ComparisonResult_Succeeded; |
| 183 } else if (expectation.ignoreFailure()) { | 183 } else if (expectation.ignoreFailure()) { |
| 184 comparisonResult = kJsonValue_Image_ComparisonResult_FailureIgnored; | 184 comparisonResult = kJsonValue_Image_ComparisonResult_FailureIgnored; |
| 185 } else { | 185 } else { |
| 186 comparisonResult = kJsonValue_Image_ComparisonResult_Failed; | 186 comparisonResult = kJsonValue_Image_ComparisonResult_Failed; |
| 187 } | 187 } |
| 188 actualImage[kJsonKey_Image_ComparisonResult] = comparisonResult; | 188 actualImage[kJsonKey_Image_ComparisonResult] = comparisonResult; |
| 189 | 189 |
| 190 // Add this actual result to our collection. | 190 // Add this actual result to our collection. |
| 191 if (NULL == tileNumber) { | 191 if (nullptr == tileNumber) { |
| 192 fActualResults[sourceName][kJsonKey_Source_WholeImage] = actualImage
; | 192 fActualResults[sourceName][kJsonKey_Source_WholeImage] = actualImage
; |
| 193 } else { | 193 } else { |
| 194 fActualResults[sourceName][kJsonKey_Source_TiledImages][*tileNumber]
= actualImage; | 194 fActualResults[sourceName][kJsonKey_Source_TiledImages][*tileNumber]
= actualImage; |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 | 197 |
| 198 void ImageResultsAndExpectations::addDescription(const char *key, const char
*value) { | 198 void ImageResultsAndExpectations::addDescription(const char *key, const char
*value) { |
| 199 fDescriptions[key] = value; | 199 fDescriptions[key] = value; |
| 200 } | 200 } |
| 201 | 201 |
| 202 void ImageResultsAndExpectations::setImageBaseGSUrl(const char *imageBaseGSU
rl) { | 202 void ImageResultsAndExpectations::setImageBaseGSUrl(const char *imageBaseGSU
rl) { |
| 203 fImageBaseGSUrl = imageBaseGSUrl; | 203 fImageBaseGSUrl = imageBaseGSUrl; |
| 204 } | 204 } |
| 205 | 205 |
| 206 Expectation ImageResultsAndExpectations::getExpectation(const char *sourceNa
me, | 206 Expectation ImageResultsAndExpectations::getExpectation(const char *sourceNa
me, |
| 207 const int *tileNumbe
r) { | 207 const int *tileNumbe
r) { |
| 208 if (fExpectedResults.isNull()) { | 208 if (fExpectedResults.isNull()) { |
| 209 return Expectation(); | 209 return Expectation(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 Json::Value expectedImage; | 212 Json::Value expectedImage; |
| 213 if (NULL == tileNumber) { | 213 if (nullptr == tileNumber) { |
| 214 expectedImage = fExpectedResults[sourceName][kJsonKey_Source_WholeIm
age]; | 214 expectedImage = fExpectedResults[sourceName][kJsonKey_Source_WholeIm
age]; |
| 215 } else { | 215 } else { |
| 216 expectedImage = fExpectedResults[sourceName][kJsonKey_Source_TiledIm
ages][*tileNumber]; | 216 expectedImage = fExpectedResults[sourceName][kJsonKey_Source_TiledIm
ages][*tileNumber]; |
| 217 } | 217 } |
| 218 if (expectedImage.isNull()) { | 218 if (expectedImage.isNull()) { |
| 219 return Expectation(); | 219 return Expectation(); |
| 220 } | 220 } |
| 221 | 221 |
| 222 bool ignoreFailure = (expectedImage[kJsonKey_Image_IgnoreFailure] == tru
e); | 222 bool ignoreFailure = (expectedImage[kJsonKey_Image_IgnoreFailure] == tru
e); |
| 223 return Expectation(SkString(expectedImage[kJsonKey_Image_ChecksumAlgorit
hm].asCString()), | 223 return Expectation(SkString(expectedImage[kJsonKey_Image_ChecksumAlgorit
hm].asCString()), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 235 root[kJsonKey_Header] = header; | 235 root[kJsonKey_Header] = header; |
| 236 root[kJsonKey_ImageBaseGSUrl] = fImageBaseGSUrl; | 236 root[kJsonKey_ImageBaseGSUrl] = fImageBaseGSUrl; |
| 237 std::string jsonStdString = root.toStyledString(); | 237 std::string jsonStdString = root.toStyledString(); |
| 238 SkFILEWStream stream(filename); | 238 SkFILEWStream stream(filename); |
| 239 stream.write(jsonStdString.c_str(), jsonStdString.length()); | 239 stream.write(jsonStdString.c_str(), jsonStdString.length()); |
| 240 } | 240 } |
| 241 | 241 |
| 242 /*static*/ bool ImageResultsAndExpectations::Parse(SkFILE *filePtr, | 242 /*static*/ bool ImageResultsAndExpectations::Parse(SkFILE *filePtr, |
| 243 Json::Value *jsonRoot) { | 243 Json::Value *jsonRoot) { |
| 244 SkAutoDataUnref dataRef(SkData::NewFromFILE(filePtr)); | 244 SkAutoDataUnref dataRef(SkData::NewFromFILE(filePtr)); |
| 245 if (NULL == dataRef.get()) { | 245 if (nullptr == dataRef.get()) { |
| 246 return false; | 246 return false; |
| 247 } | 247 } |
| 248 | 248 |
| 249 const char *bytes = reinterpret_cast<const char *>(dataRef.get()->data()
); | 249 const char *bytes = reinterpret_cast<const char *>(dataRef.get()->data()
); |
| 250 size_t size = dataRef.get()->size(); | 250 size_t size = dataRef.get()->size(); |
| 251 Json::Reader reader; | 251 Json::Reader reader; |
| 252 if (!reader.parse(bytes, bytes+size, *jsonRoot)) { | 252 if (!reader.parse(bytes, bytes+size, *jsonRoot)) { |
| 253 return false; | 253 return false; |
| 254 } | 254 } |
| 255 | 255 |
| 256 return true; | 256 return true; |
| 257 } | 257 } |
| 258 | 258 |
| 259 } // namespace sk_tools | 259 } // namespace sk_tools |
| OLD | NEW |