blob: fe3457c97833a55ac8ec71f1cddaf26f6dd770f8 [file] [log] [blame]
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -07001/* -*- 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-status.hpp"
8
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07009#include "boost-test.hpp"
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070010
11namespace ndn {
12namespace nfd {
13
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070014BOOST_AUTO_TEST_SUITE(ManagementTestNfdFaceStatus)
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070015
16BOOST_AUTO_TEST_CASE(Encode)
17{
18 FaceStatus status1;
19 status1.setFaceId(100)
20 .setRemoteUri("tcp4://192.0.2.1:6363")
21 .setLocalUri("tcp4://192.0.2.2:55555")
22 .setFlags(FACE_IS_ON_DEMAND)
23 .setNInInterests(10)
24 .setNInDatas(200)
25 .setNOutInterests(3000)
26 .setNOutDatas(4);
27
28 Block wire;
29 BOOST_REQUIRE_NO_THROW(wire = status1.wireEncode());
30
31 // These octets are obtained by the snippet below.
32 // This check is intended to detect unexpected encoding change in the future.
33 //for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
34 // printf("0x%02x, ", *it);
35 //}
36 static const uint8_t expected[] = {
37 0x80, 0x42, 0x69, 0x01, 0x64, 0x72, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a,
38 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a,
39 0x36, 0x33, 0x36, 0x33, 0x81, 0x16, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
40 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32, 0x3a, 0x35,
41 0x35, 0x35, 0x35, 0x35, 0xc2, 0x01, 0x02, 0x90, 0x01, 0x0a, 0x91, 0x01,
42 0xc8, 0x92, 0x02, 0x0b, 0xb8, 0x93, 0x01, 0x04
43 };
44 BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
45 wire.begin(), wire.end());
46
47 BOOST_REQUIRE_NO_THROW(FaceStatus(wire));
48 FaceStatus status2(wire);
49 BOOST_CHECK_EQUAL(status1.getFaceId(), status2.getFaceId());
50 BOOST_CHECK_EQUAL(status1.getRemoteUri(), status2.getRemoteUri());
51 BOOST_CHECK_EQUAL(status1.getLocalUri(), status2.getLocalUri());
52 BOOST_CHECK_EQUAL(status1.getFlags(), status2.getFlags());
53 BOOST_CHECK_EQUAL(status1.getNInInterests(), status2.getNInInterests());
54 BOOST_CHECK_EQUAL(status1.getNInDatas(), status2.getNInDatas());
55 BOOST_CHECK_EQUAL(status1.getNOutInterests(), status2.getNOutInterests());
56 BOOST_CHECK_EQUAL(status1.getNOutDatas(), status2.getNOutDatas());
57
58 std::ostringstream os;
59 os << status2;
60 BOOST_CHECK_EQUAL(os.str(), "FaceStatus(FaceID: 100, "
61 "RemoteUri: tcp4://192.0.2.1:6363, "
62 "LocalUri: tcp4://192.0.2.2:55555, "
63 "Flags: 2, "
64 "Counters: 10|200|3000|4)");
65}
66
67BOOST_AUTO_TEST_SUITE_END()
68
69} // namespace nfd
70} // namespace ndn