mimic++ v4
Loading...
Searching...
No Matches
InterfaceMock.hpp
Go to the documentation of this file.
1// // Copyright Dominic (DNKpp) Koepke 2024 - 2024.
2// // Distributed under the Boost Software License, Version 1.0.
3// // (See accompanying file LICENSE_1_0.txt or copy at
4// // https://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef MIMICPP_INTERFACE_MOCK_HPP
7#define MIMICPP_INTERFACE_MOCK_HPP
8
9#pragma once
10
11#include "mimic++/Fwd.hpp"
12#include "mimic++/Mock.hpp"
13
14#include <type_traits>
15#include <utility>
16
17namespace mimicpp
18{
54}
55
62#define MIMICPP_DETAIL_STRIP_PARENS(x) MIMICPP_DETAIL_STRIP_PARENS_OUTER(MIMICPP_DETAIL_STRIP_PARENS_INNER x)
63
68#define MIMICPP_DETAIL_STRIP_PARENS_INNER(...) MIMICPP_DETAIL_STRIP_PARENS_INNER __VA_ARGS__
69
74#define MIMICPP_DETAIL_STRIP_PARENS_OUTER(...) MIMICPP_DETAIL_STRIP_PARENS_OUTER_(__VA_ARGS__)
75
80#define MIMICPP_DETAIL_STRIP_PARENS_OUTER_(...) MIMICPP_DETAIL_STRIP_PARENS_STRIPPED_ ## __VA_ARGS__
81
86#define MIMICPP_DETAIL_STRIP_PARENS_STRIPPED_MIMICPP_DETAIL_STRIP_PARENS_INNER
87
88namespace mimicpp
89{
100}
101
106#define MIMICPP_DETAIL_PARENS ()
107
112#define MIMICPP_DETAIL_COMMA_DELIMITER() ,
113
118#define MIMICPP_DETAIL_NO_DELIMITER()
119
124#define MIMICPP_DETAIL_IDENTITY(...) __VA_ARGS__
125
130#define MIMICPP_DETAIL_EXPAND(...) MIMICPP_DETAIL_EXPAND3(MIMICPP_DETAIL_EXPAND3(MIMICPP_DETAIL_EXPAND3(MIMICPP_DETAIL_EXPAND3(__VA_ARGS__))))
131
136#define MIMICPP_DETAIL_EXPAND3(...) MIMICPP_DETAIL_EXPAND2(MIMICPP_DETAIL_EXPAND2(MIMICPP_DETAIL_EXPAND2(MIMICPP_DETAIL_EXPAND2(__VA_ARGS__))))
137
142#define MIMICPP_DETAIL_EXPAND2(...) MIMICPP_DETAIL_EXPAND1(MIMICPP_DETAIL_EXPAND1(MIMICPP_DETAIL_EXPAND1(MIMICPP_DETAIL_EXPAND1(__VA_ARGS__))))
143
148#define MIMICPP_DETAIL_EXPAND1(...) __VA_ARGS__
149
157#define MIMICPP_DETAIL_FOR_EACH_EXT_INDIRECT(macro, sequence, ...) macro(sequence, __VA_ARGS__)
158
174#define MIMICPP_DETAIL_FOR_EACH_EXT(macro, token, delimiter, projection_macro, bound, ...) \
175 __VA_OPT__(MIMICPP_DETAIL_EXPAND(MIMICPP_DETAIL_FOR_EACH_EXT_HELPER(macro, token, token, delimiter, projection_macro, bound, __VA_ARGS__)))
176
181#define MIMICPP_DETAIL_FOR_EACH_EXT_HELPER(macro, token, sequence, delimiter, projection_macro, bound, a1, ...) \
182 MIMICPP_DETAIL_FOR_EACH_EXT_INDIRECT(macro, sequence, MIMICPP_DETAIL_STRIP_PARENS(bound), projection_macro(a1)) \
183 __VA_OPT__(delimiter() MIMICPP_FOR_EACH_EXT_AGAIN MIMICPP_DETAIL_PARENS (macro, token, sequence##token, delimiter, projection_macro, bound, __VA_ARGS__))
184
189#define MIMICPP_FOR_EACH_EXT_AGAIN() MIMICPP_DETAIL_FOR_EACH_EXT_HELPER
190
191namespace mimicpp
192{
198}
199
209#define MIMICPP_DETAIL_MAKE_SIGNATURE(sequence, bound_data, ret, param_type_list, specs, ...) ret param_type_list specs
210
215#define MIMICPP_DETAIL_MAKE_SIGNATURE_LIST(...) \
216 MIMICPP_DETAIL_FOR_EACH_EXT( \
217 MIMICPP_DETAIL_MAKE_SIGNATURE, \
218 , \
219 MIMICPP_DETAIL_COMMA_DELIMITER, \
220 MIMICPP_DETAIL_STRIP_PARENS, \
221 , \
222 __VA_ARGS__)
223
230#define MIMICPP_DETAIL_MAKE_OVERLOADED_MOCK(mock_name, signatures) \
231 ::mimicpp::Mock< MIMICPP_DETAIL_STRIP_PARENS(signatures) > mock_name{}
232
233namespace mimicpp
234{
240}
241
249#define MIMICPP_DETAIL_MAKE_PARAM(sequence, bound_data, type) MIMICPP_DETAIL_STRIP_PARENS(type) arg_##sequence
250
255#define MIMICPP_DETAIL_MAKE_PARAM_LIST(...) \
256 MIMICPP_DETAIL_FOR_EACH_EXT( \
257 MIMICPP_DETAIL_MAKE_PARAM, \
258 i, \
259 MIMICPP_DETAIL_COMMA_DELIMITER, \
260 MIMICPP_DETAIL_IDENTITY, \
261 , \
262 __VA_ARGS__)
263
264namespace mimicpp
265{
271}
272
280#define MIMICPP_DETAIL_FORWARD_ARG(sequence, bound_data, type) \
281 ::std::forward<::std::add_rvalue_reference_t<MIMICPP_DETAIL_STRIP_PARENS(type)>>(arg_##sequence)
282
287#define MIMICPP_DETAIL_FORWARD_ARGS(...) \
288 MIMICPP_DETAIL_FOR_EACH_EXT( \
289 MIMICPP_DETAIL_FORWARD_ARG, \
290 i, \
291 MIMICPP_DETAIL_COMMA_DELIMITER, \
292 MIMICPP_DETAIL_IDENTITY, \
293 , \
294 __VA_ARGS__)
295
296namespace mimicpp
297{
303}
304
312#define MIMICPP_DETAIL_MAKE_OVERLOAD_INFOS_SPECS(ret, param_type_list, specs, ...) \
313 (ret, param_type_list, specs, \
314 (MIMICPP_DETAIL_MAKE_PARAM_LIST(MIMICPP_DETAIL_STRIP_PARENS(param_type_list))), \
315 (MIMICPP_DETAIL_FORWARD_ARGS(MIMICPP_DETAIL_STRIP_PARENS(param_type_list))))
316
323#define MIMICPP_DETAIL_MAKE_OVERLOAD_INFOS_BASIC(ret, param_type_list, ...) \
324 MIMICPP_DETAIL_MAKE_OVERLOAD_INFOS_SPECS(ret, param_type_list, )
325
331#define MIMICPP_DETAIL_SELECT_MAKE_OVERLOAD_INFOS(_1, N, ...) N
332
340#define MIMICPP_ADD_OVERLOAD(ret, param_type_list, ...) \
341 MIMICPP_DETAIL_SELECT_MAKE_OVERLOAD_INFOS( \
342 __VA_ARGS__, \
343 MIMICPP_DETAIL_MAKE_OVERLOAD_INFOS_SPECS, \
344 MIMICPP_DETAIL_MAKE_OVERLOAD_INFOS_BASIC)(ret, param_type_list, __VA_ARGS__,) // clangCl doesn't compile without that extra ,
345
346namespace mimicpp
347{
353}
354
367#define MIMICPP_DETAIL_MAKE_METHOD_OVERRIDE(ignore, mock_name, fn_name, ret, param_type_list, specs, param_list, forward_list, ...) \
368 inline MIMICPP_DETAIL_STRIP_PARENS(ret) fn_name param_list MIMICPP_DETAIL_STRIP_PARENS(specs) override \
369 { \
370 return mock_name (MIMICPP_DETAIL_STRIP_PARENS(forward_list)); \
371 }
372
379#define MIMICPP_DETAIL_MAKE_METHOD_OVERRIDES(mock_name, fn_name, ...) \
380 MIMICPP_DETAIL_FOR_EACH_EXT( \
381 MIMICPP_DETAIL_MAKE_METHOD_OVERRIDE, \
382 , \
383 MIMICPP_DETAIL_NO_DELIMITER, \
384 MIMICPP_DETAIL_STRIP_PARENS, \
385 (mock_name, fn_name), \
386 __VA_ARGS__)
387
398#define MIMICPP_MOCK_OVERLOADED_METHOD(fn_name, ...) \
399 MIMICPP_DETAIL_MAKE_METHOD_OVERRIDES(fn_name##_, fn_name, __VA_ARGS__) \
400 MIMICPP_DETAIL_MAKE_OVERLOADED_MOCK( \
401 fn_name##_, \
402 (MIMICPP_DETAIL_MAKE_SIGNATURE_LIST(__VA_ARGS__)))
403
414#define MIMICPP_MOCK_METHOD(fn_name, ret, param_type_list, ...) \
415 MIMICPP_MOCK_OVERLOADED_METHOD( \
416 fn_name, \
417 MIMICPP_ADD_OVERLOAD(ret, param_type_list __VA_OPT__(,) __VA_ARGS__ ))
418
419#ifndef MIMICPP_CONFIG_ONLY_PREFIXED_MACROS
420
425#define MOCK_METHOD MIMICPP_MOCK_METHOD
426
431#define MOCK_OVERLOADED_METHOD MIMICPP_MOCK_OVERLOADED_METHOD
432
437#define ADD_OVERLOAD MIMICPP_ADD_OVERLOAD
438
439#endif
440
441#endif
Definition BoostTest.hpp:20