wininet: Keep handles invalid but reserved in InternetCloseHandle.
[wine] / dlls / mmdevapi / tests / propstore.c
1 /*
2  * Copyright 2010 Maarten Lankhorst for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #define NONAMELESSUNION
20 #include "wine/test.h"
21
22 #define COBJMACROS
23
24 #ifdef STANDALONE
25 #include "initguid.h"
26 #endif
27
28 #include "unknwn.h"
29 #include "uuids.h"
30 #include "mmdeviceapi.h"
31 #include "devpkey.h"
32
33 static void test_propertystore(IPropertyStore *store)
34 {
35     HRESULT hr;
36     PROPVARIANT pv;
37     char temp[128];
38     temp[sizeof(temp)-1] = 0;
39
40     pv.vt = VT_EMPTY;
41     hr = IPropertyStore_GetValue(store, &PKEY_AudioEndpoint_GUID, &pv);
42     ok(hr == S_OK, "Failed with %08x\n", hr);
43     ok(pv.vt == VT_LPWSTR, "Value should be %i, is %i\n", VT_LPWSTR, pv.vt);
44     if (hr == S_OK && pv.vt == VT_LPWSTR)
45     {
46         WideCharToMultiByte(CP_ACP, 0, pv.u.pwszVal, -1, temp, sizeof(temp)-1, NULL, NULL);
47         trace("guid: %s\n", temp);
48         CoTaskMemFree(pv.u.pwszVal);
49     }
50
51     pv.vt = VT_EMPTY;
52     hr = IPropertyStore_GetValue(store, (const PROPERTYKEY*)&DEVPKEY_DeviceInterface_FriendlyName, &pv);
53     ok(hr == S_OK, "Failed with %08x\n", hr);
54     ok(pv.vt == VT_EMPTY, "Key should not be found\n");
55
56     pv.vt = VT_EMPTY;
57     hr = IPropertyStore_GetValue(store, (const PROPERTYKEY*)&DEVPKEY_DeviceInterface_Enabled, &pv);
58     ok(pv.vt == VT_EMPTY, "Key should not be found\n");
59
60     pv.vt = VT_EMPTY;
61     hr = IPropertyStore_GetValue(store, (const PROPERTYKEY*)&DEVPKEY_DeviceInterface_ClassGuid, &pv);
62     ok(pv.vt == VT_EMPTY, "Key should not be found\n");
63 }
64
65 START_TEST(propstore)
66 {
67     HRESULT hr;
68     IMMDeviceEnumerator *mme = NULL;
69     IMMDevice *dev = NULL;
70     IPropertyStore *store;
71
72     CoInitializeEx(NULL, COINIT_MULTITHREADED);
73     hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&mme);
74     if (FAILED(hr))
75     {
76         skip("mmdevapi not available: 0x%08x\n", hr);
77         goto cleanup;
78     }
79
80     hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(mme, eRender, eMultimedia, &dev);
81     ok(hr == S_OK || hr == E_NOTFOUND, "GetDefaultAudioEndpoint failed: 0x%08x\n", hr);
82     if (hr != S_OK)
83     {
84         if (hr == E_NOTFOUND)
85             skip("No sound card available\n");
86         else
87             skip("GetDefaultAudioEndpoint returns 0x%08x\n", hr);
88         goto cleanup;
89     }
90     store = NULL;
91     hr = IMMDevice_OpenPropertyStore(dev, 3, &store);
92     ok(hr == E_INVALIDARG, "Wrong hr returned: %08x\n", hr);
93     if (hr != S_OK)
94         /* It seems on windows returning with E_INVALIDARG doesn't
95          * set store to NULL, so just don't set store to non-null
96          * before calling this function
97          */
98         ok(!store, "Store set to non-NULL on failure: %p/%08x\n", store, hr);
99     else if (store)
100         IPropertyStore_Release(store);
101     hr = IMMDevice_OpenPropertyStore(dev, STGM_READ, NULL);
102     ok(hr == E_POINTER, "Wrong hr returned: %08x\n", hr);
103
104     store = NULL;
105     hr = IMMDevice_OpenPropertyStore(dev, STGM_READ, &store);
106     ok(hr == S_OK, "Opening valid store returned %08x\n", hr);
107     if (store)
108     {
109         test_propertystore(store);
110         IPropertyStore_Release(store);
111     }
112     IMMDevice_Release(dev);
113 cleanup:
114     if (mme)
115         IUnknown_Release(mme);
116     CoUninitialize();
117 }