4 * Copyright 2006 Jan Zerebecki
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
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
;
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
;
40 MCI_GENERIC_PARMS gen
;
43 const char* dbg_mcierr(MCIERROR 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
)
52 X(MCIERR_INVALID_DEVICE_NAME
)
53 X(MCIERR_OUT_OF_MEMORY
)
55 X(MCIERR_CANNOT_LOAD_DRIVER
)
56 X(MCIERR_MISSING_COMMAND_STRING
)
57 X(MCIERR_PARAM_OVERFLOW
)
58 X(MCIERR_MISSING_STRING_ARGUMENT
)
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
)
68 X(MCIERR_CANNOT_USE_ALL
)
70 X(MCIERR_EXTENSION_NOT_FOUND
)
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
)
97 X(MCIERR_DEVICE_LENGTH
)
98 X(MCIERR_DEVICE_ORD_LENGTH
)
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
)
116 X(MCIERR_SEQ_PORTUNSPECIFIED
)
117 X(MCIERR_SEQ_NOMIDIPRESENT
)
119 X(MCIERR_CREATEWINDOW
)
122 X(MCIERR_NO_IDENTITY
)
125 static char name
[20]; /* Not to be called twice in a parameter list! */
126 sprintf(name
, "MMSYSERR %u", err
);
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
);
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 */
148 do { seen
= PeekMessageA(&msg
, hwnd
, 0, 0, PM_REMOVE
); }
149 while(seen
&& spurious_message(&msg
));
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
);
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 void test_mciParser(HWND hwnd
)
169 MCIDEVICEID wDeviceID
;
170 MCI_PARMS_UNION parm
;
172 memset(buf
, 0, sizeof(buf
));
173 test_notification(hwnd
, "-prior to parser test-", 0);
175 /* Get a handle on an MCI device, works even without sound. */
176 parm
.open
.lpstrDeviceType
= "waveaudio";
177 parm
.open
.lpstrElementName
= ""; /* "new" at the command level */
178 parm
.open
.lpstrAlias
= "x"; /* to enable mciSendStringA */
179 parm
.open
.dwCallback
= (DWORD_PTR
)hwnd
;
180 err
= mciSendCommandA(0, MCI_OPEN
,
181 MCI_OPEN_ELEMENT
| MCI_OPEN_TYPE
| MCI_OPEN_ALIAS
| MCI_NOTIFY
, (DWORD_PTR
)&parm
);
182 ok(!err
,"mciCommand open new type waveaudio alias x notify: %s\n", dbg_mcierr(err
));
183 wDeviceID
= parm
.open
.wDeviceID
;
184 ok(!strcmp(parm
.open
.lpstrDeviceType
,"waveaudio"), "open modified device type\n");
186 test_notification(hwnd
, "MCI_OPEN", MCI_NOTIFY_SUCCESSFUL
);
187 test_notification(hwnd
, "MCI_OPEN no #2", 0);
189 err
= mciSendStringA("open avivideo alias a", buf
, sizeof(buf
), hwnd
);
190 ok(!err
,"open another: %s\n", dbg_mcierr(err
));
193 err
= mciSendStringA("", buf
, sizeof(buf
), NULL
);
194 ok(err
==MCIERR_MISSING_COMMAND_STRING
,"empty string: %s\n", dbg_mcierr(err
));
195 ok(!buf
[0], "error buffer %s\n", buf
);
198 err
= mciSendStringA("open", buf
, sizeof(buf
), NULL
);
199 ok(err
==MCIERR_MISSING_DEVICE_NAME
,"open void: %s\n", dbg_mcierr(err
));
200 ok(!buf
[0], "open error buffer %s\n", buf
);
202 err
= mciSendStringA("open notify", buf
, sizeof(buf
), NULL
);
203 todo_wine
ok(err
==MCIERR_INVALID_DEVICE_NAME
,"open notify: %s\n", dbg_mcierr(err
));
205 err
= mciSendStringA("open new", buf
, sizeof(buf
), NULL
);
206 todo_wine
ok(err
==MCIERR_NEW_REQUIRES_ALIAS
,"open new: %s\n", dbg_mcierr(err
));
208 err
= mciSendStringA("open new type waveaudio alias r shareable shareable", buf
, sizeof(buf
), NULL
);
209 todo_wine
ok(err
==MCIERR_DUPLICATE_FLAGS
,"open new: %s\n", dbg_mcierr(err
));
210 if(!err
) mciSendStringA("close r", NULL
, 0, NULL
);
212 err
= mciSendStringA("status x position wait wait", buf
, sizeof(buf
), NULL
);
213 todo_wine
ok(err
==MCIERR_DUPLICATE_FLAGS
,"status wait wait: %s\n", dbg_mcierr(err
));
215 err
= mciSendStringA("status x length length", buf
, sizeof(buf
), NULL
);
216 todo_wine
ok(err
==MCIERR_FLAGS_NOT_COMPATIBLE
,"status 2xlength: %s\n", dbg_mcierr(err
));
218 err
= mciSendStringA("status x length position", buf
, sizeof(buf
), NULL
);
219 todo_wine
ok(err
==MCIERR_FLAGS_NOT_COMPATIBLE
,"status length+position: %s\n", dbg_mcierr(err
));
222 err
= mciSendStringA("set x time format milliseconds time format ms", buf
, sizeof(buf
), NULL
);
223 todo_wine
ok(err
==MCIERR_FLAGS_NOT_COMPATIBLE
,"status length+position: %s\n", dbg_mcierr(err
));
224 ok(!buf
[0], "set error buffer %s\n", buf
);
226 /* device's response, not a parser test */
227 err
= mciSendStringA("status x", buf
, sizeof(buf
), NULL
);
228 ok(err
==MCIERR_MISSING_PARAMETER
,"status waveaudio nokeyword: %s\n", dbg_mcierr(err
));
231 err
= mciSendStringA("status a", buf
, sizeof(buf
), NULL
);
232 todo_wine
ok(err
==MCIERR_UNSUPPORTED_FUNCTION
,"status avivideo nokeyword: %s\n", dbg_mcierr(err
));
233 ok(!buf
[0], "status error buffer %s\n", buf
);
235 err
= mciSendStringA("status x track", buf
, sizeof(buf
), NULL
);
236 ok(err
==MCIERR_BAD_INTEGER
,"status waveaudio no track: %s\n", dbg_mcierr(err
));
238 err
= mciSendStringA("status x track 3", buf
, sizeof(buf
), NULL
);
239 ok(err
==MCIERR_MISSING_PARAMETER
,"status waveaudio track 3: %s\n", dbg_mcierr(err
));
241 err
= mciSendStringA("status x 2 track 3", buf
, sizeof(buf
), NULL
);
242 todo_wine
ok(err
==MCIERR_OUTOFRANGE
,"status 2(position) track 3: %s\n", dbg_mcierr(err
));
244 err
= mciSendStringA("status x 0x4", buf
, sizeof(buf
), NULL
);
245 todo_wine
ok(err
==MCIERR_BAD_CONSTANT
, "status 0x4: %s\n", dbg_mcierr(err
));
247 err
= mciSendStringA("status x 4", buf
, sizeof(buf
), hwnd
);
248 ok(!err
,"status 4(mode): %s\n", dbg_mcierr(err
));
249 if(!err
)ok(!strcmp(buf
,"stopped"), "status 4(mode), got: %s\n", buf
);
251 err
= mciSendStringA("status x 4 notify", buf
, sizeof(buf
), hwnd
);
252 todo_wine
ok(!err
,"status 4(mode) notify: %s\n", dbg_mcierr(err
));
253 if(!err
)ok(!strcmp(buf
,"stopped"), "status 4(mode), got: %s\n", buf
);
254 test_notification(hwnd
, "status 4 notify", err
? 0 : MCI_NOTIFY_SUCCESSFUL
);
256 err
= mciSendStringA("set x milliseconds", buf
, sizeof(buf
), hwnd
);
257 todo_wine
ok(err
==MCIERR_UNRECOGNIZED_KEYWORD
,"set milliseconds: %s\n", dbg_mcierr(err
));
259 err
= mciSendStringA("set x milliseconds ms", buf
, sizeof(buf
), hwnd
);
260 todo_wine
ok(err
==MCIERR_UNRECOGNIZED_KEYWORD
,"set milliseconds ms: %s\n", dbg_mcierr(err
));
262 err
= mciSendStringA("capability x can save", buf
, sizeof(buf
), hwnd
);
263 todo_wine
ok(!err
,"capability can (space) save: %s\n", dbg_mcierr(err
));
265 err
= mciSendStringA("status x nsa", buf
, sizeof(buf
), hwnd
);
266 todo_wine
ok(err
==MCIERR_BAD_CONSTANT
,"status nsa: %s\n", dbg_mcierr(err
));
268 err
= mciSendStringA("seek x to 0:0:0:0:0", buf
, sizeof(buf
), NULL
);
269 ok(err
==MCIERR_BAD_INTEGER
,"seek to 0:0:0:0:0 returned %s\n", dbg_mcierr(err
));
271 err
= mciSendStringA("seek x to 0:0:0:0:", buf
, sizeof(buf
), NULL
);
272 ok(err
==MCIERR_BAD_INTEGER
,"seek to 0:0:0:0: returned %s\n", dbg_mcierr(err
));
274 err
= mciSendStringA("seek x to :0:0:0:0", buf
, sizeof(buf
), NULL
);
275 ok(err
==MCIERR_BAD_INTEGER
,"seek to :0:0:0:0 returned %s\n", dbg_mcierr(err
));
277 err
= mciSendStringA("seek x to 256:0:0:0", buf
, sizeof(buf
), NULL
);
278 ok(err
==MCIERR_BAD_INTEGER
,"seek to 256:0:0:0 returned %s\n", dbg_mcierr(err
));
280 err
= mciSendStringA("seek x to 0:256", buf
, sizeof(buf
), NULL
);
281 ok(err
==MCIERR_BAD_INTEGER
,"seek to 0:256 returned %s\n", dbg_mcierr(err
));
283 err
= mciSendStringA("status all time format", buf
, sizeof(buf
), hwnd
);
284 ok(err
==MCIERR_CANNOT_USE_ALL
,"status all: %s\n", dbg_mcierr(err
));
286 err
= mciSendStringA("cue all", buf
, sizeof(buf
), NULL
);
287 ok(err
==MCIERR_UNRECOGNIZED_COMMAND
,"cue all: %s\n", dbg_mcierr(err
));
289 err
= mciSendStringA("open all", buf
, sizeof(buf
), NULL
);
290 todo_wine
ok(err
==MCIERR_CANNOT_USE_ALL
,"open all: %s\n", dbg_mcierr(err
));
292 /* avivideo is not a known MCI_DEVTYPE resource name */
293 err
= mciSendStringA("sysinfo avivideo quantity", buf
, sizeof(buf
), hwnd
);
294 ok(err
==MCIERR_DEVICE_TYPE_REQUIRED
,"sysinfo sequencer quantity: %s\n", dbg_mcierr(err
));
296 err
= mciSendStringA("sysinfo digitalvideo quantity", buf
, sizeof(buf
), hwnd
);
297 ok(!err
,"sysinfo digitalvideo quantity: %s\n", dbg_mcierr(err
));
298 if(!err
) ok(!strcmp(buf
,"0"), "sysinfo digitalvideo quantity returned %s\n", buf
);
300 /* quantity 0 yet open 1 (via type "avivideo"), fun */
301 err
= mciSendStringA("sysinfo digitalvideo quantity open", buf
, sizeof(buf
), hwnd
);
302 ok(!err
,"sysinfo digitalvideo quantity open: %s\n", dbg_mcierr(err
));
303 if(!err
) ok(!strcmp(buf
,"1"), "sysinfo digitalvideo quantity open returned %s\n", buf
);
305 err
= mciSendStringA("put a window at 0 0", buf
, sizeof(buf
), NULL
);
306 ok(err
==MCIERR_BAD_INTEGER
,"put incomplete rect: %s\n", dbg_mcierr(err
));
308 /*w9X-w2k report code from device last opened, newer versions compare them all
309 * and return the one error code or MCIERR_MULTIPLE if they differ. */
310 err
= mciSendStringA("pause all", buf
, sizeof(buf
), NULL
);
311 todo_wine
ok(err
==MCIERR_MULTIPLE
|| broken(err
==MCIERR_NONAPPLICABLE_FUNCTION
),"pause all: %s\n", dbg_mcierr(err
));
312 ok(!buf
[0], "pause error buffer %s\n", buf
);
314 /* MCI_STATUS' dwReturn is a DWORD_PTR, others' a plain DWORD. */
315 parm
.status
.dwItem
= MCI_STATUS_TIME_FORMAT
;
316 parm
.status
.dwReturn
= 0xFEEDABAD;
317 err
= mciSendCommandA(wDeviceID
, MCI_STATUS
, MCI_STATUS_ITEM
, (DWORD_PTR
)&parm
);
318 ok(!err
,"mciCommand status time format: %s\n", dbg_mcierr(err
));
319 if(!err
) ok(MCI_FORMAT_MILLISECONDS
==parm
.status
.dwReturn
,"status time format: %ld\n",parm
.status
.dwReturn
);
321 parm
.status
.dwItem
= MCI_STATUS_MODE
;
322 parm
.status
.dwReturn
= 0xFEEDABAD;
323 err
= mciSendCommandA(wDeviceID
, MCI_STATUS
, MCI_STATUS_ITEM
, (DWORD_PTR
)&parm
);
324 ok(!err
,"mciCommand status mode: %s\n", dbg_mcierr(err
));
325 if(!err
) ok(MCI_MODE_STOP
==parm
.status
.dwReturn
,"STATUS mode: %ld\n",parm
.status
.dwReturn
);
327 err
= mciSendStringA("status x mode", buf
, sizeof(buf
), hwnd
);
328 ok(!err
,"status mode: %s\n", dbg_mcierr(err
));
329 if(!err
) ok(!strcmp(buf
, "stopped"), "status mode is %s\n", buf
);
331 parm
.caps
.dwItem
= MCI_GETDEVCAPS_USES_FILES
;
332 parm
.caps
.dwReturn
= 0xFEEDABAD;
333 err
= mciSendCommandA(wDeviceID
, MCI_GETDEVCAPS
, MCI_GETDEVCAPS_ITEM
, (DWORD_PTR
)&parm
);
334 ok(!err
,"mciCommand getdevcaps files: %s\n", dbg_mcierr(err
));
335 if(!err
) ok(1==parm
.caps
.dwReturn
,"getdevcaps files: %d\n",parm
.caps
.dwReturn
);
337 parm
.caps
.dwItem
= MCI_GETDEVCAPS_HAS_VIDEO
;
338 parm
.caps
.dwReturn
= 0xFEEDABAD;
339 err
= mciSendCommandA(wDeviceID
, MCI_GETDEVCAPS
, MCI_GETDEVCAPS_ITEM
, (DWORD_PTR
)&parm
);
340 ok(!err
,"mciCommand getdevcaps video: %s\n", dbg_mcierr(err
));
341 if(!err
) ok(0==parm
.caps
.dwReturn
,"getdevcaps video: %d\n",parm
.caps
.dwReturn
);
343 parm
.caps
.dwItem
= MCI_GETDEVCAPS_DEVICE_TYPE
;
344 parm
.caps
.dwReturn
= 0xFEEDABAD;
345 err
= mciSendCommandA(wDeviceID
, MCI_GETDEVCAPS
, MCI_GETDEVCAPS_ITEM
, (DWORD_PTR
)&parm
);
346 ok(!err
,"mciCommand getdevcaps video: %s\n", dbg_mcierr(err
));
347 if(!err
) ok(MCI_DEVTYPE_WAVEFORM_AUDIO
==parm
.caps
.dwReturn
,"getdevcaps device type: %d\n",parm
.caps
.dwReturn
);
349 err
= mciSendStringA("capability x uses files", buf
, sizeof(buf
), hwnd
);
350 ok(!err
,"capability files: %s\n", dbg_mcierr(err
));
351 if(!err
) ok(!strcmp(buf
, "true"), "capability files is %s\n", buf
);
353 err
= mciSendStringA("capability x has video", buf
, sizeof(buf
), hwnd
);
354 ok(!err
,"capability video: %s\n", dbg_mcierr(err
));
355 if(!err
) ok(!strcmp(buf
, "false"), "capability video is %s\n", buf
);
357 err
= mciSendStringA("capability x device type", buf
, sizeof(buf
), hwnd
);
358 ok(!err
,"capability device type: %s\n", dbg_mcierr(err
));
359 if(!err
) ok(!strcmp(buf
, "waveaudio"), "capability device type is %s\n", buf
);
361 err
= mciSendStringA("info a version", buf
, sizeof(buf
), hwnd
);
362 ok(!err
,"info version: %s\n", dbg_mcierr(err
));
363 if(!err
) ok(!strcmp(buf
, "1.1"), "info version is %s\n", buf
);
365 err
= mciSendCommandA(wDeviceID
, MCI_CLOSE
, 0, 0);
366 ok(!err
,"mciCommand close returned %s\n", dbg_mcierr(err
));
368 err
= mciSendStringA("close a", buf
, sizeof(buf
), hwnd
);
369 ok(!err
,"close avi: %s\n", dbg_mcierr(err
));
371 test_notification(hwnd
, "-end of 1st set-", 0);
374 static void test_openCloseWAVE(HWND hwnd
)
377 MCI_PARMS_UNION parm
;
378 const char command_open
[] = "open new type waveaudio alias mysound notify";
379 const char command_close_my
[] = "close mysound notify";
380 const char command_close_all
[] = "close all notify";
381 const char command_sysinfo
[] = "sysinfo waveaudio quantity open";
383 DWORD intbuf
[3] = { 0xDEADF00D, 99, 0xABADCAFE };
384 memset(buf
, 0, sizeof(buf
));
385 test_notification(hwnd
, "-prior to any command-", 0);
387 /* Avoid Sysinfo quantity with notify because Win9x and newer differ. */
388 err
= mciSendStringA("sysinfo all quantity", buf
, sizeof(buf
), hwnd
);
389 ok(!err
,"mci sysinfo all quantity returned %s\n", dbg_mcierr(err
));
390 if(!err
) trace("[MCI] with %s drivers\n", buf
);
392 parm
.sys
.lpstrReturn
= (LPSTR
)&intbuf
[1];
393 parm
.sys
.dwRetSize
= sizeof(DWORD
);
394 parm
.sys
.wDeviceType
= MCI_DEVTYPE_WAVEFORM_AUDIO
; /* ignored */
395 err
= mciSendCommandA(MCI_ALL_DEVICE_ID
, MCI_SYSINFO
, MCI_SYSINFO_QUANTITY
| MCI_WAIT
,
397 ok(!err
, "mciCommand sysinfo all quantity returned %s\n", dbg_mcierr(err
));
398 if(!err
) ok(atoi(buf
)==intbuf
[1],"sysinfo all quantity string and command differ\n");
400 parm
.sys
.dwRetSize
= sizeof(DWORD
)-1;
401 err
= mciSendCommandA(MCI_ALL_DEVICE_ID
, MCI_SYSINFO
, MCI_SYSINFO_QUANTITY
, (DWORD_PTR
)&parm
);
402 ok(err
== MCIERR_PARAM_OVERFLOW
|| broken(!err
/* Win9x */),
403 "mciCommand sysinfo with too small buffer returned %s\n", dbg_mcierr(err
));
405 err
= mciSendStringA("open new type waveaudio alias r shareable", buf
, sizeof(buf
), NULL
);
406 ok(err
==MCIERR_UNSUPPORTED_FUNCTION
,"mci open new shareable returned %s\n", dbg_mcierr(err
));
408 err
= mciSendStringA("close r", NULL
, 0, NULL
);
409 ok(!err
,"mci close shareable returned %s\n", dbg_mcierr(err
));
412 err
= mciGetDeviceIDA("waveaudio");
413 ok(!err
, "mciGetDeviceIDA waveaudio returned %u, expected 0\n", err
);
415 err
= mciSendStringA(command_open
, buf
, sizeof(buf
), hwnd
);
416 ok(!err
,"mci %s returned %s\n", command_open
, dbg_mcierr(err
));
417 ok(!strcmp(buf
,"1"), "mci open deviceId: %s, expected 1\n", buf
);
418 /* Wine<=1.1.33 used to ignore anything past alias XY */
419 test_notification(hwnd
,"open new alias notify",MCI_NOTIFY_SUCCESSFUL
);
421 err
= mciSendStringA("status mysound time format", buf
, sizeof(buf
), hwnd
);
422 ok(!err
,"mci status time format returned %s\n", dbg_mcierr(err
));
424 if (PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) == LANG_ENGLISH
)
425 ok(!strcmp(buf
,"milliseconds"), "mci status time format: %s\n", buf
);
426 else trace("locale-dependent time format: %s (ms)\n", buf
);
429 memset(buf
, 0, sizeof(buf
));
430 parm
.sys
.dwNumber
= 1;
431 parm
.sys
.wDeviceType
= MCI_DEVTYPE_WAVEFORM_AUDIO
; /* ignored */
432 parm
.sys
.lpstrReturn
= buf
;
433 parm
.sys
.dwRetSize
= sizeof(buf
);
434 parm
.sys
.dwCallback
= (DWORD_PTR
)hwnd
;
435 err
= mciSendCommandA(MCI_ALL_DEVICE_ID
, MCI_SYSINFO
,
436 MCI_SYSINFO_NAME
| MCI_SYSINFO_OPEN
| MCI_NOTIFY
, (DWORD_PTR
)&parm
);
437 ok(!err
,"mciCommand MCI_SYSINFO all name 1 open notify: %s\n", dbg_mcierr(err
));
438 if(!err
) ok(!strcmp(buf
,"mysound"), "sysinfo name returned %s\n", buf
);
439 test_notification(hwnd
, "SYSINFO name notify\n", MCI_NOTIFY_SUCCESSFUL
);
441 memset(buf
, 0, sizeof(buf
));
442 parm
.sys
.dwNumber
= 1;
443 parm
.sys
.wDeviceType
= MCI_DEVTYPE_WAVEFORM_AUDIO
; /* ignored */
444 parm
.sys
.lpstrReturn
= buf
;
445 parm
.sys
.dwRetSize
= 8; /* mysound\0 */
446 err
= mciSendCommandA(MCI_ALL_DEVICE_ID
, MCI_SYSINFO
, MCI_SYSINFO_NAME
| MCI_SYSINFO_OPEN
,
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
);
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(!lstrcmpW((LPWSTR
)buf
, L
"mysound"), "sysinfo name 1 open contents\n");
462 memset(buf
, 0, sizeof(buf
));
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
);
472 /* Win9x overwrites the tiny buffer and returns success, newer versions signal overflow. */
473 memset(buf
, 0, sizeof(buf
));
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
= mciSendCommandA(MCI_ALL_DEVICE_ID
, MCI_SYSINFO
, MCI_SYSINFO_NAME
| MCI_SYSINFO_OPEN
,
481 ok(err
==MCIERR_PARAM_OVERFLOW
|| broken(!err
/* Win9x */),"mciCommand MCI_SYSINFO all name 1 open too small: %s\n", dbg_mcierr(err
));
482 ok(!strcmp(buf
, err
? "Y" : "mysound"), "sysinfo short name returned %s\n", buf
);
484 err
= mciSendStringA("sysinfo mysound quantity open", buf
, sizeof(buf
), hwnd
);
485 ok(err
==MCIERR_DEVICE_TYPE_REQUIRED
,"sysinfo alias quantity: %s\n", dbg_mcierr(err
));
487 err
= mciSendStringA("sysinfo nosuchalias quantity open", buf
, sizeof(buf
), hwnd
);
488 ok(err
==MCIERR_DEVICE_TYPE_REQUIRED
,"sysinfo unknown quantity open: %s\n", dbg_mcierr(err
));
490 err
= mciSendStringA("sysinfo all installname", buf
, sizeof(buf
), hwnd
);
491 ok(err
==MCIERR_CANNOT_USE_ALL
,"sysinfo all installname: %s\n", dbg_mcierr(err
));
493 buf
[0] = 'M'; buf
[1] = 0;
494 parm
.sys
.lpstrReturn
= buf
;
495 parm
.sys
.dwRetSize
= sizeof(buf
);
496 err
= mciSendCommandA(MCI_ALL_DEVICE_ID
, MCI_SYSINFO
, MCI_SYSINFO_INSTALLNAME
, (DWORD_PTR
)&parm
);
497 ok(err
==MCIERR_CANNOT_USE_ALL
,"mciCommand MCI_SYSINFO all installname: %s\n", dbg_mcierr(err
));
498 ok(!strcmp(buf
,"M"), "output buffer %s\n", buf
);
500 err
= mciSendStringA("sysinfo nodev installname", buf
, sizeof(buf
), hwnd
);
501 ok(err
==MCIERR_INVALID_DEVICE_NAME
,"sysinfo nodev installname: %s\n", dbg_mcierr(err
));
502 ok(!buf
[0], "sysinfo error buffer %s\n", buf
);
505 parm
.sys
.lpstrReturn
= buf
;
506 parm
.sys
.dwRetSize
= sizeof(buf
);
507 err
= mciSendCommandW(24000, MCI_SYSINFO
, MCI_SYSINFO_INSTALLNAME
, (DWORD_PTR
)&parm
);
508 ok(err
==MCIERR_INVALID_DEVICE_NAME
|| broken(err
==MMSYSERR_NOTSUPPORTED
/* Win9x */), "mciCommand MCI_SYSINFO nodev installname: %s\n", dbg_mcierr(err
));
509 ok(!strcmp(buf
,"K"), "output buffer %s\n", buf
);
511 buf
[0] = 0; buf
[1] = 'A'; buf
[2] = 'j'; buf
[3] = 0;
512 parm
.info
.lpstrReturn
= buf
;
513 parm
.info
.dwRetSize
= 2;
514 err
= mciSendCommandA(1, MCI_INFO
, MCI_INFO_PRODUCT
, (DWORD_PTR
)&parm
);
515 ok(!err
, "mciCommand MCI_INFO product: %s\n", dbg_mcierr(err
));
516 ok(buf
[0] /* && !buf[1] */ && (buf
[2] == 'j' || broken(!buf
[2])), "info product output buffer %s\n", buf
);
517 /* Producing non-ASCII multi-byte output, native forgets to zero-terminate a too small buffer
518 * with SendStringA, while SendStringW works correctly (jap. and chin. locale): ignore buf[1] */
519 /* Bug in 64 bit Vista/w2k8/w7: mciSendStringW is used! (not in xp nor w2k3) */
521 buf
[0] = 'K'; buf
[1] = 0;
522 parm
.info
.dwRetSize
= sizeof(buf
);
523 err
= mciSendCommandW(1, MCI_INFO
, 0x07000000, (DWORD_PTR
)&parm
);
524 ok(err
==MCIERR_UNRECOGNIZED_KEYWORD
|| broken(err
==MMSYSERR_NOTSUPPORTED
/* Win9x */), "mciCommand MCI_INFO other: %s\n", dbg_mcierr(err
));
525 ok(!strcmp(buf
,"K"), "info output buffer %s\n", buf
);
527 err
= mciGetDeviceIDA("all");
528 ok(err
== MCI_ALL_DEVICE_ID
, "mciGetDeviceIDA all returned %u, expected MCI_ALL_DEVICE_ID\n", err
);
530 err
= mciSendStringA(command_close_my
, NULL
, 0, hwnd
);
531 ok(!err
,"mci %s returned %s\n", command_close_my
, dbg_mcierr(err
));
532 test_notification(hwnd
, command_close_my
, MCI_NOTIFY_SUCCESSFUL
);
534 test_notification(hwnd
, command_close_my
, 0);
536 err
= mciSendStringA("open no-such-file-exists.wav alias y buffer 6", buf
, sizeof(buf
), NULL
);
537 ok(err
==MCIERR_FILE_NOT_FOUND
,"open no-such-file.wav returned %s\n", dbg_mcierr(err
));
539 err
= mciSendStringA("close y", NULL
, 0, NULL
);
540 ok(!err
,"close y returned %s\n", dbg_mcierr(err
));
543 err
= mciSendStringA("open no-such-dir\\file.wav alias y type waveaudio", buf
, sizeof(buf
), NULL
);
544 ok(err
==MCIERR_FILE_NOT_FOUND
|| broken(err
==MCIERR_INVALID_FILE
/* Win9X */),"open no-such-dir/file.wav returned %s\n", dbg_mcierr(err
));
546 err
= mciSendStringA("close y", NULL
, 0, NULL
);
547 ok(!err
,"close y returned %s\n", dbg_mcierr(err
));
550 err
= mciSendStringA("open ! alias no", buf
, sizeof(buf
), NULL
);
551 ok(err
==MCIERR_INVALID_DEVICE_NAME
,"open !(void): %s\n", dbg_mcierr(err
));
553 err
= mciSendStringA("open !no-such-file-exists.wav alias no", buf
, sizeof(buf
), NULL
);
554 ok(err
==MCIERR_FILE_NOT_FOUND
|| /* Win9X */err
==MCIERR_INVALID_DEVICE_NAME
,"open !name: %s\n", dbg_mcierr(err
));
556 /* FILE_NOT_FOUND stems from mciwave,
557 * the complete name including ! is passed through since NT */
558 err
= mciSendStringA("open nosuchdevice!tempfile.wav alias no", buf
, sizeof(buf
), NULL
);
559 ok(err
==MCIERR_FILE_NOT_FOUND
|| /* Win9X */err
==MCIERR_INVALID_DEVICE_NAME
,"open nosuchdevice!name: %s\n", dbg_mcierr(err
));
560 /* FIXME? use broken(INVALID_DEVICE_NAME) and have Wine not mimic Win9X? */
562 err
= mciSendStringA("close waveaudio", buf
, sizeof(buf
), NULL
);
563 ok(err
==MCIERR_INVALID_DEVICE_NAME
,"close waveaudio: %s\n", dbg_mcierr(err
));
565 err
= mciSendStringA(command_close_all
, NULL
, 0, NULL
);
566 ok(!err
,"mci %s (without buffer) returned %s\n", command_close_all
, dbg_mcierr(err
));
568 err
= mciSendStringA(command_close_all
, buf
, sizeof(buf
), hwnd
);
569 ok(!err
,"mci %s (with output buffer) returned %s\n", command_close_all
, dbg_mcierr(err
));
570 ok(buf
[0] == 0, "mci %s output buffer: %s\n", command_close_all
, buf
);
571 /* No notification left, everything closed already */
572 test_notification(hwnd
, command_close_all
, 0);
573 /* TODO test close all sends one notification per open device */
575 err
= mciSendStringA(command_sysinfo
, buf
, sizeof(buf
), NULL
);
576 ok(!err
,"mci %s returned %s\n", command_sysinfo
, dbg_mcierr(err
));
577 ok(buf
[0] == '0' && buf
[1] == 0, "mci %s, expected output buffer '0', got: '%s'\n", command_sysinfo
, buf
);
579 err
= mciSendStringA("open new type waveaudio", buf
, sizeof(buf
), NULL
);
580 ok(err
==MCIERR_NEW_REQUIRES_ALIAS
,"mci open new without alias returned %s\n", dbg_mcierr(err
));
582 parm
.open
.lpstrDeviceType
= (LPSTR
)MCI_DEVTYPE_WAVEFORM_AUDIO
;
583 err
= mciSendCommandA(0, MCI_OPEN
, MCI_OPEN_TYPE
| MCI_OPEN_TYPE_ID
, (DWORD_PTR
)&parm
);
584 ok(!err
,"mciCommand OPEN_TYPE_ID waveaudio: %s\n", dbg_mcierr(err
));
587 MCIDEVICEID wDeviceID
= parm
.open
.wDeviceID
;
588 parm
.caps
.dwItem
= MCI_GETDEVCAPS_DEVICE_TYPE
;
589 err
= mciSendCommandA(wDeviceID
, MCI_GETDEVCAPS
, MCI_GETDEVCAPS_ITEM
, (DWORD_PTR
)&parm
);
590 ok(!err
,"mciCommand MCI_GETDEVCAPS device type: %s\n", dbg_mcierr(err
));
591 ok(MCI_DEVTYPE_WAVEFORM_AUDIO
==parm
.caps
.dwReturn
,"mciCommand GETDEVCAPS says %u, expected %u\n", parm
.caps
.dwReturn
, MCI_DEVTYPE_WAVEFORM_AUDIO
);
594 ok(0xDEADF00D==intbuf
[0] && 0xABADCAFE==intbuf
[2],"DWORD buffer corruption\n");
596 err
= mciGetDeviceIDA("waveaudio");
597 ok(err
== 1, "mciGetDeviceIDA waveaudio returned %u, expected 1\n", err
);
599 err
= mciSendStringA("open no-such-file.wav alias waveaudio", buf
, sizeof(buf
), NULL
);
600 ok(err
==MCIERR_DUPLICATE_ALIAS
, "mci open alias waveaudio returned %s\n", dbg_mcierr(err
));
601 /* If it were not already in use, open avivideo alias waveaudio would succeed,
602 * making for funny test cases. */
604 err
= mciSendCommandA(MCI_ALL_DEVICE_ID
, MCI_CLOSE
, MCI_WAIT
, 0); /* from MSDN */
605 ok(!err
, "mciCommand close returned %s\n", dbg_mcierr(err
));
607 err
= mciSendCommandA(MCI_ALL_DEVICE_ID
, MCI_CLOSE
, MCI_NOTIFY
, 0);
608 ok(!err
, "mciCommand close returned %s\n", dbg_mcierr(err
));
610 parm
.gen
.dwCallback
= (DWORD_PTR
)hwnd
;
611 err
= mciSendCommandA(MCI_ALL_DEVICE_ID
, MCI_CLOSE
, MCI_NOTIFY
, (DWORD_PTR
)&parm
);
612 ok(!err
, "mciCommand close returned %s\n", dbg_mcierr(err
));
613 test_notification(hwnd
, command_close_all
, 0); /* None left */
616 static void test_recordWAVE(HWND hwnd
)
620 DWORD nsamp
= 16000, expect
;
621 UINT ndevs
= waveInGetNumDevs();
622 MCIERROR err
, ok_pcm
;
623 MCIDEVICEID wDeviceID
;
624 MCI_PARMS_UNION parm
;
626 memset(buf
, 0, sizeof(buf
));
627 test_notification(hwnd
, "-prior to recording-", 0);
629 parm
.open
.lpstrDeviceType
= "waveaudio";
630 parm
.open
.lpstrElementName
= ""; /* "new" at the command level */
631 parm
.open
.lpstrAlias
= "x"; /* to enable mciSendStringA */
632 parm
.open
.dwCallback
= (DWORD_PTR
)hwnd
;
633 err
= mciSendCommandA(0, MCI_OPEN
,
634 MCI_OPEN_ELEMENT
| MCI_OPEN_TYPE
| MCI_OPEN_ALIAS
| MCI_NOTIFY
, (DWORD_PTR
)&parm
);
635 ok(!err
,"mciCommand open new type waveaudio alias x notify: %s\n", dbg_mcierr(err
));
636 wDeviceID
= parm
.open
.wDeviceID
;
638 err
= mciGetDeviceIDA("x");
639 ok(err
== wDeviceID
, "mciGetDeviceIDA x returned %u, expected %u\n", err
, wDeviceID
);
641 /* Only the alias is looked up. */
642 err
= mciGetDeviceIDA("waveaudio");
643 ok(!err
, "mciGetDeviceIDA waveaudio returned %u, expected 0\n", err
);
645 test_notification(hwnd
, "open new", MCI_NOTIFY_SUCCESSFUL
);
646 test_notification(hwnd
, "open new no #2", 0);
648 /* Do not query time format as string because result depends on locale! */
649 parm
.status
.dwItem
= MCI_STATUS_TIME_FORMAT
;
650 err
= mciSendCommandA(wDeviceID
, MCI_STATUS
, MCI_STATUS_ITEM
, (DWORD_PTR
)&parm
);
651 ok(!err
,"mciCommand status time format: %s\n", dbg_mcierr(err
));
652 ok(parm
.status
.dwReturn
==MCI_FORMAT_MILLISECONDS
,"status time format: %ld\n",parm
.status
.dwReturn
);
654 /* Info file fails until named in Open or Save. */
655 err
= mciSendStringA("info x file", buf
, sizeof(buf
), NULL
);
656 todo_wine
ok(err
==MCIERR_NONAPPLICABLE_FUNCTION
,"mci info new file returned %s\n", dbg_mcierr(err
));
657 ok(!buf
[0], "info error buffer %s\n", buf
);
659 err
= mciSendStringA("status x length", buf
, sizeof(buf
), NULL
);
660 todo_wine
ok(!err
,"status x length initial: %s\n", dbg_mcierr(err
));
661 if(!err
) ok(!strcmp(buf
,"0"), "mci status length expected 0, got: %s\n", buf
);
663 /* Check the default recording: 8-bits per sample, mono, 11kHz */
664 err
= mciSendStringA("status x samplespersec", buf
, sizeof(buf
), NULL
);
665 ok(!err
,"mci status samplespersec returned %s\n", dbg_mcierr(err
));
666 if(!err
) ok(!strcmp(buf
,"11025"), "mci status samplespersec expected 11025, got: %s\n", buf
);
668 /* MCI appears to scan the available devices for support of this format,
669 * returning MCIERR_OUTOFRANGE on machines with no sound.
670 * However some w2k8/w7 machines return no error when there's no wave
671 * input device (perhaps querying waveOutGetNumDevs instead of waveIn?),
672 * still the record command below fails with MCIERR_WAVE_INPUTSUNSUITABLE.
673 * Don't skip here, record will fail below. */
674 err
= mciSendStringA("set x format tag pcm", NULL
, 0, NULL
);
675 ok(!err
|| err
==MCIERR_OUTOFRANGE
,"mci set format tag pcm returned %s\n", dbg_mcierr(err
));
678 /* MSDN warns against not setting all wave format parameters.
679 * Indeed, it produces strange results, incl.
680 * inconsistent PCMWAVEFORMAT headers in the saved file.
682 err
= mciSendStringA("set x bytespersec 22050 alignment 2 samplespersec 11025 channels 1 bitspersample 16", NULL
, 0, NULL
);
683 ok(err
==ok_pcm
,"mci set 5 wave parameters returned %s\n", dbg_mcierr(err
));
684 /* Investigate: on w2k, set samplespersec 22050 sets nChannels to 2!
685 * err = mciSendStringA("set x samplespersec 22050", NULL, 0, NULL);
686 * ok(!err,"mci set samplespersec returned %s\n", dbg_mcierr(err));
689 /* Checks are generally performed immediately. */
690 err
= mciSendStringA("set x bitspersample 4", NULL
, 0, NULL
);
691 todo_wine
ok(err
==MCIERR_OUTOFRANGE
,"mci set bitspersample 4 returned %s\n", dbg_mcierr(err
));
693 parm
.set
.wFormatTag
= WAVE_FORMAT_PCM
;
694 parm
.set
.nSamplesPerSec
= nsamp
;
695 parm
.set
.wBitsPerSample
= nbits
;
696 parm
.set
.nChannels
= nch
;
697 parm
.set
.nBlockAlign
= parm
.set
.nChannels
* parm
.set
.wBitsPerSample
/8;
698 parm
.set
.nAvgBytesPerSec
= parm
.set
.nSamplesPerSec
* parm
.set
.nBlockAlign
;
699 err
= mciSendCommandA(wDeviceID
, MCI_SET
,
700 MCI_WAVE_SET_SAMPLESPERSEC
| MCI_WAVE_SET_CHANNELS
| MCI_WAVE_SET_BITSPERSAMPLE
|
701 MCI_WAVE_SET_BLOCKALIGN
| MCI_WAVE_SET_AVGBYTESPERSEC
| MCI_WAVE_SET_FORMATTAG
,
703 ok(err
==ok_pcm
,"mciCommand set wave format: %s\n", dbg_mcierr(err
));
705 parm
.caps
.dwItem
= MCI_WAVE_GETDEVCAPS_INPUTS
;
706 parm
.caps
.dwCallback
= (DWORD_PTR
)hwnd
;
707 err
= mciSendCommandA(wDeviceID
, MCI_GETDEVCAPS
, MCI_GETDEVCAPS_ITEM
| MCI_NOTIFY
,
709 ok(!err
,"mciCommand MCI_GETDEVCAPS inputs: %s\n", dbg_mcierr(err
));
710 ok(parm
.caps
.dwReturn
==ndevs
,"mciCommand GETDEVCAPS claims %u inputs, expected %u\n", parm
.caps
.dwReturn
, ndevs
);
711 ok(!ok_pcm
|| !parm
.caps
.dwReturn
,"No input device accepts PCM!?\n");
712 test_notification(hwnd
, "GETDEVCAPS inputs", MCI_NOTIFY_SUCCESSFUL
);
714 /* A few ME machines pass all tests except set format tag pcm! */
715 err
= mciSendStringA("record x to 2000 wait", NULL
, 0, hwnd
);
716 ok(err
|| !ok_pcm
,"can record yet set wave format pcm returned %s\n", dbg_mcierr(ok_pcm
));
717 todo_wine_if (!ndevs
) /* with sound disabled */
718 ok(ndevs
> 0 ? !err
: err
== MCIERR_WAVE_INPUTSUNSUITABLE
, "mci record to 2000 returned %s\n", dbg_mcierr(err
));
720 if (err
==MCIERR_WAVE_INPUTSUNSUITABLE
)
721 skip("Please install audio driver. Everything is skipped.\n");
722 else skip("Cannot record cause %s. Everything is skipped.\n", dbg_mcierr(err
));
724 err
= mciSendStringA("close x", NULL
, 0, NULL
);
725 ok(!err
,"mci close returned %s\n", dbg_mcierr(err
));
726 test_notification(hwnd
,"record skipped",0);
730 /* Query some wave format parameters depending on the time format. */
731 err
= mciSendStringA("status x position", buf
, sizeof(buf
), NULL
);
732 ok(!err
,"mci status position returned %s\n", dbg_mcierr(err
));
733 if(!err
) todo_wine
ok(!strcmp(buf
,"2000"), "mci status position gave %s, expected 2000, some tests will fail\n", buf
);
735 err
= mciSendStringA("set x time format 8", NULL
, 0, NULL
); /* bytes */
736 ok(!err
,"mci returned %s\n", dbg_mcierr(err
));
738 parm
.status
.dwItem
= MCI_STATUS_POSITION
;
739 err
= mciSendCommandA(wDeviceID
, MCI_STATUS
, MCI_STATUS_ITEM
, (DWORD_PTR
)&parm
);
740 ok(!err
,"mciCommand status position: %s\n", dbg_mcierr(err
));
741 expect
= 2 * nsamp
* nch
* nbits
/8;
742 if(!err
) todo_wine
ok(parm
.status
.dwReturn
==expect
,"recorded %lu bytes, expected %u\n",parm
.status
.dwReturn
,expect
);
744 parm
.set
.dwTimeFormat
= MCI_FORMAT_SAMPLES
;
745 err
= mciSendCommandA(wDeviceID
, MCI_SET
, MCI_SET_TIME_FORMAT
, (DWORD_PTR
)&parm
);
746 ok(!err
,"mciCommand set time format samples: %s\n", dbg_mcierr(err
));
748 parm
.status
.dwItem
= MCI_STATUS_POSITION
;
749 err
= mciSendCommandA(wDeviceID
, MCI_STATUS
, MCI_STATUS_ITEM
, (DWORD_PTR
)&parm
);
750 ok(!err
,"mciCommand status position: %s\n", dbg_mcierr(err
));
752 if(!err
) todo_wine
ok(parm
.status
.dwReturn
==expect
,"recorded %lu samples, expected %u\n",parm
.status
.dwReturn
,expect
);
754 err
= mciSendStringA("set x time format milliseconds", NULL
, 0, NULL
);
755 ok(!err
,"mci set time format milliseconds returned %s\n", dbg_mcierr(err
));
757 err
= mciSendStringA("save x tempfile1.wav", NULL
, 0, NULL
);
758 ok(!err
,"mci save returned %s\n", dbg_mcierr(err
));
760 err
= mciSendStringA("save x tempfile.wav", NULL
, 0, NULL
);
761 ok(!err
,"mci save returned %s\n", dbg_mcierr(err
));
762 if(!err
) ok_saved
= 0;
764 /* Save must not rename the original file. */
765 if (!DeleteFileA("tempfile1.wav"))
766 todo_wine
ok(FALSE
, "Save must not rename the original file; DeleteFileA returned %d\n",
769 err
= mciSendStringA("set x channels 2", NULL
, 0, NULL
);
770 ok(err
==MCIERR_NONAPPLICABLE_FUNCTION
,"mci set channels after saving returned %s\n", dbg_mcierr(err
));
772 parm
.seek
.dwTo
= 600;
773 err
= mciSendCommandA(wDeviceID
, MCI_SEEK
, MCI_TO
| MCI_WAIT
, (DWORD_PTR
)&parm
);
774 ok(!err
,"mciCommand seek to 600: %s\n", dbg_mcierr(err
));
776 /* Truncate to current position */
777 err
= mciSendStringA("delete x", NULL
, 0, NULL
);
778 todo_wine
ok(!err
,"mci delete returned %s\n", dbg_mcierr(err
));
780 err
= mciSendStringA("status x length", buf
, sizeof(buf
), NULL
);
781 ok(!err
,"mci status length returned %s\n", dbg_mcierr(err
));
782 todo_wine
ok(!strcmp(buf
,"600"), "mci status length after delete gave %s, expected 600\n", buf
);
784 err
= mciSendStringA("close x", NULL
, 0, NULL
);
785 ok(!err
,"mci close returned %s\n", dbg_mcierr(err
));
786 test_notification(hwnd
,"record complete",0);
789 static void test_playWAVE(HWND hwnd
)
793 memset(buf
, 0, sizeof(buf
));
795 err
= mciSendStringA("open waveaudio!tempfile.wav alias mysound", NULL
, 0, NULL
);
796 ok(err
==ok_saved
,"mci open waveaudio!tempfile.wav returned %s\n", dbg_mcierr(err
));
798 skip("Cannot open waveaudio!tempfile.wav for playing (%s), skipping\n", dbg_mcierr(err
));
802 err
= mciGetDeviceIDA("mysound");
803 ok(err
== 1, "mciGetDeviceIDA mysound returned %u, expected 1\n", err
);
805 err
= mciGetDeviceIDA("tempfile.wav");
806 ok(!err
, "mciGetDeviceIDA tempfile.wav returned %u, expected 0\n", err
);
808 err
= mciGetDeviceIDA("waveaudio");
809 ok(!err
, "mciGetDeviceIDA waveaudio returned %u, expected 0\n", err
);
811 err
= mciSendStringA("status mysound length", buf
, sizeof(buf
), NULL
);
812 ok(!err
,"mci status length returned %s\n", dbg_mcierr(err
));
813 todo_wine
ok(!strcmp(buf
,"2000"), "mci status length gave %s, expected 2000, some tests will fail.\n", buf
);
815 err
= mciSendStringA("cue output", NULL
, 0, NULL
);
816 ok(err
==MCIERR_UNRECOGNIZED_COMMAND
,"mci incorrect cue output returned %s\n", dbg_mcierr(err
));
818 /* Test MCI to the bones -- Some todo_wine from Cue and
819 * from Play from 0 to 0 are not worth fixing. */
820 err
= mciSendStringA("cue mysound output notify", NULL
, 0, hwnd
);
821 ok(!err
,"mci cue output after open file returned %s\n", dbg_mcierr(err
));
822 /* Notification is delayed as a play thread is started. */
823 todo_wine
test_notification(hwnd
, "cue immediate", 0);
825 /* Cue pretends to put the MCI into paused state. */
826 err
= mciSendStringA("status mysound mode", buf
, sizeof(buf
), hwnd
);
827 ok(!err
,"mci status mode returned %s\n", dbg_mcierr(err
));
828 todo_wine
ok(!strcmp(buf
,"paused"), "mci status mode: %s, expected (pseudo)paused\n", buf
);
830 /* Strange pause where Pause is rejected, unlike Play; Pause; Pause tested below */
831 err
= mciSendStringA("pause mysound", NULL
, 0, hwnd
);
832 ok(err
==MCIERR_NONAPPLICABLE_FUNCTION
,"mci pause after cue returned %s\n", dbg_mcierr(err
));
834 /* MCI appears to start the play thread in this border case.
835 * Guessed that from (flaky) status mode and late notification arrival. */
836 err
= mciSendStringA("play mysound from 0 to 0 notify", NULL
, 0, hwnd
);
837 ok(!err
,"mci play from 0 to 0 returned %s\n", dbg_mcierr(err
));
838 todo_wine
test_notification(hwnd
, "cue aborted by play", MCI_NOTIFY_ABORTED
);
839 /* play's own notification follows below */
841 err
= mciSendStringA("play mysound from 250 to 0", NULL
, 0, NULL
);
842 ok(err
==MCIERR_OUTOFRANGE
,"mci play from 250 to 0 returned %s\n", dbg_mcierr(err
));
844 Sleep(100); /* Give play from 0 to 0 time to finish. */
845 todo_wine
test_notification(hwnd
, "play from 0 to 0", MCI_NOTIFY_SUCCESSFUL
);
847 err
= mciSendStringA("status mysound mode", buf
, sizeof(buf
), hwnd
);
848 ok(!err
,"mci status mode returned %s\n", dbg_mcierr(err
));
849 ok(!strcmp(buf
,"stopped"), "mci status mode: %s after play from 0 to 0\n", buf
);
851 err
= mciSendStringA("play MYSOUND from 250 to 0 notify", NULL
, 0, hwnd
);
852 ok(err
==MCIERR_OUTOFRANGE
,"mci play from 250 to 0 notify returned %s\n", dbg_mcierr(err
));
853 /* No notification (checked below) sent if error */
855 /* A second play caused Wine<1.1.33 to hang */
856 err
= mciSendStringA("play mysound from 500 to 220:5:0 wait", NULL
, 0, NULL
);
857 ok(!err
,"mci play from 500 to 220:5:0 (=1500) returned %s\n", dbg_mcierr(err
));
859 err
= mciSendStringA("status mysound position", buf
, sizeof(buf
), hwnd
);
860 ok(!err
,"mci status position returned %s\n", dbg_mcierr(err
));
861 if(!err
) ok(!strcmp(buf
,"1500"), "mci status position: %s\n", buf
);
863 /* mci will not play position < current */
864 err
= mciSendStringA("play mysound to 1000", NULL
, 0, NULL
);
865 ok(err
==MCIERR_OUTOFRANGE
,"mci play to 1000 returned %s\n", dbg_mcierr(err
));
867 /* mci will not play to > end */
868 err
= mciSendStringA("play mysound TO 3000 notify", NULL
, 0, hwnd
);
869 ok(err
==MCIERR_OUTOFRANGE
,"mci play to 3000 notify returned %s\n", dbg_mcierr(err
));
871 err
= mciSendStringA("play mysound to 2000", NULL
, 0, NULL
);
872 ok(!err
,"mci play to 2000 returned %s\n", dbg_mcierr(err
));
874 /* Rejected while playing */
875 err
= mciSendStringA("cue mysound output", NULL
, 0, NULL
);
876 ok(err
==MCIERR_NONAPPLICABLE_FUNCTION
,"mci cue output while playing returned %s\n", dbg_mcierr(err
));
878 err
= mciSendStringA("play mysound to 3000", NULL
, 0, NULL
);
879 ok(err
==MCIERR_OUTOFRANGE
,"mci play to 3000 returned %s\n", dbg_mcierr(err
));
881 err
= mciSendStringA("stop mysound Wait", NULL
, 0, NULL
);
882 ok(!err
,"mci stop wait returned %s\n", dbg_mcierr(err
));
883 test_notification(hwnd
, "play/cue/pause/stop", 0);
885 err
= mciSendStringA("Seek Mysound to 250 wait Notify", NULL
, 0, hwnd
);
886 ok(!err
,"mci seek to 250 wait notify returned %s\n", dbg_mcierr(err
));
887 test_notification(hwnd
,"seek wait notify",MCI_NOTIFY_SUCCESSFUL
);
889 err
= mciSendStringA("seek mysound to 0xfa", NULL
, 0, NULL
);
890 ok(err
==MCIERR_BAD_INTEGER
,"mci seek to 0xfa returned %s\n", dbg_mcierr(err
));
892 /* MCI_INTEGER always accepts colon notation */
893 err
= mciSendStringA("seek mysound to :1", NULL
, 0, NULL
);
894 ok(!err
,"mci seek to :1 (=256) returned %s\n", dbg_mcierr(err
));
896 err
= mciSendStringA("seek mysound to 250::", NULL
, 0, NULL
);
897 ok(!err
,"mci seek to 250:: returned %s\n", dbg_mcierr(err
));
899 err
= mciSendStringA("seek mysound to 250:0", NULL
, 0, NULL
);
900 ok(!err
,"mci seek to 250:0 returned %s\n", dbg_mcierr(err
));
902 err
= mciSendStringA("status mysound position notify", buf
, sizeof(buf
), hwnd
);
903 ok(!err
,"mci status position notify returned %s\n", dbg_mcierr(err
));
904 if(!err
) ok(!strcmp(buf
,"250"), "mci status position: %s\n", buf
);
905 /* Immediate commands like status also send notifications. */
906 test_notification(hwnd
,"status position",MCI_NOTIFY_SUCCESSFUL
);
908 err
= mciSendStringA("status mysound mode", buf
, sizeof(buf
), hwnd
);
909 ok(!err
,"mci status mode returned %s\n", dbg_mcierr(err
));
910 ok(!strcmp(buf
,"stopped"), "mci status mode: %s\n", buf
);
912 /* Another play from == to testcase */
913 err
= mciSendStringA("play mysound to 250 wait notify", NULL
, 0, hwnd
);
914 ok(!err
,"mci play (from 250) to 250 returned %s\n", dbg_mcierr(err
));
915 todo_wine
test_notification(hwnd
,"play to 250 wait notify",MCI_NOTIFY_SUCCESSFUL
);
917 err
= mciSendStringA("cue mysound output", NULL
, 0, NULL
);
918 ok(!err
,"mci cue output after play returned %s\n", dbg_mcierr(err
));
920 err
= mciSendStringA("close mysound", NULL
, 0, NULL
);
921 ok(!err
,"mci close returned %s\n", dbg_mcierr(err
));
922 test_notification(hwnd
,"after close",0);
925 static void test_asyncWAVE(HWND hwnd
)
927 MCIDEVICEID wDeviceID
;
928 MCI_PARMS_UNION parm
;
931 memset(buf
, 0, sizeof(buf
));
933 err
= mciSendStringA("open tempfile.wav alias mysound notify type waveaudio", buf
, sizeof(buf
), hwnd
);
934 ok(err
==ok_saved
,"mci open tempfile.wav returned %s\n", dbg_mcierr(err
));
936 skip("Cannot open tempfile.wav for playing (%s), skipping\n", dbg_mcierr(err
));
939 ok(!strcmp(buf
,"1"), "mci open deviceId: %s, expected 1\n", buf
);
940 wDeviceID
= atoi(buf
);
941 ok(wDeviceID
,"mci open DeviceID: %d\n", wDeviceID
);
942 test_notification(hwnd
,"open alias notify",MCI_NOTIFY_SUCCESSFUL
);
944 err
= mciGetDeviceIDA("mysound");
945 ok(err
== wDeviceID
, "mciGetDeviceIDA alias returned %u, expected %u\n", err
, wDeviceID
);
947 /* Only the alias is looked up. */
948 err
= mciGetDeviceIDA("tempfile.wav");
949 ok(!err
, "mciGetDeviceIDA tempfile.wav returned %u, expected 0\n", err
);
951 err
= mciGetDeviceIDA("waveaudio");
952 ok(!err
, "mciGetDeviceIDA waveaudio returned %u, expected 0\n", err
);
954 err
= mciSendStringA("status mysound mode", buf
, sizeof(buf
), hwnd
);
955 ok(!err
,"mci status mode returned %s\n", dbg_mcierr(err
));
956 ok(!strcmp(buf
,"stopped"), "mci status mode: %s\n", buf
);
958 err
= mciSendStringA("play mysound notify", NULL
, 0, hwnd
);
959 ok(!err
,"mci play returned %s\n", dbg_mcierr(err
));
961 Sleep(500); /* milliseconds */
963 /* Do not query time format as string because result depends on locale! */
964 parm
.status
.dwItem
= MCI_STATUS_TIME_FORMAT
;
965 err
= mciSendCommandA(wDeviceID
, MCI_STATUS
, MCI_STATUS_ITEM
, (DWORD_PTR
)&parm
);
966 ok(!err
,"mciCommand status time format: %s\n", dbg_mcierr(err
));
967 if(!err
) ok(parm
.status
.dwReturn
==MCI_FORMAT_MILLISECONDS
,"status time format: %ld\n",parm
.status
.dwReturn
);
969 parm
.set
.dwTimeFormat
= MCI_FORMAT_MILLISECONDS
;
970 err
= mciSendCommandA(wDeviceID
, MCI_SET
, MCI_SET_TIME_FORMAT
, (DWORD_PTR
)&parm
);
971 ok(!err
,"mciCommand set time format ms: %s\n", dbg_mcierr(err
));
973 err
= mciSendStringA("status mysound position", buf
, sizeof(buf
), hwnd
);
974 ok(!err
,"mci status position returned %s\n", dbg_mcierr(err
));
975 trace("position after Sleep: %sms\n", buf
);
977 /* Check that the 2s sound plays at a normal pace, giving a wide margin to
978 * account for timing granularity and small delays.
980 todo_wine
ok(350 <= p2
&& p2
<= 600, "%ums is not in the expected 350-600ms range\n", p2
);
981 /* Wine's asynchronous thread needs some time to start up. Furthermore, it
982 * uses 3 buffers per second, so that the positions reported will be 333ms,
983 * 667ms etc. at best, which is why it fails the above test. So add a
984 * second test specifically to prevent Wine from getting even worse.
985 * FIXME: To be removed when Wine is fixed and passes the above test.
987 ok(350 <= p2
&& p2
<= 1000, "%ums is not even in the expected 350-1000ms range\n", p2
);
988 test_notification(hwnd
,"play (nowait)",0);
990 err
= mciSendStringA("pause mysound wait", NULL
, 0, hwnd
);
991 ok(!err
,"mci pause wait returned %s\n", dbg_mcierr(err
));
993 err
= mciSendStringA("status mysound mode notify", buf
, sizeof(buf
), hwnd
);
994 ok(!err
,"mci status mode returned %s\n", dbg_mcierr(err
));
995 if(!err
) ok(!strcmp(buf
,"paused"), "mci status mode: %s\n", buf
);
996 test_notification(hwnd
,"play",MCI_NOTIFY_SUPERSEDED
);
997 test_notification(hwnd
,"status",MCI_NOTIFY_SUCCESSFUL
);
999 err
= mciSendStringA("status mysound position", buf
, sizeof(buf
), hwnd
);
1000 ok(!err
,"mci status position returned %s\n", dbg_mcierr(err
));
1001 trace("position while paused: %sms\n",buf
);
1003 ok(p1
>=p2
, "position not increasing: %u > %u\n", p2
, p1
);
1005 err
= mciSendStringA("stop mysound wait", NULL
, 0, NULL
);
1006 ok(!err
,"mci stop returned %s\n", dbg_mcierr(err
));
1008 err
= mciSendStringA("info mysound file notify", buf
, sizeof(buf
), hwnd
);
1009 ok(!err
,"mci info file returned %s\n", dbg_mcierr(err
));
1010 if(!err
) { /* fully qualified name */
1011 int len
= strlen(buf
);
1012 todo_wine
ok(len
>2 && buf
[1]==':',"Expected full pathname from info file: %s\n", buf
);
1013 ok(len
>=12 && !strcmp(&buf
[len
-12],"tempfile.wav"), "info file returned: %s\n", buf
);
1015 test_notification(hwnd
,"info file",MCI_NOTIFY_SUCCESSFUL
);
1017 err
= mciSendStringA("status mysound mode", buf
, sizeof(buf
), hwnd
);
1018 ok(!err
,"mci status mode returned %s\n", dbg_mcierr(err
));
1019 ok(!strcmp(buf
,"stopped"), "mci status mode: %s\n", buf
);
1021 err
= mciSendStringA("status mysound position", buf
, sizeof(buf
), hwnd
);
1022 ok(!err
,"mci status position returned %s\n", dbg_mcierr(err
));
1023 trace("position once stopped: %sms\n",buf
);
1025 /* An XP machine let the position increase slightly after pause. */
1026 ok(p2
>=p1
&& p2
<=p1
+16,"position changed from %ums to %ums\n",p1
,p2
);
1028 /* No Resume once stopped (waveaudio, sequencer and cdaudio differ). */
1029 err
= mciSendStringA("resume mysound wait", NULL
, 0, NULL
);
1030 ok(err
==MCIERR_NONAPPLICABLE_FUNCTION
,"mci resume wait returned %s\n", dbg_mcierr(err
));
1032 err
= mciSendStringA("play mysound wait", NULL
, 0, NULL
);
1033 ok(!err
,"mci play wait returned %s\n", dbg_mcierr(err
));
1035 err
= mciSendStringA("status mysound position", buf
, sizeof(buf
), hwnd
);
1036 ok(!err
,"mci status position returned %s\n", dbg_mcierr(err
));
1037 todo_wine
ok(!strcmp(buf
,"2000"), "mci status position: %s\n", buf
);
1039 err
= mciSendStringA("seek mysound to start wait", NULL
, 0, NULL
);
1040 ok(!err
,"mci seek to start wait returned %s\n", dbg_mcierr(err
));
1042 err
= mciSendStringA("play mysound to 1000 notify", NULL
, 0, hwnd
);
1043 ok(!err
,"mci play returned %s\n", dbg_mcierr(err
));
1045 /* Sleep(200); not needed with Wine any more. */
1047 err
= mciSendStringA("pause mysound notify", NULL
, 0, NULL
); /* notify no callback */
1048 ok(!err
,"mci pause notify returned %s\n", dbg_mcierr(err
));
1049 /* Supersede even though pause cannot notify given no callback */
1050 test_notification(hwnd
,"pause aborted play #1 notification",MCI_NOTIFY_SUPERSEDED
);
1051 test_notification(hwnd
,"impossible pause notification",0);
1053 err
= mciSendStringA("cue mysound output notify", NULL
, 0, hwnd
);
1054 ok(err
==MCIERR_NONAPPLICABLE_FUNCTION
,"mci cue output while paused returned %s\n", dbg_mcierr(err
));
1055 test_notification(hwnd
,"cue output notify #2",0);
1057 err
= mciSendStringA("resume mysound notify", NULL
, 0, hwnd
);
1058 ok(!err
,"mci resume notify returned %s\n", dbg_mcierr(err
));
1059 test_notification(hwnd
, "resume notify", MCI_NOTIFY_SUCCESSFUL
);
1061 /* Seek or even Stop used to hang Wine<1.1.32 on MacOS. */
1062 err
= mciSendStringA("seek mysound to 0 wait", NULL
, 0, NULL
);
1063 ok(!err
,"mci seek to start returned %s\n", dbg_mcierr(err
));
1066 err
= mciSendStringA("status mysound mode", buf
, sizeof(buf
), NULL
);
1067 ok(!err
,"mci status mode returned %s\n", dbg_mcierr(err
));
1068 if(!err
) ok(!strcmp(buf
,"stopped"), "mci status mode: %s\n", buf
);
1070 err
= mciSendStringA("seek mysound wait", NULL
, 0, NULL
);
1071 ok(err
==MCIERR_MISSING_PARAMETER
,"mci seek to nowhere returned %s\n", dbg_mcierr(err
));
1073 /* cdaudio does not detect to start to end as error */
1074 err
= mciSendStringA("seek mysound to start to 0", NULL
, 0, NULL
);
1075 ok(err
==MCIERR_FLAGS_NOT_COMPATIBLE
,"mci seek to start to 0 returned %s\n", dbg_mcierr(err
));
1077 err
= mciSendStringA("PLAY mysound to 1000 notify", NULL
, 0, hwnd
);
1078 ok(!err
,"mci play to 1000 notify returned %s\n", dbg_mcierr(err
));
1080 /* Sleep(200); not needed with Wine any more. */
1081 /* Give it 400ms and resume will appear to complete below. */
1083 err
= mciSendStringA("pause mysound wait", NULL
, 0, NULL
);
1084 ok(!err
,"mci pause wait returned %s\n", dbg_mcierr(err
));
1085 /* Unlike sequencer and cdaudio, waveaudio's pause does not abort. */
1086 test_notification(hwnd
,"pause aborted play #2 notification",0);
1088 err
= mciSendStringA("resume mysound wait", NULL
, 0, NULL
);
1089 ok(!err
,"mci resume wait returned %s\n", dbg_mcierr(err
));
1090 /* Resume is a short asynchronous call, something else is playing. */
1092 err
= mciSendStringA("status mysound mode", buf
, sizeof(buf
), NULL
);
1093 ok(!err
,"mci status mode returned %s\n", dbg_mcierr(err
));
1094 if(!err
) ok(!strcmp(buf
,"playing"), "mci status mode: %s\n", buf
);
1096 /* Note extra space before alias */
1097 err
= mciSendStringA("pause mysound wait", NULL
, 0, NULL
);
1098 todo_wine
ok(!err
,"mci pause (space) wait returned %s\n", dbg_mcierr(err
));
1100 err
= mciSendStringA("pause mysound wait", NULL
, 0, NULL
);
1101 ok(!err
,"mci pause wait returned %s\n", dbg_mcierr(err
));
1103 /* Better ask position only when paused, is it updated while playing? */
1104 err
= mciSendStringA("status mysound position", buf
, sizeof(buf
), NULL
);
1105 ok(!err
,"mci status position returned %s\n", dbg_mcierr(err
));
1106 /* TODO compare position < 900 */
1107 ok(strcmp(buf
,"1000"), "mci resume waited\n");
1108 ok(strcmp(buf
,"2000"), "mci resume played to end\n");
1109 trace("position after resume: %sms\n",buf
);
1110 test_notification(hwnd
,"play (aborted by pause/resume/pause)",0);
1112 /* A small Sleep() here prevents the notification test failing with MCI_NOTIFY_SUCCESSFUL */
1114 err
= mciSendStringA("close mysound wait", NULL
, 0, NULL
);
1115 ok(!err
,"mci close wait returned %s\n", dbg_mcierr(err
));
1116 test_notification(hwnd
,"play (aborted by close)",MCI_NOTIFY_ABORTED
);
1119 static void test_AutoOpenWAVE(HWND hwnd
)
1121 /* This test used(?) to cause intermittent crashes when Wine exits, after
1122 * fixme:winmm:MMDRV_Exit Closing while ll-driver open
1124 UINT ndevs
= waveOutGetNumDevs();
1125 MCIERROR err
, ok_snd
= ndevs
? 0 : MCIERR_HARDWARE
;
1126 MCI_PARMS_UNION parm
;
1127 char buf
[512], path
[300], command
[330];
1128 DWORD intbuf
[3] = { 0xDEADF00D, 99, 0xABADCAFE };
1129 memset(buf
, 0, sizeof(buf
)); memset(path
, 0, sizeof(path
));
1131 /* Do not crash on NULL buffer pointer */
1132 err
= mciSendStringA("sysinfo waveaudio quantity open", NULL
, 0, NULL
);
1133 ok(err
==MCIERR_PARAM_OVERFLOW
,"mci sysinfo without buffer returned %s\n", dbg_mcierr(err
));
1135 err
= mciSendStringA("sysinfo waveaudio quantity open", buf
, sizeof(buf
), NULL
);
1136 ok(!err
,"mci sysinfo waveaudio quantity open returned %s\n", dbg_mcierr(err
));
1137 if(!err
) ok(!strcmp(buf
,"0"), "sysinfo quantity open expected 0, got: %s, some more tests will fail.\n", buf
);
1139 /* Who knows why some MS machines pass all tests but return MCIERR_HARDWARE here? */
1140 /* Wine returns MCIERR_HARDWARE when no default sound is found in win.ini or the registry. */
1141 err
= mciSendStringA("sound NoSuchSoundDefined wait", NULL
, 0, NULL
);
1142 ok(err
==ok_snd
|| err
==MCIERR_HARDWARE
, "mci sound NoSuchSoundDefined returned %s\n", dbg_mcierr(err
));
1144 err
= mciSendStringA("sound SystemExclamation notify wait", NULL
, 0, hwnd
);
1145 ok(err
==ok_snd
|| err
==MCIERR_HARDWARE
, "mci sound SystemExclamation returned %s\n", dbg_mcierr(err
));
1146 test_notification(hwnd
, "sound notify", err
? 0 : MCI_NOTIFY_SUCCESSFUL
);
1148 Sleep(16); /* time to auto-close makes sysinfo below return expected error */
1149 err
= mciSendStringA("sysinfo waveaudio notify name 1 open", buf
, sizeof(buf
), hwnd
);
1150 ok(err
==MCIERR_OUTOFRANGE
,"sysinfo waveaudio name 1 returned %s\n", dbg_mcierr(err
));
1151 if(!err
) trace("sysinfo dangling open alias: %s\n", buf
);
1152 test_notification(hwnd
, "sysinfo name outofrange\n", err
? 0 : MCI_NOTIFY_SUCCESSFUL
);
1154 err
= mciSendStringA("play no-such-file-exists.wav notify", buf
, sizeof(buf
), NULL
);
1155 todo_wine
ok(err
==MCIERR_NOTIFY_ON_AUTO_OPEN
,"mci auto-open notify returned %s\n", dbg_mcierr(err
));
1156 /* FILE_NOT_FOUND in Wine because auto-open fails before testing the notify flag */
1158 test_notification(hwnd
, "-prior to auto-open-", 0);
1160 err
= mciSendStringA("play tempfile.wav notify", buf
, sizeof(buf
), hwnd
);
1161 todo_wine_if (ok_saved
== MCIERR_FILE_NOT_FOUND
) /* same as above */
1162 ok(err
==MCIERR_NOTIFY_ON_AUTO_OPEN
,"mci auto-open play notify returned %s\n", dbg_mcierr(err
));
1164 if(err
) /* FIXME: don't open twice yet, it confuses Wine. */
1165 err
= mciSendStringA("play tempfile.wav", buf
, sizeof(buf
), hwnd
);
1166 ok(err
==ok_saved
,"mci auto-open play returned %s\n", dbg_mcierr(err
));
1168 if(err
==MCIERR_FILE_NOT_FOUND
) {
1169 skip("Cannot open tempfile.wav for auto-play, skipping\n");
1173 err
= mciSendStringA("sysinfo waveaudio quantity open", buf
, sizeof(buf
), NULL
);
1174 ok(!err
,"mci sysinfo waveaudio quantity after auto-open returned %s\n", dbg_mcierr(err
));
1175 if(!err
) ok(!strcmp(buf
,"1"), "sysinfo quantity open expected 1, got: %s\n", buf
);
1177 parm
.sys
.lpstrReturn
= (LPSTR
)&intbuf
[1];
1178 parm
.sys
.dwRetSize
= 2*sizeof(DWORD
); /* only one DWORD is used */
1179 parm
.sys
.wDeviceType
= MCI_DEVTYPE_WAVEFORM_AUDIO
;
1180 err
= mciSendCommandA(0, MCI_SYSINFO
, MCI_SYSINFO_QUANTITY
| MCI_SYSINFO_OPEN
, (DWORD_PTR
)&parm
);
1181 ok(!err
, "mciCommand sysinfo waveaudio open notify returned %s\n", dbg_mcierr(err
));
1182 if(!err
) ok(atoi(buf
)==intbuf
[1],"sysinfo waveaudio quantity open string and command differ\n");
1184 err
= mciSendStringA("sysinfo waveaudio name 1 open notify", buf
, sizeof(buf
), hwnd
);
1185 ok(!err
,"mci sysinfo waveaudio name after auto-open returned %s\n", dbg_mcierr(err
));
1186 /* This is the alias, not necessarily a file name. */
1187 if(!err
) ok(!strcmp(buf
,"tempfile.wav"), "sysinfo name 1 open: %s\n", buf
);
1188 test_notification(hwnd
, "sysinfo name notify\n", MCI_NOTIFY_SUCCESSFUL
);
1190 err
= mciGetDeviceIDA("tempfile.wav");
1191 ok(err
== 1, "mciGetDeviceIDA tempfile.wav returned %u, expected 1\n", err
);
1193 /* Save the full pathname to the file. */
1194 err
= mciSendStringA("info tempfile.wav file", path
, sizeof(path
), NULL
);
1195 ok(!err
,"mci info tempfile.wav file returned %s\n", dbg_mcierr(err
));
1196 if(err
) strcpy(path
,"tempfile.wav");
1198 err
= mciSendStringA("status tempfile.wav mode", NULL
, 0, hwnd
);
1199 ok(!err
,"mci status tempfile.wav mode without buffer returned %s\n", dbg_mcierr(err
));
1201 sprintf(command
,"status \"%s\" mode",path
);
1202 err
= mciSendStringA(command
, buf
, sizeof(buf
), hwnd
);
1203 ok(!err
,"mci status \"%s\" mode returned %s\n", path
, dbg_mcierr(err
));
1205 err
= mciSendStringA("status tempfile.wav mode", buf
, sizeof(buf
), hwnd
);
1206 ok(!err
,"mci status tempfile.wav mode returned %s\n", dbg_mcierr(err
));
1207 if(!err
) ok(!strcmp(buf
,"playing"), "mci auto-open status mode, got: %s\n", buf
);
1209 err
= mciSendStringA("open tempfile.wav", buf
, sizeof(buf
), NULL
);
1210 ok(err
==MCIERR_DEVICE_OPEN
, "mci open from auto-open returned %s\n", dbg_mcierr(err
));
1212 err
= mciSendStringA("open foo.wav alias tempfile.wav", buf
, sizeof(buf
), NULL
);
1213 ok(err
==MCIERR_DUPLICATE_ALIAS
, "mci open re-using alias returned %s\n", dbg_mcierr(err
));
1215 /* w2k/xp and Wine differ. While the device is busy playing, it is
1216 * regularly open and accessible via the filename: subsequent
1217 * commands must not cause auto-open each. In Wine, a subsequent
1218 * command with notify request may cause the initial play
1219 * notification to be superseded, in turn causing MCI to close the
1220 * device. I.e. MCI uses the auto-open notification for itself,
1221 * that's why it's not available to the app. On w2k/xp,
1222 * subsequent commands with notify requests are returned with
1223 * MCIERR_NOTIFY_ON_AUTO_OPEN and thus don't abort the original
1226 err
= mciSendStringA("status tempfile.wav mode notify", buf
, sizeof(buf
), hwnd
);
1227 todo_wine
ok(err
==MCIERR_NOTIFY_ON_AUTO_OPEN
, "mci status auto-open notify returned %s\n", dbg_mcierr(err
));
1229 trace("Wine style MCI auto-close upon notification\n");
1231 /* "playing" because auto-close comes after the status call. */
1232 ok(!strcmp(buf
,"playing"), "mci auto-open status mode notify, got: %s\n", buf
);
1233 /* fixme:winmm:MMDRV_Exit Closing while ll-driver open
1234 * is explained by failure to auto-close a device. */
1235 test_notification(hwnd
,"status notify",MCI_NOTIFY_SUCCESSFUL
);
1236 /* MCI received NOTIFY_SUPERSEDED and auto-closed the device. */
1238 /* Until this is implemented, force closing the device */
1239 err
= mciSendStringA("close tempfile.wav", NULL
, 0, hwnd
);
1240 ok(!err
,"mci auto-still-open stop returned %s\n", dbg_mcierr(err
));
1242 test_notification(hwnd
,"auto-open",0);
1243 } else if(err
==MCIERR_NOTIFY_ON_AUTO_OPEN
) { /* MS style */
1244 trace("MS style MCI auto-open forbids notification\n");
1246 err
= mciSendStringA("pause tempfile.wav", NULL
, 0, hwnd
);
1247 ok(!err
,"mci auto-still-open pause returned %s\n", dbg_mcierr(err
));
1249 err
= mciSendStringA("status tempfile.wav mode", buf
, sizeof(buf
), hwnd
);
1250 ok(!err
,"mci status mode returned %s\n", dbg_mcierr(err
));
1251 if(!err
) ok(!strcmp(buf
,"paused"), "mci auto-open status mode, got: %s\n", buf
);
1254 err
= mciSendStringA("stop tempfile.wav wait", NULL
, 0, hwnd
);
1255 ok(!err
,"mci auto-still-open stop returned %s\n", dbg_mcierr(err
));
1256 Sleep(16); /* makes sysinfo quantity open below succeed */
1259 err
= mciSendStringA("sysinfo waveaudio quantity open", buf
, sizeof(buf
), NULL
);
1260 ok(!err
,"mci sysinfo waveaudio quantity open after close returned %s\n", dbg_mcierr(err
));
1261 if(!err
) ok(!strcmp(buf
,"0"), "sysinfo quantity open expected 0 after auto-close, got: %s\n", buf
);
1263 /* w95-WinME (not w2k/XP) switch to C:\ after auto-playing once. Prevent
1264 * MCIERR_FILE_NOT_FOUND by using the full path name from the Info file command.
1266 sprintf(command
,"status \"%s\" mode wait",path
);
1267 err
= mciSendStringA(command
, buf
, sizeof(buf
), hwnd
);
1268 ok(!err
,"mci re-auto-open status mode returned %s\n", dbg_mcierr(err
));
1269 if(!err
) ok(!strcmp(buf
,"stopped"), "mci re-auto-open status mode, got: %s\n", buf
);
1271 /* This uses auto-open as well. */
1272 err
= mciSendStringA("capability waveaudio outputs", buf
, sizeof(buf
), NULL
);
1273 ok(!err
,"mci capability waveaudio outputs returned %s\n", dbg_mcierr(err
));
1274 /* Wine with no sound selected in winecfg's audio tab fails this test. */
1275 if(!err
) ok(atoi(buf
)==ndevs
,"Expected %d audio outputs, got %s\n", ndevs
, buf
);
1277 err
= mciSendStringA("capability waveaudio device type", buf
, sizeof(buf
), hwnd
);
1278 ok(!err
,"mci capability device type returned %s\n", dbg_mcierr(err
));
1279 if(!err
) ok(!strcmp(buf
,"waveaudio"), "mci capability device type response: %s\n", buf
);
1281 /* waveaudio forbids Pause without Play. */
1282 sprintf(command
,"pause \"%s\"",path
);
1283 err
= mciSendStringA(command
, NULL
, 0, hwnd
);
1284 ok(err
==MCIERR_NONAPPLICABLE_FUNCTION
,"mci auto-open pause returned %s\n", dbg_mcierr(err
));
1286 ok(0xDEADF00D==intbuf
[0] && 0xABADCAFE==intbuf
[2],"DWORD buffer corruption\n");
1289 static void test_playWaveTypeMpegvideo(void)
1292 MCIDEVICEID wDeviceID
;
1293 MCI_PLAY_PARMS play_parm
;
1294 MCI_STATUS_PARMS status_parm
;
1296 memset(buf
, 0, sizeof(buf
));
1298 err
= mciSendStringA("open tempfile.wav type MPEGVideo alias mysound", NULL
, 0, NULL
);
1299 ok(err
==ok_saved
,"mci open tempfile.wav type MPEGVideo returned %s\n", dbg_mcierr(err
));
1301 skip("Cannot open tempfile.wav type MPEGVideo for playing (%s), skipping\n", dbg_mcierr(err
));
1305 wDeviceID
= mciGetDeviceIDA("mysound");
1306 ok(wDeviceID
== 1, "mciGetDeviceIDA mysound returned %u, expected 1\n", wDeviceID
);
1308 err
= mciSendCommandA(wDeviceID
, MCI_PLAY
, 0, (DWORD_PTR
)&play_parm
);
1309 ok(!err
,"mciCommand play returned %s\n", dbg_mcierr(err
));
1311 err
= mciSendStringA("status mysound mode", buf
, sizeof(buf
), NULL
);
1312 ok(!err
,"mci status mode returned %s\n", dbg_mcierr(err
));
1313 ok(!strcmp(buf
,"playing"), "mci status mode: %s\n", buf
);
1315 status_parm
.dwItem
= MCI_STATUS_MODE
;
1316 err
= mciSendCommandA(wDeviceID
, MCI_STATUS
,
1318 (DWORD_PTR
)&status_parm
);
1319 ok(!err
,"mciCommand status mode returned %s\n", dbg_mcierr(err
));
1320 ok(status_parm
.dwReturn
== MCI_MODE_PLAY
,
1321 "mciCommand status mode: %u\n", (DWORD
)status_parm
.dwReturn
);
1323 err
= mciSendStringA("setaudio mysound volume to 1000", NULL
, 0, NULL
);
1324 ok(!err
,"mci setaudio volume to 1000 returned %s\n", dbg_mcierr(err
));
1326 err
= mciSendStringA("status mysound mode", buf
, sizeof(buf
), NULL
);
1327 ok(!err
,"mci status mode returned %s\n", dbg_mcierr(err
));
1328 ok(!strcmp(buf
,"playing"), "mci status mode: %s\n", buf
);
1330 err
= mciSendStringA("setaudio mysound volume to 1001", NULL
, 0, NULL
);
1331 ok(err
==MCIERR_OUTOFRANGE
,"mci setaudio volume to 1001 returned %s\n", dbg_mcierr(err
));
1333 err
= mciSendStringA("status mysound mode", buf
, sizeof(buf
), NULL
);
1334 ok(!err
,"mci status mode returned %s\n", dbg_mcierr(err
));
1335 ok(!strcmp(buf
,"playing"), "mci status mode: %s\n", buf
);
1337 err
= mciSendStringA("close mysound", NULL
, 0, NULL
);
1338 ok(!err
,"mci close returned %s\n", dbg_mcierr(err
));
1341 static void test_asyncWaveTypeMpegvideo(HWND hwnd
)
1343 MCIDEVICEID wDeviceID
;
1346 memset(buf
, 0, sizeof(buf
));
1348 err
= mciSendStringA("open tempfile.wav alias mysound notify type mpegvideo", buf
, sizeof(buf
), hwnd
);
1349 ok(err
==ok_saved
,"mci open tempfile.wav returned %s\n", dbg_mcierr(err
));
1351 skip("Cannot open tempfile.wav for playing (%s), skipping\n", dbg_mcierr(err
));
1354 ok(!strcmp(buf
,"1"), "mci open deviceId: %s, expected 1\n", buf
);
1355 wDeviceID
= atoi(buf
);
1356 ok(wDeviceID
,"mci open DeviceID: %d\n", wDeviceID
);
1357 test_notification(hwnd
,"open alias notify",MCI_NOTIFY_SUCCESSFUL
);
1359 err
= mciSendStringA("play mysound notify", NULL
, 0, hwnd
);
1360 ok(!err
,"mci play returned %s\n", dbg_mcierr(err
));
1362 Sleep(500); /* milliseconds */
1364 err
= mciSendStringA("pause mysound wait", NULL
, 0, hwnd
);
1365 ok(!err
,"mci pause wait returned %s\n", dbg_mcierr(err
));
1367 err
= mciSendStringA("status mysound mode notify", buf
, sizeof(buf
), hwnd
);
1368 ok(!err
,"mci status mode returned %s\n", dbg_mcierr(err
));
1369 if(!err
) ok(!strcmp(buf
,"paused"), "mci status mode: %s\n", buf
);
1370 test_notification(hwnd
,"play (superseded)",MCI_NOTIFY_SUPERSEDED
);
1371 test_notification(hwnd
,"status",MCI_NOTIFY_SUCCESSFUL
);
1373 err
= mciSendStringA("seek mysound to start wait", NULL
, 0, NULL
);
1374 ok(!err
,"mci seek to start wait returned %s\n", dbg_mcierr(err
));
1376 err
= mciSendStringA("set mysound time format milliseconds", NULL
, 0, NULL
);
1377 ok(!err
,"mci time format milliseconds returned %s\n", dbg_mcierr(err
));
1379 err
= mciSendStringA("play mysound to 1500 notify", NULL
, 0, hwnd
);
1380 ok(!err
,"mci play returned %s\n", dbg_mcierr(err
));
1382 test_notification(hwnd
,"play",0);
1384 err
= mciSendStringA("close mysound wait", NULL
, 0, NULL
);
1385 ok(!err
,"mci close wait returned %s\n", dbg_mcierr(err
));
1386 test_notification(hwnd
,"play (aborted by close)",MCI_NOTIFY_ABORTED
);
1389 static DWORD CALLBACK
thread_cb(void *p
)
1394 mr
= mciSendStringA("play x", NULL
, 0, NULL
);
1395 ok(mr
== MCIERR_INVALID_DEVICE_NAME
, "play gave: 0x%x\n", mr
);
1397 mr
= mciSendStringA("close x", NULL
, 0, NULL
);
1398 ok(mr
== MCIERR_INVALID_DEVICE_NAME
, "close gave: 0x%x\n", mr
);
1405 static void test_threads(void)
1410 mr
= mciSendStringA("open tempfile.wav alias x", NULL
, 0, NULL
);
1411 ok(mr
== 0 || mr
== ok_saved
, "open gave: 0x%x\n", mr
);
1413 skip("Cannot open tempfile.wav for playing (%s), skipping\n", dbg_mcierr(mr
));
1417 evt
= CreateEventW( NULL
, TRUE
, FALSE
, NULL
);
1419 CloseHandle(CreateThread(NULL
, 0, &thread_cb
, evt
, 0, NULL
));
1421 WaitForSingleObject(evt
, INFINITE
);
1425 mr
= mciSendStringA("close x", NULL
, 0, NULL
);
1426 ok(mr
== 0, "close gave: 0x%x\n", mr
);
1431 char curdir
[MAX_PATH
], tmpdir
[MAX_PATH
];
1435 GetCurrentDirectoryA(MAX_PATH
, curdir
);
1436 GetTempPathA(MAX_PATH
, tmpdir
);
1437 SetCurrentDirectoryA(tmpdir
);
1439 hwnd
= CreateWindowExA(0, "static", "winmm test", WS_POPUP
, 0,0,100,100,
1441 test_mciParser(hwnd
);
1442 test_openCloseWAVE(hwnd
);
1443 test_recordWAVE(hwnd
);
1444 if(waveOutGetNumDevs()){
1446 test_playWAVE(hwnd
);
1447 test_asyncWAVE(hwnd
);
1448 test_AutoOpenWAVE(hwnd
);
1449 test_playWaveTypeMpegvideo();
1450 test_asyncWaveTypeMpegvideo(hwnd
);
1452 skip("No output devices available, skipping all output tests\n");
1453 /* Win9X hangs when exiting with something still open. */
1454 err
= mciSendStringA("close all", NULL
, 0, hwnd
);
1455 ok(!err
,"final close all returned %s\n", dbg_mcierr(err
));
1456 ok(DeleteFileA("tempfile.wav") || ok_saved
, "Delete tempfile.wav (cause auto-open?)\n");
1457 DestroyWindow(hwnd
);
1459 SetCurrentDirectoryA(curdir
);