dmusic: IDirectMusicBufferImpl_GetUsedBytes.
[wine/multimedia.git] / dlls / dmusic / tests / dmusic.c
blob71e89fd82b034f638900685a1c732bac56d4985f
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;
51 hr = CoCreateInstance(&CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusic, (LPVOID*)&dmusic);
52 if (hr != S_OK)
54 skip("Cannot create DirectMusic object (%x)\n", hr);
55 return;
58 port_params.dwSize = sizeof(port_params);
59 port_params.dwValidParams = DMUS_PORTPARAMS_CHANNELGROUPS | DMUS_PORTPARAMS_AUDIOCHANNELS;
60 port_params.dwChannelGroups = 1;
61 port_params.dwAudioChannels = 2;
63 /* No port can be created before SetDirectSound is called */
64 hr = IDirectMusic_CreatePort(dmusic, &GUID_NULL, &port_params, &port, NULL);
65 todo_wine ok(hr == DMUS_E_DSOUND_NOT_SET, "IDirectMusic_CreatePort returned: %x\n", hr);
67 hr = IDirectMusic_SetDirectSound(dmusic, NULL, NULL);
68 ok(hr == S_OK, "IDirectMusic_SetDirectSound returned: %x\n", hr);
70 /* Check wrong params */
71 hr = IDirectMusic_CreatePort(dmusic, &GUID_NULL, &port_params, &port, (IUnknown*)dmusic);
72 ok(hr == CLASS_E_NOAGGREGATION, "IDirectMusic_CreatePort returned: %x\n", hr);
73 hr = IDirectMusic_CreatePort(dmusic, NULL, &port_params, &port, NULL);
74 ok(hr == E_POINTER, "IDirectMusic_CreatePort returned: %x\n", hr);
75 hr = IDirectMusic_CreatePort(dmusic, &GUID_NULL, NULL, &port, NULL);
76 ok(hr == E_INVALIDARG, "IDirectMusic_CreatePort returned: %x\n", hr);
77 hr = IDirectMusic_CreatePort(dmusic, &GUID_NULL, &port_params, NULL, NULL);
78 ok(hr == E_POINTER, "IDirectMusic_CreatePort returned: %x\n", hr);
80 /* Test creation of default port with GUID_NULL */
81 hr = IDirectMusic_CreatePort(dmusic, &GUID_NULL, &port_params, &port, NULL);
82 ok(hr == S_OK, "IDirectMusic_CreatePort returned: %x\n", hr);
84 port_caps.dwSize = sizeof(port_caps);
85 while (IDirectMusic_EnumPort(dmusic, index, &port_caps) == S_OK)
87 ok(port_caps.dwSize == sizeof(port_caps), "DMUS_PORTCAPS dwSize member is wrong (%u)\n", port_caps.dwSize);
88 trace("Port %u:\n", index);
89 trace(" dwFlags = %x\n", port_caps.dwFlags);
90 trace(" guidPort = %s\n", debugstr_guid(&port_caps.guidPort));
91 trace(" dwClass = %u\n", port_caps.dwClass);
92 trace(" dwType = %u\n", port_caps.dwType);
93 trace(" dwMemorySize = %u\n", port_caps.dwMemorySize);
94 trace(" dwMaxChannelGroups = %u\n", port_caps.dwMaxChannelGroups);
95 trace(" dwMaxVoices = %u\n", port_caps.dwMaxVoices);
96 trace(" dwMaxAudioChannels = %u\n", port_caps.dwMaxAudioChannels);
97 trace(" dwEffectFlags = %x\n", port_caps.dwEffectFlags);
98 trace(" wszDescription = %s\n", wine_dbgstr_w(port_caps.wszDescription));
99 index++;
102 if (port)
103 IDirectMusicPort_Release(port);
104 IDirectMusic_Release(dmusic);
107 static void test_dmbuffer(void)
109 IDirectMusic *dmusic;
110 IDirectMusicBuffer *dmbuffer = NULL;
111 HRESULT hr;
112 DMUS_BUFFERDESC desc;
113 GUID format;
114 DWORD size;
115 DWORD bytes;
117 hr = CoCreateInstance(&CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusic, (LPVOID*)&dmusic);
118 if (hr != S_OK)
120 skip("Cannot create DirectMusic object (%x)\n", hr);
121 return;
124 desc.dwSize = sizeof(DMUS_BUFFERDESC);
125 desc.dwFlags = 0;
126 desc.cbBuffer = 1023;
127 memcpy(&desc.guidBufferFormat, &GUID_NULL, sizeof(GUID));
129 hr = IDirectMusic_CreateMusicBuffer(dmusic, &desc, &dmbuffer, NULL);
130 ok(hr == S_OK, "IDirectMusic_CreateMusicBuffer return %x\n", hr);
132 hr = IDirectMusicBuffer_GetBufferFormat(dmbuffer, &format);
133 ok(hr == S_OK, "IDirectMusicBuffer_GetBufferFormat returned %x\n", hr);
134 ok(IsEqualGUID(&format, &KSDATAFORMAT_SUBTYPE_MIDI), "Wrong format returned %s\n", debugstr_guid(&format));
135 hr = IDirectMusicBuffer_GetMaxBytes(dmbuffer, &size);
136 ok(hr == S_OK, "IDirectMusicBuffer_GetMaxBytes returned %x\n", hr);
137 ok(size == 1024, "Buffer size is %u instead of 1024\n", size);
139 hr = IDirectMusicBuffer_PackStructured(dmbuffer, 10, 0, 0);
140 ok(hr == DMUS_E_INVALID_EVENT, "IDirectMusicBuffer_PackStructured returned %x\n", hr);
141 hr = IDirectMusicBuffer_PackStructured(dmbuffer, 10, 0, 0x000090); /* note on : chan 0, note 0 & vel 0 */
142 ok(hr == S_OK, "IDirectMusicBuffer_PackStructured returned %x\n", hr);
143 hr = IDirectMusicBuffer_GetUsedBytes(dmbuffer, &bytes);
144 ok(hr == S_OK, "IDirectMusicBuffer_GetUsedBytes returned %x\n", hr);
145 ok(bytes == 24, "Buffer size is %u instead of 0\n", bytes);
147 if (dmbuffer)
148 IDirectMusicBuffer_Release(dmbuffer);
149 IDirectMusic_Release(dmusic);
152 START_TEST(dmusic)
154 CoInitializeEx(NULL, COINIT_MULTITHREADED);
156 test_dmusic();
157 test_dmbuffer();
159 CoUninitialize();