blob: 0d933473a26ff46efc46f102cc9ab24f5b0e3197 [file] [log] [blame]
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento9c0bd8d2022-03-14 16:48:12 -04002/*
3 * Copyright (c) 2014-2022, 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"
Davide Pesavento9c0bd8d2022-03-14 16:48:12 -040024
Wentao Shang91fb4f22014-05-20 10:55:22 -070025#include <vector>
26#include <boost/mpl/vector.hpp>
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070027
28namespace repo {
29namespace tests {
30
Junxiao Shi047a6fb2017-06-08 16:16:05 +000031class DatasetBase : public virtual IdentityManagementFixture
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070032{
33public:
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070034 class Error : public std::runtime_error
35 {
36 public:
Davide Pesavento9c0bd8d2022-03-14 16:48:12 -040037 using std::runtime_error::runtime_error;
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070038 };
39
weijia yuan3aa8d2b2018-03-06 15:35:57 -080040 using DataContainer = std::list<std::shared_ptr<ndn::Data>>;
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070041 DataContainer data;
42
weijia yuan3aa8d2b2018-03-06 15:35:57 -080043 using InterestContainer = std::list<std::pair<ndn::Interest, std::shared_ptr<ndn::Data>>>;
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070044 InterestContainer interests;
Shuo Chen9a43f162014-07-01 13:43:54 +080045
weijia yuan3aa8d2b2018-03-06 15:35:57 -080046 using RemovalsContainer = std::list<std::pair<ndn::Interest, size_t>>;
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070047 RemovalsContainer removals;
Weiqi Shi28a90fb2014-07-09 10:28:55 -070048
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070049protected:
Alexander Afanasyev42290b22017-03-09 12:58:29 -080050 std::shared_ptr<ndn::Data>
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070051 createData(const ndn::Name& name)
Shuo Chen9a43f162014-07-01 13:43:54 +080052 {
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070053 if (map.count(name) > 0)
54 return map[name];
Shuo Chen9a43f162014-07-01 13:43:54 +080055
Davide Pesavento9c0bd8d2022-03-14 16:48:12 -040056 static const std::vector<uint8_t> content(1500, '-');
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070057
Davide Pesavento9c0bd8d2022-03-14 16:48:12 -040058 auto data = std::make_shared<ndn::Data>(name);
59 data->setContent(content);
Junxiao Shi047a6fb2017-06-08 16:16:05 +000060 m_keyChain.sign(*data);
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070061
62 map.insert(std::make_pair(name, data));
63 return data;
64 }
65
Alexander Afanasyev42290b22017-03-09 12:58:29 -080066 std::shared_ptr<ndn::Data>
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070067 getData(const ndn::Name& name)
Shuo Chen9a43f162014-07-01 13:43:54 +080068 {
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070069 if (map.count(name) > 0)
70 return map[name];
71 else
Davide Pesavento9c0bd8d2022-03-14 16:48:12 -040072 NDN_THROW(Error("Data with name " + name.toUri() + " is not found"));
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070073 }
74
75private:
weijia yuan3aa8d2b2018-03-06 15:35:57 -080076 std::map<Name, std::shared_ptr<Data>> map;
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070077};
78
79
80template<size_t N>
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070081class SamePrefixDataset : public DatasetBase
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070082{
83public:
84 static const std::string&
85 getName()
86 {
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070087 static std::string name = "SamePrefixDataset";
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070088 return name;
89 }
90
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070091 SamePrefixDataset()
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070092 {
93 ndn::Name baseName("/x/y/z/test/1");
94 for (size_t i = 0; i < N; i++) {
95 ndn::Name name(baseName);
96 name.appendSegment(i);
Alexander Afanasyev42290b22017-03-09 12:58:29 -080097 std::shared_ptr<Data> data = createData(name);
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070098 this->data.push_back(data);
99
100 this->interests.push_back(std::make_pair(Interest(name), data));
101 }
102 }
103};
104
105
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -0700106class BasicDataset : public DatasetBase
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700107{
108public:
109 static const std::string&
110 getName()
111 {
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -0700112 static std::string name = "BasicDataset";
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700113 return name;
114 }
115
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -0700116 BasicDataset()
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700117 {
118 this->data.push_back(createData("/a"));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700119 this->data.push_back(createData("/a/b"));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700120 this->data.push_back(createData("/a/b/c"));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700121 this->data.push_back(createData("/a/b/c/d"));
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -0700122
Alexander Afanasyev595b2bd2014-12-14 12:55:36 -0800123 this->interests.push_back(std::make_pair(Interest("/a"), getData("/a")));
124 this->interests.push_back(std::make_pair(Interest("/a/b"), getData("/a/b")));
125 this->interests.push_back(std::make_pair(Interest("/a/b/c"), getData("/a/b/c")));
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -0700126 this->interests.push_back(std::make_pair(Interest("/a/b/c/d"), getData("/a/b/c/d")));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700127 }
128};
129
Weiqi Shi28a90fb2014-07-09 10:28:55 -0700130//Fetch by prefix is useless due to the database is fetched by id
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -0700131class FetchByPrefixDataset : public DatasetBase
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700132{
133public:
134 static const std::string&
135 getName()
136 {
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -0700137 static std::string name = "FetchByPrefixDataset";
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700138 return name;
139 }
140
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -0700141 FetchByPrefixDataset()
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700142 {
143 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"));
144 this->interests.push_back(std::make_pair(Interest("/a"),
145 this->data.back()));
146 this->interests.push_back(std::make_pair(Interest("/a/b"),
147 this->data.back()));
148 this->interests.push_back(std::make_pair(Interest("/a/b/c"),
149 this->data.back()));
150 this->interests.push_back(std::make_pair(Interest("/a/b/c/d"),
151 this->data.back()));
152 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e"),
153 this->data.back()));
154 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f"),
155 this->data.back()));
156 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g"),
157 this->data.back()));
158 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h"),
159 this->data.back()));
160 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i"),
161 this->data.back()));
162 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j"),
163 this->data.back()));
164 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k"),
165 this->data.back()));
166 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l"),
167 this->data.back()));
168 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m"),
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/m/n"),
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/n/o"),
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/o/p"),
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/p/q"),
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/q/r"),
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/r/s"),
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/s/t"),
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/t/u"),
185 this->data.back()));
186 this->interests.push_back(
Weiqi Shi28a90fb2014-07-09 10:28:55 -0700187 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"),
188 this->data.back()));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700189 this->interests.push_back(
Weiqi Shi28a90fb2014-07-09 10:28:55 -0700190 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"),
191 this->data.back()));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700192 this->interests.push_back(
193 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"),
194 this->data.back()));
195 this->interests.push_back(
196 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"),
197 this->data.back()));
198 this->interests.push_back(
199 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"),
200 this->data.back()));
201 }
202};
203
weijia yuan3aa8d2b2018-03-06 15:35:57 -0800204using CommonDatasets = boost::mpl::vector<BasicDataset,
205 FetchByPrefixDataset,
206 SamePrefixDataset<10>,
207 SamePrefixDataset<100>>;
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700208} // namespace tests
209} // namespace repo
210
211#endif // REPO_TESTS_DATASET_FIXTURES_HPP