blob: b02be0c80e6de968fb5356e04bbe2c441dc73825 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev4671bf72014-05-19 09:01:37 -04002/**
Junxiao Shibc6beb12017-01-11 23:20:39 +00003 * Copyright (c) 2013-2017 Regents of the University of California.
Alexander Afanasyev4671bf72014-05-19 09:01:37 -04004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyev4671bf72014-05-19 09:01:37 -04006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040020 */
21
Junxiao Shi7357ef22016-09-07 02:39:37 +000022#include "mgmt/nfd/strategy-choice.hpp"
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040023
24#include "boost-test.hpp"
Junxiao Shibc6beb12017-01-11 23:20:39 +000025#include <boost/lexical_cast.hpp>
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040026
27namespace ndn {
28namespace nfd {
29namespace tests {
30
Junxiao Shi7357ef22016-09-07 02:39:37 +000031BOOST_AUTO_TEST_SUITE(Mgmt)
32BOOST_AUTO_TEST_SUITE(Nfd)
33BOOST_AUTO_TEST_SUITE(TestStrategyChoice)
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040034
35BOOST_AUTO_TEST_CASE(Encode)
36{
Junxiao Shibc6beb12017-01-11 23:20:39 +000037 StrategyChoice sc1;
38 sc1.setName("/hello/world")
39 .setStrategy("/some/non/existing/strategy/name");
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040040
41 Block wire;
Junxiao Shibc6beb12017-01-11 23:20:39 +000042 BOOST_REQUIRE_NO_THROW(wire = sc1.wireEncode());
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040043
44 // These octets are obtained by the snippet below.
45 // This check is intended to detect unexpected encoding change in the future.
46 // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
47 // printf("0x%02x, ", *it);
48 // }
49 static const uint8_t expected[] = {
50 0x80, 0x39, 0x07, 0x0e, 0x08, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x08, 0x05, 0x77,
51 0x6f, 0x72, 0x6c, 0x64, 0x6b, 0x27, 0x07, 0x25, 0x08, 0x04, 0x73, 0x6f, 0x6d, 0x65,
52 0x08, 0x03, 0x6e, 0x6f, 0x6e, 0x08, 0x08, 0x65, 0x78, 0x69, 0x73, 0x74, 0x69, 0x6e,
53 0x67, 0x08, 0x08, 0x73, 0x74, 0x72, 0x61, 0x74, 0x65, 0x67, 0x79, 0x08, 0x04, 0x6e,
54 0x61, 0x6d, 0x65
55 };
56 BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
57 wire.begin(), wire.end());
58
59 BOOST_REQUIRE_NO_THROW(StrategyChoice(wire));
Junxiao Shibc6beb12017-01-11 23:20:39 +000060 StrategyChoice sc2(wire);
61 BOOST_CHECK_EQUAL(sc1, sc2);
62}
63
64BOOST_AUTO_TEST_CASE(Equality)
65{
66 StrategyChoice sc1, sc2;
67
68 sc1.setName("/A")
69 .setStrategy("/strategyP");
70 sc2 = sc1;
71 BOOST_CHECK_EQUAL(sc1, sc2);
72
73 sc2.setName("/B");
74 BOOST_CHECK_NE(sc1, sc2);
75
76 sc2 = sc1;
77 sc2.setStrategy("/strategyQ");
78 BOOST_CHECK_NE(sc1, sc2);
79}
80
81BOOST_AUTO_TEST_CASE(Print)
82{
83 StrategyChoice sc;
84 sc.setName("/A")
85 .setStrategy("/strategyP");
86 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(sc),
87 "StrategyChoice(Name: /A, Strategy: /strategyP)");
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040088}
89
Junxiao Shi7357ef22016-09-07 02:39:37 +000090BOOST_AUTO_TEST_SUITE_END() // TestStrategyChoice
91BOOST_AUTO_TEST_SUITE_END() // Nfd
92BOOST_AUTO_TEST_SUITE_END() // Mgmt
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040093
94} // namespace tests
95} // namespace nfd
96} // namespace ndn