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 | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2021 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; |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 39 | bool isFinalBlock; |
| 40 | }; |
| 41 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 42 | protected: |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 43 | StatusDatasetContextFixture() |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 44 | : interest(makeInterest("/test/context/interest")) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 45 | , contentBlock(makeStringBlock(tlv::Content, "/test/data/content")) |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 46 | , context(*interest, |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 47 | [this] (auto&&... args) { |
| 48 | sendDataHistory.push_back({std::forward<decltype(args)>(args)...}); |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 49 | }, |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 50 | [this] (const auto& resp) { |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 51 | sendNackHistory.push_back(resp); |
| 52 | }) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 53 | { |
| 54 | } |
| 55 | |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 56 | Name |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 57 | makeSegmentName(size_t segmentNo) const |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 58 | { |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 59 | auto name = context.getPrefix(); |
| 60 | return name.appendSegment(segmentNo); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | Block |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 64 | concatenateDataContent() const |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 65 | { |
| 66 | EncodingBuffer encoder; |
| 67 | size_t valueLength = 0; |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 68 | for (const auto& args : sendDataHistory) { |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 69 | const auto& content = args.content; |
| 70 | valueLength += encoder.appendByteArray(content.value(), content.value_size()); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 71 | } |
| 72 | encoder.prependVarNumber(valueLength); |
| 73 | encoder.prependVarNumber(tlv::Content); |
| 74 | return encoder.block(); |
| 75 | } |
| 76 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 77 | protected: |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 78 | shared_ptr<Interest> interest; |
| 79 | Block contentBlock; |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 80 | StatusDatasetContext context; |
| 81 | std::vector<SendDataArgs> sendDataHistory; |
| 82 | std::vector<ControlResponse> sendNackHistory; |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 85 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 86 | BOOST_FIXTURE_TEST_SUITE(TestStatusDatasetContext, StatusDatasetContextFixture) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 87 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 88 | BOOST_AUTO_TEST_SUITE(Prefix) |
| 89 | |
| 90 | BOOST_AUTO_TEST_CASE(Get) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 91 | { |
| 92 | Name dataName = context.getPrefix(); |
| 93 | BOOST_CHECK(dataName[-1].isVersion()); |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 94 | BOOST_CHECK_EQUAL(dataName.getPrefix(-1), interest->getName()); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 97 | BOOST_AUTO_TEST_CASE(SetValid) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 98 | { |
| 99 | Name validPrefix = Name(interest->getName()).append("/valid"); |
| 100 | BOOST_CHECK_NO_THROW(context.setPrefix(validPrefix)); |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 101 | BOOST_CHECK_EQUAL(context.getPrefix().getPrefix(-1), validPrefix); |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 102 | BOOST_CHECK(context.getPrefix()[-1].isVersion()); |
| 103 | |
| 104 | // trailing version component is preserved |
| 105 | validPrefix.appendVersion(42); |
| 106 | BOOST_CHECK_NO_THROW(context.setPrefix(validPrefix)); |
| 107 | BOOST_CHECK_EQUAL(context.getPrefix(), 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 | { |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 112 | // Interest name is not a prefix of invalidPrefix |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 113 | Name invalidPrefix = Name(interest->getName()).getPrefix(-1).append("/invalid"); |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 114 | BOOST_CHECK_EXCEPTION(context.setPrefix(invalidPrefix), std::invalid_argument, [] (const auto& e) { |
| 115 | return e.what() == "prefix must start with the Interest's name"s; |
| 116 | }); |
| 117 | |
| 118 | // invalidPrefix contains a segment component |
| 119 | invalidPrefix = Name(interest->getName()).appendSegment(1); |
| 120 | BOOST_CHECK_EXCEPTION(context.setPrefix(invalidPrefix), std::invalid_argument, [] (const auto& e) { |
| 121 | return e.what() == "prefix must not contain a segment component"s; |
| 122 | }); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 125 | BOOST_AUTO_TEST_CASE(SetValidAfterAppend) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 126 | { |
| 127 | Name validPrefix = Name(interest->getName()).append("/valid"); |
| 128 | context.append(contentBlock); |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 129 | BOOST_CHECK_EXCEPTION(context.setPrefix(validPrefix), std::logic_error, [] (const auto& e) { |
| 130 | return e.what() == "cannot call setPrefix() after append/end/reject"s; |
| 131 | }); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 134 | BOOST_AUTO_TEST_CASE(SetValidAfterEnd) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 135 | { |
| 136 | Name validPrefix = Name(interest->getName()).append("/valid"); |
| 137 | context.end(); |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 138 | BOOST_CHECK_EXCEPTION(context.setPrefix(validPrefix), std::logic_error, [] (const auto& e) { |
| 139 | return e.what() == "cannot call setPrefix() after append/end/reject"s; |
| 140 | }); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 143 | BOOST_AUTO_TEST_CASE(SetValidAfterReject) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 144 | { |
| 145 | Name validPrefix = Name(interest->getName()).append("/valid"); |
| 146 | context.reject(); |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 147 | BOOST_CHECK_EXCEPTION(context.setPrefix(validPrefix), std::logic_error, [] (const auto& e) { |
| 148 | return e.what() == "cannot call setPrefix() after append/end/reject"s; |
| 149 | }); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 152 | BOOST_AUTO_TEST_SUITE_END() // Prefix |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 153 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 154 | BOOST_AUTO_TEST_SUITE(Respond) |
| 155 | |
| 156 | BOOST_AUTO_TEST_CASE(Basic) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 157 | { |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 158 | context.append(contentBlock); |
| 159 | BOOST_CHECK(sendDataHistory.empty()); // end() not called yet |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 160 | |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 161 | context.end(); |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 162 | BOOST_REQUIRE_EQUAL(sendDataHistory.size(), 1); |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 163 | |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 164 | const auto& args = sendDataHistory[0]; |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 165 | BOOST_CHECK_EQUAL(args.dataName, makeSegmentName(0)); |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 166 | BOOST_CHECK_EQUAL(args.content.blockFromValue(), contentBlock); |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 167 | BOOST_CHECK_EQUAL(args.isFinalBlock, true); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 170 | BOOST_AUTO_TEST_CASE(Large) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 171 | { |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 172 | const Block largeBlock = [] { |
| 173 | Block b(tlv::Content, std::make_shared<const Buffer>(10000)); |
| 174 | b.encode(); |
| 175 | return b; |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 176 | }(); |
| 177 | |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 178 | context.append(largeBlock); |
| 179 | BOOST_CHECK_EQUAL(sendDataHistory.size(), 1); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 180 | |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 181 | context.end(); |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 182 | BOOST_REQUIRE_EQUAL(sendDataHistory.size(), 2); |
| 183 | |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 184 | // check segment 0 |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 185 | BOOST_CHECK_EQUAL(sendDataHistory[0].dataName, makeSegmentName(0)); |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 186 | BOOST_CHECK_EQUAL(sendDataHistory[0].isFinalBlock, false); |
| 187 | |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 188 | // check segment 1 |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 189 | BOOST_CHECK_EQUAL(sendDataHistory[1].dataName, makeSegmentName(1)); |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 190 | BOOST_CHECK_EQUAL(sendDataHistory[1].isFinalBlock, true); |
| 191 | |
| 192 | // check data content |
| 193 | auto contentLargeBlock = concatenateDataContent(); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 194 | BOOST_CHECK_NO_THROW(contentLargeBlock.parse()); |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 195 | BOOST_REQUIRE_EQUAL(contentLargeBlock.elements().size(), 1); |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 196 | BOOST_CHECK_EQUAL(contentLargeBlock.elements()[0], largeBlock); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 199 | BOOST_AUTO_TEST_CASE(MultipleSmall) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 200 | { |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 201 | const size_t nBlocks = 100; |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 202 | for (size_t i = 0 ; i < nBlocks ; i ++) { |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 203 | context.append(contentBlock); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 204 | } |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 205 | context.end(); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 206 | |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 207 | // check data to in-memory storage |
| 208 | BOOST_REQUIRE_EQUAL(sendDataHistory.size(), 1); |
| 209 | BOOST_CHECK_EQUAL(sendDataHistory[0].dataName, makeSegmentName(0)); |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 210 | BOOST_CHECK_EQUAL(sendDataHistory[0].isFinalBlock, true); |
| 211 | |
| 212 | auto contentMultiBlocks = concatenateDataContent(); |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 213 | contentMultiBlocks.parse(); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 214 | BOOST_CHECK_EQUAL(contentMultiBlocks.elements().size(), nBlocks); |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 215 | for (const auto& element : contentMultiBlocks.elements()) { |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 216 | BOOST_CHECK_EQUAL(element, contentBlock); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 220 | BOOST_AUTO_TEST_SUITE_END() // Respond |
| 221 | |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 222 | BOOST_AUTO_TEST_CASE(Reject) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 223 | { |
| 224 | BOOST_CHECK_NO_THROW(context.reject()); |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 225 | BOOST_REQUIRE_EQUAL(sendNackHistory.size(), 1); |
| 226 | BOOST_CHECK_EQUAL(sendNackHistory[0].getCode(), 400); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 229 | class AbnormalStateTestFixture |
| 230 | { |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 231 | protected: |
Davide Pesavento | 2e481fc | 2021-07-02 18:20:03 -0400 | [diff] [blame] | 232 | StatusDatasetContext context{Interest("/abnormal-state"), [] (auto&&...) {}, [] (auto&&...) {}}; |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 233 | }; |
| 234 | |
| 235 | BOOST_FIXTURE_TEST_SUITE(AbnormalState, AbnormalStateTestFixture) |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 236 | |
| 237 | BOOST_AUTO_TEST_CASE(AppendReject) |
| 238 | { |
Davide Pesavento | b10024c | 2017-09-22 01:36:44 -0400 | [diff] [blame] | 239 | const uint8_t buf[] = {0x82, 0x01, 0x02}; |
| 240 | BOOST_CHECK_NO_THROW(context.append(Block(buf, sizeof(buf)))); |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 241 | BOOST_CHECK_EXCEPTION(context.reject(), std::logic_error, [] (const auto& e) { |
| 242 | return e.what() == "cannot call reject() after append/end"s; |
| 243 | }); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | BOOST_AUTO_TEST_CASE(AppendEndReject) |
| 247 | { |
Davide Pesavento | b10024c | 2017-09-22 01:36:44 -0400 | [diff] [blame] | 248 | const uint8_t buf[] = {0x82, 0x01, 0x02}; |
| 249 | BOOST_CHECK_NO_THROW(context.append(Block(buf, sizeof(buf)))); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 250 | BOOST_CHECK_NO_THROW(context.end()); |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 251 | BOOST_CHECK_EXCEPTION(context.reject(), std::logic_error, [] (const auto& e) { |
| 252 | return e.what() == "cannot call reject() after append/end"s; |
| 253 | }); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | BOOST_AUTO_TEST_CASE(EndAppend) |
| 257 | { |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 258 | BOOST_CHECK_NO_THROW(context.end()); |
Davide Pesavento | b10024c | 2017-09-22 01:36:44 -0400 | [diff] [blame] | 259 | const uint8_t buf[] = {0x82, 0x01, 0x02}; |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 260 | BOOST_CHECK_EXCEPTION(context.append(Block(buf, sizeof(buf))), std::logic_error, [] (const auto& e) { |
| 261 | return e.what() == "cannot call append() on a finalized context"s; |
| 262 | }); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | BOOST_AUTO_TEST_CASE(EndEnd) |
| 266 | { |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 267 | BOOST_CHECK_NO_THROW(context.end()); |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 268 | BOOST_CHECK_EXCEPTION(context.end(), std::logic_error, [] (const auto& e) { |
| 269 | return e.what() == "cannot call end() on a finalized context"s; |
| 270 | }); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | BOOST_AUTO_TEST_CASE(EndReject) |
| 274 | { |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 275 | BOOST_CHECK_NO_THROW(context.end()); |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 276 | BOOST_CHECK_EXCEPTION(context.reject(), std::logic_error, [] (const auto& e) { |
| 277 | return e.what() == "cannot call reject() after append/end"s; |
| 278 | }); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | BOOST_AUTO_TEST_CASE(RejectAppend) |
| 282 | { |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 283 | BOOST_CHECK_NO_THROW(context.reject()); |
Davide Pesavento | b10024c | 2017-09-22 01:36:44 -0400 | [diff] [blame] | 284 | const uint8_t buf[] = {0x82, 0x01, 0x02}; |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 285 | BOOST_CHECK_EXCEPTION(context.append(Block(buf, sizeof(buf))), std::logic_error, [] (const auto& e) { |
| 286 | return e.what() == "cannot call append() on a finalized context"s; |
| 287 | }); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | BOOST_AUTO_TEST_CASE(RejectEnd) |
| 291 | { |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 292 | BOOST_CHECK_NO_THROW(context.reject()); |
Davide Pesavento | 3c34ec1 | 2021-03-28 21:50:06 -0400 | [diff] [blame] | 293 | BOOST_CHECK_EXCEPTION(context.end(), std::logic_error, [] (const auto& e) { |
| 294 | return e.what() == "cannot call end() on a finalized context"s; |
| 295 | }); |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | BOOST_AUTO_TEST_SUITE_END() // AbnormalState |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 299 | |
Yanbiao Li | 4b4f754 | 2016-03-11 02:04:43 +0800 | [diff] [blame] | 300 | BOOST_AUTO_TEST_SUITE_END() // TestStatusDatasetContext |
| 301 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Yanbiao Li | 8ee37ed | 2015-05-19 12:44:04 -0700 | [diff] [blame] | 302 | |
| 303 | } // namespace tests |
| 304 | } // namespace mgmt |
| 305 | } // namespace ndn |