blob: 131562783f7c744343a3e6a6bc26e623e6cb7d71 [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"
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -08009
Wentao Shang4d5e1de2014-01-28 21:00:03 -080010#include <boost/test/unit_test.hpp>
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080011#include <boost/test/output_test_stream.hpp>
12
13using namespace std;
14
15namespace ndn {
Alexander Afanasyeve289b532014-02-09 22:14:44 -080016namespace nfd {
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080017
18BOOST_AUTO_TEST_SUITE(TestNfdControl)
19
20const 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};
21
Wentao Shang4d5e1de2014-01-28 21:00:03 -080022const uint8_t TestFibManagementOptions[] = {
23 0x68, 0x1e, 0x03, 0x16, 0x04, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68,
24 0x6f, 0x73, 0x74, 0x04, 0x03, 0x72, 0x65, 0x67, 0x04, 0x04, 0x74, 0x65,
25 0x73, 0x74, 0x69, 0x01, 0x00, 0x6a, 0x01, 0x00
26};
27
28// ControlResponse
29
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080030BOOST_AUTO_TEST_CASE (ControlResponseEncode)
31{
Alexander Afanasyeve289b532014-02-09 22:14:44 -080032 ControlResponse controlResponse(404, "Nothing not found");
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080033 const Block &wire = controlResponse.wireEncode();
34
35 BOOST_REQUIRE_EQUAL_COLLECTIONS(TestControlResponse, TestControlResponse+sizeof(TestControlResponse),
36 wire.begin(), wire.end());
37}
38
39BOOST_AUTO_TEST_CASE (ControlResponseDecode)
40{
Alexander Afanasyeve289b532014-02-09 22:14:44 -080041 ControlResponse controlResponse;
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080042
43 BOOST_REQUIRE_NO_THROW(controlResponse.wireDecode(Block(TestControlResponse, sizeof(TestControlResponse))));
44
45 BOOST_REQUIRE_EQUAL(controlResponse.getCode(), 404);
46 BOOST_REQUIRE_EQUAL(controlResponse.getText(), "Nothing not found");
47}
48
Wentao Shang4d5e1de2014-01-28 21:00:03 -080049// FibManagementOptions
50
51BOOST_AUTO_TEST_CASE (FibManagementOptionsEncoding)
52{
53 Name n ("/localhost/reg/test");
54 FibManagementOptions opt;
55
56 opt.setName (n);
57 opt.setFaceId (0);
58 opt.setCost (0);
59
Alexander Afanasyeve289b532014-02-09 22:14:44 -080060 const Block& blk = opt.wireEncode ();
Wentao Shang4d5e1de2014-01-28 21:00:03 -080061
62 BOOST_REQUIRE_EQUAL_COLLECTIONS (TestFibManagementOptions,
63 TestFibManagementOptions + sizeof (TestFibManagementOptions),
64 blk.begin (), blk.end ());
65}
66
Wentao Shang77949212014-02-01 23:42:24 -080067BOOST_AUTO_TEST_CASE (FibManagementOptionsFastEncoding)
68{
69 Name n ("/localhost/reg/test");
70 FibManagementOptions opt;
71
72 opt.setName (n);
73 opt.setFaceId (0);
74 opt.setCost (0);
75
76 EncodingBuffer blk;
77
78 BOOST_REQUIRE_NO_THROW (opt.wireEncode (blk));
79
80 BOOST_REQUIRE_EQUAL_COLLECTIONS (TestFibManagementOptions,
81 TestFibManagementOptions + sizeof (TestFibManagementOptions),
82 blk.begin (), blk.end ());
83
84 EncodingBuffer blk2 (4);
85
86 BOOST_REQUIRE_NO_THROW (opt.wireEncode (blk2));
87
88 BOOST_REQUIRE_EQUAL_COLLECTIONS (TestFibManagementOptions,
89 TestFibManagementOptions + sizeof (TestFibManagementOptions),
90 blk2.begin (), blk2.end ());
91}
92
Wentao Shang4d5e1de2014-01-28 21:00:03 -080093BOOST_AUTO_TEST_CASE (FibManagementOptionsDecoding)
94{
95 Block blk (TestFibManagementOptions, sizeof (TestFibManagementOptions));
96 Name n ("/localhost/reg/test");
97 FibManagementOptions opt;
98
99 BOOST_REQUIRE_NO_THROW (opt.wireDecode (blk));
100
101 BOOST_CHECK_EQUAL (opt.getName (), n);
102 BOOST_CHECK_EQUAL (opt.getFaceId (), 0);
103 BOOST_CHECK_EQUAL (opt.getCost (), 0);
104}
105
106
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -0800107BOOST_AUTO_TEST_SUITE_END()
108
Alexander Afanasyeve289b532014-02-09 22:14:44 -0800109} // namespace nfd
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -0800110} // namespace ndn