blob: 920c606e9159cb84ccf31f385b2cce84441878fa [file] [log] [blame]
Obaid793401d2014-02-27 19:13:49 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#include "rib.hpp"
8
9#include <boost/test/unit_test.hpp>
10
11namespace ndn {
12namespace nrd {
13namespace tests {
14
15BOOST_AUTO_TEST_SUITE(TestRib)
16
17BOOST_AUTO_TEST_CASE(Basic)
18{
19 Rib rib;
20
21 PrefixRegOptions options1;
22 options1.setName("/hello/world");
23 options1.setFlags(tlv::nrd::NDN_FORW_CHILD_INHERIT | tlv::nrd::NDN_FORW_CAPTURE);
24 options1.setCost(10);
Obaidea56c612014-03-17 22:50:47 -050025 options1.setExpirationPeriod(time::milliseconds(1500));
Obaid03f4dc92014-04-13 10:57:04 -050026 options1.setFaceId(1);
27
28 rib.insert(options1);
29 BOOST_CHECK_EQUAL(rib.size(), 1);
Obaid793401d2014-02-27 19:13:49 -060030
31 PrefixRegOptions options2;
32 options2.setName("/hello/world");
33 options2.setFlags(tlv::nrd::NDN_FORW_CHILD_INHERIT);
Obaidea56c612014-03-17 22:50:47 -050034 options2.setExpirationPeriod(time::seconds(0));
Obaid03f4dc92014-04-13 10:57:04 -050035 options2.setFaceId(1);
36 options2.setCost(100);
Obaid793401d2014-02-27 19:13:49 -060037
Obaid793401d2014-02-27 19:13:49 -060038 rib.insert(options2);
39 BOOST_CHECK_EQUAL(rib.size(), 1);
40
Obaid03f4dc92014-04-13 10:57:04 -050041 options2.setFaceId(2);
Obaid793401d2014-02-27 19:13:49 -060042 rib.insert(options2);
43 BOOST_CHECK_EQUAL(rib.size(), 2);
44
Obaid03f4dc92014-04-13 10:57:04 -050045 options2.setName("/foo/bar");
46 rib.insert(options2);
47 BOOST_CHECK_EQUAL(rib.size(), 3);
48
49 rib.erase(options2);
50 BOOST_CHECK_EQUAL(rib.size(), 2);
51
52 options2.setName("/hello/world");
Obaid793401d2014-02-27 19:13:49 -060053 rib.erase(options2);
54 BOOST_CHECK_EQUAL(rib.size(), 1);
55
56 BOOST_CHECK(rib.find(options2) == rib.end());
57 BOOST_CHECK(rib.find(options1) != rib.end());
58
59 rib.erase(options1);
60 BOOST_CHECK(rib.empty());
61}
62
63BOOST_AUTO_TEST_SUITE_END()
64
65} // namespace tests
66} // namespace nrd
67} // namespace ndn