1 // Copyright (c) 2007, Google Inc.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
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
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.
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.
30 // Author: Zhanyong Wan
32 // Tests the ScopedMockLog class.
38 #include <gmock/gmock.h>
39 #include <gtest/gtest.h>
43 using GOOGLE_NAMESPACE::INFO;
44 using GOOGLE_NAMESPACE::WARNING;
45 using GOOGLE_NAMESPACE::ERROR;
46 using GOOGLE_NAMESPACE::glog_testing::ScopedMockLog;
49 using testing::HasSubstr;
50 using testing::InSequence;
51 using testing::InvokeWithoutArgs;
53 // Tests that ScopedMockLog intercepts LOG()s when it's alive.
54 TEST(ScopedMockLogTest, InterceptsLog) {
58 EXPECT_CALL(log, Log(WARNING, HasSubstr("/mock-log_test.cc"), "Fishy."));
59 EXPECT_CALL(log, Log(INFO, _, "Working..."))
61 EXPECT_CALL(log, Log(ERROR, _, "Bad!!"));
63 LOG(WARNING) << "Fishy.";
64 LOG(INFO) << "Working...";
65 LOG(INFO) << "Working...";
66 LOG(ERROR) << "Bad!!";
70 LOG(INFO) << "Logging a branch...";
74 LOG(INFO) << "Logging the whole tree...";
78 LOG(INFO) << "Logging the entire forest.";
79 LOG(INFO) << "Logging the entire forest..";
80 LOG(INFO) << "Logging the entire forest...";
83 // The purpose of the following test is to verify that intercepting logging
84 // continues to work properly if a LOG statement is executed within the scope
86 TEST(ScopedMockLogTest, LogDuringIntercept) {
89 EXPECT_CALL(log, Log(INFO, __FILE__, "Logging a branch..."))
90 .WillOnce(InvokeWithoutArgs(LogTree));
91 EXPECT_CALL(log, Log(INFO, __FILE__, "Logging the whole tree..."))
92 .WillOnce(InvokeWithoutArgs(LogForest));
93 EXPECT_CALL(log, Log(INFO, __FILE__, "Logging the entire forest."));
94 EXPECT_CALL(log, Log(INFO, __FILE__, "Logging the entire forest.."));
95 EXPECT_CALL(log, Log(INFO, __FILE__, "Logging the entire forest..."));
101 int main(int argc, char **argv) {
102 GOOGLE_NAMESPACE::InitGoogleLogging(argv[0]);
103 testing::InitGoogleMock(&argc, argv);
105 return RUN_ALL_TESTS();