riched20: Use ME_PointFromChar to calculate the caret position.
[wine] / dlls / ole32 / tests / propvariant.c
1 /*
2  * PropVariant Tests
3  *
4  * Copyright 2004 Robert Shearman
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "windows.h"
22
23 #include "wine/test.h"
24
25 /* invalid in all versions */
26 #define PROP_INV 0x7f
27 /* valid in v0 and above (NT4+) */
28 #define PROP_V0  0
29 /* valid in v1 and above (Win2k+) */
30 #define PROP_V1  1
31 /* valid in v1a and above (WinXP+) */
32 #define PROP_V1A 2
33 #define PROP_TODO 0x80
34
35 static const struct valid_mapping
36 {
37     BYTE simple;
38     BYTE with_array;
39     BYTE with_vector;
40     BYTE byref;
41 } valid_types[] =
42 {
43     { PROP_V0 , PROP_INV, PROP_INV, PROP_INV }, /* VT_EMPTY */
44     { PROP_V0 , PROP_INV, PROP_INV, PROP_INV }, /* VT_NULL */
45     { PROP_V0 , PROP_V1 | PROP_TODO , PROP_V0 , PROP_V1 | PROP_TODO  }, /* VT_I2 */
46     { PROP_V0 , PROP_V1 | PROP_TODO , PROP_V0 , PROP_V1 | PROP_TODO  }, /* VT_I4 */
47     { PROP_V0 , PROP_V1 | PROP_TODO , PROP_V0 , PROP_V1 | PROP_TODO  }, /* VT_R4 */
48     { PROP_V0 , PROP_V1 | PROP_TODO , PROP_V0 , PROP_V1 | PROP_TODO  }, /* VT_R8 */
49     { PROP_V0 , PROP_V1 | PROP_TODO , PROP_V0 , PROP_V1 | PROP_TODO  }, /* VT_CY */
50     { PROP_V0 , PROP_V1 | PROP_TODO , PROP_V0 , PROP_V1 | PROP_TODO  }, /* VT_DATE */
51     { PROP_V0 , PROP_V1 | PROP_TODO , PROP_V0 , PROP_V1 | PROP_TODO  }, /* VT_BSTR */
52     { PROP_V1 | PROP_TODO , PROP_V1 | PROP_TODO , PROP_INV, PROP_V1 | PROP_TODO  }, /* VT_DISPATCH */
53     { PROP_V0 , PROP_V1 | PROP_TODO , PROP_V0 , PROP_V1 | PROP_TODO  }, /* VT_ERROR */
54     { PROP_V0 , PROP_V1 | PROP_TODO , PROP_V0 , PROP_V1 | PROP_TODO  }, /* VT_BOOL */
55     { PROP_V1 | PROP_TODO , PROP_V1 | PROP_TODO , PROP_V0 , PROP_V1 | PROP_TODO  }, /* VT_VARIANT */
56     { PROP_V1 | PROP_TODO , PROP_V1 | PROP_TODO , PROP_INV, PROP_V1 | PROP_TODO  }, /* VT_UNKNOWN */
57     { PROP_V1 , PROP_V1 | PROP_TODO , PROP_INV, PROP_V1 | PROP_TODO  }, /* VT_DECIMAL */
58     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 15 */
59     { PROP_V1 , PROP_V1 | PROP_TODO , PROP_V1 , PROP_V1 | PROP_TODO  }, /* VT_I1 */
60     { PROP_V0 , PROP_V1 | PROP_TODO , PROP_V0 , PROP_V1 | PROP_TODO  }, /* VT_UI1 */
61     { PROP_V0 , PROP_V1 | PROP_TODO , PROP_V0 , PROP_V1 | PROP_TODO  }, /* VT_UI2 */
62     { PROP_V0 , PROP_V1 | PROP_TODO , PROP_V0 , PROP_V1 | PROP_TODO  }, /* VT_UI4 */
63     { PROP_V0 , PROP_V1A | PROP_TODO, PROP_V0 , PROP_V1A | PROP_TODO }, /* VT_I8 */
64     { PROP_V0 , PROP_V1A | PROP_TODO, PROP_V0 , PROP_V1A | PROP_TODO }, /* VT_UI8 */
65     { PROP_V1 | PROP_TODO , PROP_V1 | PROP_TODO , PROP_INV, PROP_V1 | PROP_TODO  }, /* VT_INT */
66     { PROP_V1 | PROP_TODO , PROP_V1 | PROP_TODO , PROP_INV, PROP_V1 | PROP_TODO  }, /* VT_UINT */
67     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* VT_VOID */
68     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* VT_HRESULT */
69     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* VT_PTR */
70     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* VT_SAFEARRAY */
71     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* VT_CARRAY */
72     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* VT_USERDEFINED */
73     { PROP_V0 , PROP_INV, PROP_V0 , PROP_INV }, /* VT_LPSTR */
74     { PROP_V0 , PROP_INV, PROP_V0 , PROP_INV }, /* VT_LPWSTR */
75     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 32 */
76     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 33 */
77     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 34 */
78     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 35 */
79     { PROP_V1 | PROP_TODO , PROP_V1 | PROP_TODO , PROP_INV, PROP_V1 | PROP_TODO  }, /* VT_RECORD */
80     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* VT_INT_PTR */
81     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* VT_UINT_PTR */
82     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 39 */
83     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 40 */
84     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 41 */
85     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 42 */
86     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 43 */
87     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 44 */
88     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 45 */
89     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 46 */
90     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 47 */
91     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 48 */
92     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 49 */
93     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 50 */
94     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 51 */
95     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 52 */
96     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 53 */
97     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 54 */
98     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 55 */
99     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 56 */
100     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 57 */
101     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 58 */
102     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 59 */
103     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 60 */
104     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 61 */
105     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 62 */
106     { PROP_INV, PROP_INV, PROP_INV, PROP_INV }, /* 63 */
107     { PROP_V0 , PROP_INV, PROP_V0 , PROP_INV }, /* VT_FILETIME */
108     { PROP_V0 , PROP_INV, PROP_INV, PROP_INV }, /* VT_BLOB */
109     { PROP_V0 , PROP_INV, PROP_INV, PROP_INV }, /* VT_STREAM */
110     { PROP_V0 , PROP_INV, PROP_INV, PROP_INV }, /* VT_STORAGE */
111     { PROP_V0 , PROP_INV, PROP_INV, PROP_INV }, /* VT_STREAMED_OBJECT */
112     { PROP_V0 , PROP_INV, PROP_INV, PROP_INV }, /* VT_STORED_OBJECT */
113     { PROP_V0 , PROP_INV, PROP_INV, PROP_INV }, /* VT_BLOB_OBJECT */
114     { PROP_V0 , PROP_INV, PROP_V0 , PROP_INV }  /* VT_CF */
115 };
116
117 static const char* wine_vtypes[VT_CLSID+1] =
118 {
119   "VT_EMPTY","VT_NULL","VT_I2","VT_I4","VT_R4","VT_R8","VT_CY","VT_DATE",
120   "VT_BSTR","VT_DISPATCH","VT_ERROR","VT_BOOL","VT_VARIANT","VT_UNKNOWN",
121   "VT_DECIMAL","15","VT_I1","VT_UI1","VT_UI2","VT_UI4","VT_I8","VT_UI8",
122   "VT_INT","VT_UINT","VT_VOID","VT_HRESULT","VT_PTR","VT_SAFEARRAY",
123   "VT_CARRAY","VT_USERDEFINED","VT_LPSTR","VT_LPWSTR","32","33","34","35",
124   "VT_RECORD","VT_INT_PTR","VT_UINT_PTR","39","40","41","42","43","44","45",
125   "46","47","48","49","50","51","52","53","54","55","56","57","58","59","60",
126   "61","62","63","VT_FILETIME","VT_BLOB","VT_STREAM","VT_STORAGE",
127   "VT_STREAMED_OBJECT","VT_STORED_OBJECT","VT_BLOB_OBJECT","VT_CF","VT_CLSID"
128 };
129
130
131 static void expect(HRESULT hr, VARTYPE vt)
132 {
133     int idx = vt & VT_TYPEMASK;
134     BYTE flags;
135     const char *modifier;
136
137     if(vt & VT_BYREF)
138     {
139         flags = valid_types[idx].byref;
140         modifier = "byref";
141     }
142     else if(vt & VT_ARRAY)
143     {
144         flags = valid_types[idx].with_array;
145         modifier = "array";
146     }
147     else if(vt & VT_VECTOR)
148     {
149         flags = valid_types[idx].with_vector;
150         modifier = "vector";
151     }
152     else
153     {
154         flags = valid_types[idx].simple;
155         modifier = "simple";
156     }
157
158     if(flags == PROP_INV)
159         ok(hr == STG_E_INVALIDPARAMETER, "%s (%s): got %08x\n", wine_vtypes[idx], modifier, hr);
160     else if(flags == PROP_V0)
161         ok(hr == S_OK, "%s (%s): got %08x\n", wine_vtypes[idx], modifier, hr);
162     else if(flags & PROP_TODO)
163     {
164         todo_wine
165         {
166         if(hr != S_OK)
167             win_skip("%s (%s): unsupported\n", wine_vtypes[idx], modifier);
168         else ok(hr == S_OK, "%s (%s): got %08x\n", wine_vtypes[idx], modifier, hr);
169         }
170     }
171     else
172     {
173         if(hr != S_OK)
174             win_skip("%s (%s): unsupported\n", wine_vtypes[idx], modifier);
175         else ok(hr == S_OK, "%s (%s): got %08x\n", wine_vtypes[idx], modifier, hr);
176     }
177 }
178
179 static void test_validtypes(void)
180 {
181     PROPVARIANT propvar;
182     HRESULT hr;
183     unsigned int i;
184
185     memset(&propvar, 0, sizeof(propvar));
186
187     for (i = 0; i < sizeof(valid_types)/sizeof(valid_types[0]); i++)
188     {
189         VARTYPE vt;
190
191         vt = propvar.vt = i;
192         hr = PropVariantClear(&propvar);
193         expect(hr, vt);
194
195         vt = propvar.vt = i | VT_ARRAY;
196         hr = PropVariantClear(&propvar);
197         expect(hr, vt);
198
199         vt = propvar.vt = i | VT_VECTOR;
200         hr = PropVariantClear(&propvar);
201         expect(hr, vt);
202
203         vt = propvar.vt = i | VT_BYREF;
204         hr = PropVariantClear(&propvar);
205         expect(hr, vt);
206
207     }
208 }
209
210 static void test_copy(void)
211 {
212     static char szTestString[] = "Test String";
213     static WCHAR wszTestString[] = {'T','e','s','t',' ','S','t','r','i','n','g',0};
214     PROPVARIANT propvarSrc;
215     PROPVARIANT propvarDst;
216     HRESULT hr;
217
218     propvarSrc.vt = VT_BSTR;
219     U(propvarSrc).bstrVal = SysAllocString(wszTestString);
220
221     hr = PropVariantCopy(&propvarDst, &propvarSrc);
222     ok(hr == S_OK, "PropVariantCopy(...VT_BSTR...) failed\n");
223     ok(!lstrcmpW(U(propvarSrc).bstrVal, U(propvarDst).bstrVal), "BSTR not copied properly\n");
224     hr = PropVariantClear(&propvarSrc);
225     ok(hr == S_OK, "PropVariantClear(...VT_BSTR...) failed\n");
226     hr = PropVariantClear(&propvarDst);
227     ok(hr == S_OK, "PropVariantClear(...VT_BSTR...) failed\n");
228
229     propvarSrc.vt = VT_LPWSTR;
230     U(propvarSrc).pwszVal = wszTestString;
231     hr = PropVariantCopy(&propvarDst, &propvarSrc);
232     ok(hr == S_OK, "PropVariantCopy(...VT_LPWSTR...) failed\n");
233     ok(!lstrcmpW(U(propvarSrc).pwszVal, U(propvarDst).pwszVal), "Wide string not copied properly\n");
234     hr = PropVariantClear(&propvarDst);
235     ok(hr == S_OK, "PropVariantClear(...VT_LPWSTR...) failed\n");
236     memset(&propvarSrc, 0, sizeof(propvarSrc));
237
238     propvarSrc.vt = VT_LPSTR;
239     U(propvarSrc).pszVal = szTestString;
240     hr = PropVariantCopy(&propvarDst, &propvarSrc);
241     ok(hr == S_OK, "PropVariantCopy(...VT_LPSTR...) failed\n");
242     ok(!strcmp(U(propvarSrc).pszVal, U(propvarDst).pszVal), "String not copied properly\n");
243     hr = PropVariantClear(&propvarDst);
244     ok(hr == S_OK, "PropVariantClear(...VT_LPSTR...) failed\n");
245     memset(&propvarSrc, 0, sizeof(propvarSrc));
246 }
247
248 struct _PMemoryAllocator_vtable {
249     void *Allocate; /* virtual void* Allocate(ULONG cbSize); */
250     void *Free; /* virtual void Free(void *pv); */
251 };
252
253 typedef struct _PMemoryAllocator {
254     struct _PMemoryAllocator_vtable *vt;
255 } PMemoryAllocator;
256
257 #ifdef __i386__
258 #define __thiscall __stdcall
259 #else
260 #define __thiscall __cdecl
261 #endif
262
263 static void * __thiscall PMemoryAllocator_Allocate(PMemoryAllocator *_this, ULONG cbSize)
264 {
265     return CoTaskMemAlloc(cbSize);
266 }
267
268 static void __thiscall PMemoryAllocator_Free(PMemoryAllocator *_this, void *pv)
269 {
270     CoTaskMemFree(pv);
271 }
272
273 #ifdef __i386__
274
275 #include "pshpack1.h"
276 typedef struct
277 {
278     BYTE pop_eax;  /* popl  %eax  */
279     BYTE push_ecx; /* pushl %ecx  */
280     BYTE push_eax; /* pushl %eax  */
281     BYTE jmp_func; /* jmp   $func */
282     DWORD func;
283 } THISCALL_TO_STDCALL_THUNK;
284 #include "poppack.h"
285
286 static THISCALL_TO_STDCALL_THUNK *wrapperCodeMem = NULL;
287
288 static void fill_thunk(THISCALL_TO_STDCALL_THUNK *thunk, void *fn)
289 {
290     thunk->pop_eax = 0x58;
291     thunk->push_ecx = 0x51;
292     thunk->push_eax = 0x50;
293     thunk->jmp_func = 0xe9;
294     thunk->func = (char*)fn - (char*)(&thunk->func + 1);
295 }
296
297 static void setup_vtable(struct _PMemoryAllocator_vtable *vtable)
298 {
299     wrapperCodeMem = VirtualAlloc(NULL, 2 * sizeof(*wrapperCodeMem),
300                                   MEM_COMMIT, PAGE_EXECUTE_READWRITE);
301
302     fill_thunk(&wrapperCodeMem[0], PMemoryAllocator_Allocate);
303     fill_thunk(&wrapperCodeMem[1], PMemoryAllocator_Free);
304
305     vtable->Allocate = &wrapperCodeMem[0];
306     vtable->Free = &wrapperCodeMem[1];
307 }
308
309 #else
310
311 static void setup_vtable(struct _PMemoryAllocator_vtable *vtable)
312 {
313     vtable->Allocate = PMemoryAllocator_Allocate;
314     vtable->Free = PMemoryAllocator_Free;
315 }
316
317 #endif
318
319 static const char serialized_empty[] = {
320     0,0, /* VT_EMPTY */
321     0,0, /* padding */
322 };
323
324 static const char serialized_null[] = {
325     1,0, /* VT_NULL */
326     0,0, /* padding */
327 };
328
329 static const char serialized_i4[] = {
330     3,0, /* VT_I4 */
331     0,0, /* padding */
332     0xef,0xcd,0xab,0xfe
333 };
334
335 static const char serialized_bstr_wc[] = {
336     8,0, /* VT_BSTR */
337     0,0, /* padding */
338     10,0,0,0, /* size */
339     't',0,'e',0,
340     's',0,'t',0,
341     0,0,0,0
342 };
343
344 static const char serialized_bstr_mb[] = {
345     8,0, /* VT_BSTR */
346     0,0, /* padding */
347     5,0,0,0, /* size */
348     't','e','s','t',
349     0,0,0,0
350 };
351
352 static void test_propertytovariant(void)
353 {
354     HANDLE hole32;
355     BOOLEAN (__stdcall *pStgConvertPropertyToVariant)(const SERIALIZEDPROPERTYVALUE*,USHORT,PROPVARIANT*,PMemoryAllocator*);
356     PROPVARIANT propvar;
357     PMemoryAllocator allocator;
358     struct _PMemoryAllocator_vtable vtable;
359     BOOLEAN ret;
360     static const WCHAR test_string[] = {'t','e','s','t',0};
361
362     hole32 = GetModuleHandleA("ole32");
363
364     pStgConvertPropertyToVariant = (void*)GetProcAddress(hole32, "StgConvertPropertyToVariant");
365
366     if (!pStgConvertPropertyToVariant)
367     {
368         win_skip("StgConvertPropertyToVariant not available\n");
369         return;
370     }
371
372     setup_vtable(&vtable);
373     allocator.vt = &vtable;
374
375     ret = pStgConvertPropertyToVariant((SERIALIZEDPROPERTYVALUE*)serialized_empty,
376         CP_WINUNICODE, &propvar, &allocator);
377
378     ok(ret == 0, "StgConvertPropertyToVariant returned %i\n", ret);
379     ok(propvar.vt == VT_EMPTY, "unexpected vt %x\n", propvar.vt);
380
381     ret = pStgConvertPropertyToVariant((SERIALIZEDPROPERTYVALUE*)serialized_null,
382         CP_WINUNICODE, &propvar, &allocator);
383
384     ok(ret == 0, "StgConvertPropertyToVariant returned %i\n", ret);
385     ok(propvar.vt == VT_NULL, "unexpected vt %x\n", propvar.vt);
386
387     ret = pStgConvertPropertyToVariant((SERIALIZEDPROPERTYVALUE*)serialized_i4,
388         CP_WINUNICODE, &propvar, &allocator);
389
390     ok(ret == 0, "StgConvertPropertyToVariant returned %i\n", ret);
391     ok(propvar.vt == VT_I4, "unexpected vt %x\n", propvar.vt);
392     ok(U(propvar).lVal == 0xfeabcdef, "unexpected lVal %x\n", U(propvar).lVal);
393
394     ret = pStgConvertPropertyToVariant((SERIALIZEDPROPERTYVALUE*)serialized_bstr_wc,
395         CP_WINUNICODE, &propvar, &allocator);
396
397     ok(ret == 0, "StgConvertPropertyToVariant returned %i\n", ret);
398     ok(propvar.vt == VT_BSTR, "unexpected vt %x\n", propvar.vt);
399     ok(!lstrcmpW(U(propvar).bstrVal, test_string), "unexpected string value\n");
400     PropVariantClear(&propvar);
401
402     ret = pStgConvertPropertyToVariant((SERIALIZEDPROPERTYVALUE*)serialized_bstr_mb,
403         CP_UTF8, &propvar, &allocator);
404
405     ok(ret == 0, "StgConvertPropertyToVariant returned %i\n", ret);
406     ok(propvar.vt == VT_BSTR, "unexpected vt %x\n", propvar.vt);
407     ok(!lstrcmpW(U(propvar).bstrVal, test_string), "unexpected string value\n");
408     PropVariantClear(&propvar);
409 }
410
411 static void test_varianttoproperty(void)
412 {
413     HANDLE hole32;
414     PROPVARIANT propvar;
415     SERIALIZEDPROPERTYVALUE *propvalue, *own_propvalue;
416     SERIALIZEDPROPERTYVALUE* (__stdcall *pStgConvertVariantToProperty)(
417         const PROPVARIANT*,USHORT,SERIALIZEDPROPERTYVALUE*,ULONG*,PROPID,BOOLEAN,ULONG*);
418     ULONG len;
419     static const WCHAR test_string[] = {'t','e','s','t',0};
420     BSTR test_string_bstr;
421
422     hole32 = GetModuleHandleA("ole32");
423
424     pStgConvertVariantToProperty = (void*)GetProcAddress(hole32, "StgConvertVariantToProperty");
425
426     if (!pStgConvertVariantToProperty)
427     {
428         win_skip("StgConvertVariantToProperty not available\n");
429         return;
430     }
431
432     own_propvalue = HeapAlloc(GetProcessHeap(), 0, sizeof(SERIALIZEDPROPERTYVALUE) + 20);
433
434     PropVariantInit(&propvar);
435
436     propvar.vt = VT_I4;
437     U(propvar).lVal = 0xfeabcdef;
438
439     len = 0xdeadbeef;
440     propvalue = pStgConvertVariantToProperty(&propvar, CP_WINUNICODE, NULL, &len,
441         0, FALSE, 0);
442
443     ok(propvalue == NULL, "got nonnull propvalue\n");
444     todo_wine ok(len == 8, "unexpected length %d\n", len);
445
446     if (len == 0xdeadbeef)
447     {
448         HeapFree(GetProcessHeap(), 0, own_propvalue);
449         return;
450     }
451
452     len = 20;
453     propvalue = pStgConvertVariantToProperty(&propvar, CP_WINUNICODE, own_propvalue, &len,
454         0, FALSE, 0);
455
456     ok(propvalue == own_propvalue, "unexpected propvalue %p\n", propvalue);
457     ok(len == 8, "unexpected length %d\n", len);
458     ok(!memcmp(propvalue, serialized_i4, 8), "got wrong data\n");
459
460     propvar.vt = VT_EMPTY;
461     len = 20;
462     own_propvalue->dwType = 0xdeadbeef;
463     propvalue = pStgConvertVariantToProperty(&propvar, CP_WINUNICODE, own_propvalue, &len,
464         0, FALSE, 0);
465
466     ok(propvalue == own_propvalue, "unexpected propvalue %p\n", propvalue);
467     ok(len == 4 || broken(len == 0) /* before Vista */, "unexpected length %d\n", len);
468     if (len) ok(!memcmp(propvalue, serialized_empty, 4), "got wrong data\n");
469     else ok(propvalue->dwType == 0xdeadbeef, "unexpected type %d\n", propvalue->dwType);
470
471     propvar.vt = VT_NULL;
472     len = 20;
473     propvalue = pStgConvertVariantToProperty(&propvar, CP_WINUNICODE, own_propvalue, &len,
474         0, FALSE, 0);
475
476     ok(propvalue == own_propvalue, "unexpected propvalue %p\n", propvalue);
477     ok(len == 4, "unexpected length %d\n", len);
478     ok(!memcmp(propvalue, serialized_null, 4), "got wrong data\n");
479
480     test_string_bstr = SysAllocString(test_string);
481
482     propvar.vt = VT_BSTR;
483     U(propvar).bstrVal = test_string_bstr;
484     len = 20;
485     propvalue = pStgConvertVariantToProperty(&propvar, CP_WINUNICODE, own_propvalue, &len,
486         0, FALSE, 0);
487
488     ok(propvalue == own_propvalue, "unexpected propvalue %p\n", propvalue);
489     ok(len == 20, "unexpected length %d\n", len);
490     ok(!memcmp(propvalue, serialized_bstr_wc, 20), "got wrong data\n");
491
492     len = 20;
493     propvalue = pStgConvertVariantToProperty(&propvar, CP_UTF8, own_propvalue, &len,
494         0, FALSE, 0);
495
496     ok(propvalue == own_propvalue, "unexpected propvalue %p\n", propvalue);
497     ok(len == 16, "unexpected length %d\n", len);
498     ok(!memcmp(propvalue, serialized_bstr_mb, 16), "got wrong data\n");
499
500     SysFreeString(test_string_bstr);
501
502     HeapFree(GetProcessHeap(), 0, own_propvalue);
503 }
504
505 START_TEST(propvariant)
506 {
507     test_validtypes();
508     test_copy();
509     test_propertytovariant();
510     test_varianttoproperty();
511 }