blob: c934be196c4596b28cdabc53bef0ba033e4a3fb4 [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/*
Junxiao Shicf4ac5b2018-03-28 22:46:06 +00003 * Copyright (c) 2013-2018 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
Junxiao Shia36f15d2018-04-04 02:22:11 +000024#include "block-literal.hpp"
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070025#include "boost-test.hpp"
Yingdi Yu90e23582014-11-06 14:21:04 -080026#include <unordered_map>
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070027
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080028namespace ndn {
Junxiao Shi6bf0adf2015-02-15 13:54:56 -070029namespace tests {
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080030
Junxiao Shia36f15d2018-04-04 02:22:11 +000031using Component = name::Component;
32
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080033BOOST_AUTO_TEST_SUITE(TestName)
34
Junxiao Shia36f15d2018-04-04 02:22:11 +000035// ---- encoding, decoding, and URI ----
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080036
Junxiao Shia36f15d2018-04-04 02:22:11 +000037BOOST_AUTO_TEST_CASE(EncodeDecode)
Alexander Afanasyevc2344292014-03-02 00:08:00 +000038{
Junxiao Shia36f15d2018-04-04 02:22:11 +000039 std::string uri = "/Emid/25042=P3/.../..../%1C%9F/"
40 "sha256digest=0415e3624a151850ac686c84f155f29808c0dd73819aa4a4c20be73a4d8a874c";
41 Name name(uri);
42 BOOST_CHECK_EQUAL(name.size(), 6);
43 BOOST_CHECK_EQUAL(name[0], Component("Emid"));
44 BOOST_CHECK_EQUAL(name[1], Component("FD61D2025033"_block));
45 BOOST_CHECK_EQUAL(name[2], Component(""));
46 BOOST_CHECK_EQUAL(name[3], Component("."));
47 BOOST_CHECK_EQUAL(name[4], Component("\x1C\x9F"));
48 BOOST_CHECK(name[5].isImplicitSha256Digest());
Alexander Afanasyevc2344292014-03-02 00:08:00 +000049
Junxiao Shia36f15d2018-04-04 02:22:11 +000050 Block wire = name.wireEncode();
51 BOOST_CHECK(wire == "0737 0804456D6964 FD61D2025033 0800 08012E 08021C9F "
52 "01200415E3624A151850AC686C84F155F29808C0DD73819AA4A4C20BE73A4D8A874C"_block);
Alexander Afanasyevc2344292014-03-02 00:08:00 +000053
Junxiao Shia36f15d2018-04-04 02:22:11 +000054 Name decoded(wire);
55 BOOST_CHECK_EQUAL(decoded, name);
Alexander Afanasyev6486d522014-10-23 14:14:11 -070056}
57
Junxiao Shi9c9672e2018-04-18 12:55:08 +000058BOOST_AUTO_TEST_CASE(ParseUri)
Alexander Afanasyevd7eacc72015-04-03 13:06:26 -070059{
Junxiao Shi9c9672e2018-04-18 12:55:08 +000060 // URI with correct scheme
61 BOOST_CHECK_EQUAL(Name("ndn:/hello/world").toUri(), "/hello/world");
Alexander Afanasyevd7eacc72015-04-03 13:06:26 -070062
Junxiao Shi9c9672e2018-04-18 12:55:08 +000063 // URI with incorrect scheme: auto-corrected
64 BOOST_CHECK_EQUAL(Name("ncc:/hello/world").toUri(), "/hello/world");
65
66 // URI with authority: authority ignored
67 BOOST_CHECK_EQUAL(Name("//authority/hello/world").toUri(), "/hello/world");
68 BOOST_CHECK_EQUAL(Name("ndn://authority/hello/world").toUri(), "/hello/world");
69
70 // URI containing unescaped characters: auto-corrected
71 BOOST_CHECK_EQUAL(Name("/ hello\t/\tworld \r\n").toUri(), "/%20hello%09/%09world%20%0D%0A");
72 BOOST_CHECK_EQUAL(Name("/hello/world/ ").toUri(), "/hello/world/%20%20");
73 BOOST_CHECK_EQUAL(Name("/:?#[]@").toUri(), "/%3A%3F%23%5B%5D%40");
74
75 // URI not starting with '/': accepted as PartialName
76 BOOST_CHECK_EQUAL(Name("").toUri(), "/");
77 BOOST_CHECK_EQUAL(Name(" ").toUri(), "/%20");
78 BOOST_CHECK_EQUAL(Name(" /hello/world").toUri(), "/%20%20/hello/world");
79 BOOST_CHECK_EQUAL(Name("hello/world").toUri(), "/hello/world");
80
81 // URI ending with '/': auto-corrected
82 BOOST_CHECK_EQUAL(Name("/hello/world/").toUri(), "/hello/world");
83
84 // URI containing bad component: rejected
Alexander Afanasyevd7eacc72015-04-03 13:06:26 -070085 BOOST_CHECK_THROW(Name("/hello//world"), name::Component::Error);
Junxiao Shi9c9672e2018-04-18 12:55:08 +000086 BOOST_CHECK_THROW(Name("/hello/./world"), name::Component::Error);
87 BOOST_CHECK_THROW(Name("/hello/../world"), name::Component::Error);
Alexander Afanasyevd7eacc72015-04-03 13:06:26 -070088}
89
Junxiao Shi71ff2312017-07-12 13:32:50 +000090BOOST_AUTO_TEST_CASE(DeepCopy)
91{
92 Name n1("/hello/world");
93 Name n2 = n1.deepCopy();
94
95 BOOST_CHECK_EQUAL(n1, n2);
96 BOOST_CHECK_NE(&n1.wireEncode(), &n2.wireEncode());
97
98 EncodingBuffer buffer(1024, 0);
99 n1.wireEncode(buffer);
100 Name n3(buffer.block());
101
102 BOOST_CHECK_EQUAL(n1, n3);
103 BOOST_CHECK_EQUAL(n3.wireEncode().getBuffer()->size(), 1024);
104 n3 = n3.deepCopy();
105
106 BOOST_CHECK_LT(n3.wireEncode().size(), 1024);
107 BOOST_CHECK_EQUAL(n3.wireEncode().getBuffer()->size(), n3.wireEncode().size());
108}
109
Junxiao Shia36f15d2018-04-04 02:22:11 +0000110// ---- access ----
111
112BOOST_AUTO_TEST_CASE(At)
113{
114 Name name("/hello/5=NDN");
115
116 BOOST_CHECK_EQUAL(name.at(0), name::Component("080568656C6C6F"_block));
117 BOOST_CHECK_EQUAL(name.at(1), name::Component("05034E444E"_block));
118 BOOST_CHECK_EQUAL(name.at(-1), name::Component("05034E444E"_block));
119 BOOST_CHECK_EQUAL(name.at(-2), name::Component("080568656C6C6F"_block));
120
121 BOOST_CHECK_THROW(name.at(2), Name::Error);
122 BOOST_CHECK_THROW(name.at(-3), Name::Error);
123}
124
125BOOST_AUTO_TEST_CASE(SubName)
126{
127 Name name("/hello/world");
128
129 BOOST_CHECK_EQUAL("/hello/world", name.getSubName(0));
130 BOOST_CHECK_EQUAL("/world", name.getSubName(1));
Junxiao Shi9c9672e2018-04-18 12:55:08 +0000131 BOOST_CHECK_EQUAL("/hello", name.getSubName(0, 1));
Junxiao Shia36f15d2018-04-04 02:22:11 +0000132}
133
134BOOST_AUTO_TEST_CASE(SubNameNegativeIndex)
135{
136 Name name("/first/second/third/last");
137
138 BOOST_CHECK_EQUAL("/last", name.getSubName(-1));
139 BOOST_CHECK_EQUAL("/third/last", name.getSubName(-2));
140 BOOST_CHECK_EQUAL("/second", name.getSubName(-3, 1));
141}
142
143BOOST_AUTO_TEST_CASE(SubNameOutOfRangeIndexes)
144{
145 Name name("/first/second/last");
146 // No length
147 BOOST_CHECK_EQUAL("/first/second/last", name.getSubName(-10));
148 BOOST_CHECK_EQUAL("/", name.getSubName(10));
149
150 // Starting after the max position
151 BOOST_CHECK_EQUAL("/", name.getSubName(10, 1));
152 BOOST_CHECK_EQUAL("/", name.getSubName(10, 10));
153
154 // Not enough components
155 BOOST_CHECK_EQUAL("/second/last", name.getSubName(1, 10));
156 BOOST_CHECK_EQUAL("/last", name.getSubName(-1, 10));
157
158 // Start before first
159 BOOST_CHECK_EQUAL("/first/second", name.getSubName(-10, 2));
160 BOOST_CHECK_EQUAL("/first/second/last", name.getSubName(-10, 10));
161}
162
Junxiao Shi71ff2312017-07-12 13:32:50 +0000163// ---- iterators ----
164
165BOOST_AUTO_TEST_CASE(ForwardIterator)
166{
167 name::Component comps[] {
168 name::Component("A"),
169 name::Component("B"),
170 name::Component("C"),
171 name::Component("D")
172 };
173
174 Name n0;
175 BOOST_CHECK_EQUAL_COLLECTIONS(n0.begin(), n0.end(), comps, comps + 0);
176
177 Name n4("/A/B/C/D");
178 BOOST_CHECK_EQUAL_COLLECTIONS(n4.begin(), n4.end(), comps, comps + 4);
179}
180
181BOOST_AUTO_TEST_CASE(ReverseIterator)
182{
183 name::Component comps[] {
184 name::Component("D"),
185 name::Component("C"),
186 name::Component("B"),
187 name::Component("A")
188 };
189
190 Name n0;
191 BOOST_CHECK_EQUAL_COLLECTIONS(n0.rbegin(), n0.rend(), comps, comps + 0);
192
193 Name n4("/A/B/C/D");
194 BOOST_CHECK_EQUAL_COLLECTIONS(n4.rbegin(), n4.rend(), comps, comps + 4);
195}
196
197// ---- modifiers ----
198
Junxiao Shia36f15d2018-04-04 02:22:11 +0000199BOOST_AUTO_TEST_CASE(AppendComponent)
Joao Pereira6f7cfd02015-06-15 11:36:26 -0400200{
Junxiao Shia36f15d2018-04-04 02:22:11 +0000201 Name name;
202 BOOST_CHECK(name.wireEncode() == "0700"_block);
Ashlesh Gawande7dffab62017-12-21 16:40:53 -0600203
Junxiao Shia36f15d2018-04-04 02:22:11 +0000204 name.append(Component("Emid"));
205 BOOST_CHECK(name.wireEncode() == "0706 0804456D6964"_block);
206
207 name.append(25042, reinterpret_cast<const uint8_t*>("P3"), 2);
208 BOOST_CHECK(name.wireEncode() == "070C 0804456D6964 FD61D2025033"_block);
209
210 name.append(reinterpret_cast<const uint8_t*>("."), 1);
211 BOOST_CHECK(name.wireEncode() == "070F 0804456D6964 FD61D2025033 08012E"_block);
212
213 std::vector<uint8_t> v1{0x28, 0xF0, 0xA3, 0x6B};
214 name.append(16, v1.begin(), v1.end());
215 BOOST_CHECK(name.wireEncode() == "0715 0804456D6964 FD61D2025033 08012E 100428F0A36B"_block);
216
217 BOOST_CHECK(!name.empty());
218 name.clear();
219 BOOST_CHECK(name.empty());
220 BOOST_CHECK(name.wireEncode() == "0700"_block);
221
222 name.append(v1.begin(), v1.end());
223 BOOST_CHECK(name.wireEncode() == "0706 080428F0A36B"_block);
224
225 name.append("xKh");
226 BOOST_CHECK(name.wireEncode() == "070B 080428F0A36B 0803784B68"_block);
227
228 name.append("0100"_block);
229 BOOST_CHECK(name.wireEncode() == "070F 080428F0A36B 0803784B68 08020100"_block);
230
231 name.append("080109"_block);
232 BOOST_CHECK(name.wireEncode() == "0712 080428F0A36B 0803784B68 08020100 080109"_block);
Joao Pereira6f7cfd02015-06-15 11:36:26 -0400233}
234
Junxiao Shia36f15d2018-04-04 02:22:11 +0000235BOOST_AUTO_TEST_CASE(AppendPartialName)
Junxiao Shi71ff2312017-07-12 13:32:50 +0000236{
Junxiao Shia36f15d2018-04-04 02:22:11 +0000237 Name name("/A/B");
238 name.append(PartialName("/6=C/D"))
239 .append(PartialName("/E"));
240 BOOST_CHECK(name.wireEncode() == "070F 080141 080142 060143 080144 080145"_block);
Junxiao Shi71ff2312017-07-12 13:32:50 +0000241}
242
243BOOST_AUTO_TEST_CASE(AppendNumber)
244{
245 Name name;
246 for (uint32_t i = 0; i < 10; i++) {
247 name.appendNumber(i);
248 }
Junxiao Shi71ff2312017-07-12 13:32:50 +0000249 BOOST_CHECK_EQUAL(name.size(), 10);
250
251 for (uint32_t i = 0; i < 10; i++) {
252 BOOST_CHECK_EQUAL(name[i].toNumber(), i);
253 }
254}
255
256BOOST_AUTO_TEST_CASE(Markers)
257{
258 // TestNameComponent/NamingConvention provides additional coverage for these methods,
259 // including verifications of the wire format.
260
261 Name name;
262 uint64_t number;
263
264 BOOST_REQUIRE_NO_THROW(number = name.appendSegment(30923).at(-1).toSegment());
265 BOOST_CHECK_EQUAL(number, 30923);
266
267 BOOST_REQUIRE_NO_THROW(number = name.appendSegmentOffset(589).at(-1).toSegmentOffset());
268 BOOST_CHECK_EQUAL(number, 589);
269
270 BOOST_REQUIRE_NO_THROW(number = name.appendVersion().at(-1).toVersion());
271
272 BOOST_REQUIRE_NO_THROW(number = name.appendVersion(25912).at(-1).toVersion());
273 BOOST_CHECK_EQUAL(number, 25912);
274
275 const time::system_clock::TimePoint tp = time::system_clock::now();
276 time::system_clock::TimePoint tp2;
277 BOOST_REQUIRE_NO_THROW(tp2 = name.appendTimestamp(tp).at(-1).toTimestamp());
278 BOOST_CHECK_LE(std::abs(time::duration_cast<time::microseconds>(tp2 - tp).count()), 1);
279
280 BOOST_REQUIRE_NO_THROW(number = name.appendSequenceNumber(11676).at(-1).toSequenceNumber());
281 BOOST_CHECK_EQUAL(number, 11676);
282}
283
Junxiao Shi71ff2312017-07-12 13:32:50 +0000284// ---- algorithms ----
285
286BOOST_AUTO_TEST_CASE(GetSuccessor)
287{
Junxiao Shia36f15d2018-04-04 02:22:11 +0000288 BOOST_CHECK_EQUAL(Name("/%00%01/%01%02").getSuccessor(), Name("/%00%01/%01%03"));
289 BOOST_CHECK_EQUAL(Name("/%00%01/%01%FF").getSuccessor(), Name("/%00%01/%02%00"));
290 BOOST_CHECK_EQUAL(Name("/%00%01/%FF%FF").getSuccessor(), Name("/%00%01/%00%00%00"));
291 BOOST_CHECK_EQUAL(Name().getSuccessor(), Name("/%00"));
Junxiao Shi71ff2312017-07-12 13:32:50 +0000292}
293
Junxiao Shia36f15d2018-04-04 02:22:11 +0000294BOOST_AUTO_TEST_CASE(IsPrefixOf)
295{
296 BOOST_CHECK(Name("/").isPrefixOf("/"));
297 BOOST_CHECK(Name("/").isPrefixOf("/sha256digest=0000000000000000000000000000000000000000000000000000000000000000"));
298 BOOST_CHECK(Name("/").isPrefixOf("/2=D"));
299 BOOST_CHECK(Name("/").isPrefixOf("/F"));
300 BOOST_CHECK(Name("/").isPrefixOf("/21426=AA"));
301
302 BOOST_CHECK(Name("/B").isPrefixOf("/B"));
303 BOOST_CHECK(Name("/B").isPrefixOf("/B/sha256digest=0000000000000000000000000000000000000000000000000000000000000000"));
304 BOOST_CHECK(Name("/B").isPrefixOf("/B/2=D"));
305 BOOST_CHECK(Name("/B").isPrefixOf("/B/F"));
306 BOOST_CHECK(Name("/B").isPrefixOf("/B/21426=AA"));
307
308 BOOST_CHECK(!Name("/C").isPrefixOf("/"));
309 BOOST_CHECK(!Name("/C").isPrefixOf("/sha256digest=0000000000000000000000000000000000000000000000000000000000000000"));
310 BOOST_CHECK(!Name("/C").isPrefixOf("/2=D"));
311 BOOST_CHECK(!Name("/C").isPrefixOf("/F"));
312 BOOST_CHECK(!Name("/C").isPrefixOf("/21426=AA"));
313}
314
315BOOST_AUTO_TEST_CASE(CompareOp)
316{
317 std::vector<Name> names = {
318 Name("/"),
319 Name("/sha256digest=0000000000000000000000000000000000000000000000000000000000000000"),
320 Name("/sha256digest=0000000000000000000000000000000000000000000000000000000000000001"),
321 Name("/sha256digest=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"),
322 Name("/2=..."),
323 Name("/2=D"),
324 Name("/2=F"),
325 Name("/2=AA"),
326 Name("/..."),
327 Name("/D"),
328 Name("/D/sha256digest=0000000000000000000000000000000000000000000000000000000000000000"),
329 Name("/D/sha256digest=0000000000000000000000000000000000000000000000000000000000000001"),
330 Name("/D/sha256digest=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"),
331 Name("/D/2=..."),
332 Name("/D/2=D"),
333 Name("/D/2=F"),
334 Name("/D/2=AA"),
335 Name("/D/..."),
336 Name("/D/D"),
337 Name("/D/F"),
338 Name("/D/AA"),
339 Name("/D/21426=..."),
340 Name("/D/21426=D"),
341 Name("/D/21426=F"),
342 Name("/D/21426=AA"),
343 Name("/F"),
344 Name("/AA"),
345 Name("/21426=..."),
346 Name("/21426=D"),
347 Name("/21426=F"),
348 Name("/21426=AA"),
349 };
350
351 for (size_t i = 0; i < names.size(); ++i) {
352 for (size_t j = 0; j < names.size(); ++j) {
353 Name lhs = names[i];
354 Name rhs = names[j];
355 BOOST_CHECK_EQUAL(lhs == rhs, i == j);
356 BOOST_CHECK_EQUAL(lhs != rhs, i != j);
357 BOOST_CHECK_EQUAL(lhs < rhs, i < j);
358 BOOST_CHECK_EQUAL(lhs <= rhs, i <= j);
359 BOOST_CHECK_EQUAL(lhs > rhs, i > j);
360 BOOST_CHECK_EQUAL(lhs >= rhs, i >= j);
361 }
362 }
363}
364
365BOOST_AUTO_TEST_CASE(CompareFunc)
Junxiao Shi71ff2312017-07-12 13:32:50 +0000366{
367 BOOST_CHECK_EQUAL(Name("/A") .compare(Name("/A")), 0);
368 BOOST_CHECK_LT (Name("/A") .compare(Name("/B")), 0);
369 BOOST_CHECK_GT (Name("/B") .compare(Name("/A")), 0);
370 BOOST_CHECK_LT (Name("/A") .compare(Name("/AA")), 0);
371 BOOST_CHECK_GT (Name("/AA") .compare(Name("/A")), 0);
372 BOOST_CHECK_LT (Name("/A") .compare(Name("/A/C")), 0);
373 BOOST_CHECK_GT (Name("/A/C").compare(Name("/A")), 0);
374
375 BOOST_CHECK_EQUAL(Name("/Z/A/Y") .compare(1, 1, Name("/A")), 0);
376 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/B")), 0);
377 BOOST_CHECK_GT (Name("/Z/B/Y") .compare(1, 1, Name("/A")), 0);
378 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/AA")), 0);
379 BOOST_CHECK_GT (Name("/Z/AA/Y") .compare(1, 1, Name("/A")), 0);
380 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/A/C")), 0);
381 BOOST_CHECK_GT (Name("/Z/A/C/Y").compare(1, 2, Name("/A")), 0);
382
383 BOOST_CHECK_EQUAL(Name("/Z/A") .compare(1, Name::npos, Name("/A")), 0);
384 BOOST_CHECK_LT (Name("/Z/A") .compare(1, Name::npos, Name("/B")), 0);
385 BOOST_CHECK_GT (Name("/Z/B") .compare(1, Name::npos, Name("/A")), 0);
386 BOOST_CHECK_LT (Name("/Z/A") .compare(1, Name::npos, Name("/AA")), 0);
387 BOOST_CHECK_GT (Name("/Z/AA") .compare(1, Name::npos, Name("/A")), 0);
388 BOOST_CHECK_LT (Name("/Z/A") .compare(1, Name::npos, Name("/A/C")), 0);
389 BOOST_CHECK_GT (Name("/Z/A/C").compare(1, Name::npos, Name("/A")), 0);
390
391 BOOST_CHECK_EQUAL(Name("/Z/A/Y") .compare(1, 1, Name("/X/A/W"), 1, 1), 0);
392 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/B/W"), 1, 1), 0);
393 BOOST_CHECK_GT (Name("/Z/B/Y") .compare(1, 1, Name("/X/A/W"), 1, 1), 0);
394 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/AA/W"), 1, 1), 0);
395 BOOST_CHECK_GT (Name("/Z/AA/Y") .compare(1, 1, Name("/X/A/W"), 1, 1), 0);
396 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/A/C/W"), 1, 2), 0);
397 BOOST_CHECK_GT (Name("/Z/A/C/Y").compare(1, 2, Name("/X/A/W"), 1, 1), 0);
398
399 BOOST_CHECK_EQUAL(Name("/Z/A/Y") .compare(1, 1, Name("/X/A"), 1), 0);
400 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/B"), 1), 0);
401 BOOST_CHECK_GT (Name("/Z/B/Y") .compare(1, 1, Name("/X/A"), 1), 0);
402 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/AA"), 1), 0);
403 BOOST_CHECK_GT (Name("/Z/AA/Y") .compare(1, 1, Name("/X/A"), 1), 0);
404 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/A/C"), 1), 0);
405 BOOST_CHECK_GT (Name("/Z/A/C/Y").compare(1, 2, Name("/X/A"), 1), 0);
406}
407
Junxiao Shi71ff2312017-07-12 13:32:50 +0000408BOOST_AUTO_TEST_CASE(UnorderedMap)
Alexander Afanasyev4f512fb2016-05-18 10:47:53 -0700409{
Junxiao Shi71ff2312017-07-12 13:32:50 +0000410 std::unordered_map<Name, int> map;
411 Name name1("/1");
412 Name name2("/2");
413 Name name3("/3");
414 map[name1] = 1;
415 map[name2] = 2;
416 map[name3] = 3;
Alexander Afanasyev4f512fb2016-05-18 10:47:53 -0700417
Junxiao Shi71ff2312017-07-12 13:32:50 +0000418 BOOST_CHECK_EQUAL(map[name1], 1);
419 BOOST_CHECK_EQUAL(map[name2], 2);
420 BOOST_CHECK_EQUAL(map[name3], 3);
Alexander Afanasyev4f512fb2016-05-18 10:47:53 -0700421}
422
Davide Pesaventoeee3e822016-11-26 19:19:34 +0100423BOOST_AUTO_TEST_SUITE_END() // TestName
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -0800424
Junxiao Shi6bf0adf2015-02-15 13:54:56 -0700425} // namespace tests
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -0800426} // namespace ndn