blob: 100429c01e3961f47f3121464d5e863a9c73c9d1 [file] [log] [blame]
Junxiao Shi899277a2017-07-07 22:12:12 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento0f830802018-01-16 23:58:58 -05003 * Copyright (c) 2013-2018 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"
25#include "ndn-cxx/security/signature-sha256-with-rsa.hpp"
26#include "ndn-cxx/security/digest-sha256.hpp"
27#include "ndn-cxx/util/dummy-client-face.hpp"
Junxiao Shi899277a2017-07-07 22:12:12 +000028
Davide Pesavento7e780642018-11-24 15:51:34 -050029#include "tests/boost-test.hpp"
30#include "tests/make-interest-data.hpp"
Junxiao Shi899277a2017-07-07 22:12:12 +000031
32namespace ndn {
33namespace tests {
34
35BOOST_AUTO_TEST_SUITE(TestInterestFilter)
36
37BOOST_AUTO_TEST_CASE(Matching)
38{
39 BOOST_CHECK_EQUAL(InterestFilter("/a").doesMatch("/a/b"), true);
40 BOOST_CHECK_EQUAL(InterestFilter("/a/b").doesMatch("/a/b"), true);
41 BOOST_CHECK_EQUAL(InterestFilter("/a/b/c").doesMatch("/a/b"), false);
42
43 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b"), true);
44 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b"), false);
45
46 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b/c/b"), false);
47 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<>*<b>").doesMatch("/a/b/c/b"), true);
48
49 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b/c/d"), false);
50 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b/c/d"), true);
51 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b"), true);
52 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b"), false);
53 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b/c"), true);
54}
55
Junxiao Shi2bea5c42017-08-14 20:10:32 +000056BOOST_AUTO_TEST_CASE(RegexConvertToName)
57{
58 util::DummyClientFace face;
59 face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
60 [] (const Name&, const Interest&) { BOOST_ERROR("unexpected Interest"); });
Davide Pesavento0f830802018-01-16 23:58:58 -050061 face.processEvents(1_ms);
Junxiao Shib55e5d32018-07-18 13:32:00 -060062 BOOST_CHECK_THROW(face.receive(*makeInterest("/Hello/World/a/b/c")), InterestFilter::Error);
Junxiao Shi2bea5c42017-08-14 20:10:32 +000063}
64
Junxiao Shib6828912017-11-20 14:06:32 +000065BOOST_AUTO_TEST_CASE(AllowLoopback)
66{
67 InterestFilter filter("/A");
68 BOOST_CHECK_EQUAL(filter.allowsLoopback(), true);
69 BOOST_CHECK_EQUAL(&filter.allowLoopback(false), &filter);
70 BOOST_CHECK_EQUAL(filter.allowsLoopback(), false);
71}
72
Junxiao Shi899277a2017-07-07 22:12:12 +000073BOOST_AUTO_TEST_SUITE_END() // TestInterestFilter
74
75} // namespace tests
76} // namespace ndn