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" | 5 #include "gm_expectations.h" |
6 | 6 |
7 namespace DM { | 7 namespace DM { |
8 | 8 |
9 struct Expectations { | 9 struct Expectations { |
10 virtual ~Expectations() {} | 10 virtual ~Expectations() {} |
11 | 11 |
12 // Return true if bitmap is the correct output for task, else false. | 12 // Return true if bitmap is the correct output for task, else false. |
13 virtual bool check(const Task& task, SkBitmap bitmap) const = 0; | 13 virtual bool check(const Task& task, SkBitmap bitmap) const = 0; |
14 }; | 14 }; |
15 | 15 |
16 class NoExpectations : public Expectations { | 16 class NoExpectations : public Expectations { |
17 public: | 17 public: |
18 NoExpectations() {} | 18 NoExpectations() {} |
19 bool check(const Task&, SkBitmap) const SK_OVERRIDE { return true; } | 19 bool check(const Task&, SkBitmap) const SK_OVERRIDE { return true; } |
20 }; | 20 }; |
21 | 21 |
22 #ifdef SK_BUILD_JSON_WRITER | |
23 class JsonExpectations : public Expectations { | 22 class JsonExpectations : public Expectations { |
24 public: | 23 public: |
25 explicit JsonExpectations(const char* path) : fGMExpectations(path) {} | 24 explicit JsonExpectations(const char* path) : fGMExpectations(path) {} |
26 | 25 |
27 bool check(const Task& task, SkBitmap bitmap) const SK_OVERRIDE { | 26 bool check(const Task& task, SkBitmap bitmap) const SK_OVERRIDE { |
28 SkString filename = task.name(); | 27 SkString filename = task.name(); |
29 filename.append(".png"); | 28 filename.append(".png"); |
30 const skiagm::Expectations expectations = fGMExpectations.get(filename.c
_str()); | 29 const skiagm::Expectations expectations = fGMExpectations.get(filename.c
_str()); |
31 | 30 |
32 if (expectations.ignoreFailure() || expectations.empty()) { | 31 if (expectations.ignoreFailure() || expectations.empty()) { |
33 return true; | 32 return true; |
34 } | 33 } |
35 | 34 |
36 // Delay this calculation as long as possible. It's expensive. | 35 // Delay this calculation as long as possible. It's expensive. |
37 const skiagm::GmResultDigest digest(bitmap); | 36 const skiagm::GmResultDigest digest(bitmap); |
38 return expectations.match(digest); | 37 return expectations.match(digest); |
39 } | 38 } |
40 | 39 |
41 private: | 40 private: |
42 skiagm::JsonExpectationsSource fGMExpectations; | 41 skiagm::JsonExpectationsSource fGMExpectations; |
43 }; | 42 }; |
44 #endif | |
45 | 43 |
46 } // namespace DM | 44 } // namespace DM |
47 | 45 |
48 #endif // DMExpectations_DEFINED | 46 #endif // DMExpectations_DEFINED |
OLD | NEW |