summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libs/hwui/tests/common/TestUtils.h11
-rw-r--r--libs/hwui/tests/unit/CanvasContextTests.cpp20
-rw-r--r--libs/hwui/tests/unit/SkiaDisplayListTests.cpp19
3 files changed, 15 insertions, 35 deletions
diff --git a/libs/hwui/tests/common/TestUtils.h b/libs/hwui/tests/common/TestUtils.h
index cdaa705ed387..f6fe7d267354 100644
--- a/libs/hwui/tests/common/TestUtils.h
+++ b/libs/hwui/tests/common/TestUtils.h
@@ -249,6 +249,17 @@ public:
static std::unique_ptr<uint16_t[]> asciiToUtf16(const char* str);
+ class MockFunctor : public Functor {
+ public:
+ virtual status_t operator ()(int what, void* data) {
+ mLastMode = what;
+ return DrawGlInfo::kStatusDone;
+ }
+ int getLastMode() const { return mLastMode; }
+ private:
+ int mLastMode = -1;
+ };
+
private:
static void syncHierarchyPropertiesAndDisplayListImpl(RenderNode* node) {
node->syncProperties();
diff --git a/libs/hwui/tests/unit/CanvasContextTests.cpp b/libs/hwui/tests/unit/CanvasContextTests.cpp
index 344cc16fdf9c..d3d80a96d5a3 100644
--- a/libs/hwui/tests/unit/CanvasContextTests.cpp
+++ b/libs/hwui/tests/unit/CanvasContextTests.cpp
@@ -43,24 +43,8 @@ RENDERTHREAD_TEST(CanvasContext, create) {
canvasContext->destroy(nullptr);
}
-// This must be in an anonymous namespace as this class name is used in multiple
-// cpp files for different purposes and without the namespace the linker can
-// arbitrarily choose which class to link against.
-namespace {
-class TestFunctor : public Functor {
-public:
- bool didProcess = false;
-
- virtual status_t operator ()(int what, void* data) {
- if (what == DrawGlInfo::kModeProcess) { didProcess = true; }
- return DrawGlInfo::kStatusDone;
- }
-};
-}; // end anonymous namespace
-
RENDERTHREAD_TEST(CanvasContext, invokeFunctor) {
- TestFunctor functor;
- ASSERT_FALSE(functor.didProcess);
+ TestUtils::MockFunctor functor;
CanvasContext::invokeFunctor(renderThread, &functor);
- ASSERT_TRUE(functor.didProcess);
+ ASSERT_EQ(functor.getLastMode(), DrawGlInfo::kModeProcess);
}
diff --git a/libs/hwui/tests/unit/SkiaDisplayListTests.cpp b/libs/hwui/tests/unit/SkiaDisplayListTests.cpp
index 4d79dde54b35..72029b9ccfc7 100644
--- a/libs/hwui/tests/unit/SkiaDisplayListTests.cpp
+++ b/libs/hwui/tests/unit/SkiaDisplayListTests.cpp
@@ -91,27 +91,12 @@ TEST(SkiaDisplayList, reuseDisplayList) {
ASSERT_EQ(availableList.get(), nullptr);
}
-// This must be in an anonymous namespace as this class name is used in multiple
-// cpp files for different purposes and without the namespace the linker can
-// arbitrarily choose which class to link against.
-namespace {
-class TestFunctor : public Functor {
-public:
- bool didSync = false;
-
- virtual status_t operator ()(int what, void* data) {
- if (what == DrawGlInfo::kModeSync) { didSync = true; }
- return DrawGlInfo::kStatusDone;
- }
-};
-}; // end anonymous namespace
-
TEST(SkiaDisplayList, syncContexts) {
SkRect bounds = SkRect::MakeWH(200, 200);
SkiaDisplayList skiaDL(bounds);
SkCanvas dummyCanvas;
- TestFunctor functor;
+ TestUtils::MockFunctor functor;
skiaDL.mChildFunctors.emplace_back(&functor, nullptr, &dummyCanvas);
VectorDrawableRoot vectorDrawable(new VectorDrawable::Group());
@@ -121,7 +106,7 @@ TEST(SkiaDisplayList, syncContexts) {
// ensure that the functor and vectorDrawable are properly synced
skiaDL.syncContents();
- ASSERT_TRUE(functor.didSync);
+ ASSERT_EQ(functor.getLastMode(), DrawGlInfo::kModeSync);
ASSERT_EQ(vectorDrawable.mutateProperties()->getBounds(), bounds);
}