blob: 843faddae1c2e1599d4a812520713c245be15d96 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -08002/**
Junxiao Shidf4b24e2016-07-14 21:41:43 +00003 * Copyright (c) 2013-2016 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 Afanasyev035c7b42014-02-06 18:26:19 -080020 */
21
22#include "exclude.hpp"
Junxiao Shidf4b24e2016-07-14 21:41:43 +000023#include "util/crypto.hpp"
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080024
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070025#include "boost-test.hpp"
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080026
27namespace ndn {
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080028namespace tests {
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080029
30BOOST_AUTO_TEST_SUITE(TestExclude)
31
Junxiao Shidf4b24e2016-07-14 21:41:43 +000032BOOST_AUTO_TEST_SUITE(GenericComponent) // exclude generic NameComponent
33
34BOOST_AUTO_TEST_CASE(One)
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080035{
36 Exclude e;
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070037 e.excludeOne(name::Component("b"));
38 BOOST_CHECK_EQUAL(e.size(), 1);
39 BOOST_CHECK_EQUAL(e.toUri(), "b");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080040
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070041 e.excludeOne(name::Component("d"));
42 BOOST_CHECK_EQUAL(e.size(), 2);
43 BOOST_CHECK_EQUAL(e.toUri(), "b,d");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080044
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070045 e.excludeOne(name::Component("a"));
46 BOOST_CHECK_EQUAL(e.size(), 3);
47 BOOST_CHECK_EQUAL(e.toUri(), "a,b,d");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080048
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070049 e.excludeOne(name::Component("aa"));
50 BOOST_CHECK_EQUAL(e.size(), 4);
51 BOOST_CHECK_EQUAL(e.toUri(), "a,b,d,aa");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080052
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070053 e.excludeOne(name::Component("cc"));
54 BOOST_CHECK_EQUAL(e.size(), 5);
55 BOOST_CHECK_EQUAL(e.toUri(), "a,b,d,aa,cc");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080056
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070057 e.excludeOne(name::Component("c"));
58 BOOST_CHECK_EQUAL(e.size(), 6);
59 BOOST_CHECK_EQUAL(e.toUri(), "a,b,c,d,aa,cc");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080060}
61
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070062BOOST_AUTO_TEST_CASE(Before)
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080063{
64 // based on http://redmine.named-data.net/issues/1158
65 ndn::Exclude e;
66 BOOST_REQUIRE_NO_THROW(e.excludeBefore(name::Component("PuQxMaf91")));
67
68 BOOST_CHECK_EQUAL(e.toUri(), "*,PuQxMaf91");
69}
70
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070071BOOST_AUTO_TEST_CASE(Ranges)
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080072{
Junxiao Shidf4b24e2016-07-14 21:41:43 +000073 // example: ANY /b /d ANY /f
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080074
75 Exclude e;
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070076 e.excludeOne(name::Component("b0"));
77 BOOST_CHECK_EQUAL(e.size(), 1);
78 BOOST_CHECK_EQUAL(e.toUri(), "b0");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080079
Junxiao Shidf4b24e2016-07-14 21:41:43 +000080 e.excludeBefore(name::Component("b1"));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070081 BOOST_CHECK_EQUAL(e.size(), 2);
82 BOOST_CHECK_EQUAL(e.toUri(), "*,b1");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080083
Junxiao Shidf4b24e2016-07-14 21:41:43 +000084 e.excludeBefore(name::Component("c0"));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070085 BOOST_CHECK_EQUAL(e.size(), 2);
86 BOOST_CHECK_EQUAL(e.toUri(), "*,c0");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080087
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070088 e.excludeRange(name::Component("a0"), name::Component("c0"));
89 BOOST_CHECK_EQUAL(e.size(), 2);
90 BOOST_CHECK_EQUAL(e.toUri(), "*,c0");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080091
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070092 e.excludeRange(name::Component("d0"), name::Component("e0"));
93 BOOST_CHECK_EQUAL(e.size(), 4);
94 BOOST_CHECK_EQUAL(e.toUri(), "*,c0,d0,*,e0");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080095
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070096 e.excludeRange(name::Component("c1"), name::Component("d1"));
97 BOOST_CHECK_EQUAL(e.size(), 4);
98 BOOST_CHECK_EQUAL(e.toUri(), "*,c0,c1,*,e0");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080099
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700100 e.excludeRange(name::Component("a1"), name::Component("d1"));
101 BOOST_CHECK_EQUAL(e.size(), 2);
102 BOOST_CHECK_EQUAL(e.toUri(), "*,e0");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -0800103
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700104 e.excludeBefore(name::Component("e2"));
105 BOOST_CHECK_EQUAL(e.size(), 2);
106 BOOST_CHECK_EQUAL(e.toUri(), "*,e2");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -0800107
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700108 e.excludeAfter(name::Component("f0"));
109 BOOST_CHECK_EQUAL(e.size(), 3);
110 BOOST_CHECK_EQUAL(e.toUri(), "*,e2,f0,*");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -0800111
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700112 e.excludeAfter(name::Component("e5"));
113 BOOST_CHECK_EQUAL(e.size(), 3);
114 BOOST_CHECK_EQUAL(e.toUri(), "*,e2,e5,*");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -0800115
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700116 e.excludeAfter(name::Component("b2"));
117 BOOST_CHECK_EQUAL(e.size(), 1);
118 BOOST_CHECK_EQUAL(e.toUri(), "*");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -0800119
Junxiao Shi75203022014-09-11 10:01:50 -0700120 BOOST_REQUIRE_THROW(e.excludeRange(name::Component("d0"), name::Component("a0")),
121 Exclude::Error);
Alexander Afanasyev035c7b42014-02-06 18:26:19 -0800122}
123
Junxiao Shidf4b24e2016-07-14 21:41:43 +0000124BOOST_AUTO_TEST_SUITE_END() // GenericComponent
125
126
127BOOST_AUTO_TEST_SUITE(ImplicitDigest) // exclude ImplicitSha256DigestComponent
128
129/** \brief make a name::Component with an octet repeated crypto::SHA256_DIGEST_SIZE times
130 * \param octet the octet to fill the component
131 * \param isDigest whether to make an ImplicitSha256DigestComponent or a generic NameComponent
132 * \param lastOctet if non-negative, set the last octet to a different value
133 */
134static name::Component
135makeComponent(uint8_t octet, bool isDigest, int lastOctet = -1)
136{
137 uint8_t wire[crypto::SHA256_DIGEST_SIZE];
138 std::memset(wire, octet, sizeof(wire));
139 if (lastOctet >= 0) {
140 wire[crypto::SHA256_DIGEST_SIZE - 1] = static_cast<uint8_t>(lastOctet);
141 }
142
143 if (isDigest) {
144 return name::Component::fromImplicitSha256Digest(wire, sizeof(wire));
145 }
146 else {
147 return name::Component(wire, sizeof(wire));
148 }
149}
150
151BOOST_AUTO_TEST_CASE(One)
152{
153 name::Component digestC = makeComponent(0xCC, true);;
154 name::Component genericC = makeComponent(0xCC, false);
155 name::Component digestD = makeComponent(0xDD, true);
156
157 Exclude e;
158 e.excludeOne(digestC);
159 BOOST_CHECK_EQUAL(e.isExcluded(digestC), true);
160 BOOST_CHECK_EQUAL(e.isExcluded(genericC), false);
161 BOOST_CHECK_EQUAL(e.isExcluded(digestD), false);
162
163 e.clear();
164 e.excludeOne(genericC);
165 BOOST_CHECK_EQUAL(e.isExcluded(digestC), false);
166 BOOST_CHECK_EQUAL(e.isExcluded(genericC), true);
167}
168
169BOOST_AUTO_TEST_CASE(BeforeDigest)
170{
171 name::Component digestBA = makeComponent(0xBB, true, 0xBA);
172 name::Component digestBB = makeComponent(0xBB, true);
173 name::Component digestBC = makeComponent(0xBB, true, 0xBC);
174
175 Exclude e;
176 e.excludeBefore(digestBB);
177 BOOST_CHECK_EQUAL(e.isExcluded(digestBA), true);
178 BOOST_CHECK_EQUAL(e.isExcluded(digestBB), true);
179 BOOST_CHECK_EQUAL(e.isExcluded(digestBC), false);
180 BOOST_CHECK_EQUAL(e.isExcluded(name::Component("")), false);
181 BOOST_CHECK_EQUAL(e.isExcluded(name::Component("generic")), false);
182}
183
184BOOST_AUTO_TEST_CASE(BeforeGeneric)
185{
186 name::Component digest0 = makeComponent(0x00, true);
187 name::Component digest9 = makeComponent(0x99, true);
188 name::Component digestF = makeComponent(0xFF, true);
189
190 Exclude e;
191 e.excludeBefore(name::Component(""));
192 BOOST_CHECK_EQUAL(e.isExcluded(digest0), true);
193 BOOST_CHECK_EQUAL(e.isExcluded(digest9), true);
194 BOOST_CHECK_EQUAL(e.isExcluded(digestF), true);
195 BOOST_CHECK_EQUAL(e.isExcluded(name::Component("")), true);
196 BOOST_CHECK_EQUAL(e.isExcluded(name::Component("generic")), false);
197}
198
199BOOST_AUTO_TEST_CASE(AfterDigest)
200{
201 name::Component digestBA = makeComponent(0xBB, true, 0xBA);
202 name::Component digestBB = makeComponent(0xBB, true);
203 name::Component digestBC = makeComponent(0xBB, true, 0xBC);
204
205 Exclude e;
206 e.excludeAfter(digestBB);
207 BOOST_CHECK_EQUAL(e.isExcluded(digestBA), false);
208 BOOST_CHECK_EQUAL(e.isExcluded(digestBB), true);
209 BOOST_CHECK_EQUAL(e.isExcluded(digestBC), true);
210 BOOST_CHECK_EQUAL(e.isExcluded(name::Component("")), true);
211 BOOST_CHECK_EQUAL(e.isExcluded(name::Component("generic")), true);
212}
213
214BOOST_AUTO_TEST_CASE(AfterDigestFF)
215{
216 name::Component digest00 = makeComponent(0x00, true);
217 name::Component digest99 = makeComponent(0x99, true);
218 name::Component digestFE = makeComponent(0xFF, true, 0xFE);
219 name::Component digestFF = makeComponent(0xFF, true);
220
221 Exclude e;
222 e.excludeAfter(digestFF);
223 BOOST_CHECK_EQUAL(e.isExcluded(digest00), false);
224 BOOST_CHECK_EQUAL(e.isExcluded(digest99), false);
225 BOOST_CHECK_EQUAL(e.isExcluded(digestFE), false);
226 BOOST_CHECK_EQUAL(e.isExcluded(digestFF), true);
227 BOOST_CHECK_EQUAL(e.isExcluded(name::Component("")), true);
228 BOOST_CHECK_EQUAL(e.isExcluded(name::Component("generic")), true);
229}
230
231BOOST_AUTO_TEST_CASE(AfterGeneric)
232{
233 name::Component digest0 = makeComponent(0x00, true);
234 name::Component digest9 = makeComponent(0x99, true);
235 name::Component digestF = makeComponent(0xFF, true);
236
237 Exclude e;
238 e.excludeAfter(name::Component(""));
239 BOOST_CHECK_EQUAL(e.isExcluded(digest0), false);
240 BOOST_CHECK_EQUAL(e.isExcluded(digest9), false);
241 BOOST_CHECK_EQUAL(e.isExcluded(digestF), false);
242 BOOST_CHECK_EQUAL(e.isExcluded(name::Component("")), true);
243 BOOST_CHECK_EQUAL(e.isExcluded(name::Component("generic")), true);
244}
245
246BOOST_AUTO_TEST_CASE(RangeDigest)
247{
248 name::Component digest0 = makeComponent(0x00, true);
249 name::Component digest7 = makeComponent(0x77, true);
250 name::Component digest8 = makeComponent(0x88, true);
251 name::Component digest9 = makeComponent(0x99, true);
252 name::Component digestF = makeComponent(0xFF, true);
253
254 Exclude e;
255 e.excludeRange(digest7, digest9);
256 BOOST_CHECK_EQUAL(e.isExcluded(digest0), false);
257 BOOST_CHECK_EQUAL(e.isExcluded(digest7), true);
258 BOOST_CHECK_EQUAL(e.isExcluded(digest8), true);
259 BOOST_CHECK_EQUAL(e.isExcluded(digest9), true);
260 BOOST_CHECK_EQUAL(e.isExcluded(digestF), false);
261 BOOST_CHECK_EQUAL(e.isExcluded(name::Component("")), false);
262 BOOST_CHECK_EQUAL(e.isExcluded(name::Component("generic")), false);
263}
264
265BOOST_AUTO_TEST_CASE(RangeDigestReverse)
266{
267 name::Component digest7 = makeComponent(0x77, true);
268 name::Component digest9 = makeComponent(0x99, true);
269
270 Exclude e;
271 BOOST_CHECK_THROW(e.excludeRange(digest9, digest7), Exclude::Error);
272}
273
274BOOST_AUTO_TEST_CASE(RangeDigestGeneric)
275{
276 name::Component digest0 = makeComponent(0x00, true);
277 name::Component digest7 = makeComponent(0x77, true);
278 name::Component digest9 = makeComponent(0x99, true);
279 name::Component digestF = makeComponent(0xFF, true);
280
281 Exclude e;
282 e.excludeRange(digest9, name::Component(""));
283 BOOST_CHECK_EQUAL(e.isExcluded(digest0), false);
284 BOOST_CHECK_EQUAL(e.isExcluded(digest7), false);
285 BOOST_CHECK_EQUAL(e.isExcluded(digest9), true);
286 BOOST_CHECK_EQUAL(e.isExcluded(digestF), true);
287 BOOST_CHECK_EQUAL(e.isExcluded(name::Component("")), true);
288 BOOST_CHECK_EQUAL(e.isExcluded(name::Component("generic")), false);
289}
290
291BOOST_AUTO_TEST_CASE(RangeGenericDigest)
292{
293 name::Component digestF = makeComponent(0xFF, true);
294
295 Exclude e;
296 BOOST_CHECK_THROW(e.excludeRange(name::Component(""), digestF), Exclude::Error);
297}
298
299BOOST_AUTO_TEST_SUITE_END() // ImplicitDigest
300
301
302BOOST_AUTO_TEST_SUITE(WireCompare) // wireEncode, wireDecode, operator==, operator!=
303
304BOOST_AUTO_TEST_CASE(EqualityComparable)
305{
306 Exclude e1;
307 Exclude e2;
308 BOOST_CHECK_EQUAL(e1, e2);
309
310 e1.excludeOne(name::Component("T"));
311 BOOST_CHECK_NE(e1, e2);
312
313 e2.excludeOne(name::Component("D"));
314 BOOST_CHECK_NE(e1, e2);
315
316 e2.clear();
317 e2.excludeOne(name::Component("T"));
318 BOOST_CHECK_EQUAL(e1, e2);
319
320 e2.clear();
321 const uint8_t EXCLUDE[] = { 0x10, 0x15, 0x13, 0x00, 0x08, 0x01, 0x41, 0x08, 0x01, 0x42,
322 0x08, 0x01, 0x43, 0x13, 0x00, 0x08, 0x01, 0x44, 0x08, 0x01,
323 0x45, 0x13, 0x00 };
324 e2.wireDecode(Block(EXCLUDE, sizeof(EXCLUDE)));
325
326 e1.clear();
327 e1.excludeBefore(name::Component("A"));
328 e1.excludeOne(name::Component("B"));
329 e1.excludeRange(name::Component("C"), name::Component("D"));
330 e1.excludeAfter(name::Component("E"));
331 BOOST_CHECK_EQUAL(e1, e2);
332}
333
Junxiao Shi7284a402014-09-12 13:42:16 -0700334BOOST_AUTO_TEST_CASE(Malformed)
335{
336 Exclude e1;
337 BOOST_CHECK_THROW(e1.wireEncode(), Exclude::Error);
338
339 Exclude e2;
340
341 // top-level TLV-TYPE is not tlv::Exclude
342 const uint8_t NON_EXCLUDE[] = { 0x01, 0x02, 0x13, 0x00 };
343 BOOST_CHECK_THROW(e2.wireDecode(Block(NON_EXCLUDE, sizeof(NON_EXCLUDE))),
344 tlv::Error);
345
346 // Exclude element is empty
347 const uint8_t EMPTY_EXCLUDE[] = { 0x10, 0x00 };
348 BOOST_CHECK_THROW(e2.wireDecode(Block(EMPTY_EXCLUDE, sizeof(EMPTY_EXCLUDE))),
349 Exclude::Error);
350
351 // Exclude element contains unknown element
352 const uint8_t UNKNOWN_COMP1[] = { 0x10, 0x02, 0xAA, 0x00 };
353 BOOST_CHECK_THROW(e2.wireDecode(Block(UNKNOWN_COMP1, sizeof(UNKNOWN_COMP1))),
354 Exclude::Error);
355
356 // Exclude element contains unknown element
357 const uint8_t UNKNOWN_COMP2[] = { 0x10, 0x05, 0x08, 0x01, 0x54, 0xAA, 0x00 };
358 BOOST_CHECK_THROW(e2.wireDecode(Block(UNKNOWN_COMP2, sizeof(UNKNOWN_COMP2))),
359 Exclude::Error);
360
361 // // <Exclude><Any/></Exclude>
362 // const uint8_t ONLY_ANY[] = { 0x10, 0x02, 0x13, 0x00 };
363 // BOOST_CHECK_THROW(e2.wireDecode(Block(ONLY_ANY, sizeof(ONLY_ANY))),
364 // Exclude::Error);
365
366 // <Exclude><Any/><Any/></Exclude>
367 const uint8_t ANY_ANY[] = { 0x10, 0x04, 0x13, 0x00, 0x13, 0x00 };
368 BOOST_CHECK_THROW(e2.wireDecode(Block(ANY_ANY, sizeof(ANY_ANY))),
369 Exclude::Error);
370
371 // // <Exclude><Any/><NameComponent>T</NameComponent><Any/></Exclude>
372 // const uint8_t ANY_COMPONENT_ANY[] = { 0x10, 0x07, 0x13, 0x00, 0x08, 0x01, 0x54, 0x13, 0x00 };
373 // BOOST_CHECK_THROW(e2.wireDecode(Block(ANY_COMPONENT_ANY, sizeof(ANY_COMPONENT_ANY))),
374 // Exclude::Error);
Ilya Moiseenko741771f2015-03-10 16:53:44 -0700375
376 uint8_t WIRE[] = {
377 0x10, 0x20, // Exclude
378 0x01, 0x1E, // ImplicitSha256DigestComponent with incorrect length
379 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
380 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
381 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
382 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd
383 };
384
385 BOOST_CHECK_THROW(Exclude().wireDecode(Block(WIRE, sizeof(WIRE))), Exclude::Error);
386}
387
388BOOST_AUTO_TEST_CASE(ImplicitSha256Digest)
389{
390 uint8_t WIRE[] = {
391 0x10, 0x22, // Exclude
392 0x01, 0x20, // ImplicitSha256DigestComponent
393 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
394 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
395 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
396 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd
397 };
398
399 Block block(WIRE, sizeof(WIRE));
400
401 Exclude exclude;
402 BOOST_CHECK_NO_THROW(exclude.wireDecode(block));
Junxiao Shidf4b24e2016-07-14 21:41:43 +0000403 BOOST_CHECK(exclude.wireEncode() == block);
Junxiao Shi7284a402014-09-12 13:42:16 -0700404}
405
Junxiao Shidf4b24e2016-07-14 21:41:43 +0000406BOOST_AUTO_TEST_CASE(EmptyComponent) // Bug #2660
Alexander Afanasyevc076e6d2015-04-02 20:07:13 -0700407{
408 Exclude e1, e2;
409
410 e1.excludeOne(name::Component());
411 e2.excludeOne(name::Component(""));
412
413 BOOST_CHECK_EQUAL(e1, e2);
414 BOOST_CHECK_EQUAL(e1.toUri(), e2.toUri());
415 BOOST_CHECK(e1.wireEncode() == e2.wireEncode());
416
417 BOOST_CHECK_EQUAL("...", e1.toUri());
418
419 uint8_t WIRE[] {0x10, 0x02, 0x08, 0x00};
420 BOOST_CHECK_EQUAL_COLLECTIONS(e1.wireEncode().begin(), e1.wireEncode().end(),
421 WIRE, WIRE + sizeof(WIRE));
422
423 Exclude e3(Block(WIRE, sizeof(WIRE)));
424 BOOST_CHECK_EQUAL(e1, e3);
425 BOOST_CHECK_EQUAL(e1.toUri(), e3.toUri());
426}
427
Junxiao Shidf4b24e2016-07-14 21:41:43 +0000428BOOST_AUTO_TEST_SUITE_END() // WireCompare
429
Alexander Afanasyev035c7b42014-02-06 18:26:19 -0800430BOOST_AUTO_TEST_SUITE_END()
431
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800432} // namespace tests
Alexander Afanasyev035c7b42014-02-06 18:26:19 -0800433} // namespace ndn