@@ -15,13 +15,24 @@ struct ReturnTemplateSpecializationTests : tpunit::TestFixture {
1515
1616 ReturnTemplateSpecializationTests ()
1717 : tpunit::TestFixture(
18- TEST (ReturnTemplateSpecializationTests::return_specialization_from_same_type_temp),
18+ TEST (ReturnTemplateSpecializationTests::return_default_from_same_type_temp),
19+ TEST(ReturnTemplateSpecializationTests::return_valspecialization_from_same_type_temp),
1920 TEST(ReturnTemplateSpecializationTests::return_capture_from_same_type_temp),
20- TEST(ReturnTemplateSpecializationTests::return_specialization_from_other_type_temp),
21+ TEST(ReturnTemplateSpecializationTests::return_default_from_other_type_temp),
22+ TEST(ReturnTemplateSpecializationTests::return_valspecialization_from_other_type_temp),
2123 TEST(ReturnTemplateSpecializationTests::return_capture_from_other_type_temp),
2224 TEST(ReturnTemplateSpecializationTests::return_default_from_variable),
23- TEST(ReturnTemplateSpecializationTests::return_specialization_from_variable),
24- TEST(ReturnTemplateSpecializationTests::return_capture_from_variable)
25+ TEST(ReturnTemplateSpecializationTests::return_valspecialization_from_variable),
26+ TEST(ReturnTemplateSpecializationTests::return_capture_from_variable),
27+ TEST(ReturnTemplateSpecializationTests::always_return_default_from_same_type_temp),
28+ TEST(ReturnTemplateSpecializationTests::always_return_valspecialization_from_same_type_temp),
29+ TEST(ReturnTemplateSpecializationTests::always_return_capture_from_same_type_temp),
30+ TEST(ReturnTemplateSpecializationTests::always_return_default_from_other_type_temp),
31+ TEST(ReturnTemplateSpecializationTests::always_return_valspecialization_from_other_type_temp),
32+ TEST(ReturnTemplateSpecializationTests::always_return_capture_from_other_type_temp),
33+ TEST(ReturnTemplateSpecializationTests::always_return_default_from_variable),
34+ TEST(ReturnTemplateSpecializationTests::always_return_valspecialization_from_variable),
35+ TEST(ReturnTemplateSpecializationTests::always_return_capture_from_variable)
2536 ) {
2637 }
2738
@@ -44,7 +55,19 @@ struct ReturnTemplateSpecializationTests : tpunit::TestFixture {
4455 virtual MoveOnly returnValMo () = 0;
4556 };
4657
47- void return_specialization_from_same_type_temp () {
58+ void return_default_from_same_type_temp () {
59+ Mock<SomeStruct> mock;
60+
61+ When (Method (mock, returnVal)).Return (std::string (" something" ));
62+ ASSERT_EQUAL (mock.get ().returnVal (), " something" );
63+ Verify (Method (mock, returnVal)).Once ();
64+
65+ When (Method (mock, returnValMo)).Return (MoveOnly{5 });
66+ ASSERT_EQUAL (mock.get ().returnValMo ().i , 5 );
67+ Verify (Method (mock, returnValMo)).Once ();
68+ }
69+
70+ void return_valspecialization_from_same_type_temp () {
4871 Mock<SomeStruct> mock;
4972
5073 When (Method (mock, returnRef)).Return <std::string>(std::string (" something" ));
@@ -84,7 +107,19 @@ struct ReturnTemplateSpecializationTests : tpunit::TestFixture {
84107 Verify (Method (mock, returnValMo)).Once ();
85108 }
86109
87- void return_specialization_from_other_type_temp () {
110+ void return_default_from_other_type_temp () {
111+ Mock<SomeStruct> mock;
112+
113+ When (Method (mock, returnVal)).Return (" something" );
114+ ASSERT_EQUAL (mock.get ().returnVal (), " something" );
115+ Verify (Method (mock, returnVal)).Once ();
116+
117+ When (Method (mock, returnValMo)).Return (5 );
118+ ASSERT_EQUAL (mock.get ().returnValMo ().i , 5 );
119+ Verify (Method (mock, returnValMo)).Once ();
120+ }
121+
122+ void return_valspecialization_from_other_type_temp () {
88123 Mock<SomeStruct> mock;
89124
90125 When (Method (mock, returnRef)).Return <std::string>(" something" );
@@ -158,7 +193,7 @@ struct ReturnTemplateSpecializationTests : tpunit::TestFixture {
158193 }
159194 }
160195
161- void return_specialization_from_variable () {
196+ void return_valspecialization_from_variable () {
162197 Mock<SomeStruct> mock;
163198
164199 {
@@ -226,4 +261,200 @@ struct ReturnTemplateSpecializationTests : tpunit::TestFixture {
226261 }
227262 }
228263
264+ void always_return_default_from_same_type_temp () {
265+ Mock<SomeStruct> mock;
266+
267+ When (Method (mock, returnVal)).AlwaysReturn (std::string (" something" ));
268+ ASSERT_EQUAL (mock.get ().returnVal (), " something" );
269+ ASSERT_EQUAL (mock.get ().returnVal (), " something" );
270+ Verify (Method (mock, returnVal)).Exactly (2 );
271+ }
272+
273+ void always_return_valspecialization_from_same_type_temp () {
274+ Mock<SomeStruct> mock;
275+
276+ When (Method (mock, returnRef)).AlwaysReturn <std::string>(std::string (" something" ));
277+ ASSERT_EQUAL (mock.get ().returnRef (), " something" );
278+ ASSERT_EQUAL (mock.get ().returnRef (), " something" );
279+ Verify (Method (mock, returnRef)).Exactly (2 );
280+
281+ When (Method (mock, returnRefMo)).AlwaysReturn <MoveOnly>(MoveOnly{5 });
282+ ASSERT_EQUAL (mock.get ().returnRefMo ().i , 5 );
283+ ASSERT_EQUAL (mock.get ().returnRefMo ().i , 5 );
284+ Verify (Method (mock, returnRefMo)).Exactly (2 );
285+
286+ When (Method (mock, returnVal)).AlwaysReturn <std::string>(std::string (" something" ));
287+ ASSERT_EQUAL (mock.get ().returnVal (), " something" );
288+ ASSERT_EQUAL (mock.get ().returnVal (), " something" );
289+ Verify (Method (mock, returnVal)).Exactly (2 );
290+ }
291+
292+ void always_return_capture_from_same_type_temp () {
293+ Mock<SomeStruct> mock;
294+
295+ When (Method (mock, returnRef)).AlwaysReturnCapture (std::string (" something" ));
296+ ASSERT_EQUAL (mock.get ().returnRef (), " something" );
297+ ASSERT_EQUAL (mock.get ().returnRef (), " something" );
298+ Verify (Method (mock, returnRef)).Exactly (2 );
299+
300+ When (Method (mock, returnRefMo)).AlwaysReturnCapture (MoveOnly{5 });
301+ ASSERT_EQUAL (mock.get ().returnRefMo ().i , 5 );
302+ ASSERT_EQUAL (mock.get ().returnRefMo ().i , 5 );
303+ Verify (Method (mock, returnRefMo)).Exactly (2 );
304+
305+ When (Method (mock, returnVal)).AlwaysReturnCapture (std::string (" something" ));
306+ ASSERT_EQUAL (mock.get ().returnVal (), " something" );
307+ ASSERT_EQUAL (mock.get ().returnVal (), " something" );
308+ Verify (Method (mock, returnVal)).Exactly (2 );
309+ }
310+
311+ void always_return_default_from_other_type_temp () {
312+ Mock<SomeStruct> mock;
313+
314+ When (Method (mock, returnVal)).AlwaysReturn (" something" );
315+ ASSERT_EQUAL (mock.get ().returnVal (), " something" );
316+ ASSERT_EQUAL (mock.get ().returnVal (), " something" );
317+ Verify (Method (mock, returnVal)).Exactly (2 );
318+ }
319+
320+ void always_return_valspecialization_from_other_type_temp () {
321+ Mock<SomeStruct> mock;
322+
323+ When (Method (mock, returnRef)).AlwaysReturn <std::string>(" something" );
324+ ASSERT_EQUAL (mock.get ().returnRef (), " something" );
325+ ASSERT_EQUAL (mock.get ().returnRef (), " something" );
326+ Verify (Method (mock, returnRef)).Exactly (2 );
327+
328+ When (Method (mock, returnRefMo)).AlwaysReturn <MoveOnly>(5 );
329+ ASSERT_EQUAL (mock.get ().returnRefMo ().i , 5 );
330+ ASSERT_EQUAL (mock.get ().returnRefMo ().i , 5 );
331+ Verify (Method (mock, returnRefMo)).Exactly (2 );
332+
333+ When (Method (mock, returnVal)).AlwaysReturn <std::string>(" something" );
334+ ASSERT_EQUAL (mock.get ().returnVal (), " something" );
335+ ASSERT_EQUAL (mock.get ().returnVal (), " something" );
336+ Verify (Method (mock, returnVal)).Exactly (2 );
337+ }
338+
339+ void always_return_capture_from_other_type_temp () {
340+ Mock<SomeStruct> mock;
341+
342+ When (Method (mock, returnRef)).AlwaysReturnCapture (" something" );
343+ ASSERT_EQUAL (mock.get ().returnRef (), " something" );
344+ ASSERT_EQUAL (mock.get ().returnRef (), " something" );
345+ Verify (Method (mock, returnRef)).Exactly (2 );
346+
347+ When (Method (mock, returnRefMo)).AlwaysReturnCapture (5 );
348+ ASSERT_EQUAL (mock.get ().returnRefMo ().i , 5 );
349+ ASSERT_EQUAL (mock.get ().returnRefMo ().i , 5 );
350+ Verify (Method (mock, returnRefMo)).Exactly (2 );
351+
352+ When (Method (mock, returnVal)).AlwaysReturnCapture (" something" );
353+ ASSERT_EQUAL (mock.get ().returnVal (), " something" );
354+ ASSERT_EQUAL (mock.get ().returnVal (), " something" );
355+ Verify (Method (mock, returnVal)).Exactly (2 );
356+ }
357+
358+ void always_return_default_from_variable () {
359+ Mock<SomeStruct> mock;
360+
361+ {
362+ std::string something = " something" ;
363+ MoveOnly mo = 5 ;
364+
365+ When (Method (mock, returnRef)).AlwaysReturn (something);
366+ something = " a different thing" ;
367+ ASSERT_EQUAL (mock.get ().returnRef (), " a different thing" );
368+ something = " another different thing" ;
369+ ASSERT_EQUAL (mock.get ().returnRef (), " another different thing" );
370+ Verify (Method (mock, returnRef)).Exactly (2 );
371+
372+ When (Method (mock, returnRefMo)).AlwaysReturn (mo);
373+ mo.i = 10 ;
374+ ASSERT_EQUAL (mock.get ().returnRefMo ().i , 10 );
375+ mo.i = 50 ;
376+ ASSERT_EQUAL (mock.get ().returnRefMo ().i , 50 );
377+ Verify (Method (mock, returnRefMo)).Exactly (2 );
378+ }
379+
380+ {
381+ std::string something = " something" ;
382+
383+ When (Method (mock, returnVal)).AlwaysReturn (something);
384+ something = " a different thing" ;
385+ ASSERT_EQUAL (mock.get ().returnVal (), " something" );
386+ something = " another different thing" ;
387+ ASSERT_EQUAL (mock.get ().returnVal (), " something" );
388+ Verify (Method (mock, returnVal)).Exactly (2 );
389+ }
390+ }
391+
392+ void always_return_valspecialization_from_variable () {
393+ Mock<SomeStruct> mock;
394+
395+ {
396+ std::string something = " something" ;
397+ MoveOnly mo = 5 ;
398+
399+ When (Method (mock, returnRef)).AlwaysReturn <std::string>(something);
400+ something = " a different thing" ;
401+ ASSERT_EQUAL (mock.get ().returnRef (), " something" );
402+ something = " another different thing" ;
403+ ASSERT_EQUAL (mock.get ().returnRef (), " something" );
404+ Verify (Method (mock, returnRef)).Exactly (2 );
405+
406+ When (Method (mock, returnRefMo)).AlwaysReturn <MoveOnly>(std::move (mo));
407+ mo.i = 10 ;
408+ ASSERT_EQUAL (mock.get ().returnRefMo ().i , 5 );
409+ mo.i = 50 ;
410+ ASSERT_EQUAL (mock.get ().returnRefMo ().i , 5 );
411+ Verify (Method (mock, returnRefMo)).Exactly (2 );
412+ }
413+
414+ {
415+ std::string something = " something" ;
416+
417+ When (Method (mock, returnVal)).AlwaysReturn <std::string>(something);
418+ something = " a different thing" ;
419+ ASSERT_EQUAL (mock.get ().returnVal (), " something" );
420+ something = " another different thing" ;
421+ ASSERT_EQUAL (mock.get ().returnVal (), " something" );
422+ Verify (Method (mock, returnVal)).Exactly (2 );
423+ }
424+ }
425+
426+ void always_return_capture_from_variable () {
427+ Mock<SomeStruct> mock;
428+
429+ {
430+ std::string something = " something" ;
431+ MoveOnly mo = 5 ;
432+
433+ When (Method (mock, returnRef)).AlwaysReturnCapture (something);
434+ something = " a different thing" ;
435+ ASSERT_EQUAL (mock.get ().returnRef (), " something" );
436+ something = " another different thing" ;
437+ ASSERT_EQUAL (mock.get ().returnRef (), " something" );
438+ Verify (Method (mock, returnRef)).Exactly (2 );
439+
440+ When (Method (mock, returnRefMo)).AlwaysReturnCapture (std::move (mo));
441+ mo.i = 10 ;
442+ ASSERT_EQUAL (mock.get ().returnRefMo ().i , 5 );
443+ mo.i = 50 ;
444+ ASSERT_EQUAL (mock.get ().returnRefMo ().i , 5 );
445+ Verify (Method (mock, returnRefMo)).Exactly (2 );
446+ }
447+
448+ {
449+ std::string something = " something" ;
450+
451+ When (Method (mock, returnVal)).AlwaysReturnCapture (something);
452+ something = " a different thing" ;
453+ ASSERT_EQUAL (mock.get ().returnVal (), " something" );
454+ something = " another different thing" ;
455+ ASSERT_EQUAL (mock.get ().returnVal (), " something" );
456+ Verify (Method (mock, returnVal)).Exactly (2 );
457+ }
458+ }
459+
229460} __ReturnTemplateSpecializationTests;
0 commit comments