riched20: Implement ITextRange::GetChar.
[wine/multimedia.git] / dlls / winmm / tests / mci.c
blobc162fce9e802bc3a6697719593e0010dbea71085
1 /*
2 * Test winmm mci
4 * Copyright 2006 Jan Zerebecki
5 * 2009 Jörg Höhle
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.
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.
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
22 #include <stdio.h>
23 #include "windows.h"
24 #include "mmsystem.h"
25 #include "mmreg.h"
26 #include "wine/test.h"
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;
32 typedef union {
33 MCI_INFO_PARMSA info;
34 MCI_STATUS_PARMS status;
35 MCI_WAVE_SET_PARMS set;
36 MCI_WAVE_OPEN_PARMSA open;
37 MCI_GETDEVCAPS_PARMS caps;
38 MCI_SYSINFO_PARMSA sys;
39 MCI_SEEK_PARMS seek;
40 MCI_GENERIC_PARMS gen;
41 } MCI_PARMS_UNION;
43 const char* dbg_mcierr(MCIERROR err)
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;
132 static BOOL spurious_message(LPMSG msg)
134 /* WM_DEVICECHANGE 0x0219 appears randomly */
135 if(msg->message != MM_MCINOTIFY) {
136 trace("skipping spurious message %04x\n",msg->message);
137 return TRUE;
139 return FALSE;
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);
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);
166 static int strcmp_wa(LPCWSTR strw, const char *stra)
168 CHAR buf[512];
169 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), 0, 0);
170 return lstrcmpA(buf, stra);
173 static void test_mciParser(HWND hwnd)
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);
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 mciSendStringA */
186 parm.open.dwCallback = (DWORD_PTR)hwnd;
187 err = mciSendCommandA(0, MCI_OPEN,
188 MCI_OPEN_ELEMENT | MCI_OPEN_TYPE | MCI_OPEN_ALIAS | MCI_NOTIFY, (DWORD_PTR)&parm);
189 ok(!err,"mciCommand open new type waveaudio alias x notify: %s\n", dbg_mcierr(err));
190 wDeviceID = parm.open.wDeviceID;
191 ok(!strcmp(parm.open.lpstrDeviceType,"waveaudio"), "open modified device type\n");
193 test_notification(hwnd, "MCI_OPEN", MCI_NOTIFY_SUCCESSFUL);
194 test_notification(hwnd, "MCI_OPEN no #2", 0);
196 err = mciSendStringA("open avivideo alias a", buf, sizeof(buf), hwnd);
197 ok(!err,"open another: %s\n", dbg_mcierr(err));
199 buf[0]='z';
200 err = mciSendStringA("", buf, sizeof(buf), NULL);
201 todo_wine ok(err==MCIERR_MISSING_COMMAND_STRING,"empty string: %s\n", dbg_mcierr(err));
202 ok(!buf[0], "error buffer %s\n", buf);
204 buf[0]='d';
205 err = mciSendStringA("open", buf, sizeof(buf), NULL);
206 ok(err==MCIERR_MISSING_DEVICE_NAME,"open void: %s\n", dbg_mcierr(err));
207 ok(!buf[0], "open error buffer %s\n", buf);
209 err = mciSendStringA("open notify", buf, sizeof(buf), NULL);
210 todo_wine ok(err==MCIERR_INVALID_DEVICE_NAME,"open notify: %s\n", dbg_mcierr(err));
212 err = mciSendStringA("open new", buf, sizeof(buf), NULL);
213 todo_wine ok(err==MCIERR_NEW_REQUIRES_ALIAS,"open new: %s\n", dbg_mcierr(err));
215 err = mciSendStringA("open new type waveaudio alias r shareable shareable", buf, sizeof(buf), NULL);
216 todo_wine ok(err==MCIERR_DUPLICATE_FLAGS,"open new: %s\n", dbg_mcierr(err));
217 if(!err) mciSendStringA("close r", NULL, 0, NULL);
219 err = mciSendStringA("status x position wait wait", buf, sizeof(buf), NULL);
220 todo_wine ok(err==MCIERR_DUPLICATE_FLAGS,"status wait wait: %s\n", dbg_mcierr(err));
222 err = mciSendStringA("status x length length", buf, sizeof(buf), NULL);
223 todo_wine ok(err==MCIERR_FLAGS_NOT_COMPATIBLE,"status 2xlength: %s\n", dbg_mcierr(err));
225 err = mciSendStringA("status x length position", buf, sizeof(buf), NULL);
226 todo_wine ok(err==MCIERR_FLAGS_NOT_COMPATIBLE,"status length+position: %s\n", dbg_mcierr(err));
228 buf[0]='I';
229 err = mciSendStringA("set x time format milliseconds time format ms", buf, sizeof(buf), NULL);
230 todo_wine ok(err==MCIERR_FLAGS_NOT_COMPATIBLE,"status length+position: %s\n", dbg_mcierr(err));
231 ok(!buf[0], "set error buffer %s\n", buf);
233 /* device's response, not a parser test */
234 err = mciSendStringA("status x", buf, sizeof(buf), NULL);
235 ok(err==MCIERR_MISSING_PARAMETER,"status waveaudio nokeyword: %s\n", dbg_mcierr(err));
237 buf[0]='G';
238 err = mciSendStringA("status a", buf, sizeof(buf), NULL);
239 todo_wine ok(err==MCIERR_UNSUPPORTED_FUNCTION,"status avivideo nokeyword: %s\n", dbg_mcierr(err));
240 ok(!buf[0], "status error buffer %s\n", buf);
242 err = mciSendStringA("status x track", buf, sizeof(buf), NULL);
243 ok(err==MCIERR_BAD_INTEGER,"status waveaudio no track: %s\n", dbg_mcierr(err));
245 err = mciSendStringA("status x track 3", buf, sizeof(buf), NULL);
246 ok(err==MCIERR_MISSING_PARAMETER,"status waveaudio track 3: %s\n", dbg_mcierr(err));
248 err = mciSendStringA("status x 2 track 3", buf, sizeof(buf), NULL);
249 todo_wine ok(err==MCIERR_OUTOFRANGE,"status 2(position) track 3: %s\n", dbg_mcierr(err));
251 err = mciSendStringA("status x 0x4", buf, sizeof(buf), NULL);
252 todo_wine ok(err==MCIERR_BAD_CONSTANT, "status 0x4: %s\n", dbg_mcierr(err));
254 err = mciSendStringA("status x 4", buf, sizeof(buf), hwnd);
255 ok(!err,"status 4(mode): %s\n", dbg_mcierr(err));
256 if(!err)ok(!strcmp(buf,"stopped"), "status 4(mode), got: %s\n", buf);
258 err = mciSendStringA("status x 4 notify", buf, sizeof(buf), hwnd);
259 todo_wine ok(!err,"status 4(mode) notify: %s\n", dbg_mcierr(err));
260 if(!err)ok(!strcmp(buf,"stopped"), "status 4(mode), got: %s\n", buf);
261 test_notification(hwnd, "status 4 notify", err ? 0 : MCI_NOTIFY_SUCCESSFUL);
263 err = mciSendStringA("set x milliseconds", buf, sizeof(buf), hwnd);
264 todo_wine ok(err==MCIERR_UNRECOGNIZED_KEYWORD,"set milliseconds: %s\n", dbg_mcierr(err));
266 err = mciSendStringA("set x milliseconds ms", buf, sizeof(buf), hwnd);
267 todo_wine ok(err==MCIERR_UNRECOGNIZED_KEYWORD,"set milliseconds ms: %s\n", dbg_mcierr(err));
269 err = mciSendStringA("capability x can save", buf, sizeof(buf), hwnd);
270 todo_wine ok(!err,"capability can (space) save: %s\n", dbg_mcierr(err));
272 err = mciSendStringA("status x nsa", buf, sizeof(buf), hwnd);
273 todo_wine ok(err==MCIERR_BAD_CONSTANT,"status nsa: %s\n", dbg_mcierr(err));
275 err = mciSendStringA("seek x to 0:0:0:0:0", buf, sizeof(buf), NULL);
276 ok(err==MCIERR_BAD_INTEGER,"seek to 0:0:0:0:0 returned %s\n", dbg_mcierr(err));
278 err = mciSendStringA("seek x to 0:0:0:0:", buf, sizeof(buf), NULL);
279 ok(err==MCIERR_BAD_INTEGER,"seek to 0:0:0:0: returned %s\n", dbg_mcierr(err));
281 err = mciSendStringA("seek x to :0:0:0:0", buf, sizeof(buf), NULL);
282 ok(err==MCIERR_BAD_INTEGER,"seek to :0:0:0:0 returned %s\n", dbg_mcierr(err));
284 err = mciSendStringA("seek x to 256:0:0:0", buf, sizeof(buf), NULL);
285 ok(err==MCIERR_BAD_INTEGER,"seek to 256:0:0:0 returned %s\n", dbg_mcierr(err));
287 err = mciSendStringA("seek x to 0:256", buf, sizeof(buf), NULL);
288 ok(err==MCIERR_BAD_INTEGER,"seek to 0:256 returned %s\n", dbg_mcierr(err));
290 err = mciSendStringA("status all time format", buf, sizeof(buf), hwnd);
291 ok(err==MCIERR_CANNOT_USE_ALL,"status all: %s\n", dbg_mcierr(err));
293 err = mciSendStringA("cue all", buf, sizeof(buf), NULL);
294 ok(err==MCIERR_UNRECOGNIZED_COMMAND,"cue all: %s\n", dbg_mcierr(err));
296 err = mciSendStringA("open all", buf, sizeof(buf), NULL);
297 todo_wine ok(err==MCIERR_CANNOT_USE_ALL,"open all: %s\n", dbg_mcierr(err));
299 /* avivideo is not a known MCI_DEVTYPE resource name */
300 err = mciSendStringA("sysinfo avivideo quantity", buf, sizeof(buf), hwnd);
301 ok(err==MCIERR_DEVICE_TYPE_REQUIRED,"sysinfo sequencer quantity: %s\n", dbg_mcierr(err));
303 err = mciSendStringA("sysinfo digitalvideo quantity", buf, sizeof(buf), hwnd);
304 ok(!err,"sysinfo digitalvideo quantity: %s\n", dbg_mcierr(err));
305 if(!err) ok(!strcmp(buf,"0"), "sysinfo digitalvideo quantity returned %s\n", buf);
307 /* quantity 0 yet open 1 (via type "avivideo"), fun */
308 err = mciSendStringA("sysinfo digitalvideo quantity open", buf, sizeof(buf), hwnd);
309 ok(!err,"sysinfo digitalvideo quantity open: %s\n", dbg_mcierr(err));
310 if(!err) ok(!strcmp(buf,"1"), "sysinfo digitalvideo quantity open returned %s\n", buf);
312 err = mciSendStringA("put a window at 0 0", buf, sizeof(buf), NULL);
313 ok(err==MCIERR_BAD_INTEGER,"put incomplete rect: %s\n", dbg_mcierr(err));
315 /*w9X-w2k report code from device last opened, newer versions compare them all
316 * and return the one error code or MCIERR_MULTIPLE if they differ. */
317 err = mciSendStringA("pause all", buf, sizeof(buf), NULL);
318 todo_wine ok(err==MCIERR_MULTIPLE || broken(err==MCIERR_NONAPPLICABLE_FUNCTION),"pause all: %s\n", dbg_mcierr(err));
319 ok(!buf[0], "pause error buffer %s\n", buf);
321 /* MCI_STATUS' dwReturn is a DWORD_PTR, others' a plain DWORD. */
322 parm.status.dwItem = MCI_STATUS_TIME_FORMAT;
323 parm.status.dwReturn = 0xFEEDABAD;
324 err = mciSendCommandA(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
325 ok(!err,"mciCommand status time format: %s\n", dbg_mcierr(err));
326 if(!err) ok(MCI_FORMAT_MILLISECONDS==parm.status.dwReturn,"status time format: %ld\n",parm.status.dwReturn);
328 parm.status.dwItem = MCI_STATUS_MODE;
329 parm.status.dwReturn = 0xFEEDABAD;
330 err = mciSendCommandA(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
331 ok(!err,"mciCommand status mode: %s\n", dbg_mcierr(err));
332 if(!err) ok(MCI_MODE_STOP==parm.status.dwReturn,"STATUS mode: %ld\n",parm.status.dwReturn);
334 err = mciSendStringA("status x mode", buf, sizeof(buf), hwnd);
335 ok(!err,"status mode: %s\n", dbg_mcierr(err));
336 if(!err) ok(!strcmp(buf, "stopped"), "status mode is %s\n", buf);
338 parm.caps.dwItem = MCI_GETDEVCAPS_USES_FILES;
339 parm.caps.dwReturn = 0xFEEDABAD;
340 err = mciSendCommandA(wDeviceID, MCI_GETDEVCAPS, MCI_GETDEVCAPS_ITEM, (DWORD_PTR)&parm);
341 ok(!err,"mciCommand getdevcaps files: %s\n", dbg_mcierr(err));
342 if(!err) ok(1==parm.caps.dwReturn,"getdevcaps files: %d\n",parm.caps.dwReturn);
344 parm.caps.dwItem = MCI_GETDEVCAPS_HAS_VIDEO;
345 parm.caps.dwReturn = 0xFEEDABAD;
346 err = mciSendCommandA(wDeviceID, MCI_GETDEVCAPS, MCI_GETDEVCAPS_ITEM, (DWORD_PTR)&parm);
347 ok(!err,"mciCommand getdevcaps video: %s\n", dbg_mcierr(err));
348 if(!err) ok(0==parm.caps.dwReturn,"getdevcaps video: %d\n",parm.caps.dwReturn);
350 parm.caps.dwItem = MCI_GETDEVCAPS_DEVICE_TYPE;
351 parm.caps.dwReturn = 0xFEEDABAD;
352 err = mciSendCommandA(wDeviceID, MCI_GETDEVCAPS, MCI_GETDEVCAPS_ITEM, (DWORD_PTR)&parm);
353 ok(!err,"mciCommand getdevcaps video: %s\n", dbg_mcierr(err));
354 if(!err) ok(MCI_DEVTYPE_WAVEFORM_AUDIO==parm.caps.dwReturn,"getdevcaps device type: %d\n",parm.caps.dwReturn);
356 err = mciSendStringA("capability x uses files", buf, sizeof(buf), hwnd);
357 ok(!err,"capability files: %s\n", dbg_mcierr(err));
358 if(!err) ok(!strcmp(buf, "true"), "capability files is %s\n", buf);
360 err = mciSendStringA("capability x has video", buf, sizeof(buf), hwnd);
361 ok(!err,"capability video: %s\n", dbg_mcierr(err));
362 if(!err) ok(!strcmp(buf, "false"), "capability video is %s\n", buf);
364 err = mciSendStringA("capability x device type", buf, sizeof(buf), hwnd);
365 ok(!err,"capability device type: %s\n", dbg_mcierr(err));
366 if(!err) ok(!strcmp(buf, "waveaudio"), "capability device type is %s\n", buf);
368 err = mciSendCommandA(wDeviceID, MCI_CLOSE, 0, 0);
369 ok(!err,"mciCommand close returned %s\n", dbg_mcierr(err));
371 err = mciSendStringA("close a", buf, sizeof(buf), hwnd);
372 ok(!err,"close avi: %s\n", dbg_mcierr(err));
374 test_notification(hwnd, "-end of 1st set-", 0);
377 static void test_openCloseWAVE(HWND hwnd)
379 MCIERROR err;
380 MCI_PARMS_UNION parm;
381 const char command_open[] = "open new type waveaudio alias mysound notify";
382 const char command_close_my[] = "close mysound notify";
383 const char command_close_all[] = "close all notify";
384 const char command_sysinfo[] = "sysinfo waveaudio quantity open";
385 char buf[1024];
386 DWORD intbuf[3] = { 0xDEADF00D, 99, 0xABADCAFE };
387 memset(buf, 0, sizeof(buf));
388 test_notification(hwnd, "-prior to any command-", 0);
390 /* Avoid Sysinfo quantity with notify because Win9x and newer differ. */
391 err = mciSendStringA("sysinfo all quantity", buf, sizeof(buf), hwnd);
392 ok(!err,"mci sysinfo all quantity returned %s\n", dbg_mcierr(err));
393 if(!err) trace("[MCI] with %s drivers\n", buf);
395 parm.sys.lpstrReturn = (LPSTR)&intbuf[1];
396 parm.sys.dwRetSize = sizeof(DWORD);
397 parm.sys.wDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; /* ignored */
398 err = mciSendCommandA(MCI_ALL_DEVICE_ID, MCI_SYSINFO, MCI_SYSINFO_QUANTITY | MCI_WAIT,
399 (DWORD_PTR)&parm);
400 ok(!err, "mciCommand sysinfo all quantity returned %s\n", dbg_mcierr(err));
401 if(!err) ok(atoi(buf)==intbuf[1],"sysinfo all quantity string and command differ\n");
403 parm.sys.dwRetSize = sizeof(DWORD)-1;
404 err = mciSendCommandA(MCI_ALL_DEVICE_ID, MCI_SYSINFO, MCI_SYSINFO_QUANTITY, (DWORD_PTR)&parm);
405 ok(err == MCIERR_PARAM_OVERFLOW || broken(!err/* Win9x */),
406 "mciCommand sysinfo with too small buffer returned %s\n", dbg_mcierr(err));
408 err = mciSendStringA("open new type waveaudio alias r shareable", buf, sizeof(buf), NULL);
409 ok(err==MCIERR_UNSUPPORTED_FUNCTION,"mci open new shareable returned %s\n", dbg_mcierr(err));
410 if(!err) {
411 err = mciSendStringA("close r", NULL, 0, NULL);
412 ok(!err,"mci close shareable returned %s\n", dbg_mcierr(err));
415 err = mciGetDeviceIDA("waveaudio");
416 ok(!err, "mciGetDeviceIDA waveaudio returned %u, expected 0\n", err);
418 err = mciSendStringA(command_open, buf, sizeof(buf), hwnd);
419 ok(!err,"mci %s returned %s\n", command_open, dbg_mcierr(err));
420 ok(!strcmp(buf,"1"), "mci open deviceId: %s, expected 1\n", buf);
421 /* Wine<=1.1.33 used to ignore anything past alias XY */
422 test_notification(hwnd,"open new alias notify",MCI_NOTIFY_SUCCESSFUL);
424 err = mciSendStringA("status mysound time format", buf, sizeof(buf), hwnd);
425 ok(!err,"mci status time format returned %s\n", dbg_mcierr(err));
426 if(!err) {
427 if (PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) == LANG_ENGLISH)
428 ok(!strcmp(buf,"milliseconds"), "mci status time format: %s\n", buf);
429 else trace("locale-dependent time format: %s (ms)\n", buf);
432 memset(buf, 0, sizeof(buf));
433 parm.sys.dwNumber = 1;
434 parm.sys.wDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; /* ignored */
435 parm.sys.lpstrReturn = buf;
436 parm.sys.dwRetSize = sizeof(buf);
437 parm.sys.dwCallback = (DWORD_PTR)hwnd;
438 err = mciSendCommandA(MCI_ALL_DEVICE_ID, MCI_SYSINFO,
439 MCI_SYSINFO_NAME | MCI_SYSINFO_OPEN | MCI_NOTIFY, (DWORD_PTR)&parm);
440 ok(!err,"mciCommand MCI_SYSINFO all name 1 open notify: %s\n", dbg_mcierr(err));
441 if(!err) ok(!strcmp(buf,"mysound"), "sysinfo name returned %s\n", buf);
442 test_notification(hwnd, "SYSINFO name notify\n", MCI_NOTIFY_SUCCESSFUL);
444 memset(buf, 0, sizeof(buf));
445 parm.sys.dwNumber = 1;
446 parm.sys.wDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; /* ignored */
447 parm.sys.lpstrReturn = buf;
448 parm.sys.dwRetSize = 8; /* mysound\0 */
449 err = mciSendCommandA(MCI_ALL_DEVICE_ID, MCI_SYSINFO, MCI_SYSINFO_NAME | MCI_SYSINFO_OPEN,
450 (DWORD_PTR)&parm);
451 ok(!err,"mciCommand MCI_SYSINFO all name 1 open buffer[8]: %s\n", dbg_mcierr(err));
452 if(!err) ok(!strcmp(buf,"mysound"), "sysinfo name returned %s\n", buf);
454 memset(buf, 0, sizeof(buf));
455 /* dwRetSize counts characters, not bytes, despite what MSDN says. */
456 parm.sys.dwNumber = 1;
457 parm.sys.wDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; /* ignored */
458 parm.sys.lpstrReturn = buf;
459 parm.sys.dwRetSize = 8; /* mysound\0 */
460 /* MCI_..._PARMSA and PARMSW share the same layout, use one for both tests. */
461 err = mciSendCommandW(MCI_ALL_DEVICE_ID, MCI_SYSINFO, MCI_SYSINFO_NAME | MCI_SYSINFO_OPEN, (DWORD_PTR)&parm);
462 ok(!err || broken(err==MMSYSERR_NOTSUPPORTED/* Win9x */), "mciCommandW MCI_SYSINFO all name 1 open buffer[8]: %s\n", dbg_mcierr(err));
463 if(!err) ok(!strcmp_wa((LPWSTR)buf,"mysound"), "sysinfo name 1 open contents\n");
465 memset(buf, 0, sizeof(buf));
466 buf[0] = 'Y';
467 parm.sys.dwNumber = 1;
468 parm.sys.wDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; /* ignored */
469 parm.sys.lpstrReturn = buf;
470 parm.sys.dwRetSize = 7; /* too short for mysound\0 */
471 err = mciSendCommandW(MCI_ALL_DEVICE_ID, MCI_SYSINFO, MCI_SYSINFO_NAME | MCI_SYSINFO_OPEN, (DWORD_PTR)&parm);
472 ok(err==MCIERR_PARAM_OVERFLOW || broken(err==MMSYSERR_NOTSUPPORTED/* Win9x */), "mciCommandW MCI_SYSINFO all name 1 open too small: %s\n", dbg_mcierr(err));
473 ok(!strcmp(buf,"Y"), "output buffer %s\n", buf);
475 /* Win9x overwrites the tiny buffer and returns success, newer versions signal overflow. */
476 memset(buf, 0, sizeof(buf));
477 buf[0] = 'Y';
478 parm.sys.dwNumber = 1;
479 parm.sys.wDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; /* ignored */
480 parm.sys.lpstrReturn = buf;
481 parm.sys.dwRetSize = 2; /* too short for mysound\0 */
482 err = mciSendCommandA(MCI_ALL_DEVICE_ID, MCI_SYSINFO, MCI_SYSINFO_NAME | MCI_SYSINFO_OPEN,
483 (DWORD_PTR)&parm);
484 ok(err==MCIERR_PARAM_OVERFLOW || broken(!err /* Win9x */),"mciCommand MCI_SYSINFO all name 1 open too small: %s\n", dbg_mcierr(err));
485 ok(!strcmp(buf, err ? "Y" : "mysound"), "sysinfo short name returned %s\n", buf);
487 err = mciSendStringA("sysinfo mysound quantity open", buf, sizeof(buf), hwnd);
488 ok(err==MCIERR_DEVICE_TYPE_REQUIRED,"sysinfo alias quantity: %s\n", dbg_mcierr(err));
490 err = mciSendStringA("sysinfo nosuchalias quantity open", buf, sizeof(buf), hwnd);
491 ok(err==MCIERR_DEVICE_TYPE_REQUIRED,"sysinfo unknown quantity open: %s\n", dbg_mcierr(err));
493 err = mciSendStringA("sysinfo all installname", buf, sizeof(buf), hwnd);
494 ok(err==MCIERR_CANNOT_USE_ALL,"sysinfo all installname: %s\n", dbg_mcierr(err));
496 buf[0] = 'M'; buf[1] = 0;
497 parm.sys.lpstrReturn = buf;
498 parm.sys.dwRetSize = sizeof(buf);
499 err = mciSendCommandA(MCI_ALL_DEVICE_ID, MCI_SYSINFO, MCI_SYSINFO_INSTALLNAME, (DWORD_PTR)&parm);
500 ok(err==MCIERR_CANNOT_USE_ALL,"mciCommand MCI_SYSINFO all installname: %s\n", dbg_mcierr(err));
501 ok(!strcmp(buf,"M"), "output buffer %s\n", buf);
503 err = mciSendStringA("sysinfo nodev installname", buf, sizeof(buf), hwnd);
504 ok(err==MCIERR_INVALID_DEVICE_NAME,"sysinfo nodev installname: %s\n", dbg_mcierr(err));
505 ok(!buf[0], "sysinfo error buffer %s\n", buf);
507 buf[0] = 'K';
508 parm.sys.lpstrReturn = buf;
509 parm.sys.dwRetSize = sizeof(buf);
510 err = mciSendCommandW(24000, MCI_SYSINFO, MCI_SYSINFO_INSTALLNAME, (DWORD_PTR)&parm);
511 ok(err==MCIERR_INVALID_DEVICE_NAME || broken(err==MMSYSERR_NOTSUPPORTED/* Win9x */), "mciCommand MCI_SYSINFO nodev installname: %s\n", dbg_mcierr(err));
512 ok(!strcmp(buf,"K"), "output buffer %s\n", buf);
514 buf[0] = 0; buf[1] = 'A'; buf[2] = 'j'; buf[3] = 0;
515 parm.info.lpstrReturn = buf;
516 parm.info.dwRetSize = 2;
517 err = mciSendCommandA(1, MCI_INFO, MCI_INFO_PRODUCT, (DWORD_PTR)&parm);
518 ok(!err, "mciCommand MCI_INFO product: %s\n", dbg_mcierr(err));
519 ok(buf[0] /* && !buf[1] */ && (buf[2] == 'j' || broken(!buf[2])), "info product output buffer %s\n", buf);
520 /* Producing non-ASCII multi-byte output, native forgets to zero-terminate a too small buffer
521 * with SendStringA, while SendStringW works correctly (jap. and chin. locale): ignore buf[1] */
522 /* Bug in 64 bit Vista/w2k8/w7: mciSendStringW is used! (not in xp nor w2k3) */
524 buf[0] = 'K'; buf[1] = 0;
525 parm.info.dwRetSize = sizeof(buf);
526 err = mciSendCommandW(1, MCI_INFO, 0x07000000, (DWORD_PTR)&parm);
527 ok(err==MCIERR_UNRECOGNIZED_KEYWORD || broken(err==MMSYSERR_NOTSUPPORTED/* Win9x */), "mciCommand MCI_INFO other: %s\n", dbg_mcierr(err));
528 ok(!strcmp(buf,"K"), "info output buffer %s\n", buf);
530 err = mciGetDeviceIDA("all");
531 ok(err == MCI_ALL_DEVICE_ID, "mciGetDeviceIDA all returned %u, expected MCI_ALL_DEVICE_ID\n", err);
533 err = mciSendStringA(command_close_my, NULL, 0, hwnd);
534 ok(!err,"mci %s returned %s\n", command_close_my, dbg_mcierr(err));
535 test_notification(hwnd, command_close_my, MCI_NOTIFY_SUCCESSFUL);
536 Sleep(5);
537 test_notification(hwnd, command_close_my, 0);
539 err = mciSendStringA("open no-such-file-exists.wav alias y buffer 6", buf, sizeof(buf), NULL);
540 ok(err==MCIERR_FILE_NOT_FOUND,"open no-such-file.wav returned %s\n", dbg_mcierr(err));
541 if(!err) {
542 err = mciSendStringA("close y", NULL, 0, NULL);
543 ok(!err,"close y returned %s\n", dbg_mcierr(err));
546 err = mciSendStringA("open no-such-dir\\file.wav alias y type waveaudio", buf, sizeof(buf), NULL);
547 ok(err==MCIERR_FILE_NOT_FOUND || broken(err==MCIERR_INVALID_FILE /* Win9X */),"open no-such-dir/file.wav returned %s\n", dbg_mcierr(err));
548 if(!err) {
549 err = mciSendStringA("close y", NULL, 0, NULL);
550 ok(!err,"close y returned %s\n", dbg_mcierr(err));
553 err = mciSendStringA("open ! alias no", buf, sizeof(buf), NULL);
554 ok(err==MCIERR_INVALID_DEVICE_NAME,"open !(void): %s\n", dbg_mcierr(err));
556 err = mciSendStringA("open !no-such-file-exists.wav alias no", buf, sizeof(buf), NULL);
557 ok(err==MCIERR_FILE_NOT_FOUND || /* Win9X */err==MCIERR_INVALID_DEVICE_NAME,"open !name: %s\n", dbg_mcierr(err));
559 /* FILE_NOT_FOUND stems from mciwave,
560 * the complete name including ! is passed through since NT */
561 err = mciSendStringA("open nosuchdevice!tempfile.wav alias no", buf, sizeof(buf), NULL);
562 ok(err==MCIERR_FILE_NOT_FOUND || /* Win9X */err==MCIERR_INVALID_DEVICE_NAME,"open nosuchdevice!name: %s\n", dbg_mcierr(err));
563 /* FIXME? use broken(INVALID_DEVICE_NAME) and have Wine not mimic Win9X? */
565 err = mciSendStringA("close waveaudio", buf, sizeof(buf), NULL);
566 ok(err==MCIERR_INVALID_DEVICE_NAME,"close waveaudio: %s\n", dbg_mcierr(err));
568 err = mciSendStringA(command_close_all, NULL, 0, NULL);
569 ok(!err,"mci %s (without buffer) returned %s\n", command_close_all, dbg_mcierr(err));
571 err = mciSendStringA(command_close_all, buf, sizeof(buf), hwnd);
572 ok(!err,"mci %s (with output buffer) returned %s\n", command_close_all, dbg_mcierr(err));
573 ok(buf[0] == 0, "mci %s output buffer: %s\n", command_close_all, buf);
574 /* No notification left, everything closed already */
575 test_notification(hwnd, command_close_all, 0);
576 /* TODO test close all sends one notification per open device */
578 err = mciSendStringA(command_sysinfo, buf, sizeof(buf), NULL);
579 ok(!err,"mci %s returned %s\n", command_sysinfo, dbg_mcierr(err));
580 ok(buf[0] == '0' && buf[1] == 0, "mci %s, expected output buffer '0', got: '%s'\n", command_sysinfo, buf);
582 err = mciSendStringA("open new type waveaudio", buf, sizeof(buf), NULL);
583 ok(err==MCIERR_NEW_REQUIRES_ALIAS,"mci open new without alias returned %s\n", dbg_mcierr(err));
585 parm.open.lpstrDeviceType = (LPSTR)MCI_DEVTYPE_WAVEFORM_AUDIO;
586 err = mciSendCommandA(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID, (DWORD_PTR)&parm);
587 ok(!err,"mciCommand OPEN_TYPE_ID waveaudio: %s\n", dbg_mcierr(err));
589 if(!err) {
590 MCIDEVICEID wDeviceID = parm.open.wDeviceID;
591 parm.caps.dwItem = MCI_GETDEVCAPS_DEVICE_TYPE;
592 err = mciSendCommandA(wDeviceID, MCI_GETDEVCAPS, MCI_GETDEVCAPS_ITEM, (DWORD_PTR)&parm);
593 ok(!err,"mciCommand MCI_GETDEVCAPS device type: %s\n", dbg_mcierr(err));
594 ok(MCI_DEVTYPE_WAVEFORM_AUDIO==parm.caps.dwReturn,"mciCommand GETDEVCAPS says %u, expected %u\n", parm.caps.dwReturn, MCI_DEVTYPE_WAVEFORM_AUDIO);
597 ok(0xDEADF00D==intbuf[0] && 0xABADCAFE==intbuf[2],"DWORD buffer corruption\n");
599 err = mciGetDeviceIDA("waveaudio");
600 ok(err == 1, "mciGetDeviceIDA waveaudio returned %u, expected 1\n", err);
602 err = mciSendStringA("open no-such-file.wav alias waveaudio", buf, sizeof(buf), NULL);
603 ok(err==MCIERR_DUPLICATE_ALIAS, "mci open alias waveaudio returned %s\n", dbg_mcierr(err));
604 /* If it were not already in use, open avivideo alias waveaudio would succeed,
605 * making for funny test cases. */
607 err = mciSendCommandA(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_WAIT, 0); /* from MSDN */
608 ok(!err, "mciCommand close returned %s\n", dbg_mcierr(err));
610 err = mciSendCommandA(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, 0);
611 ok(!err, "mciCommand close returned %s\n", dbg_mcierr(err));
613 parm.gen.dwCallback = (DWORD_PTR)hwnd;
614 err = mciSendCommandA(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, (DWORD_PTR)&parm);
615 ok(!err, "mciCommand close returned %s\n", dbg_mcierr(err));
616 test_notification(hwnd, command_close_all, 0); /* None left */
619 static void test_recordWAVE(HWND hwnd)
621 WORD nch = 1;
622 WORD nbits = 16;
623 DWORD nsamp = 16000, expect;
624 UINT ndevs = waveInGetNumDevs();
625 MCIERROR err, ok_pcm;
626 MCIDEVICEID wDeviceID;
627 MCI_PARMS_UNION parm;
628 char buf[1024];
629 memset(buf, 0, sizeof(buf));
630 test_notification(hwnd, "-prior to recording-", 0);
632 parm.open.lpstrDeviceType = "waveaudio";
633 parm.open.lpstrElementName = ""; /* "new" at the command level */
634 parm.open.lpstrAlias = "x"; /* to enable mciSendStringA */
635 parm.open.dwCallback = (DWORD_PTR)hwnd;
636 err = mciSendCommandA(0, MCI_OPEN,
637 MCI_OPEN_ELEMENT | MCI_OPEN_TYPE | MCI_OPEN_ALIAS | MCI_NOTIFY, (DWORD_PTR)&parm);
638 ok(!err,"mciCommand open new type waveaudio alias x notify: %s\n", dbg_mcierr(err));
639 wDeviceID = parm.open.wDeviceID;
641 err = mciGetDeviceIDA("x");
642 ok(err == wDeviceID, "mciGetDeviceIDA x returned %u, expected %u\n", err, wDeviceID);
644 /* Only the alias is looked up. */
645 err = mciGetDeviceIDA("waveaudio");
646 ok(!err, "mciGetDeviceIDA waveaudio returned %u, expected 0\n", err);
648 test_notification(hwnd, "open new", MCI_NOTIFY_SUCCESSFUL);
649 test_notification(hwnd, "open new no #2", 0);
651 /* Do not query time format as string because result depends on locale! */
652 parm.status.dwItem = MCI_STATUS_TIME_FORMAT;
653 err = mciSendCommandA(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
654 ok(!err,"mciCommand status time format: %s\n", dbg_mcierr(err));
655 ok(parm.status.dwReturn==MCI_FORMAT_MILLISECONDS,"status time format: %ld\n",parm.status.dwReturn);
657 /* Info file fails until named in Open or Save. */
658 err = mciSendStringA("info x file", buf, sizeof(buf), NULL);
659 todo_wine ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci info new file returned %s\n", dbg_mcierr(err));
660 ok(!buf[0], "info error buffer %s\n", buf);
662 err = mciSendStringA("status x length", buf, sizeof(buf), NULL);
663 todo_wine ok(!err,"status x length initial: %s\n", dbg_mcierr(err));
664 if(!err) ok(!strcmp(buf,"0"), "mci status length expected 0, got: %s\n", buf);
666 /* Check the default recording: 8-bits per sample, mono, 11kHz */
667 err = mciSendStringA("status x samplespersec", buf, sizeof(buf), NULL);
668 ok(!err,"mci status samplespersec returned %s\n", dbg_mcierr(err));
669 if(!err) ok(!strcmp(buf,"11025"), "mci status samplespersec expected 11025, got: %s\n", buf);
671 /* MCI seems to solely support PCM, no need for ACM conversion. */
672 err = mciSendStringA("set x format tag 2", NULL, 0, NULL);
673 ok(err==MCIERR_OUTOFRANGE,"mci set format tag 2 returned %s\n", dbg_mcierr(err));
675 /* MCI appears to scan the available devices for support of this format,
676 * returning MCIERR_OUTOFRANGE on machines with no sound.
677 * However some w2k8/w7 machines return no error when there's no wave
678 * input device (perhaps querying waveOutGetNumDevs instead of waveIn?),
679 * still the record command below fails with MCIERR_WAVE_INPUTSUNSUITABLE.
680 * Don't skip here, record will fail below. */
681 err = mciSendStringA("set x format tag pcm", NULL, 0, NULL);
682 ok(!err || err==MCIERR_OUTOFRANGE,"mci set format tag pcm returned %s\n", dbg_mcierr(err));
683 ok_pcm = err;
685 /* MSDN warns against not setting all wave format parameters.
686 * Indeed, it produces strange results, incl.
687 * inconsistent PCMWAVEFORMAT headers in the saved file.
689 err = mciSendStringA("set x bytespersec 22050 alignment 2 samplespersec 11025 channels 1 bitspersample 16", NULL, 0, NULL);
690 ok(err==ok_pcm,"mci set 5 wave parameters returned %s\n", dbg_mcierr(err));
691 /* Investigate: on w2k, set samplespersec 22050 sets nChannels to 2!
692 * err = mciSendStringA("set x samplespersec 22050", NULL, 0, NULL);
693 * ok(!err,"mci set samplespersec returned %s\n", dbg_mcierr(err));
696 /* Checks are generally performed immediately. */
697 err = mciSendStringA("set x bitspersample 4", NULL, 0, NULL);
698 todo_wine ok(err==MCIERR_OUTOFRANGE,"mci set bitspersample 4 returned %s\n", dbg_mcierr(err));
700 parm.set.wFormatTag = WAVE_FORMAT_PCM;
701 parm.set.nSamplesPerSec = nsamp;
702 parm.set.wBitsPerSample = nbits;
703 parm.set.nChannels = nch;
704 parm.set.nBlockAlign = parm.set.nChannels * parm.set.wBitsPerSample /8;
705 parm.set.nAvgBytesPerSec= parm.set.nSamplesPerSec * parm.set.nBlockAlign;
706 err = mciSendCommandA(wDeviceID, MCI_SET,
707 MCI_WAVE_SET_SAMPLESPERSEC | MCI_WAVE_SET_CHANNELS | MCI_WAVE_SET_BITSPERSAMPLE |
708 MCI_WAVE_SET_BLOCKALIGN | MCI_WAVE_SET_AVGBYTESPERSEC| MCI_WAVE_SET_FORMATTAG,
709 (DWORD_PTR)&parm);
710 ok(err==ok_pcm,"mciCommand set wave format: %s\n", dbg_mcierr(err));
712 parm.caps.dwItem = MCI_WAVE_GETDEVCAPS_INPUTS;
713 parm.caps.dwCallback = (DWORD_PTR)hwnd;
714 err = mciSendCommandA(wDeviceID, MCI_GETDEVCAPS, MCI_GETDEVCAPS_ITEM | MCI_NOTIFY,
715 (DWORD_PTR)&parm);
716 ok(!err,"mciCommand MCI_GETDEVCAPS inputs: %s\n", dbg_mcierr(err));
717 ok(parm.caps.dwReturn==ndevs,"mciCommand GETDEVCAPS claims %u inputs, expected %u\n", parm.caps.dwReturn, ndevs);
718 ok(!ok_pcm || !parm.caps.dwReturn,"No input device accepts PCM!?\n");
719 test_notification(hwnd, "GETDEVCAPS inputs", MCI_NOTIFY_SUCCESSFUL);
721 /* A few ME machines pass all tests except set format tag pcm! */
722 err = mciSendStringA("record x to 2000 wait", NULL, 0, hwnd);
723 ok(err || !ok_pcm,"can record yet set wave format pcm returned %s\n", dbg_mcierr(ok_pcm));
724 if(!ndevs) todo_wine /* with sound disabled */
725 ok(ndevs>0 ? !err : err==MCIERR_WAVE_INPUTSUNSUITABLE,"mci record to 2000 returned %s\n", dbg_mcierr(err));
726 else
727 ok(ndevs>0 ? !err : err==MCIERR_WAVE_INPUTSUNSUITABLE,"mci record to 2000 returned %s\n", dbg_mcierr(err));
728 if(err) {
729 if (err==MCIERR_WAVE_INPUTSUNSUITABLE)
730 skip("Please install audio driver. Everything is skipped.\n");
731 else skip("Cannot record cause %s. Everything is skipped.\n", dbg_mcierr(err));
733 err = mciSendStringA("close x", NULL, 0, NULL);
734 ok(!err,"mci close returned %s\n", dbg_mcierr(err));
735 test_notification(hwnd,"record skipped",0);
736 return;
739 /* Query some wave format parameters depending on the time format. */
740 err = mciSendStringA("status x position", buf, sizeof(buf), NULL);
741 ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
742 if(!err) todo_wine ok(!strcmp(buf,"2000"), "mci status position gave %s, expected 2000, some tests will fail\n", buf);
744 err = mciSendStringA("set x time format 8", NULL, 0, NULL); /* bytes */
745 ok(!err,"mci returned %s\n", dbg_mcierr(err));
747 parm.status.dwItem = MCI_STATUS_POSITION;
748 err = mciSendCommandA(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
749 ok(!err,"mciCommand status position: %s\n", dbg_mcierr(err));
750 expect = 2 * nsamp * nch * nbits/8;
751 if(!err) todo_wine ok(parm.status.dwReturn==expect,"recorded %lu bytes, expected %u\n",parm.status.dwReturn,expect);
753 parm.set.dwTimeFormat = MCI_FORMAT_SAMPLES;
754 err = mciSendCommandA(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)&parm);
755 ok(!err,"mciCommand set time format samples: %s\n", dbg_mcierr(err));
757 parm.status.dwItem = MCI_STATUS_POSITION;
758 err = mciSendCommandA(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
759 ok(!err,"mciCommand status position: %s\n", dbg_mcierr(err));
760 expect = 2 * nsamp;
761 if(!err) todo_wine ok(parm.status.dwReturn==expect,"recorded %lu samples, expected %u\n",parm.status.dwReturn,expect);
763 err = mciSendStringA("set x time format milliseconds", NULL, 0, NULL);
764 ok(!err,"mci set time format milliseconds returned %s\n", dbg_mcierr(err));
766 err = mciSendStringA("save x tempfile1.wav", NULL, 0, NULL);
767 ok(!err,"mci save returned %s\n", dbg_mcierr(err));
769 err = mciSendStringA("save x tempfile.wav", NULL, 0, NULL);
770 ok(!err,"mci save returned %s\n", dbg_mcierr(err));
771 if(!err) ok_saved = 0;
773 /* Save must not rename the original file. */
774 if (!DeleteFileA("tempfile1.wav"))
775 todo_wine ok(FALSE, "Save must not rename the original file; DeleteFileA returned %d\n",
776 GetLastError());
778 err = mciSendStringA("set x channels 2", NULL, 0, NULL);
779 ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci set channels after saving returned %s\n", dbg_mcierr(err));
781 parm.seek.dwTo = 600;
782 err = mciSendCommandA(wDeviceID, MCI_SEEK, MCI_TO | MCI_WAIT, (DWORD_PTR)&parm);
783 ok(!err,"mciCommand seek to 600: %s\n", dbg_mcierr(err));
785 /* Truncate to current position */
786 err = mciSendStringA("delete x", NULL, 0, NULL);
787 todo_wine ok(!err,"mci delete returned %s\n", dbg_mcierr(err));
789 err = mciSendStringA("status x length", buf, sizeof(buf), NULL);
790 ok(!err,"mci status length returned %s\n", dbg_mcierr(err));
791 todo_wine ok(!strcmp(buf,"600"), "mci status length after delete gave %s, expected 600\n", buf);
793 err = mciSendStringA("close x", NULL, 0, NULL);
794 ok(!err,"mci close returned %s\n", dbg_mcierr(err));
795 test_notification(hwnd,"record complete",0);
798 static void test_playWAVE(HWND hwnd)
800 MCIERROR err;
801 char buf[1024];
802 memset(buf, 0, sizeof(buf));
804 err = mciSendStringA("open waveaudio!tempfile.wav alias mysound", NULL, 0, NULL);
805 ok(err==ok_saved,"mci open waveaudio!tempfile.wav returned %s\n", dbg_mcierr(err));
806 if(err) {
807 skip("Cannot open waveaudio!tempfile.wav for playing (%s), skipping\n", dbg_mcierr(err));
808 return;
811 err = mciGetDeviceIDA("mysound");
812 ok(err == 1, "mciGetDeviceIDA mysound returned %u, expected 1\n", err);
814 err = mciGetDeviceIDA("tempfile.wav");
815 ok(!err, "mciGetDeviceIDA tempfile.wav returned %u, expected 0\n", err);
817 err = mciGetDeviceIDA("waveaudio");
818 ok(!err, "mciGetDeviceIDA waveaudio returned %u, expected 0\n", err);
820 err = mciSendStringA("status mysound length", buf, sizeof(buf), NULL);
821 ok(!err,"mci status length returned %s\n", dbg_mcierr(err));
822 todo_wine ok(!strcmp(buf,"2000"), "mci status length gave %s, expected 2000, some tests will fail.\n", buf);
824 err = mciSendStringA("cue output", NULL, 0, NULL);
825 ok(err==MCIERR_UNRECOGNIZED_COMMAND,"mci incorrect cue output returned %s\n", dbg_mcierr(err));
827 /* Test MCI to the bones -- Some todo_wine from Cue and
828 * from Play from 0 to 0 are not worth fixing. */
829 err = mciSendStringA("cue mysound output notify", NULL, 0, hwnd);
830 ok(!err,"mci cue output after open file returned %s\n", dbg_mcierr(err));
831 /* Notification is delayed as a play thread is started. */
832 todo_wine test_notification(hwnd, "cue immediate", 0);
834 /* Cue pretends to put the MCI into paused state. */
835 err = mciSendStringA("status mysound mode", buf, sizeof(buf), hwnd);
836 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
837 todo_wine ok(!strcmp(buf,"paused"), "mci status mode: %s, expected (pseudo)paused\n", buf);
839 /* Strange pause where Pause is rejected, unlike Play; Pause; Pause tested below */
840 err = mciSendStringA("pause mysound", NULL, 0, hwnd);
841 ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci pause after cue returned %s\n", dbg_mcierr(err));
843 /* MCI appears to start the play thread in this border case.
844 * Guessed that from (flaky) status mode and late notification arrival. */
845 err = mciSendStringA("play mysound from 0 to 0 notify", NULL, 0, hwnd);
846 ok(!err,"mci play from 0 to 0 returned %s\n", dbg_mcierr(err));
847 todo_wine test_notification(hwnd, "cue aborted by play", MCI_NOTIFY_ABORTED);
848 /* play's own notification follows below */
850 err = mciSendStringA("play mysound from 250 to 0", NULL, 0, NULL);
851 ok(err==MCIERR_OUTOFRANGE,"mci play from 250 to 0 returned %s\n", dbg_mcierr(err));
853 Sleep(50); /* Give play from 0 to 0 time to finish. */
854 todo_wine test_notification(hwnd, "play from 0 to 0", MCI_NOTIFY_SUCCESSFUL);
856 err = mciSendStringA("status mysound mode", buf, sizeof(buf), hwnd);
857 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
858 ok(!strcmp(buf,"stopped"), "mci status mode: %s after play from 0 to 0\n", buf);
860 err = mciSendStringA("play MYSOUND from 250 to 0 notify", NULL, 0, hwnd);
861 ok(err==MCIERR_OUTOFRANGE,"mci play from 250 to 0 notify returned %s\n", dbg_mcierr(err));
862 /* No notification (checked below) sent if error */
864 /* A second play caused Wine<1.1.33 to hang */
865 err = mciSendStringA("play mysound from 500 to 220:5:0 wait", NULL, 0, NULL);
866 ok(!err,"mci play from 500 to 220:5:0 (=1500) returned %s\n", dbg_mcierr(err));
868 err = mciSendStringA("status mysound position", buf, sizeof(buf), hwnd);
869 ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
870 if(!err) ok(!strcmp(buf,"1500"), "mci status position: %s\n", buf);
872 /* mci will not play position < current */
873 err = mciSendStringA("play mysound to 1000", NULL, 0, NULL);
874 ok(err==MCIERR_OUTOFRANGE,"mci play to 1000 returned %s\n", dbg_mcierr(err));
876 /* mci will not play to > end */
877 err = mciSendStringA("play mysound TO 3000 notify", NULL, 0, hwnd);
878 ok(err==MCIERR_OUTOFRANGE,"mci play to 3000 notify returned %s\n", dbg_mcierr(err));
880 err = mciSendStringA("play mysound to 2000", NULL, 0, NULL);
881 ok(!err,"mci play to 2000 returned %s\n", dbg_mcierr(err));
883 /* Rejected while playing */
884 err = mciSendStringA("cue mysound output", NULL, 0, NULL);
885 ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci cue output while playing returned %s\n", dbg_mcierr(err));
887 err = mciSendStringA("play mysound to 3000", NULL, 0, NULL);
888 ok(err==MCIERR_OUTOFRANGE,"mci play to 3000 returned %s\n", dbg_mcierr(err));
890 err = mciSendStringA("stop mysound Wait", NULL, 0, NULL);
891 ok(!err,"mci stop wait returned %s\n", dbg_mcierr(err));
892 test_notification(hwnd, "play/cue/pause/stop", 0);
894 err = mciSendStringA("Seek Mysound to 250 wait Notify", NULL, 0, hwnd);
895 ok(!err,"mci seek to 250 wait notify returned %s\n", dbg_mcierr(err));
896 test_notification(hwnd,"seek wait notify",MCI_NOTIFY_SUCCESSFUL);
898 err = mciSendStringA("seek mysound to 0xfa", NULL, 0, NULL);
899 ok(err==MCIERR_BAD_INTEGER,"mci seek to 0xfa returned %s\n", dbg_mcierr(err));
901 /* MCI_INTEGER always accepts colon notation */
902 err = mciSendStringA("seek mysound to :1", NULL, 0, NULL);
903 ok(!err,"mci seek to :1 (=256) returned %s\n", dbg_mcierr(err));
905 err = mciSendStringA("seek mysound to 250::", NULL, 0, NULL);
906 ok(!err,"mci seek to 250:: returned %s\n", dbg_mcierr(err));
908 err = mciSendStringA("seek mysound to 250:0", NULL, 0, NULL);
909 ok(!err,"mci seek to 250:0 returned %s\n", dbg_mcierr(err));
911 err = mciSendStringA("status mysound position notify", buf, sizeof(buf), hwnd);
912 ok(!err,"mci status position notify returned %s\n", dbg_mcierr(err));
913 if(!err) ok(!strcmp(buf,"250"), "mci status position: %s\n", buf);
914 /* Immediate commands like status also send notifications. */
915 test_notification(hwnd,"status position",MCI_NOTIFY_SUCCESSFUL);
917 err = mciSendStringA("status mysound mode", buf, sizeof(buf), hwnd);
918 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
919 ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
921 /* Another play from == to testcase */
922 err = mciSendStringA("play mysound to 250 wait notify", NULL, 0, hwnd);
923 ok(!err,"mci play (from 250) to 250 returned %s\n", dbg_mcierr(err));
924 todo_wine test_notification(hwnd,"play to 250 wait notify",MCI_NOTIFY_SUCCESSFUL);
926 err = mciSendStringA("cue mysound output", NULL, 0, NULL);
927 ok(!err,"mci cue output after play returned %s\n", dbg_mcierr(err));
929 err = mciSendStringA("close mysound", NULL, 0, NULL);
930 ok(!err,"mci close returned %s\n", dbg_mcierr(err));
931 test_notification(hwnd,"after close",0);
934 static void test_asyncWAVE(HWND hwnd)
936 MCIDEVICEID wDeviceID;
937 MCI_PARMS_UNION parm;
938 int err, p1, p2;
939 char buf[1024];
940 memset(buf, 0, sizeof(buf));
942 err = mciSendStringA("open tempfile.wav alias mysound notify type waveaudio", buf, sizeof(buf), hwnd);
943 ok(err==ok_saved,"mci open tempfile.wav returned %s\n", dbg_mcierr(err));
944 if(err) {
945 skip("Cannot open tempfile.wav for playing (%s), skipping\n", dbg_mcierr(err));
946 return;
948 ok(!strcmp(buf,"1"), "mci open deviceId: %s, expected 1\n", buf);
949 wDeviceID = atoi(buf);
950 ok(wDeviceID,"mci open DeviceID: %d\n", wDeviceID);
951 test_notification(hwnd,"open alias notify",MCI_NOTIFY_SUCCESSFUL);
953 err = mciGetDeviceIDA("mysound");
954 ok(err == wDeviceID, "mciGetDeviceIDA alias returned %u, expected %u\n", err, wDeviceID);
956 /* Only the alias is looked up. */
957 err = mciGetDeviceIDA("tempfile.wav");
958 ok(!err, "mciGetDeviceIDA tempfile.wav returned %u, expected 0\n", err);
960 err = mciGetDeviceIDA("waveaudio");
961 ok(!err, "mciGetDeviceIDA waveaudio returned %u, expected 0\n", err);
963 err = mciSendStringA("status mysound mode", buf, sizeof(buf), hwnd);
964 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
965 ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
967 err = mciSendStringA("play mysound notify", NULL, 0, hwnd);
968 ok(!err,"mci play returned %s\n", dbg_mcierr(err));
970 Sleep(500); /* milliseconds */
972 /* Do not query time format as string because result depends on locale! */
973 parm.status.dwItem = MCI_STATUS_TIME_FORMAT;
974 err = mciSendCommandA(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
975 ok(!err,"mciCommand status time format: %s\n", dbg_mcierr(err));
976 if(!err) ok(parm.status.dwReturn==MCI_FORMAT_MILLISECONDS,"status time format: %ld\n",parm.status.dwReturn);
978 parm.set.dwTimeFormat = MCI_FORMAT_MILLISECONDS;
979 err = mciSendCommandA(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)&parm);
980 ok(!err,"mciCommand set time format ms: %s\n", dbg_mcierr(err));
982 err = mciSendStringA("status mysound position", buf, sizeof(buf), hwnd);
983 ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
984 trace("position after Sleep: %sms\n", buf);
985 p2 = atoi(buf);
986 /* Check that the 2s sound plays at a normal pace, giving a wide margin to
987 * account for timing granularity and small delays.
989 todo_wine ok(350 <= p2 && p2 <= 600, "%ums is not in the expected 350-600ms range\n", p2);
990 /* Wine's asynchronous thread needs some time to start up. Furthermore, it
991 * uses 3 buffers per second, so that the positions reported will be 333ms,
992 * 667ms etc. at best, which is why it fails the above test. So add a
993 * second test specifically to prevent Wine from getting even worse.
994 * FIXME: To be removed when Wine is fixed and passes the above test.
996 ok(350 <= p2 && p2 <= 1000, "%ums is not even in the expected 350-1000ms range\n", p2);
997 test_notification(hwnd,"play (nowait)",0);
999 err = mciSendStringA("pause mysound wait", NULL, 0, hwnd);
1000 ok(!err,"mci pause wait returned %s\n", dbg_mcierr(err));
1002 err = mciSendStringA("status mysound mode notify", buf, sizeof(buf), hwnd);
1003 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
1004 if(!err) ok(!strcmp(buf,"paused"), "mci status mode: %s\n", buf);
1005 test_notification(hwnd,"play",MCI_NOTIFY_SUPERSEDED);
1006 test_notification(hwnd,"status",MCI_NOTIFY_SUCCESSFUL);
1008 err = mciSendStringA("status mysound position", buf, sizeof(buf), hwnd);
1009 ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
1010 trace("position while paused: %sms\n",buf);
1011 p1 = atoi(buf);
1012 ok(p1>=p2, "position not increasing: %u > %u\n", p2, p1);
1014 err = mciSendStringA("stop mysound wait", NULL, 0, NULL);
1015 ok(!err,"mci stop returned %s\n", dbg_mcierr(err));
1017 err = mciSendStringA("info mysound file notify", buf, sizeof(buf), hwnd);
1018 ok(!err,"mci info file returned %s\n", dbg_mcierr(err));
1019 if(!err) { /* fully qualified name */
1020 int len = strlen(buf);
1021 todo_wine ok(len>2 && buf[1]==':',"Expected full pathname from info file: %s\n", buf);
1022 ok(len>=12 && !strcmp(&buf[len-12],"tempfile.wav"), "info file returned: %s\n", buf);
1024 test_notification(hwnd,"info file",MCI_NOTIFY_SUCCESSFUL);
1026 err = mciSendStringA("status mysound mode", buf, sizeof(buf), hwnd);
1027 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
1028 ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
1030 err = mciSendStringA("status mysound position", buf, sizeof(buf), hwnd);
1031 ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
1032 trace("position once stopped: %sms\n",buf);
1033 p2 = atoi(buf);
1034 /* An XP machine let the position increase slightly after pause. */
1035 ok(p2>=p1 && p2<=p1+16,"position changed from %ums to %ums\n",p1,p2);
1037 /* No Resume once stopped (waveaudio, sequencer and cdaudio differ). */
1038 err = mciSendStringA("resume mysound wait", NULL, 0, NULL);
1039 ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci resume wait returned %s\n", dbg_mcierr(err));
1041 err = mciSendStringA("play mysound wait", NULL, 0, NULL);
1042 ok(!err,"mci play wait returned %s\n", dbg_mcierr(err));
1044 err = mciSendStringA("status mysound position", buf, sizeof(buf), hwnd);
1045 ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
1046 todo_wine ok(!strcmp(buf,"2000"), "mci status position: %s\n", buf);
1048 err = mciSendStringA("seek mysound to start wait", NULL, 0, NULL);
1049 ok(!err,"mci seek to start wait returned %s\n", dbg_mcierr(err));
1051 err = mciSendStringA("play mysound to 1000 notify", NULL, 0, hwnd);
1052 ok(!err,"mci play returned %s\n", dbg_mcierr(err));
1054 /* Sleep(200); not needed with Wine any more. */
1056 err = mciSendStringA("pause mysound notify", NULL, 0, NULL); /* notify no callback */
1057 ok(!err,"mci pause notify returned %s\n", dbg_mcierr(err));
1058 /* Supersede even though pause cannot notify given no callback */
1059 test_notification(hwnd,"pause aborted play #1 notification",MCI_NOTIFY_SUPERSEDED);
1060 test_notification(hwnd,"impossible pause notification",0);
1062 err = mciSendStringA("cue mysound output notify", NULL, 0, hwnd);
1063 ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci cue output while paused returned %s\n", dbg_mcierr(err));
1064 test_notification(hwnd,"cue output notify #2",0);
1066 err = mciSendStringA("resume mysound notify", NULL, 0, hwnd);
1067 ok(!err,"mci resume notify returned %s\n", dbg_mcierr(err));
1068 test_notification(hwnd, "resume notify", MCI_NOTIFY_SUCCESSFUL);
1070 /* Seek or even Stop used to hang Wine<1.1.32 on MacOS. */
1071 err = mciSendStringA("seek mysound to 0 wait", NULL, 0, NULL);
1072 ok(!err,"mci seek to start returned %s\n", dbg_mcierr(err));
1074 /* Seek stops. */
1075 err = mciSendStringA("status mysound mode", buf, sizeof(buf), NULL);
1076 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
1077 if(!err) ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
1079 err = mciSendStringA("seek mysound wait", NULL, 0, NULL);
1080 ok(err==MCIERR_MISSING_PARAMETER,"mci seek to nowhere returned %s\n", dbg_mcierr(err));
1082 /* cdaudio does not detect to start to end as error */
1083 err = mciSendStringA("seek mysound to start to 0", NULL, 0, NULL);
1084 ok(err==MCIERR_FLAGS_NOT_COMPATIBLE,"mci seek to start to 0 returned %s\n", dbg_mcierr(err));
1086 err = mciSendStringA("PLAY mysound to 1000 notify", NULL, 0, hwnd);
1087 ok(!err,"mci play to 1000 notify returned %s\n", dbg_mcierr(err));
1089 /* Sleep(200); not needed with Wine any more. */
1090 /* Give it 400ms and resume will appear to complete below. */
1092 err = mciSendStringA("pause mysound wait", NULL, 0, NULL);
1093 ok(!err,"mci pause wait returned %s\n", dbg_mcierr(err));
1094 /* Unlike sequencer and cdaudio, waveaudio's pause does not abort. */
1095 test_notification(hwnd,"pause aborted play #2 notification",0);
1097 err = mciSendStringA("resume mysound wait", NULL, 0, NULL);
1098 ok(!err,"mci resume wait returned %s\n", dbg_mcierr(err));
1099 /* Resume is a short asynchronous call, something else is playing. */
1101 err = mciSendStringA("status mysound mode", buf, sizeof(buf), NULL);
1102 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
1103 if(!err) ok(!strcmp(buf,"playing"), "mci status mode: %s\n", buf);
1105 /* Note extra space before alias */
1106 err = mciSendStringA("pause mysound wait", NULL, 0, NULL);
1107 todo_wine ok(!err,"mci pause (space) wait returned %s\n", dbg_mcierr(err));
1109 err = mciSendStringA("pause mysound wait", NULL, 0, NULL);
1110 ok(!err,"mci pause wait returned %s\n", dbg_mcierr(err));
1112 /* Better ask position only when paused, is it updated while playing? */
1113 err = mciSendStringA("status mysound position", buf, sizeof(buf), NULL);
1114 ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
1115 /* TODO compare position < 900 */
1116 ok(strcmp(buf,"1000"), "mci resume waited\n");
1117 ok(strcmp(buf,"2000"), "mci resume played to end\n");
1118 trace("position after resume: %sms\n",buf);
1119 test_notification(hwnd,"play (aborted by pause/resume/pause)",0);
1121 err = mciSendStringA("close mysound wait", NULL, 0, NULL);
1122 ok(!err,"mci close wait returned %s\n", dbg_mcierr(err));
1123 test_notification(hwnd,"play (aborted by close)",MCI_NOTIFY_ABORTED);
1126 static void test_AutoOpenWAVE(HWND hwnd)
1128 /* This test used(?) to cause intermittent crashes when Wine exits, after
1129 * fixme:winmm:MMDRV_Exit Closing while ll-driver open
1131 UINT ndevs = waveOutGetNumDevs();
1132 MCIERROR err, ok_snd = ndevs ? 0 : MCIERR_HARDWARE;
1133 MCI_PARMS_UNION parm;
1134 char buf[512], path[300], command[330];
1135 DWORD intbuf[3] = { 0xDEADF00D, 99, 0xABADCAFE };
1136 memset(buf, 0, sizeof(buf)); memset(path, 0, sizeof(path));
1138 /* Do not crash on NULL buffer pointer */
1139 err = mciSendStringA("sysinfo waveaudio quantity open", NULL, 0, NULL);
1140 ok(err==MCIERR_PARAM_OVERFLOW,"mci sysinfo without buffer returned %s\n", dbg_mcierr(err));
1142 err = mciSendStringA("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL);
1143 ok(!err,"mci sysinfo waveaudio quantity open returned %s\n", dbg_mcierr(err));
1144 if(!err) ok(!strcmp(buf,"0"), "sysinfo quantity open expected 0, got: %s, some more tests will fail.\n", buf);
1146 /* Who knows why some MS machines pass all tests but return MCIERR_HARDWARE here? */
1147 /* Wine returns MCIERR_HARDWARE when no default sound is found in win.ini or the registry. */
1148 err = mciSendStringA("sound NoSuchSoundDefined wait", NULL, 0, NULL);
1149 ok(err==ok_snd || err==MCIERR_HARDWARE, "mci sound NoSuchSoundDefined returned %s\n", dbg_mcierr(err));
1151 err = mciSendStringA("sound SystemExclamation notify wait", NULL, 0, hwnd);
1152 ok(err==ok_snd || err==MCIERR_HARDWARE, "mci sound SystemExclamation returned %s\n", dbg_mcierr(err));
1153 test_notification(hwnd, "sound notify", err ? 0 : MCI_NOTIFY_SUCCESSFUL);
1155 Sleep(16); /* time to auto-close makes sysinfo below return expected error */
1156 err = mciSendStringA("sysinfo waveaudio notify name 1 open", buf, sizeof(buf), hwnd);
1157 ok(err==MCIERR_OUTOFRANGE,"sysinfo waveaudio name 1 returned %s\n", dbg_mcierr(err));
1158 if(!err) trace("sysinfo dangling open alias: %s\n", buf);
1159 test_notification(hwnd, "sysinfo name outofrange\n", err ? 0 : MCI_NOTIFY_SUCCESSFUL);
1161 err = mciSendStringA("play no-such-file-exists.wav notify", buf, sizeof(buf), NULL);
1162 todo_wine ok(err==MCIERR_NOTIFY_ON_AUTO_OPEN,"mci auto-open notify returned %s\n", dbg_mcierr(err));
1163 /* FILE_NOT_FOUND in Wine because auto-open fails before testing the notify flag */
1165 test_notification(hwnd, "-prior to auto-open-", 0);
1167 err = mciSendStringA("play tempfile.wav notify", buf, sizeof(buf), hwnd);
1168 if(ok_saved==MCIERR_FILE_NOT_FOUND) todo_wine /* same as above */
1169 ok(err==MCIERR_NOTIFY_ON_AUTO_OPEN,"mci auto-open play notify returned %s\n", dbg_mcierr(err));
1170 else
1171 ok(err==MCIERR_NOTIFY_ON_AUTO_OPEN,"mci auto-open play notify returned %s\n", dbg_mcierr(err));
1173 if(err) /* FIXME: don't open twice yet, it confuses Wine. */
1174 err = mciSendStringA("play tempfile.wav", buf, sizeof(buf), hwnd);
1175 ok(err==ok_saved,"mci auto-open play returned %s\n", dbg_mcierr(err));
1177 if(err==MCIERR_FILE_NOT_FOUND) {
1178 skip("Cannot open tempfile.wav for auto-play, skipping\n");
1179 return;
1182 err = mciSendStringA("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL);
1183 ok(!err,"mci sysinfo waveaudio quantity after auto-open returned %s\n", dbg_mcierr(err));
1184 if(!err) ok(!strcmp(buf,"1"), "sysinfo quantity open expected 1, got: %s\n", buf);
1186 parm.sys.lpstrReturn = (LPSTR)&intbuf[1];
1187 parm.sys.dwRetSize = 2*sizeof(DWORD); /* only one DWORD is used */
1188 parm.sys.wDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO;
1189 err = mciSendCommandA(0, MCI_SYSINFO, MCI_SYSINFO_QUANTITY | MCI_SYSINFO_OPEN, (DWORD_PTR)&parm);
1190 ok(!err, "mciCommand sysinfo waveaudio open notify returned %s\n", dbg_mcierr(err));
1191 if(!err) ok(atoi(buf)==intbuf[1],"sysinfo waveaudio quantity open string and command differ\n");
1193 err = mciSendStringA("sysinfo waveaudio name 1 open notify", buf, sizeof(buf), hwnd);
1194 ok(!err,"mci sysinfo waveaudio name after auto-open returned %s\n", dbg_mcierr(err));
1195 /* This is the alias, not necessarily a file name. */
1196 if(!err) ok(!strcmp(buf,"tempfile.wav"), "sysinfo name 1 open: %s\n", buf);
1197 test_notification(hwnd, "sysinfo name notify\n", MCI_NOTIFY_SUCCESSFUL);
1199 err = mciGetDeviceIDA("tempfile.wav");
1200 ok(err == 1, "mciGetDeviceIDA tempfile.wav returned %u, expected 1\n", err);
1202 /* Save the full pathname to the file. */
1203 err = mciSendStringA("info tempfile.wav file", path, sizeof(path), NULL);
1204 ok(!err,"mci info tempfile.wav file returned %s\n", dbg_mcierr(err));
1205 if(err) strcpy(path,"tempfile.wav");
1207 err = mciSendStringA("status tempfile.wav mode", NULL, 0, hwnd);
1208 ok(!err,"mci status tempfile.wav mode without buffer returned %s\n", dbg_mcierr(err));
1210 sprintf(command,"status \"%s\" mode",path);
1211 err = mciSendStringA(command, buf, sizeof(buf), hwnd);
1212 ok(!err,"mci status \"%s\" mode returned %s\n", path, dbg_mcierr(err));
1214 err = mciSendStringA("status tempfile.wav mode", buf, sizeof(buf), hwnd);
1215 ok(!err,"mci status tempfile.wav mode returned %s\n", dbg_mcierr(err));
1216 if(!err) ok(!strcmp(buf,"playing"), "mci auto-open status mode, got: %s\n", buf);
1218 err = mciSendStringA("open tempfile.wav", buf, sizeof(buf), NULL);
1219 ok(err==MCIERR_DEVICE_OPEN, "mci open from auto-open returned %s\n", dbg_mcierr(err));
1221 err = mciSendStringA("open foo.wav alias tempfile.wav", buf, sizeof(buf), NULL);
1222 ok(err==MCIERR_DUPLICATE_ALIAS, "mci open re-using alias returned %s\n", dbg_mcierr(err));
1224 /* w2k/xp and Wine differ. While the device is busy playing, it is
1225 * regularly open and accessible via the filename: subsequent
1226 * commands must not cause auto-open each. In Wine, a subsequent
1227 * command with notify request may cause the initial play
1228 * notification to be superseded, in turn causing MCI to close the
1229 * device. I.e. MCI uses the auto-open notification for itself,
1230 * that's why it's not available to the app. On w2k/xp,
1231 * subsequent commands with notify requests are returned with
1232 * MCIERR_NOTIFY_ON_AUTO_OPEN and thus don't abort the original
1233 * command.
1235 err = mciSendStringA("status tempfile.wav mode notify", buf, sizeof(buf), hwnd);
1236 todo_wine ok(err==MCIERR_NOTIFY_ON_AUTO_OPEN, "mci status auto-open notify returned %s\n", dbg_mcierr(err));
1237 if(!err) {
1238 trace("Wine style MCI auto-close upon notification\n");
1240 /* "playing" because auto-close comes after the status call. */
1241 ok(!strcmp(buf,"playing"), "mci auto-open status mode notify, got: %s\n", buf);
1242 /* fixme:winmm:MMDRV_Exit Closing while ll-driver open
1243 * is explained by failure to auto-close a device. */
1244 test_notification(hwnd,"status notify",MCI_NOTIFY_SUCCESSFUL);
1245 /* MCI received NOTIFY_SUPERSEDED and auto-closed the device. */
1247 /* Until this is implemented, force closing the device */
1248 err = mciSendStringA("close tempfile.wav", NULL, 0, hwnd);
1249 ok(!err,"mci auto-still-open stop returned %s\n", dbg_mcierr(err));
1250 Sleep(16);
1251 test_notification(hwnd,"auto-open",0);
1252 } else if(err==MCIERR_NOTIFY_ON_AUTO_OPEN) { /* MS style */
1253 trace("MS style MCI auto-open forbids notification\n");
1255 err = mciSendStringA("pause tempfile.wav", NULL, 0, hwnd);
1256 ok(!err,"mci auto-still-open pause returned %s\n", dbg_mcierr(err));
1258 err = mciSendStringA("status tempfile.wav mode", buf, sizeof(buf), hwnd);
1259 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
1260 if(!err) ok(!strcmp(buf,"paused"), "mci auto-open status mode, got: %s\n", buf);
1262 /* Auto-close */
1263 err = mciSendStringA("stop tempfile.wav wait", NULL, 0, hwnd);
1264 ok(!err,"mci auto-still-open stop returned %s\n", dbg_mcierr(err));
1265 Sleep(16); /* makes sysinfo quantity open below succeed */
1268 err = mciSendStringA("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL);
1269 ok(!err,"mci sysinfo waveaudio quantity open after close returned %s\n", dbg_mcierr(err));
1270 if(!err) ok(!strcmp(buf,"0"), "sysinfo quantity open expected 0 after auto-close, got: %s\n", buf);
1272 /* w95-WinME (not w2k/XP) switch to C:\ after auto-playing once. Prevent
1273 * MCIERR_FILE_NOT_FOUND by using the full path name from the Info file command.
1275 sprintf(command,"status \"%s\" mode wait",path);
1276 err = mciSendStringA(command, buf, sizeof(buf), hwnd);
1277 ok(!err,"mci re-auto-open status mode returned %s\n", dbg_mcierr(err));
1278 if(!err) ok(!strcmp(buf,"stopped"), "mci re-auto-open status mode, got: %s\n", buf);
1280 /* This uses auto-open as well. */
1281 err = mciSendStringA("capability waveaudio outputs", buf, sizeof(buf), NULL);
1282 ok(!err,"mci capability waveaudio outputs returned %s\n", dbg_mcierr(err));
1283 /* Wine with no sound selected in winecfg's audio tab fails this test. */
1284 if(!err) ok(atoi(buf)==ndevs,"Expected %d audio outputs, got %s\n", ndevs, buf);
1286 err = mciSendStringA("capability waveaudio device type", buf, sizeof(buf), hwnd);
1287 ok(!err,"mci capability device type returned %s\n", dbg_mcierr(err));
1288 if(!err) ok(!strcmp(buf,"waveaudio"), "mci capability device type response: %s\n", buf);
1290 /* waveaudio forbids Pause without Play. */
1291 sprintf(command,"pause \"%s\"",path);
1292 err = mciSendStringA(command, NULL, 0, hwnd);
1293 ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci auto-open pause returned %s\n", dbg_mcierr(err));
1295 ok(0xDEADF00D==intbuf[0] && 0xABADCAFE==intbuf[2],"DWORD buffer corruption\n");
1298 START_TEST(mci)
1300 char curdir[MAX_PATH], tmpdir[MAX_PATH];
1301 MCIERROR err;
1302 HWND hwnd;
1304 GetCurrentDirectoryA(MAX_PATH, curdir);
1305 GetTempPathA(MAX_PATH, tmpdir);
1306 SetCurrentDirectoryA(tmpdir);
1308 hwnd = CreateWindowExA(0, "static", "winmm test", WS_POPUP, 0,0,100,100,
1309 0, 0, 0, NULL);
1310 test_mciParser(hwnd);
1311 test_openCloseWAVE(hwnd);
1312 test_recordWAVE(hwnd);
1313 if(waveOutGetNumDevs()){
1314 test_playWAVE(hwnd);
1315 test_asyncWAVE(hwnd);
1316 test_AutoOpenWAVE(hwnd);
1317 }else
1318 skip("No output devices available, skipping all output tests\n");
1319 /* Win9X hangs when exiting with something still open. */
1320 err = mciSendStringA("close all", NULL, 0, hwnd);
1321 ok(!err,"final close all returned %s\n", dbg_mcierr(err));
1322 ok(DeleteFileA("tempfile.wav") || ok_saved, "Delete tempfile.wav (cause auto-open?)\n");
1323 DestroyWindow(hwnd);
1325 SetCurrentDirectoryA(curdir);