1 /*
2 * Copyright (c) 2022-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_adapter.h"
18 #include "display_manager_proxy.h"
19
20 using namespace testing;
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace Rosen {
25 class DisplayManagerAdapterTest : public testing::Test {
26 public:
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29 void SetUp() override;
30 void TearDown() override;
31 };
32
SetUpTestCase()33 void DisplayManagerAdapterTest::SetUpTestCase()
34 {
35 }
36
TearDownTestCase()37 void DisplayManagerAdapterTest::TearDownTestCase()
38 {
39 }
40
SetUp()41 void DisplayManagerAdapterTest::SetUp()
42 {
43 }
44
TearDown()45 void DisplayManagerAdapterTest::TearDown()
46 {
47 }
48
49 namespace {
50 /**
51 * @tc.name: GetDisplayInfo
52 * @tc.desc: test nullptr
53 * @tc.type: FUNC
54 */
55 HWTEST_F(DisplayManagerAdapterTest, GetDisplayInfo, Function | SmallTest | Level2)
56 {
57 sptr<DisplayInfo> info = SingletonContainer::Get<DisplayManagerAdapter>().GetDisplayInfo(DISPLAY_ID_INVALID);
58 ASSERT_EQ(info, nullptr);
59 }
60
61 /**
62 * @tc.name: GetCutoutInfo
63 * @tc.desc: test nullptr
64 * @tc.type: FUNC
65 */
66 HWTEST_F(DisplayManagerAdapterTest, GetCutoutInfo, Function | SmallTest | Level2)
67 {
68 sptr<CutoutInfo> info = SingletonContainer::Get<DisplayManagerAdapter>().GetCutoutInfo(DISPLAY_ID_INVALID);
69 ASSERT_EQ(info, nullptr);
70 }
71
72 /**
73 * @tc.name: GetScreenSupportedColorGamuts
74 * @tc.desc: test success
75 * @tc.type: FUNC
76 */
77 HWTEST_F(DisplayManagerAdapterTest, GetScreenSupportedColorGamuts, Function | SmallTest | Level2)
78 {
79 std::vector<ScreenColorGamut> colorGamuts;
80 SingletonContainer::Get<ScreenManagerAdapter>().GetScreenSupportedColorGamuts(0, colorGamuts);
81 }
82
83 /**
84 * @tc.name: SetScreenColorGamut
85 * @tc.desc: test success
86 * @tc.type: FUNC
87 */
88 HWTEST_F(DisplayManagerAdapterTest, SetScreenColorGamut, Function | SmallTest | Level2)
89 {
90 std::vector<ScreenColorGamut> colorGamuts;
91 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().SetScreenColorGamut(0, -1);
92 ASSERT_EQ(err, DMError::DM_ERROR_RENDER_SERVICE_FAILED);
93 }
94
95 /**
96 * @tc.name: GetScreenColorGamut
97 * @tc.desc: test success
98 * @tc.type: FUNC
99 */
100 HWTEST_F(DisplayManagerAdapterTest, GetScreenColorGamut, Function | SmallTest | Level2)
101 {
102 ScreenColorGamut colorGamut;
103 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().GetScreenColorGamut(0, colorGamut);
104 ASSERT_EQ(err, DMError::DM_ERROR_RENDER_SERVICE_FAILED);
105 }
106
107 /**
108 * @tc.name: GetScreenGamutMap
109 * @tc.desc: test success
110 * @tc.type: FUNC
111 */
112 HWTEST_F(DisplayManagerAdapterTest, GetScreenGamutMap, Function | SmallTest | Level2)
113 {
114 ScreenGamutMap gamutMap;
115 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().GetScreenGamutMap(0, gamutMap);
116 ASSERT_EQ(err, DMError::DM_ERROR_RENDER_SERVICE_FAILED);
117 }
118
119 /**
120 * @tc.name: SetScreenGamutMap
121 * @tc.desc: test success
122 * @tc.type: FUNC
123 */
124 HWTEST_F(DisplayManagerAdapterTest, SetScreenGamutMap, Function | SmallTest | Level2)
125 {
126 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().SetScreenGamutMap(0, GAMUT_MAP_CONSTANT);
127 ASSERT_EQ(err, DMError::DM_ERROR_RENDER_SERVICE_FAILED);
128 }
129
130 /**
131 * @tc.name: SetScreenColorTransform
132 * @tc.desc: test success
133 * @tc.type: FUNC
134 */
135 HWTEST_F(DisplayManagerAdapterTest, SetScreenColorTransform, Function | SmallTest | Level2)
136 {
137 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().SetScreenColorTransform(0);
138 ASSERT_EQ(err, DMError::DM_OK);
139 }
140
141 /**
142 * @tc.name: SetFreeze
143 * @tc.desc: test success
144 * @tc.type: FUNC
145 */
146 HWTEST_F(DisplayManagerAdapterTest, SetFreeze, Function | SmallTest | Level2)
147 {
148 std::vector<DisplayId> displayIds;
149 bool ret = SingletonContainer::Get<DisplayManagerAdapter>().SetFreeze(displayIds, false);
150 ASSERT_TRUE(ret);
151 }
152
153 /**
154 * @tc.name: GetScreenGroupInfoById
155 * @tc.desc: test nullptr
156 * @tc.type: FUNC
157 */
158 HWTEST_F(DisplayManagerAdapterTest, GetScreenGroupInfoById, Function | SmallTest | Level2)
159 {
160 auto info = SingletonContainer::Get<ScreenManagerAdapter>().GetScreenGroupInfoById(SCREEN_ID_INVALID);
161 ASSERT_EQ(info, nullptr);
162 }
163
164 /**
165 * @tc.name: GetScreenInfo
166 * @tc.desc: test nullptr
167 * @tc.type: FUNC
168 */
169 HWTEST_F(DisplayManagerAdapterTest, GetScreenInfo, Function | SmallTest | Level2)
170 {
171 sptr<ScreenInfo> info = SingletonContainer::Get<ScreenManagerAdapter>().GetScreenInfo(SCREEN_ID_INVALID);
172 ASSERT_EQ(info, nullptr);
173 }
174
175 /**
176 * @tc.name: OnRemoteDied
177 * @tc.desc: test nullptr
178 * @tc.type: FUNC
179 */
180 HWTEST_F(DisplayManagerAdapterTest, OnRemoteDied, Function | SmallTest | Level2)
181 {
182 sptr<IRemoteObject::DeathRecipient> dmsDeath_ = nullptr;
183 dmsDeath_ = new(std::nothrow) DMSDeathRecipient(SingletonContainer::Get<ScreenManagerAdapter>());
184 dmsDeath_->OnRemoteDied(nullptr);
185 }
186
187 /**
188 * @tc.name: OnRemoteDied01
189 * @tc.desc: test nullptr
190 * @tc.type: FUNC
191 */
192 HWTEST_F(DisplayManagerAdapterTest, OnRemoteDied01, Function | SmallTest | Level2)
193 {
194 sptr<IRemoteObject::DeathRecipient> dmsDeath_ = nullptr;
195 dmsDeath_ = new(std::nothrow) DMSDeathRecipient(SingletonContainer::Get<ScreenManagerAdapter>());
196 SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
197 sptr<IRemoteObject> obj = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
198 wptr<IRemoteObject> wptrDeath = obj;
199 dmsDeath_->OnRemoteDied(wptrDeath);
200 }
201
202 /**
203 * @tc.name: Clear
204 * @tc.desc: test success
205 * @tc.type: FUNC
206 */
207 HWTEST_F(DisplayManagerAdapterTest, Clear, Function | SmallTest | Level2)
208 {
209 SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
210 SingletonContainer::Get<ScreenManagerAdapter>().Clear();
211 ASSERT_FALSE(SingletonContainer::Get<ScreenManagerAdapter>().isProxyValid_);
212 }
213
214 /**
215 * @tc.name: Clear01
216 * @tc.desc: test success
217 * @tc.type: FUNC
218 */
219 HWTEST_F(DisplayManagerAdapterTest, Clear01, Function | SmallTest | Level2)
220 {
221 SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
222 SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_ = nullptr;
223 SingletonContainer::Get<ScreenManagerAdapter>().Clear();
224 ASSERT_FALSE(SingletonContainer::Get<ScreenManagerAdapter>().isProxyValid_);
225 }
226 }
227 }
228 }