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-status.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(ManagementTestNfdFaceStatus) |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 30 | |
| 31 | BOOST_AUTO_TEST_CASE(Encode) |
| 32 | { |
| 33 | FaceStatus status1; |
| 34 | status1.setFaceId(100) |
| 35 | .setRemoteUri("tcp4://192.0.2.1:6363") |
| 36 | .setLocalUri("tcp4://192.0.2.2:55555") |
| 37 | .setFlags(FACE_IS_ON_DEMAND) |
Alexander Afanasyev | e63eaf6 | 2014-06-30 12:40:55 -0700 | [diff] [blame] | 38 | .setExpirationPeriod(time::seconds(10)) |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 39 | .setNInInterests(10) |
| 40 | .setNInDatas(200) |
| 41 | .setNOutInterests(3000) |
| 42 | .setNOutDatas(4); |
| 43 | |
| 44 | Block wire; |
| 45 | BOOST_REQUIRE_NO_THROW(wire = status1.wireEncode()); |
| 46 | |
| 47 | // These octets are obtained by the snippet below. |
| 48 | // This check is intended to detect unexpected encoding change in the future. |
Alexander Afanasyev | e63eaf6 | 2014-06-30 12:40:55 -0700 | [diff] [blame] | 49 | // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) { |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 50 | // printf("0x%02x, ", *it); |
Alexander Afanasyev | e63eaf6 | 2014-06-30 12:40:55 -0700 | [diff] [blame] | 51 | // } |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 52 | static const uint8_t expected[] = { |
Alexander Afanasyev | e63eaf6 | 2014-06-30 12:40:55 -0700 | [diff] [blame] | 53 | 0x80, 0x46, 0x69, 0x01, 0x64, 0x72, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 54 | 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, |
| 55 | 0x36, 0x33, 0x36, 0x33, 0x81, 0x16, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, |
| 56 | 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32, 0x3a, 0x35, |
Alexander Afanasyev | e63eaf6 | 2014-06-30 12:40:55 -0700 | [diff] [blame] | 57 | 0x35, 0x35, 0x35, 0x35, 0x6d, 0x02, 0x27, 0x10, 0xc2, 0x01, 0x02, 0x90, |
| 58 | 0x01, 0x0a, 0x91, 0x01, 0xc8, 0x92, 0x02, 0x0b, 0xb8, 0x93, 0x01, 0x04 |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 59 | }; |
| 60 | BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected), |
| 61 | wire.begin(), wire.end()); |
| 62 | |
| 63 | BOOST_REQUIRE_NO_THROW(FaceStatus(wire)); |
| 64 | FaceStatus status2(wire); |
| 65 | BOOST_CHECK_EQUAL(status1.getFaceId(), status2.getFaceId()); |
| 66 | BOOST_CHECK_EQUAL(status1.getRemoteUri(), status2.getRemoteUri()); |
| 67 | BOOST_CHECK_EQUAL(status1.getLocalUri(), status2.getLocalUri()); |
| 68 | BOOST_CHECK_EQUAL(status1.getFlags(), status2.getFlags()); |
| 69 | BOOST_CHECK_EQUAL(status1.getNInInterests(), status2.getNInInterests()); |
| 70 | BOOST_CHECK_EQUAL(status1.getNInDatas(), status2.getNInDatas()); |
| 71 | BOOST_CHECK_EQUAL(status1.getNOutInterests(), status2.getNOutInterests()); |
| 72 | BOOST_CHECK_EQUAL(status1.getNOutDatas(), status2.getNOutDatas()); |
| 73 | |
| 74 | std::ostringstream os; |
| 75 | os << status2; |
| 76 | BOOST_CHECK_EQUAL(os.str(), "FaceStatus(FaceID: 100, " |
| 77 | "RemoteUri: tcp4://192.0.2.1:6363, " |
| 78 | "LocalUri: tcp4://192.0.2.2:55555, " |
Alexander Afanasyev | e63eaf6 | 2014-06-30 12:40:55 -0700 | [diff] [blame] | 79 | "ExpirationPeriod: 10000 milliseconds, " |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 80 | "Flags: 2, " |
| 81 | "Counters: 10|200|3000|4)"); |
| 82 | } |
| 83 | |
| 84 | BOOST_AUTO_TEST_SUITE_END() |
| 85 | |
| 86 | } // namespace nfd |
| 87 | } // namespace ndn |