Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 2bea5c4 | 2017-08-14 20:10:32 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2013-2020 Regents of the University of California. |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 80b68e1 | 2015-09-17 17:01:04 -0700 | [diff] [blame] | 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | 80b68e1 | 2015-09-17 17:01:04 -0700 | [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. |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 10 | * |
Alexander Afanasyev | 80b68e1 | 2015-09-17 17:01:04 -0700 | [diff] [blame] | 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. |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 14 | * |
Alexander Afanasyev | 80b68e1 | 2015-09-17 17:01:04 -0700 | [diff] [blame] | 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. |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 22 | #include "ndn-cxx/mgmt/status-dataset-context.hpp" |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 23 | |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame^] | 24 | #include "tests/test-common.hpp" |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 25 | |
| 26 | namespace ndn { |
| 27 | namespace mgmt { |
| 28 | namespace tests { |
| 29 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 30 | using namespace ndn::tests; |
| 31 | |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 32 | class StatusDatasetContextFixture |
| 33 | { |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 34 | private: |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 35 | struct SendDataArgs |
| 36 | { |
| 37 | Name dataName; |
| 38 | Block content; |
| 39 | time::milliseconds imsFresh; |
| 40 | bool isFinalBlock; |
| 41 | }; |
| 42 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 43 | protected: |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 44 | StatusDatasetContextFixture() |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 45 | : interest(makeInterest("/test/context/interest")) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 46 | , contentBlock(makeStringBlock(tlv::Content, "/test/data/content")) |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 47 | , context(*interest, |
| 48 | [this] (const Name& dataName, const Block& content, |
| 49 | time::milliseconds imsFresh, bool isFinalBlock) { |
| 50 | SendDataArgs args{dataName, content, imsFresh, isFinalBlock}; |
| 51 | sendDataHistory.push_back(args); |
| 52 | }, |
| 53 | [this] (const ControlResponse& resp) { |
| 54 | sendNackHistory.push_back(resp); |
| 55 | }) |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 56 | , defaultImsFresh(1000_ms) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 57 | { |
| 58 | } |
| 59 | |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 60 | Name |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 61 | makeSegmentName(size_t segmentNo) const |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 62 | { |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 63 | auto name = context.getPrefix(); |
| 64 | return name.appendSegment(segmentNo); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | Block |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 68 | concatenateDataContent() const |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 69 | { |
| 70 | EncodingBuffer encoder; |
| 71 | size_t valueLength = 0; |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 72 | for (const auto& args : sendDataHistory) { |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 73 | const auto& content = args.content; |
| 74 | valueLength += encoder.appendByteArray(content.value(), content.value_size()); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 75 | } |
| 76 | encoder.prependVarNumber(valueLength); |
| 77 | encoder.prependVarNumber(tlv::Content); |
| 78 | return encoder.block(); |
| 79 | } |
| 80 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 81 | protected: |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 82 | std::vector<SendDataArgs> sendDataHistory; |
| 83 | std::vector<ControlResponse> sendNackHistory; |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 84 | shared_ptr<Interest> interest; |
| 85 | Block contentBlock; |
| 86 | mgmt::StatusDatasetContext context; |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 87 | time::milliseconds defaultImsFresh; |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 90 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 91 | BOOST_FIXTURE_TEST_SUITE(TestStatusDatasetContext, StatusDatasetContextFixture) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 92 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 93 | BOOST_AUTO_TEST_SUITE(Prefix) |
| 94 | |
| 95 | BOOST_AUTO_TEST_CASE(Get) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 96 | { |
| 97 | Name dataName = context.getPrefix(); |
| 98 | BOOST_CHECK(dataName[-1].isVersion()); |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 99 | BOOST_CHECK_EQUAL(dataName.getPrefix(-1), interest->getName()); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 102 | BOOST_AUTO_TEST_CASE(SetValid) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 103 | { |
| 104 | Name validPrefix = Name(interest->getName()).append("/valid"); |
| 105 | BOOST_CHECK_NO_THROW(context.setPrefix(validPrefix)); |
| 106 | BOOST_CHECK(context.getPrefix()[-1].isVersion()); |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 107 | BOOST_CHECK_EQUAL(context.getPrefix().getPrefix(-1), validPrefix); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 110 | BOOST_AUTO_TEST_CASE(SetInvalid) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 111 | { |
| 112 | Name invalidPrefix = Name(interest->getName()).getPrefix(-1).append("/invalid"); |
| 113 | BOOST_CHECK_THROW(context.setPrefix(invalidPrefix), std::invalid_argument); |
| 114 | } |
| 115 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 116 | BOOST_AUTO_TEST_CASE(SetValidWithAppendCalled) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 117 | { |
| 118 | Name validPrefix = Name(interest->getName()).append("/valid"); |
| 119 | context.append(contentBlock); |
| 120 | BOOST_CHECK_THROW(context.setPrefix(validPrefix), std::domain_error); |
| 121 | } |
| 122 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 123 | BOOST_AUTO_TEST_CASE(SetValidWithEndCalled) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 124 | { |
| 125 | Name validPrefix = Name(interest->getName()).append("/valid"); |
| 126 | context.end(); |
| 127 | BOOST_CHECK_THROW(context.setPrefix(validPrefix), std::domain_error); |
| 128 | } |
| 129 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 130 | BOOST_AUTO_TEST_CASE(SetValidWithRejectCalled) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 131 | { |
| 132 | Name validPrefix = Name(interest->getName()).append("/valid"); |
| 133 | context.reject(); |
| 134 | BOOST_CHECK_THROW(context.setPrefix(validPrefix), std::domain_error); |
| 135 | } |
| 136 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 137 | BOOST_AUTO_TEST_SUITE_END() // Prefix |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 138 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 139 | BOOST_AUTO_TEST_SUITE(Expiry) |
| 140 | |
| 141 | BOOST_AUTO_TEST_CASE(GetAndSet) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 142 | { |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 143 | auto period = 9527_ms; |
| 144 | BOOST_CHECK_EQUAL(context.getExpiry(), 1000_ms); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 145 | BOOST_CHECK_EQUAL(context.setExpiry(period).getExpiry(), period); |
| 146 | } |
| 147 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 148 | BOOST_AUTO_TEST_SUITE_END() // Expiry |
| 149 | |
| 150 | BOOST_AUTO_TEST_SUITE(Respond) |
| 151 | |
| 152 | BOOST_AUTO_TEST_CASE(Basic) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 153 | { |
| 154 | BOOST_CHECK_NO_THROW(context.append(contentBlock)); |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 155 | BOOST_CHECK(sendDataHistory.empty()); // does not call end yet |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 156 | |
| 157 | BOOST_CHECK_NO_THROW(context.end()); |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 158 | |
| 159 | BOOST_REQUIRE_EQUAL(sendDataHistory.size(), 1); |
| 160 | const auto& args = sendDataHistory[0]; |
| 161 | |
| 162 | BOOST_CHECK_EQUAL(args.dataName, makeSegmentName(0)); |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 163 | BOOST_CHECK_EQUAL(args.content.blockFromValue(), contentBlock); |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 164 | BOOST_CHECK_EQUAL(args.imsFresh, defaultImsFresh); |
| 165 | BOOST_CHECK_EQUAL(args.isFinalBlock, true); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 168 | BOOST_AUTO_TEST_CASE(Large) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 169 | { |
| 170 | static Block largeBlock = [] () -> Block { |
| 171 | EncodingBuffer encoder; |
| 172 | size_t maxBlockSize = MAX_NDN_PACKET_SIZE >> 1; |
| 173 | for (size_t i = 0; i < maxBlockSize; ++i) { |
| 174 | encoder.prependByte(1); |
| 175 | } |
| 176 | encoder.prependVarNumber(maxBlockSize); |
| 177 | encoder.prependVarNumber(tlv::Content); |
| 178 | return encoder.block(); |
| 179 | }(); |
| 180 | |
| 181 | BOOST_CHECK_NO_THROW(context.append(largeBlock)); |
| 182 | BOOST_CHECK_NO_THROW(context.end()); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 183 | |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 184 | // two segments are generated |
| 185 | BOOST_REQUIRE_EQUAL(sendDataHistory.size(), 2); |
| 186 | |
| 187 | // check segment0 |
| 188 | BOOST_CHECK_EQUAL(sendDataHistory[0].dataName, makeSegmentName(0)); |
| 189 | BOOST_CHECK_EQUAL(sendDataHistory[0].imsFresh, defaultImsFresh); |
| 190 | BOOST_CHECK_EQUAL(sendDataHistory[0].isFinalBlock, false); |
| 191 | |
| 192 | // check segment1 |
| 193 | BOOST_CHECK_EQUAL(sendDataHistory[1].dataName, makeSegmentName(1)); |
| 194 | BOOST_CHECK_EQUAL(sendDataHistory[1].imsFresh, defaultImsFresh); |
| 195 | BOOST_CHECK_EQUAL(sendDataHistory[1].isFinalBlock, true); |
| 196 | |
| 197 | // check data content |
| 198 | auto contentLargeBlock = concatenateDataContent(); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 199 | BOOST_CHECK_NO_THROW(contentLargeBlock.parse()); |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 200 | BOOST_REQUIRE_EQUAL(contentLargeBlock.elements().size(), 1); |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 201 | BOOST_CHECK_EQUAL(contentLargeBlock.elements()[0], largeBlock); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 204 | BOOST_AUTO_TEST_CASE(MultipleSmall) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 205 | { |
| 206 | size_t nBlocks = 100; |
| 207 | for (size_t i = 0 ; i < nBlocks ; i ++) { |
| 208 | BOOST_CHECK_NO_THROW(context.append(contentBlock)); |
| 209 | } |
| 210 | BOOST_CHECK_NO_THROW(context.end()); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 211 | |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 212 | // check data to in-memory storage |
| 213 | BOOST_REQUIRE_EQUAL(sendDataHistory.size(), 1); |
| 214 | BOOST_CHECK_EQUAL(sendDataHistory[0].dataName, makeSegmentName(0)); |
| 215 | BOOST_CHECK_EQUAL(sendDataHistory[0].imsFresh, defaultImsFresh); |
| 216 | BOOST_CHECK_EQUAL(sendDataHistory[0].isFinalBlock, true); |
| 217 | |
| 218 | auto contentMultiBlocks = concatenateDataContent(); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 219 | BOOST_CHECK_NO_THROW(contentMultiBlocks.parse()); |
| 220 | BOOST_CHECK_EQUAL(contentMultiBlocks.elements().size(), nBlocks); |
| 221 | for (auto&& element : contentMultiBlocks.elements()) { |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 222 | BOOST_CHECK_EQUAL(element, contentBlock); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 226 | BOOST_AUTO_TEST_SUITE_END() // Respond |
| 227 | |
| 228 | BOOST_AUTO_TEST_SUITE(Reject) |
| 229 | |
| 230 | BOOST_AUTO_TEST_CASE(Basic) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 231 | { |
| 232 | BOOST_CHECK_NO_THROW(context.reject()); |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 233 | BOOST_REQUIRE_EQUAL(sendNackHistory.size(), 1); |
| 234 | BOOST_CHECK_EQUAL(sendNackHistory[0].getCode(), 400); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 237 | BOOST_AUTO_TEST_SUITE_END() // Reject |
| 238 | |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 239 | class AbnormalStateTestFixture |
| 240 | { |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 241 | protected: |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 242 | AbnormalStateTestFixture() |
| 243 | : context(Interest("/abnormal-state"), bind([]{}), bind([]{})) |
| 244 | { |
| 245 | } |
| 246 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 247 | protected: |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 248 | mgmt::StatusDatasetContext context; |
| 249 | }; |
| 250 | |
| 251 | BOOST_FIXTURE_TEST_SUITE(AbnormalState, AbnormalStateTestFixture) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 252 | |
| 253 | BOOST_AUTO_TEST_CASE(AppendReject) |
| 254 | { |
Davide Pesavento | b10024c | 2017-09-22 01:36:44 -0400 | [diff] [blame] | 255 | const uint8_t buf[] = {0x82, 0x01, 0x02}; |
| 256 | BOOST_CHECK_NO_THROW(context.append(Block(buf, sizeof(buf)))); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 257 | BOOST_CHECK_THROW(context.reject(), std::domain_error); |
| 258 | } |
| 259 | |
| 260 | BOOST_AUTO_TEST_CASE(AppendEndReject) |
| 261 | { |
Davide Pesavento | b10024c | 2017-09-22 01:36:44 -0400 | [diff] [blame] | 262 | const uint8_t buf[] = {0x82, 0x01, 0x02}; |
| 263 | BOOST_CHECK_NO_THROW(context.append(Block(buf, sizeof(buf)))); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 264 | BOOST_CHECK_NO_THROW(context.end()); |
| 265 | BOOST_CHECK_THROW(context.reject(), std::domain_error); |
| 266 | } |
| 267 | |
| 268 | BOOST_AUTO_TEST_CASE(EndAppend) |
| 269 | { |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 270 | BOOST_CHECK_NO_THROW(context.end()); |
| 271 | // end, append -> error |
Davide Pesavento | b10024c | 2017-09-22 01:36:44 -0400 | [diff] [blame] | 272 | const uint8_t buf[] = {0x82, 0x01, 0x02}; |
| 273 | BOOST_CHECK_THROW(context.append(Block(buf, sizeof(buf))), std::domain_error); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | BOOST_AUTO_TEST_CASE(EndEnd) |
| 277 | { |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 278 | BOOST_CHECK_NO_THROW(context.end()); |
| 279 | BOOST_CHECK_THROW(context.end(), std::domain_error); |
| 280 | } |
| 281 | |
| 282 | BOOST_AUTO_TEST_CASE(EndReject) |
| 283 | { |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 284 | BOOST_CHECK_NO_THROW(context.end()); |
| 285 | BOOST_CHECK_THROW(context.reject(), std::domain_error); |
| 286 | } |
| 287 | |
| 288 | BOOST_AUTO_TEST_CASE(RejectAppend) |
| 289 | { |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 290 | BOOST_CHECK_NO_THROW(context.reject()); |
Davide Pesavento | b10024c | 2017-09-22 01:36:44 -0400 | [diff] [blame] | 291 | const uint8_t buf[] = {0x82, 0x01, 0x02}; |
| 292 | BOOST_CHECK_THROW(context.append(Block(buf, sizeof(buf))), std::domain_error); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | BOOST_AUTO_TEST_CASE(RejectEnd) |
| 296 | { |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 297 | BOOST_CHECK_NO_THROW(context.reject()); |
| 298 | BOOST_CHECK_THROW(context.end(), std::domain_error); |
| 299 | } |
| 300 | |
| 301 | BOOST_AUTO_TEST_SUITE_END() // AbnormalState |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 302 | |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 303 | BOOST_AUTO_TEST_SUITE_END() // TestStatusDatasetContext |
| 304 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 305 | |
| 306 | } // namespace tests |
| 307 | } // namespace mgmt |
| 308 | } // namespace ndn |