1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17
18 #include "display_manager.h"
19 #include "screen_manager.h"
20 #include "screen_manager_utils.h"
21 #include "mock_display_manager_adapter.h"
22 #include "singleton_mocker.h"
23
24 using namespace testing;
25 using namespace testing::ext;
26
27 namespace OHOS {
28 namespace Rosen {
29 using Mocker = SingletonMocker<ScreenManagerAdapter, MockScreenManagerAdapter>;
30 class ScreenTest : public testing::Test {
31 public:
32 static void SetUpTestCase();
33 static void TearDownTestCase();
34 virtual void SetUp() override;
35 virtual void TearDown() override;
36
37 static sptr<Display> defaultDisplay_;
38 static ScreenId defaultScreenId_;
39 static sptr<Screen> screen_;
40 };
41 sptr<Display> ScreenTest::defaultDisplay_ = nullptr;
42 ScreenId ScreenTest::defaultScreenId_ = SCREEN_ID_INVALID;
43 sptr<Screen> ScreenTest::screen_ = nullptr;
44
SetUpTestCase()45 void ScreenTest::SetUpTestCase()
46 {
47 defaultDisplay_ = DisplayManager::GetInstance().GetDefaultDisplay();
48 defaultScreenId_ = static_cast<ScreenId>(defaultDisplay_->GetId());
49 screen_ = ScreenManager::GetInstance().GetScreenById(defaultScreenId_);
50 }
51
TearDownTestCase()52 void ScreenTest::TearDownTestCase()
53 {
54 defaultDisplay_ = nullptr;
55 screen_ = nullptr;
56 }
57
SetUp()58 void ScreenTest::SetUp()
59 {
60 }
61
TearDown()62 void ScreenTest::TearDown()
63 {
64 }
65
66 namespace {
67 /**
68 * @tc.name: GetBasicProperty01
69 * @tc.desc: Basic property getter test
70 * @tc.type: FUNC
71 */
72 HWTEST_F(ScreenTest, GetBasicProperty01, Function | SmallTest | Level1)
73 {
74 ASSERT_GT(screen_->GetName().size(), 0);
75 ASSERT_GT(screen_->GetWidth(), 0);
76 ASSERT_GT(screen_->GetHeight(), 0);
77 ASSERT_GT(screen_->GetVirtualWidth(), 0);
78 ASSERT_GT(screen_->GetVirtualHeight(), 0);
79 ASSERT_GT(screen_->GetVirtualPixelRatio(), 0);
80 ASSERT_EQ(screen_->GetRotation(), Rotation::ROTATION_0);
81 ASSERT_EQ(screen_->IsReal(), true);
82 ASSERT_NE(screen_->GetScreenInfo(), nullptr);
83 }
84
85 /**
86 * @tc.name: SetScreenActiveMode01
87 * @tc.desc: SetScreenActiveMode with valid modeId and return success
88 * @tc.type: FUNC
89 */
90 HWTEST_F(ScreenTest, SetScreenActiveMode01, Function | SmallTest | Level1)
91 {
92 auto supportedModes = screen_->GetSupportedModes();
93 ASSERT_GT(supportedModes.size(), 0);
94 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
95 EXPECT_CALL(m->Mock(), SetScreenActiveMode(_, _)).Times(1).WillOnce(Return(true));
96 bool res = screen_->SetScreenActiveMode(supportedModes.size() - 1);
97 ASSERT_EQ(true, res);
98 }
99
100 /**
101 * @tc.name: SetScreenActiveMode02
102 * @tc.desc: SetScreenActiveMode with valid modeId and return failed
103 * @tc.type: FUNC
104 */
105 HWTEST_F(ScreenTest, SetScreenActiveMode02, Function | SmallTest | Level1)
106 {
107 auto supportedModes = screen_->GetSupportedModes();
108 ASSERT_GT(supportedModes.size(), 0);
109 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
110 EXPECT_CALL(m->Mock(), SetScreenActiveMode(_, _)).Times(1).WillOnce(Return(false));
111 bool res = screen_->SetScreenActiveMode(supportedModes.size() - 1);
112 ASSERT_EQ(false, res);
113 }
114
115 /**
116 * @tc.name: GetScreenSupportedColorGamuts01
117 * @tc.desc: GetScreenSupportedColorGamuts
118 * @tc.type: FUNC
119 */
120 HWTEST_F(ScreenTest, GetScreenSupportedColorGamuts01, Function | SmallTest | Level2)
121 {
122 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
123 EXPECT_CALL(m->Mock(), GetScreenSupportedColorGamuts(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
124 std::vector<ScreenColorGamut> colorGamuts;
125 auto res = screen_->GetScreenSupportedColorGamuts(colorGamuts);
126 ASSERT_EQ(DMError::DM_OK, res);
127 }
128
129 /**
130 * @tc.name: GetScreenColorGamut01
131 * @tc.desc: GetScreenColorGamut
132 * @tc.type: FUNC
133 */
134 HWTEST_F(ScreenTest, GetScreenColorGamut01, Function | SmallTest | Level2)
135 {
136 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
137 EXPECT_CALL(m->Mock(), GetScreenColorGamut(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
138 ScreenColorGamut colorGamut = ScreenColorGamut::COLOR_GAMUT_SRGB;
139 auto res = screen_->GetScreenColorGamut(colorGamut);
140 ASSERT_EQ(DMError::DM_OK, res);
141 }
142
143 /**
144 * @tc.name: SetScreenColorGamut01
145 * @tc.desc: SetScreenColorGamut
146 * @tc.type: FUNC
147 */
148 HWTEST_F(ScreenTest, SetScreenColorGamut01, Function | SmallTest | Level2)
149 {
150 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
151 EXPECT_CALL(m->Mock(), SetScreenColorGamut(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
152 ScreenColorGamut colorGamut = ScreenColorGamut::COLOR_GAMUT_SRGB;
153 auto res = screen_->SetScreenColorGamut(colorGamut);
154 ASSERT_EQ(DMError::DM_OK, res);
155 }
156
157 /**
158 * @tc.name: GetScreenGamutMap01
159 * @tc.desc: GetScreenGamutMap
160 * @tc.type: FUNC
161 */
162 HWTEST_F(ScreenTest, GetScreenGamutMap01, Function | SmallTest | Level2)
163 {
164 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
165 EXPECT_CALL(m->Mock(), GetScreenGamutMap(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
166 ScreenGamutMap gamutMap = ScreenGamutMap::GAMUT_MAP_CONSTANT;
167 auto res = screen_->GetScreenGamutMap(gamutMap);
168 ASSERT_EQ(DMError::DM_OK, res);
169 }
170
171 /**
172 * @tc.name: SetScreenGamutMap01
173 * @tc.desc: SetScreenGamutMap
174 * @tc.type: FUNC
175 */
176 HWTEST_F(ScreenTest, SetScreenGamutMap01, Function | SmallTest | Level2)
177 {
178 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
179 EXPECT_CALL(m->Mock(), SetScreenGamutMap(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
180 ScreenGamutMap gamutMap = ScreenGamutMap::GAMUT_MAP_CONSTANT;
181 auto res = screen_->SetScreenGamutMap(gamutMap);
182 ASSERT_EQ(DMError::DM_OK, res);
183 }
184
185 /**
186 * @tc.name: SetScreenColorTransform01
187 * @tc.desc: SetScreenColorTransform
188 * @tc.type: FUNC
189 */
190 HWTEST_F(ScreenTest, SetScreenColorTransform01, Function | SmallTest | Level2)
191 {
192 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
193 EXPECT_CALL(m->Mock(), SetScreenColorTransform(_)).Times(1).WillOnce(Return(DMError::DM_OK));
194 auto res = screen_->SetScreenColorTransform();
195 ASSERT_EQ(DMError::DM_OK, res);
196 }
197
198 /**
199 * @tc.name: IsGroup
200 * @tc.desc: for interface coverage and check IsGroup
201 * @tc.type: FUNC
202 */
203 HWTEST_F(ScreenTest, IsGroup, Function | SmallTest | Level2)
204 {
205 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
206 sptr<ScreenInfo> screenInfo = screen_->GetScreenInfo();
207 screenInfo->SetIsScreenGroup(true);
208 EXPECT_CALL(m->Mock(), GetScreenInfo(_)).Times(1).WillOnce(Return(screenInfo));
209 ASSERT_EQ(true, screen_->IsGroup());
210 screenInfo->SetIsScreenGroup(false);
211 EXPECT_CALL(m->Mock(), GetScreenInfo(_)).Times(1).WillOnce(Return(screenInfo));
212 ASSERT_EQ(false, screen_->IsGroup());
213 }
214
215 /**
216 * @tc.name: GetParentId
217 * @tc.desc: for interface coverage and check GetParentId
218 * @tc.type: FUNC
219 */
220 HWTEST_F(ScreenTest, GetParentId, Function | SmallTest | Level2)
221 {
222 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
223 sptr<ScreenInfo> screenInfo = screen_->GetScreenInfo();
224 screenInfo->SetParentId(0);
225 EXPECT_CALL(m->Mock(), GetScreenInfo(_)).Times(1).WillOnce(Return(screenInfo));
226 ASSERT_EQ(0, screen_->GetParentId());
227 screenInfo->SetParentId(SCREEN_ID_INVALID);
228 EXPECT_CALL(m->Mock(), GetScreenInfo(_)).Times(1).WillOnce(Return(screenInfo));
229 ASSERT_EQ(SCREEN_ID_INVALID, screen_->GetParentId());
230 }
231 }
232 } // namespace Rosen
233 } // namespace OHOS