blob: 5e792893a5b53c847a2e80226d885e04bcf94a30 [file] [log] [blame]
Junxiao Shi9685cc52016-08-29 12:47:05 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento5f35f642018-05-10 19:36:03 -04002/*
3 * Copyright (c) 2014-2018, Regents of the University of California,
Junxiao Shi9685cc52016-08-29 12:47:05 +00004 * 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 Pesavento5f35f642018-05-10 19:36:03 -040034
35#include <boost/core/demangle.hpp>
Junxiao Shi9685cc52016-08-29 12:47:05 +000036#include <typeinfo>
37
38/** \def NFD_TYPEID_NAME(x)
39 * \return type name of typeid(x) as std::string
40 */
Junxiao Shi9685cc52016-08-29 12:47:05 +000041#define NFD_TYPEID_NAME(x) (::boost::core::demangle(typeid(x).name()))
Junxiao Shi9685cc52016-08-29 12:47:05 +000042
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