Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 4a16004 | 2020-04-13 16:50:02 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | b496642 | 2023-08-10 21:15:32 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2023, Regents of the University of California. |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 4 | * |
| 5 | * This file is part of NDN repo-ng (Next generation of NDN repository). |
| 6 | * See AUTHORS.md for complete list of repo-ng authors and contributors. |
| 7 | * |
| 8 | * repo-ng is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include "handles/read-handle.hpp" |
| 21 | #include "storage/sqlite-storage.hpp" |
| 22 | #include "storage/repo-storage.hpp" |
| 23 | |
| 24 | #include "../repo-storage-fixture.hpp" |
| 25 | |
| 26 | #include <boost/test/unit_test.hpp> |
| 27 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 28 | |
Davide Pesavento | 9bf1a1d | 2020-04-14 16:50:03 -0400 | [diff] [blame] | 29 | #define CHECK_INTERESTS(NAME, COMPONENT, EXPECTED) \ |
| 30 | do { \ |
| 31 | bool didMatch = false; \ |
| 32 | for (const auto& interest : face.sentInterests) { \ |
| 33 | didMatch = didMatch || containsNameComponent(NAME, COMPONENT); \ |
| 34 | } \ |
| 35 | BOOST_CHECK_EQUAL(didMatch, EXPECTED); \ |
| 36 | } while (false) |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 37 | |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 38 | namespace repo::tests { |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 39 | |
| 40 | BOOST_AUTO_TEST_SUITE(TestReadHandle) |
| 41 | |
| 42 | class Fixture : public RepoStorageFixture |
| 43 | { |
| 44 | public: |
| 45 | Fixture() |
Davide Pesavento | 9bf1a1d | 2020-04-14 16:50:03 -0400 | [diff] [blame] | 46 | : face({true, true}) |
Davide Pesavento | 164ae3b | 2023-11-11 22:00:23 -0500 | [diff] [blame] | 47 | , scheduler(face.getIoContext()) |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 48 | , subsetLength(1) |
| 49 | , dataPrefix("/ndn/test/prefix") |
| 50 | , identity("/ndn/test/identity") |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 51 | , readHandle(face, *handle, subsetLength) |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 52 | , numPrefixRegistrations(0) |
| 53 | , numPrefixUnregistrations(0) |
| 54 | { |
| 55 | readHandle.connectAutoListen(); |
| 56 | } |
| 57 | |
Davide Pesavento | 9bf1a1d | 2020-04-14 16:50:03 -0400 | [diff] [blame] | 58 | static bool |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 59 | containsNameComponent(const Name& name, const Name::Component& component) |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 60 | { |
Davide Pesavento | 9bf1a1d | 2020-04-14 16:50:03 -0400 | [diff] [blame] | 61 | for (const auto& c : name) { |
| 62 | if (c == component) |
| 63 | return true; |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 64 | } |
Davide Pesavento | 9bf1a1d | 2020-04-14 16:50:03 -0400 | [diff] [blame] | 65 | return false; |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | public: |
Davide Pesavento | b496642 | 2023-08-10 21:15:32 -0400 | [diff] [blame] | 69 | ndn::DummyClientFace face; |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 70 | ndn::KeyChain keyChain; |
| 71 | ndn::Scheduler scheduler; |
| 72 | |
| 73 | size_t subsetLength; |
| 74 | ndn::Name dataPrefix; |
| 75 | ndn::Name identity; |
| 76 | ReadHandle readHandle; |
| 77 | |
| 78 | size_t numPrefixRegistrations; |
| 79 | size_t numPrefixUnregistrations; |
| 80 | }; |
| 81 | |
| 82 | BOOST_FIXTURE_TEST_CASE(DataPrefixes, Fixture) |
| 83 | { |
| 84 | const std::vector<uint8_t> content(100, 'x'); |
Davide Pesavento | 4a16004 | 2020-04-13 16:50:02 -0400 | [diff] [blame] | 85 | auto data1 = std::make_shared<Data>(Name{dataPrefix}.appendNumber(1)); |
| 86 | auto data2 = std::make_shared<Data>(Name{dataPrefix}.appendNumber(2)); |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 87 | |
Davide Pesavento | 9c0bd8d | 2022-03-14 16:48:12 -0400 | [diff] [blame] | 88 | data1->setContent(content); |
| 89 | data2->setContent(content); |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 90 | |
| 91 | keyChain.createIdentity(identity); |
| 92 | keyChain.sign(*data1, ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_ID, |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 93 | identity)); |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 94 | keyChain.sign(*data2, ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_ID, |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 95 | identity)); |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 96 | |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 97 | face.sentInterests.clear(); |
| 98 | handle->insertData(*data1); |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 99 | face.processEvents(-1_ms); |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 100 | CHECK_INTERESTS(interest.getName(), Name::Component{"register"}, true); |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 101 | |
| 102 | face.sentInterests.clear(); |
| 103 | handle->deleteData(data1->getFullName()); |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 104 | face.processEvents(-1_ms); |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 105 | CHECK_INTERESTS(interest.getName(), Name::Component{"unregister"}, true); |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 106 | |
| 107 | face.sentInterests.clear(); |
| 108 | handle->insertData(*data1); |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 109 | face.processEvents(-1_ms); |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 110 | CHECK_INTERESTS(interest.getName(), Name::Component{"register"}, true); |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 111 | |
| 112 | face.sentInterests.clear(); |
| 113 | handle->insertData(*data2); |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 114 | face.processEvents(-1_ms); |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 115 | CHECK_INTERESTS(interest.getName(), Name::Component{"register"}, false); |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 116 | |
| 117 | face.sentInterests.clear(); |
| 118 | handle->deleteData(data1->getFullName()); |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 119 | face.processEvents(-1_ms); |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 120 | CHECK_INTERESTS(interest.getName(), Name::Component{"unregister"}, false); |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 121 | |
| 122 | face.sentInterests.clear(); |
| 123 | handle->deleteData(data2->getFullName()); |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 124 | face.processEvents(-1_ms); |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 125 | CHECK_INTERESTS(interest.getName(), Name::Component{"unregister"}, true); |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | BOOST_AUTO_TEST_SUITE_END() // TestReadHandle |
| 129 | |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 130 | } // namespace repo::tests |