Skip to content

Commit

Permalink
fix(tests): fix web request handler for websocket tests
Browse files Browse the repository at this point in the history
  • Loading branch information
obiltschnig committed Nov 10, 2024
1 parent 3975f58 commit 4bbea93
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
10 changes: 9 additions & 1 deletion Net/testsuite/src/WebSocketTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace
n = ws.receiveFrame(buffer.begin(), static_cast<int>(buffer.size()), flags);
if (n > 0) ws.sendFrame(buffer.begin(), n, flags);
}
while (n > 0 || (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE);
while (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE);
}
catch (WebSocketException& exc)
{
Expand Down Expand Up @@ -187,6 +187,7 @@ void WebSocketTest::testWebSocket()
assertTrue (n == 2);
assertTrue ((flags & WebSocket::FRAME_OP_BITMASK) == WebSocket::FRAME_OP_CLOSE);

ws.close();
server.stop();
}

Expand Down Expand Up @@ -222,6 +223,9 @@ void WebSocketTest::testWebSocketLarge()

assertTrue (n == payload.size());
assertTrue (payload.compare(0, payload.size(), buffer, n) == 0);

ws.close();
server.stop();
}


Expand Down Expand Up @@ -258,6 +262,9 @@ void WebSocketTest::testOneLargeFrame(int msgSize)
n = ws.receiveFrame(pocobuffer, flags);
assertTrue (n == payload.size());
assertTrue (payload.compare(0, payload.size(), pocobuffer.begin(), n) == 0);

ws.close();
server.stop();
}


Expand Down Expand Up @@ -331,6 +338,7 @@ void WebSocketTest::testWebSocketNB()
assertTrue (n == 2);
assertTrue ((flags & WebSocket::FRAME_OP_BITMASK) == WebSocket::FRAME_OP_CLOSE);

ws.close();
server.stop();
}

Expand Down
22 changes: 10 additions & 12 deletions NetSSL_OpenSSL/testsuite/src/WebSocketTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,15 @@ namespace
try
{
WebSocket ws(request, response);
std::unique_ptr<char[]> pBuffer(new char[_bufSize]);
Poco::Buffer<char> buffer(_bufSize);
int flags;
int n;
do
{
n = ws.receiveFrame(pBuffer.get(), static_cast<int>(_bufSize), flags);
if (n == 0)
break;
ws.sendFrame(pBuffer.get(), n, flags);
n = ws.receiveFrame(buffer.begin(), static_cast<int>(buffer.size()), flags);
if (n > 0) ws.sendFrame(buffer.begin(), n, flags);
}
while ((flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE);
while (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE);
}
catch (WebSocketException& exc)
{
Expand All @@ -82,7 +80,7 @@ namespace
private:
std::size_t _bufSize;
};

class WebSocketRequestHandlerFactory: public Poco::Net::HTTPRequestHandlerFactory
{
public:
Expand Down Expand Up @@ -132,7 +130,7 @@ void WebSocketTest::testWebSocket()
assertTrue (n == payload.size());
assertTrue (payload.compare(0, payload.size(), buffer, 0, n) == 0);
assertTrue (flags == WebSocket::FRAME_TEXT);

/***
for (int i = 2; i < 20; i++)
{
payload.assign(i, 'x');
Expand Down Expand Up @@ -166,13 +164,13 @@ void WebSocketTest::testWebSocket()
assertTrue (n == payload.size());
assertTrue (payload.compare(0, payload.size(), buffer, 0, n) == 0);
assertTrue (flags == WebSocket::FRAME_BINARY);

*/
ws.shutdown();
n = ws.receiveFrame(buffer, sizeof(buffer), flags);
assertTrue (n == 2);
assertTrue ((flags & WebSocket::FRAME_OP_BITMASK) == WebSocket::FRAME_OP_CLOSE);

server.stop();
server.stopAll(true);
}


Expand Down Expand Up @@ -208,7 +206,7 @@ void WebSocketTest::testWebSocketLarge()
assertTrue (n == payload.size());
assertTrue (payload.compare(0, payload.size(), buffer, 0, n) == 0);

server.stop();
server.stopAll(true);
}


Expand Down Expand Up @@ -275,7 +273,7 @@ void WebSocketTest::testWebSocketNB()
assertTrue (n == 2);
assertTrue ((flags & WebSocket::FRAME_OP_BITMASK) == WebSocket::FRAME_OP_CLOSE);

server.stop();
server.stopAll(true);
}


Expand Down

0 comments on commit 4bbea93

Please sign in to comment.