Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -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) 2014-2023 Regents of the University of California, |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 10 | * |
| 11 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 12 | * |
| 13 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 14 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 15 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 19 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 20 | * |
| 21 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 22 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 23 | * <http://www.gnu.org/licenses/>. |
| 24 | * |
| 25 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 26 | */ |
| 27 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 28 | #include "ndn-cxx/util/notification-subscriber.hpp" |
| 29 | #include "ndn-cxx/util/dummy-client-face.hpp" |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 30 | |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 31 | #include "tests/test-common.hpp" |
| 32 | #include "tests/unit/io-key-chain-fixture.hpp" |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 33 | #include "tests/unit/util/simple-notification.hpp" |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 34 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 35 | namespace ndn::tests { |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 36 | |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 37 | class NotificationSubscriberFixture : public IoKeyChainFixture |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 38 | { |
| 39 | public: |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 40 | NotificationSubscriberFixture() |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 41 | : streamPrefix("/NotificationSubscriberTest") |
| 42 | , subscriberFace(m_io, m_keyChain) |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 43 | , subscriber(subscriberFace, streamPrefix, 1_s) |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 44 | , nextSendNotificationNo(0) |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 45 | { |
| 46 | } |
| 47 | |
Davide Pesavento | c860bd1 | 2022-10-04 03:23:43 -0400 | [diff] [blame] | 48 | /** \brief Deliver one notification to subscriber. |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 49 | */ |
| 50 | void |
| 51 | deliverNotification(const std::string& msg) |
| 52 | { |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 53 | SimpleNotification notification(msg); |
Alexander Afanasyev | 370d260 | 2014-08-20 10:21:34 -0500 | [diff] [blame] | 54 | |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 55 | Name dataName = streamPrefix; |
| 56 | dataName.appendSequenceNumber(nextSendNotificationNo); |
| 57 | Data data(dataName); |
| 58 | data.setContent(notification.wireEncode()); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 59 | data.setFreshnessPeriod(1_s); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 60 | m_keyChain.sign(data); |
Alexander Afanasyev | 370d260 | 2014-08-20 10:21:34 -0500 | [diff] [blame] | 61 | |
Junxiao Shi | 946a51c | 2018-11-24 00:25:57 +0000 | [diff] [blame] | 62 | lastDeliveredSeqNum = nextSendNotificationNo; |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 63 | lastNotification.setMessage(""); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 64 | ++nextSendNotificationNo; |
| 65 | subscriberFace.receive(data); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Davide Pesavento | c860bd1 | 2022-10-04 03:23:43 -0400 | [diff] [blame] | 68 | /** \brief Deliver a Nack to subscriber. |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 69 | */ |
| 70 | void |
| 71 | deliverNack(const Interest& interest, const lp::NackReason& reason) |
| 72 | { |
Davide Pesavento | 2e481fc | 2021-07-02 18:20:03 -0400 | [diff] [blame] | 73 | subscriberFace.receive(makeNack(interest, reason)); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 76 | void |
| 77 | connectHandlers() |
| 78 | { |
Davide Pesavento | 2e481fc | 2021-07-02 18:20:03 -0400 | [diff] [blame] | 79 | notificationConn = subscriber.onNotification.connect([this] (const auto& n) { lastNotification = n; }); |
| 80 | nackConn = subscriber.onNack.connect([this] (const auto& nack) { lastNack = nack; }); |
| 81 | subscriber.onTimeout.connect([this] { hasTimeout = true; }); |
| 82 | subscriber.onDecodeError.connect([this] (const auto& data) { lastDecodeErrorData = data; }); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | void |
| 86 | disconnectHandlers() |
| 87 | { |
| 88 | notificationConn.disconnect(); |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 89 | nackConn.disconnect(); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 92 | /** \return true if subscriberFace has an initial request (first sent Interest) |
| 93 | */ |
| 94 | bool |
| 95 | hasInitialRequest() const |
| 96 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 97 | if (subscriberFace.sentInterests.empty()) |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 98 | return false; |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 99 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 100 | const Interest& interest = subscriberFace.sentInterests[0]; |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 101 | return interest.getName() == streamPrefix && |
Junxiao Shi | 946a51c | 2018-11-24 00:25:57 +0000 | [diff] [blame] | 102 | interest.getCanBePrefix() && |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 103 | interest.getMustBeFresh() && |
| 104 | interest.getInterestLifetime() == subscriber.getInterestLifetime(); |
| 105 | } |
| 106 | |
| 107 | /** \return sequence number of the continuation request sent from subscriberFace |
| 108 | * or 0 if there's no such request as sole sent Interest |
| 109 | */ |
| 110 | uint64_t |
Junxiao Shi | 946a51c | 2018-11-24 00:25:57 +0000 | [diff] [blame] | 111 | getRequestSeqNum() const |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 112 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 113 | if (subscriberFace.sentInterests.size() != 1) |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 114 | return 0; |
| 115 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 116 | const Interest& interest = subscriberFace.sentInterests[0]; |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 117 | const Name& name = interest.getName(); |
| 118 | if (streamPrefix.isPrefixOf(name) && |
| 119 | name.size() == streamPrefix.size() + 1 && |
| 120 | interest.getInterestLifetime() == subscriber.getInterestLifetime()) |
| 121 | return name[-1].toSequenceNumber(); |
| 122 | else |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | protected: |
| 127 | Name streamPrefix; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 128 | DummyClientFace subscriberFace; |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 129 | util::NotificationSubscriber<SimpleNotification> subscriber; |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 130 | signal::Connection notificationConn; |
| 131 | signal::Connection nackConn; |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 132 | uint64_t nextSendNotificationNo; |
Junxiao Shi | 946a51c | 2018-11-24 00:25:57 +0000 | [diff] [blame] | 133 | uint64_t lastDeliveredSeqNum; |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 134 | SimpleNotification lastNotification; |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 135 | lp::Nack lastNack; |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 136 | bool hasTimeout; |
| 137 | Data lastDecodeErrorData; |
| 138 | }; |
| 139 | |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 140 | BOOST_AUTO_TEST_SUITE(Util) |
| 141 | BOOST_FIXTURE_TEST_SUITE(TestNotificationSubscriber, NotificationSubscriberFixture) |
| 142 | |
| 143 | BOOST_AUTO_TEST_CASE(StartStop) |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 144 | { |
| 145 | BOOST_REQUIRE_EQUAL(subscriber.isRunning(), false); |
| 146 | |
| 147 | // has no effect because onNotification has no handler |
| 148 | subscriber.start(); |
| 149 | BOOST_REQUIRE_EQUAL(subscriber.isRunning(), false); |
| 150 | |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 151 | this->connectHandlers(); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 152 | subscriber.start(); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 153 | BOOST_REQUIRE_EQUAL(subscriber.isRunning(), true); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 154 | advanceClocks(1_ms); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 155 | BOOST_CHECK(this->hasInitialRequest()); |
| 156 | |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 157 | subscriberFace.sentInterests.clear(); |
| 158 | this->disconnectHandlers(); |
| 159 | this->deliverNotification("n1"); |
| 160 | BOOST_REQUIRE_EQUAL(subscriberFace.sentInterests.size(), 0); |
| 161 | } |
| 162 | |
| 163 | BOOST_AUTO_TEST_CASE(Notifications) |
| 164 | { |
| 165 | this->connectHandlers(); |
| 166 | subscriber.start(); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 167 | advanceClocks(1_ms); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 168 | |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 169 | // respond to initial request |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 170 | subscriberFace.sentInterests.clear(); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 171 | this->deliverNotification("n1"); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 172 | advanceClocks(1_ms); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 173 | BOOST_CHECK_EQUAL(lastNotification.getMessage(), "n1"); |
Junxiao Shi | 946a51c | 2018-11-24 00:25:57 +0000 | [diff] [blame] | 174 | BOOST_CHECK_EQUAL(this->getRequestSeqNum(), lastDeliveredSeqNum + 1); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 175 | |
| 176 | // respond to continuation request |
| 177 | subscriberFace.sentInterests.clear(); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 178 | this->deliverNotification("n2"); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 179 | advanceClocks(1_ms); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 180 | BOOST_CHECK_EQUAL(lastNotification.getMessage(), "n2"); |
Junxiao Shi | 946a51c | 2018-11-24 00:25:57 +0000 | [diff] [blame] | 181 | BOOST_CHECK_EQUAL(this->getRequestSeqNum(), lastDeliveredSeqNum + 1); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 182 | } |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 183 | |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 184 | BOOST_AUTO_TEST_CASE(Nack) |
| 185 | { |
| 186 | this->connectHandlers(); |
| 187 | subscriber.start(); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 188 | advanceClocks(1_ms); |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 189 | |
| 190 | // send the first Nack to initial request |
| 191 | BOOST_REQUIRE_EQUAL(subscriberFace.sentInterests.size(), 1); |
| 192 | Interest interest = subscriberFace.sentInterests[0]; |
| 193 | subscriberFace.sentInterests.clear(); |
| 194 | this->deliverNack(interest, lp::NackReason::CONGESTION); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 195 | advanceClocks(1_ms); |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 196 | BOOST_CHECK_EQUAL(lastNack.getReason(), lp::NackReason::CONGESTION); |
| 197 | BOOST_REQUIRE_EQUAL(this->hasInitialRequest(), false); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 198 | advanceClocks(300_ms); |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 199 | BOOST_REQUIRE_EQUAL(this->hasInitialRequest(), true); |
| 200 | |
| 201 | // send the second Nack to initial request |
| 202 | BOOST_REQUIRE_EQUAL(subscriberFace.sentInterests.size(), 1); |
| 203 | interest = subscriberFace.sentInterests[0]; |
| 204 | subscriberFace.sentInterests.clear(); |
| 205 | this->deliverNack(interest, lp::NackReason::CONGESTION); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 206 | advanceClocks(301_ms); |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 207 | BOOST_REQUIRE_EQUAL(this->hasInitialRequest(), false); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 208 | advanceClocks(200_ms); |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 209 | BOOST_REQUIRE_EQUAL(this->hasInitialRequest(), true); |
| 210 | |
| 211 | // send a notification to initial request |
| 212 | subscriberFace.sentInterests.clear(); |
| 213 | this->deliverNotification("n1"); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 214 | advanceClocks(1_ms); |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 215 | |
| 216 | // send a Nack to subsequent request |
| 217 | BOOST_REQUIRE_EQUAL(subscriberFace.sentInterests.size(), 1); |
| 218 | interest = subscriberFace.sentInterests[0]; |
| 219 | subscriberFace.sentInterests.clear(); |
| 220 | this->deliverNack(interest, lp::NackReason::CONGESTION); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 221 | advanceClocks(1_ms); |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 222 | BOOST_CHECK_EQUAL(lastNack.getReason(), lp::NackReason::CONGESTION); |
| 223 | BOOST_REQUIRE_EQUAL(this->hasInitialRequest(), false); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 224 | advanceClocks(300_ms); |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 225 | BOOST_REQUIRE_EQUAL(this->hasInitialRequest(), true); |
| 226 | } |
| 227 | |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 228 | BOOST_AUTO_TEST_CASE(Timeout) |
| 229 | { |
| 230 | this->connectHandlers(); |
| 231 | subscriber.start(); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 232 | advanceClocks(1_ms); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 233 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 234 | subscriberFace.sentInterests.clear(); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 235 | lastNotification.setMessage(""); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 236 | advanceClocks(subscriber.getInterestLifetime(), 2); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 237 | BOOST_CHECK(lastNotification.getMessage().empty()); |
| 238 | BOOST_CHECK_EQUAL(hasTimeout, true); |
| 239 | BOOST_CHECK(this->hasInitialRequest()); |
| 240 | |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 241 | subscriberFace.sentInterests.clear(); |
| 242 | this->deliverNotification("n1"); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 243 | advanceClocks(1_ms); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 244 | BOOST_CHECK_EQUAL(lastNotification.getMessage(), "n1"); |
| 245 | } |
| 246 | |
| 247 | BOOST_AUTO_TEST_CASE(SequenceError) |
| 248 | { |
| 249 | this->connectHandlers(); |
| 250 | subscriber.start(); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 251 | advanceClocks(1_ms); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 252 | |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 253 | Name wrongName = streamPrefix; |
| 254 | wrongName.append("%07%07"); |
| 255 | Data wrongData(wrongName); |
Junxiao Shi | 2ad2fbe | 2019-05-24 03:11:05 +0000 | [diff] [blame] | 256 | wrongData.setFreshnessPeriod(1_s); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 257 | m_keyChain.sign(wrongData); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 258 | subscriberFace.receive(wrongData); |
| 259 | subscriberFace.sentInterests.clear(); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 260 | lastNotification.setMessage(""); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 261 | advanceClocks(1_ms); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 262 | BOOST_CHECK(lastNotification.getMessage().empty()); |
| 263 | BOOST_CHECK_EQUAL(lastDecodeErrorData.getName(), wrongName); |
| 264 | BOOST_CHECK(this->hasInitialRequest()); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 265 | } |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 266 | |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 267 | BOOST_AUTO_TEST_CASE(PayloadError) |
| 268 | { |
| 269 | this->connectHandlers(); |
| 270 | subscriber.start(); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 271 | advanceClocks(1_ms); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 272 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 273 | subscriberFace.sentInterests.clear(); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 274 | lastNotification.setMessage(""); |
| 275 | this->deliverNotification("\x07n4"); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 276 | advanceClocks(1_ms); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 277 | BOOST_CHECK(lastNotification.getMessage().empty()); |
| 278 | BOOST_CHECK(this->hasInitialRequest()); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 281 | BOOST_AUTO_TEST_SUITE_END() // TestNotificationSubscriber |
| 282 | BOOST_AUTO_TEST_SUITE_END() // Util |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 283 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 284 | } // namespace ndn::tests |