blob: b678a9e55f01b532653a12abd5486dc37360a738 [file] [log] [blame]
shiqiane35fdd92008-12-10 05:08:54 +00001// Copyright 2007, 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// Author: wan@google.com (Zhanyong Wan)
31
32// Google Mock - a framework for writing C++ mock classes.
33//
34// This file tests the internal utilities.
35
36#include <gmock/internal/gmock-internal-utils.h>
37#include <map>
38#include <string>
39#include <sstream>
40#include <vector>
41#include <gmock/gmock.h>
42#include <gmock/internal/gmock-port.h>
43#include <gtest/gtest.h>
44#include <gtest/gtest-spi.h>
45
46namespace testing {
47namespace internal {
48
49namespace {
50
51using ::std::tr1::tuple;
52
zhanyong.wance198ff2009-02-12 01:34:27 +000053TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsNoWord) {
54 EXPECT_EQ("", ConvertIdentifierNameToWords(""));
55 EXPECT_EQ("", ConvertIdentifierNameToWords("_"));
56 EXPECT_EQ("", ConvertIdentifierNameToWords("__"));
57}
58
59TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsDigits) {
60 EXPECT_EQ("1", ConvertIdentifierNameToWords("_1"));
61 EXPECT_EQ("2", ConvertIdentifierNameToWords("2_"));
62 EXPECT_EQ("34", ConvertIdentifierNameToWords("_34_"));
63 EXPECT_EQ("34 56", ConvertIdentifierNameToWords("_34_56"));
64}
65
66TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsCamelCaseWords) {
67 EXPECT_EQ("a big word", ConvertIdentifierNameToWords("ABigWord"));
68 EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("FooBar"));
69 EXPECT_EQ("foo", ConvertIdentifierNameToWords("Foo_"));
70 EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("_Foo_Bar_"));
71 EXPECT_EQ("foo and bar", ConvertIdentifierNameToWords("_Foo__And_Bar"));
72}
73
74TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContains_SeparatedWords) {
75 EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("foo_bar"));
76 EXPECT_EQ("foo", ConvertIdentifierNameToWords("_foo_"));
77 EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("_foo_bar_"));
78 EXPECT_EQ("foo and bar", ConvertIdentifierNameToWords("_foo__and_bar"));
79}
80
81TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) {
82 EXPECT_EQ("foo bar 123", ConvertIdentifierNameToWords("Foo_bar123"));
83 EXPECT_EQ("chapter 11 section 1",
84 ConvertIdentifierNameToWords("_Chapter11Section_1_"));
85}
86
shiqiane35fdd92008-12-10 05:08:54 +000087// Tests that CompileAssertTypesEqual compiles when the type arguments are
88// equal.
89TEST(CompileAssertTypesEqual, CompilesWhenTypesAreEqual) {
90 CompileAssertTypesEqual<void, void>();
91 CompileAssertTypesEqual<int*, int*>();
92}
93
94// Tests that RemoveReference does not affect non-reference types.
95TEST(RemoveReferenceTest, DoesNotAffectNonReferenceType) {
96 CompileAssertTypesEqual<int, RemoveReference<int>::type>();
97 CompileAssertTypesEqual<const char, RemoveReference<const char>::type>();
98}
99
100// Tests that RemoveReference removes reference from reference types.
101TEST(RemoveReferenceTest, RemovesReference) {
102 CompileAssertTypesEqual<int, RemoveReference<int&>::type>();
103 CompileAssertTypesEqual<const char, RemoveReference<const char&>::type>();
104}
105
zhanyong.wane0d051e2009-02-19 00:33:37 +0000106// Tests GMOCK_REMOVE_REFERENCE_.
shiqiane35fdd92008-12-10 05:08:54 +0000107
108template <typename T1, typename T2>
109void TestGMockRemoveReference() {
zhanyong.wane0d051e2009-02-19 00:33:37 +0000110 CompileAssertTypesEqual<T1, GMOCK_REMOVE_REFERENCE_(T2)>();
shiqiane35fdd92008-12-10 05:08:54 +0000111}
112
113TEST(RemoveReferenceTest, MacroVersion) {
114 TestGMockRemoveReference<int, int>();
115 TestGMockRemoveReference<const char, const char&>();
116}
117
118
119// Tests that RemoveConst does not affect non-const types.
120TEST(RemoveConstTest, DoesNotAffectNonConstType) {
121 CompileAssertTypesEqual<int, RemoveConst<int>::type>();
122 CompileAssertTypesEqual<char&, RemoveConst<char&>::type>();
123}
124
125// Tests that RemoveConst removes const from const types.
126TEST(RemoveConstTest, RemovesConst) {
127 CompileAssertTypesEqual<int, RemoveConst<const int>::type>();
128}
129
zhanyong.wane0d051e2009-02-19 00:33:37 +0000130// Tests GMOCK_REMOVE_CONST_.
shiqiane35fdd92008-12-10 05:08:54 +0000131
132template <typename T1, typename T2>
133void TestGMockRemoveConst() {
zhanyong.wane0d051e2009-02-19 00:33:37 +0000134 CompileAssertTypesEqual<T1, GMOCK_REMOVE_CONST_(T2)>();
shiqiane35fdd92008-12-10 05:08:54 +0000135}
136
137TEST(RemoveConstTest, MacroVersion) {
138 TestGMockRemoveConst<int, int>();
139 TestGMockRemoveConst<double&, double&>();
140 TestGMockRemoveConst<char, const char>();
141}
142
143// Tests that AddReference does not affect reference types.
144TEST(AddReferenceTest, DoesNotAffectReferenceType) {
145 CompileAssertTypesEqual<int&, AddReference<int&>::type>();
146 CompileAssertTypesEqual<const char&, AddReference<const char&>::type>();
147}
148
149// Tests that AddReference adds reference to non-reference types.
150TEST(AddReferenceTest, AddsReference) {
151 CompileAssertTypesEqual<int&, AddReference<int>::type>();
152 CompileAssertTypesEqual<const char&, AddReference<const char>::type>();
153}
154
zhanyong.wane0d051e2009-02-19 00:33:37 +0000155// Tests GMOCK_ADD_REFERENCE_.
shiqiane35fdd92008-12-10 05:08:54 +0000156
157template <typename T1, typename T2>
158void TestGMockAddReference() {
zhanyong.wane0d051e2009-02-19 00:33:37 +0000159 CompileAssertTypesEqual<T1, GMOCK_ADD_REFERENCE_(T2)>();
shiqiane35fdd92008-12-10 05:08:54 +0000160}
161
162TEST(AddReferenceTest, MacroVersion) {
163 TestGMockAddReference<int&, int>();
164 TestGMockAddReference<const char&, const char&>();
165}
166
zhanyong.wane0d051e2009-02-19 00:33:37 +0000167// Tests GMOCK_REFERENCE_TO_CONST_.
shiqiane35fdd92008-12-10 05:08:54 +0000168
169template <typename T1, typename T2>
170void TestGMockReferenceToConst() {
zhanyong.wane0d051e2009-02-19 00:33:37 +0000171 CompileAssertTypesEqual<T1, GMOCK_REFERENCE_TO_CONST_(T2)>();
shiqiane35fdd92008-12-10 05:08:54 +0000172}
173
174TEST(GMockReferenceToConstTest, Works) {
175 TestGMockReferenceToConst<const char&, char>();
176 TestGMockReferenceToConst<const int&, const int>();
177 TestGMockReferenceToConst<const double&, double>();
178 TestGMockReferenceToConst<const string&, const string&>();
179}
180
181TEST(PointeeOfTest, WorksForSmartPointers) {
182 CompileAssertTypesEqual<const char,
183 PointeeOf<internal::linked_ptr<const char> >::type>();
184}
185
186TEST(PointeeOfTest, WorksForRawPointers) {
187 CompileAssertTypesEqual<int, PointeeOf<int*>::type>();
188 CompileAssertTypesEqual<const char, PointeeOf<const char*>::type>();
189 CompileAssertTypesEqual<void, PointeeOf<void*>::type>();
190}
191
192TEST(GetRawPointerTest, WorksForSmartPointers) {
193 const char* const raw_p4 = new const char('a'); // NOLINT
194 const internal::linked_ptr<const char> p4(raw_p4);
195 EXPECT_EQ(raw_p4, GetRawPointer(p4));
196}
197
198TEST(GetRawPointerTest, WorksForRawPointers) {
199 int* p = NULL;
200 EXPECT_EQ(NULL, GetRawPointer(p));
201 int n = 1;
202 EXPECT_EQ(&n, GetRawPointer(&n));
203}
204
205class Base {};
206class Derived : public Base {};
207
208// Tests that ImplicitlyConvertible<T1, T2>::value is a compile-time constant.
209TEST(ImplicitlyConvertibleTest, ValueIsCompileTimeConstant) {
zhanyong.wane0d051e2009-02-19 00:33:37 +0000210 GMOCK_COMPILE_ASSERT_((ImplicitlyConvertible<int, int>::value), const_true);
211 GMOCK_COMPILE_ASSERT_((!ImplicitlyConvertible<void*, int*>::value),
212 const_false);
shiqiane35fdd92008-12-10 05:08:54 +0000213}
214
215// Tests that ImplicitlyConvertible<T1, T2>::value is true when T1 can
216// be implicitly converted to T2.
217TEST(ImplicitlyConvertibleTest, ValueIsTrueWhenConvertible) {
218 EXPECT_TRUE((ImplicitlyConvertible<int, double>::value));
219 EXPECT_TRUE((ImplicitlyConvertible<double, int>::value));
220 EXPECT_TRUE((ImplicitlyConvertible<int*, void*>::value));
221 EXPECT_TRUE((ImplicitlyConvertible<int*, const int*>::value));
222 EXPECT_TRUE((ImplicitlyConvertible<Derived&, const Base&>::value));
223 EXPECT_TRUE((ImplicitlyConvertible<const Base, Base>::value));
224}
225
226// Tests that ImplicitlyConvertible<T1, T2>::value is false when T1
227// cannot be implicitly converted to T2.
228TEST(ImplicitlyConvertibleTest, ValueIsFalseWhenNotConvertible) {
229 EXPECT_FALSE((ImplicitlyConvertible<double, int*>::value));
230 EXPECT_FALSE((ImplicitlyConvertible<void*, int*>::value));
231 EXPECT_FALSE((ImplicitlyConvertible<const int*, int*>::value));
232 EXPECT_FALSE((ImplicitlyConvertible<Base&, Derived&>::value));
233}
234
235// Tests that IsAProtocolMessage<T>::value is a compile-time constant.
236TEST(IsAProtocolMessageTest, ValueIsCompileTimeConstant) {
zhanyong.wane0d051e2009-02-19 00:33:37 +0000237 GMOCK_COMPILE_ASSERT_(IsAProtocolMessage<ProtocolMessage>::value, const_true);
238 GMOCK_COMPILE_ASSERT_(!IsAProtocolMessage<int>::value, const_false);
shiqiane35fdd92008-12-10 05:08:54 +0000239}
240
241// Tests that IsAProtocolMessage<T>::value is true when T is
242// ProtocolMessage or a sub-class of it.
243TEST(IsAProtocolMessageTest, ValueIsTrueWhenTypeIsAProtocolMessage) {
244 EXPECT_TRUE(IsAProtocolMessage<ProtocolMessage>::value);
245#if GMOCK_HAS_PROTOBUF_
246 EXPECT_TRUE(IsAProtocolMessage<const TestMessage>::value);
247#endif // GMOCK_HAS_PROTOBUF_
248}
249
250// Tests that IsAProtocolMessage<T>::value is false when T is neither
251// ProtocolMessage nor a sub-class of it.
252TEST(IsAProtocolMessageTest, ValueIsFalseWhenTypeIsNotAProtocolMessage) {
253 EXPECT_FALSE(IsAProtocolMessage<int>::value);
254 EXPECT_FALSE(IsAProtocolMessage<const Base>::value);
255}
256
257// Tests IsContainerTest.
258
259class NonContainer {};
260
261TEST(IsContainerTestTest, WorksForNonContainer) {
262 EXPECT_EQ(sizeof(IsNotContainer), sizeof(IsContainerTest<int>(0)));
263 EXPECT_EQ(sizeof(IsNotContainer), sizeof(IsContainerTest<char[5]>(0)));
264 EXPECT_EQ(sizeof(IsNotContainer), sizeof(IsContainerTest<NonContainer>(0)));
265}
266
267TEST(IsContainerTestTest, WorksForContainer) {
268 EXPECT_EQ(sizeof(IsContainer), sizeof(IsContainerTest<std::vector<bool> >(0)));
269 EXPECT_EQ(sizeof(IsContainer), sizeof(IsContainerTest<std::map<int, double> >(0)));
270}
271
272// Tests the TupleMatches() template function.
273
274TEST(TupleMatchesTest, WorksForSize0) {
275 tuple<> matchers;
276 tuple<> values;
277
278 EXPECT_TRUE(TupleMatches(matchers, values));
279}
280
281TEST(TupleMatchesTest, WorksForSize1) {
282 tuple<Matcher<int> > matchers(Eq(1));
283 tuple<int> values1(1),
284 values2(2);
285
286 EXPECT_TRUE(TupleMatches(matchers, values1));
287 EXPECT_FALSE(TupleMatches(matchers, values2));
288}
289
290TEST(TupleMatchesTest, WorksForSize2) {
291 tuple<Matcher<int>, Matcher<char> > matchers(Eq(1), Eq('a'));
292 tuple<int, char> values1(1, 'a'),
293 values2(1, 'b'),
294 values3(2, 'a'),
295 values4(2, 'b');
296
297 EXPECT_TRUE(TupleMatches(matchers, values1));
298 EXPECT_FALSE(TupleMatches(matchers, values2));
299 EXPECT_FALSE(TupleMatches(matchers, values3));
300 EXPECT_FALSE(TupleMatches(matchers, values4));
301}
302
303TEST(TupleMatchesTest, WorksForSize5) {
304 tuple<Matcher<int>, Matcher<char>, Matcher<bool>, Matcher<long>, // NOLINT
305 Matcher<string> >
306 matchers(Eq(1), Eq('a'), Eq(true), Eq(2L), Eq("hi"));
307 tuple<int, char, bool, long, string> // NOLINT
308 values1(1, 'a', true, 2L, "hi"),
309 values2(1, 'a', true, 2L, "hello"),
310 values3(2, 'a', true, 2L, "hi");
311
312 EXPECT_TRUE(TupleMatches(matchers, values1));
313 EXPECT_FALSE(TupleMatches(matchers, values2));
314 EXPECT_FALSE(TupleMatches(matchers, values3));
315}
316
317// Tests that Assert(true, ...) succeeds.
318TEST(AssertTest, SucceedsOnTrue) {
319 Assert(true, __FILE__, __LINE__, "This should succeed.");
320 Assert(true, __FILE__, __LINE__); // This should succeed too.
321}
322
zhanyong.wan652540a2009-02-23 23:37:29 +0000323#if GTEST_HAS_DEATH_TEST
shiqiane35fdd92008-12-10 05:08:54 +0000324
325// Tests that Assert(false, ...) generates a fatal failure.
326TEST(AssertTest, FailsFatallyOnFalse) {
327 EXPECT_DEATH({ // NOLINT
328 Assert(false, __FILE__, __LINE__, "This should fail.");
329 }, "");
330
331 EXPECT_DEATH({ // NOLINT
332 Assert(false, __FILE__, __LINE__);
333 }, "");
334}
335
336#endif // GTEST_HAS_DEATH_TEST
337
338// Tests that Expect(true, ...) succeeds.
339TEST(ExpectTest, SucceedsOnTrue) {
340 Expect(true, __FILE__, __LINE__, "This should succeed.");
341 Expect(true, __FILE__, __LINE__); // This should succeed too.
342}
343
344// Tests that Expect(false, ...) generates a non-fatal failure.
345TEST(ExpectTest, FailsNonfatallyOnFalse) {
346 EXPECT_NONFATAL_FAILURE({ // NOLINT
347 Expect(false, __FILE__, __LINE__, "This should fail.");
348 }, "This should fail");
349
350 EXPECT_NONFATAL_FAILURE({ // NOLINT
351 Expect(false, __FILE__, __LINE__);
352 }, "Expectation failed");
353}
354
355// TODO(wan@google.com): find a way to re-enable these tests.
356#if 0
357
358// Tests the Log() function.
359
360// Verifies that Log() behaves correctly for the given verbosity level
361// and log severity.
362void TestLogWithSeverity(const string& verbosity, LogSeverity severity,
363 bool should_print) {
364 const string old_flag = GMOCK_FLAG(verbose);
365 GMOCK_FLAG(verbose) = verbosity;
366 CaptureTestStdout();
367 Log(severity, "Test log.\n", 0);
368 if (should_print) {
369 EXPECT_PRED2(RE::FullMatch,
370 GetCapturedTestStdout(),
371 severity == WARNING ?
372 "\nGMOCK WARNING:\nTest log\\.\nStack trace:\n[\\s\\S]*" :
373 "\nTest log\\.\nStack trace:\n[\\s\\S]*");
374 } else {
375 EXPECT_EQ("", GetCapturedTestStdout());
376 }
377 GMOCK_FLAG(verbose) = old_flag;
378}
379
380// Tests that when the stack_frames_to_skip parameter is negative,
381// Log() doesn't include the stack trace in the output.
382TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) {
383 GMOCK_FLAG(verbose) = kInfoVerbosity;
384 CaptureTestStdout();
385 Log(INFO, "Test log.\n", -1);
386 EXPECT_EQ("\nTest log.\n", GetCapturedTestStdout());
387}
388
389// Tests that in opt mode, a positive stack_frames_to_skip argument is
390// treated as 0.
391TEST(LogTest, NoSkippingStackFrameInOptMode) {
392 CaptureTestStdout();
393 Log(WARNING, "Test log.\n", 100);
394 const string log = GetCapturedTestStdout();
395#ifdef NDEBUG
396 // In opt mode, no stack frame should be skipped.
397 EXPECT_THAT(log, ContainsRegex("\nGMOCK WARNING:\n"
398 "Test log\\.\n"
399 "Stack trace:\n"
400 ".+"));
401#else
402 // In dbg mode, the stack frames should be skipped.
403 EXPECT_EQ("\nGMOCK WARNING:\n"
404 "Test log.\n"
405 "Stack trace:\n", log);
406#endif // NDEBUG
407}
408
409// Tests that all logs are printed when the value of the
410// --gmock_verbose flag is "info".
411TEST(LogTest, AllLogsArePrintedWhenVerbosityIsInfo) {
412 TestLogWithSeverity(kInfoVerbosity, INFO, true);
413 TestLogWithSeverity(kInfoVerbosity, WARNING, true);
414}
415
416// Tests that only warnings are printed when the value of the
417// --gmock_verbose flag is "warning".
418TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsWarning) {
419 TestLogWithSeverity(kWarningVerbosity, INFO, false);
420 TestLogWithSeverity(kWarningVerbosity, WARNING, true);
421}
422
423// Tests that no logs are printed when the value of the
424// --gmock_verbose flag is "error".
425TEST(LogTest, NoLogsArePrintedWhenVerbosityIsError) {
426 TestLogWithSeverity(kErrorVerbosity, INFO, false);
427 TestLogWithSeverity(kErrorVerbosity, WARNING, false);
428}
429
430// Tests that only warnings are printed when the value of the
431// --gmock_verbose flag is invalid.
432TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
433 TestLogWithSeverity("invalid", INFO, false);
434 TestLogWithSeverity("invalid", WARNING, true);
435}
436
437#endif // 0
438
439TEST(TypeTraitsTest, true_type) {
440 EXPECT_TRUE(true_type::value);
441}
442
443TEST(TypeTraitsTest, false_type) {
444 EXPECT_FALSE(false_type::value);
445}
446
447TEST(TypeTraitsTest, is_reference) {
448 EXPECT_FALSE(is_reference<int>::value);
449 EXPECT_FALSE(is_reference<char*>::value);
450 EXPECT_TRUE(is_reference<const int&>::value);
451}
452
453TEST(TypeTraitsTest, is_pointer) {
454 EXPECT_FALSE(is_pointer<int>::value);
455 EXPECT_FALSE(is_pointer<char&>::value);
456 EXPECT_TRUE(is_pointer<const int*>::value);
457}
458
459TEST(TypeTraitsTest, type_equals) {
460 EXPECT_FALSE((type_equals<int, const int>::value));
461 EXPECT_FALSE((type_equals<int, int&>::value));
462 EXPECT_FALSE((type_equals<int, double>::value));
463 EXPECT_TRUE((type_equals<char, char>::value));
464}
465
466TEST(TypeTraitsTest, remove_reference) {
467 EXPECT_TRUE((type_equals<char, remove_reference<char&>::type>::value));
468 EXPECT_TRUE((type_equals<const int,
469 remove_reference<const int&>::type>::value));
470 EXPECT_TRUE((type_equals<int, remove_reference<int>::type>::value));
471 EXPECT_TRUE((type_equals<double*, remove_reference<double*>::type>::value));
472}
473
474// TODO(wan@google.com): find a way to re-enable these tests.
475#if 0
476
477// Verifies that Log() behaves correctly for the given verbosity level
478// and log severity.
479string GrabOutput(void(*logger)(), const char* verbosity) {
480 const string saved_flag = GMOCK_FLAG(verbose);
481 GMOCK_FLAG(verbose) = verbosity;
482 CaptureTestStdout();
483 logger();
484 GMOCK_FLAG(verbose) = saved_flag;
485 return GetCapturedTestStdout();
486}
487
488class DummyMock {
489 public:
490 MOCK_METHOD0(TestMethod, void());
491 MOCK_METHOD1(TestMethodArg, void(int dummy));
492};
493
494void ExpectCallLogger() {
495 DummyMock mock;
496 EXPECT_CALL(mock, TestMethod());
497 mock.TestMethod();
498};
499
500// Verifies that EXPECT_CALL logs if the --gmock_verbose flag is set to "info".
501TEST(ExpectCallTest, LogsWhenVerbosityIsInfo) {
502 EXPECT_THAT(GrabOutput(ExpectCallLogger, kInfoVerbosity),
503 HasSubstr("EXPECT_CALL(mock, TestMethod())"));
504}
505
506// Verifies that EXPECT_CALL doesn't log
507// if the --gmock_verbose flag is set to "warning".
508TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsWarning) {
509 EXPECT_EQ("", GrabOutput(ExpectCallLogger, kWarningVerbosity));
510}
511
512// Verifies that EXPECT_CALL doesn't log
513// if the --gmock_verbose flag is set to "error".
514TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsError) {
515 EXPECT_EQ("", GrabOutput(ExpectCallLogger, kErrorVerbosity));
516}
517
518void OnCallLogger() {
519 DummyMock mock;
520 ON_CALL(mock, TestMethod());
521};
522
523// Verifies that ON_CALL logs if the --gmock_verbose flag is set to "info".
524TEST(OnCallTest, LogsWhenVerbosityIsInfo) {
525 EXPECT_THAT(GrabOutput(OnCallLogger, kInfoVerbosity),
526 HasSubstr("ON_CALL(mock, TestMethod())"));
527}
528
529// Verifies that ON_CALL doesn't log
530// if the --gmock_verbose flag is set to "warning".
531TEST(OnCallTest, DoesNotLogWhenVerbosityIsWarning) {
532 EXPECT_EQ("", GrabOutput(OnCallLogger, kWarningVerbosity));
533}
534
535// Verifies that ON_CALL doesn't log if
536// the --gmock_verbose flag is set to "error".
537TEST(OnCallTest, DoesNotLogWhenVerbosityIsError) {
538 EXPECT_EQ("", GrabOutput(OnCallLogger, kErrorVerbosity));
539}
540
541void OnCallAnyArgumentLogger() {
542 DummyMock mock;
543 ON_CALL(mock, TestMethodArg(_));
544}
545
546// Verifies that ON_CALL prints provided _ argument.
547TEST(OnCallTest, LogsAnythingArgument) {
548 EXPECT_THAT(GrabOutput(OnCallAnyArgumentLogger, kInfoVerbosity),
549 HasSubstr("ON_CALL(mock, TestMethodArg(_)"));
550}
551
552#endif // 0
553
554} // namespace
555} // namespace internal
556} // namespace testing