Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 2 | /** |
| 3 | * Copyright (C) 2013 Regents of the University of California. |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 7 | #include "management/nfd-control-response.hpp" |
| 8 | #include "management/nfd-fib-management-options.hpp" |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame^] | 9 | #include "management/nfd-face-management-options.hpp" |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 10 | |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 11 | #include <boost/test/unit_test.hpp> |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 12 | #include <boost/test/output_test_stream.hpp> |
| 13 | |
| 14 | using namespace std; |
| 15 | |
| 16 | namespace ndn { |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 17 | namespace nfd { |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 18 | |
| 19 | BOOST_AUTO_TEST_SUITE(TestNfdControl) |
| 20 | |
| 21 | const 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 Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 23 | const uint8_t TestFibManagementOptions[] = { |
Alexander Afanasyev | 6835ad8 | 2014-02-12 10:07:20 -0800 | [diff] [blame] | 24 | 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 Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 26 | 0x73, 0x74, 0x69, 0x01, 0x00, 0x6a, 0x01, 0x00 |
| 27 | }; |
| 28 | |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame^] | 29 | const 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 Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 35 | // ControlResponse |
| 36 | |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 37 | BOOST_AUTO_TEST_CASE (ControlResponseEncode) |
| 38 | { |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 39 | ControlResponse controlResponse(404, "Nothing not found"); |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 40 | const Block &wire = controlResponse.wireEncode(); |
| 41 | |
| 42 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestControlResponse, TestControlResponse+sizeof(TestControlResponse), |
| 43 | wire.begin(), wire.end()); |
| 44 | } |
| 45 | |
| 46 | BOOST_AUTO_TEST_CASE (ControlResponseDecode) |
| 47 | { |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 48 | ControlResponse controlResponse; |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 49 | |
| 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 Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 56 | // FibManagementOptions |
| 57 | |
| 58 | BOOST_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 Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 67 | const Block& blk = opt.wireEncode (); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 68 | |
| 69 | BOOST_REQUIRE_EQUAL_COLLECTIONS (TestFibManagementOptions, |
| 70 | TestFibManagementOptions + sizeof (TestFibManagementOptions), |
| 71 | blk.begin (), blk.end ()); |
| 72 | } |
| 73 | |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 74 | BOOST_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 Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 100 | BOOST_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 Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame^] | 113 | BOOST_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 | |
| 127 | BOOST_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 Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 137 | |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 138 | BOOST_AUTO_TEST_SUITE_END() |
| 139 | |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 140 | } // namespace nfd |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 141 | } // namespace ndn |