libui: PrintTo and comparisons for values for tests
Define `PrintTo` and (except for Region) ensure there is an appropriate
`operator==`. The Google Test framework will uses `PrintTo` to print out
values if available, and uses operator == to check if values match
expected values.
The following value types were modified:
* Rect
* FloatRect
* Region
* Transform
With these definitions, the Composition Engine tests no longer need
custom matchers to print/compare values (except for Region).
For Region it seemed unwise to define a general `operator==` as equality
of Regions might mean different things to different callers. Instead
this change just adds a `Region::hasSameRects(const Region& other)`
function to do the fast check that the tests were doing. As such a
matcher helper is still needed which calls that function, though now it
is much more trivial to write.
Bug: None
Test: libcompositionengine_test
Change-Id: I160cda695d99257966634e767ee1164bc6105e30
diff --git a/services/surfaceflinger/CompositionEngine/tests/RegionMatcher.h b/services/surfaceflinger/CompositionEngine/tests/RegionMatcher.h
index 5a4efa9..2adde23 100644
--- a/services/surfaceflinger/CompositionEngine/tests/RegionMatcher.h
+++ b/services/surfaceflinger/CompositionEngine/tests/RegionMatcher.h
@@ -20,24 +20,22 @@
namespace {
-// Checks for a region match
-MATCHER_P(RegionEq, expected, "") {
- std::string buf;
- buf.append("Regions are not equal\n");
- expected.dump(buf, "expected region");
- arg.dump(buf, "actual region");
- *result_listener << buf;
+using Region = android::Region;
- size_t expectedRectCount = 0;
- android::Rect const* expectedRects = expected.getArray(&expectedRectCount);
- size_t actualRectCount = 0;
- android::Rect const* actualRects = arg.getArray(&actualRectCount);
+struct RegionMatcher : public testing::MatcherInterface<const Region&> {
+ const Region expected;
- if (expectedRectCount != actualRectCount) return false;
- for (size_t i = 0; i < expectedRectCount; i++) {
- if (expectedRects[i] != actualRects[i]) return false;
+ explicit RegionMatcher(const Region& expectedValue) : expected(expectedValue) {}
+
+ bool MatchAndExplain(const Region& actual, testing::MatchResultListener*) const override {
+ return expected.hasSameRects(actual);
}
- return true;
+
+ void DescribeTo(::std::ostream* os) const override { PrintTo(expected, os); }
+};
+
+testing::Matcher<const Region&> RegionEq(const Region& expected) {
+ return MakeMatcher(new RegionMatcher(expected));
}
} // namespace