]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/STUB.h
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
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.
13 * A set of useful macros to create stub_* files.
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.
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.
24 * #define STUB_API "foo/libexample.la"
25 * #include "tests/STUB.h"
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); }
32 /// macro to stub a void function.
33 #define STUB { stub_fatal(STUB_API " required"); }
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"; }
39 /// macro to stub a function with return value.
40 /// Aborts unit tests requiring its definition with a message about the missing linkage
41 #define STUB_RETVAL(x) { stub_fatal(STUB_API " required"); return x; }
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; }
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
52 #define STUB_RETREF(x) { stub_fatal(STUB_API " required"); return new x; }
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
59 #define STUB_RETSTATREF(x) { stub_fatal(STUB_API " required"); static x v; return v; }