Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017 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 | |
| 22 | #include "util/in-memory-storage-lfu.hpp" |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 23 | |
| 24 | #include "boost-test.hpp" |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 25 | #include "../make-interest-data.hpp" |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 26 | |
| 27 | namespace ndn { |
| 28 | namespace util { |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 29 | namespace tests { |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 30 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 31 | using namespace ndn::tests; |
| 32 | |
| 33 | BOOST_AUTO_TEST_SUITE(Util) |
| 34 | BOOST_AUTO_TEST_SUITE(TestInMemoryStorage) |
Alexander Afanasyev | 3ccc6f7 | 2014-10-12 12:19:09 -0700 | [diff] [blame] | 35 | BOOST_AUTO_TEST_SUITE(Lfu) |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 36 | |
| 37 | BOOST_AUTO_TEST_CASE(FrequencyQueue) |
| 38 | { |
| 39 | InMemoryStorageLfu 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 Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 68 | BOOST_CHECK(found2 == nullptr); |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 69 | |
| 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 | |
| 76 | BOOST_AUTO_TEST_CASE(FrequencyQueue2) |
| 77 | { |
| 78 | InMemoryStorageLfu ims; |
| 79 | |
| 80 | Name name1("/insert/1"); |
| 81 | shared_ptr<Data> data1 = makeData(name1); |
| 82 | ims.insert(*data1); |
| 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 Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 107 | BOOST_CHECK(found2 == nullptr); |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 108 | |
| 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 | |
| 121 | ims.evictItem(); |
| 122 | BOOST_CHECK_EQUAL(ims.size(), 2); |
| 123 | |
| 124 | shared_ptr<const Data> found4 = ims.find(*interest4); |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 125 | BOOST_CHECK(found4 == nullptr); |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 126 | |
| 127 | found1 = ims.find(*interest1); |
| 128 | BOOST_CHECK_EQUAL(found1->getName(), name1); |
| 129 | found3 = ims.find(*interest3); |
| 130 | BOOST_CHECK_EQUAL(found3->getName(), name3); |
| 131 | } |
| 132 | |
Alexander Afanasyev | 3ccc6f7 | 2014-10-12 12:19:09 -0700 | [diff] [blame] | 133 | BOOST_AUTO_TEST_SUITE_END() // Lfu |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 134 | BOOST_AUTO_TEST_SUITE_END() // TestInMemoryStorage |
| 135 | BOOST_AUTO_TEST_SUITE_END() // Util |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 136 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 137 | } // namespace tests |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 138 | } // namespace util |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 139 | } // namespace ndn |