blob: c5972030723ea1acc360c165ac133fb108fdfefa [file] [log] [blame]
Alexander Afanasyeva3887ae2014-12-29 16:11:57 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento3b101d02018-07-21 22:44:09 -04002/*
Davide Pesavento47ce2ee2023-05-09 01:33:33 -04003 * Copyright (c) 2013-2023 Regents of the University of California.
Alexander Afanasyeva3887ae2014-12-29 16:11:57 -08004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
Junxiao Shi1e36ceb2018-12-17 13:20:26 -070022#include "ndn-cxx/detail/tag-host.hpp"
Davide Pesavento7e780642018-11-24 15:51:34 -050023#include "ndn-cxx/data.hpp"
24#include "ndn-cxx/interest.hpp"
Alexander Afanasyeva3887ae2014-12-29 16:11:57 -080025
Davide Pesavento7e780642018-11-24 15:51:34 -050026#include "tests/boost-test.hpp"
Alexander Afanasyeva3887ae2014-12-29 16:11:57 -080027
28#include <boost/mpl/vector.hpp>
29
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040030namespace ndn::tests {
Alexander Afanasyeva3887ae2014-12-29 16:11:57 -080031
Junxiao Shi1e36ceb2018-12-17 13:20:26 -070032BOOST_AUTO_TEST_SUITE(Detail)
Alexander Afanasyeva3887ae2014-12-29 16:11:57 -080033BOOST_AUTO_TEST_SUITE(TestTagHost)
34
35class TestTag : public Tag
36{
37public:
Davide Pesavento3b101d02018-07-21 22:44:09 -040038 static constexpr int
39 getTypeId() noexcept
Alexander Afanasyeva3887ae2014-12-29 16:11:57 -080040 {
41 return 1;
42 }
43};
44
45class TestTag2 : public Tag
46{
47public:
Davide Pesavento3b101d02018-07-21 22:44:09 -040048 static constexpr int
49 getTypeId() noexcept
Alexander Afanasyeva3887ae2014-12-29 16:11:57 -080050 {
51 return 2;
52 }
53};
54
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040055using Fixtures = boost::mpl::vector<TagHost, Interest, Data>;
Alexander Afanasyeva3887ae2014-12-29 16:11:57 -080056
57BOOST_FIXTURE_TEST_CASE_TEMPLATE(Basic, T, Fixtures, T)
58{
59 BOOST_CHECK(this->template getTag<TestTag>() == nullptr);
60 BOOST_CHECK(this->template getTag<TestTag2>() == nullptr);
61
62 this->setTag(make_shared<TestTag>());
63
64 BOOST_CHECK(this->template getTag<TestTag>() != nullptr);
65 BOOST_CHECK(this->template getTag<TestTag2>() == nullptr);
66
67 this->setTag(make_shared<TestTag2>());
68
69 BOOST_CHECK(this->template getTag<TestTag>() != nullptr);
70 BOOST_CHECK(this->template getTag<TestTag2>() != nullptr);
71
72 this->template removeTag<TestTag2>();
73
74 BOOST_CHECK(this->template getTag<TestTag>() != nullptr);
75 BOOST_CHECK(this->template getTag<TestTag2>() == nullptr);
76
77 this->template removeTag<TestTag>();
78
79 BOOST_CHECK(this->template getTag<TestTag>() == nullptr);
80 BOOST_CHECK(this->template getTag<TestTag2>() == nullptr);
81}
82
Davide Pesaventoeee3e822016-11-26 19:19:34 +010083BOOST_AUTO_TEST_SUITE_END() // TestTagHost
Junxiao Shi1e36ceb2018-12-17 13:20:26 -070084BOOST_AUTO_TEST_SUITE_END() // Detail
Alexander Afanasyeva3887ae2014-12-29 16:11:57 -080085
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040086} // namespace ndn::tests