MRPT  2.0.4
exception_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <gtest/gtest.h>
11 #include <mrpt/core/exceptions.h>
12 #include <algorithm> // count()
13 #include <sstream>
14 
15 TEST(exception, stackedExceptionBasic)
16 {
17  EXPECT_THROW({ THROW_STACKED_EXCEPTION; }, std::logic_error);
18 }
19 
21 {
23  THROW_EXCEPTION("Aw!");
24  MRPT_END
25 }
26 
28 {
31  MRPT_END
32 }
33 
35 {
38  MRPT_END
39 }
40 
41 TEST(exception, stackedExceptionComplex)
42 {
43  try
44  {
46  GTEST_FAIL() << "Shouldn't reach here.";
47  }
48  catch (const std::exception& e)
49  {
50  const auto sExc = mrpt::exception_to_str(e);
51  // std::cerr << sExc;
52  const auto num_lines = std::count(sExc.begin(), sExc.end(), '\n');
53  EXPECT_EQ(num_lines, 6);
54  }
55 }
56 
57 TEST(exception, assertException)
58 {
59  bool trueValue = true;
60  bool falseValue = false;
61  EXPECT_THROW({ ASSERT_EQUAL_(trueValue, falseValue); }, std::logic_error);
62 }
63 
64 TEST(exception, stackedExceptionCustomMsg)
65 {
66  EXPECT_THROW(
67  { THROW_STACKED_EXCEPTION_CUSTOM_MSG2("Foo %s\n", "bar"); },
68  std::logic_error);
69 }
#define MRPT_START
Definition: exceptions.h:241
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:67
void test_except_2nd_lvl()
#define ASSERT_EQUAL_(__A, __B)
Assert comparing two values, reporting their actual values upon failure.
Definition: exceptions.h:137
void test_except_toplevel()
#define MRPT_END
Definition: exceptions.h:245
EXPECT_EQ(out.image_pair_was_used.size(), NUM_IMGS)
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
Definition: exceptions.cpp:59
TEST(exception, stackedExceptionBasic)
void test_except_3rd_lvl()
#define THROW_STACKED_EXCEPTION_CUSTOM_MSG2(stuff, param1)
Definition: exceptions.h:90
#define THROW_STACKED_EXCEPTION
Definition: exceptions.h:79



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020