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 | /** |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2013-2015 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 { |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame^] | 28 | namespace tests { |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 29 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame^] | 30 | BOOST_AUTO_TEST_SUITE(ManagementNfdFaceEventNotification) |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 31 | |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 32 | BOOST_AUTO_TEST_CASE(Traits) |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 33 | { |
| 34 | FaceEventNotification notification; |
| 35 | |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 36 | BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_NON_LOCAL); |
| 37 | BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_PERSISTENT); |
| 38 | BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_POINT_TO_POINT); |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 39 | |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 40 | notification.setFaceScope(FACE_SCOPE_LOCAL); |
| 41 | BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_LOCAL); |
| 42 | BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_PERSISTENT); |
| 43 | BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_POINT_TO_POINT); |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 44 | |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 45 | notification.setFacePersistency(FACE_PERSISTENCY_ON_DEMAND); |
| 46 | BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_LOCAL); |
| 47 | BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_ON_DEMAND); |
| 48 | BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_POINT_TO_POINT); |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 49 | |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 50 | notification.setFacePersistency(FACE_PERSISTENCY_PERMANENT); |
| 51 | BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_LOCAL); |
| 52 | BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_PERMANENT); |
| 53 | BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_POINT_TO_POINT); |
| 54 | |
| 55 | notification.setLinkType(LINK_TYPE_MULTI_ACCESS); |
| 56 | BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_LOCAL); |
| 57 | BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_PERMANENT); |
| 58 | BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_MULTI_ACCESS); |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | BOOST_AUTO_TEST_CASE(EncodeCreated) |
| 62 | { |
| 63 | FaceEventNotification notification1; |
| 64 | notification1.setKind(FACE_EVENT_CREATED) |
| 65 | .setFaceId(20) |
| 66 | .setRemoteUri("tcp4://192.0.2.1:55555") |
| 67 | .setLocalUri("tcp4://192.0.2.2:6363") |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 68 | .setFaceScope(FACE_SCOPE_LOCAL) |
| 69 | .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND) |
| 70 | .setLinkType(LINK_TYPE_MULTI_ACCESS); |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 71 | Block wire; |
| 72 | BOOST_REQUIRE_NO_THROW(wire = notification1.wireEncode()); |
| 73 | |
| 74 | // These octets are obtained by the snippet below. |
| 75 | // This check is intended to detect unexpected encoding change in the future. |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 76 | // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) { |
| 77 | // printf("0x%02x, ", *it); |
| 78 | // } |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 79 | static const uint8_t expected[] = { |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 80 | 0xc0, 0x3e, 0xc1, 0x01, 0x01, 0x69, 0x01, 0x14, 0x72, 0x16, |
| 81 | 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, |
| 82 | 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35, |
| 83 | 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, |
| 84 | 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32, |
| 85 | 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01, |
| 86 | 0x01, 0x86, 0x01, 0x01, |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 87 | }; |
| 88 | BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected), |
| 89 | wire.begin(), wire.end()); |
| 90 | |
| 91 | BOOST_REQUIRE_NO_THROW(FaceEventNotification(wire)); |
| 92 | FaceEventNotification notification2(wire); |
| 93 | BOOST_CHECK_EQUAL(notification1.getKind(), notification2.getKind()); |
| 94 | BOOST_CHECK_EQUAL(notification1.getFaceId(), notification2.getFaceId()); |
| 95 | BOOST_CHECK_EQUAL(notification1.getRemoteUri(), notification2.getRemoteUri()); |
| 96 | BOOST_CHECK_EQUAL(notification1.getLocalUri(), notification2.getLocalUri()); |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 97 | BOOST_CHECK_EQUAL(notification1.getFaceScope(), notification2.getFaceScope()); |
| 98 | BOOST_CHECK_EQUAL(notification1.getFacePersistency(), notification2.getFacePersistency()); |
| 99 | BOOST_CHECK_EQUAL(notification1.getLinkType(), notification2.getLinkType()); |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 100 | |
| 101 | std::ostringstream os; |
| 102 | os << notification2; |
| 103 | BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification(" |
| 104 | "Kind: created, " |
| 105 | "FaceID: 20, " |
| 106 | "RemoteUri: tcp4://192.0.2.1:55555, " |
| 107 | "LocalUri: tcp4://192.0.2.2:6363, " |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 108 | "FaceScope: local, " |
| 109 | "FacePersistency: on-demand, " |
| 110 | "LinkType: multi-access)"); |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | BOOST_AUTO_TEST_CASE(EncodeDestroyed) |
| 114 | { |
| 115 | FaceEventNotification notification1; |
| 116 | notification1.setKind(FACE_EVENT_DESTROYED) |
| 117 | .setFaceId(20) |
| 118 | .setRemoteUri("tcp4://192.0.2.1:55555") |
| 119 | .setLocalUri("tcp4://192.0.2.2:6363") |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 120 | .setFaceScope(FACE_SCOPE_LOCAL) |
| 121 | .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND) |
| 122 | .setLinkType(LINK_TYPE_MULTI_ACCESS); |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 123 | Block wire; |
| 124 | BOOST_REQUIRE_NO_THROW(wire = notification1.wireEncode()); |
| 125 | |
| 126 | // These octets are obtained by the snippet below. |
| 127 | // This check is intended to detect unexpected encoding change in the future. |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 128 | // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) { |
| 129 | // printf("0x%02x, ", *it); |
| 130 | // } |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 131 | static const uint8_t expected[] = { |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 132 | 0xc0, 0x3e, 0xc1, 0x01, 0x02, 0x69, 0x01, 0x14, 0x72, 0x16, |
| 133 | 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, |
| 134 | 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35, |
| 135 | 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, |
| 136 | 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32, |
| 137 | 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01, |
| 138 | 0x01, 0x86, 0x01, 0x01, |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 139 | }; |
| 140 | BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected), |
| 141 | wire.begin(), wire.end()); |
| 142 | |
| 143 | BOOST_REQUIRE_NO_THROW(FaceEventNotification(wire)); |
| 144 | FaceEventNotification notification2(wire); |
| 145 | BOOST_CHECK_EQUAL(notification1.getKind(), notification2.getKind()); |
| 146 | BOOST_CHECK_EQUAL(notification1.getFaceId(), notification2.getFaceId()); |
| 147 | BOOST_CHECK_EQUAL(notification1.getRemoteUri(), notification2.getRemoteUri()); |
| 148 | BOOST_CHECK_EQUAL(notification1.getLocalUri(), notification2.getLocalUri()); |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 149 | BOOST_CHECK_EQUAL(notification1.getFaceScope(), notification2.getFaceScope()); |
| 150 | BOOST_CHECK_EQUAL(notification1.getFacePersistency(), notification2.getFacePersistency()); |
| 151 | BOOST_CHECK_EQUAL(notification1.getLinkType(), notification2.getLinkType()); |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 152 | |
| 153 | std::ostringstream os; |
| 154 | os << notification2; |
| 155 | BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification(" |
| 156 | "Kind: destroyed, " |
| 157 | "FaceID: 20, " |
| 158 | "RemoteUri: tcp4://192.0.2.1:55555, " |
| 159 | "LocalUri: tcp4://192.0.2.2:6363, " |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 160 | "FaceScope: local, " |
| 161 | "FacePersistency: on-demand, " |
| 162 | "LinkType: multi-access)"); |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | BOOST_AUTO_TEST_SUITE_END() |
| 166 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame^] | 167 | } // namespace tests |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 168 | } // namespace nfd |
| 169 | } // namespace ndn |