2 * Unit tests for winmm functions
4 * Copyright (c) 2002 Francois Gouget
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "wine/test.h"
26 * Note that in most of this test we may get MMSYSERR_BADDEVICEID errors
27 * at about any time if the user starts another application that uses the
28 * sound device. So we should not report these as test failures.
31 #define TEST_FORMATS 12
32 static const int win_formats[TEST_FORMATS][4]={
33 {WAVE_FORMAT_1M08, 11025, 8, 1},
34 {WAVE_FORMAT_1S08, 11025, 8, 2},
35 {WAVE_FORMAT_1M16, 11025, 16, 1},
36 {WAVE_FORMAT_1S16, 11025, 16, 2},
37 {WAVE_FORMAT_2M08, 22050, 8, 1},
38 {WAVE_FORMAT_2S08, 22050, 8, 2},
39 {WAVE_FORMAT_2M16, 22050, 16, 1},
40 {WAVE_FORMAT_2S16, 22050, 16, 2},
41 {WAVE_FORMAT_4M08, 44100, 8, 1},
42 {WAVE_FORMAT_4S08, 44100, 8, 2},
43 {WAVE_FORMAT_4M16, 44100, 16, 1},
44 {WAVE_FORMAT_4S16, 44100, 16, 2}
56 ndev=waveOutGetNumDevs();
57 winetest_trace("found %d WaveOut devices\n",ndev);
60 rc=waveOutGetDevCapsA(ndev+1,&caps,sizeof(caps));
61 ok(rc==MMSYSERR_BADDEVICEID,
62 "waveOutGetDevCa psA: MMSYSERR_BADDEVICEID expected, got %d",rc);
65 format.wFormatTag=WAVE_FORMAT_PCM;
67 format.wBitsPerSample=16;
68 format.nSamplesPerSec=44100;
69 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
70 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
72 rc=waveOutOpen(&wout,ndev+1,&format,0,0,CALLBACK_NULL);
73 ok(rc==MMSYSERR_BADDEVICEID,
74 "waveOutOpen: MMSYSERR_BADDEVICEID expected, got %d",rc);
76 for (d=0;d<ndev;d++) {
77 rc=waveOutGetDevCapsA(d,&caps,sizeof(caps));
78 success=(rc==MMSYSERR_NOERROR || rc==MMSYSERR_BADDEVICEID);
79 ok(success,"failed to get capabilities of device %d: rc=%d",d,rc);
83 winetest_trace(" %d: \"%s\" %d.%d (%d:%d): channels=%d formats=%04lx support=%04lx\n",
84 d,caps.szPname,caps.vDriverVersion >> 8,
85 caps.vDriverVersion & 0xff,
87 caps.wChannels,caps.dwFormats,caps.dwSupport);
89 for (f=0;f<TEST_FORMATS;f++) {
90 if (!(caps.dwFormats & win_formats[f][0]))
93 format.wFormatTag=WAVE_FORMAT_PCM;
94 format.nChannels=win_formats[f][3];
95 format.wBitsPerSample=win_formats[f][2];
96 format.nSamplesPerSec=win_formats[f][1];
97 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
98 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
101 rc=waveOutOpen(&wout,d,&format,0,0,CALLBACK_NULL);
102 success=(rc==MMSYSERR_NOERROR || rc==MMSYSERR_BADDEVICEID);
103 ok(success, "failed to open device %d: rc=%d",d,rc);
105 ok(format.nChannels==win_formats[f][3] &&
106 format.wBitsPerSample==win_formats[f][2] &&
107 format.nSamplesPerSec==win_formats[f][1],
108 "got the wrong format: %ldx%2dx%d instead of %dx%2dx%d\n",
109 format.nSamplesPerSec, format.wBitsPerSample,
110 format.nChannels, win_formats[f][1], win_formats[f][2],
113 if (rc==MMSYSERR_NOERROR)
116 /* Try again with WAVE_FORMAT_DIRECT */
117 rc=waveOutOpen(&wout,d,&format,0,0,CALLBACK_NULL|WAVE_FORMAT_DIRECT);
118 success=(rc==MMSYSERR_NOERROR || rc==MMSYSERR_BADDEVICEID);
119 ok(success, "failed to open device %d: rc=%d",d,rc);
121 ok(format.nChannels==win_formats[f][3] &&
122 format.wBitsPerSample==win_formats[f][2] &&
123 format.nSamplesPerSec==win_formats[f][1],
124 "got the wrong format: %ldx%2dx%d instead of %dx%2dx%d\n",
125 format.nSamplesPerSec, format.wBitsPerSample,
126 format.nChannels, win_formats[f][1], win_formats[f][2],
129 if (rc==MMSYSERR_NOERROR)
133 /* Check an invalid format to test error handling */
135 winetest_trace("Testing invalid 2MHz format\n");
136 format.wFormatTag=WAVE_FORMAT_PCM;
138 format.wBitsPerSample=16;
139 format.nSamplesPerSec=2000000; /* 2MHz! */
140 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
141 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
143 rc=waveOutOpen(&wout,d,&format,0,0,CALLBACK_NULL);
144 success=(rc==WAVERR_BADFORMAT);
145 ok(success, "opening the device at 2MHz should fail %d: rc=%d",d,rc);
146 if (rc==MMSYSERR_NOERROR) {
147 winetest_trace(" got %ldx%2dx%d for %dx%2dx%d\n",
148 format.nSamplesPerSec, format.wBitsPerSample,
150 win_formats[f][1], win_formats[f][2],
156 format.wFormatTag=WAVE_FORMAT_PCM;
158 format.wBitsPerSample=16;
159 format.nSamplesPerSec=2000000; /* 2MHz! */
160 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
161 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
163 rc=waveOutOpen(&wout,d,&format,0,0,CALLBACK_NULL|WAVE_FORMAT_DIRECT);
164 success=(rc==WAVERR_BADFORMAT);
165 ok(success, "opening the device at 2MHz should fail %d: rc=%d",d,rc);
166 if (rc==MMSYSERR_NOERROR) {
167 winetest_trace(" got %ldx%2dx%d for %dx%2dx%d\n",
168 format.nSamplesPerSec, format.wBitsPerSample,
170 win_formats[f][1], win_formats[f][2],