1 /*
2  * Copyright (c) 2022 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 "utils.h"
18 
19 #define private public
20 #define protected public
21 #include "memory_level_manager.h"
22 #undef private
23 #undef protected
24 
25 namespace OHOS {
26 namespace Memory {
27 using namespace testing;
28 using namespace testing::ext;
29 
30 class MemoryLevelManagerTest : public testing::Test {
31 public:
32     static void SetUpTestCase();
33     static void TearDownTestCase();
34     void SetUp();
35     void TearDown();
36 };
37 
SetUpTestCase()38 void MemoryLevelManagerTest::SetUpTestCase()
39 {
40 }
41 
TearDownTestCase()42 void MemoryLevelManagerTest::TearDownTestCase()
43 {
44 }
45 
SetUp()46 void MemoryLevelManagerTest::SetUp()
47 {
48 }
49 
TearDown()50 void MemoryLevelManagerTest::TearDown()
51 {
52 }
53 
54 /**
55  * @tc.name: SetModerate and GetModerate
56  * @tc.desc: Test PsiHandler
57  * @tc.desc: Test PsiHandler
58  * @tc.type: FUNC
59  */
60 HWTEST_F(MemoryLevelManagerTest, PsiHandlerTest, TestSize.Level1)
61 {
62     MemoryLevelManager::GetInstance().PsiHandler();
63 }
64 
65 /**
66  * @tc.name: SetModerate and GetModerate
67  * @tc.desc: Test PsiHandlerInner
68  * @tc.desc: Test PsiHandlerInner
69  * @tc.type: FUNC
70  */
71 HWTEST_F(MemoryLevelManagerTest, PsiHandlerInnerTest, TestSize.Level1)
72 {
73     MemoryLevelManager::GetInstance().PsiHandlerInner();
74 }
75 
76 /**
77  * @tc.name: SetModerate and GetModerate
78  * @tc.desc: Test GetEventHandler
79  * @tc.desc: Test GetEventHandler
80  * @tc.type: FUNC
81  */
82 HWTEST_F(MemoryLevelManagerTest, GetEventHandlerTest, TestSize.Level1)
83 {
84     bool ret = MemoryLevelManager::GetInstance().GetEventHandler();
85     EXPECT_EQ(ret, true);
86 }
87 
88 /**
89  * @tc.name: SetModerate and GetModerate
90  * @tc.desc: Test CalcSystemMemoryLevel
91  * @tc.desc: Test CalcSystemMemoryLevel
92  * @tc.type: FUNC
93  */
94 HWTEST_F(MemoryLevelManagerTest, CalcSystemMemoryLevelTest, TestSize.Level1)
95 {
96     SystemMemoryInfo info;
97     info.level = SystemMemoryLevel::MEMORY_LEVEL_LOW;
98     bool ret = MemoryLevelManager::GetInstance().CalcSystemMemoryLevel(info);
99     EXPECT_EQ(ret, false);
100 }
101 
102 /**
103  * @tc.name: SetModerate and GetModerate
104  * @tc.desc: Test CalcReclaimAppList
105  * @tc.desc: Test CalcReclaimAppList
106  * @tc.type: FUNC
107  */
108 HWTEST_F(MemoryLevelManagerTest, CalcReclaimAppListTest, TestSize.Level1)
109 {
110     std::vector<std::shared_ptr<AppEntity>> appList;
111     bool ret = MemoryLevelManager::GetInstance().CalcReclaimAppList(appList);
112     EXPECT_EQ(ret, true);
113 }
114 } // namespace Memory
115 } // namespace OHOS
116