diff --git a/Tests/UnitTests/Tests/MockTests.cpp b/Tests/UnitTests/Tests/MockTests.cpp index 505a0f47..8058edc7 100644 --- a/Tests/UnitTests/Tests/MockTests.cpp +++ b/Tests/UnitTests/Tests/MockTests.cpp @@ -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")); diff --git a/Tests/UnitTests/Tests/WebsocketTests.cpp b/Tests/UnitTests/Tests/WebsocketTests.cpp index 5a789650..b33ef3e1 100644 --- a/Tests/UnitTests/Tests/WebsocketTests.cpp +++ b/Tests/UnitTests/Tests/WebsocketTests.cpp @@ -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(HCWebSocketConnectAsync), __FUNCTION__, [](XAsyncOp op, const XAsyncProviderData* data) { + auto websocket = static_cast(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(data->buffer); + ZeroMemory(result, sizeof(WebSocketCompletionResult)); + result->errorCode = S_OK; + result->websocket = websocket; return S_OK; } default: return S_OK; @@ -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(HCWebSocketConnectAsync), __FUNCTION__, [](XAsyncOp op, const XAsyncProviderData* data) { auto websocket = static_cast(data->context); @@ -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(HCWebSocketConnectAsync), __FUNCTION__, [](XAsyncOp op, const XAsyncProviderData* data) { auto provider = static_cast(data->context); @@ -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));