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 | c860bd1 | 2022-10-04 03:23:43 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2022 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 | |
| 35 | namespace ndn { |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 36 | namespace util { |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 37 | namespace tests { |
| 38 | |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 39 | using namespace ndn::tests; |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 40 | |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 41 | class NotificationSubscriberFixture : public IoKeyChainFixture |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 42 | { |
| 43 | public: |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 44 | NotificationSubscriberFixture() |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 45 | : streamPrefix("/NotificationSubscriberTest") |
| 46 | , subscriberFace(m_io, m_keyChain) |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 47 | , subscriber(subscriberFace, streamPrefix, 1_s) |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 48 | , nextSendNotificationNo(0) |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 49 | { |
| 50 | } |
| 51 | |
Davide Pesavento | c860bd1 | 2022-10-04 03:23:43 -0400 | [diff] [blame^] | 52 | /** \brief Deliver one notification to subscriber. |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 53 | */ |
| 54 | void |
| 55 | deliverNotification(const std::string& msg) |
| 56 | { |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 57 | SimpleNotification notification(msg); |
Alexander Afanasyev | 370d260 | 2014-08-20 10:21:34 -0500 | [diff] [blame] | 58 | |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 59 | Name dataName = streamPrefix; |
| 60 | dataName.appendSequenceNumber(nextSendNotificationNo); |
| 61 | Data data(dataName); |
| 62 | data.setContent(notification.wireEncode()); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 63 | data.setFreshnessPeriod(1_s); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 64 | m_keyChain.sign(data); |
Alexander Afanasyev | 370d260 | 2014-08-20 10:21:34 -0500 | [diff] [blame] | 65 | |
Junxiao Shi | 946a51c | 2018-11-24 00:25:57 +0000 | [diff] [blame] | 66 | lastDeliveredSeqNum = nextSendNotificationNo; |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 67 | lastNotification.setMessage(""); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 68 | ++nextSendNotificationNo; |
| 69 | subscriberFace.receive(data); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Davide Pesavento | c860bd1 | 2022-10-04 03:23:43 -0400 | [diff] [blame^] | 72 | /** \brief Deliver a Nack to subscriber. |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 73 | */ |
| 74 | void |
| 75 | deliverNack(const Interest& interest, const lp::NackReason& reason) |
| 76 | { |
Davide Pesavento | 2e481fc | 2021-07-02 18:20:03 -0400 | [diff] [blame] | 77 | subscriberFace.receive(makeNack(interest, reason)); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 80 | void |
| 81 | connectHandlers() |
| 82 | { |
Davide Pesavento | 2e481fc | 2021-07-02 18:20:03 -0400 | [diff] [blame] | 83 | notificationConn = subscriber.onNotification.connect([this] (const auto& n) { lastNotification = n; }); |
| 84 | nackConn = subscriber.onNack.connect([this] (const auto& nack) { lastNack = nack; }); |
| 85 | subscriber.onTimeout.connect([this] { hasTimeout = true; }); |
| 86 | subscriber.onDecodeError.connect([this] (const auto& data) { lastDecodeErrorData = data; }); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | void |
| 90 | disconnectHandlers() |
| 91 | { |
| 92 | notificationConn.disconnect(); |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 93 | nackConn.disconnect(); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 96 | /** \return true if subscriberFace has an initial request (first sent Interest) |
| 97 | */ |
| 98 | bool |
| 99 | hasInitialRequest() const |
| 100 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 101 | if (subscriberFace.sentInterests.empty()) |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 102 | return false; |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 103 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 104 | const Interest& interest = subscriberFace.sentInterests[0]; |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 105 | return interest.getName() == streamPrefix && |
Junxiao Shi | 946a51c | 2018-11-24 00:25:57 +0000 | [diff] [blame] | 106 | interest.getCanBePrefix() && |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 107 | interest.getMustBeFresh() && |
| 108 | interest.getInterestLifetime() == subscriber.getInterestLifetime(); |
| 109 | } |
| 110 | |
| 111 | /** \return sequence number of the continuation request sent from subscriberFace |
| 112 | * or 0 if there's no such request as sole sent Interest |
| 113 | */ |
| 114 | uint64_t |
Junxiao Shi | 946a51c | 2018-11-24 00:25:57 +0000 | [diff] [blame] | 115 | getRequestSeqNum() const |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 116 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 117 | if (subscriberFace.sentInterests.size() != 1) |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 118 | return 0; |
| 119 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 120 | const Interest& interest = subscriberFace.sentInterests[0]; |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 121 | const Name& name = interest.getName(); |
| 122 | if (streamPrefix.isPrefixOf(name) && |
| 123 | name.size() == streamPrefix.size() + 1 && |
| 124 | interest.getInterestLifetime() == subscriber.getInterestLifetime()) |
| 125 | return name[-1].toSequenceNumber(); |
| 126 | else |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | protected: |
| 131 | Name streamPrefix; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 132 | DummyClientFace subscriberFace; |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 133 | util::NotificationSubscriber<SimpleNotification> subscriber; |
Junxiao Shi | 728873f | 2015-01-20 16:01:26 -0700 | [diff] [blame] | 134 | util::signal::Connection notificationConn; |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 135 | util::signal::Connection nackConn; |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 136 | uint64_t nextSendNotificationNo; |
Junxiao Shi | 946a51c | 2018-11-24 00:25:57 +0000 | [diff] [blame] | 137 | uint64_t lastDeliveredSeqNum; |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 138 | SimpleNotification lastNotification; |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 139 | lp::Nack lastNack; |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 140 | bool hasTimeout; |
| 141 | Data lastDecodeErrorData; |
| 142 | }; |
| 143 | |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 144 | BOOST_AUTO_TEST_SUITE(Util) |
| 145 | BOOST_FIXTURE_TEST_SUITE(TestNotificationSubscriber, NotificationSubscriberFixture) |
| 146 | |
| 147 | BOOST_AUTO_TEST_CASE(StartStop) |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 148 | { |
| 149 | BOOST_REQUIRE_EQUAL(subscriber.isRunning(), false); |
| 150 | |
| 151 | // has no effect because onNotification has no handler |
| 152 | subscriber.start(); |
| 153 | BOOST_REQUIRE_EQUAL(subscriber.isRunning(), false); |
| 154 | |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 155 | this->connectHandlers(); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 156 | subscriber.start(); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 157 | BOOST_REQUIRE_EQUAL(subscriber.isRunning(), true); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 158 | advanceClocks(1_ms); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 159 | BOOST_CHECK(this->hasInitialRequest()); |
| 160 | |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 161 | subscriberFace.sentInterests.clear(); |
| 162 | this->disconnectHandlers(); |
| 163 | this->deliverNotification("n1"); |
| 164 | BOOST_REQUIRE_EQUAL(subscriberFace.sentInterests.size(), 0); |
| 165 | } |
| 166 | |
| 167 | BOOST_AUTO_TEST_CASE(Notifications) |
| 168 | { |
| 169 | this->connectHandlers(); |
| 170 | subscriber.start(); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 171 | advanceClocks(1_ms); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 172 | |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 173 | // respond to initial request |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 174 | subscriberFace.sentInterests.clear(); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 175 | this->deliverNotification("n1"); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 176 | advanceClocks(1_ms); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 177 | BOOST_CHECK_EQUAL(lastNotification.getMessage(), "n1"); |
Junxiao Shi | 946a51c | 2018-11-24 00:25:57 +0000 | [diff] [blame] | 178 | BOOST_CHECK_EQUAL(this->getRequestSeqNum(), lastDeliveredSeqNum + 1); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 179 | |
| 180 | // respond to continuation request |
| 181 | subscriberFace.sentInterests.clear(); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 182 | this->deliverNotification("n2"); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 183 | advanceClocks(1_ms); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 184 | BOOST_CHECK_EQUAL(lastNotification.getMessage(), "n2"); |
Junxiao Shi | 946a51c | 2018-11-24 00:25:57 +0000 | [diff] [blame] | 185 | BOOST_CHECK_EQUAL(this->getRequestSeqNum(), lastDeliveredSeqNum + 1); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 186 | } |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 187 | |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 188 | BOOST_AUTO_TEST_CASE(Nack) |
| 189 | { |
| 190 | this->connectHandlers(); |
| 191 | subscriber.start(); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 192 | advanceClocks(1_ms); |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 193 | |
| 194 | // send the first Nack to initial request |
| 195 | BOOST_REQUIRE_EQUAL(subscriberFace.sentInterests.size(), 1); |
| 196 | Interest interest = subscriberFace.sentInterests[0]; |
| 197 | subscriberFace.sentInterests.clear(); |
| 198 | this->deliverNack(interest, lp::NackReason::CONGESTION); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 199 | advanceClocks(1_ms); |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 200 | BOOST_CHECK_EQUAL(lastNack.getReason(), lp::NackReason::CONGESTION); |
| 201 | BOOST_REQUIRE_EQUAL(this->hasInitialRequest(), false); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 202 | advanceClocks(300_ms); |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 203 | BOOST_REQUIRE_EQUAL(this->hasInitialRequest(), true); |
| 204 | |
| 205 | // send the second Nack to initial request |
| 206 | BOOST_REQUIRE_EQUAL(subscriberFace.sentInterests.size(), 1); |
| 207 | interest = subscriberFace.sentInterests[0]; |
| 208 | subscriberFace.sentInterests.clear(); |
| 209 | this->deliverNack(interest, lp::NackReason::CONGESTION); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 210 | advanceClocks(301_ms); |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 211 | BOOST_REQUIRE_EQUAL(this->hasInitialRequest(), false); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 212 | advanceClocks(200_ms); |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 213 | BOOST_REQUIRE_EQUAL(this->hasInitialRequest(), true); |
| 214 | |
| 215 | // send a notification to initial request |
| 216 | subscriberFace.sentInterests.clear(); |
| 217 | this->deliverNotification("n1"); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 218 | advanceClocks(1_ms); |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 219 | |
| 220 | // send a Nack to subsequent request |
| 221 | BOOST_REQUIRE_EQUAL(subscriberFace.sentInterests.size(), 1); |
| 222 | interest = subscriberFace.sentInterests[0]; |
| 223 | subscriberFace.sentInterests.clear(); |
| 224 | this->deliverNack(interest, lp::NackReason::CONGESTION); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 225 | advanceClocks(1_ms); |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 226 | BOOST_CHECK_EQUAL(lastNack.getReason(), lp::NackReason::CONGESTION); |
| 227 | BOOST_REQUIRE_EQUAL(this->hasInitialRequest(), false); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 228 | advanceClocks(300_ms); |
Teng Liang | f8bf1b0 | 2016-07-17 11:54:19 -0700 | [diff] [blame] | 229 | BOOST_REQUIRE_EQUAL(this->hasInitialRequest(), true); |
| 230 | } |
| 231 | |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 232 | BOOST_AUTO_TEST_CASE(Timeout) |
| 233 | { |
| 234 | this->connectHandlers(); |
| 235 | subscriber.start(); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 236 | advanceClocks(1_ms); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 237 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 238 | subscriberFace.sentInterests.clear(); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 239 | lastNotification.setMessage(""); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 240 | advanceClocks(subscriber.getInterestLifetime(), 2); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 241 | BOOST_CHECK(lastNotification.getMessage().empty()); |
| 242 | BOOST_CHECK_EQUAL(hasTimeout, true); |
| 243 | BOOST_CHECK(this->hasInitialRequest()); |
| 244 | |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 245 | subscriberFace.sentInterests.clear(); |
| 246 | this->deliverNotification("n1"); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 247 | advanceClocks(1_ms); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 248 | BOOST_CHECK_EQUAL(lastNotification.getMessage(), "n1"); |
| 249 | } |
| 250 | |
| 251 | BOOST_AUTO_TEST_CASE(SequenceError) |
| 252 | { |
| 253 | this->connectHandlers(); |
| 254 | subscriber.start(); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 255 | advanceClocks(1_ms); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 256 | |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 257 | Name wrongName = streamPrefix; |
| 258 | wrongName.append("%07%07"); |
| 259 | Data wrongData(wrongName); |
Junxiao Shi | 2ad2fbe | 2019-05-24 03:11:05 +0000 | [diff] [blame] | 260 | wrongData.setFreshnessPeriod(1_s); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 261 | m_keyChain.sign(wrongData); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 262 | subscriberFace.receive(wrongData); |
| 263 | subscriberFace.sentInterests.clear(); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 264 | lastNotification.setMessage(""); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 265 | advanceClocks(1_ms); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 266 | BOOST_CHECK(lastNotification.getMessage().empty()); |
| 267 | BOOST_CHECK_EQUAL(lastDecodeErrorData.getName(), wrongName); |
| 268 | BOOST_CHECK(this->hasInitialRequest()); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 269 | } |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 270 | |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 271 | BOOST_AUTO_TEST_CASE(PayloadError) |
| 272 | { |
| 273 | this->connectHandlers(); |
| 274 | subscriber.start(); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 275 | advanceClocks(1_ms); |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 276 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 277 | subscriberFace.sentInterests.clear(); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 278 | lastNotification.setMessage(""); |
| 279 | this->deliverNotification("\x07n4"); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 280 | advanceClocks(1_ms); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 281 | BOOST_CHECK(lastNotification.getMessage().empty()); |
| 282 | BOOST_CHECK(this->hasInitialRequest()); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Teng Liang | 93adaff | 2016-07-30 15:57:12 -0700 | [diff] [blame] | 285 | BOOST_AUTO_TEST_SUITE_END() // TestNotificationSubscriber |
| 286 | BOOST_AUTO_TEST_SUITE_END() // Util |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 287 | |
| 288 | } // namespace tests |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 289 | } // namespace util |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 290 | } // namespace ndn |