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 | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 7 | #include "management/control-response.hpp" |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 8 | #include "management/fib-management-options.hpp" |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 9 | |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 10 | #include <boost/test/unit_test.hpp> |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 11 | #include <boost/test/output_test_stream.hpp> |
| 12 | |
| 13 | using namespace std; |
| 14 | |
| 15 | namespace ndn { |
| 16 | |
| 17 | BOOST_AUTO_TEST_SUITE(TestNfdControl) |
| 18 | |
| 19 | 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}; |
| 20 | |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 21 | const uint8_t TestFibManagementOptions[] = { |
| 22 | 0x68, 0x1e, 0x03, 0x16, 0x04, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, |
| 23 | 0x6f, 0x73, 0x74, 0x04, 0x03, 0x72, 0x65, 0x67, 0x04, 0x04, 0x74, 0x65, |
| 24 | 0x73, 0x74, 0x69, 0x01, 0x00, 0x6a, 0x01, 0x00 |
| 25 | }; |
| 26 | |
| 27 | // ControlResponse |
| 28 | |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 29 | BOOST_AUTO_TEST_CASE (ControlResponseEncode) |
| 30 | { |
| 31 | ndn::ControlResponse controlResponse(404, "Nothing not found"); |
| 32 | const Block &wire = controlResponse.wireEncode(); |
| 33 | |
| 34 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestControlResponse, TestControlResponse+sizeof(TestControlResponse), |
| 35 | wire.begin(), wire.end()); |
| 36 | } |
| 37 | |
| 38 | BOOST_AUTO_TEST_CASE (ControlResponseDecode) |
| 39 | { |
| 40 | ndn::ControlResponse controlResponse; |
| 41 | |
| 42 | BOOST_REQUIRE_NO_THROW(controlResponse.wireDecode(Block(TestControlResponse, sizeof(TestControlResponse)))); |
| 43 | |
| 44 | BOOST_REQUIRE_EQUAL(controlResponse.getCode(), 404); |
| 45 | BOOST_REQUIRE_EQUAL(controlResponse.getText(), "Nothing not found"); |
| 46 | } |
| 47 | |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 48 | // FibManagementOptions |
| 49 | |
| 50 | BOOST_AUTO_TEST_CASE (FibManagementOptionsEncoding) |
| 51 | { |
| 52 | Name n ("/localhost/reg/test"); |
| 53 | FibManagementOptions opt; |
| 54 | |
| 55 | opt.setName (n); |
| 56 | opt.setFaceId (0); |
| 57 | opt.setCost (0); |
| 58 | |
| 59 | const ndn::Block& blk = opt.wireEncode (); |
| 60 | |
| 61 | BOOST_REQUIRE_EQUAL_COLLECTIONS (TestFibManagementOptions, |
| 62 | TestFibManagementOptions + sizeof (TestFibManagementOptions), |
| 63 | blk.begin (), blk.end ()); |
| 64 | } |
| 65 | |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 66 | BOOST_AUTO_TEST_CASE (FibManagementOptionsFastEncoding) |
| 67 | { |
| 68 | Name n ("/localhost/reg/test"); |
| 69 | FibManagementOptions opt; |
| 70 | |
| 71 | opt.setName (n); |
| 72 | opt.setFaceId (0); |
| 73 | opt.setCost (0); |
| 74 | |
| 75 | EncodingBuffer blk; |
| 76 | |
| 77 | BOOST_REQUIRE_NO_THROW (opt.wireEncode (blk)); |
| 78 | |
| 79 | BOOST_REQUIRE_EQUAL_COLLECTIONS (TestFibManagementOptions, |
| 80 | TestFibManagementOptions + sizeof (TestFibManagementOptions), |
| 81 | blk.begin (), blk.end ()); |
| 82 | |
| 83 | EncodingBuffer blk2 (4); |
| 84 | |
| 85 | BOOST_REQUIRE_NO_THROW (opt.wireEncode (blk2)); |
| 86 | |
| 87 | BOOST_REQUIRE_EQUAL_COLLECTIONS (TestFibManagementOptions, |
| 88 | TestFibManagementOptions + sizeof (TestFibManagementOptions), |
| 89 | blk2.begin (), blk2.end ()); |
| 90 | } |
| 91 | |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 92 | BOOST_AUTO_TEST_CASE (FibManagementOptionsDecoding) |
| 93 | { |
| 94 | Block blk (TestFibManagementOptions, sizeof (TestFibManagementOptions)); |
| 95 | Name n ("/localhost/reg/test"); |
| 96 | FibManagementOptions opt; |
| 97 | |
| 98 | BOOST_REQUIRE_NO_THROW (opt.wireDecode (blk)); |
| 99 | |
| 100 | BOOST_CHECK_EQUAL (opt.getName (), n); |
| 101 | BOOST_CHECK_EQUAL (opt.getFaceId (), 0); |
| 102 | BOOST_CHECK_EQUAL (opt.getCost (), 0); |
| 103 | } |
| 104 | |
| 105 | |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 106 | BOOST_AUTO_TEST_SUITE_END() |
| 107 | |
| 108 | } // namespace ndn |