]>
Commit | Line | Data |
---|---|---|
4e0938ef AJ |
1 | /* |
2 | * Copyright (C) 1996-2014 The Squid Software Foundation and contributors | |
3 | * | |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
7c8931a1 | 9 | #ifndef STUB |
7c8931a1 | 10 | |
8658767a AJ |
11 | /** \group STUB |
12 | * | |
13 | * A set of useful macros to create stub_* files. | |
daac1c64 | 14 | * |
8658767a AJ |
15 | * Intended for use building unit tests, if a stubbed function is called |
16 | * by any code it is linked to it will abort with a message indicating | |
17 | * which API file is missing from the linked dependencies. | |
18 | * | |
19 | * Usage: | |
20 | * at the top of your intended stub file define STUB_API to be the | |
21 | * name of the .cc file or library you are providing a stub of | |
22 | * then include this STUB.h header. | |
23 | * | |
24 | * #define STUB_API "foo/libexample.la" | |
25 | * #include "tests/STUB.h" | |
26 | */ | |
081edc2d AJ |
27 | #include <iostream> |
28 | ||
29 | // Internal Special: the STUB framework requires this function | |
30 | #define stub_fatal(m) { std::cerr<<"FATAL: "<<(m)<<" for use of "<<__FUNCTION__<<"\n"; exit(1); } | |
8658767a AJ |
31 | |
32 | /// macro to stub a void function. | |
081edc2d AJ |
33 | #define STUB { stub_fatal(STUB_API " required"); } |
34 | ||
35 | /// macro to stub a void function without a fatal message | |
36 | /// Intended for registration pattern APIs where the function result does not matter to the test | |
37 | #define STUB_NOP { std::cerr<<"SKIP: "<<STUB_API<<" "<<__FUNCTION__<<" (not implemented).\n"; } | |
8658767a | 38 | |
bd765fdc FC |
39 | /// macro to stub a function with return value. |
40 | /// Aborts unit tests requiring its definition with a message about the missing linkage | |
081edc2d | 41 | #define STUB_RETVAL(x) { stub_fatal(STUB_API " required"); return x; } |
8658767a | 42 | |
bd765fdc FC |
43 | /// macro to stub a void function without a fatal message and with a return value |
44 | /// Intended for registration pattern APIs where the function result does not matter to the test | |
45 | #define STUB_RETVAL_NOP(x) { std::cerr<<"SKIP: "<<STUB_API<<" "<<__FUNCTION__<<" (not implemented).\n"; return x; } | |
46 | ||
8658767a AJ |
47 | /** macro to stub a function which returns a reference to dynamic |
48 | * Aborts unit tests requiring its definition with a message about the missing linkage | |
49 | * This macro uses 'new x' to construct a stack vailable for the reference, may leak. | |
50 | * \param x may be the type to define or a constructor call with parameter values | |
51 | */ | |
081edc2d | 52 | #define STUB_RETREF(x) { stub_fatal(STUB_API " required"); return new x; } |
8658767a AJ |
53 | |
54 | /** macro to stub a function which returns a reference to static | |
55 | * Aborts unit tests requiring its definition with a message about the missing linkage | |
56 | * This macro uses static variable definition to avoid leaks. | |
57 | * \param x the type name to define | |
58 | */ | |
081edc2d | 59 | #define STUB_RETSTATREF(x) { stub_fatal(STUB_API " required"); static x v; return v; } |
7c8931a1 AJ |
60 | |
61 | #endif /* STUB */ |