blob: aa63b72dfd7affc27f673a738d9f559ce1d4fc0e [file] [log] [blame]
Alexander Afanasyev0553cd52014-02-18 02:34:45 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * Copyright (c) 2013-2014, Regents of the University of California.
4 * All rights reserved.
5 *
6 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
7 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
8 *
9 * This file licensed under New BSD License. See COPYING for detailed information about
10 * ndn-cxx library copyright, permissions, and redistribution restrictions.
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080011 */
12
13#include "management/nrd-prefix-reg-options.hpp"
14
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070015#include "boost-test.hpp"
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080016
17namespace ndn {
18namespace nrd {
19
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070020BOOST_AUTO_TEST_SUITE(ManagementTestNrd)
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080021
22const uint8_t RealPrefixRegOptions[] = {
23 0x65, 0x1b, 0x07, 0x16, 0x08, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74,
24 0x08, 0x03, 0x72, 0x65, 0x67, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x66, 0x01, 0x00,
25};
26
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070027BOOST_AUTO_TEST_CASE(PrefixRegOptionsEncode)
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080028{
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070029 Name n("/localhost/reg/test");
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080030 PrefixRegOptions opt;
31
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070032 opt.setName(n);
33 opt.setFaceId(0);
34 opt.setCost(0);
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080035
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070036 const Block& blk = opt.wireEncode();
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080037
Obaid6e7f5f12014-03-11 14:46:10 -050038 BOOST_CHECK_EQUAL_COLLECTIONS(RealPrefixRegOptions,
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070039 RealPrefixRegOptions + sizeof(RealPrefixRegOptions),
40 blk.begin(), blk.end());
Obaid6e7f5f12014-03-11 14:46:10 -050041
42 std::ostringstream os;
43 os << opt;
44 BOOST_CHECK_EQUAL(os.str(), "PrefixRegOptions(Prefix: /localhost/reg/test, "
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070045 "FaceID: 0, Flags: 1, Cost: 0, "
46 "ExpirationPeriod: -9223372036854775808 milliseconds, Protocol: )");
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080047}
48
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070049BOOST_AUTO_TEST_CASE(PrefixRegOptionsDecoding)
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080050{
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070051 Block blk(RealPrefixRegOptions, sizeof(RealPrefixRegOptions));
52 Name n("/localhost/reg/test");
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080053 PrefixRegOptions opt;
54
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070055 BOOST_REQUIRE_NO_THROW(opt.wireDecode(blk));
56
57 BOOST_CHECK_EQUAL(opt.getName(), n);
58 BOOST_CHECK_EQUAL(opt.getFaceId(), 0);
59 BOOST_CHECK_EQUAL(opt.getCost(), 0);
Alexander Afanasyev0553cd52014-02-18 02:34:45 -080060}
61
62BOOST_AUTO_TEST_SUITE_END()
63
64} // namespace nrd
65} // namespace ndn