• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 GetEventHandler
57  * @tc.desc: Test GetEventHandler
58  * @tc.type: FUNC
59  */
60 HWTEST_F(MemoryLevelManagerTest, GetEventHandlerTest, TestSize.Level1)
61 {
62     MemoryLevelManager::GetInstance().PsiHandler();
63     MemoryLevelManager::GetInstance().PsiHandlerInner();
64     bool ret = MemoryLevelManager::GetInstance().GetEventHandler();
65     EXPECT_EQ(ret, true);
66 }
67 
68 /**
69  * @tc.name: SetModerate and GetModerate
70  * @tc.desc: Test CalcSystemMemoryLevel
71  * @tc.desc: Test CalcSystemMemoryLevel
72  * @tc.type: FUNC
73  */
74 HWTEST_F(MemoryLevelManagerTest, CalcSystemMemoryLevelTest, TestSize.Level1)
75 {
76     SystemMemoryInfo info;
77     info.level = SystemMemoryLevel::MEMORY_LEVEL_LOW;
78     bool ret = MemoryLevelManager::GetInstance().CalcSystemMemoryLevel(info);
79     EXPECT_EQ(ret, false);
80 }
81 
82 /**
83  * @tc.name: SetModerate and GetModerate
84  * @tc.desc: Test CalcReclaimAppList
85  * @tc.desc: Test CalcReclaimAppList
86  * @tc.type: FUNC
87  */
88 HWTEST_F(MemoryLevelManagerTest, CalcReclaimAppListTest, TestSize.Level1)
89 {
90     std::vector<std::shared_ptr<AppEntity>> appList;
91     bool ret = MemoryLevelManager::GetInstance().CalcReclaimAppList(appList);
92     EXPECT_EQ(ret, true);
93 }
94 } // namespace Memory
95 } // namespace OHOS
96