• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "display_manager.h"
18 #include "display_manager_proxy.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_->IsReal(), true);
81     ASSERT_NE(screen_->GetScreenInfo(), nullptr);
82 }
83 
84 /**
85  * @tc.name: SetScreenActiveMode01
86  * @tc.desc: SetScreenActiveMode with valid modeId and return success
87  * @tc.type: FUNC
88  */
89 HWTEST_F(ScreenTest, SetScreenActiveMode01, Function | SmallTest | Level1)
90 {
91     auto supportedModes = screen_->GetSupportedModes();
92     ASSERT_GT(supportedModes.size(), 0);
93     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
94     EXPECT_CALL(m->Mock(), SetScreenActiveMode(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
95     DMError res = screen_->SetScreenActiveMode(supportedModes.size() - 1);
96     ASSERT_EQ(DMError::DM_OK, res);
97 }
98 
99 /**
100  * @tc.name: SetScreenActiveMode02
101  * @tc.desc: SetScreenActiveMode with valid modeId and return failed
102  * @tc.type: FUNC
103  */
104 HWTEST_F(ScreenTest, SetScreenActiveMode02, Function | SmallTest | Level1)
105 {
106     auto supportedModes = screen_->GetSupportedModes();
107     ASSERT_GT(supportedModes.size(), 0);
108     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
109     EXPECT_CALL(m->Mock(), SetScreenActiveMode(_, _)).Times(1).WillOnce(Return(DMError::DM_ERROR_NULLPTR));
110     DMError res = screen_->SetScreenActiveMode(supportedModes.size() - 1);
111     ASSERT_TRUE(DMError::DM_OK != res);
112 }
113 
114 /**
115  * @tc.name: GetScreenSupportedColorGamuts01
116  * @tc.desc: GetScreenSupportedColorGamuts
117  * @tc.type: FUNC
118  */
119 HWTEST_F(ScreenTest, GetScreenSupportedColorGamuts01, Function | SmallTest | Level2)
120 {
121     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
122     EXPECT_CALL(m->Mock(), GetScreenSupportedColorGamuts(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
123     std::vector<ScreenColorGamut> colorGamuts;
124     auto res = screen_->GetScreenSupportedColorGamuts(colorGamuts);
125     ASSERT_EQ(DMError::DM_OK, res);
126 }
127 
128 /**
129  * @tc.name: GetScreenColorGamut01
130  * @tc.desc: GetScreenColorGamut
131  * @tc.type: FUNC
132  */
133 HWTEST_F(ScreenTest, GetScreenColorGamut01, Function | SmallTest | Level2)
134 {
135     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
136     EXPECT_CALL(m->Mock(), GetScreenColorGamut(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
137     ScreenColorGamut colorGamut = ScreenColorGamut::COLOR_GAMUT_SRGB;
138     auto res = screen_->GetScreenColorGamut(colorGamut);
139     ASSERT_EQ(DMError::DM_OK, res);
140 }
141 
142 /**
143  * @tc.name: SetScreenColorGamut01
144  * @tc.desc: SetScreenColorGamut
145  * @tc.type: FUNC
146  */
147 HWTEST_F(ScreenTest, SetScreenColorGamut01, Function | SmallTest | Level2)
148 {
149     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
150     EXPECT_CALL(m->Mock(), SetScreenColorGamut(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
151     ScreenColorGamut colorGamut = ScreenColorGamut::COLOR_GAMUT_SRGB;
152     auto res = screen_->SetScreenColorGamut(colorGamut);
153     ASSERT_EQ(DMError::DM_OK, res);
154 }
155 
156 /**
157  * @tc.name: GetScreenGamutMap01
158  * @tc.desc: GetScreenGamutMap
159  * @tc.type: FUNC
160  */
161 HWTEST_F(ScreenTest, GetScreenGamutMap01, Function | SmallTest | Level2)
162 {
163     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
164     EXPECT_CALL(m->Mock(), GetScreenGamutMap(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
165     ScreenGamutMap gamutMap = ScreenGamutMap::GAMUT_MAP_CONSTANT;
166     auto res = screen_->GetScreenGamutMap(gamutMap);
167     ASSERT_EQ(DMError::DM_OK, res);
168 }
169 
170 /**
171  * @tc.name: SetScreenGamutMap01
172  * @tc.desc: SetScreenGamutMap
173  * @tc.type: FUNC
174  */
175 HWTEST_F(ScreenTest, SetScreenGamutMap01, Function | SmallTest | Level2)
176 {
177     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
178     EXPECT_CALL(m->Mock(), SetScreenGamutMap(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
179     ScreenGamutMap gamutMap = ScreenGamutMap::GAMUT_MAP_CONSTANT;
180     auto res = screen_->SetScreenGamutMap(gamutMap);
181     ASSERT_EQ(DMError::DM_OK, res);
182 }
183 
184 /**
185  * @tc.name: SetScreenColorTransform01
186  * @tc.desc: SetScreenColorTransform
187  * @tc.type: FUNC
188  */
189 HWTEST_F(ScreenTest, SetScreenColorTransform01, Function | SmallTest | Level2)
190 {
191     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
192     EXPECT_CALL(m->Mock(), SetScreenColorTransform(_)).Times(1).WillOnce(Return(DMError::DM_OK));
193     auto res = screen_->SetScreenColorTransform();
194     ASSERT_EQ(DMError::DM_OK, res);
195 }
196 
197 /**
198  * @tc.name: IsGroup
199  * @tc.desc: for interface coverage and check IsGroup
200  * @tc.type: FUNC
201  */
202 HWTEST_F(ScreenTest, IsGroup, Function | SmallTest | Level2)
203 {
204     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
205     sptr<ScreenInfo> screenInfo = screen_->GetScreenInfo();
206     screenInfo->SetIsScreenGroup(true);
207     EXPECT_CALL(m->Mock(), GetScreenInfo(_)).Times(1).WillOnce(Return(screenInfo));
208     ASSERT_EQ(true, screen_->IsGroup());
209     screenInfo->SetIsScreenGroup(false);
210     EXPECT_CALL(m->Mock(), GetScreenInfo(_)).Times(1).WillOnce(Return(screenInfo));
211     ASSERT_EQ(false, screen_->IsGroup());
212 }
213 
214 /**
215  * @tc.name: GetParentId
216  * @tc.desc: for interface coverage and check GetParentId
217  * @tc.type: FUNC
218  */
219 HWTEST_F(ScreenTest, GetParentId, Function | SmallTest | Level2)
220 {
221     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
222     sptr<ScreenInfo> screenInfo = screen_->GetScreenInfo();
223     screenInfo->SetParentId(0);
224     EXPECT_CALL(m->Mock(), GetScreenInfo(_)).Times(1).WillOnce(Return(screenInfo));
225     ASSERT_EQ(0, screen_->GetParentId());
226     screenInfo->SetParentId(SCREEN_ID_INVALID);
227     EXPECT_CALL(m->Mock(), GetScreenInfo(_)).Times(1).WillOnce(Return(screenInfo));
228     ASSERT_EQ(SCREEN_ID_INVALID, screen_->GetParentId());
229 }
230 }
231 } // namespace Rosen
232 } // namespace OHOS