From: Anton Baskanov baskanov@gmail.com
--- dlls/dplayx/dplay.c | 70 +++++++++++++++++++++++++++++++++++++- dlls/dplayx/tests/dplayx.c | 64 +++++++++++++++++----------------- 2 files changed, 101 insertions(+), 33 deletions(-)
diff --git a/dlls/dplayx/dplay.c b/dlls/dplayx/dplay.c index 9ed4c25b737..24fb9476afe 100644 --- a/dlls/dplayx/dplay.c +++ b/dlls/dplayx/dplay.c @@ -5959,9 +5959,75 @@ static HRESULT WINAPI IDirectPlay4Impl_GetMessageQueue( IDirectPlay4 *iface, DPI DWORD flags, DWORD *msgs, DWORD *bytes ) { IDirectPlayImpl *This = impl_from_IDirectPlay4( iface ); + struct PlayerList *playerFrom = NULL; + struct PlayerList *playerTo = NULL; HRESULT hr = DP_OK;
- FIXME( "(%p)->(0x%08lx,0x%08lx,0x%08lx,%p,%p): semi-stub\n", This, from, to, flags, msgs, bytes ); + TRACE( "(%p)->(0x%08lx,0x%08lx,0x%08lx,%p,%p)\n", This, from, to, flags, msgs, bytes ); + + if ( This->dp2->connectionInitialized == NO_PROVIDER ) + return DPERR_UNINITIALIZED; + + if ( !flags ) + flags = DPMESSAGEQUEUE_SEND; + + if ( flags != DPMESSAGEQUEUE_SEND && flags != DPMESSAGEQUEUE_RECEIVE ) + return DPERR_INVALIDFLAGS; + + EnterCriticalSection( &This->lock ); + + if ( to ) + { + playerTo = DP_FindPlayer( This, to ); + if ( !playerTo ) + { + LeaveCriticalSection( &This->lock ); + return DPERR_INVALIDPLAYER; + } + } + + if ( from ) + { + playerFrom = DP_FindPlayer( This, from ); + if ( !playerFrom ) + { + LeaveCriticalSection( &This->lock ); + return DPERR_INVALIDPLAYER; + } + } + + if ( flags & DPMESSAGEQUEUE_RECEIVE ) + { + DWORD byteCount = 0; + DWORD msgCount = 0; + struct DPMSG *msg; + + if ( playerTo && !(playerTo->lpPData->dwFlags & DPPLAYER_LOCAL) ) + { + LeaveCriticalSection( &This->lock ); + return DPERR_INVALIDPLAYER; + } + + for ( msg = DPQ_FIRST( This->dp2->receiveMsgs ); msg; msg = DPQ_NEXT( msg->msgs ) ) + { + if( from && msg->fromId != from ) + continue; + if( to && msg->toId != to ) + continue; + + ++msgCount; + byteCount += msg->copyMessage( NULL, msg->msg, msg->genericSize, FALSE ); + } + + if ( msgs ) + *msgs = msgCount; + if ( bytes ) + *bytes = byteCount; + + LeaveCriticalSection( &This->lock ); + + return DP_OK; + }
/* FIXME: Do we need to do from and to sanity checking here? */ /* FIXME: What about sends which are not immediate? */ @@ -5985,6 +6051,8 @@ static HRESULT WINAPI IDirectPlay4Impl_GetMessageQueue( IDirectPlay4 *iface, DPI else FIXME( "No SP for GetMessageQueue - fake some data\n" );
+ LeaveCriticalSection( &This->lock ); + return hr; }
diff --git a/dlls/dplayx/tests/dplayx.c b/dlls/dplayx/tests/dplayx.c index c1a954554f9..642e97b2e3d 100644 --- a/dlls/dplayx/tests/dplayx.c +++ b/dlls/dplayx/tests/dplayx.c @@ -9582,7 +9582,7 @@ static void test_GetMessageQueue(void) msgCount = 0xdeadbeef; byteCount = 0xdeadbeef; hr = IDirectPlayX_GetMessageQueue( dpA, 0, 0, 0, &msgCount, &byteCount ); - todo_wine ok( hr == DPERR_UNINITIALIZED, "got hr %#lx.\n", hr ); + ok( hr == DPERR_UNINITIALIZED, "got hr %#lx.\n", hr ); ok( msgCount == 0xdeadbeef, "got message count %lu.\n", msgCount ); ok( byteCount == 0xdeadbeef, "got byte count %lu.\n", byteCount );
@@ -9591,37 +9591,37 @@ static void test_GetMessageQueue(void) msgCount = 0xdeadbeef; byteCount = 0xdeadbeef; hr = IDirectPlayX_GetMessageQueue( dpA, 0, 0, DPMESSAGEQUEUE_SEND | DPMESSAGEQUEUE_RECEIVE, &msgCount, &byteCount ); - todo_wine ok( hr == DPERR_INVALIDFLAGS, "got hr %#lx.\n", hr ); + ok( hr == DPERR_INVALIDFLAGS, "got hr %#lx.\n", hr ); ok( msgCount == 0xdeadbeef, "got message count %lu.\n", msgCount ); ok( byteCount == 0xdeadbeef, "got byte count %lu.\n", byteCount );
msgCount = 0xdeadbeef; byteCount = 0xdeadbeef; hr = IDirectPlayX_GetMessageQueue( dpA, 0, 0, 4, &msgCount, &byteCount ); - todo_wine ok( hr == DPERR_INVALIDFLAGS, "got hr %#lx.\n", hr ); + ok( hr == DPERR_INVALIDFLAGS, "got hr %#lx.\n", hr ); ok( msgCount == 0xdeadbeef, "got message count %lu.\n", msgCount ); ok( byteCount == 0xdeadbeef, "got byte count %lu.\n", byteCount );
msgCount = 0xdeadbeef; byteCount = 0xdeadbeef; hr = IDirectPlayX_GetMessageQueue( dpA, 0x07734, 0, DPMESSAGEQUEUE_RECEIVE, &msgCount, &byteCount ); - todo_wine ok( hr == DPERR_INVALIDPLAYER, "got hr %#lx.\n", hr ); + ok( hr == DPERR_INVALIDPLAYER, "got hr %#lx.\n", hr ); ok( msgCount == 0xdeadbeef, "got message count %lu.\n", msgCount ); ok( byteCount == 0xdeadbeef, "got byte count %lu.\n", byteCount );
msgCount = 0xdeadbeef; byteCount = 0xdeadbeef; hr = IDirectPlayX_GetMessageQueue( dpA, 0, 0x07734, DPMESSAGEQUEUE_RECEIVE, &msgCount, &byteCount ); - todo_wine ok( hr == DPERR_INVALIDPLAYER, "got hr %#lx.\n", hr ); + ok( hr == DPERR_INVALIDPLAYER, "got hr %#lx.\n", hr ); ok( msgCount == 0xdeadbeef, "got message count %lu.\n", msgCount ); ok( byteCount == 0xdeadbeef, "got byte count %lu.\n", byteCount );
msgCount = 0xdeadbeef; byteCount = 0xdeadbeef; hr = IDirectPlayX_GetMessageQueue( dpA, 0, 0, DPMESSAGEQUEUE_RECEIVE, &msgCount, &byteCount ); - todo_wine ok( hr == DP_OK, "got hr %#lx.\n", hr ); - todo_wine ok( msgCount == 0, "got message count %lu.\n", msgCount ); - todo_wine ok( byteCount == 0, "got byte count %lu.\n", byteCount ); + ok( hr == DP_OK, "got hr %#lx.\n", hr ); + ok( msgCount == 0, "got message count %lu.\n", msgCount ); + ok( byteCount == 0, "got byte count %lu.\n", byteCount );
joinSession( dpA, &appGuidDpsd, &serverDpsd, &sendSock, &recvSock, NULL );
@@ -9630,42 +9630,42 @@ static void test_GetMessageQueue(void) msgCount = 0xdeadbeef; byteCount = 0xdeadbeef; hr = IDirectPlayX_GetMessageQueue( dpA, 0x07734, 0, DPMESSAGEQUEUE_RECEIVE, &msgCount, &byteCount ); - todo_wine ok( hr == DP_OK, "got hr %#lx.\n", hr ); - todo_wine ok( msgCount == 0, "got message count %lu.\n", msgCount ); - todo_wine ok( byteCount == 0, "got byte count %lu.\n", byteCount ); + ok( hr == DP_OK, "got hr %#lx.\n", hr ); + ok( msgCount == 0, "got message count %lu.\n", msgCount ); + ok( byteCount == 0, "got byte count %lu.\n", byteCount );
msgCount = 0xdeadbeef; byteCount = 0xdeadbeef; hr = IDirectPlayX_GetMessageQueue( dpA, 0, 0x07734, DPMESSAGEQUEUE_RECEIVE, &msgCount, &byteCount ); - todo_wine ok( hr == DP_OK, "got hr %#lx.\n", hr ); - todo_wine ok( msgCount == 0, "got message count %lu.\n", msgCount ); - todo_wine ok( byteCount == 0, "got byte count %lu.\n", byteCount ); + ok( hr == DP_OK, "got hr %#lx.\n", hr ); + ok( msgCount == 0, "got message count %lu.\n", msgCount ); + ok( byteCount == 0, "got byte count %lu.\n", byteCount );
msgCount = 0xdeadbeef; byteCount = 0xdeadbeef; hr = IDirectPlayX_GetMessageQueue( dpA, 0x1337, 0, DPMESSAGEQUEUE_RECEIVE, &msgCount, &byteCount ); - todo_wine ok( hr == DP_OK, "got hr %#lx.\n", hr ); - todo_wine ok( msgCount == 0, "got message count %lu.\n", msgCount ); - todo_wine ok( byteCount == 0, "got byte count %lu.\n", byteCount ); + ok( hr == DP_OK, "got hr %#lx.\n", hr ); + ok( msgCount == 0, "got message count %lu.\n", msgCount ); + ok( byteCount == 0, "got byte count %lu.\n", byteCount );
msgCount = 0xdeadbeef; byteCount = 0xdeadbeef; hr = IDirectPlayX_GetMessageQueue( dpA, 0, 0x1337, DPMESSAGEQUEUE_RECEIVE, &msgCount, &byteCount ); - todo_wine ok( hr == DPERR_INVALIDPLAYER, "got hr %#lx.\n", hr ); + ok( hr == DPERR_INVALIDPLAYER, "got hr %#lx.\n", hr ); ok( msgCount == 0xdeadbeef, "got message count %lu.\n", msgCount ); ok( byteCount == 0xdeadbeef, "got byte count %lu.\n", byteCount );
msgCount = 0xdeadbeef; byteCount = 0xdeadbeef; hr = IDirectPlayX_GetMessageQueue( dpA, 0x5e7, 0, DPMESSAGEQUEUE_RECEIVE, &msgCount, &byteCount ); - todo_wine ok( hr == DPERR_INVALIDPLAYER, "got hr %#lx.\n", hr ); + ok( hr == DPERR_INVALIDPLAYER, "got hr %#lx.\n", hr ); ok( msgCount == 0xdeadbeef, "got message count %lu.\n", msgCount ); ok( byteCount == 0xdeadbeef, "got byte count %lu.\n", byteCount );
msgCount = 0xdeadbeef; byteCount = 0xdeadbeef; hr = IDirectPlayX_GetMessageQueue( dpA, 0, 0x5e7, DPMESSAGEQUEUE_RECEIVE, &msgCount, &byteCount ); - todo_wine ok( hr == DPERR_INVALIDPLAYER, "got hr %#lx.\n", hr ); + ok( hr == DPERR_INVALIDPLAYER, "got hr %#lx.\n", hr ); ok( msgCount == 0xdeadbeef, "got message count %lu.\n", msgCount ); ok( byteCount == 0xdeadbeef, "got byte count %lu.\n", byteCount );
@@ -9689,30 +9689,30 @@ static void test_GetMessageQueue(void) msgCount = 0xdeadbeef; byteCount = 0xdeadbeef; hr = IDirectPlayX_GetMessageQueue( dpA, 0, 0x07734, DPMESSAGEQUEUE_RECEIVE, &msgCount, &byteCount ); - todo_wine ok( hr == DP_OK, "got hr %#lx.\n", hr ); - todo_wine ok( msgCount == 1, "got message count %lu.\n", msgCount ); - todo_wine ok( byteCount == createPlayerMsgSize, "got byte count %lu.\n", byteCount ); + ok( hr == DP_OK, "got hr %#lx.\n", hr ); + ok( msgCount == 1, "got message count %lu.\n", msgCount ); + ok( byteCount == createPlayerMsgSize, "got byte count %lu.\n", byteCount );
msgCount = 0xdeadbeef; byteCount = 0xdeadbeef; hr = IDirectPlayX_GetMessageQueue( dp, 0, 0x07734, DPMESSAGEQUEUE_RECEIVE, &msgCount, &byteCount ); - todo_wine ok( hr == DP_OK, "got hr %#lx.\n", hr ); - todo_wine ok( msgCount == 1, "got message count %lu.\n", msgCount ); - todo_wine ok( byteCount == createPlayerMsgSize, "got byte count %lu.\n", byteCount ); + ok( hr == DP_OK, "got hr %#lx.\n", hr ); + ok( msgCount == 1, "got message count %lu.\n", msgCount ); + ok( byteCount == createPlayerMsgSize, "got byte count %lu.\n", byteCount );
msgCount = 0xdeadbeef; byteCount = 0xdeadbeef; hr = IDirectPlayX_GetMessageQueue( dpA, 0x1337, 0, DPMESSAGEQUEUE_RECEIVE, &msgCount, &byteCount ); - todo_wine ok( hr == DP_OK, "got hr %#lx.\n", hr ); - todo_wine ok( msgCount == 1, "got message count %lu.\n", msgCount ); - todo_wine ok( byteCount == sizeof( data ), "got byte count %lu.\n", byteCount ); + ok( hr == DP_OK, "got hr %#lx.\n", hr ); + ok( msgCount == 1, "got message count %lu.\n", msgCount ); + ok( byteCount == sizeof( data ), "got byte count %lu.\n", byteCount );
msgCount = 0xdeadbeef; byteCount = 0xdeadbeef; hr = IDirectPlayX_GetMessageQueue( dpA, 0, 0, DPMESSAGEQUEUE_RECEIVE, &msgCount, &byteCount ); - todo_wine ok( hr == DP_OK, "got hr %#lx.\n", hr ); - todo_wine ok( msgCount == 2, "got message count %lu.\n", msgCount ); - todo_wine ok( byteCount == createPlayerMsgSize + sizeof( data ), "got byte count %lu.\n", byteCount ); + ok( hr == DP_OK, "got hr %#lx.\n", hr ); + ok( msgCount == 2, "got message count %lu.\n", msgCount ); + ok( byteCount == createPlayerMsgSize + sizeof( data ), "got byte count %lu.\n", byteCount );
closesocket( recvSock ); closesocket( sendSock );