blob: 12aba0a97a106fd359e63c7c76c1047e402f0cb4 [file] [log] [blame]
Junxiao Shi899277a2017-07-07 22:12:12 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento14c56cd2020-05-21 01:44:03 -04003 * Copyright (c) 2013-2020 Regents of the University of California.
Junxiao Shi899277a2017-07-07 22:12:12 +00004 *
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
Davide Pesavento7e780642018-11-24 15:51:34 -050022#include "ndn-cxx/interest-filter.hpp"
23#include "ndn-cxx/data.hpp"
24#include "ndn-cxx/encoding/buffer-stream.hpp"
Davide Pesavento7e780642018-11-24 15:51:34 -050025#include "ndn-cxx/util/dummy-client-face.hpp"
Junxiao Shi899277a2017-07-07 22:12:12 +000026
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050027#include "tests/test-common.hpp"
Junxiao Shi899277a2017-07-07 22:12:12 +000028
29namespace ndn {
30namespace tests {
31
32BOOST_AUTO_TEST_SUITE(TestInterestFilter)
33
34BOOST_AUTO_TEST_CASE(Matching)
35{
36 BOOST_CHECK_EQUAL(InterestFilter("/a").doesMatch("/a/b"), true);
37 BOOST_CHECK_EQUAL(InterestFilter("/a/b").doesMatch("/a/b"), true);
38 BOOST_CHECK_EQUAL(InterestFilter("/a/b/c").doesMatch("/a/b"), false);
39
40 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b"), true);
41 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b"), false);
42
43 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b/c/b"), false);
44 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<>*<b>").doesMatch("/a/b/c/b"), true);
45
46 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b/c/d"), false);
47 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b/c/d"), true);
48 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b"), true);
49 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b"), false);
50 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b/c"), true);
51}
52
Junxiao Shi2bea5c42017-08-14 20:10:32 +000053BOOST_AUTO_TEST_CASE(RegexConvertToName)
54{
55 util::DummyClientFace face;
56 face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
57 [] (const Name&, const Interest&) { BOOST_ERROR("unexpected Interest"); });
Davide Pesavento0f830802018-01-16 23:58:58 -050058 face.processEvents(1_ms);
Junxiao Shib55e5d32018-07-18 13:32:00 -060059 BOOST_CHECK_THROW(face.receive(*makeInterest("/Hello/World/a/b/c")), InterestFilter::Error);
Junxiao Shi2bea5c42017-08-14 20:10:32 +000060}
61
Junxiao Shib6828912017-11-20 14:06:32 +000062BOOST_AUTO_TEST_CASE(AllowLoopback)
63{
64 InterestFilter filter("/A");
65 BOOST_CHECK_EQUAL(filter.allowsLoopback(), true);
66 BOOST_CHECK_EQUAL(&filter.allowLoopback(false), &filter);
67 BOOST_CHECK_EQUAL(filter.allowsLoopback(), false);
68}
69
Junxiao Shi899277a2017-07-07 22:12:12 +000070BOOST_AUTO_TEST_SUITE_END() // TestInterestFilter
71
72} // namespace tests
73} // namespace ndn