blob: b3ba1c67b96e1d51622e0172a2a268f8a2d035ee [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/*
Davide Pesaventob5e57652023-09-17 15:18:08 -04003 * Copyright (c) 2014-2023, 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
Davide Pesaventob5e57652023-09-17 15:18:08 -040025#include <list>
26#include <map>
Wentao Shang91fb4f22014-05-20 10:55:22 -070027#include <vector>
Davide Pesaventob5e57652023-09-17 15:18:08 -040028
29#include <boost/mp11/list.hpp>
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070030
Davide Pesavento11904062022-04-14 22:33:28 -040031namespace repo::tests {
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070032
Junxiao Shi047a6fb2017-06-08 16:16:05 +000033class DatasetBase : public virtual IdentityManagementFixture
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070034{
35public:
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070036 class Error : public std::runtime_error
37 {
38 public:
Davide Pesavento9c0bd8d2022-03-14 16:48:12 -040039 using std::runtime_error::runtime_error;
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070040 };
41
Davide Pesavento11904062022-04-14 22:33:28 -040042 std::list<std::shared_ptr<Data>> data;
43 std::list<std::pair<Interest, std::shared_ptr<Data>>> interests;
44 std::list<std::pair<Interest, size_t>> removals;
Weiqi Shi28a90fb2014-07-09 10:28:55 -070045
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070046protected:
Davide Pesavento11904062022-04-14 22:33:28 -040047 std::shared_ptr<Data>
48 createData(const Name& name)
Shuo Chen9a43f162014-07-01 13:43:54 +080049 {
Davide Pesavento11904062022-04-14 22:33:28 -040050 auto it = m_map.find(name);
51 if (it != m_map.end())
52 return it->second;
Shuo Chen9a43f162014-07-01 13:43:54 +080053
Davide Pesavento9c0bd8d2022-03-14 16:48:12 -040054 static const std::vector<uint8_t> content(1500, '-');
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070055
Davide Pesavento11904062022-04-14 22:33:28 -040056 auto data = std::make_shared<Data>(name);
Davide Pesavento9c0bd8d2022-03-14 16:48:12 -040057 data->setContent(content);
Junxiao Shi047a6fb2017-06-08 16:16:05 +000058 m_keyChain.sign(*data);
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070059
Davide Pesavento11904062022-04-14 22:33:28 -040060 m_map.emplace(name, data);
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070061 return data;
62 }
63
Davide Pesavento11904062022-04-14 22:33:28 -040064 std::shared_ptr<Data>
65 getData(const Name& name) const
Shuo Chen9a43f162014-07-01 13:43:54 +080066 {
Davide Pesavento11904062022-04-14 22:33:28 -040067 auto it = m_map.find(name);
68 if (it != m_map.end())
69 return it->second;
70
71 NDN_THROW(Error("Data with name " + name.toUri() + " not found"));
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070072 }
73
74private:
Davide Pesavento11904062022-04-14 22:33:28 -040075 std::map<Name, std::shared_ptr<Data>> m_map;
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070076};
77
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070078template<size_t N>
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070079class SamePrefixDataset : public DatasetBase
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070080{
81public:
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070082 SamePrefixDataset()
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070083 {
Davide Pesavento11904062022-04-14 22:33:28 -040084 const Name baseName("/x/y/z/test/1");
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070085 for (size_t i = 0; i < N; i++) {
Davide Pesavento11904062022-04-14 22:33:28 -040086 Name name(baseName);
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070087 name.appendSegment(i);
Davide Pesavento11904062022-04-14 22:33:28 -040088 auto data = createData(name);
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070089 this->data.push_back(data);
Davide Pesavento11904062022-04-14 22:33:28 -040090 this->interests.emplace_back(Interest(name), data);
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070091 }
92 }
93};
94
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070095class BasicDataset : public DatasetBase
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070096{
97public:
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070098 BasicDataset()
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070099 {
100 this->data.push_back(createData("/a"));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700101 this->data.push_back(createData("/a/b"));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700102 this->data.push_back(createData("/a/b/c"));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700103 this->data.push_back(createData("/a/b/c/d"));
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -0700104
Davide Pesavento11904062022-04-14 22:33:28 -0400105 this->interests.emplace_back(Interest("/a"), getData("/a"));
106 this->interests.emplace_back(Interest("/a/b"), getData("/a/b"));
107 this->interests.emplace_back(Interest("/a/b/c"), getData("/a/b/c"));
108 this->interests.emplace_back(Interest("/a/b/c/d"), getData("/a/b/c/d"));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700109 }
110};
111
Weiqi Shi28a90fb2014-07-09 10:28:55 -0700112//Fetch by prefix is useless due to the database is fetched by id
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -0700113class FetchByPrefixDataset : public DatasetBase
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700114{
115public:
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -0700116 FetchByPrefixDataset()
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700117 {
118 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"));
119 this->interests.push_back(std::make_pair(Interest("/a"),
120 this->data.back()));
121 this->interests.push_back(std::make_pair(Interest("/a/b"),
122 this->data.back()));
123 this->interests.push_back(std::make_pair(Interest("/a/b/c"),
124 this->data.back()));
125 this->interests.push_back(std::make_pair(Interest("/a/b/c/d"),
126 this->data.back()));
127 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e"),
128 this->data.back()));
129 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f"),
130 this->data.back()));
131 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g"),
132 this->data.back()));
133 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h"),
134 this->data.back()));
135 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i"),
136 this->data.back()));
137 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j"),
138 this->data.back()));
139 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k"),
140 this->data.back()));
141 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l"),
142 this->data.back()));
143 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m"),
144 this->data.back()));
145 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m/n"),
146 this->data.back()));
147 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o"),
148 this->data.back()));
149 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p"),
150 this->data.back()));
151 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"),
152 this->data.back()));
153 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"),
154 this->data.back()));
155 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"),
156 this->data.back()));
157 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"),
158 this->data.back()));
159 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"),
160 this->data.back()));
161 this->interests.push_back(
Weiqi Shi28a90fb2014-07-09 10:28:55 -0700162 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"),
163 this->data.back()));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700164 this->interests.push_back(
Weiqi Shi28a90fb2014-07-09 10:28:55 -0700165 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"),
166 this->data.back()));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700167 this->interests.push_back(
168 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"),
169 this->data.back()));
170 this->interests.push_back(
171 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"),
172 this->data.back()));
173 this->interests.push_back(
174 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"),
175 this->data.back()));
176 }
177};
178
Davide Pesaventob5e57652023-09-17 15:18:08 -0400179using CommonDatasets = boost::mp11::mp_list<BasicDataset,
180 FetchByPrefixDataset,
181 SamePrefixDataset<10>,
182 SamePrefixDataset<100>>;
183
Davide Pesavento11904062022-04-14 22:33:28 -0400184} // namespace repo::tests
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700185
186#endif // REPO_TESTS_DATASET_FIXTURES_HPP