winmm/tests: Add MCI_DGV_WINDOW_TEXT tests.
[wine.git] / dlls / winmm / tests / mci.c
blobb2f3c2c8d45ded38c55b41bbf89bae63ffe28916
1 /*
2 * Test winmm mci
4 * Copyright 2006 Jan Zerebecki
5 * 2009 Jörg Höhle
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdio.h>
23 #include "windows.h"
24 #include "mmsystem.h"
25 #include "mmreg.h"
26 #include "digitalv.h"
27 #include "wine/test.h"
29 /* The tests use the MCI's own save capability to create the tempfile.wav to play.
30 * To use a pre-existing file, write-protect it. */
31 static MCIERROR ok_saved = MCIERR_FILE_NOT_FOUND;
33 typedef union {
34 MCI_INFO_PARMSA info;
35 MCI_STATUS_PARMS status;
36 MCI_WAVE_SET_PARMS set;
37 MCI_WAVE_OPEN_PARMSA open;
38 MCI_GETDEVCAPS_PARMS caps;
39 MCI_SYSINFO_PARMSA sys;
40 MCI_SEEK_PARMS seek;
41 MCI_DGV_OPEN_PARMSW dgv_open;
42 MCI_DGV_PUT_PARMS put;
43 MCI_DGV_WHERE_PARMS where;
44 MCI_DGV_WINDOW_PARMSW win;
45 MCI_GENERIC_PARMS gen;
46 } MCI_PARMS_UNION;
48 const char* dbg_mcierr(MCIERROR err)
50 switch (err) {
51 case 0: return "0=NOERROR";
52 #define X(label) case label: return #label ;
53 X(MCIERR_INVALID_DEVICE_ID)
54 X(MCIERR_UNRECOGNIZED_KEYWORD)
55 X(MCIERR_UNRECOGNIZED_COMMAND)
56 X(MCIERR_HARDWARE)
57 X(MCIERR_INVALID_DEVICE_NAME)
58 X(MCIERR_OUT_OF_MEMORY)
59 X(MCIERR_DEVICE_OPEN)
60 X(MCIERR_CANNOT_LOAD_DRIVER)
61 X(MCIERR_MISSING_COMMAND_STRING)
62 X(MCIERR_PARAM_OVERFLOW)
63 X(MCIERR_MISSING_STRING_ARGUMENT)
64 X(MCIERR_BAD_INTEGER)
65 X(MCIERR_PARSER_INTERNAL)
66 X(MCIERR_DRIVER_INTERNAL)
67 X(MCIERR_MISSING_PARAMETER)
68 X(MCIERR_UNSUPPORTED_FUNCTION)
69 X(MCIERR_FILE_NOT_FOUND)
70 X(MCIERR_DEVICE_NOT_READY)
71 X(MCIERR_INTERNAL)
72 X(MCIERR_DRIVER)
73 X(MCIERR_CANNOT_USE_ALL)
74 X(MCIERR_MULTIPLE)
75 X(MCIERR_EXTENSION_NOT_FOUND)
76 X(MCIERR_OUTOFRANGE)
77 X(MCIERR_FLAGS_NOT_COMPATIBLE)
78 X(MCIERR_FILE_NOT_SAVED)
79 X(MCIERR_DEVICE_TYPE_REQUIRED)
80 X(MCIERR_DEVICE_LOCKED)
81 X(MCIERR_DUPLICATE_ALIAS)
82 X(MCIERR_BAD_CONSTANT)
83 X(MCIERR_MUST_USE_SHAREABLE)
84 X(MCIERR_MISSING_DEVICE_NAME)
85 X(MCIERR_BAD_TIME_FORMAT)
86 X(MCIERR_NO_CLOSING_QUOTE)
87 X(MCIERR_DUPLICATE_FLAGS)
88 X(MCIERR_INVALID_FILE)
89 X(MCIERR_NULL_PARAMETER_BLOCK)
90 X(MCIERR_UNNAMED_RESOURCE)
91 X(MCIERR_NEW_REQUIRES_ALIAS)
92 X(MCIERR_NOTIFY_ON_AUTO_OPEN)
93 X(MCIERR_NO_ELEMENT_ALLOWED)
94 X(MCIERR_NONAPPLICABLE_FUNCTION)
95 X(MCIERR_ILLEGAL_FOR_AUTO_OPEN)
96 X(MCIERR_FILENAME_REQUIRED)
97 X(MCIERR_EXTRA_CHARACTERS)
98 X(MCIERR_DEVICE_NOT_INSTALLED)
99 X(MCIERR_GET_CD)
100 X(MCIERR_SET_CD)
101 X(MCIERR_SET_DRIVE)
102 X(MCIERR_DEVICE_LENGTH)
103 X(MCIERR_DEVICE_ORD_LENGTH)
104 X(MCIERR_NO_INTEGER)
105 X(MCIERR_WAVE_OUTPUTSINUSE)
106 X(MCIERR_WAVE_SETOUTPUTINUSE)
107 X(MCIERR_WAVE_INPUTSINUSE)
108 X(MCIERR_WAVE_SETINPUTINUSE)
109 X(MCIERR_WAVE_OUTPUTUNSPECIFIED)
110 X(MCIERR_WAVE_INPUTUNSPECIFIED)
111 X(MCIERR_WAVE_OUTPUTSUNSUITABLE)
112 X(MCIERR_WAVE_SETOUTPUTUNSUITABLE)
113 X(MCIERR_WAVE_INPUTSUNSUITABLE)
114 X(MCIERR_WAVE_SETINPUTUNSUITABLE)
115 X(MCIERR_SEQ_DIV_INCOMPATIBLE)
116 X(MCIERR_SEQ_PORT_INUSE)
117 X(MCIERR_SEQ_PORT_NONEXISTENT)
118 X(MCIERR_SEQ_PORT_MAPNODEVICE)
119 X(MCIERR_SEQ_PORT_MISCERROR)
120 X(MCIERR_SEQ_TIMER)
121 X(MCIERR_SEQ_PORTUNSPECIFIED)
122 X(MCIERR_SEQ_NOMIDIPRESENT)
123 X(MCIERR_NO_WINDOW)
124 X(MCIERR_CREATEWINDOW)
125 X(MCIERR_FILE_READ)
126 X(MCIERR_FILE_WRITE)
127 X(MCIERR_NO_IDENTITY)
128 #undef X
129 default: {
130 static char name[20]; /* Not to be called twice in a parameter list! */
131 sprintf(name, "MMSYSERR %lu", err);
132 return name;
137 static BOOL spurious_message(LPMSG msg)
139 /* WM_DEVICECHANGE 0x0219 appears randomly */
140 if(msg->message != MM_MCINOTIFY) {
141 trace("skipping spurious message %04x\n",msg->message);
142 return TRUE;
144 return FALSE;
147 static WCHAR *load_resource(const WCHAR *name)
149 static WCHAR pathW[MAX_PATH];
150 DWORD written;
151 HANDLE file;
152 HRSRC res;
153 void *ptr;
155 GetTempPathW(ARRAY_SIZE(pathW), pathW);
156 wcscat(pathW, name);
158 file = CreateFileW(pathW, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
159 ok(file != INVALID_HANDLE_VALUE, "Failed to create file %s, error %lu.\n",
160 wine_dbgstr_w(pathW), GetLastError());
162 res = FindResourceW(NULL, name, (LPCWSTR)RT_RCDATA);
163 ok(!!res, "Failed to load resource, error %lu.\n", GetLastError());
164 ptr = LockResource(LoadResource(GetModuleHandleA(NULL), res));
165 WriteFile(file, ptr, SizeofResource( GetModuleHandleA(NULL), res), &written, NULL);
166 ok(written == SizeofResource(GetModuleHandleA(NULL), res), "Failed to write resource.\n");
167 CloseHandle(file);
169 return pathW;
172 /* A single ok() in each code path allows us to prefix this with todo_wine */
173 #define test_notification(hwnd, command, type) test_notification_dbg(hwnd, command, type, __LINE__)
174 static void test_notification_dbg(HWND hwnd, const char* command, WPARAM type, int line)
175 { /* Use type 0 as meaning no message */
176 MSG msg;
177 BOOL seen;
178 do { seen = PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE); }
179 while(seen && spurious_message(&msg));
180 if(type && !seen) {
181 /* We observe transient delayed notification, mostly on native.
182 * Notification is not always present right when mciSend returns. */
183 trace_(__FILE__,line)("Waiting for delayed notification from %s\n", command);
184 MsgWaitForMultipleObjects(0, NULL, FALSE, 3000, QS_POSTMESSAGE);
185 seen = PeekMessageA(&msg, hwnd, MM_MCINOTIFY, MM_MCINOTIFY, PM_REMOVE);
187 if(!seen)
188 ok_(__FILE__,line)(type==0, "Expect message %04Ix from %s\n", type, command);
189 else if(msg.hwnd != hwnd)
190 ok_(__FILE__,line)(msg.hwnd == hwnd, "Didn't get the handle to our test window\n");
191 else if(msg.message != MM_MCINOTIFY)
192 ok_(__FILE__,line)(msg.message == MM_MCINOTIFY, "got %04x instead of MM_MCINOTIFY from command %s\n", msg.message, command);
193 else ok_(__FILE__,line)(msg.wParam == type, "got %04Ix instead of MCI_NOTIFY_xyz %04Ix from command %s\n", msg.wParam, type, command);
196 static void test_mciParser(HWND hwnd)
198 MCIERROR err;
199 MCIDEVICEID wDeviceID;
200 MCI_PARMS_UNION parm;
201 char buf[1024];
202 memset(buf, 0, sizeof(buf));
203 test_notification(hwnd, "-prior to parser test-", 0);
205 /* Get a handle on an MCI device, works even without sound. */
206 parm.open.lpstrDeviceType = "waveaudio";
207 parm.open.lpstrElementName = ""; /* "new" at the command level */
208 parm.open.lpstrAlias = "x"; /* to enable mciSendStringA */
209 parm.open.dwCallback = (DWORD_PTR)hwnd;
210 err = mciSendCommandA(0, MCI_OPEN,
211 MCI_OPEN_ELEMENT | MCI_OPEN_TYPE | MCI_OPEN_ALIAS | MCI_NOTIFY, (DWORD_PTR)&parm);
212 ok(!err,"mciCommand open new type waveaudio alias x notify: %s\n", dbg_mcierr(err));
213 wDeviceID = parm.open.wDeviceID;
214 ok(!strcmp(parm.open.lpstrDeviceType,"waveaudio"), "open modified device type\n");
216 test_notification(hwnd, "MCI_OPEN", MCI_NOTIFY_SUCCESSFUL);
217 test_notification(hwnd, "MCI_OPEN no #2", 0);
219 err = mciSendStringA("open avivideo alias a", buf, sizeof(buf), hwnd);
220 ok(!err,"open another: %s\n", dbg_mcierr(err));
222 buf[0]='z';
223 err = mciSendStringA("", buf, sizeof(buf), NULL);
224 ok(err==MCIERR_MISSING_COMMAND_STRING,"empty string: %s\n", dbg_mcierr(err));
225 ok(!buf[0], "error buffer %s\n", buf);
227 buf[0]='d';
228 err = mciSendStringA("open", buf, sizeof(buf), NULL);
229 ok(err==MCIERR_MISSING_DEVICE_NAME,"open void: %s\n", dbg_mcierr(err));
230 ok(!buf[0], "open error buffer %s\n", buf);
232 err = mciSendStringA("open notify", buf, sizeof(buf), NULL);
233 todo_wine ok(err==MCIERR_INVALID_DEVICE_NAME,"open notify: %s\n", dbg_mcierr(err));
235 err = mciSendStringA("open new", buf, sizeof(buf), NULL);
236 todo_wine ok(err==MCIERR_NEW_REQUIRES_ALIAS,"open new: %s\n", dbg_mcierr(err));
238 err = mciSendStringA("open new type waveaudio alias r shareable shareable", buf, sizeof(buf), NULL);
239 todo_wine ok(err==MCIERR_DUPLICATE_FLAGS,"open new: %s\n", dbg_mcierr(err));
240 if(!err) mciSendStringA("close r", NULL, 0, NULL);
242 err = mciSendStringA("status x position wait wait", buf, sizeof(buf), NULL);
243 todo_wine ok(err==MCIERR_DUPLICATE_FLAGS,"status wait wait: %s\n", dbg_mcierr(err));
245 err = mciSendStringA("status x length length", buf, sizeof(buf), NULL);
246 todo_wine ok(err==MCIERR_FLAGS_NOT_COMPATIBLE,"status 2xlength: %s\n", dbg_mcierr(err));
248 err = mciSendStringA("status x length position", buf, sizeof(buf), NULL);
249 todo_wine ok(err==MCIERR_FLAGS_NOT_COMPATIBLE,"status length+position: %s\n", dbg_mcierr(err));
251 buf[0]='I';
252 err = mciSendStringA("set x time format milliseconds time format ms", buf, sizeof(buf), NULL);
253 todo_wine ok(err==MCIERR_FLAGS_NOT_COMPATIBLE,"status length+position: %s\n", dbg_mcierr(err));
254 ok(!buf[0], "set error buffer %s\n", buf);
256 /* device's response, not a parser test */
257 err = mciSendStringA("status x", buf, sizeof(buf), NULL);
258 ok(err==MCIERR_MISSING_PARAMETER,"status waveaudio nokeyword: %s\n", dbg_mcierr(err));
260 buf[0]='G';
261 err = mciSendStringA("status a", buf, sizeof(buf), NULL);
262 todo_wine ok(err==MCIERR_UNSUPPORTED_FUNCTION,"status avivideo nokeyword: %s\n", dbg_mcierr(err));
263 ok(!buf[0], "status error buffer %s\n", buf);
265 err = mciSendStringA("status x track", buf, sizeof(buf), NULL);
266 ok(err==MCIERR_BAD_INTEGER,"status waveaudio no track: %s\n", dbg_mcierr(err));
268 err = mciSendStringA("status x track 3", buf, sizeof(buf), NULL);
269 ok(err==MCIERR_MISSING_PARAMETER,"status waveaudio track 3: %s\n", dbg_mcierr(err));
271 err = mciSendStringA("status x 2 track 3", buf, sizeof(buf), NULL);
272 todo_wine ok(err==MCIERR_OUTOFRANGE,"status 2(position) track 3: %s\n", dbg_mcierr(err));
274 err = mciSendStringA("status x 0x4", buf, sizeof(buf), NULL);
275 todo_wine ok(err==MCIERR_BAD_CONSTANT, "status 0x4: %s\n", dbg_mcierr(err));
277 err = mciSendStringA("status x 4", buf, sizeof(buf), hwnd);
278 ok(!err,"status 4(mode): %s\n", dbg_mcierr(err));
279 if(!err)ok(!strcmp(buf,"stopped"), "status 4(mode), got: %s\n", buf);
281 err = mciSendStringA("status x 4 notify", buf, sizeof(buf), hwnd);
282 todo_wine ok(!err,"status 4(mode) notify: %s\n", dbg_mcierr(err));
283 if(!err)ok(!strcmp(buf,"stopped"), "status 4(mode), got: %s\n", buf);
284 test_notification(hwnd, "status 4 notify", err ? 0 : MCI_NOTIFY_SUCCESSFUL);
286 err = mciSendStringA("set x milliseconds", buf, sizeof(buf), hwnd);
287 todo_wine ok(err==MCIERR_UNRECOGNIZED_KEYWORD,"set milliseconds: %s\n", dbg_mcierr(err));
289 err = mciSendStringA("set x milliseconds ms", buf, sizeof(buf), hwnd);
290 todo_wine ok(err==MCIERR_UNRECOGNIZED_KEYWORD,"set milliseconds ms: %s\n", dbg_mcierr(err));
292 err = mciSendStringA("capability x can save", buf, sizeof(buf), hwnd);
293 todo_wine ok(!err,"capability can (space) save: %s\n", dbg_mcierr(err));
295 err = mciSendStringA("status x nsa", buf, sizeof(buf), hwnd);
296 todo_wine ok(err==MCIERR_BAD_CONSTANT,"status nsa: %s\n", dbg_mcierr(err));
298 err = mciSendStringA("seek x to 0:0:0:0:0", buf, sizeof(buf), NULL);
299 ok(err==MCIERR_BAD_INTEGER,"seek to 0:0:0:0:0 returned %s\n", dbg_mcierr(err));
301 err = mciSendStringA("seek x to 0:0:0:0:", buf, sizeof(buf), NULL);
302 ok(err==MCIERR_BAD_INTEGER,"seek to 0:0:0:0: returned %s\n", dbg_mcierr(err));
304 err = mciSendStringA("seek x to :0:0:0:0", buf, sizeof(buf), NULL);
305 ok(err==MCIERR_BAD_INTEGER,"seek to :0:0:0:0 returned %s\n", dbg_mcierr(err));
307 err = mciSendStringA("seek x to 256:0:0:0", buf, sizeof(buf), NULL);
308 ok(err==MCIERR_BAD_INTEGER,"seek to 256:0:0:0 returned %s\n", dbg_mcierr(err));
310 err = mciSendStringA("seek x to 0:256", buf, sizeof(buf), NULL);
311 ok(err==MCIERR_BAD_INTEGER,"seek to 0:256 returned %s\n", dbg_mcierr(err));
313 err = mciSendStringA("status all time format", buf, sizeof(buf), hwnd);
314 ok(err==MCIERR_CANNOT_USE_ALL,"status all: %s\n", dbg_mcierr(err));
316 err = mciSendStringA("cue all", buf, sizeof(buf), NULL);
317 ok(err==MCIERR_UNRECOGNIZED_COMMAND,"cue all: %s\n", dbg_mcierr(err));
319 err = mciSendStringA("open all", buf, sizeof(buf), NULL);
320 todo_wine ok(err==MCIERR_CANNOT_USE_ALL,"open all: %s\n", dbg_mcierr(err));
322 /* avivideo is not a known MCI_DEVTYPE resource name */
323 err = mciSendStringA("sysinfo avivideo quantity", buf, sizeof(buf), hwnd);
324 ok(err==MCIERR_DEVICE_TYPE_REQUIRED,"sysinfo sequencer quantity: %s\n", dbg_mcierr(err));
326 err = mciSendStringA("sysinfo digitalvideo quantity", buf, sizeof(buf), hwnd);
327 ok(!err,"sysinfo digitalvideo quantity: %s\n", dbg_mcierr(err));
328 if(!err) ok(!strcmp(buf,"0"), "sysinfo digitalvideo quantity returned %s\n", buf);
330 /* quantity 0 yet open 1 (via type "avivideo"), fun */
331 err = mciSendStringA("sysinfo digitalvideo quantity open", buf, sizeof(buf), hwnd);
332 ok(!err,"sysinfo digitalvideo quantity open: %s\n", dbg_mcierr(err));
333 if(!err) ok(!strcmp(buf,"1"), "sysinfo digitalvideo quantity open returned %s\n", buf);
335 err = mciSendStringA("put a window at 0 0", buf, sizeof(buf), NULL);
336 ok(err==MCIERR_BAD_INTEGER,"put incomplete rect: %s\n", dbg_mcierr(err));
338 /*w9X-w2k report code from device last opened, newer versions compare them all
339 * and return the one error code or MCIERR_MULTIPLE if they differ. */
340 err = mciSendStringA("pause all", buf, sizeof(buf), NULL);
341 todo_wine ok(err==MCIERR_MULTIPLE || broken(err==MCIERR_NONAPPLICABLE_FUNCTION),"pause all: %s\n", dbg_mcierr(err));
342 ok(!buf[0], "pause error buffer %s\n", buf);
344 /* MCI_STATUS' dwReturn is a DWORD_PTR, others' a plain DWORD. */
345 parm.status.dwItem = MCI_STATUS_TIME_FORMAT;
346 parm.status.dwReturn = 0xFEEDABAD;
347 err = mciSendCommandA(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
348 ok(!err,"mciCommand status time format: %s\n", dbg_mcierr(err));
349 if(!err) ok(MCI_FORMAT_MILLISECONDS==parm.status.dwReturn,"status time format: %Id\n",parm.status.dwReturn);
351 parm.status.dwItem = MCI_STATUS_MODE;
352 parm.status.dwReturn = 0xFEEDABAD;
353 err = mciSendCommandA(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
354 ok(!err,"mciCommand status mode: %s\n", dbg_mcierr(err));
355 if(!err) ok(MCI_MODE_STOP==parm.status.dwReturn,"STATUS mode: %Id\n",parm.status.dwReturn);
357 err = mciSendStringA("status x mode", buf, sizeof(buf), hwnd);
358 ok(!err,"status mode: %s\n", dbg_mcierr(err));
359 if(!err) ok(!strcmp(buf, "stopped"), "status mode is %s\n", buf);
361 parm.caps.dwItem = MCI_GETDEVCAPS_USES_FILES;
362 parm.caps.dwReturn = 0xFEEDABAD;
363 err = mciSendCommandA(wDeviceID, MCI_GETDEVCAPS, MCI_GETDEVCAPS_ITEM, (DWORD_PTR)&parm);
364 ok(!err,"mciCommand getdevcaps files: %s\n", dbg_mcierr(err));
365 if(!err) ok(1==parm.caps.dwReturn,"getdevcaps files: %ld\n",parm.caps.dwReturn);
367 parm.caps.dwItem = MCI_GETDEVCAPS_HAS_VIDEO;
368 parm.caps.dwReturn = 0xFEEDABAD;
369 err = mciSendCommandA(wDeviceID, MCI_GETDEVCAPS, MCI_GETDEVCAPS_ITEM, (DWORD_PTR)&parm);
370 ok(!err,"mciCommand getdevcaps video: %s\n", dbg_mcierr(err));
371 if(!err) ok(0==parm.caps.dwReturn,"getdevcaps video: %ld\n",parm.caps.dwReturn);
373 parm.caps.dwItem = MCI_GETDEVCAPS_DEVICE_TYPE;
374 parm.caps.dwReturn = 0xFEEDABAD;
375 err = mciSendCommandA(wDeviceID, MCI_GETDEVCAPS, MCI_GETDEVCAPS_ITEM, (DWORD_PTR)&parm);
376 ok(!err,"mciCommand getdevcaps video: %s\n", dbg_mcierr(err));
377 if(!err) ok(MCI_DEVTYPE_WAVEFORM_AUDIO==parm.caps.dwReturn,"getdevcaps device type: %ld\n",parm.caps.dwReturn);
379 err = mciSendStringA("capability x uses files", buf, sizeof(buf), hwnd);
380 ok(!err,"capability files: %s\n", dbg_mcierr(err));
381 if(!err) ok(!strcmp(buf, "true"), "capability files is %s\n", buf);
383 err = mciSendStringA("capability x has video", buf, sizeof(buf), hwnd);
384 ok(!err,"capability video: %s\n", dbg_mcierr(err));
385 if(!err) ok(!strcmp(buf, "false"), "capability video is %s\n", buf);
387 err = mciSendStringA("capability x device type", buf, sizeof(buf), hwnd);
388 ok(!err,"capability device type: %s\n", dbg_mcierr(err));
389 if(!err) ok(!strcmp(buf, "waveaudio"), "capability device type is %s\n", buf);
391 err = mciSendStringA("info a version", buf, sizeof(buf), hwnd);
392 ok(!err,"info version: %s\n", dbg_mcierr(err));
393 if(!err) ok(!strcmp(buf, "1.1"), "info version is %s\n", buf);
395 err = mciSendCommandA(wDeviceID, MCI_CLOSE, 0, 0);
396 ok(!err,"mciCommand close returned %s\n", dbg_mcierr(err));
398 err = mciSendStringA("close a", buf, sizeof(buf), hwnd);
399 ok(!err,"close avi: %s\n", dbg_mcierr(err));
401 test_notification(hwnd, "-end of 1st set-", 0);
404 static void test_openCloseWAVE(HWND hwnd)
406 MCIERROR err;
407 MCI_PARMS_UNION parm;
408 const char command_open[] = "open new type waveaudio alias mysound notify";
409 const char command_close_my[] = "close mysound notify";
410 const char command_close_all[] = "close all notify";
411 const char command_sysinfo[] = "sysinfo waveaudio quantity open";
412 char buf[1024];
413 DWORD intbuf[3] = { 0xDEADF00D, 99, 0xABADCAFE };
414 memset(buf, 0, sizeof(buf));
415 test_notification(hwnd, "-prior to any command-", 0);
417 /* Avoid Sysinfo quantity with notify because Win9x and newer differ. */
418 err = mciSendStringA("sysinfo all quantity", buf, sizeof(buf), hwnd);
419 ok(!err,"mci sysinfo all quantity returned %s\n", dbg_mcierr(err));
420 if(!err) trace("[MCI] with %s drivers\n", buf);
422 parm.sys.lpstrReturn = (LPSTR)&intbuf[1];
423 parm.sys.dwRetSize = sizeof(DWORD);
424 parm.sys.wDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; /* ignored */
425 err = mciSendCommandA(MCI_ALL_DEVICE_ID, MCI_SYSINFO, MCI_SYSINFO_QUANTITY | MCI_WAIT,
426 (DWORD_PTR)&parm);
427 ok(!err, "mciCommand sysinfo all quantity returned %s\n", dbg_mcierr(err));
428 if(!err) ok(atoi(buf)==intbuf[1],"sysinfo all quantity string and command differ\n");
430 parm.sys.dwRetSize = sizeof(DWORD)-1;
431 err = mciSendCommandA(MCI_ALL_DEVICE_ID, MCI_SYSINFO, MCI_SYSINFO_QUANTITY, (DWORD_PTR)&parm);
432 ok(err == MCIERR_PARAM_OVERFLOW || broken(!err/* Win9x */),
433 "mciCommand sysinfo with too small buffer returned %s\n", dbg_mcierr(err));
435 err = mciSendStringA("open new type waveaudio alias r shareable", buf, sizeof(buf), NULL);
436 ok(err==MCIERR_UNSUPPORTED_FUNCTION,"mci open new shareable returned %s\n", dbg_mcierr(err));
437 if(!err) {
438 err = mciSendStringA("close r", NULL, 0, NULL);
439 ok(!err,"mci close shareable returned %s\n", dbg_mcierr(err));
442 err = mciGetDeviceIDA("waveaudio");
443 ok(!err, "mciGetDeviceIDA waveaudio returned %lu, expected 0\n", err);
445 err = mciSendStringA(command_open, buf, sizeof(buf), hwnd);
446 ok(!err,"mci %s returned %s\n", command_open, dbg_mcierr(err));
447 ok(!strcmp(buf,"1"), "mci open deviceId: %s, expected 1\n", buf);
448 /* Wine<=1.1.33 used to ignore anything past alias XY */
449 test_notification(hwnd,"open new alias notify",MCI_NOTIFY_SUCCESSFUL);
451 err = mciSendStringA("status mysound time format", buf, sizeof(buf), hwnd);
452 ok(!err,"mci status time format returned %s\n", dbg_mcierr(err));
453 if(!err) {
454 if (PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) == LANG_ENGLISH)
455 ok(!strcmp(buf,"milliseconds"), "mci status time format: %s\n", buf);
456 else trace("locale-dependent time format: %s (ms)\n", buf);
459 memset(buf, 0, sizeof(buf));
460 parm.sys.dwNumber = 1;
461 parm.sys.wDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; /* ignored */
462 parm.sys.lpstrReturn = buf;
463 parm.sys.dwRetSize = sizeof(buf);
464 parm.sys.dwCallback = (DWORD_PTR)hwnd;
465 err = mciSendCommandA(MCI_ALL_DEVICE_ID, MCI_SYSINFO,
466 MCI_SYSINFO_NAME | MCI_SYSINFO_OPEN | MCI_NOTIFY, (DWORD_PTR)&parm);
467 ok(!err,"mciCommand MCI_SYSINFO all name 1 open notify: %s\n", dbg_mcierr(err));
468 if(!err) ok(!strcmp(buf,"mysound"), "sysinfo name returned %s\n", buf);
469 test_notification(hwnd, "SYSINFO name notify\n", MCI_NOTIFY_SUCCESSFUL);
471 memset(buf, 0, sizeof(buf));
472 parm.sys.dwNumber = 1;
473 parm.sys.wDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; /* ignored */
474 parm.sys.lpstrReturn = buf;
475 parm.sys.dwRetSize = 8; /* mysound\0 */
476 err = mciSendCommandA(MCI_ALL_DEVICE_ID, MCI_SYSINFO, MCI_SYSINFO_NAME | MCI_SYSINFO_OPEN,
477 (DWORD_PTR)&parm);
478 ok(!err,"mciCommand MCI_SYSINFO all name 1 open buffer[8]: %s\n", dbg_mcierr(err));
479 if(!err) ok(!strcmp(buf,"mysound"), "sysinfo name returned %s\n", buf);
481 memset(buf, 0, sizeof(buf));
482 /* dwRetSize counts characters, not bytes, despite what MSDN says. */
483 parm.sys.dwNumber = 1;
484 parm.sys.wDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; /* ignored */
485 parm.sys.lpstrReturn = buf;
486 parm.sys.dwRetSize = 8; /* mysound\0 */
487 /* MCI_..._PARMSA and PARMSW share the same layout, use one for both tests. */
488 err = mciSendCommandW(MCI_ALL_DEVICE_ID, MCI_SYSINFO, MCI_SYSINFO_NAME | MCI_SYSINFO_OPEN, (DWORD_PTR)&parm);
489 ok(!err || broken(err==MMSYSERR_NOTSUPPORTED/* Win9x */), "mciCommandW MCI_SYSINFO all name 1 open buffer[8]: %s\n", dbg_mcierr(err));
490 if (!err) ok(!lstrcmpW((LPWSTR)buf, L"mysound"), "sysinfo name 1 open contents\n");
492 memset(buf, 0, sizeof(buf));
493 buf[0] = 'Y';
494 parm.sys.dwNumber = 1;
495 parm.sys.wDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; /* ignored */
496 parm.sys.lpstrReturn = buf;
497 parm.sys.dwRetSize = 7; /* too short for mysound\0 */
498 err = mciSendCommandW(MCI_ALL_DEVICE_ID, MCI_SYSINFO, MCI_SYSINFO_NAME | MCI_SYSINFO_OPEN, (DWORD_PTR)&parm);
499 ok(err==MCIERR_PARAM_OVERFLOW || broken(err==MMSYSERR_NOTSUPPORTED/* Win9x */), "mciCommandW MCI_SYSINFO all name 1 open too small: %s\n", dbg_mcierr(err));
500 ok(!strcmp(buf,"Y"), "output buffer %s\n", buf);
502 /* Win9x overwrites the tiny buffer and returns success, newer versions signal overflow. */
503 memset(buf, 0, sizeof(buf));
504 buf[0] = 'Y';
505 parm.sys.dwNumber = 1;
506 parm.sys.wDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; /* ignored */
507 parm.sys.lpstrReturn = buf;
508 parm.sys.dwRetSize = 2; /* too short for mysound\0 */
509 err = mciSendCommandA(MCI_ALL_DEVICE_ID, MCI_SYSINFO, MCI_SYSINFO_NAME | MCI_SYSINFO_OPEN,
510 (DWORD_PTR)&parm);
511 ok(err==MCIERR_PARAM_OVERFLOW || broken(!err /* Win9x */),"mciCommand MCI_SYSINFO all name 1 open too small: %s\n", dbg_mcierr(err));
512 ok(!strcmp(buf, err ? "Y" : "mysound"), "sysinfo short name returned %s\n", buf);
514 err = mciSendStringA("sysinfo mysound quantity open", buf, sizeof(buf), hwnd);
515 ok(err==MCIERR_DEVICE_TYPE_REQUIRED,"sysinfo alias quantity: %s\n", dbg_mcierr(err));
517 err = mciSendStringA("sysinfo nosuchalias quantity open", buf, sizeof(buf), hwnd);
518 ok(err==MCIERR_DEVICE_TYPE_REQUIRED,"sysinfo unknown quantity open: %s\n", dbg_mcierr(err));
520 err = mciSendStringA("sysinfo all installname", buf, sizeof(buf), hwnd);
521 ok(err==MCIERR_CANNOT_USE_ALL,"sysinfo all installname: %s\n", dbg_mcierr(err));
523 buf[0] = 'M'; buf[1] = 0;
524 parm.sys.lpstrReturn = buf;
525 parm.sys.dwRetSize = sizeof(buf);
526 err = mciSendCommandA(MCI_ALL_DEVICE_ID, MCI_SYSINFO, MCI_SYSINFO_INSTALLNAME, (DWORD_PTR)&parm);
527 ok(err==MCIERR_CANNOT_USE_ALL,"mciCommand MCI_SYSINFO all installname: %s\n", dbg_mcierr(err));
528 ok(!strcmp(buf,"M"), "output buffer %s\n", buf);
530 err = mciSendStringA("sysinfo nodev installname", buf, sizeof(buf), hwnd);
531 ok(err==MCIERR_INVALID_DEVICE_NAME,"sysinfo nodev installname: %s\n", dbg_mcierr(err));
532 ok(!buf[0], "sysinfo error buffer %s\n", buf);
534 buf[0] = 'K';
535 parm.sys.lpstrReturn = buf;
536 parm.sys.dwRetSize = sizeof(buf);
537 err = mciSendCommandW(24000, MCI_SYSINFO, MCI_SYSINFO_INSTALLNAME, (DWORD_PTR)&parm);
538 ok(err==MCIERR_INVALID_DEVICE_NAME || broken(err==MMSYSERR_NOTSUPPORTED/* Win9x */), "mciCommand MCI_SYSINFO nodev installname: %s\n", dbg_mcierr(err));
539 ok(!strcmp(buf,"K"), "output buffer %s\n", buf);
541 buf[0] = 0; buf[1] = 'A'; buf[2] = 'j'; buf[3] = 0;
542 parm.info.lpstrReturn = buf;
543 parm.info.dwRetSize = 2;
544 err = mciSendCommandA(1, MCI_INFO, MCI_INFO_PRODUCT, (DWORD_PTR)&parm);
545 ok(!err, "mciCommand MCI_INFO product: %s\n", dbg_mcierr(err));
546 ok(buf[0] /* && !buf[1] */ && (buf[2] == 'j' || broken(!buf[2])), "info product output buffer %s\n", buf);
547 /* Producing non-ASCII multi-byte output, native forgets to zero-terminate a too small buffer
548 * with SendStringA, while SendStringW works correctly (jap. and chin. locale): ignore buf[1] */
549 /* Bug in 64 bit Vista/w2k8/w7: mciSendStringW is used! (not in xp nor w2k3) */
551 buf[0] = 'K'; buf[1] = 0;
552 parm.info.dwRetSize = sizeof(buf);
553 err = mciSendCommandW(1, MCI_INFO, 0x07000000, (DWORD_PTR)&parm);
554 ok(err==MCIERR_UNRECOGNIZED_KEYWORD || broken(err==MMSYSERR_NOTSUPPORTED/* Win9x */), "mciCommand MCI_INFO other: %s\n", dbg_mcierr(err));
555 ok(!strcmp(buf,"K"), "info output buffer %s\n", buf);
557 err = mciGetDeviceIDA("all");
558 ok(err == MCI_ALL_DEVICE_ID, "mciGetDeviceIDA all returned %lu, expected MCI_ALL_DEVICE_ID\n", err);
560 err = mciSendStringA(command_close_my, NULL, 0, hwnd);
561 ok(!err,"mci %s returned %s\n", command_close_my, dbg_mcierr(err));
562 test_notification(hwnd, command_close_my, MCI_NOTIFY_SUCCESSFUL);
563 Sleep(5);
564 test_notification(hwnd, command_close_my, 0);
566 err = mciSendStringA("open no-such-file-exists.wav alias y buffer 6", buf, sizeof(buf), NULL);
567 ok(err==MCIERR_FILE_NOT_FOUND,"open no-such-file.wav returned %s\n", dbg_mcierr(err));
568 if(!err) {
569 err = mciSendStringA("close y", NULL, 0, NULL);
570 ok(!err,"close y returned %s\n", dbg_mcierr(err));
573 err = mciSendStringA("open no-such-dir\\file.wav alias y type waveaudio", buf, sizeof(buf), NULL);
574 ok(err==MCIERR_FILE_NOT_FOUND || broken(err==MCIERR_INVALID_FILE /* Win9X */),"open no-such-dir/file.wav returned %s\n", dbg_mcierr(err));
575 if(!err) {
576 err = mciSendStringA("close y", NULL, 0, NULL);
577 ok(!err,"close y returned %s\n", dbg_mcierr(err));
580 err = mciSendStringA("open ! alias no", buf, sizeof(buf), NULL);
581 ok(err==MCIERR_INVALID_DEVICE_NAME,"open !(void): %s\n", dbg_mcierr(err));
583 err = mciSendStringA("open !no-such-file-exists.wav alias no", buf, sizeof(buf), NULL);
584 ok(err==MCIERR_FILE_NOT_FOUND || /* Win9X */err==MCIERR_INVALID_DEVICE_NAME,"open !name: %s\n", dbg_mcierr(err));
586 /* FILE_NOT_FOUND stems from mciwave,
587 * the complete name including ! is passed through since NT */
588 err = mciSendStringA("open nosuchdevice!tempfile.wav alias no", buf, sizeof(buf), NULL);
589 ok(err==MCIERR_FILE_NOT_FOUND || /* Win9X */err==MCIERR_INVALID_DEVICE_NAME,"open nosuchdevice!name: %s\n", dbg_mcierr(err));
590 /* FIXME? use broken(INVALID_DEVICE_NAME) and have Wine not mimic Win9X? */
592 err = mciSendStringA("close waveaudio", buf, sizeof(buf), NULL);
593 ok(err==MCIERR_INVALID_DEVICE_NAME,"close waveaudio: %s\n", dbg_mcierr(err));
595 err = mciSendStringA(command_close_all, NULL, 0, NULL);
596 ok(!err,"mci %s (without buffer) returned %s\n", command_close_all, dbg_mcierr(err));
598 err = mciSendStringA(command_close_all, buf, sizeof(buf), hwnd);
599 ok(!err,"mci %s (with output buffer) returned %s\n", command_close_all, dbg_mcierr(err));
600 ok(buf[0] == 0, "mci %s output buffer: %s\n", command_close_all, buf);
601 /* No notification left, everything closed already */
602 test_notification(hwnd, command_close_all, 0);
603 /* TODO test close all sends one notification per open device */
605 err = mciSendStringA(command_sysinfo, buf, sizeof(buf), NULL);
606 ok(!err,"mci %s returned %s\n", command_sysinfo, dbg_mcierr(err));
607 ok(buf[0] == '0' && buf[1] == 0, "mci %s, expected output buffer '0', got: '%s'\n", command_sysinfo, buf);
609 err = mciSendStringA("open new type waveaudio", buf, sizeof(buf), NULL);
610 ok(err==MCIERR_NEW_REQUIRES_ALIAS,"mci open new without alias returned %s\n", dbg_mcierr(err));
612 parm.open.lpstrDeviceType = (LPSTR)MCI_DEVTYPE_WAVEFORM_AUDIO;
613 err = mciSendCommandA(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID, (DWORD_PTR)&parm);
614 ok(!err,"mciCommand OPEN_TYPE_ID waveaudio: %s\n", dbg_mcierr(err));
616 if(!err) {
617 MCIDEVICEID wDeviceID = parm.open.wDeviceID;
618 parm.caps.dwItem = MCI_GETDEVCAPS_DEVICE_TYPE;
619 err = mciSendCommandA(wDeviceID, MCI_GETDEVCAPS, MCI_GETDEVCAPS_ITEM, (DWORD_PTR)&parm);
620 ok(!err,"mciCommand MCI_GETDEVCAPS device type: %s\n", dbg_mcierr(err));
621 ok(MCI_DEVTYPE_WAVEFORM_AUDIO==parm.caps.dwReturn,"mciCommand GETDEVCAPS says %lu, expected %u\n", parm.caps.dwReturn, MCI_DEVTYPE_WAVEFORM_AUDIO);
624 ok(0xDEADF00D==intbuf[0] && 0xABADCAFE==intbuf[2],"DWORD buffer corruption\n");
626 err = mciGetDeviceIDA("waveaudio");
627 ok(err == 1, "mciGetDeviceIDA waveaudio returned %lu, expected 1\n", err);
629 err = mciSendStringA("open no-such-file.wav alias waveaudio", buf, sizeof(buf), NULL);
630 ok(err==MCIERR_DUPLICATE_ALIAS, "mci open alias waveaudio returned %s\n", dbg_mcierr(err));
631 /* If it were not already in use, open avivideo alias waveaudio would succeed,
632 * making for funny test cases. */
634 err = mciSendCommandA(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_WAIT, 0); /* from MSDN */
635 ok(!err, "mciCommand close returned %s\n", dbg_mcierr(err));
637 err = mciSendCommandA(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, 0);
638 ok(!err, "mciCommand close returned %s\n", dbg_mcierr(err));
640 parm.gen.dwCallback = (DWORD_PTR)hwnd;
641 err = mciSendCommandA(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_NOTIFY, (DWORD_PTR)&parm);
642 ok(!err, "mciCommand close returned %s\n", dbg_mcierr(err));
643 test_notification(hwnd, command_close_all, 0); /* None left */
646 static void test_recordWAVE(HWND hwnd)
648 WORD nch = 1;
649 WORD nbits = 16;
650 DWORD nsamp = 16000, expect;
651 UINT ndevs = waveInGetNumDevs();
652 MCIERROR err, ok_pcm;
653 MCIDEVICEID wDeviceID;
654 MCI_PARMS_UNION parm;
655 char buf[1024];
656 memset(buf, 0, sizeof(buf));
657 test_notification(hwnd, "-prior to recording-", 0);
659 parm.open.lpstrDeviceType = "waveaudio";
660 parm.open.lpstrElementName = ""; /* "new" at the command level */
661 parm.open.lpstrAlias = "x"; /* to enable mciSendStringA */
662 parm.open.dwCallback = (DWORD_PTR)hwnd;
663 err = mciSendCommandA(0, MCI_OPEN,
664 MCI_OPEN_ELEMENT | MCI_OPEN_TYPE | MCI_OPEN_ALIAS | MCI_NOTIFY, (DWORD_PTR)&parm);
665 ok(!err,"mciCommand open new type waveaudio alias x notify: %s\n", dbg_mcierr(err));
666 wDeviceID = parm.open.wDeviceID;
668 err = mciGetDeviceIDA("x");
669 ok(err == wDeviceID, "mciGetDeviceIDA x returned %lu, expected %u\n", err, wDeviceID);
671 /* Only the alias is looked up. */
672 err = mciGetDeviceIDA("waveaudio");
673 ok(!err, "mciGetDeviceIDA waveaudio returned %lu, expected 0\n", err);
675 test_notification(hwnd, "open new", MCI_NOTIFY_SUCCESSFUL);
676 test_notification(hwnd, "open new no #2", 0);
678 /* Do not query time format as string because result depends on locale! */
679 parm.status.dwItem = MCI_STATUS_TIME_FORMAT;
680 err = mciSendCommandA(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
681 ok(!err,"mciCommand status time format: %s\n", dbg_mcierr(err));
682 ok(parm.status.dwReturn==MCI_FORMAT_MILLISECONDS,"status time format: %Id\n",parm.status.dwReturn);
684 /* Info file fails until named in Open or Save. */
685 err = mciSendStringA("info x file", buf, sizeof(buf), NULL);
686 todo_wine ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci info new file returned %s\n", dbg_mcierr(err));
687 ok(!buf[0], "info error buffer %s\n", buf);
689 err = mciSendStringA("status x length", buf, sizeof(buf), NULL);
690 todo_wine ok(!err,"status x length initial: %s\n", dbg_mcierr(err));
691 if(!err) ok(!strcmp(buf,"0"), "mci status length expected 0, got: %s\n", buf);
693 /* Check the default recording: 8-bits per sample, mono, 11kHz */
694 err = mciSendStringA("status x samplespersec", buf, sizeof(buf), NULL);
695 ok(!err,"mci status samplespersec returned %s\n", dbg_mcierr(err));
696 if(!err) ok(!strcmp(buf,"11025"), "mci status samplespersec expected 11025, got: %s\n", buf);
698 /* MCI appears to scan the available devices for support of this format,
699 * returning MCIERR_OUTOFRANGE on machines with no sound.
700 * However some w2k8/w7 machines return no error when there's no wave
701 * input device (perhaps querying waveOutGetNumDevs instead of waveIn?),
702 * still the record command below fails with MCIERR_WAVE_INPUTSUNSUITABLE.
703 * Don't skip here, record will fail below. */
704 err = mciSendStringA("set x format tag pcm", NULL, 0, NULL);
705 ok(!err || err==MCIERR_OUTOFRANGE,"mci set format tag pcm returned %s\n", dbg_mcierr(err));
706 ok_pcm = err;
708 /* MSDN warns against not setting all wave format parameters.
709 * Indeed, it produces strange results, incl.
710 * inconsistent PCMWAVEFORMAT headers in the saved file.
712 err = mciSendStringA("set x bytespersec 22050 alignment 2 samplespersec 11025 channels 1 bitspersample 16", NULL, 0, NULL);
713 ok(err==ok_pcm,"mci set 5 wave parameters returned %s\n", dbg_mcierr(err));
714 /* Investigate: on w2k, set samplespersec 22050 sets nChannels to 2!
715 * err = mciSendStringA("set x samplespersec 22050", NULL, 0, NULL);
716 * ok(!err,"mci set samplespersec returned %s\n", dbg_mcierr(err));
719 /* Checks are generally performed immediately. */
720 err = mciSendStringA("set x bitspersample 4", NULL, 0, NULL);
721 todo_wine ok(err==MCIERR_OUTOFRANGE,"mci set bitspersample 4 returned %s\n", dbg_mcierr(err));
723 parm.set.wFormatTag = WAVE_FORMAT_PCM;
724 parm.set.nSamplesPerSec = nsamp;
725 parm.set.wBitsPerSample = nbits;
726 parm.set.nChannels = nch;
727 parm.set.nBlockAlign = parm.set.nChannels * parm.set.wBitsPerSample /8;
728 parm.set.nAvgBytesPerSec= parm.set.nSamplesPerSec * parm.set.nBlockAlign;
729 err = mciSendCommandA(wDeviceID, MCI_SET,
730 MCI_WAVE_SET_SAMPLESPERSEC | MCI_WAVE_SET_CHANNELS | MCI_WAVE_SET_BITSPERSAMPLE |
731 MCI_WAVE_SET_BLOCKALIGN | MCI_WAVE_SET_AVGBYTESPERSEC| MCI_WAVE_SET_FORMATTAG,
732 (DWORD_PTR)&parm);
733 ok(err==ok_pcm,"mciCommand set wave format: %s\n", dbg_mcierr(err));
735 parm.caps.dwItem = MCI_WAVE_GETDEVCAPS_INPUTS;
736 parm.caps.dwCallback = (DWORD_PTR)hwnd;
737 err = mciSendCommandA(wDeviceID, MCI_GETDEVCAPS, MCI_GETDEVCAPS_ITEM | MCI_NOTIFY,
738 (DWORD_PTR)&parm);
739 ok(!err,"mciCommand MCI_GETDEVCAPS inputs: %s\n", dbg_mcierr(err));
740 ok(parm.caps.dwReturn==ndevs,"mciCommand GETDEVCAPS claims %lu inputs, expected %u\n", parm.caps.dwReturn, ndevs);
741 ok(!ok_pcm || !parm.caps.dwReturn,"No input device accepts PCM!?\n");
742 test_notification(hwnd, "GETDEVCAPS inputs", MCI_NOTIFY_SUCCESSFUL);
744 /* A few ME machines pass all tests except set format tag pcm! */
745 err = mciSendStringA("record x to 2000 wait", NULL, 0, hwnd);
746 ok(err || !ok_pcm,"can record yet set wave format pcm returned %s\n", dbg_mcierr(ok_pcm));
747 todo_wine_if (!ndevs) /* with sound disabled */
748 ok(ndevs > 0 ? !err : err == MCIERR_WAVE_INPUTSUNSUITABLE, "mci record to 2000 returned %s\n", dbg_mcierr(err));
749 if(err) {
750 if (err==MCIERR_WAVE_INPUTSUNSUITABLE)
751 skip("Please install audio driver. Everything is skipped.\n");
752 else skip("Cannot record cause %s. Everything is skipped.\n", dbg_mcierr(err));
754 err = mciSendStringA("close x", NULL, 0, NULL);
755 ok(!err,"mci close returned %s\n", dbg_mcierr(err));
756 test_notification(hwnd,"record skipped",0);
757 return;
760 /* Query some wave format parameters depending on the time format. */
761 err = mciSendStringA("status x position", buf, sizeof(buf), NULL);
762 ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
763 if(!err) todo_wine ok(!strcmp(buf,"2000"), "mci status position gave %s, expected 2000, some tests will fail\n", buf);
765 err = mciSendStringA("set x time format 8", NULL, 0, NULL); /* bytes */
766 ok(!err,"mci returned %s\n", dbg_mcierr(err));
768 parm.status.dwItem = MCI_STATUS_POSITION;
769 err = mciSendCommandA(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
770 ok(!err,"mciCommand status position: %s\n", dbg_mcierr(err));
771 expect = 2 * nsamp * nch * nbits/8;
772 if(!err) todo_wine ok(parm.status.dwReturn==expect,"recorded %Iu bytes, expected %lu\n",parm.status.dwReturn,expect);
774 parm.set.dwTimeFormat = MCI_FORMAT_SAMPLES;
775 err = mciSendCommandA(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)&parm);
776 ok(!err,"mciCommand set time format samples: %s\n", dbg_mcierr(err));
778 parm.status.dwItem = MCI_STATUS_POSITION;
779 err = mciSendCommandA(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
780 ok(!err,"mciCommand status position: %s\n", dbg_mcierr(err));
781 expect = 2 * nsamp;
782 if(!err) todo_wine ok(parm.status.dwReturn==expect,"recorded %Iu samples, expected %lu\n",parm.status.dwReturn,expect);
784 err = mciSendStringA("set x time format milliseconds", NULL, 0, NULL);
785 ok(!err,"mci set time format milliseconds returned %s\n", dbg_mcierr(err));
787 err = mciSendStringA("save x tempfile1.wav", NULL, 0, NULL);
788 ok(!err,"mci save returned %s\n", dbg_mcierr(err));
790 err = mciSendStringA("save x tempfile.wav", NULL, 0, NULL);
791 ok(!err,"mci save returned %s\n", dbg_mcierr(err));
792 if(!err) ok_saved = 0;
794 /* Save must not rename the original file. */
795 if (!DeleteFileA("tempfile1.wav"))
796 todo_wine ok(FALSE, "Save must not rename the original file; DeleteFileA returned %ld\n",
797 GetLastError());
799 err = mciSendStringA("set x channels 2", NULL, 0, NULL);
800 ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci set channels after saving returned %s\n", dbg_mcierr(err));
802 parm.seek.dwTo = 600;
803 err = mciSendCommandA(wDeviceID, MCI_SEEK, MCI_TO | MCI_WAIT, (DWORD_PTR)&parm);
804 ok(!err,"mciCommand seek to 600: %s\n", dbg_mcierr(err));
806 /* Truncate to current position */
807 err = mciSendStringA("delete x", NULL, 0, NULL);
808 todo_wine ok(!err,"mci delete returned %s\n", dbg_mcierr(err));
810 err = mciSendStringA("status x length", buf, sizeof(buf), NULL);
811 ok(!err,"mci status length returned %s\n", dbg_mcierr(err));
812 todo_wine ok(!strcmp(buf,"600"), "mci status length after delete gave %s, expected 600\n", buf);
814 err = mciSendStringA("close x", NULL, 0, NULL);
815 ok(!err,"mci close returned %s\n", dbg_mcierr(err));
816 test_notification(hwnd,"record complete",0);
819 static void test_playWAVE(HWND hwnd)
821 MCIERROR err;
822 char buf[1024];
823 memset(buf, 0, sizeof(buf));
825 err = mciSendStringA("open waveaudio!tempfile.wav alias mysound", NULL, 0, NULL);
826 ok(err==ok_saved,"mci open waveaudio!tempfile.wav returned %s\n", dbg_mcierr(err));
827 if(err) {
828 skip("Cannot open waveaudio!tempfile.wav for playing (%s), skipping\n", dbg_mcierr(err));
829 return;
832 err = mciGetDeviceIDA("mysound");
833 ok(err == 1, "mciGetDeviceIDA mysound returned %lu, expected 1\n", err);
835 err = mciGetDeviceIDA("tempfile.wav");
836 ok(!err, "mciGetDeviceIDA tempfile.wav returned %lu, expected 0\n", err);
838 err = mciGetDeviceIDA("waveaudio");
839 ok(!err, "mciGetDeviceIDA waveaudio returned %lu, expected 0\n", err);
841 err = mciSendStringA("status mysound length", buf, sizeof(buf), NULL);
842 ok(!err,"mci status length returned %s\n", dbg_mcierr(err));
843 todo_wine ok(!strcmp(buf,"2000"), "mci status length gave %s, expected 2000, some tests will fail.\n", buf);
845 err = mciSendStringA("cue output", NULL, 0, NULL);
846 ok(err==MCIERR_UNRECOGNIZED_COMMAND,"mci incorrect cue output returned %s\n", dbg_mcierr(err));
848 /* Test MCI to the bones -- Some todo_wine from Cue and
849 * from Play from 0 to 0 are not worth fixing. */
850 err = mciSendStringA("cue mysound output notify", NULL, 0, hwnd);
851 ok(!err,"mci cue output after open file returned %s\n", dbg_mcierr(err));
852 /* Notification is delayed as a play thread is started. */
853 todo_wine test_notification(hwnd, "cue immediate", 0);
855 /* Cue pretends to put the MCI into paused state. */
856 err = mciSendStringA("status mysound mode", buf, sizeof(buf), hwnd);
857 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
858 todo_wine ok(!strcmp(buf,"paused"), "mci status mode: %s, expected (pseudo)paused\n", buf);
860 /* Strange pause where Pause is rejected, unlike Play; Pause; Pause tested below */
861 err = mciSendStringA("pause mysound", NULL, 0, hwnd);
862 ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci pause after cue returned %s\n", dbg_mcierr(err));
864 /* MCI appears to start the play thread in this border case.
865 * Guessed that from (flaky) status mode and late notification arrival. */
866 err = mciSendStringA("play mysound from 0 to 0 notify", NULL, 0, hwnd);
867 ok(!err,"mci play from 0 to 0 returned %s\n", dbg_mcierr(err));
868 todo_wine test_notification(hwnd, "cue aborted by play", MCI_NOTIFY_ABORTED);
869 /* play's own notification follows below */
871 err = mciSendStringA("play mysound from 250 to 0", NULL, 0, NULL);
872 ok(err==MCIERR_OUTOFRANGE,"mci play from 250 to 0 returned %s\n", dbg_mcierr(err));
874 Sleep(100); /* Give play from 0 to 0 time to finish. */
875 todo_wine test_notification(hwnd, "play from 0 to 0", MCI_NOTIFY_SUCCESSFUL);
877 err = mciSendStringA("status mysound mode", buf, sizeof(buf), hwnd);
878 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
879 ok(!strcmp(buf,"stopped"), "mci status mode: %s after play from 0 to 0\n", buf);
881 err = mciSendStringA("play MYSOUND from 250 to 0 notify", NULL, 0, hwnd);
882 ok(err==MCIERR_OUTOFRANGE,"mci play from 250 to 0 notify returned %s\n", dbg_mcierr(err));
883 /* No notification (checked below) sent if error */
885 /* A second play caused Wine<1.1.33 to hang */
886 err = mciSendStringA("play mysound from 500 to 220:5:0 wait", NULL, 0, NULL);
887 ok(!err,"mci play from 500 to 220:5:0 (=1500) returned %s\n", dbg_mcierr(err));
889 err = mciSendStringA("status mysound position", buf, sizeof(buf), hwnd);
890 ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
891 if(!err) ok(!strcmp(buf,"1500"), "mci status position: %s\n", buf);
893 /* mci will not play position < current */
894 err = mciSendStringA("play mysound to 1000", NULL, 0, NULL);
895 ok(err==MCIERR_OUTOFRANGE,"mci play to 1000 returned %s\n", dbg_mcierr(err));
897 /* mci will not play to > end */
898 err = mciSendStringA("play mysound TO 3000 notify", NULL, 0, hwnd);
899 ok(err==MCIERR_OUTOFRANGE,"mci play to 3000 notify returned %s\n", dbg_mcierr(err));
901 err = mciSendStringA("play mysound to 2000", NULL, 0, NULL);
902 ok(!err,"mci play to 2000 returned %s\n", dbg_mcierr(err));
904 /* Rejected while playing */
905 err = mciSendStringA("cue mysound output", NULL, 0, NULL);
906 ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci cue output while playing returned %s\n", dbg_mcierr(err));
908 err = mciSendStringA("play mysound to 3000", NULL, 0, NULL);
909 ok(err==MCIERR_OUTOFRANGE,"mci play to 3000 returned %s\n", dbg_mcierr(err));
911 err = mciSendStringA("stop mysound Wait", NULL, 0, NULL);
912 ok(!err,"mci stop wait returned %s\n", dbg_mcierr(err));
913 test_notification(hwnd, "play/cue/pause/stop", 0);
915 err = mciSendStringA("Seek Mysound to 250 wait Notify", NULL, 0, hwnd);
916 ok(!err,"mci seek to 250 wait notify returned %s\n", dbg_mcierr(err));
917 test_notification(hwnd,"seek wait notify",MCI_NOTIFY_SUCCESSFUL);
919 err = mciSendStringA("seek mysound to 0xfa", NULL, 0, NULL);
920 ok(err==MCIERR_BAD_INTEGER,"mci seek to 0xfa returned %s\n", dbg_mcierr(err));
922 /* MCI_INTEGER always accepts colon notation */
923 err = mciSendStringA("seek mysound to :1", NULL, 0, NULL);
924 ok(!err,"mci seek to :1 (=256) returned %s\n", dbg_mcierr(err));
926 err = mciSendStringA("seek mysound to 250::", NULL, 0, NULL);
927 ok(!err,"mci seek to 250:: returned %s\n", dbg_mcierr(err));
929 err = mciSendStringA("seek mysound to 250:0", NULL, 0, NULL);
930 ok(!err,"mci seek to 250:0 returned %s\n", dbg_mcierr(err));
932 err = mciSendStringA("status mysound position notify", buf, sizeof(buf), hwnd);
933 ok(!err,"mci status position notify returned %s\n", dbg_mcierr(err));
934 if(!err) ok(!strcmp(buf,"250"), "mci status position: %s\n", buf);
935 /* Immediate commands like status also send notifications. */
936 test_notification(hwnd,"status position",MCI_NOTIFY_SUCCESSFUL);
938 err = mciSendStringA("status mysound mode", buf, sizeof(buf), hwnd);
939 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
940 ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
942 /* Another play from == to testcase */
943 err = mciSendStringA("play mysound to 250 wait notify", NULL, 0, hwnd);
944 ok(!err,"mci play (from 250) to 250 returned %s\n", dbg_mcierr(err));
945 todo_wine test_notification(hwnd,"play to 250 wait notify",MCI_NOTIFY_SUCCESSFUL);
947 err = mciSendStringA("cue mysound output", NULL, 0, NULL);
948 ok(!err,"mci cue output after play returned %s\n", dbg_mcierr(err));
950 err = mciSendStringA("close mysound", NULL, 0, NULL);
951 ok(!err,"mci close returned %s\n", dbg_mcierr(err));
952 test_notification(hwnd,"after close",0);
955 static void test_asyncWAVE(HWND hwnd)
957 MCIDEVICEID wDeviceID;
958 MCI_PARMS_UNION parm;
959 int err, p1, p2;
960 char buf[1024];
961 memset(buf, 0, sizeof(buf));
963 err = mciSendStringA("open tempfile.wav alias mysound notify type waveaudio", buf, sizeof(buf), hwnd);
964 ok(err==ok_saved,"mci open tempfile.wav returned %s\n", dbg_mcierr(err));
965 if(err) {
966 skip("Cannot open tempfile.wav for playing (%s), skipping\n", dbg_mcierr(err));
967 return;
969 ok(!strcmp(buf,"1"), "mci open deviceId: %s, expected 1\n", buf);
970 wDeviceID = atoi(buf);
971 ok(wDeviceID,"mci open DeviceID: %d\n", wDeviceID);
972 test_notification(hwnd,"open alias notify",MCI_NOTIFY_SUCCESSFUL);
974 err = mciGetDeviceIDA("mysound");
975 ok(err == wDeviceID, "mciGetDeviceIDA alias returned %u, expected %u\n", err, wDeviceID);
977 /* Only the alias is looked up. */
978 err = mciGetDeviceIDA("tempfile.wav");
979 ok(!err, "mciGetDeviceIDA tempfile.wav returned %u, expected 0\n", err);
981 err = mciGetDeviceIDA("waveaudio");
982 ok(!err, "mciGetDeviceIDA waveaudio returned %u, expected 0\n", err);
984 err = mciSendStringA("status mysound mode", buf, sizeof(buf), hwnd);
985 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
986 ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
988 err = mciSendStringA("play mysound notify", NULL, 0, hwnd);
989 ok(!err,"mci play returned %s\n", dbg_mcierr(err));
991 Sleep(500); /* milliseconds */
993 /* Do not query time format as string because result depends on locale! */
994 parm.status.dwItem = MCI_STATUS_TIME_FORMAT;
995 err = mciSendCommandA(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parm);
996 ok(!err,"mciCommand status time format: %s\n", dbg_mcierr(err));
997 if(!err) ok(parm.status.dwReturn==MCI_FORMAT_MILLISECONDS,"status time format: %Id\n",parm.status.dwReturn);
999 parm.set.dwTimeFormat = MCI_FORMAT_MILLISECONDS;
1000 err = mciSendCommandA(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)&parm);
1001 ok(!err,"mciCommand set time format ms: %s\n", dbg_mcierr(err));
1003 err = mciSendStringA("status mysound position", buf, sizeof(buf), hwnd);
1004 ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
1005 trace("position after Sleep: %sms\n", buf);
1006 p2 = atoi(buf);
1007 /* Check that the 2s sound plays at a normal pace, giving a wide margin to
1008 * account for timing granularity and small delays.
1010 todo_wine ok(350 <= p2 && p2 <= 600, "%ums is not in the expected 350-600ms range\n", p2);
1011 /* Wine's asynchronous thread needs some time to start up. Furthermore, it
1012 * uses 3 buffers per second, so that the positions reported will be 333ms,
1013 * 667ms etc. at best, which is why it fails the above test. So add a
1014 * second test specifically to prevent Wine from getting even worse.
1015 * FIXME: To be removed when Wine is fixed and passes the above test.
1017 ok(350 <= p2 && p2 <= 1000, "%ums is not even in the expected 350-1000ms range\n", p2);
1018 test_notification(hwnd,"play (nowait)",0);
1020 err = mciSendStringA("pause mysound wait", NULL, 0, hwnd);
1021 ok(!err,"mci pause wait returned %s\n", dbg_mcierr(err));
1023 err = mciSendStringA("status mysound mode notify", buf, sizeof(buf), hwnd);
1024 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
1025 if(!err) ok(!strcmp(buf,"paused"), "mci status mode: %s\n", buf);
1026 test_notification(hwnd,"play",MCI_NOTIFY_SUPERSEDED);
1027 test_notification(hwnd,"status",MCI_NOTIFY_SUCCESSFUL);
1029 err = mciSendStringA("status mysound position", buf, sizeof(buf), hwnd);
1030 ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
1031 trace("position while paused: %sms\n",buf);
1032 p1 = atoi(buf);
1033 ok(p1>=p2, "position not increasing: %u > %u\n", p2, p1);
1035 err = mciSendStringA("stop mysound wait", NULL, 0, NULL);
1036 ok(!err,"mci stop returned %s\n", dbg_mcierr(err));
1038 err = mciSendStringA("info mysound file notify", buf, sizeof(buf), hwnd);
1039 ok(!err,"mci info file returned %s\n", dbg_mcierr(err));
1040 if(!err) { /* fully qualified name */
1041 int len = strlen(buf);
1042 todo_wine ok(len>2 && buf[1]==':',"Expected full pathname from info file: %s\n", buf);
1043 ok(len>=12 && !strcmp(&buf[len-12],"tempfile.wav"), "info file returned: %s\n", buf);
1045 test_notification(hwnd,"info file",MCI_NOTIFY_SUCCESSFUL);
1047 err = mciSendStringA("status mysound mode", buf, sizeof(buf), hwnd);
1048 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
1049 ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
1051 err = mciSendStringA("status mysound position", buf, sizeof(buf), hwnd);
1052 ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
1053 trace("position once stopped: %sms\n",buf);
1054 p2 = atoi(buf);
1055 /* An XP machine let the position increase slightly after pause. */
1056 ok(p2>=p1 && p2<=p1+16,"position changed from %ums to %ums\n",p1,p2);
1058 /* No Resume once stopped (waveaudio, sequencer and cdaudio differ). */
1059 err = mciSendStringA("resume mysound wait", NULL, 0, NULL);
1060 ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci resume wait returned %s\n", dbg_mcierr(err));
1062 err = mciSendStringA("play mysound wait", NULL, 0, NULL);
1063 ok(!err,"mci play wait returned %s\n", dbg_mcierr(err));
1065 err = mciSendStringA("status mysound position", buf, sizeof(buf), hwnd);
1066 ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
1067 todo_wine ok(!strcmp(buf,"2000"), "mci status position: %s\n", buf);
1069 err = mciSendStringA("seek mysound to start wait", NULL, 0, NULL);
1070 ok(!err,"mci seek to start wait returned %s\n", dbg_mcierr(err));
1072 err = mciSendStringA("play mysound to 1000 notify", NULL, 0, hwnd);
1073 ok(!err,"mci play returned %s\n", dbg_mcierr(err));
1075 /* Sleep(200); not needed with Wine any more. */
1077 err = mciSendStringA("pause mysound notify", NULL, 0, NULL); /* notify no callback */
1078 ok(!err,"mci pause notify returned %s\n", dbg_mcierr(err));
1079 /* Supersede even though pause cannot notify given no callback */
1080 test_notification(hwnd,"pause aborted play #1 notification",MCI_NOTIFY_SUPERSEDED);
1081 test_notification(hwnd,"impossible pause notification",0);
1083 err = mciSendStringA("cue mysound output notify", NULL, 0, hwnd);
1084 ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci cue output while paused returned %s\n", dbg_mcierr(err));
1085 test_notification(hwnd,"cue output notify #2",0);
1087 err = mciSendStringA("resume mysound notify", NULL, 0, hwnd);
1088 ok(!err,"mci resume notify returned %s\n", dbg_mcierr(err));
1089 test_notification(hwnd, "resume notify", MCI_NOTIFY_SUCCESSFUL);
1091 /* Seek or even Stop used to hang Wine<1.1.32 on MacOS. */
1092 err = mciSendStringA("seek mysound to 0 wait", NULL, 0, NULL);
1093 ok(!err,"mci seek to start returned %s\n", dbg_mcierr(err));
1095 /* Seek stops. */
1096 err = mciSendStringA("status mysound mode", buf, sizeof(buf), NULL);
1097 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
1098 if(!err) ok(!strcmp(buf,"stopped"), "mci status mode: %s\n", buf);
1100 err = mciSendStringA("seek mysound wait", NULL, 0, NULL);
1101 ok(err==MCIERR_MISSING_PARAMETER,"mci seek to nowhere returned %s\n", dbg_mcierr(err));
1103 /* cdaudio does not detect to start to end as error */
1104 err = mciSendStringA("seek mysound to start to 0", NULL, 0, NULL);
1105 ok(err==MCIERR_FLAGS_NOT_COMPATIBLE,"mci seek to start to 0 returned %s\n", dbg_mcierr(err));
1107 err = mciSendStringA("PLAY mysound to 1000 notify", NULL, 0, hwnd);
1108 ok(!err,"mci play to 1000 notify returned %s\n", dbg_mcierr(err));
1110 /* Sleep(200); not needed with Wine any more. */
1111 /* Give it 400ms and resume will appear to complete below. */
1113 err = mciSendStringA("pause mysound wait", NULL, 0, NULL);
1114 ok(!err,"mci pause wait returned %s\n", dbg_mcierr(err));
1115 /* Unlike sequencer and cdaudio, waveaudio's pause does not abort. */
1116 test_notification(hwnd,"pause aborted play #2 notification",0);
1118 err = mciSendStringA("resume mysound wait", NULL, 0, NULL);
1119 ok(!err,"mci resume wait returned %s\n", dbg_mcierr(err));
1120 /* Resume is a short asynchronous call, something else is playing. */
1122 err = mciSendStringA("status mysound mode", buf, sizeof(buf), NULL);
1123 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
1124 if(!err) ok(!strcmp(buf,"playing"), "mci status mode: %s\n", buf);
1126 /* Note extra space before alias */
1127 err = mciSendStringA("pause mysound wait", NULL, 0, NULL);
1128 todo_wine ok(!err,"mci pause (space) wait returned %s\n", dbg_mcierr(err));
1130 err = mciSendStringA("pause mysound wait", NULL, 0, NULL);
1131 ok(!err,"mci pause wait returned %s\n", dbg_mcierr(err));
1133 /* Better ask position only when paused, is it updated while playing? */
1134 err = mciSendStringA("status mysound position", buf, sizeof(buf), NULL);
1135 ok(!err,"mci status position returned %s\n", dbg_mcierr(err));
1136 /* TODO compare position < 900 */
1137 ok(strcmp(buf,"1000"), "mci resume waited\n");
1138 ok(strcmp(buf,"2000"), "mci resume played to end\n");
1139 trace("position after resume: %sms\n",buf);
1140 test_notification(hwnd,"play (aborted by pause/resume/pause)",0);
1142 /* A small Sleep() here prevents the notification test failing with MCI_NOTIFY_SUCCESSFUL */
1143 Sleep(10);
1144 err = mciSendStringA("close mysound wait", NULL, 0, NULL);
1145 ok(!err,"mci close wait returned %s\n", dbg_mcierr(err));
1146 test_notification(hwnd,"play (aborted by close)",MCI_NOTIFY_ABORTED);
1149 static void test_AutoOpenWAVE(HWND hwnd)
1151 /* This test used(?) to cause intermittent crashes when Wine exits, after
1152 * fixme:winmm:MMDRV_Exit Closing while ll-driver open
1154 UINT ndevs = waveOutGetNumDevs();
1155 MCIERROR err, ok_snd = ndevs ? 0 : MCIERR_HARDWARE;
1156 MCI_PARMS_UNION parm;
1157 char buf[512], path[300], command[330];
1158 DWORD intbuf[3] = { 0xDEADF00D, 99, 0xABADCAFE };
1159 memset(buf, 0, sizeof(buf)); memset(path, 0, sizeof(path));
1161 /* Do not crash on NULL buffer pointer */
1162 err = mciSendStringA("sysinfo waveaudio quantity open", NULL, 0, NULL);
1163 ok(err==MCIERR_PARAM_OVERFLOW,"mci sysinfo without buffer returned %s\n", dbg_mcierr(err));
1165 err = mciSendStringA("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL);
1166 ok(!err,"mci sysinfo waveaudio quantity open returned %s\n", dbg_mcierr(err));
1167 if(!err) ok(!strcmp(buf,"0"), "sysinfo quantity open expected 0, got: %s, some more tests will fail.\n", buf);
1169 /* Who knows why some MS machines pass all tests but return MCIERR_HARDWARE here? */
1170 /* Wine returns MCIERR_HARDWARE when no default sound is found in win.ini or the registry. */
1171 err = mciSendStringA("sound NoSuchSoundDefined wait", NULL, 0, NULL);
1172 ok(err==ok_snd || err==MCIERR_HARDWARE, "mci sound NoSuchSoundDefined returned %s\n", dbg_mcierr(err));
1174 err = mciSendStringA("sound SystemExclamation notify wait", NULL, 0, hwnd);
1175 ok(err==ok_snd || err==MCIERR_HARDWARE, "mci sound SystemExclamation returned %s\n", dbg_mcierr(err));
1176 test_notification(hwnd, "sound notify", err ? 0 : MCI_NOTIFY_SUCCESSFUL);
1178 Sleep(16); /* time to auto-close makes sysinfo below return expected error */
1179 err = mciSendStringA("sysinfo waveaudio notify name 1 open", buf, sizeof(buf), hwnd);
1180 ok(err==MCIERR_OUTOFRANGE,"sysinfo waveaudio name 1 returned %s\n", dbg_mcierr(err));
1181 if(!err) trace("sysinfo dangling open alias: %s\n", buf);
1182 test_notification(hwnd, "sysinfo name outofrange\n", err ? 0 : MCI_NOTIFY_SUCCESSFUL);
1184 err = mciSendStringA("play no-such-file-exists.wav notify", buf, sizeof(buf), NULL);
1185 todo_wine ok(err==MCIERR_NOTIFY_ON_AUTO_OPEN,"mci auto-open notify returned %s\n", dbg_mcierr(err));
1186 /* FILE_NOT_FOUND in Wine because auto-open fails before testing the notify flag */
1188 test_notification(hwnd, "-prior to auto-open-", 0);
1190 err = mciSendStringA("play tempfile.wav notify", buf, sizeof(buf), hwnd);
1191 todo_wine_if (ok_saved == MCIERR_FILE_NOT_FOUND) /* same as above */
1192 ok(err==MCIERR_NOTIFY_ON_AUTO_OPEN,"mci auto-open play notify returned %s\n", dbg_mcierr(err));
1194 if(err) /* FIXME: don't open twice yet, it confuses Wine. */
1195 err = mciSendStringA("play tempfile.wav", buf, sizeof(buf), hwnd);
1196 ok(err==ok_saved,"mci auto-open play returned %s\n", dbg_mcierr(err));
1198 if(err==MCIERR_FILE_NOT_FOUND) {
1199 skip("Cannot open tempfile.wav for auto-play, skipping\n");
1200 return;
1203 err = mciSendStringA("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL);
1204 ok(!err,"mci sysinfo waveaudio quantity after auto-open returned %s\n", dbg_mcierr(err));
1205 if(!err) ok(!strcmp(buf,"1"), "sysinfo quantity open expected 1, got: %s\n", buf);
1207 parm.sys.lpstrReturn = (LPSTR)&intbuf[1];
1208 parm.sys.dwRetSize = 2*sizeof(DWORD); /* only one DWORD is used */
1209 parm.sys.wDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO;
1210 err = mciSendCommandA(0, MCI_SYSINFO, MCI_SYSINFO_QUANTITY | MCI_SYSINFO_OPEN, (DWORD_PTR)&parm);
1211 ok(!err, "mciCommand sysinfo waveaudio open notify returned %s\n", dbg_mcierr(err));
1212 if(!err) ok(atoi(buf)==intbuf[1],"sysinfo waveaudio quantity open string and command differ\n");
1214 err = mciSendStringA("sysinfo waveaudio name 1 open notify", buf, sizeof(buf), hwnd);
1215 ok(!err,"mci sysinfo waveaudio name after auto-open returned %s\n", dbg_mcierr(err));
1216 /* This is the alias, not necessarily a file name. */
1217 if(!err) ok(!strcmp(buf,"tempfile.wav"), "sysinfo name 1 open: %s\n", buf);
1218 test_notification(hwnd, "sysinfo name notify\n", MCI_NOTIFY_SUCCESSFUL);
1220 err = mciGetDeviceIDA("tempfile.wav");
1221 ok(err == 1, "mciGetDeviceIDA tempfile.wav returned %lu, expected 1\n", err);
1223 /* Save the full pathname to the file. */
1224 err = mciSendStringA("info tempfile.wav file", path, sizeof(path), NULL);
1225 ok(!err,"mci info tempfile.wav file returned %s\n", dbg_mcierr(err));
1226 if(err) strcpy(path,"tempfile.wav");
1228 err = mciSendStringA("status tempfile.wav mode", NULL, 0, hwnd);
1229 ok(!err,"mci status tempfile.wav mode without buffer returned %s\n", dbg_mcierr(err));
1231 sprintf(command,"status \"%s\" mode",path);
1232 err = mciSendStringA(command, buf, sizeof(buf), hwnd);
1233 ok(!err,"mci status \"%s\" mode returned %s\n", path, dbg_mcierr(err));
1235 err = mciSendStringA("status tempfile.wav mode", buf, sizeof(buf), hwnd);
1236 ok(!err,"mci status tempfile.wav mode returned %s\n", dbg_mcierr(err));
1237 if(!err) ok(!strcmp(buf,"playing"), "mci auto-open status mode, got: %s\n", buf);
1239 err = mciSendStringA("open tempfile.wav", buf, sizeof(buf), NULL);
1240 ok(err==MCIERR_DEVICE_OPEN, "mci open from auto-open returned %s\n", dbg_mcierr(err));
1242 err = mciSendStringA("open foo.wav alias tempfile.wav", buf, sizeof(buf), NULL);
1243 ok(err==MCIERR_DUPLICATE_ALIAS, "mci open re-using alias returned %s\n", dbg_mcierr(err));
1245 /* w2k/xp and Wine differ. While the device is busy playing, it is
1246 * regularly open and accessible via the filename: subsequent
1247 * commands must not cause auto-open each. In Wine, a subsequent
1248 * command with notify request may cause the initial play
1249 * notification to be superseded, in turn causing MCI to close the
1250 * device. I.e. MCI uses the auto-open notification for itself,
1251 * that's why it's not available to the app. On w2k/xp,
1252 * subsequent commands with notify requests are returned with
1253 * MCIERR_NOTIFY_ON_AUTO_OPEN and thus don't abort the original
1254 * command.
1256 err = mciSendStringA("status tempfile.wav mode notify", buf, sizeof(buf), hwnd);
1257 todo_wine ok(err==MCIERR_NOTIFY_ON_AUTO_OPEN, "mci status auto-open notify returned %s\n", dbg_mcierr(err));
1258 if(!err) {
1259 trace("Wine style MCI auto-close upon notification\n");
1261 /* "playing" because auto-close comes after the status call. */
1262 ok(!strcmp(buf,"playing"), "mci auto-open status mode notify, got: %s\n", buf);
1263 /* fixme:winmm:MMDRV_Exit Closing while ll-driver open
1264 * is explained by failure to auto-close a device. */
1265 test_notification(hwnd,"status notify",MCI_NOTIFY_SUCCESSFUL);
1266 /* MCI received NOTIFY_SUPERSEDED and auto-closed the device. */
1268 /* Until this is implemented, force closing the device */
1269 err = mciSendStringA("close tempfile.wav", NULL, 0, hwnd);
1270 ok(!err,"mci auto-still-open stop returned %s\n", dbg_mcierr(err));
1271 Sleep(16);
1272 test_notification(hwnd,"auto-open",0);
1273 } else if(err==MCIERR_NOTIFY_ON_AUTO_OPEN) { /* MS style */
1274 trace("MS style MCI auto-open forbids notification\n");
1276 err = mciSendStringA("pause tempfile.wav", NULL, 0, hwnd);
1277 ok(!err,"mci auto-still-open pause returned %s\n", dbg_mcierr(err));
1279 err = mciSendStringA("status tempfile.wav mode", buf, sizeof(buf), hwnd);
1280 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
1281 if(!err) ok(!strcmp(buf,"paused"), "mci auto-open status mode, got: %s\n", buf);
1283 /* Auto-close */
1284 err = mciSendStringA("stop tempfile.wav wait", NULL, 0, hwnd);
1285 ok(!err,"mci auto-still-open stop returned %s\n", dbg_mcierr(err));
1286 Sleep(16); /* makes sysinfo quantity open below succeed */
1289 err = mciSendStringA("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL);
1290 ok(!err,"mci sysinfo waveaudio quantity open after close returned %s\n", dbg_mcierr(err));
1291 if(!err) ok(!strcmp(buf,"0"), "sysinfo quantity open expected 0 after auto-close, got: %s\n", buf);
1293 /* w95-WinME (not w2k/XP) switch to C:\ after auto-playing once. Prevent
1294 * MCIERR_FILE_NOT_FOUND by using the full path name from the Info file command.
1296 sprintf(command,"status \"%s\" mode wait",path);
1297 err = mciSendStringA(command, buf, sizeof(buf), hwnd);
1298 ok(!err,"mci re-auto-open status mode returned %s\n", dbg_mcierr(err));
1299 if(!err) ok(!strcmp(buf,"stopped"), "mci re-auto-open status mode, got: %s\n", buf);
1301 /* This uses auto-open as well. */
1302 err = mciSendStringA("capability waveaudio outputs", buf, sizeof(buf), NULL);
1303 ok(!err,"mci capability waveaudio outputs returned %s\n", dbg_mcierr(err));
1304 /* Wine with no sound selected in winecfg's audio tab fails this test. */
1305 if(!err) ok(atoi(buf)==ndevs,"Expected %d audio outputs, got %s\n", ndevs, buf);
1307 err = mciSendStringA("capability waveaudio device type", buf, sizeof(buf), hwnd);
1308 ok(!err,"mci capability device type returned %s\n", dbg_mcierr(err));
1309 if(!err) ok(!strcmp(buf,"waveaudio"), "mci capability device type response: %s\n", buf);
1311 /* waveaudio forbids Pause without Play. */
1312 sprintf(command,"pause \"%s\"",path);
1313 err = mciSendStringA(command, NULL, 0, hwnd);
1314 ok(err==MCIERR_NONAPPLICABLE_FUNCTION,"mci auto-open pause returned %s\n", dbg_mcierr(err));
1316 ok(0xDEADF00D==intbuf[0] && 0xABADCAFE==intbuf[2],"DWORD buffer corruption\n");
1319 static void test_playWaveTypeMpegvideo(void)
1321 MCIERROR err;
1322 MCIDEVICEID wDeviceID;
1323 MCI_PLAY_PARMS play_parm;
1324 MCI_STATUS_PARMS status_parm;
1325 char buf[1024];
1326 memset(buf, 0, sizeof(buf));
1328 err = mciSendStringA("open tempfile.wav type MPEGVideo alias mysound", NULL, 0, NULL);
1329 ok(err==ok_saved,"mci open tempfile.wav type MPEGVideo returned %s\n", dbg_mcierr(err));
1330 if(err) {
1331 skip("Cannot open tempfile.wav type MPEGVideo for playing (%s), skipping\n", dbg_mcierr(err));
1332 return;
1335 wDeviceID = mciGetDeviceIDA("mysound");
1336 ok(wDeviceID == 1, "mciGetDeviceIDA mysound returned %u, expected 1\n", wDeviceID);
1338 err = mciSendCommandA(wDeviceID, MCI_PLAY, 0, (DWORD_PTR)&play_parm);
1339 ok(!err,"mciCommand play returned %s\n", dbg_mcierr(err));
1341 err = mciSendStringA("status mysound mode", buf, sizeof(buf), NULL);
1342 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
1343 ok(!strcmp(buf,"playing"), "mci status mode: %s\n", buf);
1345 status_parm.dwItem = MCI_STATUS_MODE;
1346 err = mciSendCommandA(wDeviceID, MCI_STATUS,
1347 MCI_STATUS_ITEM,
1348 (DWORD_PTR)&status_parm);
1349 ok(!err,"mciCommand status mode returned %s\n", dbg_mcierr(err));
1350 ok(status_parm.dwReturn == MCI_MODE_PLAY,
1351 "mciCommand status mode: %lu\n", (DWORD)status_parm.dwReturn);
1353 err = mciSendStringA("setaudio mysound volume to 1000", NULL, 0, NULL);
1354 ok(!err,"mci setaudio volume to 1000 returned %s\n", dbg_mcierr(err));
1356 err = mciSendStringA("status mysound mode", buf, sizeof(buf), NULL);
1357 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
1358 ok(!strcmp(buf,"playing"), "mci status mode: %s\n", buf);
1360 err = mciSendStringA("setaudio mysound volume to 1001", NULL, 0, NULL);
1361 ok(err==MCIERR_OUTOFRANGE,"mci setaudio volume to 1001 returned %s\n", dbg_mcierr(err));
1363 err = mciSendStringA("status mysound mode", buf, sizeof(buf), NULL);
1364 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
1365 ok(!strcmp(buf,"playing"), "mci status mode: %s\n", buf);
1367 err = mciSendStringA("close mysound", NULL, 0, NULL);
1368 ok(!err,"mci close returned %s\n", dbg_mcierr(err));
1370 /* test a second play */
1371 err = mciSendStringA("open tempfile.wav type MPEGVideo alias mysound", NULL, 0, NULL);
1372 ok(err==ok_saved,"mci open tempfile.wav type MPEGVideo returned %s\n", dbg_mcierr(err));
1374 err = mciSendStringA("play mysound", NULL, 0, NULL);
1375 ok(!err,"mci play retuend %s\n", dbg_mcierr(err));
1377 err = mciSendStringA("play mysound", NULL, 0, NULL);
1378 ok(!err,"mci play retuend %s\n", dbg_mcierr(err));
1380 err = mciSendStringA("close mysound", NULL, 0, NULL);
1381 ok(!err,"mci close returned %s\n", dbg_mcierr(err));
1384 static void test_asyncWaveTypeMpegvideo(HWND hwnd)
1386 MCIDEVICEID wDeviceID;
1387 int err;
1388 char buf[1024];
1389 memset(buf, 0, sizeof(buf));
1391 err = mciSendStringA("open tempfile.wav alias mysound notify type mpegvideo", buf, sizeof(buf), hwnd);
1392 ok(err==ok_saved,"mci open tempfile.wav returned %s\n", dbg_mcierr(err));
1393 if(err) {
1394 skip("Cannot open tempfile.wav for playing (%s), skipping\n", dbg_mcierr(err));
1395 return;
1397 ok(!strcmp(buf,"1"), "mci open deviceId: %s, expected 1\n", buf);
1398 wDeviceID = atoi(buf);
1399 ok(wDeviceID,"mci open DeviceID: %d\n", wDeviceID);
1400 test_notification(hwnd,"open alias notify",MCI_NOTIFY_SUCCESSFUL);
1402 err = mciSendStringA("play mysound notify", NULL, 0, hwnd);
1403 ok(!err,"mci play returned %s\n", dbg_mcierr(err));
1405 Sleep(500); /* milliseconds */
1407 err = mciSendStringA("pause mysound wait", NULL, 0, hwnd);
1408 ok(!err,"mci pause wait returned %s\n", dbg_mcierr(err));
1410 err = mciSendStringA("status mysound mode notify", buf, sizeof(buf), hwnd);
1411 ok(!err,"mci status mode returned %s\n", dbg_mcierr(err));
1412 if(!err) ok(!strcmp(buf,"paused"), "mci status mode: %s\n", buf);
1413 test_notification(hwnd,"play (superseded)",MCI_NOTIFY_SUPERSEDED);
1414 test_notification(hwnd,"status",MCI_NOTIFY_SUCCESSFUL);
1416 err = mciSendStringA("seek mysound to start wait", NULL, 0, NULL);
1417 ok(!err,"mci seek to start wait returned %s\n", dbg_mcierr(err));
1419 err = mciSendStringA("set mysound time format milliseconds", NULL, 0, NULL);
1420 ok(!err,"mci time format milliseconds returned %s\n", dbg_mcierr(err));
1422 err = mciSendStringA("play mysound to 1500 notify", NULL, 0, hwnd);
1423 ok(!err,"mci play returned %s\n", dbg_mcierr(err));
1424 Sleep(200);
1425 test_notification(hwnd,"play",0);
1427 err = mciSendStringA("window mysound state hide", NULL, 0, NULL);
1428 ok(err == MCIERR_NO_WINDOW, "mci window state returned %s\n", dbg_mcierr(err));
1430 err = mciSendStringA("window mysound text abracadabra", NULL, 0, NULL);
1431 todo_wine ok(err == MCIERR_NO_WINDOW, "mci window text returned %s\n", dbg_mcierr(err));
1433 err = mciSendStringA("close mysound wait", NULL, 0, NULL);
1434 ok(!err,"mci close wait returned %s\n", dbg_mcierr(err));
1435 test_notification(hwnd,"play (aborted by close)",MCI_NOTIFY_ABORTED);
1438 static DWORD CALLBACK thread_cb(void *p)
1440 HANDLE evt = p;
1441 MCIERROR mr;
1443 mr = mciSendStringA("play x", NULL, 0, NULL);
1444 ok(mr == MCIERR_INVALID_DEVICE_NAME, "play gave: 0x%lx\n", mr);
1446 mr = mciSendStringA("close x", NULL, 0, NULL);
1447 ok(mr == MCIERR_INVALID_DEVICE_NAME, "close gave: 0x%lx\n", mr);
1449 SetEvent(evt);
1451 return 0;
1454 static void test_threads(void)
1456 MCIERROR mr;
1457 HANDLE evt;
1459 mr = mciSendStringA("open tempfile.wav alias x", NULL, 0, NULL);
1460 ok(mr == 0 || mr == ok_saved, "open gave: 0x%lx\n", mr);
1461 if(mr){
1462 skip("Cannot open tempfile.wav for playing (%s), skipping\n", dbg_mcierr(mr));
1463 return;
1466 evt = CreateEventW( NULL, TRUE, FALSE, NULL );
1468 CloseHandle(CreateThread(NULL, 0, &thread_cb, evt, 0, NULL));
1470 WaitForSingleObject(evt, INFINITE);
1472 CloseHandle(evt);
1474 mr = mciSendStringA("close x", NULL, 0, NULL);
1475 ok(mr == 0, "close gave: 0x%lx\n", mr);
1478 static BOOL CALLBACK my_visible_window_proc(HWND hwnd, LPARAM param)
1480 HWND *ret = (HWND *)param;
1481 DWORD pid;
1483 GetWindowThreadProcessId(hwnd, &pid);
1484 if (pid != GetCurrentProcessId())
1485 return TRUE;
1487 if (GetWindowLongW(hwnd, GWL_STYLE) & WS_VISIBLE)
1489 *ret = hwnd;
1490 return FALSE;
1493 return TRUE;
1496 static void test_video_window(void)
1498 const WCHAR *filename = load_resource(L"test.mpg");
1499 MCI_PARMS_UNION parm;
1500 WCHAR buffer[256];
1501 unsigned int i;
1502 MCIDEVICEID id;
1503 MCIERROR err;
1504 BOOL ret;
1506 static const struct
1508 DWORD open_flags;
1509 DWORD style;
1510 DWORD expected_style;
1512 testcase[] =
1517 (WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS) & ~WS_MAXIMIZEBOX,
1520 MCI_DGV_OPEN_PARENT,
1522 (WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS) & ~WS_MAXIMIZEBOX,
1525 MCI_DGV_OPEN_WS,
1527 WS_BORDER | WS_CLIPSIBLINGS | WS_BORDER | WS_DLGFRAME,
1530 MCI_DGV_OPEN_WS,
1531 WS_POPUPWINDOW,
1532 WS_POPUPWINDOW | WS_CLIPSIBLINGS,
1535 MCI_DGV_OPEN_PARENT | MCI_DGV_OPEN_WS,
1536 WS_OVERLAPPEDWINDOW,
1537 WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS,
1540 MCI_DGV_OPEN_PARENT | MCI_DGV_OPEN_WS,
1541 WS_CHILDWINDOW,
1542 WS_CHILD,
1546 for (i = 0; i < ARRAY_SIZE(testcase); ++i)
1548 HWND parent_window = NULL, hwnd, video_window, main_window;
1549 DWORD style, expected;
1550 RECT rc, src_rc, win_rc;
1552 winetest_push_context("%u", i);
1554 main_window = CreateWindowExA(0, "static", "main",
1555 WS_POPUPWINDOW, 0, 0, 10, 10, 0, 0, 0, NULL);
1556 if (testcase[i].open_flags & MCI_DGV_OPEN_PARENT)
1557 parent_window = CreateWindowExA(0, "static", "parent",
1558 WS_POPUPWINDOW, 0, 0, 100, 100, 0, 0, 0, NULL);
1560 parm.dgv_open.lpstrDeviceType = (WCHAR *)L"MPEGVideo";
1561 parm.dgv_open.lpstrElementName = (WCHAR *)filename;
1562 parm.dgv_open.hWndParent = parent_window;
1563 parm.dgv_open.dwStyle = testcase[i].style;
1564 err = mciSendCommandW(0, MCI_OPEN,
1565 MCI_OPEN_ELEMENT | MCI_OPEN_TYPE | testcase[i].open_flags, (DWORD_PTR)&parm);
1566 ok(!err, "Got %s.\n", dbg_mcierr(err));
1567 id = parm.dgv_open.wDeviceID;
1569 err = mciSendCommandW(id, MCI_PLAY, 0, (DWORD_PTR)&parm);
1570 ok(!err, "Got %s.\n", dbg_mcierr(err));
1572 if (!(testcase[i].style & WS_CHILD))
1574 video_window = NULL;
1575 EnumWindows(my_visible_window_proc, (LPARAM)&video_window);
1576 ok(video_window != NULL, "Video window should be shown.\n");
1578 hwnd = GetWindow(video_window, GW_OWNER);
1579 ok(hwnd == parent_window, "Got owner %p, expected %p.\n", hwnd, parent_window);
1581 else
1583 ok(!IsWindowVisible(parent_window), "Parent window should be hidden.\n");
1584 ShowWindow(parent_window, SW_SHOWNA);
1586 hwnd = GetWindow(parent_window, GW_CHILD);
1587 ok(hwnd != NULL, "Child video window should be shown.\n");
1588 video_window = hwnd;
1591 expected = testcase[i].expected_style | WS_VISIBLE;
1592 style = GetWindowLongW(video_window, GWL_STYLE);
1593 ok(style == expected, "Got style %#lx for window %p, expected %#lx.\n", style, video_window, expected);
1595 /* Get the source video size. */
1596 err = mciSendCommandW(id, MCI_WHERE, MCI_DGV_WHERE_SOURCE, (DWORD_PTR)&parm);
1597 ok(!err, "Got %s.\n", dbg_mcierr(err));
1598 SetRect(&rc, 0, 0, 32, 24);
1599 ok(EqualRect(&parm.where.rc, &rc), "Got source rect %s, expected %s.\n",
1600 wine_dbgstr_rect(&parm.where.rc), wine_dbgstr_rect(&rc));
1601 src_rc = parm.where.rc;
1603 /* Test the default video destination size. */
1604 err = mciSendCommandW(id, MCI_WHERE, MCI_DGV_WHERE_DESTINATION, (DWORD_PTR)&parm);
1605 ok(!err, "Got %s.\n", dbg_mcierr(err));
1606 if (style & (WS_POPUP | WS_CHILD))
1607 rc = src_rc;
1608 else
1609 /* The video destination is stretched to fit the window,
1610 * in particular if the video width is less than SM_CXMIN. */
1611 GetClientRect(video_window, &rc);
1613 ok(EqualRect(&parm.where.rc, &rc), "Got destination rect %s, expected %s.\n",
1614 wine_dbgstr_rect(&parm.where.rc), wine_dbgstr_rect(&rc));
1616 /* Test the default video window size. */
1617 rc = src_rc;
1618 /* Windows is broken and always uses WS_OVERLAPPEDWINDOW regardless of
1619 * the window's actual style. */
1620 AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE);
1621 OffsetRect(&rc, -rc.left, -rc.top);
1622 rc.right = max(rc.right, GetSystemMetrics(SM_CXMIN));
1624 GetWindowRect(video_window, &win_rc);
1625 OffsetRect(&rc, win_rc.left, win_rc.top);
1626 ok(EqualRect(&rc, &win_rc), "Got window rect %s, expected %s.\n",
1627 wine_dbgstr_rect(&win_rc), wine_dbgstr_rect(&rc));
1629 err = mciSendCommandW(id, MCI_WHERE, MCI_DGV_WHERE_WINDOW, (DWORD_PTR)&parm);
1630 ok(!err, "Got %s.\n", dbg_mcierr(err));
1631 win_rc.right -= win_rc.left;
1632 win_rc.bottom -= win_rc.top;
1633 ok(EqualRect(&win_rc, &parm.where.rc), "Got rect %s, expected %s.\n",
1634 wine_dbgstr_rect(&parm.where.rc), wine_dbgstr_rect(&win_rc));
1636 err = mciSendCommandW(id, MCI_STOP, 0, (DWORD_PTR)&parm);
1637 ok(!err, "Got %s.\n", dbg_mcierr(err));
1639 ok(IsWindowVisible(video_window), "Video window should be visible.\n");
1641 err = mciSendCommandW(id, MCI_PLAY, 0, (DWORD_PTR)&parm);
1642 ok(!err, "Got %s.\n", dbg_mcierr(err));
1644 ok(IsWindowVisible(video_window), "Video window should be visible.\n");
1646 err = mciSendCommandW(id, MCI_SEEK, MCI_SEEK_TO_START, (DWORD_PTR)&parm);
1647 ok(!err, "Got %s.\n", dbg_mcierr(err));
1649 ok(IsWindowVisible(video_window), "Video window should be visible.\n");
1651 /* Test MCI_DGV_WINDOW_HWND. */
1652 parm.win.hWnd = main_window;
1653 err = mciSendCommandW(id, MCI_WINDOW, MCI_DGV_WINDOW_HWND, (DWORD_PTR)&parm);
1654 ok(!err, "Got %s.\n", dbg_mcierr(err));
1655 ok(!IsWindowVisible(main_window), "Main window should be hidden.\n");
1657 hwnd = GetWindow(main_window, GW_CHILD);
1658 ok(hwnd != video_window, "Video window (%p) and child window (%p) should be different.\n",
1659 video_window, hwnd);
1660 style = GetWindowLongW(hwnd, GWL_STYLE);
1661 expected = WS_CHILD | WS_VISIBLE;
1662 ok(style == expected, "Child window %p: got style %#lx, expected %#lx.\n",
1663 hwnd, style, expected);
1665 style = GetWindowLongW(video_window, GWL_STYLE);
1666 expected = testcase[i].expected_style;
1667 ok(style == expected, "Video window %p: got style %#lx, expected %#lx.\n",
1668 video_window, style, expected);
1670 /* destination size is reset to the source video size */
1671 err = mciSendCommandW(id, MCI_WHERE, MCI_DGV_WHERE_DESTINATION, (DWORD_PTR)&parm);
1672 ok(!err, "Got %s.\n", dbg_mcierr(err));
1673 ok(EqualRect(&parm.where.rc, &src_rc), "Got destination rect %s, expected %s.\n",
1674 wine_dbgstr_rect(&parm.where.rc), wine_dbgstr_rect(&src_rc));
1676 /* destination size isn't reset unless the destination window is changed */
1677 SetRect(&rc, 0, 0, src_rc.right * 2, src_rc.bottom / 2);
1678 parm.put.rc = rc;
1679 err = mciSendCommandW(id, MCI_PUT, MCI_DGV_PUT_DESTINATION | MCI_DGV_RECT, (DWORD_PTR)&parm);
1680 ok(!err, "Got %s.\n", dbg_mcierr(err));
1682 parm.win.hWnd = main_window;
1683 err = mciSendCommandW(id, MCI_WINDOW, MCI_DGV_WINDOW_HWND, (DWORD_PTR)&parm);
1684 ok(!err, "Got %s.\n", dbg_mcierr(err));
1685 ok(!IsWindowVisible(main_window), "Main window should be hidden.\n");
1687 err = mciSendCommandW(id, MCI_WHERE, MCI_DGV_WHERE_DESTINATION, (DWORD_PTR)&parm);
1688 ok(!err, "Got %s.\n", dbg_mcierr(err));
1689 ok(EqualRect(&parm.where.rc, &rc), "Got destination rect %s, expected %s.\n",
1690 wine_dbgstr_rect(&parm.where.rc), wine_dbgstr_rect(&rc));
1692 /* MCI_PLAY shows current video window */
1693 err = mciSendCommandW(id, MCI_PLAY, 0, (DWORD_PTR)&parm);
1694 ok(!err, "Got %s.\n", dbg_mcierr(err));
1695 ok(IsWindowVisible(main_window), "Main window should be shown.\n");
1696 ok(IsWindow(video_window), "Video window should exist.\n");
1697 ok(!IsWindowVisible(video_window), "Video window should be hidden.\n");
1699 /* Test MCI_DGV_WINDOW_STATE for the non-default window. */
1700 parm.win.nCmdShow = SW_MINIMIZE;
1701 err = mciSendCommandW(id, MCI_WINDOW, MCI_DGV_WINDOW_STATE, (DWORD_PTR)&parm);
1702 ok(!err, "Got %s.\n", dbg_mcierr(err));
1703 ok(IsIconic(main_window), "Video window should be minimized.\n");
1705 /* Test MCI_DGV_WINDOW_TEXT for the non-default window. */
1706 parm.win.lpstrText = (LPWSTR)L"foobar";
1707 err = mciSendCommandW(id, MCI_WINDOW, MCI_DGV_WINDOW_TEXT, (DWORD_PTR)&parm);
1708 ok(!err, "Got %s.\n", dbg_mcierr(err));
1709 GetWindowTextW(main_window, buffer, ARRAY_SIZE(buffer));
1710 todo_wine ok(!wcscmp(buffer, parm.win.lpstrText), "Got %s, expected %s\n", wine_dbgstr_w(buffer), wine_dbgstr_w(parm.win.lpstrText));
1712 /* video window is reset to the default window, which is visible again */
1713 parm.win.hWnd = NULL;
1714 err = mciSendCommandW(id, MCI_WINDOW, MCI_DGV_WINDOW_HWND, (DWORD_PTR)&parm);
1715 ok(!err, "Got %s.\n", dbg_mcierr(err));
1716 ok(IsWindowVisible(main_window), "Main window should be shown.\n");
1717 ok(IsWindowVisible(video_window), "Video window should be shown.\n");
1719 err = mciSendCommandW(id, MCI_WHERE, MCI_DGV_WHERE_DESTINATION, (DWORD_PTR)&parm);
1720 ok(!err, "Got %s.\n", dbg_mcierr(err));
1721 ok(EqualRect(&parm.where.rc, &src_rc), "Got destination rect %s, expected %s.\n",
1722 wine_dbgstr_rect(&parm.where.rc), wine_dbgstr_rect(&src_rc));
1724 /* Test MCI_DGV_WINDOW_STATE for the default window. */
1725 parm.win.nCmdShow = SW_MINIMIZE;
1726 err = mciSendCommandW(id, MCI_WINDOW, MCI_DGV_WINDOW_STATE, (DWORD_PTR)&parm);
1727 ok(!err, "Got %s.\n", dbg_mcierr(err));
1728 ok(IsIconic(video_window), "Video window should be minimized.\n");
1730 /* Test MCI_DGV_WINDOW_TEXT for the default window. */
1731 parm.win.lpstrText = (LPWSTR)L"abracadabra";
1732 err = mciSendCommandW(id, MCI_WINDOW, MCI_DGV_WINDOW_TEXT, (DWORD_PTR)&parm);
1733 ok(!err, "Got %s.\n", dbg_mcierr(err));
1734 GetWindowTextW(video_window, buffer, ARRAY_SIZE(buffer));
1735 todo_wine ok(!wcscmp(buffer, parm.win.lpstrText), "Got %s, expected %s\n", wine_dbgstr_w(buffer), wine_dbgstr_w(parm.win.lpstrText));
1737 err = mciSendCommandW(id, MCI_CLOSE, 0, 0);
1738 ok(!err, "Got %s.\n", dbg_mcierr(err));
1740 if (parent_window)
1742 ret = DestroyWindow(parent_window);
1743 ok(ret, "Failed to destroy parent window\n");
1745 DestroyWindow(main_window);
1747 winetest_pop_context();
1750 ret = DeleteFileW(filename);
1751 ok(ret, "Failed to delete %s, error %lu.\n", debugstr_w(filename), GetLastError());
1754 START_TEST(mci)
1756 char curdir[MAX_PATH], tmpdir[MAX_PATH];
1757 MCIERROR err;
1758 HWND hwnd;
1760 GetCurrentDirectoryA(MAX_PATH, curdir);
1761 GetTempPathA(MAX_PATH, tmpdir);
1762 SetCurrentDirectoryA(tmpdir);
1764 hwnd = CreateWindowExA(0, "static", "winmm test", WS_POPUP, 0,0,100,100,
1765 0, 0, 0, NULL);
1766 test_mciParser(hwnd);
1767 test_openCloseWAVE(hwnd);
1768 test_recordWAVE(hwnd);
1769 if(waveOutGetNumDevs()){
1770 test_threads();
1771 test_playWAVE(hwnd);
1772 test_asyncWAVE(hwnd);
1773 test_AutoOpenWAVE(hwnd);
1774 test_playWaveTypeMpegvideo();
1775 test_asyncWaveTypeMpegvideo(hwnd);
1776 }else
1777 skip("No output devices available, skipping all output tests\n");
1779 test_video_window();
1781 /* Win9X hangs when exiting with something still open. */
1782 err = mciSendStringA("close all", NULL, 0, hwnd);
1783 ok(!err,"final close all returned %s\n", dbg_mcierr(err));
1784 ok(DeleteFileA("tempfile.wav") || ok_saved, "Delete tempfile.wav (cause auto-open?)\n");
1785 DestroyWindow(hwnd);
1787 SetCurrentDirectoryA(curdir);