Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * 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. |
| 20 | */ |
| 21 | |
| 22 | #include "interest-filter.hpp" |
| 23 | #include "data.hpp" |
Junxiao Shi | 2bea5c4 | 2017-08-14 20:10:32 +0000 | [diff] [blame] | 24 | #include "encoding/buffer-stream.hpp" |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 25 | #include "security/signature-sha256-with-rsa.hpp" |
| 26 | #include "security/digest-sha256.hpp" |
Junxiao Shi | 2bea5c4 | 2017-08-14 20:10:32 +0000 | [diff] [blame] | 27 | #include "util/dummy-client-face.hpp" |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 28 | |
| 29 | #include "boost-test.hpp" |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 30 | |
| 31 | namespace ndn { |
| 32 | namespace tests { |
| 33 | |
| 34 | BOOST_AUTO_TEST_SUITE(TestInterestFilter) |
| 35 | |
| 36 | BOOST_AUTO_TEST_CASE(Matching) |
| 37 | { |
| 38 | BOOST_CHECK_EQUAL(InterestFilter("/a").doesMatch("/a/b"), true); |
| 39 | BOOST_CHECK_EQUAL(InterestFilter("/a/b").doesMatch("/a/b"), true); |
| 40 | BOOST_CHECK_EQUAL(InterestFilter("/a/b/c").doesMatch("/a/b"), false); |
| 41 | |
| 42 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b"), true); |
| 43 | BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b"), false); |
| 44 | |
| 45 | BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b/c/b"), false); |
| 46 | BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<>*<b>").doesMatch("/a/b/c/b"), true); |
| 47 | |
| 48 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b/c/d"), false); |
| 49 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b/c/d"), true); |
| 50 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b"), true); |
| 51 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b"), false); |
| 52 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b/c"), true); |
| 53 | } |
| 54 | |
Junxiao Shi | 2bea5c4 | 2017-08-14 20:10:32 +0000 | [diff] [blame] | 55 | BOOST_AUTO_TEST_CASE(RegexConvertToName) |
| 56 | { |
| 57 | util::DummyClientFace face; |
| 58 | face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"), |
| 59 | [] (const Name&, const Interest&) { BOOST_ERROR("unexpected Interest"); }); |
| 60 | face.processEvents(time::milliseconds(1)); |
| 61 | BOOST_CHECK_THROW(face.receive(Interest("/Hello/World/a/b/c")), InterestFilter::Error); |
| 62 | } |
| 63 | |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 64 | BOOST_AUTO_TEST_SUITE_END() // TestInterestFilter |
| 65 | |
| 66 | } // namespace tests |
| 67 | } // namespace ndn |