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