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 {
29  PINOCCHIO_CHECK_ARGUMENT_SIZE(v.size(), size, "custom message " << "with stream");
30 }
31 
32 BOOST_AUTO_TEST_CASE(test_check_arguments)
33 {
34  expected_msg = "wrong argument size: expected 2, got 3\n"
35  "hint: v.size() is different from size\n";
36  BOOST_CHECK_EXCEPTION(
37  function_1(std::vector<int>(3), 2), std::invalid_argument, check_exception_msg);
38  expected_msg = "wrong argument size: expected 2, got 3\n"
39  "hint: custom message with stream\n";
40  BOOST_CHECK_EXCEPTION(
41  function_2(std::vector<int>(3), 2), std::invalid_argument, check_exception_msg);
42 }
43 
44 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:216
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:32
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:1084
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 Thu Dec 19 2024 03:41:31