1 /*
2  * Copyright (c) 2021-2023 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 "fault_logger_config.h"
18 
19 #include <memory>
20 #include <string>
21 
22 using namespace OHOS::HiviewDFX;
23 using namespace testing::ext;
24 using namespace std;
25 
26 namespace OHOS {
27 namespace HiviewDFX {
28 class FaultLoggerConfigTest : public testing::Test {
29 public:
SetUpTestCase(void)30     static void SetUpTestCase(void) {}
TearDownTestCase(void)31     static void TearDownTestCase(void) {}
SetUp()32     void SetUp() {}
TearDown()33     void TearDown() {}
34 };
35 } // namespace HiviewDFX
36 } // namespace OHOS
37 
38 /** FaultLoggerConfigTest001
39  * @tc.name: DfxMapsRequestTest033
40  * @tc.desc: test get file max number
41  * @tc.type: FUNC
42  */
43 HWTEST_F (FaultLoggerConfigTest, FaultLoggerConfigTest001, TestSize.Level2)
44 {
45     GTEST_LOG_(INFO) << "FaultLoggerConfigTest001: start.";
46     std::shared_ptr<FaultLoggerConfig> config = std::make_shared<FaultLoggerConfig>(LOG_FILE_NUMBER, LOG_FILE_SIZE,
47         LOG_FILE_PATH, DEBUG_LOG_FILE_PATH);
48     int input = 100;
49     bool ret = config->SetLogFileMaxNumber(input);
50     if (ret) {
51         int output = config->GetLogFileMaxNumber();
52         EXPECT_EQ(true, input == output);
53     }
54     GTEST_LOG_(INFO) << "FaultLoggerConfigTest001: end.";
55 }
56 
57 /**
58  * @tc.name: FaultLoggerConfigTest002
59  * @tc.desc: test get file max size
60  * @tc.type: FUNC
61  */
62 HWTEST_F (FaultLoggerConfigTest, FaultLoggerConfigTest002, TestSize.Level2)
63 {
64     GTEST_LOG_(INFO) << "FaultLoggerConfigTest002: start.";
65     std::shared_ptr<FaultLoggerConfig> config = std::make_shared<FaultLoggerConfig>(LOG_FILE_NUMBER, LOG_FILE_SIZE,
66         LOG_FILE_PATH, DEBUG_LOG_FILE_PATH);
67     long input = 100;
68     bool ret = config->SetLogFileMaxSize(input);
69     if (ret) {
70         long output = config->GetLogFileMaxSize();
71         EXPECT_EQ(true, input == output);
72     }
73     GTEST_LOG_(INFO) << "FaultLoggerConfigTest002: end.";
74 }
75 
76 /**
77  * @tc.name: FaultLoggerConfigTest003
78  * @tc.desc: test get file path
79  * @tc.type: FUNC
80  */
81 HWTEST_F (FaultLoggerConfigTest, FaultLoggerConfigTest003, TestSize.Level2)
82 {
83     GTEST_LOG_(INFO) << "FaultLoggerConfigTest003: start.";
84     std::shared_ptr<FaultLoggerConfig> config = std::make_shared<FaultLoggerConfig>(LOG_FILE_NUMBER, LOG_FILE_SIZE,
85         LOG_FILE_PATH, DEBUG_LOG_FILE_PATH);
86     std::string input = "/data/log.txt";
87     bool ret = config->SetLogFilePath(input);
88     if (ret) {
89         std::string output = config->GetLogFilePath();
90         EXPECT_EQ(true, input == output);
91     }
92     GTEST_LOG_(INFO) << "FaultLoggerConfigTest003: end.";
93 }
94 
95 /**
96  * @tc.name: FaultLoggerConfigTest004
97  * @tc.desc: test get debug file path
98  * @tc.type: FUNC
99  */
100 HWTEST_F (FaultLoggerConfigTest, FaultLoggerConfigTest004, TestSize.Level2)
101 {
102     GTEST_LOG_(INFO) << "FaultLoggerConfigTest004: start.";
103     std::shared_ptr<FaultLoggerConfig> config = std::make_shared<FaultLoggerConfig>(LOG_FILE_NUMBER, LOG_FILE_SIZE,
104         LOG_FILE_PATH, DEBUG_LOG_FILE_PATH);
105     std::string input = "/data/debug/log.txt";
106     bool ret = config->SetDebugLogFilePath(input);
107     if (ret) {
108         std::string output = config->GetDebugLogFilePath();
109         EXPECT_EQ(true, input == output);
110     }
111     GTEST_LOG_(INFO) << "FaultLoggerConfigTest004: end.";
112 }
113