| OLD | NEW |
| 1 #ifndef DMExpectations_DEFINED | 1 #ifndef DMExpectations_DEFINED |
| 2 #define DMExpectations_DEFINED | 2 #define DMExpectations_DEFINED |
| 3 | 3 |
| 4 #include "DMTask.h" | 4 #include "DMTask.h" |
| 5 #include "gm_expectations.h" | |
| 6 | 5 |
| 7 namespace DM { | 6 namespace DM { |
| 8 | 7 |
| 9 struct Expectations { | 8 struct Expectations { |
| 10 virtual ~Expectations() {} | 9 virtual ~Expectations() {} |
| 11 | 10 |
| 12 // Return true if bitmap is the correct output for task, else false. | 11 // Return true if bitmap is the correct output for task, else false. |
| 13 virtual bool check(const Task& task, SkBitmap bitmap) const = 0; | 12 virtual bool check(const Task& task, SkBitmap bitmap) const { |
| 14 }; | 13 return true; |
| 15 | |
| 16 class NoExpectations : public Expectations { | |
| 17 public: | |
| 18 NoExpectations() {} | |
| 19 bool check(const Task&, SkBitmap) const SK_OVERRIDE { return true; } | |
| 20 }; | |
| 21 | |
| 22 class JsonExpectations : public Expectations { | |
| 23 public: | |
| 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 } | 14 } |
| 39 | |
| 40 private: | |
| 41 skiagm::JsonExpectationsSource fGMExpectations; | |
| 42 }; | 15 }; |
| 43 | 16 |
| 44 } // namespace DM | 17 } // namespace DM |
| 45 | 18 |
| 46 #endif // DMExpectations_DEFINED | 19 #endif // DMExpectations_DEFINED |
| OLD | NEW |