Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | c542f63 | 2017-07-18 14:20:32 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 3 | * Copyright (c) 2013-2020 Regents of the University of California. |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 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 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 22 | #include "ndn-cxx/ims/in-memory-storage-lru.hpp" |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 23 | |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 24 | #include "tests/test-common.hpp" |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 25 | |
| 26 | namespace ndn { |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 27 | namespace tests { |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 28 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 29 | using namespace ndn::tests; |
| 30 | |
Junxiao Shi | c542f63 | 2017-07-18 14:20:32 +0000 | [diff] [blame] | 31 | BOOST_AUTO_TEST_SUITE(Ims) |
| 32 | BOOST_AUTO_TEST_SUITE(TestInMemoryStorageLru) |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 33 | |
| 34 | BOOST_AUTO_TEST_CASE(UsedTimeQueue) |
| 35 | { |
| 36 | InMemoryStorageLru ims; |
| 37 | |
| 38 | Name name1("/insert/1"); |
| 39 | shared_ptr<Data> data1 = makeData(name1); |
| 40 | ims.insert(*data1); |
| 41 | |
| 42 | Name name2("/insert/2"); |
| 43 | shared_ptr<Data> data2 = makeData(name2); |
| 44 | ims.insert(*data2); |
| 45 | |
| 46 | Name name3("/insert/3"); |
| 47 | shared_ptr<Data> data3 = makeData(name3); |
| 48 | ims.insert(*data3); |
| 49 | |
| 50 | shared_ptr<Interest> interest1 = makeInterest(name1); |
| 51 | shared_ptr<Interest> interest2 = makeInterest(name2); |
| 52 | shared_ptr<Interest> interest3 = makeInterest(name3); |
| 53 | |
| 54 | ims.find(*interest1); |
| 55 | ims.find(*interest2); |
| 56 | ims.find(*interest3); |
| 57 | ims.find(*interest1); |
| 58 | ims.find(*interest3); |
| 59 | ims.find(*interest3); |
| 60 | |
| 61 | ims.evictItem(); |
| 62 | BOOST_CHECK_EQUAL(ims.size(), 2); |
| 63 | |
| 64 | shared_ptr<const Data> found2 = ims.find(*interest2); |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 65 | BOOST_CHECK(found2 == nullptr); |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 66 | |
| 67 | shared_ptr<const Data> found1 = ims.find(*interest1); |
| 68 | BOOST_CHECK_EQUAL(found1->getName(), name1); |
| 69 | shared_ptr<const Data> found3 = ims.find(*interest3); |
| 70 | BOOST_CHECK_EQUAL(found3->getName(), name3); |
| 71 | } |
| 72 | |
| 73 | BOOST_AUTO_TEST_CASE(UsedTimeQueue2) |
| 74 | { |
| 75 | InMemoryStorageLru ims; |
| 76 | |
| 77 | Name name1("/insert/1"); |
| 78 | shared_ptr<Data> data = makeData(name1); |
| 79 | ims.insert(*data); |
| 80 | |
| 81 | Name name2("/insert/2"); |
| 82 | shared_ptr<Data> data2 = makeData(name2); |
| 83 | ims.insert(*data2); |
| 84 | |
| 85 | Name name3("/insert/3"); |
| 86 | shared_ptr<Data> data3 = makeData(name3); |
| 87 | ims.insert(*data3); |
| 88 | |
| 89 | shared_ptr<Interest> interest1 = makeInterest(name1); |
| 90 | shared_ptr<Interest> interest2 = makeInterest(name2); |
| 91 | shared_ptr<Interest> interest3 = makeInterest(name3); |
| 92 | |
| 93 | ims.find(*interest1); |
| 94 | ims.find(*interest2); |
| 95 | ims.find(*interest3); |
| 96 | ims.find(*interest1); |
| 97 | ims.find(*interest3); |
| 98 | ims.find(*interest3); |
| 99 | |
| 100 | ims.evictItem(); |
| 101 | BOOST_CHECK_EQUAL(ims.size(), 2); |
| 102 | |
| 103 | shared_ptr<const Data> found2 = ims.find(*interest2); |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 104 | BOOST_CHECK(found2 == nullptr); |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 105 | |
| 106 | shared_ptr<const Data> found1 = ims.find(*interest1); |
| 107 | BOOST_CHECK_EQUAL(found1->getName(), name1); |
| 108 | shared_ptr<const Data> found3 = ims.find(*interest3); |
| 109 | BOOST_CHECK_EQUAL(found3->getName(), name3); |
| 110 | |
| 111 | Name name4("/insert/4"); |
| 112 | shared_ptr<Data> data4 = makeData(name4); |
| 113 | ims.insert(*data4); |
| 114 | |
| 115 | shared_ptr<Interest> interest4 = makeInterest(name4); |
| 116 | ims.find(*interest4); |
| 117 | ims.find(*interest1); |
| 118 | ims.find(*interest3); |
| 119 | |
| 120 | ims.evictItem(); |
| 121 | BOOST_CHECK_EQUAL(ims.size(), 2); |
| 122 | |
| 123 | shared_ptr<const Data> found4 = ims.find(*interest4); |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 124 | BOOST_CHECK(found4 == nullptr); |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 125 | |
| 126 | found1 = ims.find(*interest1); |
| 127 | BOOST_CHECK_EQUAL(found1->getName(), name1); |
| 128 | found3 = ims.find(*interest3); |
| 129 | BOOST_CHECK_EQUAL(found3->getName(), name3); |
| 130 | } |
| 131 | |
Junxiao Shi | c542f63 | 2017-07-18 14:20:32 +0000 | [diff] [blame] | 132 | BOOST_AUTO_TEST_SUITE_END() // TestInMemoryStorageLru |
| 133 | BOOST_AUTO_TEST_SUITE_END() // Ims |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 134 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 135 | } // namespace tests |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 136 | } // namespace ndn |