Release 1.5.29.
[wine] / dlls / dmsynth / tests / dmsynth.c
1 /*
2  * Unit tests for dmsynth functions
3  *
4  * Copyright (C) 2012 Christian Costa
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #define COBJMACROS
22
23 #include <stdio.h>
24
25 #include "wine/test.h"
26 #include "uuids.h"
27 #include "ole2.h"
28 #include "initguid.h"
29 #include "dmusics.h"
30 #include "dmusici.h"
31 #include "dmksctrl.h"
32
33 static void test_dmsynth(void)
34 {
35     IDirectMusicSynth *dmsynth = NULL;
36     IDirectMusicSynthSink *dmsynth_sink = NULL;
37     IReferenceClock* clock_synth = NULL;
38     IReferenceClock* clock_sink = NULL;
39     IKsControl* control_synth = NULL;
40     IKsControl* control_sink = NULL;
41     HRESULT hr;
42     KSPROPERTY property;
43     ULONG value;
44     ULONG bytes;
45
46     hr = CoCreateInstance(&CLSID_DirectMusicSynth, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicSynth, (LPVOID*)&dmsynth);
47     if (hr != S_OK)
48     {
49         skip("Cannot create DirectMusicSync object (%x)\n", hr);
50         return;
51     }
52
53     hr = CoCreateInstance(&CLSID_DirectMusicSynthSink, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicSynthSink, (LPVOID*)&dmsynth_sink);
54     ok(hr == S_OK, "CoCreateInstance returned: %x\n", hr);
55
56     hr = IDirectMusicSynth_QueryInterface(dmsynth, &IID_IKsControl, (LPVOID*)&control_synth);
57     ok(hr == S_OK, "IDirectMusicSynth_QueryInterface returned: %x\n", hr);
58
59     property.Id = 0;
60     property.Flags = KSPROPERTY_TYPE_GET;
61
62     property.Set = GUID_DMUS_PROP_INSTRUMENT2;
63     hr = IKsControl_KsProperty(control_synth, &property, sizeof(property), &value, sizeof(value), &bytes);
64     ok(hr == S_OK, "IKsControl_KsProperty returned: %x\n", hr);
65     ok(bytes == sizeof(DWORD), "Returned bytes: %u, should be 4\n", bytes);
66     ok(value == TRUE, "Return value: %u, should be 1\n", value);
67     property.Set = GUID_DMUS_PROP_DLS2;
68     hr = IKsControl_KsProperty(control_synth, &property, sizeof(property), &value, sizeof(value), &bytes);
69     ok(hr == S_OK, "IKsControl_KsProperty returned: %x\n", hr);
70     ok(bytes == sizeof(DWORD), "Returned bytes: %u, should be 4\n", bytes);
71     ok(value == TRUE, "Return value: %u, should be 1\n", value);
72     property.Set = GUID_DMUS_PROP_GM_Hardware;
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 == FALSE, "Return value: %u, should be 0\n", value);
77     property.Set = GUID_DMUS_PROP_GS_Hardware;
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 == FALSE, "Return value: %u, should be 0\n", value);
82     property.Set = GUID_DMUS_PROP_XG_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
88     hr = IDirectMusicSynthSink_QueryInterface(dmsynth_sink, &IID_IKsControl, (LPVOID*)&control_sink);
89     ok(hr == S_OK, "IDirectMusicSynthSink_QueryInterface returned: %x\n", hr);
90
91     property.Set = GUID_DMUS_PROP_SinkUsesDSound;
92     hr = IKsControl_KsProperty(control_sink, &property, sizeof(property), &value, sizeof(value), &bytes);
93     ok(hr == S_OK, "IKsControl_KsProperty returned: %x\n", hr);
94     ok(bytes == sizeof(DWORD), "Returned bytes: %u, should be 4\n", bytes);
95     ok(value == TRUE, "Return value: %u, should be 1\n", value);
96
97     /* Synth has no default clock */
98     hr = IDirectMusicSynth_GetLatencyClock(dmsynth, &clock_synth);
99     ok(hr == DMUS_E_NOSYNTHSINK, "IDirectMusicSynth_GetLatencyClock returned: %x\n", hr);
100
101     /* SynthSink has a default clock */
102     hr = IDirectMusicSynthSink_GetLatencyClock(dmsynth_sink, &clock_sink);
103     ok(hr == S_OK, "IDirectMusicSynth_GetLatencyClock returned: %x\n", hr);
104     ok(clock_sink != NULL, "No clock returned\n");
105
106     /* This will set clock to Synth */
107     hr = IDirectMusicSynth_SetSynthSink(dmsynth, dmsynth_sink);
108     ok(hr == S_OK, "IDirectMusicSynth_SetSynthSink returned: %x\n", hr);
109
110     /* Check clocks are the same */
111     hr = IDirectMusicSynth_GetLatencyClock(dmsynth, &clock_synth);
112     ok(hr == S_OK, "IDirectMusicSynth_GetLatencyClock returned: %x\n", hr);
113     ok(clock_synth != NULL, "No clock returned\n");
114     ok(clock_synth == clock_sink, "Synth and SynthSink clocks are not the same\n");
115
116     if (control_synth)
117         IDirectMusicSynth_Release(control_synth);
118     if (control_sink)
119         IDirectMusicSynth_Release(control_sink);
120     if (clock_synth)
121         IReferenceClock_Release(clock_synth);
122     if (clock_sink)
123         IReferenceClock_Release(clock_sink);
124     if (dmsynth_sink)
125         IDirectMusicSynthSink_Release(dmsynth_sink);
126     IDirectMusicSynth_Release(dmsynth);
127 }
128
129 START_TEST(dmsynth)
130 {
131     CoInitializeEx(NULL, COINIT_MULTITHREADED);
132
133     test_dmsynth();
134
135     CoUninitialize();
136 }