Debian Codegraph @

tests/CppUTestExt/MockSupport_cTestCFile.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the <organization> nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include "CppUTestExt/MockSupport_c.h"
29 #include "MockSupport_cTestCFile.h"
30
31 static int typeNameIsEqual(const void* object1, const void* object2)
32 {
33 return object1 == object2;
34 }
35
36 static const char* typeNameValueToString(const void* object)
37 {
38 return (const char*) object;
39 }
40
41 void all_mock_support_c_calls(void)
42 {
43 mock_c()->strictOrder();
44 mock_c()->expectOneCall("boo");
45 mock_c()->expectNoCall("bla");
46 mock_c()->expectNCalls(1, "foo");
47 mock_c()->actualCall("boo");
48 mock_c()->actualCall("foo");
49 mock_c()->checkExpectations();
50
51 mock_c()->expectOneCall("boo")->withIntParameters("integer", 1)->
52 withBoolParameters("bool", 1)->
53 withUnsignedIntParameters("unsigned", 1)->
54 withLongIntParameters("long int", (long int) -1)->
55 withUnsignedLongIntParameters("unsigned long int", (unsigned long int) 1)->
56 #ifdef CPPUTEST_USE_LONG_LONG
57 withLongLongIntParameters("long long int", (long long int) -1)->
58 withUnsignedLongLongIntParameters("unsigned long long int", (unsigned long long int) 1)->
59 #endif
60
61 withDoubleParameters("double", 1.0)->
62 withDoubleParametersAndTolerance("doubleWithTolerance", 1.0, 1.0)->
63 withStringParameters("string", "string")->
64 withPointerParameters("pointer", (void*) 1)->
65 withConstPointerParameters("constpointer", (const void*) 1)->
66 withFunctionPointerParameters("functionpointer", (void(*)(void)) 1)->
67 withMemoryBufferParameter("name", (void*) 1, 0UL)->
68 ignoreOtherParameters();
69
70 mock_c()->actualCall("boo")->withIntParameters("integer", 1)->
71 withBoolParameters("bool", 1)->
72 withUnsignedIntParameters("unsigned", 1)->
73 withLongIntParameters("long int", (long int) -1)->
74 withUnsignedLongIntParameters("unsigned long int", (unsigned long int) 1)->
75 #ifdef CPPUTEST_USE_LONG_LONG
76 withLongLongIntParameters("long long int", (long long int) -1)->
77 withUnsignedLongLongIntParameters("unsigned long long int", (unsigned long long int) 1)->
78 #endif
79 withDoubleParameters("double", 1.0)->
80 withDoubleParameters("doubleWithTolerance", 0.0 )->
81 withStringParameters("string", "string")->
82 withPointerParameters("pointer", (void*) 1)->
83 withConstPointerParameters("constpointer", (const void*) 1)->
84 withFunctionPointerParameters("functionpointer", (void(*)(void)) 1)->
85 withMemoryBufferParameter("name", (void*) 1, 0UL)->
86 hasReturnValue();
87
88 mock_c()->disable();
89 mock_c()->expectOneCall("boo")->withParameterOfType("type", "name", (void*) 1)->
90 withOutputParameterReturning("name", (void*)1, 0UL)->
91 withOutputParameterOfTypeReturning("type", "name", (void*)1);
92 mock_c()->actualCall("boo")->withParameterOfType("type", "name", (void*) 1)->
93 withOutputParameter("name", (void*)1)->
94 withOutputParameterOfType("type", "name", (void*)1);
95 mock_c()->enable();
96
97 mock_c()->clear();
98
99 mock_c()->installComparator("typeName", typeNameIsEqual, typeNameValueToString);
100 mock_c()->expectOneCall("boo")->withParameterOfType("typeName", "name", (void*) 1);
101 mock_c()->actualCall("boo")->withParameterOfType("typeName", "name", (void*) 1);
102 mock_c()->clear();
103 mock_c()->removeAllComparatorsAndCopiers();
104
105 mock_c()->expectOneCall("boo")->andReturnBoolValue(1);
106 mock_c()->actualCall("boo")->boolReturnValue();
107 mock_c()->boolReturnValue();
108
109 mock_c()->expectOneCall("boo")->andReturnIntValue(-10);
110 mock_c()->actualCall("boo")->intReturnValue();
111 mock_c()->intReturnValue();
112 mock_c()->returnValue();
113
114 mock_c()->expectOneCall("boo2")->andReturnUnsignedIntValue(1);
115 mock_c()->actualCall("boo2")->unsignedIntReturnValue();
116 mock_c()->unsignedIntReturnValue();
117
118 mock_c()->expectOneCall("boo3")->andReturnLongIntValue(1);
119 mock_c()->actualCall("boo3")->longIntReturnValue();
120 mock_c()->longIntReturnValue();
121
122 mock_c()->expectOneCall("boo3")->andReturnUnsignedLongIntValue(1);
123 mock_c()->actualCall("boo3")->unsignedLongIntReturnValue();
124 mock_c()->unsignedLongIntReturnValue();
125
126 #ifdef CPPUTEST_USE_LONG_LONG
127 mock_c()->expectOneCall("mgrgrgr1")->andReturnLongLongIntValue(1);
128 mock_c()->actualCall("mgrgrgr1")->longLongIntReturnValue();
129 mock_c()->longLongIntReturnValue();
130
131 mock_c()->expectOneCall("mgrgrgr2")->andReturnUnsignedLongLongIntValue(1);
132 mock_c()->actualCall("mgrgrgr2")->unsignedLongLongIntReturnValue();
133 mock_c()->unsignedLongLongIntReturnValue();
134 #endif
135
136 mock_c()->expectOneCall("boo4")->andReturnDoubleValue(1.0);
137 mock_c()->actualCall("boo4")->doubleReturnValue();
138 mock_c()->doubleReturnValue();
139
140 mock_c()->expectOneCall("boo5")->andReturnStringValue("hello world");
141 mock_c()->actualCall("boo5")->stringReturnValue();
142 mock_c()->stringReturnValue();
143
144 mock_c()->expectOneCall("boo6")->andReturnPointerValue((void*) 10);
145 mock_c()->actualCall("boo6")->pointerReturnValue();
146 mock_c()->pointerReturnValue();
147
148 mock_c()->expectOneCall("boo7")->andReturnConstPointerValue((void*) 10);
149 mock_c()->actualCall("boo7")->constPointerReturnValue();
150 mock_c()->constPointerReturnValue();
151
152 mock_c()->expectOneCall("boo8")->andReturnFunctionPointerValue((void(*)(void)) 10);
153 mock_c()->actualCall("boo8")->functionPointerReturnValue();
154 mock_c()->functionPointerReturnValue();
155
156 mock_c()->setBoolData("bool", 1);
157 mock_c()->expectOneCall("bla")->withBoolParameters("bool", 1);
158 mock_c()->actualCall("bla")->withBoolParameters("bool", mock_c()->getData("bool").value.boolValue);
159
160 mock_c()->setIntData("int", 5);
161 mock_c()->expectOneCall("bla")->withIntParameters("int", 5);
162 mock_c()->actualCall("bla")->withIntParameters("int", mock_c()->getData("int").value.intValue);
163
164 mock_c()->setStringData("string", "lol");
165 mock_c()->expectOneCall("bla")->withStringParameters("str", "lol");
166 mock_c()->actualCall("bla")->withStringParameters("str", mock_c()->getData("string").value.stringValue);
167
168 mock_c()->setDoubleData("double", 0.001);
169 mock_c()->expectOneCall("bla")->withDoubleParameters("double", 0.001);
170 mock_c()->actualCall("bla")->withDoubleParameters("double", mock_c()->getData("double").value.doubleValue);
171
172 mock_c()->setPointerData("ptr", (void*)1);
173 mock_c()->expectOneCall("bla")->withPointerParameters("ptr", (void*)1);
174 mock_c()->actualCall("bla")->withPointerParameters("ptr", mock_c()->getData("ptr").value.pointerValue);
175
176 mock_c()->setConstPointerData("cptr", (const void*)1);
177 mock_c()->expectOneCall("bla")->withConstPointerParameters("cptr", (const void*)1);
178 mock_c()->actualCall("bla")->withConstPointerParameters("cptr", mock_c()->getData("ptr").value.constPointerValue);
179
180 mock_c()->setFunctionPointerData("ptr", (void(*)(void))1);
181 mock_c()->expectOneCall("bla")->withFunctionPointerParameters("ptr", (void(*)(void))1);
182 mock_c()->actualCall("bla")->withFunctionPointerParameters("ptr", mock_c()->getData("ptr").value.functionPointerValue);
183
184 mock_c()->clear();
185
186 mock_c()->hasReturnValue();
187 mock_c()->returnBoolValueOrDefault(1);
188 mock_c()->returnIntValueOrDefault(-1);
189 mock_c()->returnUnsignedIntValueOrDefault(1);
190 mock_c()->returnLongIntValueOrDefault(-1L);
191 mock_c()->returnUnsignedLongIntValueOrDefault(1L);
192 #ifdef CPPUTEST_USE_LONG_LONG
193 mock_c()->returnLongLongIntValueOrDefault(-1LL);
194 mock_c()->returnUnsignedLongLongIntValueOrDefault(1ULL);
195 #endif
196 mock_c()->returnStringValueOrDefault("");
197 mock_c()->returnDoubleValueOrDefault(0.01);
198 mock_c()->returnPointerValueOrDefault(0);
199 mock_c()->returnConstPointerValueOrDefault(0);
200 mock_c()->returnFunctionPointerValueOrDefault(0);
201
202 mock_c()->disable();
203 mock_c()->actualCall("disabled");
204 mock_c()->enable();
205 mock_c()->checkExpectations();
206
207 mock_c()->setIntData("bla1", -2);
208 mock_c()->setUnsignedIntData("bla2", 2);
209 mock_c()->setDoubleData("bla3", 0.035);
210 mock_c()->setStringData("bla4", "abc");
211 mock_c()->setPointerData("bla", (void*) 2);
212 mock_c()->setConstPointerData("bla", (const void*) 2);
213 mock_c()->setFunctionPointerData("bla", (void (*)(void)) 2);
214 mock_c()->setDataObject("bla", "type", (void*) 2);
215 mock_c()->getData("bla");
216
217 mock_scope_c("scope")->expectOneCall("boo");
218 mock_scope_c("other")->expectedCallsLeft();
219 mock_scope_c("scope")->expectedCallsLeft();
220 mock_scope_c("scope")->actualCall("boo");
221 }