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