blob: e46d6c162f88a88d9220ec3a123f77c390e5c5fc [file] [log] [blame]
Chengyu Fanfc8aebb2014-10-22 16:35:23 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento74daf742018-11-23 18:14:13 -05002/*
Davide Pesaventodf8fd8a2022-02-21 20:04:21 -05003 * Copyright (c) 2013-2022 Regents of the University of California.
Chengyu Fanfc8aebb2014-10-22 16:35:23 -06004 *
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/mgmt/nfd/face-query-filter.hpp"
Chengyu Fanfc8aebb2014-10-22 16:35:23 -060023
Davide Pesavento7e780642018-11-24 15:51:34 -050024#include "tests/boost-test.hpp"
Davide Pesaventodf8fd8a2022-02-21 20:04:21 -050025
Junxiao Shia825d262017-02-07 18:24:59 +000026#include <boost/lexical_cast.hpp>
Chengyu Fanfc8aebb2014-10-22 16:35:23 -060027
28namespace ndn {
29namespace nfd {
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080030namespace tests {
Chengyu Fanfc8aebb2014-10-22 16:35:23 -060031
Junxiao Shi7357ef22016-09-07 02:39:37 +000032BOOST_AUTO_TEST_SUITE(Mgmt)
33BOOST_AUTO_TEST_SUITE(Nfd)
34BOOST_AUTO_TEST_SUITE(TestFaceQueryFilter)
Chengyu Fanfc8aebb2014-10-22 16:35:23 -060035
36BOOST_AUTO_TEST_CASE(Encode)
37{
38 FaceQueryFilter filter1;
39 BOOST_CHECK_EQUAL(filter1.hasFaceId(), false);
40 BOOST_CHECK_EQUAL(filter1.hasUriScheme(), false);
41 BOOST_CHECK_EQUAL(filter1.hasRemoteUri(), false);
42 BOOST_CHECK_EQUAL(filter1.hasLocalUri(), false);
43 BOOST_CHECK_EQUAL(filter1.hasFaceScope(), false);
44 BOOST_CHECK_EQUAL(filter1.hasFacePersistency(), false);
45 BOOST_CHECK_EQUAL(filter1.hasLinkType(), false);
46
47 filter1.setFaceId(100)
48 .setUriScheme("tcp4")
49 .setRemoteUri("tcp4://192.0.2.1:6363")
50 .setLocalUri("tcp4://192.0.2.2:55555")
51 .setFaceScope(FACE_SCOPE_LOCAL)
52 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
53 .setLinkType(LINK_TYPE_MULTI_ACCESS);
54
Junxiao Shia825d262017-02-07 18:24:59 +000055 Block wire = filter1.wireEncode();
Chengyu Fanfc8aebb2014-10-22 16:35:23 -060056
57 // These octets are obtained by the snippet below.
58 // This check is intended to detect unexpected encoding change in the future.
Davide Pesaventodf8fd8a2022-02-21 20:04:21 -050059 // for (auto it = wire.begin(); it != wire.end(); ++it) {
Chengyu Fanfc8aebb2014-10-22 16:35:23 -060060 // printf("0x%02x, ", *it);
61 // }
62 static const uint8_t expected[] = {
63 0x96, 0x41, 0x69, 0x01, 0x64, 0x83, 0x04, 0x74, 0x63, 0x70,
64 0x34, 0x72, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f,
65 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a,
66 0x36, 0x33, 0x36, 0x33, 0x81, 0x16, 0x74, 0x63, 0x70, 0x34,
67 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32,
68 0x2e, 0x32, 0x3a, 0x35, 0x35, 0x35, 0x35, 0x35, 0x84, 0x01,
69 0x01, 0x85, 0x01, 0x01, 0x86, 0x01, 0x01,
70 };
71
72 BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
73 wire.begin(), wire.end());
74
Chengyu Fanfc8aebb2014-10-22 16:35:23 -060075 FaceQueryFilter filter2(wire);
76 BOOST_CHECK_EQUAL(filter1.getFaceId(), filter2.getFaceId());
77 BOOST_CHECK_EQUAL(filter1.getUriScheme(), filter2.getUriScheme());
78 BOOST_CHECK_EQUAL(filter1.getRemoteUri(), filter2.getRemoteUri());
79 BOOST_CHECK_EQUAL(filter1.getLocalUri(), filter2.getLocalUri());
80 BOOST_CHECK_EQUAL(filter1.getFaceScope(), filter2.getFaceScope());
81 BOOST_CHECK_EQUAL(filter1.getFacePersistency(), filter2.getFacePersistency());
82 BOOST_CHECK_EQUAL(filter1.getLinkType(), filter2.getLinkType());
Junxiao Shia825d262017-02-07 18:24:59 +000083}
Chengyu Fanfc8aebb2014-10-22 16:35:23 -060084
Junxiao Shia825d262017-02-07 18:24:59 +000085BOOST_AUTO_TEST_CASE(Equality)
86{
87 FaceQueryFilter filter1, filter2;
Junxiao Shia341ae82017-02-13 19:45:12 +000088 BOOST_CHECK_EQUAL(filter1.empty(), true);
Junxiao Shia825d262017-02-07 18:24:59 +000089 BOOST_CHECK_EQUAL(filter1, filter2);
90
91 filter1.setFaceId(100)
92 .setUriScheme("tcp4")
93 .setRemoteUri("tcp4://192.0.2.1:6363")
94 .setLocalUri("tcp4://192.0.2.2:55555")
95 .setFaceScope(FACE_SCOPE_LOCAL)
96 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
97 .setLinkType(LINK_TYPE_MULTI_ACCESS);
Junxiao Shia341ae82017-02-13 19:45:12 +000098 BOOST_CHECK_EQUAL(filter1.empty(), false);
Junxiao Shia825d262017-02-07 18:24:59 +000099 BOOST_CHECK_NE(filter1, filter2);
100
101 filter2 = filter1;
102 BOOST_CHECK_EQUAL(filter1, filter2);
103
104 filter2.setFaceScope(FACE_SCOPE_NON_LOCAL);
105 BOOST_CHECK_NE(filter1, filter2);
106}
107
108BOOST_AUTO_TEST_CASE(Print)
109{
110 FaceQueryFilter filter;
111 filter.setFaceId(100)
112 .setUriScheme("tcp4")
113 .setRemoteUri("tcp4://192.0.2.1:6363")
114 .setLocalUri("tcp4://192.0.2.2:55555")
115 .setFaceScope(FACE_SCOPE_LOCAL)
116 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
117 .setLinkType(LINK_TYPE_MULTI_ACCESS);
118 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(filter),
119 "FaceQueryFilter(FaceID: 100,\n"
120 "UriScheme: tcp4,\n"
121 "RemoteUri: tcp4://192.0.2.1:6363,\n"
122 "LocalUri: tcp4://192.0.2.2:55555,\n"
123 "FaceScope: local,\n"
124 "FacePersistency: on-demand,\n"
125 "LinkType: multi-access,\n"
126 ")");
127
128 filter.unsetFaceId()
129 .unsetUriScheme()
130 .unsetRemoteUri()
131 .unsetLocalUri()
132 .unsetFaceScope()
133 .unsetFacePersistency()
134 .unsetLinkType();
135 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(filter), "FaceQueryFilter()");
Chengyu Fanfc8aebb2014-10-22 16:35:23 -0600136}
137
Junxiao Shi7357ef22016-09-07 02:39:37 +0000138BOOST_AUTO_TEST_SUITE_END() // TestFaceQueryFilter
139BOOST_AUTO_TEST_SUITE_END() // Nfd
140BOOST_AUTO_TEST_SUITE_END() // Mgmt
Chengyu Fanfc8aebb2014-10-22 16:35:23 -0600141
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800142} // namespace tests
Chengyu Fanfc8aebb2014-10-22 16:35:23 -0600143} // namespace nfd
144} // namespace ndn