blob: 59500633b8a5cc951a19b0d8489a2b3341e12adb [file] [log] [blame]
Shock Jiang895bc1b2014-10-01 20:00:58 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi767f35c2016-07-23 01:54:42 +00003 * Copyright (c) 2014-2016, Regents of the University of California.
Shock Jiang895bc1b2014-10-01 20:00:58 -07004 *
5 * This file is part of NDNS (Named Data Networking Domain Name Service).
6 * See AUTHORS.md for complete list of NDNS authors and contributors.
7 *
8 * NDNS is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "clients/response.hpp"
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080021
22#include "test-common.hpp"
Shock Jiang895bc1b2014-10-01 20:00:58 -070023
24namespace ndn {
25namespace ndns {
26namespace tests {
27
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080028BOOST_FIXTURE_TEST_SUITE(Response, IdentityManagementFixture)
Shock Jiang895bc1b2014-10-01 20:00:58 -070029
30BOOST_AUTO_TEST_CASE(Basic)
31{
Shock Jiang895bc1b2014-10-01 20:00:58 -070032 Name hint;
33 Name zone("/net");
34 name::Component qType = ndns::label::NDNS_ITERATIVE_QUERY;
35
36
37 ndns::Response r(zone, qType);
38 r.setRrLabel(Name("/ndnsim/www"));
39 r.setRrType(label::CERT_RR_TYPE);
40 r.setNdnsType(NDNS_RAW);
41 r.setFreshnessPeriod(time::seconds(4000));
42
43 BOOST_CHECK_EQUAL(r.getFreshnessPeriod(), time::seconds(4000));
44 BOOST_CHECK_EQUAL(r.getRrType(), label::CERT_RR_TYPE);
45 BOOST_CHECK_EQUAL(r.getNdnsType(), NDNS_RAW);
46 BOOST_CHECK_EQUAL(r.getZone(), zone);
47 BOOST_CHECK_EQUAL(r.getQueryType(), qType);
48
49 const std::string DATA1("some fake content");
Junxiao Shi767f35c2016-07-23 01:54:42 +000050 r.setAppContent(makeBinaryBlock(ndn::tlv::Content, DATA1.c_str(), DATA1.size()));
Shock Jiang895bc1b2014-10-01 20:00:58 -070051
52 //const Block& block = r.wireEncode();
53 shared_ptr<Data> data = r.toData();
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080054 // m_keyChain.sign(*data);
Shock Jiang895bc1b2014-10-01 20:00:58 -070055
56 ndns::Response r2;
57 BOOST_CHECK_EQUAL(r2.fromData(hint, zone, *data), true);
58 BOOST_CHECK_EQUAL(r, r2);
59
60 ndns::Response r4(zone, qType);
61 r4.setRrLabel(Name("/ndnsim/www"));
62 r4.setRrType(label::TXT_RR_TYPE);
63 r4.setNdnsType(NDNS_RESP);
64
65 std::string str = "Just try it";
Junxiao Shi767f35c2016-07-23 01:54:42 +000066 Block s = makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size());
Shock Jiang895bc1b2014-10-01 20:00:58 -070067 r4.addRr(s);
68 str = "Go to Hell";
Junxiao Shi767f35c2016-07-23 01:54:42 +000069 // Block s2 = makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size());
Shock Jiang895bc1b2014-10-01 20:00:58 -070070 r4.addRr(str);
71
72 BOOST_CHECK_NE(r2, r4);
73
74 data = r4.toData();
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080075 // m_keyChain.sign(*data);
Shock Jiang895bc1b2014-10-01 20:00:58 -070076
77 ndns::Response r5(zone, qType);
78
79 BOOST_CHECK_EQUAL(r5.fromData(hint, zone, *data), true);
80 BOOST_CHECK_EQUAL(r4, r5);
81 }
82
83BOOST_AUTO_TEST_SUITE_END()
84
85} // namespace tests
86} // namespace ndns
87} // namespace ndn