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