blob: 79b4d393c20c7409bc00c397103e2f2a920c9fc7 [file] [log] [blame]
Wentao Shang77949212014-02-01 23:42:24 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -08002/**
3 * Copyright (C) 2013 Regents of the University of California.
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -08004 * See COPYING for copyright and distribution information.
5 */
6
Alexander Afanasyeve289b532014-02-09 22:14:44 -08007#include "management/nfd-control-response.hpp"
8#include "management/nfd-fib-management-options.hpp"
Yingdi Yud3370492014-02-12 17:17:11 -08009#include "management/nfd-face-management-options.hpp"
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080010
Wentao Shang4d5e1de2014-01-28 21:00:03 -080011#include <boost/test/unit_test.hpp>
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080012#include <boost/test/output_test_stream.hpp>
13
14using namespace std;
15
16namespace ndn {
Alexander Afanasyeve289b532014-02-09 22:14:44 -080017namespace nfd {
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080018
19BOOST_AUTO_TEST_SUITE(TestNfdControl)
20
Alexander Afanasyev4b456282014-02-13 00:34:34 -080021const uint8_t TestControlResponse[] = {0x65, 0x17,
22 0x66, 0x02, 0x01, 0x94, 0x67, 0x11, 0x4e, 0x6f, 0x74,
23 0x68, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x6f, 0x74, 0x20,
24 0x66, 0x6f, 0x75, 0x6e, 0x64};
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080025
Wentao Shang4d5e1de2014-01-28 21:00:03 -080026const uint8_t TestFibManagementOptions[] = {
Alexander Afanasyev4b456282014-02-13 00:34:34 -080027 0x68, 0x1e, 0x07, 0x16, 0x08, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68,
28 0x6f, 0x73, 0x74, 0x08, 0x03, 0x72, 0x65, 0x67, 0x08, 0x04, 0x74, 0x65,
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080029 0x73, 0x74, 0x69, 0x01, 0x00, 0x6a, 0x01, 0x01
Wentao Shang4d5e1de2014-01-28 21:00:03 -080030};
31
Yingdi Yud3370492014-02-12 17:17:11 -080032const uint8_t TestFaceManagementOptions[] = {
33 0x6c, 0x1e, 0x69, 0x01, 0x0a, 0x72, 0x19, 0x74, 0x63, 0x70, 0x3a, 0x2f,
34 0x2f, 0x31, 0x2e, 0x31, 0x2e, 0x31, 0x2e, 0x31, 0x2f, 0x68, 0x65, 0x6c,
35 0x6c, 0x6f, 0x2f, 0x77, 0x6f, 0x72, 0x6c, 0x64
36};
37
Wentao Shang4d5e1de2014-01-28 21:00:03 -080038// ControlResponse
39
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080040BOOST_AUTO_TEST_CASE (ControlResponseEncode)
41{
Alexander Afanasyeve289b532014-02-09 22:14:44 -080042 ControlResponse controlResponse(404, "Nothing not found");
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080043 const Block &wire = controlResponse.wireEncode();
44
45 BOOST_REQUIRE_EQUAL_COLLECTIONS(TestControlResponse, TestControlResponse+sizeof(TestControlResponse),
46 wire.begin(), wire.end());
47}
48
49BOOST_AUTO_TEST_CASE (ControlResponseDecode)
50{
Alexander Afanasyeve289b532014-02-09 22:14:44 -080051 ControlResponse controlResponse;
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080052
53 BOOST_REQUIRE_NO_THROW(controlResponse.wireDecode(Block(TestControlResponse, sizeof(TestControlResponse))));
54
55 BOOST_REQUIRE_EQUAL(controlResponse.getCode(), 404);
56 BOOST_REQUIRE_EQUAL(controlResponse.getText(), "Nothing not found");
57}
58
Wentao Shang4d5e1de2014-01-28 21:00:03 -080059// FibManagementOptions
60
61BOOST_AUTO_TEST_CASE (FibManagementOptionsEncoding)
62{
63 Name n ("/localhost/reg/test");
64 FibManagementOptions opt;
65
66 opt.setName (n);
67 opt.setFaceId (0);
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080068 opt.setCost (1);
Wentao Shang4d5e1de2014-01-28 21:00:03 -080069
Alexander Afanasyeve289b532014-02-09 22:14:44 -080070 const Block& blk = opt.wireEncode ();
Wentao Shang4d5e1de2014-01-28 21:00:03 -080071
72 BOOST_REQUIRE_EQUAL_COLLECTIONS (TestFibManagementOptions,
73 TestFibManagementOptions + sizeof (TestFibManagementOptions),
74 blk.begin (), blk.end ());
75}
76
Wentao Shang77949212014-02-01 23:42:24 -080077BOOST_AUTO_TEST_CASE (FibManagementOptionsFastEncoding)
78{
79 Name n ("/localhost/reg/test");
80 FibManagementOptions opt;
81
82 opt.setName (n);
83 opt.setFaceId (0);
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080084 opt.setCost (1);
Wentao Shang77949212014-02-01 23:42:24 -080085
86 EncodingBuffer blk;
87
88 BOOST_REQUIRE_NO_THROW (opt.wireEncode (blk));
89
90 BOOST_REQUIRE_EQUAL_COLLECTIONS (TestFibManagementOptions,
91 TestFibManagementOptions + sizeof (TestFibManagementOptions),
92 blk.begin (), blk.end ());
93
94 EncodingBuffer blk2 (4);
95
96 BOOST_REQUIRE_NO_THROW (opt.wireEncode (blk2));
97
98 BOOST_REQUIRE_EQUAL_COLLECTIONS (TestFibManagementOptions,
99 TestFibManagementOptions + sizeof (TestFibManagementOptions),
100 blk2.begin (), blk2.end ());
101}
102
Wentao Shang4d5e1de2014-01-28 21:00:03 -0800103BOOST_AUTO_TEST_CASE (FibManagementOptionsDecoding)
104{
105 Block blk (TestFibManagementOptions, sizeof (TestFibManagementOptions));
106 Name n ("/localhost/reg/test");
107 FibManagementOptions opt;
108
109 BOOST_REQUIRE_NO_THROW (opt.wireDecode (blk));
110
111 BOOST_CHECK_EQUAL (opt.getName (), n);
112 BOOST_CHECK_EQUAL (opt.getFaceId (), 0);
Alexander Afanasyev0553cd52014-02-18 02:34:45 -0800113 BOOST_CHECK_EQUAL (opt.getCost (), 1);
Wentao Shang4d5e1de2014-01-28 21:00:03 -0800114}
115
Yingdi Yud3370492014-02-12 17:17:11 -0800116BOOST_AUTO_TEST_CASE (FaceManagementOptionsFastEncoding)
117{
118 FaceManagementOptions opt;
119
120 opt.setFaceId (10);
121 opt.setUri ("tcp://1.1.1.1/hello/world");
122
123 BOOST_REQUIRE_NO_THROW (opt.wireEncode ());
124
125 BOOST_REQUIRE_EQUAL_COLLECTIONS (TestFaceManagementOptions,
126 TestFaceManagementOptions + sizeof (TestFibManagementOptions),
127 opt.wireEncode ().begin (), opt.wireEncode ().end ());
128}
129
130BOOST_AUTO_TEST_CASE (FaceManagementOptionsDecoding)
131{
132 Block blk (TestFaceManagementOptions, sizeof (TestFaceManagementOptions));
133 FaceManagementOptions opt;
134
135 BOOST_REQUIRE_NO_THROW (opt.wireDecode (blk));
136
137 BOOST_CHECK_EQUAL (opt.getFaceId(), 10);
138 BOOST_CHECK_EQUAL (opt.getUri(), "tcp://1.1.1.1/hello/world");
139}
Wentao Shang4d5e1de2014-01-28 21:00:03 -0800140
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -0800141BOOST_AUTO_TEST_SUITE_END()
142
Alexander Afanasyeve289b532014-02-09 22:14:44 -0800143} // namespace nfd
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -0800144} // namespace ndn