Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 9c0bd8d | 2022-03-14 16:48:12 -0400 | [diff] [blame^] | 2 | /* |
| 3 | * Copyright (c) 2014-2022, Regents of the University of California. |
Alexander Afanasyev | e1e6f2a | 2014-04-25 11:28:12 -0700 | [diff] [blame] | 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/>. |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #ifndef REPO_TESTS_DATASET_FIXTURES_HPP |
| 21 | #define REPO_TESTS_DATASET_FIXTURES_HPP |
| 22 | |
Junxiao Shi | 047a6fb | 2017-06-08 16:16:05 +0000 | [diff] [blame] | 23 | #include "identity-management-fixture.hpp" |
Davide Pesavento | 9c0bd8d | 2022-03-14 16:48:12 -0400 | [diff] [blame^] | 24 | |
Wentao Shang | 91fb4f2 | 2014-05-20 10:55:22 -0700 | [diff] [blame] | 25 | #include <vector> |
| 26 | #include <boost/mpl/vector.hpp> |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 27 | |
| 28 | namespace repo { |
| 29 | namespace tests { |
| 30 | |
Junxiao Shi | 047a6fb | 2017-06-08 16:16:05 +0000 | [diff] [blame] | 31 | class DatasetBase : public virtual IdentityManagementFixture |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 32 | { |
| 33 | public: |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 34 | class Error : public std::runtime_error |
| 35 | { |
| 36 | public: |
Davide Pesavento | 9c0bd8d | 2022-03-14 16:48:12 -0400 | [diff] [blame^] | 37 | using std::runtime_error::runtime_error; |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 40 | using DataContainer = std::list<std::shared_ptr<ndn::Data>>; |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 41 | DataContainer data; |
| 42 | |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 43 | using InterestContainer = std::list<std::pair<ndn::Interest, std::shared_ptr<ndn::Data>>>; |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 44 | InterestContainer interests; |
Shuo Chen | 9a43f16 | 2014-07-01 13:43:54 +0800 | [diff] [blame] | 45 | |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 46 | using RemovalsContainer = std::list<std::pair<ndn::Interest, size_t>>; |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 47 | RemovalsContainer removals; |
Weiqi Shi | 28a90fb | 2014-07-09 10:28:55 -0700 | [diff] [blame] | 48 | |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 49 | protected: |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 50 | std::shared_ptr<ndn::Data> |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 51 | createData(const ndn::Name& name) |
Shuo Chen | 9a43f16 | 2014-07-01 13:43:54 +0800 | [diff] [blame] | 52 | { |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 53 | if (map.count(name) > 0) |
| 54 | return map[name]; |
Shuo Chen | 9a43f16 | 2014-07-01 13:43:54 +0800 | [diff] [blame] | 55 | |
Davide Pesavento | 9c0bd8d | 2022-03-14 16:48:12 -0400 | [diff] [blame^] | 56 | static const std::vector<uint8_t> content(1500, '-'); |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 57 | |
Davide Pesavento | 9c0bd8d | 2022-03-14 16:48:12 -0400 | [diff] [blame^] | 58 | auto data = std::make_shared<ndn::Data>(name); |
| 59 | data->setContent(content); |
Junxiao Shi | 047a6fb | 2017-06-08 16:16:05 +0000 | [diff] [blame] | 60 | m_keyChain.sign(*data); |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 61 | |
| 62 | map.insert(std::make_pair(name, data)); |
| 63 | return data; |
| 64 | } |
| 65 | |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 66 | std::shared_ptr<ndn::Data> |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 67 | getData(const ndn::Name& name) |
Shuo Chen | 9a43f16 | 2014-07-01 13:43:54 +0800 | [diff] [blame] | 68 | { |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 69 | if (map.count(name) > 0) |
| 70 | return map[name]; |
| 71 | else |
Davide Pesavento | 9c0bd8d | 2022-03-14 16:48:12 -0400 | [diff] [blame^] | 72 | NDN_THROW(Error("Data with name " + name.toUri() + " is not found")); |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | private: |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 76 | std::map<Name, std::shared_ptr<Data>> map; |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | |
| 80 | template<size_t N> |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 81 | class SamePrefixDataset : public DatasetBase |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 82 | { |
| 83 | public: |
| 84 | static const std::string& |
| 85 | getName() |
| 86 | { |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 87 | static std::string name = "SamePrefixDataset"; |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 88 | return name; |
| 89 | } |
| 90 | |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 91 | SamePrefixDataset() |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 92 | { |
| 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 Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 97 | std::shared_ptr<Data> data = createData(name); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 98 | this->data.push_back(data); |
| 99 | |
| 100 | this->interests.push_back(std::make_pair(Interest(name), data)); |
| 101 | } |
| 102 | } |
| 103 | }; |
| 104 | |
| 105 | |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 106 | class BasicDataset : public DatasetBase |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 107 | { |
| 108 | public: |
| 109 | static const std::string& |
| 110 | getName() |
| 111 | { |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 112 | static std::string name = "BasicDataset"; |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 113 | return name; |
| 114 | } |
| 115 | |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 116 | BasicDataset() |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 117 | { |
| 118 | this->data.push_back(createData("/a")); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 119 | this->data.push_back(createData("/a/b")); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 120 | this->data.push_back(createData("/a/b/c")); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 121 | this->data.push_back(createData("/a/b/c/d")); |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 122 | |
Alexander Afanasyev | 595b2bd | 2014-12-14 12:55:36 -0800 | [diff] [blame] | 123 | 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 Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 126 | this->interests.push_back(std::make_pair(Interest("/a/b/c/d"), getData("/a/b/c/d"))); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 127 | } |
| 128 | }; |
| 129 | |
Weiqi Shi | 28a90fb | 2014-07-09 10:28:55 -0700 | [diff] [blame] | 130 | //Fetch by prefix is useless due to the database is fetched by id |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 131 | class FetchByPrefixDataset : public DatasetBase |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 132 | { |
| 133 | public: |
| 134 | static const std::string& |
| 135 | getName() |
| 136 | { |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 137 | static std::string name = "FetchByPrefixDataset"; |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 138 | return name; |
| 139 | } |
| 140 | |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 141 | FetchByPrefixDataset() |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 142 | { |
| 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 Shi | 28a90fb | 2014-07-09 10:28:55 -0700 | [diff] [blame] | 187 | 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 Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 189 | this->interests.push_back( |
Weiqi Shi | 28a90fb | 2014-07-09 10:28:55 -0700 | [diff] [blame] | 190 | 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 Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 192 | 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 yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 204 | using CommonDatasets = boost::mpl::vector<BasicDataset, |
| 205 | FetchByPrefixDataset, |
| 206 | SamePrefixDataset<10>, |
| 207 | SamePrefixDataset<100>>; |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 208 | } // namespace tests |
| 209 | } // namespace repo |
| 210 | |
| 211 | #endif // REPO_TESTS_DATASET_FIXTURES_HPP |