blob: 3cc2685ce3b5a9418c911d69cd7be86281f6e5e1 [file] [log] [blame]
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyeve1e6f2a2014-04-25 11:28:12 -07003 * Copyright (c) 2014, Regents of the University of California.
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 Afanasyevb0c78ea2014-04-15 18:12:04 -070018 */
19
20#ifndef REPO_TESTS_DATASET_FIXTURES_HPP
21#define REPO_TESTS_DATASET_FIXTURES_HPP
22
Alexander Afanasyeve291caf2014-04-25 11:17:36 -070023#include <ndn-cxx/security/key-chain.hpp>
Wentao Shang91fb4f22014-05-20 10:55:22 -070024#include <vector>
25#include <boost/mpl/vector.hpp>
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070026
27namespace repo {
28namespace tests {
29
30static inline ndn::shared_ptr<ndn::Data>
31createData(const ndn::Name& name)
32{
33 static ndn::KeyChain keyChain;
34 static std::vector<uint8_t> content(1500, '-');
35
36 ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>();
37 data->setName(name);
38 data->setContent(&content[0], content.size());
39 keyChain.sign(*data);
40
41 return data;
42}
43
44
45class DatasetBase
46{
47public:
48 typedef std::list<ndn::shared_ptr<ndn::Data> > DataContainer;
49 DataContainer data;
50
51 typedef std::list<std::pair<ndn::Interest, ndn::shared_ptr<ndn::Data> > > InterestContainer;
52 InterestContainer interests;
Shuo Chen9a43f162014-07-01 13:43:54 +080053
54
55 struct DataSetNameCompare
56 {
57 bool operator()(const ndn::Name& a, const ndn::Name& b) const
58 {
59 return a < b;
60 }
61 };
62
63 struct DataSetDataCompare
64 {
65 bool operator()(const Data& a, const Data& b) const
66 {
67 return a.getName() < b.getName();
68 }
69 };
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070070};
71
72
73template<size_t N>
74class BaseSmoketestFixture : public DatasetBase
75{
76public:
77 static const std::string&
78 getName()
79 {
80 static std::string name = "BaseSmoketest";
81 return name;
82 }
83
84 BaseSmoketestFixture()
85 {
86 ndn::Name baseName("/x/y/z/test/1");
87 for (size_t i = 0; i < N; i++) {
88 ndn::Name name(baseName);
89 name.appendSegment(i);
90 ndn::shared_ptr<Data> data = createData(name);
91 this->data.push_back(data);
92
93 this->interests.push_back(std::make_pair(Interest(name), data));
94 }
95 }
96};
97
98
99class BaseTestFixture : public DatasetBase
100{
101public:
102 static const std::string&
103 getName()
104 {
105 static std::string name = "BaseTest";
106 return name;
107 }
108
109 BaseTestFixture()
110 {
111 this->data.push_back(createData("/a"));
112 this->interests.push_back(std::make_pair(Interest("/a"), this->data.back()));
113
114 this->data.push_back(createData("/a/b"));
115 this->interests.push_back(std::make_pair(Interest("/a/b"), this->data.back()));
116
117 this->data.push_back(createData("/a/b/c"));
118 this->interests.push_back(std::make_pair(Interest("/a/b/c"), this->data.back()));
119
120 this->data.push_back(createData("/a/b/c/d"));
121 this->interests.push_back(std::make_pair(Interest("/a/b/c/d"), this->data.back()));
122 }
123};
124
125
126class FetchByPrefixTestFixture : public DatasetBase
127{
128public:
129 static const std::string&
130 getName()
131 {
132 static std::string name = "FetchByPrefix";
133 return name;
134 }
135
136 FetchByPrefixTestFixture()
137 {
138 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"));
139 this->interests.push_back(std::make_pair(Interest("/a"),
140 this->data.back()));
141 this->interests.push_back(std::make_pair(Interest("/a/b"),
142 this->data.back()));
143 this->interests.push_back(std::make_pair(Interest("/a/b/c"),
144 this->data.back()));
145 this->interests.push_back(std::make_pair(Interest("/a/b/c/d"),
146 this->data.back()));
147 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e"),
148 this->data.back()));
149 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f"),
150 this->data.back()));
151 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g"),
152 this->data.back()));
153 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h"),
154 this->data.back()));
155 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i"),
156 this->data.back()));
157 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j"),
158 this->data.back()));
159 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k"),
160 this->data.back()));
161 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l"),
162 this->data.back()));
163 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m"),
164 this->data.back()));
165 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m/n"),
166 this->data.back()));
167 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o"),
168 this->data.back()));
169 this->interests.push_back(std::make_pair(Interest("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p"),
170 this->data.back()));
171 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"),
172 this->data.back()));
173 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"),
174 this->data.back()));
175 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"),
176 this->data.back()));
177 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"),
178 this->data.back()));
179 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"),
180 this->data.back()));
181 this->interests.push_back(
182 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"),
183 this->data.back()));
184 this->interests.push_back(
185 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"),
186 this->data.back()));
187 this->interests.push_back(
188 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"),
189 this->data.back()));
190 this->interests.push_back(
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/w/x/y"),
192 this->data.back()));
193 this->interests.push_back(
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/x/y/z"),
195 this->data.back()));
196 }
197};
198
199
200class SelectorTestFixture : public DatasetBase
201{
202public:
203 static const std::string&
204 getName()
205 {
206 static std::string name = "SelectorTest";
207 return name;
208 }
209
210 SelectorTestFixture()
211 {
212 this->data.push_back(createData("/a/1"));
213 this->data.push_back(createData("/b/1"));
214 this->interests.push_back(std::make_pair(Interest()
215 .setName("/b")
216 .setSelectors(Selectors()
217 .setChildSelector(0)),
218 this->data.back()));
219
220 this->data.push_back(createData("/c/1"));
221 this->data.push_back(createData("/b/99"));
222 this->interests.push_back(std::make_pair(Interest()
223 .setName("/b")
224 .setSelectors(Selectors()
225 .setChildSelector(1)),
226 this->data.back()));
227 this->data.push_back(createData("/b/5"));
228 this->data.push_back(createData("/b/55"));
229 }
230};
231
232
233typedef boost::mpl::vector< BaseTestFixture,
234 FetchByPrefixTestFixture,
235 SelectorTestFixture,
236 BaseSmoketestFixture<1>,
237 BaseSmoketestFixture<100> > DatasetFixtures;
238
239} // namespace tests
240} // namespace repo
241
242#endif // REPO_TESTS_DATASET_FIXTURES_HPP