blob: 41f99307b511f3e2c46a58294ee1cc73c61bf47e [file] [log] [blame]
Weiqi Shif0330d52014-07-09 10:54:27 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
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/>.
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
25#include <boost/test/unit_test.hpp>
26#include <iostream>
27#include <string.h>
28
29namespace repo {
30namespace tests {
31
32BOOST_AUTO_TEST_SUITE(RepoStorage)
33template<class Dataset>
34class Fixture : public Dataset, public RepoStorageFixture
35{
36};
37
38BOOST_FIXTURE_TEST_CASE_TEMPLATE(NdnNameSkipList, T, DatasetFixtures_Storage, Fixture<T>)
39{
40 //Insert
41 for (typename T::DataContainer::iterator i = this->data.begin();
42 i != this->data.end(); ++i)
43 {
44 BOOST_CHECK_EQUAL(this->handle->insertData(**i), true);
45 }
46
47 //Read
48 for (typename T::InterestContainer::iterator i = this->interests.begin();
49 i != this->interests.end(); ++i)
50 {
51 shared_ptr<ndn::Data> dataTest = this->handle->readData(i->first);
52 BOOST_CHECK_EQUAL(*this->handle->readData(i->first), *i->second);
53 // int rc = memcmp(dataTest->getContent().value(),
54 // i->second->getContent().value(), sizeof(i->second->getContent().value()));
55 //BOOST_CHECK_EQUAL(rc, 0);
56 BOOST_CHECK_EQUAL(this->handle->deleteData(i->first.getName()), 1);
57 }
58
59 //Insert
60 for (typename T::DataContainer::iterator i = this->data.begin();
61 i != this->data.end(); ++i)
62 {
63 BOOST_CHECK_EQUAL(this->handle->insertData(**i), true);
64 }
65
66 //Erase
67 for (typename T::InterestIdContainer::iterator i = this->interestDeleteCount.begin();
68 i != this->interestDeleteCount.end(); ++i)
69 {
70 BOOST_CHECK_EQUAL(this->handle->deleteData(i->first), i->second);
71 }
72}
73
74BOOST_FIXTURE_TEST_CASE_TEMPLATE(Index, T, DatasetFixtures_Storage, Fixture<T>)
75{
76
77 for (typename T::DataContainer::iterator i = this->data.begin();
78 i != this->data.end(); ++i)
79 {
80 BOOST_CHECK_EQUAL(this->handle->insertData(**i), true);
81 }
82 ndn::Interest interest("/a");
83 ndn::Interest interest1("/a/b/d/1");
84
85 BOOST_CHECK_EQUAL(this->handle->deleteData(interest), 7);
86
87
88 for (typename T::DataContainer::iterator i = this->data.begin();
89 i != this->data.end(); ++i)
90 {
91 BOOST_CHECK_EQUAL(this->handle->insertData(**i), true);
92 }
93 BOOST_CHECK_EQUAL(this->handle->deleteData(interest.getName()), 7);
94}
95
96BOOST_AUTO_TEST_SUITE_END()
97
98} // namespace tests
99} // namespace repo