• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <ctime>
17 #include <gtest/gtest.h>
18 
19 #include "accesstoken_kit.h"
20 #include "directory_ex.h"
21 #include "file_deal.h"
22 #include "hilog_wrapper.h"
23 #include "image_packer.h"
24 #include "nativetoken_kit.h"
25 #include "pixel_map.h"
26 #include "token_setproc.h"
27 #include "wallpaper_manager.h"
28 #include "wallpaper_manager_kits.h"
29 #include "wallpaper_service.h"
30 
31 constexpr int SYSTYEM = 0;
32 constexpr int LOCKSCREEN = 1;
33 constexpr int HUNDRED = 100;
34 constexpr int32_t FOO_MAX_LEN = 60000000;
35 using namespace testing::ext;
36 using namespace testing;
37 using namespace OHOS::Media;
38 using namespace OHOS::HiviewDFX;
39 using namespace OHOS::MiscServices;
40 using namespace OHOS::Security::AccessToken;
41 
42 namespace OHOS {
43 namespace WallpaperMgrService {
44 constexpr const char *URL = "/data/test/theme/wallpaper/wallpaper_test.JPG";
GrantNativePermission()45 void GrantNativePermission()
46 {
47     const char **perms = new const char *[2];
48     perms[0] = "ohos.permission.GET_WALLPAPER";
49     perms[1] = "ohos.permission.SET_WALLPAPER";
50     TokenInfoParams infoInstance = {
51         .dcapsNum = 0,
52         .permsNum = 2,
53         .aclsNum = 0,
54         .dcaps = nullptr,
55         .perms = perms,
56         .acls = nullptr,
57         .processName = "wallpaper_service",
58         .aplStr = "system_core",
59     };
60     uint64_t tokenId = GetAccessTokenId(&infoInstance);
61     int res = SetSelfTokenID(tokenId);
62     if (res == 0) {
63         HILOG_INFO("SetSelfTokenID success!");
64     } else {
65         HILOG_ERROR("SetSelfTokenID fail!");
66     }
67     AccessTokenKit::ReloadNativeTokenInfo();
68     delete[] perms;
69 }
70 
71 class WallpaperTest : public testing::Test {
72 public:
73     static void SetUpTestCase(void);
74     static void TearDownTestCase(void);
75     void SetUp();
76     void TearDown();
77     static void CreateTempImage();
78     static std::shared_ptr<PixelMap> CreateTempPixelMap();
79 };
80 const std::string VALID_SCHEMA_STRICT_DEFINE = "{\"SCHEMA_VERSION\":\"1.0\","
81                                                "\"SCHEMA_MODE\":\"STRICT\","
82                                                "\"SCHEMA_SKIPSIZE\":0,"
83                                                "\"SCHEMA_DEFINE\":{"
84                                                "\"age\":\"INTEGER, NOT NULL\""
85                                                "},"
86                                                "\"SCHEMA_INDEXES\":[\"$.age\"]}";
87 
SetUpTestCase(void)88 void WallpaperTest::SetUpTestCase(void)
89 {
90     HILOG_INFO("SetUpTestCase");
91     GrantNativePermission();
92     CreateTempImage();
93     HILOG_INFO("SetUpTestCase end");
94 }
95 
TearDownTestCase(void)96 void WallpaperTest::TearDownTestCase(void)
97 {
98     HILOG_INFO("TearDownTestCase");
99     OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().ResetWallpaper(0);
100     OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().ResetWallpaper(1);
101 }
102 
SetUp(void)103 void WallpaperTest::SetUp(void)
104 {
105 }
106 
TearDown(void)107 void WallpaperTest::TearDown(void)
108 {
109 }
110 
111 class WallpaperColorChangeListenerTestImpl : public OHOS::WallpaperMgrService::WallpaperColorChangeListener {
112 public:
113     std::vector<uint64_t> color_;
114     int wallpaperType_;
115     WallpaperColorChangeListenerTestImpl();
~WallpaperColorChangeListenerTestImpl()116     ~WallpaperColorChangeListenerTestImpl()
117     {
118     }
119 
120     WallpaperColorChangeListenerTestImpl(const WallpaperColorChangeListenerTestImpl &) = delete;
121     WallpaperColorChangeListenerTestImpl &operator=(const WallpaperColorChangeListenerTestImpl &) = delete;
122     WallpaperColorChangeListenerTestImpl(WallpaperColorChangeListenerTestImpl &&) = delete;
123     WallpaperColorChangeListenerTestImpl &operator=(WallpaperColorChangeListenerTestImpl &&) = delete;
124 
125     // callback function will be called when the db data is changed.
126     void OnColorsChange(const std::vector<uint64_t> &color, int wallpaperType);
127 
128     // reset the callCount_ to zero.
129     void ResetToZero();
130 
131     unsigned long GetCallCount() const;
132 
133 private:
134     unsigned long callCount_;
135 };
136 
OnColorsChange(const std::vector<uint64_t> & color,int wallpaperType)137 void WallpaperColorChangeListenerTestImpl::OnColorsChange(const std::vector<uint64_t> &color, int wallpaperType)
138 {
139     callCount_++;
140     for (auto const &each : color) {
141         color_.push_back(each);
142     }
143     wallpaperType_ = wallpaperType;
144 }
145 
WallpaperColorChangeListenerTestImpl()146 WallpaperColorChangeListenerTestImpl::WallpaperColorChangeListenerTestImpl()
147 {
148     callCount_ = 0;
149     wallpaperType_ = -1;
150 }
151 
ResetToZero()152 void WallpaperColorChangeListenerTestImpl::ResetToZero()
153 {
154     callCount_ = 0;
155 }
156 
GetCallCount() const157 unsigned long WallpaperColorChangeListenerTestImpl::GetCallCount() const
158 {
159     return callCount_;
160 }
161 
CreateTempImage()162 void WallpaperTest::CreateTempImage()
163 {
164     std::shared_ptr<PixelMap> pixelMap = CreateTempPixelMap();
165     ImagePacker imagePacker;
166     PackOption option;
167     option.format = "image/jpeg";
168     option.quality = HUNDRED;
169     option.numberHint = 1;
170     std::set<std::string> formats;
171     imagePacker.GetSupportedFormats(formats);
172     imagePacker.StartPacking(URL, option);
173     HILOG_INFO("AddImage start");
174     imagePacker.AddImage(*pixelMap);
175     int64_t packedSize = 0;
176     HILOG_INFO("FinalizePacking start");
177     imagePacker.FinalizePacking(packedSize);
178     if (packedSize == 0) {
179         HILOG_INFO("FinalizePacking error");
180     }
181 }
182 
CreateTempPixelMap()183 std::shared_ptr<PixelMap> WallpaperTest::CreateTempPixelMap()
184 {
185     uint32_t color[100] = { 3, 7, 9, 9, 7, 6 };
186     InitializationOptions opts = { { 5, 7 }, OHOS::Media::PixelFormat::ARGB_8888 };
187     std::unique_ptr<PixelMap> uniquePixelMap = PixelMap::Create(color, sizeof(color) / sizeof(color[0]), opts);
188     std::shared_ptr<PixelMap> pixelMap = std::move(uniquePixelMap);
189     return pixelMap;
190 }
191 
192 /*********************   ResetWallpaper   *********************/
193 /**
194 * @tc.name:    Reset001
195 * @tc.desc:    Reset wallpaper with wallpaperType[0].
196 * @tc.type:    FUNC
197 * @tc.require: issueI5UHRG
198 * @tc.author:  lvbai
199 */
200 HWTEST_F(WallpaperTest, Reset001, TestSize.Level1)
201 {
202     HILOG_INFO("Reset001.");
203     int wallpaperType = 0;
204     EXPECT_EQ(OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().ResetWallpaper(wallpaperType),
205         static_cast<int32_t>(E_OK)) << "Failed to reset.";
206 }
207 
208 /**
209 * @tc.name:    Reset002
210 * @tc.desc:    Reset wallpaper with wallpaperType[1].
211 * @tc.type:    FUNC
212 * @tc.require: issueI5UHRG
213 * @tc.author:  lvbai
214 */
215 HWTEST_F(WallpaperTest, Reset002, TestSize.Level1)
216 {
217     int wallpaperType = 1;
218     EXPECT_EQ(OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().ResetWallpaper(wallpaperType),
219         static_cast<int32_t>(E_OK)) << "Failed to reset.";
220 }
221 
222 /**
223 * @tc.name:    Reset003
224 * @tc.desc:    Reset wallpaper with wallpaperType[2] throw parameters error.
225 * @tc.type:    FUNC
226 * @tc.require: issueI5UHRG
227 * @tc.author:  lvbai
228 */
229 HWTEST_F(WallpaperTest, Reset003, TestSize.Level1)
230 {
231     int wallpaperType = 2;
232     EXPECT_EQ(OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().ResetWallpaper(wallpaperType),
233         static_cast<int32_t>(E_PARAMETERS_INVALID)) << "Failed to reset .";
234 }
235 
236 /**
237 * @tc.name:    Reset004
238 * @tc.desc:    Reset wallpaper with wallpaperType[0] after resetting wallpaper[0].
239 * @tc.type:    FUNC
240 * @tc.require: issueI5UHRG
241 * @tc.author:  lvbai
242 */
243 HWTEST_F(WallpaperTest, Reset004, TestSize.Level1)
244 {
245     int wallpaperType = 0;
246     EXPECT_EQ(OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().ResetWallpaper(wallpaperType),
247         static_cast<int32_t>(E_OK)) << "Failed to  reset.";
248     /* duplicate reset */
249     EXPECT_EQ(OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().ResetWallpaper(wallpaperType),
250         static_cast<int32_t>(E_OK)) << "Failed to  reset.";
251 }
252 
253 /**
254 * @tc.name:    Reset005
255 * @tc.desc:    Reset wallpaper with wallpaperType[1] after resetting wallpaper[1] and check whether Id is same one.
256 * @tc.type:    FUNC
257 * @tc.require: issueI5UHRG
258 * @tc.author:  lvbai
259 */
260 HWTEST_F(WallpaperTest, Reset005, TestSize.Level1)
261 {
262     int wallpaperType = 1;
263     EXPECT_EQ(OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().ResetWallpaper(wallpaperType),
264         static_cast<int32_t>(E_OK)) << "Failed to reset.";
265     int firstId = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().GetWallpaperId(wallpaperType);
266     /* duplicate reset */
267     EXPECT_EQ(OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().ResetWallpaper(wallpaperType),
268         static_cast<int32_t>(E_OK)) << "Failed to  reset.";
269     int secondId = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().GetWallpaperId(wallpaperType);
270     EXPECT_EQ(firstId, secondId) << "Id should be same one.";
271 }
272 /*********************   ResetWallpaper   *********************/
273 
274 /*********************   IsChangePermitted   *********************/
275 
276 /**
277 * @tc.name: IsChangePermitted001
278 * @tc.desc: check permission.
279 * @tc.type: FUNC
280 * @tc.require:
281 * @tc.author:
282 */
283 HWTEST_F(WallpaperTest, IsChangePermitted001, TestSize.Level1)
284 {
285     bool ret = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().IsChangePermitted();
286     EXPECT_EQ(ret, true);
287 }
288 
289 /*********************   IsChangePermitted   *********************/
290 
291 /*********************   IsOperationAllowed   *********************/
292 
293 /**
294 * @tc.name: IsOperationAllowed001
295 * @tc.desc: check permission.
296 * @tc.type: FUNC
297 * @tc.require:
298 * @tc.author:
299 */
300 HWTEST_F(WallpaperTest, IsOperationAllowed001, TestSize.Level1)
301 {
302     bool ret = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().IsOperationAllowed();
303     EXPECT_EQ(ret, true);
304 }
305 
306 /*********************   IsOperationAllowed   *********************/
307 
308 /*********************   On & Off   *********************/
309 
310 /**
311 * @tc.name: On001
312 * @tc.desc: set wallpaper and get callback.
313 * @tc.type: FUNC
314 * @tc.require:
315 * @tc.author:
316 */
317 HWTEST_F(WallpaperTest, On001, TestSize.Level1)
318 {
319     HILOG_INFO("On001 begin");
320     auto listener = std::make_shared<WallpaperColorChangeListenerTestImpl>();
321     OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().On("colorChange", listener);
322 
323     auto offSubStatus = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().Off("colorChange", listener);
324     EXPECT_EQ(offSubStatus, true) << "unsubscribe wallpaper color change.";
325 }
326 
327 /*********************   On & Off   *********************/
328 
329 /*********************   GetColors   *********************/
330 /**
331 * @tc.name: GetColors001
332 * @tc.desc: GetColors with wallpaperType[0].
333 * @tc.type: FUNC
334 * @tc.require:
335 * @tc.author:
336 */
337 HWTEST_F(WallpaperTest, GetColors001, TestSize.Level0)
338 {
339     HILOG_INFO("GetColors001 begin");
340 
341     std::vector<uint64_t> color = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().GetColors(SYSTYEM);
342     bool result = color.empty();
343     EXPECT_FALSE(result);
344 }
345 
346 /**
347 * @tc.name: GetColors002
348 * @tc.desc: GetColors with wallpaperType[1].
349 * @tc.type: FUNC
350 * @tc.require:
351 * @tc.author:
352 */
353 HWTEST_F(WallpaperTest, GetColors002, TestSize.Level0)
354 {
355     HILOG_INFO("GetColors002 begin");
356     std::vector<uint64_t> color = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().GetColors(LOCKSCREEN);
357     bool result = color.empty();
358     EXPECT_FALSE(result);
359 }
360 /*********************   GetColors   *********************/
361 
362 /*********************   GetId   *********************/
363 /**
364 * @tc.name: GetId001
365 * @tc.desc: GetId with wallpaperType[0].
366 * @tc.type: FUNC
367 * @tc.require:
368 * @tc.author:
369 */
370 HWTEST_F(WallpaperTest, GetId001, TestSize.Level0)
371 {
372     HILOG_INFO("GetId001 begin");
373     bool result = false;
374     int ida = HUNDRED;
375     ida = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().GetWallpaperId(SYSTYEM);
376     if (ida != HUNDRED) {
377         result = true;
378     }
379     EXPECT_TRUE(result);
380 }
381 
382 /**
383 * @tc.name: GetId002
384 * @tc.desc: GetId with wallpaperType[1].
385 * @tc.type: FUNC
386 * @tc.require:
387 * @tc.author:
388 */
389 HWTEST_F(WallpaperTest, GetId002, TestSize.Level0)
390 {
391     HILOG_INFO("GetId002 begin");
392     bool result = false;
393     int ida = HUNDRED;
394     ida = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().GetWallpaperId(LOCKSCREEN);
395     if (ida != HUNDRED) {
396         result = true;
397     }
398     EXPECT_TRUE(result);
399 }
400 /*********************   GetId   *********************/
401 
402 /*********************   GetFile   *********************/
403 /**
404 * @tc.name:    GetFile001
405 * @tc.desc:    GetFile with wallpaperType[0].
406 * @tc.type:    FUNC
407 * @tc.require: issueI5UHRG
408 * @tc.author:  lvbai
409 */
410 HWTEST_F(WallpaperTest, GetFile001, TestSize.Level0)
411 {
412     HILOG_INFO("GetFile001 begin");
413     int32_t wallpaperFd = 0;
414     int wallpaperErrorCode =
415         OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().GetFile(SYSTYEM, wallpaperFd);
416     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_OK)) << "Failed to get File.";
417 }
418 
419 /**
420 * @tc.name:    GetFile002
421 * @tc.desc:    GetFile with wallpaperType[1].
422 * @tc.type:    FUNC
423 * @tc.require: issueI5UHRG
424 * @tc.author:  lvbai
425 */
426 HWTEST_F(WallpaperTest, GetFile002, TestSize.Level0)
427 {
428     HILOG_INFO("GetFile002 begin");
429     int32_t wallpaperFd = 0;
430     int wallpaperErrorCode =
431         OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().GetFile(LOCKSCREEN, wallpaperFd);
432     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_OK)) << "Failed to get File.";
433 }
434 
435 /**
436 * @tc.name:    GetFile003
437 * @tc.desc:    GetFile with wallpaperType[2] throw parameters error.
438 * @tc.type:    FUNC
439 * @tc.require: issueI5UHRG
440 * @tc.author:  lvbai
441 */
442 HWTEST_F(WallpaperTest, GetFile003, TestSize.Level0)
443 {
444     HILOG_INFO("GetFile003 begin");
445     int32_t wallpaperFd = 0;
446     int wallpaperErrorCode = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().GetFile(2, wallpaperFd);
447     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_PARAMETERS_INVALID)) << "Failed to throw parameters error";
448 }
449 
450 /**
451 * @tc.name:    GetFile004
452 * @tc.desc:    GetFile with wallpaperType[0].
453 * @tc.type:    FUNC
454 * @tc.require:
455 * @tc.author:
456 */
457 HWTEST_F(WallpaperTest, GetFile004, TestSize.Level0)
458 {
459     HILOG_INFO("GetFile001 begin");
460     int32_t wallpaperFd = 0;
461     int wallpaperErrorCode =
462         OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().GetFile(SYSTYEM, wallpaperFd);
463     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_OK)) << "Failed to get File.";
464 }
465 /*********************   GetFile   *********************/
466 
467 /*********************   GetWallpaperMinHeight   *********************/
468 /**
469 * @tc.name: getMinHeight001
470 * @tc.desc: GetWallpaperMinHeight .
471 * @tc.type: FUNC
472 * @tc.require:
473 * @tc.author:
474 */
475 HWTEST_F(WallpaperTest, getMinHeight001, TestSize.Level0)
476 {
477     HILOG_INFO("WallpaperReset001  begin");
478     bool result = false;
479     int hight = 0;
480     hight = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().GetWallpaperMinHeight();
481     if (hight != 0) {
482         result = true;
483     }
484     EXPECT_TRUE(result);
485 }
486 /*********************   GetWallpaperMinHeight   *********************/
487 
488 /*********************   GetWallpaperMinWidth   *********************/
489 /**
490 * @tc.name: getMinWidth001
491 * @tc.desc: GetWallpaperMinWidth .
492 * @tc.type: FUNC
493 * @tc.require:
494 * @tc.author:
495 */
496 HWTEST_F(WallpaperTest, getMinWidth001, TestSize.Level0)
497 {
498     HILOG_INFO("getMinWidth001  begin");
499     bool result = false;
500     int width = 0;
501     width = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().GetWallpaperMinWidth();
502     if (width != 0) {
503         result = true;
504     }
505     EXPECT_TRUE(result);
506 }
507 /*********************   GetWallpaperMinWidth   *********************/
508 
509 /*********************   GetPiexlMap   *********************/
510 /**
511 * @tc.name:    GetPiexlMap001
512 * @tc.desc:    GetPixelMap with wallpaperType[0].
513 * @tc.type:    FUNC
514 * @tc.require: issueI5UHRG
515 * @tc.author:  lvbai
516 */
517 HWTEST_F(WallpaperTest, GetPiexlMap001, TestSize.Level0)
518 {
519     HILOG_INFO("GetPiexlMap001  begin");
520     std::shared_ptr<OHOS::Media::PixelMap> pixelMap;
521     int32_t wallpaperErrorCode =
522         OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().GetPixelMap(SYSTYEM, pixelMap);
523     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_OK)) << "get SYSTYEM PiexlMap success.";
524     ASSERT_NE(pixelMap, nullptr) << "get LOCKSCREEN PiexlMap ptr nullptr.";
525 }
526 
527 /**
528 * @tc.name:    GetPiexlMap002
529 * @tc.desc:    GetPixelMap with wallpaperType[1].
530 * @tc.type:    FUNC
531 * @tc.require: issueI5UHRG
532 * @tc.author:  lvbai
533 */
534 HWTEST_F(WallpaperTest, GetPiexlMap002, TestSize.Level0)
535 {
536     HILOG_INFO("GetPiexlMap002  begin");
537     std::shared_ptr<OHOS::Media::PixelMap> pixelMap;
538     int32_t wallpaperErrorCode =
539         OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().GetPixelMap(LOCKSCREEN, pixelMap);
540     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_OK)) << "get LOCKSCREEN PiexlMap success.";
541     ASSERT_NE(pixelMap, nullptr) << "get LOCKSCREEN PiexlMap ptr nullptr.";
542 }
543 
544 /**
545 * @tc.name:    GetPiexlMap003
546 * @tc.desc:    GetPixelMap with wallpaperType[2] throw parameters error.
547 * @tc.type:    FUNC
548 * @tc.require: issueI5UHRG
549 * @tc.author:  lvbai
550 */
551 HWTEST_F(WallpaperTest, GetPiexlMap003, TestSize.Level0)
552 {
553     HILOG_INFO("GetPiexlMap003  begin");
554     std::shared_ptr<OHOS::Media::PixelMap> pixelMap;
555     int32_t wallpaperErrorCode =
556         OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().GetPixelMap(2, pixelMap);
557     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_PARAMETERS_INVALID)) << "Failed to throw parameters error";
558 }
559 /*********************   GetPiexlMap   *********************/
560 
561 /*********************   SetWallpaperByMap   *********************/
562 /**
563 * @tc.name:    SetWallpaperByMap001
564 * @tc.desc:    SetWallpaperByMap with wallpaperType[0].
565 * @tc.type:    FUNC
566 * @tc.require: issueI5UHRG
567 * @tc.author:  lvbai
568 */
569 HWTEST_F(WallpaperTest, SetWallpaperByMap001, TestSize.Level0)
570 {
571     HILOG_INFO("SetWallpaperByMap001  begin");
572     std::shared_ptr<PixelMap> pixelMap = WallpaperTest::CreateTempPixelMap();
573     int32_t wallpaperErrorCode =
574         OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().SetWallpaper(pixelMap, SYSTYEM);
575     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_OK)) << "Failed to set SYSTYEM PiexlMap.";
576 }
577 
578 /**
579 * @tc.name:    SetWallpaperByMap002
580 * @tc.desc:    SetWallpaperByMap with wallpaperType[1].
581 * @tc.type:    FUNC
582 * @tc.require: issueI5UHRG
583 * @tc.author:  lvbai
584 */
585 HWTEST_F(WallpaperTest, SetWallpaperByMap002, TestSize.Level0)
586 {
587     HILOG_INFO("SetWallpaperByMap002  begin");
588     std::shared_ptr<PixelMap> pixelMap = WallpaperTest::CreateTempPixelMap();
589     int32_t wallpaperErrorCode =
590         OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().SetWallpaper(pixelMap, LOCKSCREEN);
591     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_OK)) << "Failed to set LOCKSCREEN PiexlMap.";
592 }
593 
594 /**
595 * @tc.name:    SetWallpaperByMap003
596 * @tc.desc:    SetWallpaperByMap with wallpaperType[2] throw parameters error.
597 * @tc.type:    FUNC
598 * @tc.require: issueI5UHRG
599 * @tc.author:  lvbai
600 */
601 HWTEST_F(WallpaperTest, SetWallpaperByMap003, TestSize.Level0)
602 {
603     HILOG_INFO("SetWallpaperByMap003  begin");
604     std::shared_ptr<PixelMap> pixelMap = WallpaperTest::CreateTempPixelMap();
605     int32_t wallpaperErrorCode =
606         OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().SetWallpaper(pixelMap, 2);
607     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_PARAMETERS_INVALID)) << "Failed to throw parameters error";
608 }
609 /*********************   SetWallpaperByMap   *********************/
610 
611 /*********************   SetWallpaperByUrl   *********************/
612 /**
613 * @tc.name:    SetWallpaperByUrl001
614 * @tc.desc:    SetWallpaperByUrl with wallpaperType[0] .
615 * @tc.type:    FUNC
616 * @tc.require: issueI5UHRG
617 * @tc.author:  lvbai
618 */
619 HWTEST_F(WallpaperTest, SetWallpaperByUrl001, TestSize.Level0)
620 {
621     HILOG_INFO("SetWallpaperByUrl001  begin");
622     int32_t wallpaperErrorCode =
623         OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().SetWallpaper(URL, SYSTYEM);
624     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_OK)) << "Failed to set SYSTYEM.";
625 }
626 
627 /**
628 * @tc.name:    SetWallpaperByUrl002
629 * @tc.desc:    SetWallpaperByUrl with wallpaperType[1].
630 * @tc.type:    FUNC
631 * @tc.require: issueI5UHRG
632 * @tc.author:  lvbai
633 */
634 HWTEST_F(WallpaperTest, SetWallpaperByUrl002, TestSize.Level0)
635 {
636     HILOG_INFO("SetWallpaperByUrl002  begin");
637     int32_t wallpaperErrorCode =
638         OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().SetWallpaper(URL, LOCKSCREEN);
639     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_OK)) << "Failed to set LOCKSCREEN.";
640 }
641 
642 /**
643 * @tc.name:    SetWallpaperByUrl003
644 * @tc.desc:    SetWallpaperByUrl with wallpaperType[2] throw parameters error.
645 * @tc.type:    FUNC
646 * @tc.require: issueI5UHRG
647 * @tc.author:  lvbai
648 */
649 HWTEST_F(WallpaperTest, SetWallpaperByUrl003, TestSize.Level0)
650 {
651     HILOG_INFO("SetWallpaperByUrl003  begin");
652     int32_t wallpaperErrorCode = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().SetWallpaper(URL, 2);
653     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_PARAMETERS_INVALID)) << "Failed to throw error";
654 }
655 
656 /**
657 * @tc.name:    SetWallpaperByUrl004
658 * @tc.desc:    SetWallpaperByUrl with error url.
659 * @tc.type:    FUNC
660 * @tc.require: issueI5UHRG
661 * @tc.author:  lvbai
662 */
663 HWTEST_F(WallpaperTest, SetWallpaperByUrl004, TestSize.Level0)
664 {
665     HILOG_INFO("SetWallpaperByUrl004  begin");
666     int32_t wallpaperErrorCode =
667         OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().SetWallpaper("/data/test/theme/wallpaper/"
668                                                                                     "errorURL", 1);
669     EXPECT_NE(wallpaperErrorCode, static_cast<int32_t>(E_OK)) << "Failed to throw error";
670 }
671 
672 /**
673 * @tc.name:    FILE_DEAL001
674 * @tc.desc:    File operation-related interfaces
675 * @tc.type:    FUNC
676 * @tc.require:
677 * @tc.author:
678 */
679 HWTEST_F(WallpaperTest, FILE_DEAL001, TestSize.Level0)
680 {
681     HILOG_INFO("FILE_DEAL001  begin");
682     FileDeal fileOperation;
683     bool isExist = fileOperation.Mkdir("/data/test/theme/wallpaper/");
684     EXPECT_EQ(isExist, true);
685     isExist = fileOperation.Mkdir("/data/test/theme/errorURL/");
686     EXPECT_EQ(isExist, true);
687     isExist = fileOperation.FileIsExist(URL);
688     EXPECT_EQ(isExist, true);
689     isExist = fileOperation.FileIsExist("/data/test/theme/wallpaper/errorURL");
690     EXPECT_EQ(isExist, false);
691 }
692 
693 /**
694 * @tc.name:    SetWallpaper001
695 * @tc.desc:    SetWallpaper with error length
696 * @tc.type:    FUNC
697 * @tc.require: issueI6AW6M
698 * @tc.author:  weishaoxiong
699 */
700 HWTEST_F(WallpaperTest, SetWallpaper001, TestSize.Level0)
701 {
702     HILOG_INFO("SetWallpaper001  begin");
703     int32_t wallpaperErrorCode = WallpaperService::GetInstance()->SetWallpaperByMap(0, 0, -1);
704     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_PARAMETERS_INVALID)) << "Failed to throw error";
705     wallpaperErrorCode = WallpaperService::GetInstance()->SetWallpaperByFD(0, 0, FOO_MAX_LEN);
706     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_PARAMETERS_INVALID)) << "Failed to throw error";
707 }
708 /*********************   SetWallpaperByUrl   *********************/
709 } // namespace WallpaperMgrService
710 } // namespace OHOS