Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 3 | * Copyright (c) 2013-2016 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-lru.hpp" |
| 23 | #include "security/key-chain.hpp" |
| 24 | |
| 25 | #include "boost-test.hpp" |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 26 | #include "../make-interest-data.hpp" |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 27 | |
| 28 | namespace ndn { |
| 29 | namespace util { |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 30 | namespace tests { |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 31 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 32 | using namespace ndn::tests; |
| 33 | |
| 34 | BOOST_AUTO_TEST_SUITE(Util) |
| 35 | BOOST_AUTO_TEST_SUITE(TestInMemoryStorage) |
Alexander Afanasyev | 3ccc6f7 | 2014-10-12 12:19:09 -0700 | [diff] [blame] | 36 | BOOST_AUTO_TEST_SUITE(Lru) |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 37 | |
| 38 | BOOST_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 Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 69 | BOOST_CHECK(found2 == nullptr); |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 70 | |
| 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 | |
| 77 | BOOST_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 Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 108 | BOOST_CHECK(found2 == nullptr); |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 109 | |
| 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 Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 128 | BOOST_CHECK(found4 == nullptr); |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 129 | |
| 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 Afanasyev | 3ccc6f7 | 2014-10-12 12:19:09 -0700 | [diff] [blame] | 136 | BOOST_AUTO_TEST_SUITE_END() // Lru |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 137 | BOOST_AUTO_TEST_SUITE_END() // TestInMemoryStorage |
| 138 | BOOST_AUTO_TEST_SUITE_END() // Util |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 139 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 140 | } // namespace tests |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 141 | } // namespace util |
| 142 | } // namespace ndn |