Chengyu Fan | 320d233 | 2014-10-29 16:40:33 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014, 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 |
| 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 | |
| 31 | NFD_LOG_INIT("FaceQueryStatusPublisherTest"); |
| 32 | |
| 33 | BOOST_FIXTURE_TEST_SUITE(MgmtFaceQuerySatusPublisher, FaceQueryStatusPublisherFixture) |
| 34 | |
| 35 | BOOST_AUTO_TEST_CASE(NoConditionFilter) |
| 36 | { |
| 37 | // filter without conditions matches all faces |
| 38 | ndn::nfd::FaceQueryFilter filter; |
| 39 | FaceQueryStatusPublisher faceQueryStatusPublisher(m_table, *m_face, |
| 40 | "/localhost/nfd/FaceStatusPublisherFixture", |
| 41 | filter, m_keyChain); |
| 42 | |
| 43 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyFace), true); |
| 44 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyLocalFace), true); |
| 45 | } |
| 46 | |
| 47 | BOOST_AUTO_TEST_CASE(AllConditionFilter) |
| 48 | { |
| 49 | ndn::nfd::FaceQueryFilter filter; |
| 50 | filter.setUriScheme("dummy") |
| 51 | .setRemoteUri("dummy://") |
| 52 | .setLocalUri("dummy://") |
| 53 | .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL) |
| 54 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) |
| 55 | .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT); |
| 56 | |
| 57 | FaceQueryStatusPublisher faceQueryStatusPublisher(m_table, *m_face, |
| 58 | "/localhost/nfd/FaceStatusPublisherFixture", |
| 59 | filter, m_keyChain); |
| 60 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyFace), true); |
| 61 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyLocalFace), false); |
| 62 | } |
| 63 | |
| 64 | BOOST_AUTO_TEST_CASE(UriSchemeFilter) |
| 65 | { |
| 66 | ndn::nfd::FaceQueryFilter filter; |
| 67 | filter.setUriScheme("dummyurischeme"); |
| 68 | FaceQueryStatusPublisher faceQueryStatusPublisher(m_table, *m_face, |
| 69 | "/localhost/nfd/FaceStatusPublisherFixture", |
| 70 | filter, m_keyChain); |
| 71 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyFace), false); |
| 72 | auto dummyUriScheme = make_shared<DummyFace>("dummyurischeme://", "dummyurischeme://"); |
| 73 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(dummyUriScheme), true); |
| 74 | } |
| 75 | |
| 76 | BOOST_AUTO_TEST_CASE(RemoteUriFilter) |
| 77 | { |
| 78 | ndn::nfd::FaceQueryFilter filter; |
| 79 | filter.setRemoteUri("dummy://remoteUri"); |
| 80 | FaceQueryStatusPublisher faceQueryStatusPublisher(m_table, *m_face, |
| 81 | "/localhost/nfd/FaceStatusPublisherFixture", |
| 82 | filter, m_keyChain); |
| 83 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyFace), false); |
| 84 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyUri), true); |
| 85 | } |
| 86 | |
| 87 | BOOST_AUTO_TEST_CASE(LocalUriFilter) |
| 88 | { |
| 89 | ndn::nfd::FaceQueryFilter filter; |
| 90 | filter.setLocalUri("dummy://localUri"); |
| 91 | FaceQueryStatusPublisher faceQueryStatusPublisher(m_table, *m_face, |
| 92 | "/localhost/nfd/FaceStatusPublisherFixture", |
| 93 | filter, m_keyChain); |
| 94 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyFace), false); |
| 95 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyUri), true); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | BOOST_AUTO_TEST_CASE(LinkTypeFilter) |
| 100 | { |
| 101 | shared_ptr<MulticastUdpFace> multicastFace = m_factory.createMulticastFace("0.0.0.0", |
| 102 | "224.0.0.1", |
| 103 | "20070"); |
| 104 | ndn::nfd::FaceQueryFilter filter; |
| 105 | filter.setLinkType(ndn::nfd::LINK_TYPE_MULTI_ACCESS); |
| 106 | FaceQueryStatusPublisher faceQueryStatusPublisher(m_table, *m_face, |
| 107 | "/localhost/nfd/FaceStatusPublisherFixture", |
| 108 | filter, m_keyChain); |
| 109 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyFace), false); |
| 110 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(multicastFace), true); |
| 111 | } |
| 112 | |
| 113 | BOOST_AUTO_TEST_CASE(PersistencyFilter) |
| 114 | { |
| 115 | shared_ptr<MulticastUdpFace> multicastFace = m_factory.createMulticastFace("0.0.0.0", |
| 116 | "224.0.0.1", |
| 117 | "20070"); |
| 118 | ndn::nfd::FaceQueryFilter filter; |
| 119 | filter.setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); |
| 120 | FaceQueryStatusPublisher faceQueryStatusPublisher(m_table, *m_face, |
| 121 | "/localhost/nfd/FaceStatusPublisherFixture", |
| 122 | filter, m_keyChain); |
| 123 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyFace), false); |
| 124 | multicastFace->setOnDemand(true); |
| 125 | BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(multicastFace), true); |
| 126 | } |
| 127 | |
| 128 | BOOST_AUTO_TEST_SUITE_END() |
| 129 | |
| 130 | } // namespace tests |
| 131 | } // namespace nfd |