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 | |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 28 | namespace repo::tests { |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 29 | |
Junxiao Shi | 047a6fb | 2017-06-08 16:16:05 +0000 | [diff] [blame] | 30 | class DatasetBase : public virtual IdentityManagementFixture |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 31 | { |
| 32 | public: |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 33 | class Error : public std::runtime_error |
| 34 | { |
| 35 | public: |
Davide Pesavento | 9c0bd8d | 2022-03-14 16:48:12 -0400 | [diff] [blame] | 36 | using std::runtime_error::runtime_error; |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 37 | }; |
| 38 | |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 39 | 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 Shi | 28a90fb | 2014-07-09 10:28:55 -0700 | [diff] [blame] | 42 | |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 43 | protected: |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 44 | std::shared_ptr<Data> |
| 45 | createData(const Name& name) |
Shuo Chen | 9a43f16 | 2014-07-01 13:43:54 +0800 | [diff] [blame] | 46 | { |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 47 | auto it = m_map.find(name); |
| 48 | if (it != m_map.end()) |
| 49 | return it->second; |
Shuo Chen | 9a43f16 | 2014-07-01 13:43:54 +0800 | [diff] [blame] | 50 | |
Davide Pesavento | 9c0bd8d | 2022-03-14 16:48:12 -0400 | [diff] [blame] | 51 | static const std::vector<uint8_t> content(1500, '-'); |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 52 | |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 53 | auto data = std::make_shared<Data>(name); |
Davide Pesavento | 9c0bd8d | 2022-03-14 16:48:12 -0400 | [diff] [blame] | 54 | data->setContent(content); |
Junxiao Shi | 047a6fb | 2017-06-08 16:16:05 +0000 | [diff] [blame] | 55 | m_keyChain.sign(*data); |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 56 | |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 57 | m_map.emplace(name, data); |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 58 | return data; |
| 59 | } |
| 60 | |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 61 | std::shared_ptr<Data> |
| 62 | getData(const Name& name) const |
Shuo Chen | 9a43f16 | 2014-07-01 13:43:54 +0800 | [diff] [blame] | 63 | { |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 64 | 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 Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | private: |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 72 | std::map<Name, std::shared_ptr<Data>> m_map; |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 75 | template<size_t N> |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 76 | class SamePrefixDataset : public DatasetBase |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 77 | { |
| 78 | public: |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 79 | SamePrefixDataset() |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 80 | { |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 81 | const Name baseName("/x/y/z/test/1"); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 82 | for (size_t i = 0; i < N; i++) { |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 83 | Name name(baseName); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 84 | name.appendSegment(i); |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 85 | auto data = createData(name); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 86 | this->data.push_back(data); |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 87 | this->interests.emplace_back(Interest(name), data); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | }; |
| 91 | |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 92 | class BasicDataset : public DatasetBase |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 93 | { |
| 94 | public: |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 95 | BasicDataset() |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 96 | { |
| 97 | this->data.push_back(createData("/a")); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 98 | this->data.push_back(createData("/a/b")); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 99 | this->data.push_back(createData("/a/b/c")); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 100 | this->data.push_back(createData("/a/b/c/d")); |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 101 | |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 102 | 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 Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 106 | } |
| 107 | }; |
| 108 | |
Weiqi Shi | 28a90fb | 2014-07-09 10:28:55 -0700 | [diff] [blame] | 109 | //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] | 110 | class FetchByPrefixDataset : public DatasetBase |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 111 | { |
| 112 | public: |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 113 | FetchByPrefixDataset() |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 114 | { |
| 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 Shi | 28a90fb | 2014-07-09 10:28:55 -0700 | [diff] [blame] | 159 | 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 Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 161 | this->interests.push_back( |
Weiqi Shi | 28a90fb | 2014-07-09 10:28:55 -0700 | [diff] [blame] | 162 | 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 Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 164 | 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 yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 176 | using CommonDatasets = boost::mpl::vector<BasicDataset, |
| 177 | FetchByPrefixDataset, |
| 178 | SamePrefixDataset<10>, |
| 179 | SamePrefixDataset<100>>; |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 180 | } // namespace repo::tests |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 181 | |
| 182 | #endif // REPO_TESTS_DATASET_FIXTURES_HPP |