4 * Copyright 2004 Robert Shearman
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.
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.
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
23 #include "wine/test.h"
25 /* invalid in all versions */
27 /* valid in v0 and above (NT4+) */
29 /* valid in v1 and above (Win2k+) */
31 /* valid in v1a and above (WinXP+) */
33 #define PROP_TODO 0x80
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_TODO , PROP_V1 | PROP_TODO , PROP_V1 | PROP_TODO , 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 */
117 static const char* wine_vtypes[VT_CLSID+1] =
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"
131 static void expect(HRESULT hr, VARTYPE vt)
133 int idx = vt & VT_TYPEMASK;
135 const char *modifier;
139 flags = valid_types[idx].byref;
142 else if(vt & VT_ARRAY)
144 flags = valid_types[idx].with_array;
147 else if(vt & VT_VECTOR)
149 flags = valid_types[idx].with_vector;
154 flags = valid_types[idx].simple;
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)
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);
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);
179 static void test_validtypes(void)
185 memset(&propvar, 0, sizeof(propvar));
187 for (i = 0; i < sizeof(valid_types)/sizeof(valid_types[0]); i++)
192 hr = PropVariantClear(&propvar);
195 vt = propvar.vt = i | VT_ARRAY;
196 hr = PropVariantClear(&propvar);
199 vt = propvar.vt = i | VT_VECTOR;
200 hr = PropVariantClear(&propvar);
203 vt = propvar.vt = i | VT_BYREF;
204 hr = PropVariantClear(&propvar);
210 static void test_copy(void)
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;
218 propvarSrc.vt = VT_BSTR;
219 U(propvarSrc).bstrVal = SysAllocString(wszTestString);
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");
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));
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));
248 START_TEST(propvariant)