1800b99b8Sopenharmony_ci/*
2800b99b8Sopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3800b99b8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4800b99b8Sopenharmony_ci * you may not use this file except in compliance with the License.
5800b99b8Sopenharmony_ci * You may obtain a copy of the License at
6800b99b8Sopenharmony_ci *
7800b99b8Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8800b99b8Sopenharmony_ci *
9800b99b8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10800b99b8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11800b99b8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12800b99b8Sopenharmony_ci * See the License for the specific language governing permissions and
13800b99b8Sopenharmony_ci * limitations under the License.
14800b99b8Sopenharmony_ci */
15800b99b8Sopenharmony_ci
16800b99b8Sopenharmony_ci#include <gtest/gtest.h>
17800b99b8Sopenharmony_ci#include "fault_logger_config.h"
18800b99b8Sopenharmony_ci
19800b99b8Sopenharmony_ci#include <memory>
20800b99b8Sopenharmony_ci#include <string>
21800b99b8Sopenharmony_ci
22800b99b8Sopenharmony_ciusing namespace OHOS::HiviewDFX;
23800b99b8Sopenharmony_ciusing namespace testing::ext;
24800b99b8Sopenharmony_ciusing namespace std;
25800b99b8Sopenharmony_ci
26800b99b8Sopenharmony_cinamespace OHOS {
27800b99b8Sopenharmony_cinamespace HiviewDFX {
28800b99b8Sopenharmony_ciclass FaultLoggerConfigTest : public testing::Test {
29800b99b8Sopenharmony_cipublic:
30800b99b8Sopenharmony_ci    static void SetUpTestCase(void) {}
31800b99b8Sopenharmony_ci    static void TearDownTestCase(void) {}
32800b99b8Sopenharmony_ci    void SetUp() {}
33800b99b8Sopenharmony_ci    void TearDown() {}
34800b99b8Sopenharmony_ci};
35800b99b8Sopenharmony_ci} // namespace HiviewDFX
36800b99b8Sopenharmony_ci} // namespace OHOS
37800b99b8Sopenharmony_ci
38800b99b8Sopenharmony_ci/** FaultLoggerConfigTest001
39800b99b8Sopenharmony_ci * @tc.name: DfxMapsRequestTest033
40800b99b8Sopenharmony_ci * @tc.desc: test get file max number
41800b99b8Sopenharmony_ci * @tc.type: FUNC
42800b99b8Sopenharmony_ci */
43800b99b8Sopenharmony_ciHWTEST_F (FaultLoggerConfigTest, FaultLoggerConfigTest001, TestSize.Level2)
44800b99b8Sopenharmony_ci{
45800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "FaultLoggerConfigTest001: start.";
46800b99b8Sopenharmony_ci    std::shared_ptr<FaultLoggerConfig> config = std::make_shared<FaultLoggerConfig>(LOG_FILE_NUMBER, LOG_FILE_SIZE,
47800b99b8Sopenharmony_ci        LOG_FILE_PATH, DEBUG_LOG_FILE_PATH);
48800b99b8Sopenharmony_ci    int input = 100;
49800b99b8Sopenharmony_ci    bool ret = config->SetLogFileMaxNumber(input);
50800b99b8Sopenharmony_ci    if (ret) {
51800b99b8Sopenharmony_ci        int output = config->GetLogFileMaxNumber();
52800b99b8Sopenharmony_ci        EXPECT_EQ(true, input == output);
53800b99b8Sopenharmony_ci    }
54800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "FaultLoggerConfigTest001: end.";
55800b99b8Sopenharmony_ci}
56800b99b8Sopenharmony_ci
57800b99b8Sopenharmony_ci/**
58800b99b8Sopenharmony_ci * @tc.name: FaultLoggerConfigTest002
59800b99b8Sopenharmony_ci * @tc.desc: test get file max size
60800b99b8Sopenharmony_ci * @tc.type: FUNC
61800b99b8Sopenharmony_ci */
62800b99b8Sopenharmony_ciHWTEST_F (FaultLoggerConfigTest, FaultLoggerConfigTest002, TestSize.Level2)
63800b99b8Sopenharmony_ci{
64800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "FaultLoggerConfigTest002: start.";
65800b99b8Sopenharmony_ci    std::shared_ptr<FaultLoggerConfig> config = std::make_shared<FaultLoggerConfig>(LOG_FILE_NUMBER, LOG_FILE_SIZE,
66800b99b8Sopenharmony_ci        LOG_FILE_PATH, DEBUG_LOG_FILE_PATH);
67800b99b8Sopenharmony_ci    long input = 100;
68800b99b8Sopenharmony_ci    bool ret = config->SetLogFileMaxSize(input);
69800b99b8Sopenharmony_ci    if (ret) {
70800b99b8Sopenharmony_ci        long output = config->GetLogFileMaxSize();
71800b99b8Sopenharmony_ci        EXPECT_EQ(true, input == output);
72800b99b8Sopenharmony_ci    }
73800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "FaultLoggerConfigTest002: end.";
74800b99b8Sopenharmony_ci}
75800b99b8Sopenharmony_ci
76800b99b8Sopenharmony_ci/**
77800b99b8Sopenharmony_ci * @tc.name: FaultLoggerConfigTest003
78800b99b8Sopenharmony_ci * @tc.desc: test get file path
79800b99b8Sopenharmony_ci * @tc.type: FUNC
80800b99b8Sopenharmony_ci */
81800b99b8Sopenharmony_ciHWTEST_F (FaultLoggerConfigTest, FaultLoggerConfigTest003, TestSize.Level2)
82800b99b8Sopenharmony_ci{
83800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "FaultLoggerConfigTest003: start.";
84800b99b8Sopenharmony_ci    std::shared_ptr<FaultLoggerConfig> config = std::make_shared<FaultLoggerConfig>(LOG_FILE_NUMBER, LOG_FILE_SIZE,
85800b99b8Sopenharmony_ci        LOG_FILE_PATH, DEBUG_LOG_FILE_PATH);
86800b99b8Sopenharmony_ci    std::string input = "/data/log.txt";
87800b99b8Sopenharmony_ci    bool ret = config->SetLogFilePath(input);
88800b99b8Sopenharmony_ci    if (ret) {
89800b99b8Sopenharmony_ci        std::string output = config->GetLogFilePath();
90800b99b8Sopenharmony_ci        EXPECT_EQ(true, input == output);
91800b99b8Sopenharmony_ci    }
92800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "FaultLoggerConfigTest003: end.";
93800b99b8Sopenharmony_ci}
94