Chengyu Fan | 320d233 | 2014-10-29 16:40:33 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
Chengyu Fan | 320d233 | 2014-10-29 16:40:33 -0600 | [diff] [blame] | 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #include "face-query-status-publisher-common.hpp" |
| 27 | |
| 28 | namespace nfd { |
| 29 | namespace tests { |
| 30 | |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 31 | BOOST_FIXTURE_TEST_SUITE(MgmtFaceQueryStatusPublisher, FaceQueryStatusPublisherFixture) |
Chengyu Fan | 320d233 | 2014-10-29 16:40:33 -0600 | [diff] [blame] | 32 | |
| 33 | BOOST_AUTO_TEST_CASE(NoConditionFilter) |
| 34 | { |
| 35 | // filter without conditions matches all faces |
| 36 | ndn::nfd::FaceQueryFilter filter; |
| 37 | FaceQueryStatusPublisher faceQueryStatusPublisher(m_table, *m_face, |
| 38 | "/localhost/nfd/FaceStatusPublisherFixture", |
| 39 | filter, m_keyChain); |
| 40 | |
| 41 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyFace), true); |
| 42 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyLocalFace), true); |
| 43 | } |
| 44 | |
| 45 | BOOST_AUTO_TEST_CASE(AllConditionFilter) |
| 46 | { |
| 47 | ndn::nfd::FaceQueryFilter filter; |
| 48 | filter.setUriScheme("dummy") |
| 49 | .setRemoteUri("dummy://") |
| 50 | .setLocalUri("dummy://") |
| 51 | .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL) |
| 52 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) |
| 53 | .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT); |
| 54 | |
| 55 | FaceQueryStatusPublisher faceQueryStatusPublisher(m_table, *m_face, |
| 56 | "/localhost/nfd/FaceStatusPublisherFixture", |
| 57 | filter, m_keyChain); |
| 58 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyFace), true); |
| 59 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyLocalFace), false); |
| 60 | } |
| 61 | |
| 62 | BOOST_AUTO_TEST_CASE(UriSchemeFilter) |
| 63 | { |
| 64 | ndn::nfd::FaceQueryFilter filter; |
| 65 | filter.setUriScheme("dummyurischeme"); |
| 66 | FaceQueryStatusPublisher faceQueryStatusPublisher(m_table, *m_face, |
| 67 | "/localhost/nfd/FaceStatusPublisherFixture", |
| 68 | filter, m_keyChain); |
| 69 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyFace), false); |
| 70 | auto dummyUriScheme = make_shared<DummyFace>("dummyurischeme://", "dummyurischeme://"); |
| 71 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(dummyUriScheme), true); |
| 72 | } |
| 73 | |
| 74 | BOOST_AUTO_TEST_CASE(RemoteUriFilter) |
| 75 | { |
| 76 | ndn::nfd::FaceQueryFilter filter; |
| 77 | filter.setRemoteUri("dummy://remoteUri"); |
| 78 | FaceQueryStatusPublisher faceQueryStatusPublisher(m_table, *m_face, |
| 79 | "/localhost/nfd/FaceStatusPublisherFixture", |
| 80 | filter, m_keyChain); |
| 81 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyFace), false); |
| 82 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyUri), true); |
| 83 | } |
| 84 | |
| 85 | BOOST_AUTO_TEST_CASE(LocalUriFilter) |
| 86 | { |
| 87 | ndn::nfd::FaceQueryFilter filter; |
| 88 | filter.setLocalUri("dummy://localUri"); |
| 89 | FaceQueryStatusPublisher faceQueryStatusPublisher(m_table, *m_face, |
| 90 | "/localhost/nfd/FaceStatusPublisherFixture", |
| 91 | filter, m_keyChain); |
| 92 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyFace), false); |
| 93 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyUri), true); |
| 94 | } |
| 95 | |
| 96 | |
| 97 | BOOST_AUTO_TEST_CASE(LinkTypeFilter) |
| 98 | { |
| 99 | shared_ptr<MulticastUdpFace> multicastFace = m_factory.createMulticastFace("0.0.0.0", |
| 100 | "224.0.0.1", |
| 101 | "20070"); |
| 102 | ndn::nfd::FaceQueryFilter filter; |
| 103 | filter.setLinkType(ndn::nfd::LINK_TYPE_MULTI_ACCESS); |
| 104 | FaceQueryStatusPublisher faceQueryStatusPublisher(m_table, *m_face, |
| 105 | "/localhost/nfd/FaceStatusPublisherFixture", |
| 106 | filter, m_keyChain); |
| 107 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyFace), false); |
| 108 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(multicastFace), true); |
| 109 | } |
| 110 | |
| 111 | BOOST_AUTO_TEST_CASE(PersistencyFilter) |
| 112 | { |
| 113 | shared_ptr<MulticastUdpFace> multicastFace = m_factory.createMulticastFace("0.0.0.0", |
| 114 | "224.0.0.1", |
| 115 | "20070"); |
| 116 | ndn::nfd::FaceQueryFilter filter; |
| 117 | filter.setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); |
| 118 | FaceQueryStatusPublisher faceQueryStatusPublisher(m_table, *m_face, |
| 119 | "/localhost/nfd/FaceStatusPublisherFixture", |
| 120 | filter, m_keyChain); |
| 121 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyFace), false); |
| 122 | multicastFace->setOnDemand(true); |
| 123 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(multicastFace), true); |
| 124 | } |
| 125 | |
| 126 | BOOST_AUTO_TEST_SUITE_END() |
| 127 | |
| 128 | } // namespace tests |
| 129 | } // namespace nfd |