Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 3 | * Copyright (c) 2013-2018 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
Alexander Afanasyev | 09c613f | 2014-01-29 00:23:58 -0800 | [diff] [blame] | 22 | #include "interest.hpp" |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 23 | #include "data.hpp" |
Yingdi Yu | bf6a281 | 2014-06-17 15:32:11 -0700 | [diff] [blame] | 24 | #include "security/digest-sha256.hpp" |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 25 | #include "security/signature-sha256-with-rsa.hpp" |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 26 | |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 27 | #include "block-literal.hpp" |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 28 | #include "boost-test.hpp" |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 29 | #include "identity-management-fixture.hpp" |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 30 | |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 31 | namespace ndn { |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 32 | namespace tests { |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 33 | |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 34 | BOOST_AUTO_TEST_SUITE(TestInterest) |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 35 | |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 36 | // ---- constructor, encode, decode ---- |
| 37 | |
| 38 | BOOST_AUTO_TEST_CASE(DefaultConstructor) |
| 39 | { |
| 40 | Interest i; |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 41 | BOOST_CHECK(!i.hasWire()); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 42 | BOOST_CHECK_EQUAL(i.getName(), "/"); |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 43 | BOOST_CHECK_EQUAL(i.getCanBePrefix(), true); |
| 44 | BOOST_CHECK_EQUAL(i.getMustBeFresh(), false); |
| 45 | BOOST_CHECK(i.getForwardingHint().empty()); |
| 46 | BOOST_CHECK(!i.hasNonce()); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 47 | BOOST_CHECK_EQUAL(i.getInterestLifetime(), DEFAULT_INTEREST_LIFETIME); |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 48 | BOOST_CHECK(!i.hasSelectors()); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 51 | BOOST_AUTO_TEST_CASE(EncodeDecode02Basic) |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 52 | { |
| 53 | const uint8_t WIRE[] = { |
| 54 | 0x05, 0x1c, // Interest |
| 55 | 0x07, 0x14, // Name |
Junxiao Shi | 4ffbb9d | 2018-03-31 17:16:35 +0000 | [diff] [blame] | 56 | 0x08, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, // GenericNameComponent |
| 57 | 0x08, 0x03, 0x6e, 0x64, 0x6e, // GenericNameComponent |
| 58 | 0x08, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, // GenericNameComponent |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 59 | 0x0a, 0x04, // Nonce |
| 60 | 0x01, 0x00, 0x00, 0x00 |
| 61 | }; |
| 62 | |
| 63 | Interest i1("/local/ndn/prefix"); |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 64 | i1.setCanBePrefix(true); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 65 | i1.setNonce(1); |
| 66 | Block wire1 = i1.wireEncode(); |
| 67 | BOOST_CHECK_EQUAL_COLLECTIONS(wire1.begin(), wire1.end(), WIRE, WIRE + sizeof(WIRE)); |
| 68 | |
| 69 | Interest i2(wire1); |
| 70 | BOOST_CHECK_EQUAL(i2.getName(), "/local/ndn/prefix"); |
| 71 | BOOST_CHECK(i2.getSelectors().empty()); |
| 72 | BOOST_CHECK_EQUAL(i2.getNonce(), 1); |
| 73 | BOOST_CHECK_EQUAL(i2.getInterestLifetime(), DEFAULT_INTEREST_LIFETIME); |
| 74 | |
| 75 | BOOST_CHECK_EQUAL(i1, i2); |
| 76 | } |
| 77 | |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 78 | BOOST_AUTO_TEST_CASE(EncodeDecode02Full) |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 79 | { |
| 80 | const uint8_t WIRE[] = { |
Junxiao Shi | 9c154cb | 2017-07-07 22:14:54 +0000 | [diff] [blame] | 81 | 0x05, 0x31, // Interest |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 82 | 0x07, 0x14, // Name |
Junxiao Shi | 4ffbb9d | 2018-03-31 17:16:35 +0000 | [diff] [blame] | 83 | 0x08, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, // GenericNameComponent |
| 84 | 0x08, 0x03, 0x6e, 0x64, 0x6e, // GenericNameComponent |
| 85 | 0x08, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, // GenericNameComponent |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 86 | 0x09, 0x03, // Selectors |
| 87 | 0x0d, 0x01, 0x01, // MinSuffixComponents |
| 88 | 0x0a, 0x04, // Nonce |
| 89 | 0x01, 0x00, 0x00, 0x00, |
| 90 | 0x0c, 0x02, // InterestLifetime |
Junxiao Shi | 9c154cb | 2017-07-07 22:14:54 +0000 | [diff] [blame] | 91 | 0x03, 0xe8, |
| 92 | 0x1e, 0x0a, // ForwardingHint |
| 93 | 0x1f, 0x08, // Delegation |
| 94 | 0x1e, 0x01, 0x01, // Preference=1 |
| 95 | 0x07, 0x03, 0x08, 0x01, 0x41 // Name=/A |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 96 | }; |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 97 | |
| 98 | Interest i1; |
| 99 | i1.setName("/local/ndn/prefix"); |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 100 | i1.setCanBePrefix(true); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 101 | i1.setMinSuffixComponents(1); |
| 102 | i1.setNonce(1); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 103 | i1.setInterestLifetime(1000_ms); |
Junxiao Shi | 9c154cb | 2017-07-07 22:14:54 +0000 | [diff] [blame] | 104 | i1.setForwardingHint({{1, "/A"}}); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 105 | Block wire1 = i1.wireEncode(); |
| 106 | BOOST_CHECK_EQUAL_COLLECTIONS(wire1.begin(), wire1.end(), WIRE, WIRE + sizeof(WIRE)); |
| 107 | |
| 108 | Interest i2(wire1); |
| 109 | BOOST_CHECK_EQUAL(i2.getName(), "/local/ndn/prefix"); |
| 110 | BOOST_CHECK_EQUAL(i2.getMinSuffixComponents(), 1); |
| 111 | BOOST_CHECK_EQUAL(i2.getNonce(), 1); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 112 | BOOST_CHECK_EQUAL(i2.getInterestLifetime(), 1000_ms); |
Junxiao Shi | 9c154cb | 2017-07-07 22:14:54 +0000 | [diff] [blame] | 113 | BOOST_CHECK_EQUAL(i2.getForwardingHint(), DelegationList({{1, "/A"}})); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 114 | |
| 115 | BOOST_CHECK_EQUAL(i1, i2); |
| 116 | } |
| 117 | |
Arthi Padmanabhan | b38664e | 2018-07-18 11:13:12 -0700 | [diff] [blame^] | 118 | BOOST_AUTO_TEST_CASE(EncodeDecode03Basic) |
| 119 | { |
| 120 | const uint8_t WIRE[] = { |
| 121 | 0x05, 0x22, // Interest |
| 122 | 0x07, 0x14, // Name |
| 123 | 0x08, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, // GenericNameComponent |
| 124 | 0x08, 0x03, 0x6e, 0x64, 0x6e, // GenericNameComponent |
| 125 | 0x08, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, // GenericNameComponent |
| 126 | 0x0a, 0x04, // Nonce |
| 127 | 0x01, 0x00, 0x00, 0x00, |
| 128 | 0x23, 0x04, // Parameters |
| 129 | 0xc0, 0xc1, 0xc2, 0xc3}; |
| 130 | |
| 131 | Interest i1; |
| 132 | i1.setName("/local/ndn/prefix"); |
| 133 | i1.setCanBePrefix(false); |
| 134 | i1.setNonce(1); |
| 135 | i1.setParameters("2304C0C1C2C3"_block); |
| 136 | Block wire1 = i1.wireEncode(); |
| 137 | BOOST_CHECK_EQUAL_COLLECTIONS(wire1.begin(), wire1.end(), WIRE, WIRE + sizeof(WIRE)); |
| 138 | |
| 139 | Interest i2(wire1); |
| 140 | BOOST_CHECK_EQUAL(i2.getName(), "/local/ndn/prefix"); |
| 141 | BOOST_CHECK_EQUAL(i2.getCanBePrefix(), false); |
| 142 | BOOST_CHECK_EQUAL(i2.getMustBeFresh(), false); |
| 143 | BOOST_CHECK(i2.getForwardingHint().empty()); |
| 144 | BOOST_CHECK_EQUAL(i2.getNonce(), 1); |
| 145 | BOOST_CHECK_EQUAL(i2.getInterestLifetime(), DEFAULT_INTEREST_LIFETIME); |
| 146 | BOOST_CHECK(i2.hasParameters()); |
| 147 | BOOST_CHECK_EQUAL(i2.getParameters(), "2304C0C1C2C3"_block); |
| 148 | BOOST_CHECK(i2.getPublisherPublicKeyLocator().empty()); |
| 149 | } |
| 150 | |
| 151 | BOOST_AUTO_TEST_CASE(EncodeDecode03Full) |
| 152 | { |
| 153 | const uint8_t WIRE[] = { |
| 154 | 0x05, 0x37, // Interest |
| 155 | 0x07, 0x14, // Name |
| 156 | 0x08, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, // GenericNameComponent |
| 157 | 0x08, 0x03, 0x6e, 0x64, 0x6e, // GenericNameComponent |
| 158 | 0x08, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, // GenericNameComponent |
| 159 | 0x21, 0x00, // CanBePrefix |
| 160 | 0x12, 0x00, // MustBeFresh |
| 161 | 0x1e, 0x0b, // ForwardingHint |
| 162 | 0x1f, 0x09, // Delegation List |
| 163 | 0x1e, 0x02, |
| 164 | 0x3e, 0x15, |
| 165 | 0x07, 0x03, |
| 166 | 0x08, 0x01, 0x48, |
| 167 | 0x0a, 0x04, // Nonce |
| 168 | 0x4a, 0xcb, 0x1e, 0x4c, |
| 169 | 0x0c, 0x02, // Interest Lifetime |
| 170 | 0x76, 0xa1, |
| 171 | 0x23, 0x04, // Parameters |
| 172 | 0xc0, 0xc1, 0xc2, 0xc3}; |
| 173 | Interest i1; |
| 174 | i1.setName("/local/ndn/prefix"); |
| 175 | i1.setMustBeFresh(true); |
| 176 | i1.setCanBePrefix(true); |
| 177 | i1.setForwardingHint(DelegationList({{15893, "/H"}})); |
| 178 | i1.setNonce(0x4c1ecb4a); |
| 179 | i1.setInterestLifetime(30369_ms); |
| 180 | i1.setParameters("2304C0C1C2C3"_block); |
| 181 | i1.setMinSuffixComponents(1); // v0.2-only elements will not be encoded |
| 182 | i1.setExclude(Exclude().excludeAfter(name::Component("J"))); // v0.2-only elements will not be encoded |
| 183 | Block wire1 = i1.wireEncode(); |
| 184 | BOOST_CHECK_EQUAL_COLLECTIONS(wire1.begin(), wire1.end(), WIRE, WIRE + sizeof(WIRE)); |
| 185 | |
| 186 | Interest i2(wire1); |
| 187 | BOOST_CHECK_EQUAL(i2.getName(), "/local/ndn/prefix"); |
| 188 | BOOST_CHECK_EQUAL(i2.getCanBePrefix(), true); |
| 189 | BOOST_CHECK_EQUAL(i2.getMustBeFresh(), true); |
| 190 | BOOST_CHECK_EQUAL(i2.getForwardingHint(), DelegationList({{15893, "/H"}})); |
| 191 | BOOST_CHECK(i2.hasNonce()); |
| 192 | BOOST_CHECK_EQUAL(i2.getNonce(), 0x4c1ecb4a); |
| 193 | BOOST_CHECK_EQUAL(i2.getInterestLifetime(), 30369_ms); |
| 194 | BOOST_CHECK_EQUAL(i2.getParameters(), "2304C0C1C2C3"_block); |
| 195 | BOOST_CHECK_EQUAL(i2.getMinSuffixComponents(), -1); // Default because minSuffixComponents was not encoded |
| 196 | BOOST_CHECK(i2.getExclude().empty()); // Exclude was not encoded |
| 197 | } |
| 198 | |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 199 | class Decode03Fixture |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 200 | { |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 201 | protected: |
| 202 | Decode03Fixture() |
| 203 | { |
| 204 | // initialize all elements to non-empty, to verify wireDecode clears them |
| 205 | i.setName("/A"); |
| 206 | i.setForwardingHint({{10309, "/F"}}); |
| 207 | i.setNonce(0x03d645a8); |
| 208 | i.setInterestLifetime(18554_ms); |
| 209 | i.setPublisherPublicKeyLocator(Name("/K")); |
Arthi Padmanabhan | b38664e | 2018-07-18 11:13:12 -0700 | [diff] [blame^] | 210 | i.setParameters("2304A0A1A2A3"_block); |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 211 | } |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 212 | |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 213 | protected: |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 214 | Interest i; |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 215 | }; |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 216 | |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 217 | BOOST_FIXTURE_TEST_SUITE(Decode03, Decode03Fixture) |
| 218 | |
| 219 | BOOST_AUTO_TEST_CASE(Minimal) |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 220 | { |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 221 | i.wireDecode("0505 0703080149"_block); |
| 222 | BOOST_CHECK_EQUAL(i.getName(), "/I"); |
| 223 | BOOST_CHECK_EQUAL(i.getCanBePrefix(), false); |
| 224 | BOOST_CHECK_EQUAL(i.getMustBeFresh(), false); |
| 225 | BOOST_CHECK(i.getForwardingHint().empty()); |
| 226 | BOOST_CHECK(i.hasNonce()); // a random nonce is generated |
| 227 | BOOST_CHECK_EQUAL(i.getInterestLifetime(), DEFAULT_INTEREST_LIFETIME); |
| 228 | BOOST_CHECK(i.getPublisherPublicKeyLocator().empty()); |
Arthi Padmanabhan | b38664e | 2018-07-18 11:13:12 -0700 | [diff] [blame^] | 229 | BOOST_CHECK(!i.hasParameters()); |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 230 | |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 231 | BOOST_CHECK(!i.hasWire()); // nonce generation resets wire encoding |
| 232 | |
| 233 | // modify then re-encode as v0.2 format |
| 234 | i.setNonce(0x54657c95); |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 235 | BOOST_CHECK_EQUAL(i.wireEncode(), "0510 0703080149 09030E0101 0A04957C6554"_block); |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 238 | BOOST_AUTO_TEST_CASE(Full) |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 239 | { |
Arthi Padmanabhan | b38664e | 2018-07-18 11:13:12 -0700 | [diff] [blame^] | 240 | i.wireDecode("0533 FC00 0703080149 FC00 2100 FC00 1200 " |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 241 | "FC00 1E0B(1F09 1E023E15 0703080148) FC00 0A044ACB1E4C " |
Arthi Padmanabhan | b38664e | 2018-07-18 11:13:12 -0700 | [diff] [blame^] | 242 | "FC00 0C0276A1 FC00 2201D6 FC00"_block); |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 243 | BOOST_CHECK_EQUAL(i.getName(), "/I"); |
| 244 | BOOST_CHECK_EQUAL(i.getCanBePrefix(), true); |
| 245 | BOOST_CHECK_EQUAL(i.getMustBeFresh(), true); |
| 246 | BOOST_CHECK_EQUAL(i.getForwardingHint(), DelegationList({{15893, "/H"}})); |
| 247 | BOOST_CHECK(i.hasNonce()); |
| 248 | BOOST_CHECK_EQUAL(i.getNonce(), 0x4c1ecb4a); |
| 249 | BOOST_CHECK_EQUAL(i.getInterestLifetime(), 30369_ms); |
| 250 | // HopLimit=214 is not stored |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 251 | |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 252 | // encode without modification: retain original wire encoding |
Arthi Padmanabhan | b38664e | 2018-07-18 11:13:12 -0700 | [diff] [blame^] | 253 | BOOST_CHECK_EQUAL(i.wireEncode().value_size(), 51); |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 254 | |
| 255 | // modify then re-encode as v0.2 format |
| 256 | i.setName("/J"); |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 257 | BOOST_CHECK_EQUAL(i.wireEncode(), |
| 258 | "0520 070308014A 09021200 0A044ACB1E4C 0C0276A1 1E0B(1F09 1E023E15 0703080148)"_block); |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 261 | BOOST_AUTO_TEST_CASE(CriticalElementOutOfOrder) |
| 262 | { |
| 263 | BOOST_CHECK_THROW(i.wireDecode( |
| 264 | "0529 2100 0703080149 1200 1E0B(1F09 1E023E15 0703080148) " |
| 265 | "0A044ACB1E4C 0C0276A1 2201D6 2304C0C1C2C3"_block), |
| 266 | tlv::Error); |
| 267 | BOOST_CHECK_THROW(i.wireDecode( |
| 268 | "0529 0703080149 1200 2100 1E0B(1F09 1E023E15 0703080148) " |
| 269 | "0A044ACB1E4C 0C0276A1 2201D6 2304C0C1C2C3"_block), |
| 270 | tlv::Error); |
| 271 | BOOST_CHECK_THROW(i.wireDecode( |
| 272 | "0529 0703080149 2100 1E0B(1F09 1E023E15 0703080148) 1200 " |
| 273 | "0A044ACB1E4C 0C0276A1 2201D6 2304C0C1C2C3"_block), |
| 274 | tlv::Error); |
| 275 | BOOST_CHECK_THROW(i.wireDecode( |
| 276 | "0529 0703080149 2100 1200 0A044ACB1E4C " |
| 277 | "1E0B(1F09 1E023E15 0703080148) 0C0276A1 2201D6 2304C0C1C2C3"_block), |
| 278 | tlv::Error); |
| 279 | BOOST_CHECK_THROW(i.wireDecode( |
| 280 | "0529 0703080149 2100 1200 1E0B(1F09 1E023E15 0703080148) " |
| 281 | "0C0276A1 0A044ACB1E4C 2201D6 2304C0C1C2C3"_block), |
| 282 | tlv::Error); |
| 283 | BOOST_CHECK_THROW(i.wireDecode( |
| 284 | "0529 0703080149 2100 1200 1E0B(1F09 1E023E15 0703080148) " |
| 285 | "0A044ACB1E4C 2201D6 0C0276A1 2304C0C1C2C3"_block), |
| 286 | tlv::Error); |
| 287 | BOOST_CHECK_THROW(i.wireDecode( |
| 288 | "052F 0703080149 2100 1200 1E0B(1F09 1E023E15 0703080148) " |
| 289 | "0A044ACB1E4C 0C0276A1 2201D6 2304C0C1C2C3 2304C0C1C2C3"_block), |
| 290 | tlv::Error); |
| 291 | } |
| 292 | |
| 293 | BOOST_AUTO_TEST_CASE(HopLimitOutOfOrder) |
| 294 | { |
| 295 | // HopLimit is non-critical, its out-of-order appearances are ignored |
| 296 | i.wireDecode("0514 0703080149 2201D6 2200 2304C0C1C2C3 22020101"_block); |
| 297 | BOOST_CHECK_EQUAL(i.getName(), "/I"); |
| 298 | // HopLimit=214 is not stored |
Arthi Padmanabhan | b38664e | 2018-07-18 11:13:12 -0700 | [diff] [blame^] | 299 | BOOST_CHECK_EQUAL(i.getParameters(), "2304C0C1C2C3"_block); |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | BOOST_AUTO_TEST_CASE(NameMissing) |
| 303 | { |
| 304 | BOOST_CHECK_THROW(i.wireDecode("0500"_block), tlv::Error); |
| 305 | BOOST_CHECK_THROW(i.wireDecode("0502 1200"_block), tlv::Error); |
| 306 | } |
| 307 | |
| 308 | BOOST_AUTO_TEST_CASE(NameEmpty) |
| 309 | { |
| 310 | BOOST_CHECK_THROW(i.wireDecode("0502 0700"_block), tlv::Error); |
| 311 | } |
| 312 | |
| 313 | BOOST_AUTO_TEST_CASE(BadCanBePrefix) |
| 314 | { |
| 315 | BOOST_CHECK_THROW(i.wireDecode("0508 0703080149 210102"_block), tlv::Error); |
| 316 | } |
| 317 | |
| 318 | BOOST_AUTO_TEST_CASE(BadMustBeFresh) |
| 319 | { |
| 320 | BOOST_CHECK_THROW(i.wireDecode("0508 0703080149 120102"_block), tlv::Error); |
| 321 | } |
| 322 | |
| 323 | BOOST_AUTO_TEST_CASE(BadNonce) |
| 324 | { |
| 325 | BOOST_CHECK_THROW(i.wireDecode("0507 0703080149 0A00"_block), tlv::Error); |
| 326 | BOOST_CHECK_THROW(i.wireDecode("050A 0703080149 0A0304C263"_block), tlv::Error); |
| 327 | BOOST_CHECK_THROW(i.wireDecode("050C 0703080149 0A05EFA420B262"_block), tlv::Error); |
| 328 | } |
| 329 | |
| 330 | BOOST_AUTO_TEST_CASE(UnrecognizedCriticalElement) |
| 331 | { |
| 332 | BOOST_CHECK_THROW(i.wireDecode("0507 0703080149 FB00"_block), tlv::Error); |
| 333 | } |
| 334 | |
| 335 | BOOST_AUTO_TEST_SUITE_END() // Decode03 |
| 336 | |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 337 | // ---- matching ---- |
| 338 | |
| 339 | BOOST_AUTO_TEST_CASE(MatchesData) |
| 340 | { |
| 341 | Interest interest; |
| 342 | interest.setName("ndn:/A") |
| 343 | .setMinSuffixComponents(2) |
| 344 | .setMaxSuffixComponents(2) |
| 345 | .setPublisherPublicKeyLocator(KeyLocator("ndn:/B")) |
| 346 | .setExclude(Exclude().excludeAfter(name::Component("J"))); |
| 347 | |
| 348 | Data data("ndn:/A/D"); |
| 349 | SignatureSha256WithRsa signature(KeyLocator("ndn:/B")); |
Junxiao Shi | db7464d | 2017-07-13 03:11:17 +0000 | [diff] [blame] | 350 | signature.setValue(encoding::makeEmptyBlock(tlv::SignatureValue)); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 351 | data.setSignature(signature); |
| 352 | data.wireEncode(); |
| 353 | BOOST_CHECK_EQUAL(interest.matchesData(data), true); |
| 354 | |
| 355 | Data data1 = data; |
| 356 | data1.setName("ndn:/A"); // violates MinSuffixComponents |
| 357 | data1.wireEncode(); |
| 358 | BOOST_CHECK_EQUAL(interest.matchesData(data1), false); |
| 359 | |
| 360 | Interest interest1 = interest; |
| 361 | interest1.setMinSuffixComponents(1); |
| 362 | BOOST_CHECK_EQUAL(interest1.matchesData(data1), true); |
| 363 | |
| 364 | Data data2 = data; |
| 365 | data2.setName("ndn:/A/E/F"); // violates MaxSuffixComponents |
| 366 | data2.wireEncode(); |
| 367 | BOOST_CHECK_EQUAL(interest.matchesData(data2), false); |
| 368 | |
| 369 | Interest interest2 = interest; |
| 370 | interest2.setMaxSuffixComponents(3); |
| 371 | BOOST_CHECK_EQUAL(interest2.matchesData(data2), true); |
| 372 | |
| 373 | Data data3 = data; |
| 374 | SignatureSha256WithRsa signature3(KeyLocator("ndn:/G")); // violates PublisherPublicKeyLocator |
Junxiao Shi | db7464d | 2017-07-13 03:11:17 +0000 | [diff] [blame] | 375 | signature3.setValue(encoding::makeEmptyBlock(tlv::SignatureValue)); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 376 | data3.setSignature(signature3); |
| 377 | data3.wireEncode(); |
| 378 | BOOST_CHECK_EQUAL(interest.matchesData(data3), false); |
| 379 | |
| 380 | Interest interest3 = interest; |
| 381 | interest3.setPublisherPublicKeyLocator(KeyLocator("ndn:/G")); |
| 382 | BOOST_CHECK_EQUAL(interest3.matchesData(data3), true); |
| 383 | |
| 384 | Data data4 = data; |
| 385 | DigestSha256 signature4; // violates PublisherPublicKeyLocator |
Junxiao Shi | db7464d | 2017-07-13 03:11:17 +0000 | [diff] [blame] | 386 | signature4.setValue(encoding::makeEmptyBlock(tlv::SignatureValue)); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 387 | data4.setSignature(signature4); |
| 388 | data4.wireEncode(); |
| 389 | BOOST_CHECK_EQUAL(interest.matchesData(data4), false); |
| 390 | |
| 391 | Interest interest4 = interest; |
| 392 | interest4.setPublisherPublicKeyLocator(KeyLocator()); |
| 393 | BOOST_CHECK_EQUAL(interest4.matchesData(data4), true); |
| 394 | |
| 395 | Data data5 = data; |
| 396 | data5.setName("ndn:/A/J"); // violates Exclude |
| 397 | data5.wireEncode(); |
| 398 | BOOST_CHECK_EQUAL(interest.matchesData(data5), false); |
| 399 | |
| 400 | Interest interest5 = interest; |
| 401 | interest5.setExclude(Exclude().excludeAfter(name::Component("K"))); |
| 402 | BOOST_CHECK_EQUAL(interest5.matchesData(data5), true); |
| 403 | |
| 404 | Data data6 = data; |
| 405 | data6.setName("ndn:/H/I"); // violates Name |
| 406 | data6.wireEncode(); |
| 407 | BOOST_CHECK_EQUAL(interest.matchesData(data6), false); |
| 408 | |
| 409 | Data data7 = data; |
| 410 | data7.setName("ndn:/A/B"); |
| 411 | data7.wireEncode(); |
| 412 | |
Junxiao Shi | db7464d | 2017-07-13 03:11:17 +0000 | [diff] [blame] | 413 | Interest interest7("/A/B/sha256digest=54008e240a7eea2714a161dfddf0dd6ced223b3856e9da96792151e180f3b128"); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 414 | BOOST_CHECK_EQUAL(interest7.matchesData(data7), true); |
| 415 | |
| 416 | Interest interest7b("/A/B/sha256digest=0000000000000000000000000000000000000000000000000000000000000000"); |
| 417 | BOOST_CHECK_EQUAL(interest7b.matchesData(data7), false); // violates implicit digest |
| 418 | } |
| 419 | |
| 420 | BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(MatchesInterest, 1) |
| 421 | BOOST_AUTO_TEST_CASE(MatchesInterest) |
| 422 | { |
| 423 | Interest interest; |
| 424 | interest |
| 425 | .setName("/A") |
| 426 | .setMinSuffixComponents(2) |
| 427 | .setMaxSuffixComponents(2) |
| 428 | .setPublisherPublicKeyLocator(KeyLocator("/B")) |
| 429 | .setExclude(Exclude().excludeAfter(name::Component("J"))) |
| 430 | .setNonce(10) |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 431 | .setInterestLifetime(5_s) |
Junxiao Shi | d701e5b | 2017-07-26 01:30:41 +0000 | [diff] [blame] | 432 | .setForwardingHint({{1, "/H"}}); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 433 | |
| 434 | Interest other; |
| 435 | BOOST_CHECK_EQUAL(interest.matchesInterest(other), false); |
| 436 | |
| 437 | other.setName(interest.getName()); |
| 438 | BOOST_CHECK_EQUAL(interest.matchesInterest(other), false); |
| 439 | |
| 440 | other.setSelectors(interest.getSelectors()); |
| 441 | BOOST_CHECK_EQUAL(interest.matchesInterest(other), false); // will match until #3162 implemented |
| 442 | |
Junxiao Shi | d701e5b | 2017-07-26 01:30:41 +0000 | [diff] [blame] | 443 | other.setForwardingHint({{1, "/H"}}); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 444 | BOOST_CHECK_EQUAL(interest.matchesInterest(other), true); |
| 445 | |
| 446 | other.setNonce(200); |
| 447 | BOOST_CHECK_EQUAL(interest.matchesInterest(other), true); |
| 448 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 449 | other.setInterestLifetime(5_h); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 450 | BOOST_CHECK_EQUAL(interest.matchesInterest(other), true); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | // ---- field accessors ---- |
| 454 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 455 | BOOST_AUTO_TEST_CASE(CanBePrefix) |
| 456 | { |
| 457 | Interest i; |
| 458 | BOOST_CHECK_EQUAL(i.getCanBePrefix(), true); |
| 459 | i.setCanBePrefix(false); |
| 460 | BOOST_CHECK_EQUAL(i.getCanBePrefix(), false); |
| 461 | BOOST_CHECK_EQUAL(i.getSelectors().getMaxSuffixComponents(), 1); |
| 462 | i.setCanBePrefix(true); |
| 463 | BOOST_CHECK_EQUAL(i.getCanBePrefix(), true); |
| 464 | BOOST_CHECK_EQUAL(i.getSelectors().getMaxSuffixComponents(), -1); |
| 465 | } |
| 466 | |
| 467 | BOOST_AUTO_TEST_CASE(MustBeFresh) |
| 468 | { |
| 469 | Interest i; |
| 470 | BOOST_CHECK_EQUAL(i.getMustBeFresh(), false); |
| 471 | i.setMustBeFresh(true); |
| 472 | BOOST_CHECK_EQUAL(i.getMustBeFresh(), true); |
| 473 | BOOST_CHECK_EQUAL(i.getSelectors().getMustBeFresh(), true); |
| 474 | i.setMustBeFresh(false); |
| 475 | BOOST_CHECK_EQUAL(i.getMustBeFresh(), false); |
| 476 | BOOST_CHECK_EQUAL(i.getSelectors().getMustBeFresh(), false); |
| 477 | } |
| 478 | |
| 479 | BOOST_AUTO_TEST_CASE(ModifyForwardingHint) |
| 480 | { |
| 481 | Interest i; |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 482 | i.setCanBePrefix(false); |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 483 | i.setForwardingHint({{1, "/A"}}); |
| 484 | i.wireEncode(); |
| 485 | BOOST_CHECK(i.hasWire()); |
| 486 | |
| 487 | i.modifyForwardingHint([] (DelegationList& fh) { fh.insert(2, "/B"); }); |
| 488 | BOOST_CHECK(!i.hasWire()); |
| 489 | BOOST_CHECK_EQUAL(i.getForwardingHint(), DelegationList({{1, "/A"}, {2, "/B"}})); |
| 490 | } |
| 491 | |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 492 | BOOST_AUTO_TEST_CASE(GetNonce) |
| 493 | { |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 494 | unique_ptr<Interest> i1, i2; |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 495 | |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 496 | // getNonce automatically assigns a random Nonce. |
| 497 | // It's possible to assign the same Nonce to two Interest, but it's unlikely to get 100 pairs of |
| 498 | // same Nonces in a row. |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 499 | int nIterations = 0; |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 500 | uint32_t nonce1 = 0, nonce2 = 0; |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 501 | do { |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 502 | i1 = make_unique<Interest>(); |
| 503 | nonce1 = i1->getNonce(); |
| 504 | i2 = make_unique<Interest>(); |
| 505 | nonce2 = i2->getNonce(); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 506 | } |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 507 | while (nonce1 == nonce2 && ++nIterations < 100); |
| 508 | BOOST_CHECK_NE(nonce1, nonce2); |
| 509 | BOOST_CHECK(i1->hasNonce()); |
| 510 | BOOST_CHECK(i2->hasNonce()); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 511 | |
| 512 | // Once a Nonce is assigned, it should not change. |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 513 | BOOST_CHECK_EQUAL(i1->getNonce(), nonce1); |
| 514 | } |
| 515 | |
| 516 | BOOST_AUTO_TEST_CASE(SetNonce) |
| 517 | { |
| 518 | Interest i1("/A"); |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 519 | i1.setCanBePrefix(false); |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 520 | i1.setNonce(1); |
| 521 | i1.wireEncode(); |
| 522 | BOOST_CHECK_EQUAL(i1.getNonce(), 1); |
| 523 | |
| 524 | Interest i2(i1); |
| 525 | BOOST_CHECK_EQUAL(i2.getNonce(), 1); |
| 526 | |
| 527 | i2.setNonce(2); |
| 528 | BOOST_CHECK_EQUAL(i2.getNonce(), 2); |
| 529 | BOOST_CHECK_EQUAL(i1.getNonce(), 1); // should not affect i1 Nonce (Bug #4168) |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | BOOST_AUTO_TEST_CASE(RefreshNonce) |
| 533 | { |
| 534 | Interest i; |
| 535 | BOOST_CHECK(!i.hasNonce()); |
| 536 | i.refreshNonce(); |
| 537 | BOOST_CHECK(!i.hasNonce()); |
| 538 | |
| 539 | i.setNonce(1); |
| 540 | BOOST_CHECK(i.hasNonce()); |
| 541 | i.refreshNonce(); |
| 542 | BOOST_CHECK(i.hasNonce()); |
| 543 | BOOST_CHECK_NE(i.getNonce(), 1); |
| 544 | } |
| 545 | |
| 546 | BOOST_AUTO_TEST_CASE(SetInterestLifetime) |
| 547 | { |
| 548 | BOOST_CHECK_THROW(Interest("/A", time::milliseconds(-1)), std::invalid_argument); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 549 | BOOST_CHECK_NO_THROW(Interest("/A", 0_ms)); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 550 | |
| 551 | Interest i("/local/ndn/prefix"); |
| 552 | i.setNonce(1); |
| 553 | BOOST_CHECK_EQUAL(i.getInterestLifetime(), DEFAULT_INTEREST_LIFETIME); |
| 554 | BOOST_CHECK_THROW(i.setInterestLifetime(time::milliseconds(-1)), std::invalid_argument); |
| 555 | BOOST_CHECK_EQUAL(i.getInterestLifetime(), DEFAULT_INTEREST_LIFETIME); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 556 | i.setInterestLifetime(0_ms); |
| 557 | BOOST_CHECK_EQUAL(i.getInterestLifetime(), 0_ms); |
| 558 | i.setInterestLifetime(1_ms); |
| 559 | BOOST_CHECK_EQUAL(i.getInterestLifetime(), 1_ms); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 560 | } |
| 561 | |
Arthi Padmanabhan | b38664e | 2018-07-18 11:13:12 -0700 | [diff] [blame^] | 562 | BOOST_AUTO_TEST_CASE(SetParameters) |
| 563 | { |
| 564 | const uint8_t PARAMETERS1[] = {0xc1}; |
| 565 | const uint8_t PARAMETERS2[] = {0xc2}; |
| 566 | |
| 567 | Interest i; |
| 568 | BOOST_CHECK(!i.hasParameters()); |
| 569 | i.setParameters("2300"_block); |
| 570 | BOOST_CHECK(i.hasParameters()); |
| 571 | i.unsetParameters(); |
| 572 | BOOST_CHECK(!i.hasParameters()); |
| 573 | |
| 574 | i.setParameters("2301C0"_block); // Block overload |
| 575 | BOOST_CHECK_EQUAL(i.getParameters(), "2301C0"_block); |
| 576 | i.setParameters(PARAMETERS1, sizeof(PARAMETERS1)); // raw buffer overload |
| 577 | BOOST_CHECK_EQUAL(i.getParameters(), "2301C1"_block); |
| 578 | i.setParameters(make_shared<Buffer>(PARAMETERS2, sizeof(PARAMETERS2))); // ConstBufferPtr overload |
| 579 | BOOST_CHECK_EQUAL(i.getParameters(), "2301C2"_block); |
| 580 | i.setParameters("8001C1"_block); // Block of non-Parameters type |
| 581 | BOOST_CHECK_EQUAL(i.getParameters(), "23038001C1"_block); |
| 582 | } |
| 583 | |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 584 | // ---- operators ---- |
| 585 | |
| 586 | BOOST_AUTO_TEST_CASE(Equality) |
| 587 | { |
| 588 | Interest a; |
| 589 | Interest b; |
| 590 | |
| 591 | // if nonce is not set, it would be set to a random value |
| 592 | a.setNonce(1); |
| 593 | b.setNonce(1); |
| 594 | |
| 595 | BOOST_CHECK_EQUAL(a == b, true); |
| 596 | BOOST_CHECK_EQUAL(a != b, false); |
| 597 | |
| 598 | // compare Name |
| 599 | a.setName("/A"); |
| 600 | BOOST_CHECK_EQUAL(a == b, false); |
| 601 | BOOST_CHECK_EQUAL(a != b, true); |
| 602 | |
| 603 | b.setName("/B"); |
| 604 | BOOST_CHECK_EQUAL(a == b, false); |
| 605 | BOOST_CHECK_EQUAL(a != b, true); |
| 606 | |
| 607 | b.setName("/A"); |
| 608 | BOOST_CHECK_EQUAL(a == b, true); |
| 609 | BOOST_CHECK_EQUAL(a != b, false); |
| 610 | |
| 611 | // compare Selectors |
| 612 | a.setChildSelector(1); |
| 613 | BOOST_CHECK_EQUAL(a == b, false); |
| 614 | BOOST_CHECK_EQUAL(a != b, true); |
| 615 | |
| 616 | b.setChildSelector(1); |
| 617 | BOOST_CHECK_EQUAL(a == b, true); |
| 618 | BOOST_CHECK_EQUAL(a != b, false); |
| 619 | |
| 620 | // compare Nonce |
| 621 | a.setNonce(100); |
| 622 | BOOST_CHECK_EQUAL(a == b, false); |
| 623 | BOOST_CHECK_EQUAL(a != b, true); |
| 624 | |
| 625 | b.setNonce(100); |
| 626 | BOOST_CHECK_EQUAL(a == b, true); |
| 627 | BOOST_CHECK_EQUAL(a != b, false); |
| 628 | |
| 629 | // compare InterestLifetime |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 630 | a.setInterestLifetime(10_s); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 631 | BOOST_CHECK_EQUAL(a == b, false); |
| 632 | BOOST_CHECK_EQUAL(a != b, true); |
| 633 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 634 | b.setInterestLifetime(10_s); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 635 | BOOST_CHECK_EQUAL(a == b, true); |
| 636 | BOOST_CHECK_EQUAL(a != b, false); |
| 637 | |
Junxiao Shi | d701e5b | 2017-07-26 01:30:41 +0000 | [diff] [blame] | 638 | // compare ForwardingHint |
| 639 | a.setForwardingHint({{1, "/H"}}); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 640 | BOOST_CHECK_EQUAL(a == b, false); |
| 641 | BOOST_CHECK_EQUAL(a != b, true); |
| 642 | |
Junxiao Shi | d701e5b | 2017-07-26 01:30:41 +0000 | [diff] [blame] | 643 | b.setForwardingHint({{1, "/H"}}); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 644 | BOOST_CHECK_EQUAL(a == b, true); |
| 645 | BOOST_CHECK_EQUAL(a != b, false); |
Arthi Padmanabhan | b38664e | 2018-07-18 11:13:12 -0700 | [diff] [blame^] | 646 | |
| 647 | // compare Parameters |
| 648 | a.setParameters("2304C0C1C2C3"_block); |
| 649 | BOOST_CHECK_EQUAL(a == b, false); |
| 650 | BOOST_CHECK_EQUAL(a != b, true); |
| 651 | |
| 652 | b.setParameters("2304C0C1C2C3"_block); |
| 653 | BOOST_CHECK_EQUAL(a == b, true); |
| 654 | BOOST_CHECK_EQUAL(a != b, false); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 655 | } |
| 656 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 657 | BOOST_AUTO_TEST_SUITE_END() // TestInterest |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 658 | |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 659 | } // namespace tests |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 660 | } // namespace ndn |