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

Unified Diff: gm/gm_expectations.h

Issue 14265010: Make SkSHA1 and SkM5 use common SkDigestHash result type (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: sync_to_r8826 Created 7 years, 8 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 | « no previous file | gm/gmmain.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/gm_expectations.h
===================================================================
--- gm/gm_expectations.h (revision 8826)
+++ gm/gm_expectations.h (working copy)
@@ -12,6 +12,7 @@
#include "SkBitmap.h"
#include "SkBitmapHasher.h"
#include "SkData.h"
+#include "SkHashDigest.h"
#include "SkImageDecoder.h"
#include "SkOSFile.h"
#include "SkRefCnt.h"
@@ -46,6 +47,23 @@
namespace skiagm {
// The actual type we use to represent a checksum is hidden in here.
+#ifdef BITMAP_HASH_TYPE_SkHashDigest
+ typedef SkHashDigest Checksum;
+ static inline Json::Value asJsonValue(Checksum checksum) {
+ // TODO(epoger): This creates a new copy of the string representation
+ // of the checksum, by calling Json::duplicateStringValue().
+ // We may want to investigate calling Json::Value(const StaticString &value)
+ // instead, which eliminates the copy but requires that StaticString
+ // to "stick around".
+ return Json::Value(checksum.toHexString().c_str());
+ }
+ static inline Checksum asChecksum(Json::Value jsonValue) {
+ SkHashDigest digest;
+ // TODO(epoger): handle error in copyFromHexString()?
+ digest.copyFromHexString(jsonValue.asCString());
+ return digest;
+ }
+#else
typedef Json::UInt64 Checksum;
static inline Json::Value asJsonValue(Checksum checksum) {
return checksum;
@@ -53,6 +71,7 @@
static inline Checksum asChecksum(Json::Value jsonValue) {
return jsonValue.asUInt64();
}
+#endif
static void gm_fprintf(FILE *stream, const char format[], ...) {
va_list args;
@@ -94,11 +113,10 @@
Expectations(const SkBitmap& bitmap, bool ignoreFailure=kDefaultIgnoreFailure) {
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.
+ BITMAP_HASH_TYPE digest;
if (!SkBitmapHasher::ComputeDigest(bitmap, &digest)) {
- digest = 0;
+ // TODO(epoger): Better handling for error returned by ComputeDigest()?
+ // For now, we just leave digest empty...
}
fAllowedChecksums.push_back() = digest;
}
@@ -140,6 +158,16 @@
} else {
for (Json::ArrayIndex i=0; i<allowedChecksums.size(); i++) {
Json::Value checksumElement = allowedChecksums[i];
+#ifdef BITMAP_HASH_TYPE_SkHashDigest
+ if (!checksumElement.isString()) {
+ gm_fprintf(stderr, "found non-string checksum"
+ " in json element '%s'\n",
+ jsonElement.toStyledString().c_str());
+ DEBUGFAIL_SEE_STDERR;
+ } else {
+ fAllowedChecksums.push_back() = asChecksum(checksumElement);
+ }
+#else
if (!checksumElement.isIntegral()) {
gm_fprintf(stderr, "found non-integer checksum"
" in json element '%s'\n",
@@ -148,6 +176,7 @@
} else {
fAllowedChecksums.push_back() = asChecksum(checksumElement);
}
+#endif
}
}
}
@@ -170,7 +199,7 @@
*/
bool match(Checksum actualChecksum) const {
for (int i=0; i < this->fAllowedChecksums.count(); i++) {
- Checksum allowedChecksum = this->fAllowedChecksums[i];
+ BITMAP_HASH_TYPE allowedChecksum = this->fAllowedChecksums[i];
if (allowedChecksum == actualChecksum) {
return true;
}
@@ -197,7 +226,7 @@
Json::Value allowedChecksumArray;
if (!this->fAllowedChecksums.empty()) {
for (int i=0; i < this->fAllowedChecksums.count(); i++) {
- Checksum allowedChecksum = this->fAllowedChecksums[i];
+ BITMAP_HASH_TYPE allowedChecksum = this->fAllowedChecksums[i];
allowedChecksumArray.append(asJsonValue(allowedChecksum));
}
}
@@ -207,7 +236,7 @@
private:
const static bool kDefaultIgnoreFailure = false;
- SkTArray<Checksum> fAllowedChecksums;
+ SkTArray<BITMAP_HASH_TYPE> fAllowedChecksums;
bool fIgnoreFailure;
SkBitmap fBitmap;
};
« no previous file with comments | « no previous file | gm/gmmain.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698