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 "leak_detector_unit_test.h"
17 
18 #include <unordered_map>
19 #include <iostream>
20 #include "fault_detector_manager.h"
21 #include "parameters.h"
22 #include "native_leak_config.h"
23 #include "test_util.h"
24 
25 #include "hiview_logger.h"
26 
27 namespace OHOS {
28 namespace HiviewDFX {
29 DEFINE_LOG_TAG("LeakDetectorUnitTest");
30 
31 using namespace std;
32 using namespace testing::ext;
33 
34 constexpr int BUFFER_LENGTH = 128;
35 
SetUpTestCase(void)36 void LeakDetectorUnitTest::SetUpTestCase(void)
37 {
38     system::SetParameter("hiview.memleak.test", "enable");
39 }
40 
TearDownTestCase(void)41 void LeakDetectorUnitTest::TearDownTestCase(void)
42 {
43     system::SetParameter("hiview.memleak.test", "disable");
44     TestUtil::KillProcess("hiview");
45 }
46 
SetUp(void)47 void LeakDetectorUnitTest::SetUp(void) {}
48 
TearDown(void)49 void LeakDetectorUnitTest::TearDown(void) {}
50 
51 /**
52  * @tc.name: LeakDetectorUnitTest001
53  * @tc.desc: check config parser
54  * @tc.type: FUNC
55  * @tc.require:
56  * @tc.author: wuzhenyang
57  */
58 HWTEST_F(LeakDetectorUnitTest, LeakDetectorUnitTest001, TestSize.Level1)
59 {
60     unordered_map<string, uint64_t> configList;
61     bool ret = NativeLeakConfig::GetThresholdList(configList);
62     ASSERT_TRUE(ret);
63     auto it = configList.find("DEFAULT");
64     ASSERT_NE(it, configList.end());
65 }
66 
67 } // namespace HiviewDFX
68 } // namespace OHOS
69 
70