blob: 5509709104f806cb17b3c0e8aa03510caa44e35d [file] [log] [blame]
commit-bot@chromium.org99589af2013-12-10 14:53:16 +00001#ifndef DMExpectations_DEFINED
2#define DMExpectations_DEFINED
3
4#include "DMTask.h"
5#include "gm_expectations.h"
6
7namespace DM {
8
9struct Expectations {
10 virtual ~Expectations() {}
11
12 // Return true if bitmap is the correct output for task, else false.
13 virtual bool check(const Task& task, SkBitmap bitmap) const = 0;
14};
15
16class NoExpectations : public Expectations {
17public:
18 NoExpectations() {}
19 bool check(const Task&, SkBitmap) const SK_OVERRIDE { return true; }
20};
21
commit-bot@chromium.org120c9992014-05-16 18:11:51 +000022#ifdef SK_BUILD_JSON_WRITER
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000023class JsonExpectations : public Expectations {
24public:
25 explicit JsonExpectations(const char* path) : fGMExpectations(path) {}
26
27 bool check(const Task& task, SkBitmap bitmap) const SK_OVERRIDE {
28 SkString filename = task.name();
29 filename.append(".png");
30 const skiagm::Expectations expectations = fGMExpectations.get(filename.c_str());
31
32 if (expectations.ignoreFailure() || expectations.empty()) {
33 return true;
34 }
35
36 // Delay this calculation as long as possible. It's expensive.
37 const skiagm::GmResultDigest digest(bitmap);
38 return expectations.match(digest);
39 }
40
41private:
42 skiagm::JsonExpectationsSource fGMExpectations;
43};
commit-bot@chromium.org120c9992014-05-16 18:11:51 +000044#endif
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000045
46} // namespace DM
47
48#endif // DMExpectations_DEFINED