Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame^] | 3 | * Copyright (c) 2014-2016, 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 | #include <ndn-cxx/util/crypto.hpp> |
| 29 | |
| 30 | #include "tests/test-common.hpp" |
| 31 | |
| 32 | namespace nfd { |
| 33 | namespace cs { |
| 34 | namespace tests { |
| 35 | |
| 36 | using namespace nfd::tests; |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 37 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame^] | 38 | BOOST_AUTO_TEST_SUITE(Table) |
| 39 | BOOST_AUTO_TEST_SUITE(TestCsLru) |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 40 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame^] | 41 | BOOST_FIXTURE_TEST_CASE(EvictOne, UnitTestTimeFixture) |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 42 | { |
| 43 | Cs cs(3); |
Davide Pesavento | 01f8dba | 2015-09-19 21:11:45 +0200 | [diff] [blame] | 44 | cs.setPolicy(make_unique<LruPolicy>()); |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 45 | |
| 46 | cs.insert(*makeData("ndn:/A")); |
| 47 | cs.insert(*makeData("ndn:/B")); |
| 48 | cs.insert(*makeData("ndn:/C")); |
| 49 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 50 | |
| 51 | // evict A |
| 52 | cs.insert(*makeData("ndn:/D")); |
| 53 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 54 | cs.find(Interest("ndn:/A"), |
| 55 | bind([] { BOOST_CHECK(false); }), |
| 56 | bind([] { BOOST_CHECK(true); })); |
| 57 | |
| 58 | // use C then B |
| 59 | cs.find(Interest("ndn:/C"), |
| 60 | bind([] { BOOST_CHECK(true); }), |
| 61 | bind([] { BOOST_CHECK(false); })); |
| 62 | cs.find(Interest("ndn:/B"), |
| 63 | bind([] { BOOST_CHECK(true); }), |
| 64 | bind([] { BOOST_CHECK(false); })); |
| 65 | |
| 66 | // evict D then C |
| 67 | cs.insert(*makeData("ndn:/E")); |
| 68 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 69 | cs.find(Interest("ndn:/D"), |
| 70 | bind([] { BOOST_CHECK(false); }), |
| 71 | bind([] { BOOST_CHECK(true); })); |
| 72 | cs.insert(*makeData("ndn:/F")); |
| 73 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 74 | cs.find(Interest("ndn:/C"), |
| 75 | bind([] { BOOST_CHECK(false); }), |
| 76 | bind([] { BOOST_CHECK(true); })); |
| 77 | |
| 78 | // refresh B |
| 79 | cs.insert(*makeData("ndn:/B")); |
| 80 | // evict E |
| 81 | cs.insert(*makeData("ndn:/G")); |
| 82 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 83 | cs.find(Interest("ndn:/E"), |
| 84 | bind([] { BOOST_CHECK(false); }), |
| 85 | bind([] { BOOST_CHECK(true); })); |
| 86 | } |
| 87 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame^] | 88 | BOOST_AUTO_TEST_SUITE_END() // TestCsLru |
| 89 | BOOST_AUTO_TEST_SUITE_END() // Table |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 90 | |
| 91 | } // namespace tests |
| 92 | } // namespace cs |
| 93 | } // namespace nfd |