Teng Liang | e3ecad7 | 2018-08-28 21:12:53 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2020 Regents of the University of California. |
Teng Liang | e3ecad7 | 2018-08-28 21:12:53 -0700 | [diff] [blame] | 4 | * |
| 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 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 22 | #include "ndn-cxx/lp/prefix-announcement-header.hpp" |
| 23 | #include "ndn-cxx/lp/tlv.hpp" |
Teng Liang | e3ecad7 | 2018-08-28 21:12:53 -0700 | [diff] [blame] | 24 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 25 | #include "tests/boost-test.hpp" |
| 26 | #include "tests/identity-management-fixture.hpp" |
Teng Liang | e3ecad7 | 2018-08-28 21:12:53 -0700 | [diff] [blame] | 27 | |
| 28 | namespace ndn { |
| 29 | namespace lp { |
| 30 | namespace tests { |
| 31 | |
| 32 | BOOST_AUTO_TEST_SUITE(Lp) |
| 33 | BOOST_FIXTURE_TEST_SUITE(TestPrefixAnnouncementHeader, ndn::tests::IdentityManagementFixture) |
| 34 | |
| 35 | BOOST_AUTO_TEST_CASE(EncodeDecode) |
| 36 | { |
| 37 | EncodingEstimator estimator; |
| 38 | PrefixAnnouncementHeader header; |
| 39 | BOOST_CHECK_THROW(header.wireEncode(estimator), PrefixAnnouncementHeader::Error); |
| 40 | BOOST_CHECK_THROW(PrefixAnnouncementHeader{PrefixAnnouncement()}, PrefixAnnouncementHeader::Error); |
| 41 | |
| 42 | PrefixAnnouncement pa; |
| 43 | pa.setAnnouncedName("/net/example"); |
| 44 | pa.setExpiration(1_h); |
| 45 | const Data& data = pa.toData(m_keyChain, signingWithSha256(), 1); |
| 46 | Block encodedData = data.wireEncode(); |
| 47 | |
| 48 | Block expectedBlock(tlv::PrefixAnnouncement); |
| 49 | expectedBlock.push_back(encodedData); |
| 50 | expectedBlock.encode(); |
| 51 | |
| 52 | PrefixAnnouncementHeader pah0(pa); |
| 53 | size_t estimatedSize = pah0.wireEncode(estimator); |
| 54 | EncodingBuffer buffer(estimatedSize, 0); |
| 55 | pah0.wireEncode(buffer); |
| 56 | Block wire = buffer.block(); |
| 57 | BOOST_CHECK_EQUAL(expectedBlock, wire); |
| 58 | |
| 59 | PrefixAnnouncementHeader pah1; |
| 60 | pah1.wireDecode(wire); |
| 61 | BOOST_CHECK_EQUAL(*pah0.getPrefixAnn(), *pah1.getPrefixAnn()); |
| 62 | } |
| 63 | |
| 64 | BOOST_AUTO_TEST_SUITE_END() // TestPrefixAnnouncementHeader |
| 65 | BOOST_AUTO_TEST_SUITE_END() // Lp |
| 66 | |
| 67 | } // namespace tests |
| 68 | } // namespace lp |
| 69 | } // namespace ndn |