blob: 944bcb01d45665da2ba7773704eeaed53f65a590 [file] [log] [blame]
Shock Jiang01712f32014-10-01 14:34:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Yumin Xia2c509c22017-02-09 14:37:36 -08002/*
Junxiao Shi81e98762022-01-11 18:17:24 +00003 * Copyright (c) 2014-2022, Regents of the University of California.
Shock Jiang01712f32014-10-01 14:34:16 -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/query.hpp"
21
Davide Pesaventobdd88c12020-11-26 00:35:08 -050022#include "boost-test.hpp"
23#include "key-chain-fixture.hpp"
Shock Jiang01712f32014-10-01 14:34:16 -070024
Yumin Xia4e561892016-10-21 10:48:01 -070025#include <boost/lexical_cast.hpp>
Yumin Xia4e561892016-10-21 10:48:01 -070026
Shock Jiang01712f32014-10-01 14:34:16 -070027namespace ndn {
28namespace ndns {
29namespace tests {
30
31BOOST_AUTO_TEST_SUITE(Query)
32
Davide Pesaventobdd88c12020-11-26 00:35:08 -050033BOOST_FIXTURE_TEST_CASE(TestCase, KeyChainFixture)
Shock Jiang01712f32014-10-01 14:34:16 -070034{
Davide Pesaventobdd88c12020-11-26 00:35:08 -050035 auto certIdentity = m_keyChain.createIdentity("/cert/name");
Shock Jiang01712f32014-10-01 14:34:16 -070036 Name zone("/net");
37 name::Component qType = ndns::label::NDNS_ITERATIVE_QUERY;
Yumin Xia6343c5b2016-10-20 15:45:50 -070038 ndns::Query q(zone, qType);
Shock Jiang01712f32014-10-01 14:34:16 -070039
40 q.setRrLabel(Name("/ndnsim/www"));
41 BOOST_CHECK_EQUAL(q.getRrLabel(), Name("ndnsim/www"));
42 BOOST_CHECK_EQUAL(q.getRrLabel(), Name("/ndnsim/www"));
Shock Jiang01712f32014-10-01 14:34:16 -070043 BOOST_CHECK_EQUAL(q.getZone(), zone);
44 BOOST_CHECK_EQUAL(q.getQueryType(), qType);
45
46 q.setRrType(ndns::label::CERT_RR_TYPE);
47 BOOST_CHECK_EQUAL(q.getRrType(), label::CERT_RR_TYPE);
48
Yumin Xia4e561892016-10-21 10:48:01 -070049 auto link = make_shared<Link>("/ndn/link/NDNS/test/NS");
50 for (int i = 1; i <= 5; i++) {
Junxiao Shi81e98762022-01-11 18:17:24 +000051 link->addDelegation(std::string("/link/") + to_string(i));
Yumin Xia4e561892016-10-21 10:48:01 -070052 }
53 // link has to be signed first, then wireDecode
Yumin Xia2c509c22017-02-09 14:37:36 -080054 m_keyChain.sign(*link, security::signingByIdentity(certIdentity));
Yumin Xia4e561892016-10-21 10:48:01 -070055
Junxiao Shi81e98762022-01-11 18:17:24 +000056 q.setForwardingHintFromLink(*link);
57 BOOST_CHECK_EQUAL_COLLECTIONS(
58 q.getForwardingHint().begin(), q.getForwardingHint().end(),
59 link->getDelegationList().begin(), link->getDelegationList().end());
Yumin Xia4e561892016-10-21 10:48:01 -070060
Shock Jiang01712f32014-10-01 14:34:16 -070061 Interest interest = q.toInterest();
Junxiao Shi81e98762022-01-11 18:17:24 +000062 BOOST_CHECK_EQUAL_COLLECTIONS(
63 interest.getForwardingHint().begin(), interest.getForwardingHint().end(),
64 link->getDelegationList().begin(), link->getDelegationList().end());
Shock Jiang01712f32014-10-01 14:34:16 -070065
Yumin Xia6343c5b2016-10-20 15:45:50 -070066 ndns::Query q2(zone, qType);
67 BOOST_CHECK_EQUAL(q2.fromInterest(zone, interest), true);
Shock Jiang01712f32014-10-01 14:34:16 -070068
69 ndns::Query q3;
Yumin Xia6343c5b2016-10-20 15:45:50 -070070 BOOST_CHECK_EQUAL(q3.fromInterest(zone, interest), true);
Shock Jiang01712f32014-10-01 14:34:16 -070071
72 BOOST_CHECK_EQUAL(q, q3);
73 BOOST_CHECK_EQUAL(q, q2);
74
Yumin Xia6343c5b2016-10-20 15:45:50 -070075 ndns::Query q4(zone, qType);
Shock Jiang01712f32014-10-01 14:34:16 -070076 q4.setRrLabel("/ndnsim/www");
77 q4.setRrType(ndns::label::TXT_RR_TYPE);
78 interest = q4.toInterest();
79 ndns::Query q5;
80
Yumin Xia6343c5b2016-10-20 15:45:50 -070081 BOOST_CHECK_EQUAL(q5.fromInterest(zone, interest), true);
Shock Jiang01712f32014-10-01 14:34:16 -070082 BOOST_CHECK_EQUAL(q4, q5);
83 BOOST_CHECK_NE(q2, q4);
Davide Pesaventobdd88c12020-11-26 00:35:08 -050084}
Shock Jiang01712f32014-10-01 14:34:16 -070085
86BOOST_AUTO_TEST_SUITE_END()
87
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080088} // namespace tests
89} // namespace ndns
Shock Jiang01712f32014-10-01 14:34:16 -070090} // namespace ndn