Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 5f35f64 | 2018-05-10 19:36:03 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2018, Regents of the University of California, |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | /** \file |
| 27 | * \brief provides unit testing tools to validate runtime type information |
| 28 | */ |
| 29 | |
| 30 | #ifndef NFD_TESTS_CHECK_TYPEID_HPP |
| 31 | #define NFD_TESTS_CHECK_TYPEID_HPP |
| 32 | |
| 33 | #include "boost-test.hpp" |
Davide Pesavento | 5f35f64 | 2018-05-10 19:36:03 -0400 | [diff] [blame] | 34 | |
| 35 | #include <boost/core/demangle.hpp> |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 36 | #include <typeinfo> |
| 37 | |
| 38 | /** \def NFD_TYPEID_NAME(x) |
| 39 | * \return type name of typeid(x) as std::string |
| 40 | */ |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 41 | #define NFD_TYPEID_NAME(x) (::boost::core::demangle(typeid(x).name())) |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 42 | |
| 43 | /** (implementation detail) |
| 44 | */ |
| 45 | #define NFD_TEST_TYPEID_REL(level, a, op, b) \ |
| 46 | BOOST_##level##_MESSAGE((typeid(a) op typeid(b)), \ |
| 47 | "expect typeid(" #a ") " #op " typeid(" #b ") [" << \ |
| 48 | NFD_TYPEID_NAME(a) << " " #op " " << NFD_TYPEID_NAME(b) << "]") |
| 49 | |
| 50 | /** (implementation detail) |
| 51 | */ |
| 52 | #define NFD_TEST_TYPEID_EQUAL(level, a, b) NFD_TEST_TYPEID_REL(level, a, ==, b) |
| 53 | |
| 54 | /** (implementation detail) |
| 55 | */ |
| 56 | #define NFD_TEST_TYPEID_NE(level, a, b) NFD_TEST_TYPEID_REL(level, a, !=, b) |
| 57 | |
| 58 | /** \brief equivalent to BOOST_REQUIRE(typeid(a) == typeid(b)) |
| 59 | */ |
| 60 | #define NFD_REQUIRE_TYPEID_EQUAL(a, b) NFD_TEST_TYPEID_EQUAL(REQUIRE, a, b) |
| 61 | |
| 62 | /** \brief equivalent to BOOST_REQUIRE(typeid(a) != typeid(b)) |
| 63 | */ |
| 64 | #define NFD_REQUIRE_TYPEID_NE(a, b) NFD_TEST_TYPEID_NE(REQUIRE, a, b) |
| 65 | |
| 66 | /** \brief equivalent to BOOST_CHECK(typeid(a) == typeid(b)) |
| 67 | */ |
| 68 | #define NFD_CHECK_TYPEID_EQUAL(a, b) NFD_TEST_TYPEID_EQUAL(CHECK, a, b) |
| 69 | |
| 70 | /** \brief equivalent to BOOST_CHECK(typeid(a) != typeid(b)) |
| 71 | */ |
| 72 | #define NFD_CHECK_TYPEID_NE(a, b) NFD_TEST_TYPEID_NE(CHECK, a, b) |
| 73 | |
| 74 | /** \brief equivalent to BOOST_WARN(typeid(a) == typeid(b)) |
| 75 | */ |
| 76 | #define NFD_WARN_TYPEID_EQUAL(a, b) NFD_TEST_TYPEID_EQUAL(WARN, a, b) |
| 77 | |
| 78 | /** \brief equivalent to BOOST_WARN(typeid(a) != typeid(b)) |
| 79 | */ |
| 80 | #define NFD_WARN_TYPEID_NE(a, b) NFD_TEST_TYPEID_NE(WARN, a, b) |
| 81 | |
| 82 | #endif // NFD_TESTS_CHECK_TYPEID_HPP |