blob: 1a4e272c683c75669ee93174952aed6c8a1f0666 [file] [log] [blame]
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
weijia yuan82cf9142018-10-21 12:25:02 -07003 * Copyright (c) 2014-2018, Regents of the University of California.
Alexander Afanasyeve1e6f2a2014-04-25 11:28:12 -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/>.
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070018 */
19
20#ifndef REPO_TESTS_DATASET_FIXTURES_HPP
21#define REPO_TESTS_DATASET_FIXTURES_HPP
22
Junxiao Shi047a6fb2017-06-08 16:16:05 +000023#include "identity-management-fixture.hpp"
Wentao Shang91fb4f22014-05-20 10:55:22 -070024#include <vector>
25#include <boost/mpl/vector.hpp>
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070026
27namespace repo {
28namespace tests {
29
Junxiao Shi047a6fb2017-06-08 16:16:05 +000030class DatasetBase : public virtual IdentityManagementFixture
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070031{
32public:
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070033 class Error : public std::runtime_error
34 {
35 public:
36 explicit
37 Error(const std::string& what)
38 : std::runtime_error(what)
39 {
40 }
41 };
42
weijia yuan3aa8d2b2018-03-06 15:35:57 -080043 using DataContainer = std::list<std::shared_ptr<ndn::Data>>;
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070044 DataContainer data;
45
weijia yuan3aa8d2b2018-03-06 15:35:57 -080046 using InterestContainer = std::list<std::pair<ndn::Interest, std::shared_ptr<ndn::Data>>>;
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070047 InterestContainer interests;
Shuo Chen9a43f162014-07-01 13:43:54 +080048
weijia yuan3aa8d2b2018-03-06 15:35:57 -080049 using RemovalsContainer = std::list<std::pair<ndn::Interest, size_t>>;
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070050 RemovalsContainer removals;
Weiqi Shi28a90fb2014-07-09 10:28:55 -070051
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070052protected:
Alexander Afanasyev42290b22017-03-09 12:58:29 -080053 std::shared_ptr<ndn::Data>
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070054 createData(const ndn::Name& name)
Shuo Chen9a43f162014-07-01 13:43:54 +080055 {
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070056 if (map.count(name) > 0)
57 return map[name];
Shuo Chen9a43f162014-07-01 13:43:54 +080058
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070059 static std::vector<uint8_t> content(1500, '-');
60
Alexander Afanasyev42290b22017-03-09 12:58:29 -080061 std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>();
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070062 data->setName(name);
63 data->setContent(&content[0], content.size());
Junxiao Shi047a6fb2017-06-08 16:16:05 +000064 m_keyChain.sign(*data);
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070065
66 map.insert(std::make_pair(name, data));
67 return data;
68 }
69
Alexander Afanasyev42290b22017-03-09 12:58:29 -080070 std::shared_ptr<ndn::Data>
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070071 getData(const ndn::Name& name)
Shuo Chen9a43f162014-07-01 13:43:54 +080072 {
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070073 if (map.count(name) > 0)
74 return map[name];
75 else
Alexander Afanasyev42290b22017-03-09 12:58:29 -080076 BOOST_THROW_EXCEPTION(Error("Data with name " + name.toUri() + " is not found"));
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070077 }
78
79private:
weijia yuan3aa8d2b2018-03-06 15:35:57 -080080 std::map<Name, std::shared_ptr<Data>> map;
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070081};
82
83
84template<size_t N>
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070085class SamePrefixDataset : public DatasetBase
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070086{
87public:
88 static const std::string&
89 getName()
90 {
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070091 static std::string name = "SamePrefixDataset";
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070092 return name;
93 }
94
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070095 SamePrefixDataset()
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070096 {
97 ndn::Name baseName("/x/y/z/test/1");
98 for (size_t i = 0; i < N; i++) {
99 ndn::Name name(baseName);
100 name.appendSegment(i);
Alexander Afanasyev42290b22017-03-09 12:58:29 -0800101 std::shared_ptr<Data> data = createData(name);
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700102 this->data.push_back(data);
103
104 this->interests.push_back(std::make_pair(Interest(name), data));
105 }
106 }
107};
108
109
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -0700110class BasicDataset : public DatasetBase
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700111{
112public:
113 static const std::string&
114 getName()
115 {
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -0700116 static std::string name = "BasicDataset";
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700117 return name;
118 }
119
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -0700120 BasicDataset()
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700121 {
122 this->data.push_back(createData("/a"));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700123 this->data.push_back(createData("/a/b"));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700124 this->data.push_back(createData("/a/b/c"));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700125 this->data.push_back(createData("/a/b/c/d"));
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -0700126
Alexander Afanasyev595b2bd2014-12-14 12:55:36 -0800127 this->interests.push_back(std::make_pair(Interest("/a"), getData("/a")));
128 this->interests.push_back(std::make_pair(Interest("/a/b"), getData("/a/b")));
129 this->interests.push_back(std::make_pair(Interest("/a/b/c"), getData("/a/b/c")));
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -0700130 this->interests.push_back(std::make_pair(Interest("/a/b/c/d"), getData("/a/b/c/d")));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700131 }
132};
133
Weiqi Shi28a90fb2014-07-09 10:28:55 -0700134//Fetch by prefix is useless due to the database is fetched by id
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -0700135class FetchByPrefixDataset : public DatasetBase
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700136{
137public:
138 static const std::string&
139 getName()
140 {
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -0700141 static std::string name = "FetchByPrefixDataset";
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700142 return name;
143 }
144
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -0700145 FetchByPrefixDataset()
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700146 {
147 this->data.push_back(createData("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z"));
148 this->interests.push_back(std::make_pair(Interest("/a"),
149 this->data.back()));
150 this->interests.push_back(std::make_pair(Interest("/a/b"),
151 this->data.back()));
152 this->interests.push_back(std::make_pair(Interest("/a/b/c"),
153 this->data.back()));
154 this->interests.push_back(std::make_pair(Interest("/a/b/c/d"),
155 this->data.back()));
156 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e"),
157 this->data.back()));
158 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f"),
159 this->data.back()));
160 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g"),
161 this->data.back()));
162 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h"),
163 this->data.back()));
164 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i"),
165 this->data.back()));
166 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j"),
167 this->data.back()));
168 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k"),
169 this->data.back()));
170 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l"),
171 this->data.back()));
172 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m"),
173 this->data.back()));
174 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m/n"),
175 this->data.back()));
176 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o"),
177 this->data.back()));
178 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p"),
179 this->data.back()));
180 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q"),
181 this->data.back()));
182 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r"),
183 this->data.back()));
184 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s"),
185 this->data.back()));
186 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t"),
187 this->data.back()));
188 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u"),
189 this->data.back()));
190 this->interests.push_back(
Weiqi Shi28a90fb2014-07-09 10:28:55 -0700191 std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v"),
192 this->data.back()));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700193 this->interests.push_back(
Weiqi Shi28a90fb2014-07-09 10:28:55 -0700194 std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w"),
195 this->data.back()));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700196 this->interests.push_back(
197 std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x"),
198 this->data.back()));
199 this->interests.push_back(
200 std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y"),
201 this->data.back()));
202 this->interests.push_back(
203 std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z"),
204 this->data.back()));
205 }
206};
207
weijia yuan3aa8d2b2018-03-06 15:35:57 -0800208using CommonDatasets = boost::mpl::vector<BasicDataset,
209 FetchByPrefixDataset,
210 SamePrefixDataset<10>,
211 SamePrefixDataset<100>>;
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700212} // namespace tests
213} // namespace repo
214
215#endif // REPO_TESTS_DATASET_FIXTURES_HPP