1ce968135Sopenharmony_ci/* 2ce968135Sopenharmony_ci* Copyright (C) 2022 Huawei Device Co., Ltd. 3ce968135Sopenharmony_ci* Licensed under the Apache License, Version 2.0 (the "License"); 4ce968135Sopenharmony_ci* you may not use this file except in compliance with the License. 5ce968135Sopenharmony_ci* You may obtain a copy of the License at 6ce968135Sopenharmony_ci* 7ce968135Sopenharmony_ci* http://www.apache.org/licenses/LICENSE-2.0 8ce968135Sopenharmony_ci* 9ce968135Sopenharmony_ci* Unless required by applicable law or agreed to in writing, software 10ce968135Sopenharmony_ci* distributed under the License is distributed on an "AS IS" BASIS, 11ce968135Sopenharmony_ci* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12ce968135Sopenharmony_ci* See the License for the specific language governing permissions and 13ce968135Sopenharmony_ci* limitations under the License. 14ce968135Sopenharmony_ci*/ 15ce968135Sopenharmony_ci 16ce968135Sopenharmony_ci#include <gtest/gtest.h> 17ce968135Sopenharmony_ci 18ce968135Sopenharmony_ci#include <ctime> 19ce968135Sopenharmony_ci 20ce968135Sopenharmony_ci#include "directory_ex.h" 21ce968135Sopenharmony_ci#include "hilog_wrapper.h" 22ce968135Sopenharmony_ci#include "image_packer.h" 23ce968135Sopenharmony_ci#include "pixel_map.h" 24ce968135Sopenharmony_ci#include "wallpaper_manager.h" 25ce968135Sopenharmony_ci 26ce968135Sopenharmony_ciconstexpr int32_t LOCKSCREEN = 1; 27ce968135Sopenharmony_ciconstexpr uint8_t HUNDRED = 100; 28ce968135Sopenharmony_ciusing namespace testing::ext; 29ce968135Sopenharmony_ciusing namespace testing; 30ce968135Sopenharmony_ciusing namespace OHOS::Media; 31ce968135Sopenharmony_ciusing namespace OHOS::HiviewDFX; 32ce968135Sopenharmony_ciusing namespace OHOS::MiscServices; 33ce968135Sopenharmony_ci 34ce968135Sopenharmony_cinamespace OHOS { 35ce968135Sopenharmony_cinamespace WallpaperMgrService { 36ce968135Sopenharmony_ciconstexpr const char *URI = "/data/test/theme/wallpaper/wallpaper_test.JPG"; 37ce968135Sopenharmony_ci 38ce968135Sopenharmony_ciclass WallpaperPermissionTest : public testing::Test { 39ce968135Sopenharmony_cipublic: 40ce968135Sopenharmony_ci static void SetUpTestCase(void); 41ce968135Sopenharmony_ci static void TearDownTestCase(void); 42ce968135Sopenharmony_ci void SetUp(); 43ce968135Sopenharmony_ci void TearDown(); 44ce968135Sopenharmony_ci static void CreateTempImage(); 45ce968135Sopenharmony_ci static std::shared_ptr<PixelMap> CreateTempPixelMap(); 46ce968135Sopenharmony_ci}; 47ce968135Sopenharmony_ciconst std::string VALID_SCHEMA_STRICT_DEFINE = "{\"SCHEMA_VERSION\":\"1.0\"," 48ce968135Sopenharmony_ci "\"SCHEMA_MODE\":\"STRICT\"," 49ce968135Sopenharmony_ci "\"SCHEMA_SKIPSIZE\":0," 50ce968135Sopenharmony_ci "\"SCHEMA_DEFINE\":{" 51ce968135Sopenharmony_ci "\"age\":\"INTEGER, NOT NULL\"" 52ce968135Sopenharmony_ci "}," 53ce968135Sopenharmony_ci "\"SCHEMA_INDEXES\":[\"$.age\"]}"; 54ce968135Sopenharmony_ci 55ce968135Sopenharmony_civoid WallpaperPermissionTest::SetUpTestCase(void) 56ce968135Sopenharmony_ci{ 57ce968135Sopenharmony_ci CreateTempImage(); 58ce968135Sopenharmony_ci HILOG_INFO("SetUpPermissionTestCase"); 59ce968135Sopenharmony_ci} 60ce968135Sopenharmony_ci 61ce968135Sopenharmony_civoid WallpaperPermissionTest::TearDownTestCase(void) 62ce968135Sopenharmony_ci{ 63ce968135Sopenharmony_ci HILOG_INFO("PermissionTestTearDownTestCase"); 64ce968135Sopenharmony_ci} 65ce968135Sopenharmony_ci 66ce968135Sopenharmony_civoid WallpaperPermissionTest::SetUp(void) 67ce968135Sopenharmony_ci{ 68ce968135Sopenharmony_ci} 69ce968135Sopenharmony_ci 70ce968135Sopenharmony_civoid WallpaperPermissionTest::TearDown(void) 71ce968135Sopenharmony_ci{ 72ce968135Sopenharmony_ci} 73ce968135Sopenharmony_ci 74ce968135Sopenharmony_civoid WallpaperPermissionTest::CreateTempImage() 75ce968135Sopenharmony_ci{ 76ce968135Sopenharmony_ci std::shared_ptr<PixelMap> pixelMap = CreateTempPixelMap(); 77ce968135Sopenharmony_ci ImagePacker imagePacker; 78ce968135Sopenharmony_ci PackOption option; 79ce968135Sopenharmony_ci option.format = "image/jpeg"; 80ce968135Sopenharmony_ci option.quality = HUNDRED; 81ce968135Sopenharmony_ci option.numberHint = 1; 82ce968135Sopenharmony_ci std::set<std::string> formats; 83ce968135Sopenharmony_ci imagePacker.GetSupportedFormats(formats); 84ce968135Sopenharmony_ci imagePacker.StartPacking(URI, option); 85ce968135Sopenharmony_ci HILOG_INFO("AddImage start"); 86ce968135Sopenharmony_ci imagePacker.AddImage(*pixelMap); 87ce968135Sopenharmony_ci int64_t packedSize = 0; 88ce968135Sopenharmony_ci HILOG_INFO("FinalizePacking start"); 89ce968135Sopenharmony_ci imagePacker.FinalizePacking(packedSize); 90ce968135Sopenharmony_ci if (packedSize == 0) { 91ce968135Sopenharmony_ci HILOG_INFO("FinalizePacking error"); 92ce968135Sopenharmony_ci } 93ce968135Sopenharmony_ci} 94ce968135Sopenharmony_ci 95ce968135Sopenharmony_cistd::shared_ptr<PixelMap> WallpaperPermissionTest::CreateTempPixelMap() 96ce968135Sopenharmony_ci{ 97ce968135Sopenharmony_ci uint32_t color[100] = { 3, 7, 9, 9, 7, 6 }; 98ce968135Sopenharmony_ci InitializationOptions opts = { { 5, 7 }, OHOS::Media::PixelFormat::ARGB_8888 }; 99ce968135Sopenharmony_ci std::unique_ptr<PixelMap> uniquePixelMap = PixelMap::Create(color, sizeof(color) / sizeof(color[0]), opts); 100ce968135Sopenharmony_ci std::shared_ptr<PixelMap> pixelMap = std::move(uniquePixelMap); 101ce968135Sopenharmony_ci return pixelMap; 102ce968135Sopenharmony_ci} 103ce968135Sopenharmony_ci 104ce968135Sopenharmony_ci/********************* ResetWallpaper *********************/ 105ce968135Sopenharmony_ci/** 106ce968135Sopenharmony_ci* @tc.name: ResetPermission001 107ce968135Sopenharmony_ci* @tc.desc: Reset wallpaper throw permission error. 108ce968135Sopenharmony_ci* @tc.type: FUNC 109ce968135Sopenharmony_ci* @tc.require: issueI60MT1 110ce968135Sopenharmony_ci*/ 111ce968135Sopenharmony_ciHWTEST_F(WallpaperPermissionTest, ResetPermission001, TestSize.Level1) 112ce968135Sopenharmony_ci{ 113ce968135Sopenharmony_ci HILOG_INFO("ResetPermission001 begin"); 114ce968135Sopenharmony_ci ApiInfo apiInfo{ false, false }; 115ce968135Sopenharmony_ci ErrorCode wallpaperErrorCode = 116ce968135Sopenharmony_ci OHOS::WallpaperMgrService::WallpaperManager::GetInstance().ResetWallpaper(LOCKSCREEN, apiInfo); 117ce968135Sopenharmony_ci EXPECT_EQ(wallpaperErrorCode, E_NO_PERMISSION) << "throw permission error successfully"; 118ce968135Sopenharmony_ci} 119ce968135Sopenharmony_ci/********************* ResetWallpaper *********************/ 120ce968135Sopenharmony_ci 121ce968135Sopenharmony_ci/********************* GetFile *********************/ 122ce968135Sopenharmony_ci/** 123ce968135Sopenharmony_ci* @tc.name: GetFilePermission001 124ce968135Sopenharmony_ci* @tc.desc: GetFile with wallpaperType[1] throw permission error. 125ce968135Sopenharmony_ci* @tc.type: FUNC 126ce968135Sopenharmony_ci* @tc.require: issueI60MT1 127ce968135Sopenharmony_ci*/ 128ce968135Sopenharmony_ciHWTEST_F(WallpaperPermissionTest, GetFilePermission001, TestSize.Level0) 129ce968135Sopenharmony_ci{ 130ce968135Sopenharmony_ci HILOG_INFO("GetFilePermission001 begin"); 131ce968135Sopenharmony_ci int32_t wallpaperFd = 0; 132ce968135Sopenharmony_ci ErrorCode wallpaperErrorCode = 133ce968135Sopenharmony_ci OHOS::WallpaperMgrService::WallpaperManager::GetInstance().GetFile(LOCKSCREEN, wallpaperFd); 134ce968135Sopenharmony_ci EXPECT_EQ(wallpaperErrorCode, E_NO_PERMISSION) << "throw permission error successfully"; 135ce968135Sopenharmony_ci} 136ce968135Sopenharmony_ci/********************* GetFile *********************/ 137ce968135Sopenharmony_ci 138ce968135Sopenharmony_ci/********************* GetPixelMap *********************/ 139ce968135Sopenharmony_ci/** 140ce968135Sopenharmony_ci* @tc.name: GetPixelMapPermission001 141ce968135Sopenharmony_ci* @tc.desc: GetPixelMap with wallpaperType[1] throw permission error. 142ce968135Sopenharmony_ci* @tc.type: FUNC 143ce968135Sopenharmony_ci* @tc.require: issueI60MT1 144ce968135Sopenharmony_ci*/ 145ce968135Sopenharmony_ciHWTEST_F(WallpaperPermissionTest, GetPixelMapPermission001, TestSize.Level0) 146ce968135Sopenharmony_ci{ 147ce968135Sopenharmony_ci HILOG_INFO("GetPixelMapPermission001 begin"); 148ce968135Sopenharmony_ci ApiInfo apiInfo{ false, false }; 149ce968135Sopenharmony_ci std::shared_ptr<OHOS::Media::PixelMap> pixelMap; 150ce968135Sopenharmony_ci ErrorCode wallpaperErrorCode = 151ce968135Sopenharmony_ci OHOS::WallpaperMgrService::WallpaperManager::GetInstance().GetPixelMap(LOCKSCREEN, apiInfo, pixelMap); 152ce968135Sopenharmony_ci EXPECT_EQ(wallpaperErrorCode, E_NOT_SYSTEM_APP) << "throw permission error successfully"; 153ce968135Sopenharmony_ci} 154ce968135Sopenharmony_ci/********************* GetPixelMap *********************/ 155ce968135Sopenharmony_ci 156ce968135Sopenharmony_ci/********************* SetWallpaperByMap *********************/ 157ce968135Sopenharmony_ci/** 158ce968135Sopenharmony_ci* @tc.name: SetWallpaperByMapPermission001 159ce968135Sopenharmony_ci* @tc.desc: SetWallpaperByMap with wallpaperType[1] throw permission error. 160ce968135Sopenharmony_ci* @tc.type: FUNC 161ce968135Sopenharmony_ci* @tc.require: issueI60MT1 162ce968135Sopenharmony_ci*/ 163ce968135Sopenharmony_ciHWTEST_F(WallpaperPermissionTest, SetWallpaperByMapPermission001, TestSize.Level0) 164ce968135Sopenharmony_ci{ 165ce968135Sopenharmony_ci HILOG_INFO("SetWallpaperByMapPermission001 begin"); 166ce968135Sopenharmony_ci std::shared_ptr<PixelMap> pixelMap = WallpaperPermissionTest::CreateTempPixelMap(); 167ce968135Sopenharmony_ci ApiInfo apiInfo{ false, false }; 168ce968135Sopenharmony_ci ErrorCode wallpaperErrorCode = 169ce968135Sopenharmony_ci OHOS::WallpaperMgrService::WallpaperManager::GetInstance().SetWallpaper(pixelMap, 2, apiInfo); 170ce968135Sopenharmony_ci EXPECT_EQ(wallpaperErrorCode, E_NO_PERMISSION) << "throw permission error successfully"; 171ce968135Sopenharmony_ci} 172ce968135Sopenharmony_ci/********************* SetWallpaperByMap *********************/ 173ce968135Sopenharmony_ci 174ce968135Sopenharmony_ci/********************* SetWallpaperByUri *********************/ 175ce968135Sopenharmony_ci/** 176ce968135Sopenharmony_ci* @tc.name: SetWallpaperByUriPermission001 177ce968135Sopenharmony_ci* @tc.desc: SetWallpaperByUri with wallpaperType[1] throw permission error. 178ce968135Sopenharmony_ci* @tc.type: FUNC 179ce968135Sopenharmony_ci* @tc.require: issueI60MT1 180ce968135Sopenharmony_ci*/ 181ce968135Sopenharmony_ciHWTEST_F(WallpaperPermissionTest, SetWallpaperByUriPermission001, TestSize.Level0) 182ce968135Sopenharmony_ci{ 183ce968135Sopenharmony_ci HILOG_INFO("SetWallpaperByUriPermission001 begin"); 184ce968135Sopenharmony_ci ApiInfo apiInfo{ false, false }; 185ce968135Sopenharmony_ci ErrorCode wallpaperErrorCode = 186ce968135Sopenharmony_ci OHOS::WallpaperMgrService::WallpaperManager::GetInstance().SetWallpaper(URI, LOCKSCREEN, apiInfo); 187ce968135Sopenharmony_ci EXPECT_EQ(wallpaperErrorCode, E_NO_PERMISSION) << "throw permission error successfully"; 188ce968135Sopenharmony_ci HILOG_INFO("SetWallpaperByUriPermission001 end"); 189ce968135Sopenharmony_ci} 190ce968135Sopenharmony_ci/********************* SetWallpaperByUri *********************/ 191ce968135Sopenharmony_ci} // namespace WallpaperMgrService 192ce968135Sopenharmony_ci} // namespace OHOS