macros.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2021 CNRS INRIA
3 //
4 
5 #include "pinocchio/macros.hpp"
6 
7 #include <boost/test/unit_test.hpp>
8 #include <boost/utility/binary.hpp>
9 
10 using namespace pinocchio;
11 
12 std::string expected_msg;
13 
14 bool check_exception_msg(const std::exception & exception)
15 {
16  BOOST_CHECK_EQUAL(expected_msg, exception.what());
17  return expected_msg == exception.what();
18 }
19 
20 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
21 
22 void function_1(std::vector<int> v, size_t size)
23 {
25  //"size of input vector should be " << size)
26 }
27 void function_2(std::vector<int> v, size_t size)
28 {
30  v.size(), size,
31  "custom message "
32  << "with stream");
33 }
34 
35 BOOST_AUTO_TEST_CASE(test_check_arguments)
36 {
37  expected_msg = "wrong argument size: expected 2, got 3\n"
38  "hint: v.size() is different from size\n";
39  BOOST_CHECK_EXCEPTION(
40  function_1(std::vector<int>(3), 2), std::invalid_argument, check_exception_msg);
41  expected_msg = "wrong argument size: expected 2, got 3\n"
42  "hint: custom message with stream\n";
43  BOOST_CHECK_EXCEPTION(
44  function_2(std::vector<int>(3), 2), std::invalid_argument, check_exception_msg);
45 }
46 
47 BOOST_AUTO_TEST_SUITE_END()
PINOCCHIO_CHECK_ARGUMENT_SIZE
#define PINOCCHIO_CHECK_ARGUMENT_SIZE(...)
Macro to check if the size of an element is equal to the expected size.
Definition: include/pinocchio/macros.hpp:217
check_exception_msg
bool check_exception_msg(const std::exception &exception)
Definition: macros.cpp:14
macros.hpp
function_2
void function_2(std::vector< int > v, size_t size)
Definition: macros.cpp:27
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(test_check_arguments)
Definition: macros.cpp:35
size
FCL_REAL size() const
function_1
void function_1(std::vector< int > v, size_t size)
Definition: macros.cpp:22
pinocchio::v
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > const Eigen::MatrixBase< TangentVectorType > & v
Definition: joint-configuration.hpp:1118
expected_msg
std::string expected_msg
Definition: macros.cpp:12
std
Definition: autodiff/casadi/utils/static-if.hpp:64
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27


pinocchio
Author(s):
autogenerated on Sat Jun 22 2024 02:41:48