Chengyu Fan | fc8aebb | 2014-10-22 16:35:23 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 74daf74 | 2018-11-23 18:14:13 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013-2018 Regents of the University of California. |
Chengyu Fan | fc8aebb | 2014-10-22 16:35:23 -0600 | [diff] [blame] | 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 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 22 | #include "ndn-cxx/mgmt/nfd/face-query-filter.hpp" |
Chengyu Fan | fc8aebb | 2014-10-22 16:35:23 -0600 | [diff] [blame] | 23 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 24 | #include "tests/boost-test.hpp" |
Junxiao Shi | a825d26 | 2017-02-07 18:24:59 +0000 | [diff] [blame] | 25 | #include <boost/lexical_cast.hpp> |
Chengyu Fan | fc8aebb | 2014-10-22 16:35:23 -0600 | [diff] [blame] | 26 | |
| 27 | namespace ndn { |
| 28 | namespace nfd { |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 29 | namespace tests { |
Chengyu Fan | fc8aebb | 2014-10-22 16:35:23 -0600 | [diff] [blame] | 30 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 31 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 32 | BOOST_AUTO_TEST_SUITE(Nfd) |
| 33 | BOOST_AUTO_TEST_SUITE(TestFaceQueryFilter) |
Chengyu Fan | fc8aebb | 2014-10-22 16:35:23 -0600 | [diff] [blame] | 34 | |
| 35 | BOOST_AUTO_TEST_CASE(Encode) |
| 36 | { |
| 37 | FaceQueryFilter filter1; |
| 38 | BOOST_CHECK_EQUAL(filter1.hasFaceId(), false); |
| 39 | BOOST_CHECK_EQUAL(filter1.hasUriScheme(), false); |
| 40 | BOOST_CHECK_EQUAL(filter1.hasRemoteUri(), false); |
| 41 | BOOST_CHECK_EQUAL(filter1.hasLocalUri(), false); |
| 42 | BOOST_CHECK_EQUAL(filter1.hasFaceScope(), false); |
| 43 | BOOST_CHECK_EQUAL(filter1.hasFacePersistency(), false); |
| 44 | BOOST_CHECK_EQUAL(filter1.hasLinkType(), false); |
| 45 | |
| 46 | filter1.setFaceId(100) |
| 47 | .setUriScheme("tcp4") |
| 48 | .setRemoteUri("tcp4://192.0.2.1:6363") |
| 49 | .setLocalUri("tcp4://192.0.2.2:55555") |
| 50 | .setFaceScope(FACE_SCOPE_LOCAL) |
| 51 | .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND) |
| 52 | .setLinkType(LINK_TYPE_MULTI_ACCESS); |
| 53 | |
Junxiao Shi | a825d26 | 2017-02-07 18:24:59 +0000 | [diff] [blame] | 54 | Block wire = filter1.wireEncode(); |
Chengyu Fan | fc8aebb | 2014-10-22 16:35:23 -0600 | [diff] [blame] | 55 | |
| 56 | // These octets are obtained by the snippet below. |
| 57 | // This check is intended to detect unexpected encoding change in the future. |
| 58 | // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) { |
| 59 | // printf("0x%02x, ", *it); |
| 60 | // } |
| 61 | static const uint8_t expected[] = { |
| 62 | 0x96, 0x41, 0x69, 0x01, 0x64, 0x83, 0x04, 0x74, 0x63, 0x70, |
| 63 | 0x34, 0x72, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, |
| 64 | 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, |
| 65 | 0x36, 0x33, 0x36, 0x33, 0x81, 0x16, 0x74, 0x63, 0x70, 0x34, |
| 66 | 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, |
| 67 | 0x2e, 0x32, 0x3a, 0x35, 0x35, 0x35, 0x35, 0x35, 0x84, 0x01, |
| 68 | 0x01, 0x85, 0x01, 0x01, 0x86, 0x01, 0x01, |
| 69 | }; |
| 70 | |
| 71 | BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected), |
| 72 | wire.begin(), wire.end()); |
| 73 | |
Chengyu Fan | fc8aebb | 2014-10-22 16:35:23 -0600 | [diff] [blame] | 74 | FaceQueryFilter filter2(wire); |
| 75 | BOOST_CHECK_EQUAL(filter1.getFaceId(), filter2.getFaceId()); |
| 76 | BOOST_CHECK_EQUAL(filter1.getUriScheme(), filter2.getUriScheme()); |
| 77 | BOOST_CHECK_EQUAL(filter1.getRemoteUri(), filter2.getRemoteUri()); |
| 78 | BOOST_CHECK_EQUAL(filter1.getLocalUri(), filter2.getLocalUri()); |
| 79 | BOOST_CHECK_EQUAL(filter1.getFaceScope(), filter2.getFaceScope()); |
| 80 | BOOST_CHECK_EQUAL(filter1.getFacePersistency(), filter2.getFacePersistency()); |
| 81 | BOOST_CHECK_EQUAL(filter1.getLinkType(), filter2.getLinkType()); |
Junxiao Shi | a825d26 | 2017-02-07 18:24:59 +0000 | [diff] [blame] | 82 | } |
Chengyu Fan | fc8aebb | 2014-10-22 16:35:23 -0600 | [diff] [blame] | 83 | |
Junxiao Shi | a825d26 | 2017-02-07 18:24:59 +0000 | [diff] [blame] | 84 | BOOST_AUTO_TEST_CASE(Equality) |
| 85 | { |
| 86 | FaceQueryFilter filter1, filter2; |
Junxiao Shi | a341ae8 | 2017-02-13 19:45:12 +0000 | [diff] [blame] | 87 | BOOST_CHECK_EQUAL(filter1.empty(), true); |
Junxiao Shi | a825d26 | 2017-02-07 18:24:59 +0000 | [diff] [blame] | 88 | BOOST_CHECK_EQUAL(filter1, filter2); |
| 89 | |
| 90 | filter1.setFaceId(100) |
| 91 | .setUriScheme("tcp4") |
| 92 | .setRemoteUri("tcp4://192.0.2.1:6363") |
| 93 | .setLocalUri("tcp4://192.0.2.2:55555") |
| 94 | .setFaceScope(FACE_SCOPE_LOCAL) |
| 95 | .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND) |
| 96 | .setLinkType(LINK_TYPE_MULTI_ACCESS); |
Junxiao Shi | a341ae8 | 2017-02-13 19:45:12 +0000 | [diff] [blame] | 97 | BOOST_CHECK_EQUAL(filter1.empty(), false); |
Junxiao Shi | a825d26 | 2017-02-07 18:24:59 +0000 | [diff] [blame] | 98 | BOOST_CHECK_NE(filter1, filter2); |
| 99 | |
| 100 | filter2 = filter1; |
| 101 | BOOST_CHECK_EQUAL(filter1, filter2); |
| 102 | |
| 103 | filter2.setFaceScope(FACE_SCOPE_NON_LOCAL); |
| 104 | BOOST_CHECK_NE(filter1, filter2); |
| 105 | } |
| 106 | |
| 107 | BOOST_AUTO_TEST_CASE(Print) |
| 108 | { |
| 109 | FaceQueryFilter filter; |
| 110 | filter.setFaceId(100) |
| 111 | .setUriScheme("tcp4") |
| 112 | .setRemoteUri("tcp4://192.0.2.1:6363") |
| 113 | .setLocalUri("tcp4://192.0.2.2:55555") |
| 114 | .setFaceScope(FACE_SCOPE_LOCAL) |
| 115 | .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND) |
| 116 | .setLinkType(LINK_TYPE_MULTI_ACCESS); |
| 117 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(filter), |
| 118 | "FaceQueryFilter(FaceID: 100,\n" |
| 119 | "UriScheme: tcp4,\n" |
| 120 | "RemoteUri: tcp4://192.0.2.1:6363,\n" |
| 121 | "LocalUri: tcp4://192.0.2.2:55555,\n" |
| 122 | "FaceScope: local,\n" |
| 123 | "FacePersistency: on-demand,\n" |
| 124 | "LinkType: multi-access,\n" |
| 125 | ")"); |
| 126 | |
| 127 | filter.unsetFaceId() |
| 128 | .unsetUriScheme() |
| 129 | .unsetRemoteUri() |
| 130 | .unsetLocalUri() |
| 131 | .unsetFaceScope() |
| 132 | .unsetFacePersistency() |
| 133 | .unsetLinkType(); |
| 134 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(filter), "FaceQueryFilter()"); |
Chengyu Fan | fc8aebb | 2014-10-22 16:35:23 -0600 | [diff] [blame] | 135 | } |
| 136 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 137 | BOOST_AUTO_TEST_SUITE_END() // TestFaceQueryFilter |
| 138 | BOOST_AUTO_TEST_SUITE_END() // Nfd |
| 139 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Chengyu Fan | fc8aebb | 2014-10-22 16:35:23 -0600 | [diff] [blame] | 140 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 141 | } // namespace tests |
Chengyu Fan | fc8aebb | 2014-10-22 16:35:23 -0600 | [diff] [blame] | 142 | } // namespace nfd |
| 143 | } // namespace ndn |