Fixed bug where last tests were not executed.
[wine] / dlls / dsound / tests / propset.c
1 /*
2  * Unit tests for CLSID_DirectSoundPrivate property set functions (used by dxdiag)
3  *
4  * Copyright (c) 2003 Robert Reif
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #define NONAMELESSSTRUCT
22 #define NONAMELESSUNION
23 #include <windows.h>
24
25 #include <math.h>
26 #include <stdlib.h>
27
28 #include "wine/test.h"
29 #include "dsound.h"
30 #include "dsconf.h"
31
32 typedef HRESULT  (CALLBACK * MYPROC)(REFCLSID, REFIID, LPVOID FAR*);
33
34 BOOL CALLBACK callback(PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_DATA data, LPVOID context)
35 {
36         trace("found device:\n");
37         trace("\tType: %s\n", 
38                 data->Type == DIRECTSOUNDDEVICE_TYPE_EMULATED ? "Emulated" :
39                 data->Type == DIRECTSOUNDDEVICE_TYPE_VXD ? "VxD" :
40                 data->Type == DIRECTSOUNDDEVICE_TYPE_WDM ? "WDM" : "Unknown");
41         trace("\tDataFlow: %s\n",
42                 data->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_RENDER ? "Render" :
43                 data->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE ? "Capture" : "Unknown");
44         trace("\tDeviceId: {%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n",
45                 data->DeviceId.Data1,data->DeviceId.Data2,data->DeviceId.Data3,
46                 data->DeviceId.Data4[0],data->DeviceId.Data4[1],data->DeviceId.Data4[2],data->DeviceId.Data4[3],
47                 data->DeviceId.Data4[4],data->DeviceId.Data4[5],data->DeviceId.Data4[6],data->DeviceId.Data4[7]);
48         trace("\tDescription: %s\n", data->Description);
49         trace("\tModule: %s\n", data->Module);
50         trace("\tInterface: %s\n", data->Interface);
51         trace("\tWaveDeviceId: %ld\n", data->WaveDeviceId);
52
53         return TRUE;
54 }
55
56 static void propset_tests()
57 {
58         HMODULE hDsound;
59         HRESULT hr;
60         IClassFactory   * pcf;
61         IKsPropertySet  * pps;
62         MYPROC fProc;
63         ULONG   support;
64
65         hDsound = LoadLibrary("dsound.dll");
66         ok(hDsound!=0,"LoadLibrary(dsound.dll) failed\n");
67         if (hDsound==0)
68                 return;
69
70         fProc = (MYPROC)GetProcAddress(hDsound, "DllGetClassObject");
71
72         /* try direct sound first */
73         hr = (fProc)(&CLSID_DirectSound, &IID_IClassFactory, (void **)0);
74         ok(hr==DSERR_INVALIDPARAM,"DllGetClassObject(CLSID_DirectSound, IID_IClassFactory) should have failed: 0x%lx\n",hr);
75
76         hr = (fProc)(&CLSID_DirectSound, &IID_IClassFactory, (void **)(&pcf));
77         ok(pcf!=0, "DllGetClassObject(CLSID_DirectSound, IID_IClassFactory) failed: 0x%lx\n",hr);
78         if (pcf==0)
79                 goto error;
80
81         /* direct sound doesn't have an IKsPropertySet */
82         hr = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet, (void **)0);
83         ok(hr==DSERR_INVALIDPARAM, "CreateInstance(IID_IKsPropertySet) should have failed: 0x%lx\n",hr);
84
85         hr = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet, (void **)(&pps));
86         ok(hr==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have failed: 0x%lx\n",hr);
87
88         /* and the direct sound 8 version */
89         hr = (fProc)(&CLSID_DirectSound8, &IID_IClassFactory, (void **)(&pcf));
90         ok(pcf!=0, "DllGetClassObject(CLSID_DirectSound8, IID_IClassFactory) failed: 0x%lx\n",hr);
91         if (pcf==0)
92                 goto error;
93
94         /* direct sound 8 doesn't have an IKsPropertySet */
95         hr = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet, (void **)(&pps));
96         ok(hr==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have failed: 0x%lx\n",hr);
97
98         /* try direct sound capture next */
99         hr = (fProc)(&CLSID_DirectSoundCapture, &IID_IClassFactory, (void **)(&pcf));
100         ok(pcf!=0, "DllGetClassObject(CLSID_DirectSoundCapture, IID_IClassFactory) failed: 0x%lx\n",hr);
101         if (pcf==0)
102                 goto error;
103
104         /* direct sound capture doesn't have an IKsPropertySet */
105         hr = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet, (void **)(&pps));
106         ok(hr==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have failed: 0x%lx\n",hr);
107
108         /* and the direct sound capture 8 version */
109         hr = (fProc)(&CLSID_DirectSoundCapture8, &IID_IClassFactory, (void **)(&pcf));
110         ok(pcf!=0, "DllGetClassObject(CLSID_DirectSoundCapture8, IID_IClassFactory) failed: 0x%lx\n",hr);
111         if (pcf==0)
112                 goto error;
113
114         /* direct sound capture 8 doesn't have an IKsPropertySet */
115         hr = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet, (void **)(&pps));
116         ok(hr==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have failed: 0x%lx\n",hr);
117
118         /* try direct sound full duplex next */
119         hr = (fProc)(&CLSID_DirectSoundFullDuplex, &IID_IClassFactory, (void **)(&pcf));
120         ok(pcf!=0, "DllGetClassObject(CLSID_DirectSoundFullDuplex, IID_IClassFactory) failed: 0x%lx\n",hr);
121         if (pcf==0)
122                 goto error;
123
124         /* direct sound full duplex doesn't have an IKsPropertySet */
125         hr = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet, (void **)(&pps));
126         ok(hr==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have failed: 0x%lx\n",hr);
127
128         /* try direct sound private last */
129         hr = (fProc)(&CLSID_DirectSoundPrivate, &IID_IClassFactory, (void **)(&pcf));
130         ok(pcf!=0, "DllGetClassObject(CLSID_DirectSoundPrivate, IID_IClassFactory) failed: 0x%lx\n",hr);
131         if (pcf==0)
132                 goto error;
133
134         /* direct sound private does have an IKsPropertySet */
135         hr = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet, (void **)(&pps));
136         ok(hr==DS_OK, "CreateInstance(IID_IKsPropertySet) failed: 0x%lx\n",hr);
137         if (hr!=DS_OK)
138                 goto error;
139
140         hr = pps->lpVtbl->QuerySupport(pps, &DSPROPSETID_DirectSoundDevice, DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION, &support);
141         ok(hr==DS_OK, "QuerySupport(DSPROPSETID_DirectSoundDevice, DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION) failed: 0x%lx\n",hr);
142         if (hr!=DS_OK)
143                 goto error;
144
145         ok (support & KSPROPERTY_SUPPORT_GET, "Couldn't get DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION: support = 0x%lx\n",support);
146         ok (!(support & KSPROPERTY_SUPPORT_SET), "Shouldn't be able to set DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION: support = 0x%lx\n",support);
147
148         hr = pps->lpVtbl->QuerySupport(pps, &DSPROPSETID_DirectSoundDevice, DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING, &support);
149         ok(hr==DS_OK, "QuerySupport(DSPROPSETID_DirectSoundDevice, DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING) failed: 0x%lx\n",hr);
150         if (hr!=DS_OK)
151                 goto error;
152
153         ok (support & KSPROPERTY_SUPPORT_GET, "Couldn't get DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING: support = 0x%lx\n",support);
154         ok (!(support & KSPROPERTY_SUPPORT_SET), "Shouldn't be able to set DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING: support = 0x%lx\n",support);
155
156         hr = pps->lpVtbl->QuerySupport(pps, &DSPROPSETID_DirectSoundDevice, DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE, &support);
157         ok(hr==DS_OK, "QuerySupport(DSPROPSETID_DirectSoundDevice, DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE) failed: 0x%lx\n",hr);
158         if (hr!=DS_OK)
159                 goto error;
160
161         ok (support & KSPROPERTY_SUPPORT_GET, "Couldn't get DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE: support = 0x%lx\n",support);
162         ok (!(support & KSPROPERTY_SUPPORT_SET), "Shouldn't be able to set DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE: support = 0x%lx\n",support);
163
164         if (support & KSPROPERTY_SUPPORT_GET)
165         {
166                 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_DATA data;
167                 ULONG bytes;
168
169                 data.Callback = callback;
170                 data.Context = 0;
171
172                 hr = pps->lpVtbl->Get(pps, &DSPROPSETID_DirectSoundDevice, 
173                                           DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE,
174                                           NULL,
175                                           0,
176                                           &data, 
177                                           sizeof(data), 
178                                           &bytes);
179                 ok(hr==DS_OK, "Couldn't enumerate: 0x%lx\n",hr);
180         }
181
182 error:
183         FreeLibrary(hDsound);
184 }
185
186 START_TEST(propset)
187 {
188     propset_tests();
189 }