Chromium Code Reviews| Index: gm/gm_expectations.cpp |
| =================================================================== |
| --- gm/gm_expectations.cpp (revision 9256) |
| +++ gm/gm_expectations.cpp (working copy) |
| @@ -18,12 +18,15 @@ |
| 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"; |
| -const static char kJsonKey_ExpectedResults_AllowedBitmapHashes[] = "allowed-bitmap-64bitMD5s"; |
| -const static char kJsonKey_ExpectedResults_IgnoreFailure[] = "ignore-failure"; |
| +const static char kJsonKey_ExpectedResults_AllowedDigests[] = "allowed-digests"; |
|
epoger
2013/05/23 19:18:31
As the GmResultDigest class learns about additiona
|
| +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 +46,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 +63,64 @@ |
| } |
| + // 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(const Json::Value &jsonTypeValuePair) { |
| + // TODO(epoger): We check for various error cases below, but in release |
| + // mode we keep on trucking even in these error cases. |
| + // |
| + // Maybe we should set some sort of fIsBogus boolean flag on the |
| + // object created? Or, instead of a constructor, use a factory method |
| + // which can signal success/failure? |
| + |
| + fHashDigest = 0; // default value in case of error |
| + if (!jsonTypeValuePair.isArray()) { |
| + gm_fprintf(stderr, "found non-array json value when parsing GmResultDigest: %s\n", |
| + jsonTypeValuePair.toStyledString().c_str()); |
| + DEBUGFAIL_SEE_STDERR; |
| + } else if (2 != jsonTypeValuePair.size()) { |
| + gm_fprintf(stderr, "found json array with wrong size when parsing GmResultDigest: %s\n", |
| + jsonTypeValuePair.toStyledString().c_str()); |
| + DEBUGFAIL_SEE_STDERR; |
| + } else { |
| + // TODO(epoger): The current implementation assumes that the |
| + // result digest is always of type kJsonKey_Hashtype_Bitmap_64bitMD5 |
| + Json::Value jsonHashValue = jsonTypeValuePair[1]; |
| + if (!jsonHashValue.isIntegral()) { |
| + gm_fprintf(stderr, |
| + "found non-integer jsonHashValue when parsing GmResultDigest: %s\n", |
| + jsonTypeValuePair.toStyledString().c_str()); |
| + DEBUGFAIL_SEE_STDERR; |
| + } else { |
| + fHashDigest = jsonHashValue.asUInt64(); |
| + } |
| + } |
| + } |
| + |
| + 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); |
|
scroggo
2013/05/23 20:42:58
If we special cased 0, two failed GmResultDigests
epoger
2013/05/23 21:06:18
Good idea! I took this and ran with it, adding an
|
| + } |
| + |
| + 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.append(Json::Value(kJsonKey_Hashtype_Bitmap_64bitMD5)); |
| + jsonTypeValuePair.append(Json::UInt64(fHashDigest)); |
| + return jsonTypeValuePair; |
| + } |
| + |
| + |
| // Expectations class... |
| Expectations::Expectations(bool ignoreFailure) { |
| @@ -78,13 +130,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) { |
| @@ -105,36 +151,27 @@ |
| fIgnoreFailure = ignoreFailure.asBool(); |
| } |
| - Json::Value allowedChecksums = |
| - jsonElement[kJsonKey_ExpectedResults_AllowedBitmapHashes]; |
| - if (allowedChecksums.isNull()) { |
| - // ok, we'll just assume there aren't any expected checksums to compare against |
| - } else if (!allowedChecksums.isArray()) { |
| + Json::Value allowedDigests = jsonElement[kJsonKey_ExpectedResults_AllowedDigests]; |
| + if (allowedDigests.isNull()) { |
| + // ok, we'll just assume there aren't any AllowedDigests to compare against |
| + } else if (!allowedDigests.isArray()) { |
| gm_fprintf(stderr, "found non-array json value" |
| " for key '%s' in element '%s'\n", |
| - kJsonKey_ExpectedResults_AllowedBitmapHashes, |
| + kJsonKey_ExpectedResults_AllowedDigests, |
| jsonElement.toStyledString().c_str()); |
| DEBUGFAIL_SEE_STDERR; |
| } else { |
| - for (Json::ArrayIndex i=0; i<allowedChecksums.size(); i++) { |
| - Json::Value checksumElement = allowedChecksums[i]; |
| - if (!checksumElement.isIntegral()) { |
| - gm_fprintf(stderr, "found non-integer checksum" |
| - " in json element '%s'\n", |
| - jsonElement.toStyledString().c_str()); |
| - DEBUGFAIL_SEE_STDERR; |
| - } else { |
| - fAllowedBitmapChecksums.push_back() = asChecksum(checksumElement); |
| - } |
| + for (Json::ArrayIndex i=0; i<allowedDigests.size(); i++) { |
| + fAllowedResultDigests.push_back(GmResultDigest(allowedDigests[i])); |
| } |
| } |
| } |
| } |
| - 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,18 +179,17 @@ |
| } |
| 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)); |
| + Json::Value allowedDigestArray; |
| + if (!this->fAllowedResultDigests.empty()) { |
| + for (int i=0; i < this->fAllowedResultDigests.count(); i++) { |
| + allowedDigestArray.append(this->fAllowedResultDigests[i].asJsonTypeValuePair()); |
| } |
| } |
| - Json::Value jsonValue; |
| - jsonValue[kJsonKey_ExpectedResults_AllowedBitmapHashes] = allowedChecksumArray; |
| - jsonValue[kJsonKey_ExpectedResults_IgnoreFailure] = this->ignoreFailure(); |
| - return jsonValue; |
| + Json::Value jsonExpectations; |
| + jsonExpectations[kJsonKey_ExpectedResults_AllowedDigests] = allowedDigestArray; |
| + jsonExpectations[kJsonKey_ExpectedResults_IgnoreFailure] = this->ignoreFailure(); |
| + return jsonExpectations; |
| } |