1 /* 2 * Copyright (c) 2025 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 <limits> 18 #include <test_header.h> 19 20 #include "hgm_hfbc_config.h" 21 #include "hgm_test_base.h" 22 #include "parameters.h" 23 24 using namespace testing; 25 using namespace testing::ext; 26 27 namespace OHOS { 28 namespace Rosen { 29 namespace { 30 constexpr const char* VDEC_HFBC_SWITCH = "vendor.vdec.hfbc.disable.fromuser"; 31 HgmHfbcConfig g_hfbcConfig; 32 } 33 34 class HgmHfbcConfigTest : public HgmTestBase { 35 public: SetUpTestCase()36 static void SetUpTestCase() 37 { 38 HgmTestBase::SetUpTestCase(); 39 } TearDownTestCase()40 static void TearDownTestCase() {} SetUp()41 void SetUp() {} TearDown()42 void TearDown() {} 43 }; 44 45 /** 46 * @tc.name: SetHfbcConfigMap 47 * @tc.desc: Verify the result of SetHfbcConfigMap function 48 * @tc.type: FUNC 49 * @tc.require: 50 */ 51 HWTEST_F(HgmHfbcConfigTest, SetHfbcConfigMap, Function | SmallTest | Level0) 52 { 53 std::unordered_map<std::string, std::string> hfbcConfig = { 54 { "com.test.allowapp", "1" }, { "com.test.allowapp2", "1" } 55 }; 56 ASSERT_NO_FATAL_FAILURE({g_hfbcConfig.SetHfbcConfigMap(hfbcConfig);}); 57 EXPECT_EQ(g_hfbcConfig.hfbcConfig_.size(), hfbcConfig.size()); 58 for (const auto& pkg : hfbcConfig) { 59 EXPECT_EQ(g_hfbcConfig.hfbcConfig_.find(pkg.first) != g_hfbcConfig.hfbcConfig_.end(), true); 60 } 61 } 62 63 /** 64 * @tc.name: SetHfbcControlMode 65 * @tc.desc: Verify the result of SetHfbcControlMode function 66 * @tc.type: FUNC 67 * @tc.require: 68 */ 69 HWTEST_F(HgmHfbcConfigTest, SetHfbcControlMode, Function | SmallTest | Level0) 70 { 71 g_hfbcConfig.SetHfbcControlMode(true); 72 EXPECT_EQ(g_hfbcConfig.isHfbcDisableListMode_, true); 73 g_hfbcConfig.SetHfbcControlMode(false); 74 EXPECT_EQ(g_hfbcConfig.isHfbcDisableListMode_, false); 75 } 76 77 /** 78 * @tc.name: HandleHfbcConfig01 79 * @tc.desc: Verify the execution process of HandleHfbcConfig function 80 * @tc.type: FUNC 81 * @tc.require: 82 */ 83 HWTEST_F(HgmHfbcConfigTest, HandleHfbcConfig01, Function | SmallTest | Level0) 84 { 85 std::unordered_map<std::string, std::string> hfbcConfig = { 86 { "com.test.banapp", "1" }, { "com.test.banapp2", "1" } 87 }; 88 ASSERT_NO_FATAL_FAILURE({ g_hfbcConfig.SetHfbcConfigMap(hfbcConfig); }); 89 EXPECT_EQ(g_hfbcConfig.hfbcConfig_.size(), hfbcConfig.size()); 90 91 g_hfbcConfig.SetHfbcControlMode(true); 92 EXPECT_EQ(g_hfbcConfig.isHfbcDisableListMode_, true); 93 94 std::vector<std::string> packageList; 95 packageList.emplace_back("com.test.allowapp"); 96 packageList.emplace_back("com.test.allowapp2"); 97 ASSERT_NO_FATAL_FAILURE({g_hfbcConfig.HandleHfbcConfig(packageList);}); 98 ASSERT_EQ(HgmHfbcConfig::curHfbcStatus_, 0); 99 } 100 101 /** 102 * @tc.name: HandleHfbcConfig02 103 * @tc.desc: Verify the execution process of HandleHfbcConfig function 104 * @tc.type: FUNC 105 * @tc.require: 106 */ 107 HWTEST_F(HgmHfbcConfigTest, HandleHfbcConfig02, Function | SmallTest | Level0) 108 { 109 std::unordered_map<std::string, std::string> hfbcConfig = { 110 { "com.test.allowapp", "1" }, { "com.test.allowapp2", "1" } 111 }; 112 ASSERT_NO_FATAL_FAILURE({ g_hfbcConfig.SetHfbcConfigMap(hfbcConfig); }); 113 EXPECT_EQ(g_hfbcConfig.hfbcConfig_.size(), hfbcConfig.size()); 114 115 g_hfbcConfig.SetHfbcControlMode(false); 116 EXPECT_EQ(g_hfbcConfig.isHfbcDisableListMode_, false); 117 118 std::vector<std::string> packageList; 119 packageList.emplace_back("com.test.allowapp"); 120 packageList.emplace_back("com.test.allowapp2"); 121 ASSERT_NO_FATAL_FAILURE({g_hfbcConfig.HandleHfbcConfig(packageList);}); 122 ASSERT_EQ(HgmHfbcConfig::curHfbcStatus_, 0); 123 } 124 125 } // namespace Rosen 126 } // namespace OHOS 127