blob: d7b70eb9c22466f7e86e54c4ca1fa35539429ab4 [file] [log] [blame]
Junxiao Shi3f21e582017-05-29 15:26:32 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2017, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "rib/route.hpp"
27#include "tests/test-common.hpp"
28
29namespace nfd {
30namespace rib {
31namespace tests {
32
33using namespace nfd::tests;
34
35BOOST_FIXTURE_TEST_SUITE(TestRoute, BaseFixture)
36
37BOOST_AUTO_TEST_CASE(Equality)
38{
39 Route a;
40 Route b;
41 BOOST_CHECK_EQUAL(a, b);
42
43 a.faceId = b.faceId = 15404;
44 a.origin = b.origin = ndn::nfd::ROUTE_ORIGIN_NLSR;
45 a.flags = b.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT;
46 a.cost = b.cost = 28826;
47 a.expires = b.expires = time::steady_clock::now() + time::milliseconds(26782232);
48 BOOST_CHECK_EQUAL(a, b);
49
50 b.faceId = 18559;
51 BOOST_CHECK_NE(a, b);
52 a.faceId = 18559;
53
54 b.origin = ndn::nfd::ROUTE_ORIGIN_CLIENT;
55 BOOST_CHECK_NE(a, b);
56 a.origin = ndn::nfd::ROUTE_ORIGIN_CLIENT;
57
58 b.flags = ndn::nfd::ROUTE_FLAG_CAPTURE;
59 BOOST_CHECK_NE(a, b);
60 a.flags = ndn::nfd::ROUTE_FLAG_CAPTURE;
61
62 b.cost = 103;
63 BOOST_CHECK_NE(a, b);
64 a.cost = 103;
65
66 b.expires = ndn::nullopt;
67 BOOST_CHECK_NE(a, b);
68 a.expires = ndn::nullopt;
69
70 BOOST_CHECK_EQUAL(a, b);
71}
72
73BOOST_FIXTURE_TEST_CASE(Output, UnitTestTimeFixture)
74{
75 Route r;
76 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r),
77 "Route(faceid: 0, origin: app, cost: 0, flags: 0x0, never expires)");
78
79 r.faceId = 4980;
80 r.origin = ndn::nfd::ROUTE_ORIGIN_STATIC;
81 r.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT;
82 r.cost = 2312;
83 r.expires = time::steady_clock::now() + time::milliseconds(791214234);
84 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r),
85 "Route(faceid: 4980, origin: static, cost: 2312, flags: 0x1, expires in: 791214234 milliseconds)");
86
87 r.expires = ndn::nullopt;
88 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r),
89 "Route(faceid: 4980, origin: static, cost: 2312, flags: 0x1, never expires)");
90}
91
92BOOST_AUTO_TEST_SUITE_END() // TestRoute
93
94} // namespace tests
95} // namespace rib
96} // namespace nfd