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

Unified Diff: tools/image_expectations.cpp

Issue 289063010: make render_pictures properly handle empty expectations file (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: extract some shared test code Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/image_expectations.h ('k') | tools/tests/render_pictures_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/image_expectations.cpp
diff --git a/tools/image_expectations.cpp b/tools/image_expectations.cpp
index 24c91755415d62e4e292cbd72d0af0b76f4045cc..ac232e9f30daf4eba7f8f04c59db01e3f3b80998 100644
--- a/tools/image_expectations.cpp
+++ b/tools/image_expectations.cpp
@@ -95,12 +95,43 @@ namespace sk_tools {
// ImageResultsAndExpectations class...
bool ImageResultsAndExpectations::readExpectationsFile(const char *jsonPath) {
- if (Parse(jsonPath, &fExpectedJsonRoot)) {
- fExpectedResults = fExpectedJsonRoot[kJsonKey_ExpectedResults];
+ if (NULL == jsonPath) {
+ SkDebugf("JSON expectations filename not specified\n");
+ return false;
+ }
+ SkFILE* filePtr = sk_fopen(jsonPath, kRead_SkFILE_Flag);
+ if (NULL == filePtr) {
+ SkDebugf("JSON expectations file '%s' does not exist\n", jsonPath);
+ return false;
+ }
+ size_t size = sk_fgetsize(filePtr);
+ if (0 == size) {
+ SkDebugf("JSON expectations file '%s' is empty, so no expectations\n", jsonPath);
+ sk_fclose(filePtr);
+ fExpectedResults.clear();
return true;
- } else {
+ }
+ bool parsedJson = Parse(filePtr, &fExpectedJsonRoot);
+ sk_fclose(filePtr);
+ if (!parsedJson) {
+ SkDebugf("Failed to parse JSON expectations file '%s'\n", jsonPath);
return false;
}
+ Json::Value header = fExpectedJsonRoot[kJsonKey_Header];
+ Json::Value headerType = header[kJsonKey_Header_Type];
+ Json::Value headerRevision = header[kJsonKey_Header_Revision];
+ if (strcmp(headerType.asCString(), kJsonValue_Header_Type)) {
+ SkDebugf("JSON expectations file '%s': expected headerType '%s', found '%s'\n",
+ jsonPath, kJsonValue_Header_Type, headerType.asCString());
+ return false;
+ }
+ if (headerRevision.asInt() != kJsonValue_Header_Revision) {
+ SkDebugf("JSON expectations file '%s': expected headerRevision %d, found %d\n",
+ jsonPath, kJsonValue_Header_Revision, headerRevision.asInt());
+ return false;
+ }
+ fExpectedResults = fExpectedJsonRoot[kJsonKey_ExpectedResults];
+ return true;
}
void ImageResultsAndExpectations::add(const char *sourceName, const char *fileName,
@@ -181,11 +212,10 @@ namespace sk_tools {
stream.write(jsonStdString.c_str(), jsonStdString.length());
}
- /*static*/ bool ImageResultsAndExpectations::Parse(const char *jsonPath,
+ /*static*/ bool ImageResultsAndExpectations::Parse(SkFILE *filePtr,
Json::Value *jsonRoot) {
- SkAutoDataUnref dataRef(SkData::NewFromFileName(jsonPath));
+ SkAutoDataUnref dataRef(SkData::NewFromFILE(filePtr));
if (NULL == dataRef.get()) {
- SkDebugf("error reading JSON file %s\n", jsonPath);
return false;
}
@@ -193,7 +223,6 @@ namespace sk_tools {
size_t size = dataRef.get()->size();
Json::Reader reader;
if (!reader.parse(bytes, bytes+size, *jsonRoot)) {
- SkDebugf("error parsing JSON file %s\n", jsonPath);
return false;
}
« no previous file with comments | « tools/image_expectations.h ('k') | tools/tests/render_pictures_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698