blob: 00537d210ab7e4e588c10c30bf1ca7b49a31e2c4 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi71ff2312017-07-12 13:32:50 +00002/*
Davide Pesaventoe78eeca2017-02-23 23:22:32 -05003 * Copyright (c) 2013-2017 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080020 */
21
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080022#include "name.hpp"
23
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070024#include "boost-test.hpp"
Yingdi Yu90e23582014-11-06 14:21:04 -080025#include <unordered_map>
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070026
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080027namespace ndn {
Junxiao Shi6bf0adf2015-02-15 13:54:56 -070028namespace tests {
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080029
30BOOST_AUTO_TEST_SUITE(TestName)
31
32static const uint8_t TestName[] = {
Alexander Afanasyev4b456282014-02-13 00:34:34 -080033 0x7, 0x14, // Name
34 0x8, 0x5, // NameComponent
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080035 0x6c, 0x6f, 0x63, 0x61, 0x6c,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080036 0x8, 0x3, // NameComponent
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080037 0x6e, 0x64, 0x6e,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080038 0x8, 0x6, // NameComponent
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080039 0x70, 0x72, 0x65, 0x66, 0x69, 0x78
40};
41
Alexander Afanasyev4b456282014-02-13 00:34:34 -080042const uint8_t Name1[] = {0x7, 0x7, // Name
43 0x8, 0x5, // NameComponent
44 0x6c, 0x6f, 0x63, 0x61, 0x6c};
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070045
Alexander Afanasyev4b456282014-02-13 00:34:34 -080046const uint8_t Name2[] = {0x7, 0xc, // Name
47 0x8, 0x5, // NameComponent
48 0x6c, 0x6f, 0x63, 0x61, 0x6c,
49 0x8, 0x3, // NameComponent
50 0x6e, 0x64, 0x6e};
51
Junxiao Shi71ff2312017-07-12 13:32:50 +000052// ---- encoding, decoding ----
53
Alexander Afanasyevc2344292014-03-02 00:08:00 +000054BOOST_AUTO_TEST_CASE(Basic)
55{
56 Name name("/hello/world");
57
58 BOOST_CHECK_NO_THROW(name.at(0));
59 BOOST_CHECK_NO_THROW(name.at(1));
60 BOOST_CHECK_NO_THROW(name.at(-1));
61 BOOST_CHECK_NO_THROW(name.at(-2));
62
63 BOOST_CHECK_THROW(name.at(2), Name::Error);
64 BOOST_CHECK_THROW(name.at(-3), Name::Error);
65}
66
67BOOST_AUTO_TEST_CASE(Encode)
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080068{
69 Name name("/local/ndn/prefix");
Davide Pesaventoe78eeca2017-02-23 23:22:32 -050070 const Block& wire = name.wireEncode();
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080071
Davide Pesaventoe78eeca2017-02-23 23:22:32 -050072 // for (auto i = wire.begin(); i != wire.end(); ++i) {
73 // if (i != wire.begin())
74 // std::cout << ", ";
75 // printHex(std::cout, *i);
76 // }
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080077 // std::cout << std::endl;
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070078
Davide Pesaventoe78eeca2017-02-23 23:22:32 -050079 BOOST_CHECK_EQUAL_COLLECTIONS(TestName, TestName + sizeof(TestName),
Alexander Afanasyev29e5c3d2014-02-11 00:01:10 -080080 wire.begin(), wire.end());
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080081}
82
Alexander Afanasyevc2344292014-03-02 00:08:00 +000083BOOST_AUTO_TEST_CASE(Decode)
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080084{
85 Block block(TestName, sizeof(TestName));
86
87 Name name(block);
88
89 BOOST_CHECK_EQUAL(name.toUri(), "/local/ndn/prefix");
90}
91
Junxiao Shi2586be42015-01-30 20:13:01 -070092BOOST_AUTO_TEST_CASE(ZeroLengthComponent)
93{
94 static const uint8_t compOctets[] {0x08, 0x00};
95 Block compBlock(compOctets, sizeof(compOctets));
96 name::Component comp;
97 BOOST_REQUIRE_NO_THROW(comp.wireDecode(compBlock));
98 BOOST_CHECK_EQUAL(comp.value_size(), 0);
99
100 static const uint8_t nameOctets[] {0x07, 0x08, 0x08, 0x01, 0x41, 0x08, 0x00, 0x08, 0x01, 0x42};
101 Block nameBlock(nameOctets, sizeof(nameOctets));
102 static const std::string nameUri("/A/.../B");
103 Name name;
104 BOOST_REQUIRE_NO_THROW(name.wireDecode(nameBlock));
105 BOOST_CHECK_EQUAL(name.toUri(), nameUri);
106 Block nameEncoded = name.wireEncode();
107 BOOST_CHECK(nameEncoded == nameBlock);
108
109 Name name2;
Alexander Afanasyev66ca2032015-12-04 13:17:02 -0800110 BOOST_REQUIRE_NO_THROW(name2 = Name(nameUri));
Alexander Afanasyevd7eacc72015-04-03 13:06:26 -0700111 BOOST_CHECK_EQUAL(name2.toUri(), nameUri);
Junxiao Shi2586be42015-01-30 20:13:01 -0700112 Block name2Encoded = name2.wireEncode();
113 BOOST_CHECK(name2Encoded == nameBlock);
114}
115
Junxiao Shi6bf0adf2015-02-15 13:54:56 -0700116BOOST_AUTO_TEST_CASE(ImplicitSha256Digest)
Alexander Afanasyev6486d522014-10-23 14:14:11 -0700117{
118 Name n;
119
Junxiao Shi6bf0adf2015-02-15 13:54:56 -0700120 static const uint8_t DIGEST[] = {0x28, 0xba, 0xd4, 0xb5, 0x27, 0x5b, 0xd3, 0x92,
121 0xdb, 0xb6, 0x70, 0xc7, 0x5c, 0xf0, 0xb6, 0x6f,
122 0x13, 0xf7, 0x94, 0x2b, 0x21, 0xe8, 0x0f, 0x55,
123 0xc0, 0xe8, 0x6b, 0x37, 0x47, 0x53, 0xa5, 0x48,
124 0x00, 0x00};
Alexander Afanasyev6486d522014-10-23 14:14:11 -0700125
126 BOOST_REQUIRE_NO_THROW(n.appendImplicitSha256Digest(DIGEST, 32));
127 BOOST_REQUIRE_NO_THROW(n.appendImplicitSha256Digest(make_shared<Buffer>(DIGEST, 32)));
128 BOOST_CHECK_EQUAL(n.get(0), n.get(1));
129
130 BOOST_REQUIRE_THROW(n.appendImplicitSha256Digest(DIGEST, 34), name::Component::Error);
131 BOOST_REQUIRE_THROW(n.appendImplicitSha256Digest(DIGEST, 30), name::Component::Error);
132
133 n.append(DIGEST, 32);
134 BOOST_CHECK_LT(n.get(0), n.get(2));
135 BOOST_CHECK_EQUAL_COLLECTIONS(n.get(0).value_begin(), n.get(0).value_end(),
136 n.get(2).value_begin(), n.get(2).value_end());
137
138 n.append(DIGEST + 1, 32);
139 BOOST_CHECK_LT(n.get(0), n.get(3));
140
141 n.append(DIGEST + 2, 32);
142 BOOST_CHECK_LT(n.get(0), n.get(4));
143
144 BOOST_CHECK_EQUAL(n.get(0).toUri(), "sha256digest="
145 "28bad4b5275bd392dbb670c75cf0b66f13f7942b21e80f55c0e86b374753a548");
146
147 BOOST_CHECK_EQUAL(n.get(0).isImplicitSha256Digest(), true);
148 BOOST_CHECK_EQUAL(n.get(2).isImplicitSha256Digest(), false);
149
150 BOOST_CHECK_THROW(Name("/hello/sha256digest=hmm"), name::Component::Error);
151
152 Name n2;
153 // check canonical URI encoding (lower case)
154 BOOST_CHECK_NO_THROW(n2 = Name("/hello/sha256digest="
155 "28bad4b5275bd392dbb670c75cf0b66f13f7942b21e80f55c0e86b374753a548"));
156 BOOST_CHECK_EQUAL(n.get(0), n2.get(1));
157
158 // will accept hex value in upper case too
159 BOOST_CHECK_NO_THROW(n2 = Name("/hello/sha256digest="
160 "28BAD4B5275BD392DBB670C75CF0B66F13F7942B21E80F55C0E86B374753A548"));
161 BOOST_CHECK_EQUAL(n.get(0), n2.get(1));
162
163 // this is not valid sha256digest component, will be treated as generic component
164 BOOST_CHECK_NO_THROW(n2 = Name("/hello/SHA256DIGEST="
165 "28BAD4B5275BD392DBB670C75CF0B66F13F7942B21E80F55C0E86B374753A548"));
166 BOOST_CHECK_NE(n.get(0), n2.get(1));
Junxiao Shi6bf0adf2015-02-15 13:54:56 -0700167 BOOST_CHECK(n2.get(1).isGeneric());
Alexander Afanasyev6486d522014-10-23 14:14:11 -0700168}
169
Alexander Afanasyevd7eacc72015-04-03 13:06:26 -0700170BOOST_AUTO_TEST_CASE(NameWithSpaces)
171{
172 Name name("/ hello\t/\tworld \r\n");
173
174 BOOST_CHECK_EQUAL("/hello/world", name);
175 BOOST_CHECK_THROW(Name("/hello//world"), name::Component::Error);
176}
177
Junxiao Shi71ff2312017-07-12 13:32:50 +0000178BOOST_AUTO_TEST_CASE(DeepCopy)
179{
180 Name n1("/hello/world");
181 Name n2 = n1.deepCopy();
182
183 BOOST_CHECK_EQUAL(n1, n2);
184 BOOST_CHECK_NE(&n1.wireEncode(), &n2.wireEncode());
185
186 EncodingBuffer buffer(1024, 0);
187 n1.wireEncode(buffer);
188 Name n3(buffer.block());
189
190 BOOST_CHECK_EQUAL(n1, n3);
191 BOOST_CHECK_EQUAL(n3.wireEncode().getBuffer()->size(), 1024);
192 n3 = n3.deepCopy();
193
194 BOOST_CHECK_LT(n3.wireEncode().size(), 1024);
195 BOOST_CHECK_EQUAL(n3.wireEncode().getBuffer()->size(), n3.wireEncode().size());
196}
197
198// ---- iterators ----
199
200BOOST_AUTO_TEST_CASE(ForwardIterator)
201{
202 name::Component comps[] {
203 name::Component("A"),
204 name::Component("B"),
205 name::Component("C"),
206 name::Component("D")
207 };
208
209 Name n0;
210 BOOST_CHECK_EQUAL_COLLECTIONS(n0.begin(), n0.end(), comps, comps + 0);
211
212 Name n4("/A/B/C/D");
213 BOOST_CHECK_EQUAL_COLLECTIONS(n4.begin(), n4.end(), comps, comps + 4);
214}
215
216BOOST_AUTO_TEST_CASE(ReverseIterator)
217{
218 name::Component comps[] {
219 name::Component("D"),
220 name::Component("C"),
221 name::Component("B"),
222 name::Component("A")
223 };
224
225 Name n0;
226 BOOST_CHECK_EQUAL_COLLECTIONS(n0.rbegin(), n0.rend(), comps, comps + 0);
227
228 Name n4("/A/B/C/D");
229 BOOST_CHECK_EQUAL_COLLECTIONS(n4.rbegin(), n4.rend(), comps, comps + 4);
230}
231
232// ---- modifiers ----
233
Joao Pereira6f7cfd02015-06-15 11:36:26 -0400234BOOST_AUTO_TEST_CASE(Append)
235{
236 PartialName toAppend("/and");
237 PartialName toAppend1("/beyond");
238 {
239 Name name("/hello/world");
240 BOOST_CHECK_EQUAL("/hello/world/hello/world", name.append(name));
241 BOOST_CHECK_EQUAL("/hello/world/hello/world", name);
242 }
243 {
244 Name name("/hello/world");
245 BOOST_CHECK_EQUAL("/hello/world/and", name.append(toAppend));
246 }
247 {
248 Name name("/hello/world");
249 BOOST_CHECK_EQUAL("/hello/world/and/beyond", name.append(toAppend).append(toAppend1));
250 }
Ashlesh Gawande7dffab62017-12-21 16:40:53 -0600251
252 {
253 std::vector<uint8_t> vec{1, 1, 2, 3};
254 Name name("/hello");
255 BOOST_CHECK_EQUAL("/hello/%01%01%02%03", name.append(vec.begin(), vec.end()));
256 }
Joao Pereira6f7cfd02015-06-15 11:36:26 -0400257}
258
Junxiao Shi71ff2312017-07-12 13:32:50 +0000259BOOST_AUTO_TEST_CASE(AppendsAndMultiEncode)
260{
261 Name name("/local");
262 BOOST_CHECK_EQUAL_COLLECTIONS(name.wireEncode().begin(), name.wireEncode().end(),
263 Name1, Name1 + sizeof(Name1));
264
265 name.append("ndn");
266 BOOST_CHECK_EQUAL_COLLECTIONS(name.wireEncode().begin(), name.wireEncode().end(),
267 Name2, Name2 + sizeof(Name2));
268
269 name.append("prefix");
270 BOOST_CHECK_EQUAL_COLLECTIONS(name.wireEncode().begin(), name.wireEncode().end(),
271 TestName, TestName+sizeof(TestName));
272}
273
274BOOST_AUTO_TEST_CASE(AppendNumber)
275{
276 Name name;
277 for (uint32_t i = 0; i < 10; i++) {
278 name.appendNumber(i);
279 }
280
281 BOOST_CHECK_EQUAL(name.size(), 10);
282
283 for (uint32_t i = 0; i < 10; i++) {
284 BOOST_CHECK_EQUAL(name[i].toNumber(), i);
285 }
286}
287
288BOOST_AUTO_TEST_CASE(Markers)
289{
290 // TestNameComponent/NamingConvention provides additional coverage for these methods,
291 // including verifications of the wire format.
292
293 Name name;
294 uint64_t number;
295
296 BOOST_REQUIRE_NO_THROW(number = name.appendSegment(30923).at(-1).toSegment());
297 BOOST_CHECK_EQUAL(number, 30923);
298
299 BOOST_REQUIRE_NO_THROW(number = name.appendSegmentOffset(589).at(-1).toSegmentOffset());
300 BOOST_CHECK_EQUAL(number, 589);
301
302 BOOST_REQUIRE_NO_THROW(number = name.appendVersion().at(-1).toVersion());
303
304 BOOST_REQUIRE_NO_THROW(number = name.appendVersion(25912).at(-1).toVersion());
305 BOOST_CHECK_EQUAL(number, 25912);
306
307 const time::system_clock::TimePoint tp = time::system_clock::now();
308 time::system_clock::TimePoint tp2;
309 BOOST_REQUIRE_NO_THROW(tp2 = name.appendTimestamp(tp).at(-1).toTimestamp());
310 BOOST_CHECK_LE(std::abs(time::duration_cast<time::microseconds>(tp2 - tp).count()), 1);
311
312 BOOST_REQUIRE_NO_THROW(number = name.appendSequenceNumber(11676).at(-1).toSequenceNumber());
313 BOOST_CHECK_EQUAL(number, 11676);
314}
315
316BOOST_AUTO_TEST_CASE(Clear)
317{
318 Name n("/A");
319 BOOST_CHECK_EQUAL(n.empty(), false);
320
321 n.clear();
322 BOOST_CHECK_EQUAL(n.empty(), true);
323 BOOST_CHECK_EQUAL(n.size(), 0);
324}
325
326// ---- algorithms ----
327
328BOOST_AUTO_TEST_CASE(GetSuccessor)
329{
330 BOOST_CHECK_EQUAL(Name("ndn:/%00%01/%01%02").getSuccessor(), Name("ndn:/%00%01/%01%03"));
331 BOOST_CHECK_EQUAL(Name("ndn:/%00%01/%01%FF").getSuccessor(), Name("ndn:/%00%01/%02%00"));
332 BOOST_CHECK_EQUAL(Name("ndn:/%00%01/%FF%FF").getSuccessor(), Name("ndn:/%00%01/%00%00%00"));
333 BOOST_CHECK_EQUAL(Name().getSuccessor(), Name("ndn:/%00"));
334}
335
336BOOST_AUTO_TEST_CASE(Compare)
337{
338 BOOST_CHECK_EQUAL(Name("/A") .compare(Name("/A")), 0);
339 BOOST_CHECK_LT (Name("/A") .compare(Name("/B")), 0);
340 BOOST_CHECK_GT (Name("/B") .compare(Name("/A")), 0);
341 BOOST_CHECK_LT (Name("/A") .compare(Name("/AA")), 0);
342 BOOST_CHECK_GT (Name("/AA") .compare(Name("/A")), 0);
343 BOOST_CHECK_LT (Name("/A") .compare(Name("/A/C")), 0);
344 BOOST_CHECK_GT (Name("/A/C").compare(Name("/A")), 0);
345
346 BOOST_CHECK_EQUAL(Name("/Z/A/Y") .compare(1, 1, Name("/A")), 0);
347 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/B")), 0);
348 BOOST_CHECK_GT (Name("/Z/B/Y") .compare(1, 1, Name("/A")), 0);
349 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/AA")), 0);
350 BOOST_CHECK_GT (Name("/Z/AA/Y") .compare(1, 1, Name("/A")), 0);
351 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/A/C")), 0);
352 BOOST_CHECK_GT (Name("/Z/A/C/Y").compare(1, 2, Name("/A")), 0);
353
354 BOOST_CHECK_EQUAL(Name("/Z/A") .compare(1, Name::npos, Name("/A")), 0);
355 BOOST_CHECK_LT (Name("/Z/A") .compare(1, Name::npos, Name("/B")), 0);
356 BOOST_CHECK_GT (Name("/Z/B") .compare(1, Name::npos, Name("/A")), 0);
357 BOOST_CHECK_LT (Name("/Z/A") .compare(1, Name::npos, Name("/AA")), 0);
358 BOOST_CHECK_GT (Name("/Z/AA") .compare(1, Name::npos, Name("/A")), 0);
359 BOOST_CHECK_LT (Name("/Z/A") .compare(1, Name::npos, Name("/A/C")), 0);
360 BOOST_CHECK_GT (Name("/Z/A/C").compare(1, Name::npos, Name("/A")), 0);
361
362 BOOST_CHECK_EQUAL(Name("/Z/A/Y") .compare(1, 1, Name("/X/A/W"), 1, 1), 0);
363 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/B/W"), 1, 1), 0);
364 BOOST_CHECK_GT (Name("/Z/B/Y") .compare(1, 1, Name("/X/A/W"), 1, 1), 0);
365 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/AA/W"), 1, 1), 0);
366 BOOST_CHECK_GT (Name("/Z/AA/Y") .compare(1, 1, Name("/X/A/W"), 1, 1), 0);
367 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/A/C/W"), 1, 2), 0);
368 BOOST_CHECK_GT (Name("/Z/A/C/Y").compare(1, 2, Name("/X/A/W"), 1, 1), 0);
369
370 BOOST_CHECK_EQUAL(Name("/Z/A/Y") .compare(1, 1, Name("/X/A"), 1), 0);
371 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/B"), 1), 0);
372 BOOST_CHECK_GT (Name("/Z/B/Y") .compare(1, 1, Name("/X/A"), 1), 0);
373 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/AA"), 1), 0);
374 BOOST_CHECK_GT (Name("/Z/AA/Y") .compare(1, 1, Name("/X/A"), 1), 0);
375 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/A/C"), 1), 0);
376 BOOST_CHECK_GT (Name("/Z/A/C/Y").compare(1, 2, Name("/X/A"), 1), 0);
377}
378
Joao Pereira6f7cfd02015-06-15 11:36:26 -0400379BOOST_AUTO_TEST_CASE(SubName)
380{
381 Name name("/hello/world");
382
383 BOOST_CHECK_EQUAL("/hello/world", name.getSubName(0));
384 BOOST_CHECK_EQUAL("/world", name.getSubName(1));
385 BOOST_CHECK_EQUAL("/hello/", name.getSubName(0, 1));
386}
387
388BOOST_AUTO_TEST_CASE(SubNameNegativeIndex)
389{
390 Name name("/first/second/third/last");
391
392 BOOST_CHECK_EQUAL("/last", name.getSubName(-1));
393 BOOST_CHECK_EQUAL("/third/last", name.getSubName(-2));
394 BOOST_CHECK_EQUAL("/second", name.getSubName(-3, 1));
395}
396
397BOOST_AUTO_TEST_CASE(SubNameOutOfRangeIndexes)
398{
399 Name name("/first/second/last");
400 // No length
401 BOOST_CHECK_EQUAL("/first/second/last", name.getSubName(-10));
402 BOOST_CHECK_EQUAL("/", name.getSubName(10));
403
404 // Starting after the max position
405 BOOST_CHECK_EQUAL("/", name.getSubName(10, 1));
406 BOOST_CHECK_EQUAL("/", name.getSubName(10, 10));
407
408 // Not enough components
409 BOOST_CHECK_EQUAL("/second/last", name.getSubName(1, 10));
410 BOOST_CHECK_EQUAL("/last", name.getSubName(-1, 10));
411
412 // Start before first
413 BOOST_CHECK_EQUAL("/first/second", name.getSubName(-10, 2));
414 BOOST_CHECK_EQUAL("/first/second/last", name.getSubName(-10, 10));
415}
Alexander Afanasyevd7eacc72015-04-03 13:06:26 -0700416
Junxiao Shi71ff2312017-07-12 13:32:50 +0000417BOOST_AUTO_TEST_CASE(UnorderedMap)
Alexander Afanasyev4f512fb2016-05-18 10:47:53 -0700418{
Junxiao Shi71ff2312017-07-12 13:32:50 +0000419 std::unordered_map<Name, int> map;
420 Name name1("/1");
421 Name name2("/2");
422 Name name3("/3");
423 map[name1] = 1;
424 map[name2] = 2;
425 map[name3] = 3;
Alexander Afanasyev4f512fb2016-05-18 10:47:53 -0700426
Junxiao Shi71ff2312017-07-12 13:32:50 +0000427 BOOST_CHECK_EQUAL(map[name1], 1);
428 BOOST_CHECK_EQUAL(map[name2], 2);
429 BOOST_CHECK_EQUAL(map[name3], 3);
Alexander Afanasyev4f512fb2016-05-18 10:47:53 -0700430}
431
Davide Pesaventoeee3e822016-11-26 19:19:34 +0100432BOOST_AUTO_TEST_SUITE_END() // TestName
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -0800433
Junxiao Shi6bf0adf2015-02-15 13:54:56 -0700434} // namespace tests
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -0800435} // namespace ndn