kernel32: Move GlobalMemoryStatus(Ex) to a different debug channel.
[wine.git] / dlls / dmusic / tests / dmusic.c
blobfb4b3071b69a7833d8a5b4ce2ead01d4386c6c37
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 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 void test_dmusic(void)
44 IDirectMusic *dmusic = NULL;
45 HRESULT hr;
46 ULONG index = 0;
47 DMUS_PORTCAPS port_caps;
48 DMUS_PORTPARAMS port_params;
49 IDirectMusicPort *port = NULL;
50 DMUS_CLOCKINFO clock_info;
52 hr = CoCreateInstance(&CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusic, (LPVOID*)&dmusic);
53 if (hr != S_OK)
55 skip("Cannot create DirectMusic object (%x)\n", hr);
56 return;
59 port_params.dwSize = sizeof(port_params);
60 port_params.dwValidParams = DMUS_PORTPARAMS_CHANNELGROUPS | DMUS_PORTPARAMS_AUDIOCHANNELS;
61 port_params.dwChannelGroups = 1;
62 port_params.dwAudioChannels = 2;
64 /* No port can be created before SetDirectSound is called */
65 hr = IDirectMusic_CreatePort(dmusic, &GUID_NULL, &port_params, &port, NULL);
66 todo_wine ok(hr == DMUS_E_DSOUND_NOT_SET, "IDirectMusic_CreatePort returned: %x\n", hr);
68 hr = IDirectMusic_SetDirectSound(dmusic, NULL, NULL);
69 ok(hr == S_OK, "IDirectMusic_SetDirectSound returned: %x\n", hr);
71 /* Check wrong params */
72 hr = IDirectMusic_CreatePort(dmusic, &GUID_NULL, &port_params, &port, (IUnknown*)dmusic);
73 ok(hr == CLASS_E_NOAGGREGATION, "IDirectMusic_CreatePort returned: %x\n", hr);
74 hr = IDirectMusic_CreatePort(dmusic, NULL, &port_params, &port, NULL);
75 ok(hr == E_POINTER, "IDirectMusic_CreatePort returned: %x\n", hr);
76 hr = IDirectMusic_CreatePort(dmusic, &GUID_NULL, NULL, &port, NULL);
77 ok(hr == E_INVALIDARG, "IDirectMusic_CreatePort returned: %x\n", hr);
78 hr = IDirectMusic_CreatePort(dmusic, &GUID_NULL, &port_params, NULL, NULL);
79 ok(hr == E_POINTER, "IDirectMusic_CreatePort returned: %x\n", hr);
81 /* Test creation of default port with GUID_NULL */
82 hr = IDirectMusic_CreatePort(dmusic, &GUID_NULL, &port_params, &port, NULL);
83 ok(hr == S_OK, "IDirectMusic_CreatePort returned: %x\n", hr);
85 port_caps.dwSize = sizeof(port_caps);
86 while (IDirectMusic_EnumPort(dmusic, index, &port_caps) == S_OK)
88 ok(port_caps.dwSize == sizeof(port_caps), "DMUS_PORTCAPS dwSize member is wrong (%u)\n", port_caps.dwSize);
89 trace("Port %u:\n", index);
90 trace(" dwFlags = %x\n", port_caps.dwFlags);
91 trace(" guidPort = %s\n", debugstr_guid(&port_caps.guidPort));
92 trace(" dwClass = %u\n", port_caps.dwClass);
93 trace(" dwType = %u\n", port_caps.dwType);
94 trace(" dwMemorySize = %u\n", port_caps.dwMemorySize);
95 trace(" dwMaxChannelGroups = %u\n", port_caps.dwMaxChannelGroups);
96 trace(" dwMaxVoices = %u\n", port_caps.dwMaxVoices);
97 trace(" dwMaxAudioChannels = %u\n", port_caps.dwMaxAudioChannels);
98 trace(" dwEffectFlags = %x\n", port_caps.dwEffectFlags);
99 trace(" wszDescription = %s\n", wine_dbgstr_w(port_caps.wszDescription));
100 index++;
103 index = 0;
104 clock_info.dwSize = sizeof(clock_info);
105 while (IDirectMusic_EnumMasterClock(dmusic, index, &clock_info) == S_OK)
107 ok(clock_info.dwSize == sizeof(clock_info), "DMUS_CLOCKINFO dwSize member is wrong (%u)\n", clock_info.dwSize);
108 trace("Clock %u:\n", index);
109 trace(" ctType = %u\n", clock_info.ctType);
110 trace(" guidClock = %s\n", debugstr_guid(&clock_info.guidClock));
111 trace(" wszDescription = %s\n", wine_dbgstr_w(clock_info.wszDescription));
112 index++;
115 if (port)
116 IDirectMusicPort_Release(port);
117 IDirectMusic_Release(dmusic);
120 static void test_dmbuffer(void)
122 IDirectMusic *dmusic;
123 IDirectMusicBuffer *dmbuffer = NULL;
124 HRESULT hr;
125 DMUS_BUFFERDESC desc;
126 GUID format;
127 DWORD size;
128 DWORD bytes;
129 REFERENCE_TIME time;
131 hr = CoCreateInstance(&CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusic, (LPVOID*)&dmusic);
132 if (hr != S_OK)
134 skip("Cannot create DirectMusic object (%x)\n", hr);
135 return;
138 desc.dwSize = sizeof(DMUS_BUFFERDESC);
139 desc.dwFlags = 0;
140 desc.cbBuffer = 1023;
141 memcpy(&desc.guidBufferFormat, &GUID_NULL, sizeof(GUID));
143 hr = IDirectMusic_CreateMusicBuffer(dmusic, &desc, &dmbuffer, NULL);
144 ok(hr == S_OK, "IDirectMusic_CreateMusicBuffer return %x\n", hr);
146 hr = IDirectMusicBuffer_GetBufferFormat(dmbuffer, &format);
147 ok(hr == S_OK, "IDirectMusicBuffer_GetBufferFormat returned %x\n", hr);
148 ok(IsEqualGUID(&format, &KSDATAFORMAT_SUBTYPE_MIDI), "Wrong format returned %s\n", debugstr_guid(&format));
149 hr = IDirectMusicBuffer_GetMaxBytes(dmbuffer, &size);
150 ok(hr == S_OK, "IDirectMusicBuffer_GetMaxBytes returned %x\n", hr);
151 ok(size == 1024, "Buffer size is %u instead of 1024\n", size);
153 hr = IDirectMusicBuffer_GetStartTime(dmbuffer, &time);
154 ok(hr == DMUS_E_BUFFER_EMPTY, "IDirectMusicBuffer_GetStartTime returned %x\n", hr);
155 hr = IDirectMusicBuffer_SetStartTime(dmbuffer, 10);
156 ok(hr == S_OK, "IDirectMusicBuffer_GetStartTime returned %x\n", hr);
157 hr = IDirectMusicBuffer_GetStartTime(dmbuffer, &time);
158 ok(hr == DMUS_E_BUFFER_EMPTY, "IDirectMusicBuffer_GetStartTime returned %x\n", hr);
160 hr = IDirectMusicBuffer_PackStructured(dmbuffer, 20, 0, 0);
161 ok(hr == DMUS_E_INVALID_EVENT, "IDirectMusicBuffer_PackStructured returned %x\n", hr);
162 hr = IDirectMusicBuffer_PackStructured(dmbuffer, 20, 0, 0x000090); /* note on : chan 0, note 0 & vel 0 */
163 ok(hr == S_OK, "IDirectMusicBuffer_PackStructured returned %x\n", hr);
164 hr = IDirectMusicBuffer_GetUsedBytes(dmbuffer, &bytes);
165 ok(hr == S_OK, "IDirectMusicBuffer_GetUsedBytes returned %x\n", hr);
166 ok(bytes == 24, "Buffer size is %u instead of 0\n", bytes);
168 hr = IDirectMusicBuffer_GetStartTime(dmbuffer, &time);
169 ok(hr == S_OK, "IDirectMusicBuffer_GetStartTime returned %x\n", hr);
170 ok(time == 20, "Buffer start time is wrong\n");
171 hr = IDirectMusicBuffer_SetStartTime(dmbuffer, 30);
172 ok(hr == S_OK, "IDirectMusicBuffer_GetStartTime returned %x\n", hr);
173 hr = IDirectMusicBuffer_GetStartTime(dmbuffer, &time);
174 ok(hr == S_OK, "IDirectMusicBuffer_GetStartTime returned %x\n", hr);
175 ok(time == 30, "Buffer start time is wrong\n");
177 if (dmbuffer)
178 IDirectMusicBuffer_Release(dmbuffer);
179 IDirectMusic_Release(dmusic);
182 START_TEST(dmusic)
184 CoInitializeEx(NULL, COINIT_MULTITHREADED);
186 test_dmusic();
187 test_dmbuffer();
189 CoUninitialize();