2 * Unit tests for dmsynth functions
4 * Copyright (C) 2012 Christian Costa
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/test.h"
33 static BOOL
missing_dmsynth(void)
35 IDirectMusicSynth
*dms
;
36 HRESULT hr
= CoCreateInstance(&CLSID_DirectMusicSynth
, NULL
, CLSCTX_INPROC_SERVER
,
37 &IID_IDirectMusicSynth
, (void**)&dms
);
39 if (hr
== S_OK
&& dms
)
41 IDirectMusicSynth_Release(dms
);
47 static void test_dmsynth(void)
49 IDirectMusicSynth
*dmsynth
= NULL
;
50 IDirectMusicSynthSink
*dmsynth_sink
= NULL
;
51 IReferenceClock
* clock_synth
= NULL
;
52 IReferenceClock
* clock_sink
= NULL
;
53 IKsControl
* control_synth
= NULL
;
54 IKsControl
* control_sink
= NULL
;
60 hr
= CoCreateInstance(&CLSID_DirectMusicSynth
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectMusicSynth
, (LPVOID
*)&dmsynth
);
61 ok(hr
== S_OK
, "CoCreateInstance returned: %x\n", hr
);
63 hr
= CoCreateInstance(&CLSID_DirectMusicSynthSink
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectMusicSynthSink
, (LPVOID
*)&dmsynth_sink
);
64 ok(hr
== S_OK
, "CoCreateInstance returned: %x\n", hr
);
66 hr
= IDirectMusicSynth_QueryInterface(dmsynth
, &IID_IKsControl
, (LPVOID
*)&control_synth
);
67 ok(hr
== S_OK
, "IDirectMusicSynth_QueryInterface returned: %x\n", hr
);
69 S(U(property
)).Id
= 0;
70 S(U(property
)).Flags
= KSPROPERTY_TYPE_GET
;
72 S(U(property
)).Set
= GUID_DMUS_PROP_INSTRUMENT2
;
73 hr
= IKsControl_KsProperty(control_synth
, &property
, sizeof(property
), &value
, sizeof(value
), &bytes
);
74 ok(hr
== S_OK
, "IKsControl_KsProperty returned: %x\n", hr
);
75 ok(bytes
== sizeof(DWORD
), "Returned bytes: %u, should be 4\n", bytes
);
76 ok(value
== TRUE
, "Return value: %u, should be 1\n", value
);
77 S(U(property
)).Set
= GUID_DMUS_PROP_DLS2
;
78 hr
= IKsControl_KsProperty(control_synth
, &property
, sizeof(property
), &value
, sizeof(value
), &bytes
);
79 ok(hr
== S_OK
, "IKsControl_KsProperty returned: %x\n", hr
);
80 ok(bytes
== sizeof(DWORD
), "Returned bytes: %u, should be 4\n", bytes
);
81 ok(value
== TRUE
, "Return value: %u, should be 1\n", value
);
82 S(U(property
)).Set
= GUID_DMUS_PROP_GM_Hardware
;
83 hr
= IKsControl_KsProperty(control_synth
, &property
, sizeof(property
), &value
, sizeof(value
), &bytes
);
84 ok(hr
== S_OK
, "IKsControl_KsProperty returned: %x\n", hr
);
85 ok(bytes
== sizeof(DWORD
), "Returned bytes: %u, should be 4\n", bytes
);
86 ok(value
== FALSE
, "Return value: %u, should be 0\n", value
);
87 S(U(property
)).Set
= GUID_DMUS_PROP_GS_Hardware
;
88 hr
= IKsControl_KsProperty(control_synth
, &property
, sizeof(property
), &value
, sizeof(value
), &bytes
);
89 ok(hr
== S_OK
, "IKsControl_KsProperty returned: %x\n", hr
);
90 ok(bytes
== sizeof(DWORD
), "Returned bytes: %u, should be 4\n", bytes
);
91 ok(value
== FALSE
, "Return value: %u, should be 0\n", value
);
92 S(U(property
)).Set
= GUID_DMUS_PROP_XG_Hardware
;
93 hr
= IKsControl_KsProperty(control_synth
, &property
, sizeof(property
), &value
, sizeof(value
), &bytes
);
94 ok(hr
== S_OK
, "IKsControl_KsProperty returned: %x\n", hr
);
95 ok(bytes
== sizeof(DWORD
), "Returned bytes: %u, should be 4\n", bytes
);
96 ok(value
== FALSE
, "Return value: %u, should be 0\n", value
);
98 hr
= IDirectMusicSynthSink_QueryInterface(dmsynth_sink
, &IID_IKsControl
, (LPVOID
*)&control_sink
);
99 ok(hr
== S_OK
, "IDirectMusicSynthSink_QueryInterface returned: %x\n", hr
);
101 S(U(property
)).Set
= GUID_DMUS_PROP_SinkUsesDSound
;
102 hr
= IKsControl_KsProperty(control_sink
, &property
, sizeof(property
), &value
, sizeof(value
), &bytes
);
103 ok(hr
== S_OK
, "IKsControl_KsProperty returned: %x\n", hr
);
104 ok(bytes
== sizeof(DWORD
), "Returned bytes: %u, should be 4\n", bytes
);
105 ok(value
== TRUE
, "Return value: %u, should be 1\n", value
);
107 /* Synth has no default clock */
108 hr
= IDirectMusicSynth_GetLatencyClock(dmsynth
, &clock_synth
);
109 ok(hr
== DMUS_E_NOSYNTHSINK
, "IDirectMusicSynth_GetLatencyClock returned: %x\n", hr
);
111 /* SynthSink has a default clock */
112 hr
= IDirectMusicSynthSink_GetLatencyClock(dmsynth_sink
, &clock_sink
);
113 ok(hr
== S_OK
, "IDirectMusicSynth_GetLatencyClock returned: %x\n", hr
);
114 ok(clock_sink
!= NULL
, "No clock returned\n");
116 /* This will set clock to Synth */
117 hr
= IDirectMusicSynth_SetSynthSink(dmsynth
, dmsynth_sink
);
118 ok(hr
== S_OK
, "IDirectMusicSynth_SetSynthSink returned: %x\n", hr
);
120 /* Check clocks are the same */
121 hr
= IDirectMusicSynth_GetLatencyClock(dmsynth
, &clock_synth
);
122 ok(hr
== S_OK
, "IDirectMusicSynth_GetLatencyClock returned: %x\n", hr
);
123 ok(clock_synth
!= NULL
, "No clock returned\n");
124 ok(clock_synth
== clock_sink
, "Synth and SynthSink clocks are not the same\n");
127 IDirectMusicSynth_Release(control_synth
);
129 IDirectMusicSynth_Release(control_sink
);
131 IReferenceClock_Release(clock_synth
);
133 IReferenceClock_Release(clock_sink
);
135 IDirectMusicSynthSink_Release(dmsynth_sink
);
136 IDirectMusicSynth_Release(dmsynth
);
139 static void test_COM(void)
141 IDirectMusicSynth8
*dms8
= (IDirectMusicSynth8
*)0xdeadbeef;
147 /* COM aggregation */
148 hr
= CoCreateInstance(&CLSID_DirectMusicSynth
, (IUnknown
*)&dms8
, CLSCTX_INPROC_SERVER
,
149 &IID_IUnknown
, (void**)&dms8
);
150 ok(hr
== CLASS_E_NOAGGREGATION
,
151 "DirectMusicSynth create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr
);
152 ok(!dms8
, "dms8 = %p\n", dms8
);
155 hr
= CoCreateInstance(&CLSID_DirectMusicSynth
, NULL
, CLSCTX_INPROC_SERVER
,
156 &IID_IDirectMusicObject
, (void**)&dms8
);
157 ok(hr
== E_NOINTERFACE
, "DirectMusicSynth create failed: %08x, expected E_NOINTERFACE\n", hr
);
159 /* Same refcount for all DirectMusicSynth interfaces */
160 hr
= CoCreateInstance(&CLSID_DirectMusicSynth
, NULL
, CLSCTX_INPROC_SERVER
,
161 &IID_IDirectMusicSynth8
, (void**)&dms8
);
162 ok(hr
== S_OK
, "DirectMusicSynth create failed: %08x, expected S_OK\n", hr
);
163 refcount
= IDirectMusicSynth8_AddRef(dms8
);
164 ok(refcount
== 2, "refcount == %u, expected 2\n", refcount
);
166 hr
= IDirectMusicSynth8_QueryInterface(dms8
, &IID_IKsControl
, (void**)&iksc
);
167 ok(hr
== S_OK
, "QueryInterface for IID_IKsControl failed: %08x\n", hr
);
168 refcount
= IKsControl_AddRef(iksc
);
169 ok(refcount
== 4, "refcount == %u, expected 4\n", refcount
);
170 IKsControl_Release(iksc
);
172 hr
= IDirectMusicSynth8_QueryInterface(dms8
, &IID_IUnknown
, (void**)&unk
);
173 ok(hr
== S_OK
, "QueryInterface for IID_IUnknown failed: %08x\n", hr
);
174 refcount
= IUnknown_AddRef(unk
);
175 ok(refcount
== 5, "refcount == %u, expected 5\n", refcount
);
176 IUnknown_Release(unk
);
178 /* Unsupported interfaces */
179 hr
= IDirectMusicSynth8_QueryInterface(dms8
, &IID_IDirectMusicSynthSink
, (void**)&unk
);
180 ok(hr
== E_NOINTERFACE
, "QueryInterface for IID_IDirectMusicSynthSink failed: %08x\n", hr
);
181 hr
= IDirectMusicSynth8_QueryInterface(dms8
, &IID_IReferenceClock
, (void**)&unk
);
182 ok(hr
== E_NOINTERFACE
, "QueryInterface for IID_IReferenceClock failed: %08x\n", hr
);
184 while (IDirectMusicSynth8_Release(dms8
));
187 static void test_COM_synthsink(void)
189 IDirectMusicSynthSink
*dmss
= (IDirectMusicSynthSink
*)0xdeadbeef;
195 /* COM aggregation */
196 hr
= CoCreateInstance(&CLSID_DirectMusicSynthSink
, (IUnknown
*)&dmss
, CLSCTX_INPROC_SERVER
,
197 &IID_IUnknown
, (void**)&dmss
);
198 ok(hr
== CLASS_E_NOAGGREGATION
,
199 "DirectMusicSynthSink create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr
);
200 ok(!dmss
, "dmss = %p\n", dmss
);
203 hr
= CoCreateInstance(&CLSID_DirectMusicSynthSink
, NULL
, CLSCTX_INPROC_SERVER
,
204 &IID_IDirectMusicObject
, (void**)&dmss
);
205 ok(hr
== E_NOINTERFACE
, "DirectMusicSynthSink create failed: %08x, expected E_NOINTERFACE\n", hr
);
207 /* Same refcount for all DirectMusicSynthSink interfaces */
208 hr
= CoCreateInstance(&CLSID_DirectMusicSynthSink
, NULL
, CLSCTX_INPROC_SERVER
,
209 &IID_IDirectMusicSynthSink
, (void**)&dmss
);
210 ok(hr
== S_OK
, "DirectMusicSynthSink create failed: %08x, expected S_OK\n", hr
);
211 refcount
= IDirectMusicSynthSink_AddRef(dmss
);
212 ok(refcount
== 2, "refcount == %u, expected 2\n", refcount
);
214 hr
= IDirectMusicSynthSink_QueryInterface(dmss
, &IID_IKsControl
, (void**)&iksc
);
215 ok(hr
== S_OK
, "QueryInterface for IID_IKsControl failed: %08x\n", hr
);
216 refcount
= IKsControl_AddRef(iksc
);
217 ok(refcount
== 4, "refcount == %u, expected 4\n", refcount
);
218 IKsControl_Release(iksc
);
220 hr
= IDirectMusicSynthSink_QueryInterface(dmss
, &IID_IUnknown
, (void**)&unk
);
221 ok(hr
== S_OK
, "QueryInterface for IID_IUnknown failed: %08x\n", hr
);
222 refcount
= IUnknown_AddRef(unk
);
223 ok(refcount
== 5, "refcount == %u, expected 5\n", refcount
);
224 IUnknown_Release(unk
);
226 /* Unsupported interfaces */
227 hr
= IDirectMusicSynthSink_QueryInterface(dmss
, &IID_IReferenceClock
, (void**)&unk
);
228 ok(hr
== E_NOINTERFACE
, "QueryInterface for IID_IReferenceClock failed: %08x\n", hr
);
230 while (IDirectMusicSynthSink_Release(dmss
));
234 CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
236 if (missing_dmsynth())
238 skip("dmsynth not available\n");
244 test_COM_synthsink();