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