1 /* Unit test suite for various shell Association objects
3 * Copyright 2012 Detlef Riekenberg
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.
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.
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
28 #include "wine/test.h"
31 static void test_IQueryAssociations_QueryInterface(void)
33 IQueryAssociations
*qa
;
34 IQueryAssociations
*qa2
;
38 hr
= CoCreateInstance(&CLSID_QueryAssociations
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IQueryAssociations
, (void*)&qa
);
39 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
41 hr
= IQueryAssociations_QueryInterface(qa
, &IID_IQueryAssociations
, (void**)&qa2
);
42 ok(hr
== S_OK
, "QueryInterface (IQueryAssociations) returned 0x%x\n", hr
);
44 IQueryAssociations_Release(qa2
);
47 hr
= IQueryAssociations_QueryInterface(qa
, &IID_IUnknown
, (void**)&unk
);
48 ok(hr
== S_OK
, "QueryInterface (IUnknown) returned 0x%x\n", hr
);
50 IUnknown_Release(unk
);
53 hr
= IQueryAssociations_QueryInterface(qa
, &IID_IUnknown
, NULL
);
54 ok(hr
== E_POINTER
, "got 0x%x (expected E_POINTER)\n", hr
);
56 IQueryAssociations_Release(qa
);
60 static void test_IApplicationAssociationRegistration_QueryInterface(void)
62 IApplicationAssociationRegistration
*appreg
;
63 IApplicationAssociationRegistration
*appreg2
;
67 /* this works since Vista */
68 hr
= CoCreateInstance(&CLSID_ApplicationAssociationRegistration
, NULL
, CLSCTX_INPROC_SERVER
,
69 &IID_IApplicationAssociationRegistration
, (LPVOID
*)&appreg
);
72 skip("IApplicationAssociationRegistration not created: 0x%x\n", hr
);
76 hr
= IApplicationAssociationRegistration_QueryInterface(appreg
, &IID_IApplicationAssociationRegistration
,
78 ok(hr
== S_OK
, "QueryInterface (IApplicationAssociationRegistration) returned 0x%x\n", hr
);
80 IApplicationAssociationRegistration_Release(appreg2
);
83 hr
= IApplicationAssociationRegistration_QueryInterface(appreg
, &IID_IUnknown
, (void**)&unk
);
84 ok(hr
== S_OK
, "QueryInterface (IUnknown) returned 0x%x\n", hr
);
86 IUnknown_Release(unk
);
89 hr
= IApplicationAssociationRegistration_QueryInterface(appreg
, &IID_IUnknown
, NULL
);
90 ok(hr
== E_POINTER
, "got 0x%x (expected E_POINTER)\n", hr
);
92 IApplicationAssociationRegistration_Release(appreg
);
95 struct assoc_getstring_test
105 static const WCHAR httpW
[] = {'h','t','t','p',0};
107 static struct assoc_getstring_test getstring_tests
[] =
109 { httpW
, 0, ASSOCSTR_EXECUTABLE
, 2, 0x8007007a /* E_NOT_SUFFICIENT_BUFFER */, S_OK
},
110 { httpW
, ASSOCF_NOTRUNCATE
, ASSOCSTR_EXECUTABLE
, 2, E_POINTER
},
114 static void test_IQueryAssociations_GetString(void)
116 struct assoc_getstring_test
*ptr
= getstring_tests
;
117 IQueryAssociations
*assoc
;
122 hr
= CoCreateInstance(&CLSID_QueryAssociations
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IQueryAssociations
, (void*)&assoc
);
123 ok(hr
== S_OK
, "failed to create object, 0x%x\n", hr
);
125 hr
= IQueryAssociations_Init(assoc
, 0, httpW
, NULL
, NULL
);
126 ok(hr
== S_OK
, "Init failed, 0x%x\n", hr
);
129 hr
= IQueryAssociations_GetString(assoc
, 0, ASSOCSTR_EXECUTABLE
, NULL
, NULL
, &len
);
130 ok(hr
== S_FALSE
, "got 0x%08x\n", hr
);
131 ok(len
> 0, "got wrong needed length, %d\n", len
);
135 WCHAR buffW
[MAX_PATH
];
138 hr
= IQueryAssociations_Init(assoc
, 0, ptr
->key
, NULL
, NULL
);
139 ok(hr
== S_OK
, "%d: Init failed, 0x%x\n", i
, hr
);
142 buffW
[0] = ptr
->flags
& ASSOCF_NOTRUNCATE
? 0x1 : 0;
143 hr
= IQueryAssociations_GetString(assoc
, ptr
->flags
, ptr
->str
, NULL
, buffW
, &len
);
145 ok(broken(hr
== ptr
->brokenhr
), "%d: GetString failed, 0x%08x\n", i
, hr
);
148 ok(hr
== ptr
->hr
, "%d: GetString failed, 0x%08x\n", i
, hr
);
149 ok(len
> ptr
->len
, "%d: got needed length %d\n", i
, len
);
152 /* even with ASSOCF_NOTRUNCATE it's null terminated */
153 if ((ptr
->flags
& ASSOCF_NOTRUNCATE
) && (ptr
->len
> 0))
154 ok(buffW
[0] == 0 || broken(buffW
[0] == 0x1) /* pre win7 */, "%d: got %x\n", i
, buffW
[0]);
156 if (!(ptr
->flags
& ASSOCF_NOTRUNCATE
) && ptr
->len
&& FAILED(ptr
->hr
))
157 ok(buffW
[0] != 0, "%d: got %x\n", i
, buffW
[0]);
163 IQueryAssociations_Release(assoc
);
168 IQueryAssociations
*qa
;
173 /* this works since XP */
174 hr
= CoCreateInstance(&CLSID_QueryAssociations
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IQueryAssociations
, (void*)&qa
);
177 test_IQueryAssociations_QueryInterface();
178 test_IQueryAssociations_GetString();
180 IQueryAssociations_Release(qa
);
183 win_skip("IQueryAssociations not supported, 0x%x\n", hr
);
185 test_IApplicationAssociationRegistration_QueryInterface();