blob: 6f7f306490b05f28e6f7d53c7c8ca39b4233ec3a [file] [log] [blame]
Alexander Afanasyev035c7b42014-02-06 18:26:19 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Alexander Afanasyev
5 *
6 * BSD license, See the LICENSE file for more information
7 *
8 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
9 */
10
11#include "exclude.hpp"
12
13#include <boost/test/unit_test.hpp>
14
15namespace ndn {
16
17BOOST_AUTO_TEST_SUITE(TestExclude)
18
19BOOST_AUTO_TEST_CASE (Basic)
20{
21 Exclude e;
22 e.excludeOne (name::Component("b"));
23 BOOST_CHECK_EQUAL (e.size (), 1);
24 BOOST_CHECK_EQUAL (e.toUri(), "b");
25
26 e.excludeOne (name::Component("d"));
27 BOOST_CHECK_EQUAL (e.size (), 2);
28 BOOST_CHECK_EQUAL (e.toUri(), "b,d");
29
30 e.excludeOne (name::Component("a"));
31 BOOST_CHECK_EQUAL (e.size (), 3);
32 BOOST_CHECK_EQUAL (e.toUri(), "a,b,d");
33
34 e.excludeOne (name::Component("aa"));
35 BOOST_CHECK_EQUAL (e.size (), 4);
36 BOOST_CHECK_EQUAL (e.toUri(), "a,b,d,aa");
37
38 e.excludeOne (name::Component("cc"));
39 BOOST_CHECK_EQUAL (e.size (), 5);
40 BOOST_CHECK_EQUAL (e.toUri(), "a,b,d,aa,cc");
41
42 e.excludeOne (name::Component("c"));
43 BOOST_CHECK_EQUAL (e.size (), 6);
44 BOOST_CHECK_EQUAL (e.toUri(), "a,b,c,d,aa,cc");
45}
46
47BOOST_AUTO_TEST_CASE (Before)
48{
49 // based on http://redmine.named-data.net/issues/1158
50 ndn::Exclude e;
51 BOOST_REQUIRE_NO_THROW(e.excludeBefore(name::Component("PuQxMaf91")));
52
53 BOOST_CHECK_EQUAL(e.toUri(), "*,PuQxMaf91");
54}
55
56BOOST_AUTO_TEST_CASE (Ranges)
57{
58// example: ANY /b /d ANY /f
59
60 Exclude e;
61 e.excludeOne (name::Component ("b0"));
62 BOOST_CHECK_EQUAL (e.size (), 1);
63 BOOST_CHECK_EQUAL (e.toUri(), "b0");
64
65 e.excludeRange (name::Component (), name::Component ("b1"));
66 BOOST_CHECK_EQUAL (e.size (), 2);
67 BOOST_CHECK_EQUAL (e.toUri(), "*,b1");
68
69 e.excludeRange (name::Component (), name::Component("c0"));
70 BOOST_CHECK_EQUAL (e.size (), 2);
71 BOOST_CHECK_EQUAL (e.toUri(), "*,c0");
72
73 e.excludeRange (name::Component("a0"), name::Component("c0"));
74 BOOST_CHECK_EQUAL (e.size (), 2);
75 BOOST_CHECK_EQUAL (e.toUri(), "*,c0");
76
77 e.excludeRange (name::Component("d0"), name::Component("e0"));
78 BOOST_CHECK_EQUAL (e.size (), 4);
79 BOOST_CHECK_EQUAL (e.toUri(), "*,c0,d0,*,e0");
80
81 e.excludeRange (name::Component("c1"), name::Component("d1"));
82 BOOST_CHECK_EQUAL (e.size (), 4);
83 BOOST_CHECK_EQUAL (e.toUri(), "*,c0,c1,*,e0");
84
85 e.excludeRange (name::Component("a1"), name::Component("d1"));
86 BOOST_CHECK_EQUAL (e.size (), 2);
87 BOOST_CHECK_EQUAL (e.toUri(), "*,e0");
88
89 e.excludeBefore (name::Component("e2"));
90 BOOST_CHECK_EQUAL (e.size (), 2);
91 BOOST_CHECK_EQUAL (e.toUri(), "*,e2");
92
93 e.excludeAfter (name::Component("f0"));
94 BOOST_CHECK_EQUAL (e.size (), 3);
95 BOOST_CHECK_EQUAL (e.toUri(), "*,e2,f0,*");
96
97 e.excludeAfter (name::Component("e5"));
98 BOOST_CHECK_EQUAL (e.size (), 3);
99 BOOST_CHECK_EQUAL (e.toUri(), "*,e2,e5,*");
100
101 e.excludeAfter (name::Component("b2"));
102 BOOST_CHECK_EQUAL (e.size (), 1);
103 BOOST_CHECK_EQUAL (e.toUri(), "*");
104
105 BOOST_REQUIRE_THROW (e.excludeRange (name::Component("d0"), name::Component("a0")), Exclude::Error);
106}
107
108BOOST_AUTO_TEST_SUITE_END()
109
110} // namespace ndn