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 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 9 | #include "boost-test.hpp" |
Alexander Afanasyev | 0553cd5 | 2014-02-18 02:34:45 -0800 | [diff] [blame] | 10 | |
| 11 | namespace ndn { |
| 12 | namespace nrd { |
| 13 | |
| 14 | BOOST_AUTO_TEST_SUITE(TestNrd) |
| 15 | |
| 16 | const uint8_t RealPrefixRegOptions[] = { |
| 17 | 0x65, 0x1b, 0x07, 0x16, 0x08, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, |
| 18 | 0x08, 0x03, 0x72, 0x65, 0x67, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x66, 0x01, 0x00, |
| 19 | }; |
| 20 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 21 | BOOST_AUTO_TEST_CASE(PrefixRegOptionsEncode) |
Alexander Afanasyev | 0553cd5 | 2014-02-18 02:34:45 -0800 | [diff] [blame] | 22 | { |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 23 | Name n("/localhost/reg/test"); |
Alexander Afanasyev | 0553cd5 | 2014-02-18 02:34:45 -0800 | [diff] [blame] | 24 | PrefixRegOptions opt; |
| 25 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 26 | opt.setName(n); |
| 27 | opt.setFaceId(0); |
| 28 | opt.setCost(0); |
Alexander Afanasyev | 0553cd5 | 2014-02-18 02:34:45 -0800 | [diff] [blame] | 29 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 30 | const Block& blk = opt.wireEncode(); |
Alexander Afanasyev | 0553cd5 | 2014-02-18 02:34:45 -0800 | [diff] [blame] | 31 | |
Obaid | 6e7f5f1 | 2014-03-11 14:46:10 -0500 | [diff] [blame] | 32 | BOOST_CHECK_EQUAL_COLLECTIONS(RealPrefixRegOptions, |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 33 | RealPrefixRegOptions + sizeof(RealPrefixRegOptions), |
| 34 | blk.begin(), blk.end()); |
Obaid | 6e7f5f1 | 2014-03-11 14:46:10 -0500 | [diff] [blame] | 35 | |
| 36 | std::ostringstream os; |
| 37 | os << opt; |
| 38 | BOOST_CHECK_EQUAL(os.str(), "PrefixRegOptions(Prefix: /localhost/reg/test, " |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 39 | "FaceID: 0, Flags: 1, Cost: 0, " |
| 40 | "ExpirationPeriod: -9223372036854775808 milliseconds, Protocol: )"); |
Alexander Afanasyev | 0553cd5 | 2014-02-18 02:34:45 -0800 | [diff] [blame] | 41 | } |
| 42 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 43 | BOOST_AUTO_TEST_CASE(PrefixRegOptionsDecoding) |
Alexander Afanasyev | 0553cd5 | 2014-02-18 02:34:45 -0800 | [diff] [blame] | 44 | { |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 45 | Block blk(RealPrefixRegOptions, sizeof(RealPrefixRegOptions)); |
| 46 | Name n("/localhost/reg/test"); |
Alexander Afanasyev | 0553cd5 | 2014-02-18 02:34:45 -0800 | [diff] [blame] | 47 | PrefixRegOptions opt; |
| 48 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 49 | BOOST_REQUIRE_NO_THROW(opt.wireDecode(blk)); |
| 50 | |
| 51 | BOOST_CHECK_EQUAL(opt.getName(), n); |
| 52 | BOOST_CHECK_EQUAL(opt.getFaceId(), 0); |
| 53 | BOOST_CHECK_EQUAL(opt.getCost(), 0); |
Alexander Afanasyev | 0553cd5 | 2014-02-18 02:34:45 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | BOOST_AUTO_TEST_SUITE_END() |
| 57 | |
| 58 | } // namespace nrd |
| 59 | } // namespace ndn |