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

Unified Diff: gm/gm_expectations.h

Issue 14284018: GM: specify that currently used checksums are CityHashes of SkBitmaps (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: move_some_of_gm_expectations_h_into_cpp_file 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/gm_expectations.cpp » ('j') | gm/gm_expectations.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/gm_expectations.h
===================================================================
--- gm/gm_expectations.h (revision 8850)
+++ gm/gm_expectations.h (working copy)
@@ -7,12 +7,9 @@
#ifndef gm_expectations_DEFINED
#define gm_expectations_DEFINED
-#include <stdarg.h>
#include "gm.h"
#include "SkBitmap.h"
-#include "SkBitmapHasher.h"
#include "SkData.h"
-#include "SkImageDecoder.h"
#include "SkOSFile.h"
#include "SkRefCnt.h"
#include "SkStream.h"
@@ -30,18 +27,17 @@
#pragma warning(pop)
#endif
-#define DEBUGFAIL_SEE_STDERR SkDEBUGFAIL("see stderr for message")
-
+// EPOGER: move these into a .cpp file so we know nobody else uses them?
const static char kJsonKey_ActualResults[] = "actual-results";
const static char kJsonKey_ActualResults_Failed[] = "failed";
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_Checksum[] = "checksum";
+const static char kJsonKey_ActualResults_AnyStatus_BitmapCityhash[] = "bitmap-cityhash";
const static char kJsonKey_ExpectedResults[] = "expected-results";
-const static char kJsonKey_ExpectedResults_Checksums[] = "checksums";
-const static char kJsonKey_ExpectedResults_IgnoreFailure[] = "ignore-failure";
+const static char kJsonKey_ExpectedResults_AllowedBitmapCityhashes[] = "allowed-bitmap-cityhashes";
+const static char kJsonKey_ExpectedResults_IgnoreFailure[] = "ignore-failure";
namespace skiagm {
@@ -83,25 +79,13 @@
/**
* No expectations at all.
*/
- Expectations(bool ignoreFailure=kDefaultIgnoreFailure) {
- fIgnoreFailure = ignoreFailure;
- }
+ Expectations(bool ignoreFailure=kDefaultIgnoreFailure);
/**
* Expect exactly one image (appropriate for the case when we
* are comparing against a single PNG file).
*/
- 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.
- if (!SkBitmapHasher::ComputeDigest(bitmap, &digest)) {
- digest = 0;
- }
- fAllowedChecksums.push_back() = digest;
- }
+ Expectations(const SkBitmap& bitmap, bool ignoreFailure=kDefaultIgnoreFailure);
/**
* Create Expectations from a JSON element as found within the
@@ -110,49 +94,8 @@
* It's fine if the jsonElement is null or empty; in that case, we just
* don't have any expectations.
*/
- Expectations(Json::Value jsonElement) {
- if (jsonElement.empty()) {
- fIgnoreFailure = kDefaultIgnoreFailure;
- } else {
- Json::Value ignoreFailure = jsonElement[kJsonKey_ExpectedResults_IgnoreFailure];
- if (ignoreFailure.isNull()) {
- fIgnoreFailure = kDefaultIgnoreFailure;
- } else if (!ignoreFailure.isBool()) {
- gm_fprintf(stderr, "found non-boolean json value"
- " for key '%s' in element '%s'\n",
- kJsonKey_ExpectedResults_IgnoreFailure,
- jsonElement.toStyledString().c_str());
- DEBUGFAIL_SEE_STDERR;
- fIgnoreFailure = kDefaultIgnoreFailure;
- } else {
- fIgnoreFailure = ignoreFailure.asBool();
- }
+ Expectations(Json::Value jsonElement);
- Json::Value allowedChecksums = jsonElement[kJsonKey_ExpectedResults_Checksums];
- if (allowedChecksums.isNull()) {
- // ok, we'll just assume there aren't any expected checksums to compare against
- } else if (!allowedChecksums.isArray()) {
- gm_fprintf(stderr, "found non-array json value"
- " for key '%s' in element '%s'\n",
- kJsonKey_ExpectedResults_Checksums,
- 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 {
- fAllowedChecksums.push_back() = asChecksum(checksumElement);
- }
- }
- }
- }
- }
-
/**
* Returns true iff we want to ignore failed expectations.
*/
@@ -161,22 +104,14 @@
/**
* Returns true iff there are no allowed checksums.
*/
- bool empty() const { return this->fAllowedChecksums.empty(); }
+ bool empty() const { return this->fAllowedBitmapCityhashes.empty(); }
/**
* Returns true iff actualChecksum matches any allowedChecksum,
* regardless of fIgnoreFailure. (The caller can check
* that separately.)
*/
- bool match(Checksum actualChecksum) const {
- for (int i=0; i < this->fAllowedChecksums.count(); i++) {
- Checksum allowedChecksum = this->fAllowedChecksums[i];
- if (allowedChecksum == actualChecksum) {
- return true;
- }
- }
- return false;
- }
+ bool match(Checksum actualChecksum) const;
/**
* If this Expectation is based on a single SkBitmap, return a
@@ -193,21 +128,12 @@
* This does NOT include any information about whether to
* ignore failures.
*/
- Json::Value allowedChecksumsAsJson() const {
- Json::Value allowedChecksumArray;
- if (!this->fAllowedChecksums.empty()) {
- for (int i=0; i < this->fAllowedChecksums.count(); i++) {
- Checksum allowedChecksum = this->fAllowedChecksums[i];
- allowedChecksumArray.append(asJsonValue(allowedChecksum));
- }
- }
- return allowedChecksumArray;
- }
+ Json::Value allowedChecksumsAsJson() const;
private:
const static bool kDefaultIgnoreFailure = false;
- SkTArray<Checksum> fAllowedChecksums;
+ SkTArray<Checksum> fAllowedBitmapCityhashes;
bool fIgnoreFailure;
SkBitmap fBitmap;
};
@@ -234,21 +160,7 @@
*/
IndividualImageExpectationsSource(const char *rootDir) : fRootDir(rootDir) {}
- Expectations get(const char *testName) SK_OVERRIDE {
- SkString path = make_filename(fRootDir.c_str(), "", testName,
- "png");
- SkBitmap referenceBitmap;
- bool decodedReferenceBitmap =
- SkImageDecoder::DecodeFile(path.c_str(), &referenceBitmap,
- SkBitmap::kARGB_8888_Config,
- SkImageDecoder::kDecodePixels_Mode,
- NULL);
- if (decodedReferenceBitmap) {
- return Expectations(referenceBitmap);
- } else {
- return Expectations();
- }
- }
+ Expectations get(const char *testName) SK_OVERRIDE ;
private:
const SkString fRootDir;
@@ -265,14 +177,9 @@
*
* jsonPath: path to JSON file to read
*/
- JsonExpectationsSource(const char *jsonPath) {
- parse(jsonPath, &fJsonRoot);
- fJsonExpectedResults = fJsonRoot[kJsonKey_ExpectedResults];
- }
+ JsonExpectationsSource(const char *jsonPath);
- Expectations get(const char *testName) SK_OVERRIDE {
- return Expectations(fJsonExpectedResults[testName]);
- }
+ Expectations get(const char *testName) SK_OVERRIDE;
private:
@@ -307,23 +214,7 @@
// TODO(epoger): Move this, into SkStream.[cpp|h] as attempted in
// https://codereview.appspot.com/7300071 ?
// And maybe readFileIntoSkData() also?
- static SkData* readIntoSkData(SkStream &stream, size_t maxBytes) {
- if (0 == maxBytes) {
- return SkData::NewEmpty();
- }
- char* bufStart = reinterpret_cast<char *>(sk_malloc_throw(maxBytes));
- char* bufPtr = bufStart;
- size_t bytesRemaining = maxBytes;
- while (bytesRemaining > 0) {
- size_t bytesReadThisTime = stream.read(bufPtr, bytesRemaining);
- if (0 == bytesReadThisTime) {
- break;
- }
- bytesRemaining -= bytesReadThisTime;
- bufPtr += bytesReadThisTime;
- }
- return SkData::NewFromMalloc(bufStart, maxBytes - bytesRemaining);
- }
+ static SkData* readIntoSkData(SkStream &stream, size_t maxBytes);
/**
* Wrapper around readIntoSkData for files: reads the entire file into
@@ -338,32 +229,8 @@
*
* Returns true if successful.
*/
- static bool parse(const char *jsonPath, Json::Value *jsonRoot) {
- SkFILEStream inFile(jsonPath);
- if (!inFile.isValid()) {
- gm_fprintf(stderr, "unable to read JSON file %s\n", jsonPath);
- DEBUGFAIL_SEE_STDERR;
- return false;
- }
+ static bool parse(const char *jsonPath, Json::Value *jsonRoot);
- SkAutoDataUnref dataRef(readFileIntoSkData(inFile));
- if (NULL == dataRef.get()) {
- gm_fprintf(stderr, "error reading JSON file %s\n", jsonPath);
- DEBUGFAIL_SEE_STDERR;
- return false;
- }
-
- const char *bytes = reinterpret_cast<const char *>(dataRef.get()->data());
- size_t size = dataRef.get()->size();
- Json::Reader reader;
- if (!reader.parse(bytes, bytes+size, *jsonRoot)) {
- gm_fprintf(stderr, "error parsing JSON file %s\n", jsonPath);
- DEBUGFAIL_SEE_STDERR;
- return false;
- }
- return true;
- }
-
Json::Value fJsonRoot;
Json::Value fJsonExpectedResults;
};
« no previous file with comments | « no previous file | gm/gm_expectations.cpp » ('j') | gm/gm_expectations.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698