1#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
22class JsonExpectations : public Expectations {
23public:
24    explicit JsonExpectations(const char* path) : fGMExpectations(path) {}
25
26    bool check(const Task& task, SkBitmap bitmap) const SK_OVERRIDE {
27        SkString filename = task.name();
28        filename.append(".png");
29        const skiagm::Expectations expectations = fGMExpectations.get(filename.c_str());
30
31        if (expectations.ignoreFailure() || expectations.empty()) {
32            return true;
33        }
34
35        // Delay this calculation as long as possible.  It's expensive.
36        const skiagm::GmResultDigest digest(bitmap);
37        return expectations.match(digest);
38    }
39
40private:
41    skiagm::JsonExpectationsSource fGMExpectations;
42};
43
44}  // namespace DM
45
46#endif // DMExpectations_DEFINED
47