Chengyu Fan | fc8aebb | 2014-10-22 16:35:23 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2014 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 "management/nfd-face-query-filter.hpp" |
| 23 | |
| 24 | #include "boost-test.hpp" |
| 25 | |
| 26 | namespace ndn { |
| 27 | namespace nfd { |
| 28 | |
| 29 | BOOST_AUTO_TEST_SUITE(ManagementTestNfdFaceQueryFilter) |
| 30 | |
| 31 | BOOST_AUTO_TEST_CASE(Encode) |
| 32 | { |
| 33 | FaceQueryFilter filter1; |
| 34 | BOOST_CHECK_EQUAL(filter1.hasFaceId(), false); |
| 35 | BOOST_CHECK_EQUAL(filter1.hasUriScheme(), false); |
| 36 | BOOST_CHECK_EQUAL(filter1.hasRemoteUri(), false); |
| 37 | BOOST_CHECK_EQUAL(filter1.hasLocalUri(), false); |
| 38 | BOOST_CHECK_EQUAL(filter1.hasFaceScope(), false); |
| 39 | BOOST_CHECK_EQUAL(filter1.hasFacePersistency(), false); |
| 40 | BOOST_CHECK_EQUAL(filter1.hasLinkType(), false); |
| 41 | |
| 42 | filter1.setFaceId(100) |
| 43 | .setUriScheme("tcp4") |
| 44 | .setRemoteUri("tcp4://192.0.2.1:6363") |
| 45 | .setLocalUri("tcp4://192.0.2.2:55555") |
| 46 | .setFaceScope(FACE_SCOPE_LOCAL) |
| 47 | .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND) |
| 48 | .setLinkType(LINK_TYPE_MULTI_ACCESS); |
| 49 | |
| 50 | Block wire; |
| 51 | BOOST_REQUIRE_NO_THROW(wire = filter1.wireEncode()); |
| 52 | |
| 53 | // These octets are obtained by the snippet below. |
| 54 | // This check is intended to detect unexpected encoding change in the future. |
| 55 | // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) { |
| 56 | // printf("0x%02x, ", *it); |
| 57 | // } |
| 58 | static const uint8_t expected[] = { |
| 59 | 0x96, 0x41, 0x69, 0x01, 0x64, 0x83, 0x04, 0x74, 0x63, 0x70, |
| 60 | 0x34, 0x72, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, |
| 61 | 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, |
| 62 | 0x36, 0x33, 0x36, 0x33, 0x81, 0x16, 0x74, 0x63, 0x70, 0x34, |
| 63 | 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, |
| 64 | 0x2e, 0x32, 0x3a, 0x35, 0x35, 0x35, 0x35, 0x35, 0x84, 0x01, |
| 65 | 0x01, 0x85, 0x01, 0x01, 0x86, 0x01, 0x01, |
| 66 | }; |
| 67 | |
| 68 | BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected), |
| 69 | wire.begin(), wire.end()); |
| 70 | |
| 71 | BOOST_REQUIRE_NO_THROW(FaceQueryFilter(wire)); |
| 72 | |
| 73 | FaceQueryFilter filter2(wire); |
| 74 | BOOST_CHECK_EQUAL(filter1.getFaceId(), filter2.getFaceId()); |
| 75 | BOOST_CHECK_EQUAL(filter1.getUriScheme(), filter2.getUriScheme()); |
| 76 | BOOST_CHECK_EQUAL(filter1.getRemoteUri(), filter2.getRemoteUri()); |
| 77 | BOOST_CHECK_EQUAL(filter1.getLocalUri(), filter2.getLocalUri()); |
| 78 | BOOST_CHECK_EQUAL(filter1.getFaceScope(), filter2.getFaceScope()); |
| 79 | BOOST_CHECK_EQUAL(filter1.getFacePersistency(), filter2.getFacePersistency()); |
| 80 | BOOST_CHECK_EQUAL(filter1.getLinkType(), filter2.getLinkType()); |
| 81 | |
| 82 | std::ostringstream os; |
| 83 | os << filter2; |
| 84 | BOOST_CHECK_EQUAL(os.str(), "FaceQueryFilter(FaceID: 100,\n" |
| 85 | "UriScheme: tcp4,\n" |
| 86 | "RemoteUri: tcp4://192.0.2.1:6363,\n" |
| 87 | "LocalUri: tcp4://192.0.2.2:55555,\n" |
| 88 | "FaceScope: local,\n" |
| 89 | "FacePersistency: on-demand,\n" |
| 90 | "LinkType: multi-access,\n" |
| 91 | ")"); |
| 92 | } |
| 93 | |
| 94 | BOOST_AUTO_TEST_SUITE_END() |
| 95 | |
| 96 | } // namespace nfd |
| 97 | } // namespace ndn |