]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/STUB.h
6 * A set of useful macros to create stub_* files.
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.
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.
17 * #define STUB_API "foo/libexample.la"
18 * #include "tests/STUB.h"
21 /// macro to stub a void function.
22 #define STUB { fatal(STUB_API " required"); }
24 /** macro to stub a function with return value.
25 * Aborts unit tests requiring its definition with a message about the missing linkage
27 #define STUB_RETVAL(x) { fatal(STUB_API " required"); return x; }
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
34 #define STUB_RETREF(x) { fatal(STUB_API " required"); return new x; }
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
41 #define STUB_RETSTATREF(x) { fatal(STUB_API " required"); static x v; return v; }