File: test_nevercall.cpp

package info (click to toggle)
hippomocks 5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 672 kB
  • sloc: cpp: 7,791; ansic: 31; makefile: 28
file content (81 lines) | stat: -rw-r--r-- 1,718 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "Framework.h"
#include "hippomocks.h"

class IR { 
public:
	virtual ~IR() {}
	virtual void f() {}
	virtual void g() {}
	virtual int h() { return 0; }
};

TEST (checkNeverCallWorks)
{
	bool exceptionCaught = false;
	MockRepository mocks;
	IR *iamock = mocks.Mock<IR>();
	Call &callF = mocks.ExpectCall(iamock, IR::f);
	mocks.OnCall(iamock, IR::g);
	mocks.NeverCall(iamock, IR::g).After(callF);
	iamock->g();
	iamock->g();
	iamock->f();
	try 
	{
		iamock->g();
	}
	catch (HippoMocks::ExpectationException &)
	{
		exceptionCaught = true;
	}
	CHECK(exceptionCaught);
}

TEST (checkNeverCallExceptionDetail)
{
	bool exceptionCaught = false;
	MockRepository mocks;
	IR *iamock = mocks.Mock<IR>();
	mocks.NeverCall(iamock, IR::g);
	try
	{
		iamock->g();
	}
	catch (HippoMocks::ExpectationException &ex)
	{
		exceptionCaught = true;
		CHECK(strstr(ex.what(), "IR::g") != NULL);
	}
	CHECK(exceptionCaught);
}

TEST (checkInteractionBetweenCallTypesWorks)
{
	bool exceptionCaught = false;
	MockRepository mocks;
	mocks.autoExpect = false;
	IR *iamock = mocks.Mock<IR>();
	Call &callF = mocks.ExpectCall(iamock, IR::f);
	Call &onCallG = mocks.OnCall(iamock, IR::g);
	mocks.OnCall(iamock, IR::h).Return(2);
	Call &returnThree = mocks.ExpectCall(iamock, IR::h).After(onCallG).Return(3);
	Call &returnFour = mocks.ExpectCall(iamock, IR::h).After(callF).Return(4);
	mocks.NeverCall(iamock, IR::h).After(returnThree).After(returnFour);
	CHECK(iamock->h() == 2);
	CHECK(iamock->h() == 2);
	iamock->f();
	CHECK(iamock->h() == 4);
	CHECK(iamock->h() == 2);
	iamock->g();
	CHECK(iamock->h() == 3);
	try 
	{
		iamock->h();
	}
	catch (HippoMocks::ExpectationException &)
	{
		exceptionCaught = true;
	}
	CHECK(exceptionCaught);
}