blob: 4d66d0d630f8b8c6502da7a75d504a3ee328e9d2 [file] [log] [blame]
Junxiao Shi3f21e582017-05-29 15:26:32 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento87fc0f82018-04-11 23:43:51 -04002/*
3 * Copyright (c) 2014-2018, Regents of the University of California,
Junxiao Shi3f21e582017-05-29 15:26:32 +00004 * 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"
Davide Pesavento87fc0f82018-04-11 23:43:51 -040027
Junxiao Shi3f21e582017-05-29 15:26:32 +000028#include "tests/test-common.hpp"
29
30namespace nfd {
31namespace rib {
32namespace tests {
33
34using namespace nfd::tests;
35
36BOOST_FIXTURE_TEST_SUITE(TestRoute, BaseFixture)
37
38BOOST_AUTO_TEST_CASE(Equality)
39{
40 Route a;
41 Route b;
42 BOOST_CHECK_EQUAL(a, b);
43
44 a.faceId = b.faceId = 15404;
45 a.origin = b.origin = ndn::nfd::ROUTE_ORIGIN_NLSR;
46 a.flags = b.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT;
47 a.cost = b.cost = 28826;
48 a.expires = b.expires = time::steady_clock::now() + time::milliseconds(26782232);
49 BOOST_CHECK_EQUAL(a, b);
50
51 b.faceId = 18559;
52 BOOST_CHECK_NE(a, b);
53 a.faceId = 18559;
54
55 b.origin = ndn::nfd::ROUTE_ORIGIN_CLIENT;
56 BOOST_CHECK_NE(a, b);
57 a.origin = ndn::nfd::ROUTE_ORIGIN_CLIENT;
58
59 b.flags = ndn::nfd::ROUTE_FLAG_CAPTURE;
60 BOOST_CHECK_NE(a, b);
61 a.flags = ndn::nfd::ROUTE_FLAG_CAPTURE;
62
63 b.cost = 103;
64 BOOST_CHECK_NE(a, b);
65 a.cost = 103;
66
Davide Pesavento87fc0f82018-04-11 23:43:51 -040067 b.expires = nullopt;
Junxiao Shi3f21e582017-05-29 15:26:32 +000068 BOOST_CHECK_NE(a, b);
Davide Pesavento87fc0f82018-04-11 23:43:51 -040069 a.expires = nullopt;
Junxiao Shi3f21e582017-05-29 15:26:32 +000070
71 BOOST_CHECK_EQUAL(a, b);
72}
73
74BOOST_FIXTURE_TEST_CASE(Output, UnitTestTimeFixture)
75{
76 Route r;
77 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r),
78 "Route(faceid: 0, origin: app, cost: 0, flags: 0x0, never expires)");
79
80 r.faceId = 4980;
81 r.origin = ndn::nfd::ROUTE_ORIGIN_STATIC;
82 r.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT;
83 r.cost = 2312;
84 r.expires = time::steady_clock::now() + time::milliseconds(791214234);
85 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r),
86 "Route(faceid: 4980, origin: static, cost: 2312, flags: 0x1, expires in: 791214234 milliseconds)");
87
Davide Pesavento87fc0f82018-04-11 23:43:51 -040088 r.expires = nullopt;
Junxiao Shi3f21e582017-05-29 15:26:32 +000089 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r),
90 "Route(faceid: 4980, origin: static, cost: 2312, flags: 0x1, never expires)");
91}
92
93BOOST_AUTO_TEST_SUITE_END() // TestRoute
94
95} // namespace tests
96} // namespace rib
97} // namespace nfd