Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 2 | /* |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 3 | * Copyright (c) 2013-2018 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * 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 Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 22 | #include "name.hpp" |
| 23 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 24 | #include "block-literal.hpp" |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 25 | #include "boost-test.hpp" |
Yingdi Yu | 90e2358 | 2014-11-06 14:21:04 -0800 | [diff] [blame] | 26 | #include <unordered_map> |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 27 | |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 28 | namespace ndn { |
Junxiao Shi | 6bf0adf | 2015-02-15 13:54:56 -0700 | [diff] [blame] | 29 | namespace tests { |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 30 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 31 | using Component = name::Component; |
| 32 | |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 33 | BOOST_AUTO_TEST_SUITE(TestName) |
| 34 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 35 | // ---- encoding, decoding, and URI ---- |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 36 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 37 | BOOST_AUTO_TEST_CASE(EncodeDecode) |
Alexander Afanasyev | c234429 | 2014-03-02 00:08:00 +0000 | [diff] [blame] | 38 | { |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 39 | 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 Afanasyev | c234429 | 2014-03-02 00:08:00 +0000 | [diff] [blame] | 49 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 50 | Block wire = name.wireEncode(); |
| 51 | BOOST_CHECK(wire == "0737 0804456D6964 FD61D2025033 0800 08012E 08021C9F " |
| 52 | "01200415E3624A151850AC686C84F155F29808C0DD73819AA4A4C20BE73A4D8A874C"_block); |
Alexander Afanasyev | c234429 | 2014-03-02 00:08:00 +0000 | [diff] [blame] | 53 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 54 | Name decoded(wire); |
| 55 | BOOST_CHECK_EQUAL(decoded, name); |
Alexander Afanasyev | 6486d52 | 2014-10-23 14:14:11 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Junxiao Shi | 9c9672e | 2018-04-18 12:55:08 +0000 | [diff] [blame^] | 58 | BOOST_AUTO_TEST_CASE(ParseUri) |
Alexander Afanasyev | d7eacc7 | 2015-04-03 13:06:26 -0700 | [diff] [blame] | 59 | { |
Junxiao Shi | 9c9672e | 2018-04-18 12:55:08 +0000 | [diff] [blame^] | 60 | // URI with correct scheme |
| 61 | BOOST_CHECK_EQUAL(Name("ndn:/hello/world").toUri(), "/hello/world"); |
Alexander Afanasyev | d7eacc7 | 2015-04-03 13:06:26 -0700 | [diff] [blame] | 62 | |
Junxiao Shi | 9c9672e | 2018-04-18 12:55:08 +0000 | [diff] [blame^] | 63 | // 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 Afanasyev | d7eacc7 | 2015-04-03 13:06:26 -0700 | [diff] [blame] | 85 | BOOST_CHECK_THROW(Name("/hello//world"), name::Component::Error); |
Junxiao Shi | 9c9672e | 2018-04-18 12:55:08 +0000 | [diff] [blame^] | 86 | BOOST_CHECK_THROW(Name("/hello/./world"), name::Component::Error); |
| 87 | BOOST_CHECK_THROW(Name("/hello/../world"), name::Component::Error); |
Alexander Afanasyev | d7eacc7 | 2015-04-03 13:06:26 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 90 | BOOST_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 Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 110 | // ---- access ---- |
| 111 | |
| 112 | BOOST_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 | |
| 125 | BOOST_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 Shi | 9c9672e | 2018-04-18 12:55:08 +0000 | [diff] [blame^] | 131 | BOOST_CHECK_EQUAL("/hello", name.getSubName(0, 1)); |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | BOOST_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 | |
| 143 | BOOST_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 Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 163 | // ---- iterators ---- |
| 164 | |
| 165 | BOOST_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 | |
| 181 | BOOST_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 Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 199 | BOOST_AUTO_TEST_CASE(AppendComponent) |
Joao Pereira | 6f7cfd0 | 2015-06-15 11:36:26 -0400 | [diff] [blame] | 200 | { |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 201 | Name name; |
| 202 | BOOST_CHECK(name.wireEncode() == "0700"_block); |
Ashlesh Gawande | 7dffab6 | 2017-12-21 16:40:53 -0600 | [diff] [blame] | 203 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 204 | 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 Pereira | 6f7cfd0 | 2015-06-15 11:36:26 -0400 | [diff] [blame] | 233 | } |
| 234 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 235 | BOOST_AUTO_TEST_CASE(AppendPartialName) |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 236 | { |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 237 | 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 Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | BOOST_AUTO_TEST_CASE(AppendNumber) |
| 244 | { |
| 245 | Name name; |
| 246 | for (uint32_t i = 0; i < 10; i++) { |
| 247 | name.appendNumber(i); |
| 248 | } |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 249 | 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 | |
| 256 | BOOST_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 Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 284 | // ---- algorithms ---- |
| 285 | |
| 286 | BOOST_AUTO_TEST_CASE(GetSuccessor) |
| 287 | { |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 288 | 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 Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 294 | BOOST_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 | |
| 315 | BOOST_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 | |
| 365 | BOOST_AUTO_TEST_CASE(CompareFunc) |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 366 | { |
| 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 Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 408 | BOOST_AUTO_TEST_CASE(UnorderedMap) |
Alexander Afanasyev | 4f512fb | 2016-05-18 10:47:53 -0700 | [diff] [blame] | 409 | { |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 410 | 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 Afanasyev | 4f512fb | 2016-05-18 10:47:53 -0700 | [diff] [blame] | 417 | |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 418 | BOOST_CHECK_EQUAL(map[name1], 1); |
| 419 | BOOST_CHECK_EQUAL(map[name2], 2); |
| 420 | BOOST_CHECK_EQUAL(map[name3], 3); |
Alexander Afanasyev | 4f512fb | 2016-05-18 10:47:53 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 423 | BOOST_AUTO_TEST_SUITE_END() // TestName |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 424 | |
Junxiao Shi | 6bf0adf | 2015-02-15 13:54:56 -0700 | [diff] [blame] | 425 | } // namespace tests |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 426 | } // namespace ndn |