• 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     ApiInfo apiInfo{ false, false };
100     WallpaperManagerkits::GetInstance().ResetWallpaper(SYSTYEM, apiInfo);
101     WallpaperManagerkits::GetInstance().ResetWallpaper(LOCKSCREEN, apiInfo);
102 }
103 
SetUp(void)104 void WallpaperTest::SetUp(void)
105 {
106 }
107 
TearDown(void)108 void WallpaperTest::TearDown(void)
109 {
110 }
111 
112 class WallpaperColorChangeListenerTestImpl : public OHOS::WallpaperMgrService::WallpaperColorChangeListener {
113 public:
114     std::vector<uint64_t> color_;
115     int wallpaperType_;
116     WallpaperColorChangeListenerTestImpl();
~WallpaperColorChangeListenerTestImpl()117     ~WallpaperColorChangeListenerTestImpl()
118     {
119     }
120 
121     WallpaperColorChangeListenerTestImpl(const WallpaperColorChangeListenerTestImpl &) = delete;
122     WallpaperColorChangeListenerTestImpl &operator=(const WallpaperColorChangeListenerTestImpl &) = delete;
123     WallpaperColorChangeListenerTestImpl(WallpaperColorChangeListenerTestImpl &&) = delete;
124     WallpaperColorChangeListenerTestImpl &operator=(WallpaperColorChangeListenerTestImpl &&) = delete;
125 
126     // callback function will be called when the db data is changed.
127     void OnColorsChange(const std::vector<uint64_t> &color, int wallpaperType);
128 
129     // reset the callCount_ to zero.
130     void ResetToZero();
131 
132     unsigned long GetCallCount() const;
133 
134 private:
135     unsigned long callCount_;
136 };
137 
OnColorsChange(const std::vector<uint64_t> & color,int wallpaperType)138 void WallpaperColorChangeListenerTestImpl::OnColorsChange(const std::vector<uint64_t> &color, int wallpaperType)
139 {
140     callCount_++;
141     for (auto const &each : color) {
142         color_.push_back(each);
143     }
144     wallpaperType_ = wallpaperType;
145 }
146 
WallpaperColorChangeListenerTestImpl()147 WallpaperColorChangeListenerTestImpl::WallpaperColorChangeListenerTestImpl()
148 {
149     callCount_ = 0;
150     wallpaperType_ = -1;
151 }
152 
ResetToZero()153 void WallpaperColorChangeListenerTestImpl::ResetToZero()
154 {
155     callCount_ = 0;
156 }
157 
GetCallCount() const158 unsigned long WallpaperColorChangeListenerTestImpl::GetCallCount() const
159 {
160     return callCount_;
161 }
162 
CreateTempImage()163 void WallpaperTest::CreateTempImage()
164 {
165     std::shared_ptr<PixelMap> pixelMap = CreateTempPixelMap();
166     ImagePacker imagePacker;
167     PackOption option;
168     option.format = "image/jpeg";
169     option.quality = HUNDRED;
170     option.numberHint = 1;
171     std::set<std::string> formats;
172     imagePacker.GetSupportedFormats(formats);
173     imagePacker.StartPacking(URL, option);
174     HILOG_INFO("AddImage start");
175     imagePacker.AddImage(*pixelMap);
176     int64_t packedSize = 0;
177     HILOG_INFO("FinalizePacking start");
178     imagePacker.FinalizePacking(packedSize);
179     if (packedSize == 0) {
180         HILOG_INFO("FinalizePacking error");
181     }
182 }
183 
CreateTempPixelMap()184 std::shared_ptr<PixelMap> WallpaperTest::CreateTempPixelMap()
185 {
186     uint32_t color[100] = { 3, 7, 9, 9, 7, 6 };
187     InitializationOptions opts = { { 5, 7 }, OHOS::Media::PixelFormat::ARGB_8888 };
188     std::unique_ptr<PixelMap> uniquePixelMap = PixelMap::Create(color, sizeof(color) / sizeof(color[0]), opts);
189     std::shared_ptr<PixelMap> pixelMap = std::move(uniquePixelMap);
190     return pixelMap;
191 }
192 
193 /*********************   ResetWallpaper   *********************/
194 /**
195 * @tc.name:    Reset001
196 * @tc.desc:    Reset wallpaper with wallpaperType[0].
197 * @tc.type:    FUNC
198 * @tc.require: issueI5UHRG
199 */
200 HWTEST_F(WallpaperTest, Reset001, TestSize.Level1)
201 {
202     HILOG_INFO("Reset001 begin.");
203     ApiInfo apiInfo{ false, false };
204     int32_t wallpaperErrorCode = WallpaperManagerkits::GetInstance().ResetWallpaper(SYSTYEM, apiInfo);
205     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(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 */
214 HWTEST_F(WallpaperTest, Reset002, TestSize.Level1)
215 {
216     HILOG_INFO("Reset002 begin.");
217     ApiInfo apiInfo{ false, false };
218     int32_t wallpaperErrorCode = WallpaperManagerkits::GetInstance().ResetWallpaper(LOCKSCREEN, apiInfo);
219     EXPECT_EQ(wallpaperErrorCode, 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 */
228 HWTEST_F(WallpaperTest, Reset003, TestSize.Level1)
229 {
230     HILOG_INFO("Reset003 begin.");
231     ApiInfo apiInfo{ false, false };
232     int32_t wallpaperErrorCode = WallpaperManagerkits::GetInstance().ResetWallpaper(2, apiInfo);
233     EXPECT_EQ(wallpaperErrorCode, E_PARAMETERS_INVALID) << "Failed to throw error.";
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 */
242 HWTEST_F(WallpaperTest, Reset004, TestSize.Level1)
243 {
244     HILOG_INFO("Reset004 begin.");
245     ApiInfo apiInfo{ false, false };
246     int32_t wallpaperErrorCode = WallpaperManagerkits::GetInstance().ResetWallpaper(SYSTYEM, apiInfo);
247     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_OK)) << "Failed to reset.";
248 
249     /* duplicate reset */
250     wallpaperErrorCode = WallpaperManagerkits::GetInstance().ResetWallpaper(SYSTYEM, apiInfo);
251     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_OK)) << "Failed to reset.";
252 }
253 
254 /**
255 * @tc.name:    Reset005
256 * @tc.desc:    Reset wallpaper with wallpaperType[1] after resetting wallpaper[1] and check whether Id is same one.
257 * @tc.type:    FUNC
258 * @tc.require: issueI5UHRG
259 */
260 HWTEST_F(WallpaperTest, Reset005, TestSize.Level1)
261 {
262     HILOG_INFO("Reset005 begin.");
263     ApiInfo apiInfo{ false, false };
264     int32_t wallpaperErrorCode = WallpaperManagerkits::GetInstance().ResetWallpaper(LOCKSCREEN, apiInfo);
265     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_OK)) << "Failed to reset.";
266     int firstId = WallpaperManagerkits::GetInstance().GetWallpaperId(LOCKSCREEN);
267 
268     /* duplicate reset */
269     wallpaperErrorCode = WallpaperManagerkits::GetInstance().ResetWallpaper(LOCKSCREEN, apiInfo);
270     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_OK)) << "Failed to reset.";
271     int secondId = WallpaperManagerkits::GetInstance().GetWallpaperId(LOCKSCREEN);
272     EXPECT_EQ(firstId, secondId) << "Id should be same one.";
273 }
274 /*********************   ResetWallpaper   *********************/
275 
276 /*********************   IsChangePermitted   *********************/
277 
278 /**
279 * @tc.name: IsChangePermitted001
280 * @tc.desc: check permission.
281 * @tc.type: FUNC
282 * @tc.require:
283 * @tc.author:
284 */
285 HWTEST_F(WallpaperTest, IsChangePermitted001, TestSize.Level1)
286 {
287     bool ret = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().IsChangePermitted();
288     EXPECT_EQ(ret, true);
289 }
290 
291 /*********************   IsChangePermitted   *********************/
292 
293 /*********************   IsOperationAllowed   *********************/
294 
295 /**
296 * @tc.name: IsOperationAllowed001
297 * @tc.desc: check permission.
298 * @tc.type: FUNC
299 * @tc.require:
300 * @tc.author:
301 */
302 HWTEST_F(WallpaperTest, IsOperationAllowed001, TestSize.Level1)
303 {
304     bool ret = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().IsOperationAllowed();
305     EXPECT_EQ(ret, true);
306 }
307 
308 /*********************   IsOperationAllowed   *********************/
309 
310 /*********************   On & Off   *********************/
311 
312 /**
313 * @tc.name: On001
314 * @tc.desc: set wallpaper and get callback.
315 * @tc.type: FUNC
316 * @tc.require:
317 * @tc.author:
318 */
319 HWTEST_F(WallpaperTest, On001, TestSize.Level1)
320 {
321     HILOG_INFO("On001 begin");
322     auto listener = std::make_shared<WallpaperColorChangeListenerTestImpl>();
323     OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().On("colorChange", listener);
324 
325     auto offSubStatus = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().Off("colorChange", listener);
326     EXPECT_EQ(offSubStatus, true) << "unsubscribe wallpaper color change.";
327 }
328 
329 /*********************   On & Off   *********************/
330 
331 /*********************   GetColors   *********************/
332 /**
333 * @tc.name: GetColors001
334 * @tc.desc: GetColors with wallpaperType[0].
335 * @tc.type: FUNC
336 * @tc.require:
337 * @tc.author:
338 */
339 HWTEST_F(WallpaperTest, GetColors001, TestSize.Level0)
340 {
341     HILOG_INFO("GetColors001 begin");
342     std::vector<uint64_t> colors;
343     ApiInfo apiInfo{ false, false };
344     int32_t errorCode = WallpaperManagerkits::GetInstance().GetColors(SYSTYEM, apiInfo, colors);
345     EXPECT_EQ(errorCode, static_cast<int32_t>(E_OK)) << "Failed to GetColors.";
346     EXPECT_FALSE(colors.empty());
347 }
348 
349 /**
350 * @tc.name: GetColors002
351 * @tc.desc: GetColors with wallpaperType[1].
352 * @tc.type: FUNC
353 * @tc.require:
354 * @tc.author:
355 */
356 HWTEST_F(WallpaperTest, GetColors002, TestSize.Level0)
357 {
358     HILOG_INFO("GetColors002 begin");
359     std::vector<uint64_t> colors;
360     ApiInfo apiInfo{ false, false };
361     int32_t errorCode = WallpaperManagerkits::GetInstance().GetColors(LOCKSCREEN, apiInfo, colors);
362     EXPECT_EQ(errorCode, static_cast<int32_t>(E_OK)) << "Failed to GetColors.";
363     EXPECT_FALSE(colors.empty());
364 }
365 /*********************   GetColors   *********************/
366 
367 /*********************   GetId   *********************/
368 /**
369 * @tc.name: GetId001
370 * @tc.desc: GetId with wallpaperType[0].
371 * @tc.type: FUNC
372 * @tc.require:
373 * @tc.author:
374 */
375 HWTEST_F(WallpaperTest, GetId001, TestSize.Level0)
376 {
377     HILOG_INFO("GetId001 begin");
378     bool result = false;
379     int ida = HUNDRED;
380     ida = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().GetWallpaperId(SYSTYEM);
381     if (ida != HUNDRED) {
382         result = true;
383     }
384     EXPECT_TRUE(result);
385 }
386 
387 /**
388 * @tc.name: GetId002
389 * @tc.desc: GetId with wallpaperType[1].
390 * @tc.type: FUNC
391 * @tc.require:
392 * @tc.author:
393 */
394 HWTEST_F(WallpaperTest, GetId002, TestSize.Level0)
395 {
396     HILOG_INFO("GetId002 begin");
397     bool result = false;
398     int ida = HUNDRED;
399     ida = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().GetWallpaperId(LOCKSCREEN);
400     if (ida != HUNDRED) {
401         result = true;
402     }
403     EXPECT_TRUE(result);
404 }
405 /*********************   GetId   *********************/
406 
407 /*********************   GetFile   *********************/
408 /**
409 * @tc.name:    GetFile001
410 * @tc.desc:    GetFile with wallpaperType[0].
411 * @tc.type:    FUNC
412 * @tc.require: issueI5UHRG
413 */
414 HWTEST_F(WallpaperTest, GetFile001, TestSize.Level0)
415 {
416     HILOG_INFO("GetFile001 begin");
417     int32_t wallpaperFd = 0;
418     int wallpaperErrorCode =
419         OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().GetFile(SYSTYEM, wallpaperFd);
420     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(static_cast<int32_t>(E_OK))) << "Failed to get File.";
421 }
422 
423 /**
424 * @tc.name:    GetFile002
425 * @tc.desc:    GetFile with wallpaperType[1].
426 * @tc.type:    FUNC
427 * @tc.require: issueI5UHRG
428 */
429 HWTEST_F(WallpaperTest, GetFile002, TestSize.Level0)
430 {
431     HILOG_INFO("GetFile002 begin");
432     int32_t wallpaperFd = 0;
433     int wallpaperErrorCode =
434         OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().GetFile(LOCKSCREEN, wallpaperFd);
435     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(static_cast<int32_t>(E_OK))) << "Failed to get File.";
436 }
437 
438 /**
439 * @tc.name:    GetFile003
440 * @tc.desc:    GetFile with wallpaperType[2] throw parameters error.
441 * @tc.type:    FUNC
442 * @tc.require: issueI5UHRG
443 */
444 HWTEST_F(WallpaperTest, GetFile003, TestSize.Level0)
445 {
446     HILOG_INFO("GetFile003 begin");
447     int32_t wallpaperFd = 0;
448     int wallpaperErrorCode = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().GetFile(2, wallpaperFd);
449     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_PARAMETERS_INVALID)) << "Failed to throw parameters error";
450 }
451 
452 /**
453 * @tc.name:    GetFile004
454 * @tc.desc:    GetFile with wallpaperType[0].
455 * @tc.type:    FUNC
456 * @tc.require:
457 * @tc.author:
458 */
459 HWTEST_F(WallpaperTest, GetFile004, TestSize.Level0)
460 {
461     HILOG_INFO("GetFile001 begin");
462     int32_t wallpaperFd = 0;
463     int wallpaperErrorCode =
464         OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().GetFile(SYSTYEM, wallpaperFd);
465     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(static_cast<int32_t>(E_OK))) << "Failed to get File.";
466 }
467 /*********************   GetFile   *********************/
468 
469 /*********************   GetWallpaperMinHeight   *********************/
470 /**
471 * @tc.name: getMinHeight001
472 * @tc.desc: GetWallpaperMinHeight .
473 * @tc.type: FUNC
474 * @tc.require:
475 */
476 HWTEST_F(WallpaperTest, getMinHeight001, TestSize.Level0)
477 {
478     HILOG_INFO("WallpaperReset001  begin");
479     int height = 0;
480     ApiInfo apiInfo{ false, false };
481     int32_t wallpaperErrorCode = WallpaperManagerkits::GetInstance().GetWallpaperMinHeight(apiInfo, height);
482     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_OK)) << "Failed to get WallpaperMinHeight.";
483     EXPECT_GT(height, 0);
484 }
485 /*********************   GetWallpaperMinHeight   *********************/
486 
487 /*********************   GetWallpaperMinWidth   *********************/
488 /**
489 * @tc.name: getMinWidth001
490 * @tc.desc: GetWallpaperMinWidth .
491 * @tc.type: FUNC
492 * @tc.require:
493 */
494 HWTEST_F(WallpaperTest, getMinWidth001, TestSize.Level0)
495 {
496     HILOG_INFO("getMinWidth001  begin");
497     int width = 0;
498     ApiInfo apiInfo{ false, false };
499     int32_t wallpaperErrorCode = WallpaperManagerkits::GetInstance().GetWallpaperMinWidth(apiInfo, width);
500     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_OK)) << "Failed to get WallpaperMinWidth.";
501     EXPECT_GT(width, 0);
502 }
503 /*********************   GetWallpaperMinWidth   *********************/
504 
505 /*********************   GetPiexlMap   *********************/
506 /**
507 * @tc.name:    GetPiexlMap001
508 * @tc.desc:    GetPixelMap with wallpaperType[0].
509 * @tc.type:    FUNC
510 * @tc.require: issueI5UHRG
511 */
512 HWTEST_F(WallpaperTest, GetPiexlMap001, TestSize.Level0)
513 {
514     HILOG_INFO("GetPiexlMap001  begin");
515     std::shared_ptr<OHOS::Media::PixelMap> pixelMap;
516     ApiInfo apiInfo{ false, false };
517     int32_t wallpaperErrorCode = WallpaperManagerkits::GetInstance().GetPixelMap(SYSTYEM, apiInfo, pixelMap);
518     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_OK)) << "Failed to GetPixelMap.";
519 }
520 
521 /**
522 * @tc.name:    GetPiexlMap002
523 * @tc.desc:    GetPixelMap with wallpaperType[1].
524 * @tc.type:    FUNC
525 * @tc.require: issueI5UHRG
526 */
527 HWTEST_F(WallpaperTest, GetPiexlMap002, TestSize.Level0)
528 {
529     HILOG_INFO("GetPiexlMap002  begin");
530     std::shared_ptr<OHOS::Media::PixelMap> pixelMap;
531     ApiInfo apiInfo{ false, false };
532     int32_t wallpaperErrorCode = WallpaperManagerkits::GetInstance().GetPixelMap(LOCKSCREEN, apiInfo, pixelMap);
533     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_OK)) << "Failed to GetPixelMap.";
534 }
535 
536 /**
537 * @tc.name:    GetPiexlMap003
538 * @tc.desc:    GetPixelMap with wallpaperType[2] throw parameters error.
539 * @tc.type:    FUNC
540 * @tc.require: issueI5UHRG
541 */
542 HWTEST_F(WallpaperTest, GetPiexlMap003, TestSize.Level0)
543 {
544     HILOG_INFO("GetPiexlMap003  begin");
545     std::shared_ptr<OHOS::Media::PixelMap> pixelMap;
546     ApiInfo apiInfo{ false, false };
547     int32_t wallpaperErrorCode =
548         OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().GetPixelMap(2, apiInfo, pixelMap);
549     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_PARAMETERS_INVALID)) << "Failed to throw parameters error";
550 }
551 /*********************   GetPiexlMap   *********************/
552 
553 /*********************   SetWallpaperByMap   *********************/
554 /**
555 * @tc.name:    SetWallpaperByMap001
556 * @tc.desc:    SetWallpaperByMap with wallpaperType[0].
557 * @tc.type:    FUNC
558 * @tc.require: issueI5UHRG
559 */
560 HWTEST_F(WallpaperTest, SetWallpaperByMap001, TestSize.Level0)
561 {
562     HILOG_INFO("SetWallpaperByMap001  begin");
563     std::shared_ptr<PixelMap> pixelMap = WallpaperTest::CreateTempPixelMap();
564     ApiInfo apiInfo{ false, false };
565     int32_t wallpaperErrorCode = WallpaperManagerkits::GetInstance().SetWallpaper(pixelMap, SYSTYEM, apiInfo);
566     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_OK)) << "Failed to set SYSTYEM PixelMap.";
567 }
568 
569 /**
570 * @tc.name:    SetWallpaperByMap002
571 * @tc.desc:    SetWallpaperByMap with wallpaperType[1].
572 * @tc.type:    FUNC
573 * @tc.require: issueI5UHRG
574 */
575 HWTEST_F(WallpaperTest, SetWallpaperByMap002, TestSize.Level0)
576 {
577     HILOG_INFO("SetWallpaperByMap002  begin");
578     std::shared_ptr<PixelMap> pixelMap = WallpaperTest::CreateTempPixelMap();
579     ApiInfo apiInfo{ false, false };
580     int32_t wallpaperErrorCode = WallpaperManagerkits::GetInstance().SetWallpaper(pixelMap, LOCKSCREEN, apiInfo);
581     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_OK)) << "Failed to set LOCKSCREEN PixelMap.";
582 }
583 
584 /**
585 * @tc.name:    SetWallpaperByMap003
586 * @tc.desc:    SetWallpaperByMap with wallpaperType[2] throw parameters error.
587 * @tc.type:    FUNC
588 * @tc.require: issueI5UHRG
589 */
590 HWTEST_F(WallpaperTest, SetWallpaperByMap003, TestSize.Level0)
591 {
592     HILOG_INFO("SetWallpaperByMap003  begin");
593     std::shared_ptr<PixelMap> pixelMap = WallpaperTest::CreateTempPixelMap();
594     ApiInfo apiInfo{ false, false };
595     int32_t wallpaperErrorCode = WallpaperManagerkits::GetInstance().SetWallpaper(pixelMap, 2, apiInfo);
596     EXPECT_EQ(wallpaperErrorCode, E_PARAMETERS_INVALID) << "Failed to throw parameters error";
597 }
598 /*********************   SetWallpaperByMap   *********************/
599 
600 /*********************   SetWallpaperByUrl   *********************/
601 /**
602 * @tc.name:    SetWallpaperByUrl001
603 * @tc.desc:    SetWallpaperByUrl with wallpaperType[0] .
604 * @tc.type:    FUNC
605 * @tc.require: issueI5UHRG
606 */
607 HWTEST_F(WallpaperTest, SetWallpaperByUrl001, TestSize.Level0)
608 {
609     HILOG_INFO("SetWallpaperByUri001  begin");
610     ApiInfo apiInfo{ false, false };
611     int32_t wallpaperErrorCode = WallpaperManagerkits::GetInstance().SetWallpaper(URL, SYSTYEM, apiInfo);
612     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_OK)) << "Failed to set SYSTYEM.";
613 }
614 
615 /**
616 * @tc.name:    SetWallpaperByUrl002
617 * @tc.desc:    SetWallpaperByUrl with wallpaperType[1].
618 * @tc.type:    FUNC
619 * @tc.require: issueI5UHRG
620 */
621 HWTEST_F(WallpaperTest, SetWallpaperByUrl002, TestSize.Level0)
622 {
623     HILOG_INFO("SetWallpaperByUri002  begin");
624     ApiInfo apiInfo{ false, false };
625     int32_t wallpaperErrorCode = WallpaperManagerkits::GetInstance().SetWallpaper(URL, LOCKSCREEN, apiInfo);
626     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_OK)) << "Failed to set LOCKSCREEN.";
627 }
628 
629 /**
630 * @tc.name:    SetWallpaperByUrl003
631 * @tc.desc:    SetWallpaperByUrl with wallpaperType[2] throw parameters error.
632 * @tc.type:    FUNC
633 * @tc.require: issueI5UHRG
634 */
635 HWTEST_F(WallpaperTest, SetWallpaperByUrl003, TestSize.Level0)
636 {
637     HILOG_INFO("SetWallpaperByUri003  begin");
638     ApiInfo apiInfo{ false, false };
639     int32_t wallpaperErrorCode = WallpaperManagerkits::GetInstance().SetWallpaper(URL, 2, apiInfo);
640     EXPECT_EQ(wallpaperErrorCode, E_PARAMETERS_INVALID) << "Failed to throw error";
641 }
642 
643 /**
644 * @tc.name:    FILE_DEAL001
645 * @tc.desc:    File operation-related interfaces
646 * @tc.type:    FUNC
647 * @tc.require:
648 * @tc.author:
649 */
650 HWTEST_F(WallpaperTest, FILE_DEAL001, TestSize.Level0)
651 {
652     HILOG_INFO("FILE_DEAL001  begin");
653     FileDeal fileOperation;
654     bool isExist = fileOperation.Mkdir("/data/test/theme/wallpaper/");
655     EXPECT_EQ(isExist, true);
656     isExist = fileOperation.Mkdir("/data/test/theme/errorURL/");
657     EXPECT_EQ(isExist, true);
658     isExist = fileOperation.FileIsExist(URL);
659     EXPECT_EQ(isExist, true);
660     isExist = fileOperation.FileIsExist("/data/test/theme/wallpaper/errorURL");
661     EXPECT_EQ(isExist, false);
662 }
663 
664 /**
665 * @tc.name:    SetWallpaper001
666 * @tc.desc:    SetWallpaper with error length
667 * @tc.type:    FUNC
668 * @tc.require: issueI6AW6M
669 * @tc.author:  weishaoxiong
670 */
671 HWTEST_F(WallpaperTest, SetWallpaper001, TestSize.Level0)
672 {
673     HILOG_INFO("SetWallpaper001  begin");
674     int32_t wallpaperErrorCode = WallpaperService::GetInstance()->SetWallpaperByMap(0, 0, -1);
675     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_PARAMETERS_INVALID)) << "Failed to throw error";
676     wallpaperErrorCode = WallpaperService::GetInstance()->SetWallpaperByFD(0, 0, FOO_MAX_LEN);
677     EXPECT_EQ(wallpaperErrorCode, static_cast<int32_t>(E_PARAMETERS_INVALID)) << "Failed to throw error";
678 }
679 /*********************   SetWallpaperByUrl   *********************/
680 } // namespace WallpaperMgrService
681 } // namespace OHOS