Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 5c16cc2 | 2019-04-02 14:17:12 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2022, Regents of the University of California. |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [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 "storage/repo-storage.hpp" |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 21 | #include "../dataset-fixtures.hpp" |
| 22 | #include "../repo-storage-fixture.hpp" |
| 23 | |
| 24 | #include <boost/test/unit_test.hpp> |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 25 | |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 26 | namespace repo::tests { |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 27 | |
| 28 | BOOST_AUTO_TEST_SUITE(RepoStorage) |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 29 | |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 30 | template<class Dataset> |
| 31 | class Fixture : public Dataset, public RepoStorageFixture |
| 32 | { |
| 33 | }; |
| 34 | |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 35 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(Bulk, T, CommonDatasets, Fixture<T>) |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 36 | { |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 37 | // Insert data into repo |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 38 | for (auto i = this->data.begin(); i != this->data.end(); ++i) { |
| 39 | BOOST_CHECK_EQUAL(this->handle->insertData(**i), true); |
| 40 | } |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 41 | |
| 42 | // check size directly with the storage (repo doesn't have interface yet) |
Alexander Afanasyev | d352cce | 2015-11-20 14:15:11 -0500 | [diff] [blame] | 43 | BOOST_CHECK_EQUAL(this->store->size(), static_cast<int64_t>(this->data.size())); |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 44 | |
| 45 | // Read |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 46 | for (auto i = this->interests.begin(); i != this->interests.end(); ++i) { |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 47 | auto dataTest = this->handle->readData(i->first); |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 48 | BOOST_CHECK_EQUAL(*dataTest, *i->second); |
| 49 | } |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 50 | |
| 51 | // Remove items |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 52 | for (auto i = this->removals.begin(); i != this->removals.end(); ++i) { |
| 53 | size_t nRemoved = 0; |
| 54 | nRemoved = this->handle->deleteData(i->first); |
| 55 | BOOST_CHECK_EQUAL(nRemoved, i->second); |
| 56 | } |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Alexander Afanasyev | 5c16cc2 | 2019-04-02 14:17:12 -0400 | [diff] [blame] | 59 | BOOST_FIXTURE_TEST_CASE(NotifyAboutExistingData, Fixture<BasicDataset>) |
| 60 | { |
| 61 | // Insert data into repo |
| 62 | for (const auto& d : this->data) { |
| 63 | handle->insertData(*d); |
| 64 | } |
| 65 | |
| 66 | std::vector<Name> names; |
| 67 | handle->afterDataInsertion.connect([&] (const Name& name) { |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 68 | names.push_back(name); |
| 69 | }); |
Alexander Afanasyev | 5c16cc2 | 2019-04-02 14:17:12 -0400 | [diff] [blame] | 70 | handle->notifyAboutExistingData(); |
| 71 | |
| 72 | BOOST_CHECK_EQUAL(names.size(), this->data.size()); |
| 73 | } |
| 74 | |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 75 | BOOST_AUTO_TEST_SUITE_END() |
| 76 | |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 77 | } // namespace repo::tests |