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