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;
33 MCI_STATUS_PARMS status;
34 MCI_WAVE_SET_PARMS set;
35 MCI_WAVE_OPEN_PARMS open;
39 static const char* dbg_mcierr(MCIERROR err)
42 case 0: return "0=NOERROR";
43 #define X(label) case label: return #label ;
44 X(MCIERR_INVALID_DEVICE_ID)
45 X(MCIERR_UNRECOGNIZED_KEYWORD)
46 X(MCIERR_UNRECOGNIZED_COMMAND)
48 X(MCIERR_INVALID_DEVICE_NAME)
49 X(MCIERR_OUT_OF_MEMORY)
51 X(MCIERR_CANNOT_LOAD_DRIVER)
52 X(MCIERR_MISSING_COMMAND_STRING)
53 X(MCIERR_PARAM_OVERFLOW)
54 X(MCIERR_MISSING_STRING_ARGUMENT)
56 X(MCIERR_PARSER_INTERNAL)
57 X(MCIERR_DRIVER_INTERNAL)
58 X(MCIERR_MISSING_PARAMETER)
59 X(MCIERR_UNSUPPORTED_FUNCTION)
60 X(MCIERR_FILE_NOT_FOUND)
61 X(MCIERR_DEVICE_NOT_READY)
64 X(MCIERR_CANNOT_USE_ALL)
66 X(MCIERR_EXTENSION_NOT_FOUND)
68 X(MCIERR_FLAGS_NOT_COMPATIBLE)
69 X(MCIERR_FILE_NOT_SAVED)
70 X(MCIERR_DEVICE_TYPE_REQUIRED)
71 X(MCIERR_DEVICE_LOCKED)
72 X(MCIERR_DUPLICATE_ALIAS)
73 X(MCIERR_BAD_CONSTANT)
74 X(MCIERR_MUST_USE_SHAREABLE)
75 X(MCIERR_MISSING_DEVICE_NAME)
76 X(MCIERR_BAD_TIME_FORMAT)
77 X(MCIERR_NO_CLOSING_QUOTE)
78 X(MCIERR_DUPLICATE_FLAGS)
79 X(MCIERR_INVALID_FILE)
80 X(MCIERR_NULL_PARAMETER_BLOCK)
81 X(MCIERR_UNNAMED_RESOURCE)
82 X(MCIERR_NEW_REQUIRES_ALIAS)
83 X(MCIERR_NOTIFY_ON_AUTO_OPEN)
84 X(MCIERR_NO_ELEMENT_ALLOWED)
85 X(MCIERR_NONAPPLICABLE_FUNCTION)
86 X(MCIERR_ILLEGAL_FOR_AUTO_OPEN)
87 X(MCIERR_FILENAME_REQUIRED)
88 X(MCIERR_EXTRA_CHARACTERS)
89 X(MCIERR_DEVICE_NOT_INSTALLED)
93 X(MCIERR_DEVICE_LENGTH)
94 X(MCIERR_DEVICE_ORD_LENGTH)
96 X(MCIERR_WAVE_OUTPUTSINUSE)
97 X(MCIERR_WAVE_SETOUTPUTINUSE)
98 X(MCIERR_WAVE_INPUTSINUSE)
99 X(MCIERR_WAVE_SETINPUTINUSE)
100 X(MCIERR_WAVE_OUTPUTUNSPECIFIED)
101 X(MCIERR_WAVE_INPUTUNSPECIFIED)
102 X(MCIERR_WAVE_OUTPUTSUNSUITABLE)
103 X(MCIERR_WAVE_SETOUTPUTUNSUITABLE)
104 X(MCIERR_WAVE_INPUTSUNSUITABLE)
105 X(MCIERR_WAVE_SETINPUTUNSUITABLE)
106 X(MCIERR_SEQ_DIV_INCOMPATIBLE)
107 X(MCIERR_SEQ_PORT_INUSE)
108 X(MCIERR_SEQ_PORT_NONEXISTENT)
109 X(MCIERR_SEQ_PORT_MAPNODEVICE)
110 X(MCIERR_SEQ_PORT_MISCERROR)
112 X(MCIERR_SEQ_PORTUNSPECIFIED)
113 X(MCIERR_SEQ_NOMIDIPRESENT)
115 X(MCIERR_CREATEWINDOW)
118 X(MCIERR_NO_IDENTITY)
121 static char name[20]; /* Not to be called twice in a parameter list! */
122 sprintf(name, "MMSYSERR %u", err);
128 static BOOL spurious_message(LPMSG msg)
130 /* WM_DEVICECHANGE 0x0219 appears randomly */
131 if(msg->message != MM_MCINOTIFY) {
132 trace("skipping spurious message %04x\n",msg->message);
138 /* A single ok() in each code path allows to prefix this with todo_wine */
139 static void test_notification(HWND hwnd, const char* command, WPARAM type)
140 { /* Use type 0 as meaning no message */
143 do { seen = PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE); }
144 while(seen && spurious_message(&msg));
146 /* We observe transient delayed notification, mostly on native.
147 * Notification is not always present right when mciSend returns. */
148 trace("Waiting for delayed notification from %s\n", command);
149 MsgWaitForMultipleObjects(0, NULL, FALSE, 3000, QS_POSTMESSAGE);
150 seen = PeekMessageA(&msg, hwnd, MM_MCINOTIFY, MM_MCINOTIFY, PM_REMOVE);
153 ok(type==0, "Expect message %lx from %s\n", type, command);
154 else if(msg.hwnd != hwnd)
155 ok(msg.hwnd == hwnd, "Didn't get the handle to our test window\n");
156 else if(msg.message != MM_MCINOTIFY)
157 ok(msg.message == MM_MCINOTIFY, "got %04x instead of MM_MCINOTIFY from command %s\n", msg.message, command);
158 else ok(msg.wParam == type, "got %04lx instead of MCI_NOTIFY_xyz %04lx from command %s\n", msg.wParam, type, command);
161 static void test_openCloseWAVE(HWND hwnd)
164 MCI_GENERIC_PARMS parm;
165 const char command_open[] = "open new type waveaudio alias mysound notify";
166 const char command_close_my[] = "close mysound notify";
167 const char command_close_all[] = "close all notify";
168 const char command_sysinfo[] = "sysinfo waveaudio quantity open";
170 memset(buf, 0, sizeof(buf));
171 test_notification(hwnd, "-prior to any command-", 0);
173 err = mciSendString("sysinfo all quantity", buf, sizeof(buf), hwnd);
174 todo_wine ok(!err,"mci %s returned %s\n", command_open, dbg_mcierr(err));
175 if(!err) trace("[MCI] with %s drivers\n", buf);
177 err = mciSendString("open new type waveaudio alias r shareable", buf, sizeof(buf), NULL);
178 ok(err==MCIERR_UNSUPPORTED_FUNCTION,"mci open new shareable returned %s\n", dbg_mcierr(err));
180 err = mciSendString("close r", NULL, 0, NULL);
181 ok(!err,"mci close shareable returned %s\n", dbg_mcierr(err));
184 err = mciSendString(command_open, buf, sizeof(buf), hwnd);
185 ok(!err,"mci %s returned %s\n", command_open, dbg_mcierr(err));
186 ok(!strcmp(buf,"1"), "mci open deviceId: %s, expected 1\n", buf);
187 /* Wine<=1.1.33 used to ignore anything past alias XY */
188 test_notification(hwnd,"open new alias notify",MCI_NOTIFY_SUCCESSFUL);
190 err = mciSendString("status mysound time format", buf, sizeof(buf), hwnd);
191 ok(!err,"mci status time format returned %s\n", dbg_mcierr(err));
193 if (PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) == LANG_ENGLISH)
194 ok(!strcmp(buf,"milliseconds"), "mci status time format: %s\n", buf);
195 else trace("locale-dependent time format: %s (ms)\n", buf);
198 err = mciSendString(command_close_my, NULL, 0, hwnd);
199 ok(!err,"mci %s returned %s\n", command_close_my, dbg_mcierr(err));
200 test_notification(hwnd, command_close_my, MCI_NOTIFY_SUCCESSFUL);
202 test_notification(hwnd, command_close_my, 0);
204 err = mciSendString("open no-such-file-exists.wav alias y", buf, sizeof(buf), NULL);
205 ok(err==MCIERR_FILE_NOT_FOUND,"open no-such-file.wav returned %s\n", dbg_mcierr(err));
207 err = mciSendString("close y", NULL, 0, NULL);
208 ok(!err,"close y returned %s\n", dbg_mcierr(err));
211 err = mciSendString("open no-such-dir\\file.wav alias y type waveaudio", buf, sizeof(buf), NULL);
212 ok(err==MCIERR_FILE_NOT_FOUND || broken(err==MCIERR_INVALID_FILE /* Win9X */),"open no-such-dir/file.wav returned %s\n", dbg_mcierr(err));
214 err = mciSendString("close y", NULL, 0, NULL);
215 ok(!err,"close y returned %s\n", dbg_mcierr(err));
218 err = mciSendString(command_close_all, NULL, 0, NULL);
219 todo_wine ok(!err,"mci %s (without buffer) returned %s\n", command_close_all, dbg_mcierr(err));
221 memset(buf, 0, sizeof(buf));
222 err = mciSendString(command_close_all, buf, sizeof(buf), hwnd);
223 todo_wine ok(!err,"mci %s (with output buffer) returned %s\n", command_close_all, dbg_mcierr(err));
224 ok(buf[0] == 0, "mci %s changed output buffer: %s\n", command_close_all, buf);
225 /* No notification left, everything closed already */
226 test_notification(hwnd, command_close_all, 0);
227 /* TODO test close all sends one notification per open device */
229 memset(buf, 0, sizeof(buf));
230 err = mciSendString(command_sysinfo, buf, sizeof(buf), NULL);
231 ok(!err,"mci %s returned %s\n", command_sysinfo, dbg_mcierr(err));
232 todo_wine ok(buf[0] == '0' && buf[1] == 0, "mci %s, expected output buffer '0', got: '%s'\n", command_sysinfo, buf);
234 err = mciSendString("open new type waveaudio", buf, sizeof(buf), NULL);
235 ok(err==MCIERR_NEW_REQUIRES_ALIAS,"mci open new without alias returned %s\n", dbg_mcierr(err));
237 err = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_WAIT, 0); /* from MSDN */
238 ok(!err,"mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, 0) returned %s\n", dbg_mcierr(err));
240 err = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, 0);
241 ok(!err,"mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, 0) returned %s\n", dbg_mcierr(err));
243 parm.dwCallback = (DWORD_PTR)hwnd;
244 err = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, (DWORD_PTR)&parm);
245 ok(!err,"mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, hwnd) returned %s\n", dbg_mcierr(err));
246 test_notification(hwnd, command_close_all, 0); /* None left */
249 static void test_recordWAVE(HWND hwnd)
253 DWORD nsamp = 16000, expect;
254 MCIERROR err, ok_pcm;
255 MCIDEVICEID wDeviceID;
256 MCI_PARMS_UNION parm;
258 memset(buf, 0, sizeof(buf));
259 test_notification(hwnd, "-prior to recording-", 0);
261 parm.open.lpstrDeviceType = "waveaudio";
262 parm.open.lpstrElementName = ""; /* "new" at the command level */
263 parm.open.lpstrAlias = "x"; /* to enable mciSendString */
264 parm.open.dwCallback = (DWORD_PTR)hwnd;
265 err = mciSendCommand(0, MCI_OPEN,
266 MCI_OPEN_ELEMENT | MCI_OPEN_TYPE | MCI_OPEN_ALIAS | MCI_NOTIFY,
268 ok(!err,"mciCommand open new type waveaudio alias x notify: %s\n", dbg_mcierr(err));
269 wDeviceID = parm.open.wDeviceID;
271 /* In Wine, both MCI_Open and the individual drivers send notifications. */
272 test_notification(hwnd, "open new", MCI_NOTIFY_SUCCESSFUL);
273 todo_wine test_notification(hwnd, "open new no #2", 0);
275 /* Do not query time format as string because result depends on locale! */
276 parm.status.dwItem = MCI_STATUS_TIME_FORMAT;
277 err = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
278 ok(!err,"mciCommand status time format: %s\n", dbg_mcierr(err));
279 ok(parm.status.dwReturn==MCI_FORMAT_MILLISECONDS,"status time format: %ld\n",parm.status.dwReturn);
281 /* Info file fails until named in Open or Save. */
282 err = mciSendString("info x file", buf, sizeof(buf), NULL);
283 todo_wine ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci info new file returned %s\n", dbg_mcierr(err));
285 /* Check the default recording: 8-bits per sample, mono, 11kHz */
286 err = mciSendString("status x samplespersec", buf, sizeof(buf), NULL);
287 ok(!err,"mci status samplespersec returned %s\n", dbg_mcierr(err));
288 if(!err) ok(!strcmp(buf,"11025"), "mci status samplespersec expected 11025, got: %s\n", buf);
290 /* MCI seems to solely support PCM, no need for ACM conversion. */
291 err = mciSendString("set x format tag 2", NULL, 0, NULL);
292 ok(err==MCIERR_OUTOFRANGE,"mci set format tag 2 returned %s\n", dbg_mcierr(err));
294 /* MCI appears to scan the available devices for support of this format,
295 * returning MCIERR_OUTOFRANGE on machines with no sound.
296 * Don't skip here, record will fail below. */
297 err = mciSendString("set x format tag pcm", NULL, 0, NULL);
298 ok(!err || err==MCIERR_OUTOFRANGE,"mci set format tag pcm returned %s\n", dbg_mcierr(err));
301 err = mciSendString("set x samplespersec 41000 alignment 4 channels 2", NULL, 0, NULL);
302 ok(err==ok_pcm,"mci set samples+align+channels returned %s\n", dbg_mcierr(err));
304 /* Investigate: on w2k, set samplespersec 22050 sets nChannels to 2!
305 * err = mciSendString("set x samplespersec 22050", NULL, 0, NULL);
306 * ok(!err,"mci set samplespersec returned %s\n", dbg_mcierr(err));
309 parm.set.wFormatTag = WAVE_FORMAT_PCM;
310 parm.set.nSamplesPerSec = nsamp;
311 parm.set.wBitsPerSample = nbits;
312 parm.set.nChannels = nch;
313 parm.set.nBlockAlign = parm.set.nChannels * parm.set.wBitsPerSample /8;
314 parm.set.nAvgBytesPerSec= parm.set.nSamplesPerSec * parm.set.nBlockAlign;
315 err = mciSendCommand(wDeviceID, MCI_SET,
316 MCI_WAVE_SET_SAMPLESPERSEC | MCI_WAVE_SET_CHANNELS |
317 MCI_WAVE_SET_BITSPERSAMPLE | MCI_WAVE_SET_BLOCKALIGN |
318 MCI_WAVE_SET_AVGBYTESPERSEC| MCI_WAVE_SET_FORMATTAG, (DWORD_PTR)&parm);
319 ok(err==ok_pcm,"mciCommand set wave format: %s\n", dbg_mcierr(err));
321 /* A few ME machines pass all tests except set format tag pcm! */
322 err = mciSendString("record x to 2000 wait", NULL, 0, hwnd);
323 ok(err || !ok_pcm,"can record yet set wave format pcm returned %s\n", dbg_mcierr(ok_pcm));
324 ok(!err || err==(ok_pcm==MCIERR_OUTOFRANGE ? MCIERR_WAVE_INPUTSUNSUITABLE : 0),"mci record to 2000 returned %s\n", dbg_mcierr(err));
326 if (err==MCIERR_WAVE_INPUTSUNSUITABLE)
327 skip("Please install audio driver. Everything is skipped.\n");
328 else skip("Cannot record cause %s. Everything is skipped.\n", dbg_mcierr(err));
330 err = mciSendString("close x", NULL, 0, NULL);
331 ok(!err,"mci close returned %s\n", dbg_mcierr(err));
332 test_notification(hwnd,"record skipped",0);
336 /* Query some wave format parameters depending on the time format. */
337 err = mciSendString("status x position", buf, sizeof(buf), NULL);
338 ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
339 if(!err) todo_wine ok(!strcmp(buf,"2000"), "mci status position gave %s, expected 2000, some tests will fail\n", buf);
341 err = mciSendString("set x time format 8", NULL, 0, NULL); /* bytes */
342 ok(!err,"mci returned %s\n", dbg_mcierr(err));
344 parm.status.dwItem = MCI_STATUS_POSITION;
345 err = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
346 ok(!err,"mciCommand status position: %s\n", dbg_mcierr(err));
347 expect = 2 * nsamp * nch * nbits/8;
348 if(!err) todo_wine ok(parm.status.dwReturn==expect,"recorded %lu bytes, expected %u\n",parm.status.dwReturn,expect);
350 parm.set.dwTimeFormat = MCI_FORMAT_SAMPLES;
351 err = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)&parm);
352 ok(!err,"mciCommand set time format samples: %s\n", dbg_mcierr(err));
354 parm.status.dwItem = MCI_STATUS_POSITION;
355 err = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
356 ok(!err,"mciCommand status position: %s\n", dbg_mcierr(err));
358 if(!err) todo_wine ok(parm.status.dwReturn==expect,"recorded %lu samples, expected %u\n",parm.status.dwReturn,expect);
360 err = mciSendString("set x time format milliseconds", NULL, 0, NULL);
361 ok(!err,"mci set time format milliseconds returned %s\n", dbg_mcierr(err));
363 err = mciSendString("save x tempfile1.wav", NULL, 0, NULL);
364 ok(!err,"mci save returned %s\n", dbg_mcierr(err));
366 err = mciSendString("save x tempfile.wav", NULL, 0, NULL);
367 ok(!err,"mci save returned %s\n", dbg_mcierr(err));
368 if(!err) ok_saved = 0;
370 /* Save must not rename the original file. */
371 if (!DeleteFile("tempfile1.wav"))
372 todo_wine ok(FALSE, "Save must not rename the original file; DeleteFile returned %d\n", GetLastError());
374 err = mciSendString("set x channels 2", NULL, 0, NULL);
375 ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci set channels after saving returned %s\n", dbg_mcierr(err));
377 parm.seek.dwTo = 600;
378 err = mciSendCommand(wDeviceID, MCI_SEEK, MCI_TO | MCI_WAIT, (DWORD_PTR)&parm);
379 ok(!err,"mciCommand seek to 600: %s\n", dbg_mcierr(err));
381 /* Truncate to current position */
382 err = mciSendString("delete x", NULL, 0, NULL);
383 todo_wine ok(!err,"mci delete returned %s\n", dbg_mcierr(err));
386 err = mciSendString("status x length", buf, sizeof(buf), NULL);
387 ok(!err,"mci status length returned %s\n", dbg_mcierr(err));
388 todo_wine ok(!strcmp(buf,"600"), "mci status length after delete gave %s, expected 600\n", buf);
390 err = mciSendString("close x", NULL, 0, NULL);
391 ok(!err,"mci close returned %s\n", dbg_mcierr(err));
392 test_notification(hwnd,"record complete",0);
395 static void test_playWAVE(HWND hwnd)
399 memset(buf, 0, sizeof(buf));
401 err = mciSendString("open waveaudio!tempfile.wav alias mysound", NULL, 0, NULL);
402 ok(err==ok_saved,"mci open waveaudio!tempfile.wav returned %s\n", dbg_mcierr(err));
404 skip("Cannot open waveaudio!tempfile.wav for playing (%s), skipping\n", dbg_mcierr(err));
408 err = mciSendString("status mysound length", buf, sizeof(buf), NULL);
409 ok(!err,"mci status length returned %s\n", dbg_mcierr(err));
410 todo_wine ok(!strcmp(buf,"2000"), "mci status length gave %s, expected 2000, some tests will fail.\n", buf);
412 err = mciSendString("cue output", NULL, 0, NULL);
413 todo_wine ok(err==MCIERR_UNRECOGNIZED_COMMAND,"mci incorrect cue output returned %s\n", dbg_mcierr(err));
415 /* Test MCI to the bones -- Some todo_wine from Cue and
416 * from Play from 0 to 0 are not worth fixing. */
417 err = mciSendString("cue mysound output notify", NULL, 0, hwnd);
418 ok(!err,"mci cue output after open file returned %s\n", dbg_mcierr(err));
419 /* Notification is delayed as a play thread is started. */
420 todo_wine test_notification(hwnd, "cue immediate", 0);
422 /* Cue pretends to put the MCI into paused state. */
423 err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
424 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
425 todo_wine ok(!strcmp(buf,"paused"), "mci status mode: %s, expected (pseudo)paused\n", buf);
427 /* Strange pause where Pause is rejected, unlike Play; Pause; Pause tested below */
428 err = mciSendString("pause mysound", NULL, 0, hwnd);
429 ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci pause after cue returned %s\n", dbg_mcierr(err));
431 /* MCI appears to start the play thread in this border case.
432 * Guessed that from (flaky) status mode and late notification arrival. */
433 err = mciSendString("play mysound from 0 to 0 notify", NULL, 0, hwnd);
434 ok(!err,"mci play from 0 to 0 returned %s\n", dbg_mcierr(err));
435 todo_wine test_notification(hwnd, "cue aborted by play", MCI_NOTIFY_ABORTED);
436 /* play's own notification follows below */
438 err = mciSendString("play mysound from 250 to 0", NULL, 0, NULL);
439 ok(err==MCIERR_OUTOFRANGE,"mci play from 250 to 0 returned %s\n", dbg_mcierr(err));
441 Sleep(50); /* Give play from 0 to 0 time to finish. */
442 todo_wine test_notification(hwnd, "play from 0 to 0", MCI_NOTIFY_SUCCESSFUL);
444 err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
445 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
446 ok(!strcmp(buf,"stopped"), "mci status mode: %s after play from 0 to 0\n", buf);
448 err = mciSendString("play MYSOUND from 250 to 0 notify", NULL, 0, hwnd);
449 ok(err==MCIERR_OUTOFRANGE,"mci play from 250 to 0 notify returned %s\n", dbg_mcierr(err));
450 /* No notification (checked below) sent if error */
452 /* A second play caused Wine<1.1.33 to hang */
453 err = mciSendString("play mysound from 500 to 1500 wait", NULL, 0, NULL);
454 ok(!err,"mci play from 500 to 1500 returned %s\n", dbg_mcierr(err));
456 memset(buf, 0, sizeof(buf));
457 err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
458 ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
459 if(!err) ok(!strcmp(buf,"1500"), "mci status position: %s\n", buf);
461 /* mci will not play position < current */
462 err = mciSendString("play mysound to 1000", NULL, 0, NULL);
463 ok(err==MCIERR_OUTOFRANGE,"mci play to 1000 returned %s\n", dbg_mcierr(err));
465 /* mci will not play to > end */
466 err = mciSendString("play mysound TO 3000 notify", NULL, 0, hwnd);
467 ok(err==MCIERR_OUTOFRANGE,"mci play to 3000 notify returned %s\n", dbg_mcierr(err));
469 err = mciSendString("play mysound to 2000", NULL, 0, NULL);
470 ok(!err,"mci play to 2000 returned %s\n", dbg_mcierr(err));
472 /* Rejected while playing */
473 err = mciSendString("cue mysound output", NULL, 0, NULL);
474 ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci cue output while playing returned %s\n", dbg_mcierr(err));
476 err = mciSendString("play mysound to 3000", NULL, 0, NULL);
477 ok(err==MCIERR_OUTOFRANGE,"mci play to 3000 returned %s\n", dbg_mcierr(err));
479 err = mciSendString("stop mysound Wait", NULL, 0, NULL);
480 ok(!err,"mci stop wait returned %s\n", dbg_mcierr(err));
481 test_notification(hwnd, "play/cue/pause/stop", 0);
483 err = mciSendString("Seek Mysound to 250 wait Notify", NULL, 0, hwnd);
484 ok(!err,"mci seek to 250 wait notify returned %s\n", dbg_mcierr(err));
485 test_notification(hwnd,"seek wait notify",MCI_NOTIFY_SUCCESSFUL);
487 memset(buf, 0, sizeof(buf));
488 err = mciSendString("status mysound position notify", buf, sizeof(buf), hwnd);
489 ok(!err,"mci status position notify returned %s\n", dbg_mcierr(err));
490 if(!err) ok(!strcmp(buf,"250"), "mci status position: %s\n", buf);
491 /* Immediate commands like status also send notifications. */
492 test_notification(hwnd,"status position",MCI_NOTIFY_SUCCESSFUL);
494 memset(buf, 0, sizeof(buf));
495 err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
496 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
497 ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
499 /* Another play from == to testcase */
500 err = mciSendString("play mysound to 250 wait notify", NULL, 0, hwnd);
501 ok(!err,"mci play (from 250) to 250 returned %s\n", dbg_mcierr(err));
502 todo_wine test_notification(hwnd,"play to 250 wait notify",MCI_NOTIFY_SUCCESSFUL);
504 err = mciSendString("cue mysound output", NULL, 0, NULL);
505 ok(!err,"mci cue output after play returned %s\n", dbg_mcierr(err));
507 err = mciSendString("close mysound", NULL, 0, NULL);
508 ok(!err,"mci close returned %s\n", dbg_mcierr(err));
509 test_notification(hwnd,"after close",0);
512 static void test_asyncWAVE(HWND hwnd)
514 MCIDEVICEID wDeviceID;
515 MCI_PARMS_UNION parm;
518 memset(buf, 0, sizeof(buf));
520 err = mciSendString("open tempfile.wav alias mysound notify", buf, sizeof(buf), hwnd);
521 ok(err==ok_saved,"mci open tempfile.wav returned %s\n", dbg_mcierr(err));
523 skip("Cannot open tempfile.wav for playing (%s), skipping\n", dbg_mcierr(err));
526 ok(!strcmp(buf,"1"), "mci open deviceId: %s, expected 1\n", buf);
527 wDeviceID = atoi(buf);
528 ok(wDeviceID,"mci open DeviceID: %d\n", wDeviceID);
529 test_notification(hwnd,"open alias notify",MCI_NOTIFY_SUCCESSFUL);
531 err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
532 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
533 ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
535 err = mciSendString("play mysound notify", NULL, 0, hwnd);
536 ok(!err,"mci play returned %s\n", dbg_mcierr(err));
538 /* Give Wine's asynchronous thread time to start up. Furthermore,
539 * it uses 3 buffers per second, so that the positions reported
540 * will be 333ms, 667ms etc. at best. */
541 Sleep(100); /* milliseconds */
543 /* Do not query time format as string because result depends on locale! */
544 parm.status.dwItem = MCI_STATUS_TIME_FORMAT;
545 err = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
546 ok(!err,"mciCommand status time format: %s\n", dbg_mcierr(err));
547 if(!err) ok(parm.status.dwReturn==MCI_FORMAT_MILLISECONDS,"status time format: %ld\n",parm.status.dwReturn);
549 parm.set.dwTimeFormat = MCI_FORMAT_MILLISECONDS;
550 err = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)&parm);
551 ok(!err,"mciCommand set time format ms: %s\n", dbg_mcierr(err));
554 err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
555 ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
556 ok(strcmp(buf,"2000"), "mci status position: %s, expected 2000\n", buf);
557 trace("position after Sleep: %sms\n",buf);
559 /* Some machines reach 79ms only during the 100ms sleep. */
560 ok(p2>=67,"not enough time elapsed %ums\n",p2);
561 test_notification(hwnd,"play (nowait)",0);
563 err = mciSendString("pause mysound wait", NULL, 0, hwnd);
564 ok(!err,"mci pause wait returned %s\n", dbg_mcierr(err));
567 err = mciSendString("status mysound mode notify", buf, sizeof(buf), hwnd);
568 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
569 if(!err) ok(!strcmp(buf,"paused"), "mci status mode: %s\n", buf);
570 test_notification(hwnd,"play",MCI_NOTIFY_SUPERSEDED);
571 test_notification(hwnd,"status",MCI_NOTIFY_SUCCESSFUL);
574 err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
575 ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
576 trace("position while paused: %sms\n",buf);
578 ok(p1>=p2, "position not increasing: %u > %u\n", p2, p1);
580 err = mciSendString("stop mysound wait", NULL, 0, NULL);
581 ok(!err,"mci stop returned %s\n", dbg_mcierr(err));
584 err = mciSendString("info mysound file notify", buf, sizeof(buf), hwnd);
585 ok(!err,"mci info file returned %s\n", dbg_mcierr(err));
586 if(!err) { /* fully qualified name */
587 int len = strlen(buf);
588 todo_wine ok(len>2 && buf[1]==':',"Expected full pathname from info file: %s\n", buf);
589 ok(len>=12 && !strcmp(&buf[len-12],"tempfile.wav"), "info file returned: %s\n", buf);
591 test_notification(hwnd,"info file",MCI_NOTIFY_SUCCESSFUL);
594 err = mciSendString("status mysound mode", buf, sizeof(buf), hwnd);
595 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
596 ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
599 err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
600 ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
601 trace("position once stopped: %sms\n",buf);
603 /* An XP machine let the position increase slightly after pause. */
604 ok(p2>=p1 && p2<=p1+16,"position changed from %ums to %ums\n",p1,p2);
606 /* No Resume once stopped (waveaudio, sequencer and cdaudio differ). */
607 err = mciSendString("resume mysound wait", NULL, 0, NULL);
608 ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci resume wait returned %s\n", dbg_mcierr(err));
610 err = mciSendString("play mysound wait", NULL, 0, NULL);
611 ok(!err,"mci play wait returned %s\n", dbg_mcierr(err));
614 err = mciSendString("status mysound position", buf, sizeof(buf), hwnd);
615 ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
616 todo_wine ok(!strcmp(buf,"2000"), "mci status position: %s\n", buf);
618 err = mciSendString("seek mysound to start wait", NULL, 0, NULL);
619 ok(!err,"mci seek to start wait returned %s\n", dbg_mcierr(err));
621 err = mciSendString("play mysound to 1000 notify", NULL, 0, hwnd);
622 ok(!err,"mci play returned %s\n", dbg_mcierr(err));
624 /* Sleep(200); not needed with Wine any more. */
626 err = mciSendString("pause mysound notify", NULL, 0, NULL); /* notify no callback */
627 ok(!err,"mci pause notify returned %s\n", dbg_mcierr(err));
628 /* Supersede even though pause cannot notify given no callback */
629 test_notification(hwnd,"pause aborted play #1 notification",MCI_NOTIFY_SUPERSEDED);
630 test_notification(hwnd,"impossible pause notification",0);
632 err = mciSendString("cue mysound output notify", NULL, 0, hwnd);
633 ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci cue output while paused returned %s\n", dbg_mcierr(err));
634 test_notification(hwnd,"cue output notify #2",0);
636 err = mciSendString("resume mysound notify", NULL, 0, hwnd);
637 ok(!err,"mci resume notify returned %s\n", dbg_mcierr(err));
638 test_notification(hwnd, "resume notify", MCI_NOTIFY_SUCCESSFUL);
640 /* Seek or even Stop used to hang Wine<1.1.32 on MacOS. */
641 err = mciSendString("seek mysound to 0 wait", NULL, 0, NULL);
642 ok(!err,"mci seek to start returned %s\n", dbg_mcierr(err));
645 err = mciSendString("status mysound mode", buf, sizeof(buf), NULL);
646 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
647 if(!err) ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
649 err = mciSendString("seek mysound wait", NULL, 0, NULL);
650 ok(err==MCIERR_MISSING_PARAMETER,"mci seek to nowhere returned %s\n", dbg_mcierr(err));
652 /* cdaudio does not detect to start to end as error */
653 err = mciSendString("seek mysound to start to 0", NULL, 0, NULL);
654 ok(err==MCIERR_FLAGS_NOT_COMPATIBLE,"mci seek to start to 0 returned %s\n", dbg_mcierr(err));
656 err = mciSendString("PLAY mysound to 1000 notify", NULL, 0, hwnd);
657 ok(!err,"mci play to 1000 notify returned %s\n", dbg_mcierr(err));
659 /* Sleep(200); not needed with Wine any more. */
660 /* Give it 400ms and resume will appear to complete below. */
662 err = mciSendString("pause mysound wait", NULL, 0, NULL);
663 ok(!err,"mci pause wait returned %s\n", dbg_mcierr(err));
664 /* Unlike sequencer and cdaudio, waveaudio's pause does not abort. */
665 test_notification(hwnd,"pause aborted play #2 notification",0);
667 err = mciSendString("resume mysound wait", NULL, 0, NULL);
668 ok(!err,"mci resume wait returned %s\n", dbg_mcierr(err));
669 /* Resume is a short asynchronous call, something else is playing. */
671 err = mciSendString("status mysound mode", buf, sizeof(buf), NULL);
672 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
673 if(!err) ok(!strcmp(buf,"playing"), "mci status mode: %s\n", buf);
675 /* Note extra space before alias */
676 err = mciSendString("pause mysound wait", NULL, 0, NULL);
677 todo_wine ok(!err,"mci pause (space) wait returned %s\n", dbg_mcierr(err));
679 err = mciSendString("pause mysound wait", NULL, 0, NULL);
680 ok(!err,"mci pause wait returned %s\n", dbg_mcierr(err));
682 /* Better ask position only when paused, is it updated while playing? */
684 err = mciSendString("status mysound position", buf, sizeof(buf), NULL);
685 ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
686 /* TODO compare position < 900 */
687 ok(strcmp(buf,"1000"), "mci resume waited\n");
688 ok(strcmp(buf,"2000"), "mci resume played to end\n");
689 trace("position after resume: %sms\n",buf);
690 test_notification(hwnd,"play (aborted by pause/resume/pause)",0);
692 err = mciSendString("close mysound wait", NULL, 0, NULL);
693 ok(!err,"mci close wait returned %s\n", dbg_mcierr(err));
694 test_notification(hwnd,"play (aborted by close)",MCI_NOTIFY_ABORTED);
697 static void test_AutoOpenWAVE(HWND hwnd)
699 /* This test used(?) to cause intermittent crashes when Wine exits, after
700 * fixme:winmm:MMDRV_Exit Closing while ll-driver open
702 MCIERROR err, ok_snd;
703 char buf[512], path[300], command[330];
704 memset(buf, 0, sizeof(buf)); memset(path, 0, sizeof(path));
706 /* Do not crash on NULL buffer pointer */
707 err = mciSendString("sysinfo waveaudio quantity open", NULL, 0, NULL);
708 ok(err==MCIERR_PARAM_OVERFLOW,"mci sysinfo without buffer returned %s\n", dbg_mcierr(err));
710 err = mciSendString("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL);
711 ok(!err,"mci sysinfo waveaudio quantity open returned %s\n", dbg_mcierr(err));
712 if(!err) todo_wine ok(!strcmp(buf,"0"), "sysinfo quantity open expected 0, got: %s, some more tests will fail.\n", buf);
714 ok_snd = waveOutGetNumDevs() ? 0 : MCIERR_HARDWARE;
715 err = mciSendString("sound NoSuchSoundDefined wait", NULL, 0, NULL);
716 todo_wine ok(err==ok_snd,"mci sound NoSuchSoundDefined returned %s\n", dbg_mcierr(err));
718 err = mciSendString("sound SystemExclamation notify wait", NULL, 0, hwnd);
719 todo_wine ok(err==ok_snd,"mci sound SystemExclamation returned %s\n", dbg_mcierr(err));
720 test_notification(hwnd, "sound notify", err ? 0 : MCI_NOTIFY_SUCCESSFUL);
723 err = mciSendString("sysinfo waveaudio name 1 open", buf, sizeof(buf), NULL);
724 todo_wine ok(err==MCIERR_OUTOFRANGE,"sysinfo waveaudio name 1 returned %s\n", dbg_mcierr(err));
725 if(!err) trace("sysinfo dangling open alias: %s\n", buf);
727 err = mciSendString("play no-such-file-exists.wav notify", buf, sizeof(buf), NULL);
728 if(err==MCIERR_FILE_NOT_FOUND) { /* a Wine detector */
729 /* Unsupported auto-open leaves the file open, preventing clean-up */
730 skip("Skipping auto-open tests in Wine\n");
734 err = mciSendString("play tempfile.wav notify", buf, sizeof(buf), hwnd);
735 todo_wine ok(err==MCIERR_NOTIFY_ON_AUTO_OPEN,"mci auto-open play notify returned %s\n", dbg_mcierr(err));
737 if(err) /* FIXME: don't open twice yet, it confuses Wine. */
738 err = mciSendString("play tempfile.wav", buf, sizeof(buf), hwnd);
739 ok(err==ok_saved,"mci auto-open play returned %s\n", dbg_mcierr(err));
741 if(err==MCIERR_FILE_NOT_FOUND) {
742 skip("Cannot open tempfile.wav for auto-play, skipping\n");
747 err = mciSendString("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL);
748 ok(!err,"mci sysinfo waveaudio quantity after auto-open returned %s\n", dbg_mcierr(err));
749 if(!err) todo_wine ok(!strcmp(buf,"1"), "sysinfo quantity open expected 1, got: %s\n", buf);
752 err = mciSendString("sysinfo waveaudio name 1 open", buf, sizeof(buf), NULL);
753 todo_wine ok(!err,"mci sysinfo waveaudio name after auto-open returned %s\n", dbg_mcierr(err));
754 /* This is the alias, not necessarily a file name. */
755 if(!err) ok(!strcmp(buf,"tempfile.wav"), "sysinfo name 1 open: %s\n", buf);
757 /* Save the full pathname to the file. */
758 err = mciSendString("info tempfile.wav file", path, sizeof(path), NULL);
759 ok(!err,"mci info tempfile.wav file returned %s\n", dbg_mcierr(err));
760 if(err) strcpy(path,"tempfile.wav");
762 err = mciSendString("status tempfile.wav mode", NULL, 0, hwnd);
763 ok(!err,"mci status tempfile.wav mode without buffer returned %s\n", dbg_mcierr(err));
765 sprintf(command,"status \"%s\" mode",path);
766 err = mciSendString(command, buf, sizeof(buf), hwnd);
767 ok(!err,"mci status \"%s\" mode returned %s\n", path, dbg_mcierr(err));
770 err = mciSendString("status tempfile.wav mode", buf, sizeof(buf), hwnd);
771 ok(!err,"mci status tempfile.wav mode returned %s\n", dbg_mcierr(err));
772 if(!err) ok(!strcmp(buf,"playing"), "mci auto-open status mode, got: %s\n", buf);
774 err = mciSendString("open tempfile.wav", buf, sizeof(buf), NULL);
775 todo_wine ok(err==MCIERR_DEVICE_OPEN, "mci open from auto-open returned %s\n", dbg_mcierr(err));
777 /* w2k/xp and Wine differ. While the device is busy playing, it is
778 * regularly open and accessible via the filename: subsequent
779 * commands must not cause auto-open each. In Wine, a subsequent
780 * command with notify request may cause the initial play
781 * notification to be superseded, in turn causing MCI to close the
782 * device. I.e. MCI uses the auto-open notification for itself,
783 * that's why it's not available to the app. On w2k/xp,
784 * subsequent commands with notify requests are returned with
785 * MCIERR_NOTIFY_ON_AUTO_OPEN and thus don't abort the original
788 err = mciSendString("status tempfile.wav mode notify", buf, sizeof(buf), hwnd);
789 todo_wine ok(err==MCIERR_NOTIFY_ON_AUTO_OPEN, "mci status auto-open notify returned %s\n", dbg_mcierr(err));
791 trace("Wine style MCI auto-close upon notification\n");
793 /* "playing" because auto-close comes after the status call. */
794 todo_wine ok(!strcmp(buf,"playing"), "mci auto-open status mode notify, got: %s\n", buf);
795 /* fixme:winmm:MMDRV_Exit Closing while ll-driver open
796 * is explained by failure to auto-close a device. */
797 test_notification(hwnd,"status notify",MCI_NOTIFY_SUCCESSFUL);
798 /* MCI received NOTIFY_SUPERSEDED and auto-closed the device. */
800 test_notification(hwnd,"auto-open",0);
801 } else if(err==MCIERR_NOTIFY_ON_AUTO_OPEN) { /* MS style */
802 trace("MS style MCI auto-open forbids notification\n");
804 err = mciSendString("pause tempfile.wav", NULL, 0, hwnd);
805 ok(!err,"mci auto-still-open pause returned %s\n", dbg_mcierr(err));
807 err = mciSendString("status tempfile.wav mode", buf, sizeof(buf), hwnd);
808 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
809 if(!err) ok(!strcmp(buf,"paused"), "mci auto-open status mode, got: %s\n", buf);
812 err = mciSendString("stop tempfile.wav", NULL, 0, hwnd);
813 ok(!err,"mci auto-still-open stop returned %s\n", dbg_mcierr(err));
814 Sleep(16); /* makes sysinfo quantity open below succeed */
817 err = mciSendString("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL);
818 ok(!err,"mci sysinfo waveaudio quantity open after close returned %s\n", dbg_mcierr(err));
819 if(!err) todo_wine ok(!strcmp(buf,"0"), "sysinfo quantity open expected 0 after auto-close, got: %s\n", buf);
821 /* w95-WinME (not w2k/XP) switch to C:\ after auto-playing once. Prevent
822 * MCIERR_FILE_NOT_FOUND by using the full path name from the Info file command.
824 sprintf(command,"status \"%s\" mode wait",path);
825 err = mciSendString(command, buf, sizeof(buf), hwnd);
826 ok(!err,"mci re-auto-open status mode returned %s\n", dbg_mcierr(err));
827 if(!err) ok(!strcmp(buf,"stopped"), "mci re-auto-open status mode, got: %s\n", buf);
829 err = mciSendString("capability waveaudio device type", buf, sizeof(buf), hwnd);
830 ok(!err,"mci capability device type returned %s\n", dbg_mcierr(err));
831 if(!err) ok(!strcmp(buf,"waveaudio"), "mci capability device type response: %s\n", buf);
833 /* waveaudio forbids Pause without Play. */
834 sprintf(command,"pause \"%s\"",path);
835 err = mciSendString(command, NULL, 0, hwnd);
836 ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci auto-open pause returned %s\n", dbg_mcierr(err));
843 hwnd = CreateWindowExA(0, "static", "winmm test", WS_POPUP, 0,0,100,100,
845 test_openCloseWAVE(hwnd);
846 test_recordWAVE(hwnd);
848 test_asyncWAVE(hwnd);
849 test_AutoOpenWAVE(hwnd);
850 /* Win9X hangs when exiting with something still open. */
851 err = mciSendString("close all", NULL, 0, hwnd);
852 todo_wine ok(!err,"final close all returned %s\n", dbg_mcierr(err));
853 ok(DeleteFile("tempfile.wav")||ok_saved,"Delete tempfile.wav (cause auto-open?)\n");