blob: 3cccdb76371d92e33025ead39ddfd93e1880a018 [file] [log] [blame]
Teng Liange3ecad72018-08-28 21:12:53 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento14c56cd2020-05-21 01:44:03 -04003 * Copyright (c) 2013-2020 Regents of the University of California.
Teng Liange3ecad72018-08-28 21:12:53 -07004 *
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 Pesavento7e780642018-11-24 15:51:34 -050022#include "ndn-cxx/lp/prefix-announcement-header.hpp"
23#include "ndn-cxx/lp/tlv.hpp"
Teng Liange3ecad72018-08-28 21:12:53 -070024
Davide Pesavento7e780642018-11-24 15:51:34 -050025#include "tests/boost-test.hpp"
26#include "tests/identity-management-fixture.hpp"
Teng Liange3ecad72018-08-28 21:12:53 -070027
28namespace ndn {
29namespace lp {
30namespace tests {
31
32BOOST_AUTO_TEST_SUITE(Lp)
33BOOST_FIXTURE_TEST_SUITE(TestPrefixAnnouncementHeader, ndn::tests::IdentityManagementFixture)
34
35BOOST_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
64BOOST_AUTO_TEST_SUITE_END() // TestPrefixAnnouncementHeader
65BOOST_AUTO_TEST_SUITE_END() // Lp
66
67} // namespace tests
68} // namespace lp
69} // namespace ndn