Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | e1e6f2a | 2014-04-25 11:28:12 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014, Regents of the University of California. |
| 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/>. |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame^] | 20 | #include "storage/sqlite-storage.hpp" |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 21 | |
Shuo Chen | ca32918 | 2014-03-19 18:05:18 -0700 | [diff] [blame] | 22 | #include "../sqlite-fixture.hpp" |
| 23 | #include "../dataset-fixtures.hpp" |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 24 | |
| 25 | #include <boost/test/unit_test.hpp> |
| 26 | |
| 27 | namespace repo { |
| 28 | namespace tests { |
| 29 | |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame^] | 30 | BOOST_AUTO_TEST_SUITE(SqliteStorage) |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 31 | |
| 32 | template<class Dataset> |
| 33 | class Fixture : public SqliteFixture, public Dataset |
| 34 | { |
| 35 | }; |
| 36 | |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame^] | 37 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(InsertReadDelete, T, DatasetFixtures_Sqlite, Fixture<T>) |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 38 | { |
| 39 | BOOST_TEST_MESSAGE(T::getName()); |
| 40 | |
| 41 | // Insert |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame^] | 42 | for (typename T::IdContainer::iterator i = this->ids.begin(); |
| 43 | i != this->ids.end(); ++i) { |
| 44 | BOOST_CHECK_EQUAL(this->handle->insert(*i->second), i->first); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | BOOST_CHECK_EQUAL(this->handle->size(), this->data.size()); |
| 48 | |
| 49 | // Read (all items should exist) |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame^] | 50 | for (typename T::IdContainer::iterator i = this->ids.begin(); |
| 51 | i != this->ids.end(); ++i) { |
| 52 | shared_ptr<Data> retrievedData = this->handle->read(i->first); |
| 53 | BOOST_CHECK_EQUAL(*retrievedData, *i->second); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | // Delete |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame^] | 57 | for (typename T::IdContainer::iterator i = this->ids.begin(); |
| 58 | i != this->ids.end(); ++i) { |
| 59 | //std::cout<<"remove name = "<<i->second->getName()<<std::endl; |
| 60 | BOOST_CHECK_EQUAL(this->handle->erase(i->first), true); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame^] | 63 | /* |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 64 | // Read (none of the items should exist) |
| 65 | for (typename T::InterestContainer::iterator i = this->interests.begin(); |
| 66 | i != this->interests.end(); ++i) { |
| 67 | ndn::Data retrievedData; |
| 68 | BOOST_REQUIRE_EQUAL(this->handle->readData(i->first, retrievedData), false); |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame^] | 69 | }*/ |
| 70 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | BOOST_AUTO_TEST_SUITE_END() |
| 74 | |
| 75 | } // namespace tests |
| 76 | } // namespace repo |