msvcp110: Add missing exports to msvcp110.spec file.
[wine.git] / dlls / propsys / tests / propsys.c
blobfc595f95705e1e6db61a535e96bb39796303c7be
1 /*
2 * Unit tests for Windows property system
4 * Copyright 2006 Paul Vriens
5 * Copyright 2010 Andrew Nguyen
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.
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.
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
22 #define COBJMACROS
24 #include <stdarg.h>
25 #include <stdio.h>
27 #define NONAMELESSUNION
29 #include "windef.h"
30 #include "winbase.h"
31 #include "objbase.h"
32 #include "initguid.h"
33 #include "propsys.h"
34 #include "propvarutil.h"
35 #include "wine/test.h"
37 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
38 DEFINE_GUID(dummy_guid, 0xdeadbeef, 0xdead, 0xbeef, 0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0xba, 0xbe);
39 DEFINE_GUID(expect_guid, 0x12345678, 0x1234, 0x1234, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12);
41 static int strcmp_wa(LPCWSTR strw, const char *stra)
43 CHAR buf[512];
44 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
45 return lstrcmpA(stra, buf);
48 static void test_PSStringFromPropertyKey(void)
50 static const WCHAR fillerW[] = {'X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X',
51 'X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X',
52 'X','X','X','X','X','X','X','X','X','X'};
53 static const WCHAR zero_fillerW[] = {'\0','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X',
54 'X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X',
55 'X','X','X','X','X','X','X','X','X','X','X','X','X','X'};
56 static const WCHAR zero_truncatedW[] = {'\0','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0',
57 '0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0',
58 '0','0','0','}',' ','\0','9','X','X','X','X','X','X','X','X','X'};
59 static const WCHAR zero_truncated2W[] = {'\0','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0',
60 '0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0',
61 '0','0','0','}',' ','\0','9','2','7','6','9','4','9','2','X','X'};
62 static const WCHAR zero_truncated3W[] = {'\0','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0',
63 '0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0',
64 '0','0','0','}',' ','\0','9','2','7','6','9','4','9','2','4','X'};
65 static const WCHAR zero_truncated4W[] = {'\0','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0',
66 '0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0',
67 '0','0','0','}',' ','\0','7','X','X','X','X','X','X','X','X','X'};
68 static const WCHAR truncatedW[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
69 '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
70 '0','}',' ','\0','9','X','X','X','X','X','X','X','X','X'};
71 static const WCHAR truncated2W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
72 '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
73 '0','}',' ','\0','9','2','7','6','9','4','9','2','X','X'};
74 static const WCHAR truncated3W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
75 '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
76 '0','}',' ','\0','9','2','7','6','9','4','9','2','4','X'};
77 static const WCHAR truncated4W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
78 '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
79 '0','}',' ','\0','7','X','X','X','X','X','X','X','X','X'};
80 static const WCHAR expectedW[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
81 '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
82 '0','}',' ','4','2','9','4','9','6','7','2','9','5',0};
83 static const WCHAR expected2W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
84 '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
85 '0','}',' ','1','3','5','7','9','\0','X','X','X','X','X'};
86 static const WCHAR expected3W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
87 '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
88 '0','}',' ','0','\0','X','X','X','X','X','X','X','X','X'};
89 PROPERTYKEY prop = {GUID_NULL, ~0U};
90 PROPERTYKEY prop2 = {GUID_NULL, 13579};
91 PROPERTYKEY prop3 = {GUID_NULL, 0};
92 WCHAR out[PKEYSTR_MAX];
93 HRESULT ret;
95 const struct
97 REFPROPERTYKEY pkey;
98 LPWSTR psz;
99 UINT cch;
100 HRESULT hr_expect;
101 const WCHAR *buf_expect;
102 BOOL hr_broken;
103 HRESULT hr2;
104 BOOL buf_broken;
105 const WCHAR *buf2;
106 } testcases[] =
108 {NULL, NULL, 0, E_POINTER},
109 {&prop, NULL, 0, E_POINTER},
110 {&prop, NULL, PKEYSTR_MAX, E_POINTER},
111 {NULL, out, 0, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), fillerW},
112 {NULL, out, PKEYSTR_MAX, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), zero_fillerW, FALSE, 0, TRUE, fillerW},
113 {&prop, out, 0, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), fillerW},
114 {&prop, out, GUIDSTRING_MAX, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), fillerW},
115 {&prop, out, GUIDSTRING_MAX + 1, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), fillerW},
116 {&prop, out, GUIDSTRING_MAX + 2, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), zero_truncatedW, TRUE, S_OK, TRUE, truncatedW},
117 {&prop, out, PKEYSTR_MAX - 2, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), zero_truncated2W, TRUE, S_OK, TRUE, truncated2W},
118 {&prop, out, PKEYSTR_MAX - 1, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), zero_truncated3W, TRUE, S_OK, TRUE, truncated3W},
119 {&prop, out, PKEYSTR_MAX, S_OK, expectedW},
120 {&prop2, out, GUIDSTRING_MAX + 2, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), zero_truncated4W, TRUE, S_OK, TRUE, truncated4W},
121 {&prop2, out, GUIDSTRING_MAX + 6, S_OK, expected2W},
122 {&prop2, out, PKEYSTR_MAX, S_OK, expected2W},
123 {&prop3, out, GUIDSTRING_MAX + 1, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), fillerW},
124 {&prop3, out, GUIDSTRING_MAX + 2, S_OK, expected3W},
125 {&prop3, out, PKEYSTR_MAX, S_OK, expected3W},
128 int i;
130 for (i = 0; i < sizeof(testcases)/sizeof(testcases[0]); i++)
132 if (testcases[i].psz)
133 memcpy(testcases[i].psz, fillerW, PKEYSTR_MAX * sizeof(WCHAR));
135 ret = PSStringFromPropertyKey(testcases[i].pkey,
136 testcases[i].psz,
137 testcases[i].cch);
138 ok(ret == testcases[i].hr_expect ||
139 broken(testcases[i].hr_broken && ret == testcases[i].hr2), /* Vista/Win2k8 */
140 "[%d] Expected PSStringFromPropertyKey to return 0x%08x, got 0x%08x\n",
141 i, testcases[i].hr_expect, ret);
143 if (testcases[i].psz)
144 ok(!memcmp(testcases[i].psz, testcases[i].buf_expect, PKEYSTR_MAX * sizeof(WCHAR)) ||
145 broken(testcases[i].buf_broken &&
146 !memcmp(testcases[i].psz, testcases[i].buf2, PKEYSTR_MAX * sizeof(WCHAR))), /* Vista/Win2k8 */
147 "[%d] Unexpected output contents\n", i);
151 static void test_PSPropertyKeyFromString(void)
153 static const WCHAR emptyW[] = {0};
154 static const WCHAR fmtid_clsidW[] = {'S','t','d','F','o','n','t',' ','1',0};
155 static const WCHAR fmtid_truncatedW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
156 '1','2','3','4','-',0};
157 static const WCHAR fmtid_nobracketsW[] = {'1','2','3','4','5','6','7','8','-','1','2','3','4','-',
158 '1','2','3','4','-','1','2','3','4','-',
159 '1','2','3','4','5','6','7','8','9','0','1','2',0};
160 static const WCHAR fmtid_badbracketW[] = {'X','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
161 '1','2','3','4','-','1','2','3','4','-',
162 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
163 static const WCHAR fmtid_badcharW[] = {'{','X','2','3','4','5','6','7','8','-','1','2','3','4','-',
164 '1','2','3','4','-','1','2','3','4','-',
165 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
166 static const WCHAR fmtid_badchar2W[] = {'{','1','2','3','4','5','6','7','X','-','1','2','3','4','-',
167 '1','2','3','4','-','1','2','3','4','-',
168 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
169 static const WCHAR fmtid_baddashW[] = {'{','1','2','3','4','5','6','7','8','X','1','2','3','4','-',
170 '1','2','3','4','-','1','2','3','4','-',
171 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
172 static const WCHAR fmtid_badchar3W[] = {'{','1','2','3','4','5','6','7','8','-','X','2','3','4','-',
173 '1','2','3','4','-','1','2','3','4','-',
174 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
175 static const WCHAR fmtid_badchar4W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','X','-',
176 '1','2','3','4','-','1','2','3','4','-',
177 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
178 static const WCHAR fmtid_baddash2W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','X',
179 '1','2','3','4','-','1','2','3','4','-',
180 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
181 static const WCHAR fmtid_badchar5W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
182 'X','2','3','4','-','1','2','3','4','-',
183 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
184 static const WCHAR fmtid_badchar6W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
185 '1','2','3','X','-','1','2','3','4','-',
186 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
187 static const WCHAR fmtid_baddash3W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
188 '1','2','3','4','X','1','2','3','4','-',
189 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
190 static const WCHAR fmtid_badchar7W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
191 '1','2','3','4','-','X','2','3','4','-',
192 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
193 static const WCHAR fmtid_badchar8W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
194 '1','2','3','4','-','1','2','3','X','-',
195 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
196 static const WCHAR fmtid_baddash4W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
197 '1','2','3','4','-','1','2','3','4','X',
198 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
199 static const WCHAR fmtid_badchar9W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
200 '1','2','3','4','-','1','2','3','4','-',
201 'X','2','3','4','5','6','7','8','9','0','1','2','}',0};
202 static const WCHAR fmtid_badchar9_adjW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
203 '1','2','3','4','-','1','2','3','4','-',
204 '1','X','3','4','5','6','7','8','9','0','1','2','}',0};
205 static const WCHAR fmtid_badchar10W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
206 '1','2','3','4','-','1','2','3','4','-',
207 '1','2','X','4','5','6','7','8','9','0','1','2','}',0};
208 static const WCHAR fmtid_badchar11W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
209 '1','2','3','4','-','1','2','3','4','-',
210 '1','2','3','4','X','6','7','8','9','0','1','2','}',0};
211 static const WCHAR fmtid_badchar12W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
212 '1','2','3','4','-','1','2','3','4','-',
213 '1','2','3','4','5','6','X','8','9','0','1','2','}',0};
214 static const WCHAR fmtid_badchar13W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
215 '1','2','3','4','-','1','2','3','4','-',
216 '1','2','3','4','5','6','7','8','X','0','1','2','}',0};
217 static const WCHAR fmtid_badchar14W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
218 '1','2','3','4','-','1','2','3','4','-',
219 '1','2','3','4','5','6','7','8','9','0','X','2','}',0};
220 static const WCHAR fmtid_badbracket2W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
221 '1','2','3','4','-','1','2','3','4','-',
222 '1','2','3','4','5','6','7','8','9','0','1','2','X',0};
223 static const WCHAR fmtid_spaceW[] = {' ','{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
224 '1','2','3','4','-','1','2','3','4','-',
225 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
226 static const WCHAR fmtid_spaceendW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
227 '1','2','3','4','-','1','2','3','4','-',
228 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',0};
229 static const WCHAR fmtid_spacesendW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
230 '1','2','3','4','-','1','2','3','4','-',
231 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',' ',' ',0};
232 static const WCHAR fmtid_nopidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
233 '1','2','3','4','-','1','2','3','4','-',
234 '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
235 static const WCHAR fmtid_badpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
236 '1','2','3','4','-','1','2','3','4','-',
237 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','D','E','A','D',0};
238 static const WCHAR fmtid_adjpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
239 '1','2','3','4','-','1','2','3','4','-',
240 '1','2','3','4','5','6','7','8','9','0','1','2','}','1','3','5','7','9',0};
241 static const WCHAR fmtid_spacespidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
242 '1','2','3','4','-','1','2','3','4','-',
243 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',' ',' ','1','3','5','7','9',0};
244 static const WCHAR fmtid_negpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
245 '1','2','3','4','-','1','2','3','4','-',
246 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-','1','3','5','7','9',0};
247 static const WCHAR fmtid_negnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
248 '1','2','3','4','-','1','2','3','4','-',
249 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-','-','1','3','5','7','9',0};
250 static const WCHAR fmtid_negnegnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
251 '1','2','3','4','-','1','2','3','4','-',
252 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-','-','-','1','3','5','7','9',0};
253 static const WCHAR fmtid_negspacepidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
254 '1','2','3','4','-','1','2','3','4','-',
255 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-',' ','1','3','5','7','9',0};
256 static const WCHAR fmtid_negspacenegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
257 '1','2','3','4','-','1','2','3','4','-',
258 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-',' ','-','1','3','5','7','9',0};
259 static const WCHAR fmtid_negspacespidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
260 '1','2','3','4','-','1','2','3','4','-',
261 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-',' ','-',' ','-','1','3','5','7','9',0};
262 static const WCHAR fmtid_pospidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
263 '1','2','3','4','-','1','2','3','4','-',
264 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','+','1','3','5','7','9',0};
265 static const WCHAR fmtid_posnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
266 '1','2','3','4','-','1','2','3','4','-',
267 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','+','-','+','-','1','3','5','7','9',0};
268 static const WCHAR fmtid_symbolpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
269 '1','2','3','4','-','1','2','3','4','-',
270 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','+','/','$','-','1','3','5','7','9',0};
271 static const WCHAR fmtid_letterpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
272 '1','2','3','4','-','1','2','3','4','-',
273 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','A','B','C','D','1','3','5','7','9',0};
274 static const WCHAR fmtid_spacepadpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
275 '1','2','3','4','-','1','2','3','4','-',
276 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','1','3','5','7','9',' ',' ',' ',0};
277 static const WCHAR fmtid_spacemixpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
278 '1','2','3','4','-','1','2','3','4','-',
279 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','1',' ','3',' ','5','7','9',' ',' ',' ',0};
280 static const WCHAR fmtid_tabpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
281 '1','2','3','4','-','1','2','3','4','-',
282 '1','2','3','4','5','6','7','8','9','0','1','2','}','\t','1','3','5','7','9',0};
283 static const WCHAR fmtid_hexpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
284 '1','2','3','4','-','1','2','3','4','-',
285 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','0','x','D','E','A','D',0};
286 static const WCHAR fmtid_mixedpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
287 '1','2','3','4','-','1','2','3','4','-',
288 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','A','9','B','5','C','3','D','1',0};
289 static const WCHAR fmtid_overflowpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
290 '1','2','3','4','-','1','2','3','4','-',
291 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','1','2','3','4','5','6','7','8','9','0','1',0};
292 static const WCHAR fmtid_commapidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
293 '1','2','3','4','-','1','2','3','4','-',
294 '1','2','3','4','5','6','7','8','9','0','1','2','}',',','1','3','5','7','9',0};
295 static const WCHAR fmtid_commaspidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
296 '1','2','3','4','-','1','2','3','4','-',
297 '1','2','3','4','5','6','7','8','9','0','1','2','}',',',',',',','1','3','5','7','9',0};
298 static const WCHAR fmtid_commaspacepidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
299 '1','2','3','4','-','1','2','3','4','-',
300 '1','2','3','4','5','6','7','8','9','0','1','2','}',',',' ','1','3','5','7','9',0};
301 static const WCHAR fmtid_spacecommapidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
302 '1','2','3','4','-','1','2','3','4','-',
303 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',','1','3','5','7','9',0};
304 static const WCHAR fmtid_spccommaspcpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
305 '1','2','3','4','-','1','2','3','4','-',
306 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',',' ','1','3','5','7','9',0};
307 static const WCHAR fmtid_spacescommaspidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
308 '1','2','3','4','-','1','2','3','4','-',
309 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',',' ',',','1','3','5','7','9',0};
310 static const WCHAR fmtid_commanegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
311 '1','2','3','4','-','1','2','3','4','-',
312 '1','2','3','4','5','6','7','8','9','0','1','2','}',',','-','1','3','5','7','9',0};
313 static const WCHAR fmtid_spccommanegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
314 '1','2','3','4','-','1','2','3','4','-',
315 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',','-','1','3','5','7','9',0};
316 static const WCHAR fmtid_commaspcnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
317 '1','2','3','4','-','1','2','3','4','-',
318 '1','2','3','4','5','6','7','8','9','0','1','2','}',',',' ','-','1','3','5','7','9',0};
319 static const WCHAR fmtid_spccommaspcnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
320 '1','2','3','4','-','1','2','3','4','-',
321 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',',' ','-','1','3','5','7','9',0};
322 static const WCHAR fmtid_commanegspcpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
323 '1','2','3','4','-','1','2','3','4','-',
324 '1','2','3','4','5','6','7','8','9','0','1','2','}',',','-',' ','1','3','5','7','9',0};
325 static const WCHAR fmtid_negcommapidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
326 '1','2','3','4','-','1','2','3','4','-',
327 '1','2','3','4','5','6','7','8','9','0','1','2','}','-',',','1','3','5','7','9',0};
328 static const WCHAR fmtid_normalpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
329 '1','2','3','4','-','1','2','3','4','-',
330 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','1','3','5','7','9',0};
331 PROPERTYKEY out_init = {dummy_guid, 0xdeadbeef};
332 PROPERTYKEY out;
333 HRESULT ret;
335 const struct
337 LPCWSTR pwzString;
338 PROPERTYKEY *pkey;
339 HRESULT hr_expect;
340 PROPERTYKEY pkey_expect;
341 } testcases[] =
343 {NULL, NULL, E_POINTER},
344 {NULL, &out, E_POINTER, out_init},
345 {emptyW, NULL, E_POINTER},
346 {emptyW, &out, E_INVALIDARG, {GUID_NULL, 0}},
347 {fmtid_clsidW, &out, E_INVALIDARG, {GUID_NULL, 0}},
348 {fmtid_truncatedW, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0,0,0,0,0,0,0,0}}, 0}},
349 {fmtid_nobracketsW, &out, E_INVALIDARG, {GUID_NULL, 0}},
350 {fmtid_badbracketW, &out, E_INVALIDARG, {GUID_NULL, 0}},
351 {fmtid_badcharW, &out, E_INVALIDARG, {GUID_NULL, 0}},
352 {fmtid_badchar2W, &out, E_INVALIDARG, {GUID_NULL, 0}},
353 {fmtid_baddashW, &out, E_INVALIDARG, { {0x12345678,0,0,{0,0,0,0,0,0,0,0}}, 0}},
354 {fmtid_badchar3W, &out, E_INVALIDARG, { {0x12345678,0,0,{0,0,0,0,0,0,0,0}}, 0}},
355 {fmtid_badchar4W, &out, E_INVALIDARG, { {0x12345678,0,0,{0,0,0,0,0,0,0,0}}, 0}},
356 {fmtid_baddash2W, &out, E_INVALIDARG, { {0x12345678,0,0,{0,0,0,0,0,0,0,0}}, 0}},
357 {fmtid_badchar5W, &out, E_INVALIDARG, { {0x12345678,0x1234,0,{0,0,0,0,0,0,0,0}}, 0}},
358 {fmtid_badchar6W, &out, E_INVALIDARG, { {0x12345678,0x1234,0,{0,0,0,0,0,0,0,0}}, 0}},
359 {fmtid_baddash3W, &out, E_INVALIDARG, { {0x12345678,0x1234,0,{0,0,0,0,0,0,0,0}}, 0}},
360 {fmtid_badchar7W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0,0,0,0,0,0,0,0}}, 0}},
361 {fmtid_badchar8W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0,0,0,0,0,0,0}}, 0}},
362 {fmtid_baddash4W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0,0,0,0,0,0,0}}, 0}},
363 {fmtid_badchar9W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0,0,0,0,0,0}}, 0}},
364 {fmtid_badchar9_adjW, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0,0,0,0,0,0}}, 0}},
365 {fmtid_badchar10W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0,0,0,0,0}}, 0}},
366 {fmtid_badchar11W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0,0,0,0}}, 0}},
367 {fmtid_badchar12W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0,0,0}}, 0}},
368 {fmtid_badchar13W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0x78,0,0}}, 0}},
369 {fmtid_badchar14W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0x78,0x90,0}}, 0}},
370 {fmtid_badbracket2W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0x78,0x90,0x00}}, 0 }},
371 {fmtid_spaceW, &out, E_INVALIDARG, {GUID_NULL, 0 }},
372 {fmtid_spaceendW, &out, E_INVALIDARG, {expect_guid, 0}},
373 {fmtid_spacesendW, &out, E_INVALIDARG, {expect_guid, 0}},
374 {fmtid_nopidW, &out, E_INVALIDARG, {expect_guid, 0}},
375 {fmtid_badpidW, &out, S_OK, {expect_guid, 0}},
376 {fmtid_adjpidW, &out, S_OK, {expect_guid, 13579}},
377 {fmtid_spacespidW, &out, S_OK, {expect_guid, 13579}},
378 {fmtid_negpidW, &out, S_OK, {expect_guid, 13579}},
379 {fmtid_negnegpidW, &out, S_OK, {expect_guid, 4294953717U}},
380 {fmtid_negnegnegpidW, &out, S_OK, {expect_guid, 0}},
381 {fmtid_negspacepidW, &out, S_OK, {expect_guid, 13579}},
382 {fmtid_negspacenegpidW, &out, S_OK, {expect_guid, 4294953717U}},
383 {fmtid_negspacespidW, &out, S_OK, {expect_guid, 0}},
384 {fmtid_pospidW, &out, S_OK, {expect_guid, 0}},
385 {fmtid_posnegpidW, &out, S_OK, {expect_guid, 0}},
386 {fmtid_symbolpidW, &out, S_OK, {expect_guid, 0}},
387 {fmtid_letterpidW, &out, S_OK, {expect_guid, 0}},
388 {fmtid_spacepadpidW, &out, S_OK, {expect_guid, 13579}},
389 {fmtid_spacemixpidW, &out, S_OK, {expect_guid, 1}},
390 {fmtid_tabpidW, &out, S_OK, {expect_guid, 0}},
391 {fmtid_hexpidW, &out, S_OK, {expect_guid, 0}},
392 {fmtid_mixedpidW, &out, S_OK, {expect_guid, 0}},
393 {fmtid_overflowpidW, &out, S_OK, {expect_guid, 3755744309U}},
394 {fmtid_commapidW, &out, S_OK, {expect_guid, 13579}},
395 {fmtid_commaspidW, &out, S_OK, {expect_guid, 0}},
396 {fmtid_commaspacepidW, &out, S_OK, {expect_guid, 13579}},
397 {fmtid_spacecommapidW, &out, S_OK, {expect_guid, 13579}},
398 {fmtid_spccommaspcpidW, &out, S_OK, {expect_guid, 13579}},
399 {fmtid_spacescommaspidW, &out, S_OK, {expect_guid, 0}},
400 {fmtid_commanegpidW, &out, S_OK, {expect_guid, 4294953717U}},
401 {fmtid_spccommanegpidW, &out, S_OK, {expect_guid, 4294953717U}},
402 {fmtid_commaspcnegpidW, &out, S_OK, {expect_guid, 4294953717U}},
403 {fmtid_spccommaspcnegpidW, &out, S_OK, {expect_guid, 4294953717U}},
404 {fmtid_commanegspcpidW, &out, S_OK, {expect_guid, 0U}},
405 {fmtid_negcommapidW, &out, S_OK, {expect_guid, 0}},
406 {fmtid_normalpidW, &out, S_OK, {expect_guid, 13579}},
409 int i;
411 for (i = 0; i < sizeof(testcases)/sizeof(testcases[0]); i++)
413 if (testcases[i].pkey)
414 *testcases[i].pkey = out_init;
416 ret = PSPropertyKeyFromString(testcases[i].pwzString, testcases[i].pkey);
417 ok(ret == testcases[i].hr_expect,
418 "[%d] Expected PSPropertyKeyFromString to return 0x%08x, got 0x%08x\n",
419 i, testcases[i].hr_expect, ret);
421 if (testcases[i].pkey)
423 ok(IsEqualGUID(&testcases[i].pkey->fmtid, &testcases[i].pkey_expect.fmtid),
424 "[%d] Expected GUID %s, got %s\n",
425 i, wine_dbgstr_guid(&testcases[i].pkey_expect.fmtid), wine_dbgstr_guid(&testcases[i].pkey->fmtid));
426 ok(testcases[i].pkey->pid == testcases[i].pkey_expect.pid,
427 "[%d] Expected property ID %u, got %u\n",
428 i, testcases[i].pkey_expect.pid, testcases[i].pkey->pid);
433 static void test_PSRefreshPropertySchema(void)
435 HRESULT ret;
437 ret = PSRefreshPropertySchema();
438 todo_wine
439 ok(ret == CO_E_NOTINITIALIZED,
440 "Expected PSRefreshPropertySchema to return CO_E_NOTINITIALIZED, got 0x%08x\n", ret);
442 CoInitialize(NULL);
444 ret = PSRefreshPropertySchema();
445 ok(ret == S_OK,
446 "Expected PSRefreshPropertySchema to return S_OK, got 0x%08x\n", ret);
448 CoUninitialize();
451 static void test_InitPropVariantFromGUIDAsString(void)
453 PROPVARIANT propvar;
454 VARIANT var;
455 HRESULT hres;
456 int i;
458 const struct {
459 REFGUID guid;
460 const char *str;
461 } testcases[] = {
462 {&IID_NULL, "{00000000-0000-0000-0000-000000000000}" },
463 {&dummy_guid, "{DEADBEEF-DEAD-BEEF-DEAD-BEEFCAFEBABE}" },
466 hres = InitPropVariantFromGUIDAsString(NULL, &propvar);
467 ok(hres == E_FAIL, "InitPropVariantFromGUIDAsString returned %x\n", hres);
469 if(0) {
470 /* Returns strange data on Win7, crashes on older systems */
471 InitVariantFromGUIDAsString(NULL, &var);
473 /* Crashes on windows */
474 InitPropVariantFromGUIDAsString(&IID_NULL, NULL);
475 InitVariantFromGUIDAsString(&IID_NULL, NULL);
478 for(i=0; i<sizeof(testcases)/sizeof(testcases[0]); i++) {
479 memset(&propvar, 0, sizeof(PROPVARIANT));
480 hres = InitPropVariantFromGUIDAsString(testcases[i].guid, &propvar);
481 ok(hres == S_OK, "%d) InitPropVariantFromGUIDAsString returned %x\n", i, hres);
482 ok(propvar.vt == VT_LPWSTR, "%d) propvar.vt = %d\n", i, propvar.vt);
483 ok(!strcmp_wa(propvar.u.pwszVal, testcases[i].str), "%d) propvar.u.pwszVal = %s\n",
484 i, wine_dbgstr_w(propvar.u.pwszVal));
485 CoTaskMemFree(propvar.u.pwszVal);
487 memset(&var, 0, sizeof(VARIANT));
488 hres = InitVariantFromGUIDAsString(testcases[i].guid, &var);
489 ok(hres == S_OK, "%d) InitVariantFromGUIDAsString returned %x\n", i, hres);
490 ok(V_VT(&var) == VT_BSTR, "%d) V_VT(&var) = %d\n", i, V_VT(&var));
491 ok(SysStringLen(V_BSTR(&var)) == 38, "SysStringLen returned %d\n",
492 SysStringLen(V_BSTR(&var)));
493 ok(!strcmp_wa(V_BSTR(&var), testcases[i].str), "%d) V_BSTR(&var) = %s\n",
494 i, wine_dbgstr_w(V_BSTR(&var)));
495 VariantClear(&var);
499 static void test_InitPropVariantFromBuffer(void)
501 static const char data_in[] = "test";
502 PROPVARIANT propvar;
503 VARIANT var;
504 HRESULT hres;
505 void *data_out;
506 LONG size;
508 hres = InitPropVariantFromBuffer(NULL, 0, &propvar);
509 ok(hres == S_OK, "InitPropVariantFromBuffer returned %x\n", hres);
510 ok(propvar.vt == (VT_VECTOR|VT_UI1), "propvar.vt = %d\n", propvar.vt);
511 ok(propvar.u.caub.cElems == 0, "cElems = %d\n", propvar.u.caub.cElems == 0);
512 PropVariantClear(&propvar);
514 hres = InitPropVariantFromBuffer(data_in, 4, &propvar);
515 ok(hres == S_OK, "InitPropVariantFromBuffer returned %x\n", hres);
516 ok(propvar.vt == (VT_VECTOR|VT_UI1), "propvar.vt = %d\n", propvar.vt);
517 ok(propvar.u.caub.cElems == 4, "cElems = %d\n", propvar.u.caub.cElems == 0);
518 ok(!memcmp(propvar.u.caub.pElems, data_in, 4), "Data inside array is incorrect\n");
519 PropVariantClear(&propvar);
521 hres = InitVariantFromBuffer(NULL, 0, &var);
522 ok(hres == S_OK, "InitVariantFromBuffer returned %x\n", hres);
523 ok(V_VT(&var) == (VT_ARRAY|VT_UI1), "V_VT(&var) = %d\n", V_VT(&var));
524 size = SafeArrayGetDim(V_ARRAY(&var));
525 ok(size == 1, "SafeArrayGetDim returned %d\n", size);
526 hres = SafeArrayGetLBound(V_ARRAY(&var), 1, &size);
527 ok(hres == S_OK, "SafeArrayGetLBound returned %x\n", hres);
528 ok(size == 0, "LBound = %d\n", size);
529 hres = SafeArrayGetUBound(V_ARRAY(&var), 1, &size);
530 ok(hres == S_OK, "SafeArrayGetUBound returned %x\n", hres);
531 ok(size == -1, "UBound = %d\n", size);
532 VariantClear(&var);
534 hres = InitVariantFromBuffer(data_in, 4, &var);
535 ok(hres == S_OK, "InitVariantFromBuffer returned %x\n", hres);
536 ok(V_VT(&var) == (VT_ARRAY|VT_UI1), "V_VT(&var) = %d\n", V_VT(&var));
537 size = SafeArrayGetDim(V_ARRAY(&var));
538 ok(size == 1, "SafeArrayGetDim returned %d\n", size);
539 hres = SafeArrayGetLBound(V_ARRAY(&var), 1, &size);
540 ok(hres == S_OK, "SafeArrayGetLBound returned %x\n", hres);
541 ok(size == 0, "LBound = %d\n", size);
542 hres = SafeArrayGetUBound(V_ARRAY(&var), 1, &size);
543 ok(hres == S_OK, "SafeArrayGetUBound returned %x\n", hres);
544 ok(size == 3, "UBound = %d\n", size);
545 hres = SafeArrayAccessData(V_ARRAY(&var), &data_out);
546 ok(hres == S_OK, "SafeArrayAccessData failed %x\n", hres);
547 ok(!memcmp(data_in, data_out, 4), "Data inside safe array is incorrect\n");
548 hres = SafeArrayUnaccessData(V_ARRAY(&var));
549 ok(hres == S_OK, "SafeArrayUnaccessData failed %x\n", hres);
550 VariantClear(&var);
553 static void test_PropVariantToGUID(void)
555 PROPVARIANT propvar;
556 VARIANT var;
557 GUID guid;
558 HRESULT hres;
560 hres = InitPropVariantFromGUIDAsString(&IID_NULL, &propvar);
561 ok(hres == S_OK, "InitPropVariantFromGUIDAsString failed %x\n", hres);
563 hres = PropVariantToGUID(&propvar, &guid);
564 ok(hres == S_OK, "PropVariantToGUID failed %x\n", hres);
565 ok(!memcmp(&IID_NULL, &guid, sizeof(GUID)), "incorrect GUID created: %s\n", wine_dbgstr_guid(&guid));
566 PropVariantClear(&propvar);
568 hres = InitPropVariantFromGUIDAsString(&dummy_guid, &propvar);
569 ok(hres == S_OK, "InitPropVariantFromGUIDAsString failed %x\n", hres);
571 hres = PropVariantToGUID(&propvar, &guid);
572 ok(hres == S_OK, "PropVariantToGUID failed %x\n", hres);
573 ok(!memcmp(&dummy_guid, &guid, sizeof(GUID)), "incorrect GUID created: %s\n", wine_dbgstr_guid(&guid));
575 ok(propvar.vt == VT_LPWSTR, "incorrect PROPVARIANT type: %d\n", propvar.vt);
576 propvar.u.pwszVal[1] = 'd';
577 propvar.u.pwszVal[2] = 'E';
578 propvar.u.pwszVal[3] = 'a';
579 hres = PropVariantToGUID(&propvar, &guid);
580 ok(hres == S_OK, "PropVariantToGUID failed %x\n", hres);
581 ok(!memcmp(&dummy_guid, &guid, sizeof(GUID)), "incorrect GUID created: %s\n", wine_dbgstr_guid(&guid));
583 propvar.u.pwszVal[1] = 'z';
584 hres = PropVariantToGUID(&propvar, &guid);
585 ok(hres == E_INVALIDARG, "PropVariantToGUID returned %x\n", hres);
586 PropVariantClear(&propvar);
589 hres = InitVariantFromGUIDAsString(&IID_NULL, &var);
590 ok(hres == S_OK, "InitVariantFromGUIDAsString failed %x\n", hres);
592 hres = VariantToGUID(&var, &guid);
593 ok(hres == S_OK, "VariantToGUID failed %x\n", hres);
594 ok(!memcmp(&IID_NULL, &guid, sizeof(GUID)), "incorrect GUID created: %s\n", wine_dbgstr_guid(&guid));
595 VariantClear(&var);
597 hres = InitVariantFromGUIDAsString(&dummy_guid, &var);
598 ok(hres == S_OK, "InitVariantFromGUIDAsString failed %x\n", hres);
600 hres = VariantToGUID(&var, &guid);
601 ok(hres == S_OK, "VariantToGUID failed %x\n", hres);
602 ok(!memcmp(&dummy_guid, &guid, sizeof(GUID)), "incorrect GUID created: %s\n", wine_dbgstr_guid(&guid));
604 ok(V_VT(&var) == VT_BSTR, "incorrect VARIANT type: %d\n", V_VT(&var));
605 V_BSTR(&var)[1] = 'z';
606 hres = VariantToGUID(&var, &guid);
607 ok(hres == E_FAIL, "VariantToGUID returned %x\n", hres);
609 V_BSTR(&var)[1] = 'd';
610 propvar.vt = V_VT(&var);
611 propvar.u.bstrVal = V_BSTR(&var);
612 V_VT(&var) = VT_EMPTY;
613 hres = PropVariantToGUID(&propvar, &guid);
614 ok(hres == S_OK, "PropVariantToGUID failed %x\n", hres);
615 ok(!memcmp(&dummy_guid, &guid, sizeof(GUID)), "incorrect GUID created: %s\n", wine_dbgstr_guid(&guid));
616 PropVariantClear(&propvar);
619 static void test_PropVariantCompare(void)
621 PROPVARIANT empty, null, emptyarray, i2_0, i2_2, i4_large, i4_largeneg, i4_2, str_2, str_02, str_b;
622 INT res;
623 static const WCHAR str_2W[] = {'2', 0};
624 static const WCHAR str_02W[] = {'0', '2', 0};
625 static const WCHAR str_bW[] = {'b', 0};
626 SAFEARRAY emptysafearray;
628 PropVariantInit(&empty);
629 PropVariantInit(&null);
630 PropVariantInit(&emptyarray);
631 PropVariantInit(&i2_0);
632 PropVariantInit(&i2_2);
633 PropVariantInit(&i4_large);
634 PropVariantInit(&i4_largeneg);
635 PropVariantInit(&i4_2);
636 PropVariantInit(&str_2);
637 PropVariantInit(&str_b);
639 empty.vt = VT_EMPTY;
640 null.vt = VT_NULL;
641 emptyarray.vt = VT_ARRAY | VT_I4;
642 emptyarray.u.parray = &emptysafearray;
643 emptysafearray.cDims = 1;
644 emptysafearray.fFeatures = FADF_FIXEDSIZE;
645 emptysafearray.cbElements = 4;
646 emptysafearray.cLocks = 0;
647 emptysafearray.pvData = NULL;
648 emptysafearray.rgsabound[0].cElements = 0;
649 emptysafearray.rgsabound[0].lLbound = 0;
650 i2_0.vt = VT_I2;
651 i2_0.u.iVal = 0;
652 i2_2.vt = VT_I2;
653 i2_2.u.iVal = 2;
654 i4_large.vt = VT_I4;
655 i4_large.u.lVal = 65536;
656 i4_largeneg.vt = VT_I4;
657 i4_largeneg.u.lVal = -65536;
658 i4_2.vt = VT_I4;
659 i4_2.u.lVal = 2;
660 str_2.vt = VT_BSTR;
661 str_2.u.bstrVal = SysAllocString(str_2W);
662 str_02.vt = VT_BSTR;
663 str_02.u.bstrVal = SysAllocString(str_02W);
664 str_b.vt = VT_BSTR;
665 str_b.u.bstrVal = SysAllocString(str_bW);
667 res = PropVariantCompareEx(&empty, &empty, 0, 0);
668 ok(res == 0, "res=%i\n", res);
670 res = PropVariantCompareEx(&empty, &null, 0, 0);
671 ok(res == 0, "res=%i\n", res);
673 res = PropVariantCompareEx(&null, &emptyarray, 0, 0);
674 ok(res == 0, "res=%i\n", res);
676 res = PropVariantCompareEx(&null, &i2_0, 0, 0);
677 ok(res == -1, "res=%i\n", res);
679 res = PropVariantCompareEx(&i2_0, &null, 0, 0);
680 ok(res == 1, "res=%i\n", res);
682 res = PropVariantCompareEx(&null, &i2_0, 0, PVCF_TREATEMPTYASGREATERTHAN);
683 ok(res == 1, "res=%i\n", res);
685 res = PropVariantCompareEx(&i2_0, &null, 0, PVCF_TREATEMPTYASGREATERTHAN);
686 ok(res == -1, "res=%i\n", res);
688 res = PropVariantCompareEx(&i2_2, &i2_0, 0, 0);
689 ok(res == 1, "res=%i\n", res);
691 res = PropVariantCompareEx(&i2_0, &i2_2, 0, 0);
692 ok(res == -1, "res=%i\n", res);
694 /* Always return -1 if second value cannot be converted to first type */
695 res = PropVariantCompareEx(&i2_0, &i4_large, 0, 0);
696 ok(res == -1, "res=%i\n", res);
698 res = PropVariantCompareEx(&i2_0, &i4_largeneg, 0, 0);
699 ok(res == -1, "res=%i\n", res);
701 res = PropVariantCompareEx(&i4_large, &i2_0, 0, 0);
702 ok(res == 1, "res=%i\n", res);
704 res = PropVariantCompareEx(&i4_largeneg, &i2_0, 0, 0);
705 ok(res == -1, "res=%i\n", res);
707 res = PropVariantCompareEx(&i2_2, &i4_2, 0, 0);
708 ok(res == 0, "res=%i\n", res);
710 res = PropVariantCompareEx(&i2_2, &str_2, 0, 0);
711 todo_wine ok(res == 0, "res=%i\n", res);
713 res = PropVariantCompareEx(&i2_2, &str_02, 0, 0);
714 todo_wine ok(res == 0, "res=%i\n", res);
716 res = PropVariantCompareEx(&str_2, &i2_2, 0, 0);
717 todo_wine ok(res == 0, "res=%i\n", res);
719 res = PropVariantCompareEx(&str_02, &i2_2, 0, 0);
720 ok(res == -1, "res=%i\n", res);
722 res = PropVariantCompareEx(&str_02, &str_2, 0, 0);
723 ok(res == -1, "res=%i\n", res);
725 res = PropVariantCompareEx(&str_02, &str_b, 0, 0);
726 ok(res == -1, "res=%i\n", res);
728 res = PropVariantCompareEx(&str_2, &str_02, 0, 0);
729 ok(res == 1, "res=%i\n", res);
731 res = PropVariantCompareEx(&i4_large, &str_b, 0, 0);
732 todo_wine ok(res == -5 /* ??? */, "res=%i\n", res);
734 SysFreeString(str_2.u.bstrVal);
735 SysFreeString(str_02.u.bstrVal);
736 SysFreeString(str_b.u.bstrVal);
739 static inline const char* debugstr_longlong(ULONGLONG ll)
741 static char string[17];
742 if (sizeof(ll) > sizeof(unsigned long) && ll >> 32)
743 sprintf(string, "%lx%08lx", (unsigned long)(ll >> 32), (unsigned long)ll);
744 else
745 sprintf(string, "%lx", (unsigned long)ll);
746 return string;
749 static void test_intconversions(void)
751 PROPVARIANT propvar;
752 SHORT sval;
753 USHORT usval;
754 LONG lval;
755 ULONG ulval;
756 LONGLONG llval;
757 ULONGLONG ullval;
758 HRESULT hr;
760 propvar.vt = 0xdead;
761 hr = PropVariantClear(&propvar);
762 ok (FAILED(hr), "PropVariantClear fails on invalid vt.\n");
764 propvar.vt = VT_I8;
765 PropVariantClear(&propvar);
767 propvar.vt = VT_I8;
768 propvar.u.hVal.QuadPart = (LONGLONG)1 << 63;
770 hr = PropVariantToInt64(&propvar, &llval);
771 ok(hr == S_OK, "hr=%x\n", hr);
772 ok(llval == (LONGLONG)1 << 63, "got wrong value %s\n", debugstr_longlong(llval));
774 hr = PropVariantToUInt64(&propvar, &ullval);
775 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr);
777 hr = PropVariantToInt32(&propvar, &lval);
778 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr);
780 hr = PropVariantToUInt32(&propvar, &ulval);
781 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr);
783 hr = PropVariantToInt16(&propvar, &sval);
784 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr);
786 hr = PropVariantToUInt16(&propvar, &usval);
787 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr);
789 propvar.vt = VT_UI8;
790 propvar.u.uhVal.QuadPart = 5;
792 hr = PropVariantToInt64(&propvar, &llval);
793 ok(hr == S_OK, "hr=%x\n", hr);
794 ok(llval == 5, "got wrong value %s\n", debugstr_longlong(llval));
796 hr = PropVariantToUInt64(&propvar, &ullval);
797 ok(hr == S_OK, "hr=%x\n", hr);
798 ok(ullval == 5, "got wrong value %s\n", debugstr_longlong(ullval));
800 hr = PropVariantToInt32(&propvar, &lval);
801 ok(hr == S_OK, "hr=%x\n", hr);
802 ok(lval == 5, "got wrong value %d\n", lval);
804 hr = PropVariantToUInt32(&propvar, &ulval);
805 ok(hr == S_OK, "hr=%x\n", hr);
806 ok(ulval == 5, "got wrong value %d\n", ulval);
808 hr = PropVariantToInt16(&propvar, &sval);
809 ok(hr == S_OK, "hr=%x\n", hr);
810 ok(sval == 5, "got wrong value %d\n", sval);
812 hr = PropVariantToUInt16(&propvar, &usval);
813 ok(hr == S_OK, "hr=%x\n", hr);
814 ok(usval == 5, "got wrong value %d\n", usval);
816 propvar.vt = VT_I8;
817 propvar.u.hVal.QuadPart = -5;
819 hr = PropVariantToInt64(&propvar, &llval);
820 ok(hr == S_OK, "hr=%x\n", hr);
821 ok(llval == -5, "got wrong value %s\n", debugstr_longlong(llval));
823 hr = PropVariantToUInt64(&propvar, &ullval);
824 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr);
826 hr = PropVariantToInt32(&propvar, &lval);
827 ok(hr == S_OK, "hr=%x\n", hr);
828 ok(lval == -5, "got wrong value %d\n", lval);
830 hr = PropVariantToUInt32(&propvar, &ulval);
831 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr);
833 hr = PropVariantToInt16(&propvar, &sval);
834 ok(hr == S_OK, "hr=%x\n", hr);
835 ok(sval == -5, "got wrong value %d\n", sval);
837 hr = PropVariantToUInt16(&propvar, &usval);
838 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr);
840 propvar.vt = VT_UI4;
841 propvar.u.ulVal = 6;
843 hr = PropVariantToInt64(&propvar, &llval);
844 ok(hr == S_OK, "hr=%x\n", hr);
845 ok(llval == 6, "got wrong value %s\n", debugstr_longlong(llval));
847 propvar.vt = VT_I4;
848 propvar.u.lVal = -6;
850 hr = PropVariantToInt64(&propvar, &llval);
851 ok(hr == S_OK, "hr=%x\n", hr);
852 ok(llval == -6, "got wrong value %s\n", debugstr_longlong(llval));
854 propvar.vt = VT_UI2;
855 propvar.u.uiVal = 7;
857 hr = PropVariantToInt64(&propvar, &llval);
858 ok(hr == S_OK, "hr=%x\n", hr);
859 ok(llval == 7, "got wrong value %s\n", debugstr_longlong(llval));
861 propvar.vt = VT_I2;
862 propvar.u.iVal = -7;
864 hr = PropVariantToInt64(&propvar, &llval);
865 ok(hr == S_OK, "hr=%x\n", hr);
866 ok(llval == -7, "got wrong value %s\n", debugstr_longlong(llval));
869 START_TEST(propsys)
871 test_PSStringFromPropertyKey();
872 test_PSPropertyKeyFromString();
873 test_PSRefreshPropertySchema();
874 test_InitPropVariantFromGUIDAsString();
875 test_InitPropVariantFromBuffer();
876 test_PropVariantToGUID();
877 test_PropVariantCompare();
878 test_intconversions();