blob: f4354e7fd52061a8b68faabb0d75910eed8c26ce [file] [log] [blame]
Junxiao Shi899277a2017-07-07 22:12:12 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento47ce2ee2023-05-09 01:33:33 -04003 * Copyright (c) 2013-2023 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
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040029namespace ndn::tests {
Junxiao Shi899277a2017-07-07 22:12:12 +000030
31BOOST_AUTO_TEST_SUITE(TestInterestFilter)
32
33BOOST_AUTO_TEST_CASE(Matching)
34{
35 BOOST_CHECK_EQUAL(InterestFilter("/a").doesMatch("/a/b"), true);
36 BOOST_CHECK_EQUAL(InterestFilter("/a/b").doesMatch("/a/b"), true);
37 BOOST_CHECK_EQUAL(InterestFilter("/a/b/c").doesMatch("/a/b"), false);
38
39 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b"), true);
40 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b"), false);
41
42 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b/c/b"), false);
43 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<>*<b>").doesMatch("/a/b/c/b"), true);
44
45 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b/c/d"), false);
46 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b/c/d"), true);
47 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b"), true);
48 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b"), false);
49 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b/c"), true);
50}
51
Junxiao Shi2bea5c42017-08-14 20:10:32 +000052BOOST_AUTO_TEST_CASE(RegexConvertToName)
53{
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040054 DummyClientFace face;
Junxiao Shi2bea5c42017-08-14 20:10:32 +000055 face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
56 [] (const Name&, const Interest&) { BOOST_ERROR("unexpected Interest"); });
Davide Pesavento0f830802018-01-16 23:58:58 -050057 face.processEvents(1_ms);
Junxiao Shib55e5d32018-07-18 13:32:00 -060058 BOOST_CHECK_THROW(face.receive(*makeInterest("/Hello/World/a/b/c")), InterestFilter::Error);
Junxiao Shi2bea5c42017-08-14 20:10:32 +000059}
60
Junxiao Shib6828912017-11-20 14:06:32 +000061BOOST_AUTO_TEST_CASE(AllowLoopback)
62{
63 InterestFilter filter("/A");
64 BOOST_CHECK_EQUAL(filter.allowsLoopback(), true);
65 BOOST_CHECK_EQUAL(&filter.allowLoopback(false), &filter);
66 BOOST_CHECK_EQUAL(filter.allowsLoopback(), false);
67}
68
Junxiao Shi899277a2017-07-07 22:12:12 +000069BOOST_AUTO_TEST_SUITE_END() // TestInterestFilter
70
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040071} // namespace ndn::tests