diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2019-11-21 19:36:15 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-11-21 19:36:15 +0000 |
commit | f026ff4a6549018be98a3b3fd02969e2cae2f79e (patch) | |
tree | ecc5b3f839b4063bb32f47543e72d97b113c64cc /services/surfaceflinger/CompositionEngine/tests | |
parent | 2bdd98deb1ab0f5f5a450cc83eccce88c50c36d1 (diff) | |
parent | e59659592eb54f44b99295e7f36596b21f328455 (diff) | |
download | native-f026ff4a6549018be98a3b3fd02969e2cae2f79e.tar.gz |
Merge "CE: Unit test coverage for Output::beginFrame"
Diffstat (limited to 'services/surfaceflinger/CompositionEngine/tests')
-rw-r--r-- | services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp b/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp index 02bb1464ce..f2502b059c 100644 --- a/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp +++ b/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp @@ -1514,6 +1514,157 @@ TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_Hdr_Prefer * Output::beginFrame() */ +struct OutputBeginFrameTest : public ::testing::Test { + using TestType = OutputBeginFrameTest; + + struct OutputPartialMock : public OutputPartialMockBase { + // Sets up the helper functions called by begiNFrame to use a mock + // implementations. + MOCK_CONST_METHOD1(getDirtyRegion, Region(bool)); + }; + + OutputBeginFrameTest() { + mOutput.setDisplayColorProfileForTest( + std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); + mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); + } + + struct IfGetDirtyRegionExpectationState + : public CallOrderStateMachineHelper<TestType, IfGetDirtyRegionExpectationState> { + [[nodiscard]] auto ifGetDirtyRegionReturns(Region dirtyRegion) { + EXPECT_CALL(getInstance()->mOutput, getDirtyRegion(false)) + .WillOnce(Return(dirtyRegion)); + return nextState<AndIfGetOutputLayerCountExpectationState>(); + } + }; + + struct AndIfGetOutputLayerCountExpectationState + : public CallOrderStateMachineHelper<TestType, AndIfGetOutputLayerCountExpectationState> { + [[nodiscard]] auto andIfGetOutputLayerCountReturns(size_t layerCount) { + EXPECT_CALL(getInstance()->mOutput, getOutputLayerCount()).WillOnce(Return(layerCount)); + return nextState<AndIfLastCompositionHadVisibleLayersState>(); + } + }; + + struct AndIfLastCompositionHadVisibleLayersState + : public CallOrderStateMachineHelper<TestType, + AndIfLastCompositionHadVisibleLayersState> { + [[nodiscard]] auto andIfLastCompositionHadVisibleLayersIs(bool hadOutputLayers) { + getInstance()->mOutput.mState.lastCompositionHadVisibleLayers = hadOutputLayers; + return nextState<ThenExpectRenderSurfaceBeginFrameCallState>(); + } + }; + + struct ThenExpectRenderSurfaceBeginFrameCallState + : public CallOrderStateMachineHelper<TestType, + ThenExpectRenderSurfaceBeginFrameCallState> { + [[nodiscard]] auto thenExpectRenderSurfaceBeginFrameCall(bool mustRecompose) { + EXPECT_CALL(*getInstance()->mRenderSurface, beginFrame(mustRecompose)); + return nextState<ExecuteState>(); + } + }; + + struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> { + [[nodiscard]] auto execute() { + getInstance()->mOutput.beginFrame(); + return nextState<CheckPostconditionHadVisibleLayersState>(); + } + }; + + struct CheckPostconditionHadVisibleLayersState + : public CallOrderStateMachineHelper<TestType, CheckPostconditionHadVisibleLayersState> { + void checkPostconditionHadVisibleLayers(bool expected) { + EXPECT_EQ(expected, getInstance()->mOutput.mState.lastCompositionHadVisibleLayers); + } + }; + + // Tests call one of these two helper member functions to start using the + // mini-DSL defined above. + [[nodiscard]] auto verify() { return IfGetDirtyRegionExpectationState::make(this); } + + static const Region kEmptyRegion; + static const Region kNotEmptyRegion; + + mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); + mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); + StrictMock<OutputPartialMock> mOutput; +}; + +const Region OutputBeginFrameTest::kEmptyRegion{Rect{0, 0, 0, 0}}; +const Region OutputBeginFrameTest::kNotEmptyRegion{Rect{0, 0, 1, 1}}; + +TEST_F(OutputBeginFrameTest, hasDirtyHasLayersHadLayersLastFrame) { + verify().ifGetDirtyRegionReturns(kNotEmptyRegion) + .andIfGetOutputLayerCountReturns(1u) + .andIfLastCompositionHadVisibleLayersIs(true) + .thenExpectRenderSurfaceBeginFrameCall(true) + .execute() + .checkPostconditionHadVisibleLayers(true); +} + +TEST_F(OutputBeginFrameTest, hasDirtyNotHasLayersHadLayersLastFrame) { + verify().ifGetDirtyRegionReturns(kNotEmptyRegion) + .andIfGetOutputLayerCountReturns(0u) + .andIfLastCompositionHadVisibleLayersIs(true) + .thenExpectRenderSurfaceBeginFrameCall(true) + .execute() + .checkPostconditionHadVisibleLayers(false); +} + +TEST_F(OutputBeginFrameTest, hasDirtyHasLayersNotHadLayersLastFrame) { + verify().ifGetDirtyRegionReturns(kNotEmptyRegion) + .andIfGetOutputLayerCountReturns(1u) + .andIfLastCompositionHadVisibleLayersIs(false) + .thenExpectRenderSurfaceBeginFrameCall(true) + .execute() + .checkPostconditionHadVisibleLayers(true); +} + +TEST_F(OutputBeginFrameTest, hasDirtyNotHasLayersNotHadLayersLastFrame) { + verify().ifGetDirtyRegionReturns(kNotEmptyRegion) + .andIfGetOutputLayerCountReturns(0u) + .andIfLastCompositionHadVisibleLayersIs(false) + .thenExpectRenderSurfaceBeginFrameCall(false) + .execute() + .checkPostconditionHadVisibleLayers(false); +} + +TEST_F(OutputBeginFrameTest, notHasDirtyHasLayersHadLayersLastFrame) { + verify().ifGetDirtyRegionReturns(kEmptyRegion) + .andIfGetOutputLayerCountReturns(1u) + .andIfLastCompositionHadVisibleLayersIs(true) + .thenExpectRenderSurfaceBeginFrameCall(false) + .execute() + .checkPostconditionHadVisibleLayers(true); +} + +TEST_F(OutputBeginFrameTest, notHasDirtyNotHasLayersHadLayersLastFrame) { + verify().ifGetDirtyRegionReturns(kEmptyRegion) + .andIfGetOutputLayerCountReturns(0u) + .andIfLastCompositionHadVisibleLayersIs(true) + .thenExpectRenderSurfaceBeginFrameCall(false) + .execute() + .checkPostconditionHadVisibleLayers(true); +} + +TEST_F(OutputBeginFrameTest, notHasDirtyHasLayersNotHadLayersLastFrame) { + verify().ifGetDirtyRegionReturns(kEmptyRegion) + .andIfGetOutputLayerCountReturns(1u) + .andIfLastCompositionHadVisibleLayersIs(false) + .thenExpectRenderSurfaceBeginFrameCall(false) + .execute() + .checkPostconditionHadVisibleLayers(false); +} + +TEST_F(OutputBeginFrameTest, notHasDirtyNotHasLayersNotHadLayersLastFrame) { + verify().ifGetDirtyRegionReturns(kEmptyRegion) + .andIfGetOutputLayerCountReturns(0u) + .andIfLastCompositionHadVisibleLayersIs(false) + .thenExpectRenderSurfaceBeginFrameCall(false) + .execute() + .checkPostconditionHadVisibleLayers(false); +} + /* * Output::devOptRepaintFlash() */ |