cleanup_with_absolute_prefix_unittest.cc
Go to the documentation of this file.
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;
53 using testing::StrNe;
54 #endif
55 
56 using namespace GOOGLE_NAMESPACE;
57 
58 TEST(CleanImmediatelyWithAbsolutePrefix, logging) {
61  google::SetLogDestination(GLOG_INFO, "test_cleanup_");
62 
63  for (unsigned i = 0; i < 1000; ++i) {
64  LOG(INFO) << "cleanup test";
65  }
66 
67  for (unsigned i = 0; i < 10; ++i) {
68  LOG(ERROR) << "cleanup test";
69  }
70 
72 }
73 
74 int main(int argc, char **argv) {
75  FLAGS_colorlogtostderr = false;
76  FLAGS_timestamp_in_logfile_name = true;
77 #ifdef HAVE_LIB_GFLAGS
78  ParseCommandLineFlags(&argc, &argv, true);
79 #endif
80  // Make sure stderr is not buffered as stderr seems to be buffered
81  // on recent windows.
82  setbuf(stderr, NULL);
83 
84  // Test some basics before InitGoogleLogging:
86  const string early_stderr = GetCapturedTestStderr();
87 
89 
90  InitGoogleLogging(argv[0]);
91 
93 
94  InitGoogleTest(&argc, argv);
95 #ifdef HAVE_LIB_GMOCK
96  InitGoogleMock(&argc, argv);
97 #endif
98 
99  // so that death tests run before we use threads
100  CHECK_EQ(RUN_ALL_TESTS(), 0);
101 }
testing::StrictMock
Definition: gmock-nice-strict.h:148
testing::InitGoogleMock
GTEST_API_ void InitGoogleMock(int *argc, char **argv)
Definition: gmock.cc:191
INFO
const int INFO
Definition: log_severity.h:59
main
int main(int argc, char **argv)
Definition: cleanup_with_absolute_prefix_unittest.cc:74
NULL
NULL
Definition: test_security_zap.cpp:405
ERROR
const int ERROR
Definition: log_severity.h:60
GLOG_INFO
const int GLOG_INFO
Definition: log_severity.h:53
InitGoogleTest
_START_GOOGLE_NAMESPACE_ void InitGoogleTest(int *, char **)
Definition: glog/src/googletest.h:124
gmock.h
EnableLogCleaner
void EnableLogCleaner(unsigned int overdue_days)
Definition: logging.cc:2639
google::protobuf.internal
Definition: python/google/protobuf/internal/__init__.py:1
GetCapturedTestStderr
static string GetCapturedTestStderr()
Definition: glog/src/googletest.h:411
gmock_output_test._
_
Definition: gmock_output_test.py:173
googletest.h
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: gtest.h:2502
EXPECT_TRUE
#define EXPECT_TRUE(cond)
Definition: glog/src/googletest.h:137
CaptureTestStderr
static void CaptureTestStderr()
Definition: glog/src/googletest.h:359
commandlineflags.h
TEST
TEST(CleanImmediatelyWithAbsolutePrefix, logging)
Definition: cleanup_with_absolute_prefix_unittest.cc:58
i
int i
Definition: gmock-matchers_test.cc:764
DisableLogCleaner
void DisableLogCleaner()
Definition: logging.cc:2643
LOG
#define LOG(x)
Definition: sdk/include/aditof/log.h:72
IsGoogleLoggingInitialized
bool IsGoogleLoggingInitialized()
Definition: utilities.cc:69
EXPECT_FALSE
#define EXPECT_FALSE(cond)
Definition: glog/src/googletest.h:145
SetLogDestination
void SetLogDestination(LogSeverity severity, const char *base_filename)
Definition: logging.cc:2067
mock-log.h
testing::AnyNumber
GTEST_API_ Cardinality AnyNumber()
Definition: gmock-cardinalities.cc:145
benchmark::internal::ParseCommandLineFlags
void ParseCommandLineFlags(int *argc, char **argv)
Definition: benchmark.cc:655
CHECK_EQ
#define CHECK_EQ(a, b)
Definition: check.h:65
SetLogFilenameExtension
void SetLogFilenameExtension(const char *ext)
Definition: logging.cc:2146
InitGoogleLogging
void InitGoogleLogging(const char *argv0)
Definition: logging.cc:2618


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:48