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" |
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 { |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame^] | 16 | namespace nfd { |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 17 | |
| 18 | BOOST_AUTO_TEST_SUITE(TestNfdControl) |
| 19 | |
| 20 | 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}; |
| 21 | |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 22 | const 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 Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 30 | BOOST_AUTO_TEST_CASE (ControlResponseEncode) |
| 31 | { |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame^] | 32 | ControlResponse controlResponse(404, "Nothing not found"); |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 33 | const Block &wire = controlResponse.wireEncode(); |
| 34 | |
| 35 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestControlResponse, TestControlResponse+sizeof(TestControlResponse), |
| 36 | wire.begin(), wire.end()); |
| 37 | } |
| 38 | |
| 39 | BOOST_AUTO_TEST_CASE (ControlResponseDecode) |
| 40 | { |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame^] | 41 | ControlResponse controlResponse; |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 42 | |
| 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 Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 49 | // FibManagementOptions |
| 50 | |
| 51 | BOOST_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 Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame^] | 60 | const Block& blk = opt.wireEncode (); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 61 | |
| 62 | BOOST_REQUIRE_EQUAL_COLLECTIONS (TestFibManagementOptions, |
| 63 | TestFibManagementOptions + sizeof (TestFibManagementOptions), |
| 64 | blk.begin (), blk.end ()); |
| 65 | } |
| 66 | |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 67 | BOOST_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 Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 93 | BOOST_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 Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 107 | BOOST_AUTO_TEST_SUITE_END() |
| 108 | |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame^] | 109 | } // namespace nfd |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 110 | } // namespace ndn |