Shock Jiang | 895bc1b | 2014-10-01 20:00:58 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 767f35c | 2016-07-23 01:54:42 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California. |
Shock Jiang | 895bc1b | 2014-10-01 20:00:58 -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/response.hpp" |
| 21 | #include <ndn-cxx/security/key-chain.hpp> |
| 22 | #include "../../boost-test.hpp" |
| 23 | |
| 24 | namespace ndn { |
| 25 | namespace ndns { |
| 26 | namespace tests { |
| 27 | |
| 28 | |
| 29 | |
| 30 | BOOST_AUTO_TEST_SUITE(Response) |
| 31 | |
| 32 | BOOST_AUTO_TEST_CASE(Basic) |
| 33 | { |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 34 | KeyChain keyChain("sqlite3", "file"); |
Shock Jiang | 895bc1b | 2014-10-01 20:00:58 -0700 | [diff] [blame] | 35 | Name hint; |
| 36 | Name zone("/net"); |
| 37 | name::Component qType = ndns::label::NDNS_ITERATIVE_QUERY; |
| 38 | |
| 39 | |
| 40 | ndns::Response r(zone, qType); |
| 41 | r.setRrLabel(Name("/ndnsim/www")); |
| 42 | r.setRrType(label::CERT_RR_TYPE); |
| 43 | r.setNdnsType(NDNS_RAW); |
| 44 | r.setFreshnessPeriod(time::seconds(4000)); |
| 45 | |
| 46 | BOOST_CHECK_EQUAL(r.getFreshnessPeriod(), time::seconds(4000)); |
| 47 | BOOST_CHECK_EQUAL(r.getRrType(), label::CERT_RR_TYPE); |
| 48 | BOOST_CHECK_EQUAL(r.getNdnsType(), NDNS_RAW); |
| 49 | BOOST_CHECK_EQUAL(r.getZone(), zone); |
| 50 | BOOST_CHECK_EQUAL(r.getQueryType(), qType); |
| 51 | |
| 52 | const std::string DATA1("some fake content"); |
Junxiao Shi | 767f35c | 2016-07-23 01:54:42 +0000 | [diff] [blame] | 53 | r.setAppContent(makeBinaryBlock(ndn::tlv::Content, DATA1.c_str(), DATA1.size())); |
Shock Jiang | 895bc1b | 2014-10-01 20:00:58 -0700 | [diff] [blame] | 54 | |
| 55 | //const Block& block = r.wireEncode(); |
| 56 | shared_ptr<Data> data = r.toData(); |
| 57 | // keyChain.sign(*data); |
| 58 | |
| 59 | ndns::Response r2; |
| 60 | BOOST_CHECK_EQUAL(r2.fromData(hint, zone, *data), true); |
| 61 | BOOST_CHECK_EQUAL(r, r2); |
| 62 | |
| 63 | ndns::Response r4(zone, qType); |
| 64 | r4.setRrLabel(Name("/ndnsim/www")); |
| 65 | r4.setRrType(label::TXT_RR_TYPE); |
| 66 | r4.setNdnsType(NDNS_RESP); |
| 67 | |
| 68 | std::string str = "Just try it"; |
Junxiao Shi | 767f35c | 2016-07-23 01:54:42 +0000 | [diff] [blame] | 69 | Block s = makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()); |
Shock Jiang | 895bc1b | 2014-10-01 20:00:58 -0700 | [diff] [blame] | 70 | r4.addRr(s); |
| 71 | str = "Go to Hell"; |
Junxiao Shi | 767f35c | 2016-07-23 01:54:42 +0000 | [diff] [blame] | 72 | // Block s2 = makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()); |
Shock Jiang | 895bc1b | 2014-10-01 20:00:58 -0700 | [diff] [blame] | 73 | r4.addRr(str); |
| 74 | |
| 75 | BOOST_CHECK_NE(r2, r4); |
| 76 | |
| 77 | data = r4.toData(); |
| 78 | // keyChain.sign(*data); |
| 79 | |
| 80 | ndns::Response r5(zone, qType); |
| 81 | |
| 82 | BOOST_CHECK_EQUAL(r5.fromData(hint, zone, *data), true); |
| 83 | BOOST_CHECK_EQUAL(r4, r5); |
| 84 | } |
| 85 | |
| 86 | BOOST_AUTO_TEST_SUITE_END() |
| 87 | |
| 88 | } // namespace tests |
| 89 | } // namespace ndns |
| 90 | } // namespace ndn |