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 | |
Alexander Afanasyev | d7eacc7 | 2015-04-03 13:06:26 -0700 | [diff] [blame] | 58 | BOOST_AUTO_TEST_CASE(NameWithSpaces) |
| 59 | { |
| 60 | Name name("/ hello\t/\tworld \r\n"); |
| 61 | |
| 62 | BOOST_CHECK_EQUAL("/hello/world", name); |
| 63 | BOOST_CHECK_THROW(Name("/hello//world"), name::Component::Error); |
| 64 | } |
| 65 | |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 66 | BOOST_AUTO_TEST_CASE(DeepCopy) |
| 67 | { |
| 68 | Name n1("/hello/world"); |
| 69 | Name n2 = n1.deepCopy(); |
| 70 | |
| 71 | BOOST_CHECK_EQUAL(n1, n2); |
| 72 | BOOST_CHECK_NE(&n1.wireEncode(), &n2.wireEncode()); |
| 73 | |
| 74 | EncodingBuffer buffer(1024, 0); |
| 75 | n1.wireEncode(buffer); |
| 76 | Name n3(buffer.block()); |
| 77 | |
| 78 | BOOST_CHECK_EQUAL(n1, n3); |
| 79 | BOOST_CHECK_EQUAL(n3.wireEncode().getBuffer()->size(), 1024); |
| 80 | n3 = n3.deepCopy(); |
| 81 | |
| 82 | BOOST_CHECK_LT(n3.wireEncode().size(), 1024); |
| 83 | BOOST_CHECK_EQUAL(n3.wireEncode().getBuffer()->size(), n3.wireEncode().size()); |
| 84 | } |
| 85 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 86 | // ---- access ---- |
| 87 | |
| 88 | BOOST_AUTO_TEST_CASE(At) |
| 89 | { |
| 90 | Name name("/hello/5=NDN"); |
| 91 | |
| 92 | BOOST_CHECK_EQUAL(name.at(0), name::Component("080568656C6C6F"_block)); |
| 93 | BOOST_CHECK_EQUAL(name.at(1), name::Component("05034E444E"_block)); |
| 94 | BOOST_CHECK_EQUAL(name.at(-1), name::Component("05034E444E"_block)); |
| 95 | BOOST_CHECK_EQUAL(name.at(-2), name::Component("080568656C6C6F"_block)); |
| 96 | |
| 97 | BOOST_CHECK_THROW(name.at(2), Name::Error); |
| 98 | BOOST_CHECK_THROW(name.at(-3), Name::Error); |
| 99 | } |
| 100 | |
| 101 | BOOST_AUTO_TEST_CASE(SubName) |
| 102 | { |
| 103 | Name name("/hello/world"); |
| 104 | |
| 105 | BOOST_CHECK_EQUAL("/hello/world", name.getSubName(0)); |
| 106 | BOOST_CHECK_EQUAL("/world", name.getSubName(1)); |
| 107 | BOOST_CHECK_EQUAL("/hello/", name.getSubName(0, 1)); |
| 108 | } |
| 109 | |
| 110 | BOOST_AUTO_TEST_CASE(SubNameNegativeIndex) |
| 111 | { |
| 112 | Name name("/first/second/third/last"); |
| 113 | |
| 114 | BOOST_CHECK_EQUAL("/last", name.getSubName(-1)); |
| 115 | BOOST_CHECK_EQUAL("/third/last", name.getSubName(-2)); |
| 116 | BOOST_CHECK_EQUAL("/second", name.getSubName(-3, 1)); |
| 117 | } |
| 118 | |
| 119 | BOOST_AUTO_TEST_CASE(SubNameOutOfRangeIndexes) |
| 120 | { |
| 121 | Name name("/first/second/last"); |
| 122 | // No length |
| 123 | BOOST_CHECK_EQUAL("/first/second/last", name.getSubName(-10)); |
| 124 | BOOST_CHECK_EQUAL("/", name.getSubName(10)); |
| 125 | |
| 126 | // Starting after the max position |
| 127 | BOOST_CHECK_EQUAL("/", name.getSubName(10, 1)); |
| 128 | BOOST_CHECK_EQUAL("/", name.getSubName(10, 10)); |
| 129 | |
| 130 | // Not enough components |
| 131 | BOOST_CHECK_EQUAL("/second/last", name.getSubName(1, 10)); |
| 132 | BOOST_CHECK_EQUAL("/last", name.getSubName(-1, 10)); |
| 133 | |
| 134 | // Start before first |
| 135 | BOOST_CHECK_EQUAL("/first/second", name.getSubName(-10, 2)); |
| 136 | BOOST_CHECK_EQUAL("/first/second/last", name.getSubName(-10, 10)); |
| 137 | } |
| 138 | |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 139 | // ---- iterators ---- |
| 140 | |
| 141 | BOOST_AUTO_TEST_CASE(ForwardIterator) |
| 142 | { |
| 143 | name::Component comps[] { |
| 144 | name::Component("A"), |
| 145 | name::Component("B"), |
| 146 | name::Component("C"), |
| 147 | name::Component("D") |
| 148 | }; |
| 149 | |
| 150 | Name n0; |
| 151 | BOOST_CHECK_EQUAL_COLLECTIONS(n0.begin(), n0.end(), comps, comps + 0); |
| 152 | |
| 153 | Name n4("/A/B/C/D"); |
| 154 | BOOST_CHECK_EQUAL_COLLECTIONS(n4.begin(), n4.end(), comps, comps + 4); |
| 155 | } |
| 156 | |
| 157 | BOOST_AUTO_TEST_CASE(ReverseIterator) |
| 158 | { |
| 159 | name::Component comps[] { |
| 160 | name::Component("D"), |
| 161 | name::Component("C"), |
| 162 | name::Component("B"), |
| 163 | name::Component("A") |
| 164 | }; |
| 165 | |
| 166 | Name n0; |
| 167 | BOOST_CHECK_EQUAL_COLLECTIONS(n0.rbegin(), n0.rend(), comps, comps + 0); |
| 168 | |
| 169 | Name n4("/A/B/C/D"); |
| 170 | BOOST_CHECK_EQUAL_COLLECTIONS(n4.rbegin(), n4.rend(), comps, comps + 4); |
| 171 | } |
| 172 | |
| 173 | // ---- modifiers ---- |
| 174 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 175 | BOOST_AUTO_TEST_CASE(AppendComponent) |
Joao Pereira | 6f7cfd0 | 2015-06-15 11:36:26 -0400 | [diff] [blame] | 176 | { |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 177 | Name name; |
| 178 | BOOST_CHECK(name.wireEncode() == "0700"_block); |
Ashlesh Gawande | 7dffab6 | 2017-12-21 16:40:53 -0600 | [diff] [blame] | 179 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 180 | name.append(Component("Emid")); |
| 181 | BOOST_CHECK(name.wireEncode() == "0706 0804456D6964"_block); |
| 182 | |
| 183 | name.append(25042, reinterpret_cast<const uint8_t*>("P3"), 2); |
| 184 | BOOST_CHECK(name.wireEncode() == "070C 0804456D6964 FD61D2025033"_block); |
| 185 | |
| 186 | name.append(reinterpret_cast<const uint8_t*>("."), 1); |
| 187 | BOOST_CHECK(name.wireEncode() == "070F 0804456D6964 FD61D2025033 08012E"_block); |
| 188 | |
| 189 | std::vector<uint8_t> v1{0x28, 0xF0, 0xA3, 0x6B}; |
| 190 | name.append(16, v1.begin(), v1.end()); |
| 191 | BOOST_CHECK(name.wireEncode() == "0715 0804456D6964 FD61D2025033 08012E 100428F0A36B"_block); |
| 192 | |
| 193 | BOOST_CHECK(!name.empty()); |
| 194 | name.clear(); |
| 195 | BOOST_CHECK(name.empty()); |
| 196 | BOOST_CHECK(name.wireEncode() == "0700"_block); |
| 197 | |
| 198 | name.append(v1.begin(), v1.end()); |
| 199 | BOOST_CHECK(name.wireEncode() == "0706 080428F0A36B"_block); |
| 200 | |
| 201 | name.append("xKh"); |
| 202 | BOOST_CHECK(name.wireEncode() == "070B 080428F0A36B 0803784B68"_block); |
| 203 | |
| 204 | name.append("0100"_block); |
| 205 | BOOST_CHECK(name.wireEncode() == "070F 080428F0A36B 0803784B68 08020100"_block); |
| 206 | |
| 207 | name.append("080109"_block); |
| 208 | BOOST_CHECK(name.wireEncode() == "0712 080428F0A36B 0803784B68 08020100 080109"_block); |
Joao Pereira | 6f7cfd0 | 2015-06-15 11:36:26 -0400 | [diff] [blame] | 209 | } |
| 210 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 211 | BOOST_AUTO_TEST_CASE(AppendPartialName) |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 212 | { |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 213 | Name name("/A/B"); |
| 214 | name.append(PartialName("/6=C/D")) |
| 215 | .append(PartialName("/E")); |
| 216 | BOOST_CHECK(name.wireEncode() == "070F 080141 080142 060143 080144 080145"_block); |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | BOOST_AUTO_TEST_CASE(AppendNumber) |
| 220 | { |
| 221 | Name name; |
| 222 | for (uint32_t i = 0; i < 10; i++) { |
| 223 | name.appendNumber(i); |
| 224 | } |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 225 | BOOST_CHECK_EQUAL(name.size(), 10); |
| 226 | |
| 227 | for (uint32_t i = 0; i < 10; i++) { |
| 228 | BOOST_CHECK_EQUAL(name[i].toNumber(), i); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | BOOST_AUTO_TEST_CASE(Markers) |
| 233 | { |
| 234 | // TestNameComponent/NamingConvention provides additional coverage for these methods, |
| 235 | // including verifications of the wire format. |
| 236 | |
| 237 | Name name; |
| 238 | uint64_t number; |
| 239 | |
| 240 | BOOST_REQUIRE_NO_THROW(number = name.appendSegment(30923).at(-1).toSegment()); |
| 241 | BOOST_CHECK_EQUAL(number, 30923); |
| 242 | |
| 243 | BOOST_REQUIRE_NO_THROW(number = name.appendSegmentOffset(589).at(-1).toSegmentOffset()); |
| 244 | BOOST_CHECK_EQUAL(number, 589); |
| 245 | |
| 246 | BOOST_REQUIRE_NO_THROW(number = name.appendVersion().at(-1).toVersion()); |
| 247 | |
| 248 | BOOST_REQUIRE_NO_THROW(number = name.appendVersion(25912).at(-1).toVersion()); |
| 249 | BOOST_CHECK_EQUAL(number, 25912); |
| 250 | |
| 251 | const time::system_clock::TimePoint tp = time::system_clock::now(); |
| 252 | time::system_clock::TimePoint tp2; |
| 253 | BOOST_REQUIRE_NO_THROW(tp2 = name.appendTimestamp(tp).at(-1).toTimestamp()); |
| 254 | BOOST_CHECK_LE(std::abs(time::duration_cast<time::microseconds>(tp2 - tp).count()), 1); |
| 255 | |
| 256 | BOOST_REQUIRE_NO_THROW(number = name.appendSequenceNumber(11676).at(-1).toSequenceNumber()); |
| 257 | BOOST_CHECK_EQUAL(number, 11676); |
| 258 | } |
| 259 | |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 260 | // ---- algorithms ---- |
| 261 | |
| 262 | BOOST_AUTO_TEST_CASE(GetSuccessor) |
| 263 | { |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 264 | BOOST_CHECK_EQUAL(Name("/%00%01/%01%02").getSuccessor(), Name("/%00%01/%01%03")); |
| 265 | BOOST_CHECK_EQUAL(Name("/%00%01/%01%FF").getSuccessor(), Name("/%00%01/%02%00")); |
| 266 | BOOST_CHECK_EQUAL(Name("/%00%01/%FF%FF").getSuccessor(), Name("/%00%01/%00%00%00")); |
| 267 | BOOST_CHECK_EQUAL(Name().getSuccessor(), Name("/%00")); |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 270 | BOOST_AUTO_TEST_CASE(IsPrefixOf) |
| 271 | { |
| 272 | BOOST_CHECK(Name("/").isPrefixOf("/")); |
| 273 | BOOST_CHECK(Name("/").isPrefixOf("/sha256digest=0000000000000000000000000000000000000000000000000000000000000000")); |
| 274 | BOOST_CHECK(Name("/").isPrefixOf("/2=D")); |
| 275 | BOOST_CHECK(Name("/").isPrefixOf("/F")); |
| 276 | BOOST_CHECK(Name("/").isPrefixOf("/21426=AA")); |
| 277 | |
| 278 | BOOST_CHECK(Name("/B").isPrefixOf("/B")); |
| 279 | BOOST_CHECK(Name("/B").isPrefixOf("/B/sha256digest=0000000000000000000000000000000000000000000000000000000000000000")); |
| 280 | BOOST_CHECK(Name("/B").isPrefixOf("/B/2=D")); |
| 281 | BOOST_CHECK(Name("/B").isPrefixOf("/B/F")); |
| 282 | BOOST_CHECK(Name("/B").isPrefixOf("/B/21426=AA")); |
| 283 | |
| 284 | BOOST_CHECK(!Name("/C").isPrefixOf("/")); |
| 285 | BOOST_CHECK(!Name("/C").isPrefixOf("/sha256digest=0000000000000000000000000000000000000000000000000000000000000000")); |
| 286 | BOOST_CHECK(!Name("/C").isPrefixOf("/2=D")); |
| 287 | BOOST_CHECK(!Name("/C").isPrefixOf("/F")); |
| 288 | BOOST_CHECK(!Name("/C").isPrefixOf("/21426=AA")); |
| 289 | } |
| 290 | |
| 291 | BOOST_AUTO_TEST_CASE(CompareOp) |
| 292 | { |
| 293 | std::vector<Name> names = { |
| 294 | Name("/"), |
| 295 | Name("/sha256digest=0000000000000000000000000000000000000000000000000000000000000000"), |
| 296 | Name("/sha256digest=0000000000000000000000000000000000000000000000000000000000000001"), |
| 297 | Name("/sha256digest=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"), |
| 298 | Name("/2=..."), |
| 299 | Name("/2=D"), |
| 300 | Name("/2=F"), |
| 301 | Name("/2=AA"), |
| 302 | Name("/..."), |
| 303 | Name("/D"), |
| 304 | Name("/D/sha256digest=0000000000000000000000000000000000000000000000000000000000000000"), |
| 305 | Name("/D/sha256digest=0000000000000000000000000000000000000000000000000000000000000001"), |
| 306 | Name("/D/sha256digest=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"), |
| 307 | Name("/D/2=..."), |
| 308 | Name("/D/2=D"), |
| 309 | Name("/D/2=F"), |
| 310 | Name("/D/2=AA"), |
| 311 | Name("/D/..."), |
| 312 | Name("/D/D"), |
| 313 | Name("/D/F"), |
| 314 | Name("/D/AA"), |
| 315 | Name("/D/21426=..."), |
| 316 | Name("/D/21426=D"), |
| 317 | Name("/D/21426=F"), |
| 318 | Name("/D/21426=AA"), |
| 319 | Name("/F"), |
| 320 | Name("/AA"), |
| 321 | Name("/21426=..."), |
| 322 | Name("/21426=D"), |
| 323 | Name("/21426=F"), |
| 324 | Name("/21426=AA"), |
| 325 | }; |
| 326 | |
| 327 | for (size_t i = 0; i < names.size(); ++i) { |
| 328 | for (size_t j = 0; j < names.size(); ++j) { |
| 329 | Name lhs = names[i]; |
| 330 | Name rhs = names[j]; |
| 331 | BOOST_CHECK_EQUAL(lhs == rhs, i == j); |
| 332 | BOOST_CHECK_EQUAL(lhs != rhs, i != j); |
| 333 | BOOST_CHECK_EQUAL(lhs < rhs, i < j); |
| 334 | BOOST_CHECK_EQUAL(lhs <= rhs, i <= j); |
| 335 | BOOST_CHECK_EQUAL(lhs > rhs, i > j); |
| 336 | BOOST_CHECK_EQUAL(lhs >= rhs, i >= j); |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | BOOST_AUTO_TEST_CASE(CompareFunc) |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 342 | { |
| 343 | BOOST_CHECK_EQUAL(Name("/A") .compare(Name("/A")), 0); |
| 344 | BOOST_CHECK_LT (Name("/A") .compare(Name("/B")), 0); |
| 345 | BOOST_CHECK_GT (Name("/B") .compare(Name("/A")), 0); |
| 346 | BOOST_CHECK_LT (Name("/A") .compare(Name("/AA")), 0); |
| 347 | BOOST_CHECK_GT (Name("/AA") .compare(Name("/A")), 0); |
| 348 | BOOST_CHECK_LT (Name("/A") .compare(Name("/A/C")), 0); |
| 349 | BOOST_CHECK_GT (Name("/A/C").compare(Name("/A")), 0); |
| 350 | |
| 351 | BOOST_CHECK_EQUAL(Name("/Z/A/Y") .compare(1, 1, Name("/A")), 0); |
| 352 | BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/B")), 0); |
| 353 | BOOST_CHECK_GT (Name("/Z/B/Y") .compare(1, 1, Name("/A")), 0); |
| 354 | BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/AA")), 0); |
| 355 | BOOST_CHECK_GT (Name("/Z/AA/Y") .compare(1, 1, Name("/A")), 0); |
| 356 | BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/A/C")), 0); |
| 357 | BOOST_CHECK_GT (Name("/Z/A/C/Y").compare(1, 2, Name("/A")), 0); |
| 358 | |
| 359 | BOOST_CHECK_EQUAL(Name("/Z/A") .compare(1, Name::npos, Name("/A")), 0); |
| 360 | BOOST_CHECK_LT (Name("/Z/A") .compare(1, Name::npos, Name("/B")), 0); |
| 361 | BOOST_CHECK_GT (Name("/Z/B") .compare(1, Name::npos, Name("/A")), 0); |
| 362 | BOOST_CHECK_LT (Name("/Z/A") .compare(1, Name::npos, Name("/AA")), 0); |
| 363 | BOOST_CHECK_GT (Name("/Z/AA") .compare(1, Name::npos, Name("/A")), 0); |
| 364 | BOOST_CHECK_LT (Name("/Z/A") .compare(1, Name::npos, Name("/A/C")), 0); |
| 365 | BOOST_CHECK_GT (Name("/Z/A/C").compare(1, Name::npos, Name("/A")), 0); |
| 366 | |
| 367 | BOOST_CHECK_EQUAL(Name("/Z/A/Y") .compare(1, 1, Name("/X/A/W"), 1, 1), 0); |
| 368 | BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/B/W"), 1, 1), 0); |
| 369 | BOOST_CHECK_GT (Name("/Z/B/Y") .compare(1, 1, Name("/X/A/W"), 1, 1), 0); |
| 370 | BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/AA/W"), 1, 1), 0); |
| 371 | BOOST_CHECK_GT (Name("/Z/AA/Y") .compare(1, 1, Name("/X/A/W"), 1, 1), 0); |
| 372 | BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/A/C/W"), 1, 2), 0); |
| 373 | BOOST_CHECK_GT (Name("/Z/A/C/Y").compare(1, 2, Name("/X/A/W"), 1, 1), 0); |
| 374 | |
| 375 | BOOST_CHECK_EQUAL(Name("/Z/A/Y") .compare(1, 1, Name("/X/A"), 1), 0); |
| 376 | BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/B"), 1), 0); |
| 377 | BOOST_CHECK_GT (Name("/Z/B/Y") .compare(1, 1, Name("/X/A"), 1), 0); |
| 378 | BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/AA"), 1), 0); |
| 379 | BOOST_CHECK_GT (Name("/Z/AA/Y") .compare(1, 1, Name("/X/A"), 1), 0); |
| 380 | BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/A/C"), 1), 0); |
| 381 | BOOST_CHECK_GT (Name("/Z/A/C/Y").compare(1, 2, Name("/X/A"), 1), 0); |
| 382 | } |
| 383 | |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 384 | BOOST_AUTO_TEST_CASE(UnorderedMap) |
Alexander Afanasyev | 4f512fb | 2016-05-18 10:47:53 -0700 | [diff] [blame] | 385 | { |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 386 | std::unordered_map<Name, int> map; |
| 387 | Name name1("/1"); |
| 388 | Name name2("/2"); |
| 389 | Name name3("/3"); |
| 390 | map[name1] = 1; |
| 391 | map[name2] = 2; |
| 392 | map[name3] = 3; |
Alexander Afanasyev | 4f512fb | 2016-05-18 10:47:53 -0700 | [diff] [blame] | 393 | |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 394 | BOOST_CHECK_EQUAL(map[name1], 1); |
| 395 | BOOST_CHECK_EQUAL(map[name2], 2); |
| 396 | BOOST_CHECK_EQUAL(map[name3], 3); |
Alexander Afanasyev | 4f512fb | 2016-05-18 10:47:53 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 399 | BOOST_AUTO_TEST_SUITE_END() // TestName |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 400 | |
Junxiao Shi | 6bf0adf | 2015-02-15 13:54:56 -0700 | [diff] [blame] | 401 | } // namespace tests |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 402 | } // namespace ndn |