dmusic: Support creating default ports with GUID_NULL.
[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
31 static inline char* debugstr_guid(CONST GUID *id)
32 {
33     static char string[39];
34     sprintf(string, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
35             id->Data1, id->Data2, id->Data3,
36             id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
37             id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );
38     return string;
39 }
40
41 static void test_dmusic(void)
42 {
43     IDirectMusic *dmusic = NULL;
44     HRESULT hr;
45     ULONG index = 0;
46     DMUS_PORTCAPS port_caps;
47     DMUS_PORTPARAMS port_params;
48     IDirectMusicPort *port = NULL;
49
50     hr = CoCreateInstance(&CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusic, (LPVOID*)&dmusic);
51     if (hr != S_OK)
52     {
53         skip("Cannot create DirectMusic object (%x)\n", hr);
54         return;
55     }
56
57     port_params.dwSize = sizeof(port_params);
58     port_params.dwValidParams = DMUS_PORTPARAMS_CHANNELGROUPS | DMUS_PORTPARAMS_AUDIOCHANNELS;
59     port_params.dwChannelGroups = 1;
60     port_params.dwAudioChannels = 2;
61
62     /* No port can be created before SetDirectSound is called */
63     hr = IDirectMusic_CreatePort(dmusic, &GUID_NULL, &port_params, &port, NULL);
64     todo_wine ok(hr == DMUS_E_DSOUND_NOT_SET, "IDirectMusic_CreatePort returned: %x\n", hr);
65
66     hr = IDirectMusic_SetDirectSound(dmusic, NULL, NULL);
67     ok(hr == S_OK, "IDirectMusic_SetDirectSound returned: %x\n", hr);
68
69     /* Test creation of default port with GUID_NULL */
70     hr = IDirectMusic_CreatePort(dmusic, &GUID_NULL, &port_params, &port, NULL);
71     ok(hr == S_OK, "IDirectMusic_CreatePort returned: %x\n", hr);
72
73     port_caps.dwSize = sizeof(port_caps);
74     while (IDirectMusic_EnumPort(dmusic, index, &port_caps) == S_OK)
75     {
76         ok(port_caps.dwSize == sizeof(port_caps), "DMUS_PORTCAPS dwSize member is wrong (%u)\n", port_caps.dwSize);
77         trace("Port %u:\n", index);
78         trace("  dwFlags            = %x\n", port_caps.dwFlags);
79         trace("  guidPort           = %s\n", debugstr_guid(&port_caps.guidPort));
80         trace("  dwClass            = %u\n", port_caps.dwClass);
81         trace("  dwType             = %u\n", port_caps.dwType);
82         trace("  dwMemorySize       = %u\n", port_caps.dwMemorySize);
83         trace("  dwMaxChannelGroups = %u\n", port_caps.dwMaxChannelGroups);
84         trace("  dwMaxVoices        = %u\n", port_caps.dwMaxVoices);
85         trace("  dwMaxAudioChannels = %u\n", port_caps.dwMaxAudioChannels);
86         trace("  dwEffectFlags      = %x\n", port_caps.dwEffectFlags);
87         trace("  wszDescription     = %s\n", wine_dbgstr_w(port_caps.wszDescription));
88         index++;
89     }
90
91     if (port)
92         IDirectMusicPort_Release(port);
93     if (dmusic)
94         IDirectMusic_Release(dmusic);
95 }
96
97 START_TEST(dmusic)
98 {
99     CoInitializeEx(NULL, COINIT_MULTITHREADED);
100
101     test_dmusic();
102
103     CoUninitialize();
104 }