1 /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * Copyright 2018 Couchbase, Inc 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 #pragma once 18 19 // Spdlog includes it's own portability code (details/os.h) to allow it to run 20 // on multiple platforms, notably it includes <io.h>. This leads to ambiguous 21 // symbol declarations when we come to include folly's GTest.h as it includes 22 // it's own portability header Unistd.h. Include folly's portability code before 23 // anything else to fix this. 24 #include <folly/portability/GTest.h> 25 26 #include "logger.h" 27 #include "logger_config.h" 28 29 #include <platform/dirutils.h> 30 31 #include <boost/optional.hpp> 32 33 class SpdloggerTest : virtual public ::testing::Test { 34 protected: 35 SpdloggerTest(); 36 37 /* 38 * Unset a few environment variables which affect how the logger works. 39 * unsetenv() is not supported on Windows. 40 */ 41 #ifndef WIN32 42 SetUpTestCase()43 static void SetUpTestCase() { 44 unsetenv("CB_MAXIMIZE_LOGGER_CYCLE_SIZE"); 45 unsetenv("CB_MAXIMIZE_LOGGER_BUFFER_SIZE"); 46 } 47 48 #endif 49 50 void SetUp() override; 51 void TearDown() override; 52 53 /** 54 * Helper function - initializes a cb logger object using the 'config' 55 * member variable. 56 */ 57 virtual void setUpLogger(); 58 59 /** 60 * Helper function - removes the files in the test working directory that 61 * are prefixed with the given filename 62 */ 63 void RemoveFiles(); 64 65 /** 66 * Helper function - counts how many times a string appears in a file. 67 * 68 * @param file the name of the file 69 * @param msg the message to search for 70 * @return the number of times we found the message in the file 71 */ 72 static int countInFile(const std::string& file, const std::string& msg); 73 74 std::string getLogContents(); 75 76 std::vector<std::string> files; 77 78 cb::logger::Config config; 79 80 const std::string openingHook = "---------- Opening logfile: "; 81 const std::string closingHook = "---------- Closing logfile"; 82 }; 83