Jeff Thompson | fa30664 | 2013-06-17 15:06:57 -0700 | [diff] [blame] | 1 | /* -*- 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 "ndn-cpp/fields/exclude.h" |
| 12 | #include "ndn-cpp/error.h" |
| 13 | |
| 14 | #include <boost/test/unit_test.hpp> |
| 15 | |
| 16 | #include <boost/lexical_cast.hpp> |
| 17 | |
| 18 | using namespace ndn; |
| 19 | using namespace std; |
| 20 | using namespace boost; |
| 21 | |
| 22 | BOOST_AUTO_TEST_SUITE(ExcludeTests) |
| 23 | |
| 24 | BOOST_AUTO_TEST_CASE (Basic) |
| 25 | { |
| 26 | Exclude e; |
| 27 | e.excludeOne (string ("b")); |
| 28 | BOOST_CHECK_EQUAL (e.size (), 1); |
| 29 | BOOST_CHECK_EQUAL (lexical_cast<string> (e), "b "); |
| 30 | |
| 31 | e.excludeOne (string ("d")); |
| 32 | BOOST_CHECK_EQUAL (e.size (), 2); |
| 33 | BOOST_CHECK_EQUAL (lexical_cast<string> (e), "b d "); |
| 34 | |
| 35 | e.excludeOne (string ("a")); |
| 36 | BOOST_CHECK_EQUAL (e.size (), 3); |
| 37 | BOOST_CHECK_EQUAL (lexical_cast<string> (e), "a b d "); |
| 38 | |
| 39 | e.excludeOne (string ("aa")); |
| 40 | BOOST_CHECK_EQUAL (e.size (), 4); |
| 41 | BOOST_CHECK_EQUAL (lexical_cast<string> (e), "a b d aa "); |
| 42 | |
| 43 | e.excludeOne (string ("cc")); |
| 44 | BOOST_CHECK_EQUAL (e.size (), 5); |
| 45 | BOOST_CHECK_EQUAL (lexical_cast<string> (e), "a b d aa cc "); |
| 46 | |
| 47 | e.excludeOne (string ("c")); |
| 48 | BOOST_CHECK_EQUAL (e.size (), 6); |
| 49 | BOOST_CHECK_EQUAL (lexical_cast<string> (e), "a b c d aa cc "); |
| 50 | } |
| 51 | |
| 52 | BOOST_AUTO_TEST_CASE (Ranges) |
| 53 | { |
| 54 | // example: ANY /b /d ANY /f |
| 55 | |
| 56 | Exclude e; |
| 57 | e.excludeOne (string ("b0")); |
| 58 | BOOST_CHECK_EQUAL (e.size (), 1); |
| 59 | BOOST_CHECK_EQUAL (lexical_cast<string> (e), "b0 "); |
| 60 | |
| 61 | e.excludeRange (name::Component (), string ("b1")); |
| 62 | BOOST_CHECK_EQUAL (e.size (), 2); |
| 63 | BOOST_CHECK_EQUAL (lexical_cast<string> (e), " ----> b1 "); |
| 64 | |
| 65 | e.excludeRange (name::Component (), string ("c0")); |
| 66 | BOOST_CHECK_EQUAL (e.size (), 2); |
| 67 | BOOST_CHECK_EQUAL (lexical_cast<string> (e), " ----> c0 "); |
| 68 | |
| 69 | e.excludeRange (string ("a0"), string ("c0")); |
| 70 | BOOST_CHECK_EQUAL (e.size (), 2); |
| 71 | BOOST_CHECK_EQUAL (lexical_cast<string> (e), " ----> c0 "); |
| 72 | |
| 73 | e.excludeRange (string ("d0"), string ("e0")); |
| 74 | BOOST_CHECK_EQUAL (e.size (), 4); |
| 75 | BOOST_CHECK_EQUAL (lexical_cast<string> (e), " ----> c0 d0 ----> e0 "); |
| 76 | |
| 77 | e.excludeRange (string ("c1"), string ("d1")); |
| 78 | BOOST_CHECK_EQUAL (e.size (), 4); |
| 79 | BOOST_CHECK_EQUAL (lexical_cast<string> (e), " ----> c0 c1 ----> e0 "); |
| 80 | |
| 81 | e.excludeRange (string ("a1"), string ("d1")); |
| 82 | BOOST_CHECK_EQUAL (e.size (), 2); |
| 83 | BOOST_CHECK_EQUAL (lexical_cast<string> (e), " ----> e0 "); |
| 84 | |
| 85 | e.excludeBefore (string ("e2")); |
| 86 | BOOST_CHECK_EQUAL (e.size (), 2); |
| 87 | BOOST_CHECK_EQUAL (lexical_cast<string> (e), " ----> e2 "); |
| 88 | |
| 89 | e.excludeAfter (string ("f0")); |
| 90 | BOOST_CHECK_EQUAL (e.size (), 3); |
| 91 | BOOST_CHECK_EQUAL (lexical_cast<string> (e), " ----> e2 f0 ----> "); |
| 92 | |
| 93 | e.excludeAfter (string ("e5")); |
| 94 | BOOST_CHECK_EQUAL (e.size (), 3); |
| 95 | BOOST_CHECK_EQUAL (lexical_cast<string> (e), " ----> e2 e5 ----> "); |
| 96 | |
| 97 | e.excludeAfter (string ("b2")); |
| 98 | BOOST_CHECK_EQUAL (e.size (), 1); |
| 99 | BOOST_CHECK_EQUAL (lexical_cast<string> (e), " ----> "); |
| 100 | |
| 101 | BOOST_REQUIRE_THROW (e.excludeRange (string ("d0"), string ("a0")), error::Exclude); |
| 102 | } |
| 103 | |
| 104 | BOOST_AUTO_TEST_SUITE_END() |