blob: 5fdde2c6b8d7906a13b9198df88843f608a6866f [file] [log] [blame]
Teng Liang5b323d12018-01-31 18:50:45 -07001/* -*- 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 * @author Teng Liang <philoliang@email.arizona.edu>
22 */
23
24#include "lp/prefix-announcement.hpp"
25#include "security/signature-sha256-with-rsa.hpp"
26
27#include "boost-test.hpp"
28#include "make-interest-data.hpp"
29
30namespace ndn {
31namespace lp {
32namespace tests {
33
34using namespace ndn::tests;
35
36BOOST_AUTO_TEST_SUITE(Lp)
37BOOST_AUTO_TEST_SUITE(TestPrefixAnnouncement)
38
39BOOST_AUTO_TEST_CASE(SetData)
40{
41 Name name1("/ndn/pa");
42 Name name2("/self-learning/ndn/pa");
43 Name name3("/self-learning/ndn/pa");
44 name3.appendVersion();
45
46 PrefixAnnouncement pa;
47 BOOST_CHECK_THROW(pa.setData(nullptr), PrefixAnnouncement::Error);
48 BOOST_CHECK_THROW(pa.setData(makeData(name1)), PrefixAnnouncement::Error);
49 BOOST_CHECK_THROW(pa.setData(makeData(name2)), PrefixAnnouncement::Error);
50 BOOST_CHECK_NO_THROW(pa.setData(makeData(name3)));
51 BOOST_CHECK_EQUAL(pa.getAnnouncedName(), "/ndn/pa");
52
53 shared_ptr<Data> data1 = makeData(name3);
54 shared_ptr<Data> data2 = makeData(name3);
55 static const uint8_t someData[] = "someData";
56 data1->setContent(someData, sizeof(someData));
57 data2->setFreshnessPeriod(10_s);
58 BOOST_CHECK_THROW(pa.setData(data1), PrefixAnnouncement::Error);
59 BOOST_CHECK_THROW(pa.setData(data2), PrefixAnnouncement::Error);
60}
61
62BOOST_AUTO_TEST_CASE(GetAnnouncedName)
63{
64 PrefixAnnouncement pa1;
65 BOOST_CHECK_THROW(pa1.getAnnouncedName(), PrefixAnnouncement::Error);
66
67 Name name("/self-learning/edu/ua/news");
68 name.appendVersion();
69
70 PrefixAnnouncement pa2(makeData(name));
71
72 BOOST_CHECK_EQUAL(pa2.getAnnouncedName(), "/edu/ua/news");
73}
74
75BOOST_AUTO_TEST_SUITE_END() // TestPrefixAnnouncement
76BOOST_AUTO_TEST_SUITE_END() // Lp
77
78} // namespace tests
79} // namespace lp
80} // namespace ndn