Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [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 | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 3 | * Copyright (c) 2013-2018 Regents of the University of California. |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 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. |
| 20 | */ |
| 21 | |
| 22 | #include "name-component.hpp" |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 23 | #include "name.hpp" |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 24 | |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 25 | #include "block-literal.hpp" |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 26 | #include "boost-test.hpp" |
| 27 | #include <boost/mpl/vector.hpp> |
| 28 | |
| 29 | namespace ndn { |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 30 | namespace name { |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 31 | namespace tests { |
| 32 | |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 33 | using namespace ndn::tests; |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 34 | |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 35 | BOOST_AUTO_TEST_SUITE(TestNameComponent) |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 36 | |
| 37 | BOOST_AUTO_TEST_SUITE(Decode) |
| 38 | |
| 39 | BOOST_AUTO_TEST_CASE(Generic) |
| 40 | { |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 41 | Component comp("0807 6E646E2D637878"_block); |
| 42 | BOOST_CHECK_EQUAL(comp.type(), tlv::GenericNameComponent); |
| 43 | BOOST_CHECK_EQUAL(comp.toUri(), "ndn-cxx"); |
| 44 | BOOST_CHECK_EQUAL(Component::fromEscapedString("ndn-cxx"), comp); |
| 45 | |
| 46 | comp.wireDecode("0800"_block); |
| 47 | BOOST_CHECK_EQUAL(comp.toUri(), "..."); |
| 48 | BOOST_CHECK_EQUAL(Component::fromEscapedString("..."), comp); |
| 49 | BOOST_CHECK_EQUAL(Component::fromEscapedString(".%2E."), comp); |
| 50 | |
| 51 | comp.wireDecode("0801 2E"_block); |
| 52 | BOOST_CHECK_EQUAL(comp.toUri(), "...."); |
| 53 | BOOST_CHECK_EQUAL(Component::fromEscapedString("...."), comp); |
| 54 | BOOST_CHECK_EQUAL(Component::fromEscapedString("%2E..%2E"), comp); |
| 55 | |
| 56 | comp.wireDecode("0803 2E412E"_block); |
| 57 | BOOST_CHECK_EQUAL(comp.toUri(), ".A."); |
| 58 | BOOST_CHECK_EQUAL(Component::fromEscapedString(".A."), comp); |
| 59 | |
| 60 | comp.wireDecode("0807 666F6F25626172"_block); |
| 61 | BOOST_CHECK_EQUAL(comp.toUri(), "foo%25bar"); |
| 62 | BOOST_CHECK_EQUAL(Component::fromEscapedString("foo%25bar"), comp); |
| 63 | |
| 64 | comp.wireDecode("0804 2D2E5F7E"_block); |
| 65 | BOOST_CHECK_EQUAL(comp.toUri(), "-._~"); |
| 66 | BOOST_CHECK_EQUAL(Component::fromEscapedString("-._~"), comp); |
| 67 | |
| 68 | comp = Component(":/?#[]@"); |
| 69 | BOOST_CHECK_EQUAL(comp.toUri(), "%3A%2F%3F%23%5B%5D%40"); |
| 70 | BOOST_CHECK_EQUAL(Component::fromEscapedString("%3A%2F%3F%23%5B%5D%40"), comp); |
| 71 | |
| 72 | BOOST_CHECK_THROW(Component::fromEscapedString(""), Component::Error); |
| 73 | BOOST_CHECK_THROW(Component::fromEscapedString("."), Component::Error); |
| 74 | BOOST_CHECK_THROW(Component::fromEscapedString(".."), Component::Error); |
| 75 | BOOST_CHECK_THROW(Component::fromEscapedString("8=A"), Component::Error); |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | BOOST_AUTO_TEST_CASE(Digest) |
| 79 | { |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 80 | std::string uriPrefix = "sha256digest="; |
| 81 | std::string hexLower = "28bad4b5275bd392dbb670c75cf0b66f13f7942b21e80f55c0e86b374753a548"; |
| 82 | std::string hexUpper = "28BAD4B5275BD392DBB670C75CF0B66F13F7942B21E80F55C0E86B374753A548"; |
| 83 | |
| 84 | Component comp("0120 28BAD4B5275BD392DBB670C75CF0B66F13F7942B21E80F55C0E86B374753A548"_block); |
| 85 | BOOST_CHECK_EQUAL(comp.toUri(), uriPrefix + hexLower); |
| 86 | BOOST_CHECK_EQUAL(Component::fromEscapedString(uriPrefix + hexLower), comp); |
| 87 | BOOST_CHECK_EQUAL(Component::fromEscapedString(uriPrefix + hexUpper), comp); |
| 88 | |
| 89 | BOOST_CHECK_THROW(comp.wireDecode("0108 A791806951F25C4D"_block), Component::Error); |
| 90 | BOOST_CHECK_THROW(Component::fromEscapedString(uriPrefix), Component::Error); |
| 91 | BOOST_CHECK_THROW(Component::fromEscapedString(uriPrefix + "=a791806951f25c4d"), |
| 92 | Component::Error); |
| 93 | BOOST_CHECK_THROW(Component::fromEscapedString("1=" + hexLower), Component::Error); |
| 94 | BOOST_CHECK_THROW(Component::fromEscapedString("SHA256DIGEST=" + hexLower), Component::Error); |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 97 | BOOST_AUTO_TEST_CASE(OtherType) |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 98 | { |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 99 | Component comp("0907 6E646E2D637878"_block); |
| 100 | BOOST_CHECK_EQUAL(comp.type(), 0x09); |
| 101 | BOOST_CHECK_EQUAL(comp.toUri(), "9=ndn-cxx"); |
| 102 | BOOST_CHECK_EQUAL(Component::fromEscapedString("9=ndn-cxx"), comp); |
| 103 | |
| 104 | comp.wireDecode("FDFFFF00"_block); |
| 105 | BOOST_CHECK_EQUAL(comp.type(), 0xFFFF); |
| 106 | BOOST_CHECK_EQUAL(comp.toUri(), "65535=..."); |
| 107 | BOOST_CHECK_EQUAL(Component::fromEscapedString("65535=..."), comp); |
| 108 | |
| 109 | comp.wireDecode("FD576501 2E"_block); |
| 110 | BOOST_CHECK_EQUAL(comp.type(), 0x5765); |
| 111 | BOOST_CHECK_EQUAL(comp.toUri(), "22373=...."); |
| 112 | BOOST_CHECK_EQUAL(Component::fromEscapedString("22373=...."), comp); |
| 113 | |
| 114 | BOOST_CHECK_THROW(Component::fromEscapedString("3="), Component::Error); |
| 115 | BOOST_CHECK_THROW(Component::fromEscapedString("3=."), Component::Error); |
| 116 | BOOST_CHECK_THROW(Component::fromEscapedString("3=.."), Component::Error); |
| 117 | } |
| 118 | |
| 119 | BOOST_AUTO_TEST_CASE(InvalidType) |
| 120 | { |
| 121 | Component comp; |
| 122 | BOOST_CHECK_THROW(comp.wireDecode("0001 80"_block), Component::Error); |
| 123 | BOOST_CHECK_THROW(comp.wireDecode("FE0001000001 80"_block), Component::Error); |
| 124 | |
| 125 | BOOST_CHECK_THROW(Component::fromEscapedString("0=A"), Component::Error); |
| 126 | BOOST_CHECK_THROW(Component::fromEscapedString("65536=A"), Component::Error); |
| 127 | BOOST_CHECK_THROW(Component::fromEscapedString("-1=A"), Component::Error); |
| 128 | BOOST_CHECK_THROW(Component::fromEscapedString("+=A"), Component::Error); |
| 129 | BOOST_CHECK_THROW(Component::fromEscapedString("=A"), Component::Error); |
| 130 | BOOST_CHECK_THROW(Component::fromEscapedString("0x1=A"), Component::Error); |
| 131 | BOOST_CHECK_THROW(Component::fromEscapedString("Z=A"), Component::Error); |
| 132 | BOOST_CHECK_THROW(Component::fromEscapedString("09=A"), Component::Error); |
| 133 | BOOST_CHECK_THROW(Component::fromEscapedString("0x2=A"), Component::Error); |
| 134 | BOOST_CHECK_THROW(Component::fromEscapedString("+9=A"), Component::Error); |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | BOOST_AUTO_TEST_SUITE_END() // Decode |
| 138 | |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 139 | BOOST_AUTO_TEST_CASE(Compare) |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 140 | { |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 141 | std::vector<Component> comps = { |
| 142 | Component("0120 0000000000000000000000000000000000000000000000000000000000000000"_block), |
| 143 | Component("0120 0000000000000000000000000000000000000000000000000000000000000001"_block), |
| 144 | Component("0120 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"_block), |
| 145 | Component(0x02), |
| 146 | Component("0201 44"_block), |
| 147 | Component("0201 46"_block), |
| 148 | Component("0202 4141"_block), |
| 149 | Component(), |
| 150 | Component("D"), |
| 151 | Component("F"), |
| 152 | Component("AA"), |
| 153 | Component(0x53B2), |
| 154 | Component("FD53B201 44"_block), |
| 155 | Component("FD53B201 46"_block), |
| 156 | Component("FD53B202 4141"_block), |
| 157 | }; |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 158 | |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 159 | for (size_t i = 0; i < comps.size(); ++i) { |
| 160 | for (size_t j = 0; j < comps.size(); ++j) { |
| 161 | Component lhs = comps[i]; |
| 162 | Component rhs = comps[j]; |
| 163 | BOOST_CHECK_EQUAL(lhs == rhs, i == j); |
| 164 | BOOST_CHECK_EQUAL(lhs != rhs, i != j); |
| 165 | BOOST_CHECK_EQUAL(lhs < rhs, i < j); |
| 166 | BOOST_CHECK_EQUAL(lhs <= rhs, i <= j); |
| 167 | BOOST_CHECK_EQUAL(lhs > rhs, i > j); |
| 168 | BOOST_CHECK_EQUAL(lhs >= rhs, i >= j); |
| 169 | } |
| 170 | } |
Davide Pesavento | 08378cb | 2018-02-01 16:10:54 -0500 | [diff] [blame] | 171 | } |
| 172 | |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 173 | BOOST_AUTO_TEST_SUITE(CreateFromIterators) // Bug 2490 |
| 174 | |
| 175 | typedef boost::mpl::vector< |
| 176 | std::vector<uint8_t>, |
| 177 | std::list<uint8_t>, |
| 178 | std::vector<int8_t>, |
| 179 | std::list<int8_t> |
| 180 | > ContainerTypes; |
| 181 | |
| 182 | BOOST_AUTO_TEST_CASE_TEMPLATE(ZeroOctet, T, ContainerTypes) |
| 183 | { |
| 184 | T bytes; |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 185 | Component c(bytes.begin(), bytes.end()); |
| 186 | BOOST_CHECK_EQUAL(c.type(), tlv::GenericNameComponent); |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 187 | BOOST_CHECK_EQUAL(c.value_size(), 0); |
| 188 | BOOST_CHECK_EQUAL(c.size(), 2); |
| 189 | } |
| 190 | |
| 191 | BOOST_AUTO_TEST_CASE_TEMPLATE(OneOctet, T, ContainerTypes) |
| 192 | { |
| 193 | T bytes{1}; |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 194 | Component c(0x09, bytes.begin(), bytes.end()); |
| 195 | BOOST_CHECK_EQUAL(c.type(), 0x09); |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 196 | BOOST_CHECK_EQUAL(c.value_size(), 1); |
| 197 | BOOST_CHECK_EQUAL(c.size(), 3); |
| 198 | } |
| 199 | |
| 200 | BOOST_AUTO_TEST_CASE_TEMPLATE(FourOctets, T, ContainerTypes) |
| 201 | { |
| 202 | T bytes{1, 2, 3, 4}; |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 203 | Component c(0xFCEC, bytes.begin(), bytes.end()); |
| 204 | BOOST_CHECK_EQUAL(c.type(), 0xFCEC); |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 205 | BOOST_CHECK_EQUAL(c.value_size(), 4); |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 206 | BOOST_CHECK_EQUAL(c.size(), 8); |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | BOOST_AUTO_TEST_SUITE_END() // CreateFromIterators |
| 210 | |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 211 | BOOST_AUTO_TEST_SUITE(NamingConvention) |
| 212 | |
| 213 | template<typename ArgType> |
| 214 | struct ConventionTest |
| 215 | { |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 216 | function<Component(ArgType)> makeComponent; |
| 217 | function<ArgType(const Component&)> getValue; |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 218 | function<Name&(Name&, ArgType)> append; |
| 219 | Name expected; |
| 220 | ArgType value; |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 221 | function<bool(const Component&)> isComponent; |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 222 | }; |
| 223 | |
| 224 | class NumberWithMarker |
| 225 | { |
| 226 | public: |
| 227 | ConventionTest<uint64_t> |
| 228 | operator()() const |
| 229 | { |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 230 | return {bind(&Component::fromNumberWithMarker, 0xAA, _1), |
| 231 | bind(&Component::toNumberWithMarker, _1, 0xAA), |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 232 | bind(&Name::appendNumberWithMarker, _1, 0xAA, _2), |
| 233 | Name("/%AA%03%E8"), |
| 234 | 1000, |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 235 | bind(&Component::isNumberWithMarker, _1, 0xAA)}; |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 236 | } |
| 237 | }; |
| 238 | |
| 239 | class Segment |
| 240 | { |
| 241 | public: |
| 242 | ConventionTest<uint64_t> |
| 243 | operator()() const |
| 244 | { |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 245 | return {&Component::fromSegment, |
| 246 | bind(&Component::toSegment, _1), |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 247 | bind(&Name::appendSegment, _1, _2), |
| 248 | Name("/%00%27%10"), |
| 249 | 10000, |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 250 | bind(&Component::isSegment, _1)}; |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 251 | } |
| 252 | }; |
| 253 | |
| 254 | class SegmentOffset |
| 255 | { |
| 256 | public: |
| 257 | ConventionTest<uint64_t> |
| 258 | operator()() const |
| 259 | { |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 260 | return {&Component::fromSegmentOffset, |
| 261 | bind(&Component::toSegmentOffset, _1), |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 262 | bind(&Name::appendSegmentOffset, _1, _2), |
| 263 | Name("/%FB%00%01%86%A0"), |
| 264 | 100000, |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 265 | bind(&Component::isSegmentOffset, _1)}; |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 266 | } |
| 267 | }; |
| 268 | |
| 269 | class Version |
| 270 | { |
| 271 | public: |
| 272 | ConventionTest<uint64_t> |
| 273 | operator()() const |
| 274 | { |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 275 | return {&Component::fromVersion, |
| 276 | bind(&Component::toVersion, _1), |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 277 | [] (Name& name, uint64_t version) -> Name& { return name.appendVersion(version); }, |
| 278 | Name("/%FD%00%0FB%40"), |
| 279 | 1000000, |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 280 | bind(&Component::isVersion, _1)}; |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 281 | } |
| 282 | }; |
| 283 | |
| 284 | class Timestamp |
| 285 | { |
| 286 | public: |
| 287 | ConventionTest<time::system_clock::TimePoint> |
| 288 | operator()() const |
| 289 | { |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 290 | return {&Component::fromTimestamp, |
| 291 | bind(&Component::toTimestamp, _1), |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 292 | [] (Name& name, time::system_clock::TimePoint t) -> Name& { return name.appendTimestamp(t); }, |
| 293 | Name("/%FC%00%04%7BE%E3%1B%00%00"), |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 294 | time::getUnixEpoch() + 14600_days, // 40 years |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 295 | bind(&Component::isTimestamp, _1)}; |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 296 | } |
| 297 | }; |
| 298 | |
| 299 | class SequenceNumber |
| 300 | { |
| 301 | public: |
| 302 | ConventionTest<uint64_t> |
| 303 | operator()() const |
| 304 | { |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 305 | return {&Component::fromSequenceNumber, |
| 306 | bind(&Component::toSequenceNumber, _1), |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 307 | bind(&Name::appendSequenceNumber, _1, _2), |
| 308 | Name("/%FE%00%98%96%80"), |
| 309 | 10000000, |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 310 | bind(&Component::isSequenceNumber, _1)}; |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 311 | } |
| 312 | }; |
| 313 | |
| 314 | using ConventionTests = boost::mpl::vector< |
| 315 | NumberWithMarker, |
| 316 | Segment, |
| 317 | SegmentOffset, |
| 318 | Version, |
| 319 | Timestamp, |
| 320 | SequenceNumber |
| 321 | >; |
| 322 | |
| 323 | BOOST_AUTO_TEST_CASE_TEMPLATE(Convention, T, ConventionTests) |
| 324 | { |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 325 | Component invalidComponent1; |
| 326 | Component invalidComponent2("1234567890"); |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 327 | |
| 328 | auto test = T()(); |
| 329 | |
| 330 | const Name& expected = test.expected; |
| 331 | BOOST_TEST_MESSAGE("Check " << expected[0].toUri()); |
| 332 | |
| 333 | BOOST_CHECK_EQUAL(expected[0].isGeneric(), true); |
| 334 | |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 335 | Component actualComponent = test.makeComponent(test.value); |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 336 | BOOST_CHECK_EQUAL(actualComponent, expected[0]); |
| 337 | |
| 338 | Name actualName; |
| 339 | test.append(actualName, test.value); |
| 340 | BOOST_CHECK_EQUAL(actualName, expected); |
| 341 | |
| 342 | BOOST_CHECK_EQUAL(test.isComponent(expected[0]), true); |
| 343 | BOOST_CHECK_EQUAL(test.getValue(expected[0]), test.value); |
| 344 | |
| 345 | BOOST_CHECK_EQUAL(test.isComponent(invalidComponent1), false); |
| 346 | BOOST_CHECK_EQUAL(test.isComponent(invalidComponent2), false); |
| 347 | |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 348 | BOOST_CHECK_THROW(test.getValue(invalidComponent1), Component::Error); |
| 349 | BOOST_CHECK_THROW(test.getValue(invalidComponent2), Component::Error); |
Junxiao Shi | 71ff231 | 2017-07-12 13:32:50 +0000 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | BOOST_AUTO_TEST_SUITE_END() // NamingConvention |
| 353 | |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 354 | BOOST_AUTO_TEST_SUITE_END() // TestNameComponent |
| 355 | |
| 356 | } // namespace tests |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 357 | } // namespace name |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 358 | } // namespace ndn |