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 | |
| 8 | #include <boost/test/unit_test.hpp> |
| 9 | |
| 10 | namespace ndn { |
| 11 | |
| 12 | BOOST_AUTO_TEST_SUITE(TestExclude) |
| 13 | |
| 14 | BOOST_AUTO_TEST_CASE (Basic) |
| 15 | { |
| 16 | Exclude e; |
| 17 | e.excludeOne (name::Component("b")); |
| 18 | BOOST_CHECK_EQUAL (e.size (), 1); |
| 19 | BOOST_CHECK_EQUAL (e.toUri(), "b"); |
| 20 | |
| 21 | e.excludeOne (name::Component("d")); |
| 22 | BOOST_CHECK_EQUAL (e.size (), 2); |
| 23 | BOOST_CHECK_EQUAL (e.toUri(), "b,d"); |
| 24 | |
| 25 | e.excludeOne (name::Component("a")); |
| 26 | BOOST_CHECK_EQUAL (e.size (), 3); |
| 27 | BOOST_CHECK_EQUAL (e.toUri(), "a,b,d"); |
| 28 | |
| 29 | e.excludeOne (name::Component("aa")); |
| 30 | BOOST_CHECK_EQUAL (e.size (), 4); |
| 31 | BOOST_CHECK_EQUAL (e.toUri(), "a,b,d,aa"); |
| 32 | |
| 33 | e.excludeOne (name::Component("cc")); |
| 34 | BOOST_CHECK_EQUAL (e.size (), 5); |
| 35 | BOOST_CHECK_EQUAL (e.toUri(), "a,b,d,aa,cc"); |
| 36 | |
| 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"); |
| 40 | } |
| 41 | |
| 42 | BOOST_AUTO_TEST_CASE (Before) |
| 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 | |
| 51 | BOOST_AUTO_TEST_CASE (Ranges) |
| 52 | { |
| 53 | // example: ANY /b /d ANY /f |
| 54 | |
| 55 | Exclude e; |
| 56 | e.excludeOne (name::Component ("b0")); |
| 57 | BOOST_CHECK_EQUAL (e.size (), 1); |
| 58 | BOOST_CHECK_EQUAL (e.toUri(), "b0"); |
| 59 | |
| 60 | e.excludeRange (name::Component (), name::Component ("b1")); |
| 61 | BOOST_CHECK_EQUAL (e.size (), 2); |
| 62 | BOOST_CHECK_EQUAL (e.toUri(), "*,b1"); |
| 63 | |
| 64 | e.excludeRange (name::Component (), name::Component("c0")); |
| 65 | BOOST_CHECK_EQUAL (e.size (), 2); |
| 66 | BOOST_CHECK_EQUAL (e.toUri(), "*,c0"); |
| 67 | |
| 68 | e.excludeRange (name::Component("a0"), name::Component("c0")); |
| 69 | BOOST_CHECK_EQUAL (e.size (), 2); |
| 70 | BOOST_CHECK_EQUAL (e.toUri(), "*,c0"); |
| 71 | |
| 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"); |
| 75 | |
| 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"); |
| 79 | |
| 80 | e.excludeRange (name::Component("a1"), name::Component("d1")); |
| 81 | BOOST_CHECK_EQUAL (e.size (), 2); |
| 82 | BOOST_CHECK_EQUAL (e.toUri(), "*,e0"); |
| 83 | |
| 84 | e.excludeBefore (name::Component("e2")); |
| 85 | BOOST_CHECK_EQUAL (e.size (), 2); |
| 86 | BOOST_CHECK_EQUAL (e.toUri(), "*,e2"); |
| 87 | |
| 88 | e.excludeAfter (name::Component("f0")); |
| 89 | BOOST_CHECK_EQUAL (e.size (), 3); |
| 90 | BOOST_CHECK_EQUAL (e.toUri(), "*,e2,f0,*"); |
| 91 | |
| 92 | e.excludeAfter (name::Component("e5")); |
| 93 | BOOST_CHECK_EQUAL (e.size (), 3); |
| 94 | BOOST_CHECK_EQUAL (e.toUri(), "*,e2,e5,*"); |
| 95 | |
| 96 | e.excludeAfter (name::Component("b2")); |
| 97 | BOOST_CHECK_EQUAL (e.size (), 1); |
| 98 | BOOST_CHECK_EQUAL (e.toUri(), "*"); |
| 99 | |
| 100 | BOOST_REQUIRE_THROW (e.excludeRange (name::Component("d0"), name::Component("a0")), Exclude::Error); |
| 101 | } |
| 102 | |
| 103 | BOOST_AUTO_TEST_SUITE_END() |
| 104 | |
| 105 | } // namespace ndn |