Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, 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" |
Wentao Shang | 91fb4f2 | 2014-05-20 10:55:22 -0700 | [diff] [blame] | 24 | #include <vector> |
| 25 | #include <boost/mpl/vector.hpp> |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 26 | |
| 27 | namespace repo { |
| 28 | namespace tests { |
| 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: |
| 36 | explicit |
| 37 | Error(const std::string& what) |
| 38 | : std::runtime_error(what) |
| 39 | { |
| 40 | } |
| 41 | }; |
| 42 | |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 43 | using DataContainer = std::list<std::shared_ptr<ndn::Data>>; |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 44 | DataContainer data; |
| 45 | |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 46 | 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] | 47 | InterestContainer interests; |
Shuo Chen | 9a43f16 | 2014-07-01 13:43:54 +0800 | [diff] [blame] | 48 | |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 49 | using RemovalsContainer = std::list<std::pair<ndn::Interest, size_t>>; |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 50 | RemovalsContainer removals; |
Weiqi Shi | 28a90fb | 2014-07-09 10:28:55 -0700 | [diff] [blame] | 51 | |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 52 | protected: |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 53 | std::shared_ptr<ndn::Data> |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 54 | createData(const ndn::Name& name) |
Shuo Chen | 9a43f16 | 2014-07-01 13:43:54 +0800 | [diff] [blame] | 55 | { |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 56 | if (map.count(name) > 0) |
| 57 | return map[name]; |
Shuo Chen | 9a43f16 | 2014-07-01 13:43:54 +0800 | [diff] [blame] | 58 | |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 59 | static std::vector<uint8_t> content(1500, '-'); |
| 60 | |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 61 | std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>(); |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 62 | data->setName(name); |
| 63 | data->setContent(&content[0], content.size()); |
Junxiao Shi | 047a6fb | 2017-06-08 16:16:05 +0000 | [diff] [blame] | 64 | m_keyChain.sign(*data); |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 65 | |
| 66 | map.insert(std::make_pair(name, data)); |
| 67 | return data; |
| 68 | } |
| 69 | |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 70 | std::shared_ptr<ndn::Data> |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 71 | getData(const ndn::Name& name) |
Shuo Chen | 9a43f16 | 2014-07-01 13:43:54 +0800 | [diff] [blame] | 72 | { |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 73 | if (map.count(name) > 0) |
| 74 | return map[name]; |
| 75 | else |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 76 | BOOST_THROW_EXCEPTION(Error("Data with name " + name.toUri() + " is not found")); |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | private: |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 80 | std::map<Name, std::shared_ptr<Data>> map; |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | |
| 84 | template<size_t N> |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 85 | class SamePrefixDataset : public DatasetBase |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 86 | { |
| 87 | public: |
| 88 | static const std::string& |
| 89 | getName() |
| 90 | { |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 91 | static std::string name = "SamePrefixDataset"; |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 92 | return name; |
| 93 | } |
| 94 | |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 95 | SamePrefixDataset() |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 96 | { |
| 97 | ndn::Name baseName("/x/y/z/test/1"); |
| 98 | for (size_t i = 0; i < N; i++) { |
| 99 | ndn::Name name(baseName); |
| 100 | name.appendSegment(i); |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 101 | std::shared_ptr<Data> data = createData(name); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 102 | this->data.push_back(data); |
| 103 | |
| 104 | this->interests.push_back(std::make_pair(Interest(name), data)); |
| 105 | } |
| 106 | } |
| 107 | }; |
| 108 | |
| 109 | |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 110 | class BasicDataset : public DatasetBase |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 111 | { |
| 112 | public: |
| 113 | static const std::string& |
| 114 | getName() |
| 115 | { |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 116 | static std::string name = "BasicDataset"; |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 117 | return name; |
| 118 | } |
| 119 | |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 120 | BasicDataset() |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 121 | { |
| 122 | this->data.push_back(createData("/a")); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 123 | this->data.push_back(createData("/a/b")); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 124 | this->data.push_back(createData("/a/b/c")); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 125 | this->data.push_back(createData("/a/b/c/d")); |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 126 | |
Alexander Afanasyev | 595b2bd | 2014-12-14 12:55:36 -0800 | [diff] [blame] | 127 | this->interests.push_back(std::make_pair(Interest("/a"), getData("/a"))); |
| 128 | this->interests.push_back(std::make_pair(Interest("/a/b"), getData("/a/b"))); |
| 129 | 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] | 130 | 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] | 131 | } |
| 132 | }; |
| 133 | |
Weiqi Shi | 28a90fb | 2014-07-09 10:28:55 -0700 | [diff] [blame] | 134 | //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] | 135 | class FetchByPrefixDataset : public DatasetBase |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 136 | { |
| 137 | public: |
| 138 | static const std::string& |
| 139 | getName() |
| 140 | { |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 141 | static std::string name = "FetchByPrefixDataset"; |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 142 | return name; |
| 143 | } |
| 144 | |
Alexander Afanasyev | b7e8a81 | 2014-07-23 01:36:47 -0700 | [diff] [blame] | 145 | FetchByPrefixDataset() |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 146 | { |
| 147 | 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")); |
| 148 | this->interests.push_back(std::make_pair(Interest("/a"), |
| 149 | this->data.back())); |
| 150 | this->interests.push_back(std::make_pair(Interest("/a/b"), |
| 151 | this->data.back())); |
| 152 | this->interests.push_back(std::make_pair(Interest("/a/b/c"), |
| 153 | this->data.back())); |
| 154 | this->interests.push_back(std::make_pair(Interest("/a/b/c/d"), |
| 155 | this->data.back())); |
| 156 | this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e"), |
| 157 | this->data.back())); |
| 158 | this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f"), |
| 159 | this->data.back())); |
| 160 | this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g"), |
| 161 | this->data.back())); |
| 162 | this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h"), |
| 163 | this->data.back())); |
| 164 | this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i"), |
| 165 | this->data.back())); |
| 166 | this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j"), |
| 167 | this->data.back())); |
| 168 | this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k"), |
| 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"), |
| 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"), |
| 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"), |
| 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"), |
| 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"), |
| 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"), |
| 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"), |
| 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"), |
| 185 | this->data.back())); |
| 186 | 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"), |
| 187 | this->data.back())); |
| 188 | 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"), |
| 189 | this->data.back())); |
| 190 | this->interests.push_back( |
Weiqi Shi | 28a90fb | 2014-07-09 10:28:55 -0700 | [diff] [blame] | 191 | 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"), |
| 192 | this->data.back())); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 193 | this->interests.push_back( |
Weiqi Shi | 28a90fb | 2014-07-09 10:28:55 -0700 | [diff] [blame] | 194 | 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"), |
| 195 | this->data.back())); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 196 | this->interests.push_back( |
| 197 | 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"), |
| 198 | this->data.back())); |
| 199 | this->interests.push_back( |
| 200 | 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"), |
| 201 | this->data.back())); |
| 202 | this->interests.push_back( |
| 203 | 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"), |
| 204 | this->data.back())); |
| 205 | } |
| 206 | }; |
| 207 | |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 208 | using CommonDatasets = boost::mpl::vector<BasicDataset, |
| 209 | FetchByPrefixDataset, |
| 210 | SamePrefixDataset<10>, |
| 211 | SamePrefixDataset<100>>; |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 212 | } // namespace tests |
| 213 | } // namespace repo |
| 214 | |
| 215 | #endif // REPO_TESTS_DATASET_FIXTURES_HPP |