Skip to content

Commit 117845d

Browse files
committed
Complete rcl package's logging API test coverage.
Signed-off-by: Michel Hidalgo <[email protected]>
1 parent 6967075 commit 117845d

File tree

3 files changed

+427
-0
lines changed

3 files changed

+427
-0
lines changed

rcl/test/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,13 @@ rcl_add_custom_gtest(test_localhost
370370
LIBRARIES ${PROJECT_NAME}
371371
)
372372

373+
rcl_add_custom_gtest(test_logging
374+
SRCS rcl/test_logging.cpp
375+
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
376+
LIBRARIES ${PROJECT_NAME} mimick
377+
AMENT_DEPENDENCIES "osrf_testing_tools_cpp"
378+
)
379+
373380
rcl_add_custom_gtest(test_validate_topic_name
374381
SRCS rcl/test_validate_topic_name.cpp
375382
APPEND_LIBRARY_DIRS ${extra_lib_dirs}

rcl/test/mocking_utils/patch.hpp

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include <utility>
3737

3838
#include "mimick/mimick.h"
39+
40+
#include "rcutils/error_handling.h"
3941
#include "rcutils/macros.h"
4042

4143
namespace mocking_utils
@@ -60,6 +62,19 @@ struct PatchTraits<ID, ReturnT(void)>
6062
mmk_mock_define(mock_type, ReturnT);
6163
};
6264

65+
/// Traits specialization for void(void) free functions.
66+
/**
67+
* Necessary for Mimick macros to adjust accordingly when the return
68+
* type is `void`.
69+
*
70+
* \tparam ID Numerical identifier of the patch. Ought to be unique.
71+
*/
72+
template<size_t ID>
73+
struct PatchTraits<ID, void(void)>
74+
{
75+
mmk_mock_define(mock_type, void);
76+
};
77+
6378
/// Traits specialization for ReturnT(ArgT0) free functions.
6479
/**
6580
* \tparam ID Numerical identifier of the patch. Ought to be unique.
@@ -72,6 +87,20 @@ struct PatchTraits<ID, ReturnT(ArgT0)>
7287
mmk_mock_define(mock_type, ReturnT, ArgT0);
7388
};
7489

90+
/// Traits specialization for void(ArgT0) free functions.
91+
/**
92+
* Necessary for Mimick macros to adjust accordingly when the return
93+
* type is `void`.
94+
*
95+
* \tparam ID Numerical identifier of the patch. Ought to be unique.
96+
* \tparam ArgT0 Argument type.
97+
*/
98+
template<size_t ID, typename ArgT0>
99+
struct PatchTraits<ID, void(ArgT0)>
100+
{
101+
mmk_mock_define(mock_type, void, ArgT0);
102+
};
103+
75104
/// Traits specialization for ReturnT(ArgT0, ArgT1) free functions.
76105
/**
77106
* \tparam ID Numerical identifier of the patch. Ought to be unique.
@@ -85,6 +114,20 @@ struct PatchTraits<ID, ReturnT(ArgT0, ArgT1)>
85114
mmk_mock_define(mock_type, ReturnT, ArgT0, ArgT1);
86115
};
87116

117+
/// Traits specialization for void(ArgT0, ArgT1) free functions.
118+
/**
119+
* Necessary for Mimick macros to adjust accordingly when the return
120+
* type is `void`.
121+
*
122+
* \tparam ID Numerical identifier of the patch. Ought to be unique.
123+
* \tparam ArgTx Argument types.
124+
*/
125+
template<size_t ID, typename ArgT0, typename ArgT1>
126+
struct PatchTraits<ID, void(ArgT0, ArgT1)>
127+
{
128+
mmk_mock_define(mock_type, void, ArgT0, ArgT1);
129+
};
130+
88131
/// Traits specialization for ReturnT(ArgT0, ArgT1, ArgT2) free functions.
89132
/**
90133
* \tparam ID Numerical identifier of the patch. Ought to be unique.
@@ -98,6 +141,20 @@ struct PatchTraits<ID, ReturnT(ArgT0, ArgT1, ArgT2)>
98141
mmk_mock_define(mock_type, ReturnT, ArgT0, ArgT1, ArgT2);
99142
};
100143

144+
/// Traits specialization for void(ArgT0, ArgT1, ArgT2) free functions.
145+
/**
146+
* Necessary for Mimick macros to adjust accordingly when the return
147+
* type is `void`.
148+
*
149+
* \tparam ID Numerical identifier of the patch. Ought to be unique.
150+
* \tparam ArgTx Argument types.
151+
*/
152+
template<size_t ID, typename ArgT0, typename ArgT1, typename ArgT2>
153+
struct PatchTraits<ID, void(ArgT0, ArgT1, ArgT2)>
154+
{
155+
mmk_mock_define(mock_type, void, ArgT0, ArgT1, ArgT2);
156+
};
157+
101158
/// Traits specialization for ReturnT(ArgT0, ArgT1, ArgT2, ArgT3) free functions.
102159
/**
103160
* \tparam ID Numerical identifier of the patch. Ought to be unique.
@@ -112,6 +169,22 @@ struct PatchTraits<ID, ReturnT(ArgT0, ArgT1, ArgT2, ArgT3)>
112169
mmk_mock_define(mock_type, ReturnT, ArgT0, ArgT1, ArgT2, ArgT3);
113170
};
114171

172+
/// Traits specialization for void(ArgT0, ArgT1, ArgT2, ArgT3) free functions.
173+
/**
174+
* Necessary for Mimick macros to adjust accordingly when the return
175+
* type is `void`.
176+
*
177+
* \tparam ID Numerical identifier of the patch. Ought to be unique.
178+
* \tparam ArgTx Argument types.
179+
*/
180+
template<size_t ID,
181+
typename ArgT0, typename ArgT1,
182+
typename ArgT2, typename ArgT3>
183+
struct PatchTraits<ID, void(ArgT0, ArgT1, ArgT2, ArgT3)>
184+
{
185+
mmk_mock_define(mock_type, void, ArgT0, ArgT1, ArgT2, ArgT3);
186+
};
187+
115188
/// Traits specialization for ReturnT(ArgT0, ArgT1, ArgT2, ArgT3, ArgT4)
116189
/// free functions.
117190
/**
@@ -127,6 +200,23 @@ struct PatchTraits<ID, ReturnT(ArgT0, ArgT1, ArgT2, ArgT3, ArgT4)>
127200
mmk_mock_define(mock_type, ReturnT, ArgT0, ArgT1, ArgT2, ArgT3, ArgT4);
128201
};
129202

203+
/// Traits specialization for void(ArgT0, ArgT1, ArgT2, ArgT3, ArgT4)
204+
/// free functions.
205+
/**
206+
* Necessary for Mimick macros to adjust accordingly when the return
207+
* type is `void`.
208+
*
209+
* \tparam ID Numerical identifier of the patch. Ought to be unique.
210+
* \tparam ArgTx Argument types.
211+
*/
212+
template<size_t ID,
213+
typename ArgT0, typename ArgT1,
214+
typename ArgT2, typename ArgT3, typename ArgT4>
215+
struct PatchTraits<ID, void(ArgT0, ArgT1, ArgT2, ArgT3, ArgT4)>
216+
{
217+
mmk_mock_define(mock_type, void, ArgT0, ArgT1, ArgT2, ArgT3, ArgT4);
218+
};
219+
130220
/// Traits specialization for ReturnT(ArgT0, ArgT1, ArgT2, ArgT3, ArgT4, ArgT5)
131221
/// free functions.
132222
/**
@@ -144,6 +234,25 @@ struct PatchTraits<ID, ReturnT(ArgT0, ArgT1, ArgT2, ArgT3, ArgT4, ArgT5)>
144234
mock_type, ReturnT, ArgT0, ArgT1, ArgT2, ArgT3, ArgT4, ArgT5);
145235
};
146236

237+
/// Traits specialization for void(ArgT0, ArgT1, ArgT2, ArgT3, ArgT4, ArgT5)
238+
/// free functions.
239+
/**
240+
* Necessary for Mimick macros to adjust accordingly when the return
241+
* type is `void`.
242+
*
243+
* \tparam ID Numerical identifier of the patch. Ought to be unique.
244+
* \tparam ArgTx Argument types.
245+
*/
246+
template<size_t ID,
247+
typename ArgT0, typename ArgT1,
248+
typename ArgT2, typename ArgT3,
249+
typename ArgT4, typename ArgT5>
250+
struct PatchTraits<ID, void(ArgT0, ArgT1, ArgT2, ArgT3, ArgT4, ArgT5)>
251+
{
252+
mmk_mock_define(
253+
mock_type, void, ArgT0, ArgT1, ArgT2, ArgT3, ArgT4, ArgT5);
254+
};
255+
147256
/// Generic trampoline to wrap generalized callables in plain functions.
148257
/**
149258
* \tparam ID Numerical identifier of this trampoline. Ought to be unique.
@@ -354,6 +463,14 @@ auto make_patch(const std::string & target, std::function<SignatureT> proxy)
354463
#define patch_and_return(scope, function, return_code) \
355464
patch(scope, function, [&](auto && ...) {return return_code;})
356465

466+
/// Patch a `function` to always yield a given `return_code` in a given `scope`.
467+
#define patch_to_fail(scope, function, error_message, return_code) \
468+
patch( \
469+
scope, function, [&](auto && ...) { \
470+
RCUTILS_SET_ERROR_MSG(error_message); \
471+
return return_code; \
472+
})
473+
357474
/// Patch a `function` to execute normally but always yield a given `return_code`
358475
/// in a given `scope`.
359476
#define inject_on_return(scope, function, return_code) \

0 commit comments

Comments
 (0)