Obaid | 793401d | 2014-02-27 19:13:49 -0600 | [diff] [blame] | 1 | /* -*- 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 | |
| 11 | namespace ndn { |
| 12 | namespace nrd { |
| 13 | namespace tests { |
| 14 | |
| 15 | BOOST_AUTO_TEST_SUITE(TestRib) |
| 16 | |
| 17 | BOOST_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); |
Obaid | ea56c61 | 2014-03-17 22:50:47 -0500 | [diff] [blame] | 25 | options1.setExpirationPeriod(time::milliseconds(1500)); |
Obaid | 03f4dc9 | 2014-04-13 10:57:04 -0500 | [diff] [blame] | 26 | options1.setFaceId(1); |
| 27 | |
| 28 | rib.insert(options1); |
| 29 | BOOST_CHECK_EQUAL(rib.size(), 1); |
Obaid | 793401d | 2014-02-27 19:13:49 -0600 | [diff] [blame] | 30 | |
| 31 | PrefixRegOptions options2; |
| 32 | options2.setName("/hello/world"); |
| 33 | options2.setFlags(tlv::nrd::NDN_FORW_CHILD_INHERIT); |
Obaid | ea56c61 | 2014-03-17 22:50:47 -0500 | [diff] [blame] | 34 | options2.setExpirationPeriod(time::seconds(0)); |
Obaid | 03f4dc9 | 2014-04-13 10:57:04 -0500 | [diff] [blame] | 35 | options2.setFaceId(1); |
| 36 | options2.setCost(100); |
Obaid | 793401d | 2014-02-27 19:13:49 -0600 | [diff] [blame] | 37 | |
Obaid | 793401d | 2014-02-27 19:13:49 -0600 | [diff] [blame] | 38 | rib.insert(options2); |
| 39 | BOOST_CHECK_EQUAL(rib.size(), 1); |
| 40 | |
Obaid | 03f4dc9 | 2014-04-13 10:57:04 -0500 | [diff] [blame] | 41 | options2.setFaceId(2); |
Obaid | 793401d | 2014-02-27 19:13:49 -0600 | [diff] [blame] | 42 | rib.insert(options2); |
| 43 | BOOST_CHECK_EQUAL(rib.size(), 2); |
| 44 | |
Obaid | 03f4dc9 | 2014-04-13 10:57:04 -0500 | [diff] [blame] | 45 | 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"); |
Obaid | 793401d | 2014-02-27 19:13:49 -0600 | [diff] [blame] | 53 | 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 | |
| 63 | BOOST_AUTO_TEST_SUITE_END() |
| 64 | |
| 65 | } // namespace tests |
| 66 | } // namespace nrd |
| 67 | } // namespace ndn |