blob: d4955dd7b2201dc51c5ff183cdbc1e17ca58682e [file] [log] [blame]
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -08002/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * 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 Afanasyev035c7b42014-02-06 18:26:19 -080011 */
12
13#include "exclude.hpp"
14
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070015#include "boost-test.hpp"
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080016
17namespace ndn {
18
19BOOST_AUTO_TEST_SUITE(TestExclude)
20
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070021BOOST_AUTO_TEST_CASE(Basic)
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080022{
23 Exclude e;
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070024 e.excludeOne(name::Component("b"));
25 BOOST_CHECK_EQUAL(e.size(), 1);
26 BOOST_CHECK_EQUAL(e.toUri(), "b");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080027
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070028 e.excludeOne(name::Component("d"));
29 BOOST_CHECK_EQUAL(e.size(), 2);
30 BOOST_CHECK_EQUAL(e.toUri(), "b,d");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080031
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070032 e.excludeOne(name::Component("a"));
33 BOOST_CHECK_EQUAL(e.size(), 3);
34 BOOST_CHECK_EQUAL(e.toUri(), "a,b,d");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080035
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070036 e.excludeOne(name::Component("aa"));
37 BOOST_CHECK_EQUAL(e.size(), 4);
38 BOOST_CHECK_EQUAL(e.toUri(), "a,b,d,aa");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080039
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070040 e.excludeOne(name::Component("cc"));
41 BOOST_CHECK_EQUAL(e.size(), 5);
42 BOOST_CHECK_EQUAL(e.toUri(), "a,b,d,aa,cc");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080043
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070044 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 Afanasyev035c7b42014-02-06 18:26:19 -080047}
48
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070049BOOST_AUTO_TEST_CASE(Before)
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080050{
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 Afanasyevb1db7c62014-04-03 14:57:25 -070058BOOST_AUTO_TEST_CASE(Ranges)
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080059{
60// example: ANY /b /d ANY /f
61
62 Exclude e;
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070063 e.excludeOne(name::Component("b0"));
64 BOOST_CHECK_EQUAL(e.size(), 1);
65 BOOST_CHECK_EQUAL(e.toUri(), "b0");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080066
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070067 e.excludeRange(name::Component(), name::Component("b1"));
68 BOOST_CHECK_EQUAL(e.size(), 2);
69 BOOST_CHECK_EQUAL(e.toUri(), "*,b1");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080070
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070071 e.excludeRange(name::Component(), name::Component("c0"));
72 BOOST_CHECK_EQUAL(e.size(), 2);
73 BOOST_CHECK_EQUAL(e.toUri(), "*,c0");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080074
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070075 e.excludeRange(name::Component("a0"), name::Component("c0"));
76 BOOST_CHECK_EQUAL(e.size(), 2);
77 BOOST_CHECK_EQUAL(e.toUri(), "*,c0");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080078
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070079 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 Afanasyev035c7b42014-02-06 18:26:19 -080082
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070083 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 Afanasyev035c7b42014-02-06 18:26:19 -080086
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070087 e.excludeRange(name::Component("a1"), name::Component("d1"));
88 BOOST_CHECK_EQUAL(e.size(), 2);
89 BOOST_CHECK_EQUAL(e.toUri(), "*,e0");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080090
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070091 e.excludeBefore(name::Component("e2"));
92 BOOST_CHECK_EQUAL(e.size(), 2);
93 BOOST_CHECK_EQUAL(e.toUri(), "*,e2");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080094
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070095 e.excludeAfter(name::Component("f0"));
96 BOOST_CHECK_EQUAL(e.size(), 3);
97 BOOST_CHECK_EQUAL(e.toUri(), "*,e2,f0,*");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -080098
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070099 e.excludeAfter(name::Component("e5"));
100 BOOST_CHECK_EQUAL(e.size(), 3);
101 BOOST_CHECK_EQUAL(e.toUri(), "*,e2,e5,*");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -0800102
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700103 e.excludeAfter(name::Component("b2"));
104 BOOST_CHECK_EQUAL(e.size(), 1);
105 BOOST_CHECK_EQUAL(e.toUri(), "*");
Alexander Afanasyev035c7b42014-02-06 18:26:19 -0800106
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700107 BOOST_REQUIRE_THROW(e.excludeRange(name::Component("d0"), name::Component("a0")), Exclude::Error);
Alexander Afanasyev035c7b42014-02-06 18:26:19 -0800108}
109
110BOOST_AUTO_TEST_SUITE_END()
111
112} // namespace ndn