]>
Commit | Line | Data |
---|---|---|
7c8931a1 AJ |
1 | #ifndef STUB |
2 | #include "fatal.h" | |
3 | ||
8658767a AJ |
4 | /** \group STUB |
5 | * | |
6 | * A set of useful macros to create stub_* files. | |
7 | * | |
8 | * Intended for use building unit tests, if a stubbed function is called | |
9 | * by any code it is linked to it will abort with a message indicating | |
10 | * which API file is missing from the linked dependencies. | |
11 | * | |
12 | * Usage: | |
13 | * at the top of your intended stub file define STUB_API to be the | |
14 | * name of the .cc file or library you are providing a stub of | |
15 | * then include this STUB.h header. | |
16 | * | |
17 | * #define STUB_API "foo/libexample.la" | |
18 | * #include "tests/STUB.h" | |
19 | */ | |
20 | ||
21 | /// macro to stub a void function. | |
7c8931a1 | 22 | #define STUB { fatal(STUB_API " required"); } |
8658767a AJ |
23 | |
24 | /** macro to stub a function with return value. | |
25 | * Aborts unit tests requiring its definition with a message about the missing linkage | |
26 | */ | |
7c8931a1 | 27 | #define STUB_RETVAL(x) { fatal(STUB_API " required"); return x; } |
8658767a AJ |
28 | |
29 | /** macro to stub a function which returns a reference to dynamic | |
30 | * Aborts unit tests requiring its definition with a message about the missing linkage | |
31 | * This macro uses 'new x' to construct a stack vailable for the reference, may leak. | |
32 | * \param x may be the type to define or a constructor call with parameter values | |
33 | */ | |
7c8931a1 | 34 | #define STUB_RETREF(x) { fatal(STUB_API " required"); return new x; } |
8658767a AJ |
35 | |
36 | /** macro to stub a function which returns a reference to static | |
37 | * Aborts unit tests requiring its definition with a message about the missing linkage | |
38 | * This macro uses static variable definition to avoid leaks. | |
39 | * \param x the type name to define | |
40 | */ | |
7c8931a1 AJ |
41 | #define STUB_RETSTATREF(x) { fatal(STUB_API " required"); static x v; return v; } |
42 | ||
43 | #endif /* STUB */ |