Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017 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 | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 23 | #include "interest-filter.hpp" |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 24 | #include "data.hpp" |
| 25 | #include "security/signature-sha256-with-rsa.hpp" |
Yingdi Yu | bf6a281 | 2014-06-17 15:32:11 -0700 | [diff] [blame] | 26 | #include "security/digest-sha256.hpp" |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 27 | #include "security/key-chain.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 28 | #include "encoding/buffer-stream.hpp" |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 29 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 30 | #include "boost-test.hpp" |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 31 | #include "identity-management-fixture.hpp" |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 32 | |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 33 | namespace ndn { |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 34 | namespace tests { |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 35 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 36 | BOOST_FIXTURE_TEST_SUITE(TestInterest, IdentityManagementFixture) |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 37 | |
| 38 | const uint8_t Interest1[] = { |
Alexander Afanasyev | 117f5ef | 2015-06-03 15:07:24 -0700 | [diff] [blame] | 39 | 0x05, 0x59, // NDN Interest |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 40 | 0x07, 0x14, // Name |
| 41 | 0x08, 0x5, // NameComponent |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 42 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 43 | 0x08, 0x3, // NameComponent |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 44 | 0x6e, 0x64, 0x6e, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 45 | 0x08, 0x6, // NameComponent |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 46 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 47 | 0x09, 0x37, // Selectors |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 48 | 0x0d, 0x1, 0x1, // MinSuffix |
| 49 | 0x0e, 0x1, 0x1, // MaxSuffix |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 50 | 0x1c, 0x16, // KeyLocator |
| 51 | 0x07, 0x14, // Name |
| 52 | 0x08, 0x04, |
| 53 | 0x74, 0x65, 0x73, 0x74, |
| 54 | 0x08, 0x03, |
| 55 | 0x6b, 0x65, 0x79, |
| 56 | 0x08, 0x07, |
| 57 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 58 | 0x10, 0x14, // Exclude |
| 59 | 0x08, 0x4, // NameComponent |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 60 | 0x61, 0x6c, 0x65, 0x78, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 61 | 0x08, 0x4, // NameComponent |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 62 | 0x78, 0x78, 0x78, 0x78, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 63 | 0x13, 0x0, // Any |
| 64 | 0x08, 0x4, // NameComponent |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 65 | 0x79, 0x79, 0x79, 0x79, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 66 | 0x11, 0x1, // ChildSelector |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 67 | 0x1, |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 68 | 0x0a, 0x4, // Nonce |
| 69 | 0x1, 0x0, 0x0, 0x00, |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 70 | 0x0c, // InterestLifetime |
| 71 | 0x2, 0x3, 0xe8 |
| 72 | }; |
| 73 | |
| 74 | const uint8_t Interest2[] = { |
Alexander Afanasyev | 117f5ef | 2015-06-03 15:07:24 -0700 | [diff] [blame] | 75 | 0x05, 0x59, // NDN Interest |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 76 | 0x07, 0x14, // Name |
| 77 | 0x08, 0x5, // NameComponent |
| 78 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 79 | 0x08, 0x3, // NameComponent |
| 80 | 0x6e, 0x64, 0x6e, |
| 81 | 0x08, 0x6, // NameComponent |
| 82 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 83 | 0x09, 0x37, // Selectors |
| 84 | 0x0d, 0x1, 0x1, // MinSuffix |
| 85 | 0x0e, 0x1, 0x1, // MaxSuffix |
| 86 | 0x1c, 0x16, // KeyLocator |
| 87 | 0x07, 0x14, // Name |
| 88 | 0x08, 0x04, |
| 89 | 0x74, 0x65, 0x73, 0x74, |
| 90 | 0x08, 0x03, |
| 91 | 0x6b, 0x65, 0x79, |
| 92 | 0x08, 0x07, |
| 93 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 94 | 0x10, 0x14, // Exclude |
| 95 | 0x08, 0x4, // NameComponent |
| 96 | 0x61, 0x6c, 0x65, 0x78, |
| 97 | 0x08, 0x4, // NameComponent |
| 98 | 0x78, 0x78, 0x78, 0x78, |
| 99 | 0x13, 0x0, // Any |
| 100 | 0x08, 0x4, // NameComponent |
| 101 | 0x79, 0x79, 0x79, 0x79, |
| 102 | 0x11, 0x1, // ChildSelector |
| 103 | 0x1, |
| 104 | 0x0a, 0x4, // Nonce |
| 105 | 0x2, 0x0, 0x0, 0x00, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 106 | 0x0c, // InterestLifetime |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 107 | 0x2, 0x3, 0xe8 |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 108 | }; |
| 109 | |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 110 | const uint8_t InterestWithLink[] = { |
| 111 | 0x05, 0xfb, // Interest |
| 112 | 0x07, 0x14, // Name |
| 113 | 0x08, 0x5, // NameComponent |
| 114 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 115 | 0x08, 0x3, // NameComponent |
| 116 | 0x6e, 0x64, 0x6e, |
| 117 | 0x08, 0x6, // NameComponent |
| 118 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 119 | 0x0a, 0x4, // Nonce |
| 120 | 0x1, 0x0, 0x0, 0x00, |
| 121 | 0x06, 0xda, // Data |
| 122 | 0x07, 0x14, // Name |
| 123 | 0x08, 0x05, |
| 124 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 125 | 0x08, 0x03, |
| 126 | 0x6e, 0x64, 0x6e, |
| 127 | 0x08, 0x06, |
| 128 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 129 | 0x14, 0x07, // MetaInfo |
| 130 | 0x18, 0x01, // ContentType |
| 131 | 0x01, |
| 132 | 0x19, 0x02, // FreshnessPeriod |
| 133 | 0x27, 0x10, |
| 134 | 0x15, 0x1a, // Content |
| 135 | 0x1f, 0x0c, // LinkDelegation |
| 136 | 0x1e, 0x01, // LinkPreference |
| 137 | 0x0a, |
| 138 | 0x07, 0x07, // Name |
| 139 | 0x08, 0x05, |
| 140 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 141 | 0x1f, 0x0a, // LinkDelegation |
| 142 | 0x1e, 0x01, // LinkPreference |
| 143 | 0x14, |
| 144 | 0x07, 0x05, // Name |
| 145 | 0x08, 0x03, |
| 146 | 0x6e, 0x64, 0x6e, |
| 147 | 0x16, 0x1b, // SignatureInfo |
| 148 | 0x1b, 0x01, // SignatureType |
| 149 | 0x01, |
| 150 | 0x1c, 0x16, // KeyLocator |
| 151 | 0x07, 0x14, // Name |
| 152 | 0x08, 0x04, |
| 153 | 0x74, 0x65, 0x73, 0x74, |
| 154 | 0x08, 0x03, |
| 155 | 0x6b, 0x65, 0x79, |
| 156 | 0x08, 0x07, |
| 157 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 158 | 0x17, 0x80, // SignatureValue |
| 159 | 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec, |
| 160 | 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6, |
| 161 | 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38, |
| 162 | 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc, |
| 163 | 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf, |
| 164 | 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9, |
| 165 | 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8, |
| 166 | 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7, |
| 167 | 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3, |
| 168 | 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1, |
| 169 | 0x20, 0x01, // SelectedDelegation |
| 170 | 0x00 |
| 171 | }; |
| 172 | |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 173 | const uint8_t LINK[] = { |
| 174 | 0x06, 0xda, // Data |
| 175 | 0x07, 0x14, // Name |
| 176 | 0x08, 0x05, |
| 177 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 178 | 0x08, 0x03, |
| 179 | 0x6e, 0x64, 0x6e, |
| 180 | 0x08, 0x06, |
| 181 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 182 | 0x14, 0x07, // MetaInfo |
| 183 | 0x18, 0x01, // ContentType |
| 184 | 0x01, |
| 185 | 0x19, 0x02, // FreshnessPeriod |
| 186 | 0x27, 0x10, |
| 187 | 0x15, 0x1a, // Content |
| 188 | 0x1f, 0x0c, // LinkDelegation |
| 189 | 0x1e, 0x01, // LinkPreference |
| 190 | 0x0a, |
| 191 | 0x07, 0x07, // Name |
| 192 | 0x08, 0x05, |
| 193 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 194 | 0x1f, 0x0a, // LinkDelegation |
| 195 | 0x1e, 0x01, // LinkPreference |
| 196 | 0x14, |
| 197 | 0x07, 0x05, // Name |
| 198 | 0x08, 0x03, |
| 199 | 0x6e, 0x64, 0x6e, |
| 200 | 0x16, 0x1b, // SignatureInfo |
| 201 | 0x1b, 0x01, // SignatureType |
| 202 | 0x01, |
| 203 | 0x1c, 0x16, // KeyLocator |
| 204 | 0x07, 0x14, // Name |
| 205 | 0x08, 0x04, |
| 206 | 0x74, 0x65, 0x73, 0x74, |
| 207 | 0x08, 0x03, |
| 208 | 0x6b, 0x65, 0x79, |
| 209 | 0x08, 0x07, |
| 210 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 211 | 0x17, 0x80, // SignatureValue |
| 212 | 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec, |
| 213 | 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6, |
| 214 | 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38, |
| 215 | 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc, |
| 216 | 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf, |
| 217 | 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9, |
| 218 | 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8, |
| 219 | 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7, |
| 220 | 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3, |
| 221 | 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1 |
| 222 | }; |
| 223 | |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 224 | const uint8_t InterestWithLinkMissingContentType[] = { |
| 225 | 0x05, 0xf8, // Interest |
| 226 | 0x07, 0x14, // Name |
| 227 | 0x08, 0x5, // NameComponent |
| 228 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 229 | 0x08, 0x3, // NameComponent |
| 230 | 0x6e, 0x64, 0x6e, |
| 231 | 0x08, 0x6, // NameComponent |
| 232 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 233 | 0x0a, 0x4, // Nonce |
| 234 | 0x1, 0x0, 0x0, 0x00, |
| 235 | 0x06, 0xd7, // Data |
| 236 | 0x07, 0x14, // Name |
| 237 | 0x08, 0x05, |
| 238 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 239 | 0x08, 0x03, |
| 240 | 0x6e, 0x64, 0x6e, |
| 241 | 0x08, 0x06, |
| 242 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 243 | 0x14, 0x04, // MetaInfo |
| 244 | 0x19, 0x02, // FreshnessPeriod |
| 245 | 0x27, 0x10, |
| 246 | 0x15, 0x1a, // Content |
| 247 | 0x1f, 0x0c, // LinkDelegation |
| 248 | 0x1e, 0x01, // LinkPreference |
| 249 | 0x0a, |
| 250 | 0x07, 0x07, // Name |
| 251 | 0x08, 0x05, |
| 252 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 253 | 0x1f, 0x0a, // LinkDelegation |
| 254 | 0x1e, 0x01, // LinkPreference |
| 255 | 0x14, |
| 256 | 0x07, 0x05, // Name |
| 257 | 0x08, 0x03, |
| 258 | 0x6e, 0x64, 0x6e, |
| 259 | 0x16, 0x1b, // SignatureInfo |
| 260 | 0x1b, 0x01, // SignatureType |
| 261 | 0x01, |
| 262 | 0x1c, 0x16, // KeyLocator |
| 263 | 0x07, 0x14, // Name |
| 264 | 0x08, 0x04, |
| 265 | 0x74, 0x65, 0x73, 0x74, |
| 266 | 0x08, 0x03, |
| 267 | 0x6b, 0x65, 0x79, |
| 268 | 0x08, 0x07, |
| 269 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 270 | 0x17, 0x80, // SignatureValue |
| 271 | 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec, |
| 272 | 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6, |
| 273 | 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38, |
| 274 | 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc, |
| 275 | 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf, |
| 276 | 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9, |
| 277 | 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8, |
| 278 | 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7, |
| 279 | 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3, |
| 280 | 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1, |
| 281 | 0x20, 0x01, // SelectedDelegation |
| 282 | 0x00 |
| 283 | }; |
| 284 | |
| 285 | const uint8_t InterestWithLinkNoMetaInfo[] = { |
| 286 | 0x05, 0xf2, // Interest |
| 287 | 0x07, 0x14, // Name |
| 288 | 0x08, 0x5, // NameComponent |
| 289 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 290 | 0x08, 0x3, // NameComponent |
| 291 | 0x6e, 0x64, 0x6e, |
| 292 | 0x08, 0x6, // NameComponent |
| 293 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 294 | 0x0a, 0x4, // Nonce |
| 295 | 0x1, 0x0, 0x0, 0x00, |
| 296 | 0x06, 0xd1, // Data |
| 297 | 0x07, 0x14, // Name |
| 298 | 0x08, 0x05, |
| 299 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 300 | 0x08, 0x03, |
| 301 | 0x6e, 0x64, 0x6e, |
| 302 | 0x08, 0x06, |
| 303 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 304 | 0x15, 0x1a, // Content |
| 305 | 0x1f, 0x0c, // LinkDelegation |
| 306 | 0x1e, 0x01, // LinkPreference |
| 307 | 0x0a, |
| 308 | 0x07, 0x07, // Name |
| 309 | 0x08, 0x05, |
| 310 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 311 | 0x1f, 0x0a, // LinkPreference |
| 312 | 0x1e, 0x01, // LinkPreference |
| 313 | 0x14, |
| 314 | 0x07, 0x05, // Name |
| 315 | 0x08, 0x03, |
| 316 | 0x6e, 0x64, 0x6e, |
| 317 | 0x16, 0x1b, // SignatureInfo |
| 318 | 0x1b, 0x01, // SignatureType |
| 319 | 0x01, |
| 320 | 0x1c, 0x16, // KeyLocator |
| 321 | 0x07, 0x14, // Name |
| 322 | 0x08, 0x04, |
| 323 | 0x74, 0x65, 0x73, 0x74, |
| 324 | 0x08, 0x03, |
| 325 | 0x6b, 0x65, 0x79, |
| 326 | 0x08, 0x07, |
| 327 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 328 | 0x17, 0x80, // SignatureValue |
| 329 | 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec, |
| 330 | 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6, |
| 331 | 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38, |
| 332 | 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc, |
| 333 | 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf, |
| 334 | 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9, |
| 335 | 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8, |
| 336 | 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7, |
| 337 | 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3, |
| 338 | 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1, |
| 339 | 0x20, 0x01, // SelectedDelegation |
| 340 | 0x00 |
| 341 | }; |
| 342 | |
| 343 | const uint8_t InterestWithLinkWrongContentType[] = { |
| 344 | 0x05, 0xfb, // Interest |
| 345 | 0x07, 0x14, // Name |
| 346 | 0x08, 0x5, // NameComponent |
| 347 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 348 | 0x08, 0x3, // NameComponent |
| 349 | 0x6e, 0x64, 0x6e, |
| 350 | 0x08, 0x6, // NameComponent |
| 351 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 352 | 0x0a, 0x4, // Nonce |
| 353 | 0x1, 0x0, 0x0, 0x00, |
| 354 | 0x06, 0xda, // Data |
| 355 | 0x07, 0x14, // Name |
| 356 | 0x08, 0x05, |
| 357 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 358 | 0x08, 0x03, |
| 359 | 0x6e, 0x64, 0x6e, |
| 360 | 0x08, 0x06, |
| 361 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 362 | 0x14, 0x07, // MetaInfo |
| 363 | 0x18, 0x01, // ContentType |
| 364 | 0x00, |
| 365 | 0x19, 0x02, // FreshnessPeriod |
| 366 | 0x27, 0x10, |
| 367 | 0x15, 0x1a, // Content |
| 368 | 0x1f, 0x0c, // LinkDelegation |
| 369 | 0x1e, 0x01, // LinkPreference |
| 370 | 0x0a, |
| 371 | 0x07, 0x07, // Name |
| 372 | 0x08, 0x05, |
| 373 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 374 | 0x1f, 0x0a, // LinkDelegation |
| 375 | 0x1e, 0x01, // LinkPreference |
| 376 | 0x14, |
| 377 | 0x07, 0x05, // Name |
| 378 | 0x08, 0x03, |
| 379 | 0x6e, 0x64, 0x6e, |
| 380 | 0x16, 0x1b, // SignatureInfo |
| 381 | 0x1b, 0x01, // SignatureType |
| 382 | 0x01, |
| 383 | 0x1c, 0x16, // KeyLocator |
| 384 | 0x07, 0x14, // Name |
| 385 | 0x08, 0x04, |
| 386 | 0x74, 0x65, 0x73, 0x74, |
| 387 | 0x08, 0x03, |
| 388 | 0x6b, 0x65, 0x79, |
| 389 | 0x08, 0x07, |
| 390 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 391 | 0x17, 0x80, // SignatureValue |
| 392 | 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec, |
| 393 | 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6, |
| 394 | 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38, |
| 395 | 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc, |
| 396 | 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf, |
| 397 | 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9, |
| 398 | 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8, |
| 399 | 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7, |
| 400 | 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3, |
| 401 | 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1, |
| 402 | 0x20, 0x01, // SelectedDelegation |
| 403 | 0x00 |
| 404 | }; |
| 405 | |
| 406 | const uint8_t InterestWithSelectedDelegationButNoLink[] = { |
| 407 | 0x05, 0x1f, // Interest |
| 408 | 0x07, 0x14, // Name |
| 409 | 0x08, 0x5, // NameComponent |
| 410 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 411 | 0x08, 0x3, // NameComponent |
| 412 | 0x6e, 0x64, 0x6e, |
| 413 | 0x08, 0x6, // NameComponent |
| 414 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 415 | 0x0a, 0x4, // Nonce |
| 416 | 0x1, 0x0, 0x0, 0x00, |
| 417 | 0x20, 0x01, // SelectedDelegation |
| 418 | 0x00 |
| 419 | }; |
| 420 | |
| 421 | const uint8_t InterestWithLinkNotNonIntegerSelectedDelegation[] = { |
| 422 | 0x05, 0xfb, // Interest |
| 423 | 0x07, 0x14, // Name |
| 424 | 0x08, 0x5, // NameComponent |
| 425 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 426 | 0x08, 0x3, // NameComponent |
| 427 | 0x6e, 0x64, 0x6e, |
| 428 | 0x08, 0x6, // NameComponent |
| 429 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 430 | 0x0a, 0x4, // Nonce |
| 431 | 0x1, 0x0, 0x0, 0x00, |
| 432 | 0x06, 0xda, // Data |
| 433 | 0x07, 0x14, // Name |
| 434 | 0x08, 0x05, |
| 435 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 436 | 0x08, 0x03, |
| 437 | 0x6e, 0x64, 0x6e, |
| 438 | 0x08, 0x06, |
| 439 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 440 | 0x14, 0x07, // MetaInfo |
| 441 | 0x18, 0x01, // ContentType |
| 442 | 0x01, |
| 443 | 0x19, 0x02, // FreshnessPeriod |
| 444 | 0x27, 0x10, |
| 445 | 0x15, 0x1a, // Content |
| 446 | 0x1f, 0x0c, // LinkDelegation |
| 447 | 0x1e, 0x01, // LinkPreference |
| 448 | 0x0a, |
| 449 | 0x07, 0x07, // Name |
| 450 | 0x08, 0x05, |
| 451 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 452 | 0x1f, 0x0a, // LinkDelegation |
| 453 | 0x1e, 0x01, // LinkPreference |
| 454 | 0x14, |
| 455 | 0x07, 0x05, // Name |
| 456 | 0x08, 0x03, |
| 457 | 0x6e, 0x64, 0x6e, |
| 458 | 0x16, 0x1b, // SignatureInfo |
| 459 | 0x1b, 0x01, // SignatureType |
| 460 | 0x01, |
| 461 | 0x1c, 0x16, // KeyLocator |
| 462 | 0x07, 0x14, // Name |
| 463 | 0x08, 0x04, |
| 464 | 0x74, 0x65, 0x73, 0x74, |
| 465 | 0x08, 0x03, |
| 466 | 0x6b, 0x65, 0x79, |
| 467 | 0x08, 0x07, |
| 468 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 469 | 0x17, 0x78, // SignatureValue |
| 470 | 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec, |
| 471 | 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6, |
| 472 | 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38, |
| 473 | 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc, |
| 474 | 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf, |
| 475 | 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9, |
| 476 | 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8, |
| 477 | 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7, |
| 478 | 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3, |
| 479 | 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, |
| 480 | 0x20, 0x03, // SelectedDelegation |
| 481 | 0xAA, 0xAA, 0xAA |
| 482 | }; |
| 483 | |
| 484 | const uint8_t InterestWithLinkNonDecreasingOrder[] = { |
| 485 | 0x05, 0xfb, // Interest |
| 486 | 0x07, 0x14, // Name |
| 487 | 0x08, 0x5, // NameComponent |
| 488 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 489 | 0x08, 0x3, // NameComponent |
| 490 | 0x6e, 0x64, 0x6e, |
| 491 | 0x08, 0x6, // NameComponent |
| 492 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 493 | 0x0a, 0x4, // Nonce |
| 494 | 0x1, 0x0, 0x0, 0x00, |
| 495 | 0x06, 0xda, // Data |
| 496 | 0x07, 0x14, // Name |
| 497 | 0x08, 0x05, |
| 498 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 499 | 0x08, 0x03, |
| 500 | 0x6e, 0x64, 0x6e, |
| 501 | 0x08, 0x06, |
| 502 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 503 | 0x14, 0x07, // MetaInfo |
| 504 | 0x18, 0x01, // ContentType |
| 505 | 0x01, |
| 506 | 0x19, 0x02, // FreshnessPeriod |
| 507 | 0x27, 0x10, |
| 508 | 0x15, 0x1a, // Content |
| 509 | 0x1f, 0x0c, // LinkDelegation |
| 510 | 0x1e, 0x01, // LinkPreference |
| 511 | 0x14, |
| 512 | 0x07, 0x07, // Name |
| 513 | 0x08, 0x05, |
| 514 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 515 | 0x1f, 0x0a, // LinkDelegation |
| 516 | 0x1e, 0x01, // LinkPreference |
| 517 | 0x0a, |
| 518 | 0x07, 0x05, // Name |
| 519 | 0x08, 0x03, |
| 520 | 0x6e, 0x64, 0x6e, |
| 521 | 0x16, 0x1b, // SignatureInfo |
| 522 | 0x1b, 0x01, // SignatureType |
| 523 | 0x01, |
| 524 | 0x1c, 0x16, // KeyLocator |
| 525 | 0x07, 0x14, // Name |
| 526 | 0x08, 0x04, |
| 527 | 0x74, 0x65, 0x73, 0x74, |
| 528 | 0x08, 0x03, |
| 529 | 0x6b, 0x65, 0x79, |
| 530 | 0x08, 0x07, |
| 531 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 532 | 0x17, 0x80, // SignatureValue |
| 533 | 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec, |
| 534 | 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6, |
| 535 | 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38, |
| 536 | 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc, |
| 537 | 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf, |
| 538 | 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9, |
| 539 | 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8, |
| 540 | 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7, |
| 541 | 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3, |
| 542 | 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1, |
| 543 | 0x20, 0x01, // SelectedDelegation |
| 544 | 0x01 |
| 545 | }; |
| 546 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 547 | BOOST_AUTO_TEST_CASE(InterestEqualityChecks) |
| 548 | { |
| 549 | // Interest ::= INTEREST-TYPE TLV-LENGTH |
| 550 | // Name |
| 551 | // Selectors? |
| 552 | // Nonce |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 553 | // InterestLifetime? |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 554 | // Link? |
| 555 | // SelectedDelegation? |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 556 | |
| 557 | Interest a; |
| 558 | Interest b; |
| 559 | |
| 560 | // if nonce is not set, it will be set to a random value |
| 561 | a.setNonce(1); |
| 562 | b.setNonce(1); |
| 563 | |
| 564 | BOOST_CHECK_EQUAL(a == b, true); |
| 565 | BOOST_CHECK_EQUAL(a != b, false); |
| 566 | |
| 567 | // check comparison on Name |
| 568 | a.setName("ndn:/A"); |
| 569 | BOOST_CHECK_EQUAL(a == b, false); |
| 570 | BOOST_CHECK_EQUAL(a != b, true); |
| 571 | |
| 572 | b.setName("ndn:/B"); |
| 573 | BOOST_CHECK_EQUAL(a == b, false); |
| 574 | BOOST_CHECK_EQUAL(a != b, true); |
| 575 | |
| 576 | b.setName("ndn:/A"); |
| 577 | BOOST_CHECK_EQUAL(a == b, true); |
| 578 | BOOST_CHECK_EQUAL(a != b, false); |
| 579 | |
| 580 | // check comparison on Selectors |
| 581 | a.setChildSelector(1); |
| 582 | BOOST_CHECK_EQUAL(a == b, false); |
| 583 | BOOST_CHECK_EQUAL(a != b, true); |
| 584 | |
| 585 | b.setChildSelector(1); |
| 586 | BOOST_CHECK_EQUAL(a == b, true); |
| 587 | BOOST_CHECK_EQUAL(a != b, false); |
| 588 | |
| 589 | // check comparison on Nonce |
| 590 | a.setNonce(100); |
| 591 | BOOST_CHECK_EQUAL(a == b, false); |
| 592 | BOOST_CHECK_EQUAL(a != b, true); |
| 593 | |
| 594 | b.setNonce(100); |
| 595 | BOOST_CHECK_EQUAL(a == b, true); |
| 596 | BOOST_CHECK_EQUAL(a != b, false); |
| 597 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 598 | // check comparison on InterestLifetime |
| 599 | a.setInterestLifetime(time::seconds(10)); |
| 600 | BOOST_CHECK_EQUAL(a == b, false); |
| 601 | BOOST_CHECK_EQUAL(a != b, true); |
| 602 | |
| 603 | b.setInterestLifetime(time::seconds(10)); |
| 604 | BOOST_CHECK_EQUAL(a == b, true); |
| 605 | BOOST_CHECK_EQUAL(a != b, false); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 606 | |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 607 | a.setLink(Block(LINK, sizeof(LINK))); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 608 | BOOST_CHECK_EQUAL(a == b, false); |
| 609 | BOOST_CHECK_EQUAL(a != b, true); |
| 610 | |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 611 | b.setLink(Block(LINK, sizeof(LINK))); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 612 | BOOST_CHECK_EQUAL(a == b, true); |
| 613 | BOOST_CHECK_EQUAL(a != b, false); |
| 614 | |
| 615 | // Selected Delegation |
| 616 | BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false); |
| 617 | BOOST_CHECK_EQUAL(b.hasSelectedDelegation(), false); |
| 618 | |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 619 | a.setSelectedDelegation(Name("/local")); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 620 | BOOST_CHECK_EQUAL(a == b, false); |
| 621 | BOOST_CHECK_EQUAL(a != b, true); |
| 622 | |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 623 | b.setSelectedDelegation(Name("/local")); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 624 | BOOST_CHECK_EQUAL(a == b, true); |
| 625 | BOOST_CHECK_EQUAL(a != b, false); |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | BOOST_AUTO_TEST_CASE(SelectorsEqualityChecks) |
| 629 | { |
| 630 | // Selectors ::= SELECTORS-TYPE TLV-LENGTH |
| 631 | // MinSuffixComponents? |
| 632 | // MaxSuffixComponents? |
| 633 | // PublisherPublicKeyLocator? |
| 634 | // Exclude? |
| 635 | // ChildSelector? |
| 636 | // MustBeFresh? |
| 637 | |
| 638 | Selectors a; |
| 639 | Selectors b; |
| 640 | BOOST_CHECK_EQUAL(a == b, true); |
| 641 | BOOST_CHECK_EQUAL(a != b, false); |
| 642 | |
| 643 | // MinSuffixComponents |
| 644 | a.setMinSuffixComponents(1); |
| 645 | BOOST_CHECK_EQUAL(a == b, false); |
| 646 | BOOST_CHECK_EQUAL(a != b, true); |
| 647 | |
| 648 | b.setMinSuffixComponents(2); |
| 649 | BOOST_CHECK_EQUAL(a == b, false); |
| 650 | BOOST_CHECK_EQUAL(a != b, true); |
| 651 | |
| 652 | b.setMinSuffixComponents(1); |
| 653 | BOOST_CHECK_EQUAL(a == b, true); |
| 654 | BOOST_CHECK_EQUAL(a != b, false); |
| 655 | |
| 656 | // MaxSuffixComponents |
| 657 | a.setMaxSuffixComponents(10); |
| 658 | BOOST_CHECK_EQUAL(a == b, false); |
| 659 | BOOST_CHECK_EQUAL(a != b, true); |
| 660 | |
| 661 | b.setMaxSuffixComponents(10); |
| 662 | BOOST_CHECK_EQUAL(a == b, true); |
| 663 | BOOST_CHECK_EQUAL(a != b, false); |
| 664 | |
| 665 | // PublisherPublicKeyLocator |
| 666 | a.setPublisherPublicKeyLocator(KeyLocator("/key/Locator/name")); |
| 667 | BOOST_CHECK_EQUAL(a == b, false); |
| 668 | BOOST_CHECK_EQUAL(a != b, true); |
| 669 | |
| 670 | b.setPublisherPublicKeyLocator(KeyLocator("/key/Locator/name")); |
| 671 | BOOST_CHECK_EQUAL(a == b, true); |
| 672 | BOOST_CHECK_EQUAL(a != b, false); |
| 673 | |
| 674 | // Exclude |
| 675 | a.setExclude(Exclude().excludeOne(name::Component("exclude"))); |
| 676 | BOOST_CHECK_EQUAL(a == b, false); |
| 677 | BOOST_CHECK_EQUAL(a != b, true); |
| 678 | |
| 679 | b.setExclude(Exclude().excludeOne(name::Component("exclude"))); |
| 680 | BOOST_CHECK_EQUAL(a == b, true); |
| 681 | BOOST_CHECK_EQUAL(a != b, false); |
| 682 | |
| 683 | // ChildSelector |
| 684 | a.setChildSelector(1); |
| 685 | BOOST_CHECK_EQUAL(a == b, false); |
| 686 | BOOST_CHECK_EQUAL(a != b, true); |
| 687 | |
| 688 | b.setChildSelector(1); |
| 689 | BOOST_CHECK_EQUAL(a == b, true); |
| 690 | BOOST_CHECK_EQUAL(a != b, false); |
| 691 | |
| 692 | // MustBeFresh |
| 693 | a.setMustBeFresh(true); |
| 694 | BOOST_CHECK_EQUAL(a == b, false); |
| 695 | BOOST_CHECK_EQUAL(a != b, true); |
| 696 | |
| 697 | b.setMustBeFresh(true); |
| 698 | BOOST_CHECK_EQUAL(a == b, true); |
| 699 | BOOST_CHECK_EQUAL(a != b, false); |
| 700 | } |
| 701 | |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 702 | BOOST_AUTO_TEST_CASE(LinkObject) |
| 703 | { |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 704 | Link link1("test", {{100, "/test3"}, {20, "/test2"}, {10, "/test1"}}); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 705 | m_keyChain.sign(link1); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 706 | Block wire = link1.wireEncode(); |
| 707 | |
| 708 | Interest a; |
| 709 | BOOST_REQUIRE_NO_THROW(a.setLink(wire)); |
| 710 | |
| 711 | BOOST_REQUIRE_NO_THROW(a.getLink()); |
| 712 | |
| 713 | Link link2 = a.getLink(); |
| 714 | Name name = link2.getName(); |
| 715 | BOOST_CHECK_EQUAL(Name("test"), name); |
| 716 | BOOST_CHECK_EQUAL(a.hasLink(), true); |
| 717 | Link::DelegationSet delegations; |
| 718 | delegations = link2.getDelegations(); |
| 719 | |
| 720 | auto i = delegations.begin(); |
| 721 | BOOST_CHECK_EQUAL(std::get<0>(*i), 10); |
| 722 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test1")); |
| 723 | ++i; |
| 724 | BOOST_CHECK_EQUAL(std::get<0>(*i), 20); |
| 725 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test2")); |
| 726 | ++i; |
| 727 | BOOST_CHECK_EQUAL(std::get<0>(*i), 100); |
| 728 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test3")); |
| 729 | |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 730 | a.setLink(Block(LINK, sizeof(LINK))); |
| 731 | BOOST_CHECK_EQUAL(a.getLink().getDelegations().size(), 2); |
| 732 | |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 733 | a.unsetLink(); |
| 734 | BOOST_CHECK_EQUAL(a.hasLink(), false); |
| 735 | } |
| 736 | |
| 737 | BOOST_AUTO_TEST_CASE(SelectedDelegationChecks) |
| 738 | { |
| 739 | Link link("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}}); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 740 | m_keyChain.sign(link); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 741 | Block wire = link.wireEncode(); |
| 742 | |
| 743 | Interest a; |
| 744 | a.setLink(wire); |
| 745 | BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false); |
| 746 | |
| 747 | BOOST_REQUIRE_NO_THROW(a.setSelectedDelegation(Name("test2"))); |
| 748 | BOOST_CHECK_EQUAL(a.getSelectedDelegation(), Name("test2")); |
| 749 | |
| 750 | BOOST_REQUIRE_NO_THROW(a.setSelectedDelegation(uint32_t(2))); |
| 751 | BOOST_CHECK_EQUAL(a.getSelectedDelegation(), Name("test3")); |
| 752 | |
| 753 | a.unsetSelectedDelegation(); |
| 754 | BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false); |
| 755 | } |
| 756 | |
| 757 | BOOST_AUTO_TEST_CASE(EncodeDecodeWithLink) |
| 758 | { |
| 759 | Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}}); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 760 | m_keyChain.sign(link1); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 761 | Block wire = link1.wireEncode(); |
| 762 | |
| 763 | Interest a; |
| 764 | a.setName("/Test/Encode/Decode/With/Link"); |
| 765 | a.setChildSelector(1); |
| 766 | a.setNonce(100); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 767 | a.setInterestLifetime(time::seconds(10)); |
| 768 | a.setLink(wire); |
| 769 | |
| 770 | Block interestBlock = a.wireEncode(); |
| 771 | Interest b(interestBlock); |
| 772 | |
| 773 | BOOST_CHECK_EQUAL(a == b, true); |
| 774 | |
| 775 | Link link2 = b.getLink(); |
| 776 | Link::DelegationSet delegations; |
| 777 | delegations = link2.getDelegations(); |
| 778 | |
| 779 | auto i = delegations.begin(); |
| 780 | BOOST_CHECK_EQUAL(std::get<0>(*i), 10); |
| 781 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test1")); |
| 782 | ++i; |
| 783 | BOOST_CHECK_EQUAL(std::get<0>(*i), 20); |
| 784 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test2")); |
| 785 | ++i; |
| 786 | BOOST_CHECK_EQUAL(std::get<0>(*i), 100); |
| 787 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test3")); |
| 788 | |
| 789 | } |
| 790 | |
| 791 | BOOST_AUTO_TEST_CASE(DecodeInterestWithLink) |
| 792 | { |
| 793 | Block interestBlock(InterestWithLink, sizeof(InterestWithLink)); |
| 794 | |
| 795 | ndn::Interest i; |
| 796 | BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock)); |
| 797 | Link link = i.getLink(); |
| 798 | BOOST_CHECK_EQUAL(link.getName(), Name("/local/ndn/prefix")); |
| 799 | Link::DelegationSet delegations = link.getDelegations(); |
| 800 | |
| 801 | auto it = delegations.begin(); |
| 802 | BOOST_CHECK_EQUAL(std::get<0>(*it), 10); |
| 803 | BOOST_CHECK_EQUAL(std::get<1>(*it), Name("local")); |
| 804 | ++it; |
| 805 | BOOST_CHECK_EQUAL(std::get<0>(*it), 20); |
| 806 | BOOST_CHECK_EQUAL(std::get<1>(*it), Name("ndn")); |
| 807 | |
| 808 | BOOST_REQUIRE_NO_THROW(i.getSelectedDelegation()); |
| 809 | BOOST_CHECK_EQUAL(i.getSelectedDelegation(), Name("local")); |
| 810 | } |
| 811 | |
| 812 | BOOST_AUTO_TEST_CASE(DecodeInterestWithLinkNonDecreasingOrder) |
| 813 | { |
| 814 | Block interestBlock(InterestWithLinkNonDecreasingOrder, |
| 815 | sizeof(InterestWithLinkNonDecreasingOrder)); |
| 816 | |
| 817 | ndn::Interest i; |
| 818 | BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock)); |
| 819 | BOOST_REQUIRE_NO_THROW(i.getSelectedDelegation()); |
| 820 | BOOST_CHECK_EQUAL(i.getSelectedDelegation(), Name("ndn")); |
| 821 | } |
| 822 | |
| 823 | BOOST_AUTO_TEST_CASE(LinkObjectMissingContentType) |
| 824 | { |
| 825 | Block interestBlock(InterestWithLinkMissingContentType, |
| 826 | sizeof(InterestWithLinkMissingContentType)); |
| 827 | |
| 828 | ndn::Interest i; |
| 829 | BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock)); |
| 830 | BOOST_REQUIRE_THROW(i.getLink(), Link::Error); |
| 831 | } |
| 832 | |
| 833 | BOOST_AUTO_TEST_CASE(LinkObjectNoMetaInfo) |
| 834 | { |
| 835 | Block interestBlock(InterestWithLinkNoMetaInfo, |
| 836 | sizeof(InterestWithLinkNoMetaInfo)); |
| 837 | |
| 838 | ndn::Interest i; |
| 839 | BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock)); |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 840 | BOOST_CHECK_THROW(i.getLink(), tlv::Error); |
| 841 | BOOST_CHECK_THROW(i.getLink(), tlv::Error); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | BOOST_AUTO_TEST_CASE(LinkObjectWrongContentType) |
| 845 | { |
| 846 | Block interestBlock(InterestWithLinkWrongContentType, |
| 847 | sizeof(InterestWithLinkWrongContentType)); |
| 848 | |
| 849 | ndn::Interest i; |
| 850 | BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock)); |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 851 | BOOST_CHECK_THROW(i.getLink(), Link::Error); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | BOOST_AUTO_TEST_CASE(InterestContainingSelectedDelegationButNoLink) |
| 855 | { |
| 856 | Block interestBlock(InterestWithSelectedDelegationButNoLink, |
| 857 | sizeof(InterestWithSelectedDelegationButNoLink)); |
| 858 | |
| 859 | ndn::Interest i; |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 860 | BOOST_CHECK_THROW(i.wireDecode(interestBlock), Interest::Error); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | BOOST_AUTO_TEST_CASE(SelectedDelegationIsNotNonNegativeInteger) |
| 864 | { |
| 865 | Block interestBlock(InterestWithLinkNotNonIntegerSelectedDelegation, |
| 866 | sizeof(InterestWithLinkNotNonIntegerSelectedDelegation)); |
| 867 | |
| 868 | ndn::Interest i; |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 869 | BOOST_CHECK_THROW(i.wireDecode(interestBlock), tlv::Error); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | BOOST_AUTO_TEST_CASE(SelectedDelegationEqualToDelegationCount) |
| 873 | { |
| 874 | Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}}); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 875 | m_keyChain.sign(link1); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 876 | Block wire = link1.wireEncode(); |
| 877 | |
| 878 | Interest a; |
| 879 | a.setName("/Test/Encode/Decode/With/Link"); |
| 880 | a.setChildSelector(1); |
| 881 | a.setNonce(100); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 882 | a.setInterestLifetime(time::seconds(10)); |
| 883 | a.setLink(wire); |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 884 | BOOST_CHECK_THROW(a.setSelectedDelegation(3), Interest::Error); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | BOOST_AUTO_TEST_CASE(SelectedDelegationGreaterThanDelegationCount) |
| 888 | { |
| 889 | Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}}); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 890 | m_keyChain.sign(link1); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 891 | Block wire = link1.wireEncode(); |
| 892 | |
| 893 | Interest a; |
| 894 | a.setName("/Test/Encode/Decode/With/Link"); |
| 895 | a.setChildSelector(1); |
| 896 | a.setNonce(100); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 897 | a.setInterestLifetime(time::seconds(10)); |
| 898 | a.setLink(wire); |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 899 | BOOST_CHECK_THROW(a.setSelectedDelegation(4), Interest::Error); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 900 | } |
| 901 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 902 | BOOST_AUTO_TEST_CASE(Decode) |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 903 | { |
| 904 | Block interestBlock(Interest1, sizeof(Interest1)); |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 905 | |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 906 | ndn::Interest i; |
Alexander Afanasyev | 049f8f7 | 2013-12-26 19:07:15 -0800 | [diff] [blame] | 907 | BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock)); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 908 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 909 | BOOST_CHECK_EQUAL(i.getName().toUri(), "/local/ndn/prefix"); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 910 | BOOST_CHECK_EQUAL(i.getInterestLifetime(), time::milliseconds(1000)); |
| 911 | BOOST_CHECK_EQUAL(i.getMinSuffixComponents(), 1); |
| 912 | BOOST_CHECK_EQUAL(i.getMaxSuffixComponents(), 1); |
| 913 | BOOST_CHECK_EQUAL(i.getPublisherPublicKeyLocator().getType(), |
| 914 | static_cast<uint32_t>(KeyLocator::KeyLocator_Name)); |
| 915 | BOOST_CHECK_EQUAL(i.getPublisherPublicKeyLocator().getName(), "ndn:/test/key/locator"); |
| 916 | BOOST_CHECK_EQUAL(i.getChildSelector(), 1); |
| 917 | BOOST_CHECK_EQUAL(i.getMustBeFresh(), false); |
| 918 | BOOST_CHECK_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy"); |
| 919 | BOOST_CHECK_EQUAL(i.getNonce(), 1U); |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 920 | BOOST_CHECK_EQUAL(i.hasLink(), false); |
| 921 | BOOST_CHECK_EQUAL(i.hasSelectedDelegation(), false); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 922 | } |
| 923 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 924 | BOOST_AUTO_TEST_CASE(DecodeFromStream) |
Alexander Afanasyev | 6835ad8 | 2014-02-12 10:07:20 -0800 | [diff] [blame] | 925 | { |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 926 | boost::iostreams::stream<boost::iostreams::array_source> is( |
| 927 | reinterpret_cast<const char *>(Interest1), sizeof(Interest1)); |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 928 | |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 929 | Block interestBlock = Block::fromStream(is); |
Alexander Afanasyev | 6835ad8 | 2014-02-12 10:07:20 -0800 | [diff] [blame] | 930 | |
| 931 | ndn::Interest i; |
| 932 | BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock)); |
| 933 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 934 | BOOST_CHECK_EQUAL(i.getName().toUri(), "/local/ndn/prefix"); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 935 | BOOST_CHECK_EQUAL(i.getInterestLifetime(), time::milliseconds(1000)); |
| 936 | BOOST_CHECK_EQUAL(i.getMinSuffixComponents(), 1); |
| 937 | BOOST_CHECK_EQUAL(i.getMaxSuffixComponents(), 1); |
| 938 | BOOST_CHECK_EQUAL(i.getChildSelector(), 1); |
| 939 | BOOST_CHECK_EQUAL(i.getMustBeFresh(), false); |
| 940 | BOOST_CHECK_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy"); |
| 941 | BOOST_CHECK_EQUAL(i.getNonce(), 1U); |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 942 | BOOST_CHECK_EQUAL(i.hasLink(), false); |
| 943 | BOOST_CHECK_EQUAL(i.hasSelectedDelegation(), false); |
Alexander Afanasyev | 6835ad8 | 2014-02-12 10:07:20 -0800 | [diff] [blame] | 944 | } |
| 945 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 946 | BOOST_AUTO_TEST_CASE(Encode) |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 947 | { |
| 948 | ndn::Interest i(ndn::Name("/local/ndn/prefix")); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 949 | i.setInterestLifetime(time::milliseconds(1000)); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 950 | i.setMinSuffixComponents(1); |
| 951 | i.setMaxSuffixComponents(1); |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 952 | i.setPublisherPublicKeyLocator(KeyLocator("ndn:/test/key/locator")); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 953 | i.setChildSelector(1); |
| 954 | i.setMustBeFresh(false); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 955 | Exclude exclude; |
| 956 | exclude |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 957 | .excludeOne(name::Component("alex")) |
| 958 | .excludeRange(name::Component("xxxx"), name::Component("yyyy")); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 959 | i.setExclude(exclude); |
Alexander Afanasyev | 840139f | 2013-12-28 15:02:50 -0800 | [diff] [blame] | 960 | i.setNonce(1); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 961 | |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 962 | BOOST_CHECK_EQUAL(i.hasWire(), false); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 963 | const Block &wire = i.wireEncode(); |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 964 | BOOST_CHECK_EQUAL(i.hasWire(), true); |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 965 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 966 | BOOST_CHECK_EQUAL_COLLECTIONS(Interest1, Interest1 + sizeof(Interest1), |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 967 | wire.begin(), wire.end()); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 968 | |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 969 | const uint8_t* originalWire = wire.wire(); |
| 970 | i.setNonce(2); |
| 971 | BOOST_CHECK_EQUAL(i.hasWire(), true); |
| 972 | BOOST_CHECK_EQUAL(originalWire, i.wireEncode().wire()); |
| 973 | BOOST_CHECK_EQUAL(i.hasWire(), true); |
| 974 | |
| 975 | BOOST_CHECK_EQUAL_COLLECTIONS(Interest2, Interest2 + sizeof(Interest2), |
| 976 | wire.begin(), wire.end()); |
Alexander Afanasyev | a0c5f83 | 2014-06-19 13:27:56 -0700 | [diff] [blame] | 977 | |
| 978 | std::ostringstream strStream; |
| 979 | BOOST_CHECK_NO_THROW(strStream << i); |
| 980 | |
| 981 | BOOST_CHECK_EQUAL(strStream.str(), |
| 982 | "/local/ndn/prefix?" |
| 983 | "ndn.MinSuffixComponents=1&ndn.MaxSuffixComponents=1&" |
Alexander Afanasyev | 117f5ef | 2015-06-03 15:07:24 -0700 | [diff] [blame] | 984 | "ndn.ChildSelector=1&" |
Alexander Afanasyev | a0c5f83 | 2014-06-19 13:27:56 -0700 | [diff] [blame] | 985 | "ndn.InterestLifetime=1000&" |
| 986 | "ndn.Nonce=2&ndn.Exclude=alex,xxxx,*,yyyy"); |
Alexander Afanasyev | c393217 | 2014-07-10 18:53:56 -0700 | [diff] [blame] | 987 | |
| 988 | i.refreshNonce(); |
| 989 | BOOST_CHECK_EQUAL(i.hasWire(), true); |
| 990 | BOOST_CHECK_EQUAL(originalWire, i.wireEncode().wire()); |
| 991 | BOOST_CHECK_NE(i.getNonce(), 2); |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 992 | } |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 993 | |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 994 | BOOST_AUTO_TEST_CASE(DecodeEncode) // this test case to ensure that wireDecode resets all the fields |
| 995 | { |
| 996 | Interest i1; |
| 997 | i1.setName("/test"); |
| 998 | i1.setMinSuffixComponents(100); |
| 999 | i1.setNonce(10); |
| 1000 | i1.setInterestLifetime(time::seconds(10)); |
| 1001 | i1.setLink(Block(LINK, sizeof(LINK))); |
| 1002 | i1.setSelectedDelegation(0); |
| 1003 | |
| 1004 | Interest i2(i1.wireEncode()); |
| 1005 | |
| 1006 | BOOST_CHECK_EQUAL(i2.getName().toUri(), "/test"); |
| 1007 | BOOST_CHECK_EQUAL(i2.getInterestLifetime(), time::seconds(10)); |
| 1008 | BOOST_CHECK_EQUAL(i2.getMinSuffixComponents(), 100); |
| 1009 | BOOST_CHECK_EQUAL(i2.getNonce(), 10); |
| 1010 | BOOST_CHECK_EQUAL(i2.hasLink(), true); |
| 1011 | BOOST_CHECK_EQUAL(i2.hasSelectedDelegation(), true); |
| 1012 | |
| 1013 | i2.wireDecode(Interest().wireEncode()); |
| 1014 | |
| 1015 | BOOST_CHECK_EQUAL(i2.getName().toUri(), "/"); |
| 1016 | BOOST_CHECK_EQUAL(i2.getInterestLifetime(), DEFAULT_INTEREST_LIFETIME); |
| 1017 | BOOST_CHECK_EQUAL(i2.getMinSuffixComponents(), -1); |
| 1018 | BOOST_WARN_NE(i2.getNonce(), 10); |
| 1019 | BOOST_CHECK_EQUAL(i2.hasLink(), false); |
| 1020 | BOOST_CHECK_EQUAL(i2.hasSelectedDelegation(), false); |
| 1021 | } |
| 1022 | |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1023 | BOOST_AUTO_TEST_CASE(MatchesData) |
| 1024 | { |
| 1025 | Interest interest; |
| 1026 | interest.setName("ndn:/A") |
| 1027 | .setMinSuffixComponents(2) |
| 1028 | .setMaxSuffixComponents(2) |
| 1029 | .setPublisherPublicKeyLocator(KeyLocator("ndn:/B")) |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 1030 | .setExclude(Exclude().excludeAfter(name::Component("J"))); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1031 | |
| 1032 | Data data("ndn:/A/D"); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 1033 | SignatureSha256WithRsa signature(KeyLocator("ndn:/B")); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1034 | data.setSignature(signature); |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1035 | data.wireEncode(); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1036 | BOOST_CHECK_EQUAL(interest.matchesData(data), true); |
| 1037 | |
| 1038 | Data data1 = data; |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1039 | data1.setName("ndn:/A"); // violates MinSuffixComponents |
| 1040 | data1.wireEncode(); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1041 | BOOST_CHECK_EQUAL(interest.matchesData(data1), false); |
| 1042 | |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 1043 | Interest interest1 = interest; |
| 1044 | interest1.setMinSuffixComponents(1); |
| 1045 | BOOST_CHECK_EQUAL(interest1.matchesData(data1), true); |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1046 | |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1047 | Data data2 = data; |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1048 | data2.setName("ndn:/A/E/F"); // violates MaxSuffixComponents |
| 1049 | data2.wireEncode(); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1050 | BOOST_CHECK_EQUAL(interest.matchesData(data2), false); |
| 1051 | |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 1052 | Interest interest2 = interest; |
| 1053 | interest2.setMaxSuffixComponents(3); |
| 1054 | BOOST_CHECK_EQUAL(interest2.matchesData(data2), true); |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1055 | |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1056 | Data data3 = data; |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 1057 | SignatureSha256WithRsa signature3(KeyLocator("ndn:/G")); // violates PublisherPublicKeyLocator |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1058 | data3.setSignature(signature3); |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1059 | data3.wireEncode(); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1060 | BOOST_CHECK_EQUAL(interest.matchesData(data3), false); |
| 1061 | |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 1062 | Interest interest3 = interest; |
| 1063 | interest3.setPublisherPublicKeyLocator(KeyLocator("ndn:/G")); |
| 1064 | BOOST_CHECK_EQUAL(interest3.matchesData(data3), true); |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1065 | |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1066 | Data data4 = data; |
Yingdi Yu | bf6a281 | 2014-06-17 15:32:11 -0700 | [diff] [blame] | 1067 | DigestSha256 signature4; // violates PublisherPublicKeyLocator |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1068 | data4.setSignature(signature4); |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1069 | data4.wireEncode(); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1070 | BOOST_CHECK_EQUAL(interest.matchesData(data4), false); |
| 1071 | |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 1072 | Interest interest4 = interest; |
| 1073 | interest4.setPublisherPublicKeyLocator(KeyLocator()); |
| 1074 | BOOST_CHECK_EQUAL(interest4.matchesData(data4), true); |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1075 | |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1076 | Data data5 = data; |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 1077 | data5.setName("ndn:/A/J"); // violates Exclude |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1078 | data5.wireEncode(); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1079 | BOOST_CHECK_EQUAL(interest.matchesData(data5), false); |
| 1080 | |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 1081 | Interest interest5 = interest; |
| 1082 | interest5.setExclude(Exclude().excludeAfter(name::Component("K"))); |
| 1083 | BOOST_CHECK_EQUAL(interest5.matchesData(data5), true); |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1084 | |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1085 | Data data6 = data; |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1086 | data6.setName("ndn:/H/I"); // violates Name |
| 1087 | data6.wireEncode(); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1088 | BOOST_CHECK_EQUAL(interest.matchesData(data6), false); |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1089 | |
| 1090 | Data data7 = data; |
| 1091 | data7.setName("ndn:/A/B"); |
| 1092 | data7.wireEncode(); |
| 1093 | |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 1094 | Interest interest7("/A/B/sha256digest=D548DECEFC4B880720DC9257A8D815E9DF4465E63742EE55C29133055DAA67C2"); |
| 1095 | BOOST_CHECK_EQUAL(interest7.matchesData(data7), true); |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1096 | |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 1097 | Interest interest7b("/A/B/sha256digest=0000000000000000000000000000000000000000000000000000000000000000"); |
| 1098 | BOOST_CHECK_EQUAL(interest7b.matchesData(data7), false); // violates implicit digest |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1099 | } |
| 1100 | |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 1101 | BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(MatchesInterest, 1) |
| 1102 | BOOST_AUTO_TEST_CASE(MatchesInterest) |
| 1103 | { |
| 1104 | Interest interest; |
| 1105 | interest |
| 1106 | .setName("ndn:/A") |
| 1107 | .setMinSuffixComponents(2) |
| 1108 | .setMaxSuffixComponents(2) |
| 1109 | .setPublisherPublicKeyLocator(KeyLocator("ndn:/B")) |
| 1110 | .setExclude(Exclude().excludeAfter(name::Component("J"))) |
| 1111 | .setNonce(10) |
| 1112 | .setInterestLifetime(time::seconds(5)); |
| 1113 | |
| 1114 | Link link("/A/LINK", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}}); |
| 1115 | m_keyChain.sign(link); |
| 1116 | interest.setLink(link.wireEncode()); |
| 1117 | |
| 1118 | Interest other; |
| 1119 | BOOST_CHECK_EQUAL(interest.matchesInterest(other), false); |
| 1120 | |
| 1121 | other.setName(interest.getName()); |
| 1122 | BOOST_CHECK_EQUAL(interest.matchesInterest(other), false); |
| 1123 | |
| 1124 | // TODO: will match until #3162 implemented |
| 1125 | other.setSelectors(interest.getSelectors()); |
| 1126 | BOOST_CHECK_EQUAL(interest.matchesInterest(other), false); |
| 1127 | |
| 1128 | other.setLink(interest.getLink().wireEncode()); |
| 1129 | BOOST_CHECK_EQUAL(interest.matchesInterest(other), true); |
| 1130 | |
| 1131 | other.setNonce(200); |
| 1132 | BOOST_CHECK_EQUAL(interest.matchesInterest(other), true); |
| 1133 | |
| 1134 | other.setInterestLifetime(time::hours(5)); |
| 1135 | BOOST_CHECK_EQUAL(interest.matchesInterest(other), true); |
| 1136 | |
| 1137 | other.setSelectedDelegation(0); |
| 1138 | BOOST_CHECK_EQUAL(interest.matchesInterest(other), true); |
| 1139 | } |
| 1140 | |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 1141 | BOOST_AUTO_TEST_CASE(InterestFilterMatching) |
| 1142 | { |
| 1143 | BOOST_CHECK_EQUAL(InterestFilter("/a").doesMatch("/a/b"), true); |
| 1144 | BOOST_CHECK_EQUAL(InterestFilter("/a/b").doesMatch("/a/b"), true); |
| 1145 | BOOST_CHECK_EQUAL(InterestFilter("/a/b/c").doesMatch("/a/b"), false); |
| 1146 | |
| 1147 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b"), true); |
| 1148 | BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b"), false); |
| 1149 | |
| 1150 | BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b/c/b"), false); |
| 1151 | BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<>*<b>").doesMatch("/a/b/c/b"), true); |
| 1152 | |
| 1153 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b/c/d"), false); |
| 1154 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b/c/d"), true); |
| 1155 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b"), true); |
| 1156 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b"), false); |
| 1157 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b/c"), true); |
| 1158 | } |
| 1159 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 1160 | BOOST_AUTO_TEST_SUITE_END() // TestInterest |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 1161 | |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 1162 | } // namespace tests |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 1163 | } // namespace ndn |