rsaenh: Fix padding bytes check for 0-byte payload.
[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 static void test_notification(HWND hwnd, const char* command, WPARAM type)
139 {   /* Use type 0 as meaning no message */
140     MSG msg;
141     BOOL seen;
142     do { seen = PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE); }
143     while(seen && spurious_message(&msg));
144     if(type==0)
145         ok(!seen, "Expect no message from command %s\n", command);
146     else
147         ok(seen, "PeekMessage should succeed for command %s\n", command);
148     if(seen) {
149         ok(msg.hwnd == hwnd, "Didn't get the handle to our test window\n");
150         ok(msg.message == MM_MCINOTIFY, "got %04x instead of MM_MCINOTIFY from command %s\n", msg.message, command);
151         ok(msg.wParam == type, "got %04lx instead of MCI_NOTIFY_xyz %04lx from command %s\n", msg.wParam, type, command);
152     }
153 }
154 static void test_notification1(HWND hwnd, const char* command, WPARAM type)
155 {   /* This version works with todo_wine prefix. */
156     MSG msg;
157     BOOL seen;
158     do { seen = PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE); }
159     while(seen && spurious_message(&msg));
160     if(type==0)
161         ok(!seen, "Expect no message from command %s\n", command);
162     else if(seen)
163       ok(msg.message == MM_MCINOTIFY && msg.wParam == type,"got %04lx instead of MCI_NOTIFY_xyz %04lx from command %s\n", msg.wParam, type, command);
164     else ok(seen, "PeekMessage should succeed for command %s\n", command);
165 }
166
167 static void test_openCloseWAVE(HWND hwnd)
168 {
169     MCIERROR err;
170     MCI_GENERIC_PARMS parm;
171     const char command_open[] = "open new type waveaudio alias mysound notify";
172     const char command_close_my[] = "close mysound notify";
173     const char command_close_all[] = "close all notify";
174     const char command_sysinfo[] = "sysinfo waveaudio quantity open";
175     char buf[1024];
176     memset(buf, 0, sizeof(buf));
177     test_notification(hwnd, "-prior to any command-", 0);
178
179     err = mciSendString("sysinfo all quantity", buf, sizeof(buf), hwnd);
180     todo_wine ok(!err,"mci %s returned %s\n", command_open, dbg_mcierr(err));
181     if(!err) trace("[MCI] with %s drivers\n", buf);
182
183     err = mciSendString("open new type waveaudio alias r shareable", buf, sizeof(buf), NULL);
184     ok(err==MCIERR_UNSUPPORTED_FUNCTION,"mci open new shareable returned %s\n", dbg_mcierr(err));
185     if(!err) {
186         err = mciSendString("close r", NULL, 0, NULL);
187         ok(!err,"mci close shareable returned %s\n", dbg_mcierr(err));
188     }
189
190     err = mciSendString(command_open, buf, sizeof(buf), hwnd);
191     ok(!err,"mci %s returned %s\n", command_open, dbg_mcierr(err));
192     ok(!strcmp(buf,"1"), "mci open deviceId: %s, expected 1\n", buf);
193     /* Wine<=1.1.33 used to ignore anything past alias XY */
194     test_notification(hwnd,"open new alias notify",MCI_NOTIFY_SUCCESSFUL);
195
196     err = mciSendString("status mysound time format", buf, sizeof(buf), hwnd);
197     ok(!err,"mci status time format returned %s\n", dbg_mcierr(err));
198     if(!err) {
199         if (PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) == LANG_ENGLISH)
200             ok(!strcmp(buf,"milliseconds"), "mci status time format: %s\n", buf);
201         else trace("locale-dependent time format: %s (ms)\n", buf);
202     }
203
204     err = mciSendString(command_close_my, NULL, 0, hwnd);
205     ok(!err,"mci %s returned %s\n", command_close_my, dbg_mcierr(err));
206     test_notification(hwnd, command_close_my, MCI_NOTIFY_SUCCESSFUL);
207     Sleep(5);
208     test_notification(hwnd, command_close_my, 0);
209
210     err = mciSendString("open no-such-file-exists.wav alias y", buf, sizeof(buf), NULL);
211     ok(err==MCIERR_FILE_NOT_FOUND,"open no-such-file.wav returned %s\n", dbg_mcierr(err));
212     if(!err) {
213         err = mciSendString("close y", NULL, 0, NULL);
214         ok(!err,"close y returned %s\n", dbg_mcierr(err));
215     }
216
217     err = mciSendString("open no-such-dir\\file.wav alias y type waveaudio", buf, sizeof(buf), NULL);
218     ok(err==MCIERR_FILE_NOT_FOUND || broken(err==MCIERR_INVALID_FILE /* Win9X */),"open no-such-dir/file.wav returned %s\n", dbg_mcierr(err));
219     if(!err) {
220         err = mciSendString("close y", NULL, 0, NULL);
221         ok(!err,"close y returned %s\n", dbg_mcierr(err));
222     }
223
224     err = mciSendString(command_close_all, NULL, 0, NULL);
225     todo_wine ok(!err,"mci %s (without buffer) returned %s\n", command_close_all, dbg_mcierr(err));
226
227     memset(buf, 0, sizeof(buf));
228     err = mciSendString(command_close_all, buf, sizeof(buf), hwnd);
229     todo_wine ok(!err,"mci %s (with output buffer) returned %s\n", command_close_all, dbg_mcierr(err));
230     ok(buf[0] == 0, "mci %s changed output buffer: %s\n", command_close_all, buf);
231     /* No notification left, everything closed already */
232     test_notification(hwnd, command_close_all, 0);
233     /* TODO test close all sends one notification per open device */
234
235     memset(buf, 0, sizeof(buf));
236     err = mciSendString(command_sysinfo, buf, sizeof(buf), NULL);
237     ok(!err,"mci %s returned %s\n", command_sysinfo, dbg_mcierr(err));
238     todo_wine ok(buf[0] == '0' && buf[1] == 0, "mci %s, expected output buffer '0', got: '%s'\n", command_sysinfo, buf);
239
240     err = mciSendString("open new type waveaudio", buf, sizeof(buf), NULL);
241     ok(err==MCIERR_NEW_REQUIRES_ALIAS,"mci open new without alias returned %s\n", dbg_mcierr(err));
242
243     err = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_WAIT, 0); /* from MSDN */
244     ok(!err,"mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, 0) returned %s\n", dbg_mcierr(err));
245
246     err = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, 0);
247     ok(!err,"mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, 0) returned %s\n", dbg_mcierr(err));
248
249     parm.dwCallback = (DWORD_PTR)hwnd;
250     err = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, (DWORD_PTR)&parm);
251     ok(!err,"mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, hwnd) returned %s\n", dbg_mcierr(err));
252     test_notification(hwnd, command_close_all, 0); /* None left */
253 }
254
255 static void test_recordWAVE(HWND hwnd)
256 {
257     WORD nch    = 1;
258     WORD nbits  = 16;
259     DWORD nsamp = 16000, expect;
260     MCIERROR err, ok_pcm;
261     MCIDEVICEID wDeviceID;
262     MCI_PARMS_UNION parm;
263     char buf[1024];
264     memset(buf, 0, sizeof(buf));
265     test_notification(hwnd, "-prior to recording-", 0);
266
267     parm.open.lpstrDeviceType = "waveaudio";
268     parm.open.lpstrElementName = ""; /* "new" at the command level */
269     parm.open.lpstrAlias = "x"; /* to enable mciSendString */
270     parm.open.dwCallback = (DWORD_PTR)hwnd;
271     err = mciSendCommand(0, MCI_OPEN,
272         MCI_OPEN_ELEMENT | MCI_OPEN_TYPE | MCI_OPEN_ALIAS | MCI_NOTIFY,
273         (DWORD_PTR)&parm);
274     ok(!err,"mciCommand open new type waveaudio alias x notify: %s\n", dbg_mcierr(err));
275     wDeviceID = parm.open.wDeviceID;
276
277     /* In Wine, both MCI_Open and the individual drivers send notifications. */
278     test_notification(hwnd, "open new", MCI_NOTIFY_SUCCESSFUL);
279     todo_wine test_notification1(hwnd, "open new no #2", 0);
280
281     /* Do not query time format as string because result depends on locale! */
282     parm.status.dwItem = MCI_STATUS_TIME_FORMAT;
283     err = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
284     ok(!err,"mciCommand status time format: %s\n", dbg_mcierr(err));
285     ok(parm.status.dwReturn==MCI_FORMAT_MILLISECONDS,"status time format: %ld\n",parm.status.dwReturn);
286
287     /* Info file fails until named in Open or Save. */
288     err = mciSendString("info x file", buf, sizeof(buf), NULL);
289     todo_wine ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci info new file returned %s\n", dbg_mcierr(err));
290
291     /* Check the default recording: 8-bits per sample, mono, 11kHz */
292     err = mciSendString("status x samplespersec", buf, sizeof(buf), NULL);
293     ok(!err,"mci status samplespersec returned %s\n", dbg_mcierr(err));
294     if(!err) ok(!strcmp(buf,"11025"), "mci status samplespersec expected 11025, got: %s\n", buf);
295
296     /* MCI seems to solely support PCM, no need for ACM conversion. */
297     err = mciSendString("set x format tag 2", NULL, 0, NULL);
298     ok(err==MCIERR_OUTOFRANGE,"mci set format tag 2 returned %s\n", dbg_mcierr(err));
299
300     /* MCI appears to scan the available devices for support of this format,
301      * returning MCIERR_OUTOFRANGE on machines with no sound.
302      * Don't skip here, record will fail below. */
303     err = mciSendString("set x format tag pcm", NULL, 0, NULL);
304     ok(!err || err==MCIERR_OUTOFRANGE,"mci set format tag pcm returned %s\n", dbg_mcierr(err));
305     ok_pcm = err;
306
307     err = mciSendString("set x samplespersec 41000 alignment 4 channels 2", NULL, 0, NULL);
308     ok(err==ok_pcm,"mci set samples+align+channels returned %s\n", dbg_mcierr(err));
309
310     /* Investigate: on w2k, set samplespersec 22050 sets nChannels to 2!
311      *  err = mciSendString("set x samplespersec 22050", NULL, 0, NULL);
312      *  ok(!err,"mci set samplespersec returned %s\n", dbg_mcierr(err));
313      */
314
315     parm.set.wFormatTag = WAVE_FORMAT_PCM;
316     parm.set.nSamplesPerSec = nsamp;
317     parm.set.wBitsPerSample = nbits;
318     parm.set.nChannels      = nch;
319     parm.set.nBlockAlign    = parm.set.nChannels * parm.set.wBitsPerSample /8;
320     parm.set.nAvgBytesPerSec= parm.set.nSamplesPerSec * parm.set.nBlockAlign;
321     err = mciSendCommand(wDeviceID, MCI_SET,
322         MCI_WAVE_SET_SAMPLESPERSEC | MCI_WAVE_SET_CHANNELS |
323         MCI_WAVE_SET_BITSPERSAMPLE | MCI_WAVE_SET_BLOCKALIGN |
324         MCI_WAVE_SET_AVGBYTESPERSEC| MCI_WAVE_SET_FORMATTAG, (DWORD_PTR)&parm);
325     ok(err==ok_pcm,"mciCommand set wave format: %s\n", dbg_mcierr(err));
326
327     /* A few ME machines pass all tests except set format tag pcm! */
328     err = mciSendString("record x to 2000 wait", NULL, 0, hwnd);
329     ok(err || !ok_pcm,"can record yet set wave format pcm returned %s\n", dbg_mcierr(ok_pcm));
330     ok(!err || err==(ok_pcm==MCIERR_OUTOFRANGE ? MCIERR_WAVE_INPUTSUNSUITABLE : 0),"mci record to 2000 returned %s\n", dbg_mcierr(err));
331     if(err) {
332         if (err==MCIERR_WAVE_INPUTSUNSUITABLE)
333              skip("Please install audio driver. Everything is skipped.\n");
334         else skip("Cannot record cause %s. Everything is skipped.\n", dbg_mcierr(err));
335
336         err = mciSendString("close x", NULL, 0, NULL);
337         ok(!err,"mci close returned %s\n", dbg_mcierr(err));
338         test_notification(hwnd,"record skipped",0);
339         return;
340     }
341
342     /* Query some wave format parameters depending on the time format. */
343     err = mciSendString("status x position", buf, sizeof(buf), NULL);
344     ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
345     if(!err) todo_wine ok(!strcmp(buf,"2000"), "mci status position gave %s, expected 2000, some tests will fail\n", buf);
346
347     err = mciSendString("set x time format 8", NULL, 0, NULL); /* bytes */
348     ok(!err,"mci returned %s\n", dbg_mcierr(err));
349
350     parm.status.dwItem = MCI_STATUS_POSITION;
351     err = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
352     ok(!err,"mciCommand status position: %s\n", dbg_mcierr(err));
353     expect = 2 * nsamp * nch * nbits/8;
354     if(!err) todo_wine ok(parm.status.dwReturn==expect,"recorded %lu bytes, expected %u\n",parm.status.dwReturn,expect);
355
356     parm.set.dwTimeFormat = MCI_FORMAT_SAMPLES;
357     err = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)&parm);
358     ok(!err,"mciCommand set time format samples: %s\n", dbg_mcierr(err));
359
360     parm.status.dwItem = MCI_STATUS_POSITION;
361     err = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
362     ok(!err,"mciCommand status position: %s\n", dbg_mcierr(err));
363     expect = 2 * nsamp;
364     if(!err) todo_wine ok(parm.status.dwReturn==expect,"recorded %lu samples, expected %u\n",parm.status.dwReturn,expect);
365
366     err = mciSendString("set x time format milliseconds", NULL, 0, NULL);
367     ok(!err,"mci set time format milliseconds returned %s\n", dbg_mcierr(err));
368
369     err = mciSendString("save x tempfile1.wav", NULL, 0, NULL);
370     ok(!err,"mci save returned %s\n", dbg_mcierr(err));
371
372     err = mciSendString("save x tempfile.wav", NULL, 0, NULL);
373     ok(!err,"mci save returned %s\n", dbg_mcierr(err));
374     if(!err) ok_saved = 0;
375
376     /* Save must not rename the original file. */
377     if (!DeleteFile("tempfile1.wav"))
378         todo_wine ok(FALSE, "Save must not rename the original file; DeleteFile returned %d\n", GetLastError());
379
380     err = mciSendString("set x channels 2", NULL, 0, NULL);
381     ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci set channels after saving returned %s\n", dbg_mcierr(err));
382
383     parm.seek.dwTo = 600;
384     err = mciSendCommand(wDeviceID, MCI_SEEK, MCI_TO | MCI_WAIT, (DWORD_PTR)&parm);
385     ok(!err,"mciCommand seek to 600: %s\n", dbg_mcierr(err));
386
387     /* Truncate to current position */
388     err = mciSendString("delete x", NULL, 0, NULL);
389     todo_wine ok(!err,"mci delete returned %s\n", dbg_mcierr(err));
390
391     buf[0]='\0';
392     err = mciSendString("status x length", buf, sizeof(buf), NULL);
393     ok(!err,"mci status length returned %s\n", dbg_mcierr(err));
394     todo_wine ok(!strcmp(buf,"600"), "mci status length after delete gave %s, expected 600\n", buf);
395
396     err = mciSendString("close x", NULL, 0, NULL);
397     ok(!err,"mci close returned %s\n", dbg_mcierr(err));
398     test_notification(hwnd,"record complete",0);
399 }
400
401 static void test_playWAVE(HWND hwnd)
402 {
403     MCIERROR err;
404     char buf[1024];
405     memset(buf, 0, sizeof(buf));
406
407     err = mciSendString("open waveaudio!tempfile.wav alias mysound", NULL, 0, NULL);
408     ok(err==ok_saved,"mci open waveaudio!tempfile.wav returned %s\n", dbg_mcierr(err));
409     if(err) {
410         skip("Cannot open waveaudio!tempfile.wav for playing (%s), skipping\n", dbg_mcierr(err));
411         return;
412     }
413
414     err = mciSendString("status mysound length", buf, sizeof(buf), NULL);
415     ok(!err,"mci status length returned %s\n", dbg_mcierr(err));
416     todo_wine ok(!strcmp(buf,"2000"), "mci status length gave %s, expected 2000, some tests will fail.\n", buf);
417
418     err = mciSendString("cue output", NULL, 0, NULL);
419     todo_wine ok(err==MCIERR_UNRECOGNIZED_COMMAND,"mci incorrect cue output returned %s\n", dbg_mcierr(err));
420
421     /* Test MCI to the bones -- Some todo_wine from Cue and
422      * from Play from 0 to 0 are not worth fixing. */
423     err = mciSendString("cue mysound output notify", NULL, 0, hwnd);
424     ok(!err,"mci cue output after open file returned %s\n", dbg_mcierr(err));
425     /* Notification is delayed as a play thread is started. */
426     todo_wine test_notification1(hwnd, "cue immediate", 0);
427
428     /* Cue pretends to put the MCI into paused state. */
429     err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
430     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
431     todo_wine ok(!strcmp(buf,"paused"), "mci status mode: %s, expected (pseudo)paused\n", buf);
432
433     /* Strange pause where Pause is rejected, unlike Play; Pause; Pause tested below */
434     err = mciSendString("pause mysound", NULL, 0, hwnd);
435     ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci pause after cue returned %s\n", dbg_mcierr(err));
436
437     /* MCI appears to start the play thread in this border case.
438      * Guessed that from (flaky) status mode and late notification arrival. */
439     err = mciSendString("play mysound from 0 to 0 notify", NULL, 0, hwnd);
440     ok(!err,"mci play from 0 to 0 returned %s\n", dbg_mcierr(err));
441     todo_wine test_notification1(hwnd, "cue aborted by play", MCI_NOTIFY_ABORTED);
442     /* play's own notification follows below */
443
444     err = mciSendString("play mysound from 250 to 0", NULL, 0, NULL);
445     ok(err==MCIERR_OUTOFRANGE,"mci play from 250 to 0 returned %s\n", dbg_mcierr(err));
446
447     Sleep(50); /* Give play from 0 to 0 time to finish. */
448     todo_wine test_notification1(hwnd, "play from 0 to 0", MCI_NOTIFY_SUCCESSFUL);
449
450     err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
451     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
452     ok(!strcmp(buf,"stopped"), "mci status mode: %s after play from 0 to 0\n", buf);
453
454     err = mciSendString("play MYSOUND from 250 to 0 notify", NULL, 0, hwnd);
455     ok(err==MCIERR_OUTOFRANGE,"mci play from 250 to 0 notify returned %s\n", dbg_mcierr(err));
456     /* No notification (checked below) sent if error */
457
458     /* A second play caused Wine<1.1.33 to hang */
459     err = mciSendString("play mysound from 500 to 1500 wait", NULL, 0, NULL);
460     ok(!err,"mci play from 500 to 1500 returned %s\n", dbg_mcierr(err));
461
462     memset(buf, 0, sizeof(buf));
463     err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
464     ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
465     if(!err) ok(!strcmp(buf,"1500"), "mci status position: %s\n", buf);
466
467     /* mci will not play position < current */
468     err = mciSendString("play mysound to 1000", NULL, 0, NULL);
469     ok(err==MCIERR_OUTOFRANGE,"mci play to 1000 returned %s\n", dbg_mcierr(err));
470
471     /* mci will not play to > end */
472     err = mciSendString("play mysound TO 3000 notify", NULL, 0, hwnd);
473     ok(err==MCIERR_OUTOFRANGE,"mci play to 3000 notify returned %s\n", dbg_mcierr(err));
474
475     err = mciSendString("play mysound to 2000", NULL, 0, NULL);
476     ok(!err,"mci play to 2000 returned %s\n", dbg_mcierr(err));
477
478     /* Rejected while playing */
479     err = mciSendString("cue mysound output", NULL, 0, NULL);
480     ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci cue output while playing returned %s\n", dbg_mcierr(err));
481
482     err = mciSendString("play mysound to 3000", NULL, 0, NULL);
483     ok(err==MCIERR_OUTOFRANGE,"mci play to 3000 returned %s\n", dbg_mcierr(err));
484
485     err = mciSendString("stop mysound Wait", NULL, 0, NULL);
486     ok(!err,"mci stop wait returned %s\n", dbg_mcierr(err));
487     test_notification(hwnd, "play/cue/pause/stop", 0);
488
489     err = mciSendString("Seek Mysound to 250 wait Notify", NULL, 0, hwnd);
490     ok(!err,"mci seek to 250 wait notify returned %s\n", dbg_mcierr(err));
491     test_notification(hwnd,"seek wait notify",MCI_NOTIFY_SUCCESSFUL);
492
493     memset(buf, 0, sizeof(buf));
494     err = mciSendString("status mysound position notify", buf, sizeof(buf), hwnd);
495     ok(!err,"mci status position notify returned %s\n", dbg_mcierr(err));
496     if(!err) ok(!strcmp(buf,"250"), "mci status position: %s\n", buf);
497     /* Immediate commands like status also send notifications. */
498     test_notification(hwnd,"status position",MCI_NOTIFY_SUCCESSFUL);
499
500     memset(buf, 0, sizeof(buf));
501     err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
502     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
503     ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
504
505     /* Another play from == to testcase */
506     err = mciSendString("play mysound to 250 wait notify", NULL, 0, hwnd);
507     ok(!err,"mci play (from 250) to 250 returned %s\n", dbg_mcierr(err));
508     todo_wine test_notification1(hwnd,"play to 250 wait notify",MCI_NOTIFY_SUCCESSFUL);
509
510     err = mciSendString("cue mysound output", NULL, 0, NULL);
511     ok(!err,"mci cue output after play returned %s\n", dbg_mcierr(err));
512
513     err = mciSendString("close mysound", NULL, 0, NULL);
514     ok(!err,"mci close returned %s\n", dbg_mcierr(err));
515     test_notification(hwnd,"after close",0);
516 }
517
518 static void test_asyncWAVE(HWND hwnd)
519 {
520     MCIDEVICEID wDeviceID;
521     MCI_PARMS_UNION parm;
522     int err, p1, p2;
523     char buf[1024];
524     memset(buf, 0, sizeof(buf));
525
526     err = mciSendString("open tempfile.wav alias mysound notify", buf, sizeof(buf), hwnd);
527     ok(err==ok_saved,"mci open tempfile.wav returned %s\n", dbg_mcierr(err));
528     if(err) {
529         skip("Cannot open tempfile.wav for playing (%s), skipping\n", dbg_mcierr(err));
530         return;
531     }
532     ok(!strcmp(buf,"1"), "mci open deviceId: %s, expected 1\n", buf);
533     wDeviceID = atoi(buf);
534     ok(wDeviceID,"mci open DeviceID: %d\n", wDeviceID);
535     test_notification(hwnd,"open alias notify",MCI_NOTIFY_SUCCESSFUL);
536
537     err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
538     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
539     ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
540
541     err = mciSendString("play mysound notify", NULL, 0, hwnd);
542     ok(!err,"mci play returned %s\n", dbg_mcierr(err));
543
544     /* Give Wine's asynchronous thread time to start up.  Furthermore,
545      * it uses 3 buffers per second, so that the positions reported
546      * will be 333ms, 667ms etc. at best. */
547     Sleep(100); /* milliseconds */
548
549     /* Do not query time format as string because result depends on locale! */
550     parm.status.dwItem = MCI_STATUS_TIME_FORMAT;
551     err = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
552     ok(!err,"mciCommand status time format: %s\n", dbg_mcierr(err));
553     if(!err) ok(parm.status.dwReturn==MCI_FORMAT_MILLISECONDS,"status time format: %ld\n",parm.status.dwReturn);
554
555     parm.set.dwTimeFormat = MCI_FORMAT_MILLISECONDS;
556     err = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)&parm);
557     ok(!err,"mciCommand set time format ms: %s\n", dbg_mcierr(err));
558
559     buf[0]=0;
560     err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
561     ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
562     ok(strcmp(buf,"2000"), "mci status position: %s, expected 2000\n", buf);
563     trace("position after Sleep: %sms\n",buf);
564     p2 = atoi(buf);
565     /* Some machines reach 79ms only during the 100ms sleep. */
566     ok(p2>=67,"not enough time elapsed %ums\n",p2);
567     test_notification(hwnd,"play (nowait)",0);
568
569     err = mciSendString("pause mysound wait", NULL, 0, hwnd);
570     ok(!err,"mci pause wait returned %s\n", dbg_mcierr(err));
571
572     buf[0]=0;
573     err = mciSendString("status mysound mode notify", buf, sizeof(buf), hwnd);
574     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
575     if(!err) ok(!strcmp(buf,"paused"), "mci status mode: %s\n", buf);
576     test_notification(hwnd,"play",MCI_NOTIFY_SUPERSEDED);
577     test_notification(hwnd,"status",MCI_NOTIFY_SUCCESSFUL);
578
579     buf[0]=0;
580     err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
581     ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
582     trace("position while paused: %sms\n",buf);
583     p1 = atoi(buf);
584     ok(p1>=p2, "position not increasing: %u > %u\n", p2, p1);
585
586     err = mciSendString("stop mysound wait", NULL, 0, NULL);
587     ok(!err,"mci stop returned %s\n", dbg_mcierr(err));
588
589     buf[0]=0;
590     err = mciSendString("info mysound file notify", buf, sizeof(buf), hwnd);
591     ok(!err,"mci info file returned %s\n", dbg_mcierr(err));
592     if(!err) { /* fully qualified name */
593         int len = strlen(buf);
594         todo_wine ok(len>2 && buf[1]==':',"Expected full pathname from info file: %s\n", buf);
595         ok(len>=12 && !strcmp(&buf[len-12],"tempfile.wav"), "info file returned: %s\n", buf);
596     }
597     test_notification(hwnd,"info file",MCI_NOTIFY_SUCCESSFUL);
598
599     buf[0]=0;
600     err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
601     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
602     ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
603
604     buf[0]=0;
605     err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
606     ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
607     trace("position once stopped: %sms\n",buf);
608     p2 = atoi(buf);
609     /* An XP machine let the position increase slightly after pause. */
610     ok(p2>=p1 && p2<=p1+16,"position changed from %ums to %ums\n",p1,p2);
611
612     /* No Resume once stopped (waveaudio, sequencer and cdaudio differ). */
613     err = mciSendString("resume mysound wait", NULL, 0, NULL);
614     ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci resume wait returned %s\n", dbg_mcierr(err));
615
616     err = mciSendString("play mysound wait", NULL, 0, NULL);
617     ok(!err,"mci play wait returned %s\n", dbg_mcierr(err));
618
619     buf[0]=0;
620     err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
621     ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
622     todo_wine ok(!strcmp(buf,"2000"), "mci status position: %s\n", buf);
623
624     err = mciSendString("seek mysound to start wait", NULL, 0, NULL);
625     ok(!err,"mci seek to start wait returned %s\n", dbg_mcierr(err));
626
627     err = mciSendString("play mysound to 1000 notify", NULL, 0, hwnd);
628     ok(!err,"mci play returned %s\n", dbg_mcierr(err));
629
630     /* Sleep(200); not needed with Wine any more. */
631
632     err = mciSendString("pause mysound notify", NULL, 0, NULL); /* notify no callback */
633     ok(!err,"mci pause notify returned %s\n", dbg_mcierr(err));
634     /* Supersede even though pause cannot notify given no callback */
635     test_notification(hwnd,"pause aborted play #1 notification",MCI_NOTIFY_SUPERSEDED);
636     test_notification(hwnd,"impossible pause notification",0);
637
638     err = mciSendString("cue mysound output notify", NULL, 0, hwnd);
639     ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci cue output while paused returned %s\n", dbg_mcierr(err));
640     test_notification(hwnd,"cue output notify #2",0);
641
642     err = mciSendString("resume mysound notify", NULL, 0, hwnd);
643     ok(!err,"mci resume notify returned %s\n", dbg_mcierr(err));
644     test_notification(hwnd, "resume notify", MCI_NOTIFY_SUCCESSFUL);
645
646     /* Seek or even Stop used to hang Wine<1.1.32 on MacOS. */
647     err = mciSendString("seek mysound to 0 wait", NULL, 0, NULL);
648     ok(!err,"mci seek to start returned %s\n", dbg_mcierr(err));
649
650     /* Seek stops. */
651     err = mciSendString("status mysound mode", buf, sizeof(buf), NULL);
652     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
653     if(!err) ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
654
655     err = mciSendString("seek mysound wait", NULL, 0, NULL);
656     ok(err==MCIERR_MISSING_PARAMETER,"mci seek to nowhere returned %s\n", dbg_mcierr(err));
657
658     /* cdaudio does not detect to start to end as error */
659     err = mciSendString("seek mysound to start to 0", NULL, 0, NULL);
660     ok(err==MCIERR_FLAGS_NOT_COMPATIBLE,"mci seek to start to 0 returned %s\n", dbg_mcierr(err));
661
662     err = mciSendString("PLAY mysound to 1000 notify", NULL, 0, hwnd);
663     ok(!err,"mci play to 1000 notify returned %s\n", dbg_mcierr(err));
664
665     /* Sleep(200); not needed with Wine any more. */
666     /* Give it 400ms and resume will appear to complete below. */
667
668     err = mciSendString("pause mysound wait", NULL, 0, NULL);
669     ok(!err,"mci pause wait returned %s\n", dbg_mcierr(err));
670     /* Unlike sequencer and cdaudio, waveaudio's pause does not abort. */
671     test_notification(hwnd,"pause aborted play #2 notification",0);
672
673     err = mciSendString("resume mysound wait", NULL, 0, NULL);
674     ok(!err,"mci resume wait returned %s\n", dbg_mcierr(err));
675     /* Resume is a short asynchronous call, something else is playing. */
676
677     err = mciSendString("status mysound mode", buf, sizeof(buf), NULL);
678     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
679     if(!err) ok(!strcmp(buf,"playing"), "mci status mode: %s\n", buf);
680
681     /* Note extra space before alias */
682     err = mciSendString("pause  mysound wait", NULL, 0, NULL);
683     todo_wine ok(!err,"mci pause (space) wait returned %s\n", dbg_mcierr(err));
684
685     err = mciSendString("pause mysound wait", NULL, 0, NULL);
686     ok(!err,"mci pause wait returned %s\n", dbg_mcierr(err));
687
688     /* Better ask position only when paused, is it updated while playing? */
689     buf[0]='\0';
690     err = mciSendString("status mysound position", buf, sizeof(buf), NULL);
691     ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
692     /* TODO compare position < 900 */
693     ok(strcmp(buf,"1000"), "mci resume waited\n");
694     ok(strcmp(buf,"2000"), "mci resume played to end\n");
695     trace("position after resume: %sms\n",buf);
696     test_notification(hwnd,"play (aborted by pause/resume/pause)",0);
697
698     err = mciSendString("close mysound wait", NULL, 0, NULL);
699     ok(!err,"mci close wait returned %s\n", dbg_mcierr(err));
700     test_notification(hwnd,"play (aborted by close)",MCI_NOTIFY_ABORTED);
701 }
702
703 static void test_AutoOpenWAVE(HWND hwnd)
704 {
705     /* This test used(?) to cause intermittent crashes when Wine exits, after
706      * fixme:winmm:MMDRV_Exit Closing while ll-driver open
707      */
708     MCIERROR err, ok_snd;
709     char buf[512], path[300], command[330];
710     memset(buf, 0, sizeof(buf)); memset(path, 0, sizeof(path));
711
712     /* Do not crash on NULL buffer pointer */
713     err = mciSendString("sysinfo waveaudio quantity open", NULL, 0, NULL);
714     ok(err==MCIERR_PARAM_OVERFLOW,"mci sysinfo without buffer returned %s\n", dbg_mcierr(err));
715
716     err = mciSendString("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL);
717     ok(!err,"mci sysinfo waveaudio quantity open returned %s\n", dbg_mcierr(err));
718     if(!err) todo_wine ok(!strcmp(buf,"0"), "sysinfo quantity open expected 0, got: %s, some more tests will fail.\n", buf);
719
720     ok_snd = waveOutGetNumDevs() ? 0 : MCIERR_HARDWARE;
721     err = mciSendString("sound NoSuchSoundDefined wait", NULL, 0, NULL);
722     todo_wine ok(err==ok_snd,"mci sound NoSuchSoundDefined returned %s\n", dbg_mcierr(err));
723
724     err = mciSendString("sound SystemExclamation notify wait", NULL, 0, hwnd);
725     todo_wine ok(err==ok_snd,"mci sound SystemExclamation returned %s\n", dbg_mcierr(err));
726     test_notification(hwnd, "sound notify", err ? 0 : MCI_NOTIFY_SUCCESSFUL);
727
728     buf[0]=0;
729     err = mciSendString("sysinfo waveaudio name 1 open", buf, sizeof(buf), NULL);
730     todo_wine ok(err==MCIERR_OUTOFRANGE,"sysinfo waveaudio name 1 returned %s\n", dbg_mcierr(err));
731     if(!err) trace("sysinfo dangling open alias: %s\n", buf);
732
733     err = mciSendString("play no-such-file-exists.wav notify", buf, sizeof(buf), NULL);
734     if(err==MCIERR_FILE_NOT_FOUND) { /* a Wine detector */
735         /* Unsupported auto-open leaves the file open, preventing clean-up */
736         skip("Skipping auto-open tests in Wine\n");
737         return;
738     }
739
740     err = mciSendString("play tempfile.wav notify", buf, sizeof(buf), hwnd);
741     todo_wine ok(err==MCIERR_NOTIFY_ON_AUTO_OPEN,"mci auto-open play notify returned %s\n", dbg_mcierr(err));
742
743     if(err) /* FIXME: don't open twice yet, it confuses Wine. */
744     err = mciSendString("play tempfile.wav", buf, sizeof(buf), hwnd);
745     ok(err==ok_saved,"mci auto-open play returned %s\n", dbg_mcierr(err));
746
747     if(err==MCIERR_FILE_NOT_FOUND) {
748         skip("Cannot open tempfile.wav for auto-play, skipping\n");
749         return;
750     }
751
752     buf[0]=0;
753     err = mciSendString("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL);
754     ok(!err,"mci sysinfo waveaudio quantity after auto-open returned %s\n", dbg_mcierr(err));
755     if(!err) todo_wine ok(!strcmp(buf,"1"), "sysinfo quantity open expected 1, got: %s\n", buf);
756
757     buf[0]=0;
758     err = mciSendString("sysinfo waveaudio name 1 open", buf, sizeof(buf), NULL);
759     todo_wine ok(!err,"mci sysinfo waveaudio name after auto-open returned %s\n", dbg_mcierr(err));
760     /* This is the alias, not necessarily a file name. */
761     if(!err) ok(!strcmp(buf,"tempfile.wav"), "sysinfo name 1 open: %s\n", buf);
762
763     /* Save the full pathname to the file. */
764     err = mciSendString("info tempfile.wav file", path, sizeof(path), NULL);
765     ok(!err,"mci info tempfile.wav file returned %s\n", dbg_mcierr(err));
766     if(err) strcpy(path,"tempfile.wav");
767
768     err = mciSendString("status tempfile.wav mode", NULL, 0, hwnd);
769     ok(!err,"mci status tempfile.wav mode without buffer returned %s\n", dbg_mcierr(err));
770
771     sprintf(command,"status \"%s\" mode",path);
772     err = mciSendString(command, buf, sizeof(buf), hwnd);
773     ok(!err,"mci status \"%s\" mode returned %s\n", path, dbg_mcierr(err));
774
775     buf[0]=0;
776     err = mciSendString("status tempfile.wav mode", buf, sizeof(buf), hwnd);
777     ok(!err,"mci status tempfile.wav mode returned %s\n", dbg_mcierr(err));
778     if(!err) ok(!strcmp(buf,"playing"), "mci auto-open status mode, got: %s\n", buf);
779
780     err = mciSendString("open tempfile.wav", buf, sizeof(buf), NULL);
781     todo_wine ok(err==MCIERR_DEVICE_OPEN, "mci open from auto-open returned %s\n", dbg_mcierr(err));
782
783     /* w2k/xp and Wine differ. While the device is busy playing, it is
784      * regularly open and accessible via the filename: subsequent
785      * commands must not cause auto-open each.  In Wine, a subsequent
786      * command with notify request may cause the initial play
787      * notification to be superseded, in turn causing MCI to close the
788      * device.  I.e. MCI uses the auto-open notification for itself,
789      * that's why it's not available to the app.  On w2k/xp,
790      * subsequent commands with notify requests are returned with
791      * MCIERR_NOTIFY_ON_AUTO_OPEN and thus don't abort the original
792      * command.
793      */
794     err = mciSendString("status tempfile.wav mode notify", buf, sizeof(buf), hwnd);
795     todo_wine ok(err==MCIERR_NOTIFY_ON_AUTO_OPEN, "mci status auto-open notify returned %s\n", dbg_mcierr(err));
796     if(!err) {
797         trace("Wine style MCI auto-close upon notification\n");
798
799         /* "playing" because auto-close comes after the status call. */
800         todo_wine ok(!strcmp(buf,"playing"), "mci auto-open status mode notify, got: %s\n", buf);
801         /* fixme:winmm:MMDRV_Exit Closing while ll-driver open
802          *  is explained by failure to auto-close a device. */
803         test_notification(hwnd,"status notify",MCI_NOTIFY_SUCCESSFUL);
804         /* MCI received NOTIFY_SUPERSEDED and auto-closed the device. */
805         Sleep(16);
806         test_notification(hwnd,"auto-open",0);
807     } else if(err==MCIERR_NOTIFY_ON_AUTO_OPEN) { /* MS style */
808         trace("MS style MCI auto-open forbids notification\n");
809
810         err = mciSendString("pause tempfile.wav", NULL, 0, hwnd);
811         ok(!err,"mci auto-still-open pause returned %s\n", dbg_mcierr(err));
812
813         err = mciSendString("status tempfile.wav mode", buf, sizeof(buf), hwnd);
814         ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
815         if(!err) ok(!strcmp(buf,"paused"), "mci auto-open status mode, got: %s\n", buf);
816
817         /* Auto-close */
818         err = mciSendString("stop tempfile.wav", NULL, 0, hwnd);
819         ok(!err,"mci auto-still-open stop returned %s\n", dbg_mcierr(err));
820         Sleep(16); /* makes sysinfo quantity open below succeed */
821     }
822
823     err = mciSendString("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL);
824     ok(!err,"mci sysinfo waveaudio quantity open after close returned %s\n", dbg_mcierr(err));
825     if(!err) todo_wine ok(!strcmp(buf,"0"), "sysinfo quantity open expected 0 after auto-close, got: %s\n", buf);
826
827     /* w95-WinME (not w2k/XP) switch to C:\ after auto-playing once.  Prevent
828      * MCIERR_FILE_NOT_FOUND by using the full path name from the Info file command.
829      */
830     sprintf(command,"status \"%s\" mode wait",path);
831     err = mciSendString(command, buf, sizeof(buf), hwnd);
832     ok(!err,"mci re-auto-open status mode returned %s\n", dbg_mcierr(err));
833     if(!err) ok(!strcmp(buf,"stopped"), "mci re-auto-open status mode, got: %s\n", buf);
834
835     err = mciSendString("capability waveaudio device type", buf, sizeof(buf), hwnd);
836     ok(!err,"mci capability device type returned %s\n", dbg_mcierr(err));
837     if(!err) ok(!strcmp(buf,"waveaudio"), "mci capability device type response: %s\n", buf);
838
839     /* waveaudio forbids Pause without Play. */
840     sprintf(command,"pause \"%s\"",path);
841     err = mciSendString(command, NULL, 0, hwnd);
842     ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci auto-open pause returned %s\n", dbg_mcierr(err));
843 }
844
845 START_TEST(mci)
846 {
847     MCIERROR err;
848     HWND hwnd;
849     hwnd = CreateWindowExA(0, "static", "winmm test", WS_POPUP, 0,0,100,100,
850                            0, 0, 0, NULL);
851     test_openCloseWAVE(hwnd);
852     test_recordWAVE(hwnd);
853     test_playWAVE(hwnd);
854     test_asyncWAVE(hwnd);
855     test_AutoOpenWAVE(hwnd);
856     /* Win9X hangs when exiting with something still open. */
857     err = mciSendString("close all", NULL, 0, hwnd);
858     todo_wine ok(!err,"final close all returned %s\n", dbg_mcierr(err));
859     ok(DeleteFile("tempfile.wav")||ok_saved,"Delete tempfile.wav (cause auto-open?)\n");
860     DestroyWindow(hwnd);
861 }