diff options
Diffstat (limited to 'services/surfaceflinger/tests/unittests/EventThreadTest.cpp')
-rw-r--r-- | services/surfaceflinger/tests/unittests/EventThreadTest.cpp | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/services/surfaceflinger/tests/unittests/EventThreadTest.cpp b/services/surfaceflinger/tests/unittests/EventThreadTest.cpp index dbd9b84039..2662f52581 100644 --- a/services/surfaceflinger/tests/unittests/EventThreadTest.cpp +++ b/services/surfaceflinger/tests/unittests/EventThreadTest.cpp @@ -42,6 +42,8 @@ constexpr PhysicalDisplayId DISPLAY_ID_64BIT = 0xabcd12349876fedcULL; class MockVSyncSource : public VSyncSource { public: + const char* getName() const override { return "test"; } + MOCK_METHOD1(setVSyncEnabled, void(bool)); MOCK_METHOD1(setCallback, void(VSyncSource::Callback*)); MOCK_METHOD1(setPhaseOffset, void(nsecs_t)); @@ -54,8 +56,7 @@ class EventThreadTest : public testing::Test { protected: class MockEventThreadConnection : public EventThreadConnection { public: - MockEventThreadConnection(android::impl::EventThread* eventThread, - ResyncCallback&& resyncCallback, + MockEventThreadConnection(impl::EventThread* eventThread, ResyncCallback&& resyncCallback, ISurfaceComposer::ConfigChanged configChanged) : EventThreadConnection(eventThread, std::move(resyncCallback), configChanged) {} MOCK_METHOD1(postEvent, status_t(const DisplayEventReceiver::Event& event)); @@ -67,7 +68,7 @@ protected: EventThreadTest(); ~EventThreadTest() override; - void createThread(); + void createThread(std::unique_ptr<VSyncSource>); sp<MockEventThreadConnection> createConnection(ConnectionEventRecorder& recorder, ISurfaceComposer::ConfigChanged configChanged); @@ -91,9 +92,9 @@ protected: AsyncCallRecorder<void (*)(nsecs_t)> mInterceptVSyncCallRecorder; ConnectionEventRecorder mConnectionEventCallRecorder{0}; - MockVSyncSource mVSyncSource; + MockVSyncSource* mVSyncSource; VSyncSource::Callback* mCallback = nullptr; - std::unique_ptr<android::impl::EventThread> mThread; + std::unique_ptr<impl::EventThread> mThread; sp<MockEventThreadConnection> mConnection; }; @@ -102,16 +103,19 @@ EventThreadTest::EventThreadTest() { ::testing::UnitTest::GetInstance()->current_test_info(); ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); - EXPECT_CALL(mVSyncSource, setVSyncEnabled(_)) + auto vsyncSource = std::make_unique<MockVSyncSource>(); + mVSyncSource = vsyncSource.get(); + + EXPECT_CALL(*mVSyncSource, setVSyncEnabled(_)) .WillRepeatedly(Invoke(mVSyncSetEnabledCallRecorder.getInvocable())); - EXPECT_CALL(mVSyncSource, setCallback(_)) + EXPECT_CALL(*mVSyncSource, setCallback(_)) .WillRepeatedly(Invoke(mVSyncSetCallbackCallRecorder.getInvocable())); - EXPECT_CALL(mVSyncSource, setPhaseOffset(_)) + EXPECT_CALL(*mVSyncSource, setPhaseOffset(_)) .WillRepeatedly(Invoke(mVSyncSetPhaseOffsetCallRecorder.getInvocable())); - createThread(); + createThread(std::move(vsyncSource)); mConnection = createConnection(mConnectionEventCallRecorder, ISurfaceComposer::eConfigChangedDispatch); @@ -129,11 +133,9 @@ EventThreadTest::~EventThreadTest() { EXPECT_TRUE(!mVSyncSetCallbackCallRecorder.waitForUnexpectedCall().has_value()); } -void EventThreadTest::createThread() { - mThread = - std::make_unique<android::impl::EventThread>(&mVSyncSource, - mInterceptVSyncCallRecorder.getInvocable(), - "unit-test-event-thread"); +void EventThreadTest::createThread(std::unique_ptr<VSyncSource> source) { + mThread = std::make_unique<impl::EventThread>(std::move(source), + mInterceptVSyncCallRecorder.getInvocable()); // EventThread should register itself as VSyncSource callback. mCallback = expectVSyncSetCallbackCallReceived(); |