windowscodecs: Convert the source bitmap to the requested pixel format in IWICColorTr...
[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_INFO_PARMS      info;
34       MCI_STATUS_PARMS    status;
35       MCI_WAVE_SET_PARMS  set;
36       MCI_WAVE_OPEN_PARMS open;
37       MCI_GETDEVCAPS_PARMS caps;
38       MCI_SYSINFO_PARMS   sys;
39       MCI_SEEK_PARMS      seek;
40       MCI_GENERIC_PARMS   gen;
41     } MCI_PARMS_UNION;
42
43 const char* dbg_mcierr(MCIERROR err)
44 {
45      switch (err) {
46      case 0: return "0=NOERROR";
47 #define X(label) case label: return #label ;
48      X(MCIERR_INVALID_DEVICE_ID)
49      X(MCIERR_UNRECOGNIZED_KEYWORD)
50      X(MCIERR_UNRECOGNIZED_COMMAND)
51      X(MCIERR_HARDWARE)
52      X(MCIERR_INVALID_DEVICE_NAME)
53      X(MCIERR_OUT_OF_MEMORY)
54      X(MCIERR_DEVICE_OPEN)
55      X(MCIERR_CANNOT_LOAD_DRIVER)
56      X(MCIERR_MISSING_COMMAND_STRING)
57      X(MCIERR_PARAM_OVERFLOW)
58      X(MCIERR_MISSING_STRING_ARGUMENT)
59      X(MCIERR_BAD_INTEGER)
60      X(MCIERR_PARSER_INTERNAL)
61      X(MCIERR_DRIVER_INTERNAL)
62      X(MCIERR_MISSING_PARAMETER)
63      X(MCIERR_UNSUPPORTED_FUNCTION)
64      X(MCIERR_FILE_NOT_FOUND)
65      X(MCIERR_DEVICE_NOT_READY)
66      X(MCIERR_INTERNAL)
67      X(MCIERR_DRIVER)
68      X(MCIERR_CANNOT_USE_ALL)
69      X(MCIERR_MULTIPLE)
70      X(MCIERR_EXTENSION_NOT_FOUND)
71      X(MCIERR_OUTOFRANGE)
72      X(MCIERR_FLAGS_NOT_COMPATIBLE)
73      X(MCIERR_FILE_NOT_SAVED)
74      X(MCIERR_DEVICE_TYPE_REQUIRED)
75      X(MCIERR_DEVICE_LOCKED)
76      X(MCIERR_DUPLICATE_ALIAS)
77      X(MCIERR_BAD_CONSTANT)
78      X(MCIERR_MUST_USE_SHAREABLE)
79      X(MCIERR_MISSING_DEVICE_NAME)
80      X(MCIERR_BAD_TIME_FORMAT)
81      X(MCIERR_NO_CLOSING_QUOTE)
82      X(MCIERR_DUPLICATE_FLAGS)
83      X(MCIERR_INVALID_FILE)
84      X(MCIERR_NULL_PARAMETER_BLOCK)
85      X(MCIERR_UNNAMED_RESOURCE)
86      X(MCIERR_NEW_REQUIRES_ALIAS)
87      X(MCIERR_NOTIFY_ON_AUTO_OPEN)
88      X(MCIERR_NO_ELEMENT_ALLOWED)
89      X(MCIERR_NONAPPLICABLE_FUNCTION)
90      X(MCIERR_ILLEGAL_FOR_AUTO_OPEN)
91      X(MCIERR_FILENAME_REQUIRED)
92      X(MCIERR_EXTRA_CHARACTERS)
93      X(MCIERR_DEVICE_NOT_INSTALLED)
94      X(MCIERR_GET_CD)
95      X(MCIERR_SET_CD)
96      X(MCIERR_SET_DRIVE)
97      X(MCIERR_DEVICE_LENGTH)
98      X(MCIERR_DEVICE_ORD_LENGTH)
99      X(MCIERR_NO_INTEGER)
100      X(MCIERR_WAVE_OUTPUTSINUSE)
101      X(MCIERR_WAVE_SETOUTPUTINUSE)
102      X(MCIERR_WAVE_INPUTSINUSE)
103      X(MCIERR_WAVE_SETINPUTINUSE)
104      X(MCIERR_WAVE_OUTPUTUNSPECIFIED)
105      X(MCIERR_WAVE_INPUTUNSPECIFIED)
106      X(MCIERR_WAVE_OUTPUTSUNSUITABLE)
107      X(MCIERR_WAVE_SETOUTPUTUNSUITABLE)
108      X(MCIERR_WAVE_INPUTSUNSUITABLE)
109      X(MCIERR_WAVE_SETINPUTUNSUITABLE)
110      X(MCIERR_SEQ_DIV_INCOMPATIBLE)
111      X(MCIERR_SEQ_PORT_INUSE)
112      X(MCIERR_SEQ_PORT_NONEXISTENT)
113      X(MCIERR_SEQ_PORT_MAPNODEVICE)
114      X(MCIERR_SEQ_PORT_MISCERROR)
115      X(MCIERR_SEQ_TIMER)
116      X(MCIERR_SEQ_PORTUNSPECIFIED)
117      X(MCIERR_SEQ_NOMIDIPRESENT)
118      X(MCIERR_NO_WINDOW)
119      X(MCIERR_CREATEWINDOW)
120      X(MCIERR_FILE_READ)
121      X(MCIERR_FILE_WRITE)
122      X(MCIERR_NO_IDENTITY)
123 #undef X
124      default: {
125          static char name[20]; /* Not to be called twice in a parameter list! */
126          sprintf(name, "MMSYSERR %u", err);
127          return name;
128          }
129      }
130 }
131
132 static BOOL spurious_message(LPMSG msg)
133 {
134   /* WM_DEVICECHANGE 0x0219 appears randomly */
135   if(msg->message != MM_MCINOTIFY) {
136     trace("skipping spurious message %04x\n",msg->message);
137     return TRUE;
138   }
139   return FALSE;
140 }
141
142 /* A single ok() in each code path allows us to prefix this with todo_wine */
143 #define test_notification(hwnd, command, type) test_notification_dbg(hwnd, command, type, __LINE__)
144 static void test_notification_dbg(HWND hwnd, const char* command, WPARAM type, int line)
145 {   /* Use type 0 as meaning no message */
146     MSG msg;
147     BOOL seen;
148     do { seen = PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE); }
149     while(seen && spurious_message(&msg));
150     if(type && !seen) {
151       /* We observe transient delayed notification, mostly on native.
152        * Notification is not always present right when mciSend returns. */
153       trace_(__FILE__,line)("Waiting for delayed notification from %s\n", command);
154       MsgWaitForMultipleObjects(0, NULL, FALSE, 3000, QS_POSTMESSAGE);
155       seen = PeekMessageA(&msg, hwnd, MM_MCINOTIFY, MM_MCINOTIFY, PM_REMOVE);
156     }
157     if(!seen)
158       ok_(__FILE__,line)(type==0, "Expect message %04lx from %s\n", type, command);
159     else if(msg.hwnd != hwnd)
160         ok_(__FILE__,line)(msg.hwnd == hwnd, "Didn't get the handle to our test window\n");
161     else if(msg.message != MM_MCINOTIFY)
162         ok_(__FILE__,line)(msg.message == MM_MCINOTIFY, "got %04x instead of MM_MCINOTIFY from command %s\n", msg.message, command);
163     else ok_(__FILE__,line)(msg.wParam == type, "got %04lx instead of MCI_NOTIFY_xyz %04lx from command %s\n", msg.wParam, type, command);
164 }
165
166 static int strcmp_wa(LPCWSTR strw, const char *stra)
167 {
168     CHAR buf[512];
169     WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), 0, 0);
170     return lstrcmpA(buf, stra);
171 }
172
173 static void test_mciParser(HWND hwnd)
174 {
175     MCIERROR err;
176     MCIDEVICEID wDeviceID;
177     MCI_PARMS_UNION parm;
178     char buf[1024];
179     memset(buf, 0, sizeof(buf));
180     test_notification(hwnd, "-prior to parser test-", 0);
181
182     /* Get a handle on an MCI device, works even without sound. */
183     parm.open.lpstrDeviceType = "waveaudio";
184     parm.open.lpstrElementName = ""; /* "new" at the command level */
185     parm.open.lpstrAlias = "x"; /* to enable mciSendString */
186     parm.open.dwCallback = (DWORD_PTR)hwnd;
187     err = mciSendCommand(0, MCI_OPEN,
188         MCI_OPEN_ELEMENT | MCI_OPEN_TYPE | MCI_OPEN_ALIAS | MCI_NOTIFY,
189         (DWORD_PTR)&parm);
190     ok(!err,"mciCommand open new type waveaudio alias x notify: %s\n", dbg_mcierr(err));
191     wDeviceID = parm.open.wDeviceID;
192     ok(!strcmp(parm.open.lpstrDeviceType,"waveaudio"), "open modified device type\n");
193
194     test_notification(hwnd, "MCI_OPEN", MCI_NOTIFY_SUCCESSFUL);
195     test_notification(hwnd, "MCI_OPEN no #2", 0);
196
197     err = mciSendString("open avivideo alias a", buf, sizeof(buf), hwnd);
198     ok(!err,"open another: %s\n", dbg_mcierr(err));
199
200     buf[0]='z';
201     err = mciSendString("", buf, sizeof(buf), NULL);
202     todo_wine ok(err==MCIERR_MISSING_COMMAND_STRING,"empty string: %s\n", dbg_mcierr(err));
203     ok(!buf[0], "error buffer %s\n", buf);
204
205     buf[0]='d';
206     err = mciSendString("open", buf, sizeof(buf), NULL);
207     ok(err==MCIERR_MISSING_DEVICE_NAME,"open void: %s\n", dbg_mcierr(err));
208     ok(!buf[0], "open error buffer %s\n", buf);
209
210     err = mciSendString("open notify", buf, sizeof(buf), NULL);
211     todo_wine ok(err==MCIERR_INVALID_DEVICE_NAME,"open notify: %s\n", dbg_mcierr(err));
212
213     err = mciSendString("open new", buf, sizeof(buf), NULL);
214     todo_wine ok(err==MCIERR_NEW_REQUIRES_ALIAS,"open new: %s\n", dbg_mcierr(err));
215
216     err = mciSendString("open new type waveaudio alias r shareable shareable", buf, sizeof(buf), NULL);
217     todo_wine ok(err==MCIERR_DUPLICATE_FLAGS,"open new: %s\n", dbg_mcierr(err));
218     if(!err) mciSendString("close r", NULL, 0, NULL);
219
220     err = mciSendString("status x position wait wait", buf, sizeof(buf), NULL);
221     todo_wine ok(err==MCIERR_DUPLICATE_FLAGS,"status wait wait: %s\n", dbg_mcierr(err));
222
223     err = mciSendString("status x length length", buf, sizeof(buf), NULL);
224     todo_wine ok(err==MCIERR_FLAGS_NOT_COMPATIBLE,"status 2xlength: %s\n", dbg_mcierr(err));
225
226     err = mciSendString("status x length position", buf, sizeof(buf), NULL);
227     todo_wine ok(err==MCIERR_FLAGS_NOT_COMPATIBLE,"status length+position: %s\n", dbg_mcierr(err));
228
229     buf[0]='I';
230     err = mciSendString("set x time format milliseconds time format ms", buf, sizeof(buf), NULL);
231     todo_wine ok(err==MCIERR_FLAGS_NOT_COMPATIBLE,"status length+position: %s\n", dbg_mcierr(err));
232     ok(!buf[0], "set error buffer %s\n", buf);
233
234     /* device's response, not a parser test */
235     err = mciSendString("status x", buf, sizeof(buf), NULL);
236     ok(err==MCIERR_MISSING_PARAMETER,"status waveaudio nokeyword: %s\n", dbg_mcierr(err));
237
238     buf[0]='G';
239     err = mciSendString("status a", buf, sizeof(buf), NULL);
240     todo_wine ok(err==MCIERR_UNSUPPORTED_FUNCTION,"status avivideo nokeyword: %s\n", dbg_mcierr(err));
241     ok(!buf[0], "status error buffer %s\n", buf);
242
243     err = mciSendString("status x track", buf, sizeof(buf), NULL);
244     ok(err==MCIERR_BAD_INTEGER,"status waveaudio no track: %s\n", dbg_mcierr(err));
245
246     err = mciSendString("status x track 3", buf, sizeof(buf), NULL);
247     ok(err==MCIERR_MISSING_PARAMETER,"status waveaudio track 3: %s\n", dbg_mcierr(err));
248
249     err = mciSendString("status x 2 track 3", buf, sizeof(buf), NULL);
250     todo_wine ok(err==MCIERR_OUTOFRANGE,"status 2(position) track 3: %s\n", dbg_mcierr(err));
251
252     err = mciSendString("status x 0x4", buf, sizeof(buf), NULL);
253     todo_wine ok(err==MCIERR_BAD_CONSTANT, "status 0x4: %s\n", dbg_mcierr(err));
254
255     err = mciSendString("status x 4", buf, sizeof(buf), hwnd);
256     ok(!err,"status 4(mode): %s\n", dbg_mcierr(err));
257     if(!err)ok(!strcmp(buf,"stopped"), "status 4(mode), got: %s\n", buf);
258
259     err = mciSendString("status x 4 notify", buf, sizeof(buf), hwnd);
260     todo_wine ok(!err,"status 4(mode) notify: %s\n", dbg_mcierr(err));
261     if(!err)ok(!strcmp(buf,"stopped"), "status 4(mode), got: %s\n", buf);
262     test_notification(hwnd, "status 4 notify", err ? 0 : MCI_NOTIFY_SUCCESSFUL);
263
264     err = mciSendString("set x milliseconds", buf, sizeof(buf), hwnd);
265     todo_wine ok(err==MCIERR_UNRECOGNIZED_KEYWORD,"set milliseconds: %s\n", dbg_mcierr(err));
266
267     err = mciSendString("set x milliseconds ms", buf, sizeof(buf), hwnd);
268     todo_wine ok(err==MCIERR_UNRECOGNIZED_KEYWORD,"set milliseconds ms: %s\n", dbg_mcierr(err));
269
270     err = mciSendString("capability x can   save", buf, sizeof(buf), hwnd);
271     todo_wine ok(!err,"capability can (space) save: %s\n", dbg_mcierr(err));
272
273     err = mciSendString("status x nsa", buf, sizeof(buf), hwnd);
274     todo_wine ok(err==MCIERR_BAD_CONSTANT,"status nsa: %s\n", dbg_mcierr(err));
275
276     err = mciSendString("seek x to 0:0:0:0:0", buf, sizeof(buf), NULL);
277     ok(err==MCIERR_BAD_INTEGER,"seek to 0:0:0:0:0 returned %s\n", dbg_mcierr(err));
278
279     err = mciSendString("seek x to 0:0:0:0:", buf, sizeof(buf), NULL);
280     ok(err==MCIERR_BAD_INTEGER,"seek to 0:0:0:0: returned %s\n", dbg_mcierr(err));
281
282     err = mciSendString("seek x to :0:0:0:0", buf, sizeof(buf), NULL);
283     ok(err==MCIERR_BAD_INTEGER,"seek to :0:0:0:0 returned %s\n", dbg_mcierr(err));
284
285     err = mciSendString("seek x to 256:0:0:0", buf, sizeof(buf), NULL);
286     ok(err==MCIERR_BAD_INTEGER,"seek to 256:0:0:0 returned %s\n", dbg_mcierr(err));
287
288     err = mciSendString("seek x to 0:256", buf, sizeof(buf), NULL);
289     ok(err==MCIERR_BAD_INTEGER,"seek to 0:256 returned %s\n", dbg_mcierr(err));
290
291     err = mciSendString("status all time format", buf, sizeof(buf), hwnd);
292     ok(err==MCIERR_CANNOT_USE_ALL,"status all: %s\n", dbg_mcierr(err));
293
294     err = mciSendString("cue all", buf, sizeof(buf), NULL);
295     ok(err==MCIERR_UNRECOGNIZED_COMMAND,"cue all: %s\n", dbg_mcierr(err));
296
297     err = mciSendString("open all", buf, sizeof(buf), NULL);
298     todo_wine ok(err==MCIERR_CANNOT_USE_ALL,"open all: %s\n", dbg_mcierr(err));
299
300     /* avivideo is not a known MCI_DEVTYPE resource name */
301     err = mciSendString("sysinfo avivideo quantity", buf, sizeof(buf), hwnd);
302     ok(err==MCIERR_DEVICE_TYPE_REQUIRED,"sysinfo sequencer quantity: %s\n", dbg_mcierr(err));
303
304     err = mciSendString("sysinfo digitalvideo quantity", buf, sizeof(buf), hwnd);
305     ok(!err,"sysinfo digitalvideo quantity: %s\n", dbg_mcierr(err));
306     if(!err) ok(!strcmp(buf,"0"), "sysinfo digitalvideo quantity returned %s\n", buf);
307
308     /* quantity 0 yet open 1 (via type "avivideo"), fun */
309     err = mciSendString("sysinfo digitalvideo quantity open", buf, sizeof(buf), hwnd);
310     ok(!err,"sysinfo digitalvideo quantity open: %s\n", dbg_mcierr(err));
311     if(!err) ok(!strcmp(buf,"1"), "sysinfo digitalvideo quantity open returned %s\n", buf);
312
313     err = mciSendString("put a window at 0 0", buf, sizeof(buf), NULL);
314     ok(err==MCIERR_BAD_INTEGER,"put incomplete rect: %s\n", dbg_mcierr(err));
315
316     /*w9X-w2k report code from device last opened, newer versions compare them all
317      * and return the one error code or MCIERR_MULTIPLE if they differ. */
318     err = mciSendString("pause all", buf, sizeof(buf), NULL);
319     todo_wine ok(err==MCIERR_MULTIPLE || broken(err==MCIERR_NONAPPLICABLE_FUNCTION),"pause all: %s\n", dbg_mcierr(err));
320     ok(!buf[0], "pause error buffer %s\n", buf);
321
322     /* MCI_STATUS' dwReturn is a DWORD_PTR, others' a plain DWORD. */
323     parm.status.dwItem = MCI_STATUS_TIME_FORMAT;
324     parm.status.dwReturn = 0xFEEDABAD;
325     err = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
326     ok(!err,"mciCommand status time format: %s\n", dbg_mcierr(err));
327     if(!err) ok(MCI_FORMAT_MILLISECONDS==parm.status.dwReturn,"status time format: %ld\n",parm.status.dwReturn);
328
329     parm.status.dwItem = MCI_STATUS_MODE;
330     parm.status.dwReturn = 0xFEEDABAD;
331     err = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
332     ok(!err,"mciCommand status mode: %s\n", dbg_mcierr(err));
333     if(!err) ok(MCI_MODE_STOP==parm.status.dwReturn,"STATUS mode: %ld\n",parm.status.dwReturn);
334
335     err = mciSendString("status x mode", buf, sizeof(buf), hwnd);
336     ok(!err,"status mode: %s\n", dbg_mcierr(err));
337     if(!err) ok(!strcmp(buf, "stopped"), "status mode is %s\n", buf);
338
339     parm.caps.dwItem = MCI_GETDEVCAPS_USES_FILES;
340     parm.caps.dwReturn = 0xFEEDABAD;
341     err = mciSendCommand(wDeviceID, MCI_GETDEVCAPS, MCI_GETDEVCAPS_ITEM, (DWORD_PTR)&parm);
342     ok(!err,"mciCommand getdevcaps files: %s\n", dbg_mcierr(err));
343     if(!err) ok(1==parm.caps.dwReturn,"getdevcaps files: %d\n",parm.caps.dwReturn);
344
345     parm.caps.dwItem = MCI_GETDEVCAPS_HAS_VIDEO;
346     parm.caps.dwReturn = 0xFEEDABAD;
347     err = mciSendCommand(wDeviceID, MCI_GETDEVCAPS, MCI_GETDEVCAPS_ITEM, (DWORD_PTR)&parm);
348     ok(!err,"mciCommand getdevcaps video: %s\n", dbg_mcierr(err));
349     if(!err) ok(0==parm.caps.dwReturn,"getdevcaps video: %d\n",parm.caps.dwReturn);
350
351     parm.caps.dwItem = MCI_GETDEVCAPS_DEVICE_TYPE;
352     parm.caps.dwReturn = 0xFEEDABAD;
353     err = mciSendCommand(wDeviceID, MCI_GETDEVCAPS, MCI_GETDEVCAPS_ITEM, (DWORD_PTR)&parm);
354     ok(!err,"mciCommand getdevcaps video: %s\n", dbg_mcierr(err));
355     if(!err) ok(MCI_DEVTYPE_WAVEFORM_AUDIO==parm.caps.dwReturn,"getdevcaps device type: %d\n",parm.caps.dwReturn);
356
357     err = mciSendString("capability x uses files", buf, sizeof(buf), hwnd);
358     ok(!err,"capability files: %s\n", dbg_mcierr(err));
359     if(!err) ok(!strcmp(buf, "true"), "capability files is %s\n", buf);
360
361     err = mciSendString("capability x has video", buf, sizeof(buf), hwnd);
362     ok(!err,"capability video: %s\n", dbg_mcierr(err));
363     if(!err) ok(!strcmp(buf, "false"), "capability video is %s\n", buf);
364
365     err = mciSendString("capability x device type", buf, sizeof(buf), hwnd);
366     ok(!err,"capability device type: %s\n", dbg_mcierr(err));
367     if(!err) ok(!strcmp(buf, "waveaudio"), "capability device type is %s\n", buf);
368
369     err = mciSendCommand(wDeviceID, MCI_CLOSE, 0, 0);
370     ok(!err,"mciCommand close returned %s\n", dbg_mcierr(err));
371
372     err = mciSendString("close a", buf, sizeof(buf), hwnd);
373     ok(!err,"close avi: %s\n", dbg_mcierr(err));
374
375     test_notification(hwnd, "-end of 1st set-", 0);
376 }
377
378 static void test_openCloseWAVE(HWND hwnd)
379 {
380     MCIERROR err;
381     MCI_PARMS_UNION parm;
382     const char command_open[] = "open new type waveaudio alias mysound notify";
383     const char command_close_my[] = "close mysound notify";
384     const char command_close_all[] = "close all notify";
385     const char command_sysinfo[] = "sysinfo waveaudio quantity open";
386     char buf[1024];
387     DWORD intbuf[3] = { 0xDEADF00D, 99, 0xABADCAFE };
388     memset(buf, 0, sizeof(buf));
389     test_notification(hwnd, "-prior to any command-", 0);
390
391     /* Avoid Sysinfo quantity with notify because Win9x and newer differ. */
392     err = mciSendString("sysinfo all quantity", buf, sizeof(buf), hwnd);
393     ok(!err,"mci sysinfo all quantity returned %s\n", dbg_mcierr(err));
394     if(!err) trace("[MCI] with %s drivers\n", buf);
395
396     parm.sys.lpstrReturn = (LPSTR)&intbuf[1];
397     parm.sys.dwRetSize = sizeof(DWORD);
398     parm.sys.wDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; /* ignored */
399     err = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_SYSINFO, MCI_SYSINFO_QUANTITY | MCI_WAIT, (DWORD_PTR)&parm);
400     ok(!err,"mciSendCommand(MCI_ALL_DEVICE_ID, MCI_SYSINFO QUANTITY, MCI_WAIT, 0) returned %s\n", dbg_mcierr(err));
401     if(!err) ok(atoi(buf)==intbuf[1],"sysinfo all quantity string and command differ\n");
402
403     parm.sys.dwRetSize = sizeof(DWORD)-1;
404     err = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_SYSINFO, MCI_SYSINFO_QUANTITY, (DWORD_PTR)&parm);
405     ok(err==MCIERR_PARAM_OVERFLOW || broken(!err/* Win9x */),"mciSendCommand MCI_SYSINFO with too small buffer returned %s\n", dbg_mcierr(err));
406
407     err = mciSendString("open new type waveaudio alias r shareable", buf, sizeof(buf), NULL);
408     ok(err==MCIERR_UNSUPPORTED_FUNCTION,"mci open new shareable returned %s\n", dbg_mcierr(err));
409     if(!err) {
410         err = mciSendString("close r", NULL, 0, NULL);
411         ok(!err,"mci close shareable returned %s\n", dbg_mcierr(err));
412     }
413
414     err = mciGetDeviceID("waveaudio");
415     ok(err==0,"mciGetDeviceID waveaudio returned %u, expected 0\n", err);
416
417     err = mciSendString(command_open, buf, sizeof(buf), hwnd);
418     ok(!err,"mci %s returned %s\n", command_open, dbg_mcierr(err));
419     ok(!strcmp(buf,"1"), "mci open deviceId: %s, expected 1\n", buf);
420     /* Wine<=1.1.33 used to ignore anything past alias XY */
421     test_notification(hwnd,"open new alias notify",MCI_NOTIFY_SUCCESSFUL);
422
423     err = mciSendString("status mysound time format", buf, sizeof(buf), hwnd);
424     ok(!err,"mci status time format returned %s\n", dbg_mcierr(err));
425     if(!err) {
426         if (PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) == LANG_ENGLISH)
427             ok(!strcmp(buf,"milliseconds"), "mci status time format: %s\n", buf);
428         else trace("locale-dependent time format: %s (ms)\n", buf);
429     }
430
431     memset(buf, 0, sizeof(buf));
432     parm.sys.dwNumber = 1;
433     parm.sys.wDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; /* ignored */
434     parm.sys.lpstrReturn = buf;
435     parm.sys.dwRetSize = sizeof(buf);
436     parm.sys.dwCallback = (DWORD_PTR)hwnd;
437     err = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_SYSINFO, MCI_SYSINFO_NAME | MCI_SYSINFO_OPEN | MCI_NOTIFY, (DWORD_PTR)&parm);
438     ok(!err,"mciCommand MCI_SYSINFO all name 1 open notify: %s\n", dbg_mcierr(err));
439     if(!err) ok(!strcmp(buf,"mysound"), "sysinfo name returned %s\n", buf);
440     test_notification(hwnd, "SYSINFO name notify\n", MCI_NOTIFY_SUCCESSFUL);
441
442     memset(buf, 0, sizeof(buf));
443     parm.sys.dwNumber = 1;
444     parm.sys.wDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; /* ignored */
445     parm.sys.lpstrReturn = buf;
446     parm.sys.dwRetSize = 8; /* mysound\0 */
447     err = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_SYSINFO, MCI_SYSINFO_NAME | MCI_SYSINFO_OPEN, (DWORD_PTR)&parm);
448     ok(!err,"mciCommand MCI_SYSINFO all name 1 open buffer[8]: %s\n", dbg_mcierr(err));
449     if(!err) ok(!strcmp(buf,"mysound"), "sysinfo name returned %s\n", buf);
450
451     memset(buf, 0, sizeof(buf));
452     /* dwRetSize counts characters, not bytes, despite what MSDN says. */
453     parm.sys.dwNumber = 1;
454     parm.sys.wDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; /* ignored */
455     parm.sys.lpstrReturn = buf;
456     parm.sys.dwRetSize = 8; /* mysound\0 */
457     /* MCI_..._PARMSA and PARMSW share the same layout, use one for both tests. */
458     err = mciSendCommandW(MCI_ALL_DEVICE_ID, MCI_SYSINFO, MCI_SYSINFO_NAME | MCI_SYSINFO_OPEN, (DWORD_PTR)&parm);
459     ok(!err || broken(err==MMSYSERR_NOTSUPPORTED/* Win9x */), "mciCommandW MCI_SYSINFO all name 1 open buffer[8]: %s\n", dbg_mcierr(err));
460     if(!err) ok(!strcmp_wa((LPWSTR)buf,"mysound"), "sysinfo name 1 open contents\n");
461
462     memset(buf, 0, sizeof(buf));
463     buf[0] = 'Y';
464     parm.sys.dwNumber = 1;
465     parm.sys.wDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; /* ignored */
466     parm.sys.lpstrReturn = buf;
467     parm.sys.dwRetSize = 7; /* too short for mysound\0 */
468     err = mciSendCommandW(MCI_ALL_DEVICE_ID, MCI_SYSINFO, MCI_SYSINFO_NAME | MCI_SYSINFO_OPEN, (DWORD_PTR)&parm);
469     ok(err==MCIERR_PARAM_OVERFLOW || broken(err==MMSYSERR_NOTSUPPORTED/* Win9x */), "mciCommandW MCI_SYSINFO all name 1 open too small: %s\n", dbg_mcierr(err));
470     ok(!strcmp(buf,"Y"), "output buffer %s\n", buf);
471
472     /* Win9x overwrites the tiny buffer and returns success, newer versions signal overflow. */
473     memset(buf, 0, sizeof(buf));
474     buf[0] = 'Y';
475     parm.sys.dwNumber = 1;
476     parm.sys.wDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; /* ignored */
477     parm.sys.lpstrReturn = buf;
478     parm.sys.dwRetSize = 2; /* too short for mysound\0 */
479     err = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_SYSINFO, MCI_SYSINFO_NAME | MCI_SYSINFO_OPEN, (DWORD_PTR)&parm);
480     ok(err==MCIERR_PARAM_OVERFLOW || broken(!err /* Win9x */),"mciCommand MCI_SYSINFO all name 1 open too small: %s\n", dbg_mcierr(err));
481     ok(!strcmp(buf, err ? "Y" : "mysound"), "sysinfo short name returned %s\n", buf);
482
483     err = mciSendString("sysinfo mysound quantity open", buf, sizeof(buf), hwnd);
484     ok(err==MCIERR_DEVICE_TYPE_REQUIRED,"sysinfo alias quantity: %s\n", dbg_mcierr(err));
485
486     err = mciSendString("sysinfo nosuchalias quantity open", buf, sizeof(buf), hwnd);
487     ok(err==MCIERR_DEVICE_TYPE_REQUIRED,"sysinfo unknown quantity open: %s\n", dbg_mcierr(err));
488
489     err = mciSendString("sysinfo all installname", buf, sizeof(buf), hwnd);
490     ok(err==MCIERR_CANNOT_USE_ALL,"sysinfo all installname: %s\n", dbg_mcierr(err));
491
492     buf[0] = 'M'; buf[1] = 0;
493     parm.sys.lpstrReturn = buf;
494     parm.sys.dwRetSize = sizeof(buf);
495     err = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_SYSINFO, MCI_SYSINFO_INSTALLNAME, (DWORD_PTR)&parm);
496     ok(err==MCIERR_CANNOT_USE_ALL,"mciCommand MCI_SYSINFO all installname: %s\n", dbg_mcierr(err));
497     ok(!strcmp(buf,"M"), "output buffer %s\n", buf);
498
499     err = mciSendString("sysinfo nodev installname", buf, sizeof(buf), hwnd);
500     ok(err==MCIERR_INVALID_DEVICE_NAME,"sysinfo nodev installname: %s\n", dbg_mcierr(err));
501     ok(!buf[0], "sysinfo error buffer %s\n", buf);
502
503     buf[0] = 'K';
504     parm.sys.lpstrReturn = buf;
505     parm.sys.dwRetSize = sizeof(buf);
506     err = mciSendCommandW(24000, MCI_SYSINFO, MCI_SYSINFO_INSTALLNAME, (DWORD_PTR)&parm);
507     ok(err==MCIERR_INVALID_DEVICE_NAME || broken(err==MMSYSERR_NOTSUPPORTED/* Win9x */), "mciCommand MCI_SYSINFO nodev installname: %s\n", dbg_mcierr(err));
508     ok(!strcmp(buf,"K"), "output buffer %s\n", buf);
509
510     buf[0] = 0; buf[1] = 'A'; buf[2] = 'j'; buf[3] = 0;
511     parm.info.lpstrReturn = buf;
512     parm.info.dwRetSize = 2;
513     err = mciSendCommandA(1, MCI_INFO, MCI_INFO_PRODUCT, (DWORD_PTR)&parm);
514     ok(!err, "mciCommand MCI_INFO product: %s\n", dbg_mcierr(err));
515     ok(buf[0] /* && !buf[1] */ && (buf[2] == 'j' || broken(!buf[2])), "info product output buffer %s\n", buf);
516     /* Producing non-ASCII multi-byte output, native forgets to zero-terminate a too small buffer
517      * with SendStringA, while SendStringW works correctly (jap. and chin. locale): ignore buf[1] */
518     /* Bug in 64 bit Vista/w2k8/w7: mciSendStringW is used! (not in xp nor w2k3) */
519
520     buf[0] = 'K'; buf[1] = 0;
521     parm.info.dwRetSize = sizeof(buf);
522     err = mciSendCommandW(1, MCI_INFO, 0x07000000, (DWORD_PTR)&parm);
523     ok(err==MCIERR_UNRECOGNIZED_KEYWORD || broken(err==MMSYSERR_NOTSUPPORTED/* Win9x */), "mciCommand MCI_INFO other: %s\n", dbg_mcierr(err));
524     ok(!strcmp(buf,"K"), "info output buffer %s\n", buf);
525
526     err = mciGetDeviceID("all");
527     ok(MCI_ALL_DEVICE_ID==err || /* Win9x */(WORD)MCI_ALL_DEVICE_ID==err,"mciGetDeviceID all returned %u, expected %d\n", err, MCI_ALL_DEVICE_ID);
528
529     err = mciSendString(command_close_my, NULL, 0, hwnd);
530     ok(!err,"mci %s returned %s\n", command_close_my, dbg_mcierr(err));
531     test_notification(hwnd, command_close_my, MCI_NOTIFY_SUCCESSFUL);
532     Sleep(5);
533     test_notification(hwnd, command_close_my, 0);
534
535     err = mciSendString("open no-such-file-exists.wav alias y buffer 6", buf, sizeof(buf), NULL);
536     ok(err==MCIERR_FILE_NOT_FOUND,"open no-such-file.wav returned %s\n", dbg_mcierr(err));
537     if(!err) {
538         err = mciSendString("close y", NULL, 0, NULL);
539         ok(!err,"close y returned %s\n", dbg_mcierr(err));
540     }
541
542     err = mciSendString("open no-such-dir\\file.wav alias y type waveaudio", buf, sizeof(buf), NULL);
543     ok(err==MCIERR_FILE_NOT_FOUND || broken(err==MCIERR_INVALID_FILE /* Win9X */),"open no-such-dir/file.wav returned %s\n", dbg_mcierr(err));
544     if(!err) {
545         err = mciSendString("close y", NULL, 0, NULL);
546         ok(!err,"close y returned %s\n", dbg_mcierr(err));
547     }
548
549     err = mciSendString("open ! alias no", buf, sizeof(buf), NULL);
550     ok(err==MCIERR_INVALID_DEVICE_NAME,"open !(void): %s\n", dbg_mcierr(err));
551
552     err = mciSendString("open !no-such-file-exists.wav alias no", buf, sizeof(buf), NULL);
553     ok(err==MCIERR_FILE_NOT_FOUND || /* Win9X */err==MCIERR_INVALID_DEVICE_NAME,"open !name: %s\n", dbg_mcierr(err));
554
555     /* FILE_NOT_FOUND stems from mciwave,
556      * the complete name including ! is passed through since NT */
557     err = mciSendString("open nosuchdevice!tempfile.wav alias no", buf, sizeof(buf), NULL);
558     ok(err==MCIERR_FILE_NOT_FOUND || /* Win9X */err==MCIERR_INVALID_DEVICE_NAME,"open nosuchdevice!name: %s\n", dbg_mcierr(err));
559     /* FIXME? use broken(INVALID_DEVICE_NAME) and have Wine not mimic Win9X? */
560
561     err = mciSendString("close waveaudio", buf, sizeof(buf), NULL);
562     ok(err==MCIERR_INVALID_DEVICE_NAME,"close waveaudio: %s\n", dbg_mcierr(err));
563
564     err = mciSendString(command_close_all, NULL, 0, NULL);
565     ok(!err,"mci %s (without buffer) returned %s\n", command_close_all, dbg_mcierr(err));
566
567     err = mciSendString(command_close_all, buf, sizeof(buf), hwnd);
568     ok(!err,"mci %s (with output buffer) returned %s\n", command_close_all, dbg_mcierr(err));
569     ok(buf[0] == 0, "mci %s output buffer: %s\n", command_close_all, buf);
570     /* No notification left, everything closed already */
571     test_notification(hwnd, command_close_all, 0);
572     /* TODO test close all sends one notification per open device */
573
574     err = mciSendString(command_sysinfo, buf, sizeof(buf), NULL);
575     ok(!err,"mci %s returned %s\n", command_sysinfo, dbg_mcierr(err));
576     ok(buf[0] == '0' && buf[1] == 0, "mci %s, expected output buffer '0', got: '%s'\n", command_sysinfo, buf);
577
578     err = mciSendString("open new type waveaudio", buf, sizeof(buf), NULL);
579     ok(err==MCIERR_NEW_REQUIRES_ALIAS,"mci open new without alias returned %s\n", dbg_mcierr(err));
580
581     parm.open.lpstrDeviceType = (LPSTR)MCI_DEVTYPE_WAVEFORM_AUDIO;
582     err = mciSendCommand(0, MCI_OPEN,
583         MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID,
584         (DWORD_PTR)&parm);
585     ok(!err,"mciCommand OPEN_TYPE_ID waveaudio: %s\n", dbg_mcierr(err));
586
587     if(!err) {
588         MCIDEVICEID wDeviceID = parm.open.wDeviceID;
589         parm.caps.dwItem = MCI_GETDEVCAPS_DEVICE_TYPE;
590         err = mciSendCommand(wDeviceID, MCI_GETDEVCAPS, MCI_GETDEVCAPS_ITEM, (DWORD_PTR)&parm);
591         ok(!err,"mciCommand MCI_GETDEVCAPS device type: %s\n", dbg_mcierr(err));
592         ok(MCI_DEVTYPE_WAVEFORM_AUDIO==parm.caps.dwReturn,"mciCommand GETDEVCAPS says %u, expected %u\n", parm.caps.dwReturn, MCI_DEVTYPE_WAVEFORM_AUDIO);
593     }
594
595     ok(0xDEADF00D==intbuf[0] && 0xABADCAFE==intbuf[2],"DWORD buffer corruption\n");
596
597     err = mciGetDeviceID("waveaudio");
598     ok(err==1,"mciGetDeviceID waveaudio returned %u, expected 0\n", err);
599
600     err = mciSendString("open no-such-file.wav alias waveaudio", buf, sizeof(buf), NULL);
601     ok(err==MCIERR_DUPLICATE_ALIAS, "mci open alias waveaudio returned %s\n", dbg_mcierr(err));
602     /* If it were not already in use, open avivideo alias waveaudio would succeed,
603      * making for funny test cases. */
604
605     err = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_WAIT, 0); /* from MSDN */
606     ok(!err,"mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_WAIT, 0) returned %s\n", dbg_mcierr(err));
607
608     err = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, 0);
609     ok(!err,"mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, 0) returned %s\n", dbg_mcierr(err));
610
611     parm.gen.dwCallback = (DWORD_PTR)hwnd;
612     err = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, (DWORD_PTR)&parm);
613     ok(!err,"mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, hwnd) returned %s\n", dbg_mcierr(err));
614     test_notification(hwnd, command_close_all, 0); /* None left */
615 }
616
617 static void test_recordWAVE(HWND hwnd)
618 {
619     WORD nch    = 1;
620     WORD nbits  = 16;
621     DWORD nsamp = 16000, expect;
622     UINT ndevs  = waveInGetNumDevs();
623     MCIERROR err, ok_pcm;
624     MCIDEVICEID wDeviceID;
625     MCI_PARMS_UNION parm;
626     char buf[1024];
627     memset(buf, 0, sizeof(buf));
628     test_notification(hwnd, "-prior to recording-", 0);
629
630     parm.open.lpstrDeviceType = "waveaudio";
631     parm.open.lpstrElementName = ""; /* "new" at the command level */
632     parm.open.lpstrAlias = "x"; /* to enable mciSendString */
633     parm.open.dwCallback = (DWORD_PTR)hwnd;
634     err = mciSendCommand(0, MCI_OPEN,
635         MCI_OPEN_ELEMENT | MCI_OPEN_TYPE | MCI_OPEN_ALIAS | MCI_NOTIFY,
636         (DWORD_PTR)&parm);
637     ok(!err,"mciCommand open new type waveaudio alias x notify: %s\n", dbg_mcierr(err));
638     wDeviceID = parm.open.wDeviceID;
639
640     err = mciGetDeviceID("x");
641     ok(err==wDeviceID,"mciGetDeviceID x returned %u, expected %u\n", err, wDeviceID);
642
643     /* Only the alias is looked up. */
644     err = mciGetDeviceID("waveaudio");
645     ok(err==0,"mciGetDeviceID waveaudio returned %u, expected 0\n", err);
646
647     test_notification(hwnd, "open new", MCI_NOTIFY_SUCCESSFUL);
648     test_notification(hwnd, "open new no #2", 0);
649
650     /* Do not query time format as string because result depends on locale! */
651     parm.status.dwItem = MCI_STATUS_TIME_FORMAT;
652     err = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
653     ok(!err,"mciCommand status time format: %s\n", dbg_mcierr(err));
654     ok(parm.status.dwReturn==MCI_FORMAT_MILLISECONDS,"status time format: %ld\n",parm.status.dwReturn);
655
656     /* Info file fails until named in Open or Save. */
657     err = mciSendString("info x file", buf, sizeof(buf), NULL);
658     todo_wine ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci info new file returned %s\n", dbg_mcierr(err));
659     ok(!buf[0], "info error buffer %s\n", buf);
660
661     err = mciSendString("status x length", buf, sizeof(buf), NULL);
662     todo_wine ok(!err,"status x length initial: %s\n", dbg_mcierr(err));
663     if(!err) ok(!strcmp(buf,"0"), "mci status length expected 0, got: %s\n", buf);
664
665     /* Check the default recording: 8-bits per sample, mono, 11kHz */
666     err = mciSendString("status x samplespersec", buf, sizeof(buf), NULL);
667     ok(!err,"mci status samplespersec returned %s\n", dbg_mcierr(err));
668     if(!err) ok(!strcmp(buf,"11025"), "mci status samplespersec expected 11025, got: %s\n", buf);
669
670     /* MCI seems to solely support PCM, no need for ACM conversion. */
671     err = mciSendString("set x format tag 2", NULL, 0, NULL);
672     ok(err==MCIERR_OUTOFRANGE,"mci set format tag 2 returned %s\n", dbg_mcierr(err));
673
674     /* MCI appears to scan the available devices for support of this format,
675      * returning MCIERR_OUTOFRANGE on machines with no sound.
676      * However some w2k8/w7 machines return no error when there's no wave
677      * input device (perhaps querying waveOutGetNumDevs instead of waveIn?),
678      * still the record command below fails with MCIERR_WAVE_INPUTSUNSUITABLE.
679      * Don't skip here, record will fail below. */
680     err = mciSendString("set x format tag pcm", NULL, 0, NULL);
681     ok(!err || err==MCIERR_OUTOFRANGE,"mci set format tag pcm returned %s\n", dbg_mcierr(err));
682     ok_pcm = err;
683
684     /* MSDN warns against not setting all wave format parameters.
685      * Indeed, it produces strange results, incl.
686      * inconsistent PCMWAVEFORMAT headers in the saved file.
687      */
688     err = mciSendString("set x bytespersec 22050 alignment 2 samplespersec 11025 channels 1 bitspersample 16", NULL, 0, NULL);
689     ok(err==ok_pcm,"mci set 5 wave parameters returned %s\n", dbg_mcierr(err));
690     /* Investigate: on w2k, set samplespersec 22050 sets nChannels to 2!
691      *  err = mciSendString("set x samplespersec 22050", NULL, 0, NULL);
692      *  ok(!err,"mci set samplespersec returned %s\n", dbg_mcierr(err));
693      */
694
695     /* Checks are generally performed immediately. */
696     err = mciSendString("set x bitspersample 4", NULL, 0, NULL);
697     todo_wine ok(err==MCIERR_OUTOFRANGE,"mci set bitspersample 4 returned %s\n", dbg_mcierr(err));
698
699     parm.set.wFormatTag = WAVE_FORMAT_PCM;
700     parm.set.nSamplesPerSec = nsamp;
701     parm.set.wBitsPerSample = nbits;
702     parm.set.nChannels      = nch;
703     parm.set.nBlockAlign    = parm.set.nChannels * parm.set.wBitsPerSample /8;
704     parm.set.nAvgBytesPerSec= parm.set.nSamplesPerSec * parm.set.nBlockAlign;
705     err = mciSendCommand(wDeviceID, MCI_SET,
706         MCI_WAVE_SET_SAMPLESPERSEC | MCI_WAVE_SET_CHANNELS |
707         MCI_WAVE_SET_BITSPERSAMPLE | MCI_WAVE_SET_BLOCKALIGN |
708         MCI_WAVE_SET_AVGBYTESPERSEC| MCI_WAVE_SET_FORMATTAG, (DWORD_PTR)&parm);
709     ok(err==ok_pcm,"mciCommand set wave format: %s\n", dbg_mcierr(err));
710
711     parm.caps.dwItem = MCI_WAVE_GETDEVCAPS_INPUTS;
712     parm.caps.dwCallback = (DWORD_PTR)hwnd;
713     err = mciSendCommand(wDeviceID, MCI_GETDEVCAPS, MCI_GETDEVCAPS_ITEM | MCI_NOTIFY, (DWORD_PTR)&parm);
714     ok(!err,"mciCommand MCI_GETDEVCAPS inputs: %s\n", dbg_mcierr(err));
715     ok(parm.caps.dwReturn==ndevs,"mciCommand GETDEVCAPS claims %u inputs, expected %u\n", parm.caps.dwReturn, ndevs);
716     ok(!ok_pcm || !parm.caps.dwReturn,"No input device accepts PCM!?\n");
717     test_notification(hwnd, "GETDEVCAPS inputs", MCI_NOTIFY_SUCCESSFUL);
718
719     /* A few ME machines pass all tests except set format tag pcm! */
720     err = mciSendString("record x to 2000 wait", NULL, 0, hwnd);
721     ok(err || !ok_pcm,"can record yet set wave format pcm returned %s\n", dbg_mcierr(ok_pcm));
722     if(!ndevs) todo_wine /* with sound disabled */
723     ok(ndevs>0 ? !err : err==MCIERR_WAVE_INPUTSUNSUITABLE,"mci record to 2000 returned %s\n", dbg_mcierr(err));
724     else
725     ok(ndevs>0 ? !err : err==MCIERR_WAVE_INPUTSUNSUITABLE,"mci record to 2000 returned %s\n", dbg_mcierr(err));
726     if(err) {
727         if (err==MCIERR_WAVE_INPUTSUNSUITABLE)
728              skip("Please install audio driver. Everything is skipped.\n");
729         else skip("Cannot record cause %s. Everything is skipped.\n", dbg_mcierr(err));
730
731         err = mciSendString("close x", NULL, 0, NULL);
732         ok(!err,"mci close returned %s\n", dbg_mcierr(err));
733         test_notification(hwnd,"record skipped",0);
734         return;
735     }
736
737     /* Query some wave format parameters depending on the time format. */
738     err = mciSendString("status x position", buf, sizeof(buf), NULL);
739     ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
740     if(!err) todo_wine ok(!strcmp(buf,"2000"), "mci status position gave %s, expected 2000, some tests will fail\n", buf);
741
742     err = mciSendString("set x time format 8", NULL, 0, NULL); /* bytes */
743     ok(!err,"mci returned %s\n", dbg_mcierr(err));
744
745     parm.status.dwItem = MCI_STATUS_POSITION;
746     err = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
747     ok(!err,"mciCommand status position: %s\n", dbg_mcierr(err));
748     expect = 2 * nsamp * nch * nbits/8;
749     if(!err) todo_wine ok(parm.status.dwReturn==expect,"recorded %lu bytes, expected %u\n",parm.status.dwReturn,expect);
750
751     parm.set.dwTimeFormat = MCI_FORMAT_SAMPLES;
752     err = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)&parm);
753     ok(!err,"mciCommand set time format samples: %s\n", dbg_mcierr(err));
754
755     parm.status.dwItem = MCI_STATUS_POSITION;
756     err = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
757     ok(!err,"mciCommand status position: %s\n", dbg_mcierr(err));
758     expect = 2 * nsamp;
759     if(!err) todo_wine ok(parm.status.dwReturn==expect,"recorded %lu samples, expected %u\n",parm.status.dwReturn,expect);
760
761     err = mciSendString("set x time format milliseconds", NULL, 0, NULL);
762     ok(!err,"mci set time format milliseconds returned %s\n", dbg_mcierr(err));
763
764     err = mciSendString("save x tempfile1.wav", NULL, 0, NULL);
765     ok(!err,"mci save returned %s\n", dbg_mcierr(err));
766
767     err = mciSendString("save x tempfile.wav", NULL, 0, NULL);
768     ok(!err,"mci save returned %s\n", dbg_mcierr(err));
769     if(!err) ok_saved = 0;
770
771     /* Save must not rename the original file. */
772     if (!DeleteFile("tempfile1.wav"))
773         todo_wine ok(FALSE, "Save must not rename the original file; DeleteFile returned %d\n", GetLastError());
774
775     err = mciSendString("set x channels 2", NULL, 0, NULL);
776     ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci set channels after saving returned %s\n", dbg_mcierr(err));
777
778     parm.seek.dwTo = 600;
779     err = mciSendCommand(wDeviceID, MCI_SEEK, MCI_TO | MCI_WAIT, (DWORD_PTR)&parm);
780     ok(!err,"mciCommand seek to 600: %s\n", dbg_mcierr(err));
781
782     /* Truncate to current position */
783     err = mciSendString("delete x", NULL, 0, NULL);
784     todo_wine ok(!err,"mci delete returned %s\n", dbg_mcierr(err));
785
786     err = mciSendString("status x length", buf, sizeof(buf), NULL);
787     ok(!err,"mci status length returned %s\n", dbg_mcierr(err));
788     todo_wine ok(!strcmp(buf,"600"), "mci status length after delete gave %s, expected 600\n", buf);
789
790     err = mciSendString("close x", NULL, 0, NULL);
791     ok(!err,"mci close returned %s\n", dbg_mcierr(err));
792     test_notification(hwnd,"record complete",0);
793 }
794
795 static void test_playWAVE(HWND hwnd)
796 {
797     MCIERROR err;
798     char buf[1024];
799     memset(buf, 0, sizeof(buf));
800
801     err = mciSendString("open waveaudio!tempfile.wav alias mysound", NULL, 0, NULL);
802     ok(err==ok_saved,"mci open waveaudio!tempfile.wav returned %s\n", dbg_mcierr(err));
803     if(err) {
804         skip("Cannot open waveaudio!tempfile.wav for playing (%s), skipping\n", dbg_mcierr(err));
805         return;
806     }
807
808     err = mciGetDeviceID("mysound");
809     ok(err==1,"mciGetDeviceID mysound returned %u, expected 1\n", err);
810
811     err = mciGetDeviceID("tempfile.wav");
812     ok(err==0,"mciGetDeviceID tempfile.wav returned %u, expected 0\n", err);
813
814     err = mciGetDeviceID("waveaudio");
815     ok(err==0,"mciGetDeviceID waveaudio returned %u, expected 0\n", err);
816
817     err = mciSendString("status mysound length", buf, sizeof(buf), NULL);
818     ok(!err,"mci status length returned %s\n", dbg_mcierr(err));
819     todo_wine ok(!strcmp(buf,"2000"), "mci status length gave %s, expected 2000, some tests will fail.\n", buf);
820
821     err = mciSendString("cue output", NULL, 0, NULL);
822     ok(err==MCIERR_UNRECOGNIZED_COMMAND,"mci incorrect cue output returned %s\n", dbg_mcierr(err));
823
824     /* Test MCI to the bones -- Some todo_wine from Cue and
825      * from Play from 0 to 0 are not worth fixing. */
826     err = mciSendString("cue mysound output notify", NULL, 0, hwnd);
827     ok(!err,"mci cue output after open file returned %s\n", dbg_mcierr(err));
828     /* Notification is delayed as a play thread is started. */
829     todo_wine test_notification(hwnd, "cue immediate", 0);
830
831     /* Cue pretends to put the MCI into paused state. */
832     err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
833     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
834     todo_wine ok(!strcmp(buf,"paused"), "mci status mode: %s, expected (pseudo)paused\n", buf);
835
836     /* Strange pause where Pause is rejected, unlike Play; Pause; Pause tested below */
837     err = mciSendString("pause mysound", NULL, 0, hwnd);
838     ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci pause after cue returned %s\n", dbg_mcierr(err));
839
840     /* MCI appears to start the play thread in this border case.
841      * Guessed that from (flaky) status mode and late notification arrival. */
842     err = mciSendString("play mysound from 0 to 0 notify", NULL, 0, hwnd);
843     ok(!err,"mci play from 0 to 0 returned %s\n", dbg_mcierr(err));
844     todo_wine test_notification(hwnd, "cue aborted by play", MCI_NOTIFY_ABORTED);
845     /* play's own notification follows below */
846
847     err = mciSendString("play mysound from 250 to 0", NULL, 0, NULL);
848     ok(err==MCIERR_OUTOFRANGE,"mci play from 250 to 0 returned %s\n", dbg_mcierr(err));
849
850     Sleep(50); /* Give play from 0 to 0 time to finish. */
851     todo_wine test_notification(hwnd, "play from 0 to 0", MCI_NOTIFY_SUCCESSFUL);
852
853     err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
854     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
855     ok(!strcmp(buf,"stopped"), "mci status mode: %s after play from 0 to 0\n", buf);
856
857     err = mciSendString("play MYSOUND from 250 to 0 notify", NULL, 0, hwnd);
858     ok(err==MCIERR_OUTOFRANGE,"mci play from 250 to 0 notify returned %s\n", dbg_mcierr(err));
859     /* No notification (checked below) sent if error */
860
861     /* A second play caused Wine<1.1.33 to hang */
862     err = mciSendString("play mysound from 500 to 220:5:0 wait", NULL, 0, NULL);
863     ok(!err,"mci play from 500 to 220:5:0 (=1500) returned %s\n", dbg_mcierr(err));
864
865     err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
866     ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
867     if(!err) ok(!strcmp(buf,"1500"), "mci status position: %s\n", buf);
868
869     /* mci will not play position < current */
870     err = mciSendString("play mysound to 1000", NULL, 0, NULL);
871     ok(err==MCIERR_OUTOFRANGE,"mci play to 1000 returned %s\n", dbg_mcierr(err));
872
873     /* mci will not play to > end */
874     err = mciSendString("play mysound TO 3000 notify", NULL, 0, hwnd);
875     ok(err==MCIERR_OUTOFRANGE,"mci play to 3000 notify returned %s\n", dbg_mcierr(err));
876
877     err = mciSendString("play mysound to 2000", NULL, 0, NULL);
878     ok(!err,"mci play to 2000 returned %s\n", dbg_mcierr(err));
879
880     /* Rejected while playing */
881     err = mciSendString("cue mysound output", NULL, 0, NULL);
882     ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci cue output while playing returned %s\n", dbg_mcierr(err));
883
884     err = mciSendString("play mysound to 3000", NULL, 0, NULL);
885     ok(err==MCIERR_OUTOFRANGE,"mci play to 3000 returned %s\n", dbg_mcierr(err));
886
887     err = mciSendString("stop mysound Wait", NULL, 0, NULL);
888     ok(!err,"mci stop wait returned %s\n", dbg_mcierr(err));
889     test_notification(hwnd, "play/cue/pause/stop", 0);
890
891     err = mciSendString("Seek Mysound to 250 wait Notify", NULL, 0, hwnd);
892     ok(!err,"mci seek to 250 wait notify returned %s\n", dbg_mcierr(err));
893     test_notification(hwnd,"seek wait notify",MCI_NOTIFY_SUCCESSFUL);
894
895     err = mciSendString("seek mysound to 0xfa", NULL, 0, NULL);
896     ok(err==MCIERR_BAD_INTEGER,"mci seek to 0xfa returned %s\n", dbg_mcierr(err));
897
898     /* MCI_INTEGER always accepts colon notation */
899     err = mciSendString("seek mysound to :1", NULL, 0, NULL);
900     ok(!err,"mci seek to :1 (=256) returned %s\n", dbg_mcierr(err));
901
902     err = mciSendString("seek mysound to 250::", NULL, 0, NULL);
903     ok(!err,"mci seek to 250:: returned %s\n", dbg_mcierr(err));
904
905     err = mciSendString("seek mysound to 250:0", NULL, 0, NULL);
906     ok(!err,"mci seek to 250:0 returned %s\n", dbg_mcierr(err));
907
908     err = mciSendString("status mysound position notify", buf, sizeof(buf), hwnd);
909     ok(!err,"mci status position notify returned %s\n", dbg_mcierr(err));
910     if(!err) ok(!strcmp(buf,"250"), "mci status position: %s\n", buf);
911     /* Immediate commands like status also send notifications. */
912     test_notification(hwnd,"status position",MCI_NOTIFY_SUCCESSFUL);
913
914     err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
915     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
916     ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
917
918     /* Another play from == to testcase */
919     err = mciSendString("play mysound to 250 wait notify", NULL, 0, hwnd);
920     ok(!err,"mci play (from 250) to 250 returned %s\n", dbg_mcierr(err));
921     todo_wine test_notification(hwnd,"play to 250 wait notify",MCI_NOTIFY_SUCCESSFUL);
922
923     err = mciSendString("cue mysound output", NULL, 0, NULL);
924     ok(!err,"mci cue output after play returned %s\n", dbg_mcierr(err));
925
926     err = mciSendString("close mysound", NULL, 0, NULL);
927     ok(!err,"mci close returned %s\n", dbg_mcierr(err));
928     test_notification(hwnd,"after close",0);
929 }
930
931 static void test_asyncWAVE(HWND hwnd)
932 {
933     MCIDEVICEID wDeviceID;
934     MCI_PARMS_UNION parm;
935     int err, p1, p2;
936     char buf[1024];
937     memset(buf, 0, sizeof(buf));
938
939     err = mciSendString("open tempfile.wav alias mysound notify type waveaudio", buf, sizeof(buf), hwnd);
940     ok(err==ok_saved,"mci open tempfile.wav returned %s\n", dbg_mcierr(err));
941     if(err) {
942         skip("Cannot open tempfile.wav for playing (%s), skipping\n", dbg_mcierr(err));
943         return;
944     }
945     ok(!strcmp(buf,"1"), "mci open deviceId: %s, expected 1\n", buf);
946     wDeviceID = atoi(buf);
947     ok(wDeviceID,"mci open DeviceID: %d\n", wDeviceID);
948     test_notification(hwnd,"open alias notify",MCI_NOTIFY_SUCCESSFUL);
949
950     err = mciGetDeviceID("mysound");
951     ok(err==wDeviceID,"mciGetDeviceID alias returned %u, expected %u\n", err, wDeviceID);
952
953     /* Only the alias is looked up. */
954     err = mciGetDeviceID("tempfile.wav");
955     ok(err==0,"mciGetDeviceID tempfile.wav returned %u, expected 0\n", err);
956
957     err = mciGetDeviceID("waveaudio");
958     ok(err==0,"mciGetDeviceID waveaudio returned %u, expected 0\n", err);
959
960     err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
961     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
962     ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
963
964     err = mciSendString("play mysound notify", NULL, 0, hwnd);
965     ok(!err,"mci play returned %s\n", dbg_mcierr(err));
966
967     Sleep(500); /* milliseconds */
968
969     /* Do not query time format as string because result depends on locale! */
970     parm.status.dwItem = MCI_STATUS_TIME_FORMAT;
971     err = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
972     ok(!err,"mciCommand status time format: %s\n", dbg_mcierr(err));
973     if(!err) ok(parm.status.dwReturn==MCI_FORMAT_MILLISECONDS,"status time format: %ld\n",parm.status.dwReturn);
974
975     parm.set.dwTimeFormat = MCI_FORMAT_MILLISECONDS;
976     err = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)&parm);
977     ok(!err,"mciCommand set time format ms: %s\n", dbg_mcierr(err));
978
979     err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
980     ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
981     trace("position after Sleep: %sms\n", buf);
982     p2 = atoi(buf);
983     /* Check that the 2s sound plays at a normal pace, giving a wide margin to
984      * account for timing granularity and small delays.
985      */
986     todo_wine ok(400 <= p2 && p2 <= 600, "%ums is not in the expected 400-600ms range\n", p2);
987     /* Wine's asynchronous thread needs some time to start up. Furthermore, it
988      * uses 3 buffers per second, so that the positions reported will be 333ms,
989      * 667ms etc. at best, which is why it fails the above test. So add a
990      * second test specifically to prevent Wine from getting even worse.
991      * FIXME: To be removed when Wine is fixed and passes the above test.
992      */
993     ok(400 <= p2 && p2 <= 1000, "%ums is not even in the expected 400-1000ms range\n", p2);
994     test_notification(hwnd,"play (nowait)",0);
995
996     err = mciSendString("pause mysound wait", NULL, 0, hwnd);
997     ok(!err,"mci pause wait returned %s\n", dbg_mcierr(err));
998
999     err = mciSendString("status mysound mode notify", buf, sizeof(buf), hwnd);
1000     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
1001     if(!err) ok(!strcmp(buf,"paused"), "mci status mode: %s\n", buf);
1002     test_notification(hwnd,"play",MCI_NOTIFY_SUPERSEDED);
1003     test_notification(hwnd,"status",MCI_NOTIFY_SUCCESSFUL);
1004
1005     err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
1006     ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
1007     trace("position while paused: %sms\n",buf);
1008     p1 = atoi(buf);
1009     ok(p1>=p2, "position not increasing: %u > %u\n", p2, p1);
1010
1011     err = mciSendString("stop mysound wait", NULL, 0, NULL);
1012     ok(!err,"mci stop returned %s\n", dbg_mcierr(err));
1013
1014     err = mciSendString("info mysound file notify", buf, sizeof(buf), hwnd);
1015     ok(!err,"mci info file returned %s\n", dbg_mcierr(err));
1016     if(!err) { /* fully qualified name */
1017         int len = strlen(buf);
1018         todo_wine ok(len>2 && buf[1]==':',"Expected full pathname from info file: %s\n", buf);
1019         ok(len>=12 && !strcmp(&buf[len-12],"tempfile.wav"), "info file returned: %s\n", buf);
1020     }
1021     test_notification(hwnd,"info file",MCI_NOTIFY_SUCCESSFUL);
1022
1023     err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
1024     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
1025     ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
1026
1027     err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
1028     ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
1029     trace("position once stopped: %sms\n",buf);
1030     p2 = atoi(buf);
1031     /* An XP machine let the position increase slightly after pause. */
1032     ok(p2>=p1 && p2<=p1+16,"position changed from %ums to %ums\n",p1,p2);
1033
1034     /* No Resume once stopped (waveaudio, sequencer and cdaudio differ). */
1035     err = mciSendString("resume mysound wait", NULL, 0, NULL);
1036     ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci resume wait returned %s\n", dbg_mcierr(err));
1037
1038     err = mciSendString("play mysound wait", NULL, 0, NULL);
1039     ok(!err,"mci play wait returned %s\n", dbg_mcierr(err));
1040
1041     err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
1042     ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
1043     todo_wine ok(!strcmp(buf,"2000"), "mci status position: %s\n", buf);
1044
1045     err = mciSendString("seek mysound to start wait", NULL, 0, NULL);
1046     ok(!err,"mci seek to start wait returned %s\n", dbg_mcierr(err));
1047
1048     err = mciSendString("play mysound to 1000 notify", NULL, 0, hwnd);
1049     ok(!err,"mci play returned %s\n", dbg_mcierr(err));
1050
1051     /* Sleep(200); not needed with Wine any more. */
1052
1053     err = mciSendString("pause mysound notify", NULL, 0, NULL); /* notify no callback */
1054     ok(!err,"mci pause notify returned %s\n", dbg_mcierr(err));
1055     /* Supersede even though pause cannot notify given no callback */
1056     test_notification(hwnd,"pause aborted play #1 notification",MCI_NOTIFY_SUPERSEDED);
1057     test_notification(hwnd,"impossible pause notification",0);
1058
1059     err = mciSendString("cue mysound output notify", NULL, 0, hwnd);
1060     ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci cue output while paused returned %s\n", dbg_mcierr(err));
1061     test_notification(hwnd,"cue output notify #2",0);
1062
1063     err = mciSendString("resume mysound notify", NULL, 0, hwnd);
1064     ok(!err,"mci resume notify returned %s\n", dbg_mcierr(err));
1065     test_notification(hwnd, "resume notify", MCI_NOTIFY_SUCCESSFUL);
1066
1067     /* Seek or even Stop used to hang Wine<1.1.32 on MacOS. */
1068     err = mciSendString("seek mysound to 0 wait", NULL, 0, NULL);
1069     ok(!err,"mci seek to start returned %s\n", dbg_mcierr(err));
1070
1071     /* Seek stops. */
1072     err = mciSendString("status mysound mode", buf, sizeof(buf), NULL);
1073     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
1074     if(!err) ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
1075
1076     err = mciSendString("seek mysound wait", NULL, 0, NULL);
1077     ok(err==MCIERR_MISSING_PARAMETER,"mci seek to nowhere returned %s\n", dbg_mcierr(err));
1078
1079     /* cdaudio does not detect to start to end as error */
1080     err = mciSendString("seek mysound to start to 0", NULL, 0, NULL);
1081     ok(err==MCIERR_FLAGS_NOT_COMPATIBLE,"mci seek to start to 0 returned %s\n", dbg_mcierr(err));
1082
1083     err = mciSendString("PLAY mysound to 1000 notify", NULL, 0, hwnd);
1084     ok(!err,"mci play to 1000 notify returned %s\n", dbg_mcierr(err));
1085
1086     /* Sleep(200); not needed with Wine any more. */
1087     /* Give it 400ms and resume will appear to complete below. */
1088
1089     err = mciSendString("pause mysound wait", NULL, 0, NULL);
1090     ok(!err,"mci pause wait returned %s\n", dbg_mcierr(err));
1091     /* Unlike sequencer and cdaudio, waveaudio's pause does not abort. */
1092     test_notification(hwnd,"pause aborted play #2 notification",0);
1093
1094     err = mciSendString("resume mysound wait", NULL, 0, NULL);
1095     ok(!err,"mci resume wait returned %s\n", dbg_mcierr(err));
1096     /* Resume is a short asynchronous call, something else is playing. */
1097
1098     err = mciSendString("status mysound mode", buf, sizeof(buf), NULL);
1099     ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
1100     if(!err) ok(!strcmp(buf,"playing"), "mci status mode: %s\n", buf);
1101
1102     /* Note extra space before alias */
1103     err = mciSendString("pause  mysound wait", NULL, 0, NULL);
1104     todo_wine ok(!err,"mci pause (space) wait returned %s\n", dbg_mcierr(err));
1105
1106     err = mciSendString("pause mysound wait", NULL, 0, NULL);
1107     ok(!err,"mci pause wait returned %s\n", dbg_mcierr(err));
1108
1109     /* Better ask position only when paused, is it updated while playing? */
1110     err = mciSendString("status mysound position", buf, sizeof(buf), NULL);
1111     ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
1112     /* TODO compare position < 900 */
1113     ok(strcmp(buf,"1000"), "mci resume waited\n");
1114     ok(strcmp(buf,"2000"), "mci resume played to end\n");
1115     trace("position after resume: %sms\n",buf);
1116     test_notification(hwnd,"play (aborted by pause/resume/pause)",0);
1117
1118     err = mciSendString("close mysound wait", NULL, 0, NULL);
1119     ok(!err,"mci close wait returned %s\n", dbg_mcierr(err));
1120     test_notification(hwnd,"play (aborted by close)",MCI_NOTIFY_ABORTED);
1121 }
1122
1123 static void test_AutoOpenWAVE(HWND hwnd)
1124 {
1125     /* This test used(?) to cause intermittent crashes when Wine exits, after
1126      * fixme:winmm:MMDRV_Exit Closing while ll-driver open
1127      */
1128     UINT ndevs = waveOutGetNumDevs();
1129     MCIERROR err, ok_snd = ndevs ? 0 : MCIERR_HARDWARE;
1130     MCI_PARMS_UNION parm;
1131     char buf[512], path[300], command[330];
1132     DWORD intbuf[3] = { 0xDEADF00D, 99, 0xABADCAFE };
1133     memset(buf, 0, sizeof(buf)); memset(path, 0, sizeof(path));
1134
1135     /* Do not crash on NULL buffer pointer */
1136     err = mciSendString("sysinfo waveaudio quantity open", NULL, 0, NULL);
1137     ok(err==MCIERR_PARAM_OVERFLOW,"mci sysinfo without buffer returned %s\n", dbg_mcierr(err));
1138
1139     err = mciSendString("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL);
1140     ok(!err,"mci sysinfo waveaudio quantity open returned %s\n", dbg_mcierr(err));
1141     if(!err) ok(!strcmp(buf,"0"), "sysinfo quantity open expected 0, got: %s, some more tests will fail.\n", buf);
1142
1143     /* Who knows why some MS machines pass all tests but return MCIERR_HARDWARE here? */
1144     /* Wine returns MCIERR_HARDWARE when no default sound is found in win.ini or the registry. */
1145     err = mciSendString("sound NoSuchSoundDefined wait", NULL, 0, NULL);
1146     ok(err==ok_snd || err==MCIERR_HARDWARE, "mci sound NoSuchSoundDefined returned %s\n", dbg_mcierr(err));
1147
1148     err = mciSendString("sound SystemExclamation notify wait", NULL, 0, hwnd);
1149     ok(err==ok_snd || err==MCIERR_HARDWARE, "mci sound SystemExclamation returned %s\n", dbg_mcierr(err));
1150     test_notification(hwnd, "sound notify", err ? 0 : MCI_NOTIFY_SUCCESSFUL);
1151
1152     Sleep(16); /* time to auto-close makes sysinfo below return expected error */
1153     err = mciSendString("sysinfo waveaudio notify name 1 open", buf, sizeof(buf), hwnd);
1154     ok(err==MCIERR_OUTOFRANGE,"sysinfo waveaudio name 1 returned %s\n", dbg_mcierr(err));
1155     if(!err) trace("sysinfo dangling open alias: %s\n", buf);
1156     test_notification(hwnd, "sysinfo name outofrange\n", err ? 0 : MCI_NOTIFY_SUCCESSFUL);
1157
1158     err = mciSendString("play no-such-file-exists.wav notify", buf, sizeof(buf), NULL);
1159     todo_wine ok(err==MCIERR_NOTIFY_ON_AUTO_OPEN,"mci auto-open notify returned %s\n", dbg_mcierr(err));
1160     /* FILE_NOT_FOUND in Wine because auto-open fails before testing the notify flag */
1161
1162     test_notification(hwnd, "-prior to auto-open-", 0);
1163
1164     err = mciSendString("play tempfile.wav notify", buf, sizeof(buf), hwnd);
1165     if(ok_saved==MCIERR_FILE_NOT_FOUND) todo_wine /* same as above */
1166     ok(err==MCIERR_NOTIFY_ON_AUTO_OPEN,"mci auto-open play notify returned %s\n", dbg_mcierr(err));
1167     else
1168     ok(err==MCIERR_NOTIFY_ON_AUTO_OPEN,"mci auto-open play notify returned %s\n", dbg_mcierr(err));
1169
1170     if(err) /* FIXME: don't open twice yet, it confuses Wine. */
1171     err = mciSendString("play tempfile.wav", buf, sizeof(buf), hwnd);
1172     ok(err==ok_saved,"mci auto-open play returned %s\n", dbg_mcierr(err));
1173
1174     if(err==MCIERR_FILE_NOT_FOUND) {
1175         skip("Cannot open tempfile.wav for auto-play, skipping\n");
1176         return;
1177     }
1178
1179     err = mciSendString("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL);
1180     ok(!err,"mci sysinfo waveaudio quantity after auto-open returned %s\n", dbg_mcierr(err));
1181     if(!err) ok(!strcmp(buf,"1"), "sysinfo quantity open expected 1, got: %s\n", buf);
1182
1183     parm.sys.lpstrReturn = (LPSTR)&intbuf[1];
1184     parm.sys.dwRetSize = 2*sizeof(DWORD); /* only one DWORD is used */
1185     parm.sys.wDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO;
1186     err = mciSendCommand(0, MCI_SYSINFO, MCI_SYSINFO_QUANTITY | MCI_SYSINFO_OPEN, (DWORD_PTR)&parm);
1187     ok(!err,"mciSendCommand(0(WAVEAUDIO), MCI_SYSINFO, OPEN | MCI_NOTIFY) returned %s\n", dbg_mcierr(err));
1188     if(!err) ok(atoi(buf)==intbuf[1],"sysinfo waveaudio quantity open string and command differ\n");
1189
1190     err = mciSendString("sysinfo waveaudio name 1 open notify", buf, sizeof(buf), hwnd);
1191     ok(!err,"mci sysinfo waveaudio name after auto-open returned %s\n", dbg_mcierr(err));
1192     /* This is the alias, not necessarily a file name. */
1193     if(!err) ok(!strcmp(buf,"tempfile.wav"), "sysinfo name 1 open: %s\n", buf);
1194     test_notification(hwnd, "sysinfo name notify\n", MCI_NOTIFY_SUCCESSFUL);
1195
1196     err = mciGetDeviceID("tempfile.wav");
1197     ok(err==1,"mciGetDeviceID tempfile.wav returned %u, expected 1\n", err);
1198
1199     /* Save the full pathname to the file. */
1200     err = mciSendString("info tempfile.wav file", path, sizeof(path), NULL);
1201     ok(!err,"mci info tempfile.wav file returned %s\n", dbg_mcierr(err));
1202     if(err) strcpy(path,"tempfile.wav");
1203
1204     err = mciSendString("status tempfile.wav mode", NULL, 0, hwnd);
1205     ok(!err,"mci status tempfile.wav mode without buffer returned %s\n", dbg_mcierr(err));
1206
1207     sprintf(command,"status \"%s\" mode",path);
1208     err = mciSendString(command, buf, sizeof(buf), hwnd);
1209     ok(!err,"mci status \"%s\" mode returned %s\n", path, dbg_mcierr(err));
1210
1211     err = mciSendString("status tempfile.wav mode", buf, sizeof(buf), hwnd);
1212     ok(!err,"mci status tempfile.wav mode returned %s\n", dbg_mcierr(err));
1213     if(!err) ok(!strcmp(buf,"playing"), "mci auto-open status mode, got: %s\n", buf);
1214
1215     err = mciSendString("open tempfile.wav", buf, sizeof(buf), NULL);
1216     ok(err==MCIERR_DEVICE_OPEN, "mci open from auto-open returned %s\n", dbg_mcierr(err));
1217
1218     err = mciSendString("open foo.wav alias tempfile.wav", buf, sizeof(buf), NULL);
1219     ok(err==MCIERR_DUPLICATE_ALIAS, "mci open re-using alias returned %s\n", dbg_mcierr(err));
1220
1221     /* w2k/xp and Wine differ. While the device is busy playing, it is
1222      * regularly open and accessible via the filename: subsequent
1223      * commands must not cause auto-open each.  In Wine, a subsequent
1224      * command with notify request may cause the initial play
1225      * notification to be superseded, in turn causing MCI to close the
1226      * device.  I.e. MCI uses the auto-open notification for itself,
1227      * that's why it's not available to the app.  On w2k/xp,
1228      * subsequent commands with notify requests are returned with
1229      * MCIERR_NOTIFY_ON_AUTO_OPEN and thus don't abort the original
1230      * command.
1231      */
1232     err = mciSendString("status tempfile.wav mode notify", buf, sizeof(buf), hwnd);
1233     todo_wine ok(err==MCIERR_NOTIFY_ON_AUTO_OPEN, "mci status auto-open notify returned %s\n", dbg_mcierr(err));
1234     if(!err) {
1235         trace("Wine style MCI auto-close upon notification\n");
1236
1237         /* "playing" because auto-close comes after the status call. */
1238         ok(!strcmp(buf,"playing"), "mci auto-open status mode notify, got: %s\n", buf);
1239         /* fixme:winmm:MMDRV_Exit Closing while ll-driver open
1240          *  is explained by failure to auto-close a device. */
1241         test_notification(hwnd,"status notify",MCI_NOTIFY_SUCCESSFUL);
1242         /* MCI received NOTIFY_SUPERSEDED and auto-closed the device. */
1243
1244         /* Until this is implemented, force closing the device */
1245         err = mciSendString("close tempfile.wav", NULL, 0, hwnd);
1246         ok(!err,"mci auto-still-open stop returned %s\n", dbg_mcierr(err));
1247         Sleep(16);
1248         test_notification(hwnd,"auto-open",0);
1249     } else if(err==MCIERR_NOTIFY_ON_AUTO_OPEN) { /* MS style */
1250         trace("MS style MCI auto-open forbids notification\n");
1251
1252         err = mciSendString("pause tempfile.wav", NULL, 0, hwnd);
1253         ok(!err,"mci auto-still-open pause returned %s\n", dbg_mcierr(err));
1254
1255         err = mciSendString("status tempfile.wav mode", buf, sizeof(buf), hwnd);
1256         ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
1257         if(!err) ok(!strcmp(buf,"paused"), "mci auto-open status mode, got: %s\n", buf);
1258
1259         /* Auto-close */
1260         err = mciSendString("stop tempfile.wav wait", NULL, 0, hwnd);
1261         ok(!err,"mci auto-still-open stop returned %s\n", dbg_mcierr(err));
1262         Sleep(16); /* makes sysinfo quantity open below succeed */
1263     }
1264
1265     err = mciSendString("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL);
1266     ok(!err,"mci sysinfo waveaudio quantity open after close returned %s\n", dbg_mcierr(err));
1267     if(!err) ok(!strcmp(buf,"0"), "sysinfo quantity open expected 0 after auto-close, got: %s\n", buf);
1268
1269     /* w95-WinME (not w2k/XP) switch to C:\ after auto-playing once.  Prevent
1270      * MCIERR_FILE_NOT_FOUND by using the full path name from the Info file command.
1271      */
1272     sprintf(command,"status \"%s\" mode wait",path);
1273     err = mciSendString(command, buf, sizeof(buf), hwnd);
1274     ok(!err,"mci re-auto-open status mode returned %s\n", dbg_mcierr(err));
1275     if(!err) ok(!strcmp(buf,"stopped"), "mci re-auto-open status mode, got: %s\n", buf);
1276
1277     /* This uses auto-open as well. */
1278     err = mciSendString("capability waveaudio outputs", buf, sizeof(buf), NULL);
1279     ok(!err,"mci capability waveaudio outputs returned %s\n", dbg_mcierr(err));
1280     /* Wine with no sound selected in winecfg's audio tab fails this test. */
1281     if(!err) ok(atoi(buf)==ndevs,"Expected %d audio outputs, got %s\n", ndevs, buf);
1282
1283     err = mciSendString("capability waveaudio device type", buf, sizeof(buf), hwnd);
1284     ok(!err,"mci capability device type returned %s\n", dbg_mcierr(err));
1285     if(!err) ok(!strcmp(buf,"waveaudio"), "mci capability device type response: %s\n", buf);
1286
1287     /* waveaudio forbids Pause without Play. */
1288     sprintf(command,"pause \"%s\"",path);
1289     err = mciSendString(command, NULL, 0, hwnd);
1290     ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci auto-open pause returned %s\n", dbg_mcierr(err));
1291
1292     ok(0xDEADF00D==intbuf[0] && 0xABADCAFE==intbuf[2],"DWORD buffer corruption\n");
1293 }
1294
1295 START_TEST(mci)
1296 {
1297     MCIERROR err;
1298     HWND hwnd;
1299     hwnd = CreateWindowExA(0, "static", "winmm test", WS_POPUP, 0,0,100,100,
1300                            0, 0, 0, NULL);
1301     test_mciParser(hwnd);
1302     test_openCloseWAVE(hwnd);
1303     test_recordWAVE(hwnd);
1304     if(waveOutGetNumDevs()){
1305         test_playWAVE(hwnd);
1306         test_asyncWAVE(hwnd);
1307         test_AutoOpenWAVE(hwnd);
1308     }else
1309         skip("No output devices available, skipping all output tests\n");
1310     /* Win9X hangs when exiting with something still open. */
1311     err = mciSendString("close all", NULL, 0, hwnd);
1312     ok(!err,"final close all returned %s\n", dbg_mcierr(err));
1313     ok(DeleteFile("tempfile.wav")||ok_saved,"Delete tempfile.wav (cause auto-open?)\n");
1314     DestroyWindow(hwnd);
1315 }