Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
| 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" |
| 34 | #include <typeinfo> |
| 35 | |
| 36 | /** \def NFD_TYPEID_NAME(x) |
| 37 | * \return type name of typeid(x) as std::string |
| 38 | */ |
| 39 | #if BOOST_VERSION >= 105600 |
| 40 | #include <boost/core/demangle.hpp> |
| 41 | #define NFD_TYPEID_NAME(x) (::boost::core::demangle(typeid(x).name())) |
| 42 | #else |
| 43 | #define NFD_TYPEID_NAME(x) (::std::string(typeid(x).name())) |
| 44 | #endif |
| 45 | |
| 46 | /** (implementation detail) |
| 47 | */ |
| 48 | #define NFD_TEST_TYPEID_REL(level, a, op, b) \ |
| 49 | BOOST_##level##_MESSAGE((typeid(a) op typeid(b)), \ |
| 50 | "expect typeid(" #a ") " #op " typeid(" #b ") [" << \ |
| 51 | NFD_TYPEID_NAME(a) << " " #op " " << NFD_TYPEID_NAME(b) << "]") |
| 52 | |
| 53 | /** (implementation detail) |
| 54 | */ |
| 55 | #define NFD_TEST_TYPEID_EQUAL(level, a, b) NFD_TEST_TYPEID_REL(level, a, ==, b) |
| 56 | |
| 57 | /** (implementation detail) |
| 58 | */ |
| 59 | #define NFD_TEST_TYPEID_NE(level, a, b) NFD_TEST_TYPEID_REL(level, a, !=, b) |
| 60 | |
| 61 | /** \brief equivalent to BOOST_REQUIRE(typeid(a) == typeid(b)) |
| 62 | */ |
| 63 | #define NFD_REQUIRE_TYPEID_EQUAL(a, b) NFD_TEST_TYPEID_EQUAL(REQUIRE, a, b) |
| 64 | |
| 65 | /** \brief equivalent to BOOST_REQUIRE(typeid(a) != typeid(b)) |
| 66 | */ |
| 67 | #define NFD_REQUIRE_TYPEID_NE(a, b) NFD_TEST_TYPEID_NE(REQUIRE, a, b) |
| 68 | |
| 69 | /** \brief equivalent to BOOST_CHECK(typeid(a) == typeid(b)) |
| 70 | */ |
| 71 | #define NFD_CHECK_TYPEID_EQUAL(a, b) NFD_TEST_TYPEID_EQUAL(CHECK, a, b) |
| 72 | |
| 73 | /** \brief equivalent to BOOST_CHECK(typeid(a) != typeid(b)) |
| 74 | */ |
| 75 | #define NFD_CHECK_TYPEID_NE(a, b) NFD_TEST_TYPEID_NE(CHECK, a, b) |
| 76 | |
| 77 | /** \brief equivalent to BOOST_WARN(typeid(a) == typeid(b)) |
| 78 | */ |
| 79 | #define NFD_WARN_TYPEID_EQUAL(a, b) NFD_TEST_TYPEID_EQUAL(WARN, a, b) |
| 80 | |
| 81 | /** \brief equivalent to BOOST_WARN(typeid(a) != typeid(b)) |
| 82 | */ |
| 83 | #define NFD_WARN_TYPEID_NE(a, b) NFD_TEST_TYPEID_NE(WARN, a, b) |
| 84 | |
| 85 | #endif // NFD_TESTS_CHECK_TYPEID_HPP |