blob: 11f99104e936b98483885e2a05ff68a458486e8d [file] [log] [blame]
Lloyd Pique45a165a2018-10-19 11:54:47 -07001/*
2 * Copyright 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <gtest/gtest.h>
18
19#include <cmath>
20
21#include <compositionengine/DisplayCreationArgs.h>
22#include <compositionengine/impl/Display.h>
23#include <compositionengine/mock/CompositionEngine.h>
24
25#include "MockHWComposer.h"
26
27namespace android::compositionengine {
28namespace {
29
30using testing::ReturnRef;
31using testing::StrictMock;
32
33constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42};
34
35class DisplayTest : public testing::Test {
36public:
37 ~DisplayTest() override = default;
38
39 StrictMock<android::mock::HWComposer> mHwComposer;
40 StrictMock<mock::CompositionEngine> mCompositionEngine;
41 impl::Display mDisplay{mCompositionEngine,
42 DisplayCreationArgsBuilder().setDisplayId(DEFAULT_DISPLAY_ID).build()};
43};
44
45/* ------------------------------------------------------------------------
46 * Basic construction
47 */
48
49TEST_F(DisplayTest, canInstantiateDisplay) {
50 {
51 constexpr DisplayId display1 = DisplayId{123u};
52 auto display =
53 impl::createDisplay(mCompositionEngine,
54 DisplayCreationArgsBuilder().setDisplayId(display1).build());
55 EXPECT_FALSE(display->isSecure());
56 EXPECT_FALSE(display->isVirtual());
57 EXPECT_EQ(display1, display->getId());
58 }
59
60 {
61 constexpr DisplayId display2 = DisplayId{546u};
62 auto display = impl::createDisplay(mCompositionEngine,
63 DisplayCreationArgsBuilder()
64 .setIsSecure(true)
65 .setDisplayId(display2)
66 .build());
67 EXPECT_TRUE(display->isSecure());
68 EXPECT_FALSE(display->isVirtual());
69 EXPECT_EQ(display2, display->getId());
70 }
71
72 {
73 constexpr DisplayId display3 = DisplayId{789u};
74 auto display = impl::createDisplay(mCompositionEngine,
75 DisplayCreationArgsBuilder()
76 .setIsVirtual(true)
77 .setDisplayId(display3)
78 .build());
79 EXPECT_FALSE(display->isSecure());
80 EXPECT_TRUE(display->isVirtual());
81 EXPECT_EQ(display3, display->getId());
82 }
83}
84
85/* ------------------------------------------------------------------------
86 * Display::disconnect()
87 */
88
89TEST_F(DisplayTest, disconnectDisconnectsDisplay) {
90 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
91
92 // The first call to disconnect will disconnect the display with the HWC and
93 // set mHwcId to -1.
94 EXPECT_CALL(mHwComposer, disconnectDisplay(DEFAULT_DISPLAY_ID)).Times(1);
95 mDisplay.disconnect();
96 EXPECT_FALSE(mDisplay.getId());
97
98 // Subsequent calls will do nothing,
99 EXPECT_CALL(mHwComposer, disconnectDisplay(DEFAULT_DISPLAY_ID)).Times(0);
100 mDisplay.disconnect();
101 EXPECT_FALSE(mDisplay.getId());
102}
103
104} // namespace
105} // namespace android::compositionengine