shell32/tests: Fix test_one_cmdline() and add a few more tests.
[wine] / dlls / shell32 / tests / assoc.c
1 /* Unit test suite for various shell Association objects
2  *
3  * Copyright 2012 Detlef Riekenberg
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19
20 #define COBJMACROS
21
22 #include <stdarg.h>
23
24 #include "shlwapi.h"
25 #include "shlguid.h"
26 #include "shobjidl.h"
27
28 #include "wine/test.h"
29
30
31 static void test_IQueryAssociations_QueryInterface(void)
32 {
33     IQueryAssociations *qa;
34     IQueryAssociations *qa2;
35     IUnknown *unk;
36     HRESULT hr;
37
38     /* this works since XP */
39     hr = CoCreateInstance(&CLSID_QueryAssociations, NULL, CLSCTX_INPROC_SERVER, &IID_IQueryAssociations, (void*)&qa);
40
41     if (FAILED(hr)) {
42         win_skip("CoCreateInstance for IQueryAssociations returned 0x%x\n", hr);
43         return;
44     }
45
46     hr = IQueryAssociations_QueryInterface(qa, &IID_IQueryAssociations, (void**)&qa2);
47     ok(hr == S_OK, "QueryInterface (IQueryAssociations) returned 0x%x\n", hr);
48     if (SUCCEEDED(hr)) {
49         IQueryAssociations_Release(qa2);
50     }
51
52     hr = IQueryAssociations_QueryInterface(qa, &IID_IUnknown, (void**)&unk);
53     ok(hr == S_OK, "QueryInterface (IUnknown) returned 0x%x\n", hr);
54     if (SUCCEEDED(hr)) {
55         IUnknown_Release(unk);
56     }
57
58     hr = IQueryAssociations_QueryInterface(qa, &IID_IUnknown, NULL);
59     ok(hr == E_POINTER, "got 0x%x (expected E_POINTER)\n", hr);
60
61     IQueryAssociations_Release(qa);
62 }
63
64
65 static void test_IApplicationAssociationRegistration_QueryInterface(void)
66 {
67     IApplicationAssociationRegistration *appreg;
68     IApplicationAssociationRegistration *appreg2;
69     IUnknown *unk;
70     HRESULT hr;
71
72     /* this works since Vista */
73     hr = CoCreateInstance(&CLSID_ApplicationAssociationRegistration, NULL, CLSCTX_INPROC_SERVER,
74                           &IID_IApplicationAssociationRegistration, (LPVOID*)&appreg);
75
76     if (FAILED(hr)) {
77         skip("IApplicationAssociationRegistration not created: 0x%x\n", hr);
78         return;
79     }
80
81     hr = IApplicationAssociationRegistration_QueryInterface(appreg, &IID_IApplicationAssociationRegistration,
82        (void**)&appreg2);
83     ok(hr == S_OK, "QueryInterface (IApplicationAssociationRegistration) returned 0x%x\n", hr);
84     if (SUCCEEDED(hr)) {
85         IApplicationAssociationRegistration_Release(appreg2);
86     }
87
88     hr = IApplicationAssociationRegistration_QueryInterface(appreg, &IID_IUnknown, (void**)&unk);
89     ok(hr == S_OK, "QueryInterface (IUnknown) returned 0x%x\n", hr);
90     if (SUCCEEDED(hr)) {
91         IUnknown_Release(unk);
92     }
93
94     hr = IApplicationAssociationRegistration_QueryInterface(appreg, &IID_IUnknown, NULL);
95     ok(hr == E_POINTER, "got 0x%x (expected E_POINTER)\n", hr);
96
97     IApplicationAssociationRegistration_Release(appreg);
98 }
99
100
101 START_TEST(assoc)
102 {
103     CoInitialize(NULL);
104
105     test_IQueryAssociations_QueryInterface();
106     test_IApplicationAssociationRegistration_QueryInterface();
107
108     CoUninitialize();
109 }