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