1 /*
2 * Copyright (C) 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 "wallpaper_manager_kits.h"
18 #include "wallpaper_manager.h"
19 #include "hilog_wrapper.h"
20 #include "directory_ex.h"
21
22 constexpr int SYSTYEM = 0;
23 constexpr int LOCKSCREEN = 1;
24 constexpr int HUNDRED = 100;
25 using namespace testing::ext;
26 using namespace OHOS::Media;
27 using namespace OHOS::HiviewDFX;
28
29 namespace OHOS {
30 namespace WallpaperMgrService {
31 class WallpaperTest : public testing::Test {
32 public:
33 static void SetUpTestCase(void);
34 static void TearDownTestCase(void);
35 void SetUp();
36 void TearDown();
37 };
38
39 const std::string VALID_SCHEMA_STRICT_DEFINE = "{\"SCHEMA_VERSION\":\"1.0\","
40 "\"SCHEMA_MODE\":\"STRICT\","
41 "\"SCHEMA_SKIPSIZE\":0,"
42 "\"SCHEMA_DEFINE\":{"
43 "\"age\":\"INTEGER, NOT NULL\""
44 "},"
45 "\"SCHEMA_INDEXES\":[\"$.age\"]}";
46
SetUpTestCase(void)47 void WallpaperTest::SetUpTestCase(void)
48 {
49 }
50
TearDownTestCase(void)51 void WallpaperTest::TearDownTestCase(void)
52 {
53 }
54
SetUp(void)55 void WallpaperTest::SetUp(void)
56 {
57 }
58
TearDown(void)59 void WallpaperTest::TearDown(void)
60 {
61 }
62
63 class WallpaperColorChangeListenerTestImpl : public OHOS::WallpaperMgrService::WallpaperColorChangeListener {
64 public:
65 std::vector<RgbaColor> color_;
66 int wallpaperType_;
67 WallpaperColorChangeListenerTestImpl();
~WallpaperColorChangeListenerTestImpl()68 ~WallpaperColorChangeListenerTestImpl()
69 {}
70
71 WallpaperColorChangeListenerTestImpl(const WallpaperColorChangeListenerTestImpl &) = delete;
72 WallpaperColorChangeListenerTestImpl &operator=(const WallpaperColorChangeListenerTestImpl &) = delete;
73 WallpaperColorChangeListenerTestImpl(WallpaperColorChangeListenerTestImpl &&) = delete;
74 WallpaperColorChangeListenerTestImpl &operator=(WallpaperColorChangeListenerTestImpl &&) = delete;
75
76 // callback function will be called when the db data is changed.
77 void onColorsChange(std::vector<RgbaColor> color, int wallpaperType);
78
79 // reset the callCount_ to zero.
80 void ResetToZero();
81
82 unsigned long GetCallCount() const;
83
84 private:
85 unsigned long callCount_;
86 };
87
onColorsChange(std::vector<RgbaColor> color,int wallpaperType)88 void WallpaperColorChangeListenerTestImpl::onColorsChange(std::vector<RgbaColor> color, int wallpaperType)
89 {
90 callCount_++;
91 for (auto const &each : color) {
92 color_.push_back(each);
93 }
94 wallpaperType_ = wallpaperType;
95 }
96
97
WallpaperColorChangeListenerTestImpl()98 WallpaperColorChangeListenerTestImpl::WallpaperColorChangeListenerTestImpl()
99 {
100 callCount_ = 0;
101 color_ = {};
102 wallpaperType_ = -1;
103 }
104
ResetToZero()105 void WallpaperColorChangeListenerTestImpl::ResetToZero()
106 {
107 callCount_ = 0;
108 }
109
GetCallCount() const110 unsigned long WallpaperColorChangeListenerTestImpl::GetCallCount() const
111 {
112 return callCount_;
113 }
114
115 /********************* ResetWallpaper *********************/
116 /**
117 * @tc.name: Reset001
118 * @tc.desc: Reset wallpaper with wallpaperType[0].
119 * @tc.type: FUNC
120 * @tc.require:
121 * @tc.author:
122 */
123 HWTEST_F(WallpaperTest, Reset001, TestSize.Level1)
124 {
125 int wallpaperType = 0;
126 EXPECT_EQ(OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
127 ResetWallpaper(wallpaperType), true) << "should reset successfully.";
128 }
129
130 /**
131 * @tc.name: Reset002
132 * @tc.desc: Reset wallpaper with wallpaperType[1].
133 * @tc.type: FUNC
134 * @tc.require:
135 * @tc.author:
136 */
137 HWTEST_F(WallpaperTest, Reset002, TestSize.Level1)
138 {
139 int wallpaperType = 1;
140 EXPECT_EQ(OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
141 ResetWallpaper(wallpaperType), true) << "should reset successfully.";
142 }
143
144 /**
145 * @tc.name: Reset003
146 * @tc.desc: Reset wallpaper with wallpaperType[2].
147 * @tc.type: FUNC
148 * @tc.require:
149 * @tc.author:
150 */
151 HWTEST_F(WallpaperTest, Reset003, TestSize.Level1)
152 {
153 int wallpaperType = 2;
154 EXPECT_NE(OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
155 ResetWallpaper(wallpaperType), true) << "shouldn't reset successfully.";
156 }
157
158 /**
159 * @tc.name: Reset004
160 * @tc.desc: Reset wallpaper with wallpaperType[0] after resetting wallpaper[0].
161 * @tc.type: FUNC
162 * @tc.require:
163 * @tc.author:
164 */
165 HWTEST_F(WallpaperTest, Reset004, TestSize.Level1)
166 {
167 int wallpaperType = 0;
168 EXPECT_EQ(OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
169 ResetWallpaper(wallpaperType), true) << "should reset successfully.";
170 /* duplicate reset */
171 EXPECT_EQ(OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
172 ResetWallpaper(wallpaperType), true) << "should reset successfully.";
173 }
174
175 /**
176 * @tc.name: Reset005
177 * @tc.desc: Reset wallpaper with wallpaperType[1] after resetting wallpaper[1] and check whether Id is same one.
178 * @tc.type: FUNC
179 * @tc.require:
180 * @tc.author:
181 */
182 HWTEST_F(WallpaperTest, Reset005, TestSize.Level1)
183 {
184 int wallpaperType = 1;
185 EXPECT_EQ(OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
186 ResetWallpaper(wallpaperType), true) << "should reset successfully.";
187 int firstId = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
188 GetWallpaperId(wallpaperType);
189 /* duplicate reset */
190 EXPECT_EQ(OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
191 ResetWallpaper(wallpaperType), true) << "should reset successfully.";
192 int secondId = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
193 GetWallpaperId(wallpaperType);
194 EXPECT_EQ(firstId, secondId) << "Id should be same one.";
195 }
196
197 /********************* ResetWallpaper *********************/
198
199 /********************* IsChangePermitted *********************/
200
201 /**
202 * @tc.name: IsChangePermitted001
203 * @tc.desc: check permission.
204 * @tc.type: FUNC
205 * @tc.require:
206 * @tc.author:
207 */
208 HWTEST_F(WallpaperTest, IsChangePermitted001, TestSize.Level1)
209 {
210 }
211
212 /********************* IsChangePermitted *********************/
213
214 /********************* IsOperationAllowed *********************/
215
216 /**
217 * @tc.name: IsOperationAllowed001
218 * @tc.desc: check permission.
219 * @tc.type: FUNC
220 * @tc.require:
221 * @tc.author:
222 */
223 HWTEST_F(WallpaperTest, IsOperationAllowed001, TestSize.Level1)
224 {
225 }
226
227 /********************* IsOperationAllowed *********************/
228
229 /********************* On & Off *********************/
230
231 /**
232 * @tc.name: On001
233 * @tc.desc: set wallpaper and get callback.
234 * @tc.type: FUNC
235 * @tc.require:
236 * @tc.author:
237 */
238 HWTEST_F(WallpaperTest, On001, TestSize.Level1)
239 {
240 auto listener = std::make_shared<WallpaperColorChangeListenerTestImpl>();
241 auto onStatus = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
242 On(listener);
243 EXPECT_EQ(onStatus, true) << "subscribe wallpaper color change failed.";
244
245 auto offSubStatus = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
246 Off(listener);
247 EXPECT_EQ(offSubStatus, true) << "unsubscribe wallpaper color change failed.";
248 }
249
250 /********************* On & Off *********************/
251
252
253 /********************* GetColors *********************/
254 /**
255 * @tc.name: GetColors001
256 * @tc.desc: GetColors with wallpaperType[0].
257 * @tc.type: FUNC
258 * @tc.require:
259 * @tc.author:
260 */
261 HWTEST_F(WallpaperTest, GetColors001, TestSize.Level0)
262 {
263 HILOG_INFO(" GetColors001 GetColors001 begin");
264
265 std::vector<RgbaColor> Color = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
266 GetColors(SYSTYEM);
267 bool result = Color.empty();
268 EXPECT_FALSE(result);
269 }
270
271 /**
272 * @tc.name: GetColors002
273 * @tc.desc: GetColors with wallpaperType[1].
274 * @tc.type: FUNC
275 * @tc.require:
276 * @tc.author:
277 */
278 HWTEST_F(WallpaperTest, GetColors002, TestSize.Level0)
279 {
280 HILOG_INFO(" GetColors002 GetColors001 begin");
281 std::vector<RgbaColor> Color = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
282 GetColors(LOCKSCREEN);
283 bool result = Color.empty();
284 EXPECT_FALSE(result);
285 }
286 /********************* GetColors *********************/
287
288 /********************* GetId *********************/
289 /**
290 * @tc.name: GetId001
291 * @tc.desc: GetId with wallpaperType[0].
292 * @tc.type: FUNC
293 * @tc.require:
294 * @tc.author:
295 */
296 HWTEST_F(WallpaperTest, GetId001, TestSize.Level0)
297 {
298 HILOG_INFO(" GetId001 GetId001 begin");
299 bool result = false;
300 int ida = HUNDRED;
301 ida = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
302 GetWallpaperId(SYSTYEM);
303 if (ida != HUNDRED) {
304 result = true;
305 }
306 EXPECT_TRUE(result);
307 }
308
309 /**
310 * @tc.name: GetId002
311 * @tc.desc: GetId with wallpaperType[1].
312 * @tc.type: FUNC
313 * @tc.require:
314 * @tc.author:
315 */
316 HWTEST_F(WallpaperTest, GetId002, TestSize.Level0)
317 {
318 HILOG_INFO(" GetId002 GetId002 begin");
319 bool result = false;
320 int ida = HUNDRED;
321 ida = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
322 GetWallpaperId(LOCKSCREEN);
323 if (ida != HUNDRED) {
324 result = true;
325 }
326 EXPECT_TRUE(result);
327 }
328 /********************* GetId *********************/
329
330 /********************* GetWallpaperMinHeight *********************/
331 /**
332 * @tc.name: getMinHeight001
333 * @tc.desc: GetWallpaperMinHeight .
334 * @tc.type: FUNC
335 * @tc.require:
336 * @tc.author:
337 */
338 HWTEST_F(WallpaperTest, getMinHeight001, TestSize.Level0)
339 {
340 HILOG_INFO(" WallpaperReset001 begin");
341 bool result = false;
342 int hight = 0;
343 hight = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
344 GetWallpaperMinHeight();
345 if (hight != 0) {
346 result = true;
347 }
348 EXPECT_TRUE(result);
349 }
350 /********************* GetWallpaperMinHeight *********************/
351
352 /********************* GetWallpaperMinWidth *********************/
353 /**
354 * @tc.name: getMinWidth001
355 * @tc.desc: GetWallpaperMinWidth .
356 * @tc.type: FUNC
357 * @tc.require:
358 * @tc.author:
359 */
360 HWTEST_F(WallpaperTest, getMinWidth001, TestSize.Level0)
361 {
362 HILOG_INFO(" getMinWidth001 begin");
363 bool result = false;
364 int width = 0;
365 width = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
366 GetWallpaperMinWidth();
367 if (width != 0) {
368 result = true;
369 }
370 EXPECT_TRUE(result);
371 }
372 /********************* GetWallpaperMinWidth *********************/
373
374 /********************* GetPiexlMap *********************/
375 /**
376 * @tc.name: GetPiexlMap001
377 * @tc.desc: GetPixelMap with wallpaperType[0] .
378 * @tc.type: FUNC
379 * @tc.require:
380 * @tc.author:
381 */
382 HWTEST_F(WallpaperTest, GetPiexlMap001, TestSize.Level0)
383 {
384 HILOG_INFO(" SetWallpaper&GetPiexlMap001 begin");
385 auto PixelMap = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
386 GetPixelMap(SYSTYEM);
387 EXPECT_TRUE(PixelMap);
388 }
389
390 /**
391 * @tc.name: GetPiexlMap002
392 * @tc.desc: GetPixelMap with wallpaperType[1].
393 * @tc.type: FUNC
394 * @tc.require:
395 * @tc.author:
396 */
397 HWTEST_F(WallpaperTest, GetPiexlMap002, TestSize.Level0)
398 {
399 HILOG_INFO(" SetWallpaper&GetPiexlMap002 begin");
400 auto PixelMap = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
401 GetPixelMap(LOCKSCREEN);
402 EXPECT_TRUE(PixelMap);
403 }
404 /********************* GetPiexlMap *********************/
405 } // wallpaperservice
406 } // OHOS