blob: 77866a013149770d2826d12e7df32047250566e4 [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
Davide Pesavento11904062022-04-14 22:33:28 -040028namespace repo::tests {
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070029
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:
Davide Pesavento9c0bd8d2022-03-14 16:48:12 -040036 using std::runtime_error::runtime_error;
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070037 };
38
Davide Pesavento11904062022-04-14 22:33:28 -040039 std::list<std::shared_ptr<Data>> data;
40 std::list<std::pair<Interest, std::shared_ptr<Data>>> interests;
41 std::list<std::pair<Interest, size_t>> removals;
Weiqi Shi28a90fb2014-07-09 10:28:55 -070042
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070043protected:
Davide Pesavento11904062022-04-14 22:33:28 -040044 std::shared_ptr<Data>
45 createData(const Name& name)
Shuo Chen9a43f162014-07-01 13:43:54 +080046 {
Davide Pesavento11904062022-04-14 22:33:28 -040047 auto it = m_map.find(name);
48 if (it != m_map.end())
49 return it->second;
Shuo Chen9a43f162014-07-01 13:43:54 +080050
Davide Pesavento9c0bd8d2022-03-14 16:48:12 -040051 static const std::vector<uint8_t> content(1500, '-');
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070052
Davide Pesavento11904062022-04-14 22:33:28 -040053 auto data = std::make_shared<Data>(name);
Davide Pesavento9c0bd8d2022-03-14 16:48:12 -040054 data->setContent(content);
Junxiao Shi047a6fb2017-06-08 16:16:05 +000055 m_keyChain.sign(*data);
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070056
Davide Pesavento11904062022-04-14 22:33:28 -040057 m_map.emplace(name, data);
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070058 return data;
59 }
60
Davide Pesavento11904062022-04-14 22:33:28 -040061 std::shared_ptr<Data>
62 getData(const Name& name) const
Shuo Chen9a43f162014-07-01 13:43:54 +080063 {
Davide Pesavento11904062022-04-14 22:33:28 -040064 auto it = m_map.find(name);
65 if (it != m_map.end())
66 return it->second;
67
68 NDN_THROW(Error("Data with name " + name.toUri() + " not found"));
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070069 }
70
71private:
Davide Pesavento11904062022-04-14 22:33:28 -040072 std::map<Name, std::shared_ptr<Data>> m_map;
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070073};
74
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070075template<size_t N>
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070076class SamePrefixDataset : public DatasetBase
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070077{
78public:
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070079 SamePrefixDataset()
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070080 {
Davide Pesavento11904062022-04-14 22:33:28 -040081 const Name baseName("/x/y/z/test/1");
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070082 for (size_t i = 0; i < N; i++) {
Davide Pesavento11904062022-04-14 22:33:28 -040083 Name name(baseName);
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070084 name.appendSegment(i);
Davide Pesavento11904062022-04-14 22:33:28 -040085 auto data = createData(name);
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070086 this->data.push_back(data);
Davide Pesavento11904062022-04-14 22:33:28 -040087 this->interests.emplace_back(Interest(name), data);
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070088 }
89 }
90};
91
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070092class BasicDataset : public DatasetBase
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070093{
94public:
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -070095 BasicDataset()
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070096 {
97 this->data.push_back(createData("/a"));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070098 this->data.push_back(createData("/a/b"));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070099 this->data.push_back(createData("/a/b/c"));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700100 this->data.push_back(createData("/a/b/c/d"));
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -0700101
Davide Pesavento11904062022-04-14 22:33:28 -0400102 this->interests.emplace_back(Interest("/a"), getData("/a"));
103 this->interests.emplace_back(Interest("/a/b"), getData("/a/b"));
104 this->interests.emplace_back(Interest("/a/b/c"), getData("/a/b/c"));
105 this->interests.emplace_back(Interest("/a/b/c/d"), getData("/a/b/c/d"));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700106 }
107};
108
Weiqi Shi28a90fb2014-07-09 10:28:55 -0700109//Fetch by prefix is useless due to the database is fetched by id
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -0700110class FetchByPrefixDataset : public DatasetBase
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700111{
112public:
Alexander Afanasyevb7e8a812014-07-23 01:36:47 -0700113 FetchByPrefixDataset()
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700114 {
115 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"));
116 this->interests.push_back(std::make_pair(Interest("/a"),
117 this->data.back()));
118 this->interests.push_back(std::make_pair(Interest("/a/b"),
119 this->data.back()));
120 this->interests.push_back(std::make_pair(Interest("/a/b/c"),
121 this->data.back()));
122 this->interests.push_back(std::make_pair(Interest("/a/b/c/d"),
123 this->data.back()));
124 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e"),
125 this->data.back()));
126 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f"),
127 this->data.back()));
128 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g"),
129 this->data.back()));
130 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h"),
131 this->data.back()));
132 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i"),
133 this->data.back()));
134 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j"),
135 this->data.back()));
136 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k"),
137 this->data.back()));
138 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l"),
139 this->data.back()));
140 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m"),
141 this->data.back()));
142 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m/n"),
143 this->data.back()));
144 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o"),
145 this->data.back()));
146 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p"),
147 this->data.back()));
148 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"),
149 this->data.back()));
150 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"),
151 this->data.back()));
152 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"),
153 this->data.back()));
154 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"),
155 this->data.back()));
156 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"),
157 this->data.back()));
158 this->interests.push_back(
Weiqi Shi28a90fb2014-07-09 10:28:55 -0700159 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"),
160 this->data.back()));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700161 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/w"),
163 this->data.back()));
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700164 this->interests.push_back(
165 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"),
166 this->data.back()));
167 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/y"),
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/z"),
172 this->data.back()));
173 }
174};
175
weijia yuan3aa8d2b2018-03-06 15:35:57 -0800176using CommonDatasets = boost::mpl::vector<BasicDataset,
177 FetchByPrefixDataset,
178 SamePrefixDataset<10>,
179 SamePrefixDataset<100>>;
Davide Pesavento11904062022-04-14 22:33:28 -0400180} // namespace repo::tests
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700181
182#endif // REPO_TESTS_DATASET_FIXTURES_HPP