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 | /* |
Davide Pesavento | 3fdb02f | 2023-04-12 02:32:38 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2023 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 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 22 | #include "ndn-cxx/name.hpp" |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 23 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 24 | #include "tests/boost-test.hpp" |
| 25 | |
Yingdi Yu | 90e2358 | 2014-11-06 14:21:04 -0800 | [diff] [blame] | 26 | #include <unordered_map> |
Davide Pesavento | 152ef44 | 2023-04-22 02:02:29 -0400 | [diff] [blame] | 27 | #include <boost/range/concepts.hpp> |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 28 | |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 29 | namespace ndn { |
Junxiao Shi | 6bf0adf | 2015-02-15 13:54:56 -0700 | [diff] [blame] | 30 | namespace tests { |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 31 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 32 | using Component = name::Component; |
Junxiao Shi | a39c0b5 | 2019-12-31 15:13:15 -0700 | [diff] [blame] | 33 | using UriFormat = name::UriFormat; |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 34 | |
Davide Pesavento | 152ef44 | 2023-04-22 02:02:29 -0400 | [diff] [blame] | 35 | BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Name>)); |
| 36 | BOOST_CONCEPT_ASSERT((WireEncodable<Name>)); |
| 37 | BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<Name>)); |
| 38 | BOOST_CONCEPT_ASSERT((WireDecodable<Name>)); |
| 39 | BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::iterator>)); |
| 40 | BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::const_iterator>)); |
| 41 | BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::reverse_iterator>)); |
| 42 | BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::const_reverse_iterator>)); |
| 43 | BOOST_CONCEPT_ASSERT((boost::RandomAccessRangeConcept<Name>)); |
| 44 | static_assert(std::is_convertible_v<Name::Error*, tlv::Error*>, |
| 45 | "Name::Error must inherit from tlv::Error"); |
| 46 | |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 47 | BOOST_AUTO_TEST_SUITE(TestName) |
| 48 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 49 | // ---- encoding, decoding, and URI ---- |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 50 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 51 | BOOST_AUTO_TEST_CASE(EncodeDecode) |
Alexander Afanasyev | c234429 | 2014-03-02 00:08:00 +0000 | [diff] [blame] | 52 | { |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 53 | std::string uri = "/Emid/25042=P3/.../..../%1C%9F/" |
| 54 | "sha256digest=0415e3624a151850ac686c84f155f29808c0dd73819aa4a4c20be73a4d8a874c"; |
| 55 | Name name(uri); |
| 56 | BOOST_CHECK_EQUAL(name.size(), 6); |
| 57 | BOOST_CHECK_EQUAL(name[0], Component("Emid")); |
| 58 | BOOST_CHECK_EQUAL(name[1], Component("FD61D2025033"_block)); |
| 59 | BOOST_CHECK_EQUAL(name[2], Component("")); |
| 60 | BOOST_CHECK_EQUAL(name[3], Component(".")); |
| 61 | BOOST_CHECK_EQUAL(name[4], Component("\x1C\x9F")); |
| 62 | BOOST_CHECK(name[5].isImplicitSha256Digest()); |
Alexander Afanasyev | c234429 | 2014-03-02 00:08:00 +0000 | [diff] [blame] | 63 | |
Junxiao Shi | a39c0b5 | 2019-12-31 15:13:15 -0700 | [diff] [blame] | 64 | BOOST_CHECK_EQUAL(name.toUri(UriFormat::CANONICAL), |
| 65 | "/8=Emid/25042=P3/8=.../8=..../8=%1C%9F/" |
| 66 | "1=%04%15%E3bJ%15%18P%AChl%84%F1U%F2%98%08%C0%DDs%81%9A%A4%A4%C2%0B%E7%3AM%8A%87L"); |
| 67 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 68 | Block wire = name.wireEncode(); |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 69 | BOOST_CHECK_EQUAL(wire, |
| 70 | "0737 0804456D6964 FD61D2025033 0800 08012E 08021C9F " |
| 71 | "01200415E3624A151850AC686C84F155F29808C0DD73819AA4A4C20BE73A4D8A874C"_block); |
Alexander Afanasyev | c234429 | 2014-03-02 00:08:00 +0000 | [diff] [blame] | 72 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 73 | Name decoded(wire); |
| 74 | BOOST_CHECK_EQUAL(decoded, name); |
Alexander Afanasyev | 6486d52 | 2014-10-23 14:14:11 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Junxiao Shi | 9c9672e | 2018-04-18 12:55:08 +0000 | [diff] [blame] | 77 | BOOST_AUTO_TEST_CASE(ParseUri) |
Alexander Afanasyev | d7eacc7 | 2015-04-03 13:06:26 -0700 | [diff] [blame] | 78 | { |
Junxiao Shi | a39c0b5 | 2019-12-31 15:13:15 -0700 | [diff] [blame] | 79 | // canonical URI |
| 80 | BOOST_CHECK_EQUAL(Name("/8=hello/8=world").toUri(), "/hello/world"); |
| 81 | |
Junxiao Shi | 9c9672e | 2018-04-18 12:55:08 +0000 | [diff] [blame] | 82 | // URI with correct scheme |
| 83 | BOOST_CHECK_EQUAL(Name("ndn:/hello/world").toUri(), "/hello/world"); |
Davide Pesavento | 3fdb02f | 2023-04-12 02:32:38 -0400 | [diff] [blame] | 84 | BOOST_CHECK_EQUAL(Name("ndn:/").toUri(), "/"); |
| 85 | BOOST_CHECK_EQUAL(Name("ndn:").toUri(), "/"); |
Alexander Afanasyev | d7eacc7 | 2015-04-03 13:06:26 -0700 | [diff] [blame] | 86 | |
Junxiao Shi | 9c9672e | 2018-04-18 12:55:08 +0000 | [diff] [blame] | 87 | // URI with incorrect scheme: auto-corrected |
| 88 | BOOST_CHECK_EQUAL(Name("ncc:/hello/world").toUri(), "/hello/world"); |
Davide Pesavento | 3fdb02f | 2023-04-12 02:32:38 -0400 | [diff] [blame] | 89 | BOOST_CHECK_EQUAL(Name(":/").toUri(), "/"); |
| 90 | BOOST_CHECK_EQUAL(Name(":").toUri(), "/"); |
Junxiao Shi | 9c9672e | 2018-04-18 12:55:08 +0000 | [diff] [blame] | 91 | |
| 92 | // URI with authority: authority ignored |
| 93 | BOOST_CHECK_EQUAL(Name("//authority/hello/world").toUri(), "/hello/world"); |
| 94 | BOOST_CHECK_EQUAL(Name("ndn://authority/hello/world").toUri(), "/hello/world"); |
Davide Pesavento | 3fdb02f | 2023-04-12 02:32:38 -0400 | [diff] [blame] | 95 | BOOST_CHECK_EQUAL(Name("//authority").toUri(), "/"); |
| 96 | BOOST_CHECK_EQUAL(Name("ndn://").toUri(), "/"); |
Junxiao Shi | 9c9672e | 2018-04-18 12:55:08 +0000 | [diff] [blame] | 97 | |
| 98 | // URI containing unescaped characters: auto-corrected |
| 99 | BOOST_CHECK_EQUAL(Name("/ hello\t/\tworld \r\n").toUri(), "/%20hello%09/%09world%20%0D%0A"); |
| 100 | BOOST_CHECK_EQUAL(Name("/hello/world/ ").toUri(), "/hello/world/%20%20"); |
| 101 | BOOST_CHECK_EQUAL(Name("/:?#[]@").toUri(), "/%3A%3F%23%5B%5D%40"); |
| 102 | |
| 103 | // URI not starting with '/': accepted as PartialName |
| 104 | BOOST_CHECK_EQUAL(Name("").toUri(), "/"); |
| 105 | BOOST_CHECK_EQUAL(Name(" ").toUri(), "/%20"); |
Davide Pesavento | 3fdb02f | 2023-04-12 02:32:38 -0400 | [diff] [blame] | 106 | BOOST_CHECK_EQUAL(Name("ndn: ").toUri(), "/%20"); |
| 107 | BOOST_CHECK_EQUAL(Name("ndn: /").toUri(), "/%20"); |
Junxiao Shi | 9c9672e | 2018-04-18 12:55:08 +0000 | [diff] [blame] | 108 | BOOST_CHECK_EQUAL(Name(" /hello/world").toUri(), "/%20%20/hello/world"); |
| 109 | BOOST_CHECK_EQUAL(Name("hello/world").toUri(), "/hello/world"); |
Davide Pesavento | 3fdb02f | 2023-04-12 02:32:38 -0400 | [diff] [blame] | 110 | BOOST_CHECK_EQUAL(Name("hello").toUri(), "/hello"); |
| 111 | BOOST_CHECK_EQUAL(Name("ndn:hello").toUri(), "/hello"); |
Junxiao Shi | 9c9672e | 2018-04-18 12:55:08 +0000 | [diff] [blame] | 112 | |
| 113 | // URI ending with '/': auto-corrected |
| 114 | BOOST_CHECK_EQUAL(Name("/hello/world/").toUri(), "/hello/world"); |
| 115 | |
| 116 | // URI containing bad component: rejected |
Alexander Afanasyev | d7eacc7 | 2015-04-03 13:06:26 -0700 | [diff] [blame] | 117 | BOOST_CHECK_THROW(Name("/hello//world"), name::Component::Error); |
Junxiao Shi | 9c9672e | 2018-04-18 12:55:08 +0000 | [diff] [blame] | 118 | BOOST_CHECK_THROW(Name("/hello/./world"), name::Component::Error); |
| 119 | BOOST_CHECK_THROW(Name("/hello/../world"), name::Component::Error); |
Alexander Afanasyev | d7eacc7 | 2015-04-03 13:06:26 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 122 | BOOST_AUTO_TEST_CASE(DeepCopy) |
| 123 | { |
| 124 | Name n1("/hello/world"); |
| 125 | Name n2 = n1.deepCopy(); |
| 126 | |
| 127 | BOOST_CHECK_EQUAL(n1, n2); |
| 128 | BOOST_CHECK_NE(&n1.wireEncode(), &n2.wireEncode()); |
| 129 | |
| 130 | EncodingBuffer buffer(1024, 0); |
| 131 | n1.wireEncode(buffer); |
| 132 | Name n3(buffer.block()); |
| 133 | |
| 134 | BOOST_CHECK_EQUAL(n1, n3); |
| 135 | BOOST_CHECK_EQUAL(n3.wireEncode().getBuffer()->size(), 1024); |
| 136 | n3 = n3.deepCopy(); |
| 137 | |
| 138 | BOOST_CHECK_LT(n3.wireEncode().size(), 1024); |
| 139 | BOOST_CHECK_EQUAL(n3.wireEncode().getBuffer()->size(), n3.wireEncode().size()); |
| 140 | } |
| 141 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 142 | // ---- access ---- |
| 143 | |
| 144 | BOOST_AUTO_TEST_CASE(At) |
| 145 | { |
| 146 | Name name("/hello/5=NDN"); |
| 147 | |
| 148 | BOOST_CHECK_EQUAL(name.at(0), name::Component("080568656C6C6F"_block)); |
| 149 | BOOST_CHECK_EQUAL(name.at(1), name::Component("05034E444E"_block)); |
| 150 | BOOST_CHECK_EQUAL(name.at(-1), name::Component("05034E444E"_block)); |
| 151 | BOOST_CHECK_EQUAL(name.at(-2), name::Component("080568656C6C6F"_block)); |
| 152 | |
| 153 | BOOST_CHECK_THROW(name.at(2), Name::Error); |
| 154 | BOOST_CHECK_THROW(name.at(-3), Name::Error); |
| 155 | } |
| 156 | |
| 157 | BOOST_AUTO_TEST_CASE(SubName) |
| 158 | { |
| 159 | Name name("/hello/world"); |
| 160 | |
| 161 | BOOST_CHECK_EQUAL("/hello/world", name.getSubName(0)); |
| 162 | BOOST_CHECK_EQUAL("/world", name.getSubName(1)); |
Junxiao Shi | 9c9672e | 2018-04-18 12:55:08 +0000 | [diff] [blame] | 163 | BOOST_CHECK_EQUAL("/hello", name.getSubName(0, 1)); |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | BOOST_AUTO_TEST_CASE(SubNameNegativeIndex) |
| 167 | { |
| 168 | Name name("/first/second/third/last"); |
| 169 | |
| 170 | BOOST_CHECK_EQUAL("/last", name.getSubName(-1)); |
| 171 | BOOST_CHECK_EQUAL("/third/last", name.getSubName(-2)); |
| 172 | BOOST_CHECK_EQUAL("/second", name.getSubName(-3, 1)); |
| 173 | } |
| 174 | |
| 175 | BOOST_AUTO_TEST_CASE(SubNameOutOfRangeIndexes) |
| 176 | { |
| 177 | Name name("/first/second/last"); |
| 178 | // No length |
| 179 | BOOST_CHECK_EQUAL("/first/second/last", name.getSubName(-10)); |
| 180 | BOOST_CHECK_EQUAL("/", name.getSubName(10)); |
| 181 | |
| 182 | // Starting after the max position |
| 183 | BOOST_CHECK_EQUAL("/", name.getSubName(10, 1)); |
| 184 | BOOST_CHECK_EQUAL("/", name.getSubName(10, 10)); |
| 185 | |
| 186 | // Not enough components |
| 187 | BOOST_CHECK_EQUAL("/second/last", name.getSubName(1, 10)); |
| 188 | BOOST_CHECK_EQUAL("/last", name.getSubName(-1, 10)); |
| 189 | |
| 190 | // Start before first |
| 191 | BOOST_CHECK_EQUAL("/first/second", name.getSubName(-10, 2)); |
| 192 | BOOST_CHECK_EQUAL("/first/second/last", name.getSubName(-10, 10)); |
| 193 | } |
| 194 | |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 195 | // ---- iterators ---- |
| 196 | |
| 197 | BOOST_AUTO_TEST_CASE(ForwardIterator) |
| 198 | { |
| 199 | name::Component comps[] { |
| 200 | name::Component("A"), |
| 201 | name::Component("B"), |
| 202 | name::Component("C"), |
| 203 | name::Component("D") |
| 204 | }; |
| 205 | |
| 206 | Name n0; |
| 207 | BOOST_CHECK_EQUAL_COLLECTIONS(n0.begin(), n0.end(), comps, comps + 0); |
| 208 | |
| 209 | Name n4("/A/B/C/D"); |
| 210 | BOOST_CHECK_EQUAL_COLLECTIONS(n4.begin(), n4.end(), comps, comps + 4); |
| 211 | } |
| 212 | |
| 213 | BOOST_AUTO_TEST_CASE(ReverseIterator) |
| 214 | { |
| 215 | name::Component comps[] { |
| 216 | name::Component("D"), |
| 217 | name::Component("C"), |
| 218 | name::Component("B"), |
| 219 | name::Component("A") |
| 220 | }; |
| 221 | |
| 222 | Name n0; |
| 223 | BOOST_CHECK_EQUAL_COLLECTIONS(n0.rbegin(), n0.rend(), comps, comps + 0); |
| 224 | |
| 225 | Name n4("/A/B/C/D"); |
| 226 | BOOST_CHECK_EQUAL_COLLECTIONS(n4.rbegin(), n4.rend(), comps, comps + 4); |
| 227 | } |
| 228 | |
| 229 | // ---- modifiers ---- |
| 230 | |
Davide Pesavento | adc9aa2 | 2019-06-30 19:00:20 -0400 | [diff] [blame] | 231 | BOOST_AUTO_TEST_CASE(SetComponent) |
| 232 | { |
| 233 | Name name("/A/B"); |
| 234 | BOOST_CHECK_EQUAL(name.wireEncode(), "0706 080141 080142"_block); |
| 235 | BOOST_CHECK_EQUAL(name.hasWire(), true); |
| 236 | |
| 237 | // pass by const lvalue ref |
| 238 | const Component c("C"); |
| 239 | name.set(0, c); |
| 240 | BOOST_CHECK_EQUAL(name.hasWire(), false); |
| 241 | BOOST_CHECK_EQUAL(name.wireEncode(), "0706 080143 080142"_block); |
| 242 | |
| 243 | // pass by rvalue ref |
| 244 | Component d("D"); |
| 245 | name.set(1, std::move(d)); |
| 246 | BOOST_CHECK_EQUAL(name.hasWire(), false); |
| 247 | BOOST_CHECK_EQUAL(name.wireEncode(), "0706 080143 080144"_block); |
| 248 | |
| 249 | // negative index |
| 250 | name.set(-1, Component("E")); |
| 251 | BOOST_CHECK_EQUAL(name.wireEncode(), "0706 080143 080145"_block); |
| 252 | } |
| 253 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 254 | BOOST_AUTO_TEST_CASE(AppendComponent) |
Joao Pereira | 6f7cfd0 | 2015-06-15 11:36:26 -0400 | [diff] [blame] | 255 | { |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 256 | Name name; |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 257 | BOOST_CHECK_EQUAL(name.wireEncode(), "0700"_block); |
Ashlesh Gawande | 7dffab6 | 2017-12-21 16:40:53 -0600 | [diff] [blame] | 258 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 259 | name.append(Component("Emid")); |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 260 | BOOST_CHECK_EQUAL(name.wireEncode(), "0706 0804456D6964"_block); |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 261 | |
Davide Pesavento | df8fd8a | 2022-02-21 20:04:21 -0500 | [diff] [blame] | 262 | name.append(25042, {'P', '3'}); |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 263 | BOOST_CHECK_EQUAL(name.wireEncode(), "070C 0804456D6964 FD61D2025033"_block); |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 264 | |
Davide Pesavento | 2f92b6e | 2022-04-10 16:42:01 -0400 | [diff] [blame] | 265 | const uint8_t arr[] = {'.'}; |
| 266 | name.append(arr); |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 267 | BOOST_CHECK_EQUAL(name.wireEncode(), "070F 0804456D6964 FD61D2025033 08012E"_block); |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 268 | |
Davide Pesavento | 2f92b6e | 2022-04-10 16:42:01 -0400 | [diff] [blame] | 269 | const std::vector<uint8_t> vec{0x28, 0xF0, 0xA3, 0x6B}; |
| 270 | name.append(16, vec.begin(), vec.end()); |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 271 | BOOST_CHECK_EQUAL(name.wireEncode(), "0715 0804456D6964 FD61D2025033 08012E 100428F0A36B"_block); |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 272 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 273 | name.clear(); |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 274 | BOOST_CHECK_EQUAL(name.wireEncode(), "0700"_block); |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 275 | |
Davide Pesavento | 2f92b6e | 2022-04-10 16:42:01 -0400 | [diff] [blame] | 276 | name.append(vec.begin(), vec.end()); |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 277 | BOOST_CHECK_EQUAL(name.wireEncode(), "0706 080428F0A36B"_block); |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 278 | |
| 279 | name.append("xKh"); |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 280 | BOOST_CHECK_EQUAL(name.wireEncode(), "070B 080428F0A36B 0803784B68"_block); |
Joao Pereira | 6f7cfd0 | 2015-06-15 11:36:26 -0400 | [diff] [blame] | 281 | } |
| 282 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 283 | BOOST_AUTO_TEST_CASE(AppendPartialName) |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 284 | { |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 285 | Name name("/A/B"); |
| 286 | name.append(PartialName("/6=C/D")) |
| 287 | .append(PartialName("/E")); |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 288 | BOOST_CHECK_EQUAL(name.wireEncode(), "070F 080141 080142 060143 080144 080145"_block); |
Davide Pesavento | adc9aa2 | 2019-06-30 19:00:20 -0400 | [diff] [blame] | 289 | |
| 290 | name = "/A/B"; |
| 291 | name.append(name); |
| 292 | BOOST_CHECK_EQUAL(name.wireEncode(), "070C 080141 080142 080141 080142"_block); |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | BOOST_AUTO_TEST_CASE(AppendNumber) |
| 296 | { |
| 297 | Name name; |
| 298 | for (uint32_t i = 0; i < 10; i++) { |
| 299 | name.appendNumber(i); |
| 300 | } |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 301 | BOOST_CHECK_EQUAL(name.size(), 10); |
| 302 | |
| 303 | for (uint32_t i = 0; i < 10; i++) { |
| 304 | BOOST_CHECK_EQUAL(name[i].toNumber(), i); |
| 305 | } |
| 306 | } |
| 307 | |
Davide Pesavento | adc9aa2 | 2019-06-30 19:00:20 -0400 | [diff] [blame] | 308 | BOOST_AUTO_TEST_CASE(AppendParametersSha256Digest) |
| 309 | { |
| 310 | auto digest = make_shared<Buffer>(32); |
| 311 | |
| 312 | Name name("/P"); |
Davide Pesavento | 765abc9 | 2021-12-27 00:44:04 -0500 | [diff] [blame] | 313 | name.appendParametersSha256Digest(digest); // ConstBufferPtr overload |
Davide Pesavento | adc9aa2 | 2019-06-30 19:00:20 -0400 | [diff] [blame] | 314 | BOOST_CHECK_EQUAL(name.wireEncode(), |
| 315 | "0725 080150 02200000000000000000000000000000000000000000000000000000000000000000"_block); |
| 316 | |
| 317 | name = "/P"; |
Davide Pesavento | 765abc9 | 2021-12-27 00:44:04 -0500 | [diff] [blame] | 318 | name.appendParametersSha256Digest(*digest); // span overload |
Davide Pesavento | adc9aa2 | 2019-06-30 19:00:20 -0400 | [diff] [blame] | 319 | BOOST_CHECK_EQUAL(name.wireEncode(), |
| 320 | "0725 080150 02200000000000000000000000000000000000000000000000000000000000000000"_block); |
| 321 | |
| 322 | name = "/P"; |
| 323 | name.appendParametersSha256DigestPlaceholder(); |
| 324 | BOOST_CHECK_EQUAL(name.wireEncode(), |
| 325 | "0725 080150 0220E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855"_block); |
| 326 | } |
| 327 | |
Davide Pesavento | 21ee899 | 2022-02-25 20:46:04 -0500 | [diff] [blame] | 328 | BOOST_AUTO_TEST_CASE(AppendTypedComponent) |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 329 | { |
| 330 | // TestNameComponent/NamingConvention provides additional coverage for these methods, |
Davide Pesavento | 21ee899 | 2022-02-25 20:46:04 -0500 | [diff] [blame] | 331 | // including verification of the wire format. |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 332 | |
| 333 | Name name; |
| 334 | uint64_t number; |
| 335 | |
Davide Pesavento | 21ee899 | 2022-02-25 20:46:04 -0500 | [diff] [blame] | 336 | BOOST_CHECK_NO_THROW(number = name.appendSegment(30923).at(-1).toSegment()); |
| 337 | BOOST_TEST(number == 30923); |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 338 | |
Davide Pesavento | 21ee899 | 2022-02-25 20:46:04 -0500 | [diff] [blame] | 339 | BOOST_CHECK_NO_THROW(number = name.appendByteOffset(41880).at(-1).toByteOffset()); |
| 340 | BOOST_TEST(number == 41880); |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 341 | |
Davide Pesavento | 21ee899 | 2022-02-25 20:46:04 -0500 | [diff] [blame] | 342 | auto before = time::toUnixTimestamp(time::system_clock::now()); |
| 343 | BOOST_CHECK_NO_THROW(number = name.appendVersion().at(-1).toVersion()); |
| 344 | auto after = time::toUnixTimestamp(time::system_clock::now()); |
| 345 | BOOST_TEST(number >= before.count()); |
| 346 | BOOST_TEST(number <= after.count()); |
| 347 | |
| 348 | BOOST_CHECK_NO_THROW(number = name.appendVersion(25912).at(-1).toVersion()); |
| 349 | BOOST_TEST(number == 25912); |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 350 | |
Davide Pesavento | 46cdf90 | 2020-06-08 16:38:23 -0400 | [diff] [blame] | 351 | const auto tp = time::system_clock::now(); |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 352 | time::system_clock::TimePoint tp2; |
Davide Pesavento | 21ee899 | 2022-02-25 20:46:04 -0500 | [diff] [blame] | 353 | BOOST_CHECK_NO_THROW(tp2 = name.appendTimestamp(tp).at(-1).toTimestamp()); |
| 354 | BOOST_TEST(time::abs(tp2 - tp) <= 1_us); |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 355 | |
Davide Pesavento | 21ee899 | 2022-02-25 20:46:04 -0500 | [diff] [blame] | 356 | BOOST_CHECK_NO_THROW(number = name.appendSequenceNumber(11676).at(-1).toSequenceNumber()); |
| 357 | BOOST_TEST(number == 11676); |
| 358 | |
| 359 | name.appendKeyword({0xab, 0xcd, 0xef}); |
| 360 | BOOST_TEST(name.at(-1) == Component::fromEscapedString("32=%AB%CD%EF")); |
| 361 | |
| 362 | name.appendKeyword("test-keyword"); |
| 363 | BOOST_TEST(name.at(-1) == Component::fromEscapedString("32=test-keyword")); |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 364 | } |
| 365 | |
Davide Pesavento | adc9aa2 | 2019-06-30 19:00:20 -0400 | [diff] [blame] | 366 | BOOST_AUTO_TEST_CASE(EraseComponent) |
| 367 | { |
| 368 | Name name("/A/B/C"); |
| 369 | BOOST_CHECK_EQUAL(name.wireEncode(), "0709 080141 080142 080143"_block); |
| 370 | BOOST_CHECK_EQUAL(name.hasWire(), true); |
| 371 | |
Davide Pesavento | 21ee899 | 2022-02-25 20:46:04 -0500 | [diff] [blame] | 372 | name.erase(-2); |
Davide Pesavento | adc9aa2 | 2019-06-30 19:00:20 -0400 | [diff] [blame] | 373 | BOOST_CHECK_EQUAL(name.size(), 2); |
| 374 | BOOST_CHECK_EQUAL(name.hasWire(), false); |
| 375 | BOOST_CHECK_EQUAL(name.wireEncode(), "0706 080141 080143"_block); |
| 376 | |
Davide Pesavento | 21ee899 | 2022-02-25 20:46:04 -0500 | [diff] [blame] | 377 | name.erase(1); |
Davide Pesavento | adc9aa2 | 2019-06-30 19:00:20 -0400 | [diff] [blame] | 378 | BOOST_CHECK_EQUAL(name.size(), 1); |
| 379 | BOOST_CHECK_EQUAL(name.hasWire(), false); |
| 380 | BOOST_CHECK_EQUAL(name.wireEncode(), "0703 080141"_block); |
Davide Pesavento | 21ee899 | 2022-02-25 20:46:04 -0500 | [diff] [blame] | 381 | |
| 382 | name.erase(0); |
| 383 | BOOST_CHECK_EQUAL(name.size(), 0); |
| 384 | BOOST_CHECK_EQUAL(name.hasWire(), false); |
| 385 | BOOST_CHECK_EQUAL(name.wireEncode(), "0700"_block); |
Davide Pesavento | adc9aa2 | 2019-06-30 19:00:20 -0400 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | BOOST_AUTO_TEST_CASE(Clear) |
| 389 | { |
| 390 | Name name("/A/B/C"); |
| 391 | BOOST_CHECK_EQUAL(name.empty(), false); |
| 392 | name.clear(); |
| 393 | BOOST_CHECK_EQUAL(name.empty(), true); |
| 394 | BOOST_CHECK(name.begin() == name.end()); |
| 395 | } |
| 396 | |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 397 | // ---- algorithms ---- |
| 398 | |
| 399 | BOOST_AUTO_TEST_CASE(GetSuccessor) |
| 400 | { |
Junxiao Shi | cf0aff8 | 2018-07-23 06:42:13 -0600 | [diff] [blame] | 401 | BOOST_CHECK_EQUAL(Name().getSuccessor(), "/sha256digest=0000000000000000000000000000000000000000000000000000000000000000"); |
| 402 | BOOST_CHECK_EQUAL(Name("/sha256digest=0000000000000000000000000000000000000000000000000000000000000000").getSuccessor(), |
| 403 | "/sha256digest=0000000000000000000000000000000000000000000000000000000000000001"); |
| 404 | BOOST_CHECK_EQUAL(Name("/sha256digest=ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").getSuccessor(), |
Junxiao Shi | 4053bd5 | 2018-08-16 13:39:25 -0600 | [diff] [blame] | 405 | "/params-sha256=0000000000000000000000000000000000000000000000000000000000000000"); |
| 406 | BOOST_CHECK_EQUAL(Name("/params-sha256=0000000000000000000000000000000000000000000000000000000000000000").getSuccessor(), |
| 407 | "/params-sha256=0000000000000000000000000000000000000000000000000000000000000001"); |
| 408 | BOOST_CHECK_EQUAL(Name("/params-sha256=ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").getSuccessor(), |
| 409 | "/3=..."); |
Junxiao Shi | cf0aff8 | 2018-07-23 06:42:13 -0600 | [diff] [blame] | 410 | BOOST_CHECK_EQUAL(Name("/P/A").getSuccessor(), "/P/B"); |
| 411 | BOOST_CHECK_EQUAL(Name("/P/AAA").getSuccessor(), "/P/AAB"); |
| 412 | BOOST_CHECK_EQUAL(Name("/Q/...").getSuccessor(), "/Q/%00"); |
| 413 | BOOST_CHECK_EQUAL(Name("/Q/%FF").getSuccessor(), "/Q/%00%00"); |
| 414 | BOOST_CHECK_EQUAL(Name("/Q/%FE%FF").getSuccessor(), "/Q/%FF%00"); |
| 415 | BOOST_CHECK_EQUAL(Name("/Q/%FF%FF").getSuccessor(), "/Q/%00%00%00"); |
| 416 | BOOST_CHECK_EQUAL(Name("/P/3=A").getSuccessor(), "/P/3=B"); |
| 417 | BOOST_CHECK_EQUAL(Name("/P/3=AAA").getSuccessor(), "/P/3=AAB"); |
| 418 | BOOST_CHECK_EQUAL(Name("/Q/3=...").getSuccessor(), "/Q/3=%00"); |
| 419 | BOOST_CHECK_EQUAL(Name("/Q/3=%FF").getSuccessor(), "/Q/3=%00%00"); |
| 420 | BOOST_CHECK_EQUAL(Name("/Q/3=%FE%FF").getSuccessor(), "/Q/3=%FF%00"); |
| 421 | BOOST_CHECK_EQUAL(Name("/Q/3=%FF%FF").getSuccessor(), "/Q/3=%00%00%00"); |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 422 | } |
| 423 | |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 424 | BOOST_AUTO_TEST_CASE(IsPrefixOf) |
| 425 | { |
| 426 | BOOST_CHECK(Name("/").isPrefixOf("/")); |
| 427 | BOOST_CHECK(Name("/").isPrefixOf("/sha256digest=0000000000000000000000000000000000000000000000000000000000000000")); |
Junxiao Shi | 4053bd5 | 2018-08-16 13:39:25 -0600 | [diff] [blame] | 428 | BOOST_CHECK(Name("/").isPrefixOf("/params-sha256=ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); |
| 429 | BOOST_CHECK(Name("/").isPrefixOf("/3=D")); |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 430 | BOOST_CHECK(Name("/").isPrefixOf("/F")); |
| 431 | BOOST_CHECK(Name("/").isPrefixOf("/21426=AA")); |
| 432 | |
| 433 | BOOST_CHECK(Name("/B").isPrefixOf("/B")); |
| 434 | BOOST_CHECK(Name("/B").isPrefixOf("/B/sha256digest=0000000000000000000000000000000000000000000000000000000000000000")); |
Junxiao Shi | 4053bd5 | 2018-08-16 13:39:25 -0600 | [diff] [blame] | 435 | BOOST_CHECK(Name("/").isPrefixOf("/B/params-sha256=ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); |
| 436 | BOOST_CHECK(Name("/B").isPrefixOf("/B/3=D")); |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 437 | BOOST_CHECK(Name("/B").isPrefixOf("/B/F")); |
| 438 | BOOST_CHECK(Name("/B").isPrefixOf("/B/21426=AA")); |
| 439 | |
| 440 | BOOST_CHECK(!Name("/C").isPrefixOf("/")); |
| 441 | BOOST_CHECK(!Name("/C").isPrefixOf("/sha256digest=0000000000000000000000000000000000000000000000000000000000000000")); |
Junxiao Shi | 4053bd5 | 2018-08-16 13:39:25 -0600 | [diff] [blame] | 442 | BOOST_CHECK(Name("/").isPrefixOf("/params-sha256=ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); |
| 443 | BOOST_CHECK(!Name("/C").isPrefixOf("/3=D")); |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 444 | BOOST_CHECK(!Name("/C").isPrefixOf("/F")); |
| 445 | BOOST_CHECK(!Name("/C").isPrefixOf("/21426=AA")); |
| 446 | } |
| 447 | |
| 448 | BOOST_AUTO_TEST_CASE(CompareOp) |
| 449 | { |
| 450 | std::vector<Name> names = { |
| 451 | Name("/"), |
| 452 | Name("/sha256digest=0000000000000000000000000000000000000000000000000000000000000000"), |
| 453 | Name("/sha256digest=0000000000000000000000000000000000000000000000000000000000000001"), |
| 454 | Name("/sha256digest=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"), |
Junxiao Shi | 4053bd5 | 2018-08-16 13:39:25 -0600 | [diff] [blame] | 455 | Name("/params-sha256=0000000000000000000000000000000000000000000000000000000000000000"), |
| 456 | Name("/params-sha256=0000000000000000000000000000000000000000000000000000000000000001"), |
| 457 | Name("/params-sha256=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"), |
| 458 | Name("/3=..."), |
| 459 | Name("/3=D"), |
| 460 | Name("/3=F"), |
| 461 | Name("/3=AA"), |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 462 | Name("/..."), |
| 463 | Name("/D"), |
| 464 | Name("/D/sha256digest=0000000000000000000000000000000000000000000000000000000000000000"), |
| 465 | Name("/D/sha256digest=0000000000000000000000000000000000000000000000000000000000000001"), |
| 466 | Name("/D/sha256digest=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"), |
Junxiao Shi | 4053bd5 | 2018-08-16 13:39:25 -0600 | [diff] [blame] | 467 | Name("/D/params-sha256=0000000000000000000000000000000000000000000000000000000000000000"), |
| 468 | Name("/D/params-sha256=0000000000000000000000000000000000000000000000000000000000000001"), |
| 469 | Name("/D/params-sha256=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"), |
| 470 | Name("/D/3=..."), |
| 471 | Name("/D/3=D"), |
| 472 | Name("/D/3=F"), |
| 473 | Name("/D/3=AA"), |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 474 | Name("/D/..."), |
| 475 | Name("/D/D"), |
| 476 | Name("/D/F"), |
| 477 | Name("/D/AA"), |
| 478 | Name("/D/21426=..."), |
| 479 | Name("/D/21426=D"), |
| 480 | Name("/D/21426=F"), |
| 481 | Name("/D/21426=AA"), |
| 482 | Name("/F"), |
| 483 | Name("/AA"), |
| 484 | Name("/21426=..."), |
| 485 | Name("/21426=D"), |
| 486 | Name("/21426=F"), |
| 487 | Name("/21426=AA"), |
| 488 | }; |
| 489 | |
| 490 | for (size_t i = 0; i < names.size(); ++i) { |
| 491 | for (size_t j = 0; j < names.size(); ++j) { |
| 492 | Name lhs = names[i]; |
| 493 | Name rhs = names[j]; |
| 494 | BOOST_CHECK_EQUAL(lhs == rhs, i == j); |
| 495 | BOOST_CHECK_EQUAL(lhs != rhs, i != j); |
| 496 | BOOST_CHECK_EQUAL(lhs < rhs, i < j); |
| 497 | BOOST_CHECK_EQUAL(lhs <= rhs, i <= j); |
| 498 | BOOST_CHECK_EQUAL(lhs > rhs, i > j); |
| 499 | BOOST_CHECK_EQUAL(lhs >= rhs, i >= j); |
| 500 | } |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | BOOST_AUTO_TEST_CASE(CompareFunc) |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 505 | { |
| 506 | BOOST_CHECK_EQUAL(Name("/A") .compare(Name("/A")), 0); |
| 507 | BOOST_CHECK_LT (Name("/A") .compare(Name("/B")), 0); |
| 508 | BOOST_CHECK_GT (Name("/B") .compare(Name("/A")), 0); |
| 509 | BOOST_CHECK_LT (Name("/A") .compare(Name("/AA")), 0); |
| 510 | BOOST_CHECK_GT (Name("/AA") .compare(Name("/A")), 0); |
| 511 | BOOST_CHECK_LT (Name("/A") .compare(Name("/A/C")), 0); |
| 512 | BOOST_CHECK_GT (Name("/A/C").compare(Name("/A")), 0); |
| 513 | |
| 514 | BOOST_CHECK_EQUAL(Name("/Z/A/Y") .compare(1, 1, Name("/A")), 0); |
| 515 | BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/B")), 0); |
| 516 | BOOST_CHECK_GT (Name("/Z/B/Y") .compare(1, 1, Name("/A")), 0); |
| 517 | BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/AA")), 0); |
| 518 | BOOST_CHECK_GT (Name("/Z/AA/Y") .compare(1, 1, Name("/A")), 0); |
| 519 | BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/A/C")), 0); |
| 520 | BOOST_CHECK_GT (Name("/Z/A/C/Y").compare(1, 2, Name("/A")), 0); |
| 521 | |
| 522 | BOOST_CHECK_EQUAL(Name("/Z/A") .compare(1, Name::npos, Name("/A")), 0); |
| 523 | BOOST_CHECK_LT (Name("/Z/A") .compare(1, Name::npos, Name("/B")), 0); |
| 524 | BOOST_CHECK_GT (Name("/Z/B") .compare(1, Name::npos, Name("/A")), 0); |
| 525 | BOOST_CHECK_LT (Name("/Z/A") .compare(1, Name::npos, Name("/AA")), 0); |
| 526 | BOOST_CHECK_GT (Name("/Z/AA") .compare(1, Name::npos, Name("/A")), 0); |
| 527 | BOOST_CHECK_LT (Name("/Z/A") .compare(1, Name::npos, Name("/A/C")), 0); |
| 528 | BOOST_CHECK_GT (Name("/Z/A/C").compare(1, Name::npos, Name("/A")), 0); |
| 529 | |
| 530 | BOOST_CHECK_EQUAL(Name("/Z/A/Y") .compare(1, 1, Name("/X/A/W"), 1, 1), 0); |
| 531 | BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/B/W"), 1, 1), 0); |
| 532 | BOOST_CHECK_GT (Name("/Z/B/Y") .compare(1, 1, Name("/X/A/W"), 1, 1), 0); |
| 533 | BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/AA/W"), 1, 1), 0); |
| 534 | BOOST_CHECK_GT (Name("/Z/AA/Y") .compare(1, 1, Name("/X/A/W"), 1, 1), 0); |
| 535 | BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/A/C/W"), 1, 2), 0); |
| 536 | BOOST_CHECK_GT (Name("/Z/A/C/Y").compare(1, 2, Name("/X/A/W"), 1, 1), 0); |
| 537 | |
| 538 | BOOST_CHECK_EQUAL(Name("/Z/A/Y") .compare(1, 1, Name("/X/A"), 1), 0); |
| 539 | BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/B"), 1), 0); |
| 540 | BOOST_CHECK_GT (Name("/Z/B/Y") .compare(1, 1, Name("/X/A"), 1), 0); |
| 541 | BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/AA"), 1), 0); |
| 542 | BOOST_CHECK_GT (Name("/Z/AA/Y") .compare(1, 1, Name("/X/A"), 1), 0); |
| 543 | BOOST_CHECK_LT (Name("/Z/A/Y") .compare(1, 1, Name("/X/A/C"), 1), 0); |
| 544 | BOOST_CHECK_GT (Name("/Z/A/C/Y").compare(1, 2, Name("/X/A"), 1), 0); |
| 545 | } |
| 546 | |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 547 | BOOST_AUTO_TEST_CASE(UnorderedMap) |
Alexander Afanasyev | 4f512fb | 2016-05-18 10:47:53 -0700 | [diff] [blame] | 548 | { |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 549 | std::unordered_map<Name, int> map; |
| 550 | Name name1("/1"); |
| 551 | Name name2("/2"); |
| 552 | Name name3("/3"); |
| 553 | map[name1] = 1; |
| 554 | map[name2] = 2; |
| 555 | map[name3] = 3; |
Alexander Afanasyev | 4f512fb | 2016-05-18 10:47:53 -0700 | [diff] [blame] | 556 | |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 557 | BOOST_CHECK_EQUAL(map[name1], 1); |
| 558 | BOOST_CHECK_EQUAL(map[name2], 2); |
| 559 | BOOST_CHECK_EQUAL(map[name3], 3); |
Alexander Afanasyev | 4f512fb | 2016-05-18 10:47:53 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 562 | BOOST_AUTO_TEST_SUITE_END() // TestName |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 563 | |
Junxiao Shi | 6bf0adf | 2015-02-15 13:54:56 -0700 | [diff] [blame] | 564 | } // namespace tests |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 565 | } // namespace ndn |