You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: MANUAL.md
+132-29
Original file line number
Diff line number
Diff line change
@@ -32,6 +32,8 @@ CppUMockGen can automatically generate for each mockable function its correspond
32
32
33
33
To generate expectation helper functions, pass the path where you want the files with the expectation helper functions to be generated as output using the `-e` / `--expect-output` option (additionally to or instead of the `-m` option). If the output option parameter is a directory path (i.e. ending with a path separator) then the output file names will be deduced from the input file name by replacing its extension by *"_expect.cpp"* / *"_expect.hpp"* and appended to the passed directory. If the output option parameter is empty it is equivalent to passing the current directory. If the output option parameter is **'@'**, the mock is printed to the console. In other cases the output file names will be deduced from the output option parameter by replacing its extension by *".cpp"* / *".hpp"*.
34
34
35
+
Expectation helper functions are declared inside root namespace `expect`, using the same namespace hierarchy than the mocked function but appending character **'$'** to each original namespace to avoid name clashes. Additionally, for member functions an innermost namespace hierarchy is declared according to the function class nesting hierarchy, also appending **'$'** to class names (e.g., expectation helper for member functions of class `foo` inside namespace `bar ` are declared inside namespace `expect::bar$::foo$`).
36
+
35
37
## Command-Line Options
36
38
37
39
`CppUMockGen [OPTION...] [<input>]`
@@ -62,12 +64,12 @@ CppUMockGen deduces the <code>with<i><MockedType></i>Parameter</code>/<code>r
@@ -77,64 +79,80 @@ If the resulting call for a parameter is `withParameterOfType` or `withOutputPar
77
79
78
80
## Overriding Mocked Parameter and Return Types
79
81
82
+
To override the <code>with<i><MockedType></i>Parameter</code>/<code>return<i><MockedType></i>Value</code> method to call on `MockActualCall` objects, override specifications can be passed on the command line. The override specifications can be for specific parameters or return values of specific mocked functions, or can be generic (based on data type).
83
+
84
+
Override specifications also define the <code>with<i><MockedType></i>Parameter</code> method call and the specific <code>andReturnValue</code> override method call on `MockExpectedCall` objects.
85
+
80
86
### Specific Mocked Parameter / Return Type Override
81
87
82
-
To override the <code>with<i><MockedType></i>Parameter</code>/<code>return<i><MockedType></i>Value</code> method to call on `MockActualCall` objects for a specific parameter or return value of a mocked function, an override specification can be passed on the command line using the `-p` / `--param-override` option.
88
+
A function/parameter specifc override specification is passed on the command line using the `-p` / `--param-override` option.
83
89
84
90
##### Specific parameter type override
85
91
86
92
Specific parameter type override options take the form:
- <code><i><QualifiedFunctionName></i></code> is the fully qualified name of a mocked function, including namespace (e.g. `namespace1::class1::method1`).
92
98
- <code><i><ParameterName></i></code> is the name of the parameter.
93
-
- <code><i><MockedType></i></code> indicates the CppUMock type to use for the parameter, admitted values are: _Bool, Int, UnsignedInt, LongInt, UnsignedLongInt, Double, String, Pointer, ConstPointer, Output, Skip_.
94
-
- When set to _Skip_ the corresponding method call on the `MockActualCall` object for the parameter will be skipped.
95
-
- <code><i><ArgExpr></i></code> is an optional argument expression that must contain the **'$'** character. If defined, it will be passed as the argument for the CppUMock actual call parameter method, replacing **'$'** by the mocked function parameter name.
99
+
- <code><i><MockedType></i></code> indicates the CppUMock type to use for the parameter, admitted values are: _Bool, Int, UnsignedInt, LongInt, UnsignedLongInt, Double, String, Pointer, ConstPointer, Output, Skip_, or an <code>InputOfType</code> or <code>OutputOfType</code> option.
100
+
- When set to _Skip_ the corresponding method call on the `MockActualCall` and `MockExpectedCall` objects for the parameter will be skipped, and the parameter will not appear in the signature of expectation helper functions.
101
+
- An <code>InputOfType</code> option takes the form <b>'InputOfType:'</b><code><i><DeclaredType></i></code>[<b>'<'</b><code><i><ExpectationHelperType></i></code>], where:
102
+
- <code><i><DeclaredType></i></code> indicates the type name to be passed to the <code>withParameterOfType</code> method of <code>MockActualCall</code> and <code>MockExpectedCall</code>.
103
+
- <code><i><ExpectationHelperType></i></code> optionally indicates an override type to use as the argument of expectation helper functions.
104
+
- An <code>OutputOfType</code> option takes the form <b>'OutputOfType:'</b><code><i><DeclaredType></i></code>[<b>'<'</b><code><i><ExpectationHelperType></i></code>], where:
105
+
- <code><i><DeclaredType></i></code> indicates the type name to be passed to the <code>withOutputParameterOfType</code> method of <code>MockActualCall</code> and to the <code>withOutputParameterOfTypeReturning</code> method of <code>MockExpectedCall</code>.
106
+
- <code><i><ExpectationHelperType></i></code> optionally indicates an override type to use as the argument of expectation helper functions.
107
+
- <code><i><ArgExpr></i></code> is an optional C++ expression that must contain the **'$'** placeholder character. If defined, it will be passed as the argument for the CppUMock actual call parameter method, replacing **'$'** by the mocked function parameter name.
96
108
97
109
##### Specific return type override
98
110
99
111
Specific return type override options take the form:
- <code><i><QualifiedFunctionName></i></code> is the fully qualified name of a mocked function, including namespace (e.g. `namespace1::class1::method1`).
105
117
- <code><i><MockedType></i></code> indicates the CppUMock type to use for the return value, admitted values are: _Bool, Int, UnsignedInt, LongInt, UnsignedLongInt, Double, String, Pointer, ConstPointer_.
106
-
- <code><i><ArgExpr></i></code> is an optional argument expression that must contain the **'$'** character. If defined, it will be used as the return value of the mocked function, replacing **'$'** by the CppUMock actual call sequence.
118
+
- <code><i><RetExpr></i></code> is an optional C++ expression that must contain the **'$'** placeholder character. If defined, it will be used as the return value of the mocked function, replacing **'$'** by the CppUMock actual call sequence.
107
119
108
120
### Generic Mocked Parameter / Return Type Override
109
121
110
-
To override the <code>with<i><MockedType></i>Parameter</code>/<code>return<i><MockedType></i>Value</code> method to call on `MockActualCall` objects for parameter or return values of a mocked function based on its data type, an override specification can be passed on the command line using the `-t` / `--type-override` option.
122
+
A generic override specification is passed on the command line using the `-t` / `--type-override` option.
111
123
112
124
##### Generic parameter type override
113
125
114
126
Generic parameter type override options take the form:
- <code><i><ParameterType></i></code> is a C/C++ data type.
120
-
- <code><i><MockedType></i></code> indicates the CppUMock type to use for the parameter, admitted values are: _Bool, Int, UnsignedInt, LongInt, UnsignedLongInt, Double, String, Pointer, ConstPointer, Output, Skip_.
121
-
- When set to _Skip_ the corresponding method call on the `MockActualCall` object for the parameter will be skipped.
122
-
- <code><i><ArgExpr></i></code> is an optional argument expression that must contain the **'$'** character. If defined, it will be passed as the argument for the CppUMock actual call parameter method, replacing **'$'** by the mocked function parameter name.
132
+
- <code><i><MockedType></i></code> indicates the CppUMock type to use for the parameter, admitted values are: _Bool, Int, UnsignedInt, LongInt, UnsignedLongInt, Double, String, Pointer, ConstPointer, Output, Skip_, or an <code>InputOfType</code> or <code>OutputOfType</code> option.
133
+
- When set to _Skip_ the corresponding method call on the `MockActualCall` and `MockExpectedCall` objects for the parameter will be skipped, and the parameter will not appear in the signature of expectation helper functions.
134
+
- An <code>InputOfType</code> option takes the form <b>'InputOfType:'</b><code><i><DeclaredType></i></code>[<b>'<'</b><code><i><ExpectationHelperType></i></code>], where:
135
+
- <code><i><DeclaredType></i></code> indicates the type name to be passed to the <code>withParameterOfType</code> method of <code>MockActualCall</code> and <code>MockExpectedCall</code>.
136
+
- <code><i><ExpectationHelperType></i></code> optionally indicates an override type to use as the argument of expectation helper functions.
137
+
- An <code>OutputOfType</code> option takes the form <b>'OutputOfType:'</b><code><i><DeclaredType></i></code>[<b>'<'</b><code><i><ExpectationHelperType></i></code>], where:
138
+
- <code><i><DeclaredType></i></code> indicates the type name to be passed to the <code>withOutputParameterOfType</code> method of <code>MockActualCall</code> and to the <code>withOutputParameterOfTypeReturning</code> method of <code>MockExpectedCall</code>.
139
+
- <code><i><ExpectationHelperType></i></code> optionally indicates an override type to use as the argument of expectation helper functions.
140
+
- <code><i><ArgExpr></i></code> is an optional C++ expression that must contain the **'$'** placeholder character. If defined, it will be passed as the argument for the CppUMock actual call parameter method, replacing **'$'** by the mocked function parameter name.
123
141
124
142
##### Generic return type override
125
143
126
144
Generic return type override options take the form:
- <code><i><ReturnType></i></code> is a C/C++ data type.
132
150
- <code><i><MockedType></i></code> indicates the CppUMock type to use for the return value, admitted values are: _Bool, Int, UnsignedInt, LongInt, UnsignedLongInt, Double, String, Pointer, ConstPointer_.
133
-
- <code><i><ArgExpr></i></code> is an optional argument expression that must contain the **'$'** character. If defined, it will be used as the return value of the mocked function, replacing **'$'** by the CppUMock actual call sequence.
151
+
- <code><i><RetExpr></i></code> is an optional C++ expression that must contain the **'$'** character. If defined, it will be used as the return value of the mocked function, replacing **'$'** by the CppUMock actual call sequence.
134
152
135
-
####Mocked Type Override Examples
153
+
### Mocked Type Override Examples
136
154
137
-
######Example 1: Specific parameter type override
155
+
##### Example 1: Specific parameter type override
138
156
139
157
Assuming that we want to mock the following class:
140
158
@@ -151,20 +169,29 @@ namespace namespace1
151
169
If we want to override parameter `p1` to check just the pointed value, we can use the following option:
If we want to override parameter `p` because it is not really a string and the return type because the real function is ill-designed and really just returns pointers to unmutable strings, we can use the following options:
If we want to override all parameters of type `const std::string&` and `std::string` return types to be used as strings, we can use the following options:
MockExpectedCall& foo(unsigned int __numCalls__, CppUMockGen::Parameter<const char *> p1, CppUMockGen::Parameter<int> p3);
297
+
}
298
+
```
299
+
300
+
 
301
+
##### Examle 5: Typed output parameter with asymetrical copier
302
+
303
+
Assuming that we want to mock the following function:
304
+
305
+
```cpp
306
+
voidbar( std::ostream & output );
307
+
```
308
+
309
+
As it is hard (if not even impossible) to copy an output stream into another, we can define an asymetrical CppUMock copier that outputs a string into the output stream:
310
+
311
+
```cpp
312
+
class StdOstreamCopier : public MockNamedValueCopier
313
+
{
314
+
public:
315
+
virtual void copy(void* out, const void* in)
316
+
{
317
+
*(std::ostream*)out << *(const std::string*)in;
318
+
}
319
+
};
320
+
```
321
+
322
+
CppUMockGen normal behavior with typed output parameters is to expect a symetrical copier. To override the normal behavior and force usage of an asymetrical copier, we can use the following options:
0 commit comments