vbscript: Compile tests with -D__WINESRC__.
[wine.git] / dlls / dmusic / tests / dmusic.c
blob3174685f109fde8af2b0a4201811928e0cbcbd4c
1 /*
2 * Unit tests for dmusic 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
21 #define COBJMACROS
23 #include <stdio.h>
25 #include "wine/test.h"
26 #include "uuids.h"
27 #include "ole2.h"
28 #include "initguid.h"
29 #include "dmusici.h"
30 #include "dmksctrl.h"
32 static inline const char* debugstr_guid(const GUID *id)
34 static char string[39];
35 sprintf(string, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
36 id->Data1, id->Data2, id->Data3,
37 id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
38 id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );
39 return string;
42 static inline const char* debugstr_longlong(ULONGLONG ll)
44 static char string[17];
45 if (sizeof(ll) > sizeof(unsigned long) && ll >> 32)
46 sprintf(string, "%lx%08lx", (unsigned long)(ll >> 32), (unsigned long)ll);
47 else
48 sprintf(string, "%lx", (unsigned long)ll);
49 return string;
52 static void test_dmusic(void)
54 IDirectMusic *dmusic = NULL;
55 HRESULT hr;
56 ULONG index = 0;
57 DMUS_PORTCAPS port_caps;
58 DMUS_PORTPARAMS port_params;
59 IDirectMusicPort *port = NULL;
60 DMUS_CLOCKINFO clock_info;
61 GUID guid_clock;
62 IReferenceClock *clock = NULL;
64 hr = CoCreateInstance(&CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusic, (LPVOID*)&dmusic);
65 if (hr != S_OK)
67 skip("Cannot create DirectMusic object (%x)\n", hr);
68 return;
71 hr = IDirectMusic_GetMasterClock(dmusic, &guid_clock, &clock);
72 ok(hr == S_OK, "IDirectMusic_GetMasterClock returned: %x\n", hr);
73 ok(clock != NULL, "No clock returned\n");
74 trace(" guidPort = %s\n", debugstr_guid(&guid_clock));
75 if (clock)
76 IReferenceClock_Release(clock);
78 port_params.dwSize = sizeof(port_params);
79 port_params.dwValidParams = DMUS_PORTPARAMS_CHANNELGROUPS | DMUS_PORTPARAMS_AUDIOCHANNELS;
80 port_params.dwChannelGroups = 1;
81 port_params.dwAudioChannels = 2;
83 /* No port can be created before SetDirectSound is called */
84 hr = IDirectMusic_CreatePort(dmusic, &GUID_NULL, &port_params, &port, NULL);
85 todo_wine ok(hr == DMUS_E_DSOUND_NOT_SET, "IDirectMusic_CreatePort returned: %x\n", hr);
87 hr = IDirectMusic_SetDirectSound(dmusic, NULL, NULL);
88 ok(hr == S_OK, "IDirectMusic_SetDirectSound returned: %x\n", hr);
90 /* Check wrong params */
91 hr = IDirectMusic_CreatePort(dmusic, &GUID_NULL, &port_params, &port, (IUnknown*)dmusic);
92 ok(hr == CLASS_E_NOAGGREGATION, "IDirectMusic_CreatePort returned: %x\n", hr);
93 hr = IDirectMusic_CreatePort(dmusic, NULL, &port_params, &port, NULL);
94 ok(hr == E_POINTER, "IDirectMusic_CreatePort returned: %x\n", hr);
95 hr = IDirectMusic_CreatePort(dmusic, &GUID_NULL, NULL, &port, NULL);
96 ok(hr == E_INVALIDARG, "IDirectMusic_CreatePort returned: %x\n", hr);
97 hr = IDirectMusic_CreatePort(dmusic, &GUID_NULL, &port_params, NULL, NULL);
98 ok(hr == E_POINTER, "IDirectMusic_CreatePort returned: %x\n", hr);
100 /* Test creation of default port with GUID_NULL */
101 hr = IDirectMusic_CreatePort(dmusic, &GUID_NULL, &port_params, &port, NULL);
102 ok(hr == S_OK, "IDirectMusic_CreatePort returned: %x\n", hr);
104 port_caps.dwSize = sizeof(port_caps);
105 while (IDirectMusic_EnumPort(dmusic, index, &port_caps) == S_OK)
107 ok(port_caps.dwSize == sizeof(port_caps), "DMUS_PORTCAPS dwSize member is wrong (%u)\n", port_caps.dwSize);
108 trace("Port %u:\n", index);
109 trace(" dwFlags = %x\n", port_caps.dwFlags);
110 trace(" guidPort = %s\n", debugstr_guid(&port_caps.guidPort));
111 trace(" dwClass = %u\n", port_caps.dwClass);
112 trace(" dwType = %u\n", port_caps.dwType);
113 trace(" dwMemorySize = %u\n", port_caps.dwMemorySize);
114 trace(" dwMaxChannelGroups = %u\n", port_caps.dwMaxChannelGroups);
115 trace(" dwMaxVoices = %u\n", port_caps.dwMaxVoices);
116 trace(" dwMaxAudioChannels = %u\n", port_caps.dwMaxAudioChannels);
117 trace(" dwEffectFlags = %x\n", port_caps.dwEffectFlags);
118 trace(" wszDescription = %s\n", wine_dbgstr_w(port_caps.wszDescription));
119 index++;
122 index = 0;
123 clock_info.dwSize = sizeof(clock_info);
124 while (IDirectMusic_EnumMasterClock(dmusic, index, &clock_info) == S_OK)
126 ok(clock_info.dwSize == sizeof(clock_info), "DMUS_CLOCKINFO dwSize member is wrong (%u)\n", clock_info.dwSize);
127 trace("Clock %u:\n", index);
128 trace(" ctType = %u\n", clock_info.ctType);
129 trace(" guidClock = %s\n", debugstr_guid(&clock_info.guidClock));
130 trace(" wszDescription = %s\n", wine_dbgstr_w(clock_info.wszDescription));
131 index++;
134 if (port)
135 IDirectMusicPort_Release(port);
136 IDirectMusic_Release(dmusic);
139 static void test_dmbuffer(void)
141 IDirectMusic *dmusic;
142 IDirectMusicBuffer *dmbuffer = NULL;
143 HRESULT hr;
144 DMUS_BUFFERDESC desc;
145 GUID format;
146 DWORD size;
147 DWORD bytes;
148 REFERENCE_TIME time;
149 LPBYTE data;
151 hr = CoCreateInstance(&CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusic, (LPVOID*)&dmusic);
152 if (hr != S_OK)
154 skip("Cannot create DirectMusic object (%x)\n", hr);
155 return;
158 desc.dwSize = sizeof(DMUS_BUFFERDESC);
159 desc.dwFlags = 0;
160 desc.cbBuffer = 1023;
161 memcpy(&desc.guidBufferFormat, &GUID_NULL, sizeof(GUID));
163 hr = IDirectMusic_CreateMusicBuffer(dmusic, &desc, &dmbuffer, NULL);
164 ok(hr == S_OK, "IDirectMusic_CreateMusicBuffer return %x\n", hr);
166 hr = IDirectMusicBuffer_GetBufferFormat(dmbuffer, &format);
167 ok(hr == S_OK, "IDirectMusicBuffer_GetBufferFormat returned %x\n", hr);
168 ok(IsEqualGUID(&format, &KSDATAFORMAT_SUBTYPE_MIDI), "Wrong format returned %s\n", debugstr_guid(&format));
169 hr = IDirectMusicBuffer_GetMaxBytes(dmbuffer, &size);
170 ok(hr == S_OK, "IDirectMusicBuffer_GetMaxBytes returned %x\n", hr);
171 ok(size == 1024, "Buffer size is %u instead of 1024\n", size);
173 hr = IDirectMusicBuffer_GetStartTime(dmbuffer, &time);
174 ok(hr == DMUS_E_BUFFER_EMPTY, "IDirectMusicBuffer_GetStartTime returned %x\n", hr);
175 hr = IDirectMusicBuffer_SetStartTime(dmbuffer, 10);
176 ok(hr == S_OK, "IDirectMusicBuffer_GetStartTime returned %x\n", hr);
177 hr = IDirectMusicBuffer_GetStartTime(dmbuffer, &time);
178 ok(hr == DMUS_E_BUFFER_EMPTY, "IDirectMusicBuffer_GetStartTime returned %x\n", hr);
180 hr = IDirectMusicBuffer_PackStructured(dmbuffer, 20, 0, 0);
181 ok(hr == DMUS_E_INVALID_EVENT, "IDirectMusicBuffer_PackStructured returned %x\n", hr);
182 hr = IDirectMusicBuffer_PackStructured(dmbuffer, 20, 0, 0x000090); /* note on : chan 0, note 0 & vel 0 */
183 ok(hr == S_OK, "IDirectMusicBuffer_PackStructured returned %x\n", hr);
184 hr = IDirectMusicBuffer_PackStructured(dmbuffer, 30, 0, 0x000080); /* note off : chan 0, note 0 & vel 0 */
185 ok(hr == S_OK, "IDirectMusicBuffer_PackStructured returned %x\n", hr);
186 hr = IDirectMusicBuffer_GetUsedBytes(dmbuffer, &bytes);
187 ok(hr == S_OK, "IDirectMusicBuffer_GetUsedBytes returned %x\n", hr);
188 ok(bytes == 48, "Buffer size is %u instead of 48\n", bytes);
190 hr = IDirectMusicBuffer_GetStartTime(dmbuffer, &time);
191 ok(hr == S_OK, "IDirectMusicBuffer_GetStartTime returned %x\n", hr);
192 ok(time == 20, "Buffer start time is wrong\n");
193 hr = IDirectMusicBuffer_SetStartTime(dmbuffer, 40);
194 ok(hr == S_OK, "IDirectMusicBuffer_GetStartTime returned %x\n", hr);
195 hr = IDirectMusicBuffer_GetStartTime(dmbuffer, &time);
196 ok(hr == S_OK, "IDirectMusicBuffer_GetStartTime returned %x\n", hr);
197 ok(time == 40, "Buffer start time is wrong\n");
199 hr = IDirectMusicBuffer_GetRawBufferPtr(dmbuffer, &data);
200 ok(hr == S_OK, "IDirectMusicBuffer_GetRawBufferPtr returned %x\n", hr);
201 if (hr == S_OK)
203 DMUS_EVENTHEADER* header;
204 DWORD message;
206 /* Check message 1 */
207 header = (DMUS_EVENTHEADER*)data;
208 data += sizeof(DMUS_EVENTHEADER);
209 ok(header->cbEvent == 3, "cbEvent is %u instead of 3\n", header->cbEvent);
210 ok(header->dwChannelGroup == 0, "dwChannelGroup is %u instead of 0\n", header->dwChannelGroup);
211 ok(header->rtDelta == 0, "rtDelta is %s instead of 0\n", debugstr_longlong(header->rtDelta));
212 ok(header->dwFlags == DMUS_EVENT_STRUCTURED, "dwFlags is %x instead of %x\n", header->dwFlags, DMUS_EVENT_STRUCTURED);
213 message = *(DWORD*)data & 0xffffff; /* Only 3 bytes are relevant */
214 data += sizeof(DWORD);
215 ok(message == 0x000090, "Message is %0x instead of 0x000090\n", message);
217 /* Check message 2 */
218 header = (DMUS_EVENTHEADER*)data;
219 data += sizeof(DMUS_EVENTHEADER);
220 ok(header->cbEvent == 3, "cbEvent is %u instead of 3\n", header->cbEvent);
221 ok(header->dwChannelGroup == 0, "dwChannelGroup is %u instead of 0\n", header->dwChannelGroup);
222 ok(header->rtDelta == 10, "rtDelta is %s instead of 0\n", debugstr_longlong(header->rtDelta));
223 ok(header->dwFlags == DMUS_EVENT_STRUCTURED, "dwFlags is %x instead of %x\n", header->dwFlags, DMUS_EVENT_STRUCTURED);
224 message = *(DWORD*)data & 0xffffff; /* Only 3 bytes are relevant */
225 ok(message == 0x000080, "Message 2 is %0x instead of 0x000080\n", message);
228 if (dmbuffer)
229 IDirectMusicBuffer_Release(dmbuffer);
230 IDirectMusic_Release(dmusic);
233 START_TEST(dmusic)
235 CoInitializeEx(NULL, COINIT_MULTITHREADED);
237 test_dmusic();
238 test_dmbuffer();
240 CoUninitialize();