blob: 42be67555511eae5df20b8870fe63ce04a352769 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08002/**
Spyridon Mastorakis429634f2015-02-19 17:35:33 -08003 * Copyright (c) 2013-2015 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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 Afanasyev5fa9e9a2013-12-24 19:45:07 -080020 */
21
Alexander Afanasyev09c613f2014-01-29 00:23:58 -080022#include "interest.hpp"
Junxiao Shi2af905b2014-11-27 13:10:54 -070023#include "interest-filter.hpp"
Junxiao Shiaf8eeea2014-03-31 20:10:56 -070024#include "data.hpp"
25#include "security/signature-sha256-with-rsa.hpp"
Yingdi Yubf6a2812014-06-17 15:32:11 -070026#include "security/digest-sha256.hpp"
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -070027#include "security/key-chain.hpp"
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070028#include "encoding/buffer-stream.hpp"
Junxiao Shiaf8eeea2014-03-31 20:10:56 -070029
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070030#include "boost-test.hpp"
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080031
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080032namespace ndn {
Alexander Afanasyev90164962014-03-06 08:29:59 +000033namespace tests {
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080034
35BOOST_AUTO_TEST_SUITE(TestInterest)
36
37const uint8_t Interest1[] = {
Alexander Afanasyeve881e932014-06-08 14:47:03 +030038 0x05, 0x5c, // NDN Interest
Alexander Afanasyev4b456282014-02-13 00:34:34 -080039 0x07, 0x14, // Name
40 0x08, 0x5, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080041 0x6c, 0x6f, 0x63, 0x61, 0x6c,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080042 0x08, 0x3, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080043 0x6e, 0x64, 0x6e,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080044 0x08, 0x6, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080045 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
Junxiao Shib332e782014-03-31 14:23:46 -070046 0x09, 0x37, // Selectors
Alexander Afanasyev4b456282014-02-13 00:34:34 -080047 0x0d, 0x1, 0x1, // MinSuffix
48 0x0e, 0x1, 0x1, // MaxSuffix
Junxiao Shib332e782014-03-31 14:23:46 -070049 0x1c, 0x16, // KeyLocator
50 0x07, 0x14, // Name
51 0x08, 0x04,
52 0x74, 0x65, 0x73, 0x74,
53 0x08, 0x03,
54 0x6b, 0x65, 0x79,
55 0x08, 0x07,
56 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080057 0x10, 0x14, // Exclude
58 0x08, 0x4, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080059 0x61, 0x6c, 0x65, 0x78,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080060 0x08, 0x4, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080061 0x78, 0x78, 0x78, 0x78,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080062 0x13, 0x0, // Any
63 0x08, 0x4, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080064 0x79, 0x79, 0x79, 0x79,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080065 0x11, 0x1, // ChildSelector
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080066 0x1,
Alexander Afanasyeve881e932014-06-08 14:47:03 +030067 0x0a, 0x4, // Nonce
68 0x1, 0x0, 0x0, 0x00,
69 0x0b, 0x1, // Scope
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080070 0x1,
Alexander Afanasyeve881e932014-06-08 14:47:03 +030071 0x0c, // InterestLifetime
72 0x2, 0x3, 0xe8
73};
74
75const uint8_t Interest2[] = {
76 0x05, 0x5c, // NDN Interest
77 0x07, 0x14, // Name
78 0x08, 0x5, // NameComponent
79 0x6c, 0x6f, 0x63, 0x61, 0x6c,
80 0x08, 0x3, // NameComponent
81 0x6e, 0x64, 0x6e,
82 0x08, 0x6, // NameComponent
83 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
84 0x09, 0x37, // Selectors
85 0x0d, 0x1, 0x1, // MinSuffix
86 0x0e, 0x1, 0x1, // MaxSuffix
87 0x1c, 0x16, // KeyLocator
88 0x07, 0x14, // Name
89 0x08, 0x04,
90 0x74, 0x65, 0x73, 0x74,
91 0x08, 0x03,
92 0x6b, 0x65, 0x79,
93 0x08, 0x07,
94 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
95 0x10, 0x14, // Exclude
96 0x08, 0x4, // NameComponent
97 0x61, 0x6c, 0x65, 0x78,
98 0x08, 0x4, // NameComponent
99 0x78, 0x78, 0x78, 0x78,
100 0x13, 0x0, // Any
101 0x08, 0x4, // NameComponent
102 0x79, 0x79, 0x79, 0x79,
103 0x11, 0x1, // ChildSelector
104 0x1,
105 0x0a, 0x4, // Nonce
106 0x2, 0x0, 0x0, 0x00,
Alexander Afanasyev4b456282014-02-13 00:34:34 -0800107 0x0b, 0x1, // Scope
Alexander Afanasyev636e9f12014-01-07 12:01:03 -0800108 0x1,
Alexander Afanasyev4b456282014-02-13 00:34:34 -0800109 0x0c, // InterestLifetime
Alexander Afanasyev636e9f12014-01-07 12:01:03 -0800110 0x2, 0x3, 0xe8
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800111};
112
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700113const uint8_t InterestWithLink[] = {
114 0x05, 0xfb, // Interest
115 0x07, 0x14, // Name
116 0x08, 0x5, // NameComponent
117 0x6c, 0x6f, 0x63, 0x61, 0x6c,
118 0x08, 0x3, // NameComponent
119 0x6e, 0x64, 0x6e,
120 0x08, 0x6, // NameComponent
121 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
122 0x0a, 0x4, // Nonce
123 0x1, 0x0, 0x0, 0x00,
124 0x06, 0xda, // Data
125 0x07, 0x14, // Name
126 0x08, 0x05,
127 0x6c, 0x6f, 0x63, 0x61, 0x6c,
128 0x08, 0x03,
129 0x6e, 0x64, 0x6e,
130 0x08, 0x06,
131 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
132 0x14, 0x07, // MetaInfo
133 0x18, 0x01, // ContentType
134 0x01,
135 0x19, 0x02, // FreshnessPeriod
136 0x27, 0x10,
137 0x15, 0x1a, // Content
138 0x1f, 0x0c, // LinkDelegation
139 0x1e, 0x01, // LinkPreference
140 0x0a,
141 0x07, 0x07, // Name
142 0x08, 0x05,
143 0x6c, 0x6f, 0x63, 0x61, 0x6c,
144 0x1f, 0x0a, // LinkDelegation
145 0x1e, 0x01, // LinkPreference
146 0x14,
147 0x07, 0x05, // Name
148 0x08, 0x03,
149 0x6e, 0x64, 0x6e,
150 0x16, 0x1b, // SignatureInfo
151 0x1b, 0x01, // SignatureType
152 0x01,
153 0x1c, 0x16, // KeyLocator
154 0x07, 0x14, // Name
155 0x08, 0x04,
156 0x74, 0x65, 0x73, 0x74,
157 0x08, 0x03,
158 0x6b, 0x65, 0x79,
159 0x08, 0x07,
160 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
161 0x17, 0x80, // SignatureValue
162 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
163 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
164 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
165 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
166 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
167 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
168 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
169 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
170 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
171 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
172 0x20, 0x01, // SelectedDelegation
173 0x00
174};
175
176const uint8_t InterestWithLinkMissingContentType[] = {
177 0x05, 0xf8, // Interest
178 0x07, 0x14, // Name
179 0x08, 0x5, // NameComponent
180 0x6c, 0x6f, 0x63, 0x61, 0x6c,
181 0x08, 0x3, // NameComponent
182 0x6e, 0x64, 0x6e,
183 0x08, 0x6, // NameComponent
184 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
185 0x0a, 0x4, // Nonce
186 0x1, 0x0, 0x0, 0x00,
187 0x06, 0xd7, // Data
188 0x07, 0x14, // Name
189 0x08, 0x05,
190 0x6c, 0x6f, 0x63, 0x61, 0x6c,
191 0x08, 0x03,
192 0x6e, 0x64, 0x6e,
193 0x08, 0x06,
194 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
195 0x14, 0x04, // MetaInfo
196 0x19, 0x02, // FreshnessPeriod
197 0x27, 0x10,
198 0x15, 0x1a, // Content
199 0x1f, 0x0c, // LinkDelegation
200 0x1e, 0x01, // LinkPreference
201 0x0a,
202 0x07, 0x07, // Name
203 0x08, 0x05,
204 0x6c, 0x6f, 0x63, 0x61, 0x6c,
205 0x1f, 0x0a, // LinkDelegation
206 0x1e, 0x01, // LinkPreference
207 0x14,
208 0x07, 0x05, // Name
209 0x08, 0x03,
210 0x6e, 0x64, 0x6e,
211 0x16, 0x1b, // SignatureInfo
212 0x1b, 0x01, // SignatureType
213 0x01,
214 0x1c, 0x16, // KeyLocator
215 0x07, 0x14, // Name
216 0x08, 0x04,
217 0x74, 0x65, 0x73, 0x74,
218 0x08, 0x03,
219 0x6b, 0x65, 0x79,
220 0x08, 0x07,
221 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
222 0x17, 0x80, // SignatureValue
223 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
224 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
225 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
226 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
227 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
228 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
229 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
230 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
231 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
232 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
233 0x20, 0x01, // SelectedDelegation
234 0x00
235};
236
237const uint8_t InterestWithLinkNoMetaInfo[] = {
238 0x05, 0xf2, // Interest
239 0x07, 0x14, // Name
240 0x08, 0x5, // NameComponent
241 0x6c, 0x6f, 0x63, 0x61, 0x6c,
242 0x08, 0x3, // NameComponent
243 0x6e, 0x64, 0x6e,
244 0x08, 0x6, // NameComponent
245 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
246 0x0a, 0x4, // Nonce
247 0x1, 0x0, 0x0, 0x00,
248 0x06, 0xd1, // Data
249 0x07, 0x14, // Name
250 0x08, 0x05,
251 0x6c, 0x6f, 0x63, 0x61, 0x6c,
252 0x08, 0x03,
253 0x6e, 0x64, 0x6e,
254 0x08, 0x06,
255 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
256 0x15, 0x1a, // Content
257 0x1f, 0x0c, // LinkDelegation
258 0x1e, 0x01, // LinkPreference
259 0x0a,
260 0x07, 0x07, // Name
261 0x08, 0x05,
262 0x6c, 0x6f, 0x63, 0x61, 0x6c,
263 0x1f, 0x0a, // LinkPreference
264 0x1e, 0x01, // LinkPreference
265 0x14,
266 0x07, 0x05, // Name
267 0x08, 0x03,
268 0x6e, 0x64, 0x6e,
269 0x16, 0x1b, // SignatureInfo
270 0x1b, 0x01, // SignatureType
271 0x01,
272 0x1c, 0x16, // KeyLocator
273 0x07, 0x14, // Name
274 0x08, 0x04,
275 0x74, 0x65, 0x73, 0x74,
276 0x08, 0x03,
277 0x6b, 0x65, 0x79,
278 0x08, 0x07,
279 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
280 0x17, 0x80, // SignatureValue
281 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
282 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
283 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
284 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
285 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
286 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
287 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
288 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
289 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
290 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
291 0x20, 0x01, // SelectedDelegation
292 0x00
293};
294
295const uint8_t InterestWithLinkWrongContentType[] = {
296 0x05, 0xfb, // Interest
297 0x07, 0x14, // Name
298 0x08, 0x5, // NameComponent
299 0x6c, 0x6f, 0x63, 0x61, 0x6c,
300 0x08, 0x3, // NameComponent
301 0x6e, 0x64, 0x6e,
302 0x08, 0x6, // NameComponent
303 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
304 0x0a, 0x4, // Nonce
305 0x1, 0x0, 0x0, 0x00,
306 0x06, 0xda, // Data
307 0x07, 0x14, // Name
308 0x08, 0x05,
309 0x6c, 0x6f, 0x63, 0x61, 0x6c,
310 0x08, 0x03,
311 0x6e, 0x64, 0x6e,
312 0x08, 0x06,
313 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
314 0x14, 0x07, // MetaInfo
315 0x18, 0x01, // ContentType
316 0x00,
317 0x19, 0x02, // FreshnessPeriod
318 0x27, 0x10,
319 0x15, 0x1a, // Content
320 0x1f, 0x0c, // LinkDelegation
321 0x1e, 0x01, // LinkPreference
322 0x0a,
323 0x07, 0x07, // Name
324 0x08, 0x05,
325 0x6c, 0x6f, 0x63, 0x61, 0x6c,
326 0x1f, 0x0a, // LinkDelegation
327 0x1e, 0x01, // LinkPreference
328 0x14,
329 0x07, 0x05, // Name
330 0x08, 0x03,
331 0x6e, 0x64, 0x6e,
332 0x16, 0x1b, // SignatureInfo
333 0x1b, 0x01, // SignatureType
334 0x01,
335 0x1c, 0x16, // KeyLocator
336 0x07, 0x14, // Name
337 0x08, 0x04,
338 0x74, 0x65, 0x73, 0x74,
339 0x08, 0x03,
340 0x6b, 0x65, 0x79,
341 0x08, 0x07,
342 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
343 0x17, 0x80, // SignatureValue
344 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
345 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
346 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
347 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
348 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
349 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
350 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
351 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
352 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
353 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
354 0x20, 0x01, // SelectedDelegation
355 0x00
356};
357
358const uint8_t InterestWithSelectedDelegationButNoLink[] = {
359 0x05, 0x1f, // Interest
360 0x07, 0x14, // Name
361 0x08, 0x5, // NameComponent
362 0x6c, 0x6f, 0x63, 0x61, 0x6c,
363 0x08, 0x3, // NameComponent
364 0x6e, 0x64, 0x6e,
365 0x08, 0x6, // NameComponent
366 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
367 0x0a, 0x4, // Nonce
368 0x1, 0x0, 0x0, 0x00,
369 0x20, 0x01, // SelectedDelegation
370 0x00
371};
372
373const uint8_t InterestWithLinkNotNonIntegerSelectedDelegation[] = {
374 0x05, 0xfb, // Interest
375 0x07, 0x14, // Name
376 0x08, 0x5, // NameComponent
377 0x6c, 0x6f, 0x63, 0x61, 0x6c,
378 0x08, 0x3, // NameComponent
379 0x6e, 0x64, 0x6e,
380 0x08, 0x6, // NameComponent
381 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
382 0x0a, 0x4, // Nonce
383 0x1, 0x0, 0x0, 0x00,
384 0x06, 0xda, // Data
385 0x07, 0x14, // Name
386 0x08, 0x05,
387 0x6c, 0x6f, 0x63, 0x61, 0x6c,
388 0x08, 0x03,
389 0x6e, 0x64, 0x6e,
390 0x08, 0x06,
391 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
392 0x14, 0x07, // MetaInfo
393 0x18, 0x01, // ContentType
394 0x01,
395 0x19, 0x02, // FreshnessPeriod
396 0x27, 0x10,
397 0x15, 0x1a, // Content
398 0x1f, 0x0c, // LinkDelegation
399 0x1e, 0x01, // LinkPreference
400 0x0a,
401 0x07, 0x07, // Name
402 0x08, 0x05,
403 0x6c, 0x6f, 0x63, 0x61, 0x6c,
404 0x1f, 0x0a, // LinkDelegation
405 0x1e, 0x01, // LinkPreference
406 0x14,
407 0x07, 0x05, // Name
408 0x08, 0x03,
409 0x6e, 0x64, 0x6e,
410 0x16, 0x1b, // SignatureInfo
411 0x1b, 0x01, // SignatureType
412 0x01,
413 0x1c, 0x16, // KeyLocator
414 0x07, 0x14, // Name
415 0x08, 0x04,
416 0x74, 0x65, 0x73, 0x74,
417 0x08, 0x03,
418 0x6b, 0x65, 0x79,
419 0x08, 0x07,
420 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
421 0x17, 0x78, // SignatureValue
422 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
423 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
424 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
425 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
426 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
427 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
428 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
429 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
430 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
431 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7,
432 0x20, 0x03, // SelectedDelegation
433 0xAA, 0xAA, 0xAA
434};
435
436const uint8_t InterestWithLinkNonDecreasingOrder[] = {
437 0x05, 0xfb, // Interest
438 0x07, 0x14, // Name
439 0x08, 0x5, // NameComponent
440 0x6c, 0x6f, 0x63, 0x61, 0x6c,
441 0x08, 0x3, // NameComponent
442 0x6e, 0x64, 0x6e,
443 0x08, 0x6, // NameComponent
444 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
445 0x0a, 0x4, // Nonce
446 0x1, 0x0, 0x0, 0x00,
447 0x06, 0xda, // Data
448 0x07, 0x14, // Name
449 0x08, 0x05,
450 0x6c, 0x6f, 0x63, 0x61, 0x6c,
451 0x08, 0x03,
452 0x6e, 0x64, 0x6e,
453 0x08, 0x06,
454 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
455 0x14, 0x07, // MetaInfo
456 0x18, 0x01, // ContentType
457 0x01,
458 0x19, 0x02, // FreshnessPeriod
459 0x27, 0x10,
460 0x15, 0x1a, // Content
461 0x1f, 0x0c, // LinkDelegation
462 0x1e, 0x01, // LinkPreference
463 0x14,
464 0x07, 0x07, // Name
465 0x08, 0x05,
466 0x6c, 0x6f, 0x63, 0x61, 0x6c,
467 0x1f, 0x0a, // LinkDelegation
468 0x1e, 0x01, // LinkPreference
469 0x0a,
470 0x07, 0x05, // Name
471 0x08, 0x03,
472 0x6e, 0x64, 0x6e,
473 0x16, 0x1b, // SignatureInfo
474 0x1b, 0x01, // SignatureType
475 0x01,
476 0x1c, 0x16, // KeyLocator
477 0x07, 0x14, // Name
478 0x08, 0x04,
479 0x74, 0x65, 0x73, 0x74,
480 0x08, 0x03,
481 0x6b, 0x65, 0x79,
482 0x08, 0x07,
483 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
484 0x17, 0x80, // SignatureValue
485 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
486 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
487 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
488 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
489 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
490 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
491 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
492 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
493 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
494 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
495 0x20, 0x01, // SelectedDelegation
496 0x01
497};
498
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800499const uint8_t InterestWithLocalControlHeader[] = {
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300500 0x50, 0x25, 0x51, 0x01, 0x0a,
501 0x05, 0x20, 0x07, 0x14, 0x08, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x08, 0x03, 0x6e, 0x64,
502 0x6e, 0x08, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x09, 0x02, 0x12, 0x00, 0x0a, 0x04,
503 0x01, 0x00, 0x00, 0x00
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800504};
505
506const uint8_t InterestWithoutLocalControlHeader[] = {
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300507 0x05, 0x20, 0x07, 0x14, 0x08, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x08, 0x03, 0x6e, 0x64,
508 0x6e, 0x08, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x09, 0x02, 0x12, 0x00, 0x0a, 0x04,
509 0x01, 0x00, 0x00, 0x00
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800510};
511
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700512BOOST_AUTO_TEST_CASE(InterestEqualityChecks)
513{
514 // Interest ::= INTEREST-TYPE TLV-LENGTH
515 // Name
516 // Selectors?
517 // Nonce
518 // Scope?
519 // InterestLifetime?
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700520 // Link?
521 // SelectedDelegation?
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700522
523 Interest a;
524 Interest b;
525
526 // if nonce is not set, it will be set to a random value
527 a.setNonce(1);
528 b.setNonce(1);
529
530 BOOST_CHECK_EQUAL(a == b, true);
531 BOOST_CHECK_EQUAL(a != b, false);
532
533 // check comparison on Name
534 a.setName("ndn:/A");
535 BOOST_CHECK_EQUAL(a == b, false);
536 BOOST_CHECK_EQUAL(a != b, true);
537
538 b.setName("ndn:/B");
539 BOOST_CHECK_EQUAL(a == b, false);
540 BOOST_CHECK_EQUAL(a != b, true);
541
542 b.setName("ndn:/A");
543 BOOST_CHECK_EQUAL(a == b, true);
544 BOOST_CHECK_EQUAL(a != b, false);
545
546 // check comparison on Selectors
547 a.setChildSelector(1);
548 BOOST_CHECK_EQUAL(a == b, false);
549 BOOST_CHECK_EQUAL(a != b, true);
550
551 b.setChildSelector(1);
552 BOOST_CHECK_EQUAL(a == b, true);
553 BOOST_CHECK_EQUAL(a != b, false);
554
555 // check comparison on Nonce
556 a.setNonce(100);
557 BOOST_CHECK_EQUAL(a == b, false);
558 BOOST_CHECK_EQUAL(a != b, true);
559
560 b.setNonce(100);
561 BOOST_CHECK_EQUAL(a == b, true);
562 BOOST_CHECK_EQUAL(a != b, false);
563
564 // check comparison on Nonce
565 a.setScope(1);
566 BOOST_CHECK_EQUAL(a == b, false);
567 BOOST_CHECK_EQUAL(a != b, true);
568
569 b.setScope(1);
570 BOOST_CHECK_EQUAL(a == b, true);
571 BOOST_CHECK_EQUAL(a != b, false);
572
573 // check comparison on InterestLifetime
574 a.setInterestLifetime(time::seconds(10));
575 BOOST_CHECK_EQUAL(a == b, false);
576 BOOST_CHECK_EQUAL(a != b, true);
577
578 b.setInterestLifetime(time::seconds(10));
579 BOOST_CHECK_EQUAL(a == b, true);
580 BOOST_CHECK_EQUAL(a != b, false);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700581
582 // Link object
583 Link link("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
584 KeyChain keyChain;
585 keyChain.sign(link);
586 Block wire = link.wireEncode();
587
588 a.setLink(wire);
589 BOOST_CHECK_EQUAL(a == b, false);
590 BOOST_CHECK_EQUAL(a != b, true);
591
592 b.setLink(wire);
593 BOOST_CHECK_EQUAL(a == b, true);
594 BOOST_CHECK_EQUAL(a != b, false);
595
596 // Selected Delegation
597 BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false);
598 BOOST_CHECK_EQUAL(b.hasSelectedDelegation(), false);
599
600 a.setSelectedDelegation(Name("test2"));
601 BOOST_CHECK_EQUAL(a == b, false);
602 BOOST_CHECK_EQUAL(a != b, true);
603
604 b.setSelectedDelegation(Name("test2"));
605 BOOST_CHECK_EQUAL(a == b, true);
606 BOOST_CHECK_EQUAL(a != b, false);
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700607}
608
609BOOST_AUTO_TEST_CASE(SelectorsEqualityChecks)
610{
611 // Selectors ::= SELECTORS-TYPE TLV-LENGTH
612 // MinSuffixComponents?
613 // MaxSuffixComponents?
614 // PublisherPublicKeyLocator?
615 // Exclude?
616 // ChildSelector?
617 // MustBeFresh?
618
619 Selectors a;
620 Selectors b;
621 BOOST_CHECK_EQUAL(a == b, true);
622 BOOST_CHECK_EQUAL(a != b, false);
623
624 // MinSuffixComponents
625 a.setMinSuffixComponents(1);
626 BOOST_CHECK_EQUAL(a == b, false);
627 BOOST_CHECK_EQUAL(a != b, true);
628
629 b.setMinSuffixComponents(2);
630 BOOST_CHECK_EQUAL(a == b, false);
631 BOOST_CHECK_EQUAL(a != b, true);
632
633 b.setMinSuffixComponents(1);
634 BOOST_CHECK_EQUAL(a == b, true);
635 BOOST_CHECK_EQUAL(a != b, false);
636
637 // MaxSuffixComponents
638 a.setMaxSuffixComponents(10);
639 BOOST_CHECK_EQUAL(a == b, false);
640 BOOST_CHECK_EQUAL(a != b, true);
641
642 b.setMaxSuffixComponents(10);
643 BOOST_CHECK_EQUAL(a == b, true);
644 BOOST_CHECK_EQUAL(a != b, false);
645
646 // PublisherPublicKeyLocator
647 a.setPublisherPublicKeyLocator(KeyLocator("/key/Locator/name"));
648 BOOST_CHECK_EQUAL(a == b, false);
649 BOOST_CHECK_EQUAL(a != b, true);
650
651 b.setPublisherPublicKeyLocator(KeyLocator("/key/Locator/name"));
652 BOOST_CHECK_EQUAL(a == b, true);
653 BOOST_CHECK_EQUAL(a != b, false);
654
655 // Exclude
656 a.setExclude(Exclude().excludeOne(name::Component("exclude")));
657 BOOST_CHECK_EQUAL(a == b, false);
658 BOOST_CHECK_EQUAL(a != b, true);
659
660 b.setExclude(Exclude().excludeOne(name::Component("exclude")));
661 BOOST_CHECK_EQUAL(a == b, true);
662 BOOST_CHECK_EQUAL(a != b, false);
663
664 // ChildSelector
665 a.setChildSelector(1);
666 BOOST_CHECK_EQUAL(a == b, false);
667 BOOST_CHECK_EQUAL(a != b, true);
668
669 b.setChildSelector(1);
670 BOOST_CHECK_EQUAL(a == b, true);
671 BOOST_CHECK_EQUAL(a != b, false);
672
673 // MustBeFresh
674 a.setMustBeFresh(true);
675 BOOST_CHECK_EQUAL(a == b, false);
676 BOOST_CHECK_EQUAL(a != b, true);
677
678 b.setMustBeFresh(true);
679 BOOST_CHECK_EQUAL(a == b, true);
680 BOOST_CHECK_EQUAL(a != b, false);
681}
682
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700683BOOST_AUTO_TEST_CASE(LinkObject)
684{
685 Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
686 KeyChain keyChain;
687 keyChain.sign(link1);
688 Block wire = link1.wireEncode();
689
690 Interest a;
691 BOOST_REQUIRE_NO_THROW(a.setLink(wire));
692
693 BOOST_REQUIRE_NO_THROW(a.getLink());
694
695 Link link2 = a.getLink();
696 Name name = link2.getName();
697 BOOST_CHECK_EQUAL(Name("test"), name);
698 BOOST_CHECK_EQUAL(a.hasLink(), true);
699 Link::DelegationSet delegations;
700 delegations = link2.getDelegations();
701
702 auto i = delegations.begin();
703 BOOST_CHECK_EQUAL(std::get<0>(*i), 10);
704 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test1"));
705 ++i;
706 BOOST_CHECK_EQUAL(std::get<0>(*i), 20);
707 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test2"));
708 ++i;
709 BOOST_CHECK_EQUAL(std::get<0>(*i), 100);
710 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test3"));
711
712 a.unsetLink();
713 BOOST_CHECK_EQUAL(a.hasLink(), false);
714}
715
716BOOST_AUTO_TEST_CASE(SelectedDelegationChecks)
717{
718 Link link("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
719 KeyChain keyChain;
720 keyChain.sign(link);
721 Block wire = link.wireEncode();
722
723 Interest a;
724 a.setLink(wire);
725 BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false);
726
727 BOOST_REQUIRE_NO_THROW(a.setSelectedDelegation(Name("test2")));
728 BOOST_CHECK_EQUAL(a.getSelectedDelegation(), Name("test2"));
729
730 BOOST_REQUIRE_NO_THROW(a.setSelectedDelegation(uint32_t(2)));
731 BOOST_CHECK_EQUAL(a.getSelectedDelegation(), Name("test3"));
732
733 a.unsetSelectedDelegation();
734 BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false);
735}
736
737BOOST_AUTO_TEST_CASE(EncodeDecodeWithLink)
738{
739 Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
740 KeyChain keyChain;
741 keyChain.sign(link1);
742 Block wire = link1.wireEncode();
743
744 Interest a;
745 a.setName("/Test/Encode/Decode/With/Link");
746 a.setChildSelector(1);
747 a.setNonce(100);
748 a.setScope(1);
749 a.setInterestLifetime(time::seconds(10));
750 a.setLink(wire);
751
752 Block interestBlock = a.wireEncode();
753 Interest b(interestBlock);
754
755 BOOST_CHECK_EQUAL(a == b, true);
756
757 Link link2 = b.getLink();
758 Link::DelegationSet delegations;
759 delegations = link2.getDelegations();
760
761 auto i = delegations.begin();
762 BOOST_CHECK_EQUAL(std::get<0>(*i), 10);
763 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test1"));
764 ++i;
765 BOOST_CHECK_EQUAL(std::get<0>(*i), 20);
766 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test2"));
767 ++i;
768 BOOST_CHECK_EQUAL(std::get<0>(*i), 100);
769 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test3"));
770
771}
772
773BOOST_AUTO_TEST_CASE(DecodeInterestWithLink)
774{
775 Block interestBlock(InterestWithLink, sizeof(InterestWithLink));
776
777 ndn::Interest i;
778 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
779 Link link = i.getLink();
780 BOOST_CHECK_EQUAL(link.getName(), Name("/local/ndn/prefix"));
781 Link::DelegationSet delegations = link.getDelegations();
782
783 auto it = delegations.begin();
784 BOOST_CHECK_EQUAL(std::get<0>(*it), 10);
785 BOOST_CHECK_EQUAL(std::get<1>(*it), Name("local"));
786 ++it;
787 BOOST_CHECK_EQUAL(std::get<0>(*it), 20);
788 BOOST_CHECK_EQUAL(std::get<1>(*it), Name("ndn"));
789
790 BOOST_REQUIRE_NO_THROW(i.getSelectedDelegation());
791 BOOST_CHECK_EQUAL(i.getSelectedDelegation(), Name("local"));
792}
793
794BOOST_AUTO_TEST_CASE(DecodeInterestWithLinkNonDecreasingOrder)
795{
796 Block interestBlock(InterestWithLinkNonDecreasingOrder,
797 sizeof(InterestWithLinkNonDecreasingOrder));
798
799 ndn::Interest i;
800 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
801 BOOST_REQUIRE_NO_THROW(i.getSelectedDelegation());
802 BOOST_CHECK_EQUAL(i.getSelectedDelegation(), Name("ndn"));
803}
804
805BOOST_AUTO_TEST_CASE(LinkObjectMissingContentType)
806{
807 Block interestBlock(InterestWithLinkMissingContentType,
808 sizeof(InterestWithLinkMissingContentType));
809
810 ndn::Interest i;
811 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
812 BOOST_REQUIRE_THROW(i.getLink(), Link::Error);
813}
814
815BOOST_AUTO_TEST_CASE(LinkObjectNoMetaInfo)
816{
817 Block interestBlock(InterestWithLinkNoMetaInfo,
818 sizeof(InterestWithLinkNoMetaInfo));
819
820 ndn::Interest i;
821 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
822 BOOST_REQUIRE_THROW(i.getLink(), Block::Error);
823}
824
825BOOST_AUTO_TEST_CASE(LinkObjectWrongContentType)
826{
827 Block interestBlock(InterestWithLinkWrongContentType,
828 sizeof(InterestWithLinkWrongContentType));
829
830 ndn::Interest i;
831 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
832 BOOST_REQUIRE_THROW(i.getLink(), Link::Error);
833}
834
835BOOST_AUTO_TEST_CASE(InterestContainingSelectedDelegationButNoLink)
836{
837 Block interestBlock(InterestWithSelectedDelegationButNoLink,
838 sizeof(InterestWithSelectedDelegationButNoLink));
839
840 ndn::Interest i;
841 BOOST_REQUIRE_THROW(i.wireDecode(interestBlock), Interest::Error);
842}
843
844BOOST_AUTO_TEST_CASE(SelectedDelegationIsNotNonNegativeInteger)
845{
846 Block interestBlock(InterestWithLinkNotNonIntegerSelectedDelegation,
847 sizeof(InterestWithLinkNotNonIntegerSelectedDelegation));
848
849 ndn::Interest i;
850 BOOST_REQUIRE_THROW(i.wireDecode(interestBlock), tlv::Error);
851}
852
853BOOST_AUTO_TEST_CASE(SelectedDelegationEqualToDelegationCount)
854{
855 Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
856 KeyChain keyChain;
857 keyChain.sign(link1);
858 Block wire = link1.wireEncode();
859
860 Interest a;
861 a.setName("/Test/Encode/Decode/With/Link");
862 a.setChildSelector(1);
863 a.setNonce(100);
864 a.setScope(1);
865 a.setInterestLifetime(time::seconds(10));
866 a.setLink(wire);
867 BOOST_REQUIRE_THROW(a.setSelectedDelegation(3), Interest::Error);
868}
869
870BOOST_AUTO_TEST_CASE(SelectedDelegationGreaterThanDelegationCount)
871{
872 Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
873 KeyChain keyChain;
874 keyChain.sign(link1);
875 Block wire = link1.wireEncode();
876
877 Interest a;
878 a.setName("/Test/Encode/Decode/With/Link");
879 a.setChildSelector(1);
880 a.setNonce(100);
881 a.setScope(1);
882 a.setInterestLifetime(time::seconds(10));
883 a.setLink(wire);
884 BOOST_REQUIRE_THROW(a.setSelectedDelegation(4), Interest::Error);
885}
886
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700887BOOST_AUTO_TEST_CASE(Decode)
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800888{
889 Block interestBlock(Interest1, sizeof(Interest1));
Alexander Afanasyev636e9f12014-01-07 12:01:03 -0800890
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800891 ndn::Interest i;
Alexander Afanasyev049f8f72013-12-26 19:07:15 -0800892 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800893
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700894 BOOST_CHECK_EQUAL(i.getName().toUri(), "/local/ndn/prefix");
895 BOOST_CHECK_EQUAL(i.getScope(), 1);
896 BOOST_CHECK_EQUAL(i.getInterestLifetime(), time::milliseconds(1000));
897 BOOST_CHECK_EQUAL(i.getMinSuffixComponents(), 1);
898 BOOST_CHECK_EQUAL(i.getMaxSuffixComponents(), 1);
899 BOOST_CHECK_EQUAL(i.getPublisherPublicKeyLocator().getType(),
900 static_cast<uint32_t>(KeyLocator::KeyLocator_Name));
901 BOOST_CHECK_EQUAL(i.getPublisherPublicKeyLocator().getName(), "ndn:/test/key/locator");
902 BOOST_CHECK_EQUAL(i.getChildSelector(), 1);
903 BOOST_CHECK_EQUAL(i.getMustBeFresh(), false);
904 BOOST_CHECK_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy");
905 BOOST_CHECK_EQUAL(i.getNonce(), 1U);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800906}
907
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700908BOOST_AUTO_TEST_CASE(DecodeFromStream)
Alexander Afanasyev6835ad82014-02-12 10:07:20 -0800909{
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -0700910 boost::iostreams::stream<boost::iostreams::array_source> is(
911 reinterpret_cast<const char *>(Interest1), sizeof(Interest1));
Junxiao Shib332e782014-03-31 14:23:46 -0700912
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700913 Block interestBlock = Block::fromStream(is);
Alexander Afanasyev6835ad82014-02-12 10:07:20 -0800914
915 ndn::Interest i;
916 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
917
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700918 BOOST_CHECK_EQUAL(i.getName().toUri(), "/local/ndn/prefix");
919 BOOST_CHECK_EQUAL(i.getScope(), 1);
920 BOOST_CHECK_EQUAL(i.getInterestLifetime(), time::milliseconds(1000));
921 BOOST_CHECK_EQUAL(i.getMinSuffixComponents(), 1);
922 BOOST_CHECK_EQUAL(i.getMaxSuffixComponents(), 1);
923 BOOST_CHECK_EQUAL(i.getChildSelector(), 1);
924 BOOST_CHECK_EQUAL(i.getMustBeFresh(), false);
925 BOOST_CHECK_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy");
926 BOOST_CHECK_EQUAL(i.getNonce(), 1U);
Alexander Afanasyev6835ad82014-02-12 10:07:20 -0800927}
928
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700929BOOST_AUTO_TEST_CASE(Encode)
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800930{
931 ndn::Interest i(ndn::Name("/local/ndn/prefix"));
932 i.setScope(1);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700933 i.setInterestLifetime(time::milliseconds(1000));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800934 i.setMinSuffixComponents(1);
935 i.setMaxSuffixComponents(1);
Junxiao Shib332e782014-03-31 14:23:46 -0700936 i.setPublisherPublicKeyLocator(KeyLocator("ndn:/test/key/locator"));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800937 i.setChildSelector(1);
938 i.setMustBeFresh(false);
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800939 Exclude exclude;
940 exclude
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -0800941 .excludeOne(name::Component("alex"))
942 .excludeRange(name::Component("xxxx"), name::Component("yyyy"));
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800943 i.setExclude(exclude);
Alexander Afanasyev840139f2013-12-28 15:02:50 -0800944 i.setNonce(1);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800945
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300946 BOOST_CHECK_EQUAL(i.hasWire(), false);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800947 const Block &wire = i.wireEncode();
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300948 BOOST_CHECK_EQUAL(i.hasWire(), true);
Alexander Afanasyev809805d2014-02-17 17:20:33 -0800949
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700950 BOOST_CHECK_EQUAL_COLLECTIONS(Interest1, Interest1 + sizeof(Interest1),
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800951 wire.begin(), wire.end());
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800952
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300953 const uint8_t* originalWire = wire.wire();
954 i.setNonce(2);
955 BOOST_CHECK_EQUAL(i.hasWire(), true);
956 BOOST_CHECK_EQUAL(originalWire, i.wireEncode().wire());
957 BOOST_CHECK_EQUAL(i.hasWire(), true);
958
959 BOOST_CHECK_EQUAL_COLLECTIONS(Interest2, Interest2 + sizeof(Interest2),
960 wire.begin(), wire.end());
Alexander Afanasyeva0c5f832014-06-19 13:27:56 -0700961
962 std::ostringstream strStream;
963 BOOST_CHECK_NO_THROW(strStream << i);
964
965 BOOST_CHECK_EQUAL(strStream.str(),
966 "/local/ndn/prefix?"
967 "ndn.MinSuffixComponents=1&ndn.MaxSuffixComponents=1&"
968 "ndn.ChildSelector=1&ndn.Scope=1&"
969 "ndn.InterestLifetime=1000&"
970 "ndn.Nonce=2&ndn.Exclude=alex,xxxx,*,yyyy");
Alexander Afanasyevc3932172014-07-10 18:53:56 -0700971
972 i.refreshNonce();
973 BOOST_CHECK_EQUAL(i.hasWire(), true);
974 BOOST_CHECK_EQUAL(originalWire, i.wireEncode().wire());
975 BOOST_CHECK_NE(i.getNonce(), 2);
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300976}
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800977
978BOOST_AUTO_TEST_CASE(EncodeWithLocalHeader)
979{
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800980 ndn::Interest interest(ndn::Name("/local/ndn/prefix"));
981 interest.setMustBeFresh(true);
982 interest.setIncomingFaceId(10);
983 interest.setNonce(1);
Junxiao Shib332e782014-03-31 14:23:46 -0700984
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800985 BOOST_CHECK(!interest.hasWire());
Junxiao Shib332e782014-03-31 14:23:46 -0700986
Jiewen Tanc759a202015-01-29 23:31:09 -0800987 Block headerBlock =
988 interest.getLocalControlHeader()
989 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
990 nfd::LocalControlHeader::ENCODE_NEXT_HOP);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800991
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800992 BOOST_CHECK(interest.hasWire());
993 BOOST_CHECK(headerBlock.hasWire());
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800994
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800995 BOOST_CHECK_NE(headerBlock.wire(), interest.wireEncode().wire());
996 BOOST_CHECK_NE(headerBlock.size(), interest.wireEncode().size());
997 BOOST_CHECK_EQUAL(headerBlock.size(), 5);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800998
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800999 BOOST_CHECK_EQUAL_COLLECTIONS(InterestWithLocalControlHeader,
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001000 InterestWithLocalControlHeader + 5,
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001001 headerBlock.begin(), headerBlock.end());
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001002
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001003 interest.setNonce(1000);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001004
Jiewen Tanc759a202015-01-29 23:31:09 -08001005 Block updatedHeaderBlock =
1006 interest.getLocalControlHeader()
1007 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
1008 nfd::LocalControlHeader::ENCODE_NEXT_HOP);
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001009 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 5);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001010
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001011 // only length should have changed
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001012 BOOST_CHECK_EQUAL_COLLECTIONS(updatedHeaderBlock.begin() + 2, updatedHeaderBlock.end(),
1013 headerBlock.begin() + 2, headerBlock.end());
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001014
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001015 // updating IncomingFaceId that keeps the length
1016 interest.setIncomingFaceId(100);
Jiewen Tanc759a202015-01-29 23:31:09 -08001017 updatedHeaderBlock =
1018 interest.getLocalControlHeader()
1019 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
1020 nfd::LocalControlHeader::ENCODE_NEXT_HOP);
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001021 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 5);
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001022 BOOST_CHECK_NE(*(updatedHeaderBlock.begin() + 4), *(headerBlock.begin() + 4));
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001023
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001024 // updating IncomingFaceId that increases the length by 2
1025 interest.setIncomingFaceId(1000);
Jiewen Tanc759a202015-01-29 23:31:09 -08001026 updatedHeaderBlock =
1027 interest.getLocalControlHeader()
1028 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
1029 nfd::LocalControlHeader::ENCODE_NEXT_HOP);
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001030 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 6);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001031
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001032 // adding NextHopId
1033 interest.setNextHopFaceId(1);
Jiewen Tanc759a202015-01-29 23:31:09 -08001034 updatedHeaderBlock =
1035 interest.getLocalControlHeader()
1036 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
1037 nfd::LocalControlHeader::ENCODE_NEXT_HOP);
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001038 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 9);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001039
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001040 // masking IncomingFaceId
Jiewen Tanc759a202015-01-29 23:31:09 -08001041 updatedHeaderBlock = interest.getLocalControlHeader()
1042 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_NEXT_HOP);
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001043 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 5);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001044
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001045 // masking NextHopId
Jiewen Tanc759a202015-01-29 23:31:09 -08001046 updatedHeaderBlock =
1047 interest.getLocalControlHeader()
1048 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID);
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001049 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 6);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001050
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001051 // masking everything
Jiewen Tanc759a202015-01-29 23:31:09 -08001052 BOOST_CHECK_THROW(interest.getLocalControlHeader()
1053 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_NONE),
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001054 nfd::LocalControlHeader::Error);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001055}
1056
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001057
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001058BOOST_AUTO_TEST_CASE(DecodeWithLocalHeader)
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001059{
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001060 Block wireBlock(InterestWithLocalControlHeader, sizeof(InterestWithLocalControlHeader));
1061 const Block& payload = nfd::LocalControlHeader::getPayload(wireBlock);
1062 BOOST_REQUIRE_NE(&payload, &wireBlock);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001063
Steve DiBenedetto54ce6682014-07-22 13:22:57 -06001064 BOOST_CHECK_EQUAL(payload.type(), static_cast<uint32_t>(tlv::Interest));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001065 BOOST_CHECK_EQUAL(wireBlock.type(), static_cast<uint32_t>(tlv::nfd::LocalControlHeader));
Junxiao Shib332e782014-03-31 14:23:46 -07001066
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001067 Interest interest(payload);
1068 BOOST_CHECK(!interest.getLocalControlHeader().hasIncomingFaceId());
1069 BOOST_CHECK(!interest.getLocalControlHeader().hasNextHopFaceId());
1070
1071 BOOST_REQUIRE_NO_THROW(interest.getLocalControlHeader().wireDecode(wireBlock));
1072
Jiewen Tanc759a202015-01-29 23:31:09 -08001073 BOOST_CHECK_EQUAL(
1074 interest.getLocalControlHeader()
1075 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
1076 nfd::LocalControlHeader::ENCODE_NEXT_HOP).size(),
1077 5);
Junxiao Shib332e782014-03-31 14:23:46 -07001078
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001079 BOOST_CHECK_EQUAL(interest.getIncomingFaceId(), 10);
1080 BOOST_CHECK(!interest.getLocalControlHeader().hasNextHopFaceId());
1081
Jiewen Tanc759a202015-01-29 23:31:09 -08001082 BOOST_CHECK_THROW(interest.getLocalControlHeader()
1083 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_NONE),
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001084 nfd::LocalControlHeader::Error);
1085
Jiewen Tanc759a202015-01-29 23:31:09 -08001086 BOOST_CHECK_THROW(interest.getLocalControlHeader()
1087 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_NEXT_HOP),
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001088 nfd::LocalControlHeader::Error);
1089
Jiewen Tanc759a202015-01-29 23:31:09 -08001090 BOOST_CHECK_NO_THROW(
1091 interest.getLocalControlHeader()
1092 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID));
1093 BOOST_CHECK_NO_THROW(
1094 interest.getLocalControlHeader()
1095 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
1096 nfd::LocalControlHeader::ENCODE_NEXT_HOP));
Junxiao Shib332e782014-03-31 14:23:46 -07001097
Jiewen Tanc759a202015-01-29 23:31:09 -08001098 BOOST_CHECK_NE(
1099 (void*)interest.getLocalControlHeader()
1100 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
1101 nfd::LocalControlHeader::ENCODE_NEXT_HOP)
1102 .wire(),
1103 (void*)wireBlock.wire());
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001104
Jiewen Tanc759a202015-01-29 23:31:09 -08001105 BOOST_CHECK_EQUAL(interest.getLocalControlHeader()
1106 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
1107 nfd::LocalControlHeader::ENCODE_NEXT_HOP).size(),
1108 5);
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001109}
1110
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001111BOOST_AUTO_TEST_CASE(DecodeWithoutLocalHeader)
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001112{
1113 Block wireBlock(InterestWithoutLocalControlHeader, sizeof(InterestWithoutLocalControlHeader));
1114 const Block& payload = nfd::LocalControlHeader::getPayload(wireBlock);
1115 BOOST_CHECK_EQUAL(&payload, &wireBlock);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001116}
1117
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001118BOOST_AUTO_TEST_CASE(MatchesData)
1119{
1120 Interest interest;
1121 interest.setName("ndn:/A")
1122 .setMinSuffixComponents(2)
1123 .setMaxSuffixComponents(2)
1124 .setPublisherPublicKeyLocator(KeyLocator("ndn:/B"))
1125 .setExclude(Exclude().excludeBefore(name::Component("C")));
1126
1127 Data data("ndn:/A/D");
Yingdi Yu4a557052014-07-09 16:40:37 -07001128 SignatureSha256WithRsa signature(KeyLocator("ndn:/B"));
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001129 data.setSignature(signature);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001130 data.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001131 BOOST_CHECK_EQUAL(interest.matchesData(data), true);
1132
1133 Data data1 = data;
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001134 data1.setName("ndn:/A"); // violates MinSuffixComponents
1135 data1.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001136 BOOST_CHECK_EQUAL(interest.matchesData(data1), false);
1137
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001138 interest.setMinSuffixComponents(1);
1139 BOOST_CHECK_EQUAL(interest.matchesData(data1), true);
1140 interest.setMinSuffixComponents(2);
1141
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001142 Data data2 = data;
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001143 data2.setName("ndn:/A/E/F"); // violates MaxSuffixComponents
1144 data2.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001145 BOOST_CHECK_EQUAL(interest.matchesData(data2), false);
1146
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001147 interest.setMaxSuffixComponents(3);
1148 BOOST_CHECK_EQUAL(interest.matchesData(data2), true);
1149 interest.setMaxSuffixComponents(2);
1150
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001151 Data data3 = data;
Yingdi Yu4a557052014-07-09 16:40:37 -07001152 SignatureSha256WithRsa signature3(KeyLocator("ndn:/G")); // violates PublisherPublicKeyLocator
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001153 data3.setSignature(signature3);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001154 data3.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001155 BOOST_CHECK_EQUAL(interest.matchesData(data3), false);
1156
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001157 interest.setPublisherPublicKeyLocator(KeyLocator("ndn:/G"));
1158 BOOST_CHECK_EQUAL(interest.matchesData(data3), true);
1159 interest.setPublisherPublicKeyLocator(KeyLocator("ndn:/B"));
1160
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001161 Data data4 = data;
Yingdi Yubf6a2812014-06-17 15:32:11 -07001162 DigestSha256 signature4; // violates PublisherPublicKeyLocator
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001163 data4.setSignature(signature4);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001164 data4.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001165 BOOST_CHECK_EQUAL(interest.matchesData(data4), false);
1166
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001167 interest.setPublisherPublicKeyLocator(KeyLocator());
1168 BOOST_CHECK_EQUAL(interest.matchesData(data4), true);
1169 interest.setPublisherPublicKeyLocator(KeyLocator("ndn:/B"));
1170
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001171 Data data5 = data;
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001172 data5.setName("ndn:/A/C"); // violates Exclude
1173 data5.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001174 BOOST_CHECK_EQUAL(interest.matchesData(data5), false);
1175
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001176 interest.setExclude(Exclude().excludeBefore(name::Component("A")));
1177 BOOST_CHECK_EQUAL(interest.matchesData(data5), true);
1178 interest.setExclude(Exclude().excludeBefore(name::Component("C")));
1179
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001180 Data data6 = data;
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001181 data6.setName("ndn:/H/I"); // violates Name
1182 data6.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001183 BOOST_CHECK_EQUAL(interest.matchesData(data6), false);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001184
1185 Data data7 = data;
1186 data7.setName("ndn:/A/B");
1187 data7.wireEncode();
1188
1189 interest = Interest()
Alexander Afanasyev56860f52014-11-07 11:51:17 -08001190 .setName("/A/B/sha256digest=D548DECEFC4B880720DC9257A8D815E9DF4465E63742EE55C29133055DAA67C2");
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001191 BOOST_CHECK_EQUAL(interest.matchesData(data7), true);
1192
1193 interest = Interest()
1194 .setName("/A/B/%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00"
1195 "%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00");
1196 BOOST_CHECK_EQUAL(interest.matchesData(data7), false); // violates implicit digest
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001197}
1198
Alexander Afanasyev90164962014-03-06 08:29:59 +00001199BOOST_AUTO_TEST_CASE(InterestFilterMatching)
1200{
1201 BOOST_CHECK_EQUAL(InterestFilter("/a").doesMatch("/a/b"), true);
1202 BOOST_CHECK_EQUAL(InterestFilter("/a/b").doesMatch("/a/b"), true);
1203 BOOST_CHECK_EQUAL(InterestFilter("/a/b/c").doesMatch("/a/b"), false);
1204
1205 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b"), true);
1206 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b"), false);
1207
1208 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b/c/b"), false);
1209 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<>*<b>").doesMatch("/a/b/c/b"), true);
1210
1211 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b/c/d"), false);
1212 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b/c/d"), true);
1213 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b"), true);
1214 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b"), false);
1215 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b/c"), true);
1216}
1217
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001218BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -08001219
Alexander Afanasyev90164962014-03-06 08:29:59 +00001220} // namespace tests
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -08001221} // namespace ndn