blob: 1cc708d23478ce7d4f1443eb94c0fdafa6b3cf13 [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/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 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"
23
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070024#include "boost-test.hpp"
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080025
26namespace ndn {
27
28BOOST_AUTO_TEST_SUITE(TestExclude)
29
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070030BOOST_AUTO_TEST_CASE(Basic)
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080031{
32 Exclude e;
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070033 e.excludeOne(name::Component("b"));
34 BOOST_CHECK_EQUAL(e.size(), 1);
35 BOOST_CHECK_EQUAL(e.toUri(), "b");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080036
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070037 e.excludeOne(name::Component("d"));
38 BOOST_CHECK_EQUAL(e.size(), 2);
39 BOOST_CHECK_EQUAL(e.toUri(), "b,d");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080040
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070041 e.excludeOne(name::Component("a"));
42 BOOST_CHECK_EQUAL(e.size(), 3);
43 BOOST_CHECK_EQUAL(e.toUri(), "a,b,d");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080044
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070045 e.excludeOne(name::Component("aa"));
46 BOOST_CHECK_EQUAL(e.size(), 4);
47 BOOST_CHECK_EQUAL(e.toUri(), "a,b,d,aa");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080048
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070049 e.excludeOne(name::Component("cc"));
50 BOOST_CHECK_EQUAL(e.size(), 5);
51 BOOST_CHECK_EQUAL(e.toUri(), "a,b,d,aa,cc");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080052
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070053 e.excludeOne(name::Component("c"));
54 BOOST_CHECK_EQUAL(e.size(), 6);
55 BOOST_CHECK_EQUAL(e.toUri(), "a,b,c,d,aa,cc");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080056}
57
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070058BOOST_AUTO_TEST_CASE(Before)
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080059{
60 // based on http://redmine.named-data.net/issues/1158
61 ndn::Exclude e;
62 BOOST_REQUIRE_NO_THROW(e.excludeBefore(name::Component("PuQxMaf91")));
63
64 BOOST_CHECK_EQUAL(e.toUri(), "*,PuQxMaf91");
65}
66
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070067BOOST_AUTO_TEST_CASE(Ranges)
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080068{
69// example: ANY /b /d ANY /f
70
71 Exclude e;
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070072 e.excludeOne(name::Component("b0"));
73 BOOST_CHECK_EQUAL(e.size(), 1);
74 BOOST_CHECK_EQUAL(e.toUri(), "b0");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080075
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070076 e.excludeRange(name::Component(), name::Component("b1"));
77 BOOST_CHECK_EQUAL(e.size(), 2);
78 BOOST_CHECK_EQUAL(e.toUri(), "*,b1");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080079
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070080 e.excludeRange(name::Component(), name::Component("c0"));
81 BOOST_CHECK_EQUAL(e.size(), 2);
82 BOOST_CHECK_EQUAL(e.toUri(), "*,c0");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080083
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070084 e.excludeRange(name::Component("a0"), name::Component("c0"));
85 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("d0"), name::Component("e0"));
89 BOOST_CHECK_EQUAL(e.size(), 4);
90 BOOST_CHECK_EQUAL(e.toUri(), "*,c0,d0,*,e0");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080091
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070092 e.excludeRange(name::Component("c1"), name::Component("d1"));
93 BOOST_CHECK_EQUAL(e.size(), 4);
94 BOOST_CHECK_EQUAL(e.toUri(), "*,c0,c1,*,e0");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080095
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070096 e.excludeRange(name::Component("a1"), name::Component("d1"));
97 BOOST_CHECK_EQUAL(e.size(), 2);
98 BOOST_CHECK_EQUAL(e.toUri(), "*,e0");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080099
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700100 e.excludeBefore(name::Component("e2"));
101 BOOST_CHECK_EQUAL(e.size(), 2);
102 BOOST_CHECK_EQUAL(e.toUri(), "*,e2");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -0800103
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700104 e.excludeAfter(name::Component("f0"));
105 BOOST_CHECK_EQUAL(e.size(), 3);
106 BOOST_CHECK_EQUAL(e.toUri(), "*,e2,f0,*");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -0800107
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700108 e.excludeAfter(name::Component("e5"));
109 BOOST_CHECK_EQUAL(e.size(), 3);
110 BOOST_CHECK_EQUAL(e.toUri(), "*,e2,e5,*");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -0800111
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700112 e.excludeAfter(name::Component("b2"));
113 BOOST_CHECK_EQUAL(e.size(), 1);
114 BOOST_CHECK_EQUAL(e.toUri(), "*");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -0800115
Junxiao Shi75203022014-09-11 10:01:50 -0700116 BOOST_REQUIRE_THROW(e.excludeRange(name::Component("d0"), name::Component("a0")),
117 Exclude::Error);
Alexander Afanasyev035c7b42014-02-06 18:26:19 -0800118}
119
120BOOST_AUTO_TEST_SUITE_END()
121
122} // namespace ndn