forked from arstrube/FakeFunctions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUsed_Fake.cpp
53 lines (46 loc) · 1.45 KB
/
Used_Fake.cpp
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
#include "CppUTestExt/MockSupport.h"
#include "Used_Fake.h"
namespace Dummy {
long Used_add(long, long) { return 0L; }
long Used_subtract(long, long) { return 0L; }
}
#include <cstdio>
namespace Stub {
long Used_add(long a, long b) {
printf("\n Used_add(%ld, %ld) was called\n", a, b);
return a + b;
}
long Used_subtract(long a, long b) {
printf("\n Used_subtract(%ld, %ld) was called\n", a, b);
return a - b;
}
}
namespace Mock {
long Used_add(long a, long b) {
mock().actualCall("Used_add")
.withParameter("a", a).withParameter("b", b);
return mock().returnValue().getLongIntValue();
}
long Used_subtract(long a, long b) {
mock().actualCall("Used_subtract")
.withParameter("a", a).withParameter("b", b);
return mock().returnValue().getLongIntValue();
}
}
/** Original C code -- do not build elsewhere !
*/
namespace C {
#include "Used.c" /** C++ will mangle function names */
}
/** Initialization of function pointers
*/
long (*Used_Fake::add)(long a, long b) = Dummy::Used_add;
long (*Used_Fake::subtract)(long a, long b) = Dummy::Used_subtract;
/** Wrappers to be linked in place of original functions
*/
extern "C" long Used_add(long a, long b) {
return Used_Fake::add(a, b);
}
extern "C" long Used_subtract(long a, long b) {
return Used_Fake::subtract(a, b);
}