winmm/tests: Remove uninteresting tests.
[wine] / dlls / winmm / tests / capture.c
1 /*
2  * Test winmm sound capture in each sound format
3  *
4  * Copyright (c) 2002 Francois Gouget
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <math.h>
25
26 #include "wine/test.h"
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winnls.h"
30 #include "mmsystem.h"
31 #define NOBITMAP
32 #include "mmreg.h"
33
34 extern GUID KSDATAFORMAT_SUBTYPE_PCM;
35 extern GUID KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
36
37 #include "winmm_test.h"
38
39 static const char * wave_in_error(MMRESULT error)
40 {
41     static char msg[1024];
42     static char long_msg[1100];
43     MMRESULT rc;
44
45     rc = waveInGetErrorText(error, msg, sizeof(msg));
46     if (rc != MMSYSERR_NOERROR)
47         sprintf(long_msg, "waveInGetErrorText(%x) failed with error %x", error, rc);
48     else
49         sprintf(long_msg, "%s(%s)", mmsys_error(error), msg);
50     return long_msg;
51 }
52
53 static void check_position(int device, HWAVEIN win, DWORD bytes,
54                            LPWAVEFORMATEX pwfx )
55 {
56     MMTIME mmtime;
57     MMRESULT rc;
58     DWORD returned;
59
60     mmtime.wType = TIME_BYTES;
61     rc=waveInGetPosition(win, &mmtime, sizeof(mmtime));
62     ok(rc==MMSYSERR_NOERROR,
63        "waveInGetPosition(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
64     if (mmtime.wType != TIME_BYTES && winetest_debug > 1)
65         trace("waveInGetPosition(%s): TIME_BYTES not supported, returned %s\n",
66               dev_name(device),wave_time_format(mmtime.wType));
67     returned = time_to_bytes(&mmtime, pwfx);
68     ok(returned == bytes, "waveInGetPosition(%s): returned %d bytes, "
69        "should be %d\n", dev_name(device), returned, bytes);
70
71     mmtime.wType = TIME_SAMPLES;
72     rc=waveInGetPosition(win, &mmtime, sizeof(mmtime));
73     ok(rc==MMSYSERR_NOERROR,
74        "waveInGetPosition(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
75     if (mmtime.wType != TIME_SAMPLES && winetest_debug > 1)
76         trace("waveInGetPosition(%s): TIME_SAMPLES not supported, "
77               "returned %s\n",dev_name(device),wave_time_format(mmtime.wType));
78     returned = time_to_bytes(&mmtime, pwfx);
79     ok(returned == bytes, "waveInGetPosition(%s): returned %d samples, "
80        "should be %d\n", dev_name(device), bytes_to_samples(returned, pwfx),
81        bytes_to_samples(bytes, pwfx));
82
83     mmtime.wType = TIME_MS;
84     rc=waveInGetPosition(win, &mmtime, sizeof(mmtime));
85     ok(rc==MMSYSERR_NOERROR,
86        "waveInGetPosition(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
87     if (mmtime.wType != TIME_MS && winetest_debug > 1)
88         trace("waveInGetPosition(%s): TIME_MS not supported, returned %s\n",
89               dev_name(device), wave_time_format(mmtime.wType));
90     returned = time_to_bytes(&mmtime, pwfx);
91     ok(returned == bytes, "waveInGetPosition(%s): returned %d ms, "
92        "should be %d\n", dev_name(device), bytes_to_ms(returned, pwfx),
93        bytes_to_ms(bytes, pwfx));
94
95     mmtime.wType = TIME_SMPTE;
96     rc=waveInGetPosition(win, &mmtime, sizeof(mmtime));
97     ok(rc==MMSYSERR_NOERROR,
98        "waveInGetPosition(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
99     if (mmtime.wType != TIME_SMPTE && winetest_debug > 1)
100         trace("waveInGetPosition(%s): TIME_SMPTE not supported, returned %s\n",
101               dev_name(device),wave_time_format(mmtime.wType));
102     returned = time_to_bytes(&mmtime, pwfx);
103     ok(returned == bytes, "waveInGetPosition(%s): SMPTE test failed\n",
104        dev_name(device));
105
106     mmtime.wType = TIME_MIDI;
107     rc=waveInGetPosition(win, &mmtime, sizeof(mmtime));
108     ok(rc==MMSYSERR_NOERROR,
109        "waveInGetPosition(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
110     if (mmtime.wType != TIME_MIDI && winetest_debug > 1)
111         trace("waveInGetPosition(%s): TIME_MIDI not supported, returned %s\n",
112               dev_name(device),wave_time_format(mmtime.wType));
113     returned = time_to_bytes(&mmtime, pwfx);
114     ok(returned == bytes, "waveInGetPosition(%s): MIDI test failed\n",
115        dev_name(device));
116
117     mmtime.wType = TIME_TICKS;
118     rc=waveInGetPosition(win, &mmtime, sizeof(mmtime));
119     ok(rc==MMSYSERR_NOERROR,
120        "waveInGetPosition(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
121     if (mmtime.wType != TIME_TICKS && winetest_debug > 1)
122         trace("waveInGetPosition(%s): TIME_TICKS not supported, returned %s\n",
123               dev_name(device),wave_time_format(mmtime.wType));
124     returned = time_to_bytes(&mmtime, pwfx);
125     ok(returned == bytes, "waveInGetPosition(%s): TICKS test failed\n",
126        dev_name(device));
127 }
128
129 static void wave_in_test_deviceIn(int device, LPWAVEFORMATEX pwfx, DWORD format, DWORD flags, LPWAVEINCAPS pcaps)
130 {
131     HWAVEIN win;
132     HANDLE hevent;
133     WAVEHDR frag;
134     MMRESULT rc;
135     DWORD res;
136     WORD nChannels = pwfx->nChannels;
137     WORD wBitsPerSample = pwfx->wBitsPerSample;
138     DWORD nSamplesPerSec = pwfx->nSamplesPerSec;
139
140     hevent=CreateEvent(NULL,FALSE,FALSE,NULL);
141     ok(hevent!=NULL,"CreateEvent(): error=%d\n",GetLastError());
142     if (hevent==NULL)
143         return;
144
145     win=NULL;
146     rc=waveInOpen(&win,device,pwfx,(DWORD_PTR)hevent,0,CALLBACK_EVENT|flags);
147     /* Note: Win9x doesn't know WAVE_FORMAT_DIRECT */
148     ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_BADDEVICEID ||
149        rc==MMSYSERR_NOTENABLED || rc==MMSYSERR_NODRIVER ||
150        rc==MMSYSERR_ALLOCATED ||
151        ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
152        (flags & WAVE_FORMAT_DIRECT) && !(pcaps->dwFormats & format)) ||
153        ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
154        (!(flags & WAVE_FORMAT_DIRECT) || (flags & WAVE_MAPPED)) &&
155        !(pcaps->dwFormats & format)) ||
156        (rc==MMSYSERR_INVALFLAG && (flags & WAVE_FORMAT_DIRECT)),
157        "waveInOpen(%s): format=%dx%2dx%d flags=%lx(%s) rc=%s\n",
158        dev_name(device),pwfx->nSamplesPerSec,pwfx->wBitsPerSample,
159        pwfx->nChannels,CALLBACK_EVENT|flags,
160        wave_open_flags(CALLBACK_EVENT|flags),wave_in_error(rc));
161     if ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
162        (flags & WAVE_FORMAT_DIRECT) && (pcaps->dwFormats & format))
163         trace(" Reason: The device lists this format as supported in it's "
164               "capabilities but opening it failed.\n");
165     if ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
166        !(pcaps->dwFormats & format))
167         trace("waveInOpen(%s): format=%dx%2dx%d %s rc=%s failed but format "
168               "not supported so OK.\n",dev_name(device),pwfx->nSamplesPerSec,
169               pwfx->wBitsPerSample,pwfx->nChannels,
170               flags & WAVE_FORMAT_DIRECT ? "flags=WAVE_FORMAT_DIRECT" :
171               flags & WAVE_MAPPED ? "flags=WAVE_MAPPED" : "", mmsys_error(rc));
172     if (rc!=MMSYSERR_NOERROR) {
173         CloseHandle(hevent);
174         return;
175     }
176     res=WaitForSingleObject(hevent,1000);
177     ok(res==WAIT_OBJECT_0,"WaitForSingleObject failed for open\n");
178
179     ok(pwfx->nChannels==nChannels &&
180        pwfx->wBitsPerSample==wBitsPerSample &&
181        pwfx->nSamplesPerSec==nSamplesPerSec,
182        "got the wrong format: %dx%2dx%d instead of %dx%2dx%d\n",
183        pwfx->nSamplesPerSec, pwfx->wBitsPerSample,
184        pwfx->nChannels, nSamplesPerSec, wBitsPerSample, nChannels);
185
186     /* Check that the position is 0 at start */
187     check_position(device, win, 0, pwfx);
188
189     frag.lpData=HeapAlloc(GetProcessHeap(), 0, pwfx->nAvgBytesPerSec);
190     frag.dwBufferLength=pwfx->nAvgBytesPerSec;
191     frag.dwBytesRecorded=0;
192     frag.dwUser=0;
193     frag.dwFlags=0;
194     frag.dwLoops=0;
195     frag.lpNext=0;
196
197     rc=waveInPrepareHeader(win, &frag, sizeof(frag));
198     ok(rc==MMSYSERR_NOERROR, "waveInPrepareHeader(%s): rc=%s\n",
199        dev_name(device),wave_in_error(rc));
200     ok(frag.dwFlags&WHDR_PREPARED,"waveInPrepareHeader(%s): prepared flag "
201        "not set\n",dev_name(device));
202
203     if (winetest_interactive && rc==MMSYSERR_NOERROR) {
204         trace("Recording for 1 second at %5dx%2dx%d %s %s\n",
205               pwfx->nSamplesPerSec, pwfx->wBitsPerSample,pwfx->nChannels,
206               get_format_str(pwfx->wFormatTag),
207               flags & WAVE_FORMAT_DIRECT ? "WAVE_FORMAT_DIRECT" :
208               flags & WAVE_MAPPED ? "WAVE_MAPPED" : "");
209         rc=waveInAddBuffer(win, &frag, sizeof(frag));
210         ok(rc==MMSYSERR_NOERROR,"waveInAddBuffer(%s): rc=%s\n",
211            dev_name(device),wave_in_error(rc));
212
213         /* Check that the position is 0 at start */
214         check_position(device, win, 0, pwfx);
215
216         rc=waveInStart(win);
217         ok(rc==MMSYSERR_NOERROR,"waveInStart(%s): rc=%s\n",
218            dev_name(device),wave_in_error(rc));
219
220         res = WaitForSingleObject(hevent,1200);
221         ok(res==WAIT_OBJECT_0,"WaitForSingleObject failed for header\n");
222         ok(frag.dwFlags&WHDR_DONE,"WHDR_DONE not set in frag.dwFlags\n");
223         ok(frag.dwBytesRecorded==pwfx->nAvgBytesPerSec,
224            "frag.dwBytesRecorded=%d, should=%d\n",
225            frag.dwBytesRecorded,pwfx->nAvgBytesPerSec);
226
227         /* stop playing on error */
228         if (res!=WAIT_OBJECT_0) {
229             rc=waveInStop(win);
230             ok(rc==MMSYSERR_NOERROR,
231                "waveInStop(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
232         }
233     }
234
235     rc=waveInUnprepareHeader(win, &frag, sizeof(frag));
236     ok(rc==MMSYSERR_NOERROR,"waveInUnprepareHeader(%s): rc=%s\n",
237        dev_name(device),wave_in_error(rc));
238
239     rc=waveInClose(win);
240     ok(rc==MMSYSERR_NOERROR,
241        "waveInClose(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
242     res=WaitForSingleObject(hevent,1000);
243     ok(res==WAIT_OBJECT_0,"WaitForSingleObject failed for close\n");
244
245     if (winetest_interactive)
246     {
247         /*
248          * Now play back what we recorded
249          */
250         HWAVEOUT wout;
251
252         trace("Playing back recorded sound\n");
253         rc=waveOutOpen(&wout,WAVE_MAPPER,pwfx,(DWORD_PTR)hevent,0,CALLBACK_EVENT);
254         ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_BADDEVICEID ||
255            rc==MMSYSERR_NOTENABLED || rc==MMSYSERR_NODRIVER ||
256            rc==MMSYSERR_ALLOCATED ||
257            ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
258             !(pcaps->dwFormats & format)),
259            "waveOutOpen(%s) format=%dx%2dx%d flags=%lx(%s) rc=%s\n",
260            dev_name(device),pwfx->nSamplesPerSec,pwfx->wBitsPerSample,
261            pwfx->nChannels,CALLBACK_EVENT|flags,
262            wave_open_flags(CALLBACK_EVENT),wave_out_error(rc));
263         if (rc==MMSYSERR_NOERROR)
264         {
265             rc=waveOutPrepareHeader(wout, &frag, sizeof(frag));
266             ok(rc==MMSYSERR_NOERROR,"waveOutPrepareHeader(%s): rc=%s\n",
267                dev_name(device),wave_out_error(rc));
268
269             if (rc==MMSYSERR_NOERROR)
270             {
271                 WaitForSingleObject(hevent,INFINITE);
272                 rc=waveOutWrite(wout, &frag, sizeof(frag));
273                 ok(rc==MMSYSERR_NOERROR,"waveOutWrite(%s): rc=%s\n",
274                    dev_name(device),wave_out_error(rc));
275                 WaitForSingleObject(hevent,INFINITE);
276
277                 rc=waveOutUnprepareHeader(wout, &frag, sizeof(frag));
278                 ok(rc==MMSYSERR_NOERROR,"waveOutUnprepareHeader(%s): rc=%s\n",
279                    dev_name(device),wave_out_error(rc));
280             }
281             rc=waveOutClose(wout);
282             ok(rc==MMSYSERR_NOERROR,"waveOutClose(%s): rc=%s\n",
283                dev_name(device),wave_out_error(rc));
284         }
285         else
286             trace("Unable to play back the recorded sound\n");
287     }
288
289     HeapFree(GetProcessHeap(), 0, frag.lpData);
290     CloseHandle(hevent);
291 }
292
293 static void wave_in_test_device(UINT_PTR device)
294 {
295     WAVEINCAPSA capsA;
296     WAVEINCAPSW capsW;
297     WAVEFORMATEX format;
298     WAVEFORMATEXTENSIBLE wfex;
299     HWAVEIN win;
300     MMRESULT rc;
301     UINT f;
302     WCHAR * nameW;
303     CHAR * nameA;
304     DWORD size;
305     DWORD dwPageSize;
306     BYTE * twoPages;
307     SYSTEM_INFO sSysInfo;
308     DWORD flOldProtect;
309     BOOL res;
310
311     GetSystemInfo(&sSysInfo);
312     dwPageSize = sSysInfo.dwPageSize;
313
314     rc=waveInGetDevCapsA(device,&capsA,sizeof(capsA));
315     ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_BADDEVICEID ||
316        rc==MMSYSERR_NODRIVER,
317        "waveInGetDevCapsA(%s): failed to get capabilities: rc=%s\n",
318        dev_name(device),wave_in_error(rc));
319     if (rc==MMSYSERR_BADDEVICEID || rc==MMSYSERR_NODRIVER)
320         return;
321
322     rc=waveInGetDevCapsW(device,&capsW,sizeof(capsW));
323     ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NOTSUPPORTED,
324        "waveInGetDevCapsW(%s): MMSYSERR_NOERROR or MMSYSERR_NOTSUPPORTED "
325        "expected, got %s\n",dev_name(device),wave_in_error(rc));
326
327     rc=waveInGetDevCapsA(device,NULL,sizeof(capsA));
328     ok(rc==MMSYSERR_INVALPARAM,
329        "waveInGetDevCapsA(%s): MMSYSERR_INVALPARAM expected, got %s\n",
330        dev_name(device),wave_in_error(rc));
331
332     rc=waveInGetDevCapsW(device,NULL,sizeof(capsW));
333     ok(rc==MMSYSERR_INVALPARAM || rc==MMSYSERR_NOTSUPPORTED,
334        "waveInGetDevCapsW(%s): MMSYSERR_INVALPARAM or MMSYSERR_NOTSUPPORTED "
335        "expected, got %s\n",dev_name(device),wave_in_error(rc));
336
337     if (0)
338     {
339     /* FIXME: this works on windows but crashes wine */
340     rc=waveInGetDevCapsA(device,(LPWAVEINCAPSA)1,sizeof(capsA));
341     ok(rc==MMSYSERR_INVALPARAM,
342        "waveInGetDevCapsA(%s): MMSYSERR_INVALPARAM expected, got %s\n",
343        dev_name(device),wave_in_error(rc));
344
345     rc=waveInGetDevCapsW(device,(LPWAVEINCAPSW)1,sizeof(capsW));
346     ok(rc==MMSYSERR_INVALPARAM ||  rc==MMSYSERR_NOTSUPPORTED,
347        "waveInGetDevCapsW(%s): MMSYSERR_INVALPARAM or MMSYSERR_NOTSUPPORTED "
348        "expected, got %s\n",dev_name(device),wave_in_error(rc));
349     }
350
351     rc=waveInGetDevCapsA(device,&capsA,4);
352     ok(rc==MMSYSERR_NOERROR,
353        "waveInGetDevCapsA(%s): MMSYSERR_NOERROR expected, got %s\n",
354        dev_name(device),wave_in_error(rc));
355
356     rc=waveInGetDevCapsW(device,&capsW,4);
357     ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NOTSUPPORTED ||
358        rc==MMSYSERR_INVALPARAM, /* Vista, W2K8 */
359        "waveInGetDevCapsW(%s): unexpected return value %s\n",
360        dev_name(device),wave_in_error(rc));
361
362     nameA=NULL;
363     rc=waveInMessage((HWAVEIN)device, DRV_QUERYDEVICEINTERFACESIZE,
364                      (DWORD_PTR)&size, 0);
365     ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_INVALPARAM ||
366        rc==MMSYSERR_NOTSUPPORTED,
367        "waveInMessage(%s): failed to get interface size: rc=%s\n",
368        dev_name(device),wave_in_error(rc));
369     if (rc==MMSYSERR_NOERROR) {
370         nameW = HeapAlloc(GetProcessHeap(), 0, size);
371         rc=waveInMessage((HWAVEIN)device, DRV_QUERYDEVICEINTERFACE,
372                          (DWORD_PTR)nameW, size);
373         ok(rc==MMSYSERR_NOERROR,"waveInMessage(%s): failed to get interface "
374            "name: rc=%s\n",dev_name(device),wave_in_error(rc));
375         ok(lstrlenW(nameW)+1==size/sizeof(WCHAR),
376            "got an incorrect size %d\n", size);
377         if (rc==MMSYSERR_NOERROR) {
378             nameA = HeapAlloc(GetProcessHeap(), 0, size/sizeof(WCHAR));
379             WideCharToMultiByte(CP_ACP, 0, nameW, size/sizeof(WCHAR),
380                                 nameA, size/sizeof(WCHAR), NULL, NULL);
381         }
382         HeapFree(GetProcessHeap(), 0, nameW);
383     } else if (rc==MMSYSERR_NOTSUPPORTED) {
384         nameA=HeapAlloc(GetProcessHeap(), 0, sizeof("not supported"));
385         strcpy(nameA, "not supported");
386     }
387
388     trace("  %s: \"%s\" (%s) %d.%d (%d:%d)\n",dev_name(device),capsA.szPname,
389           (nameA?nameA:"failed"),capsA.vDriverVersion >> 8,
390           capsA.vDriverVersion & 0xff,capsA.wMid,capsA.wPid);
391     trace("     channels=%d formats=%05x\n",
392           capsA.wChannels,capsA.dwFormats);
393
394     HeapFree(GetProcessHeap(), 0, nameA);
395
396     for (f=0;f<NB_WIN_FORMATS;f++) {
397         format.wFormatTag=WAVE_FORMAT_PCM;
398         format.nChannels=win_formats[f][3];
399         format.wBitsPerSample=win_formats[f][2];
400         format.nSamplesPerSec=win_formats[f][1];
401         format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
402         format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
403         format.cbSize=0;
404         wave_in_test_deviceIn(device,&format,win_formats[f][0],0, &capsA);
405         if (device != WAVE_MAPPER) {
406             wave_in_test_deviceIn(device,&format,win_formats[f][0],
407                                   WAVE_FORMAT_DIRECT, &capsA);
408             wave_in_test_deviceIn(device,&format,win_formats[f][0],
409                                   WAVE_MAPPED, &capsA);
410         }
411     }
412
413     /* Try a PCMWAVEFORMAT aligned next to an unaccessible page for bounds
414      * checking */
415     twoPages = VirtualAlloc(NULL, 2 * dwPageSize, MEM_RESERVE | MEM_COMMIT,
416                             PAGE_READWRITE);
417     ok(twoPages!=NULL,"Failed to allocate 2 pages of memory\n");
418     if (twoPages) {
419         res = VirtualProtect(twoPages + dwPageSize, dwPageSize, PAGE_NOACCESS,
420                              &flOldProtect);
421         ok(res, "Failed to set memory access on second page\n");
422         if (res) {
423             LPWAVEFORMATEX pwfx = (LPWAVEFORMATEX)(twoPages + dwPageSize -
424                 sizeof(PCMWAVEFORMAT));
425             pwfx->wFormatTag=WAVE_FORMAT_PCM;
426             pwfx->nChannels=1;
427             pwfx->wBitsPerSample=8;
428             pwfx->nSamplesPerSec=22050;
429             pwfx->nBlockAlign=pwfx->nChannels*pwfx->wBitsPerSample/8;
430             pwfx->nAvgBytesPerSec=pwfx->nSamplesPerSec*pwfx->nBlockAlign;
431             wave_in_test_deviceIn(device,pwfx,WAVE_FORMAT_2M08,0, &capsA);
432             if (device != WAVE_MAPPER) {
433                 wave_in_test_deviceIn(device,pwfx,WAVE_FORMAT_2M08,
434                     WAVE_FORMAT_DIRECT, &capsA);
435                 wave_in_test_deviceIn(device,pwfx,WAVE_FORMAT_2M08,
436                                       WAVE_MAPPED, &capsA);
437             }
438         }
439         VirtualFree(twoPages, 2 * dwPageSize, MEM_RELEASE);
440     }
441
442     /* test non PCM formats */
443     format.wFormatTag=WAVE_FORMAT_MULAW;
444     format.nChannels=1;
445     format.wBitsPerSample=8;
446     format.nSamplesPerSec=8000;
447     format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
448     format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
449     format.cbSize=0;
450     rc=waveInOpen(&win,device,&format,0,0,CALLBACK_NULL|WAVE_FORMAT_DIRECT);
451     ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
452        rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
453        "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
454     if (rc==MMSYSERR_NOERROR) {
455         waveInClose(win);
456         wave_in_test_deviceIn(device,&format,0,0,&capsA);
457     } else
458         trace("waveInOpen(%s): WAVE_FORMAT_MULAW not supported\n",
459               dev_name(device));
460
461     format.wFormatTag=WAVE_FORMAT_ADPCM;
462     format.nChannels=2;
463     format.wBitsPerSample=4;
464     format.nSamplesPerSec=22050;
465     format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
466     format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
467     format.cbSize=0;
468     rc=waveInOpen(&win,device,&format,0,0,CALLBACK_NULL|WAVE_FORMAT_DIRECT);
469     ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
470        rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
471        "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
472     if (rc==MMSYSERR_NOERROR) {
473         waveInClose(win);
474         wave_in_test_deviceIn(device,&format,0,0,&capsA);
475     } else
476         trace("waveInOpen(%s): WAVE_FORMAT_ADPCM not supported\n",
477               dev_name(device));
478
479     /* test if WAVEFORMATEXTENSIBLE supported */
480     wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
481     wfex.Format.nChannels=2;
482     wfex.Format.wBitsPerSample=16;
483     wfex.Format.nSamplesPerSec=22050;
484     wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
485     wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
486         wfex.Format.nBlockAlign;
487     wfex.Format.cbSize=22;
488     wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
489     wfex.dwChannelMask=SPEAKER_ALL;
490     wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
491     rc=waveInOpen(&win,device,&wfex.Format,0,0,
492                   CALLBACK_NULL|WAVE_FORMAT_DIRECT);
493     ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
494        rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
495        "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
496     if (rc==MMSYSERR_NOERROR) {
497         waveInClose(win);
498         wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
499     } else
500         trace("waveInOpen(%s): WAVE_FORMAT_EXTENSIBLE not supported\n",
501               dev_name(device));
502
503     /* test if 4 channels supported */
504     wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
505     wfex.Format.nChannels=4;
506     wfex.Format.wBitsPerSample=16;
507     wfex.Format.nSamplesPerSec=22050;
508     wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
509     wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
510         wfex.Format.nBlockAlign;
511     wfex.Format.cbSize=22;
512     wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
513     wfex.dwChannelMask=SPEAKER_ALL;
514     wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
515     rc=waveInOpen(&win,device,&wfex.Format,0,0,
516                   CALLBACK_NULL|WAVE_FORMAT_DIRECT);
517     ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
518        rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
519        "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
520     if (rc==MMSYSERR_NOERROR) {
521         waveInClose(win);
522         wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
523     } else
524         trace("waveInOpen(%s): 4 channels not supported\n",
525               dev_name(device));
526
527     /* test if 6 channels supported */
528     wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
529     wfex.Format.nChannels=6;
530     wfex.Format.wBitsPerSample=16;
531     wfex.Format.nSamplesPerSec=22050;
532     wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
533     wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
534         wfex.Format.nBlockAlign;
535     wfex.Format.cbSize=22;
536     wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
537     wfex.dwChannelMask=SPEAKER_ALL;
538     wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
539     rc=waveInOpen(&win,device,&wfex.Format,0,0,
540                   CALLBACK_NULL|WAVE_FORMAT_DIRECT);
541     ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
542        rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
543        "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
544     if (rc==MMSYSERR_NOERROR) {
545         waveInClose(win);
546         wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
547     } else
548         trace("waveInOpen(%s): 6 channels not supported\n",
549               dev_name(device));
550
551     if (0)
552     {
553     /* FIXME: ALSA doesn't like this */
554     /* test if 24 bit samples supported */
555     wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
556     wfex.Format.nChannels=2;
557     wfex.Format.wBitsPerSample=24;
558     wfex.Format.nSamplesPerSec=22050;
559     wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
560     wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
561         wfex.Format.nBlockAlign;
562     wfex.Format.cbSize=22;
563     wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
564     wfex.dwChannelMask=SPEAKER_ALL;
565     wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
566     rc=waveInOpen(&win,device,&wfex.Format,0,0,
567                   CALLBACK_NULL|WAVE_FORMAT_DIRECT);
568     ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
569        rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
570        "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
571     if (rc==MMSYSERR_NOERROR) {
572         waveInClose(win);
573         wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
574     } else
575         trace("waveInOpen(%s): 24 bit samples not supported\n",
576               dev_name(device));
577     }
578
579     /* test if 32 bit samples supported */
580     wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
581     wfex.Format.nChannels=2;
582     wfex.Format.wBitsPerSample=32;
583     wfex.Format.nSamplesPerSec=22050;
584     wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
585     wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
586         wfex.Format.nBlockAlign;
587     wfex.Format.cbSize=22;
588     wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
589     wfex.dwChannelMask=SPEAKER_ALL;
590     wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
591     rc=waveInOpen(&win,device,&wfex.Format,0,0,
592                   CALLBACK_NULL|WAVE_FORMAT_DIRECT);
593     ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
594        rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
595        "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
596     if (rc==MMSYSERR_NOERROR) {
597         waveInClose(win);
598         wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
599     } else
600         trace("waveInOpen(%s): 32 bit samples not supported\n",
601               dev_name(device));
602
603     /* test if 32 bit float samples supported */
604     wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
605     wfex.Format.nChannels=2;
606     wfex.Format.wBitsPerSample=32;
607     wfex.Format.nSamplesPerSec=22050;
608     wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
609     wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
610         wfex.Format.nBlockAlign;
611     wfex.Format.cbSize=22;
612     wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
613     wfex.dwChannelMask=SPEAKER_ALL;
614     wfex.SubFormat=KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
615     rc=waveInOpen(&win,device,&wfex.Format,0,0,
616                   CALLBACK_NULL|WAVE_FORMAT_DIRECT);
617     ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
618        rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
619        "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
620     if (rc==MMSYSERR_NOERROR) {
621         waveInClose(win);
622         wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
623     } else
624         trace("waveInOpen(%s): 32 bit float samples not supported\n",
625               dev_name(device));
626 }
627
628 static void wave_in_tests(void)
629 {
630     WAVEINCAPSA capsA;
631     WAVEINCAPSW capsW;
632     WAVEFORMATEX format;
633     HWAVEIN win;
634     MMRESULT rc;
635     UINT ndev,d;
636
637     ndev=waveInGetNumDevs();
638     trace("found %d WaveIn devices\n",ndev);
639
640     rc=waveInGetDevCapsA(ndev+1,&capsA,sizeof(capsA));
641     ok(rc==MMSYSERR_BADDEVICEID,
642        "waveInGetDevCapsA(%s): MMSYSERR_BADDEVICEID expected, got %s\n",
643        dev_name(ndev+1),wave_in_error(rc));
644
645     rc=waveInGetDevCapsA(WAVE_MAPPER,&capsA,sizeof(capsA));
646     ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NODRIVER || (!ndev && (rc==MMSYSERR_BADDEVICEID)),
647        "waveInGetDevCapsA(%s): got %s\n",dev_name(WAVE_MAPPER),wave_in_error(rc));
648
649     rc=waveInGetDevCapsW(ndev+1,&capsW,sizeof(capsW));
650     ok(rc==MMSYSERR_BADDEVICEID || rc==MMSYSERR_NOTSUPPORTED,
651        "waveInGetDevCapsW(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NOTSUPPORTED "
652        "expected, got %s\n",dev_name(ndev+1),wave_in_error(rc));
653
654     rc=waveInGetDevCapsW(WAVE_MAPPER,&capsW,sizeof(capsW));
655     ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NODRIVER ||
656        rc==MMSYSERR_NOTSUPPORTED || (!ndev && (rc==MMSYSERR_BADDEVICEID)),
657        "waveInGetDevCapsW(%s): got %s\n", dev_name(ndev+1),wave_in_error(rc));
658
659     format.wFormatTag=WAVE_FORMAT_PCM;
660     format.nChannels=2;
661     format.wBitsPerSample=16;
662     format.nSamplesPerSec=44100;
663     format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
664     format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
665     format.cbSize=0;
666     rc=waveInOpen(&win,ndev+1,&format,0,0,CALLBACK_NULL);
667     ok(rc==MMSYSERR_BADDEVICEID,
668        "waveInOpen(%s): MMSYSERR_BADDEVICEID expected, got %s\n",
669        dev_name(ndev+1),wave_in_error(rc));
670
671     for (d=0;d<ndev;d++)
672         wave_in_test_device(d);
673
674     if (ndev>0)
675         wave_in_test_device(WAVE_MAPPER);
676 }
677
678 START_TEST(capture)
679 {
680     wave_in_tests();
681 }