blob: b287a6b41bcb9edce235c91829823b1e445dd188 [file] [log] [blame]
Alexander Afanasyev0553cd52014-02-18 02:34:45 -08001/* -*- 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 Afanasyevb1db7c62014-04-03 14:57:25 -07009#include "boost-test.hpp"
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080010
11namespace ndn {
12namespace nrd {
13
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070014BOOST_AUTO_TEST_SUITE(ManagementTestNrd)
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080015
16const 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 Afanasyevb1db7c62014-04-03 14:57:25 -070021BOOST_AUTO_TEST_CASE(PrefixRegOptionsEncode)
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080022{
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070023 Name n("/localhost/reg/test");
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080024 PrefixRegOptions opt;
25
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070026 opt.setName(n);
27 opt.setFaceId(0);
28 opt.setCost(0);
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080029
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070030 const Block& blk = opt.wireEncode();
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080031
Obaid6e7f5f12014-03-11 14:46:10 -050032 BOOST_CHECK_EQUAL_COLLECTIONS(RealPrefixRegOptions,
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070033 RealPrefixRegOptions + sizeof(RealPrefixRegOptions),
34 blk.begin(), blk.end());
Obaid6e7f5f12014-03-11 14:46:10 -050035
36 std::ostringstream os;
37 os << opt;
38 BOOST_CHECK_EQUAL(os.str(), "PrefixRegOptions(Prefix: /localhost/reg/test, "
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070039 "FaceID: 0, Flags: 1, Cost: 0, "
40 "ExpirationPeriod: -9223372036854775808 milliseconds, Protocol: )");
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080041}
42
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070043BOOST_AUTO_TEST_CASE(PrefixRegOptionsDecoding)
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080044{
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070045 Block blk(RealPrefixRegOptions, sizeof(RealPrefixRegOptions));
46 Name n("/localhost/reg/test");
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080047 PrefixRegOptions opt;
48
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070049 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 Afanasyev0553cd52014-02-18 02:34:45 -080054}
55
56BOOST_AUTO_TEST_SUITE_END()
57
58} // namespace nrd
59} // namespace ndn