blob: 76192c200d6fe19683b32a8af07960ca14a1f806 [file] [log] [blame]
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyeve1e6f2a2014-04-25 11:28:12 -07003 * 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 Afanasyevb0c78ea2014-04-15 18:12:04 -070018 */
19
Alexander Afanasyev39d98072014-05-04 12:46:29 -070020#include "storage/sqlite-handle.hpp"
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070021
22#include "sqlite-fixture.hpp"
23#include "dataset-fixtures.hpp"
24
25#include <boost/test/unit_test.hpp>
26
27namespace repo {
28namespace tests {
29
30BOOST_AUTO_TEST_SUITE(SqliteHandle)
31
32template<class Dataset>
33class Fixture : public SqliteFixture, public Dataset
34{
35};
36
37BOOST_FIXTURE_TEST_CASE_TEMPLATE(InsertReadDelete, T, DatasetFixtures, Fixture<T>)
38{
39 BOOST_TEST_MESSAGE(T::getName());
40
41 // Insert
42 for (typename T::DataContainer::iterator i = this->data.begin();
43 i != this->data.end(); ++i) {
44 BOOST_CHECK_EQUAL(this->handle->insertData(**i), true);
45 }
46
47 BOOST_CHECK_EQUAL(this->handle->size(), this->data.size());
48
49 // Read (all items should exist)
50 for (typename T::InterestContainer::iterator i = this->interests.begin();
51 i != this->interests.end(); ++i) {
52 ndn::Data retrievedData;
53 BOOST_REQUIRE_EQUAL(this->handle->readData(i->first, retrievedData), true);
54 BOOST_CHECK_EQUAL(retrievedData, *i->second);
55 }
56
57 // Delete
58 for (typename T::DataContainer::iterator i = this->data.begin();
59 i != this->data.end(); ++i) {
60 BOOST_CHECK_EQUAL(this->handle->deleteData((*i)->getName()), true);
61 }
62
63 // Read (none of the items should exist)
64 for (typename T::InterestContainer::iterator i = this->interests.begin();
65 i != this->interests.end(); ++i) {
66 ndn::Data retrievedData;
67 BOOST_REQUIRE_EQUAL(this->handle->readData(i->first, retrievedData), false);
68 }
69}
70
71BOOST_AUTO_TEST_SUITE_END()
72
73} // namespace tests
74} // namespace repo