Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 84d62cb | 2017-07-12 16:15:18 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | d91fe6d | 2023-10-04 21:40:02 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2023, Regents of the University of California, |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [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. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 26 | #include "websocket-transport-fixture.hpp" |
| 27 | |
| 28 | #include <boost/mpl/vector.hpp> |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 29 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 30 | namespace nfd::tests { |
| 31 | |
| 32 | using namespace nfd::face; |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 33 | |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 34 | BOOST_AUTO_TEST_SUITE(Face) |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 35 | BOOST_FIXTURE_TEST_SUITE(TestWebSocketTransport, IpTransportFixture<WebSocketTransportFixture>) |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 36 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 37 | using WebSocketTransportFixtures = boost::mpl::vector< |
| 38 | GENERATE_IP_TRANSPORT_FIXTURE_INSTANTIATIONS(WebSocketTransportFixture) |
| 39 | >; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 40 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 41 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(StaticProperties, T, WebSocketTransportFixtures, T) |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 42 | { |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 43 | TRANSPORT_TEST_INIT(); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 44 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 45 | checkStaticPropertiesInitialized(*this->transport); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 46 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 47 | BOOST_CHECK_EQUAL(this->transport->getLocalUri(), FaceUri(ip::tcp::endpoint(this->address, 20070), "ws")); |
| 48 | BOOST_CHECK_EQUAL(this->transport->getRemoteUri(), FaceUri(this->remoteEp, "wsclient")); |
| 49 | BOOST_CHECK_EQUAL(this->transport->getScope(), |
| 50 | this->addressScope == AddressScope::Loopback ? ndn::nfd::FACE_SCOPE_LOCAL |
| 51 | : ndn::nfd::FACE_SCOPE_NON_LOCAL); |
| 52 | BOOST_CHECK_EQUAL(this->transport->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); |
| 53 | BOOST_CHECK_EQUAL(this->transport->getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT); |
| 54 | BOOST_CHECK_EQUAL(this->transport->getMtu(), MTU_UNLIMITED); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 55 | BOOST_CHECK_EQUAL(this->transport->getSendQueueCapacity(), QUEUE_UNSUPPORTED); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 58 | using StaticPropertiesV4MappedFixtures = boost::mpl::vector< |
| 59 | IpTransportFixture<WebSocketTransportFixture, AddressFamily::V4, AddressScope::Loopback>, |
| 60 | IpTransportFixture<WebSocketTransportFixture, AddressFamily::V4, AddressScope::Global> |
| 61 | >; |
| 62 | |
| 63 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(StaticPropertiesV4Mapped, T, StaticPropertiesV4MappedFixtures, T) |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 64 | { |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 65 | TRANSPORT_TEST_CHECK_PRECONDITIONS(); |
Davide Pesavento | d91fe6d | 2023-10-04 21:40:02 -0400 | [diff] [blame] | 66 | auto mappedAddr = ip::make_address_v6(ip::v4_mapped, this->address.to_v4()); |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 67 | BOOST_REQUIRE(mappedAddr.is_v4_mapped()); |
Davide Pesavento | 279af1c | 2022-08-29 20:18:32 -0400 | [diff] [blame] | 68 | WebSocketTransportFixture::initialize(this->interface, mappedAddr); |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 69 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 70 | checkStaticPropertiesInitialized(*this->transport); |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 71 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 72 | BOOST_CHECK_EQUAL(this->transport->getLocalUri(), FaceUri(ip::tcp::endpoint(mappedAddr, 20070), "ws")); |
| 73 | BOOST_CHECK_EQUAL(this->transport->getRemoteUri(), FaceUri(this->remoteEp, "wsclient")); |
| 74 | BOOST_CHECK_EQUAL(this->transport->getScope(), |
| 75 | this->addressScope == AddressScope::Loopback ? ndn::nfd::FACE_SCOPE_LOCAL |
| 76 | : ndn::nfd::FACE_SCOPE_NON_LOCAL); |
| 77 | BOOST_CHECK_EQUAL(this->transport->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); |
| 78 | BOOST_CHECK_EQUAL(this->transport->getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT); |
| 79 | BOOST_CHECK_EQUAL(this->transport->getMtu(), MTU_UNLIMITED); |
Eric Newberry | 4a4ccfe | 2016-07-21 22:51:04 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Davide Pesavento | 3206565 | 2017-01-15 01:52:21 -0500 | [diff] [blame] | 82 | BOOST_AUTO_TEST_CASE(PersistencyChange) |
| 83 | { |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 84 | TRANSPORT_TEST_INIT(); |
Davide Pesavento | 3206565 | 2017-01-15 01:52:21 -0500 | [diff] [blame] | 85 | |
| 86 | BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND), true); |
| 87 | BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_PERSISTENT), false); |
| 88 | BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_PERMANENT), false); |
| 89 | } |
| 90 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 91 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(PingPong, T, WebSocketTransportFixtures, T) |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 92 | { |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 93 | TRANSPORT_TEST_INIT(500_ms, 300_ms); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 94 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 95 | BOOST_CHECK_EQUAL(this->limitedIo.run(2, // clientHandlePing, serverHandlePong |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 96 | 1500_ms), LimitedIo::EXCEED_OPS); |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 97 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 98 | BOOST_CHECK_EQUAL(this->transport->getState(), TransportState::UP); |
| 99 | BOOST_CHECK_EQUAL(this->transport->getCounters().nOutPings, 1); |
| 100 | BOOST_CHECK_EQUAL(this->transport->getCounters().nInPongs, 1); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 101 | |
| 102 | this->clientShouldPong = false; |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 103 | BOOST_CHECK_EQUAL(this->limitedIo.run(2, // clientHandlePing, serverHandlePongTimeout |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 104 | 2_s), LimitedIo::EXCEED_OPS); |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 105 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 106 | BOOST_CHECK_MESSAGE(this->transport->getState() == TransportState::FAILED || |
| 107 | this->transport->getState() == TransportState::CLOSED, |
| 108 | "expected FAILED or CLOSED state, actual state=" << this->transport->getState()); |
| 109 | BOOST_CHECK_EQUAL(this->transport->getCounters().nOutPings, 2); |
| 110 | BOOST_CHECK_EQUAL(this->transport->getCounters().nInPongs, 1); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 113 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(Send, T, WebSocketTransportFixtures, T) |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 114 | { |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 115 | TRANSPORT_TEST_INIT(); |
| 116 | |
| 117 | auto block1 = ndn::encoding::makeStringBlock(300, "hello"); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 118 | this->transport->send(block1); |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 119 | BOOST_CHECK_EQUAL(this->limitedIo.run(1, // clientHandleMessage |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 120 | 1_s), LimitedIo::EXCEED_OPS); |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 121 | BOOST_CHECK_EQUAL(this->transport->getCounters().nOutPackets, 1); |
| 122 | BOOST_CHECK_EQUAL(this->transport->getCounters().nOutBytes, block1.size()); |
| 123 | |
| 124 | auto block2 = ndn::encoding::makeStringBlock(301, "world"); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 125 | this->transport->send(block2); |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 126 | BOOST_CHECK_EQUAL(this->limitedIo.run(1, // clientHandleMessage |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 127 | 1_s), LimitedIo::EXCEED_OPS); |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 128 | BOOST_CHECK_EQUAL(this->transport->getCounters().nOutPackets, 2); |
| 129 | BOOST_CHECK_EQUAL(this->transport->getCounters().nOutBytes, block1.size() + block2.size()); |
| 130 | |
| 131 | BOOST_REQUIRE_EQUAL(this->clientReceivedMessages.size(), 2); |
| 132 | BOOST_CHECK_EQUAL_COLLECTIONS( |
| 133 | reinterpret_cast<const uint8_t*>(this->clientReceivedMessages[0].data()), |
| 134 | reinterpret_cast<const uint8_t*>(this->clientReceivedMessages[0].data()) + this->clientReceivedMessages[0].size(), |
| 135 | block1.begin(), block1.end()); |
| 136 | BOOST_CHECK_EQUAL_COLLECTIONS( |
| 137 | reinterpret_cast<const uint8_t*>(this->clientReceivedMessages[1].data()), |
| 138 | reinterpret_cast<const uint8_t*>(this->clientReceivedMessages[1].data()) + this->clientReceivedMessages[1].size(), |
| 139 | block2.begin(), block2.end()); |
| 140 | BOOST_CHECK_EQUAL(this->transport->getState(), TransportState::UP); |
| 141 | } |
| 142 | |
| 143 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(ReceiveNormal, T, WebSocketTransportFixtures, T) |
| 144 | { |
| 145 | TRANSPORT_TEST_INIT(); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 146 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 147 | auto pkt1 = ndn::encoding::makeStringBlock(300, "hello"); |
Davide Pesavento | deb5427 | 2022-03-11 18:51:05 -0500 | [diff] [blame] | 148 | this->client.send(this->clientHdl, pkt1.data(), pkt1.size(), websocketpp::frame::opcode::binary); |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 149 | BOOST_CHECK_EQUAL(this->limitedIo.run(1, // serverHandleMessage |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 150 | 1_s), LimitedIo::EXCEED_OPS); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 151 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 152 | BOOST_CHECK_EQUAL(this->transport->getCounters().nInPackets, 1); |
| 153 | BOOST_CHECK_EQUAL(this->transport->getCounters().nInBytes, pkt1.size()); |
| 154 | |
| 155 | auto pkt2 = ndn::encoding::makeStringBlock(301, "world!"); |
Davide Pesavento | deb5427 | 2022-03-11 18:51:05 -0500 | [diff] [blame] | 156 | this->client.send(this->clientHdl, pkt2.data(), pkt2.size(), websocketpp::frame::opcode::binary); |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 157 | BOOST_CHECK_EQUAL(this->limitedIo.run(1, // serverHandleMessage |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 158 | 1_s), LimitedIo::EXCEED_OPS); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 159 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 160 | BOOST_CHECK_EQUAL(this->transport->getCounters().nInPackets, 2); |
| 161 | BOOST_CHECK_EQUAL(this->transport->getCounters().nInBytes, pkt1.size() + pkt2.size()); |
| 162 | BOOST_CHECK_EQUAL(this->transport->getState(), TransportState::UP); |
| 163 | |
| 164 | BOOST_REQUIRE_EQUAL(this->serverReceivedPackets->size(), 2); |
| 165 | BOOST_CHECK(this->serverReceivedPackets->at(0).packet == pkt1); |
| 166 | BOOST_CHECK(this->serverReceivedPackets->at(1).packet == pkt2); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 167 | BOOST_CHECK(this->serverReceivedPackets->at(0).endpoint == EndpointId{}); |
| 168 | BOOST_CHECK(this->serverReceivedPackets->at(1).endpoint == EndpointId{}); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 171 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(ReceiveMalformed, T, WebSocketTransportFixtures, T) |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 172 | { |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 173 | TRANSPORT_TEST_INIT(); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 174 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 175 | auto pkt1 = ndn::encoding::makeStringBlock(300, "hello"); |
Davide Pesavento | deb5427 | 2022-03-11 18:51:05 -0500 | [diff] [blame] | 176 | this->client.send(this->clientHdl, pkt1.data(), pkt1.size() - 1, // truncated |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 177 | websocketpp::frame::opcode::binary); |
| 178 | BOOST_CHECK_EQUAL(this->limitedIo.run(1, // serverHandleMessage |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 179 | 1_s), LimitedIo::EXCEED_OPS); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 180 | |
| 181 | // bad packet is dropped |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 182 | BOOST_CHECK_EQUAL(this->transport->getState(), TransportState::UP); |
| 183 | BOOST_CHECK_EQUAL(this->serverReceivedPackets->size(), 0); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 184 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 185 | auto pkt2 = ndn::encoding::makeStringBlock(301, "world!"); |
Davide Pesavento | deb5427 | 2022-03-11 18:51:05 -0500 | [diff] [blame] | 186 | this->client.send(this->clientHdl, pkt2.data(), pkt2.size(), websocketpp::frame::opcode::binary); |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 187 | BOOST_CHECK_EQUAL(this->limitedIo.run(1, // serverHandleMessage |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 188 | 1_s), LimitedIo::EXCEED_OPS); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 189 | |
| 190 | // next valid packet is still received normally |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 191 | BOOST_CHECK_EQUAL(this->transport->getState(), TransportState::UP); |
| 192 | BOOST_REQUIRE_EQUAL(this->serverReceivedPackets->size(), 1); |
| 193 | BOOST_CHECK(this->serverReceivedPackets->at(0).packet == pkt2); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 196 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(Close, T, WebSocketTransportFixtures, T) |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 197 | { |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 198 | TRANSPORT_TEST_INIT(); |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 199 | |
| 200 | int nStateChanges = 0; |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 201 | this->transport->afterStateChange.connect( |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 202 | [&nStateChanges] (auto oldState, auto newState) { |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 203 | switch (nStateChanges) { |
| 204 | case 0: |
| 205 | BOOST_CHECK_EQUAL(oldState, TransportState::UP); |
| 206 | BOOST_CHECK_EQUAL(newState, TransportState::CLOSING); |
| 207 | break; |
| 208 | case 1: |
| 209 | BOOST_CHECK_EQUAL(oldState, TransportState::CLOSING); |
| 210 | BOOST_CHECK_EQUAL(newState, TransportState::CLOSED); |
| 211 | break; |
| 212 | default: |
| 213 | BOOST_CHECK(false); |
| 214 | } |
| 215 | nStateChanges++; |
| 216 | }); |
| 217 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 218 | this->transport->close(); |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 219 | BOOST_CHECK_EQUAL(nStateChanges, 2); |
| 220 | } |
| 221 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 222 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(RemoteClose, T, WebSocketTransportFixtures, T) |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 223 | { |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 224 | TRANSPORT_TEST_INIT(); |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 225 | |
| 226 | int nStateChanges = 0; |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 227 | this->transport->afterStateChange.connect( |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 228 | [&nStateChanges] (auto oldState, auto newState) { |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 229 | switch (nStateChanges) { |
| 230 | case 0: |
| 231 | BOOST_CHECK_EQUAL(oldState, TransportState::UP); |
| 232 | BOOST_CHECK_EQUAL(newState, TransportState::CLOSING); |
| 233 | break; |
| 234 | case 1: |
| 235 | BOOST_CHECK_EQUAL(oldState, TransportState::CLOSING); |
| 236 | BOOST_CHECK_EQUAL(newState, TransportState::CLOSED); |
| 237 | break; |
| 238 | default: |
| 239 | BOOST_CHECK(false); |
| 240 | } |
| 241 | nStateChanges++; |
| 242 | }); |
| 243 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 244 | this->client.close(this->clientHdl, websocketpp::close::status::going_away, ""); |
| 245 | BOOST_CHECK_EQUAL(this->limitedIo.run(1, // serverHandleClose |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 246 | 1_s), LimitedIo::EXCEED_OPS); |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 247 | |
| 248 | BOOST_CHECK_EQUAL(nStateChanges, 2); |
| 249 | } |
| 250 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 251 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(SendQueueLength, T, WebSocketTransportFixtures, T) |
| 252 | { |
| 253 | TRANSPORT_TEST_INIT(); |
| 254 | |
| 255 | BOOST_CHECK_EQUAL(this->transport->getSendQueueLength(), QUEUE_UNSUPPORTED); |
| 256 | } |
| 257 | |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 258 | BOOST_AUTO_TEST_SUITE_END() // TestWebSocketTransport |
| 259 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 260 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 261 | } // namespace nfd::tests |