hlink/tests: Add a trailing '\n' to an ok() call.
[wine] / dlls / winmm / tests / mci.c
1 /*
2  * Test winmm mci
3  *
4  * Copyright 2006 Jan Zerebecki
5  *           2009 Jörg Höhle
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include <stdio.h>
23 #include "windows.h"
24 #include "mmsystem.h"
25 #include "mmreg.h"
26 #include "wine/test.h"
27
28 /* The tests use the MCI's own save capability to create the tempfile.wav to play.
29  * To use a pre-existing file, write-protect it. */
30 static MCIERROR ok_saved = MCIERR_FILE_NOT_FOUND;
31
32 typedef union {
33       MCI_STATUS_PARMS    status;
34       MCI_WAVE_SET_PARMS  set;
35       MCI_WAVE_OPEN_PARMS open;
36       MCI_SEEK_PARMS      seek;
37     } MCI_PARMS_UNION;
38
39 static const char* dbg_mcierr(MCIERROR err)
40 {
41      switch (err) {
42      case 0: return "0=NOERROR";
43 #define X(label) case label: return #label ;
44      X(MCIERR_INVALID_DEVICE_ID)
45      X(MCIERR_UNRECOGNIZED_KEYWORD)
46      X(MCIERR_UNRECOGNIZED_COMMAND)
47      X(MCIERR_HARDWARE)
48      X(MCIERR_INVALID_DEVICE_NAME)
49      X(MCIERR_OUT_OF_MEMORY)
50      X(MCIERR_DEVICE_OPEN)
51      X(MCIERR_CANNOT_LOAD_DRIVER)
52      X(MCIERR_MISSING_COMMAND_STRING)
53      X(MCIERR_PARAM_OVERFLOW)
54      X(MCIERR_MISSING_STRING_ARGUMENT)
55      X(MCIERR_BAD_INTEGER)
56      X(MCIERR_PARSER_INTERNAL)
57      X(MCIERR_DRIVER_INTERNAL)
58      X(MCIERR_MISSING_PARAMETER)
59      X(MCIERR_UNSUPPORTED_FUNCTION)
60      X(MCIERR_FILE_NOT_FOUND)
61      X(MCIERR_DEVICE_NOT_READY)
62      X(MCIERR_INTERNAL)
63      X(MCIERR_DRIVER)
64      X(MCIERR_CANNOT_USE_ALL)
65      X(MCIERR_MULTIPLE)
66      X(MCIERR_EXTENSION_NOT_FOUND)
67      X(MCIERR_OUTOFRANGE)
68      X(MCIERR_FLAGS_NOT_COMPATIBLE)
69      X(MCIERR_FILE_NOT_SAVED)
70      X(MCIERR_DEVICE_TYPE_REQUIRED)
71      X(MCIERR_DEVICE_LOCKED)
72      X(MCIERR_DUPLICATE_ALIAS)
73      X(MCIERR_BAD_CONSTANT)
74      X(MCIERR_MUST_USE_SHAREABLE)
75      X(MCIERR_MISSING_DEVICE_NAME)
76      X(MCIERR_BAD_TIME_FORMAT)
77      X(MCIERR_NO_CLOSING_QUOTE)
78      X(MCIERR_DUPLICATE_FLAGS)
79      X(MCIERR_INVALID_FILE)
80      X(MCIERR_NULL_PARAMETER_BLOCK)
81      X(MCIERR_UNNAMED_RESOURCE)
82      X(MCIERR_NEW_REQUIRES_ALIAS)
83      X(MCIERR_NOTIFY_ON_AUTO_OPEN)
84      X(MCIERR_NO_ELEMENT_ALLOWED)
85      X(MCIERR_NONAPPLICABLE_FUNCTION)
86      X(MCIERR_ILLEGAL_FOR_AUTO_OPEN)
87      X(MCIERR_FILENAME_REQUIRED)
88      X(MCIERR_EXTRA_CHARACTERS)
89      X(MCIERR_DEVICE_NOT_INSTALLED)
90      X(MCIERR_GET_CD)
91      X(MCIERR_SET_CD)
92      X(MCIERR_SET_DRIVE)
93      X(MCIERR_DEVICE_LENGTH)
94      X(MCIERR_DEVICE_ORD_LENGTH)
95      X(MCIERR_NO_INTEGER)
96      X(MCIERR_WAVE_OUTPUTSINUSE)
97      X(MCIERR_WAVE_SETOUTPUTINUSE)
98      X(MCIERR_WAVE_INPUTSINUSE)
99      X(MCIERR_WAVE_SETINPUTINUSE)
100      X(MCIERR_WAVE_OUTPUTUNSPECIFIED)
101      X(MCIERR_WAVE_INPUTUNSPECIFIED)
102      X(MCIERR_WAVE_OUTPUTSUNSUITABLE)
103      X(MCIERR_WAVE_SETOUTPUTUNSUITABLE)
104      X(MCIERR_WAVE_INPUTSUNSUITABLE)
105      X(MCIERR_WAVE_SETINPUTUNSUITABLE)
106      X(MCIERR_SEQ_DIV_INCOMPATIBLE)
107      X(MCIERR_SEQ_PORT_INUSE)
108      X(MCIERR_SEQ_PORT_NONEXISTENT)
109      X(MCIERR_SEQ_PORT_MAPNODEVICE)
110      X(MCIERR_SEQ_PORT_MISCERROR)
111      X(MCIERR_SEQ_TIMER)
112      X(MCIERR_SEQ_PORTUNSPECIFIED)
113      X(MCIERR_SEQ_NOMIDIPRESENT)
114      X(MCIERR_NO_WINDOW)
115      X(MCIERR_CREATEWINDOW)
116      X(MCIERR_FILE_READ)
117      X(MCIERR_FILE_WRITE)
118      X(MCIERR_NO_IDENTITY)
119 #undef X
120      default: {
121          static char name[20]; /* Not to be called twice in a parameter list! */
122          sprintf(name, "MMSYSERR %u", err);
123          return name;
124          }
125      }
126 }
127
128 static BOOL spurious_message(LPMSG msg)
129 {
130   /* WM_DEVICECHANGE 0x0219 appears randomly */
131   if(msg->message != MM_MCINOTIFY) {
132     trace("skipping spurious message %04x\n",msg->message);
133     return TRUE;
134   }
135   return FALSE;
136 }
137
138 /* A single ok() in each code path allows to prefix this with todo_wine */
139 static void test_notification(HWND hwnd, const char* command, WPARAM type)
140 {   /* Use type 0 as meaning no message */
141     MSG msg;
142     BOOL seen;
143     do { seen = PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE); }
144     while(seen && spurious_message(&msg));
145     if(type && !seen) {
146       /* We observe transient delayed notification, mostly on native.
147        * Notification is not always present right when mciSend returns. */
148       trace("Waiting for delayed notification from %s\n", command);
149       MsgWaitForMultipleObjects(0, NULL, FALSE, 3000, QS_POSTMESSAGE);
150       seen = PeekMessageA(&msg, hwnd, MM_MCINOTIFY, MM_MCINOTIFY, PM_REMOVE);
151     }
152     if(!seen)
153         ok(type==0, "Expect message %04lx from %s\n", type, command);
154     else if(msg.hwnd != hwnd)
155         ok(msg.hwnd == hwnd, "Didn't get the handle to our test window\n");
156     else if(msg.message != MM_MCINOTIFY)
157         ok(msg.message == MM_MCINOTIFY, "got %04x instead of MM_MCINOTIFY from command %s\n", msg.message, command);
158     else ok(msg.wParam == type, "got %04lx instead of MCI_NOTIFY_xyz %04lx from command %s\n", msg.wParam, type, command);
159 }
160
161 static void test_openCloseWAVE(HWND hwnd)
162 {
163     MCIERROR err;
164     MCI_GENERIC_PARMS parm;
165     const char command_open[] = "open new type waveaudio alias mysound notify";
166     const char command_close_my[] = "close mysound notify";
167     const char command_close_all[] = "close all notify";
168     const char command_sysinfo[] = "sysinfo waveaudio quantity open";
169     char buf[1024];
170     memset(buf, 0, sizeof(buf));
171     test_notification(hwnd, "-prior to any command-", 0);
172
173     err = mciSendString("sysinfo all quantity", buf, sizeof(buf), hwnd);
174     todo_wine ok(!err,"mci %s returned %s\n", command_open, dbg_mcierr(err));
175     if(!err) trace("[MCI] with %s drivers\n", buf);
176
177     err = mciSendString("open new type waveaudio alias r shareable", buf, sizeof(buf), NULL);
178     ok(err==MCIERR_UNSUPPORTED_FUNCTION,"mci open new shareable returned %s\n", dbg_mcierr(err));
179     if(!err) {
180         err = mciSendString("close r", NULL, 0, NULL);
181         ok(!err,"mci close shareable returned %s\n", dbg_mcierr(err));
182     }
183
184     err = mciSendString(command_open, buf, sizeof(buf), hwnd);
185     ok(!err,"mci %s returned %s\n", command_open, dbg_mcierr(err));
186     ok(!strcmp(buf,"1"), "mci open deviceId: %s, expected 1\n", buf);
187     /* Wine<=1.1.33 used to ignore anything past alias XY */
188     test_notification(hwnd,"open new alias notify",MCI_NOTIFY_SUCCESSFUL);
189
190     err = mciSendString("status mysound time format", buf, sizeof(buf), hwnd);
191     ok(!err,"mci status time format returned %s\n", dbg_mcierr(err));
192     if(!err) {
193         if (PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) == LANG_ENGLISH)
194             ok(!strcmp(buf,"milliseconds"), "mci status time format: %s\n", buf);
195         else trace("locale-dependent time format: %s (ms)\n", buf);
196     }
197
198     err = mciSendString(command_close_my, NULL, 0, hwnd);
199     ok(!err,"mci %s returned %s\n", command_close_my, dbg_mcierr(err));
200     test_notification(hwnd, command_close_my, MCI_NOTIFY_SUCCESSFUL);
201     Sleep(5);
202     test_notification(hwnd, command_close_my, 0);
203
204     err = mciSendString("open no-such-file-exists.wav alias y", buf, sizeof(buf), NULL);
205     ok(err==MCIERR_FILE_NOT_FOUND,"open no-such-file.wav returned %s\n", dbg_mcierr(err));
206     if(!err) {
207         err = mciSendString("close y", NULL, 0, NULL);
208         ok(!err,"close y returned %s\n", dbg_mcierr(err));
209     }
210
211     err = mciSendString("open no-such-dir\\file.wav alias y type waveaudio", buf, sizeof(buf), NULL);
212     ok(err==MCIERR_FILE_NOT_FOUND || broken(err==MCIERR_INVALID_FILE /* Win9X */),"open no-such-dir/file.wav returned %s\n", dbg_mcierr(err));
213     if(!err) {
214         err = mciSendString("close y", NULL, 0, NULL);
215         ok(!err,"close y returned %s\n", dbg_mcierr(err));
216     }
217
218     err = mciSendString(command_close_all, NULL, 0, NULL);
219     todo_wine ok(!err,"mci %s (without buffer) returned %s\n", command_close_all, dbg_mcierr(err));
220
221     memset(buf, 0, sizeof(buf));
222     err = mciSendString(command_close_all, buf, sizeof(buf), hwnd);
223     todo_wine ok(!err,"mci %s (with output buffer) returned %s\n", command_close_all, dbg_mcierr(err));
224     ok(buf[0] == 0, "mci %s changed output buffer: %s\n", command_close_all, buf);
225     /* No notification left, everything closed already */
226     test_notification(hwnd, command_close_all, 0);
227     /* TODO test close all sends one notification per open device */
228
229     memset(buf, 0, sizeof(buf));
230     err = mciSendString(command_sysinfo, buf, sizeof(buf), NULL);
231     ok(!err,"mci %s returned %s\n", command_sysinfo, dbg_mcierr(err));
232     todo_wine ok(buf[0] == '0' && buf[1] == 0, "mci %s, expected output buffer '0', got: '%s'\n", command_sysinfo, buf);
233
234     err = mciSendString("open new type waveaudio", buf, sizeof(buf), NULL);
235     ok(err==MCIERR_NEW_REQUIRES_ALIAS,"mci open new without alias returned %s\n", dbg_mcierr(err));
236
237     err = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_WAIT, 0); /* from MSDN */
238     ok(!err,"mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, 0) returned %s\n", dbg_mcierr(err));
239
240     err = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, 0);
241     ok(!err,"mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, 0) returned %s\n", dbg_mcierr(err));
242
243     parm.dwCallback = (DWORD_PTR)hwnd;
244     err = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, (DWORD_PTR)&parm);
245     ok(!err,"mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, hwnd) returned %s\n", dbg_mcierr(err));
246     test_notification(hwnd, command_close_all, 0); /* None left */
247 }
248
249 static void test_recordWAVE(HWND hwnd)
250 {
251     WORD nch    = 1;
252     WORD nbits  = 16;
253     DWORD nsamp = 16000, expect;
254     UINT ndevs  = waveInGetNumDevs();
255     MCIERROR err, ok_pcm;
256     MCIDEVICEID wDeviceID;
257     MCI_PARMS_UNION parm;
258     char buf[1024];
259     memset(buf, 0, sizeof(buf));
260     test_notification(hwnd, "-prior to recording-", 0);
261
262     parm.open.lpstrDeviceType = "waveaudio";
263     parm.open.lpstrElementName = ""; /* "new" at the command level */
264     parm.open.lpstrAlias = "x"; /* to enable mciSendString */
265     parm.open.dwCallback = (DWORD_PTR)hwnd;
266     err = mciSendCommand(0, MCI_OPEN,
267         MCI_OPEN_ELEMENT | MCI_OPEN_TYPE | MCI_OPEN_ALIAS | MCI_NOTIFY,
268         (DWORD_PTR)&parm);
269     ok(!err,"mciCommand open new type waveaudio alias x notify: %s\n", dbg_mcierr(err));
270     wDeviceID = parm.open.wDeviceID;
271
272     /* In Wine, both MCI_Open and the individual drivers send notifications. */
273     test_notification(hwnd, "open new", MCI_NOTIFY_SUCCESSFUL);
274     todo_wine test_notification(hwnd, "open new no #2", 0);
275
276     /* Do not query time format as string because result depends on locale! */
277     parm.status.dwItem = MCI_STATUS_TIME_FORMAT;
278     err = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
279     ok(!err,"mciCommand status time format: %s\n", dbg_mcierr(err));
280     ok(parm.status.dwReturn==MCI_FORMAT_MILLISECONDS,"status time format: %ld\n",parm.status.dwReturn);
281
282     /* Info file fails until named in Open or Save. */
283     err = mciSendString("info x file", buf, sizeof(buf), NULL);
284     todo_wine ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci info new file returned %s\n", dbg_mcierr(err));
285
286     /* Check the default recording: 8-bits per sample, mono, 11kHz */
287     err = mciSendString("status x samplespersec", buf, sizeof(buf), NULL);
288     ok(!err,"mci status samplespersec returned %s\n", dbg_mcierr(err));
289     if(!err) ok(!strcmp(buf,"11025"), "mci status samplespersec expected 11025, got: %s\n", buf);
290
291     /* MCI seems to solely support PCM, no need for ACM conversion. */
292     err = mciSendString("set x format tag 2", NULL, 0, NULL);
293     ok(err==MCIERR_OUTOFRANGE,"mci set format tag 2 returned %s\n", dbg_mcierr(err));
294
295     /* MCI appears to scan the available devices for support of this format,
296      * returning MCIERR_OUTOFRANGE on machines with no sound.
297      * However some w2k8/w7 machines return no error when there's no wave
298      * input device (perhaps querying waveOutGetNumDevs instead of waveIn?),
299      * still the record command below fails with MCIERR_WAVE_INPUTSUNSUITABLE.
300      * Don't skip here, record will fail below. */
301     err = mciSendString("set x format tag pcm", NULL, 0, NULL);
302     ok(!err || err==MCIERR_OUTOFRANGE,"mci set format tag pcm returned %s\n", dbg_mcierr(err));
303     ok_pcm = err;
304
305     /* MSDN warns against not setting all wave format parameters.
306      * Indeed, it produces strange results, incl.
307      * inconsistent PCMWAVEFORMAT headers in the saved file.
308      */
309     err = mciSendString("set x bytespersec 22050 alignment 2 samplespersec 11025 channels 1 bitspersample 16", NULL, 0, NULL);
310     ok(err==ok_pcm,"mci set 5 wave parameters returned %s\n", dbg_mcierr(err));
311     /* Investigate: on w2k, set samplespersec 22050 sets nChannels to 2!
312      *  err = mciSendString("set x samplespersec 22050", NULL, 0, NULL);
313      *  ok(!err,"mci set samplespersec returned %s\n", dbg_mcierr(err));
314      */
315
316     /* Checks are generally performed immediately. */
317     err = mciSendString("set x bitspersample 4", NULL, 0, NULL);
318     todo_wine ok(err==MCIERR_OUTOFRANGE,"mci set bitspersample 4 returned %s\n", dbg_mcierr(err));
319
320     parm.set.wFormatTag = WAVE_FORMAT_PCM;
321     parm.set.nSamplesPerSec = nsamp;
322     parm.set.wBitsPerSample = nbits;
323     parm.set.nChannels      = nch;
324     parm.set.nBlockAlign    = parm.set.nChannels * parm.set.wBitsPerSample /8;
325     parm.set.nAvgBytesPerSec= parm.set.nSamplesPerSec * parm.set.nBlockAlign;
326     err = mciSendCommand(wDeviceID, MCI_SET,
327         MCI_WAVE_SET_SAMPLESPERSEC | MCI_WAVE_SET_CHANNELS |
328         MCI_WAVE_SET_BITSPERSAMPLE | MCI_WAVE_SET_BLOCKALIGN |
329         MCI_WAVE_SET_AVGBYTESPERSEC| MCI_WAVE_SET_FORMATTAG, (DWORD_PTR)&parm);
330     ok(err==ok_pcm,"mciCommand set wave format: %s\n", dbg_mcierr(err));
331
332     /* A few ME machines pass all tests except set format tag pcm! */
333     err = mciSendString("record x to 2000 wait", NULL, 0, hwnd);
334     ok(err || !ok_pcm,"can record yet set wave format pcm returned %s\n", dbg_mcierr(ok_pcm));
335     if(!ndevs) todo_wine /* with sound disabled */
336     ok(ndevs>0 ? !err : err==MCIERR_WAVE_INPUTSUNSUITABLE,"mci record to 2000 returned %s\n", dbg_mcierr(err));
337     else
338     ok(ndevs>0 ? !err : err==MCIERR_WAVE_INPUTSUNSUITABLE,"mci record to 2000 returned %s\n", dbg_mcierr(err));
339     if(err) {
340         if (err==MCIERR_WAVE_INPUTSUNSUITABLE)
341              skip("Please install audio driver. Everything is skipped.\n");
342         else skip("Cannot record cause %s. Everything is skipped.\n", dbg_mcierr(err));
343
344         err = mciSendString("close x", NULL, 0, NULL);
345         ok(!err,"mci close returned %s\n", dbg_mcierr(err));
346         test_notification(hwnd,"record skipped",0);
347         return;
348     }
349
350     /* Query some wave format parameters depending on the time format. */
351     err = mciSendString("status x position", buf, sizeof(buf), NULL);
352     ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
353     if(!err) todo_wine ok(!strcmp(buf,"2000"), "mci status position gave %s, expected 2000, some tests will fail\n", buf);
354
355     err = mciSendString("set x time format 8", NULL, 0, NULL); /* bytes */
356     ok(!err,"mci returned %s\n", dbg_mcierr(err));
357
358     parm.status.dwItem = MCI_STATUS_POSITION;
359     err = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
360     ok(!err,"mciCommand status position: %s\n", dbg_mcierr(err));
361     expect = 2 * nsamp * nch * nbits/8;
362     if(!err) todo_wine ok(parm.status.dwReturn==expect,"recorded %lu bytes, expected %u\n",parm.status.dwReturn,expect);
363
364     parm.set.dwTimeFormat = MCI_FORMAT_SAMPLES;
365     err = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)&parm);
366     ok(!err,"mciCommand set time format samples: %s\n", dbg_mcierr(err));
367
368     parm.status.dwItem = MCI_STATUS_POSITION;
369     err = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
370     ok(!err,"mciCommand status position: %s\n", dbg_mcierr(err));
371     expect = 2 * nsamp;
372     if(!err) todo_wine ok(parm.status.dwReturn==expect,"recorded %lu samples, expected %u\n",parm.status.dwReturn,expect);
373
374     err = mciSendString("set x time format milliseconds", NULL, 0, NULL);
375     ok(!err,"mci set time format milliseconds returned %s\n", dbg_mcierr(err));
376
377     err = mciSendString("save x tempfile1.wav", NULL, 0, NULL);
378     ok(!err,"mci save returned %s\n", dbg_mcierr(err));
379
380     err = mciSendString("save x tempfile.wav", NULL, 0, NULL);
381     ok(!err,"mci save returned %s\n", dbg_mcierr(err));
382     if(!err) ok_saved = 0;
383
384     /* Save must not rename the original file. */
385     if (!DeleteFile("tempfile1.wav"))
386         todo_wine ok(FALSE, "Save must not rename the original file; DeleteFile returned %d\n", GetLastError());
387
388     err = mciSendString("set x channels 2", NULL, 0, NULL);
389     ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci set channels after saving returned %s\n", dbg_mcierr(err));
390
391     parm.seek.dwTo = 600;
392     err = mciSendCommand(wDeviceID, MCI_SEEK, MCI_TO | MCI_WAIT, (DWORD_PTR)&parm);
393     ok(!err,"mciCommand seek to 600: %s\n", dbg_mcierr(err));
394
395     /* Truncate to current position */
396     err = mciSendString("delete x", NULL, 0, NULL);
397     todo_wine ok(!err,"mci delete returned %s\n", dbg_mcierr(err));
398
399     buf[0]='\0';
400     err = mciSendString("status x length", buf, sizeof(buf), NULL);
401     ok(!err,"mci status length returned %s\n", dbg_mcierr(err));
402     todo_wine ok(!strcmp(buf,"600"), "mci status length after delete gave %s, expected 600\n", buf);
403
404     err = mciSendString("close x", NULL, 0, NULL);
405     ok(!err,"mci close returned %s\n", dbg_mcierr(err));
406     test_notification(hwnd,"record complete",0);
407 }
408
409 static void test_playWAVE(HWND hwnd)
410 {
411     MCIERROR err;
412     char buf[1024];
413     memset(buf, 0, sizeof(buf));
414
415     err = mciSendString("open waveaudio!tempfile.wav alias mysound", NULL, 0, NULL);
416     ok(err==ok_saved,"mci open waveaudio!tempfile.wav returned %s\n", dbg_mcierr(err));
417     if(err) {
418         skip("Cannot open waveaudio!tempfile.wav for playing (%s), skipping\n", dbg_mcierr(err));
419         return;
420     }
421
422     err = mciSendString("status mysound length", buf, sizeof(buf), NULL);
423     ok(!err,"mci status length returned %s\n", dbg_mcierr(err));
424     todo_wine ok(!strcmp(buf,"2000"), "mci status length gave %s, expected 2000, some tests will fail.\n", buf);
425
426     err = mciSendString("cue output", NULL, 0, NULL);
427     todo_wine ok(err==MCIERR_UNRECOGNIZED_COMMAND,"mci incorrect cue output returned %s\n", dbg_mcierr(err));
428
429     /* Test MCI to the bones -- Some todo_wine from Cue and
430      * from Play from 0 to 0 are not worth fixing. */
431     err = mciSendString("cue mysound output notify", NULL, 0, hwnd);
432     ok(!err,"mci cue output after open file returned %s\n", dbg_mcierr(err));
433     /* Notification is delayed as a play thread is started. */
434     todo_wine test_notification(hwnd, "cue immediate", 0);
435
436     /* Cue pretends to put the MCI into paused state. */
437     err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
438     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
439     todo_wine ok(!strcmp(buf,"paused"), "mci status mode: %s, expected (pseudo)paused\n", buf);
440
441     /* Strange pause where Pause is rejected, unlike Play; Pause; Pause tested below */
442     err = mciSendString("pause mysound", NULL, 0, hwnd);
443     ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci pause after cue returned %s\n", dbg_mcierr(err));
444
445     /* MCI appears to start the play thread in this border case.
446      * Guessed that from (flaky) status mode and late notification arrival. */
447     err = mciSendString("play mysound from 0 to 0 notify", NULL, 0, hwnd);
448     ok(!err,"mci play from 0 to 0 returned %s\n", dbg_mcierr(err));
449     todo_wine test_notification(hwnd, "cue aborted by play", MCI_NOTIFY_ABORTED);
450     /* play's own notification follows below */
451
452     err = mciSendString("play mysound from 250 to 0", NULL, 0, NULL);
453     ok(err==MCIERR_OUTOFRANGE,"mci play from 250 to 0 returned %s\n", dbg_mcierr(err));
454
455     Sleep(50); /* Give play from 0 to 0 time to finish. */
456     todo_wine test_notification(hwnd, "play from 0 to 0", MCI_NOTIFY_SUCCESSFUL);
457
458     err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
459     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
460     ok(!strcmp(buf,"stopped"), "mci status mode: %s after play from 0 to 0\n", buf);
461
462     err = mciSendString("play MYSOUND from 250 to 0 notify", NULL, 0, hwnd);
463     ok(err==MCIERR_OUTOFRANGE,"mci play from 250 to 0 notify returned %s\n", dbg_mcierr(err));
464     /* No notification (checked below) sent if error */
465
466     /* A second play caused Wine<1.1.33 to hang */
467     err = mciSendString("play mysound from 500 to 1500 wait", NULL, 0, NULL);
468     ok(!err,"mci play from 500 to 1500 returned %s\n", dbg_mcierr(err));
469
470     memset(buf, 0, sizeof(buf));
471     err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
472     ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
473     if(!err) ok(!strcmp(buf,"1500"), "mci status position: %s\n", buf);
474
475     /* mci will not play position < current */
476     err = mciSendString("play mysound to 1000", NULL, 0, NULL);
477     ok(err==MCIERR_OUTOFRANGE,"mci play to 1000 returned %s\n", dbg_mcierr(err));
478
479     /* mci will not play to > end */
480     err = mciSendString("play mysound TO 3000 notify", NULL, 0, hwnd);
481     ok(err==MCIERR_OUTOFRANGE,"mci play to 3000 notify returned %s\n", dbg_mcierr(err));
482
483     err = mciSendString("play mysound to 2000", NULL, 0, NULL);
484     ok(!err,"mci play to 2000 returned %s\n", dbg_mcierr(err));
485
486     /* Rejected while playing */
487     err = mciSendString("cue mysound output", NULL, 0, NULL);
488     ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci cue output while playing returned %s\n", dbg_mcierr(err));
489
490     err = mciSendString("play mysound to 3000", NULL, 0, NULL);
491     ok(err==MCIERR_OUTOFRANGE,"mci play to 3000 returned %s\n", dbg_mcierr(err));
492
493     err = mciSendString("stop mysound Wait", NULL, 0, NULL);
494     ok(!err,"mci stop wait returned %s\n", dbg_mcierr(err));
495     test_notification(hwnd, "play/cue/pause/stop", 0);
496
497     err = mciSendString("Seek Mysound to 250 wait Notify", NULL, 0, hwnd);
498     ok(!err,"mci seek to 250 wait notify returned %s\n", dbg_mcierr(err));
499     test_notification(hwnd,"seek wait notify",MCI_NOTIFY_SUCCESSFUL);
500
501     memset(buf, 0, sizeof(buf));
502     err = mciSendString("status mysound position notify", buf, sizeof(buf), hwnd);
503     ok(!err,"mci status position notify returned %s\n", dbg_mcierr(err));
504     if(!err) ok(!strcmp(buf,"250"), "mci status position: %s\n", buf);
505     /* Immediate commands like status also send notifications. */
506     test_notification(hwnd,"status position",MCI_NOTIFY_SUCCESSFUL);
507
508     memset(buf, 0, sizeof(buf));
509     err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
510     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
511     ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
512
513     /* Another play from == to testcase */
514     err = mciSendString("play mysound to 250 wait notify", NULL, 0, hwnd);
515     ok(!err,"mci play (from 250) to 250 returned %s\n", dbg_mcierr(err));
516     todo_wine test_notification(hwnd,"play to 250 wait notify",MCI_NOTIFY_SUCCESSFUL);
517
518     err = mciSendString("cue mysound output", NULL, 0, NULL);
519     ok(!err,"mci cue output after play returned %s\n", dbg_mcierr(err));
520
521     err = mciSendString("close mysound", NULL, 0, NULL);
522     ok(!err,"mci close returned %s\n", dbg_mcierr(err));
523     test_notification(hwnd,"after close",0);
524 }
525
526 static void test_asyncWAVE(HWND hwnd)
527 {
528     MCIDEVICEID wDeviceID;
529     MCI_PARMS_UNION parm;
530     int err, p1, p2;
531     char buf[1024];
532     memset(buf, 0, sizeof(buf));
533
534     err = mciSendString("open tempfile.wav alias mysound notify", buf, sizeof(buf), hwnd);
535     ok(err==ok_saved,"mci open tempfile.wav returned %s\n", dbg_mcierr(err));
536     if(err) {
537         skip("Cannot open tempfile.wav for playing (%s), skipping\n", dbg_mcierr(err));
538         return;
539     }
540     ok(!strcmp(buf,"1"), "mci open deviceId: %s, expected 1\n", buf);
541     wDeviceID = atoi(buf);
542     ok(wDeviceID,"mci open DeviceID: %d\n", wDeviceID);
543     test_notification(hwnd,"open alias notify",MCI_NOTIFY_SUCCESSFUL);
544
545     err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
546     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
547     ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
548
549     err = mciSendString("play mysound notify", NULL, 0, hwnd);
550     ok(!err,"mci play returned %s\n", dbg_mcierr(err));
551
552     /* Give Wine's asynchronous thread time to start up.  Furthermore,
553      * it uses 3 buffers per second, so that the positions reported
554      * will be 333ms, 667ms etc. at best. */
555     Sleep(100); /* milliseconds */
556
557     /* Do not query time format as string because result depends on locale! */
558     parm.status.dwItem = MCI_STATUS_TIME_FORMAT;
559     err = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
560     ok(!err,"mciCommand status time format: %s\n", dbg_mcierr(err));
561     if(!err) ok(parm.status.dwReturn==MCI_FORMAT_MILLISECONDS,"status time format: %ld\n",parm.status.dwReturn);
562
563     parm.set.dwTimeFormat = MCI_FORMAT_MILLISECONDS;
564     err = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)&parm);
565     ok(!err,"mciCommand set time format ms: %s\n", dbg_mcierr(err));
566
567     buf[0]=0;
568     err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
569     ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
570     ok(strcmp(buf,"2000"), "mci status position: %s, expected 2000\n", buf);
571     trace("position after Sleep: %sms\n",buf);
572     p2 = atoi(buf);
573     /* Some machines reach 79ms only during the 100ms sleep. */
574     ok(p2>=67,"not enough time elapsed %ums\n",p2);
575     test_notification(hwnd,"play (nowait)",0);
576
577     err = mciSendString("pause mysound wait", NULL, 0, hwnd);
578     ok(!err,"mci pause wait returned %s\n", dbg_mcierr(err));
579
580     buf[0]=0;
581     err = mciSendString("status mysound mode notify", buf, sizeof(buf), hwnd);
582     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
583     if(!err) ok(!strcmp(buf,"paused"), "mci status mode: %s\n", buf);
584     test_notification(hwnd,"play",MCI_NOTIFY_SUPERSEDED);
585     test_notification(hwnd,"status",MCI_NOTIFY_SUCCESSFUL);
586
587     buf[0]=0;
588     err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
589     ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
590     trace("position while paused: %sms\n",buf);
591     p1 = atoi(buf);
592     ok(p1>=p2, "position not increasing: %u > %u\n", p2, p1);
593
594     err = mciSendString("stop mysound wait", NULL, 0, NULL);
595     ok(!err,"mci stop returned %s\n", dbg_mcierr(err));
596
597     buf[0]=0;
598     err = mciSendString("info mysound file notify", buf, sizeof(buf), hwnd);
599     ok(!err,"mci info file returned %s\n", dbg_mcierr(err));
600     if(!err) { /* fully qualified name */
601         int len = strlen(buf);
602         todo_wine ok(len>2 && buf[1]==':',"Expected full pathname from info file: %s\n", buf);
603         ok(len>=12 && !strcmp(&buf[len-12],"tempfile.wav"), "info file returned: %s\n", buf);
604     }
605     test_notification(hwnd,"info file",MCI_NOTIFY_SUCCESSFUL);
606
607     buf[0]=0;
608     err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
609     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
610     ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
611
612     buf[0]=0;
613     err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
614     ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
615     trace("position once stopped: %sms\n",buf);
616     p2 = atoi(buf);
617     /* An XP machine let the position increase slightly after pause. */
618     ok(p2>=p1 && p2<=p1+16,"position changed from %ums to %ums\n",p1,p2);
619
620     /* No Resume once stopped (waveaudio, sequencer and cdaudio differ). */
621     err = mciSendString("resume mysound wait", NULL, 0, NULL);
622     ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci resume wait returned %s\n", dbg_mcierr(err));
623
624     err = mciSendString("play mysound wait", NULL, 0, NULL);
625     ok(!err,"mci play wait returned %s\n", dbg_mcierr(err));
626
627     buf[0]=0;
628     err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
629     ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
630     todo_wine ok(!strcmp(buf,"2000"), "mci status position: %s\n", buf);
631
632     err = mciSendString("seek mysound to start wait", NULL, 0, NULL);
633     ok(!err,"mci seek to start wait returned %s\n", dbg_mcierr(err));
634
635     err = mciSendString("play mysound to 1000 notify", NULL, 0, hwnd);
636     ok(!err,"mci play returned %s\n", dbg_mcierr(err));
637
638     /* Sleep(200); not needed with Wine any more. */
639
640     err = mciSendString("pause mysound notify", NULL, 0, NULL); /* notify no callback */
641     ok(!err,"mci pause notify returned %s\n", dbg_mcierr(err));
642     /* Supersede even though pause cannot notify given no callback */
643     test_notification(hwnd,"pause aborted play #1 notification",MCI_NOTIFY_SUPERSEDED);
644     test_notification(hwnd,"impossible pause notification",0);
645
646     err = mciSendString("cue mysound output notify", NULL, 0, hwnd);
647     ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci cue output while paused returned %s\n", dbg_mcierr(err));
648     test_notification(hwnd,"cue output notify #2",0);
649
650     err = mciSendString("resume mysound notify", NULL, 0, hwnd);
651     ok(!err,"mci resume notify returned %s\n", dbg_mcierr(err));
652     test_notification(hwnd, "resume notify", MCI_NOTIFY_SUCCESSFUL);
653
654     /* Seek or even Stop used to hang Wine<1.1.32 on MacOS. */
655     err = mciSendString("seek mysound to 0 wait", NULL, 0, NULL);
656     ok(!err,"mci seek to start returned %s\n", dbg_mcierr(err));
657
658     /* Seek stops. */
659     err = mciSendString("status mysound mode", buf, sizeof(buf), NULL);
660     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
661     if(!err) ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
662
663     err = mciSendString("seek mysound wait", NULL, 0, NULL);
664     ok(err==MCIERR_MISSING_PARAMETER,"mci seek to nowhere returned %s\n", dbg_mcierr(err));
665
666     /* cdaudio does not detect to start to end as error */
667     err = mciSendString("seek mysound to start to 0", NULL, 0, NULL);
668     ok(err==MCIERR_FLAGS_NOT_COMPATIBLE,"mci seek to start to 0 returned %s\n", dbg_mcierr(err));
669
670     err = mciSendString("PLAY mysound to 1000 notify", NULL, 0, hwnd);
671     ok(!err,"mci play to 1000 notify returned %s\n", dbg_mcierr(err));
672
673     /* Sleep(200); not needed with Wine any more. */
674     /* Give it 400ms and resume will appear to complete below. */
675
676     err = mciSendString("pause mysound wait", NULL, 0, NULL);
677     ok(!err,"mci pause wait returned %s\n", dbg_mcierr(err));
678     /* Unlike sequencer and cdaudio, waveaudio's pause does not abort. */
679     test_notification(hwnd,"pause aborted play #2 notification",0);
680
681     err = mciSendString("resume mysound wait", NULL, 0, NULL);
682     ok(!err,"mci resume wait returned %s\n", dbg_mcierr(err));
683     /* Resume is a short asynchronous call, something else is playing. */
684
685     err = mciSendString("status mysound mode", buf, sizeof(buf), NULL);
686     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
687     if(!err) ok(!strcmp(buf,"playing"), "mci status mode: %s\n", buf);
688
689     /* Note extra space before alias */
690     err = mciSendString("pause  mysound wait", NULL, 0, NULL);
691     todo_wine ok(!err,"mci pause (space) wait returned %s\n", dbg_mcierr(err));
692
693     err = mciSendString("pause mysound wait", NULL, 0, NULL);
694     ok(!err,"mci pause wait returned %s\n", dbg_mcierr(err));
695
696     /* Better ask position only when paused, is it updated while playing? */
697     buf[0]='\0';
698     err = mciSendString("status mysound position", buf, sizeof(buf), NULL);
699     ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
700     /* TODO compare position < 900 */
701     ok(strcmp(buf,"1000"), "mci resume waited\n");
702     ok(strcmp(buf,"2000"), "mci resume played to end\n");
703     trace("position after resume: %sms\n",buf);
704     test_notification(hwnd,"play (aborted by pause/resume/pause)",0);
705
706     err = mciSendString("close mysound wait", NULL, 0, NULL);
707     ok(!err,"mci close wait returned %s\n", dbg_mcierr(err));
708     test_notification(hwnd,"play (aborted by close)",MCI_NOTIFY_ABORTED);
709 }
710
711 static void test_AutoOpenWAVE(HWND hwnd)
712 {
713     /* This test used(?) to cause intermittent crashes when Wine exits, after
714      * fixme:winmm:MMDRV_Exit Closing while ll-driver open
715      */
716     MCIERROR err, ok_snd = waveOutGetNumDevs() ? 0 : MCIERR_HARDWARE;
717     char buf[512], path[300], command[330];
718     memset(buf, 0, sizeof(buf)); memset(path, 0, sizeof(path));
719
720     /* Do not crash on NULL buffer pointer */
721     err = mciSendString("sysinfo waveaudio quantity open", NULL, 0, NULL);
722     ok(err==MCIERR_PARAM_OVERFLOW,"mci sysinfo without buffer returned %s\n", dbg_mcierr(err));
723
724     err = mciSendString("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL);
725     ok(!err,"mci sysinfo waveaudio quantity open returned %s\n", dbg_mcierr(err));
726     if(!err) todo_wine ok(!strcmp(buf,"0"), "sysinfo quantity open expected 0, got: %s, some more tests will fail.\n", buf);
727
728     /* Who knows why some machines pass all tests but return MCIERR_HARDWARE here? */
729     err = mciSendString("sound NoSuchSoundDefined wait", NULL, 0, NULL);
730     todo_wine ok(err==ok_snd || broken(err==MCIERR_HARDWARE),"mci sound NoSuchSoundDefined returned %s\n", dbg_mcierr(err));
731
732     err = mciSendString("sound SystemExclamation notify wait", NULL, 0, hwnd);
733     todo_wine ok(err==ok_snd || broken(err==MCIERR_HARDWARE),"mci sound SystemExclamation returned %s\n", dbg_mcierr(err));
734     test_notification(hwnd, "sound notify", err ? 0 : MCI_NOTIFY_SUCCESSFUL);
735
736     buf[0]=0;
737     err = mciSendString("sysinfo waveaudio name 1 open", buf, sizeof(buf), NULL);
738     todo_wine ok(err==MCIERR_OUTOFRANGE,"sysinfo waveaudio name 1 returned %s\n", dbg_mcierr(err));
739     if(!err) trace("sysinfo dangling open alias: %s\n", buf);
740
741     err = mciSendString("play no-such-file-exists.wav notify", buf, sizeof(buf), NULL);
742     if(err==MCIERR_FILE_NOT_FOUND) { /* a Wine detector */
743         /* Unsupported auto-open leaves the file open, preventing clean-up */
744         skip("Skipping auto-open tests in Wine\n");
745         return;
746     }
747
748     err = mciSendString("play tempfile.wav notify", buf, sizeof(buf), hwnd);
749     todo_wine ok(err==MCIERR_NOTIFY_ON_AUTO_OPEN,"mci auto-open play notify returned %s\n", dbg_mcierr(err));
750
751     if(err) /* FIXME: don't open twice yet, it confuses Wine. */
752     err = mciSendString("play tempfile.wav", buf, sizeof(buf), hwnd);
753     ok(err==ok_saved,"mci auto-open play returned %s\n", dbg_mcierr(err));
754
755     if(err==MCIERR_FILE_NOT_FOUND) {
756         skip("Cannot open tempfile.wav for auto-play, skipping\n");
757         return;
758     }
759
760     buf[0]=0;
761     err = mciSendString("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL);
762     ok(!err,"mci sysinfo waveaudio quantity after auto-open returned %s\n", dbg_mcierr(err));
763     if(!err) todo_wine ok(!strcmp(buf,"1"), "sysinfo quantity open expected 1, got: %s\n", buf);
764
765     buf[0]=0;
766     err = mciSendString("sysinfo waveaudio name 1 open", buf, sizeof(buf), NULL);
767     todo_wine ok(!err,"mci sysinfo waveaudio name after auto-open returned %s\n", dbg_mcierr(err));
768     /* This is the alias, not necessarily a file name. */
769     if(!err) ok(!strcmp(buf,"tempfile.wav"), "sysinfo name 1 open: %s\n", buf);
770
771     /* Save the full pathname to the file. */
772     err = mciSendString("info tempfile.wav file", path, sizeof(path), NULL);
773     ok(!err,"mci info tempfile.wav file returned %s\n", dbg_mcierr(err));
774     if(err) strcpy(path,"tempfile.wav");
775
776     err = mciSendString("status tempfile.wav mode", NULL, 0, hwnd);
777     ok(!err,"mci status tempfile.wav mode without buffer returned %s\n", dbg_mcierr(err));
778
779     sprintf(command,"status \"%s\" mode",path);
780     err = mciSendString(command, buf, sizeof(buf), hwnd);
781     ok(!err,"mci status \"%s\" mode returned %s\n", path, dbg_mcierr(err));
782
783     buf[0]=0;
784     err = mciSendString("status tempfile.wav mode", buf, sizeof(buf), hwnd);
785     ok(!err,"mci status tempfile.wav mode returned %s\n", dbg_mcierr(err));
786     if(!err) ok(!strcmp(buf,"playing"), "mci auto-open status mode, got: %s\n", buf);
787
788     err = mciSendString("open tempfile.wav", buf, sizeof(buf), NULL);
789     todo_wine ok(err==MCIERR_DEVICE_OPEN, "mci open from auto-open returned %s\n", dbg_mcierr(err));
790
791     /* w2k/xp and Wine differ. While the device is busy playing, it is
792      * regularly open and accessible via the filename: subsequent
793      * commands must not cause auto-open each.  In Wine, a subsequent
794      * command with notify request may cause the initial play
795      * notification to be superseded, in turn causing MCI to close the
796      * device.  I.e. MCI uses the auto-open notification for itself,
797      * that's why it's not available to the app.  On w2k/xp,
798      * subsequent commands with notify requests are returned with
799      * MCIERR_NOTIFY_ON_AUTO_OPEN and thus don't abort the original
800      * command.
801      */
802     err = mciSendString("status tempfile.wav mode notify", buf, sizeof(buf), hwnd);
803     todo_wine ok(err==MCIERR_NOTIFY_ON_AUTO_OPEN, "mci status auto-open notify returned %s\n", dbg_mcierr(err));
804     if(!err) {
805         trace("Wine style MCI auto-close upon notification\n");
806
807         /* "playing" because auto-close comes after the status call. */
808         todo_wine ok(!strcmp(buf,"playing"), "mci auto-open status mode notify, got: %s\n", buf);
809         /* fixme:winmm:MMDRV_Exit Closing while ll-driver open
810          *  is explained by failure to auto-close a device. */
811         test_notification(hwnd,"status notify",MCI_NOTIFY_SUCCESSFUL);
812         /* MCI received NOTIFY_SUPERSEDED and auto-closed the device. */
813         Sleep(16);
814         test_notification(hwnd,"auto-open",0);
815     } else if(err==MCIERR_NOTIFY_ON_AUTO_OPEN) { /* MS style */
816         trace("MS style MCI auto-open forbids notification\n");
817
818         err = mciSendString("pause tempfile.wav", NULL, 0, hwnd);
819         ok(!err,"mci auto-still-open pause returned %s\n", dbg_mcierr(err));
820
821         err = mciSendString("status tempfile.wav mode", buf, sizeof(buf), hwnd);
822         ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
823         if(!err) ok(!strcmp(buf,"paused"), "mci auto-open status mode, got: %s\n", buf);
824
825         /* Auto-close */
826         err = mciSendString("stop tempfile.wav", NULL, 0, hwnd);
827         ok(!err,"mci auto-still-open stop returned %s\n", dbg_mcierr(err));
828         Sleep(16); /* makes sysinfo quantity open below succeed */
829     }
830
831     err = mciSendString("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL);
832     ok(!err,"mci sysinfo waveaudio quantity open after close returned %s\n", dbg_mcierr(err));
833     if(!err) todo_wine ok(!strcmp(buf,"0"), "sysinfo quantity open expected 0 after auto-close, got: %s\n", buf);
834
835     /* w95-WinME (not w2k/XP) switch to C:\ after auto-playing once.  Prevent
836      * MCIERR_FILE_NOT_FOUND by using the full path name from the Info file command.
837      */
838     sprintf(command,"status \"%s\" mode wait",path);
839     err = mciSendString(command, buf, sizeof(buf), hwnd);
840     ok(!err,"mci re-auto-open status mode returned %s\n", dbg_mcierr(err));
841     if(!err) ok(!strcmp(buf,"stopped"), "mci re-auto-open status mode, got: %s\n", buf);
842
843     err = mciSendString("capability waveaudio device type", buf, sizeof(buf), hwnd);
844     ok(!err,"mci capability device type returned %s\n", dbg_mcierr(err));
845     if(!err) ok(!strcmp(buf,"waveaudio"), "mci capability device type response: %s\n", buf);
846
847     /* waveaudio forbids Pause without Play. */
848     sprintf(command,"pause \"%s\"",path);
849     err = mciSendString(command, NULL, 0, hwnd);
850     ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci auto-open pause returned %s\n", dbg_mcierr(err));
851 }
852
853 START_TEST(mci)
854 {
855     MCIERROR err;
856     HWND hwnd;
857     hwnd = CreateWindowExA(0, "static", "winmm test", WS_POPUP, 0,0,100,100,
858                            0, 0, 0, NULL);
859     test_openCloseWAVE(hwnd);
860     test_recordWAVE(hwnd);
861     test_playWAVE(hwnd);
862     test_asyncWAVE(hwnd);
863     test_AutoOpenWAVE(hwnd);
864     /* Win9X hangs when exiting with something still open. */
865     err = mciSendString("close all", NULL, 0, hwnd);
866     todo_wine ok(!err,"final close all returned %s\n", dbg_mcierr(err));
867     ok(DeleteFile("tempfile.wav")||ok_saved,"Delete tempfile.wav (cause auto-open?)\n");
868     DestroyWindow(hwnd);
869 }