]> git.ipfire.org Git - thirdparty/squid.git/blame - src/tests/STUB.h
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / tests / STUB.h
CommitLineData
4e0938ef 1/*
77b1029d 2 * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
4e0938ef
AJ
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
24885773 30#define stub_fatal(m) { std::cerr<<"FATAL: "<<(m)<<" for use of "<<__FUNCTION__<<"\n"; exit(EXIT_FAILURE); }
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
3dfa82a5 49 * \param x underlying or "referred to" type
8658767a 50 */
3dfa82a5 51#define STUB_RETREF(x) { stub_fatal(STUB_API " required"); return *(x *)nullptr; }
8658767a 52
3dfa82a5
AR
53/** Same as STUB_RETREF(). TODO: Remove */
54#define STUB_RETSTATREF(x) STUB_RETREF(x)
7c8931a1
AJ
55
56#endif /* STUB */
f53969cc 57