GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: unittest/macros.cpp Lines: 13 13 100.0 %
Date: 2024-01-23 21:41:47 Branches: 86 196 43.9 %

Line Branch Exec Source
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
2
bool check_exception_msg (const std::exception& exception)
15
{
16


2
  BOOST_CHECK_EQUAL(expected_msg, exception.what());
17
2
  return expected_msg == exception.what();
18
}
19
20
BOOST_AUTO_TEST_SUITE ( BOOST_TEST_MODULE )
21
22
1
void function_1(std::vector<int> v, size_t size)
23
{
24






1
  PINOCCHIO_CHECK_ARGUMENT_SIZE(v.size(), size);
25
      //"size of input vector should be " << size)
26
}
27
1
void function_2(std::vector<int> v, size_t size)
28
{
29






1
  PINOCCHIO_CHECK_ARGUMENT_SIZE(v.size(), size,
30
      "custom message " << "with stream");
31
}
32
33
















4
BOOST_AUTO_TEST_CASE(test_check_arguments)
34
{
35
  expected_msg = "wrong argument size: expected 2, got 3\n"
36
2
    "hint: v.size() is different from size\n";
37









10
  BOOST_CHECK_EXCEPTION(function_1(std::vector<int>(3), 2),
38
      std::invalid_argument,
39
      check_exception_msg);
40
  expected_msg = "wrong argument size: expected 2, got 3\n"
41
2
    "hint: custom message with stream\n";
42









10
  BOOST_CHECK_EXCEPTION(function_2(std::vector<int>(3), 2),
43
      std::invalid_argument,
44
      check_exception_msg);
45
2
}
46
47
BOOST_AUTO_TEST_SUITE_END()