blob: 67068bd04f67dbc197ebb51e7fb1bdeda13d30bf [file] [log] [blame]
Jiewen Tan99135962014-09-20 02:18:53 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -08003 * Copyright (c) 2013-2017 Regents of the University of California.
Jiewen Tan99135962014-09-20 02:18:53 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22#include "util/in-memory-storage-lru.hpp"
Jiewen Tan99135962014-09-20 02:18:53 -070023
24#include "boost-test.hpp"
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080025#include "../make-interest-data.hpp"
Jiewen Tan99135962014-09-20 02:18:53 -070026
27namespace ndn {
28namespace util {
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080029namespace tests {
Jiewen Tan99135962014-09-20 02:18:53 -070030
Junxiao Shi85d90832016-08-04 03:19:46 +000031using namespace ndn::tests;
32
33BOOST_AUTO_TEST_SUITE(Util)
34BOOST_AUTO_TEST_SUITE(TestInMemoryStorage)
Alexander Afanasyev3ccc6f72014-10-12 12:19:09 -070035BOOST_AUTO_TEST_SUITE(Lru)
Jiewen Tan99135962014-09-20 02:18:53 -070036
37BOOST_AUTO_TEST_CASE(UsedTimeQueue)
38{
39 InMemoryStorageLru ims;
40
41 Name name1("/insert/1");
42 shared_ptr<Data> data1 = makeData(name1);
43 ims.insert(*data1);
44
45 Name name2("/insert/2");
46 shared_ptr<Data> data2 = makeData(name2);
47 ims.insert(*data2);
48
49 Name name3("/insert/3");
50 shared_ptr<Data> data3 = makeData(name3);
51 ims.insert(*data3);
52
53 shared_ptr<Interest> interest1 = makeInterest(name1);
54 shared_ptr<Interest> interest2 = makeInterest(name2);
55 shared_ptr<Interest> interest3 = makeInterest(name3);
56
57 ims.find(*interest1);
58 ims.find(*interest2);
59 ims.find(*interest3);
60 ims.find(*interest1);
61 ims.find(*interest3);
62 ims.find(*interest3);
63
64 ims.evictItem();
65 BOOST_CHECK_EQUAL(ims.size(), 2);
66
67 shared_ptr<const Data> found2 = ims.find(*interest2);
Junxiao Shi85d90832016-08-04 03:19:46 +000068 BOOST_CHECK(found2 == nullptr);
Jiewen Tan99135962014-09-20 02:18:53 -070069
70 shared_ptr<const Data> found1 = ims.find(*interest1);
71 BOOST_CHECK_EQUAL(found1->getName(), name1);
72 shared_ptr<const Data> found3 = ims.find(*interest3);
73 BOOST_CHECK_EQUAL(found3->getName(), name3);
74}
75
76BOOST_AUTO_TEST_CASE(UsedTimeQueue2)
77{
78 InMemoryStorageLru ims;
79
80 Name name1("/insert/1");
81 shared_ptr<Data> data = makeData(name1);
82 ims.insert(*data);
83
84 Name name2("/insert/2");
85 shared_ptr<Data> data2 = makeData(name2);
86 ims.insert(*data2);
87
88 Name name3("/insert/3");
89 shared_ptr<Data> data3 = makeData(name3);
90 ims.insert(*data3);
91
92 shared_ptr<Interest> interest1 = makeInterest(name1);
93 shared_ptr<Interest> interest2 = makeInterest(name2);
94 shared_ptr<Interest> interest3 = makeInterest(name3);
95
96 ims.find(*interest1);
97 ims.find(*interest2);
98 ims.find(*interest3);
99 ims.find(*interest1);
100 ims.find(*interest3);
101 ims.find(*interest3);
102
103 ims.evictItem();
104 BOOST_CHECK_EQUAL(ims.size(), 2);
105
106 shared_ptr<const Data> found2 = ims.find(*interest2);
Junxiao Shi85d90832016-08-04 03:19:46 +0000107 BOOST_CHECK(found2 == nullptr);
Jiewen Tan99135962014-09-20 02:18:53 -0700108
109 shared_ptr<const Data> found1 = ims.find(*interest1);
110 BOOST_CHECK_EQUAL(found1->getName(), name1);
111 shared_ptr<const Data> found3 = ims.find(*interest3);
112 BOOST_CHECK_EQUAL(found3->getName(), name3);
113
114 Name name4("/insert/4");
115 shared_ptr<Data> data4 = makeData(name4);
116 ims.insert(*data4);
117
118 shared_ptr<Interest> interest4 = makeInterest(name4);
119 ims.find(*interest4);
120 ims.find(*interest1);
121 ims.find(*interest3);
122
123 ims.evictItem();
124 BOOST_CHECK_EQUAL(ims.size(), 2);
125
126 shared_ptr<const Data> found4 = ims.find(*interest4);
Junxiao Shi85d90832016-08-04 03:19:46 +0000127 BOOST_CHECK(found4 == nullptr);
Jiewen Tan99135962014-09-20 02:18:53 -0700128
129 found1 = ims.find(*interest1);
130 BOOST_CHECK_EQUAL(found1->getName(), name1);
131 found3 = ims.find(*interest3);
132 BOOST_CHECK_EQUAL(found3->getName(), name3);
133}
134
Alexander Afanasyev3ccc6f72014-10-12 12:19:09 -0700135BOOST_AUTO_TEST_SUITE_END() // Lru
Junxiao Shi85d90832016-08-04 03:19:46 +0000136BOOST_AUTO_TEST_SUITE_END() // TestInMemoryStorage
137BOOST_AUTO_TEST_SUITE_END() // Util
Jiewen Tan99135962014-09-20 02:18:53 -0700138
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800139} // namespace tests
Jiewen Tan99135962014-09-20 02:18:53 -0700140} // namespace util
141} // namespace ndn