blob: 4f89d6b7f40820f94772d24326e7103ba1772fa7 [file] [log] [blame]
Weiqi Shif0330d52014-07-09 10:54:27 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev5c16cc22019-04-02 14:17:12 -04002/*
3 * Copyright (c) 2014-2019, Regents of the University of California.
Weiqi Shif0330d52014-07-09 10:54:27 -07004 *
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"
21#include "storage/sqlite-storage.hpp"
22#include "../dataset-fixtures.hpp"
23#include "../repo-storage-fixture.hpp"
24
Junxiao Shi047a6fb2017-06-08 16:16:05 +000025#include <boost/mpl/push_back.hpp>
Weiqi Shif0330d52014-07-09 10:54:27 -070026#include <boost/test/unit_test.hpp>
27#include <iostream>
28#include <string.h>
29
30namespace repo {
31namespace tests {
32
33BOOST_AUTO_TEST_SUITE(RepoStorage)
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070034
Weiqi Shif0330d52014-07-09 10:54:27 -070035template<class Dataset>
36class Fixture : public Dataset, public RepoStorageFixture
37{
38};
39
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070040
weijia yuan3aa8d2b2018-03-06 15:35:57 -080041BOOST_FIXTURE_TEST_CASE_TEMPLATE(Bulk, T, CommonDatasets, Fixture<T>)
Weiqi Shif0330d52014-07-09 10:54:27 -070042{
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070043 BOOST_TEST_MESSAGE(T::getName());
44
45 // Insert data into repo
weijia yuan3aa8d2b2018-03-06 15:35:57 -080046 for (auto i = this->data.begin(); i != this->data.end(); ++i) {
47 BOOST_CHECK_EQUAL(this->handle->insertData(**i), true);
48 }
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070049
50 // check size directly with the storage (repo doesn't have interface yet)
Alexander Afanasyevd352cce2015-11-20 14:15:11 -050051 BOOST_CHECK_EQUAL(this->store->size(), static_cast<int64_t>(this->data.size()));
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070052
53 // Read
weijia yuan3aa8d2b2018-03-06 15:35:57 -080054 for (auto i = this->interests.begin(); i != this->interests.end(); ++i) {
55 std::shared_ptr<ndn::Data> dataTest = this->handle->readData(i->first);
56 BOOST_CHECK_EQUAL(*dataTest, *i->second);
57 }
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070058
59 // Remove items
weijia yuan3aa8d2b2018-03-06 15:35:57 -080060 for (auto i = this->removals.begin(); i != this->removals.end(); ++i) {
61 size_t nRemoved = 0;
62 nRemoved = this->handle->deleteData(i->first);
63 BOOST_CHECK_EQUAL(nRemoved, i->second);
64 }
Weiqi Shif0330d52014-07-09 10:54:27 -070065}
66
Alexander Afanasyev5c16cc22019-04-02 14:17:12 -040067BOOST_FIXTURE_TEST_CASE(NotifyAboutExistingData, Fixture<BasicDataset>)
68{
69 // Insert data into repo
70 for (const auto& d : this->data) {
71 handle->insertData(*d);
72 }
73
74 std::vector<Name> names;
75 handle->afterDataInsertion.connect([&] (const Name& name) {
76 names.push_back(name);
77 BOOST_TEST_MESSAGE("Got notification about " << name);
78 });
79
80 handle->notifyAboutExistingData();
81
82 BOOST_CHECK_EQUAL(names.size(), this->data.size());
83}
84
Weiqi Shif0330d52014-07-09 10:54:27 -070085BOOST_AUTO_TEST_SUITE_END()
86
87} // namespace tests
88} // namespace repo