blob: 296d9ab716b9429e05fe98ac17881ac86c5e3aad [file] [log] [blame]
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -08001/**
2 * Copyright (C) 2013 Regents of the University of California.
3 * See COPYING for copyright and distribution information.
Alexander Afanasyev035c7b42014-02-06 18:26:19 -08004 */
5
6#include "exclude.hpp"
7
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07008#include "boost-test.hpp"
Alexander Afanasyev035c7b42014-02-06 18:26:19 -08009
10namespace ndn {
11
12BOOST_AUTO_TEST_SUITE(TestExclude)
13
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070014BOOST_AUTO_TEST_CASE(Basic)
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080015{
16 Exclude e;
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070017 e.excludeOne(name::Component("b"));
18 BOOST_CHECK_EQUAL(e.size(), 1);
19 BOOST_CHECK_EQUAL(e.toUri(), "b");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080020
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070021 e.excludeOne(name::Component("d"));
22 BOOST_CHECK_EQUAL(e.size(), 2);
23 BOOST_CHECK_EQUAL(e.toUri(), "b,d");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080024
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070025 e.excludeOne(name::Component("a"));
26 BOOST_CHECK_EQUAL(e.size(), 3);
27 BOOST_CHECK_EQUAL(e.toUri(), "a,b,d");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080028
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070029 e.excludeOne(name::Component("aa"));
30 BOOST_CHECK_EQUAL(e.size(), 4);
31 BOOST_CHECK_EQUAL(e.toUri(), "a,b,d,aa");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080032
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070033 e.excludeOne(name::Component("cc"));
34 BOOST_CHECK_EQUAL(e.size(), 5);
35 BOOST_CHECK_EQUAL(e.toUri(), "a,b,d,aa,cc");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080036
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070037 e.excludeOne(name::Component("c"));
38 BOOST_CHECK_EQUAL(e.size(), 6);
39 BOOST_CHECK_EQUAL(e.toUri(), "a,b,c,d,aa,cc");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080040}
41
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070042BOOST_AUTO_TEST_CASE(Before)
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080043{
44 // based on http://redmine.named-data.net/issues/1158
45 ndn::Exclude e;
46 BOOST_REQUIRE_NO_THROW(e.excludeBefore(name::Component("PuQxMaf91")));
47
48 BOOST_CHECK_EQUAL(e.toUri(), "*,PuQxMaf91");
49}
50
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070051BOOST_AUTO_TEST_CASE(Ranges)
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080052{
53// example: ANY /b /d ANY /f
54
55 Exclude e;
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070056 e.excludeOne(name::Component("b0"));
57 BOOST_CHECK_EQUAL(e.size(), 1);
58 BOOST_CHECK_EQUAL(e.toUri(), "b0");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080059
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070060 e.excludeRange(name::Component(), name::Component("b1"));
61 BOOST_CHECK_EQUAL(e.size(), 2);
62 BOOST_CHECK_EQUAL(e.toUri(), "*,b1");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080063
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070064 e.excludeRange(name::Component(), name::Component("c0"));
65 BOOST_CHECK_EQUAL(e.size(), 2);
66 BOOST_CHECK_EQUAL(e.toUri(), "*,c0");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080067
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070068 e.excludeRange(name::Component("a0"), name::Component("c0"));
69 BOOST_CHECK_EQUAL(e.size(), 2);
70 BOOST_CHECK_EQUAL(e.toUri(), "*,c0");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080071
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070072 e.excludeRange(name::Component("d0"), name::Component("e0"));
73 BOOST_CHECK_EQUAL(e.size(), 4);
74 BOOST_CHECK_EQUAL(e.toUri(), "*,c0,d0,*,e0");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080075
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070076 e.excludeRange(name::Component("c1"), name::Component("d1"));
77 BOOST_CHECK_EQUAL(e.size(), 4);
78 BOOST_CHECK_EQUAL(e.toUri(), "*,c0,c1,*,e0");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080079
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070080 e.excludeRange(name::Component("a1"), name::Component("d1"));
81 BOOST_CHECK_EQUAL(e.size(), 2);
82 BOOST_CHECK_EQUAL(e.toUri(), "*,e0");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080083
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070084 e.excludeBefore(name::Component("e2"));
85 BOOST_CHECK_EQUAL(e.size(), 2);
86 BOOST_CHECK_EQUAL(e.toUri(), "*,e2");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080087
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070088 e.excludeAfter(name::Component("f0"));
89 BOOST_CHECK_EQUAL(e.size(), 3);
90 BOOST_CHECK_EQUAL(e.toUri(), "*,e2,f0,*");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080091
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070092 e.excludeAfter(name::Component("e5"));
93 BOOST_CHECK_EQUAL(e.size(), 3);
94 BOOST_CHECK_EQUAL(e.toUri(), "*,e2,e5,*");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080095
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070096 e.excludeAfter(name::Component("b2"));
97 BOOST_CHECK_EQUAL(e.size(), 1);
98 BOOST_CHECK_EQUAL(e.toUri(), "*");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080099
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700100 BOOST_REQUIRE_THROW(e.excludeRange(name::Component("d0"), name::Component("a0")), Exclude::Error);
Alexander Afanasyev035c7b42014-02-06 18:26:19 -0800101}
102
103BOOST_AUTO_TEST_SUITE_END()
104
105} // namespace ndn