blob: 8c07e6e5e44983e5b93993481683cbfb1f16e71b [file] [log] [blame]
Jiewen Tan99135962014-09-20 02:18:53 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2014 Regents of the University of California.
4 *
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"
26#include "../test-make-interest-data.hpp"
27
28namespace ndn {
29namespace util {
30
31BOOST_AUTO_TEST_SUITE(UtilInMemoryStorageLru)
32
33BOOST_AUTO_TEST_CASE(UsedTimeQueue)
34{
35 InMemoryStorageLru ims;
36
37 Name name1("/insert/1");
38 shared_ptr<Data> data1 = makeData(name1);
39 ims.insert(*data1);
40
41 Name name2("/insert/2");
42 shared_ptr<Data> data2 = makeData(name2);
43 ims.insert(*data2);
44
45 Name name3("/insert/3");
46 shared_ptr<Data> data3 = makeData(name3);
47 ims.insert(*data3);
48
49 shared_ptr<Interest> interest1 = makeInterest(name1);
50 shared_ptr<Interest> interest2 = makeInterest(name2);
51 shared_ptr<Interest> interest3 = makeInterest(name3);
52
53 ims.find(*interest1);
54 ims.find(*interest2);
55 ims.find(*interest3);
56 ims.find(*interest1);
57 ims.find(*interest3);
58 ims.find(*interest3);
59
60 ims.evictItem();
61 BOOST_CHECK_EQUAL(ims.size(), 2);
62
63 shared_ptr<const Data> found2 = ims.find(*interest2);
64 BOOST_CHECK(!static_cast<bool>(found2));
65
66 shared_ptr<const Data> found1 = ims.find(*interest1);
67 BOOST_CHECK_EQUAL(found1->getName(), name1);
68 shared_ptr<const Data> found3 = ims.find(*interest3);
69 BOOST_CHECK_EQUAL(found3->getName(), name3);
70}
71
72BOOST_AUTO_TEST_CASE(UsedTimeQueue2)
73{
74 InMemoryStorageLru ims;
75
76 Name name1("/insert/1");
77 shared_ptr<Data> data = makeData(name1);
78 ims.insert(*data);
79
80 Name name2("/insert/2");
81 shared_ptr<Data> data2 = makeData(name2);
82 ims.insert(*data2);
83
84 Name name3("/insert/3");
85 shared_ptr<Data> data3 = makeData(name3);
86 ims.insert(*data3);
87
88 shared_ptr<Interest> interest1 = makeInterest(name1);
89 shared_ptr<Interest> interest2 = makeInterest(name2);
90 shared_ptr<Interest> interest3 = makeInterest(name3);
91
92 ims.find(*interest1);
93 ims.find(*interest2);
94 ims.find(*interest3);
95 ims.find(*interest1);
96 ims.find(*interest3);
97 ims.find(*interest3);
98
99 ims.evictItem();
100 BOOST_CHECK_EQUAL(ims.size(), 2);
101
102 shared_ptr<const Data> found2 = ims.find(*interest2);
103 BOOST_CHECK(!static_cast<bool>(found2));
104
105 shared_ptr<const Data> found1 = ims.find(*interest1);
106 BOOST_CHECK_EQUAL(found1->getName(), name1);
107 shared_ptr<const Data> found3 = ims.find(*interest3);
108 BOOST_CHECK_EQUAL(found3->getName(), name3);
109
110 Name name4("/insert/4");
111 shared_ptr<Data> data4 = makeData(name4);
112 ims.insert(*data4);
113
114 shared_ptr<Interest> interest4 = makeInterest(name4);
115 ims.find(*interest4);
116 ims.find(*interest1);
117 ims.find(*interest3);
118
119 ims.evictItem();
120 BOOST_CHECK_EQUAL(ims.size(), 2);
121
122 shared_ptr<const Data> found4 = ims.find(*interest4);
123 BOOST_CHECK(!static_cast<bool>(found4));
124
125 found1 = ims.find(*interest1);
126 BOOST_CHECK_EQUAL(found1->getName(), name1);
127 found3 = ims.find(*interest3);
128 BOOST_CHECK_EQUAL(found3->getName(), name3);
129}
130
131BOOST_AUTO_TEST_SUITE_END()
132
133} // namespace util
134} // namespace ndn