blob: 295af500e475df5a03a2bfea940279e1f14678b2 [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/**
Alexander Afanasyev1013fd02017-01-03 13:19:03 -08003 * Copyright (c) 2013-2017 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"
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070027#include "encoding/buffer-stream.hpp"
Junxiao Shiaf8eeea2014-03-31 20:10:56 -070028
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070029#include "boost-test.hpp"
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070030#include "identity-management-fixture.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
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070035BOOST_FIXTURE_TEST_SUITE(TestInterest, IdentityManagementFixture)
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080036
37const uint8_t Interest1[] = {
Alexander Afanasyev117f5ef2015-06-03 15:07:24 -070038 0x05, 0x59, // 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,
Alexander Afanasyeve881e932014-06-08 14:47:03 +030069 0x0c, // InterestLifetime
70 0x2, 0x3, 0xe8
71};
72
73const uint8_t Interest2[] = {
Alexander Afanasyev117f5ef2015-06-03 15:07:24 -070074 0x05, 0x59, // NDN Interest
Alexander Afanasyeve881e932014-06-08 14:47:03 +030075 0x07, 0x14, // Name
76 0x08, 0x5, // NameComponent
77 0x6c, 0x6f, 0x63, 0x61, 0x6c,
78 0x08, 0x3, // NameComponent
79 0x6e, 0x64, 0x6e,
80 0x08, 0x6, // NameComponent
81 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
82 0x09, 0x37, // Selectors
83 0x0d, 0x1, 0x1, // MinSuffix
84 0x0e, 0x1, 0x1, // MaxSuffix
85 0x1c, 0x16, // KeyLocator
86 0x07, 0x14, // Name
87 0x08, 0x04,
88 0x74, 0x65, 0x73, 0x74,
89 0x08, 0x03,
90 0x6b, 0x65, 0x79,
91 0x08, 0x07,
92 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
93 0x10, 0x14, // Exclude
94 0x08, 0x4, // NameComponent
95 0x61, 0x6c, 0x65, 0x78,
96 0x08, 0x4, // NameComponent
97 0x78, 0x78, 0x78, 0x78,
98 0x13, 0x0, // Any
99 0x08, 0x4, // NameComponent
100 0x79, 0x79, 0x79, 0x79,
101 0x11, 0x1, // ChildSelector
102 0x1,
103 0x0a, 0x4, // Nonce
104 0x2, 0x0, 0x0, 0x00,
Alexander Afanasyev4b456282014-02-13 00:34:34 -0800105 0x0c, // InterestLifetime
Alexander Afanasyev636e9f12014-01-07 12:01:03 -0800106 0x2, 0x3, 0xe8
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800107};
108
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700109const uint8_t InterestWithLink[] = {
110 0x05, 0xfb, // Interest
111 0x07, 0x14, // Name
112 0x08, 0x5, // NameComponent
113 0x6c, 0x6f, 0x63, 0x61, 0x6c,
114 0x08, 0x3, // NameComponent
115 0x6e, 0x64, 0x6e,
116 0x08, 0x6, // NameComponent
117 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
118 0x0a, 0x4, // Nonce
119 0x1, 0x0, 0x0, 0x00,
120 0x06, 0xda, // Data
121 0x07, 0x14, // Name
122 0x08, 0x05,
123 0x6c, 0x6f, 0x63, 0x61, 0x6c,
124 0x08, 0x03,
125 0x6e, 0x64, 0x6e,
126 0x08, 0x06,
127 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
128 0x14, 0x07, // MetaInfo
129 0x18, 0x01, // ContentType
130 0x01,
131 0x19, 0x02, // FreshnessPeriod
132 0x27, 0x10,
133 0x15, 0x1a, // Content
134 0x1f, 0x0c, // LinkDelegation
135 0x1e, 0x01, // LinkPreference
136 0x0a,
137 0x07, 0x07, // Name
138 0x08, 0x05,
139 0x6c, 0x6f, 0x63, 0x61, 0x6c,
140 0x1f, 0x0a, // LinkDelegation
141 0x1e, 0x01, // LinkPreference
142 0x14,
143 0x07, 0x05, // Name
144 0x08, 0x03,
145 0x6e, 0x64, 0x6e,
146 0x16, 0x1b, // SignatureInfo
147 0x1b, 0x01, // SignatureType
148 0x01,
149 0x1c, 0x16, // KeyLocator
150 0x07, 0x14, // Name
151 0x08, 0x04,
152 0x74, 0x65, 0x73, 0x74,
153 0x08, 0x03,
154 0x6b, 0x65, 0x79,
155 0x08, 0x07,
156 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
157 0x17, 0x80, // SignatureValue
158 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
159 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
160 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
161 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
162 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
163 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
164 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
165 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
166 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
167 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
168 0x20, 0x01, // SelectedDelegation
169 0x00
170};
171
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700172const uint8_t LINK[] = {
173 0x06, 0xda, // Data
174 0x07, 0x14, // Name
175 0x08, 0x05,
176 0x6c, 0x6f, 0x63, 0x61, 0x6c,
177 0x08, 0x03,
178 0x6e, 0x64, 0x6e,
179 0x08, 0x06,
180 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
181 0x14, 0x07, // MetaInfo
182 0x18, 0x01, // ContentType
183 0x01,
184 0x19, 0x02, // FreshnessPeriod
185 0x27, 0x10,
186 0x15, 0x1a, // Content
187 0x1f, 0x0c, // LinkDelegation
188 0x1e, 0x01, // LinkPreference
189 0x0a,
190 0x07, 0x07, // Name
191 0x08, 0x05,
192 0x6c, 0x6f, 0x63, 0x61, 0x6c,
193 0x1f, 0x0a, // LinkDelegation
194 0x1e, 0x01, // LinkPreference
195 0x14,
196 0x07, 0x05, // Name
197 0x08, 0x03,
198 0x6e, 0x64, 0x6e,
199 0x16, 0x1b, // SignatureInfo
200 0x1b, 0x01, // SignatureType
201 0x01,
202 0x1c, 0x16, // KeyLocator
203 0x07, 0x14, // Name
204 0x08, 0x04,
205 0x74, 0x65, 0x73, 0x74,
206 0x08, 0x03,
207 0x6b, 0x65, 0x79,
208 0x08, 0x07,
209 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
210 0x17, 0x80, // SignatureValue
211 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
212 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
213 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
214 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
215 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
216 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
217 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
218 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
219 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
220 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1
221};
222
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700223const uint8_t InterestWithLinkMissingContentType[] = {
Junxiao Shid21abd32017-06-30 02:56:40 +0000224 0x05, 0xf5, // Interest
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700225 0x07, 0x14, // Name
226 0x08, 0x5, // NameComponent
227 0x6c, 0x6f, 0x63, 0x61, 0x6c,
228 0x08, 0x3, // NameComponent
229 0x6e, 0x64, 0x6e,
230 0x08, 0x6, // NameComponent
231 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
232 0x0a, 0x4, // Nonce
233 0x1, 0x0, 0x0, 0x00,
234 0x06, 0xd7, // Data
235 0x07, 0x14, // Name
236 0x08, 0x05,
237 0x6c, 0x6f, 0x63, 0x61, 0x6c,
238 0x08, 0x03,
239 0x6e, 0x64, 0x6e,
240 0x08, 0x06,
241 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
242 0x14, 0x04, // MetaInfo
243 0x19, 0x02, // FreshnessPeriod
244 0x27, 0x10,
245 0x15, 0x1a, // Content
246 0x1f, 0x0c, // LinkDelegation
247 0x1e, 0x01, // LinkPreference
248 0x0a,
249 0x07, 0x07, // Name
250 0x08, 0x05,
251 0x6c, 0x6f, 0x63, 0x61, 0x6c,
252 0x1f, 0x0a, // LinkDelegation
253 0x1e, 0x01, // LinkPreference
254 0x14,
255 0x07, 0x05, // Name
256 0x08, 0x03,
257 0x6e, 0x64, 0x6e,
258 0x16, 0x1b, // SignatureInfo
259 0x1b, 0x01, // SignatureType
260 0x01,
261 0x1c, 0x16, // KeyLocator
262 0x07, 0x14, // Name
263 0x08, 0x04,
264 0x74, 0x65, 0x73, 0x74,
265 0x08, 0x03,
266 0x6b, 0x65, 0x79,
267 0x08, 0x07,
268 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
269 0x17, 0x80, // SignatureValue
270 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
271 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
272 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
273 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
274 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
275 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
276 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
277 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
278 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
Junxiao Shid21abd32017-06-30 02:56:40 +0000279 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700280};
281
282const uint8_t InterestWithLinkNoMetaInfo[] = {
Junxiao Shid21abd32017-06-30 02:56:40 +0000283 0x05, 0xef, // Interest
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700284 0x07, 0x14, // Name
285 0x08, 0x5, // NameComponent
286 0x6c, 0x6f, 0x63, 0x61, 0x6c,
287 0x08, 0x3, // NameComponent
288 0x6e, 0x64, 0x6e,
289 0x08, 0x6, // NameComponent
290 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
291 0x0a, 0x4, // Nonce
292 0x1, 0x0, 0x0, 0x00,
293 0x06, 0xd1, // Data
294 0x07, 0x14, // Name
295 0x08, 0x05,
296 0x6c, 0x6f, 0x63, 0x61, 0x6c,
297 0x08, 0x03,
298 0x6e, 0x64, 0x6e,
299 0x08, 0x06,
300 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
301 0x15, 0x1a, // Content
302 0x1f, 0x0c, // LinkDelegation
303 0x1e, 0x01, // LinkPreference
304 0x0a,
305 0x07, 0x07, // Name
306 0x08, 0x05,
307 0x6c, 0x6f, 0x63, 0x61, 0x6c,
308 0x1f, 0x0a, // LinkPreference
309 0x1e, 0x01, // LinkPreference
310 0x14,
311 0x07, 0x05, // Name
312 0x08, 0x03,
313 0x6e, 0x64, 0x6e,
314 0x16, 0x1b, // SignatureInfo
315 0x1b, 0x01, // SignatureType
316 0x01,
317 0x1c, 0x16, // KeyLocator
318 0x07, 0x14, // Name
319 0x08, 0x04,
320 0x74, 0x65, 0x73, 0x74,
321 0x08, 0x03,
322 0x6b, 0x65, 0x79,
323 0x08, 0x07,
324 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
325 0x17, 0x80, // SignatureValue
326 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
327 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
328 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
329 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
330 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
331 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
332 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
333 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
334 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
Junxiao Shid21abd32017-06-30 02:56:40 +0000335 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700336};
337
338const uint8_t InterestWithLinkWrongContentType[] = {
Junxiao Shid21abd32017-06-30 02:56:40 +0000339 0x05, 0xf8, // Interest
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700340 0x07, 0x14, // Name
341 0x08, 0x5, // NameComponent
342 0x6c, 0x6f, 0x63, 0x61, 0x6c,
343 0x08, 0x3, // NameComponent
344 0x6e, 0x64, 0x6e,
345 0x08, 0x6, // NameComponent
346 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
347 0x0a, 0x4, // Nonce
348 0x1, 0x0, 0x0, 0x00,
349 0x06, 0xda, // Data
350 0x07, 0x14, // Name
351 0x08, 0x05,
352 0x6c, 0x6f, 0x63, 0x61, 0x6c,
353 0x08, 0x03,
354 0x6e, 0x64, 0x6e,
355 0x08, 0x06,
356 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
357 0x14, 0x07, // MetaInfo
358 0x18, 0x01, // ContentType
359 0x00,
360 0x19, 0x02, // FreshnessPeriod
361 0x27, 0x10,
362 0x15, 0x1a, // Content
363 0x1f, 0x0c, // LinkDelegation
364 0x1e, 0x01, // LinkPreference
365 0x0a,
366 0x07, 0x07, // Name
367 0x08, 0x05,
368 0x6c, 0x6f, 0x63, 0x61, 0x6c,
369 0x1f, 0x0a, // LinkDelegation
370 0x1e, 0x01, // LinkPreference
371 0x14,
372 0x07, 0x05, // Name
373 0x08, 0x03,
374 0x6e, 0x64, 0x6e,
375 0x16, 0x1b, // SignatureInfo
376 0x1b, 0x01, // SignatureType
377 0x01,
378 0x1c, 0x16, // KeyLocator
379 0x07, 0x14, // Name
380 0x08, 0x04,
381 0x74, 0x65, 0x73, 0x74,
382 0x08, 0x03,
383 0x6b, 0x65, 0x79,
384 0x08, 0x07,
385 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
386 0x17, 0x80, // SignatureValue
387 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
388 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
389 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
390 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
391 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
392 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
393 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
394 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
395 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
Junxiao Shid21abd32017-06-30 02:56:40 +0000396 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700397};
398
399const uint8_t InterestWithSelectedDelegationButNoLink[] = {
400 0x05, 0x1f, // Interest
401 0x07, 0x14, // Name
402 0x08, 0x5, // NameComponent
403 0x6c, 0x6f, 0x63, 0x61, 0x6c,
404 0x08, 0x3, // NameComponent
405 0x6e, 0x64, 0x6e,
406 0x08, 0x6, // NameComponent
407 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
408 0x0a, 0x4, // Nonce
409 0x1, 0x0, 0x0, 0x00,
410 0x20, 0x01, // SelectedDelegation
411 0x00
412};
413
414const uint8_t InterestWithLinkNotNonIntegerSelectedDelegation[] = {
415 0x05, 0xfb, // Interest
416 0x07, 0x14, // Name
417 0x08, 0x5, // NameComponent
418 0x6c, 0x6f, 0x63, 0x61, 0x6c,
419 0x08, 0x3, // NameComponent
420 0x6e, 0x64, 0x6e,
421 0x08, 0x6, // NameComponent
422 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
423 0x0a, 0x4, // Nonce
424 0x1, 0x0, 0x0, 0x00,
425 0x06, 0xda, // Data
426 0x07, 0x14, // Name
427 0x08, 0x05,
428 0x6c, 0x6f, 0x63, 0x61, 0x6c,
429 0x08, 0x03,
430 0x6e, 0x64, 0x6e,
431 0x08, 0x06,
432 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
433 0x14, 0x07, // MetaInfo
434 0x18, 0x01, // ContentType
435 0x01,
436 0x19, 0x02, // FreshnessPeriod
437 0x27, 0x10,
438 0x15, 0x1a, // Content
439 0x1f, 0x0c, // LinkDelegation
440 0x1e, 0x01, // LinkPreference
441 0x0a,
442 0x07, 0x07, // Name
443 0x08, 0x05,
444 0x6c, 0x6f, 0x63, 0x61, 0x6c,
445 0x1f, 0x0a, // LinkDelegation
446 0x1e, 0x01, // LinkPreference
447 0x14,
448 0x07, 0x05, // Name
449 0x08, 0x03,
450 0x6e, 0x64, 0x6e,
451 0x16, 0x1b, // SignatureInfo
452 0x1b, 0x01, // SignatureType
453 0x01,
454 0x1c, 0x16, // KeyLocator
455 0x07, 0x14, // Name
456 0x08, 0x04,
457 0x74, 0x65, 0x73, 0x74,
458 0x08, 0x03,
459 0x6b, 0x65, 0x79,
460 0x08, 0x07,
461 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
462 0x17, 0x78, // SignatureValue
463 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
464 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
465 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
466 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
467 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
468 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
469 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
470 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
471 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
472 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7,
473 0x20, 0x03, // SelectedDelegation
474 0xAA, 0xAA, 0xAA
475};
476
477const uint8_t InterestWithLinkNonDecreasingOrder[] = {
478 0x05, 0xfb, // Interest
479 0x07, 0x14, // Name
480 0x08, 0x5, // NameComponent
481 0x6c, 0x6f, 0x63, 0x61, 0x6c,
482 0x08, 0x3, // NameComponent
483 0x6e, 0x64, 0x6e,
484 0x08, 0x6, // NameComponent
485 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
486 0x0a, 0x4, // Nonce
487 0x1, 0x0, 0x0, 0x00,
488 0x06, 0xda, // Data
489 0x07, 0x14, // Name
490 0x08, 0x05,
491 0x6c, 0x6f, 0x63, 0x61, 0x6c,
492 0x08, 0x03,
493 0x6e, 0x64, 0x6e,
494 0x08, 0x06,
495 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
496 0x14, 0x07, // MetaInfo
497 0x18, 0x01, // ContentType
498 0x01,
499 0x19, 0x02, // FreshnessPeriod
500 0x27, 0x10,
501 0x15, 0x1a, // Content
502 0x1f, 0x0c, // LinkDelegation
503 0x1e, 0x01, // LinkPreference
504 0x14,
505 0x07, 0x07, // Name
506 0x08, 0x05,
507 0x6c, 0x6f, 0x63, 0x61, 0x6c,
508 0x1f, 0x0a, // LinkDelegation
509 0x1e, 0x01, // LinkPreference
510 0x0a,
511 0x07, 0x05, // Name
512 0x08, 0x03,
513 0x6e, 0x64, 0x6e,
514 0x16, 0x1b, // SignatureInfo
515 0x1b, 0x01, // SignatureType
516 0x01,
517 0x1c, 0x16, // KeyLocator
518 0x07, 0x14, // Name
519 0x08, 0x04,
520 0x74, 0x65, 0x73, 0x74,
521 0x08, 0x03,
522 0x6b, 0x65, 0x79,
523 0x08, 0x07,
524 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
525 0x17, 0x80, // SignatureValue
526 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
527 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
528 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
529 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
530 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
531 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
532 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
533 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
534 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
535 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
536 0x20, 0x01, // SelectedDelegation
537 0x01
538};
539
Eric Newberryb555b002017-05-17 00:30:44 -0700540BOOST_AUTO_TEST_CASE(DefaultValues)
541{
542 Interest i;
543 BOOST_CHECK_EQUAL(i.getInterestLifetime(), DEFAULT_INTEREST_LIFETIME);
544 BOOST_CHECK(!i.hasSelectedDelegation());
545}
546
547BOOST_AUTO_TEST_CASE(EncodeChildSelector)
548{
549 Interest i;
550 i.setName("/local/ndn/prefix");
551 i.setNonce(1);
552 BOOST_CHECK_EQUAL(i.getChildSelector(), 0);
553 BOOST_CHECK_THROW(i.setChildSelector(-1), std::invalid_argument);
554 BOOST_CHECK_THROW(i.setChildSelector(2), std::invalid_argument);
555 BOOST_CHECK_NO_THROW(i.setChildSelector(1));
556 BOOST_CHECK_EQUAL(i.getChildSelector(), 1);
557 BOOST_CHECK_NO_THROW(i.setChildSelector(0));
558 BOOST_CHECK_EQUAL(i.getChildSelector(), 0);
559
560 const uint8_t expectedDefault[] = {
561 0x05, 0x1e, // MetaInfo
562 0x07, 0x14, // Name
563 0x08, 0x5, // NameComponent
564 0x6c, 0x6f, 0x63, 0x61, 0x6c,
565 0x08, 0x3, // NameComponent
566 0x6e, 0x64, 0x6e,
567 0x08, 0x6, // NameComponent
568 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
569 0x09, 0x00, // Selectors
570 0x0a, 0x04, // Nonce
571 0x01, 0x00, 0x00, 0x00, // 1
572 };
573
574 BOOST_CHECK_EQUAL_COLLECTIONS(i.wireEncode().begin(), i.wireEncode().end(),
575 expectedDefault, expectedDefault + sizeof(expectedDefault));
576
577 const uint8_t expected1[] = {
578 0x05, 0x21, // MetaInfo
579 0x07, 0x14, // Name
580 0x08, 0x5, // NameComponent
581 0x6c, 0x6f, 0x63, 0x61, 0x6c,
582 0x08, 0x3, // NameComponent
583 0x6e, 0x64, 0x6e,
584 0x08, 0x6, // NameComponent
585 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
586 0x09, 0x03, // Selectors
587 0x11, 0x01, // ChildSelector
588 0x01, // 1
589 0x0a, 0x04, // Nonce
590 0x01, 0x00, 0x00, 0x00, // 1
591 };
592
593 i.setChildSelector(1);
594 BOOST_CHECK_EQUAL_COLLECTIONS(i.wireEncode().begin(), i.wireEncode().end(),
595 expected1, expected1 + sizeof(expected1));
596}
597
598BOOST_AUTO_TEST_CASE(EncodeInterestLifetime)
599{
600 Interest i;
601 i.setName("/local/ndn/prefix");
602 i.setNonce(1);
603 BOOST_CHECK_EQUAL(i.getInterestLifetime(), DEFAULT_INTEREST_LIFETIME);
604 BOOST_CHECK_THROW(i.setInterestLifetime(time::milliseconds(-1)), std::invalid_argument);
605 BOOST_CHECK_EQUAL(i.getInterestLifetime(), DEFAULT_INTEREST_LIFETIME);
606 BOOST_CHECK_NO_THROW(i.setInterestLifetime(time::milliseconds(1)));
607 BOOST_CHECK_EQUAL(i.getInterestLifetime(), time::milliseconds(1));
608 BOOST_CHECK_NO_THROW(i.setInterestLifetime(DEFAULT_INTEREST_LIFETIME));
609
610 const uint8_t expectedDefault[] = {
611 0x05, 0x1e, // MetaInfo
612 0x07, 0x14, // Name
613 0x08, 0x5, // NameComponent
614 0x6c, 0x6f, 0x63, 0x61, 0x6c,
615 0x08, 0x3, // NameComponent
616 0x6e, 0x64, 0x6e,
617 0x08, 0x6, // NameComponent
618 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
619 0x09, 0x00, // Selectors
620 0x0a, 0x04, // Nonce
621 0x01, 0x00, 0x00, 0x00, // 1
622 };
623
624 BOOST_CHECK_EQUAL_COLLECTIONS(i.wireEncode().begin(), i.wireEncode().end(),
625 expectedDefault, expectedDefault + sizeof(expectedDefault));
626
627 const uint8_t expected1000ms[] = {
628 0x05, 0x22, // MetaInfo
629 0x07, 0x14, // Name
630 0x08, 0x5, // NameComponent
631 0x6c, 0x6f, 0x63, 0x61, 0x6c,
632 0x08, 0x3, // NameComponent
633 0x6e, 0x64, 0x6e,
634 0x08, 0x6, // NameComponent
635 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
636 0x09, 0x00, // Selectors
637 0x0a, 0x04, // Nonce
638 0x01, 0x00, 0x00, 0x00, // 1
639 0x0c, 0x02, // InterestLifetime
640 0x03, 0xe8
641 };
642
643 BOOST_CHECK_NO_THROW(i.setInterestLifetime(time::milliseconds(1000)));
644 BOOST_CHECK_EQUAL_COLLECTIONS(i.wireEncode().begin(), i.wireEncode().end(),
645 expected1000ms, expected1000ms + sizeof(expected1000ms));
646}
647
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700648BOOST_AUTO_TEST_CASE(InterestEqualityChecks)
649{
650 // Interest ::= INTEREST-TYPE TLV-LENGTH
651 // Name
652 // Selectors?
653 // Nonce
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700654 // InterestLifetime?
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700655 // Link?
656 // SelectedDelegation?
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700657
658 Interest a;
659 Interest b;
660
661 // if nonce is not set, it will be set to a random value
662 a.setNonce(1);
663 b.setNonce(1);
664
665 BOOST_CHECK_EQUAL(a == b, true);
666 BOOST_CHECK_EQUAL(a != b, false);
667
668 // check comparison on Name
669 a.setName("ndn:/A");
670 BOOST_CHECK_EQUAL(a == b, false);
671 BOOST_CHECK_EQUAL(a != b, true);
672
673 b.setName("ndn:/B");
674 BOOST_CHECK_EQUAL(a == b, false);
675 BOOST_CHECK_EQUAL(a != b, true);
676
677 b.setName("ndn:/A");
678 BOOST_CHECK_EQUAL(a == b, true);
679 BOOST_CHECK_EQUAL(a != b, false);
680
681 // check comparison on Selectors
682 a.setChildSelector(1);
683 BOOST_CHECK_EQUAL(a == b, false);
684 BOOST_CHECK_EQUAL(a != b, true);
685
686 b.setChildSelector(1);
687 BOOST_CHECK_EQUAL(a == b, true);
688 BOOST_CHECK_EQUAL(a != b, false);
689
690 // check comparison on Nonce
691 a.setNonce(100);
692 BOOST_CHECK_EQUAL(a == b, false);
693 BOOST_CHECK_EQUAL(a != b, true);
694
695 b.setNonce(100);
696 BOOST_CHECK_EQUAL(a == b, true);
697 BOOST_CHECK_EQUAL(a != b, false);
698
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700699 // check comparison on InterestLifetime
700 a.setInterestLifetime(time::seconds(10));
701 BOOST_CHECK_EQUAL(a == b, false);
702 BOOST_CHECK_EQUAL(a != b, true);
703
704 b.setInterestLifetime(time::seconds(10));
705 BOOST_CHECK_EQUAL(a == b, true);
706 BOOST_CHECK_EQUAL(a != b, false);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700707
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700708 a.setLink(Block(LINK, sizeof(LINK)));
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700709 BOOST_CHECK_EQUAL(a == b, false);
710 BOOST_CHECK_EQUAL(a != b, true);
711
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700712 b.setLink(Block(LINK, sizeof(LINK)));
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700713 BOOST_CHECK_EQUAL(a == b, true);
714 BOOST_CHECK_EQUAL(a != b, false);
715
716 // Selected Delegation
717 BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false);
718 BOOST_CHECK_EQUAL(b.hasSelectedDelegation(), false);
719
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700720 a.setSelectedDelegation(Name("/local"));
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700721 BOOST_CHECK_EQUAL(a == b, false);
722 BOOST_CHECK_EQUAL(a != b, true);
723
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700724 b.setSelectedDelegation(Name("/local"));
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700725 BOOST_CHECK_EQUAL(a == b, true);
726 BOOST_CHECK_EQUAL(a != b, false);
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700727}
728
729BOOST_AUTO_TEST_CASE(SelectorsEqualityChecks)
730{
731 // Selectors ::= SELECTORS-TYPE TLV-LENGTH
732 // MinSuffixComponents?
733 // MaxSuffixComponents?
734 // PublisherPublicKeyLocator?
735 // Exclude?
736 // ChildSelector?
737 // MustBeFresh?
738
739 Selectors a;
740 Selectors b;
741 BOOST_CHECK_EQUAL(a == b, true);
742 BOOST_CHECK_EQUAL(a != b, false);
743
744 // MinSuffixComponents
745 a.setMinSuffixComponents(1);
746 BOOST_CHECK_EQUAL(a == b, false);
747 BOOST_CHECK_EQUAL(a != b, true);
748
749 b.setMinSuffixComponents(2);
750 BOOST_CHECK_EQUAL(a == b, false);
751 BOOST_CHECK_EQUAL(a != b, true);
752
753 b.setMinSuffixComponents(1);
754 BOOST_CHECK_EQUAL(a == b, true);
755 BOOST_CHECK_EQUAL(a != b, false);
756
757 // MaxSuffixComponents
758 a.setMaxSuffixComponents(10);
759 BOOST_CHECK_EQUAL(a == b, false);
760 BOOST_CHECK_EQUAL(a != b, true);
761
762 b.setMaxSuffixComponents(10);
763 BOOST_CHECK_EQUAL(a == b, true);
764 BOOST_CHECK_EQUAL(a != b, false);
765
766 // PublisherPublicKeyLocator
767 a.setPublisherPublicKeyLocator(KeyLocator("/key/Locator/name"));
768 BOOST_CHECK_EQUAL(a == b, false);
769 BOOST_CHECK_EQUAL(a != b, true);
770
771 b.setPublisherPublicKeyLocator(KeyLocator("/key/Locator/name"));
772 BOOST_CHECK_EQUAL(a == b, true);
773 BOOST_CHECK_EQUAL(a != b, false);
774
775 // Exclude
776 a.setExclude(Exclude().excludeOne(name::Component("exclude")));
777 BOOST_CHECK_EQUAL(a == b, false);
778 BOOST_CHECK_EQUAL(a != b, true);
779
780 b.setExclude(Exclude().excludeOne(name::Component("exclude")));
781 BOOST_CHECK_EQUAL(a == b, true);
782 BOOST_CHECK_EQUAL(a != b, false);
783
784 // ChildSelector
785 a.setChildSelector(1);
786 BOOST_CHECK_EQUAL(a == b, false);
787 BOOST_CHECK_EQUAL(a != b, true);
788
789 b.setChildSelector(1);
790 BOOST_CHECK_EQUAL(a == b, true);
791 BOOST_CHECK_EQUAL(a != b, false);
792
793 // MustBeFresh
794 a.setMustBeFresh(true);
795 BOOST_CHECK_EQUAL(a == b, false);
796 BOOST_CHECK_EQUAL(a != b, true);
797
798 b.setMustBeFresh(true);
799 BOOST_CHECK_EQUAL(a == b, true);
800 BOOST_CHECK_EQUAL(a != b, false);
801}
802
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700803BOOST_AUTO_TEST_CASE(LinkObject)
804{
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700805 Link link1("test", {{100, "/test3"}, {20, "/test2"}, {10, "/test1"}});
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -0700806 m_keyChain.sign(link1);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700807 Block wire = link1.wireEncode();
808
809 Interest a;
810 BOOST_REQUIRE_NO_THROW(a.setLink(wire));
811
812 BOOST_REQUIRE_NO_THROW(a.getLink());
813
814 Link link2 = a.getLink();
815 Name name = link2.getName();
816 BOOST_CHECK_EQUAL(Name("test"), name);
817 BOOST_CHECK_EQUAL(a.hasLink(), true);
818 Link::DelegationSet delegations;
819 delegations = link2.getDelegations();
820
821 auto i = delegations.begin();
822 BOOST_CHECK_EQUAL(std::get<0>(*i), 10);
823 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test1"));
824 ++i;
825 BOOST_CHECK_EQUAL(std::get<0>(*i), 20);
826 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test2"));
827 ++i;
828 BOOST_CHECK_EQUAL(std::get<0>(*i), 100);
829 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test3"));
830
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700831 a.setLink(Block(LINK, sizeof(LINK)));
832 BOOST_CHECK_EQUAL(a.getLink().getDelegations().size(), 2);
833
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700834 a.unsetLink();
835 BOOST_CHECK_EQUAL(a.hasLink(), false);
836}
837
838BOOST_AUTO_TEST_CASE(SelectedDelegationChecks)
839{
840 Link link("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -0700841 m_keyChain.sign(link);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700842 Block wire = link.wireEncode();
843
844 Interest a;
845 a.setLink(wire);
846 BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false);
847
848 BOOST_REQUIRE_NO_THROW(a.setSelectedDelegation(Name("test2")));
849 BOOST_CHECK_EQUAL(a.getSelectedDelegation(), Name("test2"));
850
851 BOOST_REQUIRE_NO_THROW(a.setSelectedDelegation(uint32_t(2)));
852 BOOST_CHECK_EQUAL(a.getSelectedDelegation(), Name("test3"));
853
854 a.unsetSelectedDelegation();
855 BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false);
856}
857
858BOOST_AUTO_TEST_CASE(EncodeDecodeWithLink)
859{
860 Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -0700861 m_keyChain.sign(link1);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700862 Block wire = link1.wireEncode();
863
864 Interest a;
865 a.setName("/Test/Encode/Decode/With/Link");
866 a.setChildSelector(1);
867 a.setNonce(100);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700868 a.setInterestLifetime(time::seconds(10));
869 a.setLink(wire);
870
871 Block interestBlock = a.wireEncode();
872 Interest b(interestBlock);
873
874 BOOST_CHECK_EQUAL(a == b, true);
875
876 Link link2 = b.getLink();
877 Link::DelegationSet delegations;
878 delegations = link2.getDelegations();
879
880 auto i = delegations.begin();
881 BOOST_CHECK_EQUAL(std::get<0>(*i), 10);
882 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test1"));
883 ++i;
884 BOOST_CHECK_EQUAL(std::get<0>(*i), 20);
885 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test2"));
886 ++i;
887 BOOST_CHECK_EQUAL(std::get<0>(*i), 100);
888 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test3"));
889
890}
891
892BOOST_AUTO_TEST_CASE(DecodeInterestWithLink)
893{
894 Block interestBlock(InterestWithLink, sizeof(InterestWithLink));
895
896 ndn::Interest i;
897 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
898 Link link = i.getLink();
899 BOOST_CHECK_EQUAL(link.getName(), Name("/local/ndn/prefix"));
900 Link::DelegationSet delegations = link.getDelegations();
901
902 auto it = delegations.begin();
903 BOOST_CHECK_EQUAL(std::get<0>(*it), 10);
904 BOOST_CHECK_EQUAL(std::get<1>(*it), Name("local"));
905 ++it;
906 BOOST_CHECK_EQUAL(std::get<0>(*it), 20);
907 BOOST_CHECK_EQUAL(std::get<1>(*it), Name("ndn"));
908
909 BOOST_REQUIRE_NO_THROW(i.getSelectedDelegation());
910 BOOST_CHECK_EQUAL(i.getSelectedDelegation(), Name("local"));
911}
912
913BOOST_AUTO_TEST_CASE(DecodeInterestWithLinkNonDecreasingOrder)
914{
915 Block interestBlock(InterestWithLinkNonDecreasingOrder,
916 sizeof(InterestWithLinkNonDecreasingOrder));
917
918 ndn::Interest i;
919 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
920 BOOST_REQUIRE_NO_THROW(i.getSelectedDelegation());
921 BOOST_CHECK_EQUAL(i.getSelectedDelegation(), Name("ndn"));
922}
923
924BOOST_AUTO_TEST_CASE(LinkObjectMissingContentType)
925{
926 Block interestBlock(InterestWithLinkMissingContentType,
927 sizeof(InterestWithLinkMissingContentType));
928
Junxiao Shid21abd32017-06-30 02:56:40 +0000929 BOOST_CHECK_THROW(Interest(interestBlock).getLink(), tlv::Error);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700930}
931
932BOOST_AUTO_TEST_CASE(LinkObjectNoMetaInfo)
933{
934 Block interestBlock(InterestWithLinkNoMetaInfo,
935 sizeof(InterestWithLinkNoMetaInfo));
936
Junxiao Shid21abd32017-06-30 02:56:40 +0000937 BOOST_CHECK_THROW(Interest(interestBlock).getLink(), tlv::Error);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700938}
939
940BOOST_AUTO_TEST_CASE(LinkObjectWrongContentType)
941{
942 Block interestBlock(InterestWithLinkWrongContentType,
943 sizeof(InterestWithLinkWrongContentType));
944
Junxiao Shid21abd32017-06-30 02:56:40 +0000945 BOOST_CHECK_THROW(Interest(interestBlock).getLink(), tlv::Error);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700946}
947
948BOOST_AUTO_TEST_CASE(InterestContainingSelectedDelegationButNoLink)
949{
950 Block interestBlock(InterestWithSelectedDelegationButNoLink,
951 sizeof(InterestWithSelectedDelegationButNoLink));
952
953 ndn::Interest i;
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700954 BOOST_CHECK_THROW(i.wireDecode(interestBlock), Interest::Error);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700955}
956
957BOOST_AUTO_TEST_CASE(SelectedDelegationIsNotNonNegativeInteger)
958{
959 Block interestBlock(InterestWithLinkNotNonIntegerSelectedDelegation,
960 sizeof(InterestWithLinkNotNonIntegerSelectedDelegation));
961
962 ndn::Interest i;
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700963 BOOST_CHECK_THROW(i.wireDecode(interestBlock), tlv::Error);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700964}
965
966BOOST_AUTO_TEST_CASE(SelectedDelegationEqualToDelegationCount)
967{
968 Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -0700969 m_keyChain.sign(link1);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700970 Block wire = link1.wireEncode();
971
972 Interest a;
973 a.setName("/Test/Encode/Decode/With/Link");
974 a.setChildSelector(1);
975 a.setNonce(100);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700976 a.setInterestLifetime(time::seconds(10));
977 a.setLink(wire);
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700978 BOOST_CHECK_THROW(a.setSelectedDelegation(3), Interest::Error);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700979}
980
981BOOST_AUTO_TEST_CASE(SelectedDelegationGreaterThanDelegationCount)
982{
983 Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -0700984 m_keyChain.sign(link1);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700985 Block wire = link1.wireEncode();
986
987 Interest a;
988 a.setName("/Test/Encode/Decode/With/Link");
989 a.setChildSelector(1);
990 a.setNonce(100);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700991 a.setInterestLifetime(time::seconds(10));
992 a.setLink(wire);
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700993 BOOST_CHECK_THROW(a.setSelectedDelegation(4), Interest::Error);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700994}
995
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700996BOOST_AUTO_TEST_CASE(Decode)
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800997{
998 Block interestBlock(Interest1, sizeof(Interest1));
Alexander Afanasyev636e9f12014-01-07 12:01:03 -0800999
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001000 ndn::Interest i;
Alexander Afanasyev049f8f72013-12-26 19:07:15 -08001001 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001002
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001003 BOOST_CHECK_EQUAL(i.getName().toUri(), "/local/ndn/prefix");
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001004 BOOST_CHECK_EQUAL(i.getInterestLifetime(), time::milliseconds(1000));
1005 BOOST_CHECK_EQUAL(i.getMinSuffixComponents(), 1);
1006 BOOST_CHECK_EQUAL(i.getMaxSuffixComponents(), 1);
1007 BOOST_CHECK_EQUAL(i.getPublisherPublicKeyLocator().getType(),
1008 static_cast<uint32_t>(KeyLocator::KeyLocator_Name));
1009 BOOST_CHECK_EQUAL(i.getPublisherPublicKeyLocator().getName(), "ndn:/test/key/locator");
1010 BOOST_CHECK_EQUAL(i.getChildSelector(), 1);
1011 BOOST_CHECK_EQUAL(i.getMustBeFresh(), false);
1012 BOOST_CHECK_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy");
1013 BOOST_CHECK_EQUAL(i.getNonce(), 1U);
Alexander Afanasyevcac08382015-09-02 14:52:40 -07001014 BOOST_CHECK_EQUAL(i.hasLink(), false);
1015 BOOST_CHECK_EQUAL(i.hasSelectedDelegation(), false);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001016}
1017
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001018BOOST_AUTO_TEST_CASE(DecodeFromStream)
Alexander Afanasyev6835ad82014-02-12 10:07:20 -08001019{
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07001020 boost::iostreams::stream<boost::iostreams::array_source> is(
1021 reinterpret_cast<const char *>(Interest1), sizeof(Interest1));
Junxiao Shib332e782014-03-31 14:23:46 -07001022
Alexander Afanasyev9c578182014-05-14 17:28:28 -07001023 Block interestBlock = Block::fromStream(is);
Alexander Afanasyev6835ad82014-02-12 10:07:20 -08001024
1025 ndn::Interest i;
1026 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
1027
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001028 BOOST_CHECK_EQUAL(i.getName().toUri(), "/local/ndn/prefix");
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001029 BOOST_CHECK_EQUAL(i.getInterestLifetime(), time::milliseconds(1000));
1030 BOOST_CHECK_EQUAL(i.getMinSuffixComponents(), 1);
1031 BOOST_CHECK_EQUAL(i.getMaxSuffixComponents(), 1);
1032 BOOST_CHECK_EQUAL(i.getChildSelector(), 1);
1033 BOOST_CHECK_EQUAL(i.getMustBeFresh(), false);
1034 BOOST_CHECK_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy");
1035 BOOST_CHECK_EQUAL(i.getNonce(), 1U);
Alexander Afanasyevcac08382015-09-02 14:52:40 -07001036 BOOST_CHECK_EQUAL(i.hasLink(), false);
1037 BOOST_CHECK_EQUAL(i.hasSelectedDelegation(), false);
Alexander Afanasyev6835ad82014-02-12 10:07:20 -08001038}
1039
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001040BOOST_AUTO_TEST_CASE(Encode)
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001041{
1042 ndn::Interest i(ndn::Name("/local/ndn/prefix"));
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -07001043 i.setInterestLifetime(time::milliseconds(1000));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001044 i.setMinSuffixComponents(1);
1045 i.setMaxSuffixComponents(1);
Junxiao Shib332e782014-03-31 14:23:46 -07001046 i.setPublisherPublicKeyLocator(KeyLocator("ndn:/test/key/locator"));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001047 i.setChildSelector(1);
1048 i.setMustBeFresh(false);
Alexander Afanasyevc348f832014-02-17 16:35:17 -08001049 Exclude exclude;
1050 exclude
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -08001051 .excludeOne(name::Component("alex"))
1052 .excludeRange(name::Component("xxxx"), name::Component("yyyy"));
Alexander Afanasyevc348f832014-02-17 16:35:17 -08001053 i.setExclude(exclude);
Alexander Afanasyev840139f2013-12-28 15:02:50 -08001054 i.setNonce(1);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001055
Alexander Afanasyeve881e932014-06-08 14:47:03 +03001056 BOOST_CHECK_EQUAL(i.hasWire(), false);
Eric Newberryb555b002017-05-17 00:30:44 -07001057 const Block& wire = i.wireEncode();
Alexander Afanasyeve881e932014-06-08 14:47:03 +03001058 BOOST_CHECK_EQUAL(i.hasWire(), true);
Alexander Afanasyev809805d2014-02-17 17:20:33 -08001059
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001060 BOOST_CHECK_EQUAL_COLLECTIONS(Interest1, Interest1 + sizeof(Interest1),
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001061 wire.begin(), wire.end());
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001062
Alexander Afanasyeve881e932014-06-08 14:47:03 +03001063 const uint8_t* originalWire = wire.wire();
1064 i.setNonce(2);
1065 BOOST_CHECK_EQUAL(i.hasWire(), true);
1066 BOOST_CHECK_EQUAL(originalWire, i.wireEncode().wire());
1067 BOOST_CHECK_EQUAL(i.hasWire(), true);
1068
1069 BOOST_CHECK_EQUAL_COLLECTIONS(Interest2, Interest2 + sizeof(Interest2),
1070 wire.begin(), wire.end());
Alexander Afanasyeva0c5f832014-06-19 13:27:56 -07001071
1072 std::ostringstream strStream;
1073 BOOST_CHECK_NO_THROW(strStream << i);
1074
1075 BOOST_CHECK_EQUAL(strStream.str(),
1076 "/local/ndn/prefix?"
1077 "ndn.MinSuffixComponents=1&ndn.MaxSuffixComponents=1&"
Alexander Afanasyev117f5ef2015-06-03 15:07:24 -07001078 "ndn.ChildSelector=1&"
Alexander Afanasyeva0c5f832014-06-19 13:27:56 -07001079 "ndn.InterestLifetime=1000&"
1080 "ndn.Nonce=2&ndn.Exclude=alex,xxxx,*,yyyy");
Alexander Afanasyevc3932172014-07-10 18:53:56 -07001081
1082 i.refreshNonce();
1083 BOOST_CHECK_EQUAL(i.hasWire(), true);
1084 BOOST_CHECK_EQUAL(originalWire, i.wireEncode().wire());
1085 BOOST_CHECK_NE(i.getNonce(), 2);
Alexander Afanasyeve881e932014-06-08 14:47:03 +03001086}
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001087
Alexander Afanasyevcac08382015-09-02 14:52:40 -07001088BOOST_AUTO_TEST_CASE(DecodeEncode) // this test case to ensure that wireDecode resets all the fields
1089{
1090 Interest i1;
1091 i1.setName("/test");
1092 i1.setMinSuffixComponents(100);
1093 i1.setNonce(10);
1094 i1.setInterestLifetime(time::seconds(10));
1095 i1.setLink(Block(LINK, sizeof(LINK)));
1096 i1.setSelectedDelegation(0);
1097
1098 Interest i2(i1.wireEncode());
1099
1100 BOOST_CHECK_EQUAL(i2.getName().toUri(), "/test");
1101 BOOST_CHECK_EQUAL(i2.getInterestLifetime(), time::seconds(10));
1102 BOOST_CHECK_EQUAL(i2.getMinSuffixComponents(), 100);
1103 BOOST_CHECK_EQUAL(i2.getNonce(), 10);
1104 BOOST_CHECK_EQUAL(i2.hasLink(), true);
1105 BOOST_CHECK_EQUAL(i2.hasSelectedDelegation(), true);
1106
1107 i2.wireDecode(Interest().wireEncode());
1108
1109 BOOST_CHECK_EQUAL(i2.getName().toUri(), "/");
1110 BOOST_CHECK_EQUAL(i2.getInterestLifetime(), DEFAULT_INTEREST_LIFETIME);
1111 BOOST_CHECK_EQUAL(i2.getMinSuffixComponents(), -1);
1112 BOOST_WARN_NE(i2.getNonce(), 10);
1113 BOOST_CHECK_EQUAL(i2.hasLink(), false);
1114 BOOST_CHECK_EQUAL(i2.hasSelectedDelegation(), false);
1115}
1116
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001117BOOST_AUTO_TEST_CASE(MatchesData)
1118{
1119 Interest interest;
1120 interest.setName("ndn:/A")
1121 .setMinSuffixComponents(2)
1122 .setMaxSuffixComponents(2)
1123 .setPublisherPublicKeyLocator(KeyLocator("ndn:/B"))
Junxiao Shidf4b24e2016-07-14 21:41:43 +00001124 .setExclude(Exclude().excludeAfter(name::Component("J")));
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001125
1126 Data data("ndn:/A/D");
Yingdi Yu4a557052014-07-09 16:40:37 -07001127 SignatureSha256WithRsa signature(KeyLocator("ndn:/B"));
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001128 data.setSignature(signature);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001129 data.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001130 BOOST_CHECK_EQUAL(interest.matchesData(data), true);
1131
1132 Data data1 = data;
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001133 data1.setName("ndn:/A"); // violates MinSuffixComponents
1134 data1.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001135 BOOST_CHECK_EQUAL(interest.matchesData(data1), false);
1136
Junxiao Shidf4b24e2016-07-14 21:41:43 +00001137 Interest interest1 = interest;
1138 interest1.setMinSuffixComponents(1);
1139 BOOST_CHECK_EQUAL(interest1.matchesData(data1), true);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001140
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001141 Data data2 = data;
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001142 data2.setName("ndn:/A/E/F"); // violates MaxSuffixComponents
1143 data2.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001144 BOOST_CHECK_EQUAL(interest.matchesData(data2), false);
1145
Junxiao Shidf4b24e2016-07-14 21:41:43 +00001146 Interest interest2 = interest;
1147 interest2.setMaxSuffixComponents(3);
1148 BOOST_CHECK_EQUAL(interest2.matchesData(data2), true);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001149
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001150 Data data3 = data;
Yingdi Yu4a557052014-07-09 16:40:37 -07001151 SignatureSha256WithRsa signature3(KeyLocator("ndn:/G")); // violates PublisherPublicKeyLocator
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001152 data3.setSignature(signature3);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001153 data3.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001154 BOOST_CHECK_EQUAL(interest.matchesData(data3), false);
1155
Junxiao Shidf4b24e2016-07-14 21:41:43 +00001156 Interest interest3 = interest;
1157 interest3.setPublisherPublicKeyLocator(KeyLocator("ndn:/G"));
1158 BOOST_CHECK_EQUAL(interest3.matchesData(data3), true);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001159
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001160 Data data4 = data;
Yingdi Yubf6a2812014-06-17 15:32:11 -07001161 DigestSha256 signature4; // violates PublisherPublicKeyLocator
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001162 data4.setSignature(signature4);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001163 data4.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001164 BOOST_CHECK_EQUAL(interest.matchesData(data4), false);
1165
Junxiao Shidf4b24e2016-07-14 21:41:43 +00001166 Interest interest4 = interest;
1167 interest4.setPublisherPublicKeyLocator(KeyLocator());
1168 BOOST_CHECK_EQUAL(interest4.matchesData(data4), true);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001169
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001170 Data data5 = data;
Junxiao Shidf4b24e2016-07-14 21:41:43 +00001171 data5.setName("ndn:/A/J"); // violates Exclude
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001172 data5.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001173 BOOST_CHECK_EQUAL(interest.matchesData(data5), false);
1174
Junxiao Shidf4b24e2016-07-14 21:41:43 +00001175 Interest interest5 = interest;
1176 interest5.setExclude(Exclude().excludeAfter(name::Component("K")));
1177 BOOST_CHECK_EQUAL(interest5.matchesData(data5), true);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001178
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001179 Data data6 = data;
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001180 data6.setName("ndn:/H/I"); // violates Name
1181 data6.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001182 BOOST_CHECK_EQUAL(interest.matchesData(data6), false);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001183
1184 Data data7 = data;
1185 data7.setName("ndn:/A/B");
1186 data7.wireEncode();
1187
Junxiao Shidf4b24e2016-07-14 21:41:43 +00001188 Interest interest7("/A/B/sha256digest=D548DECEFC4B880720DC9257A8D815E9DF4465E63742EE55C29133055DAA67C2");
1189 BOOST_CHECK_EQUAL(interest7.matchesData(data7), true);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001190
Junxiao Shidf4b24e2016-07-14 21:41:43 +00001191 Interest interest7b("/A/B/sha256digest=0000000000000000000000000000000000000000000000000000000000000000");
1192 BOOST_CHECK_EQUAL(interest7b.matchesData(data7), false); // violates implicit digest
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001193}
1194
Alexander Afanasyev1013fd02017-01-03 13:19:03 -08001195BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(MatchesInterest, 1)
1196BOOST_AUTO_TEST_CASE(MatchesInterest)
1197{
1198 Interest interest;
1199 interest
1200 .setName("ndn:/A")
1201 .setMinSuffixComponents(2)
1202 .setMaxSuffixComponents(2)
1203 .setPublisherPublicKeyLocator(KeyLocator("ndn:/B"))
1204 .setExclude(Exclude().excludeAfter(name::Component("J")))
1205 .setNonce(10)
1206 .setInterestLifetime(time::seconds(5));
1207
1208 Link link("/A/LINK", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
1209 m_keyChain.sign(link);
1210 interest.setLink(link.wireEncode());
1211
1212 Interest other;
1213 BOOST_CHECK_EQUAL(interest.matchesInterest(other), false);
1214
1215 other.setName(interest.getName());
1216 BOOST_CHECK_EQUAL(interest.matchesInterest(other), false);
1217
1218 // TODO: will match until #3162 implemented
1219 other.setSelectors(interest.getSelectors());
1220 BOOST_CHECK_EQUAL(interest.matchesInterest(other), false);
1221
1222 other.setLink(interest.getLink().wireEncode());
1223 BOOST_CHECK_EQUAL(interest.matchesInterest(other), true);
1224
1225 other.setNonce(200);
1226 BOOST_CHECK_EQUAL(interest.matchesInterest(other), true);
1227
1228 other.setInterestLifetime(time::hours(5));
1229 BOOST_CHECK_EQUAL(interest.matchesInterest(other), true);
1230
1231 other.setSelectedDelegation(0);
1232 BOOST_CHECK_EQUAL(interest.matchesInterest(other), true);
1233}
1234
Alexander Afanasyev90164962014-03-06 08:29:59 +00001235BOOST_AUTO_TEST_CASE(InterestFilterMatching)
1236{
1237 BOOST_CHECK_EQUAL(InterestFilter("/a").doesMatch("/a/b"), true);
1238 BOOST_CHECK_EQUAL(InterestFilter("/a/b").doesMatch("/a/b"), true);
1239 BOOST_CHECK_EQUAL(InterestFilter("/a/b/c").doesMatch("/a/b"), false);
1240
1241 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b"), true);
1242 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b"), false);
1243
1244 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b/c/b"), false);
1245 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<>*<b>").doesMatch("/a/b/c/b"), true);
1246
1247 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b/c/d"), false);
1248 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b/c/d"), true);
1249 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b"), true);
1250 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b"), false);
1251 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b/c"), true);
1252}
1253
Davide Pesaventoeee3e822016-11-26 19:19:34 +01001254BOOST_AUTO_TEST_SUITE_END() // TestInterest
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -08001255
Alexander Afanasyev90164962014-03-06 08:29:59 +00001256} // namespace tests
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -08001257} // namespace ndn