laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, The University of Memphis, |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
| 6 | * |
| 7 | * This file is part of NLSR (Named-data Link State Routing). |
| 8 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 9 | * |
| 10 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 11 | * of the GNU General Public License as published by the Free Software Foundation, |
| 12 | * either version 3 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE. See the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 20 | **/ |
| 21 | |
| 22 | #include "tlv/destination.hpp" |
| 23 | |
Davide Pesavento | cb065f1 | 2019-12-27 01:03:34 -0500 | [diff] [blame] | 24 | #include "tests/boost-test.hpp" |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 25 | |
| 26 | namespace nlsr { |
| 27 | namespace tlv { |
| 28 | namespace test { |
| 29 | |
| 30 | BOOST_AUTO_TEST_SUITE(TlvTestDes) |
| 31 | |
| 32 | const uint8_t DesData[] = |
| 33 | { |
| 34 | // Header |
| 35 | 0x8e, 0x13, |
| 36 | // Routername 746573742f646573742f746c76 |
| 37 | 0x07, 0x11, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x04, 0x64, 0x65, 0x73, 0x74, |
| 38 | 0x08, 0x03, 0x74, 0x6c, 0x76 |
| 39 | }; |
| 40 | |
| 41 | BOOST_AUTO_TEST_CASE(DesEncode) |
| 42 | { |
| 43 | Destination des1; |
| 44 | des1.setName("/test/dest/tlv"); |
| 45 | |
| 46 | const ndn::Block& wire = des1.wireEncode(); |
| 47 | |
| 48 | BOOST_REQUIRE_EQUAL_COLLECTIONS(DesData, |
| 49 | DesData + sizeof(DesData), |
| 50 | wire.begin(), wire.end()); |
| 51 | } |
| 52 | |
| 53 | BOOST_AUTO_TEST_CASE(DesDecode) |
| 54 | { |
| 55 | Destination des1; |
| 56 | |
| 57 | des1.wireDecode(ndn::Block(DesData, sizeof(DesData))); |
| 58 | |
| 59 | ndn::Name DEST_NAME = ndn::Name("/test/dest/tlv"); |
| 60 | BOOST_REQUIRE_EQUAL(des1.getName(), DEST_NAME); |
| 61 | } |
| 62 | |
| 63 | BOOST_AUTO_TEST_CASE(DesOutputStream) |
| 64 | { |
| 65 | Destination des1; |
| 66 | des1.setName("/test/dest/tlv"); |
| 67 | |
| 68 | std::ostringstream os; |
| 69 | os << des1; |
| 70 | |
| 71 | BOOST_CHECK_EQUAL(os.str(), "Destination: /test/dest/tlv"); |
| 72 | } |
| 73 | |
| 74 | BOOST_AUTO_TEST_CASE(DesMake) |
| 75 | { |
| 76 | RoutingTableEntry rte("/test/dest/tlv"); |
| 77 | |
| 78 | std::shared_ptr<Destination> des = makeDes(rte); |
| 79 | BOOST_CHECK_EQUAL(des->getName(), rte.getDestination()); |
| 80 | } |
| 81 | |
| 82 | BOOST_AUTO_TEST_SUITE_END() |
| 83 | |
| 84 | } // namespace test |
| 85 | } // namespace tlv |
| 86 | } // namespace nlsr |