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
18 #include "killing_process_manager.h"
19 #include "hilog_tag_wrapper.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace AppExecFwk {
26 namespace {
27 constexpr int32_t CLEAR_CALLER_KEY_DELAY_TIME = 6;
28 } // namespace
29
30 class KillingProcessManagerTest : public testing::Test {
31 public:
32 static void SetUpTestCase();
33 static void TearDownTestCase();
34 void SetUp() override;
35 void TearDown() override;
36 };
37
SetUpTestCase()38 void KillingProcessManagerTest::SetUpTestCase()
39 {}
40
TearDownTestCase()41 void KillingProcessManagerTest::TearDownTestCase()
42 {}
43
SetUp()44 void KillingProcessManagerTest::SetUp()
45 {}
46
TearDown()47 void KillingProcessManagerTest::TearDown()
48 {}
49
50 /**
51 * @tc.name: IsCallerKilling_001
52 * @tc.desc: test IsCallerKilling function.
53 * @tc.type: FUNC
54 */
55 HWTEST_F(KillingProcessManagerTest, IsCallerKilling_001, TestSize.Level1)
56 {
57 TAG_LOGI(AAFwkTag::TEST, "KillingProcessManagerTest IsCallerKilling_001 start");
58 std::string callerKey = "testcallerKey";
59 KillingProcessManager &killingProcessManager = KillingProcessManager::GetInstance();
60 bool ret = killingProcessManager.IsCallerKilling(callerKey);
61 EXPECT_FALSE(ret);
62 TAG_LOGI(AAFwkTag::TEST, "KillingProcessManagerTest IsCallerKilling_001 end");
63 }
64
65 /**
66 * @tc.name: AddKillingCallerKey_001
67 * @tc.desc: test AddKillingCallerKey function.
68 * @tc.type: FUNC
69 */
70 HWTEST_F(KillingProcessManagerTest, AddKillingCallerKey_001, TestSize.Level1)
71 {
72 TAG_LOGI(AAFwkTag::TEST, "KillingProcessManagerTest AddKillingCallerKey_001 start");
73 std::string nullKey = "";
74 std::string callerKey = "testcallerKey";
75 KillingProcessManager &killingProcessManager = KillingProcessManager::GetInstance();
76 killingProcessManager.AddKillingCallerKey(nullKey);
77 killingProcessManager.RemoveKillingCallerKey(nullKey);
78
79 killingProcessManager.AddKillingCallerKey(callerKey);
80 EXPECT_EQ(killingProcessManager.killingCallerKeySet_.count(callerKey), 1);
81 killingProcessManager.AddKillingCallerKey(callerKey);
82 sleep(CLEAR_CALLER_KEY_DELAY_TIME);
83 EXPECT_EQ(killingProcessManager.killingCallerKeySet_.count(callerKey), 0);
84 TAG_LOGI(AAFwkTag::TEST, "KillingProcessManagerTest AddKillingCallerKey_001 end");
85 }
86 } // namespace AppExecFwk
87 } // namespace OHOS
88