Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/dmusic/tests/dmusic.c | 129 ++++++++++++++++++++++++++++++------- 1 file changed, 107 insertions(+), 22 deletions(-)
diff --git a/dlls/dmusic/tests/dmusic.c b/dlls/dmusic/tests/dmusic.c index a4fbd4af717..cb436ed0cdd 100644 --- a/dlls/dmusic/tests/dmusic.c +++ b/dlls/dmusic/tests/dmusic.c @@ -38,20 +38,10 @@ static void test_dmusic(void) DMUS_PORTCAPS port_caps; DMUS_PORTPARAMS port_params; IDirectMusicPort *port = NULL; - DMUS_CLOCKINFO clock_info; - GUID guid_clock; - IReferenceClock *clock = NULL;
hr = CoCreateInstance(&CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusic, (LPVOID*)&dmusic); ok(hr == S_OK, "Cannot create DirectMusic object (%x)\n", hr);
- hr = IDirectMusic_GetMasterClock(dmusic, &guid_clock, &clock); - ok(hr == S_OK, "IDirectMusic_GetMasterClock returned: %x\n", hr); - ok(clock != NULL, "No clock returned\n"); - trace(" guidPort = %s\n", wine_dbgstr_guid(&guid_clock)); - if (clock) - IReferenceClock_Release(clock); - port_params.dwSize = sizeof(port_params); port_params.dwValidParams = DMUS_PORTPARAMS_CHANNELGROUPS | DMUS_PORTPARAMS_AUDIOCHANNELS; port_params.dwChannelGroups = 1; @@ -96,18 +86,6 @@ static void test_dmusic(void) index++; }
- index = 0; - clock_info.dwSize = sizeof(clock_info); - while (IDirectMusic_EnumMasterClock(dmusic, index, &clock_info) == S_OK) - { - ok(clock_info.dwSize == sizeof(clock_info), "DMUS_CLOCKINFO dwSize member is wrong (%u)\n", clock_info.dwSize); - trace("Clock %u:\n", index); - trace(" ctType = %u\n", clock_info.ctType); - trace(" guidClock = %s\n", wine_dbgstr_guid(&clock_info.guidClock)); - trace(" wszDescription = %s\n", wine_dbgstr_w(clock_info.wszDescription)); - index++; - } - if (port) IDirectMusicPort_Release(port); IDirectMusic_Release(dmusic); @@ -776,6 +754,112 @@ static void test_parsedescriptor(void) IDirectMusicObject_Release(dmo); }
+static void test_master_clock(void) +{ + static const GUID guid_system_clock = {0x58d58419, 0x71b4, 0x11d1, {0xa7, 0x4c, 0x00, 0x00, 0xf8, 0x75, 0xac, 0x12}}; + static const GUID guid_dsound_clock = {0x58d58420, 0x71b4, 0x11d1, {0xa7, 0x4c, 0x00, 0x00, 0xf8, 0x75, 0xac, 0x12}}; + static const WCHAR name_dsound_clock[] = {'D','i','r','e','c','t','S','o','u','n','d',' ','C','l','o','c','k',0}; + static const WCHAR name_system_clock[] = {'S','y','s','t','e','m',' ','C','l','o','c','k',0}; + IReferenceClock *clock, *clock2; + REFERENCE_TIME time1, time2; + LARGE_INTEGER counter, freq; + DMUS_CLOCKINFO clock_info; + IDirectMusic *dmusic; + DWORD cookie; + HRESULT hr; + ULONG ref; + GUID guid; + + hr = CoCreateInstance(&CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusic, (void **)&dmusic); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IDirectMusic_GetMasterClock(dmusic, NULL, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + memset(&guid, 0xcc, sizeof(guid)); + hr = IDirectMusic_GetMasterClock(dmusic, &guid, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + todo_wine ok(IsEqualGUID(&guid, &guid_system_clock), "Got guid %s.\n", wine_dbgstr_guid(&guid)); + + clock = (IReferenceClock *)0xdeadbeef; + hr = IDirectMusic_GetMasterClock(dmusic, NULL, &clock); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(clock && clock != (IReferenceClock *)0xdeadbeef, "Got clock %p.\n", clock); + + hr = IDirectMusic_GetMasterClock(dmusic, NULL, &clock2); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(clock2 == clock, "Clocks didn't match.\n"); + IReferenceClock_Release(clock2); + + memset(&guid, 0xcc, sizeof(guid)); + hr = IDirectMusic_GetMasterClock(dmusic, &guid, &clock2); + ok(hr == S_OK, "Got hr %#x.\n", hr); + todo_wine ok(IsEqualGUID(&guid, &guid_system_clock), "Got guid %s.\n", wine_dbgstr_guid(&guid)); + ok(clock2 == clock, "Clocks didn't match.\n"); + IReferenceClock_Release(clock2); + + QueryPerformanceFrequency(&freq); + QueryPerformanceCounter(&counter); + hr = IReferenceClock_GetTime(clock, &time1); + ok(hr == S_OK, "Got hr %#x.\n", hr); + time2 = counter.QuadPart * 10000000.0 / freq.QuadPart; + todo_wine ok(abs(time1 - time2) < 20 * 10000, "Expected about %s, got %s.\n", + wine_dbgstr_longlong(time2), wine_dbgstr_longlong(time1)); + + hr = IReferenceClock_GetTime(clock, &time2); + todo_wine ok(hr == (time2 == time1 ? S_FALSE : S_OK), "Got hr %#x.\n", hr); + + Sleep(100); + hr = IReferenceClock_GetTime(clock, &time2); + ok(hr == S_OK, "Got hr %#x.\n", hr); + todo_wine ok(time2 - time1 > 80 * 10000, "Expected about %s, but got %s.\n", + wine_dbgstr_longlong(time1 + 100 * 10000), wine_dbgstr_longlong(time2)); + + hr = IReferenceClock_AdviseTime(clock, 0, 0, NULL, &cookie); + todo_wine ok(hr == E_NOTIMPL, "Got hr %#x.\n", hr); + + hr = IReferenceClock_AdvisePeriodic(clock, 0, 0, NULL, &cookie); + todo_wine ok(hr == E_NOTIMPL, "Got hr %#x.\n", hr); + + hr = IReferenceClock_Unadvise(clock, 0); + todo_wine ok(hr == E_NOTIMPL, "Got hr %#x.\n", hr); + + IReferenceClock_Release(clock); + + hr = IDirectMusic_EnumMasterClock(dmusic, 0, NULL); + todo_wine ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + + memset(&clock_info, 0xcc, sizeof(DMUS_CLOCKINFO)); + clock_info.dwSize = sizeof(DMUS_CLOCKINFO7); + hr = IDirectMusic_EnumMasterClock(dmusic, 0, &clock_info); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(clock_info.ctType == DMUS_CLOCK_SYSTEM, "Got type %#x.\n", clock_info.ctType); + ok(IsEqualGUID(&clock_info.guidClock, &guid_system_clock), "Got guid %s.\n", + wine_dbgstr_guid(&clock_info.guidClock)); + ok(!lstrcmpW(clock_info.wszDescription, name_system_clock), "Got name %s.\n", + wine_dbgstr_w(clock_info.wszDescription)); + ok(clock_info.dwFlags == 0xcccccccc, "Got flags %#x.\n", clock_info.dwFlags); + + memset(&clock_info, 0xcc, sizeof(DMUS_CLOCKINFO)); + clock_info.dwSize = sizeof(DMUS_CLOCKINFO7); + hr = IDirectMusic_EnumMasterClock(dmusic, 1, &clock_info); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(clock_info.ctType == DMUS_CLOCK_SYSTEM, "Got type %#x.\n", clock_info.ctType); + ok(IsEqualGUID(&clock_info.guidClock, &guid_dsound_clock), "Got guid %s.\n", + wine_dbgstr_guid(&clock_info.guidClock)); + ok(!lstrcmpW(clock_info.wszDescription, name_dsound_clock), "Got name %s.\n", + wine_dbgstr_w(clock_info.wszDescription)); + ok(clock_info.dwFlags == 0xcccccccc, "Got flags %#x.\n", clock_info.dwFlags); + + memset(&clock_info, 0xcc, sizeof(DMUS_CLOCKINFO)); + clock_info.dwSize = sizeof(DMUS_CLOCKINFO7); + hr = IDirectMusic_EnumMasterClock(dmusic, 2, &clock_info); + ok(hr == S_FALSE, "Got hr %#x.\n", hr); + + ref = IDirectMusic_Release(dmusic); + ok(!ref, "Got outstanding refcount %d.\n", ref); +} + START_TEST(dmusic) { CoInitializeEx(NULL, COINIT_MULTITHREADED); @@ -794,6 +878,7 @@ START_TEST(dmusic) test_dmbuffer(); test_dmcoll(); test_parsedescriptor(); + test_master_clock();
CoUninitialize(); }
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/dmusic/dmusic.c | 6 +++--- dlls/dmusic/dmusic_private.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/dlls/dmusic/dmusic.c b/dlls/dmusic/dmusic.c index 94c0ff441c8..a74a31e68bf 100644 --- a/dlls/dmusic/dmusic.c +++ b/dlls/dmusic/dmusic.c @@ -72,7 +72,7 @@ static ULONG WINAPI IDirectMusic8Impl_Release(LPDIRECTMUSIC8 iface) TRACE("(%p)->(): new ref = %u\n", This, ref);
if (!ref) { - IReferenceClock_Release(&This->master_clock->IReferenceClock_iface); + IReferenceClock_Release(This->master_clock); if (This->dsound) IDirectSound_Release(This->dsound); HeapFree(GetProcessHeap(), 0, This->system_ports); @@ -246,9 +246,9 @@ static HRESULT WINAPI IDirectMusic8Impl_GetMasterClock(LPDIRECTMUSIC8 iface, LPG TRACE("(%p)->(%p, %p)\n", This, guid_clock, reference_clock);
if (guid_clock) - *guid_clock = This->master_clock->pClockInfo.guidClock; + *guid_clock = GUID_NULL; if (reference_clock) { - *reference_clock = &This->master_clock->IReferenceClock_iface; + *reference_clock = This->master_clock; IReferenceClock_AddRef(*reference_clock); }
diff --git a/dlls/dmusic/dmusic_private.h b/dlls/dmusic/dmusic_private.h index c59646d5709..4863aad80b3 100644 --- a/dlls/dmusic/dmusic_private.h +++ b/dlls/dmusic/dmusic_private.h @@ -111,7 +111,7 @@ struct IDirectMusic8Impl { IDirectMusic8 IDirectMusic8_iface; LONG ref; IDirectSound *dsound; - IReferenceClockImpl *master_clock; + IReferenceClock *master_clock; IDirectMusicPort **ports; int num_ports; port_info *system_ports;
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/dmusic/dmusic.c | 125 ++++++++++++++++++++++++++++++++++++- dlls/dmusic/tests/dmusic.c | 12 ++-- 2 files changed, 130 insertions(+), 7 deletions(-)
diff --git a/dlls/dmusic/dmusic.c b/dlls/dmusic/dmusic.c index a74a31e68bf..cc798ce4d92 100644 --- a/dlls/dmusic/dmusic.c +++ b/dlls/dmusic/dmusic.c @@ -22,9 +22,132 @@ #include <stdio.h>
#include "dmusic_private.h" +#include "wine/heap.h"
WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
+struct master_clock { + IReferenceClock IReferenceClock_iface; + LONG ref; + double freq; + REFERENCE_TIME last_time; +}; + +static inline struct master_clock *impl_from_IReferenceClock(IReferenceClock *iface) +{ + return CONTAINING_RECORD(iface, struct master_clock, IReferenceClock_iface); +} + +static HRESULT WINAPI master_IReferenceClock_QueryInterface(IReferenceClock *iface, REFIID riid, + void **ret_iface) +{ + TRACE("(%p, %s, %p)\n", iface, debugstr_dmguid(riid), ret_iface); + + if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IReferenceClock)) + *ret_iface = iface; + else { + WARN("no interface for %s\n", debugstr_dmguid(riid)); + *ret_iface = NULL; + return E_NOINTERFACE; + } + + IReferenceClock_AddRef(iface); + + return S_OK; +} + +static ULONG WINAPI master_IReferenceClock_AddRef(IReferenceClock *iface) +{ + struct master_clock *This = impl_from_IReferenceClock(iface); + ULONG ref = InterlockedIncrement(&This->ref); + + TRACE("(%p) ref = %u\n", iface, ref); + + return ref; +} + +static ULONG WINAPI master_IReferenceClock_Release(IReferenceClock *iface) +{ + struct master_clock *This = impl_from_IReferenceClock(iface); + ULONG ref = InterlockedDecrement(&This->ref); + + TRACE("(%p) ref = %u\n", iface, ref); + + if (!ref) + heap_free(This); + + return ref; +} + +static HRESULT WINAPI master_IReferenceClock_GetTime(IReferenceClock *iface, + REFERENCE_TIME *time) +{ + struct master_clock *This = impl_from_IReferenceClock(iface); + LARGE_INTEGER counter; + HRESULT hr; + + TRACE("(%p, %p)\n", iface, time); + + QueryPerformanceCounter(&counter); + *time = counter.QuadPart * This->freq; + hr = (*time == This->last_time) ? S_FALSE : S_OK; + This->last_time = *time; + + return hr; +} + +static HRESULT WINAPI master_IReferenceClock_AdviseTime(IReferenceClock *iface, + REFERENCE_TIME base, REFERENCE_TIME offset, HANDLE event, DWORD *cookie) +{ + TRACE("(%p, %s, %s, %p, %p): method not implemented\n", iface, wine_dbgstr_longlong(base), + wine_dbgstr_longlong(offset), event, cookie); + return E_NOTIMPL; +} + +static HRESULT WINAPI master_IReferenceClock_AdvisePeriodic(IReferenceClock *iface, + REFERENCE_TIME start, REFERENCE_TIME period, HANDLE semaphore, DWORD *cookie) +{ + TRACE("(%p, %s, %s, %p, %p): method not implemented\n", iface, wine_dbgstr_longlong(start), + wine_dbgstr_longlong(period), semaphore, cookie); + return E_NOTIMPL; +} + +static HRESULT WINAPI master_IReferenceClock_Unadvise(IReferenceClock *iface, DWORD cookie) +{ + TRACE("(%p, %#x): method not implemented\n", iface, cookie); + return E_NOTIMPL; +} + +static const IReferenceClockVtbl master_clock_vtbl = { + master_IReferenceClock_QueryInterface, + master_IReferenceClock_AddRef, + master_IReferenceClock_Release, + master_IReferenceClock_GetTime, + master_IReferenceClock_AdviseTime, + master_IReferenceClock_AdvisePeriodic, + master_IReferenceClock_Unadvise, +}; + +static HRESULT master_clock_create(IReferenceClock **clock) +{ + struct master_clock *obj; + LARGE_INTEGER freq; + + TRACE("(%p)\n", clock); + + if (!(obj = heap_alloc_zero(sizeof(*obj)))) + return E_OUTOFMEMORY; + + obj->IReferenceClock_iface.lpVtbl = &master_clock_vtbl; + obj->ref = 1; + QueryPerformanceFrequency(&freq); + obj->freq = 10000000.0 / freq.QuadPart; + + *clock = &obj->IReferenceClock_iface; + + return S_OK; +} + static inline IDirectMusic8Impl *impl_from_IDirectMusic8(IDirectMusic8 *iface) { return CONTAINING_RECORD(iface, IDirectMusic8Impl, IDirectMusic8_iface); @@ -483,7 +606,7 @@ HRESULT WINAPI DMUSIC_CreateDirectMusicImpl(LPCGUID riid, LPVOID* ret_iface, LPU
dmusic->IDirectMusic8_iface.lpVtbl = &DirectMusic8_Vtbl; dmusic->ref = 1; - ret = DMUSIC_CreateReferenceClockImpl(&IID_IReferenceClock, (void **)&dmusic->master_clock, NULL); + ret = master_clock_create(&dmusic->master_clock); if (FAILED(ret)) { HeapFree(GetProcessHeap(), 0, dmusic); return ret; diff --git a/dlls/dmusic/tests/dmusic.c b/dlls/dmusic/tests/dmusic.c index cb436ed0cdd..2f287e95515 100644 --- a/dlls/dmusic/tests/dmusic.c +++ b/dlls/dmusic/tests/dmusic.c @@ -803,26 +803,26 @@ static void test_master_clock(void) hr = IReferenceClock_GetTime(clock, &time1); ok(hr == S_OK, "Got hr %#x.\n", hr); time2 = counter.QuadPart * 10000000.0 / freq.QuadPart; - todo_wine ok(abs(time1 - time2) < 20 * 10000, "Expected about %s, got %s.\n", + ok(abs(time1 - time2) < 20 * 10000, "Expected about %s, got %s.\n", wine_dbgstr_longlong(time2), wine_dbgstr_longlong(time1));
hr = IReferenceClock_GetTime(clock, &time2); - todo_wine ok(hr == (time2 == time1 ? S_FALSE : S_OK), "Got hr %#x.\n", hr); + ok(hr == (time2 == time1 ? S_FALSE : S_OK), "Got hr %#x.\n", hr);
Sleep(100); hr = IReferenceClock_GetTime(clock, &time2); ok(hr == S_OK, "Got hr %#x.\n", hr); - todo_wine ok(time2 - time1 > 80 * 10000, "Expected about %s, but got %s.\n", + ok(time2 - time1 > 80 * 10000, "Expected about %s, but got %s.\n", wine_dbgstr_longlong(time1 + 100 * 10000), wine_dbgstr_longlong(time2));
hr = IReferenceClock_AdviseTime(clock, 0, 0, NULL, &cookie); - todo_wine ok(hr == E_NOTIMPL, "Got hr %#x.\n", hr); + ok(hr == E_NOTIMPL, "Got hr %#x.\n", hr);
hr = IReferenceClock_AdvisePeriodic(clock, 0, 0, NULL, &cookie); - todo_wine ok(hr == E_NOTIMPL, "Got hr %#x.\n", hr); + ok(hr == E_NOTIMPL, "Got hr %#x.\n", hr);
hr = IReferenceClock_Unadvise(clock, 0); - todo_wine ok(hr == E_NOTIMPL, "Got hr %#x.\n", hr); + ok(hr == E_NOTIMPL, "Got hr %#x.\n", hr);
IReferenceClock_Release(clock);
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=53717
Your paranoid android.
=== wvistau64_zh_CN (32 bit report) ===
dmusic: dmusic.c:839: Test failed: Got name L"\7cfb\7edf\65f6\949f". dmusic.c:850: Test failed: Got name L"DirectSound \65f6\949f".
=== wvistau64_fr (32 bit report) ===
dmusic: dmusic.c:839: Test failed: Got name L"Horloge syst\00e8me". dmusic.c:850: Test failed: Got name L"Horloge DirectSound".
=== wvistau64_he (32 bit report) ===
dmusic: dmusic.c:839: Test failed: Got name L"\05e9\05e2\05d5\05df \05de\05e2\05e8\05db\05ea". dmusic.c:850: Test failed: Got name L"\05e9\05e2\05d5\05df DirectSound".
=== w7u (32 bit report) ===
dmusic: dmusic.c:839: Test failed: Got name L"\30b7\30b9\30c6\30e0 \30af\30ed\30c3\30af". dmusic.c:850: Test failed: Got name L"DirectSound \30af\30ed\30c3\30af".
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=53715
Your paranoid android.
=== wvistau64_zh_CN (32 bit report) ===
dmusic: dmusic.c:839: Test failed: Got name L"\7cfb\7edf\65f6\949f". dmusic.c:850: Test failed: Got name L"DirectSound \65f6\949f".
=== wvistau64_fr (32 bit report) ===
dmusic: dmusic.c:839: Test failed: Got name L"Horloge syst\00e8me". dmusic.c:850: Test failed: Got name L"Horloge DirectSound".
=== wvistau64_he (32 bit report) ===
dmusic: dmusic.c:839: Test failed: Got name L"\05e9\05e2\05d5\05df \05de\05e2\05e8\05db\05ea". dmusic.c:850: Test failed: Got name L"\05e9\05e2\05d5\05df DirectSound".
=== w7u (32 bit report) ===
dmusic: dmusic.c:839: Test failed: Got name L"\30b7\30b9\30c6\30e0 \30af\30ed\30c3\30af". dmusic.c:850: Test failed: Got name L"DirectSound \30af\30ed\30c3\30af".