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 | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 27 | 0x68, 0x49, 0x07, 0x16, 0x08, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 28 | 0x6f, 0x73, 0x74, 0x08, 0x03, 0x72, 0x65, 0x67, 0x08, 0x04, 0x74, 0x65, |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 29 | 0x73, 0x74, 0x69, 0x01, 0x00, 0x6a, 0x01, 0x01, 0x6b, 0x29, 0x07, 0x27, |
| 30 | 0x08, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x08, |
| 31 | 0x03, 0x6e, 0x66, 0x64, 0x08, 0x08, 0x73, 0x74, 0x72, 0x61, 0x74, 0x65, |
| 32 | 0x67, 0x79, 0x08, 0x0b, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2d, 0x77, 0x6f, |
| 33 | 0x72, 0x6c, 0x64 |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 34 | }; |
| 35 | |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 36 | const uint8_t TestFaceManagementOptions[] = { |
| 37 | 0x6c, 0x1e, 0x69, 0x01, 0x0a, 0x72, 0x19, 0x74, 0x63, 0x70, 0x3a, 0x2f, |
| 38 | 0x2f, 0x31, 0x2e, 0x31, 0x2e, 0x31, 0x2e, 0x31, 0x2f, 0x68, 0x65, 0x6c, |
| 39 | 0x6c, 0x6f, 0x2f, 0x77, 0x6f, 0x72, 0x6c, 0x64 |
| 40 | }; |
| 41 | |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 42 | // ControlResponse |
| 43 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 44 | BOOST_AUTO_TEST_CASE(ControlResponseEncode) |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 45 | { |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 46 | ControlResponse controlResponse(404, "Nothing not found"); |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 47 | const Block &wire = controlResponse.wireEncode(); |
| 48 | |
| 49 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestControlResponse, TestControlResponse+sizeof(TestControlResponse), |
| 50 | wire.begin(), wire.end()); |
| 51 | } |
| 52 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 53 | BOOST_AUTO_TEST_CASE(ControlResponseDecode) |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 54 | { |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 55 | ControlResponse controlResponse; |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 56 | |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 57 | BOOST_REQUIRE_NO_THROW(controlResponse.wireDecode(Block(TestControlResponse, sizeof(TestControlResponse)))); |
| 58 | |
| 59 | BOOST_REQUIRE_EQUAL(controlResponse.getCode(), 404); |
| 60 | BOOST_REQUIRE_EQUAL(controlResponse.getText(), "Nothing not found"); |
| 61 | } |
| 62 | |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 63 | // FibManagementOptions |
| 64 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 65 | BOOST_AUTO_TEST_CASE(FibManagementOptionsEncoding) |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 66 | { |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 67 | Name n("/localhost/reg/test"); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 68 | FibManagementOptions opt; |
| 69 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 70 | opt.setName(n); |
| 71 | opt.setFaceId(0); |
| 72 | opt.setCost(1); |
| 73 | opt.setStrategy("/localhost/nfd/strategy/hello-world"); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 74 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 75 | const Block& blk = opt.wireEncode(); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 76 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 77 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibManagementOptions, |
| 78 | TestFibManagementOptions + sizeof(TestFibManagementOptions), |
| 79 | blk.begin(), blk.end()); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 80 | } |
| 81 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 82 | BOOST_AUTO_TEST_CASE(FibManagementOptionsFastEncoding) |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 83 | { |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 84 | Name n("/localhost/reg/test"); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 85 | FibManagementOptions opt; |
| 86 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 87 | opt.setName(n); |
| 88 | opt.setFaceId(0); |
| 89 | opt.setCost(1); |
| 90 | opt.setStrategy("/localhost/nfd/strategy/hello-world"); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 91 | |
| 92 | EncodingBuffer blk; |
| 93 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 94 | BOOST_REQUIRE_NO_THROW(opt.wireEncode(blk)); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 95 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 96 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibManagementOptions, |
| 97 | TestFibManagementOptions + sizeof(TestFibManagementOptions), |
| 98 | blk.begin(), blk.end()); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 99 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 100 | EncodingBuffer blk2(4); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 101 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 102 | BOOST_REQUIRE_NO_THROW(opt.wireEncode(blk2)); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 103 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 104 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibManagementOptions, |
| 105 | TestFibManagementOptions + sizeof(TestFibManagementOptions), |
| 106 | blk2.begin(), blk2.end()); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 107 | } |
| 108 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 109 | BOOST_AUTO_TEST_CASE(FibManagementOptionsDecoding) |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 110 | { |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 111 | Block blk(TestFibManagementOptions, sizeof(TestFibManagementOptions)); |
| 112 | Name n("/localhost/reg/test"); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 113 | FibManagementOptions opt; |
| 114 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 115 | BOOST_REQUIRE_NO_THROW(opt.wireDecode(blk)); |
| 116 | |
| 117 | BOOST_CHECK_EQUAL(opt.getName(), n); |
| 118 | BOOST_CHECK_EQUAL(opt.getFaceId(), 0); |
| 119 | BOOST_CHECK_EQUAL(opt.getCost(), 1); |
| 120 | BOOST_CHECK_EQUAL(opt.getStrategy().toUri(), "/localhost/nfd/strategy/hello-world"); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 121 | } |
| 122 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 123 | BOOST_AUTO_TEST_CASE(FaceManagementOptionsFastEncoding) |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 124 | { |
| 125 | FaceManagementOptions opt; |
| 126 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 127 | opt.setFaceId(10); |
| 128 | opt.setUri("tcp://1.1.1.1/hello/world"); |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 129 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 130 | BOOST_REQUIRE_NO_THROW(opt.wireEncode ()); |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 131 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 132 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFaceManagementOptions, |
| 133 | TestFaceManagementOptions + sizeof(TestFaceManagementOptions), |
| 134 | opt.wireEncode().begin(), opt.wireEncode().end()); |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 135 | } |
| 136 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 137 | BOOST_AUTO_TEST_CASE(FaceManagementOptionsDecoding) |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 138 | { |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 139 | Block blk(TestFaceManagementOptions, sizeof(TestFaceManagementOptions)); |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 140 | FaceManagementOptions opt; |
| 141 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 142 | BOOST_REQUIRE_NO_THROW(opt.wireDecode (blk)); |
| 143 | |
| 144 | BOOST_CHECK_EQUAL(opt.getFaceId(), 10); |
| 145 | BOOST_CHECK_EQUAL(opt.getUri(), "tcp://1.1.1.1/hello/world"); |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 146 | } |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 147 | |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 148 | BOOST_AUTO_TEST_SUITE_END() |
| 149 | |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 150 | } // namespace nfd |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 151 | } // namespace ndn |