blob: af712063230dd69571bcdc234d0ef6e10c2145a8 [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();
Junxiao Shi72c0c642018-04-20 15:41:09 +000051 BOOST_CHECK_EQUAL(wire,
52 "0737 0804456D6964 FD61D2025033 0800 08012E 08021C9F "
53 "01200415E3624A151850AC686C84F155F29808C0DD73819AA4A4C20BE73A4D8A874C"_block);
Alexander Afanasyevc2344292014-03-02 00:08:00 +000054
Junxiao Shia36f15d2018-04-04 02:22:11 +000055 Name decoded(wire);
56 BOOST_CHECK_EQUAL(decoded, name);
Alexander Afanasyev6486d522014-10-23 14:14:11 -070057}
58
Junxiao Shi9c9672e2018-04-18 12:55:08 +000059BOOST_AUTO_TEST_CASE(ParseUri)
Alexander Afanasyevd7eacc72015-04-03 13:06:26 -070060{
Junxiao Shi9c9672e2018-04-18 12:55:08 +000061 // URI with correct scheme
62 BOOST_CHECK_EQUAL(Name("ndn:/hello/world").toUri(), "/hello/world");
Alexander Afanasyevd7eacc72015-04-03 13:06:26 -070063
Junxiao Shi9c9672e2018-04-18 12:55:08 +000064 // URI with incorrect scheme: auto-corrected
65 BOOST_CHECK_EQUAL(Name("ncc:/hello/world").toUri(), "/hello/world");
66
67 // URI with authority: authority ignored
68 BOOST_CHECK_EQUAL(Name("//authority/hello/world").toUri(), "/hello/world");
69 BOOST_CHECK_EQUAL(Name("ndn://authority/hello/world").toUri(), "/hello/world");
70
71 // URI containing unescaped characters: auto-corrected
72 BOOST_CHECK_EQUAL(Name("/ hello\t/\tworld \r\n").toUri(), "/%20hello%09/%09world%20%0D%0A");
73 BOOST_CHECK_EQUAL(Name("/hello/world/ ").toUri(), "/hello/world/%20%20");
74 BOOST_CHECK_EQUAL(Name("/:?#[]@").toUri(), "/%3A%3F%23%5B%5D%40");
75
76 // URI not starting with '/': accepted as PartialName
77 BOOST_CHECK_EQUAL(Name("").toUri(), "/");
78 BOOST_CHECK_EQUAL(Name(" ").toUri(), "/%20");
79 BOOST_CHECK_EQUAL(Name(" /hello/world").toUri(), "/%20%20/hello/world");
80 BOOST_CHECK_EQUAL(Name("hello/world").toUri(), "/hello/world");
81
82 // URI ending with '/': auto-corrected
83 BOOST_CHECK_EQUAL(Name("/hello/world/").toUri(), "/hello/world");
84
85 // URI containing bad component: rejected
Alexander Afanasyevd7eacc72015-04-03 13:06:26 -070086 BOOST_CHECK_THROW(Name("/hello//world"), name::Component::Error);
Junxiao Shi9c9672e2018-04-18 12:55:08 +000087 BOOST_CHECK_THROW(Name("/hello/./world"), name::Component::Error);
88 BOOST_CHECK_THROW(Name("/hello/../world"), name::Component::Error);
Alexander Afanasyevd7eacc72015-04-03 13:06:26 -070089}
90
Junxiao Shi71ff2312017-07-12 13:32:50 +000091BOOST_AUTO_TEST_CASE(DeepCopy)
92{
93 Name n1("/hello/world");
94 Name n2 = n1.deepCopy();
95
96 BOOST_CHECK_EQUAL(n1, n2);
97 BOOST_CHECK_NE(&n1.wireEncode(), &n2.wireEncode());
98
99 EncodingBuffer buffer(1024, 0);
100 n1.wireEncode(buffer);
101 Name n3(buffer.block());
102
103 BOOST_CHECK_EQUAL(n1, n3);
104 BOOST_CHECK_EQUAL(n3.wireEncode().getBuffer()->size(), 1024);
105 n3 = n3.deepCopy();
106
107 BOOST_CHECK_LT(n3.wireEncode().size(), 1024);
108 BOOST_CHECK_EQUAL(n3.wireEncode().getBuffer()->size(), n3.wireEncode().size());
109}
110
Junxiao Shia36f15d2018-04-04 02:22:11 +0000111// ---- access ----
112
113BOOST_AUTO_TEST_CASE(At)
114{
115 Name name("/hello/5=NDN");
116
117 BOOST_CHECK_EQUAL(name.at(0), name::Component("080568656C6C6F"_block));
118 BOOST_CHECK_EQUAL(name.at(1), name::Component("05034E444E"_block));
119 BOOST_CHECK_EQUAL(name.at(-1), name::Component("05034E444E"_block));
120 BOOST_CHECK_EQUAL(name.at(-2), name::Component("080568656C6C6F"_block));
121
122 BOOST_CHECK_THROW(name.at(2), Name::Error);
123 BOOST_CHECK_THROW(name.at(-3), Name::Error);
124}
125
126BOOST_AUTO_TEST_CASE(SubName)
127{
128 Name name("/hello/world");
129
130 BOOST_CHECK_EQUAL("/hello/world", name.getSubName(0));
131 BOOST_CHECK_EQUAL("/world", name.getSubName(1));
Junxiao Shi9c9672e2018-04-18 12:55:08 +0000132 BOOST_CHECK_EQUAL("/hello", name.getSubName(0, 1));
Junxiao Shia36f15d2018-04-04 02:22:11 +0000133}
134
135BOOST_AUTO_TEST_CASE(SubNameNegativeIndex)
136{
137 Name name("/first/second/third/last");
138
139 BOOST_CHECK_EQUAL("/last", name.getSubName(-1));
140 BOOST_CHECK_EQUAL("/third/last", name.getSubName(-2));
141 BOOST_CHECK_EQUAL("/second", name.getSubName(-3, 1));
142}
143
144BOOST_AUTO_TEST_CASE(SubNameOutOfRangeIndexes)
145{
146 Name name("/first/second/last");
147 // No length
148 BOOST_CHECK_EQUAL("/first/second/last", name.getSubName(-10));
149 BOOST_CHECK_EQUAL("/", name.getSubName(10));
150
151 // Starting after the max position
152 BOOST_CHECK_EQUAL("/", name.getSubName(10, 1));
153 BOOST_CHECK_EQUAL("/", name.getSubName(10, 10));
154
155 // Not enough components
156 BOOST_CHECK_EQUAL("/second/last", name.getSubName(1, 10));
157 BOOST_CHECK_EQUAL("/last", name.getSubName(-1, 10));
158
159 // Start before first
160 BOOST_CHECK_EQUAL("/first/second", name.getSubName(-10, 2));
161 BOOST_CHECK_EQUAL("/first/second/last", name.getSubName(-10, 10));
162}
163
Junxiao Shi71ff2312017-07-12 13:32:50 +0000164// ---- iterators ----
165
166BOOST_AUTO_TEST_CASE(ForwardIterator)
167{
168 name::Component comps[] {
169 name::Component("A"),
170 name::Component("B"),
171 name::Component("C"),
172 name::Component("D")
173 };
174
175 Name n0;
176 BOOST_CHECK_EQUAL_COLLECTIONS(n0.begin(), n0.end(), comps, comps + 0);
177
178 Name n4("/A/B/C/D");
179 BOOST_CHECK_EQUAL_COLLECTIONS(n4.begin(), n4.end(), comps, comps + 4);
180}
181
182BOOST_AUTO_TEST_CASE(ReverseIterator)
183{
184 name::Component comps[] {
185 name::Component("D"),
186 name::Component("C"),
187 name::Component("B"),
188 name::Component("A")
189 };
190
191 Name n0;
192 BOOST_CHECK_EQUAL_COLLECTIONS(n0.rbegin(), n0.rend(), comps, comps + 0);
193
194 Name n4("/A/B/C/D");
195 BOOST_CHECK_EQUAL_COLLECTIONS(n4.rbegin(), n4.rend(), comps, comps + 4);
196}
197
198// ---- modifiers ----
199
Junxiao Shia36f15d2018-04-04 02:22:11 +0000200BOOST_AUTO_TEST_CASE(AppendComponent)
Joao Pereira6f7cfd02015-06-15 11:36:26 -0400201{
Junxiao Shia36f15d2018-04-04 02:22:11 +0000202 Name name;
Junxiao Shi72c0c642018-04-20 15:41:09 +0000203 BOOST_CHECK_EQUAL(name.wireEncode(), "0700"_block);
Ashlesh Gawande7dffab62017-12-21 16:40:53 -0600204
Junxiao Shia36f15d2018-04-04 02:22:11 +0000205 name.append(Component("Emid"));
Junxiao Shi72c0c642018-04-20 15:41:09 +0000206 BOOST_CHECK_EQUAL(name.wireEncode(), "0706 0804456D6964"_block);
Junxiao Shia36f15d2018-04-04 02:22:11 +0000207
208 name.append(25042, reinterpret_cast<const uint8_t*>("P3"), 2);
Junxiao Shi72c0c642018-04-20 15:41:09 +0000209 BOOST_CHECK_EQUAL(name.wireEncode(), "070C 0804456D6964 FD61D2025033"_block);
Junxiao Shia36f15d2018-04-04 02:22:11 +0000210
211 name.append(reinterpret_cast<const uint8_t*>("."), 1);
Junxiao Shi72c0c642018-04-20 15:41:09 +0000212 BOOST_CHECK_EQUAL(name.wireEncode(), "070F 0804456D6964 FD61D2025033 08012E"_block);
Junxiao Shia36f15d2018-04-04 02:22:11 +0000213
214 std::vector<uint8_t> v1{0x28, 0xF0, 0xA3, 0x6B};
215 name.append(16, v1.begin(), v1.end());
Junxiao Shi72c0c642018-04-20 15:41:09 +0000216 BOOST_CHECK_EQUAL(name.wireEncode(), "0715 0804456D6964 FD61D2025033 08012E 100428F0A36B"_block);
Junxiao Shia36f15d2018-04-04 02:22:11 +0000217
218 BOOST_CHECK(!name.empty());
219 name.clear();
220 BOOST_CHECK(name.empty());
Junxiao Shi72c0c642018-04-20 15:41:09 +0000221 BOOST_CHECK_EQUAL(name.wireEncode(), "0700"_block);
Junxiao Shia36f15d2018-04-04 02:22:11 +0000222
223 name.append(v1.begin(), v1.end());
Junxiao Shi72c0c642018-04-20 15:41:09 +0000224 BOOST_CHECK_EQUAL(name.wireEncode(), "0706 080428F0A36B"_block);
Junxiao Shia36f15d2018-04-04 02:22:11 +0000225
226 name.append("xKh");
Junxiao Shi72c0c642018-04-20 15:41:09 +0000227 BOOST_CHECK_EQUAL(name.wireEncode(), "070B 080428F0A36B 0803784B68"_block);
Junxiao Shia36f15d2018-04-04 02:22:11 +0000228
229 name.append("0100"_block);
Junxiao Shi72c0c642018-04-20 15:41:09 +0000230 BOOST_CHECK_EQUAL(name.wireEncode(), "070F 080428F0A36B 0803784B68 08020100"_block);
Junxiao Shia36f15d2018-04-04 02:22:11 +0000231
232 name.append("080109"_block);
Junxiao Shi72c0c642018-04-20 15:41:09 +0000233 BOOST_CHECK_EQUAL(name.wireEncode(), "0712 080428F0A36B 0803784B68 08020100 080109"_block);
Joao Pereira6f7cfd02015-06-15 11:36:26 -0400234}
235
Junxiao Shia36f15d2018-04-04 02:22:11 +0000236BOOST_AUTO_TEST_CASE(AppendPartialName)
Junxiao Shi71ff2312017-07-12 13:32:50 +0000237{
Junxiao Shia36f15d2018-04-04 02:22:11 +0000238 Name name("/A/B");
239 name.append(PartialName("/6=C/D"))
240 .append(PartialName("/E"));
Junxiao Shi72c0c642018-04-20 15:41:09 +0000241 BOOST_CHECK_EQUAL(name.wireEncode(), "070F 080141 080142 060143 080144 080145"_block);
Junxiao Shi71ff2312017-07-12 13:32:50 +0000242}
243
244BOOST_AUTO_TEST_CASE(AppendNumber)
245{
246 Name name;
247 for (uint32_t i = 0; i < 10; i++) {
248 name.appendNumber(i);
249 }
Junxiao Shi71ff2312017-07-12 13:32:50 +0000250 BOOST_CHECK_EQUAL(name.size(), 10);
251
252 for (uint32_t i = 0; i < 10; i++) {
253 BOOST_CHECK_EQUAL(name[i].toNumber(), i);
254 }
255}
256
257BOOST_AUTO_TEST_CASE(Markers)
258{
259 // TestNameComponent/NamingConvention provides additional coverage for these methods,
260 // including verifications of the wire format.
261
262 Name name;
263 uint64_t number;
264
265 BOOST_REQUIRE_NO_THROW(number = name.appendSegment(30923).at(-1).toSegment());
266 BOOST_CHECK_EQUAL(number, 30923);
267
268 BOOST_REQUIRE_NO_THROW(number = name.appendSegmentOffset(589).at(-1).toSegmentOffset());
269 BOOST_CHECK_EQUAL(number, 589);
270
271 BOOST_REQUIRE_NO_THROW(number = name.appendVersion().at(-1).toVersion());
272
273 BOOST_REQUIRE_NO_THROW(number = name.appendVersion(25912).at(-1).toVersion());
274 BOOST_CHECK_EQUAL(number, 25912);
275
276 const time::system_clock::TimePoint tp = time::system_clock::now();
277 time::system_clock::TimePoint tp2;
278 BOOST_REQUIRE_NO_THROW(tp2 = name.appendTimestamp(tp).at(-1).toTimestamp());
279 BOOST_CHECK_LE(std::abs(time::duration_cast<time::microseconds>(tp2 - tp).count()), 1);
280
281 BOOST_REQUIRE_NO_THROW(number = name.appendSequenceNumber(11676).at(-1).toSequenceNumber());
282 BOOST_CHECK_EQUAL(number, 11676);
283}
284
Junxiao Shi71ff2312017-07-12 13:32:50 +0000285// ---- algorithms ----
286
287BOOST_AUTO_TEST_CASE(GetSuccessor)
288{
Junxiao Shia36f15d2018-04-04 02:22:11 +0000289 BOOST_CHECK_EQUAL(Name("/%00%01/%01%02").getSuccessor(), Name("/%00%01/%01%03"));
290 BOOST_CHECK_EQUAL(Name("/%00%01/%01%FF").getSuccessor(), Name("/%00%01/%02%00"));
291 BOOST_CHECK_EQUAL(Name("/%00%01/%FF%FF").getSuccessor(), Name("/%00%01/%00%00%00"));
292 BOOST_CHECK_EQUAL(Name().getSuccessor(), Name("/%00"));
Junxiao Shi71ff2312017-07-12 13:32:50 +0000293}
294
Junxiao Shia36f15d2018-04-04 02:22:11 +0000295BOOST_AUTO_TEST_CASE(IsPrefixOf)
296{
297 BOOST_CHECK(Name("/").isPrefixOf("/"));
298 BOOST_CHECK(Name("/").isPrefixOf("/sha256digest=0000000000000000000000000000000000000000000000000000000000000000"));
299 BOOST_CHECK(Name("/").isPrefixOf("/2=D"));
300 BOOST_CHECK(Name("/").isPrefixOf("/F"));
301 BOOST_CHECK(Name("/").isPrefixOf("/21426=AA"));
302
303 BOOST_CHECK(Name("/B").isPrefixOf("/B"));
304 BOOST_CHECK(Name("/B").isPrefixOf("/B/sha256digest=0000000000000000000000000000000000000000000000000000000000000000"));
305 BOOST_CHECK(Name("/B").isPrefixOf("/B/2=D"));
306 BOOST_CHECK(Name("/B").isPrefixOf("/B/F"));
307 BOOST_CHECK(Name("/B").isPrefixOf("/B/21426=AA"));
308
309 BOOST_CHECK(!Name("/C").isPrefixOf("/"));
310 BOOST_CHECK(!Name("/C").isPrefixOf("/sha256digest=0000000000000000000000000000000000000000000000000000000000000000"));
311 BOOST_CHECK(!Name("/C").isPrefixOf("/2=D"));
312 BOOST_CHECK(!Name("/C").isPrefixOf("/F"));
313 BOOST_CHECK(!Name("/C").isPrefixOf("/21426=AA"));
314}
315
316BOOST_AUTO_TEST_CASE(CompareOp)
317{
318 std::vector<Name> names = {
319 Name("/"),
320 Name("/sha256digest=0000000000000000000000000000000000000000000000000000000000000000"),
321 Name("/sha256digest=0000000000000000000000000000000000000000000000000000000000000001"),
322 Name("/sha256digest=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"),
323 Name("/2=..."),
324 Name("/2=D"),
325 Name("/2=F"),
326 Name("/2=AA"),
327 Name("/..."),
328 Name("/D"),
329 Name("/D/sha256digest=0000000000000000000000000000000000000000000000000000000000000000"),
330 Name("/D/sha256digest=0000000000000000000000000000000000000000000000000000000000000001"),
331 Name("/D/sha256digest=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"),
332 Name("/D/2=..."),
333 Name("/D/2=D"),
334 Name("/D/2=F"),
335 Name("/D/2=AA"),
336 Name("/D/..."),
337 Name("/D/D"),
338 Name("/D/F"),
339 Name("/D/AA"),
340 Name("/D/21426=..."),
341 Name("/D/21426=D"),
342 Name("/D/21426=F"),
343 Name("/D/21426=AA"),
344 Name("/F"),
345 Name("/AA"),
346 Name("/21426=..."),
347 Name("/21426=D"),
348 Name("/21426=F"),
349 Name("/21426=AA"),
350 };
351
352 for (size_t i = 0; i < names.size(); ++i) {
353 for (size_t j = 0; j < names.size(); ++j) {
354 Name lhs = names[i];
355 Name rhs = names[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 BOOST_CHECK_EQUAL(lhs >= rhs, i >= j);
362 }
363 }
364}
365
366BOOST_AUTO_TEST_CASE(CompareFunc)
Junxiao Shi71ff2312017-07-12 13:32:50 +0000367{
368 BOOST_CHECK_EQUAL(Name("/A") .compare(Name("/A")), 0);
369 BOOST_CHECK_LT (Name("/A") .compare(Name("/B")), 0);
370 BOOST_CHECK_GT (Name("/B") .compare(Name("/A")), 0);
371 BOOST_CHECK_LT (Name("/A") .compare(Name("/AA")), 0);
372 BOOST_CHECK_GT (Name("/AA") .compare(Name("/A")), 0);
373 BOOST_CHECK_LT (Name("/A") .compare(Name("/A/C")), 0);
374 BOOST_CHECK_GT (Name("/A/C").compare(Name("/A")), 0);
375
376 BOOST_CHECK_EQUAL(Name("/Z/A/Y") .compare(1, 1, Name("/A")), 0);
377 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/B")), 0);
378 BOOST_CHECK_GT (Name("/Z/B/Y") .compare(1, 1, Name("/A")), 0);
379 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/AA")), 0);
380 BOOST_CHECK_GT (Name("/Z/AA/Y") .compare(1, 1, Name("/A")), 0);
381 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/A/C")), 0);
382 BOOST_CHECK_GT (Name("/Z/A/C/Y").compare(1, 2, Name("/A")), 0);
383
384 BOOST_CHECK_EQUAL(Name("/Z/A") .compare(1, Name::npos, Name("/A")), 0);
385 BOOST_CHECK_LT (Name("/Z/A") .compare(1, Name::npos, Name("/B")), 0);
386 BOOST_CHECK_GT (Name("/Z/B") .compare(1, Name::npos, Name("/A")), 0);
387 BOOST_CHECK_LT (Name("/Z/A") .compare(1, Name::npos, Name("/AA")), 0);
388 BOOST_CHECK_GT (Name("/Z/AA") .compare(1, Name::npos, Name("/A")), 0);
389 BOOST_CHECK_LT (Name("/Z/A") .compare(1, Name::npos, Name("/A/C")), 0);
390 BOOST_CHECK_GT (Name("/Z/A/C").compare(1, Name::npos, Name("/A")), 0);
391
392 BOOST_CHECK_EQUAL(Name("/Z/A/Y") .compare(1, 1, Name("/X/A/W"), 1, 1), 0);
393 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/B/W"), 1, 1), 0);
394 BOOST_CHECK_GT (Name("/Z/B/Y") .compare(1, 1, Name("/X/A/W"), 1, 1), 0);
395 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/AA/W"), 1, 1), 0);
396 BOOST_CHECK_GT (Name("/Z/AA/Y") .compare(1, 1, Name("/X/A/W"), 1, 1), 0);
397 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/A/C/W"), 1, 2), 0);
398 BOOST_CHECK_GT (Name("/Z/A/C/Y").compare(1, 2, Name("/X/A/W"), 1, 1), 0);
399
400 BOOST_CHECK_EQUAL(Name("/Z/A/Y") .compare(1, 1, Name("/X/A"), 1), 0);
401 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/B"), 1), 0);
402 BOOST_CHECK_GT (Name("/Z/B/Y") .compare(1, 1, Name("/X/A"), 1), 0);
403 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/AA"), 1), 0);
404 BOOST_CHECK_GT (Name("/Z/AA/Y") .compare(1, 1, Name("/X/A"), 1), 0);
405 BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/A/C"), 1), 0);
406 BOOST_CHECK_GT (Name("/Z/A/C/Y").compare(1, 2, Name("/X/A"), 1), 0);
407}
408
Junxiao Shi71ff2312017-07-12 13:32:50 +0000409BOOST_AUTO_TEST_CASE(UnorderedMap)
Alexander Afanasyev4f512fb2016-05-18 10:47:53 -0700410{
Junxiao Shi71ff2312017-07-12 13:32:50 +0000411 std::unordered_map<Name, int> map;
412 Name name1("/1");
413 Name name2("/2");
414 Name name3("/3");
415 map[name1] = 1;
416 map[name2] = 2;
417 map[name3] = 3;
Alexander Afanasyev4f512fb2016-05-18 10:47:53 -0700418
Junxiao Shi71ff2312017-07-12 13:32:50 +0000419 BOOST_CHECK_EQUAL(map[name1], 1);
420 BOOST_CHECK_EQUAL(map[name2], 2);
421 BOOST_CHECK_EQUAL(map[name3], 3);
Alexander Afanasyev4f512fb2016-05-18 10:47:53 -0700422}
423
Davide Pesaventoeee3e822016-11-26 19:19:34 +0100424BOOST_AUTO_TEST_SUITE_END() // TestName
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -0800425
Junxiao Shi6bf0adf2015-02-15 13:54:56 -0700426} // namespace tests
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -0800427} // namespace ndn