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 <gtest/gtest.h>
17
18 #define private public
19 #include "restart_app_manager.h"
20 #undef private
21
22 using namespace testing::ext;
23 using namespace testing;
24
25 namespace OHOS {
26 namespace AAFwk {
27 class RestartAppManagerTest : public testing::Test {
28 public:
29 static void SetUpTestCase(void);
30 static void TearDownTestCase(void);
31 void SetUp();
32 void TearDown();
33 };
34
SetUpTestCase(void)35 void RestartAppManagerTest::SetUpTestCase(void)
36 {}
TearDownTestCase(void)37 void RestartAppManagerTest::TearDownTestCase(void)
38 {}
TearDown(void)39 void RestartAppManagerTest::TearDown(void)
40 {}
SetUp()41 void RestartAppManagerTest::SetUp()
42 {}
43
44 /**
45 * @tc.number: IsRestartAppFrequent_001
46 * @tc.name: IsRestartAppFrequent
47 * @tc.desc: Test whether IsRestartAppFrequent is called normally.
48 * @tc.type: FUNC
49 */
50 HWTEST_F(RestartAppManagerTest, IsRestartAppFrequent_001, TestSize.Level1)
51 {
52 RestartAppManager &instance = RestartAppManager::GetInstance();
53 RestartAppKeyType key("", 123);
54 time_t time = 0;
55 instance.restartAppHistory_[key] = time;
56 auto res = instance.IsRestartAppFrequent(key, time);
57 EXPECT_EQ(res, true);
58 }
59
60 /**
61 * @tc.number: IsRestartAppFrequent_002
62 * @tc.name: IsRestartAppFrequent
63 * @tc.desc: Test whether IsRestartAppFrequent is called normally.
64 * @tc.type: FUNC
65 */
66 HWTEST_F(RestartAppManagerTest, IsRestartAppFrequent_002, TestSize.Level1)
67 {
68 RestartAppManager &instance = RestartAppManager::GetInstance();
69 RestartAppKeyType key("", 123);
70 time_t time = 20;
71 auto res = instance.IsRestartAppFrequent(key, time);
72 EXPECT_EQ(res, false);
73 }
74
75 /**
76 * @tc.number: AddRestartAppHistory_001
77 * @tc.name: AddRestartAppHistory
78 * @tc.desc: Test whether AddRestartAppHistory is called normally.
79 * @tc.type: FUNC
80 */
81 HWTEST_F(RestartAppManagerTest, AddRestartAppHistory_001, TestSize.Level1)
82 {
83 RestartAppManager &instance = RestartAppManager::GetInstance();
84 RestartAppKeyType key("", 123);
85 time_t time = 1;
86 instance.AddRestartAppHistory(key, time);
87 EXPECT_EQ(instance.restartAppHistory_[key], time);
88 }
89 } // namespace AAFwk
90 } // namespace OHOS
91