blob: 8813de5f8976ab0dc7401d1968e9d07826cc5504 [file] [log] [blame]
Minsheng Zhang03152692015-07-28 11:53:21 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Davide Pesavento97210d52016-10-14 15:45:48 +02003 * Copyright (c) 2014-2016, 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#include <ndn-cxx/util/crypto.hpp>
29
30#include "tests/test-common.hpp"
31
32namespace nfd {
33namespace cs {
34namespace tests {
35
36using namespace nfd::tests;
Minsheng Zhang03152692015-07-28 11:53:21 -050037
Davide Pesavento97210d52016-10-14 15:45:48 +020038BOOST_AUTO_TEST_SUITE(Table)
39BOOST_AUTO_TEST_SUITE(TestCsLru)
Minsheng Zhang03152692015-07-28 11:53:21 -050040
Junxiao Shi7ee00fb2016-12-04 21:23:00 +000041BOOST_AUTO_TEST_CASE(Registration)
42{
43 std::set<std::string> policyNames = Policy::getPolicyNames();
44 BOOST_CHECK_EQUAL(policyNames.count("lru"), 1);
45}
46
Davide Pesavento97210d52016-10-14 15:45:48 +020047BOOST_FIXTURE_TEST_CASE(EvictOne, UnitTestTimeFixture)
Minsheng Zhang03152692015-07-28 11:53:21 -050048{
49 Cs cs(3);
Davide Pesavento01f8dba2015-09-19 21:11:45 +020050 cs.setPolicy(make_unique<LruPolicy>());
Minsheng Zhang03152692015-07-28 11:53:21 -050051
52 cs.insert(*makeData("ndn:/A"));
53 cs.insert(*makeData("ndn:/B"));
54 cs.insert(*makeData("ndn:/C"));
55 BOOST_CHECK_EQUAL(cs.size(), 3);
56
57 // evict A
58 cs.insert(*makeData("ndn:/D"));
59 BOOST_CHECK_EQUAL(cs.size(), 3);
60 cs.find(Interest("ndn:/A"),
61 bind([] { BOOST_CHECK(false); }),
62 bind([] { BOOST_CHECK(true); }));
63
64 // use C then B
65 cs.find(Interest("ndn:/C"),
66 bind([] { BOOST_CHECK(true); }),
67 bind([] { BOOST_CHECK(false); }));
68 cs.find(Interest("ndn:/B"),
69 bind([] { BOOST_CHECK(true); }),
70 bind([] { BOOST_CHECK(false); }));
71
72 // evict D then C
73 cs.insert(*makeData("ndn:/E"));
74 BOOST_CHECK_EQUAL(cs.size(), 3);
75 cs.find(Interest("ndn:/D"),
76 bind([] { BOOST_CHECK(false); }),
77 bind([] { BOOST_CHECK(true); }));
78 cs.insert(*makeData("ndn:/F"));
79 BOOST_CHECK_EQUAL(cs.size(), 3);
80 cs.find(Interest("ndn:/C"),
81 bind([] { BOOST_CHECK(false); }),
82 bind([] { BOOST_CHECK(true); }));
83
84 // refresh B
85 cs.insert(*makeData("ndn:/B"));
86 // evict E
87 cs.insert(*makeData("ndn:/G"));
88 BOOST_CHECK_EQUAL(cs.size(), 3);
89 cs.find(Interest("ndn:/E"),
90 bind([] { BOOST_CHECK(false); }),
91 bind([] { BOOST_CHECK(true); }));
92}
93
Davide Pesavento97210d52016-10-14 15:45:48 +020094BOOST_AUTO_TEST_SUITE_END() // TestCsLru
95BOOST_AUTO_TEST_SUITE_END() // Table
Minsheng Zhang03152692015-07-28 11:53:21 -050096
97} // namespace tests
98} // namespace cs
99} // namespace nfd