Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame^] | 1 | /* -*- 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 "tools/pib/key-cache.hpp" |
| 23 | |
| 24 | #include "tests/test-common.hpp" |
| 25 | |
| 26 | namespace ndn { |
| 27 | namespace pib { |
| 28 | namespace tests { |
| 29 | |
| 30 | BOOST_AUTO_TEST_SUITE(TestKeyCache) |
| 31 | |
| 32 | BOOST_AUTO_TEST_CASE(Basic) |
| 33 | { |
| 34 | KeyCache keyCache(3); |
| 35 | |
| 36 | Name name1("/1"); |
| 37 | Name name2("/2"); |
| 38 | Name name3("/3"); |
| 39 | Name name4("/4"); |
| 40 | |
| 41 | auto key1 = make_shared<PublicKey>(); |
| 42 | auto key2 = make_shared<PublicKey>(); |
| 43 | auto key3 = make_shared<PublicKey>(); |
| 44 | auto key4 = make_shared<PublicKey>(); |
| 45 | |
| 46 | keyCache.insert(name1, key1); |
| 47 | keyCache.insert(name2, key2); |
| 48 | keyCache.insert(name3, key3); |
| 49 | |
| 50 | BOOST_CHECK_EQUAL(keyCache.size(), 3); |
| 51 | BOOST_CHECK(static_cast<bool>(keyCache.find(name1))); |
| 52 | BOOST_CHECK(static_cast<bool>(keyCache.find(name2))); |
| 53 | BOOST_CHECK(static_cast<bool>(keyCache.find(name3))); |
| 54 | BOOST_CHECK(!static_cast<bool>(keyCache.find(name4))); |
| 55 | |
| 56 | keyCache.insert(name1, key1); |
| 57 | keyCache.insert(name4, key4); |
| 58 | BOOST_CHECK_EQUAL(keyCache.size(), 3); |
| 59 | BOOST_CHECK(static_cast<bool>(keyCache.find(name1))); |
| 60 | BOOST_CHECK(!static_cast<bool>(keyCache.find(name2))); |
| 61 | BOOST_CHECK(static_cast<bool>(keyCache.find(name3))); |
| 62 | BOOST_CHECK(static_cast<bool>(keyCache.find(name4))); |
| 63 | |
| 64 | keyCache.erase(name1); |
| 65 | BOOST_CHECK_EQUAL(keyCache.size(), 2); |
| 66 | BOOST_CHECK(!static_cast<bool>(keyCache.find(name1))); |
| 67 | BOOST_CHECK(static_cast<bool>(keyCache.find(name3))); |
| 68 | BOOST_CHECK(static_cast<bool>(keyCache.find(name4))); |
| 69 | } |
| 70 | |
| 71 | BOOST_AUTO_TEST_SUITE_END() |
| 72 | |
| 73 | } // namespace tests |
| 74 | } // namespace pib |
| 75 | } // namespace ndn |