dmusic: Implement IDirectMusicBufferImpl_PackStructured.
[wine] / dlls / dmusic / tests / dmusic.c
1 /*
2  * Unit tests for dmusic 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 "dmusici.h"
30 #include "dmksctrl.h"
31
32 static inline char* debugstr_guid(CONST GUID *id)
33 {
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;
40 }
41
42 static void test_dmusic(void)
43 {
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
51     hr = CoCreateInstance(&CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusic, (LPVOID*)&dmusic);
52     if (hr != S_OK)
53     {
54         skip("Cannot create DirectMusic object (%x)\n", hr);
55         return;
56     }
57
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;
62
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);
66
67     hr = IDirectMusic_SetDirectSound(dmusic, NULL, NULL);
68     ok(hr == S_OK, "IDirectMusic_SetDirectSound returned: %x\n", hr);
69
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);
79
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);
83
84     port_caps.dwSize = sizeof(port_caps);
85     while (IDirectMusic_EnumPort(dmusic, index, &port_caps) == S_OK)
86     {
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++;
100     }
101
102     if (port)
103         IDirectMusicPort_Release(port);
104     IDirectMusic_Release(dmusic);
105 }
106
107 static void test_dmbuffer(void)
108 {
109     IDirectMusic *dmusic;
110     IDirectMusicBuffer *dmbuffer = NULL;
111     HRESULT hr;
112     DMUS_BUFFERDESC desc;
113     GUID format;
114     DWORD size;
115
116     hr = CoCreateInstance(&CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusic, (LPVOID*)&dmusic);
117     if (hr != S_OK)
118     {
119         skip("Cannot create DirectMusic object (%x)\n", hr);
120         return;
121     }
122
123     desc.dwSize = sizeof(DMUS_BUFFERDESC);
124     desc.dwFlags = 0;
125     desc.cbBuffer = 1023;
126     memcpy(&desc.guidBufferFormat, &GUID_NULL, sizeof(GUID));
127
128     hr = IDirectMusic_CreateMusicBuffer(dmusic, &desc, &dmbuffer, NULL);
129     ok(hr == S_OK, "IDirectMusic_CreateMusicBuffer return %x\n", hr);
130
131     hr = IDirectMusicBuffer_GetBufferFormat(dmbuffer, &format);
132     ok(hr == S_OK, "IDirectMusicBuffer_GetBufferFormat returned %x\n", hr);
133     ok(IsEqualGUID(&format, &KSDATAFORMAT_SUBTYPE_MIDI), "Wrong format returned %s\n", debugstr_guid(&format));
134     hr = IDirectMusicBuffer_GetMaxBytes(dmbuffer, &size);
135     ok(hr == S_OK, "IDirectMusicBuffer_GetMaxBytes returned %x\n", hr);
136     ok(size == 1024, "Buffer size is %u instead of 1024\n", size);
137
138     hr = IDirectMusicBuffer_PackStructured(dmbuffer, 10, 0, 0);
139     ok(hr == DMUS_E_INVALID_EVENT, "IDirectMusicBuffer_PackStructured returned %x\n", hr);
140     hr = IDirectMusicBuffer_PackStructured(dmbuffer, 10, 0, 0x000090); /* note on : chan 0, note 0 & vel 0 */
141     ok(hr == S_OK, "IDirectMusicBuffer_PackStructured returned %x\n", hr);
142
143     if (dmbuffer)
144         IDirectMusicBuffer_Release(dmbuffer);
145     IDirectMusic_Release(dmusic);
146 }
147
148 START_TEST(dmusic)
149 {
150     CoInitializeEx(NULL, COINIT_MULTITHREADED);
151
152     test_dmusic();
153     test_dmbuffer();
154
155     CoUninitialize();
156 }