dwrite: Implement CreateFontFaceFromHdc().
[wine.git] / dlls / dmime / tests / performance.c
blobde8b76ee882dba7e7433281ddc850f1c0263ca56
1 /*
2 * Unit test suite for IDirectMusicPerformance
4 * Copyright 2010 Austin Lund
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 <stdarg.h>
24 #include <windef.h>
25 #include <initguid.h>
26 #include <wine/test.h>
27 #include <dmusici.h>
29 #include <stdio.h>
31 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
32 DEFINE_GUID(GUID_Bunk,0xFFFFFFFF,0xFFFF,0xFFFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF);
34 static HRESULT test_InitAudio(void)
36 IDirectMusicPerformance8 *idmusicperformance;
37 IDirectSound *pDirectSound;
38 IDirectMusicPort *pDirectMusicPort;
39 IDirectMusicAudioPath *pDirectMusicAudioPath;
40 HRESULT hr;
42 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL,
43 CLSCTX_INPROC_SERVER, &IID_IDirectMusicPerformance8, (LPVOID *)&idmusicperformance);
44 if (hr != S_OK) {
45 skip("Cannot create DirectMusicPerformance object (%x)\n", hr);
46 CoUninitialize();
47 return hr;
50 pDirectSound = NULL;
51 hr = IDirectMusicPerformance8_InitAudio(idmusicperformance ,NULL,
52 &pDirectSound, NULL, DMUS_APATH_SHARED_STEREOPLUSREVERB, 128, DMUS_AUDIOF_ALL, NULL);
53 if(hr != S_OK)
54 return hr;
56 pDirectMusicPort = NULL;
57 hr = IDirectMusicPerformance8_PChannelInfo(idmusicperformance, 0, &pDirectMusicPort, NULL, NULL);
58 ok(hr == S_OK, "Failed to call PChannelInfo (%x)\n", hr);
59 ok(pDirectMusicPort != NULL, "IDirectMusicPort not set\n");
60 if (hr == S_OK && pDirectMusicPort != NULL)
61 IDirectMusicPort_Release(pDirectMusicPort);
63 hr = IDirectMusicPerformance8_GetDefaultAudioPath(idmusicperformance, &pDirectMusicAudioPath);
64 ok(hr == S_OK, "Failed to call GetDefaultAudioPath (%x)\n", hr);
65 if (hr == S_OK)
66 IDirectMusicAudioPath_Release(pDirectMusicAudioPath);
68 hr = IDirectMusicPerformance8_CloseDown(idmusicperformance);
69 ok(hr == S_OK, "Failed to call CloseDown (%x)\n", hr);
71 IDirectMusicPerformance8_Release(idmusicperformance);
73 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL,
74 CLSCTX_INPROC_SERVER, &IID_IDirectMusicPerformance8,
75 (void**)&idmusicperformance);
76 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
78 hr = IDirectMusicPerformance8_InitAudio(idmusicperformance, NULL, NULL,
79 NULL, 0, 64, 0, NULL);
80 ok(hr == S_OK, "InitAudio failed: %08x\n", hr);
82 hr = IDirectMusicPerformance8_CloseDown(idmusicperformance);
83 ok(hr == S_OK, "CloseDown failed: %08x\n", hr);
85 IDirectMusicPerformance8_Release(idmusicperformance);
87 return S_OK;
90 static void test_createport(void)
92 IDirectMusicPerformance8 *perf;
93 IDirectMusic *music = NULL;
94 IDirectMusicPort *port = NULL;
95 DMUS_PORTCAPS portcaps;
96 DMUS_PORTPARAMS portparams;
97 DWORD i;
98 HRESULT hr;
100 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL,
101 CLSCTX_INPROC_SERVER, &IID_IDirectMusicPerformance8, (void**)&perf);
102 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
104 hr = IDirectMusicPerformance8_Init(perf, &music, NULL, NULL);
105 ok(hr == S_OK, "Init failed: %08x\n", hr);
106 ok(music != NULL, "Didn't get IDirectMusic pointer\n");
108 i = 0;
109 while(1){
110 portcaps.dwSize = sizeof(portcaps);
112 hr = IDirectMusic_EnumPort(music, i, &portcaps);
113 ok(hr == S_OK || hr == S_FALSE || (i == 0 && hr == E_INVALIDARG), "EnumPort failed: %08x\n", hr);
114 if(hr != S_OK)
115 break;
117 ok(portcaps.dwSize == sizeof(portcaps), "Got unexpected portcaps struct size: %08x\n", portcaps.dwSize);
118 trace("portcaps(%u).dwFlags: %08x\n", i, portcaps.dwFlags);
119 trace("portcaps(%u).guidPort: %s\n", i, wine_dbgstr_guid(&portcaps.guidPort));
120 trace("portcaps(%u).dwClass: %08x\n", i, portcaps.dwClass);
121 trace("portcaps(%u).dwType: %08x\n", i, portcaps.dwType);
122 trace("portcaps(%u).dwMemorySize: %08x\n", i, portcaps.dwMemorySize);
123 trace("portcaps(%u).dwMaxChannelGroups: %08x\n", i, portcaps.dwMaxChannelGroups);
124 trace("portcaps(%u).dwMaxVoices: %08x\n", i, portcaps.dwMaxVoices);
125 trace("portcaps(%u).dwMaxAudioChannels: %08x\n", i, portcaps.dwMaxAudioChannels);
126 trace("portcaps(%u).dwEffectFlags: %08x\n", i, portcaps.dwEffectFlags);
127 trace("portcaps(%u).wszDescription: %s\n", i, wine_dbgstr_w(portcaps.wszDescription));
129 ++i;
132 if(i == 0){
133 win_skip("No ports available, skipping tests\n");
134 return;
137 portparams.dwSize = sizeof(portparams);
139 /* dwValidParams == 0 -> S_OK, filled struct */
140 portparams.dwValidParams = 0;
141 hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth,
142 &portparams, &port, NULL);
143 ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
144 ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
146 IDirectMusicPort_Release(port);
147 port = NULL;
149 todo_wine ok(portparams.dwValidParams != 0, "portparams struct was not filled in\n");
151 /* dwValidParams != 0, invalid param -> S_FALSE, filled struct */
152 portparams.dwValidParams = DMUS_PORTPARAMS_CHANNELGROUPS;
153 portparams.dwChannelGroups = 0;
154 hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth,
155 &portparams, &port, NULL);
156 todo_wine ok(hr == S_FALSE, "CreatePort failed: %08x\n", hr);
157 ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
159 IDirectMusicPort_Release(port);
160 port = NULL;
162 ok(portparams.dwValidParams != 0, "portparams struct was not filled in\n");
164 /* dwValidParams != 0, valid params -> S_OK */
165 hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth,
166 &portparams, &port, NULL);
167 ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
168 ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
170 IDirectMusicPort_Release(port);
171 port = NULL;
173 /* GUID_NULL succeeds */
174 portparams.dwValidParams = 0;
175 hr = IDirectMusic_CreatePort(music, &GUID_NULL, &portparams, &port, NULL);
176 ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
177 ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
179 IDirectMusicPort_Release(port);
180 port = NULL;
182 todo_wine ok(portparams.dwValidParams != 0, "portparams struct was not filled in\n");
184 /* null GUID fails */
185 portparams.dwValidParams = 0;
186 hr = IDirectMusic_CreatePort(music, NULL, &portparams, &port, NULL);
187 ok(hr == E_POINTER, "CreatePort failed: %08x\n", hr);
188 ok(port == NULL, "Get IDirectMusicPort pointer? %p\n", port);
189 ok(portparams.dwValidParams == 0, "portparams struct was filled in?\n");
191 /* garbage GUID fails */
192 portparams.dwValidParams = 0;
193 hr = IDirectMusic_CreatePort(music, &GUID_Bunk, &portparams, &port, NULL);
194 ok(hr == E_NOINTERFACE, "CreatePort failed: %08x\n", hr);
195 ok(port == NULL, "Get IDirectMusicPort pointer? %p\n", port);
196 ok(portparams.dwValidParams == 0, "portparams struct was filled in?\n");
198 IDirectMusic_Release(music);
199 IDirectMusicPerformance_Release(perf);
202 static void test_COM(void)
204 IDirectMusicPerformance *dmp = (IDirectMusicPerformance*)0xdeadbeef;
205 IDirectMusicPerformance *dmp2;
206 IDirectMusicPerformance8 *dmp8;
207 ULONG refcount;
208 HRESULT hr;
210 /* COM aggregation */
211 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, (IUnknown*)&dmp, CLSCTX_INPROC_SERVER,
212 &IID_IUnknown, (void**)&dmp);
213 ok(hr == CLASS_E_NOAGGREGATION,
214 "DirectMusicPerformance create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr);
215 ok(!dmp, "dmp = %p\n", dmp);
217 /* Invalid RIID */
218 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC_SERVER,
219 &IID_IDirectMusicObject, (void**)&dmp);
220 ok(hr == E_NOINTERFACE,
221 "DirectMusicPerformance create failed: %08x, expected E_NOINTERFACE\n", hr);
223 /* Same refcount */
224 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC_SERVER,
225 &IID_IDirectMusicPerformance, (void**)&dmp);
226 ok(hr == S_OK, "DirectMusicPerformance create failed: %08x, expected S_OK\n", hr);
227 refcount = IDirectMusicPerformance_AddRef(dmp);
228 ok (refcount == 2, "refcount == %u, expected 2\n", refcount);
229 hr = IDirectMusicPerformance_QueryInterface(dmp, &IID_IDirectMusicPerformance2, (void**)&dmp2);
230 ok(hr == S_OK, "QueryInterface for IID_IDirectMusicPerformance2 failed: %08x\n", hr);
231 IDirectMusicPerformance_AddRef(dmp);
232 refcount = IDirectMusicPerformance_Release(dmp);
233 ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
234 hr = IDirectMusicPerformance_QueryInterface(dmp, &IID_IDirectMusicPerformance8, (void**)&dmp8);
235 ok(hr == S_OK, "QueryInterface for IID_IDirectMusicPerformance8 failed: %08x\n", hr);
236 refcount = IDirectMusicPerformance_Release(dmp);
237 ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
238 refcount = IDirectMusicPerformance8_Release(dmp8);
239 ok (refcount == 2, "refcount == %u, expected 2\n", refcount);
240 refcount = IDirectMusicPerformance_Release(dmp2);
241 ok (refcount == 1, "refcount == %u, expected 1\n", refcount);
242 refcount = IDirectMusicPerformance_Release(dmp);
243 ok (refcount == 0, "refcount == %u, expected 0\n", refcount);
246 START_TEST( performance )
248 HRESULT hr;
250 hr = CoInitialize(NULL);
251 if (FAILED(hr)) {
252 skip("Cannot initialize COM (%x)\n", hr);
253 return;
256 hr = test_InitAudio();
257 if (hr != S_OK) {
258 skip("InitAudio failed (%x)\n", hr);
259 return;
262 test_COM();
263 test_createport();
265 CoUninitialize();