blob: 7466510694ab49b6269ee74bfe02d5fe52ca86cd [file] [log] [blame]
Minsheng Zhang03152692015-07-28 11:53:21 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shibb6146e2017-07-26 23:07:52 +00002/*
3 * Copyright (c) 2014-2017, Regents of the University of California,
Minsheng Zhang03152692015-07-28 11:53:21 -05004 * 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 Zhang03152692015-07-28 11:53:21 -050026#include "table/cs-policy-lru.hpp"
Junxiao Shi0de23a22015-12-03 20:07:02 +000027#include "table/cs.hpp"
Minsheng Zhang03152692015-07-28 11:53:21 -050028
29#include "tests/test-common.hpp"
30
31namespace nfd {
32namespace cs {
33namespace tests {
34
35using namespace nfd::tests;
Minsheng Zhang03152692015-07-28 11:53:21 -050036
Davide Pesavento97210d52016-10-14 15:45:48 +020037BOOST_AUTO_TEST_SUITE(Table)
38BOOST_AUTO_TEST_SUITE(TestCsLru)
Minsheng Zhang03152692015-07-28 11:53:21 -050039
Junxiao Shi7ee00fb2016-12-04 21:23:00 +000040BOOST_AUTO_TEST_CASE(Registration)
41{
42 std::set<std::string> policyNames = Policy::getPolicyNames();
43 BOOST_CHECK_EQUAL(policyNames.count("lru"), 1);
44}
45
Davide Pesavento97210d52016-10-14 15:45:48 +020046BOOST_FIXTURE_TEST_CASE(EvictOne, UnitTestTimeFixture)
Minsheng Zhang03152692015-07-28 11:53:21 -050047{
48 Cs cs(3);
Davide Pesavento01f8dba2015-09-19 21:11:45 +020049 cs.setPolicy(make_unique<LruPolicy>());
Minsheng Zhang03152692015-07-28 11:53:21 -050050
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 Pesavento97210d52016-10-14 15:45:48 +020093BOOST_AUTO_TEST_SUITE_END() // TestCsLru
94BOOST_AUTO_TEST_SUITE_END() // Table
Minsheng Zhang03152692015-07-28 11:53:21 -050095
96} // namespace tests
97} // namespace cs
98} // namespace nfd