blob: 5d014d8435642b0a58ec08258dddaf0496cd2666 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -07002/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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 Shi7b1ba1a2014-03-29 01:01:56 -070020 */
21
22#include "management/nfd-face-event-notification.hpp"
23
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070024#include "boost-test.hpp"
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070025
26namespace ndn {
27namespace nfd {
28
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070029BOOST_AUTO_TEST_SUITE(ManagementTestNfdFaceEventNotification)
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070030
Chengyu Fan36dca992014-09-25 13:42:03 -060031BOOST_AUTO_TEST_CASE(Traits)
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070032{
33 FaceEventNotification notification;
34
Chengyu Fan36dca992014-09-25 13:42:03 -060035 BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_NON_LOCAL);
36 BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_PERSISTENT);
37 BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_POINT_TO_POINT);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070038
Chengyu Fan36dca992014-09-25 13:42:03 -060039 notification.setFaceScope(FACE_SCOPE_LOCAL);
40 BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_LOCAL);
41 BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_PERSISTENT);
42 BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_POINT_TO_POINT);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070043
Chengyu Fan36dca992014-09-25 13:42:03 -060044 notification.setFacePersistency(FACE_PERSISTENCY_ON_DEMAND);
45 BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_LOCAL);
46 BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_ON_DEMAND);
47 BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_POINT_TO_POINT);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070048
Chengyu Fan36dca992014-09-25 13:42:03 -060049 notification.setFacePersistency(FACE_PERSISTENCY_PERMANENT);
50 BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_LOCAL);
51 BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_PERMANENT);
52 BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_POINT_TO_POINT);
53
54 notification.setLinkType(LINK_TYPE_MULTI_ACCESS);
55 BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_LOCAL);
56 BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_PERMANENT);
57 BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_MULTI_ACCESS);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070058}
59
60BOOST_AUTO_TEST_CASE(EncodeCreated)
61{
62 FaceEventNotification notification1;
63 notification1.setKind(FACE_EVENT_CREATED)
64 .setFaceId(20)
65 .setRemoteUri("tcp4://192.0.2.1:55555")
66 .setLocalUri("tcp4://192.0.2.2:6363")
Chengyu Fan36dca992014-09-25 13:42:03 -060067 .setFaceScope(FACE_SCOPE_LOCAL)
68 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
69 .setLinkType(LINK_TYPE_MULTI_ACCESS);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070070 Block wire;
71 BOOST_REQUIRE_NO_THROW(wire = notification1.wireEncode());
72
73 // These octets are obtained by the snippet below.
74 // This check is intended to detect unexpected encoding change in the future.
Chengyu Fan36dca992014-09-25 13:42:03 -060075 // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
76 // printf("0x%02x, ", *it);
77 // }
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070078 static const uint8_t expected[] = {
Chengyu Fan36dca992014-09-25 13:42:03 -060079 0xc0, 0x3e, 0xc1, 0x01, 0x01, 0x69, 0x01, 0x14, 0x72, 0x16,
80 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
81 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35,
82 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
83 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32,
84 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01,
85 0x01, 0x86, 0x01, 0x01,
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070086 };
87 BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
88 wire.begin(), wire.end());
89
90 BOOST_REQUIRE_NO_THROW(FaceEventNotification(wire));
91 FaceEventNotification notification2(wire);
92 BOOST_CHECK_EQUAL(notification1.getKind(), notification2.getKind());
93 BOOST_CHECK_EQUAL(notification1.getFaceId(), notification2.getFaceId());
94 BOOST_CHECK_EQUAL(notification1.getRemoteUri(), notification2.getRemoteUri());
95 BOOST_CHECK_EQUAL(notification1.getLocalUri(), notification2.getLocalUri());
Chengyu Fan36dca992014-09-25 13:42:03 -060096 BOOST_CHECK_EQUAL(notification1.getFaceScope(), notification2.getFaceScope());
97 BOOST_CHECK_EQUAL(notification1.getFacePersistency(), notification2.getFacePersistency());
98 BOOST_CHECK_EQUAL(notification1.getLinkType(), notification2.getLinkType());
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070099
100 std::ostringstream os;
101 os << notification2;
102 BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification("
103 "Kind: created, "
104 "FaceID: 20, "
105 "RemoteUri: tcp4://192.0.2.1:55555, "
106 "LocalUri: tcp4://192.0.2.2:6363, "
Chengyu Fan36dca992014-09-25 13:42:03 -0600107 "FaceScope: local, "
108 "FacePersistency: on-demand, "
109 "LinkType: multi-access)");
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700110}
111
112BOOST_AUTO_TEST_CASE(EncodeDestroyed)
113{
114 FaceEventNotification notification1;
115 notification1.setKind(FACE_EVENT_DESTROYED)
116 .setFaceId(20)
117 .setRemoteUri("tcp4://192.0.2.1:55555")
118 .setLocalUri("tcp4://192.0.2.2:6363")
Chengyu Fan36dca992014-09-25 13:42:03 -0600119 .setFaceScope(FACE_SCOPE_LOCAL)
120 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
121 .setLinkType(LINK_TYPE_MULTI_ACCESS);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700122 Block wire;
123 BOOST_REQUIRE_NO_THROW(wire = notification1.wireEncode());
124
125 // These octets are obtained by the snippet below.
126 // This check is intended to detect unexpected encoding change in the future.
Chengyu Fan36dca992014-09-25 13:42:03 -0600127 // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
128 // printf("0x%02x, ", *it);
129 // }
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700130 static const uint8_t expected[] = {
Chengyu Fan36dca992014-09-25 13:42:03 -0600131 0xc0, 0x3e, 0xc1, 0x01, 0x02, 0x69, 0x01, 0x14, 0x72, 0x16,
132 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
133 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35,
134 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
135 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32,
136 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01,
137 0x01, 0x86, 0x01, 0x01,
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700138 };
139 BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
140 wire.begin(), wire.end());
141
142 BOOST_REQUIRE_NO_THROW(FaceEventNotification(wire));
143 FaceEventNotification notification2(wire);
144 BOOST_CHECK_EQUAL(notification1.getKind(), notification2.getKind());
145 BOOST_CHECK_EQUAL(notification1.getFaceId(), notification2.getFaceId());
146 BOOST_CHECK_EQUAL(notification1.getRemoteUri(), notification2.getRemoteUri());
147 BOOST_CHECK_EQUAL(notification1.getLocalUri(), notification2.getLocalUri());
Chengyu Fan36dca992014-09-25 13:42:03 -0600148 BOOST_CHECK_EQUAL(notification1.getFaceScope(), notification2.getFaceScope());
149 BOOST_CHECK_EQUAL(notification1.getFacePersistency(), notification2.getFacePersistency());
150 BOOST_CHECK_EQUAL(notification1.getLinkType(), notification2.getLinkType());
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700151
152 std::ostringstream os;
153 os << notification2;
154 BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification("
155 "Kind: destroyed, "
156 "FaceID: 20, "
157 "RemoteUri: tcp4://192.0.2.1:55555, "
158 "LocalUri: tcp4://192.0.2.2:6363, "
Chengyu Fan36dca992014-09-25 13:42:03 -0600159 "FaceScope: local, "
160 "FacePersistency: on-demand, "
161 "LinkType: multi-access)");
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700162}
163
164BOOST_AUTO_TEST_SUITE_END()
165
166} // namespace nfd
167} // namespace ndn