Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 047a6fb | 2017-06-08 16:16:05 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, 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" |
| 21 | #include "storage/sqlite-storage.hpp" |
| 22 | #include "../dataset-fixtures.hpp" |
| 23 | #include "../repo-storage-fixture.hpp" |
| 24 | |
Junxiao Shi | 047a6fb | 2017-06-08 16:16:05 +0000 | [diff] [blame] | 25 | #include <boost/mpl/push_back.hpp> |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 26 | #include <boost/test/unit_test.hpp> |
| 27 | #include <iostream> |
| 28 | #include <string.h> |
| 29 | |
| 30 | namespace repo { |
| 31 | namespace tests { |
| 32 | |
| 33 | BOOST_AUTO_TEST_SUITE(RepoStorage) |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 34 | |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 35 | template<class Dataset> |
| 36 | class Fixture : public Dataset, public RepoStorageFixture |
| 37 | { |
| 38 | }; |
| 39 | |
Alexander Afanasyev | 595b2bd | 2014-12-14 12:55:36 -0800 | [diff] [blame] | 40 | // Combine CommonDatasets with ComplexSelectorDataset |
| 41 | typedef boost::mpl::push_back<CommonDatasets, |
| 42 | ComplexSelectorsDataset>::type Datasets; |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 43 | |
Alexander Afanasyev | 595b2bd | 2014-12-14 12:55:36 -0800 | [diff] [blame] | 44 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(Bulk, T, Datasets, Fixture<T>) |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 45 | { |
Alexander Afanasyev | 595b2bd | 2014-12-14 12:55:36 -0800 | [diff] [blame] | 46 | // typedef ComplexSelectorsDataset T; |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 47 | BOOST_TEST_MESSAGE(T::getName()); |
| 48 | |
| 49 | // Insert data into repo |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 50 | for (typename T::DataContainer::iterator i = this->data.begin(); |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 51 | i != this->data.end(); ++i) |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 52 | { |
| 53 | BOOST_CHECK_EQUAL(this->handle->insertData(**i), true); |
| 54 | } |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 55 | |
| 56 | // check size directly with the storage (repo doesn't have interface yet) |
Alexander Afanasyev | d352cce | 2015-11-20 14:15:11 -0500 | [diff] [blame] | 57 | 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] | 58 | |
| 59 | // Read |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 60 | for (typename T::InterestContainer::iterator i = this->interests.begin(); |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 61 | i != this->interests.end(); ++i) |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 62 | { |
| 63 | shared_ptr<ndn::Data> dataTest = this->handle->readData(i->first); |
| 64 | BOOST_CHECK_EQUAL(*this->handle->readData(i->first), *i->second); |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 65 | } |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 66 | |
| 67 | // Remove items |
| 68 | for (typename T::RemovalsContainer::iterator i = this->removals.begin(); |
| 69 | i != this->removals.end(); ++i) |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 70 | { |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 71 | size_t nRemoved = 0; |
| 72 | BOOST_REQUIRE_NO_THROW(nRemoved = this->handle->deleteData(i->first)); |
| 73 | BOOST_CHECK_EQUAL(nRemoved, i->second); |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 74 | } |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | BOOST_AUTO_TEST_SUITE_END() |
| 78 | |
| 79 | } // namespace tests |
| 80 | } // namespace repo |