Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 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. |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include "management/nfd-face-event-notification.hpp" |
| 23 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 24 | #include "boost-test.hpp" |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 25 | |
| 26 | namespace ndn { |
| 27 | namespace nfd { |
| 28 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 29 | BOOST_AUTO_TEST_SUITE(ManagementTestNfdFaceEventNotification) |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 30 | |
| 31 | BOOST_AUTO_TEST_CASE(Flags) |
| 32 | { |
| 33 | FaceEventNotification notification; |
| 34 | |
| 35 | notification.setFlags(0); |
| 36 | BOOST_CHECK_EQUAL(notification.isLocal(), false); |
| 37 | BOOST_CHECK_EQUAL(notification.isOnDemand(), false); |
| 38 | |
| 39 | notification.setFlags(FACE_IS_LOCAL); |
| 40 | BOOST_CHECK_EQUAL(notification.isLocal(), true); |
| 41 | BOOST_CHECK_EQUAL(notification.isOnDemand(), false); |
| 42 | |
| 43 | notification.setFlags(FACE_IS_ON_DEMAND); |
| 44 | BOOST_CHECK_EQUAL(notification.isLocal(), false); |
| 45 | BOOST_CHECK_EQUAL(notification.isOnDemand(), true); |
| 46 | |
| 47 | notification.setFlags(FACE_IS_LOCAL | FACE_IS_ON_DEMAND); |
| 48 | BOOST_CHECK_EQUAL(notification.isLocal(), true); |
| 49 | BOOST_CHECK_EQUAL(notification.isOnDemand(), true); |
| 50 | } |
| 51 | |
| 52 | BOOST_AUTO_TEST_CASE(EncodeCreated) |
| 53 | { |
| 54 | FaceEventNotification notification1; |
| 55 | notification1.setKind(FACE_EVENT_CREATED) |
| 56 | .setFaceId(20) |
| 57 | .setRemoteUri("tcp4://192.0.2.1:55555") |
| 58 | .setLocalUri("tcp4://192.0.2.2:6363") |
| 59 | .setFlags(FACE_IS_ON_DEMAND); |
| 60 | Block wire; |
| 61 | BOOST_REQUIRE_NO_THROW(wire = notification1.wireEncode()); |
| 62 | |
| 63 | // These octets are obtained by the snippet below. |
| 64 | // This check is intended to detect unexpected encoding change in the future. |
| 65 | //for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) { |
| 66 | // printf("0x%02x, ", *it); |
| 67 | //} |
| 68 | static const uint8_t expected[] = { |
| 69 | 0xc0, 0x38, 0xc1, 0x01, 0x01, 0x69, 0x01, 0x14, 0x72, 0x16, 0x74, 0x63, |
| 70 | 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, |
| 71 | 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35, 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, |
| 72 | 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, |
| 73 | 0x2e, 0x32, 0x3a, 0x36, 0x33, 0x36, 0x33, 0xc2, 0x01, 0x02, |
| 74 | }; |
| 75 | BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected), |
| 76 | wire.begin(), wire.end()); |
| 77 | |
| 78 | BOOST_REQUIRE_NO_THROW(FaceEventNotification(wire)); |
| 79 | FaceEventNotification notification2(wire); |
| 80 | BOOST_CHECK_EQUAL(notification1.getKind(), notification2.getKind()); |
| 81 | BOOST_CHECK_EQUAL(notification1.getFaceId(), notification2.getFaceId()); |
| 82 | BOOST_CHECK_EQUAL(notification1.getRemoteUri(), notification2.getRemoteUri()); |
| 83 | BOOST_CHECK_EQUAL(notification1.getLocalUri(), notification2.getLocalUri()); |
| 84 | BOOST_CHECK_EQUAL(notification1.getFlags(), notification2.getFlags()); |
| 85 | |
| 86 | std::ostringstream os; |
| 87 | os << notification2; |
| 88 | BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification(" |
| 89 | "Kind: created, " |
| 90 | "FaceID: 20, " |
| 91 | "RemoteUri: tcp4://192.0.2.1:55555, " |
| 92 | "LocalUri: tcp4://192.0.2.2:6363, " |
| 93 | "Flags: 2)"); |
| 94 | } |
| 95 | |
| 96 | BOOST_AUTO_TEST_CASE(EncodeDestroyed) |
| 97 | { |
| 98 | FaceEventNotification notification1; |
| 99 | notification1.setKind(FACE_EVENT_DESTROYED) |
| 100 | .setFaceId(20) |
| 101 | .setRemoteUri("tcp4://192.0.2.1:55555") |
| 102 | .setLocalUri("tcp4://192.0.2.2:6363") |
| 103 | .setFlags(FACE_IS_ON_DEMAND); |
| 104 | Block wire; |
| 105 | BOOST_REQUIRE_NO_THROW(wire = notification1.wireEncode()); |
| 106 | |
| 107 | // These octets are obtained by the snippet below. |
| 108 | // This check is intended to detect unexpected encoding change in the future. |
| 109 | //for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) { |
| 110 | // printf("0x%02x, ", *it); |
| 111 | //} |
| 112 | static const uint8_t expected[] = { |
| 113 | 0xc0, 0x38, 0xc1, 0x01, 0x02, 0x69, 0x01, 0x14, 0x72, 0x16, 0x74, 0x63, |
| 114 | 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, |
| 115 | 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35, 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, |
| 116 | 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, |
| 117 | 0x2e, 0x32, 0x3a, 0x36, 0x33, 0x36, 0x33, 0xc2, 0x01, 0x02, |
| 118 | }; |
| 119 | BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected), |
| 120 | wire.begin(), wire.end()); |
| 121 | |
| 122 | BOOST_REQUIRE_NO_THROW(FaceEventNotification(wire)); |
| 123 | FaceEventNotification notification2(wire); |
| 124 | BOOST_CHECK_EQUAL(notification1.getKind(), notification2.getKind()); |
| 125 | BOOST_CHECK_EQUAL(notification1.getFaceId(), notification2.getFaceId()); |
| 126 | BOOST_CHECK_EQUAL(notification1.getRemoteUri(), notification2.getRemoteUri()); |
| 127 | BOOST_CHECK_EQUAL(notification1.getLocalUri(), notification2.getLocalUri()); |
| 128 | BOOST_CHECK_EQUAL(notification1.getFlags(), notification2.getFlags()); |
| 129 | |
| 130 | std::ostringstream os; |
| 131 | os << notification2; |
| 132 | BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification(" |
| 133 | "Kind: destroyed, " |
| 134 | "FaceID: 20, " |
| 135 | "RemoteUri: tcp4://192.0.2.1:55555, " |
| 136 | "LocalUri: tcp4://192.0.2.2:6363, " |
| 137 | "Flags: 2)"); |
| 138 | } |
| 139 | |
| 140 | BOOST_AUTO_TEST_SUITE_END() |
| 141 | |
| 142 | } // namespace nfd |
| 143 | } // namespace ndn |