1 /*
2  * Copyright (c) 2021 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 #include "hiview_platform_config_test.h"
16 
17 #include "hiview_platform_config.h"
18 using namespace testing::ext;
19 using namespace OHOS::HiviewDFX;
20 
SetUp()21 void HiviewPlatformConfigTest::SetUp()
22 {
23     /**
24      * @tc.setup: create an event loop and multiple event handlers
25      */
26     printf("SetUp.\n");
27     platform.GetPluginMap();
28 }
29 
TearDown()30 void HiviewPlatformConfigTest::TearDown()
31 {
32     /**
33      * @tc.teardown: destroy the event loop we have created
34      */
35     printf("TearDown.\n");
36 }
37 
38 /**
39  * @tc.name: PlatformConfigParse001
40  * @tc.desc: parse a correct config file and check result
41  * @tc.type: FUNC
42  * @tc.require: AR000DPTT5
43  */
44 HWTEST_F(HiviewPlatformConfigTest, PlatformConfigParse001, TestSize.Level3)
45 {
46     /**
47      * @tc.steps: step1. create event handler and events
48      */
49     HiviewPlatformConfig platformConfig = HiviewPlatformConfig("/data/test/test_data/hiview_platform_config");
50     HiviewPlatformConfig::PlatformConfigInfo platformConfigInfo;
51     bool state = platformConfig.ParsesConfig(platformConfigInfo);
52     ASSERT_EQ(true, state);
53     ASSERT_EQ(platformConfigInfo.defaultPluginConfigName, "plugin_config");
54     ASSERT_EQ(platformConfigInfo.pluginConfigFileDir, "/data/test/test_data/");
55     ASSERT_EQ(platformConfigInfo.dynamicLibSearchDir, "/system/lib/");
56     ASSERT_EQ(platformConfigInfo.dynamicLib64SearchDir, "/system/lib64/");
57     ASSERT_EQ(platformConfigInfo.workDir, "/data/test/LogService_a/");
58     ASSERT_EQ(platformConfigInfo.commercialWorkDir, "/log/LogService/");
59     ASSERT_EQ(platformConfigInfo.persistDir, "/log/hiview/");
60 }
61 
62 /**
63  * @tc.name: PlatformConfigParse002
64  * @tc.desc: parse a incorrect config file and check result
65  * @tc.type: FUNC
66  * @tc.require: issueI64QXL
67  */
68 HWTEST_F(HiviewPlatformConfigTest, PlatformConfigParse002, TestSize.Level3)
69 {
70     HiviewPlatformConfig platformConfig = HiviewPlatformConfig("//data/test/test_data/just_for_test");
71     HiviewPlatformConfig::PlatformConfigInfo platformConfigInfo;
72     auto ret = platformConfig.ParsesConfig(platformConfigInfo);
73     ASSERT_TRUE(!ret);
74 }