1 /* 2 * Copyright (c) 2024 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 <functional> 17 #include <gtest/gtest.h> 18 19 #include "work_sched_config.h" 20 #include "work_sched_hilog.h" 21 22 using namespace testing::ext; 23 24 namespace OHOS { 25 namespace WorkScheduler { 26 namespace { 27 const std::string APP1 = "test1"; 28 const std::string APP2 = "test2"; 29 const std::string APP3 = "test3"; 30 const std::string APP4 = "test4"; 31 const std::string APP5 = "test5"; 32 } 33 34 class WorkSchedConfigTest : public testing::Test { 35 public: SetUpTestCase()36 static void SetUpTestCase() {}; TearDownTestCase()37 static void TearDownTestCase() {} SetUp()38 void SetUp() {} TearDown()39 void TearDown() {} 40 }; 41 42 /** 43 * @tc.name: InitActiveGroupWhitelist_001 44 * @tc.desc: Test EventPublisher PublishEvent. 45 * @tc.type: FUNC 46 * @tc.require: I8GHCL 47 */ 48 HWTEST_F(WorkSchedConfigTest, InitActiveGroupWhitelist_001, TestSize.Level1) 49 { 50 std::string configData = ""; 51 DelayedSingleton<WorkSchedulerConfig>::GetInstance()->InitActiveGroupWhitelist(configData); 52 EXPECT_FALSE(DelayedSingleton<WorkSchedulerConfig>::GetInstance()->IsInActiveGroupWhitelist(APP1)); 53 configData = "{\"active_group_whitelist\":[" 54 "\"test1\"," 55 "\"test2\"," 56 "\"test3\"," 57 "\"test4\"" 58 "]" 59 "}"; 60 DelayedSingleton<WorkSchedulerConfig>::GetInstance()->InitActiveGroupWhitelist(configData); 61 EXPECT_TRUE(DelayedSingleton<WorkSchedulerConfig>::GetInstance()->IsInActiveGroupWhitelist(APP1)); 62 EXPECT_TRUE(DelayedSingleton<WorkSchedulerConfig>::GetInstance()->IsInActiveGroupWhitelist(APP2)); 63 EXPECT_TRUE(DelayedSingleton<WorkSchedulerConfig>::GetInstance()->IsInActiveGroupWhitelist(APP3)); 64 EXPECT_TRUE(DelayedSingleton<WorkSchedulerConfig>::GetInstance()->IsInActiveGroupWhitelist(APP4)); 65 EXPECT_FALSE(DelayedSingleton<WorkSchedulerConfig>::GetInstance()->IsInActiveGroupWhitelist(APP5)); 66 } 67 } 68 }