diff --git a/dlls/dmusic/tests/Makefile.in b/dlls/dmusic/tests/Makefile.in index e9721cac19..2f8d6a8654 100644 --- a/dlls/dmusic/tests/Makefile.in +++ b/dlls/dmusic/tests/Makefile.in @@ -1,5 +1,5 @@ TESTDLL = dmusic.dll -IMPORTS = oleaut32 ole32 uuid +IMPORTS = oleaut32 ole32 uuid user32 dsound C_SRCS = \ dmusic.c diff --git a/dlls/dmusic/tests/dmusic.c b/dlls/dmusic/tests/dmusic.c index 0a1eca6acd..8473a401ef 100644 --- a/dlls/dmusic/tests/dmusic.c +++ b/dlls/dmusic/tests/dmusic.c @@ -122,6 +122,78 @@ static void test_dmusic(void) IDirectMusic_Release(dmusic); } +static ULONG get_refcount(IDirectSound *iface) +{ + IDirectSound_AddRef(iface); + return IDirectSound_Release(iface); +} + +static void test_setdsound(void) +{ + IDirectMusic *dmusic; + IDirectSound *dsound, *dsound2; + HRESULT hr; + ULONG ref; + + /* Old dsound without SetCooperativeLevel() */ + hr = DirectSoundCreate(NULL, &dsound, NULL); + if (hr == DSERR_NODRIVER ) { + skip("No driver\n"); + return; + } + ok(hr == S_OK, "DirectSoundCreate failed: %08x\n", hr); + hr = CoCreateInstance(&CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusic8, + (void **)&dmusic); + ok(hr == S_OK, "DirectMusic create failed: %08x\n", hr); + hr = IDirectMusic_SetDirectSound(dmusic, dsound, NULL); + ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr); + IDirectMusic_Release(dmusic); + IDirectSound_Release(dsound); + + /* dsound ref counting */ + hr = CoCreateInstance(&CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusic8, + (void **)&dmusic); + ok(hr == S_OK, "DirectMusic create failed: %08x\n", hr); + hr = DirectSoundCreate8(NULL, (IDirectSound8 **)&dsound, NULL); + ok(hr == S_OK, "DirectSoundCreate failed: %08x\n", hr); + hr = IDirectSound_SetCooperativeLevel(dsound, GetForegroundWindow(), DSSCL_PRIORITY); + ok(hr == S_OK, "SetCooperativeLevel failed: %08x\n", hr); + hr = IDirectMusic_SetDirectSound(dmusic, dsound, NULL); + ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr); + ref = get_refcount(dsound); + todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref); + + /* Releasing dsound from dmusic */ + hr = IDirectMusic_SetDirectSound(dmusic, NULL, NULL); + ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr); + ref = get_refcount(dsound); + ok(ref == 1, "dsound ref count got %d expected 1\n", ref); + + /* Setting the same dsound twice */ + hr = IDirectMusic_SetDirectSound(dmusic, dsound, NULL); + ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr); + ref = get_refcount(dsound); + todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref); + hr = IDirectMusic_SetDirectSound(dmusic, dsound, NULL); + ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr); + ref = get_refcount(dsound); + todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref); + + /* Replacing one dsound with another */ + hr = DirectSoundCreate8(NULL, (IDirectSound8 **)&dsound2, NULL); + ok(hr == S_OK, "DirectSoundCreate failed: %08x\n", hr); + hr = IDirectMusic_SetDirectSound(dmusic, dsound2, NULL); + ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr); + ref = get_refcount(dsound); + ok(ref == 1, "dsound ref count got %d expected 1\n", ref); + ref = get_refcount(dsound2); + todo_wine ok(ref == 2, "dsound2 ref count got %d expected 2\n", ref); + + IDirectMusic_Release(dmusic); + IDirectSound_Release(dsound); + IDirectSound_Release(dsound2); +} + static void test_dmbuffer(void) { IDirectMusic *dmusic; @@ -450,6 +522,7 @@ START_TEST(dmusic) test_COM_dmcoll(); test_COM_synthport(); test_dmusic(); + test_setdsound(); test_dmbuffer(); test_dmcoll();