blob: 735ba189da554d189228d4b34d8d478ff6a0bd2f [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
21const uint8_t TestControlResponse[] = {0x65, 0x17, 0x66, 0x02, 0x01, 0x94, 0x67, 0x11, 0x4e, 0x6f, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x66, 0x6f, 0x75, 0x6e, 0x64};
22
Wentao Shang4d5e1de2014-01-28 21:00:03 -080023const uint8_t TestFibManagementOptions[] = {
Alexander Afanasyev6835ad82014-02-12 10:07:20 -080024 0x68, 0x1e, 0x01, 0x16, 0x02, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68,
25 0x6f, 0x73, 0x74, 0x02, 0x03, 0x72, 0x65, 0x67, 0x02, 0x04, 0x74, 0x65,
Wentao Shang4d5e1de2014-01-28 21:00:03 -080026 0x73, 0x74, 0x69, 0x01, 0x00, 0x6a, 0x01, 0x00
27};
28
Yingdi Yud3370492014-02-12 17:17:11 -080029const uint8_t TestFaceManagementOptions[] = {
30 0x6c, 0x1e, 0x69, 0x01, 0x0a, 0x72, 0x19, 0x74, 0x63, 0x70, 0x3a, 0x2f,
31 0x2f, 0x31, 0x2e, 0x31, 0x2e, 0x31, 0x2e, 0x31, 0x2f, 0x68, 0x65, 0x6c,
32 0x6c, 0x6f, 0x2f, 0x77, 0x6f, 0x72, 0x6c, 0x64
33};
34
Wentao Shang4d5e1de2014-01-28 21:00:03 -080035// ControlResponse
36
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080037BOOST_AUTO_TEST_CASE (ControlResponseEncode)
38{
Alexander Afanasyeve289b532014-02-09 22:14:44 -080039 ControlResponse controlResponse(404, "Nothing not found");
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080040 const Block &wire = controlResponse.wireEncode();
41
42 BOOST_REQUIRE_EQUAL_COLLECTIONS(TestControlResponse, TestControlResponse+sizeof(TestControlResponse),
43 wire.begin(), wire.end());
44}
45
46BOOST_AUTO_TEST_CASE (ControlResponseDecode)
47{
Alexander Afanasyeve289b532014-02-09 22:14:44 -080048 ControlResponse controlResponse;
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080049
50 BOOST_REQUIRE_NO_THROW(controlResponse.wireDecode(Block(TestControlResponse, sizeof(TestControlResponse))));
51
52 BOOST_REQUIRE_EQUAL(controlResponse.getCode(), 404);
53 BOOST_REQUIRE_EQUAL(controlResponse.getText(), "Nothing not found");
54}
55
Wentao Shang4d5e1de2014-01-28 21:00:03 -080056// FibManagementOptions
57
58BOOST_AUTO_TEST_CASE (FibManagementOptionsEncoding)
59{
60 Name n ("/localhost/reg/test");
61 FibManagementOptions opt;
62
63 opt.setName (n);
64 opt.setFaceId (0);
65 opt.setCost (0);
66
Alexander Afanasyeve289b532014-02-09 22:14:44 -080067 const Block& blk = opt.wireEncode ();
Wentao Shang4d5e1de2014-01-28 21:00:03 -080068
69 BOOST_REQUIRE_EQUAL_COLLECTIONS (TestFibManagementOptions,
70 TestFibManagementOptions + sizeof (TestFibManagementOptions),
71 blk.begin (), blk.end ());
72}
73
Wentao Shang77949212014-02-01 23:42:24 -080074BOOST_AUTO_TEST_CASE (FibManagementOptionsFastEncoding)
75{
76 Name n ("/localhost/reg/test");
77 FibManagementOptions opt;
78
79 opt.setName (n);
80 opt.setFaceId (0);
81 opt.setCost (0);
82
83 EncodingBuffer blk;
84
85 BOOST_REQUIRE_NO_THROW (opt.wireEncode (blk));
86
87 BOOST_REQUIRE_EQUAL_COLLECTIONS (TestFibManagementOptions,
88 TestFibManagementOptions + sizeof (TestFibManagementOptions),
89 blk.begin (), blk.end ());
90
91 EncodingBuffer blk2 (4);
92
93 BOOST_REQUIRE_NO_THROW (opt.wireEncode (blk2));
94
95 BOOST_REQUIRE_EQUAL_COLLECTIONS (TestFibManagementOptions,
96 TestFibManagementOptions + sizeof (TestFibManagementOptions),
97 blk2.begin (), blk2.end ());
98}
99
Wentao Shang4d5e1de2014-01-28 21:00:03 -0800100BOOST_AUTO_TEST_CASE (FibManagementOptionsDecoding)
101{
102 Block blk (TestFibManagementOptions, sizeof (TestFibManagementOptions));
103 Name n ("/localhost/reg/test");
104 FibManagementOptions opt;
105
106 BOOST_REQUIRE_NO_THROW (opt.wireDecode (blk));
107
108 BOOST_CHECK_EQUAL (opt.getName (), n);
109 BOOST_CHECK_EQUAL (opt.getFaceId (), 0);
110 BOOST_CHECK_EQUAL (opt.getCost (), 0);
111}
112
Yingdi Yud3370492014-02-12 17:17:11 -0800113BOOST_AUTO_TEST_CASE (FaceManagementOptionsFastEncoding)
114{
115 FaceManagementOptions opt;
116
117 opt.setFaceId (10);
118 opt.setUri ("tcp://1.1.1.1/hello/world");
119
120 BOOST_REQUIRE_NO_THROW (opt.wireEncode ());
121
122 BOOST_REQUIRE_EQUAL_COLLECTIONS (TestFaceManagementOptions,
123 TestFaceManagementOptions + sizeof (TestFibManagementOptions),
124 opt.wireEncode ().begin (), opt.wireEncode ().end ());
125}
126
127BOOST_AUTO_TEST_CASE (FaceManagementOptionsDecoding)
128{
129 Block blk (TestFaceManagementOptions, sizeof (TestFaceManagementOptions));
130 FaceManagementOptions opt;
131
132 BOOST_REQUIRE_NO_THROW (opt.wireDecode (blk));
133
134 BOOST_CHECK_EQUAL (opt.getFaceId(), 10);
135 BOOST_CHECK_EQUAL (opt.getUri(), "tcp://1.1.1.1/hello/world");
136}
Wentao Shang4d5e1de2014-01-28 21:00:03 -0800137
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -0800138BOOST_AUTO_TEST_SUITE_END()
139
Alexander Afanasyeve289b532014-02-09 22:14:44 -0800140} // namespace nfd
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -0800141} // namespace ndn