2 * Copyright 2010 Maarten Lankhorst for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define NONAMELESSUNION
20 #include "wine/test.h"
30 #include "mmdeviceapi.h"
33 static BOOL (WINAPI
*pIsWow64Process
)(HANDLE
, BOOL
*);
35 static const WCHAR software_renderW
[] =
36 L
"Software\\Microsoft\\Windows\\CurrentVersion\\MMDevices\\Audio\\Render";
39 static void test_propertystore(IPropertyStore
*store
)
44 temp
[sizeof(temp
)-1] = 0;
47 hr
= IPropertyStore_GetValue(store
, &PKEY_AudioEndpoint_GUID
, &pv
);
48 ok(hr
== S_OK
, "Failed with %08x\n", hr
);
49 ok(pv
.vt
== VT_LPWSTR
, "Value should be %i, is %i\n", VT_LPWSTR
, pv
.vt
);
50 if (hr
== S_OK
&& pv
.vt
== VT_LPWSTR
)
52 WideCharToMultiByte(CP_ACP
, 0, pv
.pwszVal
, -1, temp
, sizeof(temp
)-1, NULL
, NULL
);
53 trace("guid: %s\n", temp
);
54 PropVariantClear(&pv
);
58 hr
= IPropertyStore_GetValue(store
, (const PROPERTYKEY
*)&DEVPKEY_DeviceInterface_FriendlyName
, &pv
);
59 ok(hr
== S_OK
, "Failed with %08x\n", hr
);
60 ok(pv
.vt
== VT_LPWSTR
&& pv
.pwszVal
, "FriendlyName value had wrong type: 0x%x or was NULL\n", pv
.vt
);
61 PropVariantClear(&pv
);
64 hr
= IPropertyStore_GetValue(store
, (const PROPERTYKEY
*)&DEVPKEY_DeviceInterface_Enabled
, &pv
);
65 ok(hr
== S_OK
, "Failed with %08x\n", hr
);
66 ok(pv
.vt
== VT_EMPTY
, "Key should not be found\n");
67 PropVariantClear(&pv
);
70 hr
= IPropertyStore_GetValue(store
, (const PROPERTYKEY
*)&DEVPKEY_DeviceInterface_ClassGuid
, &pv
);
71 ok(hr
== S_OK
, "Failed with %08x\n", hr
);
72 ok(pv
.vt
== VT_EMPTY
, "Key should not be found\n");
73 PropVariantClear(&pv
);
76 static void test_deviceinterface(IPropertyStore
*store
)
81 static const PROPERTYKEY deviceinterface_key
= {
82 {0x233164c8, 0x1b2c, 0x4c7d, {0xbc, 0x68, 0xb6, 0x71, 0x68, 0x7a, 0x25, 0x67}}, 1
86 hr
= IPropertyStore_GetValue(store
, &deviceinterface_key
, &pv
);
87 ok(hr
== S_OK
, "GetValue failed: %08x\n", hr
);
88 ok(pv
.vt
== VT_LPWSTR
, "Got wrong variant type: 0x%x\n", pv
.vt
);
89 trace("device interface: %s\n", wine_dbgstr_w(pv
.pwszVal
));
90 PropVariantClear(&pv
);
93 static void test_getat(IPropertyStore
*store
)
99 BOOL found_name
= FALSE
;
100 BOOL found_desc
= FALSE
;
102 temp
[sizeof(temp
)-1] = 0;
104 hr
= IPropertyStore_GetCount(store
, &propcount
);
106 ok(hr
== S_OK
, "Failed with %08x\n", hr
);
107 ok(propcount
> 0, "Propcount %d should be greater than zero\n", propcount
);
109 for (prop
= 0; prop
< propcount
; prop
++) {
110 hr
= IPropertyStore_GetAt(store
, prop
, &pkey
);
111 ok(hr
== S_OK
, "Failed with %08x\n", hr
);
112 if (IsEqualPropertyKey(pkey
, DEVPKEY_Device_FriendlyName
))
114 if (IsEqualPropertyKey(pkey
, DEVPKEY_Device_DeviceDesc
))
118 broken(!found_name
) /* vista */, "DEVPKEY_Device_FriendlyName not found\n");
119 ok(found_desc
, "DEVPKEY_Device_DeviceDesc not found\n");
122 static void test_setvalue_on_wow64(IPropertyStore
*store
)
128 HKEY root
, props
, devkey
;
129 DWORD type
, regval
, size
;
131 static const PROPERTYKEY PKEY_Bogus
= {
132 {0x1da5d803, 0xd492, 0x4edd, {0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x00}}, 0x7f
134 static const WCHAR bogusW
[] = L
"{1DA5D803-D492-4EDD-8C23-E0C0FFEE7F00},127";
136 PropVariantInit(&pv
);
139 hr
= IPropertyStore_GetValue(store
, &PKEY_AudioEndpoint_GUID
, &pv
);
140 ok(hr
== S_OK
, "Failed to get Endpoint GUID: %08x\n", hr
);
147 hr
= IPropertyStore_SetValue(store
, &PKEY_Bogus
, &pv
);
148 ok(hr
== S_OK
|| hr
== E_ACCESSDENIED
, "SetValue failed: %08x\n", hr
);
151 win_skip("Missing permission to write to registry\n");
157 hr
= IPropertyStore_GetValue(store
, &PKEY_Bogus
, &pv
);
158 ok(hr
== S_OK
, "GetValue failed: %08x\n", hr
);
159 ok(pv
.ulVal
== 0xAB, "Got wrong value: 0x%x\n", pv
.ulVal
);
161 /* should find the key in 64-bit view */
162 ret
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, software_renderW
, 0, KEY_READ
|KEY_WOW64_64KEY
, &root
);
163 ok(ret
== ERROR_SUCCESS
, "Couldn't open mmdevices Render key: %u\n", ret
);
165 ret
= RegOpenKeyExW(root
, guidW
, 0, KEY_READ
|KEY_WOW64_64KEY
, &devkey
);
166 ok(ret
== ERROR_SUCCESS
, "Couldn't open mmdevice guid key: %u\n", ret
);
168 ret
= RegOpenKeyExW(devkey
, L
"Properties", 0, KEY_READ
|KEY_WOW64_64KEY
, &props
);
169 ok(ret
== ERROR_SUCCESS
, "Couldn't open mmdevice property key: %u\n", ret
);
171 /* Note: the registry key exists even without calling IPropStore::Commit */
172 size
= sizeof(regval
);
173 ret
= RegQueryValueExW(props
, bogusW
, NULL
, &type
, (LPBYTE
)®val
, &size
);
174 ok(ret
== ERROR_SUCCESS
, "Couldn't get bogus propertykey value: %u\n", ret
);
175 ok(type
== REG_DWORD
, "Got wrong value type: %u\n", type
);
176 ok(regval
== 0xAB, "Got wrong value: 0x%x\n", regval
);
182 CoTaskMemFree(guidW
);
184 /* should NOT find the key in 32-bit view */
185 ret
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, software_renderW
, 0, KEY_READ
, &root
);
186 ok(ret
== ERROR_FILE_NOT_FOUND
, "Wrong error when opening mmdevices Render key: %u\n", ret
);
189 START_TEST(propstore
)
192 IMMDeviceEnumerator
*mme
= NULL
;
193 IMMDevice
*dev
= NULL
;
194 IPropertyStore
*store
;
195 BOOL is_wow64
= FALSE
;
196 HMODULE hk32
= GetModuleHandleA("kernel32.dll");
198 pIsWow64Process
= (void *)GetProcAddress(hk32
, "IsWow64Process");
201 pIsWow64Process(GetCurrentProcess(), &is_wow64
);
203 CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
204 hr
= CoCreateInstance(&CLSID_MMDeviceEnumerator
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IMMDeviceEnumerator
, (void**)&mme
);
207 skip("mmdevapi not available: 0x%08x\n", hr
);
211 hr
= IMMDeviceEnumerator_GetDefaultAudioEndpoint(mme
, eRender
, eMultimedia
, &dev
);
212 ok(hr
== S_OK
|| hr
== E_NOTFOUND
, "GetDefaultAudioEndpoint failed: 0x%08x\n", hr
);
215 if (hr
== E_NOTFOUND
)
216 skip("No sound card available\n");
218 skip("GetDefaultAudioEndpoint returns 0x%08x\n", hr
);
222 hr
= IMMDevice_OpenPropertyStore(dev
, 3, &store
);
223 ok(hr
== E_INVALIDARG
, "Wrong hr returned: %08x\n", hr
);
225 /* It seems on windows returning with E_INVALIDARG doesn't
226 * set store to NULL, so just don't set store to non-null
227 * before calling this function
229 ok(!store
, "Store set to non-NULL on failure: %p/%08x\n", store
, hr
);
231 IPropertyStore_Release(store
);
232 hr
= IMMDevice_OpenPropertyStore(dev
, STGM_READ
, NULL
);
233 ok(hr
== E_POINTER
, "Wrong hr returned: %08x\n", hr
);
236 hr
= IMMDevice_OpenPropertyStore(dev
, STGM_READWRITE
, &store
);
237 if(hr
== E_ACCESSDENIED
)
238 hr
= IMMDevice_OpenPropertyStore(dev
, STGM_READ
, &store
);
239 ok(hr
== S_OK
, "Opening valid store returned %08x\n", hr
);
242 test_propertystore(store
);
243 test_deviceinterface(store
);
246 test_setvalue_on_wow64(store
);
247 IPropertyStore_Release(store
);
249 IMMDevice_Release(dev
);
252 IMMDeviceEnumerator_Release(mme
);