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