blob: a24505e8cb6bf22817ce36d02d6cc2bcca0b93a1 [file] [log] [blame]
Shock Jiang895bc1b2014-10-01 20:00:58 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventobdd88c12020-11-26 00:35:08 -05002/*
Davide Pesavento38fd3982022-04-18 22:22:02 -04003 * Copyright (c) 2014-2022, 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
Davide Pesaventobdd88c12020-11-26 00:35:08 -050022#include "boost-test.hpp"
23#include "key-chain-fixture.hpp"
Shock Jiang895bc1b2014-10-01 20:00:58 -070024
25namespace ndn {
26namespace ndns {
27namespace tests {
28
Davide Pesaventobdd88c12020-11-26 00:35:08 -050029BOOST_FIXTURE_TEST_SUITE(Response, KeyChainFixture)
Shock Jiang895bc1b2014-10-01 20:00:58 -070030
31BOOST_AUTO_TEST_CASE(Basic)
32{
Shock Jiang895bc1b2014-10-01 20:00:58 -070033 Name zone("/net");
34 name::Component qType = ndns::label::NDNS_ITERATIVE_QUERY;
35
Shock Jiang895bc1b2014-10-01 20:00:58 -070036 ndns::Response r(zone, qType);
37 r.setRrLabel(Name("/ndnsim/www"));
38 r.setRrType(label::CERT_RR_TYPE);
Yumin Xia3c6b1fd2016-12-11 19:08:47 -080039 r.setContentType(NDNS_KEY);
Shock Jiang895bc1b2014-10-01 20:00:58 -070040 r.setFreshnessPeriod(time::seconds(4000));
41
42 BOOST_CHECK_EQUAL(r.getFreshnessPeriod(), time::seconds(4000));
43 BOOST_CHECK_EQUAL(r.getRrType(), label::CERT_RR_TYPE);
Yumin Xia3c6b1fd2016-12-11 19:08:47 -080044 BOOST_CHECK_EQUAL(r.getContentType(), NDNS_KEY);
Shock Jiang895bc1b2014-10-01 20:00:58 -070045 BOOST_CHECK_EQUAL(r.getZone(), zone);
46 BOOST_CHECK_EQUAL(r.getQueryType(), qType);
47
48 const std::string DATA1("some fake content");
Davide Pesavento38fd3982022-04-18 22:22:02 -040049 r.setAppContent(makeStringBlock(ndn::tlv::Content, DATA1));
Shock Jiang895bc1b2014-10-01 20:00:58 -070050
51 //const Block& block = r.wireEncode();
52 shared_ptr<Data> data = r.toData();
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080053 // m_keyChain.sign(*data);
Shock Jiang895bc1b2014-10-01 20:00:58 -070054
55 ndns::Response r2;
Yumin Xia6343c5b2016-10-20 15:45:50 -070056 BOOST_CHECK_EQUAL(r2.fromData(zone, *data), true);
Shock Jiang895bc1b2014-10-01 20:00:58 -070057 BOOST_CHECK_EQUAL(r, r2);
58
59 ndns::Response r4(zone, qType);
60 r4.setRrLabel(Name("/ndnsim/www"));
61 r4.setRrType(label::TXT_RR_TYPE);
Yumin Xiaa484ba72016-11-10 20:40:12 -080062 r4.setContentType(NDNS_RESP);
Shock Jiang895bc1b2014-10-01 20:00:58 -070063
64 std::string str = "Just try it";
Davide Pesavento38fd3982022-04-18 22:22:02 -040065 Block s = makeStringBlock(ndns::tlv::RrData, str);
Shock Jiang895bc1b2014-10-01 20:00:58 -070066 r4.addRr(s);
67 str = "Go to Hell";
Shock Jiang895bc1b2014-10-01 20:00:58 -070068 r4.addRr(str);
69
70 BOOST_CHECK_NE(r2, r4);
71
72 data = r4.toData();
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080073 // m_keyChain.sign(*data);
Shock Jiang895bc1b2014-10-01 20:00:58 -070074
75 ndns::Response r5(zone, qType);
76
Yumin Xia6343c5b2016-10-20 15:45:50 -070077 BOOST_CHECK_EQUAL(r5.fromData(zone, *data), true);
Shock Jiang895bc1b2014-10-01 20:00:58 -070078 BOOST_CHECK_EQUAL(r4, r5);
Davide Pesavento38fd3982022-04-18 22:22:02 -040079}
Shock Jiang895bc1b2014-10-01 20:00:58 -070080
81BOOST_AUTO_TEST_SUITE_END()
82
83} // namespace tests
84} // namespace ndns
85} // namespace ndn