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 <stdarg.h> | |
| 10 #include "gm.h" | 11 #include "gm.h" |
| 11 #include "SkBitmap.h" | 12 #include "SkBitmap.h" |
| 12 #include "SkBitmapChecksummer.h" | 13 #include "SkBitmapChecksummer.h" |
| 13 #include "SkData.h" | 14 #include "SkData.h" |
| 14 #include "SkImageDecoder.h" | 15 #include "SkImageDecoder.h" |
| 15 #include "SkOSFile.h" | 16 #include "SkOSFile.h" |
| 16 #include "SkRefCnt.h" | 17 #include "SkRefCnt.h" |
| 17 #include "SkStream.h" | 18 #include "SkStream.h" |
| 18 #include "SkTArray.h" | 19 #include "SkTArray.h" |
| 19 | 20 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 46 | 47 |
| 47 // The actual type we use to represent a checksum is hidden in here. | 48 // The actual type we use to represent a checksum is hidden in here. |
| 48 typedef Json::UInt64 Checksum; | 49 typedef Json::UInt64 Checksum; |
| 49 static inline Json::Value asJsonValue(Checksum checksum) { | 50 static inline Json::Value asJsonValue(Checksum checksum) { |
| 50 return checksum; | 51 return checksum; |
| 51 } | 52 } |
| 52 static inline Checksum asChecksum(Json::Value jsonValue) { | 53 static inline Checksum asChecksum(Json::Value jsonValue) { |
| 53 return jsonValue.asUInt64(); | 54 return jsonValue.asUInt64(); |
| 54 } | 55 } |
| 55 | 56 |
| 57 static void gm_fprintf(FILE *stream, const char format[], ...) { | |
|
epoger
2013/03/13 01:21:40
I originally tried to declare this in gm.h, but th
| |
| 58 va_list args; | |
| 59 va_start(args, format); | |
| 60 fprintf(stream, "GM: "); | |
| 61 vfprintf(stream, format, args); | |
| 62 va_end(args); | |
| 63 } | |
| 64 | |
| 56 static SkString make_filename(const char path[], | 65 static SkString make_filename(const char path[], |
| 57 const char renderModeDescriptor[], | 66 const char renderModeDescriptor[], |
| 58 const char *name, | 67 const char *name, |
| 59 const char suffix[]) { | 68 const char suffix[]) { |
| 60 SkString filename(path); | 69 SkString filename(path); |
| 61 if (filename.endsWith(SkPATH_SEPARATOR)) { | 70 if (filename.endsWith(SkPATH_SEPARATOR)) { |
| 62 filename.remove(filename.size() - 1, 1); | 71 filename.remove(filename.size() - 1, 1); |
| 63 } | 72 } |
| 64 filename.appendf("%c%s%s.%s", SkPATH_SEPARATOR, | 73 filename.appendf("%c%s%s.%s", SkPATH_SEPARATOR, |
| 65 name, renderModeDescriptor, suffix); | 74 name, renderModeDescriptor, suffix); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 96 * don't have any expectations. | 105 * don't have any expectations. |
| 97 */ | 106 */ |
| 98 Expectations(Json::Value jsonElement) { | 107 Expectations(Json::Value jsonElement) { |
| 99 if (jsonElement.empty()) { | 108 if (jsonElement.empty()) { |
| 100 fIgnoreFailure = kDefaultIgnoreFailure; | 109 fIgnoreFailure = kDefaultIgnoreFailure; |
| 101 } else { | 110 } else { |
| 102 Json::Value ignoreFailure = jsonElement[kJsonKey_ExpectedResults _IgnoreFailure]; | 111 Json::Value ignoreFailure = jsonElement[kJsonKey_ExpectedResults _IgnoreFailure]; |
| 103 if (ignoreFailure.isNull()) { | 112 if (ignoreFailure.isNull()) { |
| 104 fIgnoreFailure = kDefaultIgnoreFailure; | 113 fIgnoreFailure = kDefaultIgnoreFailure; |
| 105 } else if (!ignoreFailure.isBool()) { | 114 } else if (!ignoreFailure.isBool()) { |
| 106 fprintf(stderr, "found non-boolean json value for key '%s' i n element '%s'\n", | 115 gm_fprintf(stderr, "found non-boolean json value" |
| 107 kJsonKey_ExpectedResults_IgnoreFailure, | 116 " for key '%s' in element '%s'\n", |
| 108 jsonElement.toStyledString().c_str()); | 117 kJsonKey_ExpectedResults_IgnoreFailure, |
| 118 jsonElement.toStyledString().c_str()); | |
| 109 DEBUGFAIL_SEE_STDERR; | 119 DEBUGFAIL_SEE_STDERR; |
| 110 fIgnoreFailure = kDefaultIgnoreFailure; | 120 fIgnoreFailure = kDefaultIgnoreFailure; |
| 111 } else { | 121 } else { |
| 112 fIgnoreFailure = ignoreFailure.asBool(); | 122 fIgnoreFailure = ignoreFailure.asBool(); |
| 113 } | 123 } |
| 114 | 124 |
| 115 Json::Value allowedChecksums = jsonElement[kJsonKey_ExpectedResu lts_Checksums]; | 125 Json::Value allowedChecksums = jsonElement[kJsonKey_ExpectedResu lts_Checksums]; |
| 116 if (allowedChecksums.isNull()) { | 126 if (allowedChecksums.isNull()) { |
| 117 // ok, we'll just assume there aren't any expected checksums to compare against | 127 // ok, we'll just assume there aren't any expected checksums to compare against |
| 118 } else if (!allowedChecksums.isArray()) { | 128 } else if (!allowedChecksums.isArray()) { |
| 119 fprintf(stderr, "found non-array json value for key '%s' in element '%s'\n", | 129 gm_fprintf(stderr, "found non-array json value" |
| 120 kJsonKey_ExpectedResults_Checksums, | 130 " for key '%s' in element '%s'\n", |
| 121 jsonElement.toStyledString().c_str()); | 131 kJsonKey_ExpectedResults_Checksums, |
| 132 jsonElement.toStyledString().c_str()); | |
| 122 DEBUGFAIL_SEE_STDERR; | 133 DEBUGFAIL_SEE_STDERR; |
| 123 } else { | 134 } else { |
| 124 for (Json::ArrayIndex i=0; i<allowedChecksums.size(); i++) { | 135 for (Json::ArrayIndex i=0; i<allowedChecksums.size(); i++) { |
| 125 Json::Value checksumElement = allowedChecksums[i]; | 136 Json::Value checksumElement = allowedChecksums[i]; |
| 126 if (!checksumElement.isIntegral()) { | 137 if (!checksumElement.isIntegral()) { |
| 127 fprintf(stderr, "found non-integer checksum in json element '%s'\n", | 138 gm_fprintf(stderr, "found non-integer checksum" |
| 128 jsonElement.toStyledString().c_str()); | 139 " in json element '%s'\n", |
| 140 jsonElement.toStyledString().c_str()); | |
| 129 DEBUGFAIL_SEE_STDERR; | 141 DEBUGFAIL_SEE_STDERR; |
| 130 } else { | 142 } else { |
| 131 fAllowedChecksums.push_back() = asChecksum(checksumE lement); | 143 fAllowedChecksums.push_back() = asChecksum(checksumE lement); |
| 132 } | 144 } |
| 133 } | 145 } |
| 134 } | 146 } |
| 135 } | 147 } |
| 136 } | 148 } |
| 137 | 149 |
| 138 /** | 150 /** |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 SkBitmap referenceBitmap; | 238 SkBitmap referenceBitmap; |
| 227 bool decodedReferenceBitmap = | 239 bool decodedReferenceBitmap = |
| 228 SkImageDecoder::DecodeFile(path.c_str(), &referenceBitmap, | 240 SkImageDecoder::DecodeFile(path.c_str(), &referenceBitmap, |
| 229 SkBitmap::kARGB_8888_Config, | 241 SkBitmap::kARGB_8888_Config, |
| 230 SkImageDecoder::kDecodePixels_Mode, | 242 SkImageDecoder::kDecodePixels_Mode, |
| 231 NULL); | 243 NULL); |
| 232 if (decodedReferenceBitmap) { | 244 if (decodedReferenceBitmap) { |
| 233 return Expectations(referenceBitmap); | 245 return Expectations(referenceBitmap); |
| 234 } else { | 246 } else { |
| 235 if (fNotifyOfMissingFiles) { | 247 if (fNotifyOfMissingFiles) { |
| 236 fprintf(stderr, "FAILED to read %s\n", path.c_str()); | 248 gm_fprintf(stderr, "FAILED to read %s\n", path.c_str()); |
| 237 } | 249 } |
| 238 return Expectations(); | 250 return Expectations(); |
| 239 } | 251 } |
| 240 } | 252 } |
| 241 | 253 |
| 242 private: | 254 private: |
| 243 const SkString fRootDir; | 255 const SkString fRootDir; |
| 244 const bool fNotifyOfMissingFiles; | 256 const bool fNotifyOfMissingFiles; |
| 245 }; | 257 }; |
| 246 | 258 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 } | 336 } |
| 325 | 337 |
| 326 /** | 338 /** |
| 327 * Read the file contents from jsonPath and parse them into jsonRoot. | 339 * Read the file contents from jsonPath and parse them into jsonRoot. |
| 328 * | 340 * |
| 329 * Returns true if successful. | 341 * Returns true if successful. |
| 330 */ | 342 */ |
| 331 static bool parse(const char *jsonPath, Json::Value *jsonRoot) { | 343 static bool parse(const char *jsonPath, Json::Value *jsonRoot) { |
| 332 SkFILEStream inFile(jsonPath); | 344 SkFILEStream inFile(jsonPath); |
| 333 if (!inFile.isValid()) { | 345 if (!inFile.isValid()) { |
| 334 fprintf(stderr, "unable to read JSON file %s\n", jsonPath); | 346 gm_fprintf(stderr, "unable to read JSON file %s\n", jsonPath); |
| 335 DEBUGFAIL_SEE_STDERR; | 347 DEBUGFAIL_SEE_STDERR; |
| 336 return false; | 348 return false; |
| 337 } | 349 } |
| 338 | 350 |
| 339 SkAutoDataUnref dataRef(readFileIntoSkData(inFile)); | 351 SkAutoDataUnref dataRef(readFileIntoSkData(inFile)); |
| 340 if (NULL == dataRef.get()) { | 352 if (NULL == dataRef.get()) { |
| 341 fprintf(stderr, "error reading JSON file %s\n", jsonPath); | 353 gm_fprintf(stderr, "error reading JSON file %s\n", jsonPath); |
| 342 DEBUGFAIL_SEE_STDERR; | 354 DEBUGFAIL_SEE_STDERR; |
| 343 return false; | 355 return false; |
| 344 } | 356 } |
| 345 | 357 |
| 346 const char *bytes = reinterpret_cast<const char *>(dataRef.get()->da ta()); | 358 const char *bytes = reinterpret_cast<const char *>(dataRef.get()->da ta()); |
| 347 size_t size = dataRef.get()->size(); | 359 size_t size = dataRef.get()->size(); |
| 348 Json::Reader reader; | 360 Json::Reader reader; |
| 349 if (!reader.parse(bytes, bytes+size, *jsonRoot)) { | 361 if (!reader.parse(bytes, bytes+size, *jsonRoot)) { |
| 350 fprintf(stderr, "error parsing JSON file %s\n", jsonPath); | 362 gm_fprintf(stderr, "error parsing JSON file %s\n", jsonPath); |
| 351 DEBUGFAIL_SEE_STDERR; | 363 DEBUGFAIL_SEE_STDERR; |
| 352 return false; | 364 return false; |
| 353 } | 365 } |
| 354 return true; | 366 return true; |
| 355 } | 367 } |
| 356 | 368 |
| 357 Json::Value fJsonRoot; | 369 Json::Value fJsonRoot; |
| 358 Json::Value fJsonExpectedResults; | 370 Json::Value fJsonExpectedResults; |
| 359 }; | 371 }; |
| 360 | 372 |
| 361 } | 373 } |
| 362 #endif | 374 #endif |
| OLD | NEW |