Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2017, Regents of the University of California. |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 4 | * |
| 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 | |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 22 | #include "test-common.hpp" |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 23 | |
Yumin Xia | 4e56189 | 2016-10-21 10:48:01 -0700 | [diff] [blame] | 24 | #include <boost/lexical_cast.hpp> |
| 25 | #include <string> |
Yumin Xia | 4e56189 | 2016-10-21 10:48:01 -0700 | [diff] [blame] | 26 | |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 27 | namespace ndn { |
| 28 | namespace ndns { |
| 29 | namespace tests { |
| 30 | |
| 31 | BOOST_AUTO_TEST_SUITE(Query) |
| 32 | |
Yumin Xia | 4e56189 | 2016-10-21 10:48:01 -0700 | [diff] [blame] | 33 | BOOST_FIXTURE_TEST_CASE(TestCase, IdentityManagementFixture) |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 34 | { |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 35 | security::Identity certIdentity = addIdentity("/cert/name"); |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 36 | Name zone("/net"); |
| 37 | name::Component qType = ndns::label::NDNS_ITERATIVE_QUERY; |
Yumin Xia | 6343c5b | 2016-10-20 15:45:50 -0700 | [diff] [blame] | 38 | ndns::Query q(zone, qType); |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 39 | |
| 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 Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 43 | 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 Xia | 4e56189 | 2016-10-21 10:48:01 -0700 | [diff] [blame] | 49 | auto link = make_shared<Link>("/ndn/link/NDNS/test/NS"); |
| 50 | for (int i = 1; i <= 5; i++) { |
| 51 | link->addDelegation(i, std::string("/link/") + to_string(i)); |
| 52 | } |
| 53 | // link has to be signed first, then wireDecode |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 54 | m_keyChain.sign(*link, security::signingByIdentity(certIdentity)); |
Yumin Xia | 4e56189 | 2016-10-21 10:48:01 -0700 | [diff] [blame] | 55 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 56 | q.setDelegationListFromLink(*link); |
| 57 | BOOST_CHECK_EQUAL(q.getDelegationList(), link->getDelegationList()); |
Yumin Xia | 4e56189 | 2016-10-21 10:48:01 -0700 | [diff] [blame] | 58 | |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 59 | Interest interest = q.toInterest(); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 60 | BOOST_CHECK_EQUAL(interest.getForwardingHint(), link->getDelegationList()); |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 61 | |
Yumin Xia | 6343c5b | 2016-10-20 15:45:50 -0700 | [diff] [blame] | 62 | ndns::Query q2(zone, qType); |
| 63 | BOOST_CHECK_EQUAL(q2.fromInterest(zone, interest), true); |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 64 | |
| 65 | ndns::Query q3; |
Yumin Xia | 6343c5b | 2016-10-20 15:45:50 -0700 | [diff] [blame] | 66 | BOOST_CHECK_EQUAL(q3.fromInterest(zone, interest), true); |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 67 | |
| 68 | BOOST_CHECK_EQUAL(q, q3); |
| 69 | BOOST_CHECK_EQUAL(q, q2); |
| 70 | |
Yumin Xia | 6343c5b | 2016-10-20 15:45:50 -0700 | [diff] [blame] | 71 | ndns::Query q4(zone, qType); |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 72 | q4.setRrLabel("/ndnsim/www"); |
| 73 | q4.setRrType(ndns::label::TXT_RR_TYPE); |
| 74 | interest = q4.toInterest(); |
| 75 | ndns::Query q5; |
| 76 | |
Yumin Xia | 6343c5b | 2016-10-20 15:45:50 -0700 | [diff] [blame] | 77 | BOOST_CHECK_EQUAL(q5.fromInterest(zone, interest), true); |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 78 | BOOST_CHECK_EQUAL(q4, q5); |
| 79 | BOOST_CHECK_NE(q2, q4); |
| 80 | } |
| 81 | |
| 82 | BOOST_AUTO_TEST_SUITE_END() |
| 83 | |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 84 | } // namespace tests |
| 85 | } // namespace ndns |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 86 | } // namespace ndn |