Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2013-2014, Regents of the University of California. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 7 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 8 | * |
| 9 | * This file licensed under New BSD License. See COPYING for detailed information about |
| 10 | * ndn-cxx library copyright, permissions, and redistribution restrictions. |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include "exclude.hpp" |
| 14 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 15 | #include "boost-test.hpp" |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 16 | |
| 17 | namespace ndn { |
| 18 | |
| 19 | BOOST_AUTO_TEST_SUITE(TestExclude) |
| 20 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 21 | BOOST_AUTO_TEST_CASE(Basic) |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 22 | { |
| 23 | Exclude e; |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 24 | e.excludeOne(name::Component("b")); |
| 25 | BOOST_CHECK_EQUAL(e.size(), 1); |
| 26 | BOOST_CHECK_EQUAL(e.toUri(), "b"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 27 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 28 | e.excludeOne(name::Component("d")); |
| 29 | BOOST_CHECK_EQUAL(e.size(), 2); |
| 30 | BOOST_CHECK_EQUAL(e.toUri(), "b,d"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 31 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 32 | e.excludeOne(name::Component("a")); |
| 33 | BOOST_CHECK_EQUAL(e.size(), 3); |
| 34 | BOOST_CHECK_EQUAL(e.toUri(), "a,b,d"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 35 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 36 | e.excludeOne(name::Component("aa")); |
| 37 | BOOST_CHECK_EQUAL(e.size(), 4); |
| 38 | BOOST_CHECK_EQUAL(e.toUri(), "a,b,d,aa"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 39 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 40 | e.excludeOne(name::Component("cc")); |
| 41 | BOOST_CHECK_EQUAL(e.size(), 5); |
| 42 | BOOST_CHECK_EQUAL(e.toUri(), "a,b,d,aa,cc"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 43 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 44 | e.excludeOne(name::Component("c")); |
| 45 | BOOST_CHECK_EQUAL(e.size(), 6); |
| 46 | BOOST_CHECK_EQUAL(e.toUri(), "a,b,c,d,aa,cc"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 47 | } |
| 48 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 49 | BOOST_AUTO_TEST_CASE(Before) |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 50 | { |
| 51 | // based on http://redmine.named-data.net/issues/1158 |
| 52 | ndn::Exclude e; |
| 53 | BOOST_REQUIRE_NO_THROW(e.excludeBefore(name::Component("PuQxMaf91"))); |
| 54 | |
| 55 | BOOST_CHECK_EQUAL(e.toUri(), "*,PuQxMaf91"); |
| 56 | } |
| 57 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 58 | BOOST_AUTO_TEST_CASE(Ranges) |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 59 | { |
| 60 | // example: ANY /b /d ANY /f |
| 61 | |
| 62 | Exclude e; |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 63 | e.excludeOne(name::Component("b0")); |
| 64 | BOOST_CHECK_EQUAL(e.size(), 1); |
| 65 | BOOST_CHECK_EQUAL(e.toUri(), "b0"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 66 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 67 | e.excludeRange(name::Component(), name::Component("b1")); |
| 68 | BOOST_CHECK_EQUAL(e.size(), 2); |
| 69 | BOOST_CHECK_EQUAL(e.toUri(), "*,b1"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 70 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 71 | e.excludeRange(name::Component(), name::Component("c0")); |
| 72 | BOOST_CHECK_EQUAL(e.size(), 2); |
| 73 | BOOST_CHECK_EQUAL(e.toUri(), "*,c0"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 74 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 75 | e.excludeRange(name::Component("a0"), name::Component("c0")); |
| 76 | BOOST_CHECK_EQUAL(e.size(), 2); |
| 77 | BOOST_CHECK_EQUAL(e.toUri(), "*,c0"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 78 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 79 | e.excludeRange(name::Component("d0"), name::Component("e0")); |
| 80 | BOOST_CHECK_EQUAL(e.size(), 4); |
| 81 | BOOST_CHECK_EQUAL(e.toUri(), "*,c0,d0,*,e0"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 82 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 83 | e.excludeRange(name::Component("c1"), name::Component("d1")); |
| 84 | BOOST_CHECK_EQUAL(e.size(), 4); |
| 85 | BOOST_CHECK_EQUAL(e.toUri(), "*,c0,c1,*,e0"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 86 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 87 | e.excludeRange(name::Component("a1"), name::Component("d1")); |
| 88 | BOOST_CHECK_EQUAL(e.size(), 2); |
| 89 | BOOST_CHECK_EQUAL(e.toUri(), "*,e0"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 90 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 91 | e.excludeBefore(name::Component("e2")); |
| 92 | BOOST_CHECK_EQUAL(e.size(), 2); |
| 93 | BOOST_CHECK_EQUAL(e.toUri(), "*,e2"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 94 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 95 | e.excludeAfter(name::Component("f0")); |
| 96 | BOOST_CHECK_EQUAL(e.size(), 3); |
| 97 | BOOST_CHECK_EQUAL(e.toUri(), "*,e2,f0,*"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 98 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 99 | e.excludeAfter(name::Component("e5")); |
| 100 | BOOST_CHECK_EQUAL(e.size(), 3); |
| 101 | BOOST_CHECK_EQUAL(e.toUri(), "*,e2,e5,*"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 102 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 103 | e.excludeAfter(name::Component("b2")); |
| 104 | BOOST_CHECK_EQUAL(e.size(), 1); |
| 105 | BOOST_CHECK_EQUAL(e.toUri(), "*"); |
Alexander Afanasyev | 035c7b4 | 2014-02-06 18:26:19 -0800 | [diff] [blame] | 106 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 107 | 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] | 108 | } |
| 109 | |
| 110 | BOOST_AUTO_TEST_SUITE_END() |
| 111 | |
| 112 | } // namespace ndn |