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 | |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 21 | const 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 Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 25 | |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 26 | const uint8_t TestFibManagementOptions[] = { |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 27 | 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 Afanasyev | 0553cd5 | 2014-02-18 02:34:45 -0800 | [diff] [blame^] | 29 | 0x73, 0x74, 0x69, 0x01, 0x00, 0x6a, 0x01, 0x01 |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 30 | }; |
| 31 | |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 32 | const 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 Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 38 | // ControlResponse |
| 39 | |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 40 | BOOST_AUTO_TEST_CASE (ControlResponseEncode) |
| 41 | { |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 42 | ControlResponse controlResponse(404, "Nothing not found"); |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 43 | const Block &wire = controlResponse.wireEncode(); |
| 44 | |
| 45 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestControlResponse, TestControlResponse+sizeof(TestControlResponse), |
| 46 | wire.begin(), wire.end()); |
| 47 | } |
| 48 | |
| 49 | BOOST_AUTO_TEST_CASE (ControlResponseDecode) |
| 50 | { |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 51 | ControlResponse controlResponse; |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 52 | |
| 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 Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 59 | // FibManagementOptions |
| 60 | |
| 61 | BOOST_AUTO_TEST_CASE (FibManagementOptionsEncoding) |
| 62 | { |
| 63 | Name n ("/localhost/reg/test"); |
| 64 | FibManagementOptions opt; |
| 65 | |
| 66 | opt.setName (n); |
| 67 | opt.setFaceId (0); |
Alexander Afanasyev | 0553cd5 | 2014-02-18 02:34:45 -0800 | [diff] [blame^] | 68 | opt.setCost (1); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 69 | |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 70 | const Block& blk = opt.wireEncode (); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 71 | |
| 72 | BOOST_REQUIRE_EQUAL_COLLECTIONS (TestFibManagementOptions, |
| 73 | TestFibManagementOptions + sizeof (TestFibManagementOptions), |
| 74 | blk.begin (), blk.end ()); |
| 75 | } |
| 76 | |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 77 | BOOST_AUTO_TEST_CASE (FibManagementOptionsFastEncoding) |
| 78 | { |
| 79 | Name n ("/localhost/reg/test"); |
| 80 | FibManagementOptions opt; |
| 81 | |
| 82 | opt.setName (n); |
| 83 | opt.setFaceId (0); |
Alexander Afanasyev | 0553cd5 | 2014-02-18 02:34:45 -0800 | [diff] [blame^] | 84 | opt.setCost (1); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 85 | |
| 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 Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 103 | BOOST_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 Afanasyev | 0553cd5 | 2014-02-18 02:34:45 -0800 | [diff] [blame^] | 113 | BOOST_CHECK_EQUAL (opt.getCost (), 1); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 114 | } |
| 115 | |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 116 | BOOST_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 | |
| 130 | BOOST_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 Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 140 | |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 141 | BOOST_AUTO_TEST_SUITE_END() |
| 142 | |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 143 | } // namespace nfd |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 144 | } // namespace ndn |