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