Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013-2018 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. |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 22 | #include "mgmt/nfd/control-parameters.hpp" |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 24 | #include "boost-test.hpp" |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 25 | |
| 26 | namespace ndn { |
| 27 | namespace nfd { |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 28 | namespace tests { |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 29 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 30 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 31 | BOOST_AUTO_TEST_SUITE(Nfd) |
| 32 | BOOST_AUTO_TEST_SUITE(TestControlParameters) |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 33 | |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 34 | BOOST_AUTO_TEST_CASE(Fields) |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 35 | { |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 36 | ControlParameters input; |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 37 | |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 38 | ControlParameters decoded(input.wireEncode()); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 39 | BOOST_CHECK_EQUAL(decoded.hasName(), false); |
| 40 | BOOST_CHECK_EQUAL(decoded.hasFaceId(), false); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 41 | BOOST_CHECK_EQUAL(decoded.hasUri(), false); |
Eric Newberry | d7f5b28 | 2017-03-28 19:55:20 -0700 | [diff] [blame] | 42 | BOOST_CHECK_EQUAL(decoded.hasLocalUri(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 43 | BOOST_CHECK_EQUAL(decoded.hasOrigin(), false); |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 44 | BOOST_CHECK_EQUAL(decoded.hasCost(), false); |
| 45 | BOOST_CHECK_EQUAL(decoded.hasCapacity(), false); |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 46 | BOOST_CHECK_EQUAL(decoded.hasCount(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 47 | BOOST_CHECK_EQUAL(decoded.hasFlags(), false); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 48 | BOOST_CHECK_EQUAL(decoded.hasMask(), false); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 49 | BOOST_CHECK_EQUAL(decoded.hasStrategy(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 50 | BOOST_CHECK_EQUAL(decoded.hasExpirationPeriod(), false); |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 51 | BOOST_CHECK_EQUAL(decoded.hasFacePersistency(), false); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 52 | |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 53 | input.setName("/name"); |
| 54 | input.setFaceId(2634); |
| 55 | input.setUri("udp4://192.0.2.1:6363"); |
| 56 | input.setLocalUri("udp4://192.0.2.2:6363"); |
| 57 | input.setOrigin(ROUTE_ORIGIN_NLSR); |
| 58 | input.setCost(1388); |
| 59 | input.setCapacity(2632); |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 60 | input.setCount(3100); |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 61 | input.setFlags(0xAFC4); |
| 62 | input.setMask(0xF7A1); |
| 63 | input.setStrategy("/strategy-name"); |
| 64 | input.setExpirationPeriod(1800000_ms); |
| 65 | input.setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 66 | |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 67 | decoded.wireDecode(input.wireEncode()); |
| 68 | BOOST_CHECK_EQUAL(decoded.hasName(), true); |
| 69 | BOOST_CHECK_EQUAL(decoded.hasFaceId(), true); |
| 70 | BOOST_CHECK_EQUAL(decoded.hasUri(), true); |
| 71 | BOOST_CHECK_EQUAL(decoded.hasLocalUri(), true); |
| 72 | BOOST_CHECK_EQUAL(decoded.hasOrigin(), true); |
| 73 | BOOST_CHECK_EQUAL(decoded.hasCost(), true); |
| 74 | BOOST_CHECK_EQUAL(decoded.hasCapacity(), true); |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 75 | BOOST_CHECK_EQUAL(decoded.hasCount(), true); |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 76 | BOOST_CHECK_EQUAL(decoded.hasFlags(), true); |
| 77 | BOOST_CHECK_EQUAL(decoded.hasMask(), true); |
| 78 | BOOST_CHECK_EQUAL(decoded.hasStrategy(), true); |
| 79 | BOOST_CHECK_EQUAL(decoded.hasExpirationPeriod(), true); |
| 80 | BOOST_CHECK_EQUAL(decoded.hasFacePersistency(), true); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 81 | |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 82 | BOOST_CHECK_EQUAL(decoded.getName(), "/name"); |
| 83 | BOOST_CHECK_EQUAL(decoded.getFaceId(), 2634); |
| 84 | BOOST_CHECK_EQUAL(decoded.getUri(), "udp4://192.0.2.1:6363"); |
| 85 | BOOST_CHECK_EQUAL(decoded.getLocalUri(), "udp4://192.0.2.2:6363"); |
Davide Pesavento | e8e48c2 | 2017-04-13 00:35:33 -0400 | [diff] [blame] | 86 | BOOST_CHECK_EQUAL(decoded.getOrigin(), ROUTE_ORIGIN_NLSR); |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 87 | BOOST_CHECK_EQUAL(decoded.getCost(), 1388); |
| 88 | BOOST_CHECK_EQUAL(decoded.getCapacity(), 2632); |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 89 | BOOST_CHECK_EQUAL(decoded.getCount(), 3100); |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 90 | BOOST_CHECK_EQUAL(decoded.getFlags(), 0xAFC4); |
| 91 | BOOST_CHECK_EQUAL(decoded.getMask(), 0xF7A1); |
| 92 | BOOST_CHECK_EQUAL(decoded.getStrategy(), "/strategy-name"); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 93 | BOOST_CHECK_EQUAL(decoded.getExpirationPeriod(), 1800000_ms); |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 94 | BOOST_CHECK_EQUAL(decoded.getFacePersistency(), FacePersistency::FACE_PERSISTENCY_PERSISTENT); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 95 | |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 96 | input.unsetName(); |
| 97 | input.unsetFaceId(); |
| 98 | input.unsetUri(); |
| 99 | input.unsetLocalUri(); |
| 100 | input.unsetOrigin(); |
| 101 | input.unsetCost(); |
| 102 | input.unsetCapacity(); |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 103 | input.unsetCount(); |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 104 | input.unsetFlags(); |
| 105 | input.unsetMask(); |
| 106 | input.unsetStrategy(); |
| 107 | input.unsetExpirationPeriod(); |
| 108 | input.unsetFacePersistency(); |
| 109 | BOOST_CHECK_EQUAL(input.hasName(), false); |
| 110 | BOOST_CHECK_EQUAL(input.hasFaceId(), false); |
| 111 | BOOST_CHECK_EQUAL(input.hasUri(), false); |
| 112 | BOOST_CHECK_EQUAL(input.hasLocalUri(), false); |
| 113 | BOOST_CHECK_EQUAL(input.hasOrigin(), false); |
| 114 | BOOST_CHECK_EQUAL(input.hasCost(), false); |
| 115 | BOOST_CHECK_EQUAL(input.hasCapacity(), false); |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 116 | BOOST_CHECK_EQUAL(input.hasCount(), false); |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 117 | BOOST_CHECK_EQUAL(input.hasFlags(), false); |
| 118 | BOOST_CHECK_EQUAL(input.hasMask(), false); |
| 119 | BOOST_CHECK_EQUAL(input.hasStrategy(), false); |
| 120 | BOOST_CHECK_EQUAL(input.hasExpirationPeriod(), false); |
| 121 | BOOST_CHECK_EQUAL(input.hasFacePersistency(), false); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 124 | BOOST_AUTO_TEST_CASE(FlagsAndMask) |
| 125 | { |
| 126 | ControlParameters p; |
| 127 | |
| 128 | BOOST_CHECK(!p.hasFlags()); |
| 129 | BOOST_CHECK(!p.hasMask()); |
| 130 | BOOST_CHECK(!p.hasFlagBit(0)); |
| 131 | BOOST_CHECK(!p.getFlagBit(0)); |
| 132 | |
| 133 | // Set bit 2 to true (change Mask) |
| 134 | p.setFlagBit(2, true); |
| 135 | // 2^2 = 4 |
| 136 | BOOST_CHECK_EQUAL(p.getFlags(), 4); |
| 137 | BOOST_CHECK_EQUAL(p.getMask(), 4); |
| 138 | BOOST_CHECK(p.hasFlagBit(2)); |
| 139 | BOOST_CHECK(p.getFlagBit(2)); |
| 140 | BOOST_CHECK(!p.hasFlagBit(1)); |
| 141 | BOOST_CHECK(!p.getFlagBit(1)); |
| 142 | |
| 143 | // Set bit 3 to true (no change to Mask) |
| 144 | p.setFlagBit(3, true, false); |
| 145 | // 2^3 + 2^2 = 12 |
| 146 | BOOST_CHECK_EQUAL(p.getFlags(), 12); |
| 147 | // 2^2 = 4 |
| 148 | BOOST_CHECK_EQUAL(p.getMask(), 4); |
| 149 | BOOST_CHECK(!p.hasFlagBit(3)); |
| 150 | BOOST_CHECK(p.getFlagBit(3)); |
| 151 | BOOST_CHECK(p.hasFlagBit(2)); |
| 152 | BOOST_CHECK(p.getFlagBit(2)); |
| 153 | |
| 154 | // Set bit 1 to false (change Mask) |
| 155 | p.setFlagBit(1, false); |
| 156 | // 2^3 + 2^2 = 12 |
| 157 | BOOST_CHECK_EQUAL(p.getFlags(), 12); |
| 158 | // 2^2 + 2^1 = 6 |
| 159 | BOOST_CHECK_EQUAL(p.getMask(), 6); |
| 160 | BOOST_CHECK(!p.hasFlagBit(3)); |
| 161 | BOOST_CHECK(p.getFlagBit(3)); |
| 162 | BOOST_CHECK(p.hasFlagBit(2)); |
| 163 | BOOST_CHECK(p.getFlagBit(2)); |
| 164 | BOOST_CHECK(p.hasFlagBit(1)); |
| 165 | BOOST_CHECK(!p.getFlagBit(1)); |
| 166 | |
| 167 | // Set bit 2 to false (change Mask) |
| 168 | p.setFlagBit(2, false); |
| 169 | // 2^3 = 8 |
| 170 | BOOST_CHECK_EQUAL(p.getFlags(), 8); |
| 171 | // 2^2 + 2^1 = 6 |
| 172 | BOOST_CHECK_EQUAL(p.getMask(), 6); |
| 173 | BOOST_CHECK(!p.hasFlagBit(3)); |
| 174 | BOOST_CHECK(p.getFlagBit(3)); |
| 175 | BOOST_CHECK(p.hasFlagBit(2)); |
| 176 | BOOST_CHECK(!p.getFlagBit(2)); |
| 177 | BOOST_CHECK(p.hasFlagBit(1)); |
| 178 | BOOST_CHECK(!p.getFlagBit(1)); |
| 179 | |
| 180 | // Set bit 0 to true (change Mask) |
| 181 | p.setFlagBit(0, true); |
| 182 | // 2^3 + 2^0 = 9 |
| 183 | BOOST_CHECK_EQUAL(p.getFlags(), 9); |
| 184 | // 2^2 + 2^1 + 2^0 = 7 |
| 185 | BOOST_CHECK_EQUAL(p.getMask(), 7); |
| 186 | BOOST_CHECK(p.hasFlagBit(0)); |
| 187 | BOOST_CHECK(p.getFlagBit(0)); |
| 188 | |
| 189 | // Unset bit 0 |
| 190 | p.unsetFlagBit(0); |
| 191 | BOOST_REQUIRE(p.hasFlags()); |
| 192 | BOOST_REQUIRE(p.hasMask()); |
| 193 | // 2^3 + 2^0 = 9 |
| 194 | BOOST_CHECK_EQUAL(p.getFlags(), 9); |
| 195 | // 2^2 + 2^1 = 6 |
| 196 | BOOST_CHECK_EQUAL(p.getMask(), 6); |
| 197 | BOOST_CHECK(p.hasFlagBit(1)); |
| 198 | BOOST_CHECK(!p.hasFlagBit(0)); |
| 199 | BOOST_CHECK(p.getFlagBit(0)); |
| 200 | |
| 201 | // Unset bit 3 (already unset in Mask, so no change) |
| 202 | p.unsetFlagBit(3); |
| 203 | BOOST_REQUIRE(p.hasFlags()); |
| 204 | BOOST_REQUIRE(p.hasMask()); |
| 205 | // 2^3 + 2^0 = 9 |
| 206 | BOOST_CHECK_EQUAL(p.getFlags(), 9); |
| 207 | // 2^2 + 2^1 = 6 |
| 208 | BOOST_CHECK_EQUAL(p.getMask(), 6); |
| 209 | BOOST_CHECK(!p.hasFlagBit(3)); |
| 210 | BOOST_CHECK(p.getFlagBit(3)); |
| 211 | |
| 212 | // Unset bit 2 |
| 213 | p.unsetFlagBit(2); |
| 214 | BOOST_REQUIRE(p.hasFlags()); |
| 215 | BOOST_REQUIRE(p.hasMask()); |
| 216 | // 2^3 + 2^0 = 9 |
| 217 | BOOST_CHECK_EQUAL(p.getFlags(), 9); |
| 218 | // 2^1 = 2 |
| 219 | BOOST_CHECK_EQUAL(p.getMask(), 2); |
| 220 | BOOST_CHECK(!p.hasFlagBit(2)); |
| 221 | BOOST_CHECK(!p.getFlagBit(2)); |
| 222 | |
| 223 | // Unset bit 1 |
| 224 | // Flags and Mask fields will be deleted as Mask is now 0 |
| 225 | p.unsetFlagBit(1); |
| 226 | BOOST_CHECK(!p.hasFlags()); |
| 227 | BOOST_CHECK(!p.hasMask()); |
| 228 | BOOST_CHECK(!p.hasFlagBit(3)); |
| 229 | BOOST_CHECK(!p.getFlagBit(3)); |
| 230 | BOOST_CHECK(!p.hasFlagBit(2)); |
| 231 | BOOST_CHECK(!p.getFlagBit(2)); |
| 232 | BOOST_CHECK(!p.hasFlagBit(1)); |
| 233 | BOOST_CHECK(!p.getFlagBit(1)); |
| 234 | BOOST_CHECK(!p.hasFlagBit(0)); |
| 235 | BOOST_CHECK(!p.getFlagBit(0)); |
| 236 | |
| 237 | BOOST_CHECK_THROW(p.setFlagBit(64, true), std::out_of_range); |
| 238 | BOOST_CHECK_THROW(p.unsetFlagBit(64), std::out_of_range); |
| 239 | } |
| 240 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 241 | BOOST_AUTO_TEST_SUITE_END() // TestControlParameters |
| 242 | BOOST_AUTO_TEST_SUITE_END() // Nfd |
| 243 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 244 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 245 | } // namespace tests |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 246 | } // namespace nfd |
| 247 | } // namespace ndn |