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 22using namespace OHOS::HiviewDFX; 23using namespace testing::ext; 24using namespace std; 25 26namespace OHOS { 27namespace HiviewDFX { 28class FaultLoggerConfigTest : public testing::Test { 29public: 30 static void SetUpTestCase(void) {} 31 static void TearDownTestCase(void) {} 32 void SetUp() {} 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 */ 43HWTEST_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 */ 62HWTEST_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 */ 81HWTEST_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