Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Tests/UnitTests/Tests/MockTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,12 @@ DEFINE_TEST_CLASS(MockTests)
VERIFY_ARE_EQUAL(E_OUTOFMEMORY, errCode);
VERIFY_ARE_EQUAL(300, platErrCode);
VERIFY_ARE_EQUAL(400, statusCode);
VERIFY_ARE_EQUAL_STR("Mock2", responseStr);
VERIFY_ARE_EQUAL_STR("Mock1", responseStr);
VERIFY_ARE_EQUAL(S_OK, HCHttpCallCloseHandle(call));
}

{
// Call 3 should repeat mock 2
// Once multiple mocks are registered, matching calls cycle in registration order.
VERIFY_ARE_EQUAL(S_OK, HCHttpCallCreate(&call));
VERIFY_ARE_EQUAL(S_OK, HCHttpCallRequestSetRetryAllowed(call, false));
VERIFY_ARE_EQUAL(S_OK, HCHttpCallRequestSetUrl(call, "1", "2"));
Expand Down
26 changes: 20 additions & 6 deletions Tests/UnitTests/Tests/WebsocketTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,32 @@ HRESULT CALLBACK Test_Internal_HCWebSocketConnectAsync(
{
UNREFERENCED_PARAMETER(uri);
UNREFERENCED_PARAMETER(subProtocol);
UNREFERENCED_PARAMETER(websocket);
UNREFERENCED_PARAMETER(asyncBlock);
UNREFERENCED_PARAMETER(context);
UNREFERENCED_PARAMETER(env);

// TODO bug - inconsistent behavior for websocket providers: Connect calls XAsyncBegin before
// invoke the client handler, Send does not.
return XAsyncBegin(asyncBlock, nullptr, nullptr, __FUNCTION__,
return XAsyncBegin(asyncBlock, websocket, reinterpret_cast<void*>(HCWebSocketConnectAsync), __FUNCTION__,
[](XAsyncOp op, const XAsyncProviderData* data)
{
auto websocket = static_cast<HCWebsocketHandle>(data->context);

switch (op)
{
case XAsyncOp::Begin:
{
g_HCWebSocketConnect_Called = true;
XAsyncComplete(data->async, S_OK, 0);
XAsyncComplete(data->async, S_OK, sizeof(WebSocketCompletionResult));
return S_OK;
}
case XAsyncOp::GetResult:
{
RETURN_HR_IF(E_NOT_SUFFICIENT_BUFFER, data->bufferSize < sizeof(WebSocketCompletionResult));

auto result = static_cast<WebSocketCompletionResult*>(data->buffer);
ZeroMemory(result, sizeof(WebSocketCompletionResult));
result->errorCode = S_OK;
result->websocket = websocket;
return S_OK;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that the provider returns a proper WebSocketCompletionResult, it might be worth adding an end-to-end assertion in TestConnect — call HCGetWebSocketConnectResult after the async completes and verify connectResult.errorCode == S_OK and connectResult.websocket == websocket. Would fully exercise the new GetResult path.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that the provider returns a proper WebSocketCompletionResult, it might be worth adding an end-to-end assertion in TestConnect — call HCGetWebSocketConnectResult after the async completes and verify connectResult.errorCode == S_OK and connectResult.websocket == websocket. Would fully exercise the new GetResult path.

Done.

default: return S_OK;
Expand All @@ -151,7 +161,7 @@ HRESULT CALLBACK Test_Internal_HCWebSocketConnectAsyncAndClose(
UNREFERENCED_PARAMETER(context);
UNREFERENCED_PARAMETER(env);

return XAsyncBegin(asyncBlock, websocket, nullptr, __FUNCTION__,
return XAsyncBegin(asyncBlock, websocket, reinterpret_cast<void*>(HCWebSocketConnectAsync), __FUNCTION__,
[](XAsyncOp op, const XAsyncProviderData* data)
{
auto websocket = static_cast<HCWebsocketHandle>(data->context);
Expand Down Expand Up @@ -212,7 +222,7 @@ class TestWebSocketConnectAndCloseProvider : public IWebSocketProvider
UNREFERENCED_PARAMETER(subprotocol);

m_websocket = websocketHandle;
return XAsyncBegin(async, this, nullptr, __FUNCTION__,
return XAsyncBegin(async, this, reinterpret_cast<void*>(HCWebSocketConnectAsync), __FUNCTION__,
[](XAsyncOp op, const XAsyncProviderData* data)
{
auto provider = static_cast<TestWebSocketConnectAndCloseProvider*>(data->context);
Expand Down Expand Up @@ -475,6 +485,10 @@ DEFINE_TEST_CLASS(WebsocketTests)
XAsyncBlock asyncBlock{};
VERIFY_ARE_EQUAL(S_OK, HCWebSocketConnectAsync("test", "subProtoTest", websocket, &asyncBlock));
VERIFY_SUCCEEDED(XAsyncGetStatus(&asyncBlock, true));
WebSocketCompletionResult connectResult{};
VERIFY_ARE_EQUAL(S_OK, HCGetWebSocketConnectResult(&asyncBlock, &connectResult));
VERIFY_ARE_EQUAL(S_OK, connectResult.errorCode);
VERIFY_IS_TRUE(connectResult.websocket == websocket);
VERIFY_ARE_EQUAL(true, g_HCWebSocketConnect_Called);

ZeroMemory(&asyncBlock, sizeof(XAsyncBlock));
Expand Down