msdaps: Add server side stubs for IAccessor.
[wine] / dlls / winmm / tests / midi.c
1 /*
2  * Test winmm midi
3  *
4  * Copyright 2010 Jörg Höhle
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 #include <stdio.h>
22 #include "windows.h"
23 #include "mmsystem.h"
24 #include "wine/test.h"
25
26 extern const char* mmsys_error(MMRESULT error); /* from wave.c */
27
28 /* Test in order of increasing probability to hang.
29  * On many UNIX systems, the Timidity softsynth provides
30  * MIDI sequencer services and it is not particularly robust.
31  */
32
33 #define MYCBINST 0x4CAFE5A8 /* not used with window or thread callbacks */
34 #define WHATEVER 0xFEEDF00D
35
36 static BOOL spurious_message(LPMSG msg)
37 {
38   /* WM_DEVICECHANGE 0x0219 appears randomly */
39   if(msg->message == WM_DEVICECHANGE) {
40     trace("skipping spurious message %04x\n", msg->message);
41     return TRUE;
42   }
43   return FALSE;
44 }
45
46 static UINT      cbmsg  = 0;
47 static DWORD_PTR cbval1 = WHATEVER;
48 static DWORD_PTR cbval2 = 0;
49 static DWORD_PTR cbinst = MYCBINST;
50
51 static void CALLBACK callback_func(HWAVEOUT hwo, UINT uMsg,
52                                    DWORD_PTR dwInstance,
53                                    DWORD_PTR dwParam1, DWORD_PTR dwParam2)
54 {
55     if (winetest_debug>1)
56         trace("Callback! msg=%x %lx %lx\n", uMsg, dwParam1, dwParam2);
57     cbmsg = uMsg;
58     cbval1 = dwParam1;   /* mhdr or 0 */
59     cbval2 = dwParam2;   /* always 0 */
60     cbinst = dwInstance; /* MYCBINST, see midiOut/StreamOpen */
61 }
62
63 static void test_notification(HWND hwnd, const char* command, UINT m1, DWORD_PTR p2)
64 {   /* Use message type 0 as meaning no message */
65     MSG msg;
66     if (hwnd) {
67         /* msg.wParam is hmidiout, msg.lParam is the mhdr (or 0) */
68         BOOL seen;
69         do { seen = PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE); }
70         while(seen && spurious_message(&msg));
71         if (seen) {
72             trace("Message %x, wParam=%lx, lParam=%lx from %s\n",
73                   msg.message, msg.wParam, msg.lParam, command);
74             ok(msg.hwnd==hwnd, "Didn't get the handle to our test window\n");
75             ok(msg.message==m1 && msg.lParam==p2, "bad message %x/%lx from %s, expect %x/%lx\n", msg.message, msg.lParam, command, m1, p2);
76         }
77         else ok(m1==0, "Expect message %x from %s\n", m1, command);
78     }
79     else {
80         /* FIXME: MOM_POSITIONCB and MOM_DONE are so close that a queue is needed. */
81         if (cbmsg) {
82             ok(cbmsg==m1 && cbval1==p2 && cbval2==0, "bad callback %x/%lx/%lx from %s, expect %x/%lx\n", cbmsg, cbval1, cbval2, command, m1, p2);
83             cbmsg = 0; /* Mark as read */
84             cbval1 = cbval2 = WHATEVER;
85             ok(cbinst==MYCBINST, "callback dwInstance changed to %lx\n", cbinst);
86         }
87         else ok(m1==0, "Expect callback %x from %s\n", m1, command);
88     }
89 }
90
91
92 static void test_midiIn_device(UINT udev, HWND hwnd)
93 {
94     HMIDIIN hm;
95     MMRESULT rc;
96     MIDIINCAPSA capsA;
97     MIDIHDR mhdr;
98
99     rc = midiInGetDevCapsA(udev, &capsA, sizeof(capsA));
100     ok((MIDIMAPPER==udev) ? (rc==MMSYSERR_BADDEVICEID || broken(rc==MMSYSERR_NODRIVER /*nt,w2k*/)) : rc==0,
101        "midiInGetDevCaps(dev=%d) rc=%s\n", udev, mmsys_error(rc));
102     if (!rc) {
103         /* MIDI IN capsA.dwSupport may contain garbage, absent in old MS-Windows */
104         trace("* %s: manufacturer=%d, product=%d, support=%X\n", capsA.szPname, capsA.wMid, capsA.wPid, capsA.dwSupport);
105     }
106
107     if (hwnd)
108         rc = midiInOpen(&hm, udev, (DWORD_PTR)hwnd, (DWORD_PTR)MYCBINST, CALLBACK_WINDOW);
109     else
110         rc = midiInOpen(&hm, udev, (DWORD_PTR)callback_func, (DWORD_PTR)MYCBINST, CALLBACK_FUNCTION);
111     ok((MIDIMAPPER!=udev) ? rc==0 : (rc==MMSYSERR_BADDEVICEID || broken(rc==MMSYSERR_NODRIVER /*nt,w2k*/)),
112        "midiInOpen(dev=%d) rc=%s\n", udev, mmsys_error(rc));
113     if (rc) return;
114
115     test_notification(hwnd, "midiInOpen", MIM_OPEN, 0);
116
117     mhdr.dwFlags = 0;
118     mhdr.dwUser = 0x56FA552C;
119     mhdr.dwBufferLength = 70000; /* > 64KB! */
120     mhdr.lpData = HeapAlloc(GetProcessHeap(), 0 , mhdr.dwBufferLength);
121     ok(mhdr.lpData!=NULL, "No %d bytes of memory!\n", mhdr.dwBufferLength);
122     if (mhdr.lpData) {
123         rc = midiInPrepareHeader(hm, &mhdr, sizeof(mhdr));
124         ok(!rc, "midiInPrepare rc=%s\n", mmsys_error(rc));
125         rc = midiInUnprepareHeader(hm, &mhdr, sizeof(mhdr));
126         ok(!rc, "midiInUnprepare rc=%s\n", mmsys_error(rc));
127         trace("MIDIHDR flags=%x when unsent\n", mhdr.dwFlags);
128
129         HeapFree(GetProcessHeap(), 0, mhdr.lpData);
130     }
131     ok(mhdr.dwUser==0x56FA552C, "MIDIHDR.dwUser changed to %lx\n", mhdr.dwUser);
132
133     rc = midiInReset(hm); /* Return any pending buffer */
134     ok(!rc, "midiInReset rc=%s\n", mmsys_error(rc));
135
136     rc = midiInClose(hm);
137     ok(!rc, "midiInClose rc=%s\n", mmsys_error(rc));
138     test_notification(hwnd, "midiInClose", MIM_CLOSE, 0);
139     test_notification(hwnd, "midiIn over", 0, WHATEVER);
140 }
141
142 static void test_midi_infns(HWND hwnd)
143 {
144     HMIDIIN hm;
145     MMRESULT rc;
146     UINT udev, ndevs = midiInGetNumDevs();
147
148     rc = midiInOpen(&hm, ndevs, 0, 0, CALLBACK_NULL);
149     ok(rc==MMSYSERR_BADDEVICEID, "midiInOpen udev>max rc=%s\n", mmsys_error(rc));
150     if (!rc) {
151         rc = midiInClose(hm);
152         ok(!rc, "midiInClose rc=%s\n", mmsys_error(rc));
153     }
154     if (!ndevs) {
155         trace("Found no MIDI IN device\n"); /* no skip for this common situation */
156         rc = midiInOpen(&hm, MIDIMAPPER, 0, 0, CALLBACK_NULL);
157         ok(rc==MMSYSERR_BADDEVICEID || broken(rc==MMSYSERR_NODRIVER /*nt,w2k*/), "midiInOpen MAPPER with no MIDI rc=%s\n", mmsys_error(rc));
158         if (!rc) {
159             rc = midiInClose(hm);
160             ok(!rc, "midiInClose rc=%s\n", mmsys_error(rc));
161         }
162         return;
163     }
164     trace("Found %d MIDI IN devices\n", ndevs);
165     for (udev=0; udev < ndevs; udev++) {
166         trace("** Testing device %d\n", udev);
167         test_midiIn_device(udev, hwnd);
168         Sleep(50);
169     }
170     trace("** Testing MIDI mapper\n");
171     test_midiIn_device(MIDIMAPPER, hwnd);
172 }
173
174
175 static void test_midi_mci(HWND hwnd)
176 {
177     MCIERROR err;
178     char buf[1024];
179     memset(buf, 0, sizeof(buf));
180
181     err = mciSendString("sysinfo sequencer quantity", buf, sizeof(buf), hwnd);
182     ok(!err, "mci sysinfo sequencer quantity returned %d\n", err);
183     if (!err) trace("Found %s MCI sequencer devices\n", buf);
184 }
185
186
187 static void test_midiOut_device(UINT udev, HWND hwnd)
188 {
189     HMIDIOUT hm;
190     MMRESULT rc;
191     MIDIOUTCAPSA capsA;
192     DWORD ovolume;
193     MIDIHDR mhdr;
194
195     rc = midiOutGetDevCapsA(udev, &capsA, sizeof(capsA));
196     ok(!rc, "midiOutGetDevCaps(dev=%d) rc=%s\n", udev, mmsys_error(rc));
197     if (!rc) {
198       trace("* %s: manufacturer=%d, product=%d, tech=%d, support=%X: %d voices, %d notes\n",
199             capsA.szPname, capsA.wMid, capsA.wPid, capsA.wTechnology, capsA.dwSupport, capsA.wVoices, capsA.wNotes);
200     }
201
202     if (hwnd)
203         rc = midiOutOpen(&hm, udev, (DWORD_PTR)hwnd, (DWORD_PTR)MYCBINST, CALLBACK_WINDOW);
204     else
205         rc = midiOutOpen(&hm, udev, (DWORD_PTR)callback_func, (DWORD_PTR)MYCBINST, CALLBACK_FUNCTION);
206     if (MIDIMAPPER==udev) todo_wine
207     ok(!rc, "midiOutOpen(dev=%d) rc=%s\n", udev, mmsys_error(rc));
208     else
209     ok(!rc, "midiOutOpen(dev=%d) rc=%s\n", udev, mmsys_error(rc));
210     if (rc) return;
211
212     test_notification(hwnd, "midiOutOpen", MOM_OPEN, 0);
213
214     rc = midiOutGetVolume(hm, &ovolume);
215     ok(rc==((capsA.dwSupport & MIDICAPS_VOLUME) ? MMSYSERR_NOERROR : MMSYSERR_NOTSUPPORTED), "midiOutGetVolume rc=%s\n", mmsys_error(rc));
216     /* The native mapper responds with FFFFFFFF initially,
217      * real devices with the volume GUI SW-synth settings. */
218     if (!rc) trace("Current volume %x on device %d\n", ovolume, udev);
219
220     /* Tests with midiOutSetvolume show that the midi mapper forwards
221      * the value to the real device, but Get initially always reports
222      * FFFFFFFF.  Therefore, a Get+SetVolume pair with the mapper is
223      * not adequate to restore the value prior to tests.
224      */
225     if (winetest_interactive && (capsA.dwSupport & MIDICAPS_VOLUME)) {
226         DWORD volume2 = (ovolume < 0x80000000) ? 0xC000C000 : 0x40004000;
227         rc = midiOutSetVolume(hm, volume2);
228         ok(!rc, "midiOutSetVolume rc=%s\n", mmsys_error(rc));
229         if (!rc) {
230             DWORD volume3;
231             rc = midiOutGetVolume(hm, &volume3);
232             ok(!rc, "midiOutGetVolume new rc=%s\n", mmsys_error(rc));
233             if (!rc) trace("New volume %x on device %d\n", volume3, udev);
234             todo_wine ok(volume2==volume3, "volume Set %x = Get %x\n", volume2, volume3);
235
236             rc = midiOutSetVolume(hm, ovolume);
237             ok(!rc, "midiOutSetVolume restore rc=%s\n", mmsys_error(rc));
238         }
239     }
240     rc = midiOutGetDevCapsA((UINT)hm, &capsA, sizeof(capsA));
241     ok(!rc, "midiOutGetDevCaps(dev=%d) by handle rc=%s\n", udev, mmsys_error(rc));
242     rc = midiInGetDevCapsA((UINT)hm, (LPMIDIINCAPSA)&capsA, sizeof(DWORD));
243     ok(rc==MMSYSERR_BADDEVICEID, "midiInGetDevCaps(dev=%d) by out handle rc=%s\n", udev, mmsys_error(rc));
244
245     {   DWORD e = 0x006F4893; /* velocity, note (#69 would be 440Hz) channel */
246         trace("ShortMsg type %x\n", LOBYTE(LOWORD(e)));
247         rc = midiOutShortMsg(hm, e);
248         ok(!rc, "midiOutShortMsg rc=%s\n", mmsys_error(rc));
249         if (!rc) Sleep(400); /* Hear note */
250     }
251
252     mhdr.dwFlags = 0;
253     mhdr.dwUser = 0x56FA552C;
254     mhdr.dwBufferLength = 70000; /* > 64KB! */
255     mhdr.lpData = HeapAlloc(GetProcessHeap(), 0 , mhdr.dwBufferLength);
256     ok(mhdr.lpData!=NULL, "No %d bytes of memory!\n", mhdr.dwBufferLength);
257     if (mhdr.lpData) {
258         rc = midiOutLongMsg(hm, &mhdr, sizeof(mhdr));
259         ok(rc==MIDIERR_UNPREPARED, "midiOutLongMsg unprepared rc=%s\n", mmsys_error(rc));
260         test_notification(hwnd, "midiOutLong unprepared", 0, WHATEVER);
261
262         rc = midiOutPrepareHeader(hm, &mhdr, sizeof(mhdr));
263         ok(!rc, "midiOutPrepare rc=%s\n", mmsys_error(rc));
264         rc = midiOutUnprepareHeader(hm, &mhdr, sizeof(mhdr));
265         ok(!rc, "midiOutUnprepare rc=%s\n", mmsys_error(rc));
266         trace("MIDIHDR flags=%x when unsent\n", mhdr.dwFlags);
267
268         HeapFree(GetProcessHeap(), 0, mhdr.lpData);
269     }
270     ok(mhdr.dwUser==0x56FA552C, "MIDIHDR.dwUser changed to %lx\n", mhdr.dwUser);
271
272     rc = midiOutReset(hm); /* Quiet everything */
273     ok(!rc, "midiOutReset rc=%s\n", mmsys_error(rc));
274
275     rc = midiOutClose(hm);
276     ok(!rc, "midiOutClose rc=%s\n", mmsys_error(rc));
277     test_notification(hwnd, "midiOutClose", MOM_CLOSE, 0);
278     test_notification(hwnd, "midiOut over", 0, WHATEVER);
279 }
280
281 static void test_position(HMIDISTRM hm, UINT typein, UINT typeout)
282 {
283     MMRESULT rc;
284     MMTIME mmtime;
285     mmtime.wType = typein;
286     rc = midiStreamPosition(hm, &mmtime, sizeof(MMTIME));
287     /* Ugly, but a single ok() herein enables using the todo_wine prefix */
288     ok(!rc && (mmtime.wType == typeout), "midiStreamPosition type %x converted to %x rc=%s\n", typein, mmtime.wType, mmsys_error(rc));
289     if (!rc) switch(mmtime.wType) {
290     case TIME_MS:
291         trace("Stream position %ums\n", mmtime.u.ms);
292         break;
293     case TIME_TICKS:
294         trace("Stream position %u ticks\n", mmtime.u.ticks);
295         break;
296     case TIME_MIDI:
297         trace("Stream position song pointer %u\n", mmtime.u.midi.songptrpos);
298         break;
299     }
300 }
301
302 static BYTE strmEvents[] = { /* A set of variable-sized MIDIEVENT structs */
303     0, 0, 0, 0,  0, 0, 0, 0, /* dwDeltaTime and dwStreamID */
304     0, 0, 0, MEVT_NOP | 0x40, /* with MEVT_F_CALLBACK */
305     0, 0, 0, 0,  0, 0, 0, 0, /* dwDeltaTime and dwStreamID */
306     0x93, 0x48, 0x6F, MEVT_SHORTMSG,
307 };
308
309 static void test_midiStream(UINT udev, HWND hwnd)
310 {
311     HMIDISTRM hm;
312     MMRESULT rc, rc2;
313     MIDIHDR mhdr;
314
315     if (hwnd)
316         rc = midiStreamOpen(&hm, &udev, 1, (DWORD_PTR)hwnd, (DWORD_PTR)MYCBINST, CALLBACK_WINDOW);
317     else
318         rc = midiStreamOpen(&hm, &udev, 1, (DWORD_PTR)callback_func, (DWORD_PTR)MYCBINST, CALLBACK_FUNCTION);
319     if (MIDIMAPPER==udev) todo_wine
320     ok(!rc, "midiStreamOpen(dev=%d) rc=%s\n", udev, mmsys_error(rc));
321     else
322     ok(!rc, "midiStreamOpen(dev=%d) rc=%s\n", udev, mmsys_error(rc));
323     if (rc) return;
324
325     test_notification(hwnd, "midiStreamOpen", MOM_OPEN, 0);
326
327     mhdr.dwFlags = 0;
328     mhdr.dwUser = 0x56FA552C;
329     mhdr.dwBufferLength = sizeof(strmEvents) * sizeof(strmEvents[0]);
330     mhdr.dwBytesRecorded = mhdr.dwBufferLength; /* unused? */
331     mhdr.lpData = (LPSTR)&strmEvents[0];
332     if (mhdr.lpData) {
333         rc = midiOutLongMsg((HMIDIOUT)hm, &mhdr, sizeof(mhdr));
334         ok(rc==MIDIERR_UNPREPARED, "midiOutLongMsg unprepared rc=%s\n", mmsys_error(rc));
335         test_notification(hwnd, "midiOutLong unprepared", 0, WHATEVER);
336
337         rc = midiOutPrepareHeader((HMIDIOUT)hm, &mhdr, sizeof(mhdr));
338         ok(!rc, "midiOutPrepare rc=%s\n", mmsys_error(rc));
339         ok(mhdr.dwFlags & MHDR_PREPARED, "MHDR.dwFlags when prepared %x\n", mhdr.dwFlags);
340
341         /* The device is still in paused mode and should queue the message. */
342         rc = midiStreamOut(hm, &mhdr, sizeof(mhdr));
343         ok(!rc, "midiStreamOut rc=%s\n", mmsys_error(rc));
344         rc2 = rc;
345         trace("MIDIHDR flags=%x when submitted\n", mhdr.dwFlags);
346         /* w9X/me does not set MHDR_ISSTRM when StreamOut exits,
347          * but it will be set on all systems after the job is finished. */
348
349         Sleep(90);
350         /* Wine starts playing immediately */
351       /*todo_wine test_notification(hwnd, "midiStream still paused", 0, WHATEVER);*/
352
353     /* MSDN asks to use midiStreamRestart prior to midiStreamOut()
354      * because the starting state is 'pause', but some apps seem to
355      * work with the inverse order.
356      */
357
358         rc = midiStreamRestart(hm);
359         ok(!rc, "midiStreamRestart rc=%s\n", mmsys_error(rc));
360
361         if (!rc2) while(mhdr.dwFlags & MHDR_INQUEUE) {
362             trace("async MIDI still queued\n");
363             Sleep(100);
364         } /* Checking INQUEUE is not the recommended way to wait for the end of a job, but we're testing. */
365         /* MHDR_ISSTRM is not necessarily set when midiStreamOut returns
366          * rather than when the queue is eventually processed. */
367         ok(mhdr.dwFlags & MHDR_ISSTRM, "MHDR.dwFlags %x no ISSTRM when out of queue\n", mhdr.dwFlags);
368         if (!rc2) while(!(mhdr.dwFlags & MHDR_DONE)) {
369             /* Never to be seen except perhaps on multicore */
370             trace("async MIDI still not done\n");
371             Sleep(100);
372         }
373         ok(mhdr.dwFlags & MHDR_DONE, "MHDR.dwFlags %x not DONE when out of queue\n", mhdr.dwFlags);
374         test_notification(hwnd, "midiStream callback", MOM_POSITIONCB, (DWORD)&mhdr);
375         test_notification(hwnd, "midiStreamOut", MOM_DONE, (DWORD)&mhdr);
376
377         rc = midiOutUnprepareHeader((HMIDIOUT)hm, &mhdr, sizeof(mhdr));
378         ok(!rc, "midiOutUnprepare rc=%s\n", mmsys_error(rc));
379         rc = midiOutUnprepareHeader((HMIDIOUT)hm, &mhdr, sizeof(mhdr));
380         ok(!rc, "midiOutUnprepare #2 rc=%s\n", mmsys_error(rc));
381
382         trace("MIDIHDR stream flags=%x when finished\n", mhdr.dwFlags);
383         ok(mhdr.dwFlags & MHDR_DONE, "MHDR.dwFlags when done %x\n", mhdr.dwFlags);
384
385         test_position(hm, TIME_MS,      TIME_MS);
386         test_position(hm, TIME_TICKS,   TIME_TICKS);
387         todo_wine test_position(hm, TIME_MIDI,    TIME_MIDI);
388         test_position(hm, TIME_SMPTE,   TIME_MS);
389         test_position(hm, TIME_SAMPLES, TIME_MS);
390         test_position(hm, TIME_BYTES,   TIME_MS);
391
392         Sleep(400); /* Hear note */
393
394         rc = midiStreamRestart(hm);
395         ok(!rc, "midiStreamRestart #2 rc=%s\n", mmsys_error(rc));
396
397         mhdr.dwFlags |= MHDR_ISSTRM; /* just in case */
398         /* Preset flags (e.g. MHDR_ISSTRM) do not disturb. */
399         rc = midiOutPrepareHeader((HMIDIOUT)hm, &mhdr, sizeof(mhdr));
400         ok(!rc, "midiOutPrepare used flags %x rc=%s\n", mhdr.dwFlags, mmsys_error(rc));
401         rc = midiOutUnprepareHeader((HMIDIOUT)hm, &mhdr, sizeof(mhdr));
402         ok(!rc, "midiOutUnprepare used flags %x rc=%s\n", mhdr.dwFlags, mmsys_error(rc));
403
404         rc = midiStreamRestart(hm);
405         ok(!rc, "midiStreamRestart #3 rc=%s\n", mmsys_error(rc));
406     }
407     ok(mhdr.dwUser==0x56FA552C, "MIDIHDR.dwUser changed to %lx\n", mhdr.dwUser);
408
409     rc = midiStreamStop(hm);
410     ok(!rc, "midiStreamStop rc=%s\n", mmsys_error(rc));
411
412     mhdr.dwBufferLength = 70000; /* > 64KB! */
413     mhdr.lpData = HeapAlloc(GetProcessHeap(), 0 , mhdr.dwBufferLength);
414     ok(mhdr.lpData!=NULL, "No %d bytes of memory!\n", mhdr.dwBufferLength);
415     if (mhdr.lpData) {
416         mhdr.dwFlags = 0;
417         /* PrepareHeader detects the too large buffer is for a stream. */
418         rc = midiOutPrepareHeader((HMIDIOUT)hm, &mhdr, sizeof(mhdr));
419         todo_wine ok(rc==MMSYSERR_INVALPARAM, "midiOutPrepare stream too large rc=%s\n", mmsys_error(rc));
420
421         rc = midiOutUnprepareHeader((HMIDIOUT)hm, &mhdr, sizeof(mhdr));
422         ok(!rc, "midiOutUnprepare rc=%s\n", mmsys_error(rc));
423
424         HeapFree(GetProcessHeap(), 0, mhdr.lpData);
425     }
426
427     rc = midiStreamClose(hm);
428     ok(!rc, "midiStreamClose rc=%s\n", mmsys_error(rc));
429     test_notification(hwnd, "midiStreamClose", MOM_CLOSE, 0);
430     test_notification(hwnd, "midiStream over", 0, WHATEVER);
431 }
432
433 static void test_midi_outfns(HWND hwnd)
434 {
435     HMIDIOUT hm;
436     MMRESULT rc;
437     UINT udev, ndevs = midiOutGetNumDevs();
438
439     rc = midiOutOpen(&hm, ndevs, 0, 0, CALLBACK_NULL);
440     ok(rc==MMSYSERR_BADDEVICEID, "midiOutOpen udev>max rc=%s\n", mmsys_error(rc));
441     if (!rc) {
442         rc = midiOutClose(hm);
443         ok(!rc, "midiOutClose rc=%s\n", mmsys_error(rc));
444     }
445     if (!ndevs) {
446         skip("Found no MIDI out device\n");
447         rc = midiOutOpen(&hm, MIDIMAPPER, 0, 0, CALLBACK_NULL);
448         if (rc==MIDIERR_INVALIDSETUP) todo_wine /* Wine without snd-seq */
449         ok(rc==MMSYSERR_BADDEVICEID || broken(rc==MMSYSERR_NODRIVER /*w2k*/), "midiOutOpen MAPPER with no MIDI rc=%s\n", mmsys_error(rc));
450         else
451         ok(rc==MMSYSERR_BADDEVICEID || broken(rc==MMSYSERR_NODRIVER /*w2k sound disabled*/),
452            "midiOutOpen MAPPER with no MIDI rc=%s\n", mmsys_error(rc));
453         if (!rc) {
454             rc = midiOutClose(hm);
455             ok(!rc, "midiOutClose rc=%s\n", mmsys_error(rc));
456         }
457         return;
458     }
459     trace("Found %d MIDI OUT devices\n", ndevs);
460
461     test_midi_mci(hwnd);
462
463     for (udev=0; udev < ndevs; udev++) {
464         trace("** Testing device %d\n", udev);
465         test_midiOut_device(udev, hwnd);
466         Sleep(800); /* Let the synth rest */
467         test_midiStream(udev, hwnd);
468         Sleep(800);
469     }
470     trace("** Testing MIDI mapper\n");
471     test_midiOut_device(MIDIMAPPER, hwnd);
472     Sleep(800);
473     test_midiStream(MIDIMAPPER, hwnd);
474 }
475
476 START_TEST(midi)
477 {
478     HWND hwnd;
479     if (1) /* select 1 for CALLBACK_WINDOW or 0 for CALLBACK_FUNCTION */
480     hwnd = CreateWindowExA(0, "static", "winmm midi test", WS_POPUP, 0,0,100,100,
481                            0, 0, 0, NULL);
482     test_midi_infns(hwnd);
483     test_midi_outfns(hwnd);
484     if (hwnd) DestroyWindow(hwnd);
485 }