Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2016 Regents of the University of California. |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [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 "link.hpp" |
| 23 | #include "security/key-chain.hpp" |
| 24 | #include "security/cryptopp.hpp" |
| 25 | #include "encoding/buffer-stream.hpp" |
| 26 | |
| 27 | #include "boost-test.hpp" |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 28 | #include "identity-management-fixture.hpp" |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 29 | |
| 30 | namespace ndn { |
| 31 | namespace tests { |
| 32 | |
| 33 | const uint8_t LinkTest[] = { |
| 34 | 0x06, 0xda, // Data |
| 35 | 0x07, 0x14, // Name |
| 36 | 0x08, 0x05, |
| 37 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 38 | 0x08, 0x03, |
| 39 | 0x6e, 0x64, 0x6e, |
| 40 | 0x08, 0x06, |
| 41 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 42 | 0x14, 0x07, // MetaInfo |
| 43 | 0x18, 0x01, // ContentType |
| 44 | 0x01, |
| 45 | 0x19, 0x02, // FreshnessPeriod |
| 46 | 0x27, 0x10, |
| 47 | 0x15, 0x1a, // Content |
| 48 | 0x1f, 0x0c, // LinkDelegation |
| 49 | 0x1e, 0x01, // LinkPreference |
| 50 | 0x0a, |
| 51 | 0x07, 0x07, // Name |
| 52 | 0x08, 0x05, |
| 53 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 54 | 0x1f, 0x0a, // LinkDelegation |
| 55 | 0x1e, 0x01, // LinkPreference |
| 56 | 0x14, |
| 57 | 0x07, 0x05, // Name |
| 58 | 0x08, 0x03, |
| 59 | 0x6e, 0x64, 0x6e, |
| 60 | 0x16, 0x1b, // SignatureInfo |
| 61 | 0x1b, 0x01, // SignatureType |
| 62 | 0x01, |
| 63 | 0x1c, 0x16, // KeyLocator |
| 64 | 0x07, 0x14, // Name |
| 65 | 0x08, 0x04, |
| 66 | 0x74, 0x65, 0x73, 0x74, |
| 67 | 0x08, 0x03, |
| 68 | 0x6b, 0x65, 0x79, |
| 69 | 0x08, 0x07, |
| 70 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 71 | 0x17, 0x80, // SignatureValue |
| 72 | 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec, |
| 73 | 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6, |
| 74 | 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38, |
| 75 | 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc, |
| 76 | 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf, |
| 77 | 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9, |
| 78 | 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8, |
| 79 | 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7, |
| 80 | 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3, |
| 81 | 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1 |
| 82 | }; |
| 83 | |
| 84 | const uint8_t IncorrectContentTypeLink[] = { |
| 85 | 0x06, 0xda, // Data |
| 86 | 0x07, 0x14, // Name |
| 87 | 0x08, 0x05, |
| 88 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 89 | 0x08, 0x03, |
| 90 | 0x6e, 0x64, 0x6e, |
| 91 | 0x08, 0x06, |
| 92 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 93 | 0x14, 0x07, // MetaInfo |
| 94 | 0x18, 0x01, // ContentType |
| 95 | 0x02, |
| 96 | 0x19, 0x02, // FreshnessPeriod |
| 97 | 0x27, 0x10, |
| 98 | 0x15, 0x1a, // Content |
| 99 | 0x1f, 0x0c, // LinkDelegation |
| 100 | 0x1e, 0x01, // LinkPreference |
| 101 | 0x0a, |
| 102 | 0x07, 0x07, // Name |
| 103 | 0x08, 0x05, |
| 104 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 105 | 0x1f, 0x0a, // LinkDelegation |
| 106 | 0x1e, 0x01, // LinkPreference |
| 107 | 0x14, |
| 108 | 0x07, 0x05, // Name |
| 109 | 0x08, 0x03, |
| 110 | 0x6e, 0x64, 0x6e, |
| 111 | 0x16, 0x1b, // SignatureInfo |
| 112 | 0x1b, 0x01, // SignatureType |
| 113 | 0x01, |
| 114 | 0x1c, 0x16, // KeyLocator |
| 115 | 0x07, 0x14, // Name |
| 116 | 0x08, 0x04, |
| 117 | 0x74, 0x65, 0x73, 0x74, |
| 118 | 0x08, 0x03, |
| 119 | 0x6b, 0x65, 0x79, |
| 120 | 0x08, 0x07, |
| 121 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 122 | 0x17, 0x80, // SignatureValue |
| 123 | 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec, |
| 124 | 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6, |
| 125 | 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38, |
| 126 | 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc, |
| 127 | 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf, |
| 128 | 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9, |
| 129 | 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8, |
| 130 | 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7, |
| 131 | 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3, |
| 132 | 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1 |
| 133 | }; |
| 134 | |
| 135 | const uint8_t MissingPreferenceLink[] = { |
| 136 | 0x06, 0xd7, // Data |
| 137 | 0x07, 0x14, // Name |
| 138 | 0x08, 0x05, |
| 139 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 140 | 0x08, 0x03, |
| 141 | 0x6e, 0x64, 0x6e, |
| 142 | 0x08, 0x06, |
| 143 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 144 | 0x14, 0x07, // MetaInfo |
| 145 | 0x18, 0x01, // ContentType |
| 146 | 0x01, |
| 147 | 0x19, 0x02, // FreshnessPeriod |
| 148 | 0x27, 0x10, |
| 149 | 0x15, 0x17, // Content |
| 150 | 0x1f, 0x09, // LinkDelegation |
| 151 | 0x07, 0x07, // Name |
| 152 | 0x08, 0x05, |
| 153 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 154 | 0x1f, 0x0a, // LinkDelegation |
| 155 | 0x1e, 0x01, // LinkPreference |
| 156 | 0x14, |
| 157 | 0x07, 0x05, // Name |
| 158 | 0x08, 0x03, |
| 159 | 0x6e, 0x64, 0x6e, |
| 160 | 0x16, 0x1b, // SignatureInfo |
| 161 | 0x1b, 0x01, // SignatureType |
| 162 | 0x01, |
| 163 | 0x1c, 0x16, // KeyLocator |
| 164 | 0x07, 0x14, // Name |
| 165 | 0x08, 0x04, |
| 166 | 0x74, 0x65, 0x73, 0x74, |
| 167 | 0x08, 0x03, |
| 168 | 0x6b, 0x65, 0x79, |
| 169 | 0x08, 0x07, |
| 170 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 171 | 0x17, 0x80, // SignatureValue |
| 172 | 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec, |
| 173 | 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6, |
| 174 | 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38, |
| 175 | 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc, |
| 176 | 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf, |
| 177 | 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9, |
| 178 | 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8, |
| 179 | 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7, |
| 180 | 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3, |
| 181 | 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1 |
| 182 | }; |
| 183 | |
| 184 | const uint8_t MissingNameLink[] = { |
| 185 | 0x06, 0xd1, // Data |
| 186 | 0x07, 0x14, // Name |
| 187 | 0x08, 0x05, |
| 188 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 189 | 0x08, 0x03, |
| 190 | 0x6e, 0x64, 0x6e, |
| 191 | 0x08, 0x06, |
| 192 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 193 | 0x14, 0x07, // MetaInfo |
| 194 | 0x18, 0x01, // ContentType |
| 195 | 0x01, |
| 196 | 0x19, 0x02, // FreshnessPeriod |
| 197 | 0x27, 0x10, |
| 198 | 0x15, 0x11, // Content |
| 199 | 0x1f, 0x03, // LinkDelegation |
| 200 | 0x1e, 0x01, // LinkPreference |
| 201 | 0x0a, |
| 202 | 0x1f, 0x0a, // LinkDelegation |
| 203 | 0x1e, 0x01, // LinkPreference |
| 204 | 0x14, |
| 205 | 0x07, 0x05, // Name |
| 206 | 0x08, 0x03, |
| 207 | 0x6e, 0x64, 0x6e, |
| 208 | 0x16, 0x1b, // SignatureInfo |
| 209 | 0x1b, 0x01, // SignatureType |
| 210 | 0x01, |
| 211 | 0x1c, 0x16, // KeyLocator |
| 212 | 0x07, 0x14, // Name |
| 213 | 0x08, 0x04, |
| 214 | 0x74, 0x65, 0x73, 0x74, |
| 215 | 0x08, 0x03, |
| 216 | 0x6b, 0x65, 0x79, |
| 217 | 0x08, 0x07, |
| 218 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 219 | 0x17, 0x80, // SignatureValue |
| 220 | 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec, |
| 221 | 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6, |
| 222 | 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38, |
| 223 | 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc, |
| 224 | 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf, |
| 225 | 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9, |
| 226 | 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8, |
| 227 | 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7, |
| 228 | 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3, |
| 229 | 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1 |
| 230 | }; |
| 231 | |
| 232 | BOOST_AUTO_TEST_SUITE(TestLink) |
| 233 | |
| 234 | BOOST_AUTO_TEST_CASE(PairParsingCheck) |
| 235 | { |
| 236 | Link link("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}}); |
| 237 | BOOST_CHECK_EQUAL(link.getDelegations().size(), static_cast<uint32_t>(3)); |
| 238 | } |
| 239 | |
| 240 | BOOST_AUTO_TEST_CASE(CheckInsertDelegation) |
| 241 | { |
| 242 | Link link("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}}); |
| 243 | |
| 244 | link.addDelegation(30, Name("test4")); |
| 245 | Link::DelegationSet delegations = link.getDelegations(); |
| 246 | int counter = 0; |
| 247 | for (auto i = delegations.begin(); i != delegations.end(); i++) { |
| 248 | counter++; |
| 249 | if (counter == 1) |
| 250 | { |
| 251 | BOOST_CHECK_EQUAL(std::get<0>(*i), 10); |
| 252 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test1")); |
| 253 | } |
| 254 | if (counter == 2) |
| 255 | { |
| 256 | BOOST_CHECK_EQUAL(std::get<0>(*i), 20); |
| 257 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test2")); |
| 258 | } |
| 259 | if (counter == 3) |
| 260 | { |
| 261 | BOOST_CHECK_EQUAL(std::get<0>(*i), 30); |
| 262 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test4")); |
| 263 | } |
| 264 | if (counter == 4) |
| 265 | { |
| 266 | BOOST_CHECK_EQUAL(std::get<0>(*i), 100); |
| 267 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test3")); |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | BOOST_AUTO_TEST_CASE(CheckRemoveDelegation) |
| 273 | { |
| 274 | Link link("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}}); |
| 275 | |
| 276 | link.removeDelegation(Name("test2")); |
| 277 | Link::DelegationSet delegations = link.getDelegations(); |
| 278 | int counter = 0; |
| 279 | for (auto i = delegations.begin(); i != delegations.end(); i++) { |
| 280 | counter++; |
| 281 | if (counter == 1) |
| 282 | { |
| 283 | BOOST_CHECK_EQUAL(std::get<0>(*i), 10); |
| 284 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test1")); |
| 285 | } |
| 286 | if (counter == 2) |
| 287 | { |
| 288 | BOOST_CHECK_EQUAL(std::get<0>(*i), 100); |
| 289 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test3")); |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 294 | BOOST_FIXTURE_TEST_CASE(CheckEncodeDecode, IdentityManagementFixture) |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 295 | { |
| 296 | Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}}); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 297 | m_keyChain.sign(link1); |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 298 | Block wire = link1.wireEncode(); |
| 299 | |
| 300 | Link link2; |
| 301 | link2.wireDecode(wire); |
| 302 | Name name = link2.getName(); |
| 303 | BOOST_CHECK_EQUAL(Name("test"), name); |
| 304 | |
| 305 | Link::DelegationSet delegations; |
| 306 | delegations = link2.getDelegations(); |
| 307 | int counter = 0; |
| 308 | for (auto i = delegations.begin(); i != delegations.end(); i++) { |
| 309 | counter++; |
| 310 | if (counter == 1) |
| 311 | { |
| 312 | BOOST_CHECK_EQUAL(std::get<0>(*i), 10); |
| 313 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test1")); |
| 314 | } |
| 315 | if (counter == 2) |
| 316 | { |
| 317 | BOOST_CHECK_EQUAL(std::get<0>(*i), 20); |
| 318 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test2")); |
| 319 | } |
| 320 | if (counter == 3) |
| 321 | { |
| 322 | BOOST_CHECK_EQUAL(std::get<0>(*i), 100); |
| 323 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test3")); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | Link link3(wire); |
| 328 | name = link3.getName(); |
| 329 | BOOST_CHECK_EQUAL(Name("test"), name); |
| 330 | |
| 331 | delegations = link3.getDelegations(); |
| 332 | counter = 0; |
| 333 | for (auto i = delegations.begin(); i != delegations.end(); i++) { |
| 334 | counter++; |
| 335 | if (counter == 1) |
| 336 | { |
| 337 | BOOST_CHECK_EQUAL(std::get<0>(*i), 10); |
| 338 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test1")); |
| 339 | } |
| 340 | if (counter == 2) |
| 341 | { |
| 342 | BOOST_CHECK_EQUAL(std::get<0>(*i), 20); |
| 343 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test2")); |
| 344 | } |
| 345 | if (counter == 3) |
| 346 | { |
| 347 | BOOST_CHECK_EQUAL(std::get<0>(*i), 100); |
| 348 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test3")); |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | BOOST_AUTO_TEST_CASE(Decode) |
| 354 | { |
| 355 | Block linkBlock(LinkTest, sizeof(LinkTest)); |
| 356 | Link link(linkBlock); |
| 357 | BOOST_CHECK_EQUAL(link.getName(), Name("/local/ndn/prefix")); |
| 358 | Link::DelegationSet delegations = link.getDelegations(); |
| 359 | int counter = 0; |
| 360 | |
| 361 | for (auto i = delegations.begin(); i != delegations.end(); i++) { |
| 362 | counter++; |
| 363 | if (counter == 1) |
| 364 | { |
| 365 | BOOST_CHECK_EQUAL(std::get<0>(*i), 10); |
| 366 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("local")); |
| 367 | } |
| 368 | if (counter == 2) |
| 369 | { |
| 370 | BOOST_CHECK_EQUAL(std::get<0>(*i), 20); |
| 371 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("ndn")); |
| 372 | } |
| 373 | } |
| 374 | } |
| 375 | |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 376 | BOOST_AUTO_TEST_CASE(CountDelegationFromWire) |
| 377 | { |
| 378 | Block linkBlock(LinkTest, sizeof(LinkTest)); |
| 379 | BOOST_CHECK_EQUAL(Link::countDelegationsFromWire(linkBlock), 2); |
| 380 | } |
| 381 | |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 382 | BOOST_AUTO_TEST_CASE(IncorrectContentType) |
| 383 | { |
| 384 | Block linkBlock(IncorrectContentTypeLink, sizeof(IncorrectContentTypeLink)); |
| 385 | Link link; |
| 386 | BOOST_REQUIRE_THROW(link.wireDecode(linkBlock), Link::Error); |
| 387 | } |
| 388 | |
| 389 | BOOST_AUTO_TEST_CASE(MissingPreferenceEncoding) |
| 390 | { |
| 391 | Block linkBlock(MissingPreferenceLink, sizeof(MissingPreferenceLink)); |
| 392 | Link link; |
| 393 | BOOST_REQUIRE_THROW(link.wireDecode(linkBlock), Link::Error); |
| 394 | } |
| 395 | |
| 396 | BOOST_AUTO_TEST_CASE(MissingNameEncoding) |
| 397 | { |
| 398 | Block linkBlock(MissingNameLink, sizeof(MissingNameLink)); |
| 399 | Link link; |
| 400 | BOOST_REQUIRE_THROW(link.wireDecode(linkBlock), Link::Error); |
| 401 | } |
| 402 | |
| 403 | BOOST_AUTO_TEST_SUITE_END() |
| 404 | |
| 405 | } // namespace tests |
| 406 | } // namespace ndn |