878cd985fe6e0c3bccb7e7342672de9b7dece4fe
[reactos.git] / rostests / winetests / propsys / propsys.c
1 /*
2 * Unit tests for Windows property system
3 *
4 * Copyright 2006 Paul Vriens
5 * Copyright 2010 Andrew Nguyen
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #define WIN32_NO_STATUS
23 #define _INC_WINDOWS
24 #define COM_NO_WINDOWS_H
25
26 #define COBJMACROS
27
28 //#include <stdarg.h>
29 #include <stdio.h>
30
31 #define NONAMELESSUNION
32
33 #include <windef.h>
34 #include <winbase.h>
35 #include <winreg.h>
36 #include <winnls.h>
37 //#include "objbase.h"
38 #include <ole2.h>
39 #include <initguid.h>
40 #include <propsys.h>
41 #include <propvarutil.h>
42 #include <wine/test.h>
43
44 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
45 DEFINE_GUID(dummy_guid, 0xdeadbeef, 0xdead, 0xbeef, 0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0xba, 0xbe);
46 DEFINE_GUID(expect_guid, 0x12345678, 0x1234, 0x1234, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12);
47
48 #define GUID_MEMBERS(g) {(g).Data1, (g).Data2, (g).Data3, {(g).Data4[0], (g).Data4[1], (g).Data4[2], (g).Data4[3], (g).Data4[4], (g).Data4[5], (g).Data4[6], (g).Data4[7]}}
49
50 static char *show_guid(const GUID *guid, char *buf)
51 {
52 static char static_buf[40];
53
54 if(!buf)
55 buf = static_buf;
56
57 sprintf(buf,
58 "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
59 guid->Data1, guid->Data2, guid->Data3,
60 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
61 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
62
63 return buf;
64 }
65
66 static int strcmp_wa(LPCWSTR strw, const char *stra)
67 {
68 CHAR buf[512];
69 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
70 return lstrcmpA(stra, buf);
71 }
72
73 static void test_PSStringFromPropertyKey(void)
74 {
75 static const WCHAR fillerW[] = {'X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X',
76 'X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X',
77 'X','X','X','X','X','X','X','X','X','X'};
78 static const WCHAR zero_fillerW[] = {'\0','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X',
79 'X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X',
80 'X','X','X','X','X','X','X','X','X','X','X','X','X','X'};
81 static const WCHAR zero_truncatedW[] = {'\0','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0',
82 '0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0',
83 '0','0','0','}',' ','\0','9','X','X','X','X','X','X','X','X','X'};
84 static const WCHAR zero_truncated2W[] = {'\0','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0',
85 '0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0',
86 '0','0','0','}',' ','\0','9','2','7','6','9','4','9','2','X','X'};
87 static const WCHAR zero_truncated3W[] = {'\0','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0',
88 '0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0',
89 '0','0','0','}',' ','\0','9','2','7','6','9','4','9','2','4','X'};
90 static const WCHAR zero_truncated4W[] = {'\0','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0',
91 '0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0',
92 '0','0','0','}',' ','\0','7','X','X','X','X','X','X','X','X','X'};
93 static const WCHAR truncatedW[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
94 '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
95 '0','}',' ','\0','9','X','X','X','X','X','X','X','X','X'};
96 static const WCHAR truncated2W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
97 '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
98 '0','}',' ','\0','9','2','7','6','9','4','9','2','X','X'};
99 static const WCHAR truncated3W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
100 '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
101 '0','}',' ','\0','9','2','7','6','9','4','9','2','4','X'};
102 static const WCHAR truncated4W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
103 '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
104 '0','}',' ','\0','7','X','X','X','X','X','X','X','X','X'};
105 static const WCHAR expectedW[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
106 '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
107 '0','}',' ','4','2','9','4','9','6','7','2','9','5',0};
108 static const WCHAR expected2W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
109 '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
110 '0','}',' ','1','3','5','7','9','\0','X','X','X','X','X'};
111 static const WCHAR expected3W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
112 '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
113 '0','}',' ','0','\0','X','X','X','X','X','X','X','X','X'};
114 PROPERTYKEY prop = {GUID_MEMBERS(GUID_NULL), ~0U};
115 PROPERTYKEY prop2 = {GUID_MEMBERS(GUID_NULL), 13579};
116 PROPERTYKEY prop3 = {GUID_MEMBERS(GUID_NULL), 0};
117 WCHAR out[PKEYSTR_MAX];
118 HRESULT ret;
119
120 const struct
121 {
122 REFPROPERTYKEY pkey;
123 LPWSTR psz;
124 UINT cch;
125 HRESULT hr_expect;
126 const WCHAR *buf_expect;
127 int hr_broken;
128 HRESULT hr2;
129 int buf_broken;
130 const WCHAR *buf2;
131 } testcases[] =
132 {
133 {NULL, NULL, 0, E_POINTER},
134 {&prop, NULL, 0, E_POINTER},
135 {&prop, NULL, PKEYSTR_MAX, E_POINTER},
136 {NULL, out, 0, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), fillerW},
137 {NULL, out, PKEYSTR_MAX, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), zero_fillerW, 0, 0, 1, fillerW},
138 {&prop, out, 0, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), fillerW},
139 {&prop, out, GUIDSTRING_MAX, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), fillerW},
140 {&prop, out, GUIDSTRING_MAX + 1, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), fillerW},
141 {&prop, out, GUIDSTRING_MAX + 2, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), zero_truncatedW, 1, S_OK, 1, truncatedW},
142 {&prop, out, PKEYSTR_MAX - 2, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), zero_truncated2W, 1, S_OK, 1, truncated2W},
143 {&prop, out, PKEYSTR_MAX - 1, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), zero_truncated3W, 1, S_OK, 1, truncated3W},
144 {&prop, out, PKEYSTR_MAX, S_OK, expectedW},
145 {&prop2, out, GUIDSTRING_MAX + 2, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), zero_truncated4W, 1, S_OK, 1, truncated4W},
146 {&prop2, out, GUIDSTRING_MAX + 6, S_OK, expected2W},
147 {&prop2, out, PKEYSTR_MAX, S_OK, expected2W},
148 {&prop3, out, GUIDSTRING_MAX + 1, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), fillerW},
149 {&prop3, out, GUIDSTRING_MAX + 2, S_OK, expected3W},
150 {&prop3, out, PKEYSTR_MAX, S_OK, expected3W},
151 };
152
153 int i;
154
155 for (i = 0; i < sizeof(testcases)/sizeof(testcases[0]); i++)
156 {
157 if (testcases[i].psz)
158 memcpy(testcases[i].psz, fillerW, PKEYSTR_MAX * sizeof(WCHAR));
159
160 ret = PSStringFromPropertyKey(testcases[i].pkey,
161 testcases[i].psz,
162 testcases[i].cch);
163 ok(ret == testcases[i].hr_expect ||
164 broken(testcases[i].hr_broken && ret == testcases[i].hr2), /* Vista/Win2k8 */
165 "[%d] Expected PSStringFromPropertyKey to return 0x%08x, got 0x%08x\n",
166 i, testcases[i].hr_expect, ret);
167
168 if (testcases[i].psz)
169 ok(!memcmp(testcases[i].psz, testcases[i].buf_expect, PKEYSTR_MAX * sizeof(WCHAR)) ||
170 broken(testcases[i].buf_broken &&
171 !memcmp(testcases[i].psz, testcases[i].buf2, PKEYSTR_MAX * sizeof(WCHAR))), /* Vista/Win2k8 */
172 "[%d] Unexpected output contents\n", i);
173 }
174 }
175
176 static void test_PSPropertyKeyFromString(void)
177 {
178 static const WCHAR emptyW[] = {0};
179 static const WCHAR fmtid_clsidW[] = {'S','t','d','F','o','n','t',' ','1',0};
180 static const WCHAR fmtid_truncatedW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
181 '1','2','3','4','-',0};
182 static const WCHAR fmtid_nobracketsW[] = {'1','2','3','4','5','6','7','8','-','1','2','3','4','-',
183 '1','2','3','4','-','1','2','3','4','-',
184 '1','2','3','4','5','6','7','8','9','0','1','2',0};
185 static const WCHAR fmtid_badbracketW[] = {'X','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
186 '1','2','3','4','-','1','2','3','4','-',
187 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
188 static const WCHAR fmtid_badcharW[] = {'{','X','2','3','4','5','6','7','8','-','1','2','3','4','-',
189 '1','2','3','4','-','1','2','3','4','-',
190 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
191 static const WCHAR fmtid_badchar2W[] = {'{','1','2','3','4','5','6','7','X','-','1','2','3','4','-',
192 '1','2','3','4','-','1','2','3','4','-',
193 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
194 static const WCHAR fmtid_baddashW[] = {'{','1','2','3','4','5','6','7','8','X','1','2','3','4','-',
195 '1','2','3','4','-','1','2','3','4','-',
196 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
197 static const WCHAR fmtid_badchar3W[] = {'{','1','2','3','4','5','6','7','8','-','X','2','3','4','-',
198 '1','2','3','4','-','1','2','3','4','-',
199 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
200 static const WCHAR fmtid_badchar4W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','X','-',
201 '1','2','3','4','-','1','2','3','4','-',
202 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
203 static const WCHAR fmtid_baddash2W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','X',
204 '1','2','3','4','-','1','2','3','4','-',
205 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
206 static const WCHAR fmtid_badchar5W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
207 'X','2','3','4','-','1','2','3','4','-',
208 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
209 static const WCHAR fmtid_badchar6W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
210 '1','2','3','X','-','1','2','3','4','-',
211 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
212 static const WCHAR fmtid_baddash3W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
213 '1','2','3','4','X','1','2','3','4','-',
214 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
215 static const WCHAR fmtid_badchar7W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
216 '1','2','3','4','-','X','2','3','4','-',
217 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
218 static const WCHAR fmtid_badchar8W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
219 '1','2','3','4','-','1','2','3','X','-',
220 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
221 static const WCHAR fmtid_baddash4W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
222 '1','2','3','4','-','1','2','3','4','X',
223 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
224 static const WCHAR fmtid_badchar9W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
225 '1','2','3','4','-','1','2','3','4','-',
226 'X','2','3','4','5','6','7','8','9','0','1','2','}',0};
227 static const WCHAR fmtid_badchar9_adjW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
228 '1','2','3','4','-','1','2','3','4','-',
229 '1','X','3','4','5','6','7','8','9','0','1','2','}',0};
230 static const WCHAR fmtid_badchar10W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
231 '1','2','3','4','-','1','2','3','4','-',
232 '1','2','X','4','5','6','7','8','9','0','1','2','}',0};
233 static const WCHAR fmtid_badchar11W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
234 '1','2','3','4','-','1','2','3','4','-',
235 '1','2','3','4','X','6','7','8','9','0','1','2','}',0};
236 static const WCHAR fmtid_badchar12W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
237 '1','2','3','4','-','1','2','3','4','-',
238 '1','2','3','4','5','6','X','8','9','0','1','2','}',0};
239 static const WCHAR fmtid_badchar13W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
240 '1','2','3','4','-','1','2','3','4','-',
241 '1','2','3','4','5','6','7','8','X','0','1','2','}',0};
242 static const WCHAR fmtid_badchar14W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
243 '1','2','3','4','-','1','2','3','4','-',
244 '1','2','3','4','5','6','7','8','9','0','X','2','}',0};
245 static const WCHAR fmtid_badbracket2W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
246 '1','2','3','4','-','1','2','3','4','-',
247 '1','2','3','4','5','6','7','8','9','0','1','2','X',0};
248 static const WCHAR fmtid_spaceW[] = {' ','{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
249 '1','2','3','4','-','1','2','3','4','-',
250 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
251 static const WCHAR fmtid_spaceendW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
252 '1','2','3','4','-','1','2','3','4','-',
253 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',0};
254 static const WCHAR fmtid_spacesendW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
255 '1','2','3','4','-','1','2','3','4','-',
256 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',' ',' ',0};
257 static const WCHAR fmtid_nopidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
258 '1','2','3','4','-','1','2','3','4','-',
259 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
260 static const WCHAR fmtid_badpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
261 '1','2','3','4','-','1','2','3','4','-',
262 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','D','E','A','D',0};
263 static const WCHAR fmtid_adjpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
264 '1','2','3','4','-','1','2','3','4','-',
265 '1','2','3','4','5','6','7','8','9','0','1','2','}','1','3','5','7','9',0};
266 static const WCHAR fmtid_spacespidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
267 '1','2','3','4','-','1','2','3','4','-',
268 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',' ',' ','1','3','5','7','9',0};
269 static const WCHAR fmtid_negpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
270 '1','2','3','4','-','1','2','3','4','-',
271 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-','1','3','5','7','9',0};
272 static const WCHAR fmtid_negnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
273 '1','2','3','4','-','1','2','3','4','-',
274 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-','-','1','3','5','7','9',0};
275 static const WCHAR fmtid_negnegnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
276 '1','2','3','4','-','1','2','3','4','-',
277 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-','-','-','1','3','5','7','9',0};
278 static const WCHAR fmtid_negspacepidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
279 '1','2','3','4','-','1','2','3','4','-',
280 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-',' ','1','3','5','7','9',0};
281 static const WCHAR fmtid_negspacenegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
282 '1','2','3','4','-','1','2','3','4','-',
283 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-',' ','-','1','3','5','7','9',0};
284 static const WCHAR fmtid_negspacespidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
285 '1','2','3','4','-','1','2','3','4','-',
286 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-',' ','-',' ','-','1','3','5','7','9',0};
287 static const WCHAR fmtid_pospidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
288 '1','2','3','4','-','1','2','3','4','-',
289 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','+','1','3','5','7','9',0};
290 static const WCHAR fmtid_posnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
291 '1','2','3','4','-','1','2','3','4','-',
292 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','+','-','+','-','1','3','5','7','9',0};
293 static const WCHAR fmtid_symbolpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
294 '1','2','3','4','-','1','2','3','4','-',
295 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','+','/','$','-','1','3','5','7','9',0};
296 static const WCHAR fmtid_letterpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
297 '1','2','3','4','-','1','2','3','4','-',
298 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','A','B','C','D','1','3','5','7','9',0};
299 static const WCHAR fmtid_spacepadpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
300 '1','2','3','4','-','1','2','3','4','-',
301 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','1','3','5','7','9',' ',' ',' ',0};
302 static const WCHAR fmtid_spacemixpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
303 '1','2','3','4','-','1','2','3','4','-',
304 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','1',' ','3',' ','5','7','9',' ',' ',' ',0};
305 static const WCHAR fmtid_tabpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
306 '1','2','3','4','-','1','2','3','4','-',
307 '1','2','3','4','5','6','7','8','9','0','1','2','}','\t','1','3','5','7','9',0};
308 static const WCHAR fmtid_hexpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
309 '1','2','3','4','-','1','2','3','4','-',
310 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','0','x','D','E','A','D',0};
311 static const WCHAR fmtid_mixedpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
312 '1','2','3','4','-','1','2','3','4','-',
313 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','A','9','B','5','C','3','D','1',0};
314 static const WCHAR fmtid_overflowpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
315 '1','2','3','4','-','1','2','3','4','-',
316 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','1','2','3','4','5','6','7','8','9','0','1',0};
317 static const WCHAR fmtid_commapidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
318 '1','2','3','4','-','1','2','3','4','-',
319 '1','2','3','4','5','6','7','8','9','0','1','2','}',',','1','3','5','7','9',0};
320 static const WCHAR fmtid_commaspidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
321 '1','2','3','4','-','1','2','3','4','-',
322 '1','2','3','4','5','6','7','8','9','0','1','2','}',',',',',',','1','3','5','7','9',0};
323 static const WCHAR fmtid_commaspacepidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
324 '1','2','3','4','-','1','2','3','4','-',
325 '1','2','3','4','5','6','7','8','9','0','1','2','}',',',' ','1','3','5','7','9',0};
326 static const WCHAR fmtid_spacecommapidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
327 '1','2','3','4','-','1','2','3','4','-',
328 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',','1','3','5','7','9',0};
329 static const WCHAR fmtid_spccommaspcpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
330 '1','2','3','4','-','1','2','3','4','-',
331 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',',' ','1','3','5','7','9',0};
332 static const WCHAR fmtid_spacescommaspidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
333 '1','2','3','4','-','1','2','3','4','-',
334 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',',' ',',','1','3','5','7','9',0};
335 static const WCHAR fmtid_commanegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
336 '1','2','3','4','-','1','2','3','4','-',
337 '1','2','3','4','5','6','7','8','9','0','1','2','}',',','-','1','3','5','7','9',0};
338 static const WCHAR fmtid_spccommanegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
339 '1','2','3','4','-','1','2','3','4','-',
340 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',','-','1','3','5','7','9',0};
341 static const WCHAR fmtid_commaspcnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
342 '1','2','3','4','-','1','2','3','4','-',
343 '1','2','3','4','5','6','7','8','9','0','1','2','}',',',' ','-','1','3','5','7','9',0};
344 static const WCHAR fmtid_spccommaspcnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
345 '1','2','3','4','-','1','2','3','4','-',
346 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',',' ','-','1','3','5','7','9',0};
347 static const WCHAR fmtid_commanegspcpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
348 '1','2','3','4','-','1','2','3','4','-',
349 '1','2','3','4','5','6','7','8','9','0','1','2','}',',','-',' ','1','3','5','7','9',0};
350 static const WCHAR fmtid_negcommapidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
351 '1','2','3','4','-','1','2','3','4','-',
352 '1','2','3','4','5','6','7','8','9','0','1','2','}','-',',','1','3','5','7','9',0};
353 static const WCHAR fmtid_normalpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
354 '1','2','3','4','-','1','2','3','4','-',
355 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','1','3','5','7','9',0};
356 PROPERTYKEY out_init = {GUID_MEMBERS(dummy_guid), 0xdeadbeef};
357 PROPERTYKEY out;
358 HRESULT ret;
359 char guid_buf[40], guid_buf2[40];
360
361 const struct
362 {
363 LPCWSTR pwzString;
364 PROPERTYKEY *pkey;
365 HRESULT hr_expect;
366 PROPERTYKEY pkey_expect;
367 } testcases[] =
368 {
369 {NULL, NULL, E_POINTER},
370 {NULL, &out, E_POINTER, {GUID_MEMBERS(dummy_guid), 0xdeadbeef}},
371 {emptyW, NULL, E_POINTER},
372 {emptyW, &out, E_INVALIDARG, {GUID_MEMBERS(GUID_NULL), 0}},
373 {fmtid_clsidW, &out, E_INVALIDARG, {GUID_MEMBERS(GUID_NULL), 0}},
374 {fmtid_truncatedW, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0,0,0,0,0,0,0,0}}, 0}},
375 {fmtid_nobracketsW, &out, E_INVALIDARG, {GUID_MEMBERS(GUID_NULL), 0}},
376 {fmtid_badbracketW, &out, E_INVALIDARG, {GUID_MEMBERS(GUID_NULL), 0}},
377 {fmtid_badcharW, &out, E_INVALIDARG, {GUID_MEMBERS(GUID_NULL), 0}},
378 {fmtid_badchar2W, &out, E_INVALIDARG, {GUID_MEMBERS(GUID_NULL), 0}},
379 {fmtid_baddashW, &out, E_INVALIDARG, { {0x12345678,0,0,{0,0,0,0,0,0,0,0}}, 0}},
380 {fmtid_badchar3W, &out, E_INVALIDARG, { {0x12345678,0,0,{0,0,0,0,0,0,0,0}}, 0}},
381 {fmtid_badchar4W, &out, E_INVALIDARG, { {0x12345678,0,0,{0,0,0,0,0,0,0,0}}, 0}},
382 {fmtid_baddash2W, &out, E_INVALIDARG, { {0x12345678,0,0,{0,0,0,0,0,0,0,0}}, 0}},
383 {fmtid_badchar5W, &out, E_INVALIDARG, { {0x12345678,0x1234,0,{0,0,0,0,0,0,0,0}}, 0}},
384 {fmtid_badchar6W, &out, E_INVALIDARG, { {0x12345678,0x1234,0,{0,0,0,0,0,0,0,0}}, 0}},
385 {fmtid_baddash3W, &out, E_INVALIDARG, { {0x12345678,0x1234,0,{0,0,0,0,0,0,0,0}}, 0}},
386 {fmtid_badchar7W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0,0,0,0,0,0,0,0}}, 0}},
387 {fmtid_badchar8W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0,0,0,0,0,0,0}}, 0}},
388 {fmtid_baddash4W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0,0,0,0,0,0,0}}, 0}},
389 {fmtid_badchar9W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0,0,0,0,0,0}}, 0}},
390 {fmtid_badchar9_adjW, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0,0,0,0,0,0}}, 0}},
391 {fmtid_badchar10W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0,0,0,0,0}}, 0}},
392 {fmtid_badchar11W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0,0,0,0}}, 0}},
393 {fmtid_badchar12W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0,0,0}}, 0}},
394 {fmtid_badchar13W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0x78,0,0}}, 0}},
395 {fmtid_badchar14W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0x78,0x90,0}}, 0}},
396 {fmtid_badbracket2W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0x78,0x90,0x00}}, 0 }},
397 {fmtid_spaceW, &out, E_INVALIDARG, {GUID_MEMBERS(GUID_NULL), 0 }},
398 {fmtid_spaceendW, &out, E_INVALIDARG, {GUID_MEMBERS(expect_guid), 0}},
399 {fmtid_spacesendW, &out, E_INVALIDARG, {GUID_MEMBERS(expect_guid), 0}},
400 {fmtid_nopidW, &out, E_INVALIDARG, {GUID_MEMBERS(expect_guid), 0}},
401 {fmtid_badpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}},
402 {fmtid_adjpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 13579}},
403 {fmtid_spacespidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 13579}},
404 {fmtid_negpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 13579}},
405 {fmtid_negnegpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 4294953717U}},
406 {fmtid_negnegnegpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}},
407 {fmtid_negspacepidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 13579}},
408 {fmtid_negspacenegpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 4294953717U}},
409 {fmtid_negspacespidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}},
410 {fmtid_pospidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}},
411 {fmtid_posnegpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}},
412 {fmtid_symbolpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}},
413 {fmtid_letterpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}},
414 {fmtid_spacepadpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 13579}},
415 {fmtid_spacemixpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 1}},
416 {fmtid_tabpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}},
417 {fmtid_hexpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}},
418 {fmtid_mixedpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}},
419 {fmtid_overflowpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 3755744309U}},
420 {fmtid_commapidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 13579}},
421 {fmtid_commaspidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}},
422 {fmtid_commaspacepidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 13579}},
423 {fmtid_spacecommapidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 13579}},
424 {fmtid_spccommaspcpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 13579}},
425 {fmtid_spacescommaspidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}},
426 {fmtid_commanegpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 4294953717U}},
427 {fmtid_spccommanegpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 4294953717U}},
428 {fmtid_commaspcnegpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 4294953717U}},
429 {fmtid_spccommaspcnegpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 4294953717U}},
430 {fmtid_commanegspcpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0U}},
431 {fmtid_negcommapidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}},
432 {fmtid_normalpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 13579}},
433 };
434
435 int i;
436
437 for (i = 0; i < sizeof(testcases)/sizeof(testcases[0]); i++)
438 {
439 if (testcases[i].pkey)
440 *testcases[i].pkey = out_init;
441
442 ret = PSPropertyKeyFromString(testcases[i].pwzString, testcases[i].pkey);
443 ok(ret == testcases[i].hr_expect,
444 "[%d] Expected PSPropertyKeyFromString to return 0x%08x, got 0x%08x\n",
445 i, testcases[i].hr_expect, ret);
446
447 if (testcases[i].pkey)
448 {
449 ok(IsEqualGUID(&testcases[i].pkey->fmtid, &testcases[i].pkey_expect.fmtid),
450 "[%d] Expected GUID %s, got %s\n",
451 i, show_guid(&testcases[i].pkey_expect.fmtid, guid_buf), show_guid(&testcases[i].pkey->fmtid, guid_buf2));
452 ok(testcases[i].pkey->pid == testcases[i].pkey_expect.pid,
453 "[%d] Expected property ID %u, got %u\n",
454 i, testcases[i].pkey_expect.pid, testcases[i].pkey->pid);
455 }
456 }
457 }
458
459 static void test_PSRefreshPropertySchema(void)
460 {
461 HRESULT ret;
462
463 ret = PSRefreshPropertySchema();
464 todo_wine
465 ok(ret == CO_E_NOTINITIALIZED,
466 "Expected PSRefreshPropertySchema to return CO_E_NOTINITIALIZED, got 0x%08x\n", ret);
467
468 CoInitialize(NULL);
469
470 ret = PSRefreshPropertySchema();
471 ok(ret == S_OK,
472 "Expected PSRefreshPropertySchema to return S_OK, got 0x%08x\n", ret);
473
474 CoUninitialize();
475 }
476
477 static void test_InitPropVariantFromGUIDAsString(void)
478 {
479 PROPVARIANT propvar;
480 VARIANT var;
481 HRESULT hres;
482 int i;
483
484 const struct {
485 REFGUID guid;
486 const char *str;
487 } testcases[] = {
488 {&IID_NULL, "{00000000-0000-0000-0000-000000000000}" },
489 {&dummy_guid, "{DEADBEEF-DEAD-BEEF-DEAD-BEEFCAFEBABE}" },
490 };
491
492 hres = InitPropVariantFromGUIDAsString(NULL, &propvar);
493 ok(hres == E_FAIL, "InitPropVariantFromGUIDAsString returned %x\n", hres);
494
495 if(0) {
496 /* Returns strange data on Win7, crashes on older systems */
497 InitVariantFromGUIDAsString(NULL, &var);
498
499 /* Crashes on windows */
500 InitPropVariantFromGUIDAsString(&IID_NULL, NULL);
501 InitVariantFromGUIDAsString(&IID_NULL, NULL);
502 }
503
504 for(i=0; i<sizeof(testcases)/sizeof(testcases[0]); i++) {
505 memset(&propvar, 0, sizeof(PROPVARIANT));
506 hres = InitPropVariantFromGUIDAsString(testcases[i].guid, &propvar);
507 ok(hres == S_OK, "%d) InitPropVariantFromGUIDAsString returned %x\n", i, hres);
508 ok(propvar.vt == VT_LPWSTR, "%d) propvar.vt = %d\n", i, propvar.vt);
509 ok(!strcmp_wa(propvar.u.pwszVal, testcases[i].str), "%d) propvar.u.pwszVal = %s\n",
510 i, wine_dbgstr_w(propvar.u.pwszVal));
511 CoTaskMemFree(propvar.u.pwszVal);
512
513 memset(&var, 0, sizeof(VARIANT));
514 hres = InitVariantFromGUIDAsString(testcases[i].guid, &var);
515 ok(hres == S_OK, "%d) InitVariantFromGUIDAsString returned %x\n", i, hres);
516 ok(V_VT(&var) == VT_BSTR, "%d) V_VT(&var) = %d\n", i, V_VT(&var));
517 ok(SysStringLen(V_BSTR(&var)) == 38, "SysStringLen returned %d\n",
518 SysStringLen(V_BSTR(&var)));
519 ok(!strcmp_wa(V_BSTR(&var), testcases[i].str), "%d) V_BSTR(&var) = %s\n",
520 i, wine_dbgstr_w(V_BSTR(&var)));
521 VariantClear(&var);
522 }
523 }
524
525 static void test_InitPropVariantFromBuffer(void)
526 {
527 static const char data_in[] = "test";
528 PROPVARIANT propvar;
529 VARIANT var;
530 HRESULT hres;
531 void *data_out;
532 LONG size;
533
534 hres = InitPropVariantFromBuffer(NULL, 0, &propvar);
535 ok(hres == S_OK, "InitPropVariantFromBuffer returned %x\n", hres);
536 ok(propvar.vt == (VT_VECTOR|VT_UI1), "propvar.vt = %d\n", propvar.vt);
537 ok(propvar.u.caub.cElems == 0, "cElems = %d\n", propvar.u.caub.cElems == 0);
538 PropVariantClear(&propvar);
539
540 hres = InitPropVariantFromBuffer(data_in, 4, &propvar);
541 ok(hres == S_OK, "InitPropVariantFromBuffer returned %x\n", hres);
542 ok(propvar.vt == (VT_VECTOR|VT_UI1), "propvar.vt = %d\n", propvar.vt);
543 ok(propvar.u.caub.cElems == 4, "cElems = %d\n", propvar.u.caub.cElems == 0);
544 ok(!memcmp(propvar.u.caub.pElems, data_in, 4), "Data inside array is incorrect\n");
545 PropVariantClear(&propvar);
546
547 hres = InitVariantFromBuffer(NULL, 0, &var);
548 ok(hres == S_OK, "InitVariantFromBuffer returned %x\n", hres);
549 ok(V_VT(&var) == (VT_ARRAY|VT_UI1), "V_VT(&var) = %d\n", V_VT(&var));
550 size = SafeArrayGetDim(V_ARRAY(&var));
551 ok(size == 1, "SafeArrayGetDim returned %d\n", size);
552 hres = SafeArrayGetLBound(V_ARRAY(&var), 1, &size);
553 ok(hres == S_OK, "SafeArrayGetLBound returned %x\n", hres);
554 ok(size == 0, "LBound = %d\n", size);
555 hres = SafeArrayGetUBound(V_ARRAY(&var), 1, &size);
556 ok(hres == S_OK, "SafeArrayGetUBound returned %x\n", hres);
557 ok(size == -1, "UBound = %d\n", size);
558 VariantClear(&var);
559
560 hres = InitVariantFromBuffer(data_in, 4, &var);
561 ok(hres == S_OK, "InitVariantFromBuffer returned %x\n", hres);
562 ok(V_VT(&var) == (VT_ARRAY|VT_UI1), "V_VT(&var) = %d\n", V_VT(&var));
563 size = SafeArrayGetDim(V_ARRAY(&var));
564 ok(size == 1, "SafeArrayGetDim returned %d\n", size);
565 hres = SafeArrayGetLBound(V_ARRAY(&var), 1, &size);
566 ok(hres == S_OK, "SafeArrayGetLBound returned %x\n", hres);
567 ok(size == 0, "LBound = %d\n", size);
568 hres = SafeArrayGetUBound(V_ARRAY(&var), 1, &size);
569 ok(hres == S_OK, "SafeArrayGetUBound returned %x\n", hres);
570 ok(size == 3, "UBound = %d\n", size);
571 hres = SafeArrayAccessData(V_ARRAY(&var), &data_out);
572 ok(hres == S_OK, "SafeArrayAccessData failed %x\n", hres);
573 ok(!memcmp(data_in, data_out, 4), "Data inside safe array is incorrect\n");
574 hres = SafeArrayUnaccessData(V_ARRAY(&var));
575 ok(hres == S_OK, "SafeArrayUnaccessData failed %x\n", hres);
576 VariantClear(&var);
577 }
578
579 static void test_PropVariantToGUID(void)
580 {
581 PROPVARIANT propvar;
582 VARIANT var;
583 GUID guid;
584 HRESULT hres;
585
586 hres = InitPropVariantFromGUIDAsString(&IID_NULL, &propvar);
587 ok(hres == S_OK, "InitPropVariantFromGUIDAsString failed %x\n", hres);
588
589 hres = PropVariantToGUID(&propvar, &guid);
590 ok(hres == S_OK, "PropVariantToGUID failed %x\n", hres);
591 ok(!memcmp(&IID_NULL, &guid, sizeof(GUID)), "incorrect GUID created: %s\n", show_guid(&guid, NULL));
592 PropVariantClear(&propvar);
593
594 hres = InitPropVariantFromGUIDAsString(&dummy_guid, &propvar);
595 ok(hres == S_OK, "InitPropVariantFromGUIDAsString failed %x\n", hres);
596
597 hres = PropVariantToGUID(&propvar, &guid);
598 ok(hres == S_OK, "PropVariantToGUID failed %x\n", hres);
599 ok(!memcmp(&dummy_guid, &guid, sizeof(GUID)), "incorrect GUID created: %s\n", show_guid(&guid, NULL));
600
601 ok(propvar.vt == VT_LPWSTR, "incorrect PROPVARIANT type: %d\n", propvar.vt);
602 propvar.u.pwszVal[1] = 'd';
603 propvar.u.pwszVal[2] = 'E';
604 propvar.u.pwszVal[3] = 'a';
605 hres = PropVariantToGUID(&propvar, &guid);
606 ok(hres == S_OK, "PropVariantToGUID failed %x\n", hres);
607 ok(!memcmp(&dummy_guid, &guid, sizeof(GUID)), "incorrect GUID created: %s\n", show_guid(&guid, NULL));
608
609 propvar.u.pwszVal[1] = 'z';
610 hres = PropVariantToGUID(&propvar, &guid);
611 ok(hres == E_INVALIDARG, "PropVariantToGUID returned %x\n", hres);
612 PropVariantClear(&propvar);
613
614
615 hres = InitVariantFromGUIDAsString(&IID_NULL, &var);
616 ok(hres == S_OK, "InitVariantFromGUIDAsString failed %x\n", hres);
617
618 hres = VariantToGUID(&var, &guid);
619 ok(hres == S_OK, "VariantToGUID failed %x\n", hres);
620 ok(!memcmp(&IID_NULL, &guid, sizeof(GUID)), "incorrect GUID created: %s\n", show_guid(&guid, NULL));
621 VariantClear(&var);
622
623 hres = InitVariantFromGUIDAsString(&dummy_guid, &var);
624 ok(hres == S_OK, "InitVariantFromGUIDAsString failed %x\n", hres);
625
626 hres = VariantToGUID(&var, &guid);
627 ok(hres == S_OK, "VariantToGUID failed %x\n", hres);
628 ok(!memcmp(&dummy_guid, &guid, sizeof(GUID)), "incorrect GUID created: %s\n", show_guid(&guid, NULL));
629
630 ok(V_VT(&var) == VT_BSTR, "incorrect VARIANT type: %d\n", V_VT(&var));
631 V_BSTR(&var)[1] = 'z';
632 hres = VariantToGUID(&var, &guid);
633 ok(hres == E_FAIL, "VariantToGUID returned %x\n", hres);
634
635 V_BSTR(&var)[1] = 'd';
636 propvar.vt = V_VT(&var);
637 propvar.u.bstrVal = V_BSTR(&var);
638 V_VT(&var) = VT_EMPTY;
639 hres = PropVariantToGUID(&propvar, &guid);
640 ok(hres == S_OK, "PropVariantToGUID failed %x\n", hres);
641 ok(!memcmp(&dummy_guid, &guid, sizeof(GUID)), "incorrect GUID created: %s\n", show_guid(&guid, NULL));
642 PropVariantClear(&propvar);
643 }
644
645 static void test_PropVariantCompare(void)
646 {
647 PROPVARIANT empty, null, emptyarray, i2_0, i2_2, i4_large, i4_largeneg, i4_2, str_2, str_02, str_b;
648 INT res;
649 static const WCHAR str_2W[] = {'2', 0};
650 static const WCHAR str_02W[] = {'0', '2', 0};
651 static const WCHAR str_bW[] = {'b', 0};
652 SAFEARRAY emptysafearray;
653
654 PropVariantInit(&empty);
655 PropVariantInit(&null);
656 PropVariantInit(&emptyarray);
657 PropVariantInit(&i2_0);
658 PropVariantInit(&i2_2);
659 PropVariantInit(&i4_large);
660 PropVariantInit(&i4_largeneg);
661 PropVariantInit(&i4_2);
662 PropVariantInit(&str_2);
663 PropVariantInit(&str_b);
664
665 empty.vt = VT_EMPTY;
666 null.vt = VT_NULL;
667 emptyarray.vt = VT_ARRAY | VT_I4;
668 emptyarray.u.parray = &emptysafearray;
669 emptysafearray.cDims = 1;
670 emptysafearray.fFeatures = FADF_FIXEDSIZE;
671 emptysafearray.cbElements = 4;
672 emptysafearray.cLocks = 0;
673 emptysafearray.pvData = NULL;
674 emptysafearray.rgsabound[0].cElements = 0;
675 emptysafearray.rgsabound[0].lLbound = 0;
676 i2_0.vt = VT_I2;
677 i2_0.u.iVal = 0;
678 i2_2.vt = VT_I2;
679 i2_2.u.iVal = 2;
680 i4_large.vt = VT_I4;
681 i4_large.u.lVal = 65536;
682 i4_largeneg.vt = VT_I4;
683 i4_largeneg.u.lVal = -65536;
684 i4_2.vt = VT_I4;
685 i4_2.u.lVal = 2;
686 str_2.vt = VT_BSTR;
687 str_2.u.bstrVal = SysAllocString(str_2W);
688 str_02.vt = VT_BSTR;
689 str_02.u.bstrVal = SysAllocString(str_02W);
690 str_b.vt = VT_BSTR;
691 str_b.u.bstrVal = SysAllocString(str_bW);
692
693 res = PropVariantCompareEx(&empty, &empty, 0, 0);
694 ok(res == 0, "res=%i\n", res);
695
696 res = PropVariantCompareEx(&empty, &null, 0, 0);
697 ok(res == 0, "res=%i\n", res);
698
699 res = PropVariantCompareEx(&null, &emptyarray, 0, 0);
700 ok(res == 0, "res=%i\n", res);
701
702 res = PropVariantCompareEx(&null, &i2_0, 0, 0);
703 ok(res == -1, "res=%i\n", res);
704
705 res = PropVariantCompareEx(&i2_0, &null, 0, 0);
706 ok(res == 1, "res=%i\n", res);
707
708 res = PropVariantCompareEx(&null, &i2_0, 0, PVCF_TREATEMPTYASGREATERTHAN);
709 ok(res == 1, "res=%i\n", res);
710
711 res = PropVariantCompareEx(&i2_0, &null, 0, PVCF_TREATEMPTYASGREATERTHAN);
712 ok(res == -1, "res=%i\n", res);
713
714 res = PropVariantCompareEx(&i2_2, &i2_0, 0, 0);
715 ok(res == 1, "res=%i\n", res);
716
717 res = PropVariantCompareEx(&i2_0, &i2_2, 0, 0);
718 ok(res == -1, "res=%i\n", res);
719
720 /* Always return -1 if second value cannot be converted to first type */
721 res = PropVariantCompareEx(&i2_0, &i4_large, 0, 0);
722 ok(res == -1, "res=%i\n", res);
723
724 res = PropVariantCompareEx(&i2_0, &i4_largeneg, 0, 0);
725 ok(res == -1, "res=%i\n", res);
726
727 res = PropVariantCompareEx(&i4_large, &i2_0, 0, 0);
728 ok(res == 1, "res=%i\n", res);
729
730 res = PropVariantCompareEx(&i4_largeneg, &i2_0, 0, 0);
731 ok(res == -1, "res=%i\n", res);
732
733 res = PropVariantCompareEx(&i2_2, &i4_2, 0, 0);
734 ok(res == 0, "res=%i\n", res);
735
736 res = PropVariantCompareEx(&i2_2, &str_2, 0, 0);
737 todo_wine ok(res == 0, "res=%i\n", res);
738
739 res = PropVariantCompareEx(&i2_2, &str_02, 0, 0);
740 todo_wine ok(res == 0, "res=%i\n", res);
741
742 res = PropVariantCompareEx(&str_2, &i2_2, 0, 0);
743 todo_wine ok(res == 0, "res=%i\n", res);
744
745 res = PropVariantCompareEx(&str_02, &i2_2, 0, 0);
746 ok(res == -1, "res=%i\n", res);
747
748 res = PropVariantCompareEx(&str_02, &str_2, 0, 0);
749 ok(res == -1, "res=%i\n", res);
750
751 res = PropVariantCompareEx(&str_02, &str_b, 0, 0);
752 ok(res == -1, "res=%i\n", res);
753
754 res = PropVariantCompareEx(&str_2, &str_02, 0, 0);
755 ok(res == 1, "res=%i\n", res);
756
757 res = PropVariantCompareEx(&i4_large, &str_b, 0, 0);
758 todo_wine ok(res == -5 /* ??? */, "res=%i\n", res);
759
760 SysFreeString(str_2.u.bstrVal);
761 SysFreeString(str_02.u.bstrVal);
762 SysFreeString(str_b.u.bstrVal);
763 }
764
765 static inline const char* debugstr_longlong(ULONGLONG ll)
766 {
767 static char string[17];
768 if (sizeof(ll) > sizeof(unsigned long) && ll >> 32)
769 sprintf(string, "%lx%08lx", (unsigned long)(ll >> 32), (unsigned long)ll);
770 else
771 sprintf(string, "%lx", (unsigned long)ll);
772 return string;
773 }
774
775 static void test_intconversions(void)
776 {
777 PROPVARIANT propvar;
778 SHORT sval;
779 USHORT usval;
780 LONG lval;
781 ULONG ulval;
782 LONGLONG llval;
783 ULONGLONG ullval;
784 HRESULT hr;
785
786 propvar.vt = 0xdead;
787 hr = PropVariantClear(&propvar);
788 ok (FAILED(hr), "PropVariantClear fails on invalid vt.\n");
789
790 propvar.vt = VT_I8;
791 PropVariantClear(&propvar);
792
793 propvar.vt = VT_I8;
794 propvar.u.hVal.QuadPart = (LONGLONG)1 << 63;
795
796 hr = PropVariantToInt64(&propvar, &llval);
797 ok(hr == S_OK, "hr=%x\n", hr);
798 ok(llval == (LONGLONG)1 << 63, "got wrong value %s\n", debugstr_longlong(llval));
799
800 hr = PropVariantToUInt64(&propvar, &ullval);
801 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr);
802
803 hr = PropVariantToInt32(&propvar, &lval);
804 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr);
805
806 hr = PropVariantToUInt32(&propvar, &ulval);
807 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr);
808
809 hr = PropVariantToInt16(&propvar, &sval);
810 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr);
811
812 hr = PropVariantToUInt16(&propvar, &usval);
813 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr);
814
815 propvar.vt = VT_UI8;
816 propvar.u.uhVal.QuadPart = 5;
817
818 hr = PropVariantToInt64(&propvar, &llval);
819 ok(hr == S_OK, "hr=%x\n", hr);
820 ok(llval == 5, "got wrong value %s\n", debugstr_longlong(llval));
821
822 hr = PropVariantToUInt64(&propvar, &ullval);
823 ok(hr == S_OK, "hr=%x\n", hr);
824 ok(ullval == 5, "got wrong value %s\n", debugstr_longlong(ullval));
825
826 hr = PropVariantToInt32(&propvar, &lval);
827 ok(hr == S_OK, "hr=%x\n", hr);
828 ok(lval == 5, "got wrong value %d\n", lval);
829
830 hr = PropVariantToUInt32(&propvar, &ulval);
831 ok(hr == S_OK, "hr=%x\n", hr);
832 ok(ulval == 5, "got wrong value %d\n", ulval);
833
834 hr = PropVariantToInt16(&propvar, &sval);
835 ok(hr == S_OK, "hr=%x\n", hr);
836 ok(sval == 5, "got wrong value %d\n", sval);
837
838 hr = PropVariantToUInt16(&propvar, &usval);
839 ok(hr == S_OK, "hr=%x\n", hr);
840 ok(usval == 5, "got wrong value %d\n", usval);
841
842 propvar.vt = VT_I8;
843 propvar.u.hVal.QuadPart = -5;
844
845 hr = PropVariantToInt64(&propvar, &llval);
846 ok(hr == S_OK, "hr=%x\n", hr);
847 ok(llval == -5, "got wrong value %s\n", debugstr_longlong(llval));
848
849 hr = PropVariantToUInt64(&propvar, &ullval);
850 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr);
851
852 hr = PropVariantToInt32(&propvar, &lval);
853 ok(hr == S_OK, "hr=%x\n", hr);
854 ok(lval == -5, "got wrong value %d\n", lval);
855
856 hr = PropVariantToUInt32(&propvar, &ulval);
857 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr);
858
859 hr = PropVariantToInt16(&propvar, &sval);
860 ok(hr == S_OK, "hr=%x\n", hr);
861 ok(sval == -5, "got wrong value %d\n", sval);
862
863 hr = PropVariantToUInt16(&propvar, &usval);
864 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr);
865
866 propvar.vt = VT_UI4;
867 propvar.u.ulVal = 6;
868
869 hr = PropVariantToInt64(&propvar, &llval);
870 ok(hr == S_OK, "hr=%x\n", hr);
871 ok(llval == 6, "got wrong value %s\n", debugstr_longlong(llval));
872
873 propvar.vt = VT_I4;
874 propvar.u.lVal = -6;
875
876 hr = PropVariantToInt64(&propvar, &llval);
877 ok(hr == S_OK, "hr=%x\n", hr);
878 ok(llval == -6, "got wrong value %s\n", debugstr_longlong(llval));
879
880 propvar.vt = VT_UI2;
881 propvar.u.uiVal = 7;
882
883 hr = PropVariantToInt64(&propvar, &llval);
884 ok(hr == S_OK, "hr=%x\n", hr);
885 ok(llval == 7, "got wrong value %s\n", debugstr_longlong(llval));
886
887 propvar.vt = VT_I2;
888 propvar.u.iVal = -7;
889
890 hr = PropVariantToInt64(&propvar, &llval);
891 ok(hr == S_OK, "hr=%x\n", hr);
892 ok(llval == -7, "got wrong value %s\n", debugstr_longlong(llval));
893 }
894
895 START_TEST(propsys)
896 {
897 test_PSStringFromPropertyKey();
898 test_PSPropertyKeyFromString();
899 test_PSRefreshPropertySchema();
900 test_InitPropVariantFromGUIDAsString();
901 test_InitPropVariantFromBuffer();
902 test_PropVariantToGUID();
903 test_PropVariantCompare();
904 test_intconversions();
905 }