Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2013-2014, Regents of the University of California. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 7 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 8 | * |
| 9 | * This file licensed under New BSD License. See COPYING for detailed information about |
| 10 | * ndn-cxx library copyright, permissions, and redistribution restrictions. |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include "management/nfd-face-status.hpp" |
| 14 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 15 | #include "boost-test.hpp" |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 16 | |
| 17 | namespace ndn { |
| 18 | namespace nfd { |
| 19 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 20 | BOOST_AUTO_TEST_SUITE(ManagementTestNfdFaceStatus) |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 21 | |
| 22 | BOOST_AUTO_TEST_CASE(Encode) |
| 23 | { |
| 24 | FaceStatus status1; |
| 25 | status1.setFaceId(100) |
| 26 | .setRemoteUri("tcp4://192.0.2.1:6363") |
| 27 | .setLocalUri("tcp4://192.0.2.2:55555") |
| 28 | .setFlags(FACE_IS_ON_DEMAND) |
| 29 | .setNInInterests(10) |
| 30 | .setNInDatas(200) |
| 31 | .setNOutInterests(3000) |
| 32 | .setNOutDatas(4); |
| 33 | |
| 34 | Block wire; |
| 35 | BOOST_REQUIRE_NO_THROW(wire = status1.wireEncode()); |
| 36 | |
| 37 | // These octets are obtained by the snippet below. |
| 38 | // This check is intended to detect unexpected encoding change in the future. |
| 39 | //for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) { |
| 40 | // printf("0x%02x, ", *it); |
| 41 | //} |
| 42 | static const uint8_t expected[] = { |
| 43 | 0x80, 0x42, 0x69, 0x01, 0x64, 0x72, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, |
| 44 | 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, |
| 45 | 0x36, 0x33, 0x36, 0x33, 0x81, 0x16, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, |
| 46 | 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32, 0x3a, 0x35, |
| 47 | 0x35, 0x35, 0x35, 0x35, 0xc2, 0x01, 0x02, 0x90, 0x01, 0x0a, 0x91, 0x01, |
| 48 | 0xc8, 0x92, 0x02, 0x0b, 0xb8, 0x93, 0x01, 0x04 |
| 49 | }; |
| 50 | BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected), |
| 51 | wire.begin(), wire.end()); |
| 52 | |
| 53 | BOOST_REQUIRE_NO_THROW(FaceStatus(wire)); |
| 54 | FaceStatus status2(wire); |
| 55 | BOOST_CHECK_EQUAL(status1.getFaceId(), status2.getFaceId()); |
| 56 | BOOST_CHECK_EQUAL(status1.getRemoteUri(), status2.getRemoteUri()); |
| 57 | BOOST_CHECK_EQUAL(status1.getLocalUri(), status2.getLocalUri()); |
| 58 | BOOST_CHECK_EQUAL(status1.getFlags(), status2.getFlags()); |
| 59 | BOOST_CHECK_EQUAL(status1.getNInInterests(), status2.getNInInterests()); |
| 60 | BOOST_CHECK_EQUAL(status1.getNInDatas(), status2.getNInDatas()); |
| 61 | BOOST_CHECK_EQUAL(status1.getNOutInterests(), status2.getNOutInterests()); |
| 62 | BOOST_CHECK_EQUAL(status1.getNOutDatas(), status2.getNOutDatas()); |
| 63 | |
| 64 | std::ostringstream os; |
| 65 | os << status2; |
| 66 | BOOST_CHECK_EQUAL(os.str(), "FaceStatus(FaceID: 100, " |
| 67 | "RemoteUri: tcp4://192.0.2.1:6363, " |
| 68 | "LocalUri: tcp4://192.0.2.2:55555, " |
| 69 | "Flags: 2, " |
| 70 | "Counters: 10|200|3000|4)"); |
| 71 | } |
| 72 | |
| 73 | BOOST_AUTO_TEST_SUITE_END() |
| 74 | |
| 75 | } // namespace nfd |
| 76 | } // namespace ndn |