Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | bb6146e | 2017-07-26 23:07:52 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 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 | |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 26 | #include "table/cs-policy-lru.hpp" |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 27 | #include "table/cs.hpp" |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 28 | |
| 29 | #include "tests/test-common.hpp" |
| 30 | |
| 31 | namespace nfd { |
| 32 | namespace cs { |
| 33 | namespace tests { |
| 34 | |
| 35 | using namespace nfd::tests; |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 36 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 37 | BOOST_AUTO_TEST_SUITE(Table) |
| 38 | BOOST_AUTO_TEST_SUITE(TestCsLru) |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 39 | |
Junxiao Shi | 7ee00fb | 2016-12-04 21:23:00 +0000 | [diff] [blame] | 40 | BOOST_AUTO_TEST_CASE(Registration) |
| 41 | { |
| 42 | std::set<std::string> policyNames = Policy::getPolicyNames(); |
| 43 | BOOST_CHECK_EQUAL(policyNames.count("lru"), 1); |
| 44 | } |
| 45 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 46 | BOOST_FIXTURE_TEST_CASE(EvictOne, UnitTestTimeFixture) |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 47 | { |
| 48 | Cs cs(3); |
Davide Pesavento | 01f8dba | 2015-09-19 21:11:45 +0200 | [diff] [blame] | 49 | cs.setPolicy(make_unique<LruPolicy>()); |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 50 | |
| 51 | cs.insert(*makeData("ndn:/A")); |
| 52 | cs.insert(*makeData("ndn:/B")); |
| 53 | cs.insert(*makeData("ndn:/C")); |
| 54 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 55 | |
| 56 | // evict A |
| 57 | cs.insert(*makeData("ndn:/D")); |
| 58 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 59 | cs.find(Interest("ndn:/A"), |
| 60 | bind([] { BOOST_CHECK(false); }), |
| 61 | bind([] { BOOST_CHECK(true); })); |
| 62 | |
| 63 | // use C then B |
| 64 | cs.find(Interest("ndn:/C"), |
| 65 | bind([] { BOOST_CHECK(true); }), |
| 66 | bind([] { BOOST_CHECK(false); })); |
| 67 | cs.find(Interest("ndn:/B"), |
| 68 | bind([] { BOOST_CHECK(true); }), |
| 69 | bind([] { BOOST_CHECK(false); })); |
| 70 | |
| 71 | // evict D then C |
| 72 | cs.insert(*makeData("ndn:/E")); |
| 73 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 74 | cs.find(Interest("ndn:/D"), |
| 75 | bind([] { BOOST_CHECK(false); }), |
| 76 | bind([] { BOOST_CHECK(true); })); |
| 77 | cs.insert(*makeData("ndn:/F")); |
| 78 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 79 | cs.find(Interest("ndn:/C"), |
| 80 | bind([] { BOOST_CHECK(false); }), |
| 81 | bind([] { BOOST_CHECK(true); })); |
| 82 | |
| 83 | // refresh B |
| 84 | cs.insert(*makeData("ndn:/B")); |
| 85 | // evict E |
| 86 | cs.insert(*makeData("ndn:/G")); |
| 87 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 88 | cs.find(Interest("ndn:/E"), |
| 89 | bind([] { BOOST_CHECK(false); }), |
| 90 | bind([] { BOOST_CHECK(true); })); |
| 91 | } |
| 92 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 93 | BOOST_AUTO_TEST_SUITE_END() // TestCsLru |
| 94 | BOOST_AUTO_TEST_SUITE_END() // Table |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 95 | |
| 96 | } // namespace tests |
| 97 | } // namespace cs |
| 98 | } // namespace nfd |