summaryrefslogtreecommitdiff
path: root/libs/ui/Region.cpp
diff options
context:
space:
mode:
author Lloyd Pique <lpique@google.com> 2019-12-03 15:57:10 -0800
committer Lloyd Pique <lpique@google.com> 2019-12-10 15:36:14 -0800
commitea6292883c768675eaf5c4925a4ed95d46a900de (patch)
tree528cf012ec5f2051303f6364000465c7a7ae49af /libs/ui/Region.cpp
parentb35b6c422577273584d6776804e9872b38bfaf74 (diff)
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
Diffstat (limited to 'libs/ui/Region.cpp')
-rw-r--r--libs/ui/Region.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/libs/ui/Region.cpp b/libs/ui/Region.cpp
index 83ebecaa67..bf487c4aec 100644
--- a/libs/ui/Region.cpp
+++ b/libs/ui/Region.cpp
@@ -280,6 +280,20 @@ bool Region::isTriviallyEqual(const Region& region) const {
return begin() == region.begin();
}
+bool Region::hasSameRects(const Region& other) const {
+ size_t thisRectCount = 0;
+ android::Rect const* thisRects = getArray(&thisRectCount);
+ size_t otherRectCount = 0;
+ android::Rect const* otherRects = other.getArray(&otherRectCount);
+
+ if (thisRectCount != otherRectCount) return false;
+
+ for (size_t i = 0; i < thisRectCount; i++) {
+ if (thisRects[i] != otherRects[i]) return false;
+ }
+ return true;
+}
+
// ----------------------------------------------------------------------------
void Region::addRectUnchecked(int l, int t, int r, int b)