Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 96f4410a authored by Derek Sollenberger's avatar Derek Sollenberger Committed by Android (Google) Code Review
Browse files

Merge "Refactor mock Functors into a common TestUtils class."

parents 1952e2dc 835b3a69
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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();
+2 −18
Original line number Diff line number Diff line
@@ -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);
}
+2 −17
Original line number Diff line number Diff line
@@ -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);
}