NetBurner 3.1
MockSupport_c.h
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 #ifndef D_MockSupport_c_h
29 #define D_MockSupport_c_h
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #include "CppUTest/StandardCLibrary.h"
36 
37 typedef enum {
38  MOCKVALUETYPE_BOOL,
39  MOCKVALUETYPE_UNSIGNED_INTEGER,
40  MOCKVALUETYPE_INTEGER,
41  MOCKVALUETYPE_LONG_INTEGER,
42  MOCKVALUETYPE_UNSIGNED_LONG_INTEGER,
43  MOCKVALUETYPE_DOUBLE,
44  MOCKVALUETYPE_STRING,
45  MOCKVALUETYPE_POINTER,
46  MOCKVALUETYPE_CONST_POINTER,
47  MOCKVALUETYPE_FUNCTIONPOINTER,
48  MOCKVALUETYPE_MEMORYBUFFER,
49  MOCKVALUETYPE_OBJECT
50 } MockValueType_c;
51 
52 typedef struct SMockValue_c
53 {
54  MockValueType_c type;
55  union {
56  int boolValue;
57  int intValue;
58  unsigned int unsignedIntValue;
59  long int longIntValue;
60  unsigned long int unsignedLongIntValue;
61  double doubleValue;
62  const char* stringValue;
63  void* pointerValue;
64  const void* constPointerValue;
65  void (*functionPointerValue)(void);
66  const unsigned char* memoryBufferValue;
67  const void* objectValue;
68  } value;
69 } MockValue_c;
70 
71 typedef struct SMockActualCall_c MockActualCall_c;
72 struct SMockActualCall_c
73 {
74  MockActualCall_c* (*withBoolParameters)(const char* name, int value);
75  MockActualCall_c* (*withIntParameters)(const char* name, int value);
76  MockActualCall_c* (*withUnsignedIntParameters)(const char* name, unsigned int value);
77  MockActualCall_c* (*withLongIntParameters)(const char* name, long int value);
78  MockActualCall_c* (*withUnsignedLongIntParameters)(const char* name, unsigned long int value);
79  MockActualCall_c* (*withDoubleParameters)(const char* name, double value);
80  MockActualCall_c* (*withStringParameters)(const char* name, const char* value);
81  MockActualCall_c* (*withPointerParameters)(const char* name, void* value);
82  MockActualCall_c* (*withConstPointerParameters)(const char* name, const void* value);
83  MockActualCall_c* (*withFunctionPointerParameters)(const char* name, void (*value)(void));
84  MockActualCall_c* (*withMemoryBufferParameter)(const char* name, const unsigned char* value, size_t size);
85  MockActualCall_c* (*withParameterOfType)(const char* type, const char* name, const void* value);
86  MockActualCall_c* (*withOutputParameter)(const char* name, void* value);
87  MockActualCall_c* (*withOutputParameterOfType)(const char* type, const char* name, void* value);
88  int (*hasReturnValue)(void);
89  MockValue_c (*returnValue)(void);
90  int (*boolReturnValue)(void);
91  int (*returnBoolValueOrDefault)(int defaultValue);
92  int (*intReturnValue)(void);
93  int (*returnIntValueOrDefault)(int defaultValue);
94  unsigned int (*unsignedIntReturnValue)(void);
95  unsigned int (*returnUnsignedIntValueOrDefault)(unsigned int defaultValue);
96  long int (*longIntReturnValue)(void);
97  long int (*returnLongIntValueOrDefault)(long int defaultValue);
98  unsigned long int (*unsignedLongIntReturnValue)(void);
99  unsigned long int (*returnUnsignedLongIntValueOrDefault)(unsigned long int defaultValue);
100  const char* (*stringReturnValue)(void);
101  const char* (*returnStringValueOrDefault)(const char * defaultValue);
102  double (*doubleReturnValue)(void);
103  double (*returnDoubleValueOrDefault)(double defaultValue);
104  void* (*pointerReturnValue)(void);
105  void* (*returnPointerValueOrDefault)(void * defaultValue);
106  const void* (*constPointerReturnValue)(void);
107  const void* (*returnConstPointerValueOrDefault)(const void * defaultValue);
108  void (*(*functionPointerReturnValue)(void))(void);
109  void (*(*returnFunctionPointerValueOrDefault)(void(*defaultValue)(void)))(void);
110 };
111 
112 typedef struct SMockExpectedCall_c MockExpectedCall_c;
113 struct SMockExpectedCall_c
114 {
115  MockExpectedCall_c* (*withBoolParameters)(const char* name, int value);
116  MockExpectedCall_c* (*withIntParameters)(const char* name, int value);
117  MockExpectedCall_c* (*withUnsignedIntParameters)(const char* name, unsigned int value);
118  MockExpectedCall_c* (*withLongIntParameters)(const char* name, long int value);
119  MockExpectedCall_c* (*withUnsignedLongIntParameters)(const char* name, unsigned long int value);
120  MockExpectedCall_c* (*withDoubleParameters)(const char* name, double value);
121  MockExpectedCall_c* (*withStringParameters)(const char* name, const char* value);
122  MockExpectedCall_c* (*withPointerParameters)(const char* name, void* value);
123  MockExpectedCall_c* (*withConstPointerParameters)(const char* name, const void* value);
124  MockExpectedCall_c* (*withFunctionPointerParameters)(const char* name, void (*value)(void));
125  MockExpectedCall_c* (*withMemoryBufferParameter)(const char* name, const unsigned char* value, size_t size);
126  MockExpectedCall_c* (*withParameterOfType)(const char* type, const char* name, const void* value);
127  MockExpectedCall_c* (*withOutputParameterReturning)(const char* name, const void* value, size_t size);
128  MockExpectedCall_c* (*withOutputParameterOfTypeReturning)(const char* type, const char* name, const void* value);
129  MockExpectedCall_c* (*ignoreOtherParameters)(void);
130 
131  MockExpectedCall_c* (*andReturnBoolValue)(int value);
132  MockExpectedCall_c* (*andReturnUnsignedIntValue)(unsigned int value);
133  MockExpectedCall_c* (*andReturnIntValue)(int value);
134  MockExpectedCall_c* (*andReturnLongIntValue)(long int value);
135  MockExpectedCall_c* (*andReturnUnsignedLongIntValue)(unsigned long int value);
136  MockExpectedCall_c* (*andReturnDoubleValue)(double value);
137  MockExpectedCall_c* (*andReturnStringValue)(const char* value);
138  MockExpectedCall_c* (*andReturnPointerValue)(void* value);
139  MockExpectedCall_c* (*andReturnConstPointerValue)(const void* value);
140  MockExpectedCall_c* (*andReturnFunctionPointerValue)(void (*value)(void));
141 };
142 
143 typedef int (*MockTypeEqualFunction_c)(const void* object1, const void* object2);
144 typedef const char* (*MockTypeValueToStringFunction_c)(const void* object1);
145 typedef void (*MockTypeCopyFunction_c)(void* dst, const void* src);
146 
147 typedef struct SMockSupport_c MockSupport_c;
148 struct SMockSupport_c
149 {
150  void (*strictOrder)(void);
151  MockExpectedCall_c* (*expectOneCall)(const char* name);
152  void (*expectNoCall)(const char* name);
153  MockExpectedCall_c* (*expectNCalls)(unsigned int number, const char* name);
154  MockActualCall_c* (*actualCall)(const char* name);
155  int (*hasReturnValue)(void);
156  MockValue_c (*returnValue)(void);
157  int (*boolReturnValue)(void);
158  int (*returnBoolValueOrDefault)(int defaultValue);
159  int (*intReturnValue)(void);
160  int (*returnIntValueOrDefault)(int defaultValue);
161  unsigned int (*unsignedIntReturnValue)(void);
162  unsigned int (*returnUnsignedIntValueOrDefault)(unsigned int defaultValue);
163  long int (*longIntReturnValue)(void);
164  long int (*returnLongIntValueOrDefault)(long int defaultValue);
165  unsigned long int (*unsignedLongIntReturnValue)(void);
166  unsigned long int (*returnUnsignedLongIntValueOrDefault)(unsigned long int defaultValue);
167  const char* (*stringReturnValue)(void);
168  const char* (*returnStringValueOrDefault)(const char * defaultValue);
169  double (*doubleReturnValue)(void);
170  double (*returnDoubleValueOrDefault)(double defaultValue);
171  void* (*pointerReturnValue)(void);
172  void* (*returnPointerValueOrDefault)(void * defaultValue);
173  const void* (*constPointerReturnValue)(void);
174  const void* (*returnConstPointerValueOrDefault)(const void * defaultValue);
175  void (*(*functionPointerReturnValue)(void))(void);
176  void (*(*returnFunctionPointerValueOrDefault) (void(*defaultValue)(void)))(void);
177 
178  void (*setBoolData) (const char* name, int value);
179  void (*setIntData) (const char* name, int value);
180  void (*setUnsignedIntData) (const char* name, unsigned int value);
181  void (*setStringData) (const char* name, const char* value);
182  void (*setDoubleData) (const char* name, double value);
183  void (*setPointerData) (const char* name, void* value);
184  void (*setConstPointerData) (const char* name, const void* value);
185  void (*setFunctionPointerData) (const char* name, void (*value)(void));
186  void (*setDataObject) (const char* name, const char* type, void* value);
187  MockValue_c (*getData)(const char* name);
188 
189  void (*disable)(void);
190  void (*enable)(void);
191  void (*ignoreOtherCalls)(void);
192 
193  void (*checkExpectations)(void);
194  int (*expectedCallsLeft)(void);
195 
196  void (*clear)(void);
197  void (*crashOnFailure)(unsigned shouldCrash);
198 
199  void (*installComparator) (const char* typeName, MockTypeEqualFunction_c isEqual, MockTypeValueToStringFunction_c valueToString);
200  void (*installCopier) (const char* typeName, MockTypeCopyFunction_c copier);
201  void (*removeAllComparatorsAndCopiers)(void);
202 };
203 
204 MockSupport_c* mock_c(void);
205 MockSupport_c* mock_scope_c(const char* scope);
206 
207 #ifdef __cplusplus
208 }
209 #endif
210 
211 #endif