Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -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-forwarder-status.hpp" |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 8 | #include "data.hpp" |
| 9 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 10 | #include "boost-test.hpp" |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 11 | |
| 12 | namespace ndn { |
| 13 | namespace nfd { |
| 14 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 15 | BOOST_AUTO_TEST_SUITE(ManagementTestNfdForwarderStatus) |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 16 | |
| 17 | BOOST_AUTO_TEST_CASE(Encode) |
| 18 | { |
| 19 | ForwarderStatus status1; |
| 20 | status1.setNfdVersion(1014210635); |
| 21 | status1.setStartTimestamp(time::fromUnixTimestamp(time::milliseconds(375193249325))); |
| 22 | status1.setCurrentTimestamp(time::fromUnixTimestamp(time::milliseconds(886109034272))); |
| 23 | status1.setNNameTreeEntries(1849943160); |
| 24 | status1.setNFibEntries(621739748); |
| 25 | status1.setNPitEntries(482129741); |
| 26 | status1.setNMeasurementsEntries(1771725298); |
| 27 | status1.setNCsEntries(1264968688); |
| 28 | status1.setNInInterests(612811615); |
| 29 | status1.setNInDatas(1843576050); |
| 30 | status1.setNOutInterests(952144445); |
| 31 | status1.setNOutDatas(138198826); |
| 32 | |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 33 | Block wire; |
| 34 | BOOST_REQUIRE_NO_THROW(wire = status1.wireEncode()); |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 35 | |
| 36 | // These octets are obtained by the snippet below. |
| 37 | // This check is intended to detect unexpected encoding change in the future. |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 38 | //for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) { |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 39 | // printf("0x%02x, ", *it); |
| 40 | //} |
| 41 | static const uint8_t expected[] = { |
| 42 | 0x15, 0x50, 0x80, 0x04, 0x3c, 0x73, 0xa0, 0x4b, 0x81, 0x08, 0x00, 0x00, |
| 43 | 0x00, 0x57, 0x5b, 0x42, 0xa6, 0x2d, 0x82, 0x08, 0x00, 0x00, 0x00, 0xce, |
| 44 | 0x50, 0x36, 0xd7, 0x20, 0x83, 0x04, 0x6e, 0x43, 0xe4, 0x78, 0x84, 0x04, |
| 45 | 0x25, 0x0e, 0xfe, 0xe4, 0x85, 0x04, 0x1c, 0xbc, 0xb7, 0x4d, 0x86, 0x04, |
| 46 | 0x69, 0x9a, 0x61, 0xf2, 0x87, 0x04, 0x4b, 0x65, 0xe3, 0xf0, 0x90, 0x04, |
| 47 | 0x24, 0x86, 0xc3, 0x5f, 0x91, 0x04, 0x6d, 0xe2, 0xbc, 0xf2, 0x92, 0x04, |
| 48 | 0x38, 0xc0, 0x92, 0x3d, 0x93, 0x04, 0x08, 0x3c, 0xbf, 0x2a |
| 49 | }; |
| 50 | BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected), |
| 51 | wire.begin(), wire.end()); |
| 52 | |
| 53 | Data data; |
| 54 | data.setContent(wire); |
| 55 | |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 56 | BOOST_REQUIRE_NO_THROW(ForwarderStatus(data.getContent())); |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 57 | ForwarderStatus status2(data.getContent()); |
| 58 | BOOST_CHECK_EQUAL(status1.getNfdVersion(), status2.getNfdVersion()); |
| 59 | BOOST_CHECK_EQUAL(status1.getStartTimestamp(), status2.getStartTimestamp()); |
| 60 | BOOST_CHECK_EQUAL(status1.getCurrentTimestamp(), status2.getCurrentTimestamp()); |
| 61 | BOOST_CHECK_EQUAL(status1.getNNameTreeEntries(), status2.getNNameTreeEntries()); |
| 62 | BOOST_CHECK_EQUAL(status1.getNFibEntries(), status2.getNFibEntries()); |
| 63 | BOOST_CHECK_EQUAL(status1.getNPitEntries(), status2.getNPitEntries()); |
| 64 | BOOST_CHECK_EQUAL(status1.getNMeasurementsEntries(), status2.getNMeasurementsEntries()); |
| 65 | BOOST_CHECK_EQUAL(status1.getNCsEntries(), status2.getNCsEntries()); |
| 66 | BOOST_CHECK_EQUAL(status1.getNInInterests(), status2.getNInInterests()); |
| 67 | BOOST_CHECK_EQUAL(status1.getNInDatas(), status2.getNInDatas()); |
| 68 | BOOST_CHECK_EQUAL(status1.getNOutInterests(), status2.getNOutInterests()); |
| 69 | BOOST_CHECK_EQUAL(status1.getNOutDatas(), status2.getNOutDatas()); |
| 70 | } |
| 71 | |
| 72 | BOOST_AUTO_TEST_SUITE_END() |
| 73 | |
| 74 | } // namespace nfd |
| 75 | } // namespace ndn |