MRPT  2.0.1
xassert_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/typemeta/xassert.h>
12 
13 constexpr int foo_i_below_10(unsigned i) { return MRPT_X_ASSERT(i < 10), 0; }
14 TEST(XAssert, build_time)
15 {
16  // Builds:
17  constexpr int x = foo_i_below_10(0);
18  (void)(x);
19 
20  // Does not build
21  // constexpr int y = foo_i_below_10(11);
22 
23  // runs:
24  foo_i_below_10(0);
25 
26  // throws:
27  EXPECT_THROW(foo_i_below_10(11), std::exception);
28 }
constexpr int foo_i_below_10(unsigned i)
#define MRPT_X_ASSERT(CHECK)
MRPT_X_ASSERT(): build error if condition is known not to work at compile time, throw an exception at...
Definition: xassert.h:27
TEST(XAssert, build_time)



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020