dinput: Fix printing NULL strings.
[wine] / dlls / propsys / tests / 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 COBJMACROS
23
24 #include <stdarg.h>
25 #include <stdio.h>
26
27 #define NONAMELESSUNION
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "objbase.h"
32 #include "propsys.h"
33 #include "propvarutil.h"
34 #include "initguid.h"
35 #include "wine/test.h"
36
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);
40
41 static char *show_guid(const GUID *guid, char *buf)
42 {
43     sprintf(buf,
44         "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
45         guid->Data1, guid->Data2, guid->Data3,
46         guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
47         guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
48
49     return buf;
50 }
51
52 static int strcmp_wa(LPCWSTR strw, const char *stra)
53 {
54     CHAR buf[512];
55     WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
56     return lstrcmpA(stra, buf);
57 }
58
59 static void test_PSStringFromPropertyKey(void)
60 {
61     static const WCHAR fillerW[] = {'X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X',
62                                     'X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X',
63                                     'X','X','X','X','X','X','X','X','X','X'};
64     static const WCHAR zero_fillerW[] = {'\0','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X',
65                                          'X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X',
66                                          'X','X','X','X','X','X','X','X','X','X','X','X','X','X'};
67     static const WCHAR zero_truncatedW[] = {'\0','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0',
68                                             '0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0',
69                                             '0','0','0','}',' ','\0','9','X','X','X','X','X','X','X','X','X'};
70     static const WCHAR zero_truncated2W[] = {'\0','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0',
71                                              '0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0',
72                                              '0','0','0','}',' ','\0','9','2','7','6','9','4','9','2','X','X'};
73     static const WCHAR zero_truncated3W[] = {'\0','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0',
74                                             '0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0',
75                                             '0','0','0','}',' ','\0','9','2','7','6','9','4','9','2','4','X'};
76     static const WCHAR zero_truncated4W[] = {'\0','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0',
77                                              '0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0',
78                                              '0','0','0','}',' ','\0','7','X','X','X','X','X','X','X','X','X'};
79     static const WCHAR truncatedW[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
80                                         '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
81                                         '0','}',' ','\0','9','X','X','X','X','X','X','X','X','X'};
82     static const WCHAR truncated2W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
83                                         '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
84                                         '0','}',' ','\0','9','2','7','6','9','4','9','2','X','X'};
85     static const WCHAR truncated3W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
86                                        '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
87                                        '0','}',' ','\0','9','2','7','6','9','4','9','2','4','X'};
88     static const WCHAR truncated4W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
89                                         '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
90                                         '0','}',' ','\0','7','X','X','X','X','X','X','X','X','X'};
91     static const WCHAR expectedW[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
92                                       '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
93                                       '0','}',' ','4','2','9','4','9','6','7','2','9','5',0};
94     static const WCHAR expected2W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
95                                        '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
96                                        '0','}',' ','1','3','5','7','9','\0','X','X','X','X','X'};
97     static const WCHAR expected3W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
98                                        '0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
99                                        '0','}',' ','0','\0','X','X','X','X','X','X','X','X','X'};
100     PROPERTYKEY prop = {GUID_NULL, ~0U};
101     PROPERTYKEY prop2 = {GUID_NULL, 13579};
102     PROPERTYKEY prop3 = {GUID_NULL, 0};
103     WCHAR out[PKEYSTR_MAX];
104     HRESULT ret;
105
106     const struct
107     {
108         REFPROPERTYKEY pkey;
109         LPWSTR psz;
110         UINT cch;
111         HRESULT hr_expect;
112         const WCHAR *buf_expect;
113         int hr_broken;
114         HRESULT hr2;
115         int buf_broken;
116         const WCHAR *buf2;
117     } testcases[] =
118     {
119         {NULL, NULL, 0, E_POINTER},
120         {&prop, NULL, 0, E_POINTER},
121         {&prop, NULL, PKEYSTR_MAX, E_POINTER},
122         {NULL, out, 0, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), fillerW},
123         {NULL, out, PKEYSTR_MAX, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), zero_fillerW, 0, 0, 1, fillerW},
124         {&prop, out, 0, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), fillerW},
125         {&prop, out, GUIDSTRING_MAX, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), fillerW},
126         {&prop, out, GUIDSTRING_MAX + 1, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), fillerW},
127         {&prop, out, GUIDSTRING_MAX + 2, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), zero_truncatedW, 1, S_OK, 1, truncatedW},
128         {&prop, out, PKEYSTR_MAX - 2, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), zero_truncated2W, 1, S_OK, 1, truncated2W},
129         {&prop, out, PKEYSTR_MAX - 1, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), zero_truncated3W, 1, S_OK, 1, truncated3W},
130         {&prop, out, PKEYSTR_MAX, S_OK, expectedW},
131         {&prop2, out, GUIDSTRING_MAX + 2, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), zero_truncated4W, 1, S_OK, 1, truncated4W},
132         {&prop2, out, GUIDSTRING_MAX + 6, S_OK, expected2W},
133         {&prop2, out, PKEYSTR_MAX, S_OK, expected2W},
134         {&prop3, out, GUIDSTRING_MAX + 1, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), fillerW},
135         {&prop3, out, GUIDSTRING_MAX + 2, S_OK, expected3W},
136         {&prop3, out, PKEYSTR_MAX, S_OK, expected3W},
137     };
138
139     int i;
140
141     for (i = 0; i < sizeof(testcases)/sizeof(testcases[0]); i++)
142     {
143         if (testcases[i].psz)
144             memcpy(testcases[i].psz, fillerW, PKEYSTR_MAX * sizeof(WCHAR));
145
146         ret = PSStringFromPropertyKey(testcases[i].pkey,
147                                       testcases[i].psz,
148                                       testcases[i].cch);
149         ok(ret == testcases[i].hr_expect ||
150            broken(testcases[i].hr_broken && ret == testcases[i].hr2), /* Vista/Win2k8 */
151            "[%d] Expected PSStringFromPropertyKey to return 0x%08x, got 0x%08x\n",
152            i, testcases[i].hr_expect, ret);
153
154         if (testcases[i].psz)
155             ok(!memcmp(testcases[i].psz, testcases[i].buf_expect, PKEYSTR_MAX * sizeof(WCHAR)) ||
156                 broken(testcases[i].buf_broken &&
157                        !memcmp(testcases[i].psz, testcases[i].buf2, PKEYSTR_MAX * sizeof(WCHAR))), /* Vista/Win2k8 */
158                "[%d] Unexpected output contents\n", i);
159     }
160 }
161
162 static void test_PSPropertyKeyFromString(void)
163 {
164     static const WCHAR emptyW[] = {0};
165     static const WCHAR fmtid_clsidW[] = {'S','t','d','F','o','n','t',' ','1',0};
166     static const WCHAR fmtid_truncatedW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
167                                              '1','2','3','4','-',0};
168     static const WCHAR fmtid_nobracketsW[] = {'1','2','3','4','5','6','7','8','-','1','2','3','4','-',
169                                               '1','2','3','4','-','1','2','3','4','-',
170                                               '1','2','3','4','5','6','7','8','9','0','1','2',0};
171     static const WCHAR fmtid_badbracketW[] = {'X','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
172                                               '1','2','3','4','-','1','2','3','4','-',
173                                               '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
174     static const WCHAR fmtid_badcharW[] = {'{','X','2','3','4','5','6','7','8','-','1','2','3','4','-',
175                                            '1','2','3','4','-','1','2','3','4','-',
176                                            '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
177     static const WCHAR fmtid_badchar2W[] = {'{','1','2','3','4','5','6','7','X','-','1','2','3','4','-',
178                                             '1','2','3','4','-','1','2','3','4','-',
179                                             '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
180     static const WCHAR fmtid_baddashW[] = {'{','1','2','3','4','5','6','7','8','X','1','2','3','4','-',
181                                            '1','2','3','4','-','1','2','3','4','-',
182                                            '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
183     static const WCHAR fmtid_badchar3W[] = {'{','1','2','3','4','5','6','7','8','-','X','2','3','4','-',
184                                             '1','2','3','4','-','1','2','3','4','-',
185                                             '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
186     static const WCHAR fmtid_badchar4W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','X','-',
187                                             '1','2','3','4','-','1','2','3','4','-',
188                                             '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
189     static const WCHAR fmtid_baddash2W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','X',
190                                             '1','2','3','4','-','1','2','3','4','-',
191                                             '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
192     static const WCHAR fmtid_badchar5W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
193                                             'X','2','3','4','-','1','2','3','4','-',
194                                             '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
195     static const WCHAR fmtid_badchar6W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
196                                             '1','2','3','X','-','1','2','3','4','-',
197                                             '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
198     static const WCHAR fmtid_baddash3W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
199                                             '1','2','3','4','X','1','2','3','4','-',
200                                             '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
201     static const WCHAR fmtid_badchar7W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
202                                             '1','2','3','4','-','X','2','3','4','-',
203                                             '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
204     static const WCHAR fmtid_badchar8W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
205                                             '1','2','3','4','-','1','2','3','X','-',
206                                             '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
207     static const WCHAR fmtid_baddash4W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
208                                             '1','2','3','4','-','1','2','3','4','X',
209                                             '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
210     static const WCHAR fmtid_badchar9W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
211                                             '1','2','3','4','-','1','2','3','4','-',
212                                             'X','2','3','4','5','6','7','8','9','0','1','2','}',0};
213     static const WCHAR fmtid_badchar9_adjW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
214                                                 '1','2','3','4','-','1','2','3','4','-',
215                                                 '1','X','3','4','5','6','7','8','9','0','1','2','}',0};
216     static const WCHAR fmtid_badchar10W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
217                                              '1','2','3','4','-','1','2','3','4','-',
218                                              '1','2','X','4','5','6','7','8','9','0','1','2','}',0};
219     static const WCHAR fmtid_badchar11W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
220                                              '1','2','3','4','-','1','2','3','4','-',
221                                              '1','2','3','4','X','6','7','8','9','0','1','2','}',0};
222     static const WCHAR fmtid_badchar12W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
223                                              '1','2','3','4','-','1','2','3','4','-',
224                                              '1','2','3','4','5','6','X','8','9','0','1','2','}',0};
225     static const WCHAR fmtid_badchar13W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
226                                              '1','2','3','4','-','1','2','3','4','-',
227                                              '1','2','3','4','5','6','7','8','X','0','1','2','}',0};
228     static const WCHAR fmtid_badchar14W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
229                                              '1','2','3','4','-','1','2','3','4','-',
230                                              '1','2','3','4','5','6','7','8','9','0','X','2','}',0};
231     static const WCHAR fmtid_badbracket2W[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
232                                                '1','2','3','4','-','1','2','3','4','-',
233                                                '1','2','3','4','5','6','7','8','9','0','1','2','X',0};
234     static const WCHAR fmtid_spaceW[] = {' ','{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
235                                          '1','2','3','4','-','1','2','3','4','-',
236                                          '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
237     static const WCHAR fmtid_spaceendW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
238                                             '1','2','3','4','-','1','2','3','4','-',
239                                             '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',0};
240     static const WCHAR fmtid_spacesendW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
241                                              '1','2','3','4','-','1','2','3','4','-',
242                                              '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',' ',' ',0};
243     static const WCHAR fmtid_nopidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
244                                          '1','2','3','4','-','1','2','3','4','-',
245                                          '1','2','3','4','5','6','7','8','9','0','1','2','}',0};
246     static const WCHAR fmtid_badpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
247                                           '1','2','3','4','-','1','2','3','4','-',
248                                           '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','D','E','A','D',0};
249     static const WCHAR fmtid_adjpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
250                                           '1','2','3','4','-','1','2','3','4','-',
251                                           '1','2','3','4','5','6','7','8','9','0','1','2','}','1','3','5','7','9',0};
252     static const WCHAR fmtid_spacespidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
253                                              '1','2','3','4','-','1','2','3','4','-',
254                                              '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',' ',' ','1','3','5','7','9',0};
255     static const WCHAR fmtid_negpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
256                                           '1','2','3','4','-','1','2','3','4','-',
257                                           '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-','1','3','5','7','9',0};
258     static const WCHAR fmtid_negnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
259                                              '1','2','3','4','-','1','2','3','4','-',
260                                              '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-','-','1','3','5','7','9',0};
261     static const WCHAR fmtid_negnegnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
262                                                 '1','2','3','4','-','1','2','3','4','-',
263                                                 '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-','-','-','1','3','5','7','9',0};
264     static const WCHAR fmtid_negspacepidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
265                                                '1','2','3','4','-','1','2','3','4','-',
266                                                '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-',' ','1','3','5','7','9',0};
267     static const WCHAR fmtid_negspacenegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
268                                                '1','2','3','4','-','1','2','3','4','-',
269                                                '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-',' ','-','1','3','5','7','9',0};
270     static const WCHAR fmtid_negspacespidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
271                                                '1','2','3','4','-','1','2','3','4','-',
272                                                '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','-',' ','-',' ','-','1','3','5','7','9',0};
273     static const WCHAR fmtid_pospidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
274                                           '1','2','3','4','-','1','2','3','4','-',
275                                           '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','+','1','3','5','7','9',0};
276     static const WCHAR fmtid_posnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
277                                              '1','2','3','4','-','1','2','3','4','-',
278                                              '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','+','-','+','-','1','3','5','7','9',0};
279     static const WCHAR fmtid_symbolpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
280                                              '1','2','3','4','-','1','2','3','4','-',
281                                              '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','+','/','$','-','1','3','5','7','9',0};
282     static const WCHAR fmtid_letterpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
283                                              '1','2','3','4','-','1','2','3','4','-',
284                                              '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','A','B','C','D','1','3','5','7','9',0};
285     static const WCHAR fmtid_spacepadpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
286                                                '1','2','3','4','-','1','2','3','4','-',
287                                                '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','1','3','5','7','9',' ',' ',' ',0};
288     static const WCHAR fmtid_spacemixpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
289                                                '1','2','3','4','-','1','2','3','4','-',
290                                                '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','1',' ','3',' ','5','7','9',' ',' ',' ',0};
291     static const WCHAR fmtid_tabpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
292                                           '1','2','3','4','-','1','2','3','4','-',
293                                           '1','2','3','4','5','6','7','8','9','0','1','2','}','\t','1','3','5','7','9',0};
294     static const WCHAR fmtid_hexpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
295                                           '1','2','3','4','-','1','2','3','4','-',
296                                           '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','0','x','D','E','A','D',0};
297     static const WCHAR fmtid_mixedpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
298                                             '1','2','3','4','-','1','2','3','4','-',
299                                             '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','A','9','B','5','C','3','D','1',0};
300     static const WCHAR fmtid_overflowpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
301                                                '1','2','3','4','-','1','2','3','4','-',
302                                                '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','1','2','3','4','5','6','7','8','9','0','1',0};
303     static const WCHAR fmtid_commapidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
304                                              '1','2','3','4','-','1','2','3','4','-',
305                                              '1','2','3','4','5','6','7','8','9','0','1','2','}',',','1','3','5','7','9',0};
306     static const WCHAR fmtid_commaspidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
307                                              '1','2','3','4','-','1','2','3','4','-',
308                                              '1','2','3','4','5','6','7','8','9','0','1','2','}',',',',',',','1','3','5','7','9',0};
309     static const WCHAR fmtid_commaspacepidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
310                                                  '1','2','3','4','-','1','2','3','4','-',
311                                                  '1','2','3','4','5','6','7','8','9','0','1','2','}',',',' ','1','3','5','7','9',0};
312     static const WCHAR fmtid_spacecommapidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
313                                                  '1','2','3','4','-','1','2','3','4','-',
314                                                  '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',','1','3','5','7','9',0};
315     static const WCHAR fmtid_spccommaspcpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
316                                                   '1','2','3','4','-','1','2','3','4','-',
317                                                   '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',',' ','1','3','5','7','9',0};
318     static const WCHAR fmtid_spacescommaspidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
319                                                    '1','2','3','4','-','1','2','3','4','-',
320                                                    '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',',' ',',','1','3','5','7','9',0};
321     static const WCHAR fmtid_commanegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
322                                                '1','2','3','4','-','1','2','3','4','-',
323                                                '1','2','3','4','5','6','7','8','9','0','1','2','}',',','-','1','3','5','7','9',0};
324     static const WCHAR fmtid_spccommanegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
325                                                '1','2','3','4','-','1','2','3','4','-',
326                                                '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',','-','1','3','5','7','9',0};
327     static const WCHAR fmtid_commaspcnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
328                                                '1','2','3','4','-','1','2','3','4','-',
329                                                '1','2','3','4','5','6','7','8','9','0','1','2','}',',',' ','-','1','3','5','7','9',0};
330     static const WCHAR fmtid_spccommaspcnegpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
331                                                '1','2','3','4','-','1','2','3','4','-',
332                                                '1','2','3','4','5','6','7','8','9','0','1','2','}',' ',',',' ','-','1','3','5','7','9',0};
333     static const WCHAR fmtid_commanegspcpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
334                                                '1','2','3','4','-','1','2','3','4','-',
335                                                '1','2','3','4','5','6','7','8','9','0','1','2','}',',','-',' ','1','3','5','7','9',0};
336     static const WCHAR fmtid_negcommapidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
337                                                '1','2','3','4','-','1','2','3','4','-',
338                                                '1','2','3','4','5','6','7','8','9','0','1','2','}','-',',','1','3','5','7','9',0};
339     static const WCHAR fmtid_normalpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-',
340                                              '1','2','3','4','-','1','2','3','4','-',
341                                              '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','1','3','5','7','9',0};
342     PROPERTYKEY out_init = {dummy_guid, 0xdeadbeef};
343     PROPERTYKEY out;
344     HRESULT ret;
345     char guid_buf[40], guid_buf2[40];
346
347     const struct
348     {
349         LPCWSTR pwzString;
350         PROPERTYKEY *pkey;
351         HRESULT hr_expect;
352         PROPERTYKEY pkey_expect;
353     } testcases[] =
354     {
355         {NULL, NULL, E_POINTER},
356         {NULL, &out, E_POINTER, out_init},
357         {emptyW, NULL, E_POINTER},
358         {emptyW, &out, E_INVALIDARG, {GUID_NULL, 0}},
359         {fmtid_clsidW, &out, E_INVALIDARG, {GUID_NULL, 0}},
360         {fmtid_truncatedW, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0,0,0,0,0,0,0,0}}, 0}},
361         {fmtid_nobracketsW, &out, E_INVALIDARG, {GUID_NULL, 0}},
362         {fmtid_badbracketW, &out, E_INVALIDARG, {GUID_NULL, 0}},
363         {fmtid_badcharW, &out, E_INVALIDARG, {GUID_NULL, 0}},
364         {fmtid_badchar2W, &out, E_INVALIDARG, {GUID_NULL, 0}},
365         {fmtid_baddashW, &out, E_INVALIDARG, { {0x12345678,0,0,{0,0,0,0,0,0,0,0}}, 0}},
366         {fmtid_badchar3W, &out, E_INVALIDARG, { {0x12345678,0,0,{0,0,0,0,0,0,0,0}}, 0}},
367         {fmtid_badchar4W, &out, E_INVALIDARG, { {0x12345678,0,0,{0,0,0,0,0,0,0,0}}, 0}},
368         {fmtid_baddash2W, &out, E_INVALIDARG, { {0x12345678,0,0,{0,0,0,0,0,0,0,0}}, 0}},
369         {fmtid_badchar5W, &out, E_INVALIDARG, { {0x12345678,0x1234,0,{0,0,0,0,0,0,0,0}}, 0}},
370         {fmtid_badchar6W, &out, E_INVALIDARG, { {0x12345678,0x1234,0,{0,0,0,0,0,0,0,0}}, 0}},
371         {fmtid_baddash3W, &out, E_INVALIDARG, { {0x12345678,0x1234,0,{0,0,0,0,0,0,0,0}}, 0}},
372         {fmtid_badchar7W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0,0,0,0,0,0,0,0}}, 0}},
373         {fmtid_badchar8W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0,0,0,0,0,0,0}}, 0}},
374         {fmtid_baddash4W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0,0,0,0,0,0,0}}, 0}},
375         {fmtid_badchar9W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0,0,0,0,0,0}}, 0}},
376         {fmtid_badchar9_adjW, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0,0,0,0,0,0}}, 0}},
377         {fmtid_badchar10W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0,0,0,0,0}}, 0}},
378         {fmtid_badchar11W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0,0,0,0}}, 0}},
379         {fmtid_badchar12W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0,0,0}}, 0}},
380         {fmtid_badchar13W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0x78,0,0}}, 0}},
381         {fmtid_badchar14W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0x78,0x90,0}}, 0}},
382         {fmtid_badbracket2W, &out, E_INVALIDARG, { {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0x78,0x90,0x00}}, 0 }},
383         {fmtid_spaceW, &out, E_INVALIDARG, {GUID_NULL, 0 }},
384         {fmtid_spaceendW, &out, E_INVALIDARG, {expect_guid, 0}},
385         {fmtid_spacesendW, &out, E_INVALIDARG, {expect_guid, 0}},
386         {fmtid_nopidW, &out, E_INVALIDARG, {expect_guid, 0}},
387         {fmtid_badpidW, &out, S_OK, {expect_guid, 0}},
388         {fmtid_adjpidW, &out, S_OK, {expect_guid, 13579}},
389         {fmtid_spacespidW, &out, S_OK, {expect_guid, 13579}},
390         {fmtid_negpidW, &out, S_OK, {expect_guid, 13579}},
391         {fmtid_negnegpidW, &out, S_OK, {expect_guid, 4294953717U}},
392         {fmtid_negnegnegpidW, &out, S_OK, {expect_guid, 0}},
393         {fmtid_negspacepidW, &out, S_OK, {expect_guid, 13579}},
394         {fmtid_negspacenegpidW, &out, S_OK, {expect_guid, 4294953717U}},
395         {fmtid_negspacespidW, &out, S_OK, {expect_guid, 0}},
396         {fmtid_pospidW, &out, S_OK, {expect_guid, 0}},
397         {fmtid_posnegpidW, &out, S_OK, {expect_guid, 0}},
398         {fmtid_symbolpidW, &out, S_OK, {expect_guid, 0}},
399         {fmtid_letterpidW, &out, S_OK, {expect_guid, 0}},
400         {fmtid_spacepadpidW, &out, S_OK, {expect_guid, 13579}},
401         {fmtid_spacemixpidW, &out, S_OK, {expect_guid, 1}},
402         {fmtid_tabpidW, &out, S_OK, {expect_guid, 0}},
403         {fmtid_hexpidW, &out, S_OK, {expect_guid, 0}},
404         {fmtid_mixedpidW, &out, S_OK, {expect_guid, 0}},
405         {fmtid_overflowpidW, &out, S_OK, {expect_guid, 3755744309U}},
406         {fmtid_commapidW, &out, S_OK, {expect_guid, 13579}},
407         {fmtid_commaspidW, &out, S_OK, {expect_guid, 0}},
408         {fmtid_commaspacepidW, &out, S_OK, {expect_guid, 13579}},
409         {fmtid_spacecommapidW, &out, S_OK, {expect_guid, 13579}},
410         {fmtid_spccommaspcpidW, &out, S_OK, {expect_guid, 13579}},
411         {fmtid_spacescommaspidW, &out, S_OK, {expect_guid, 0}},
412         {fmtid_commanegpidW, &out, S_OK, {expect_guid, 4294953717U}},
413         {fmtid_spccommanegpidW, &out, S_OK, {expect_guid, 4294953717U}},
414         {fmtid_commaspcnegpidW, &out, S_OK, {expect_guid, 4294953717U}},
415         {fmtid_spccommaspcnegpidW, &out, S_OK, {expect_guid, 4294953717U}},
416         {fmtid_commanegspcpidW, &out, S_OK, {expect_guid, 0U}},
417         {fmtid_negcommapidW, &out, S_OK, {expect_guid, 0}},
418         {fmtid_normalpidW, &out, S_OK, {expect_guid, 13579}},
419     };
420
421     int i;
422
423     for (i = 0; i < sizeof(testcases)/sizeof(testcases[0]); i++)
424     {
425         if (testcases[i].pkey)
426             *testcases[i].pkey = out_init;
427
428         ret = PSPropertyKeyFromString(testcases[i].pwzString, testcases[i].pkey);
429         ok(ret == testcases[i].hr_expect,
430            "[%d] Expected PSPropertyKeyFromString to return 0x%08x, got 0x%08x\n",
431            i, testcases[i].hr_expect, ret);
432
433         if (testcases[i].pkey)
434         {
435             ok(IsEqualGUID(&testcases[i].pkey->fmtid, &testcases[i].pkey_expect.fmtid),
436                "[%d] Expected GUID %s, got %s\n",
437                i, show_guid(&testcases[i].pkey_expect.fmtid, guid_buf), show_guid(&testcases[i].pkey->fmtid, guid_buf2));
438             ok(testcases[i].pkey->pid == testcases[i].pkey_expect.pid,
439                "[%d] Expected property ID %u, got %u\n",
440                i, testcases[i].pkey_expect.pid, testcases[i].pkey->pid);
441         }
442     }
443 }
444
445 static void test_PSRefreshPropertySchema(void)
446 {
447     HRESULT ret;
448
449     ret = PSRefreshPropertySchema();
450     todo_wine
451     ok(ret == CO_E_NOTINITIALIZED,
452        "Expected PSRefreshPropertySchema to return CO_E_NOTINITIALIZED, got 0x%08x\n", ret);
453
454     CoInitialize(NULL);
455
456     ret = PSRefreshPropertySchema();
457     ok(ret == S_OK,
458        "Expected PSRefreshPropertySchema to return S_OK, got 0x%08x\n", ret);
459
460     CoUninitialize();
461 }
462
463 static void test_InitPropVariantFromGUIDAsString(void)
464 {
465     PROPVARIANT propvar;
466     VARIANT var;
467     HRESULT hres;
468     int i;
469
470     const struct {
471         REFGUID guid;
472         const char *str;
473     } testcases[] = {
474         {&IID_NULL,             "{00000000-0000-0000-0000-000000000000}" },
475         {&dummy_guid,           "{DEADBEEF-DEAD-BEEF-DEAD-BEEFCAFEBABE}" },
476     };
477
478     hres = InitPropVariantFromGUIDAsString(NULL, &propvar);
479     ok(hres == E_FAIL, "InitPropVariantFromGUIDAsString returned %x\n", hres);
480
481     if(0) {
482         /* Returns strange data on Win7, crashes on older systems */
483         InitVariantFromGUIDAsString(NULL, &var);
484
485         /* Crashes on windows */
486         InitPropVariantFromGUIDAsString(&IID_NULL, NULL);
487         InitVariantFromGUIDAsString(&IID_NULL, NULL);
488     }
489
490     for(i=0; i<sizeof(testcases)/sizeof(testcases[0]); i++) {
491         memset(&propvar, 0, sizeof(PROPVARIANT));
492         hres = InitPropVariantFromGUIDAsString(testcases[i].guid, &propvar);
493         ok(hres == S_OK, "%d) InitPropVariantFromGUIDAsString returned %x\n", i, hres);
494         ok(propvar.vt == VT_LPWSTR, "%d) propvar.vt = %d\n", i, propvar.vt);
495         ok(!strcmp_wa(propvar.u.pwszVal, testcases[i].str), "%d) propvar.u.pwszVal = %s\n",
496                 i, wine_dbgstr_w(propvar.u.pwszVal));
497         CoTaskMemFree(propvar.u.pwszVal);
498
499         memset(&var, 0, sizeof(VARIANT));
500         hres = InitVariantFromGUIDAsString(testcases[i].guid, &var);
501         ok(hres == S_OK, "%d) InitVariantFromGUIDAsString returned %x\n", i, hres);
502         ok(V_VT(&var) == VT_BSTR, "%d) V_VT(&var) = %d\n", i, V_VT(&var));
503         ok(SysStringLen(V_BSTR(&var)) == 38, "SysStringLen returned %d\n",
504                 SysStringLen(V_BSTR(&var)));
505         ok(!strcmp_wa(V_BSTR(&var), testcases[i].str), "%d) V_BSTR(&var) = %s\n",
506                 i, wine_dbgstr_w(V_BSTR(&var)));
507         VariantClear(&var);
508     }
509 }
510
511 static void test_InitPropVariantFromBuffer(void)
512 {
513     static const char data_in[] = "test";
514     PROPVARIANT propvar;
515     VARIANT var;
516     HRESULT hres;
517     void *data_out;
518     LONG size;
519
520     hres = InitPropVariantFromBuffer(NULL, 0, &propvar);
521     ok(hres == S_OK, "InitPropVariantFromBuffer returned %x\n", hres);
522     ok(propvar.vt == (VT_VECTOR|VT_UI1), "propvar.vt = %d\n", propvar.vt);
523     ok(propvar.u.caub.cElems == 0, "cElems = %d\n", propvar.u.caub.cElems == 0);
524     PropVariantClear(&propvar);
525
526     hres = InitPropVariantFromBuffer(data_in, 4, &propvar);
527     ok(hres == S_OK, "InitPropVariantFromBuffer returned %x\n", hres);
528     ok(propvar.vt == (VT_VECTOR|VT_UI1), "propvar.vt = %d\n", propvar.vt);
529     ok(propvar.u.caub.cElems == 4, "cElems = %d\n", propvar.u.caub.cElems == 0);
530     ok(!memcmp(propvar.u.caub.pElems, data_in, 4), "Data inside array is incorrect\n");
531     PropVariantClear(&propvar);
532
533     hres = InitVariantFromBuffer(NULL, 0, &var);
534     ok(hres == S_OK, "InitVariantFromBuffer returned %x\n", hres);
535     ok(V_VT(&var) == (VT_ARRAY|VT_UI1), "V_VT(&var) = %d\n", V_VT(&var));
536     size = SafeArrayGetDim(V_ARRAY(&var));
537     ok(size == 1, "SafeArrayGetDim returned %d\n", size);
538     hres = SafeArrayGetLBound(V_ARRAY(&var), 1, &size);
539     ok(hres == S_OK, "SafeArrayGetLBound returned %x\n", hres);
540     ok(size == 0, "LBound = %d\n", size);
541     hres = SafeArrayGetUBound(V_ARRAY(&var), 1, &size);
542     ok(hres == S_OK, "SafeArrayGetUBound returned %x\n", hres);
543     ok(size == -1, "UBound = %d\n", size);
544     VariantClear(&var);
545
546     hres = InitVariantFromBuffer(data_in, 4, &var);
547     ok(hres == S_OK, "InitVariantFromBuffer returned %x\n", hres);
548     ok(V_VT(&var) == (VT_ARRAY|VT_UI1), "V_VT(&var) = %d\n", V_VT(&var));
549     size = SafeArrayGetDim(V_ARRAY(&var));
550     ok(size == 1, "SafeArrayGetDim returned %d\n", size);
551     hres = SafeArrayGetLBound(V_ARRAY(&var), 1, &size);
552     ok(hres == S_OK, "SafeArrayGetLBound returned %x\n", hres);
553     ok(size == 0, "LBound = %d\n", size);
554     hres = SafeArrayGetUBound(V_ARRAY(&var), 1, &size);
555     ok(hres == S_OK, "SafeArrayGetUBound returned %x\n", hres);
556     ok(size == 3, "UBound = %d\n", size);
557     hres = SafeArrayAccessData(V_ARRAY(&var), &data_out);
558     ok(hres == S_OK, "SafeArrayAccessData failed %x\n", hres);
559     ok(!memcmp(data_in, data_out, 4), "Data inside safe array is incorrect\n");
560     hres = SafeArrayUnaccessData(V_ARRAY(&var));
561     ok(hres == S_OK, "SafeArrayUnaccessData failed %x\n", hres);
562     VariantClear(&var);
563 }
564
565 START_TEST(propsys)
566 {
567     test_PSStringFromPropertyKey();
568     test_PSPropertyKeyFromString();
569     test_PSRefreshPropertySchema();
570     test_InitPropVariantFromGUIDAsString();
571     test_InitPropVariantFromBuffer();
572 }