Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 2 | /** |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2015 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 | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
Alexander Afanasyev | 09c613f | 2014-01-29 00:23:58 -0800 | [diff] [blame] | 22 | #include "interest.hpp" |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 23 | #include "interest-filter.hpp" |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 24 | #include "data.hpp" |
| 25 | #include "security/signature-sha256-with-rsa.hpp" |
Yingdi Yu | bf6a281 | 2014-06-17 15:32:11 -0700 | [diff] [blame] | 26 | #include "security/digest-sha256.hpp" |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 27 | #include "security/key-chain.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 28 | #include "encoding/buffer-stream.hpp" |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 29 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 30 | #include "boost-test.hpp" |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 31 | |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 32 | namespace ndn { |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 33 | namespace tests { |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 34 | |
| 35 | BOOST_AUTO_TEST_SUITE(TestInterest) |
| 36 | |
| 37 | const uint8_t Interest1[] = { |
Alexander Afanasyev | 117f5ef | 2015-06-03 15:07:24 -0700 | [diff] [blame] | 38 | 0x05, 0x59, // NDN Interest |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 39 | 0x07, 0x14, // Name |
| 40 | 0x08, 0x5, // NameComponent |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 41 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 42 | 0x08, 0x3, // NameComponent |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 43 | 0x6e, 0x64, 0x6e, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 44 | 0x08, 0x6, // NameComponent |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 45 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 46 | 0x09, 0x37, // Selectors |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 47 | 0x0d, 0x1, 0x1, // MinSuffix |
| 48 | 0x0e, 0x1, 0x1, // MaxSuffix |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 49 | 0x1c, 0x16, // KeyLocator |
| 50 | 0x07, 0x14, // Name |
| 51 | 0x08, 0x04, |
| 52 | 0x74, 0x65, 0x73, 0x74, |
| 53 | 0x08, 0x03, |
| 54 | 0x6b, 0x65, 0x79, |
| 55 | 0x08, 0x07, |
| 56 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 57 | 0x10, 0x14, // Exclude |
| 58 | 0x08, 0x4, // NameComponent |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 59 | 0x61, 0x6c, 0x65, 0x78, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 60 | 0x08, 0x4, // NameComponent |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 61 | 0x78, 0x78, 0x78, 0x78, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 62 | 0x13, 0x0, // Any |
| 63 | 0x08, 0x4, // NameComponent |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 64 | 0x79, 0x79, 0x79, 0x79, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 65 | 0x11, 0x1, // ChildSelector |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 66 | 0x1, |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 67 | 0x0a, 0x4, // Nonce |
| 68 | 0x1, 0x0, 0x0, 0x00, |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 69 | 0x0c, // InterestLifetime |
| 70 | 0x2, 0x3, 0xe8 |
| 71 | }; |
| 72 | |
| 73 | const uint8_t Interest2[] = { |
Alexander Afanasyev | 117f5ef | 2015-06-03 15:07:24 -0700 | [diff] [blame] | 74 | 0x05, 0x59, // NDN Interest |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 75 | 0x07, 0x14, // Name |
| 76 | 0x08, 0x5, // NameComponent |
| 77 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 78 | 0x08, 0x3, // NameComponent |
| 79 | 0x6e, 0x64, 0x6e, |
| 80 | 0x08, 0x6, // NameComponent |
| 81 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 82 | 0x09, 0x37, // Selectors |
| 83 | 0x0d, 0x1, 0x1, // MinSuffix |
| 84 | 0x0e, 0x1, 0x1, // MaxSuffix |
| 85 | 0x1c, 0x16, // KeyLocator |
| 86 | 0x07, 0x14, // Name |
| 87 | 0x08, 0x04, |
| 88 | 0x74, 0x65, 0x73, 0x74, |
| 89 | 0x08, 0x03, |
| 90 | 0x6b, 0x65, 0x79, |
| 91 | 0x08, 0x07, |
| 92 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 93 | 0x10, 0x14, // Exclude |
| 94 | 0x08, 0x4, // NameComponent |
| 95 | 0x61, 0x6c, 0x65, 0x78, |
| 96 | 0x08, 0x4, // NameComponent |
| 97 | 0x78, 0x78, 0x78, 0x78, |
| 98 | 0x13, 0x0, // Any |
| 99 | 0x08, 0x4, // NameComponent |
| 100 | 0x79, 0x79, 0x79, 0x79, |
| 101 | 0x11, 0x1, // ChildSelector |
| 102 | 0x1, |
| 103 | 0x0a, 0x4, // Nonce |
| 104 | 0x2, 0x0, 0x0, 0x00, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 105 | 0x0c, // InterestLifetime |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 106 | 0x2, 0x3, 0xe8 |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 107 | }; |
| 108 | |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 109 | const uint8_t InterestWithLink[] = { |
| 110 | 0x05, 0xfb, // Interest |
| 111 | 0x07, 0x14, // Name |
| 112 | 0x08, 0x5, // NameComponent |
| 113 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 114 | 0x08, 0x3, // NameComponent |
| 115 | 0x6e, 0x64, 0x6e, |
| 116 | 0x08, 0x6, // NameComponent |
| 117 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 118 | 0x0a, 0x4, // Nonce |
| 119 | 0x1, 0x0, 0x0, 0x00, |
| 120 | 0x06, 0xda, // Data |
| 121 | 0x07, 0x14, // Name |
| 122 | 0x08, 0x05, |
| 123 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 124 | 0x08, 0x03, |
| 125 | 0x6e, 0x64, 0x6e, |
| 126 | 0x08, 0x06, |
| 127 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 128 | 0x14, 0x07, // MetaInfo |
| 129 | 0x18, 0x01, // ContentType |
| 130 | 0x01, |
| 131 | 0x19, 0x02, // FreshnessPeriod |
| 132 | 0x27, 0x10, |
| 133 | 0x15, 0x1a, // Content |
| 134 | 0x1f, 0x0c, // LinkDelegation |
| 135 | 0x1e, 0x01, // LinkPreference |
| 136 | 0x0a, |
| 137 | 0x07, 0x07, // Name |
| 138 | 0x08, 0x05, |
| 139 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 140 | 0x1f, 0x0a, // LinkDelegation |
| 141 | 0x1e, 0x01, // LinkPreference |
| 142 | 0x14, |
| 143 | 0x07, 0x05, // Name |
| 144 | 0x08, 0x03, |
| 145 | 0x6e, 0x64, 0x6e, |
| 146 | 0x16, 0x1b, // SignatureInfo |
| 147 | 0x1b, 0x01, // SignatureType |
| 148 | 0x01, |
| 149 | 0x1c, 0x16, // KeyLocator |
| 150 | 0x07, 0x14, // Name |
| 151 | 0x08, 0x04, |
| 152 | 0x74, 0x65, 0x73, 0x74, |
| 153 | 0x08, 0x03, |
| 154 | 0x6b, 0x65, 0x79, |
| 155 | 0x08, 0x07, |
| 156 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 157 | 0x17, 0x80, // SignatureValue |
| 158 | 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec, |
| 159 | 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6, |
| 160 | 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38, |
| 161 | 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc, |
| 162 | 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf, |
| 163 | 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9, |
| 164 | 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8, |
| 165 | 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7, |
| 166 | 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3, |
| 167 | 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1, |
| 168 | 0x20, 0x01, // SelectedDelegation |
| 169 | 0x00 |
| 170 | }; |
| 171 | |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 172 | const uint8_t LINK[] = { |
| 173 | 0x06, 0xda, // Data |
| 174 | 0x07, 0x14, // Name |
| 175 | 0x08, 0x05, |
| 176 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 177 | 0x08, 0x03, |
| 178 | 0x6e, 0x64, 0x6e, |
| 179 | 0x08, 0x06, |
| 180 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 181 | 0x14, 0x07, // MetaInfo |
| 182 | 0x18, 0x01, // ContentType |
| 183 | 0x01, |
| 184 | 0x19, 0x02, // FreshnessPeriod |
| 185 | 0x27, 0x10, |
| 186 | 0x15, 0x1a, // Content |
| 187 | 0x1f, 0x0c, // LinkDelegation |
| 188 | 0x1e, 0x01, // LinkPreference |
| 189 | 0x0a, |
| 190 | 0x07, 0x07, // Name |
| 191 | 0x08, 0x05, |
| 192 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 193 | 0x1f, 0x0a, // LinkDelegation |
| 194 | 0x1e, 0x01, // LinkPreference |
| 195 | 0x14, |
| 196 | 0x07, 0x05, // Name |
| 197 | 0x08, 0x03, |
| 198 | 0x6e, 0x64, 0x6e, |
| 199 | 0x16, 0x1b, // SignatureInfo |
| 200 | 0x1b, 0x01, // SignatureType |
| 201 | 0x01, |
| 202 | 0x1c, 0x16, // KeyLocator |
| 203 | 0x07, 0x14, // Name |
| 204 | 0x08, 0x04, |
| 205 | 0x74, 0x65, 0x73, 0x74, |
| 206 | 0x08, 0x03, |
| 207 | 0x6b, 0x65, 0x79, |
| 208 | 0x08, 0x07, |
| 209 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 210 | 0x17, 0x80, // SignatureValue |
| 211 | 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec, |
| 212 | 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6, |
| 213 | 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38, |
| 214 | 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc, |
| 215 | 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf, |
| 216 | 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9, |
| 217 | 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8, |
| 218 | 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7, |
| 219 | 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3, |
| 220 | 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1 |
| 221 | }; |
| 222 | |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 223 | const uint8_t InterestWithLinkMissingContentType[] = { |
| 224 | 0x05, 0xf8, // Interest |
| 225 | 0x07, 0x14, // Name |
| 226 | 0x08, 0x5, // NameComponent |
| 227 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 228 | 0x08, 0x3, // NameComponent |
| 229 | 0x6e, 0x64, 0x6e, |
| 230 | 0x08, 0x6, // NameComponent |
| 231 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 232 | 0x0a, 0x4, // Nonce |
| 233 | 0x1, 0x0, 0x0, 0x00, |
| 234 | 0x06, 0xd7, // Data |
| 235 | 0x07, 0x14, // Name |
| 236 | 0x08, 0x05, |
| 237 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 238 | 0x08, 0x03, |
| 239 | 0x6e, 0x64, 0x6e, |
| 240 | 0x08, 0x06, |
| 241 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 242 | 0x14, 0x04, // MetaInfo |
| 243 | 0x19, 0x02, // FreshnessPeriod |
| 244 | 0x27, 0x10, |
| 245 | 0x15, 0x1a, // Content |
| 246 | 0x1f, 0x0c, // LinkDelegation |
| 247 | 0x1e, 0x01, // LinkPreference |
| 248 | 0x0a, |
| 249 | 0x07, 0x07, // Name |
| 250 | 0x08, 0x05, |
| 251 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 252 | 0x1f, 0x0a, // LinkDelegation |
| 253 | 0x1e, 0x01, // LinkPreference |
| 254 | 0x14, |
| 255 | 0x07, 0x05, // Name |
| 256 | 0x08, 0x03, |
| 257 | 0x6e, 0x64, 0x6e, |
| 258 | 0x16, 0x1b, // SignatureInfo |
| 259 | 0x1b, 0x01, // SignatureType |
| 260 | 0x01, |
| 261 | 0x1c, 0x16, // KeyLocator |
| 262 | 0x07, 0x14, // Name |
| 263 | 0x08, 0x04, |
| 264 | 0x74, 0x65, 0x73, 0x74, |
| 265 | 0x08, 0x03, |
| 266 | 0x6b, 0x65, 0x79, |
| 267 | 0x08, 0x07, |
| 268 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 269 | 0x17, 0x80, // SignatureValue |
| 270 | 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec, |
| 271 | 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6, |
| 272 | 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38, |
| 273 | 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc, |
| 274 | 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf, |
| 275 | 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9, |
| 276 | 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8, |
| 277 | 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7, |
| 278 | 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3, |
| 279 | 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1, |
| 280 | 0x20, 0x01, // SelectedDelegation |
| 281 | 0x00 |
| 282 | }; |
| 283 | |
| 284 | const uint8_t InterestWithLinkNoMetaInfo[] = { |
| 285 | 0x05, 0xf2, // Interest |
| 286 | 0x07, 0x14, // Name |
| 287 | 0x08, 0x5, // NameComponent |
| 288 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 289 | 0x08, 0x3, // NameComponent |
| 290 | 0x6e, 0x64, 0x6e, |
| 291 | 0x08, 0x6, // NameComponent |
| 292 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 293 | 0x0a, 0x4, // Nonce |
| 294 | 0x1, 0x0, 0x0, 0x00, |
| 295 | 0x06, 0xd1, // Data |
| 296 | 0x07, 0x14, // Name |
| 297 | 0x08, 0x05, |
| 298 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 299 | 0x08, 0x03, |
| 300 | 0x6e, 0x64, 0x6e, |
| 301 | 0x08, 0x06, |
| 302 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 303 | 0x15, 0x1a, // Content |
| 304 | 0x1f, 0x0c, // LinkDelegation |
| 305 | 0x1e, 0x01, // LinkPreference |
| 306 | 0x0a, |
| 307 | 0x07, 0x07, // Name |
| 308 | 0x08, 0x05, |
| 309 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 310 | 0x1f, 0x0a, // LinkPreference |
| 311 | 0x1e, 0x01, // LinkPreference |
| 312 | 0x14, |
| 313 | 0x07, 0x05, // Name |
| 314 | 0x08, 0x03, |
| 315 | 0x6e, 0x64, 0x6e, |
| 316 | 0x16, 0x1b, // SignatureInfo |
| 317 | 0x1b, 0x01, // SignatureType |
| 318 | 0x01, |
| 319 | 0x1c, 0x16, // KeyLocator |
| 320 | 0x07, 0x14, // Name |
| 321 | 0x08, 0x04, |
| 322 | 0x74, 0x65, 0x73, 0x74, |
| 323 | 0x08, 0x03, |
| 324 | 0x6b, 0x65, 0x79, |
| 325 | 0x08, 0x07, |
| 326 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 327 | 0x17, 0x80, // SignatureValue |
| 328 | 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec, |
| 329 | 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6, |
| 330 | 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38, |
| 331 | 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc, |
| 332 | 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf, |
| 333 | 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9, |
| 334 | 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8, |
| 335 | 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7, |
| 336 | 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3, |
| 337 | 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1, |
| 338 | 0x20, 0x01, // SelectedDelegation |
| 339 | 0x00 |
| 340 | }; |
| 341 | |
| 342 | const uint8_t InterestWithLinkWrongContentType[] = { |
| 343 | 0x05, 0xfb, // Interest |
| 344 | 0x07, 0x14, // Name |
| 345 | 0x08, 0x5, // NameComponent |
| 346 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 347 | 0x08, 0x3, // NameComponent |
| 348 | 0x6e, 0x64, 0x6e, |
| 349 | 0x08, 0x6, // NameComponent |
| 350 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 351 | 0x0a, 0x4, // Nonce |
| 352 | 0x1, 0x0, 0x0, 0x00, |
| 353 | 0x06, 0xda, // Data |
| 354 | 0x07, 0x14, // Name |
| 355 | 0x08, 0x05, |
| 356 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 357 | 0x08, 0x03, |
| 358 | 0x6e, 0x64, 0x6e, |
| 359 | 0x08, 0x06, |
| 360 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 361 | 0x14, 0x07, // MetaInfo |
| 362 | 0x18, 0x01, // ContentType |
| 363 | 0x00, |
| 364 | 0x19, 0x02, // FreshnessPeriod |
| 365 | 0x27, 0x10, |
| 366 | 0x15, 0x1a, // Content |
| 367 | 0x1f, 0x0c, // LinkDelegation |
| 368 | 0x1e, 0x01, // LinkPreference |
| 369 | 0x0a, |
| 370 | 0x07, 0x07, // Name |
| 371 | 0x08, 0x05, |
| 372 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 373 | 0x1f, 0x0a, // LinkDelegation |
| 374 | 0x1e, 0x01, // LinkPreference |
| 375 | 0x14, |
| 376 | 0x07, 0x05, // Name |
| 377 | 0x08, 0x03, |
| 378 | 0x6e, 0x64, 0x6e, |
| 379 | 0x16, 0x1b, // SignatureInfo |
| 380 | 0x1b, 0x01, // SignatureType |
| 381 | 0x01, |
| 382 | 0x1c, 0x16, // KeyLocator |
| 383 | 0x07, 0x14, // Name |
| 384 | 0x08, 0x04, |
| 385 | 0x74, 0x65, 0x73, 0x74, |
| 386 | 0x08, 0x03, |
| 387 | 0x6b, 0x65, 0x79, |
| 388 | 0x08, 0x07, |
| 389 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 390 | 0x17, 0x80, // SignatureValue |
| 391 | 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec, |
| 392 | 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6, |
| 393 | 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38, |
| 394 | 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc, |
| 395 | 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf, |
| 396 | 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9, |
| 397 | 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8, |
| 398 | 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7, |
| 399 | 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3, |
| 400 | 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1, |
| 401 | 0x20, 0x01, // SelectedDelegation |
| 402 | 0x00 |
| 403 | }; |
| 404 | |
| 405 | const uint8_t InterestWithSelectedDelegationButNoLink[] = { |
| 406 | 0x05, 0x1f, // Interest |
| 407 | 0x07, 0x14, // Name |
| 408 | 0x08, 0x5, // NameComponent |
| 409 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 410 | 0x08, 0x3, // NameComponent |
| 411 | 0x6e, 0x64, 0x6e, |
| 412 | 0x08, 0x6, // NameComponent |
| 413 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 414 | 0x0a, 0x4, // Nonce |
| 415 | 0x1, 0x0, 0x0, 0x00, |
| 416 | 0x20, 0x01, // SelectedDelegation |
| 417 | 0x00 |
| 418 | }; |
| 419 | |
| 420 | const uint8_t InterestWithLinkNotNonIntegerSelectedDelegation[] = { |
| 421 | 0x05, 0xfb, // Interest |
| 422 | 0x07, 0x14, // Name |
| 423 | 0x08, 0x5, // NameComponent |
| 424 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 425 | 0x08, 0x3, // NameComponent |
| 426 | 0x6e, 0x64, 0x6e, |
| 427 | 0x08, 0x6, // NameComponent |
| 428 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 429 | 0x0a, 0x4, // Nonce |
| 430 | 0x1, 0x0, 0x0, 0x00, |
| 431 | 0x06, 0xda, // Data |
| 432 | 0x07, 0x14, // Name |
| 433 | 0x08, 0x05, |
| 434 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 435 | 0x08, 0x03, |
| 436 | 0x6e, 0x64, 0x6e, |
| 437 | 0x08, 0x06, |
| 438 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 439 | 0x14, 0x07, // MetaInfo |
| 440 | 0x18, 0x01, // ContentType |
| 441 | 0x01, |
| 442 | 0x19, 0x02, // FreshnessPeriod |
| 443 | 0x27, 0x10, |
| 444 | 0x15, 0x1a, // Content |
| 445 | 0x1f, 0x0c, // LinkDelegation |
| 446 | 0x1e, 0x01, // LinkPreference |
| 447 | 0x0a, |
| 448 | 0x07, 0x07, // Name |
| 449 | 0x08, 0x05, |
| 450 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 451 | 0x1f, 0x0a, // LinkDelegation |
| 452 | 0x1e, 0x01, // LinkPreference |
| 453 | 0x14, |
| 454 | 0x07, 0x05, // Name |
| 455 | 0x08, 0x03, |
| 456 | 0x6e, 0x64, 0x6e, |
| 457 | 0x16, 0x1b, // SignatureInfo |
| 458 | 0x1b, 0x01, // SignatureType |
| 459 | 0x01, |
| 460 | 0x1c, 0x16, // KeyLocator |
| 461 | 0x07, 0x14, // Name |
| 462 | 0x08, 0x04, |
| 463 | 0x74, 0x65, 0x73, 0x74, |
| 464 | 0x08, 0x03, |
| 465 | 0x6b, 0x65, 0x79, |
| 466 | 0x08, 0x07, |
| 467 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 468 | 0x17, 0x78, // SignatureValue |
| 469 | 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec, |
| 470 | 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6, |
| 471 | 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38, |
| 472 | 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc, |
| 473 | 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf, |
| 474 | 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9, |
| 475 | 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8, |
| 476 | 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7, |
| 477 | 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3, |
| 478 | 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, |
| 479 | 0x20, 0x03, // SelectedDelegation |
| 480 | 0xAA, 0xAA, 0xAA |
| 481 | }; |
| 482 | |
| 483 | const uint8_t InterestWithLinkNonDecreasingOrder[] = { |
| 484 | 0x05, 0xfb, // Interest |
| 485 | 0x07, 0x14, // Name |
| 486 | 0x08, 0x5, // NameComponent |
| 487 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 488 | 0x08, 0x3, // NameComponent |
| 489 | 0x6e, 0x64, 0x6e, |
| 490 | 0x08, 0x6, // NameComponent |
| 491 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 492 | 0x0a, 0x4, // Nonce |
| 493 | 0x1, 0x0, 0x0, 0x00, |
| 494 | 0x06, 0xda, // Data |
| 495 | 0x07, 0x14, // Name |
| 496 | 0x08, 0x05, |
| 497 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 498 | 0x08, 0x03, |
| 499 | 0x6e, 0x64, 0x6e, |
| 500 | 0x08, 0x06, |
| 501 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 502 | 0x14, 0x07, // MetaInfo |
| 503 | 0x18, 0x01, // ContentType |
| 504 | 0x01, |
| 505 | 0x19, 0x02, // FreshnessPeriod |
| 506 | 0x27, 0x10, |
| 507 | 0x15, 0x1a, // Content |
| 508 | 0x1f, 0x0c, // LinkDelegation |
| 509 | 0x1e, 0x01, // LinkPreference |
| 510 | 0x14, |
| 511 | 0x07, 0x07, // Name |
| 512 | 0x08, 0x05, |
| 513 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 514 | 0x1f, 0x0a, // LinkDelegation |
| 515 | 0x1e, 0x01, // LinkPreference |
| 516 | 0x0a, |
| 517 | 0x07, 0x05, // Name |
| 518 | 0x08, 0x03, |
| 519 | 0x6e, 0x64, 0x6e, |
| 520 | 0x16, 0x1b, // SignatureInfo |
| 521 | 0x1b, 0x01, // SignatureType |
| 522 | 0x01, |
| 523 | 0x1c, 0x16, // KeyLocator |
| 524 | 0x07, 0x14, // Name |
| 525 | 0x08, 0x04, |
| 526 | 0x74, 0x65, 0x73, 0x74, |
| 527 | 0x08, 0x03, |
| 528 | 0x6b, 0x65, 0x79, |
| 529 | 0x08, 0x07, |
| 530 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 531 | 0x17, 0x80, // SignatureValue |
| 532 | 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec, |
| 533 | 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6, |
| 534 | 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38, |
| 535 | 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc, |
| 536 | 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf, |
| 537 | 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9, |
| 538 | 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8, |
| 539 | 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7, |
| 540 | 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3, |
| 541 | 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1, |
| 542 | 0x20, 0x01, // SelectedDelegation |
| 543 | 0x01 |
| 544 | }; |
| 545 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 546 | const uint8_t InterestWithLocalControlHeader[] = { |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 547 | 0x50, 0x25, 0x51, 0x01, 0x0a, |
| 548 | 0x05, 0x20, 0x07, 0x14, 0x08, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x08, 0x03, 0x6e, 0x64, |
| 549 | 0x6e, 0x08, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x09, 0x02, 0x12, 0x00, 0x0a, 0x04, |
| 550 | 0x01, 0x00, 0x00, 0x00 |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 551 | }; |
| 552 | |
| 553 | const uint8_t InterestWithoutLocalControlHeader[] = { |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 554 | 0x05, 0x20, 0x07, 0x14, 0x08, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x08, 0x03, 0x6e, 0x64, |
| 555 | 0x6e, 0x08, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x09, 0x02, 0x12, 0x00, 0x0a, 0x04, |
| 556 | 0x01, 0x00, 0x00, 0x00 |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 557 | }; |
| 558 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 559 | BOOST_AUTO_TEST_CASE(InterestEqualityChecks) |
| 560 | { |
| 561 | // Interest ::= INTEREST-TYPE TLV-LENGTH |
| 562 | // Name |
| 563 | // Selectors? |
| 564 | // Nonce |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 565 | // InterestLifetime? |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 566 | // Link? |
| 567 | // SelectedDelegation? |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 568 | |
| 569 | Interest a; |
| 570 | Interest b; |
| 571 | |
| 572 | // if nonce is not set, it will be set to a random value |
| 573 | a.setNonce(1); |
| 574 | b.setNonce(1); |
| 575 | |
| 576 | BOOST_CHECK_EQUAL(a == b, true); |
| 577 | BOOST_CHECK_EQUAL(a != b, false); |
| 578 | |
| 579 | // check comparison on Name |
| 580 | a.setName("ndn:/A"); |
| 581 | BOOST_CHECK_EQUAL(a == b, false); |
| 582 | BOOST_CHECK_EQUAL(a != b, true); |
| 583 | |
| 584 | b.setName("ndn:/B"); |
| 585 | BOOST_CHECK_EQUAL(a == b, false); |
| 586 | BOOST_CHECK_EQUAL(a != b, true); |
| 587 | |
| 588 | b.setName("ndn:/A"); |
| 589 | BOOST_CHECK_EQUAL(a == b, true); |
| 590 | BOOST_CHECK_EQUAL(a != b, false); |
| 591 | |
| 592 | // check comparison on Selectors |
| 593 | a.setChildSelector(1); |
| 594 | BOOST_CHECK_EQUAL(a == b, false); |
| 595 | BOOST_CHECK_EQUAL(a != b, true); |
| 596 | |
| 597 | b.setChildSelector(1); |
| 598 | BOOST_CHECK_EQUAL(a == b, true); |
| 599 | BOOST_CHECK_EQUAL(a != b, false); |
| 600 | |
| 601 | // check comparison on Nonce |
| 602 | a.setNonce(100); |
| 603 | BOOST_CHECK_EQUAL(a == b, false); |
| 604 | BOOST_CHECK_EQUAL(a != b, true); |
| 605 | |
| 606 | b.setNonce(100); |
| 607 | BOOST_CHECK_EQUAL(a == b, true); |
| 608 | BOOST_CHECK_EQUAL(a != b, false); |
| 609 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 610 | // check comparison on InterestLifetime |
| 611 | a.setInterestLifetime(time::seconds(10)); |
| 612 | BOOST_CHECK_EQUAL(a == b, false); |
| 613 | BOOST_CHECK_EQUAL(a != b, true); |
| 614 | |
| 615 | b.setInterestLifetime(time::seconds(10)); |
| 616 | BOOST_CHECK_EQUAL(a == b, true); |
| 617 | BOOST_CHECK_EQUAL(a != b, false); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 618 | |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 619 | a.setLink(Block(LINK, sizeof(LINK))); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 620 | BOOST_CHECK_EQUAL(a == b, false); |
| 621 | BOOST_CHECK_EQUAL(a != b, true); |
| 622 | |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 623 | b.setLink(Block(LINK, sizeof(LINK))); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 624 | BOOST_CHECK_EQUAL(a == b, true); |
| 625 | BOOST_CHECK_EQUAL(a != b, false); |
| 626 | |
| 627 | // Selected Delegation |
| 628 | BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false); |
| 629 | BOOST_CHECK_EQUAL(b.hasSelectedDelegation(), false); |
| 630 | |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 631 | a.setSelectedDelegation(Name("/local")); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 632 | BOOST_CHECK_EQUAL(a == b, false); |
| 633 | BOOST_CHECK_EQUAL(a != b, true); |
| 634 | |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 635 | b.setSelectedDelegation(Name("/local")); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 636 | BOOST_CHECK_EQUAL(a == b, true); |
| 637 | BOOST_CHECK_EQUAL(a != b, false); |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | BOOST_AUTO_TEST_CASE(SelectorsEqualityChecks) |
| 641 | { |
| 642 | // Selectors ::= SELECTORS-TYPE TLV-LENGTH |
| 643 | // MinSuffixComponents? |
| 644 | // MaxSuffixComponents? |
| 645 | // PublisherPublicKeyLocator? |
| 646 | // Exclude? |
| 647 | // ChildSelector? |
| 648 | // MustBeFresh? |
| 649 | |
| 650 | Selectors a; |
| 651 | Selectors b; |
| 652 | BOOST_CHECK_EQUAL(a == b, true); |
| 653 | BOOST_CHECK_EQUAL(a != b, false); |
| 654 | |
| 655 | // MinSuffixComponents |
| 656 | a.setMinSuffixComponents(1); |
| 657 | BOOST_CHECK_EQUAL(a == b, false); |
| 658 | BOOST_CHECK_EQUAL(a != b, true); |
| 659 | |
| 660 | b.setMinSuffixComponents(2); |
| 661 | BOOST_CHECK_EQUAL(a == b, false); |
| 662 | BOOST_CHECK_EQUAL(a != b, true); |
| 663 | |
| 664 | b.setMinSuffixComponents(1); |
| 665 | BOOST_CHECK_EQUAL(a == b, true); |
| 666 | BOOST_CHECK_EQUAL(a != b, false); |
| 667 | |
| 668 | // MaxSuffixComponents |
| 669 | a.setMaxSuffixComponents(10); |
| 670 | BOOST_CHECK_EQUAL(a == b, false); |
| 671 | BOOST_CHECK_EQUAL(a != b, true); |
| 672 | |
| 673 | b.setMaxSuffixComponents(10); |
| 674 | BOOST_CHECK_EQUAL(a == b, true); |
| 675 | BOOST_CHECK_EQUAL(a != b, false); |
| 676 | |
| 677 | // PublisherPublicKeyLocator |
| 678 | a.setPublisherPublicKeyLocator(KeyLocator("/key/Locator/name")); |
| 679 | BOOST_CHECK_EQUAL(a == b, false); |
| 680 | BOOST_CHECK_EQUAL(a != b, true); |
| 681 | |
| 682 | b.setPublisherPublicKeyLocator(KeyLocator("/key/Locator/name")); |
| 683 | BOOST_CHECK_EQUAL(a == b, true); |
| 684 | BOOST_CHECK_EQUAL(a != b, false); |
| 685 | |
| 686 | // Exclude |
| 687 | a.setExclude(Exclude().excludeOne(name::Component("exclude"))); |
| 688 | BOOST_CHECK_EQUAL(a == b, false); |
| 689 | BOOST_CHECK_EQUAL(a != b, true); |
| 690 | |
| 691 | b.setExclude(Exclude().excludeOne(name::Component("exclude"))); |
| 692 | BOOST_CHECK_EQUAL(a == b, true); |
| 693 | BOOST_CHECK_EQUAL(a != b, false); |
| 694 | |
| 695 | // ChildSelector |
| 696 | a.setChildSelector(1); |
| 697 | BOOST_CHECK_EQUAL(a == b, false); |
| 698 | BOOST_CHECK_EQUAL(a != b, true); |
| 699 | |
| 700 | b.setChildSelector(1); |
| 701 | BOOST_CHECK_EQUAL(a == b, true); |
| 702 | BOOST_CHECK_EQUAL(a != b, false); |
| 703 | |
| 704 | // MustBeFresh |
| 705 | a.setMustBeFresh(true); |
| 706 | BOOST_CHECK_EQUAL(a == b, false); |
| 707 | BOOST_CHECK_EQUAL(a != b, true); |
| 708 | |
| 709 | b.setMustBeFresh(true); |
| 710 | BOOST_CHECK_EQUAL(a == b, true); |
| 711 | BOOST_CHECK_EQUAL(a != b, false); |
| 712 | } |
| 713 | |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 714 | BOOST_AUTO_TEST_CASE(LinkObject) |
| 715 | { |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 716 | Link link1("test", {{100, "/test3"}, {20, "/test2"}, {10, "/test1"}}); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 717 | KeyChain keyChain; |
| 718 | keyChain.sign(link1); |
| 719 | Block wire = link1.wireEncode(); |
| 720 | |
| 721 | Interest a; |
| 722 | BOOST_REQUIRE_NO_THROW(a.setLink(wire)); |
| 723 | |
| 724 | BOOST_REQUIRE_NO_THROW(a.getLink()); |
| 725 | |
| 726 | Link link2 = a.getLink(); |
| 727 | Name name = link2.getName(); |
| 728 | BOOST_CHECK_EQUAL(Name("test"), name); |
| 729 | BOOST_CHECK_EQUAL(a.hasLink(), true); |
| 730 | Link::DelegationSet delegations; |
| 731 | delegations = link2.getDelegations(); |
| 732 | |
| 733 | auto i = delegations.begin(); |
| 734 | BOOST_CHECK_EQUAL(std::get<0>(*i), 10); |
| 735 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test1")); |
| 736 | ++i; |
| 737 | BOOST_CHECK_EQUAL(std::get<0>(*i), 20); |
| 738 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test2")); |
| 739 | ++i; |
| 740 | BOOST_CHECK_EQUAL(std::get<0>(*i), 100); |
| 741 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test3")); |
| 742 | |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 743 | a.setLink(Block(LINK, sizeof(LINK))); |
| 744 | BOOST_CHECK_EQUAL(a.getLink().getDelegations().size(), 2); |
| 745 | |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 746 | a.unsetLink(); |
| 747 | BOOST_CHECK_EQUAL(a.hasLink(), false); |
| 748 | } |
| 749 | |
| 750 | BOOST_AUTO_TEST_CASE(SelectedDelegationChecks) |
| 751 | { |
| 752 | Link link("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}}); |
| 753 | KeyChain keyChain; |
| 754 | keyChain.sign(link); |
| 755 | Block wire = link.wireEncode(); |
| 756 | |
| 757 | Interest a; |
| 758 | a.setLink(wire); |
| 759 | BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false); |
| 760 | |
| 761 | BOOST_REQUIRE_NO_THROW(a.setSelectedDelegation(Name("test2"))); |
| 762 | BOOST_CHECK_EQUAL(a.getSelectedDelegation(), Name("test2")); |
| 763 | |
| 764 | BOOST_REQUIRE_NO_THROW(a.setSelectedDelegation(uint32_t(2))); |
| 765 | BOOST_CHECK_EQUAL(a.getSelectedDelegation(), Name("test3")); |
| 766 | |
| 767 | a.unsetSelectedDelegation(); |
| 768 | BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false); |
| 769 | } |
| 770 | |
| 771 | BOOST_AUTO_TEST_CASE(EncodeDecodeWithLink) |
| 772 | { |
| 773 | Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}}); |
| 774 | KeyChain keyChain; |
| 775 | keyChain.sign(link1); |
| 776 | Block wire = link1.wireEncode(); |
| 777 | |
| 778 | Interest a; |
| 779 | a.setName("/Test/Encode/Decode/With/Link"); |
| 780 | a.setChildSelector(1); |
| 781 | a.setNonce(100); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 782 | a.setInterestLifetime(time::seconds(10)); |
| 783 | a.setLink(wire); |
| 784 | |
| 785 | Block interestBlock = a.wireEncode(); |
| 786 | Interest b(interestBlock); |
| 787 | |
| 788 | BOOST_CHECK_EQUAL(a == b, true); |
| 789 | |
| 790 | Link link2 = b.getLink(); |
| 791 | Link::DelegationSet delegations; |
| 792 | delegations = link2.getDelegations(); |
| 793 | |
| 794 | auto i = delegations.begin(); |
| 795 | BOOST_CHECK_EQUAL(std::get<0>(*i), 10); |
| 796 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test1")); |
| 797 | ++i; |
| 798 | BOOST_CHECK_EQUAL(std::get<0>(*i), 20); |
| 799 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test2")); |
| 800 | ++i; |
| 801 | BOOST_CHECK_EQUAL(std::get<0>(*i), 100); |
| 802 | BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test3")); |
| 803 | |
| 804 | } |
| 805 | |
| 806 | BOOST_AUTO_TEST_CASE(DecodeInterestWithLink) |
| 807 | { |
| 808 | Block interestBlock(InterestWithLink, sizeof(InterestWithLink)); |
| 809 | |
| 810 | ndn::Interest i; |
| 811 | BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock)); |
| 812 | Link link = i.getLink(); |
| 813 | BOOST_CHECK_EQUAL(link.getName(), Name("/local/ndn/prefix")); |
| 814 | Link::DelegationSet delegations = link.getDelegations(); |
| 815 | |
| 816 | auto it = delegations.begin(); |
| 817 | BOOST_CHECK_EQUAL(std::get<0>(*it), 10); |
| 818 | BOOST_CHECK_EQUAL(std::get<1>(*it), Name("local")); |
| 819 | ++it; |
| 820 | BOOST_CHECK_EQUAL(std::get<0>(*it), 20); |
| 821 | BOOST_CHECK_EQUAL(std::get<1>(*it), Name("ndn")); |
| 822 | |
| 823 | BOOST_REQUIRE_NO_THROW(i.getSelectedDelegation()); |
| 824 | BOOST_CHECK_EQUAL(i.getSelectedDelegation(), Name("local")); |
| 825 | } |
| 826 | |
| 827 | BOOST_AUTO_TEST_CASE(DecodeInterestWithLinkNonDecreasingOrder) |
| 828 | { |
| 829 | Block interestBlock(InterestWithLinkNonDecreasingOrder, |
| 830 | sizeof(InterestWithLinkNonDecreasingOrder)); |
| 831 | |
| 832 | ndn::Interest i; |
| 833 | BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock)); |
| 834 | BOOST_REQUIRE_NO_THROW(i.getSelectedDelegation()); |
| 835 | BOOST_CHECK_EQUAL(i.getSelectedDelegation(), Name("ndn")); |
| 836 | } |
| 837 | |
| 838 | BOOST_AUTO_TEST_CASE(LinkObjectMissingContentType) |
| 839 | { |
| 840 | Block interestBlock(InterestWithLinkMissingContentType, |
| 841 | sizeof(InterestWithLinkMissingContentType)); |
| 842 | |
| 843 | ndn::Interest i; |
| 844 | BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock)); |
| 845 | BOOST_REQUIRE_THROW(i.getLink(), Link::Error); |
| 846 | } |
| 847 | |
| 848 | BOOST_AUTO_TEST_CASE(LinkObjectNoMetaInfo) |
| 849 | { |
| 850 | Block interestBlock(InterestWithLinkNoMetaInfo, |
| 851 | sizeof(InterestWithLinkNoMetaInfo)); |
| 852 | |
| 853 | ndn::Interest i; |
| 854 | BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock)); |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 855 | BOOST_CHECK_THROW(i.getLink(), tlv::Error); |
| 856 | BOOST_CHECK_THROW(i.getLink(), tlv::Error); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | BOOST_AUTO_TEST_CASE(LinkObjectWrongContentType) |
| 860 | { |
| 861 | Block interestBlock(InterestWithLinkWrongContentType, |
| 862 | sizeof(InterestWithLinkWrongContentType)); |
| 863 | |
| 864 | ndn::Interest i; |
| 865 | BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock)); |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 866 | BOOST_CHECK_THROW(i.getLink(), Link::Error); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | BOOST_AUTO_TEST_CASE(InterestContainingSelectedDelegationButNoLink) |
| 870 | { |
| 871 | Block interestBlock(InterestWithSelectedDelegationButNoLink, |
| 872 | sizeof(InterestWithSelectedDelegationButNoLink)); |
| 873 | |
| 874 | ndn::Interest i; |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 875 | BOOST_CHECK_THROW(i.wireDecode(interestBlock), Interest::Error); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | BOOST_AUTO_TEST_CASE(SelectedDelegationIsNotNonNegativeInteger) |
| 879 | { |
| 880 | Block interestBlock(InterestWithLinkNotNonIntegerSelectedDelegation, |
| 881 | sizeof(InterestWithLinkNotNonIntegerSelectedDelegation)); |
| 882 | |
| 883 | ndn::Interest i; |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 884 | BOOST_CHECK_THROW(i.wireDecode(interestBlock), tlv::Error); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | BOOST_AUTO_TEST_CASE(SelectedDelegationEqualToDelegationCount) |
| 888 | { |
| 889 | Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}}); |
| 890 | KeyChain keyChain; |
| 891 | keyChain.sign(link1); |
| 892 | Block wire = link1.wireEncode(); |
| 893 | |
| 894 | Interest a; |
| 895 | a.setName("/Test/Encode/Decode/With/Link"); |
| 896 | a.setChildSelector(1); |
| 897 | a.setNonce(100); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 898 | a.setInterestLifetime(time::seconds(10)); |
| 899 | a.setLink(wire); |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 900 | BOOST_CHECK_THROW(a.setSelectedDelegation(3), Interest::Error); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | BOOST_AUTO_TEST_CASE(SelectedDelegationGreaterThanDelegationCount) |
| 904 | { |
| 905 | Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}}); |
| 906 | KeyChain keyChain; |
| 907 | keyChain.sign(link1); |
| 908 | Block wire = link1.wireEncode(); |
| 909 | |
| 910 | Interest a; |
| 911 | a.setName("/Test/Encode/Decode/With/Link"); |
| 912 | a.setChildSelector(1); |
| 913 | a.setNonce(100); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 914 | a.setInterestLifetime(time::seconds(10)); |
| 915 | a.setLink(wire); |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 916 | BOOST_CHECK_THROW(a.setSelectedDelegation(4), Interest::Error); |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 917 | } |
| 918 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 919 | BOOST_AUTO_TEST_CASE(Decode) |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 920 | { |
| 921 | Block interestBlock(Interest1, sizeof(Interest1)); |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 922 | |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 923 | ndn::Interest i; |
Alexander Afanasyev | 049f8f7 | 2013-12-26 19:07:15 -0800 | [diff] [blame] | 924 | BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock)); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 925 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 926 | BOOST_CHECK_EQUAL(i.getName().toUri(), "/local/ndn/prefix"); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 927 | BOOST_CHECK_EQUAL(i.getInterestLifetime(), time::milliseconds(1000)); |
| 928 | BOOST_CHECK_EQUAL(i.getMinSuffixComponents(), 1); |
| 929 | BOOST_CHECK_EQUAL(i.getMaxSuffixComponents(), 1); |
| 930 | BOOST_CHECK_EQUAL(i.getPublisherPublicKeyLocator().getType(), |
| 931 | static_cast<uint32_t>(KeyLocator::KeyLocator_Name)); |
| 932 | BOOST_CHECK_EQUAL(i.getPublisherPublicKeyLocator().getName(), "ndn:/test/key/locator"); |
| 933 | BOOST_CHECK_EQUAL(i.getChildSelector(), 1); |
| 934 | BOOST_CHECK_EQUAL(i.getMustBeFresh(), false); |
| 935 | BOOST_CHECK_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy"); |
| 936 | BOOST_CHECK_EQUAL(i.getNonce(), 1U); |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 937 | BOOST_CHECK_EQUAL(i.hasLink(), false); |
| 938 | BOOST_CHECK_EQUAL(i.hasSelectedDelegation(), false); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 939 | } |
| 940 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 941 | BOOST_AUTO_TEST_CASE(DecodeFromStream) |
Alexander Afanasyev | 6835ad8 | 2014-02-12 10:07:20 -0800 | [diff] [blame] | 942 | { |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 943 | boost::iostreams::stream<boost::iostreams::array_source> is( |
| 944 | reinterpret_cast<const char *>(Interest1), sizeof(Interest1)); |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 945 | |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 946 | Block interestBlock = Block::fromStream(is); |
Alexander Afanasyev | 6835ad8 | 2014-02-12 10:07:20 -0800 | [diff] [blame] | 947 | |
| 948 | ndn::Interest i; |
| 949 | BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock)); |
| 950 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 951 | BOOST_CHECK_EQUAL(i.getName().toUri(), "/local/ndn/prefix"); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 952 | BOOST_CHECK_EQUAL(i.getInterestLifetime(), time::milliseconds(1000)); |
| 953 | BOOST_CHECK_EQUAL(i.getMinSuffixComponents(), 1); |
| 954 | BOOST_CHECK_EQUAL(i.getMaxSuffixComponents(), 1); |
| 955 | BOOST_CHECK_EQUAL(i.getChildSelector(), 1); |
| 956 | BOOST_CHECK_EQUAL(i.getMustBeFresh(), false); |
| 957 | BOOST_CHECK_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy"); |
| 958 | BOOST_CHECK_EQUAL(i.getNonce(), 1U); |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 959 | BOOST_CHECK_EQUAL(i.hasLink(), false); |
| 960 | BOOST_CHECK_EQUAL(i.hasSelectedDelegation(), false); |
Alexander Afanasyev | 6835ad8 | 2014-02-12 10:07:20 -0800 | [diff] [blame] | 961 | } |
| 962 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 963 | BOOST_AUTO_TEST_CASE(Encode) |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 964 | { |
| 965 | ndn::Interest i(ndn::Name("/local/ndn/prefix")); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 966 | i.setInterestLifetime(time::milliseconds(1000)); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 967 | i.setMinSuffixComponents(1); |
| 968 | i.setMaxSuffixComponents(1); |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 969 | i.setPublisherPublicKeyLocator(KeyLocator("ndn:/test/key/locator")); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 970 | i.setChildSelector(1); |
| 971 | i.setMustBeFresh(false); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 972 | Exclude exclude; |
| 973 | exclude |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 974 | .excludeOne(name::Component("alex")) |
| 975 | .excludeRange(name::Component("xxxx"), name::Component("yyyy")); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 976 | i.setExclude(exclude); |
Alexander Afanasyev | 840139f | 2013-12-28 15:02:50 -0800 | [diff] [blame] | 977 | i.setNonce(1); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 978 | |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 979 | BOOST_CHECK_EQUAL(i.hasWire(), false); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 980 | const Block &wire = i.wireEncode(); |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 981 | BOOST_CHECK_EQUAL(i.hasWire(), true); |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 982 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 983 | BOOST_CHECK_EQUAL_COLLECTIONS(Interest1, Interest1 + sizeof(Interest1), |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 984 | wire.begin(), wire.end()); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 985 | |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 986 | const uint8_t* originalWire = wire.wire(); |
| 987 | i.setNonce(2); |
| 988 | BOOST_CHECK_EQUAL(i.hasWire(), true); |
| 989 | BOOST_CHECK_EQUAL(originalWire, i.wireEncode().wire()); |
| 990 | BOOST_CHECK_EQUAL(i.hasWire(), true); |
| 991 | |
| 992 | BOOST_CHECK_EQUAL_COLLECTIONS(Interest2, Interest2 + sizeof(Interest2), |
| 993 | wire.begin(), wire.end()); |
Alexander Afanasyev | a0c5f83 | 2014-06-19 13:27:56 -0700 | [diff] [blame] | 994 | |
| 995 | std::ostringstream strStream; |
| 996 | BOOST_CHECK_NO_THROW(strStream << i); |
| 997 | |
| 998 | BOOST_CHECK_EQUAL(strStream.str(), |
| 999 | "/local/ndn/prefix?" |
| 1000 | "ndn.MinSuffixComponents=1&ndn.MaxSuffixComponents=1&" |
Alexander Afanasyev | 117f5ef | 2015-06-03 15:07:24 -0700 | [diff] [blame] | 1001 | "ndn.ChildSelector=1&" |
Alexander Afanasyev | a0c5f83 | 2014-06-19 13:27:56 -0700 | [diff] [blame] | 1002 | "ndn.InterestLifetime=1000&" |
| 1003 | "ndn.Nonce=2&ndn.Exclude=alex,xxxx,*,yyyy"); |
Alexander Afanasyev | c393217 | 2014-07-10 18:53:56 -0700 | [diff] [blame] | 1004 | |
| 1005 | i.refreshNonce(); |
| 1006 | BOOST_CHECK_EQUAL(i.hasWire(), true); |
| 1007 | BOOST_CHECK_EQUAL(originalWire, i.wireEncode().wire()); |
| 1008 | BOOST_CHECK_NE(i.getNonce(), 2); |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 1009 | } |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 1010 | |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 1011 | BOOST_AUTO_TEST_CASE(DecodeEncode) // this test case to ensure that wireDecode resets all the fields |
| 1012 | { |
| 1013 | Interest i1; |
| 1014 | i1.setName("/test"); |
| 1015 | i1.setMinSuffixComponents(100); |
| 1016 | i1.setNonce(10); |
| 1017 | i1.setInterestLifetime(time::seconds(10)); |
| 1018 | i1.setLink(Block(LINK, sizeof(LINK))); |
| 1019 | i1.setSelectedDelegation(0); |
| 1020 | |
| 1021 | Interest i2(i1.wireEncode()); |
| 1022 | |
| 1023 | BOOST_CHECK_EQUAL(i2.getName().toUri(), "/test"); |
| 1024 | BOOST_CHECK_EQUAL(i2.getInterestLifetime(), time::seconds(10)); |
| 1025 | BOOST_CHECK_EQUAL(i2.getMinSuffixComponents(), 100); |
| 1026 | BOOST_CHECK_EQUAL(i2.getNonce(), 10); |
| 1027 | BOOST_CHECK_EQUAL(i2.hasLink(), true); |
| 1028 | BOOST_CHECK_EQUAL(i2.hasSelectedDelegation(), true); |
| 1029 | |
| 1030 | i2.wireDecode(Interest().wireEncode()); |
| 1031 | |
| 1032 | BOOST_CHECK_EQUAL(i2.getName().toUri(), "/"); |
| 1033 | BOOST_CHECK_EQUAL(i2.getInterestLifetime(), DEFAULT_INTEREST_LIFETIME); |
| 1034 | BOOST_CHECK_EQUAL(i2.getMinSuffixComponents(), -1); |
| 1035 | BOOST_WARN_NE(i2.getNonce(), 10); |
| 1036 | BOOST_CHECK_EQUAL(i2.hasLink(), false); |
| 1037 | BOOST_CHECK_EQUAL(i2.hasSelectedDelegation(), false); |
| 1038 | } |
| 1039 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 1040 | BOOST_AUTO_TEST_CASE(EncodeWithLocalHeader) |
| 1041 | { |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1042 | ndn::Interest interest(ndn::Name("/local/ndn/prefix")); |
| 1043 | interest.setMustBeFresh(true); |
| 1044 | interest.setIncomingFaceId(10); |
| 1045 | interest.setNonce(1); |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 1046 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1047 | BOOST_CHECK(!interest.hasWire()); |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 1048 | |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 1049 | Block headerBlock = |
| 1050 | interest.getLocalControlHeader() |
| 1051 | .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID | |
| 1052 | nfd::LocalControlHeader::ENCODE_NEXT_HOP); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 1053 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1054 | BOOST_CHECK(interest.hasWire()); |
| 1055 | BOOST_CHECK(headerBlock.hasWire()); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 1056 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1057 | BOOST_CHECK_NE(headerBlock.wire(), interest.wireEncode().wire()); |
| 1058 | BOOST_CHECK_NE(headerBlock.size(), interest.wireEncode().size()); |
| 1059 | BOOST_CHECK_EQUAL(headerBlock.size(), 5); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 1060 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1061 | BOOST_CHECK_EQUAL_COLLECTIONS(InterestWithLocalControlHeader, |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 1062 | InterestWithLocalControlHeader + 5, |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1063 | headerBlock.begin(), headerBlock.end()); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 1064 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1065 | interest.setNonce(1000); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 1066 | |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 1067 | Block updatedHeaderBlock = |
| 1068 | interest.getLocalControlHeader() |
| 1069 | .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID | |
| 1070 | nfd::LocalControlHeader::ENCODE_NEXT_HOP); |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1071 | BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 5); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 1072 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1073 | // only length should have changed |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 1074 | BOOST_CHECK_EQUAL_COLLECTIONS(updatedHeaderBlock.begin() + 2, updatedHeaderBlock.end(), |
| 1075 | headerBlock.begin() + 2, headerBlock.end()); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 1076 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1077 | // updating IncomingFaceId that keeps the length |
| 1078 | interest.setIncomingFaceId(100); |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 1079 | updatedHeaderBlock = |
| 1080 | interest.getLocalControlHeader() |
| 1081 | .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID | |
| 1082 | nfd::LocalControlHeader::ENCODE_NEXT_HOP); |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1083 | BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 5); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 1084 | BOOST_CHECK_NE(*(updatedHeaderBlock.begin() + 4), *(headerBlock.begin() + 4)); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 1085 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1086 | // updating IncomingFaceId that increases the length by 2 |
| 1087 | interest.setIncomingFaceId(1000); |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 1088 | updatedHeaderBlock = |
| 1089 | interest.getLocalControlHeader() |
| 1090 | .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID | |
| 1091 | nfd::LocalControlHeader::ENCODE_NEXT_HOP); |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1092 | BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 6); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 1093 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1094 | // adding NextHopId |
| 1095 | interest.setNextHopFaceId(1); |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 1096 | updatedHeaderBlock = |
| 1097 | interest.getLocalControlHeader() |
| 1098 | .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID | |
| 1099 | nfd::LocalControlHeader::ENCODE_NEXT_HOP); |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1100 | BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 9); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 1101 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1102 | // masking IncomingFaceId |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 1103 | updatedHeaderBlock = interest.getLocalControlHeader() |
| 1104 | .wireEncode(interest, nfd::LocalControlHeader::ENCODE_NEXT_HOP); |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1105 | BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 5); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 1106 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1107 | // masking NextHopId |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 1108 | updatedHeaderBlock = |
| 1109 | interest.getLocalControlHeader() |
| 1110 | .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID); |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1111 | BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 6); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 1112 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1113 | // masking everything |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 1114 | BOOST_CHECK_THROW(interest.getLocalControlHeader() |
| 1115 | .wireEncode(interest, nfd::LocalControlHeader::ENCODE_NONE), |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1116 | nfd::LocalControlHeader::Error); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 1117 | } |
| 1118 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1119 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 1120 | BOOST_AUTO_TEST_CASE(DecodeWithLocalHeader) |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 1121 | { |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1122 | Block wireBlock(InterestWithLocalControlHeader, sizeof(InterestWithLocalControlHeader)); |
| 1123 | const Block& payload = nfd::LocalControlHeader::getPayload(wireBlock); |
| 1124 | BOOST_REQUIRE_NE(&payload, &wireBlock); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 1125 | |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 1126 | BOOST_CHECK_EQUAL(payload.type(), static_cast<uint32_t>(tlv::Interest)); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 1127 | BOOST_CHECK_EQUAL(wireBlock.type(), static_cast<uint32_t>(tlv::nfd::LocalControlHeader)); |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 1128 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1129 | Interest interest(payload); |
| 1130 | BOOST_CHECK(!interest.getLocalControlHeader().hasIncomingFaceId()); |
| 1131 | BOOST_CHECK(!interest.getLocalControlHeader().hasNextHopFaceId()); |
| 1132 | |
| 1133 | BOOST_REQUIRE_NO_THROW(interest.getLocalControlHeader().wireDecode(wireBlock)); |
| 1134 | |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 1135 | BOOST_CHECK_EQUAL( |
| 1136 | interest.getLocalControlHeader() |
| 1137 | .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID | |
| 1138 | nfd::LocalControlHeader::ENCODE_NEXT_HOP).size(), |
| 1139 | 5); |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 1140 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1141 | BOOST_CHECK_EQUAL(interest.getIncomingFaceId(), 10); |
| 1142 | BOOST_CHECK(!interest.getLocalControlHeader().hasNextHopFaceId()); |
| 1143 | |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 1144 | BOOST_CHECK_THROW(interest.getLocalControlHeader() |
| 1145 | .wireEncode(interest, nfd::LocalControlHeader::ENCODE_NONE), |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1146 | nfd::LocalControlHeader::Error); |
| 1147 | |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 1148 | BOOST_CHECK_THROW(interest.getLocalControlHeader() |
| 1149 | .wireEncode(interest, nfd::LocalControlHeader::ENCODE_NEXT_HOP), |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1150 | nfd::LocalControlHeader::Error); |
| 1151 | |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 1152 | BOOST_CHECK_NO_THROW( |
| 1153 | interest.getLocalControlHeader() |
| 1154 | .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID)); |
| 1155 | BOOST_CHECK_NO_THROW( |
| 1156 | interest.getLocalControlHeader() |
| 1157 | .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID | |
| 1158 | nfd::LocalControlHeader::ENCODE_NEXT_HOP)); |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 1159 | |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 1160 | BOOST_CHECK_NE( |
| 1161 | (void*)interest.getLocalControlHeader() |
| 1162 | .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID | |
| 1163 | nfd::LocalControlHeader::ENCODE_NEXT_HOP) |
| 1164 | .wire(), |
| 1165 | (void*)wireBlock.wire()); |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1166 | |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 1167 | BOOST_CHECK_EQUAL(interest.getLocalControlHeader() |
| 1168 | .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID | |
| 1169 | nfd::LocalControlHeader::ENCODE_NEXT_HOP).size(), |
| 1170 | 5); |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1171 | } |
| 1172 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 1173 | BOOST_AUTO_TEST_CASE(DecodeWithoutLocalHeader) |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 1174 | { |
| 1175 | Block wireBlock(InterestWithoutLocalControlHeader, sizeof(InterestWithoutLocalControlHeader)); |
| 1176 | const Block& payload = nfd::LocalControlHeader::getPayload(wireBlock); |
| 1177 | BOOST_CHECK_EQUAL(&payload, &wireBlock); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 1178 | } |
| 1179 | |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1180 | BOOST_AUTO_TEST_CASE(MatchesData) |
| 1181 | { |
| 1182 | Interest interest; |
| 1183 | interest.setName("ndn:/A") |
| 1184 | .setMinSuffixComponents(2) |
| 1185 | .setMaxSuffixComponents(2) |
| 1186 | .setPublisherPublicKeyLocator(KeyLocator("ndn:/B")) |
| 1187 | .setExclude(Exclude().excludeBefore(name::Component("C"))); |
| 1188 | |
| 1189 | Data data("ndn:/A/D"); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 1190 | SignatureSha256WithRsa signature(KeyLocator("ndn:/B")); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1191 | data.setSignature(signature); |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1192 | data.wireEncode(); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1193 | BOOST_CHECK_EQUAL(interest.matchesData(data), true); |
| 1194 | |
| 1195 | Data data1 = data; |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1196 | data1.setName("ndn:/A"); // violates MinSuffixComponents |
| 1197 | data1.wireEncode(); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1198 | BOOST_CHECK_EQUAL(interest.matchesData(data1), false); |
| 1199 | |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1200 | interest.setMinSuffixComponents(1); |
| 1201 | BOOST_CHECK_EQUAL(interest.matchesData(data1), true); |
| 1202 | interest.setMinSuffixComponents(2); |
| 1203 | |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1204 | Data data2 = data; |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1205 | data2.setName("ndn:/A/E/F"); // violates MaxSuffixComponents |
| 1206 | data2.wireEncode(); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1207 | BOOST_CHECK_EQUAL(interest.matchesData(data2), false); |
| 1208 | |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1209 | interest.setMaxSuffixComponents(3); |
| 1210 | BOOST_CHECK_EQUAL(interest.matchesData(data2), true); |
| 1211 | interest.setMaxSuffixComponents(2); |
| 1212 | |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1213 | Data data3 = data; |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 1214 | SignatureSha256WithRsa signature3(KeyLocator("ndn:/G")); // violates PublisherPublicKeyLocator |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1215 | data3.setSignature(signature3); |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1216 | data3.wireEncode(); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1217 | BOOST_CHECK_EQUAL(interest.matchesData(data3), false); |
| 1218 | |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1219 | interest.setPublisherPublicKeyLocator(KeyLocator("ndn:/G")); |
| 1220 | BOOST_CHECK_EQUAL(interest.matchesData(data3), true); |
| 1221 | interest.setPublisherPublicKeyLocator(KeyLocator("ndn:/B")); |
| 1222 | |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1223 | Data data4 = data; |
Yingdi Yu | bf6a281 | 2014-06-17 15:32:11 -0700 | [diff] [blame] | 1224 | DigestSha256 signature4; // violates PublisherPublicKeyLocator |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1225 | data4.setSignature(signature4); |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1226 | data4.wireEncode(); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1227 | BOOST_CHECK_EQUAL(interest.matchesData(data4), false); |
| 1228 | |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1229 | interest.setPublisherPublicKeyLocator(KeyLocator()); |
| 1230 | BOOST_CHECK_EQUAL(interest.matchesData(data4), true); |
| 1231 | interest.setPublisherPublicKeyLocator(KeyLocator("ndn:/B")); |
| 1232 | |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1233 | Data data5 = data; |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1234 | data5.setName("ndn:/A/C"); // violates Exclude |
| 1235 | data5.wireEncode(); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1236 | BOOST_CHECK_EQUAL(interest.matchesData(data5), false); |
| 1237 | |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1238 | interest.setExclude(Exclude().excludeBefore(name::Component("A"))); |
| 1239 | BOOST_CHECK_EQUAL(interest.matchesData(data5), true); |
| 1240 | interest.setExclude(Exclude().excludeBefore(name::Component("C"))); |
| 1241 | |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1242 | Data data6 = data; |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1243 | data6.setName("ndn:/H/I"); // violates Name |
| 1244 | data6.wireEncode(); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1245 | BOOST_CHECK_EQUAL(interest.matchesData(data6), false); |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1246 | |
| 1247 | Data data7 = data; |
| 1248 | data7.setName("ndn:/A/B"); |
| 1249 | data7.wireEncode(); |
| 1250 | |
| 1251 | interest = Interest() |
Alexander Afanasyev | 56860f5 | 2014-11-07 11:51:17 -0800 | [diff] [blame] | 1252 | .setName("/A/B/sha256digest=D548DECEFC4B880720DC9257A8D815E9DF4465E63742EE55C29133055DAA67C2"); |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 1253 | BOOST_CHECK_EQUAL(interest.matchesData(data7), true); |
| 1254 | |
| 1255 | interest = Interest() |
| 1256 | .setName("/A/B/%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00" |
| 1257 | "%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00"); |
| 1258 | BOOST_CHECK_EQUAL(interest.matchesData(data7), false); // violates implicit digest |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 1261 | BOOST_AUTO_TEST_CASE(InterestFilterMatching) |
| 1262 | { |
| 1263 | BOOST_CHECK_EQUAL(InterestFilter("/a").doesMatch("/a/b"), true); |
| 1264 | BOOST_CHECK_EQUAL(InterestFilter("/a/b").doesMatch("/a/b"), true); |
| 1265 | BOOST_CHECK_EQUAL(InterestFilter("/a/b/c").doesMatch("/a/b"), false); |
| 1266 | |
| 1267 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b"), true); |
| 1268 | BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b"), false); |
| 1269 | |
| 1270 | BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b/c/b"), false); |
| 1271 | BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<>*<b>").doesMatch("/a/b/c/b"), true); |
| 1272 | |
| 1273 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b/c/d"), false); |
| 1274 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b/c/d"), true); |
| 1275 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b"), true); |
| 1276 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b"), false); |
| 1277 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b/c"), true); |
| 1278 | } |
| 1279 | |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 1280 | BOOST_AUTO_TEST_SUITE_END() |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 1281 | |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 1282 | } // namespace tests |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 1283 | } // namespace ndn |