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