Alexander Afanasyev | 0553cd5 | 2014-02-18 02:34:45 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include "management/nrd-prefix-reg-options.hpp" |
| 8 | |
| 9 | #include <boost/test/unit_test.hpp> |
| 10 | #include <boost/test/output_test_stream.hpp> |
| 11 | |
| 12 | using namespace std; |
| 13 | |
| 14 | namespace ndn { |
| 15 | namespace nrd { |
| 16 | |
| 17 | BOOST_AUTO_TEST_SUITE(TestNrd) |
| 18 | |
| 19 | const uint8_t RealPrefixRegOptions[] = { |
| 20 | 0x65, 0x1b, 0x07, 0x16, 0x08, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, |
| 21 | 0x08, 0x03, 0x72, 0x65, 0x67, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x66, 0x01, 0x00, |
| 22 | }; |
| 23 | |
| 24 | BOOST_AUTO_TEST_CASE (PrefixRegOptionsEncode) |
| 25 | { |
| 26 | Name n ("/localhost/reg/test"); |
| 27 | PrefixRegOptions opt; |
| 28 | |
| 29 | opt.setName (n); |
| 30 | opt.setFaceId (0); |
| 31 | opt.setCost (0); |
| 32 | |
| 33 | const Block& blk = opt.wireEncode (); |
| 34 | |
Obaid | 6e7f5f1 | 2014-03-11 14:46:10 -0500 | [diff] [blame^] | 35 | BOOST_CHECK_EQUAL_COLLECTIONS(RealPrefixRegOptions, |
| 36 | RealPrefixRegOptions + sizeof (RealPrefixRegOptions), |
| 37 | blk.begin (), blk.end ()); |
| 38 | |
| 39 | std::ostringstream os; |
| 40 | os << opt; |
| 41 | BOOST_CHECK_EQUAL(os.str(), "PrefixRegOptions(Prefix: /localhost/reg/test, " |
| 42 | "FaceID: 0, Flags: 1, Cost: 0, ExpirationPeriod: -1, Protocol: )"); |
Alexander Afanasyev | 0553cd5 | 2014-02-18 02:34:45 -0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | BOOST_AUTO_TEST_CASE (PrefixRegOptionsDecoding) |
| 46 | { |
| 47 | Block blk (RealPrefixRegOptions, sizeof (RealPrefixRegOptions)); |
| 48 | Name n ("/localhost/reg/test"); |
| 49 | PrefixRegOptions opt; |
| 50 | |
| 51 | BOOST_REQUIRE_NO_THROW (opt.wireDecode (blk)); |
| 52 | |
| 53 | BOOST_CHECK_EQUAL (opt.getName (), n); |
| 54 | BOOST_CHECK_EQUAL (opt.getFaceId (), 0); |
| 55 | BOOST_CHECK_EQUAL (opt.getCost (), 0); |
| 56 | } |
| 57 | |
| 58 | BOOST_AUTO_TEST_SUITE_END() |
| 59 | |
| 60 | } // namespace nrd |
| 61 | } // namespace ndn |