blob: 8277c2390c7c881988da0dcc5fc43d141a241012 [file] [log] [blame]
Junxiao Shi899277a2017-07-07 22:12:12 +00001/* -*- 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 Shi2bea5c42017-08-14 20:10:32 +000024#include "encoding/buffer-stream.hpp"
Junxiao Shi899277a2017-07-07 22:12:12 +000025#include "security/signature-sha256-with-rsa.hpp"
26#include "security/digest-sha256.hpp"
Junxiao Shi2bea5c42017-08-14 20:10:32 +000027#include "util/dummy-client-face.hpp"
Junxiao Shi899277a2017-07-07 22:12:12 +000028
29#include "boost-test.hpp"
Junxiao Shi899277a2017-07-07 22:12:12 +000030
31namespace ndn {
32namespace tests {
33
34BOOST_AUTO_TEST_SUITE(TestInterestFilter)
35
36BOOST_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 Shi2bea5c42017-08-14 20:10:32 +000055BOOST_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 Shib6828912017-11-20 14:06:32 +000064BOOST_AUTO_TEST_CASE(AllowLoopback)
65{
66 InterestFilter filter("/A");
67 BOOST_CHECK_EQUAL(filter.allowsLoopback(), true);
68 BOOST_CHECK_EQUAL(&filter.allowLoopback(false), &filter);
69 BOOST_CHECK_EQUAL(filter.allowsLoopback(), false);
70}
71
Junxiao Shi899277a2017-07-07 22:12:12 +000072BOOST_AUTO_TEST_SUITE_END() // TestInterestFilter
73
74} // namespace tests
75} // namespace ndn