blob: 7585987123a17e5ca9de9ec902f1931e8e24d135 [file] [log] [blame]
Jiewen Tan99135962014-09-20 02:18:53 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi85d90832016-08-04 03:19:46 +00003 * Copyright (c) 2013-2016 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"
23#include "security/key-chain.hpp"
24
25#include "boost-test.hpp"
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080026#include "../make-interest-data.hpp"
Jiewen Tan99135962014-09-20 02:18:53 -070027
28namespace ndn {
29namespace util {
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080030namespace tests {
Jiewen Tan99135962014-09-20 02:18:53 -070031
Junxiao Shi85d90832016-08-04 03:19:46 +000032using namespace ndn::tests;
33
34BOOST_AUTO_TEST_SUITE(Util)
35BOOST_AUTO_TEST_SUITE(TestInMemoryStorage)
Alexander Afanasyev3ccc6f72014-10-12 12:19:09 -070036BOOST_AUTO_TEST_SUITE(Lru)
Jiewen Tan99135962014-09-20 02:18:53 -070037
38BOOST_AUTO_TEST_CASE(UsedTimeQueue)
39{
40 InMemoryStorageLru ims;
41
42 Name name1("/insert/1");
43 shared_ptr<Data> data1 = makeData(name1);
44 ims.insert(*data1);
45
46 Name name2("/insert/2");
47 shared_ptr<Data> data2 = makeData(name2);
48 ims.insert(*data2);
49
50 Name name3("/insert/3");
51 shared_ptr<Data> data3 = makeData(name3);
52 ims.insert(*data3);
53
54 shared_ptr<Interest> interest1 = makeInterest(name1);
55 shared_ptr<Interest> interest2 = makeInterest(name2);
56 shared_ptr<Interest> interest3 = makeInterest(name3);
57
58 ims.find(*interest1);
59 ims.find(*interest2);
60 ims.find(*interest3);
61 ims.find(*interest1);
62 ims.find(*interest3);
63 ims.find(*interest3);
64
65 ims.evictItem();
66 BOOST_CHECK_EQUAL(ims.size(), 2);
67
68 shared_ptr<const Data> found2 = ims.find(*interest2);
Junxiao Shi85d90832016-08-04 03:19:46 +000069 BOOST_CHECK(found2 == nullptr);
Jiewen Tan99135962014-09-20 02:18:53 -070070
71 shared_ptr<const Data> found1 = ims.find(*interest1);
72 BOOST_CHECK_EQUAL(found1->getName(), name1);
73 shared_ptr<const Data> found3 = ims.find(*interest3);
74 BOOST_CHECK_EQUAL(found3->getName(), name3);
75}
76
77BOOST_AUTO_TEST_CASE(UsedTimeQueue2)
78{
79 InMemoryStorageLru ims;
80
81 Name name1("/insert/1");
82 shared_ptr<Data> data = makeData(name1);
83 ims.insert(*data);
84
85 Name name2("/insert/2");
86 shared_ptr<Data> data2 = makeData(name2);
87 ims.insert(*data2);
88
89 Name name3("/insert/3");
90 shared_ptr<Data> data3 = makeData(name3);
91 ims.insert(*data3);
92
93 shared_ptr<Interest> interest1 = makeInterest(name1);
94 shared_ptr<Interest> interest2 = makeInterest(name2);
95 shared_ptr<Interest> interest3 = makeInterest(name3);
96
97 ims.find(*interest1);
98 ims.find(*interest2);
99 ims.find(*interest3);
100 ims.find(*interest1);
101 ims.find(*interest3);
102 ims.find(*interest3);
103
104 ims.evictItem();
105 BOOST_CHECK_EQUAL(ims.size(), 2);
106
107 shared_ptr<const Data> found2 = ims.find(*interest2);
Junxiao Shi85d90832016-08-04 03:19:46 +0000108 BOOST_CHECK(found2 == nullptr);
Jiewen Tan99135962014-09-20 02:18:53 -0700109
110 shared_ptr<const Data> found1 = ims.find(*interest1);
111 BOOST_CHECK_EQUAL(found1->getName(), name1);
112 shared_ptr<const Data> found3 = ims.find(*interest3);
113 BOOST_CHECK_EQUAL(found3->getName(), name3);
114
115 Name name4("/insert/4");
116 shared_ptr<Data> data4 = makeData(name4);
117 ims.insert(*data4);
118
119 shared_ptr<Interest> interest4 = makeInterest(name4);
120 ims.find(*interest4);
121 ims.find(*interest1);
122 ims.find(*interest3);
123
124 ims.evictItem();
125 BOOST_CHECK_EQUAL(ims.size(), 2);
126
127 shared_ptr<const Data> found4 = ims.find(*interest4);
Junxiao Shi85d90832016-08-04 03:19:46 +0000128 BOOST_CHECK(found4 == nullptr);
Jiewen Tan99135962014-09-20 02:18:53 -0700129
130 found1 = ims.find(*interest1);
131 BOOST_CHECK_EQUAL(found1->getName(), name1);
132 found3 = ims.find(*interest3);
133 BOOST_CHECK_EQUAL(found3->getName(), name3);
134}
135
Alexander Afanasyev3ccc6f72014-10-12 12:19:09 -0700136BOOST_AUTO_TEST_SUITE_END() // Lru
Junxiao Shi85d90832016-08-04 03:19:46 +0000137BOOST_AUTO_TEST_SUITE_END() // TestInMemoryStorage
138BOOST_AUTO_TEST_SUITE_END() // Util
Jiewen Tan99135962014-09-20 02:18:53 -0700139
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800140} // namespace tests
Jiewen Tan99135962014-09-20 02:18:53 -0700141} // namespace util
142} // namespace ndn