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 ULONG
get_refcount(void *iface
)
49 IUnknown
*unknown
= iface
;
50 IUnknown_AddRef(unknown
);
51 return IUnknown_Release(unknown
);
54 static void test_dmsynth(void)
56 IDirectMusicSynth
*dmsynth
= NULL
;
57 IDirectMusicSynthSink
*dmsynth_sink
= NULL
;
58 IReferenceClock
* clock_synth
= NULL
;
59 IReferenceClock
* clock_sink
= NULL
;
60 IKsControl
* control_synth
= NULL
;
61 IKsControl
* control_sink
= NULL
;
62 ULONG ref_clock_synth
, ref_clock_sink
;
68 hr
= CoCreateInstance(&CLSID_DirectMusicSynth
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectMusicSynth
, (LPVOID
*)&dmsynth
);
69 ok(hr
== S_OK
, "CoCreateInstance returned: %x\n", hr
);
71 hr
= CoCreateInstance(&CLSID_DirectMusicSynthSink
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectMusicSynthSink
, (LPVOID
*)&dmsynth_sink
);
72 ok(hr
== S_OK
, "CoCreateInstance returned: %x\n", hr
);
74 hr
= IDirectMusicSynth_QueryInterface(dmsynth
, &IID_IKsControl
, (LPVOID
*)&control_synth
);
75 ok(hr
== S_OK
, "IDirectMusicSynth_QueryInterface returned: %x\n", hr
);
77 S(U(property
)).Id
= 0;
78 S(U(property
)).Flags
= KSPROPERTY_TYPE_GET
;
80 S(U(property
)).Set
= GUID_DMUS_PROP_INSTRUMENT2
;
81 hr
= IKsControl_KsProperty(control_synth
, &property
, sizeof(property
), &value
, sizeof(value
), &bytes
);
82 ok(hr
== S_OK
, "IKsControl_KsProperty returned: %x\n", hr
);
83 ok(bytes
== sizeof(DWORD
), "Returned bytes: %u, should be 4\n", bytes
);
84 ok(value
== TRUE
, "Return value: %u, should be 1\n", value
);
85 S(U(property
)).Set
= GUID_DMUS_PROP_DLS2
;
86 hr
= IKsControl_KsProperty(control_synth
, &property
, sizeof(property
), &value
, sizeof(value
), &bytes
);
87 ok(hr
== S_OK
, "IKsControl_KsProperty returned: %x\n", hr
);
88 ok(bytes
== sizeof(DWORD
), "Returned bytes: %u, should be 4\n", bytes
);
89 ok(value
== TRUE
, "Return value: %u, should be 1\n", value
);
90 S(U(property
)).Set
= GUID_DMUS_PROP_GM_Hardware
;
91 hr
= IKsControl_KsProperty(control_synth
, &property
, sizeof(property
), &value
, sizeof(value
), &bytes
);
92 ok(hr
== S_OK
, "IKsControl_KsProperty returned: %x\n", hr
);
93 ok(bytes
== sizeof(DWORD
), "Returned bytes: %u, should be 4\n", bytes
);
94 ok(value
== FALSE
, "Return value: %u, should be 0\n", value
);
95 S(U(property
)).Set
= GUID_DMUS_PROP_GS_Hardware
;
96 hr
= IKsControl_KsProperty(control_synth
, &property
, sizeof(property
), &value
, sizeof(value
), &bytes
);
97 ok(hr
== S_OK
, "IKsControl_KsProperty returned: %x\n", hr
);
98 ok(bytes
== sizeof(DWORD
), "Returned bytes: %u, should be 4\n", bytes
);
99 ok(value
== FALSE
, "Return value: %u, should be 0\n", value
);
100 S(U(property
)).Set
= GUID_DMUS_PROP_XG_Hardware
;
101 hr
= IKsControl_KsProperty(control_synth
, &property
, sizeof(property
), &value
, sizeof(value
), &bytes
);
102 ok(hr
== S_OK
, "IKsControl_KsProperty returned: %x\n", hr
);
103 ok(bytes
== sizeof(DWORD
), "Returned bytes: %u, should be 4\n", bytes
);
104 ok(value
== FALSE
, "Return value: %u, should be 0\n", value
);
106 hr
= IDirectMusicSynthSink_QueryInterface(dmsynth_sink
, &IID_IKsControl
, (LPVOID
*)&control_sink
);
107 ok(hr
== S_OK
, "IDirectMusicSynthSink_QueryInterface returned: %x\n", hr
);
109 S(U(property
)).Set
= GUID_DMUS_PROP_SinkUsesDSound
;
110 hr
= IKsControl_KsProperty(control_sink
, &property
, sizeof(property
), &value
, sizeof(value
), &bytes
);
111 ok(hr
== S_OK
, "IKsControl_KsProperty returned: %x\n", hr
);
112 ok(bytes
== sizeof(DWORD
), "Returned bytes: %u, should be 4\n", bytes
);
113 ok(value
== TRUE
, "Return value: %u, should be 1\n", value
);
115 /* Synth isn't fully initialized yet */
116 hr
= IDirectMusicSynth_Activate(dmsynth
, TRUE
);
117 todo_wine
ok(hr
== DMUS_E_NOSYNTHSINK
, "IDirectMusicSynth_Activate returned: %x\n", hr
);
119 /* Synth has no default clock */
120 hr
= IDirectMusicSynth_GetLatencyClock(dmsynth
, &clock_synth
);
121 ok(hr
== DMUS_E_NOSYNTHSINK
, "IDirectMusicSynth_GetLatencyClock returned: %x\n", hr
);
123 /* SynthSink has a default clock */
124 hr
= IDirectMusicSynthSink_GetLatencyClock(dmsynth_sink
, &clock_sink
);
125 ok(hr
== S_OK
, "IDirectMusicSynth_GetLatencyClock returned: %x\n", hr
);
126 ok(clock_sink
!= NULL
, "No clock returned\n");
127 ref_clock_sink
= get_refcount(clock_sink
);
129 /* This will Init() the SynthSink and finish initializing the Synth */
130 hr
= IDirectMusicSynth_SetSynthSink(dmsynth
, dmsynth_sink
);
131 ok(hr
== S_OK
, "IDirectMusicSynth_SetSynthSink returned: %x\n", hr
);
133 /* Check clocks are the same */
134 hr
= IDirectMusicSynth_GetLatencyClock(dmsynth
, &clock_synth
);
135 ok(hr
== S_OK
, "IDirectMusicSynth_GetLatencyClock returned: %x\n", hr
);
136 ok(clock_synth
!= NULL
, "No clock returned\n");
137 ok(clock_synth
== clock_sink
, "Synth and SynthSink clocks are not the same\n");
138 ref_clock_synth
= get_refcount(clock_synth
);
139 ok(ref_clock_synth
> ref_clock_sink
+ 1, "Latency clock refcount didn't increase\n");
142 IDirectMusicSynth_Release(control_synth
);
144 IDirectMusicSynth_Release(control_sink
);
146 IReferenceClock_Release(clock_synth
);
148 IReferenceClock_Release(clock_sink
);
150 IDirectMusicSynthSink_Release(dmsynth_sink
);
151 IDirectMusicSynth_Release(dmsynth
);
154 static void test_COM(void)
156 IDirectMusicSynth8
*dms8
= (IDirectMusicSynth8
*)0xdeadbeef;
162 /* COM aggregation */
163 hr
= CoCreateInstance(&CLSID_DirectMusicSynth
, (IUnknown
*)0xdeadbeef, CLSCTX_INPROC_SERVER
,
164 &IID_IUnknown
, (void**)&dms8
);
165 ok(hr
== CLASS_E_NOAGGREGATION
,
166 "DirectMusicSynth create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr
);
167 ok(!dms8
, "dms8 = %p\n", dms8
);
170 hr
= CoCreateInstance(&CLSID_DirectMusicSynth
, NULL
, CLSCTX_INPROC_SERVER
,
171 &IID_IDirectMusicObject
, (void**)&dms8
);
172 ok(hr
== E_NOINTERFACE
, "DirectMusicSynth create failed: %08x, expected E_NOINTERFACE\n", hr
);
174 /* Same refcount for all DirectMusicSynth interfaces */
175 hr
= CoCreateInstance(&CLSID_DirectMusicSynth
, NULL
, CLSCTX_INPROC_SERVER
,
176 &IID_IDirectMusicSynth8
, (void**)&dms8
);
177 ok(hr
== S_OK
, "DirectMusicSynth create failed: %08x, expected S_OK\n", hr
);
178 refcount
= IDirectMusicSynth8_AddRef(dms8
);
179 ok(refcount
== 2, "refcount == %u, expected 2\n", refcount
);
181 hr
= IDirectMusicSynth8_QueryInterface(dms8
, &IID_IKsControl
, (void**)&iksc
);
182 ok(hr
== S_OK
, "QueryInterface for IID_IKsControl failed: %08x\n", hr
);
183 refcount
= IKsControl_AddRef(iksc
);
184 ok(refcount
== 4, "refcount == %u, expected 4\n", refcount
);
185 IKsControl_Release(iksc
);
187 hr
= IDirectMusicSynth8_QueryInterface(dms8
, &IID_IUnknown
, (void**)&unk
);
188 ok(hr
== S_OK
, "QueryInterface for IID_IUnknown failed: %08x\n", hr
);
189 refcount
= IUnknown_AddRef(unk
);
190 ok(refcount
== 5, "refcount == %u, expected 5\n", refcount
);
191 IUnknown_Release(unk
);
193 /* Unsupported interfaces */
194 hr
= IDirectMusicSynth8_QueryInterface(dms8
, &IID_IDirectMusicSynthSink
, (void**)&unk
);
195 ok(hr
== E_NOINTERFACE
, "QueryInterface for IID_IDirectMusicSynthSink failed: %08x\n", hr
);
196 hr
= IDirectMusicSynth8_QueryInterface(dms8
, &IID_IReferenceClock
, (void**)&unk
);
197 ok(hr
== E_NOINTERFACE
, "QueryInterface for IID_IReferenceClock failed: %08x\n", hr
);
199 while (IDirectMusicSynth8_Release(dms8
));
202 static void test_COM_synthsink(void)
204 IDirectMusicSynthSink
*dmss
= (IDirectMusicSynthSink
*)0xdeadbeef;
210 /* COM aggregation */
211 hr
= CoCreateInstance(&CLSID_DirectMusicSynthSink
, (IUnknown
*)0xdeadbeef, CLSCTX_INPROC_SERVER
,
212 &IID_IUnknown
, (void**)&dmss
);
213 ok(hr
== CLASS_E_NOAGGREGATION
,
214 "DirectMusicSynthSink create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr
);
215 ok(!dmss
, "dmss = %p\n", dmss
);
218 hr
= CoCreateInstance(&CLSID_DirectMusicSynthSink
, NULL
, CLSCTX_INPROC_SERVER
,
219 &IID_IDirectMusicObject
, (void**)&dmss
);
220 ok(hr
== E_NOINTERFACE
, "DirectMusicSynthSink create failed: %08x, expected E_NOINTERFACE\n", hr
);
222 /* Same refcount for all DirectMusicSynthSink interfaces */
223 hr
= CoCreateInstance(&CLSID_DirectMusicSynthSink
, NULL
, CLSCTX_INPROC_SERVER
,
224 &IID_IDirectMusicSynthSink
, (void**)&dmss
);
225 ok(hr
== S_OK
, "DirectMusicSynthSink create failed: %08x, expected S_OK\n", hr
);
226 refcount
= IDirectMusicSynthSink_AddRef(dmss
);
227 ok(refcount
== 2, "refcount == %u, expected 2\n", refcount
);
229 hr
= IDirectMusicSynthSink_QueryInterface(dmss
, &IID_IKsControl
, (void**)&iksc
);
230 ok(hr
== S_OK
, "QueryInterface for IID_IKsControl failed: %08x\n", hr
);
231 refcount
= IKsControl_AddRef(iksc
);
232 ok(refcount
== 4, "refcount == %u, expected 4\n", refcount
);
233 IKsControl_Release(iksc
);
235 hr
= IDirectMusicSynthSink_QueryInterface(dmss
, &IID_IUnknown
, (void**)&unk
);
236 ok(hr
== S_OK
, "QueryInterface for IID_IUnknown failed: %08x\n", hr
);
237 refcount
= IUnknown_AddRef(unk
);
238 ok(refcount
== 5, "refcount == %u, expected 5\n", refcount
);
239 IUnknown_Release(unk
);
241 /* Unsupported interfaces */
242 hr
= IDirectMusicSynthSink_QueryInterface(dmss
, &IID_IReferenceClock
, (void**)&unk
);
243 ok(hr
== E_NOINTERFACE
, "QueryInterface for IID_IReferenceClock failed: %08x\n", hr
);
245 while (IDirectMusicSynthSink_Release(dmss
));
249 CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
251 if (missing_dmsynth())
253 skip("dmsynth not available\n");
259 test_COM_synthsink();