Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * See COPYING for copyright and distribution information. |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include "exclude.hpp" |
| 7 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 8 | #include "boost-test.hpp" |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 9 | |
| 10 | namespace ndn { |
| 11 | |
| 12 | BOOST_AUTO_TEST_SUITE(TestExclude) |
| 13 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 14 | BOOST_AUTO_TEST_CASE(Basic) |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 15 | { |
| 16 | Exclude e; |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 17 | e.excludeOne(name::Component("b")); |
| 18 | BOOST_CHECK_EQUAL(e.size(), 1); |
| 19 | BOOST_CHECK_EQUAL(e.toUri(), "b"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 20 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 21 | e.excludeOne(name::Component("d")); |
| 22 | BOOST_CHECK_EQUAL(e.size(), 2); |
| 23 | BOOST_CHECK_EQUAL(e.toUri(), "b,d"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 24 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 25 | e.excludeOne(name::Component("a")); |
| 26 | BOOST_CHECK_EQUAL(e.size(), 3); |
| 27 | BOOST_CHECK_EQUAL(e.toUri(), "a,b,d"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 28 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 29 | e.excludeOne(name::Component("aa")); |
| 30 | BOOST_CHECK_EQUAL(e.size(), 4); |
| 31 | BOOST_CHECK_EQUAL(e.toUri(), "a,b,d,aa"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 32 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 33 | e.excludeOne(name::Component("cc")); |
| 34 | BOOST_CHECK_EQUAL(e.size(), 5); |
| 35 | BOOST_CHECK_EQUAL(e.toUri(), "a,b,d,aa,cc"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 36 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 37 | 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 Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 40 | } |
| 41 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 42 | BOOST_AUTO_TEST_CASE(Before) |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 43 | { |
| 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 Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 51 | BOOST_AUTO_TEST_CASE(Ranges) |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 52 | { |
| 53 | // example: ANY /b /d ANY /f |
| 54 | |
| 55 | Exclude e; |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 56 | e.excludeOne(name::Component("b0")); |
| 57 | BOOST_CHECK_EQUAL(e.size(), 1); |
| 58 | BOOST_CHECK_EQUAL(e.toUri(), "b0"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 59 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 60 | e.excludeRange(name::Component(), name::Component("b1")); |
| 61 | BOOST_CHECK_EQUAL(e.size(), 2); |
| 62 | BOOST_CHECK_EQUAL(e.toUri(), "*,b1"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 63 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 64 | e.excludeRange(name::Component(), name::Component("c0")); |
| 65 | BOOST_CHECK_EQUAL(e.size(), 2); |
| 66 | BOOST_CHECK_EQUAL(e.toUri(), "*,c0"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 67 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 68 | e.excludeRange(name::Component("a0"), name::Component("c0")); |
| 69 | BOOST_CHECK_EQUAL(e.size(), 2); |
| 70 | BOOST_CHECK_EQUAL(e.toUri(), "*,c0"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 71 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 72 | 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 Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 75 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 76 | 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 Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 79 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 80 | e.excludeRange(name::Component("a1"), name::Component("d1")); |
| 81 | BOOST_CHECK_EQUAL(e.size(), 2); |
| 82 | BOOST_CHECK_EQUAL(e.toUri(), "*,e0"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 83 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 84 | e.excludeBefore(name::Component("e2")); |
| 85 | BOOST_CHECK_EQUAL(e.size(), 2); |
| 86 | BOOST_CHECK_EQUAL(e.toUri(), "*,e2"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 87 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 88 | e.excludeAfter(name::Component("f0")); |
| 89 | BOOST_CHECK_EQUAL(e.size(), 3); |
| 90 | BOOST_CHECK_EQUAL(e.toUri(), "*,e2,f0,*"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 91 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 92 | e.excludeAfter(name::Component("e5")); |
| 93 | BOOST_CHECK_EQUAL(e.size(), 3); |
| 94 | BOOST_CHECK_EQUAL(e.toUri(), "*,e2,e5,*"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 95 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 96 | e.excludeAfter(name::Component("b2")); |
| 97 | BOOST_CHECK_EQUAL(e.size(), 1); |
| 98 | BOOST_CHECK_EQUAL(e.toUri(), "*"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 99 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 100 | BOOST_REQUIRE_THROW(e.excludeRange(name::Component("d0"), name::Component("a0")), Exclude::Error); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | BOOST_AUTO_TEST_SUITE_END() |
| 104 | |
| 105 | } // namespace ndn |