James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 1 | // Copyright (c) 2021, Google Inc. |
| 2 | // All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are |
| 6 | // met: |
| 7 | // |
| 8 | // * Redistributions of source code must retain the above copyright |
| 9 | // notice, this list of conditions and the following disclaimer. |
| 10 | // * Redistributions in binary form must reproduce the above |
| 11 | // copyright notice, this list of conditions and the following disclaimer |
| 12 | // in the documentation and/or other materials provided with the |
| 13 | // distribution. |
| 14 | // * Neither the name of Google Inc. nor the names of its |
| 15 | // contributors may be used to endorse or promote products derived from |
| 16 | // this software without specific prior written permission. |
| 17 | // |
| 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | |
| 30 | #include <glog/logging.h> |
| 31 | #include <glog/raw_logging.h> |
| 32 | |
| 33 | #include "base/commandlineflags.h" |
| 34 | #include "googletest.h" |
| 35 | |
| 36 | #ifdef HAVE_LIB_GFLAGS |
| 37 | #include <gflags/gflags.h> |
| 38 | using namespace GFLAGS_NAMESPACE; |
| 39 | #endif |
| 40 | |
| 41 | #ifdef HAVE_LIB_GMOCK |
| 42 | #include <gmock/gmock.h> |
| 43 | |
| 44 | #include "mock-log.h" |
| 45 | // Introduce several symbols from gmock. |
| 46 | using GOOGLE_NAMESPACE::glog_testing::ScopedMockLog; |
| 47 | using testing::_; |
| 48 | using testing::AllOf; |
| 49 | using testing::AnyNumber; |
| 50 | using testing::HasSubstr; |
| 51 | using testing::InitGoogleMock; |
| 52 | using testing::StrictMock; |
| 53 | using testing::StrNe; |
| 54 | #endif |
| 55 | |
| 56 | using namespace GOOGLE_NAMESPACE; |
| 57 | |
| 58 | TEST(CleanImmediatelyWithRelativePrefix, logging) { |
| 59 | google::EnableLogCleaner(0); |
| 60 | google::SetLogFilenameExtension(".relativefoo"); |
| 61 | google::SetLogDestination(GLOG_INFO, "test_subdir/test_cleanup_"); |
| 62 | |
| 63 | for (unsigned i = 0; i < 1000; ++i) { |
| 64 | LOG(INFO) << "cleanup test"; |
| 65 | } |
| 66 | |
| 67 | google::DisableLogCleaner(); |
| 68 | } |
| 69 | |
| 70 | int main(int argc, char **argv) { |
| 71 | FLAGS_colorlogtostderr = false; |
| 72 | FLAGS_timestamp_in_logfile_name = true; |
| 73 | #ifdef HAVE_LIB_GFLAGS |
| 74 | ParseCommandLineFlags(&argc, &argv, true); |
| 75 | #endif |
| 76 | // Make sure stderr is not buffered as stderr seems to be buffered |
| 77 | // on recent windows. |
| 78 | setbuf(stderr, NULL); |
| 79 | |
| 80 | // Test some basics before InitGoogleLogging: |
| 81 | CaptureTestStderr(); |
| 82 | const string early_stderr = GetCapturedTestStderr(); |
| 83 | |
| 84 | EXPECT_FALSE(IsGoogleLoggingInitialized()); |
| 85 | |
| 86 | InitGoogleLogging(argv[0]); |
| 87 | |
| 88 | EXPECT_TRUE(IsGoogleLoggingInitialized()); |
| 89 | |
| 90 | InitGoogleTest(&argc, argv); |
| 91 | #ifdef HAVE_LIB_GMOCK |
| 92 | InitGoogleMock(&argc, argv); |
| 93 | #endif |
| 94 | |
| 95 | // so that death tests run before we use threads |
| 96 | CHECK_EQ(RUN_ALL_TESTS(), 0); |
| 97 | } |