Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
gmock_output_test_.cc File Reference
#include "gmock/gmock.h"
#include <stdio.h>
#include <string>
#include "gtest/gtest.h"
Include dependency graph for gmock_output_test_.cc:

Go to the source code of this file.

Classes

class  MockFoo
 
class  GMockOutputTest
 

Functions

 TEST_F (GMockOutputTest, ExpectedCall)
 
 TEST_F (GMockOutputTest, ExpectedCallToVoidFunction)
 
 TEST_F (GMockOutputTest, ExplicitActionsRunOut)
 
 TEST_F (GMockOutputTest, UnexpectedCall)
 
 TEST_F (GMockOutputTest, UnexpectedCallToVoidFunction)
 
 TEST_F (GMockOutputTest, ExcessiveCall)
 
 TEST_F (GMockOutputTest, ExcessiveCallToVoidFunction)
 
 TEST_F (GMockOutputTest, UninterestingCall)
 
 TEST_F (GMockOutputTest, UninterestingCallToVoidFunction)
 
 TEST_F (GMockOutputTest, RetiredExpectation)
 
 TEST_F (GMockOutputTest, UnsatisfiedPrerequisite)
 
 TEST_F (GMockOutputTest, UnsatisfiedPrerequisites)
 
 TEST_F (GMockOutputTest, UnsatisfiedWith)
 
 TEST_F (GMockOutputTest, UnsatisfiedExpectation)
 
 TEST_F (GMockOutputTest, MismatchArguments)
 
 TEST_F (GMockOutputTest, MismatchWith)
 
 TEST_F (GMockOutputTest, MismatchArgumentsAndWith)
 
 TEST_F (GMockOutputTest, UnexpectedCallWithDefaultAction)
 
 TEST_F (GMockOutputTest, ExcessiveCallWithDefaultAction)
 
 TEST_F (GMockOutputTest, UninterestingCallWithDefaultAction)
 
 TEST_F (GMockOutputTest, ExplicitActionsRunOutWithDefaultAction)
 
 TEST_F (GMockOutputTest, CatchesLeakedMocks)
 
 MATCHER_P2 (IsPair, first, second, "")
 
 TEST_F (GMockOutputTest, PrintsMatcher)
 
void TestCatchesLeakedMocksInAdHocTests ()
 
int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 297 of file gmock_output_test_.cc.

297 {
299 // Ensures that the tests pass no matter what value of
300 // --gmock_catch_leaked_mocks and --gmock_verbose the user specifies.
301 testing::GMOCK_FLAG(catch_leaked_mocks) = true;
302 testing::GMOCK_FLAG(verbose) = "warning";
303
305 return RUN_ALL_TESTS();
306}
void TestCatchesLeakedMocksInAdHocTests()
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition gtest.h:2328
char ** argv
GTEST_API_ void InitGoogleMock(int *argc, char **argv)
Definition gmock.cc:195
Here is the call graph for this function:

◆ MATCHER_P2()

MATCHER_P2 ( IsPair ,
first ,
second ,
""  )

Definition at line 278 of file gmock_output_test_.cc.

278 {
279 return Value(arg.first, first) && Value(arg.second, second);
280}
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition document.h:2110

◆ TEST_F() [1/23]

TEST_F ( GMockOutputTest ,
CatchesLeakedMocks  )

Definition at line 261 of file gmock_output_test_.cc.

261 {
262 MockFoo* foo1 = new MockFoo;
263 MockFoo* foo2 = new MockFoo;
264
265 // Invokes ON_CALL on foo1.
266 ON_CALL(*foo1, Bar(_, _, _)).WillByDefault(Return('a'));
267
268 // Invokes EXPECT_CALL on foo2.
269 EXPECT_CALL(*foo2, Bar2(_, _));
270 EXPECT_CALL(*foo2, Bar2(1, _));
271 EXPECT_CALL(*foo2, Bar3(_, _)).Times(AnyNumber());
272 foo2->Bar2(2, 1);
273 foo2->Bar2(1, 1);
274
275 // Both foo1 and foo2 are deliberately leaked.
276}
#define EXPECT_CALL(obj, call)
#define ON_CALL(obj, call)

◆ TEST_F() [2/23]

TEST_F ( GMockOutputTest ,
ExcessiveCall  )

Definition at line 115 of file gmock_output_test_.cc.

115 {
116 EXPECT_CALL(foo_, Bar2(0, _));
117
118 foo_.Bar2(0, 0); // Expected call
119 foo_.Bar2(0, 1); // Excessive call
120}

◆ TEST_F() [3/23]

TEST_F ( GMockOutputTest ,
ExcessiveCallToVoidFunction  )

Definition at line 122 of file gmock_output_test_.cc.

122 {
123 EXPECT_CALL(foo_, Bar3(0, _));
124
125 foo_.Bar3(0, 0); // Expected call
126 foo_.Bar3(0, 1); // Excessive call
127}

◆ TEST_F() [4/23]

TEST_F ( GMockOutputTest ,
ExcessiveCallWithDefaultAction  )

Definition at line 225 of file gmock_output_test_.cc.

225 {
226 ON_CALL(foo_, Bar2(_, _))
227 .WillByDefault(Return(true)); // Default action #1
228 ON_CALL(foo_, Bar2(1, _))
229 .WillByDefault(Return(false)); // Default action #2
230
231 EXPECT_CALL(foo_, Bar2(2, 2));
232 EXPECT_CALL(foo_, Bar2(1, 1));
233
234 foo_.Bar2(2, 2); // Expected call.
235 foo_.Bar2(2, 2); // Excessive call, takes default action #1.
236 foo_.Bar2(1, 1); // Expected call.
237 foo_.Bar2(1, 1); // Excessive call, takes default action #2.
238}

◆ TEST_F() [5/23]

TEST_F ( GMockOutputTest ,
ExpectedCall  )

Definition at line 75 of file gmock_output_test_.cc.

75 {
76 testing::GMOCK_FLAG(verbose) = "info";
77
78 EXPECT_CALL(foo_, Bar2(0, _));
79 foo_.Bar2(0, 0); // Expected call
80
81 testing::GMOCK_FLAG(verbose) = "warning";
82}

◆ TEST_F() [6/23]

TEST_F ( GMockOutputTest ,
ExpectedCallToVoidFunction  )

Definition at line 84 of file gmock_output_test_.cc.

84 {
85 testing::GMOCK_FLAG(verbose) = "info";
86
87 EXPECT_CALL(foo_, Bar3(0, _));
88 foo_.Bar3(0, 0); // Expected call
89
90 testing::GMOCK_FLAG(verbose) = "warning";
91}

◆ TEST_F() [7/23]

TEST_F ( GMockOutputTest ,
ExplicitActionsRunOut  )

Definition at line 93 of file gmock_output_test_.cc.

93 {
94 EXPECT_CALL(foo_, Bar2(_, _))
95 .Times(2)
96 .WillOnce(Return(false));
97 foo_.Bar2(2, 2);
98 foo_.Bar2(1, 1); // Explicit actions in EXPECT_CALL run out.
99}

◆ TEST_F() [8/23]

TEST_F ( GMockOutputTest ,
ExplicitActionsRunOutWithDefaultAction  )

Definition at line 250 of file gmock_output_test_.cc.

250 {
251 ON_CALL(foo_, Bar2(_, _))
252 .WillByDefault(Return(true)); // Default action #1
253
254 EXPECT_CALL(foo_, Bar2(_, _))
255 .Times(2)
256 .WillOnce(Return(false));
257 foo_.Bar2(2, 2);
258 foo_.Bar2(1, 1); // Explicit actions in EXPECT_CALL run out.
259}

◆ TEST_F() [9/23]

TEST_F ( GMockOutputTest ,
MismatchArguments  )

Definition at line 189 of file gmock_output_test_.cc.

189 {
190 const std::string s = "Hi";
191 EXPECT_CALL(foo_, Bar(Ref(s), _, Ge(0)));
192
193 foo_.Bar("Ho", 0, -0.1); // Mismatch arguments
194 foo_.Bar(s, 0, 0);
195}
char * s

◆ TEST_F() [10/23]

TEST_F ( GMockOutputTest ,
MismatchArgumentsAndWith  )

Definition at line 205 of file gmock_output_test_.cc.

205 {
206 EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1)))
207 .With(Ge());
208
209 foo_.Bar2(1, 3); // Mismatch arguments and mismatch With()
210 foo_.Bar2(2, 1);
211}

◆ TEST_F() [11/23]

TEST_F ( GMockOutputTest ,
MismatchWith  )

Definition at line 197 of file gmock_output_test_.cc.

197 {
198 EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1)))
199 .With(Ge());
200
201 foo_.Bar2(2, 3); // Mismatch With()
202 foo_.Bar2(2, 1);
203}

◆ TEST_F() [12/23]

TEST_F ( GMockOutputTest ,
PrintsMatcher  )

Definition at line 282 of file gmock_output_test_.cc.

282 {
283 const testing::Matcher<int> m1 = Ge(48);
284 EXPECT_THAT((std::pair<int, bool>(42, true)), IsPair(m1, true));
285}
#define EXPECT_THAT(value, matcher)

◆ TEST_F() [13/23]

TEST_F ( GMockOutputTest ,
RetiredExpectation  )

Definition at line 137 of file gmock_output_test_.cc.

137 {
138 EXPECT_CALL(foo_, Bar2(_, _))
139 .RetiresOnSaturation();
140 EXPECT_CALL(foo_, Bar2(0, 0));
141
142 foo_.Bar2(1, 1);
143 foo_.Bar2(1, 1); // Matches a retired expectation
144 foo_.Bar2(0, 0);
145}

◆ TEST_F() [14/23]

TEST_F ( GMockOutputTest ,
UnexpectedCall  )

Definition at line 101 of file gmock_output_test_.cc.

101 {
102 EXPECT_CALL(foo_, Bar2(0, _));
103
104 foo_.Bar2(1, 0); // Unexpected call
105 foo_.Bar2(0, 0); // Expected call
106}

◆ TEST_F() [15/23]

TEST_F ( GMockOutputTest ,
UnexpectedCallToVoidFunction  )

Definition at line 108 of file gmock_output_test_.cc.

108 {
109 EXPECT_CALL(foo_, Bar3(0, _));
110
111 foo_.Bar3(1, 0); // Unexpected call
112 foo_.Bar3(0, 0); // Expected call
113}

◆ TEST_F() [16/23]

TEST_F ( GMockOutputTest ,
UnexpectedCallWithDefaultAction  )

Definition at line 213 of file gmock_output_test_.cc.

213 {
214 ON_CALL(foo_, Bar2(_, _))
215 .WillByDefault(Return(true)); // Default action #1
216 ON_CALL(foo_, Bar2(1, _))
217 .WillByDefault(Return(false)); // Default action #2
218
219 EXPECT_CALL(foo_, Bar2(2, 2));
220 foo_.Bar2(1, 0); // Unexpected call, takes default action #2.
221 foo_.Bar2(0, 0); // Unexpected call, takes default action #1.
222 foo_.Bar2(2, 2); // Expected call.
223}

◆ TEST_F() [17/23]

TEST_F ( GMockOutputTest ,
UninterestingCall  )

Definition at line 129 of file gmock_output_test_.cc.

129 {
130 foo_.Bar2(0, 1); // Uninteresting call
131}

◆ TEST_F() [18/23]

TEST_F ( GMockOutputTest ,
UninterestingCallToVoidFunction  )

Definition at line 133 of file gmock_output_test_.cc.

133 {
134 foo_.Bar3(0, 1); // Uninteresting call
135}

◆ TEST_F() [19/23]

TEST_F ( GMockOutputTest ,
UninterestingCallWithDefaultAction  )

Definition at line 240 of file gmock_output_test_.cc.

240 {
241 ON_CALL(foo_, Bar2(_, _))
242 .WillByDefault(Return(true)); // Default action #1
243 ON_CALL(foo_, Bar2(1, _))
244 .WillByDefault(Return(false)); // Default action #2
245
246 foo_.Bar2(2, 2); // Uninteresting call, takes default action #1.
247 foo_.Bar2(1, 1); // Uninteresting call, takes default action #2.
248}

◆ TEST_F() [20/23]

TEST_F ( GMockOutputTest ,
UnsatisfiedExpectation  )

Definition at line 181 of file gmock_output_test_.cc.

181 {
182 EXPECT_CALL(foo_, Bar(_, _, _));
183 EXPECT_CALL(foo_, Bar2(0, _))
184 .Times(2);
185
186 foo_.Bar2(0, 1);
187}

◆ TEST_F() [21/23]

TEST_F ( GMockOutputTest ,
UnsatisfiedPrerequisite  )

Definition at line 147 of file gmock_output_test_.cc.

147 {
148 {
150 EXPECT_CALL(foo_, Bar(_, 0, _));
151 EXPECT_CALL(foo_, Bar2(0, 0));
152 EXPECT_CALL(foo_, Bar2(1, _));
153 }
154
155 foo_.Bar2(1, 0); // Has one immediate unsatisfied pre-requisite
156 foo_.Bar("Hi", 0, 0);
157 foo_.Bar2(0, 0);
158 foo_.Bar2(1, 0);
159}

◆ TEST_F() [22/23]

TEST_F ( GMockOutputTest ,
UnsatisfiedPrerequisites  )

Definition at line 161 of file gmock_output_test_.cc.

161 {
162 Sequence s1, s2;
163
164 EXPECT_CALL(foo_, Bar(_, 0, _))
165 .InSequence(s1);
166 EXPECT_CALL(foo_, Bar2(0, 0))
167 .InSequence(s2);
168 EXPECT_CALL(foo_, Bar2(1, _))
169 .InSequence(s1, s2);
170
171 foo_.Bar2(1, 0); // Has two immediate unsatisfied pre-requisites
172 foo_.Bar("Hi", 0, 0);
173 foo_.Bar2(0, 0);
174 foo_.Bar2(1, 0);
175}

◆ TEST_F() [23/23]

TEST_F ( GMockOutputTest ,
UnsatisfiedWith  )

Definition at line 177 of file gmock_output_test_.cc.

177 {
178 EXPECT_CALL(foo_, Bar2(_, _)).With(Ge());
179}

◆ TestCatchesLeakedMocksInAdHocTests()

void TestCatchesLeakedMocksInAdHocTests ( )

Definition at line 287 of file gmock_output_test_.cc.

287 {
288 MockFoo* foo = new MockFoo;
289
290 // Invokes EXPECT_CALL on foo.
291 EXPECT_CALL(*foo, Bar2(_, _));
292 foo->Bar2(2, 1);
293
294 // foo is deliberately leaked.
295}
Here is the caller graph for this function: