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 static const char* dbg_mcierr(MCIERROR err)
31 case 0: return "0=NOERROR";
32 #define X(label) case label: return #label ;
33 X(MCIERR_INVALID_DEVICE_ID)
34 X(MCIERR_UNRECOGNIZED_KEYWORD)
35 X(MCIERR_UNRECOGNIZED_COMMAND)
37 X(MCIERR_INVALID_DEVICE_NAME)
38 X(MCIERR_OUT_OF_MEMORY)
40 X(MCIERR_CANNOT_LOAD_DRIVER)
41 X(MCIERR_MISSING_COMMAND_STRING)
42 X(MCIERR_PARAM_OVERFLOW)
43 X(MCIERR_MISSING_STRING_ARGUMENT)
45 X(MCIERR_PARSER_INTERNAL)
46 X(MCIERR_DRIVER_INTERNAL)
47 X(MCIERR_MISSING_PARAMETER)
48 X(MCIERR_UNSUPPORTED_FUNCTION)
49 X(MCIERR_FILE_NOT_FOUND)
50 X(MCIERR_DEVICE_NOT_READY)
53 X(MCIERR_CANNOT_USE_ALL)
55 X(MCIERR_EXTENSION_NOT_FOUND)
57 X(MCIERR_FLAGS_NOT_COMPATIBLE)
58 X(MCIERR_FILE_NOT_SAVED)
59 X(MCIERR_DEVICE_TYPE_REQUIRED)
60 X(MCIERR_DEVICE_LOCKED)
61 X(MCIERR_DUPLICATE_ALIAS)
62 X(MCIERR_BAD_CONSTANT)
63 X(MCIERR_MUST_USE_SHAREABLE)
64 X(MCIERR_MISSING_DEVICE_NAME)
65 X(MCIERR_BAD_TIME_FORMAT)
66 X(MCIERR_NO_CLOSING_QUOTE)
67 X(MCIERR_DUPLICATE_FLAGS)
68 X(MCIERR_INVALID_FILE)
69 X(MCIERR_NULL_PARAMETER_BLOCK)
70 X(MCIERR_UNNAMED_RESOURCE)
71 X(MCIERR_NEW_REQUIRES_ALIAS)
72 X(MCIERR_NOTIFY_ON_AUTO_OPEN)
73 X(MCIERR_NO_ELEMENT_ALLOWED)
74 X(MCIERR_NONAPPLICABLE_FUNCTION)
75 X(MCIERR_ILLEGAL_FOR_AUTO_OPEN)
76 X(MCIERR_FILENAME_REQUIRED)
77 X(MCIERR_EXTRA_CHARACTERS)
78 X(MCIERR_DEVICE_NOT_INSTALLED)
82 X(MCIERR_DEVICE_LENGTH)
83 X(MCIERR_DEVICE_ORD_LENGTH)
85 X(MCIERR_WAVE_OUTPUTSINUSE)
86 X(MCIERR_WAVE_SETOUTPUTINUSE)
87 X(MCIERR_WAVE_INPUTSINUSE)
88 X(MCIERR_WAVE_SETINPUTINUSE)
89 X(MCIERR_WAVE_OUTPUTUNSPECIFIED)
90 X(MCIERR_WAVE_INPUTUNSPECIFIED)
91 X(MCIERR_WAVE_OUTPUTSUNSUITABLE)
92 X(MCIERR_WAVE_SETOUTPUTUNSUITABLE)
93 X(MCIERR_WAVE_INPUTSUNSUITABLE)
94 X(MCIERR_WAVE_SETINPUTUNSUITABLE)
95 X(MCIERR_SEQ_DIV_INCOMPATIBLE)
96 X(MCIERR_SEQ_PORT_INUSE)
97 X(MCIERR_SEQ_PORT_NONEXISTENT)
98 X(MCIERR_SEQ_PORT_MAPNODEVICE)
99 X(MCIERR_SEQ_PORT_MISCERROR)
101 X(MCIERR_SEQ_PORTUNSPECIFIED)
102 X(MCIERR_SEQ_NOMIDIPRESENT)
104 X(MCIERR_CREATEWINDOW)
107 X(MCIERR_NO_IDENTITY)
109 default: return "unknown error";
113 static BOOL spurious_message(LPMSG msg)
115 /* WM_DEVICECHANGE 0x0219 appears randomly */
116 if(msg->message != MM_MCINOTIFY) {
117 trace("skipping spurious message %04x\n",msg->message);
123 static void test_notification(HWND hwnd, const char* command, WPARAM type)
124 { /* Use type 0 as meaning no message */
127 do { seen = PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE); }
128 while(seen && spurious_message(&msg));
130 ok(!seen, "Expect no message from command %s\n", command);
132 ok(seen, "PeekMessage should succeed for command %s\n", command);
134 ok(msg.hwnd == hwnd, "Didn't get the handle to our test window\n");
135 ok(msg.message == MM_MCINOTIFY, "got %04x instead of MM_MCINOTIFY from command %s\n", msg.message, command);
136 ok(msg.wParam == type, "got %04lx instead of MCI_NOTIFY_xyz %04lx from command %s\n", msg.wParam, type, command);
139 static void test_notification1(HWND hwnd, const char* command, WPARAM type)
140 { /* This version works with todo_wine prefix. */
143 do { seen = PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE); }
144 while(seen && spurious_message(&msg));
146 ok(!seen, "Expect no message from command %s\n", command);
148 ok(msg.message == MM_MCINOTIFY && msg.wParam == type,"got %04lx instead of MCI_NOTIFY_xyz %04lx from command %s\n", msg.wParam, type, command);
149 else ok(seen, "PeekMessage should succeed for command %s\n", command);
152 static void test_openCloseWAVE(HWND hwnd)
155 MCI_GENERIC_PARMS parm;
156 const char command_open[] = "open new type waveaudio alias mysound";
157 const char command_close_my[] = "close mysound notify";
158 const char command_close_all[] = "close all notify";
159 const char command_sysinfo[] = "sysinfo waveaudio quantity open";
161 memset(buf, 0, sizeof(buf));
162 test_notification(hwnd, "-prior to any command-", 0);
164 err = mciSendString(command_open, buf, sizeof(buf), NULL);
165 ok(!err,"mci %s returned error: %d\n", command_open, err);
166 ok(!strcmp(buf,"1"), "mci open deviceId: %s, expected 1\n", buf);
168 if (PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) != LANG_ENGLISH)
170 skip("Non-english locale (test with hardcoded 'milliseconds')\n");
174 err = mciSendString("status mysound time format", buf, sizeof(buf), hwnd);
175 ok(!err,"mci status time format returned error: %d\n", err);
176 ok(!strcmp(buf,"milliseconds"), "mci status time format: %s\n", buf);
179 err = mciSendString(command_close_my, NULL, 0, hwnd);
180 ok(!err,"mci %s returned error: %d\n", command_close_my, err);
181 test_notification(hwnd, command_close_my, MCI_NOTIFY_SUCCESSFUL);
183 test_notification(hwnd, command_close_my, 0);
185 err = mciSendString(command_close_all, NULL, 0, NULL);
186 todo_wine ok(!err,"mci %s (without buffer) returned error: %d\n", command_close_all, err);
188 memset(buf, 0, sizeof(buf));
189 err = mciSendString(command_close_all, buf, sizeof(buf), hwnd);
190 todo_wine ok(!err,"mci %s (with output buffer) returned error: %d\n", command_close_all, err);
191 ok(buf[0] == 0, "mci %s changed output buffer: %s\n", command_close_all, buf);
192 /* No notification left, everything closed already */
193 test_notification(hwnd, command_close_all, 0);
194 /* TODO test close all sends one notification per open device */
196 memset(buf, 0, sizeof(buf));
197 err = mciSendString(command_sysinfo, buf, sizeof(buf), NULL);
198 ok(!err,"mci %s returned error: %d\n", command_sysinfo, err);
199 todo_wine ok(buf[0] == '0' && buf[1] == 0, "mci %s, expected output buffer '0', got: '%s'\n", command_sysinfo, buf);
201 err = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, 0);
202 ok(!err,"mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, 0) returned %s\n", dbg_mcierr(err));
204 parm.dwCallback = (DWORD_PTR)hwnd;
205 err = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, (DWORD_PTR)&parm);
206 ok(!err,"mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, hwnd) returned %s\n", dbg_mcierr(err));
207 test_notification(hwnd, command_close_all, 0); /* None left */
210 static void test_recordWAVE(HWND hwnd)
214 DWORD nsamp = 16000, expect;
216 MCIDEVICEID wDeviceID;
218 MCI_STATUS_PARMS status;
219 MCI_WAVE_SET_PARMS set;
220 MCI_WAVE_OPEN_PARMS open;
223 memset(buf, 0, sizeof(buf));
225 parm.open.lpstrDeviceType = "waveaudio";
226 parm.open.lpstrElementName = ""; /* "new" at the command level */
227 parm.open.lpstrAlias = "x"; /* to enable mciSendString */
228 err = mciSendCommand(0, MCI_OPEN,
229 MCI_OPEN_ELEMENT | MCI_OPEN_TYPE | MCI_OPEN_ALIAS,
231 ok(!err,"mciCommand open new type waveaudio alias x: %d\n",err);
232 wDeviceID = parm.open.wDeviceID;
234 /* Do not query time format as string because result depends on locale! */
235 parm.status.dwItem = MCI_STATUS_TIME_FORMAT;
236 err = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
237 ok(!err,"mciCommand status time format: %d\n",err);
238 ok(parm.status.dwReturn==MCI_FORMAT_MILLISECONDS,"status time format: %ld\n",parm.status.dwReturn);
240 /* Check the default recording: 8-bits per sample, mono, 11kHz */
241 err = mciSendString("status x samplespersec", buf, sizeof(buf), NULL);
242 ok(!err,"mci status samplespersec returned error: %d\n", err);
243 if(!err) ok(!strcmp(buf,"11025"), "mci status samplespersec expected 11025, got: %s\n", buf);
245 /* MCI seems to solely support PCM, no need for ACM conversion. */
246 err = mciSendString("set x format tag 2", NULL, 0, NULL);
247 ok(err==MCIERR_OUTOFRANGE,"mci set format tag 2 returned error: %d\n", err);
249 err = mciSendString("set x format tag pcm", NULL, 0, NULL);
250 ok(!err,"mci set format tag pcm returned error: %d\n", err);
252 /* Investigate: on w2k, set samplespersec 22050 sets nChannels to 2!
253 * err = mciSendString("set x samplespersec 22050", NULL, 0, NULL);
254 * ok(!err,"mci set samplespersec returned error: %d\n", err);
257 parm.set.wFormatTag = WAVE_FORMAT_PCM;
258 parm.set.nSamplesPerSec = nsamp;
259 parm.set.wBitsPerSample = nbits;
260 parm.set.nChannels = nch;
261 parm.set.nBlockAlign = parm.set.nChannels * parm.set.wBitsPerSample /8;
262 parm.set.nAvgBytesPerSec= parm.set.nSamplesPerSec * parm.set.nBlockAlign;
263 err = mciSendCommand(wDeviceID, MCI_SET,
264 MCI_WAVE_SET_SAMPLESPERSEC | MCI_WAVE_SET_CHANNELS |
265 MCI_WAVE_SET_BITSPERSAMPLE | MCI_WAVE_SET_BLOCKALIGN |
266 MCI_WAVE_SET_AVGBYTESPERSEC| MCI_WAVE_SET_FORMATTAG, (DWORD_PTR)&parm);
267 ok(!err,"mci returned error: %d\n", err);
269 err = mciSendString("record x to 2000 wait", NULL, 0, hwnd);
270 ok(!err,"mci record to 2000 returned error: %d\n", err);
271 if(err==MCIERR_WAVE_INPUTSUNSUITABLE) {
272 skip("Please install audio driver. Tests will fail\n");
276 /* Query some wave format parameters depending on the time format. */
277 err = mciSendString("status x position", buf, sizeof(buf), NULL);
278 ok(!err,"mci status position returned error: %d\n", err);
279 if(!err) todo_wine ok(!strcmp(buf,"2000"), "mci status position gave %s, expected 2000, some tests will fail\n", buf);
281 err = mciSendString("set x time format 8", NULL, 0, NULL); /* bytes */
282 ok(!err,"mci returned error: %d\n", err);
284 parm.status.dwItem = MCI_STATUS_POSITION;
285 err = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
286 ok(!err,"mci returned error: %d\n", err);
287 expect = 2 * nsamp * nch * nbits/8;
288 if(!err) todo_wine ok(parm.status.dwReturn==expect,"recorded %lu bytes, expected %u\n",parm.status.dwReturn,expect);
290 parm.set.dwTimeFormat = MCI_FORMAT_SAMPLES;
291 err = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)&parm);
292 ok(!err,"mci returned error: %d\n", err);
294 parm.status.dwItem = MCI_STATUS_POSITION;
295 err = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
296 ok(!err,"mci returned error: %d\n", err);
298 if(!err) todo_wine ok(parm.status.dwReturn==expect,"recorded %lu samples, expected %u\n",parm.status.dwReturn,expect);
300 err = mciSendString("set x time format milliseconds", NULL, 0, NULL);
301 ok(!err,"mci returned error: %d\n", err);
303 err = mciSendString("save x tempfile.wav", NULL, 0, NULL);
304 ok(!err,"mci save returned error: %d\n", err);
306 err = mciSendString("set x channels 2", NULL, 0, NULL);
307 ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci set channels after saving returned error: %d\n", err);
309 err = mciSendString("close x", NULL, 0, NULL);
310 ok(!err,"mci close returned error: %d\n", err);
311 test_notification(hwnd,"record complete",0);
314 static void test_playWAVE(HWND hwnd)
319 memset(buf, 0, sizeof(buf));
320 err = mciSendString("open waveaudio!tempfile.wav alias mysound", buf, sizeof(buf), NULL);
321 ok(!err,"mci open waveaudio!tempfile.wav returned error: %d\n", err);
323 skip("tempfile.wav was not found (not saved), skipping\n");
326 ok(!strcmp(buf,"1"), "mci open deviceId: %s, expected 1\n", buf);
328 err = mciSendString("status mysound length", buf, sizeof(buf), NULL);
329 ok(!err,"mci status length returned error: %d\n", err);
330 todo_wine ok(!strcmp(buf,"2000"), "mci status length gave %s, expected 2000, some tests will fail.\n", buf);
332 err = mciSendString("cue output", NULL, 0, NULL);
333 todo_wine ok(err==MCIERR_UNRECOGNIZED_COMMAND,"mci incorrect cue output returned: %s\n", dbg_mcierr(err));
335 /* A second play would cause Wine to hang */
336 err = mciSendString("play mysound from 500 to 1500 wait", NULL, 0, NULL);
337 ok(!err,"mci play from 500 to 1500 returned error: %d\n", err);
339 memset(buf, 0, sizeof(buf));
340 err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
341 ok(!err,"mci status position returned error: %d\n", err);
342 if(!err) ok(!strcmp(buf,"1500"), "mci status position: %s\n", buf);
344 err = mciSendString("seek mysound to 250 wait notify", NULL, 0, hwnd);
345 ok(!err,"mci seek to 250 wait notify returned error: %d\n", err);
346 test_notification(hwnd,"seek wait notify",MCI_NOTIFY_SUCCESSFUL);
348 memset(buf, 0, sizeof(buf));
349 err = mciSendString("status mysound position notify", buf, sizeof(buf), hwnd);
350 ok(!err,"mci status position notify returned error: %d\n", err);
351 if(!err) ok(!strcmp(buf,"250"), "mci status position: %s\n", buf);
352 /* Immediate commands like status also send notifications. */
353 test_notification(hwnd,"status position",MCI_NOTIFY_SUCCESSFUL);
355 memset(buf, 0, sizeof(buf));
356 err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
357 ok(!err,"mci status mode returned error: %d\n", err);
358 ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
360 err = mciSendString("close mysound", NULL, 0, NULL);
361 ok(!err,"mci close returned error: %d\n", err);
362 test_notification(hwnd,"after close",0);
365 static void test_asyncWAVE(HWND hwnd)
369 memset(buf, 0, sizeof(buf));
371 err = mciSendString("open tempfile.wav alias mysound", NULL, 0, NULL);
372 ok(!err,"mci open tempfile.wav returned error: %d\n", err);
374 skip("tempfile.wav was not found (not saved), skipping\n");
378 err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
379 ok(!err,"mci status mode returned error: %d\n", err);
380 ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
382 err = mciSendString("play mysound notify", NULL, 0, hwnd);
383 ok(!err,"mci play returned error: %d\n", err);
385 /* Give Wine's asynchronous thread time to start up. Furthermore,
386 * it uses 3 buffers per second, so that the positions reported
387 * will be 333ms, 667ms etc. at best. */
388 Sleep(100); /* milliseconds */
390 if (PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) != LANG_ENGLISH)
392 skip("Non-english locale (test with hardcoded 'milliseconds')\n");
397 err = mciSendString("status mysound time format", buf, sizeof(buf), hwnd);
398 ok(!err,"mci status time format returned error: %d\n", err);
399 ok(!strcmp(buf,"milliseconds"), "mci status time format: %s\n", buf);
403 err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
404 ok(!err,"mci status position returned error: %d\n", err);
405 ok(strcmp(buf,"2000"), "mci status position: %s\n", buf);
406 trace("position after Sleep: %sms\n",buf);
408 /* Some machines reach 79ms only during the 100ms sleep. */
409 ok(p2>=67,"not enough time elapsed %ums\n",p2);
410 test_notification(hwnd,"play (nowait)",0);
412 err = mciSendString("pause mysound wait", NULL, 0, hwnd);
413 ok(!err,"mci pause wait returned error: %s\n", dbg_mcierr(err));
416 err = mciSendString("status mysound mode notify", buf, sizeof(buf), hwnd);
417 ok(!err,"mci status mode returned error: %d\n", err);
418 if(!err) ok(!strcmp(buf,"paused"), "mci status mode: %s\n", buf);
419 test_notification(hwnd,"play",MCI_NOTIFY_SUPERSEDED);
420 test_notification(hwnd,"status",MCI_NOTIFY_SUCCESSFUL);
423 err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
424 ok(!err,"mci status position returned error: %d\n", err);
425 trace("position while paused: %sms\n",buf);
427 ok(p1>=p2, "position not increasing: %u > %u\n", p2, p1);
429 err = mciSendString("stop mysound wait", NULL, 0, NULL);
430 ok(!err,"mci stop returned error: %s\n", dbg_mcierr(err));
433 err = mciSendString("info mysound file notify", buf, sizeof(buf), hwnd);
434 ok(!err,"mci info file returned error: %d\n", err);
435 if(!err) { /* fully qualified name */
436 int len = strlen(buf);
437 todo_wine ok(len>2 && buf[1]==':',"Expected full pathname from info file: %s\n", buf);
438 ok(len>=12 && !strcmp(&buf[len-12],"tempfile.wav"), "info file returned: %s\n", buf);
440 test_notification(hwnd,"info file",MCI_NOTIFY_SUCCESSFUL);
443 err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
444 ok(!err,"mci status mode returned error: %d\n", err);
445 ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
448 err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
449 ok(!err,"mci status position returned error: %d\n", err);
450 trace("position once stopped: %sms\n",buf);
452 /* An XP machine let the position increase slightly after pause. */
453 ok(p2>=p1 && p2<=p1+16,"position changed from %ums to %ums\n",p1,p2);
455 /* No Resume once stopped (waveaudio, sequencer and cdaudio differ). */
456 err = mciSendString("resume mysound wait", NULL, 0, NULL);
457 ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci resume wait returned error: %s\n", dbg_mcierr(err));
459 err = mciSendString("play mysound wait", NULL, 0, NULL);
460 ok(!err,"mci play wait returned error: %d\n", err);
463 err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
464 ok(!err,"mci status position returned error: %d\n", err);
465 todo_wine ok(!strcmp(buf,"2000"), "mci status position: %s\n", buf);
467 err = mciSendString("seek mysound to start wait", NULL, 0, NULL);
468 ok(!err,"mci seek to start wait returned error: %d\n", err);
470 err = mciSendString("play mysound to 1000 notify", NULL, 0, hwnd);
471 ok(!err,"mci play returned error: %d\n", err);
473 Sleep(200); /* Give Wine play thread time to start up, not needed with MS-Windows. */
475 err = mciSendString("pause mysound notify", NULL, 0, NULL); /* notify no callback */
476 ok(!err,"mci pause notify returned error: %s\n", dbg_mcierr(err));
477 /* Supersede even though pause cannot notify given no callback */
478 test_notification(hwnd,"pause aborted play #1 notification",MCI_NOTIFY_SUPERSEDED);
479 test_notification(hwnd,"impossible pause notification",0);
481 err = mciSendString("cue mysound output notify", NULL, 0, hwnd);
482 ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci cue output while paused returned error: %d\n", err);
483 test_notification(hwnd,"cue output notify #2",0);
485 /* Seek or even Stop used to hang Wine on MacOS. */
486 err = mciSendString("seek mysound to 0 wait", NULL, 0, NULL);
487 ok(!err,"mci seek to start returned error: %d\n", err);
490 err = mciSendString("status mysound mode", buf, sizeof(buf), NULL);
491 ok(!err,"mci status mode returned error: %d\n", err);
492 if(!err) ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
494 err = mciSendString("seek mysound wait", NULL, 0, NULL);
495 ok(err==MCIERR_MISSING_PARAMETER,"mci seek to nowhere returned error: %d\n", err);
497 /* cdaudio does not detect to start to end as error */
498 err = mciSendString("seek mysound to start to 0", NULL, 0, NULL);
499 ok(err==MCIERR_FLAGS_NOT_COMPATIBLE,"mci seek to start to 0 returned error: %d\n", err);
501 err = mciSendString("play mysound to 1000 notify", NULL, 0, hwnd);
502 ok(!err,"mci play returned error: %d\n", err);
504 Sleep(200); /* Give Wine more than the 333ms for the first buffer? */
505 /* Give it 400ms and resume will appear to complete below. */
507 err = mciSendString("pause mysound wait", NULL, 0, NULL);
508 ok(!err,"mci pause wait returned error: %d\n", err);
509 /* Unlike sequencer and cdaudio, waveaudio's pause does not abort. */
510 test_notification(hwnd,"pause aborted play #2 notification",0);
512 err = mciSendString("resume mysound wait", NULL, 0, NULL);
513 ok(!err,"mci resume wait returned error: %d\n", err);
514 /* Resume is a short asynchronous call, something else is playing. */
516 err = mciSendString("status mysound mode", buf, sizeof(buf), NULL);
517 ok(!err,"mci status mode returned error: %d\n", err);
518 if(!err) ok(!strcmp(buf,"playing"), "mci status mode: %s\n", buf);
520 err = mciSendString("pause mysound wait", NULL, 0, NULL);
521 ok(!err,"mci pause wait returned error: %d\n", err);
523 err = mciSendString("pause mysound wait", NULL, 0, NULL);
524 ok(!err,"mci pause wait returned error: %d\n", err);
526 /* Better ask position only when paused, is it updated while playing? */
528 err = mciSendString("status mysound position", buf, sizeof(buf), NULL);
529 ok(!err,"mci status position returned error: %d\n", err);
530 /* TODO compare position < 900 */
531 ok(strcmp(buf,"1000"), "mci resume waited\n");
532 ok(strcmp(buf,"2000"), "mci resume played to end\n");
533 trace("position after resume: %sms\n",buf);
534 test_notification(hwnd,"play (aborted by pause/resume/pause)",0);
536 err = mciSendString("close mysound wait", NULL, 0, NULL);
537 ok(!err,"mci close wait returned error: %d\n", err);
538 test_notification(hwnd,"play (aborted by close)",MCI_NOTIFY_ABORTED);
541 static void test_AutoOpenWAVE(HWND hwnd)
543 /* This test used(?) to cause intermittent crashes when Wine exits, after
544 * fixme:winmm:MMDRV_Exit Closing while ll-driver open
547 char buf[512], path[300], command[330];
548 memset(buf, 0, sizeof(buf)); memset(path, 0, sizeof(path));
550 /* Do not crash on NULL buffer pointer */
551 err = mciSendString("sysinfo waveaudio quantity open", NULL, 0, NULL);
552 ok(err==MCIERR_PARAM_OVERFLOW,"mci sysinfo without buffer returned error: %d\n", err);
554 err = mciSendString("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL);
555 ok(!err,"mci sysinfo waveaudio quantity open returned error: %d\n", err);
556 if(!err) todo_wine ok(!strcmp(buf,"0"), "sysinfo quantity open expected 0, got: %s\n", buf);
558 err = mciSendString("play no-such-file-exists.wav notify", buf, sizeof(buf), NULL);
559 if(err==MCIERR_FILE_NOT_FOUND) {
560 /* Unsupported auto-open leaves the file open, preventing clean-up */
561 skip("Skipping auto-open tests in Wine\n");
565 err = mciSendString("play tempfile.wav notify", buf, sizeof(buf), hwnd);
566 todo_wine ok(err==MCIERR_NOTIFY_ON_AUTO_OPEN,"mci auto-open play notify returned error: %d\n", err);
568 if(err) /* FIXME: don't open twice yet, it confuses Wine. */
569 err = mciSendString("play tempfile.wav", buf, sizeof(buf), hwnd);
570 ok(!err,"mci auto-open play returned error: %d\n", err);
573 err = mciSendString("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL);
574 ok(!err,"mci sysinfo waveaudio quantity after auto-open returned error: %d\n", err);
575 if(!err) todo_wine ok(!strcmp(buf,"1"), "sysinfo quantity open expected 1, got: %s\n", buf);
578 err = mciSendString("sysinfo waveaudio name 1 open", buf, sizeof(buf), NULL);
579 todo_wine ok(!err,"mci sysinfo waveaudio name after auto-open returned error: %d\n", err);
580 /* This is the alias, not necessarily a file name. */
581 if(!err) ok(!strcmp(buf,"tempfile.wav"), "sysinfo name 1 open returned: %s\n", buf);
583 /* Save the full pathname to the file. */
584 err = mciSendString("info tempfile.wav file", path, sizeof(path), NULL);
585 ok(!err,"mci info tempfile.wav file returned error: %d\n", err);
586 if(err) strcpy(path,"tempfile.wav");
588 err = mciSendString("status tempfile.wav mode", NULL, 0, hwnd);
589 ok(!err,"mci status tempfile.wav mode without buffer returned error: %d\n", err);
591 sprintf(command,"status \"%s\" mode",path);
592 err = mciSendString(command, buf, sizeof(buf), hwnd);
593 ok(!err,"mci status full-path-to-tempfile.wav mode returned error: %d\n", err);
596 err = mciSendString("status tempfile.wav mode", buf, sizeof(buf), hwnd);
597 ok(!err,"mci status tempfile.wav mode returned error: %d\n", err);
598 if(!err) ok(!strcmp(buf,"playing"), "mci auto-open status mode, got: %s\n", buf);
600 err = mciSendString("open tempfile.wav", buf, sizeof(buf), NULL);
601 todo_wine ok(err==MCIERR_DEVICE_OPEN, "mci open from auto-open returned error: %s\n", dbg_mcierr(err));
603 /* w2k/xp and Wine differ. While the device is busy playing, it is
604 * regularly open and accessible via the filename: subsequent
605 * commands must not cause auto-open each. In Wine, a subsequent
606 * command with notify request may cause the initial play
607 * notification to be superseded, in turn causing MCI to close the
608 * device. I.e. MCI uses the auto-open notification for itself,
609 * that's why it's not available to the app. On w2k/xp,
610 * subsequent commands with notify requests are returned with
611 * MCIERR_NOTIFY_ON_AUTO_OPEN and thus don't abort the original
614 err = mciSendString("status tempfile.wav mode notify", buf, sizeof(buf), hwnd);
615 trace("mci auto-open status notify return value: %d\n",err);
616 todo_wine ok(err==MCIERR_NOTIFY_ON_AUTO_OPEN, "mci auto-open status notify: %s\n", dbg_mcierr(err));
617 if(!err) { /* Wine style */
618 trace("New style MCI auto-close upon notification behaviour.\n");
619 todo_wine ok(!strcmp(buf,"playing"), "mci auto-open status mode notify, got: %s\n", buf);
620 /* fixme:winmm:MMDRV_Exit Closing while ll-driver open
621 * is explained by failure to auto-close a device. */
622 test_notification(hwnd,"status notify",MCI_NOTIFY_SUCCESSFUL);
623 /* MCI received NOTIFY_SUPERSEDED and auto-closed the device. */
625 test_notification(hwnd,"auto-open",0);
626 } else if(err==MCIERR_NOTIFY_ON_AUTO_OPEN) { /* MS style */
627 trace("Old style MCI auto-open forbids notification behaviour.\n");
629 err = mciSendString("pause tempfile.wav", NULL, 0, hwnd);
630 ok(!err,"mci auto-still-open pause returned error: %d\n", err);
632 err = mciSendString("status tempfile.wav mode", buf, sizeof(buf), hwnd);
633 ok(!err,"mci status mode returned error: %d\n", err);
634 if(!err) ok(!strcmp(buf,"paused"), "mci auto-open status mode, got: %s\n", buf);
637 err = mciSendString("stop tempfile.wav", NULL, 0, hwnd);
638 ok(!err,"mci auto-still-open stop returned error: %d\n", err);
639 Sleep(16); /* makes sysinfo quantity open below succeed */
642 err = mciSendString("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL);
643 ok(!err,"mci sysinfo waveaudio quantity open after close returned error: %d\n", err);
644 if(!err) todo_wine ok(!strcmp(buf,"0"), "sysinfo quantity open expected 0 after auto-close, got: %s\n", buf);
646 /* w95-WinME (not w2k/XP) switch to C:\ after auto-playing once. Prevent
647 * MCIERR_FILE_NOT_FOUND by using the full path name from the Info file command.
649 sprintf(command,"status \"%s\" mode wait",path);
650 err = mciSendString(command, buf, sizeof(buf), hwnd);
651 ok(!err,"mci re-auto-open status mode returned error: %d\n", err);
652 if(!err) ok(!strcmp(buf,"stopped"), "mci re-auto-open status mode, got: %s\n", buf);
654 err = mciSendString("capability waveaudio device type", buf, sizeof(buf), hwnd);
655 ok(!err,"mci capability device type returned error: %d\n", err);
656 if(!err) ok(!strcmp(buf,"waveaudio"), "mci capability device type response: %s\n", buf);
658 /* waveaudio forbids Pause without Play. */
659 sprintf(command,"pause \"%s\"",path);
660 err = mciSendString(command, NULL, 0, hwnd);
661 ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci auto-open pause returned error: %d\n", err);
667 hwnd = CreateWindowExA(0, "static", "winmm test", WS_POPUP, 0,0,100,100,
669 test_openCloseWAVE(hwnd);
670 test_recordWAVE(hwnd);
672 test_asyncWAVE(hwnd);
673 test_AutoOpenWAVE(hwnd);
674 ok(DeleteFile("tempfile.wav"),"Delete tempfile.wav (cause auto-open?)\n");