Chromium Code Reviews| Index: gm/gm_expectations.cpp |
| =================================================================== |
| --- gm/gm_expectations.cpp (revision 9256) |
| +++ gm/gm_expectations.cpp (working copy) |
| @@ -18,12 +18,18 @@ |
| const static char kJsonKey_ActualResults_FailureIgnored[]= "failure-ignored"; |
| const static char kJsonKey_ActualResults_NoComparison[] = "no-comparison"; |
| const static char kJsonKey_ActualResults_Succeeded[] = "succeeded"; |
| -const static char kJsonKey_ActualResults_AnyStatus_BitmapHash[] = "bitmap-64bitMD5"; |
| const static char kJsonKey_ExpectedResults[] = "expected-results"; |
| +// TODO(epoger): Delete the following reference to "64bitMD5", and |
| +// instead call GmResultDigest.asJsonTypeValuePair() to generate all |
| +// instances of that string. |
| const static char kJsonKey_ExpectedResults_AllowedBitmapHashes[] = "allowed-bitmap-64bitMD5s"; |
| -const static char kJsonKey_ExpectedResults_IgnoreFailure[] = "ignore-failure"; |
| +const static char kJsonKey_ExpectedResults_IgnoreFailure[] = "ignore-failure"; |
| +// Types of result hashes we support in the JSON file. |
| +const static char kJsonKey_Hashtype_Bitmap_64bitMD5[] = "bitmap-64bitMD5"; |
| + |
| + |
| namespace skiagm { |
| void gm_fprintf(FILE *stream, const char format[], ...) { |
| @@ -43,15 +49,6 @@ |
| return result; |
| } |
| - // TODO(epoger): This currently assumes that the result SkHashDigest was |
| - // generated as an SkHashDigest of an SkBitmap. We'll need to allow for other |
| - // hash types to cover non-bitmaps. |
| - Json::Value ActualResultAsJsonValue(const SkHashDigest& result) { |
| - Json::Value jsonValue; |
| - jsonValue[kJsonKey_ActualResults_AnyStatus_BitmapHash] = asJsonValue(result); |
| - return jsonValue; |
| - } |
| - |
| Json::Value CreateJsonTree(Json::Value expectedResults, |
| Json::Value actualResultsFailed, |
| Json::Value actualResultsFailureIgnored, |
| @@ -69,6 +66,39 @@ |
| } |
| + // GmResultDigest class... |
| + |
| + GmResultDigest::GmResultDigest(const SkBitmap &bitmap) { |
| + // TODO(epoger): Better handling for error returned by ComputeDigest()? |
| + // For now, we just report a digest of 0 in error cases, like before. |
| + if (!SkBitmapHasher::ComputeDigest(bitmap, &fHashDigest)) { |
| + fHashDigest = 0; |
| + } |
| + } |
| + |
| + GmResultDigest::GmResultDigest(uint64_t checksum) { |
| + fHashDigest = checksum; |
| + } |
| + |
| + bool GmResultDigest::equals(const GmResultDigest &other) const { |
| + // TODO(epoger): The current implementation assumes that this |
| + // and other are always of type kJsonKey_Hashtype_Bitmap_64bitMD5 |
| + return (this->fHashDigest == other.fHashDigest); |
| + } |
| + |
| + Json::Value GmResultDigest::asJsonTypeValuePair() const { |
| + // TODO(epoger): The current implementation assumes that the |
| + // result digest is always of type kJsonKey_Hashtype_Bitmap_64bitMD5 |
| + Json::Value jsonTypeValuePair; |
| + jsonTypeValuePair[kJsonKey_Hashtype_Bitmap_64bitMD5] = Json::UInt64(fHashDigest); |
| + return jsonTypeValuePair; |
| + } |
| + |
| + Json::Value GmResultDigest::getValueAsJsonValue() const { |
| + return Json::UInt64(fHashDigest); |
| + } |
| + |
| + |
| // Expectations class... |
| Expectations::Expectations(bool ignoreFailure) { |
| @@ -78,13 +108,7 @@ |
| Expectations::Expectations(const SkBitmap& bitmap, bool ignoreFailure) { |
| fBitmap = bitmap; |
| fIgnoreFailure = ignoreFailure; |
| - SkHashDigest digest; |
| - // TODO(epoger): Better handling for error returned by ComputeDigest()? |
| - // For now, we just report a digest of 0 in error cases, like before. |
| - if (!SkBitmapHasher::ComputeDigest(bitmap, &digest)) { |
| - digest = 0; |
| - } |
| - fAllowedBitmapChecksums.push_back() = digest; |
| + fAllowedResultDigests.push_back(GmResultDigest(bitmap)); |
| } |
| Expectations::Expectations(Json::Value jsonElement) { |
| @@ -124,17 +148,17 @@ |
| jsonElement.toStyledString().c_str()); |
| DEBUGFAIL_SEE_STDERR; |
| } else { |
| - fAllowedBitmapChecksums.push_back() = asChecksum(checksumElement); |
| + fAllowedResultDigests.push_back(GmResultDigest(checksumElement.asUInt64())); |
| } |
| } |
| } |
| } |
| } |
| - bool Expectations::match(Checksum actualChecksum) const { |
| - for (int i=0; i < this->fAllowedBitmapChecksums.count(); i++) { |
| - Checksum allowedChecksum = this->fAllowedBitmapChecksums[i]; |
| - if (allowedChecksum == actualChecksum) { |
| + bool Expectations::match(GmResultDigest actualGmResultDigest) const { |
| + for (int i=0; i < this->fAllowedResultDigests.count(); i++) { |
| + GmResultDigest allowedResultDigest = this->fAllowedResultDigests[i]; |
| + if (allowedResultDigest.equals(actualGmResultDigest)) { |
| return true; |
| } |
| } |
| @@ -142,16 +166,23 @@ |
| } |
| Json::Value Expectations::asJsonValue() const { |
| - Json::Value allowedChecksumArray; |
| - if (!this->fAllowedBitmapChecksums.empty()) { |
| - for (int i=0; i < this->fAllowedBitmapChecksums.count(); i++) { |
| - Checksum allowedChecksum = this->fAllowedBitmapChecksums[i]; |
| - allowedChecksumArray.append(Json::UInt64(allowedChecksum)); |
| + // TODO(epoger): This implementation assumes that all |
|
epoger
2013/05/23 18:19:12
This comment describes the remaining work for this
|
| + // allowedResultDigests are of type "bitmap-64bitMD5". |
| + // Instead, it should allow each allowedResultDigest to contribute |
| + // its own JSON representation. |
| + Json::Value allowed64bitMD5Array; |
| + if (!this->fAllowedResultDigests.empty()) { |
| + for (int i=0; i < this->fAllowedResultDigests.count(); i++) { |
| + GmResultDigest allowedResultDigest = this->fAllowedResultDigests[i]; |
| + // TODO(epoger): If we delete this call to getValueAsJsonValue() |
| + // will there be any other callers left? If not, delete that |
| + // method's implementation. |
| + allowed64bitMD5Array.append(allowedResultDigest.getValueAsJsonValue()); |
| } |
| } |
| Json::Value jsonValue; |
| - jsonValue[kJsonKey_ExpectedResults_AllowedBitmapHashes] = allowedChecksumArray; |
| + jsonValue[kJsonKey_ExpectedResults_AllowedBitmapHashes] = allowed64bitMD5Array; |
| jsonValue[kJsonKey_ExpectedResults_IgnoreFailure] = this->ignoreFailure(); |
| return jsonValue; |
| } |