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+) */
42 { PROP_V0
, PROP_INV
, PROP_INV
, PROP_INV
}, /* VT_EMPTY */
43 { PROP_V0
, PROP_INV
, PROP_INV
, PROP_INV
}, /* VT_NULL */
44 { PROP_V0
, PROP_V1
, PROP_V0
, PROP_V1
}, /* VT_I2 */
45 { PROP_V0
, PROP_V1
, PROP_V0
, PROP_V1
}, /* VT_I4 */
46 { PROP_V0
, PROP_V1
, PROP_V0
, PROP_V1
}, /* VT_R4 */
47 { PROP_V0
, PROP_V1
, PROP_V0
, PROP_V1
}, /* VT_R8 */
48 { PROP_V0
, PROP_V1
, PROP_V0
, PROP_V1
}, /* VT_CY */
49 { PROP_V0
, PROP_V1
, PROP_V0
, PROP_V1
}, /* VT_DATE */
50 { PROP_V0
, PROP_V1
, PROP_V0
, PROP_V1
}, /* VT_BSTR */
51 { PROP_V1
, PROP_V1
, PROP_INV
, PROP_V1
}, /* VT_DISPATCH */
52 { PROP_V0
, PROP_V1
, PROP_V0
, PROP_V1
}, /* VT_ERROR */
53 { PROP_V0
, PROP_V1
, PROP_V0
, PROP_V1
}, /* VT_BOOL */
54 { PROP_V1
, PROP_V1
, PROP_V0
, PROP_V1
}, /* VT_VARIANT */
55 { PROP_V1
, PROP_V1
, PROP_INV
, PROP_V1
}, /* VT_UNKNOWN */
56 { PROP_V1
, PROP_V1
, PROP_INV
, PROP_V1
}, /* VT_DECIMAL */
57 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 15 */
58 { PROP_V1
, PROP_V1
, PROP_V1
, PROP_V1
}, /* VT_I1 */
59 { PROP_V0
, PROP_V1
, PROP_V0
, PROP_V1
}, /* VT_UI1 */
60 { PROP_V0
, PROP_V1
, PROP_V0
, PROP_V1
}, /* VT_UI2 */
61 { PROP_V0
, PROP_V1
, PROP_V0
, PROP_V1
}, /* VT_UI4 */
62 { PROP_V0
, PROP_V1A
, PROP_V0
, PROP_V1A
}, /* VT_I8 */
63 { PROP_V0
, PROP_V1A
, PROP_V0
, PROP_V1A
}, /* VT_UI8 */
64 { PROP_V1
, PROP_V1
, PROP_INV
, PROP_V1
}, /* VT_INT */
65 { PROP_V1
, PROP_V1
, PROP_INV
, PROP_V1
}, /* VT_UINT */
66 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* VT_VOID */
67 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* VT_HRESULT */
68 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* VT_PTR */
69 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* VT_SAFEARRAY */
70 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* VT_CARRAY */
71 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* VT_USERDEFINED */
72 { PROP_V0
, PROP_INV
, PROP_V0
, PROP_INV
}, /* VT_LPSTR */
73 { PROP_V0
, PROP_INV
, PROP_V0
, PROP_INV
}, /* VT_LPWSTR */
74 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 32 */
75 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 33 */
76 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 34 */
77 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 35 */
78 { PROP_V1
, PROP_V1
, PROP_INV
, PROP_V1
}, /* VT_RECORD */
79 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* VT_INT_PTR */
80 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* VT_UINT_PTR */
81 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 39 */
82 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 40 */
83 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 41 */
84 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 42 */
85 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 43 */
86 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 44 */
87 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 45 */
88 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 46 */
89 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 47 */
90 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 48 */
91 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 49 */
92 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 50 */
93 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 51 */
94 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 52 */
95 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 53 */
96 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 54 */
97 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 55 */
98 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 56 */
99 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 57 */
100 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 58 */
101 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 59 */
102 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 60 */
103 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 61 */
104 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 62 */
105 { PROP_INV
, PROP_INV
, PROP_INV
, PROP_INV
}, /* 63 */
106 { PROP_V0
, PROP_INV
, PROP_V0
, PROP_INV
}, /* VT_FILETIME */
107 { PROP_V0
, PROP_INV
, PROP_INV
, PROP_INV
}, /* VT_BLOB */
108 { PROP_V0
, PROP_INV
, PROP_INV
, PROP_INV
}, /* VT_STREAM */
109 { PROP_V0
, PROP_INV
, PROP_INV
, PROP_INV
}, /* VT_STORAGE */
110 { PROP_V0
, PROP_INV
, PROP_INV
, PROP_INV
}, /* VT_STREAMED_OBJECT */
111 { PROP_V0
, PROP_INV
, PROP_INV
, PROP_INV
}, /* VT_STORED_OBJECT */
112 { PROP_V0
, PROP_INV
, PROP_INV
, PROP_INV
}, /* VT_BLOB_OBJECT */
113 { PROP_V0
, PROP_INV
, PROP_V0
, PROP_INV
} /* VT_CF */
116 static const char* wine_vtypes
[VT_CLSID
+1] =
118 "VT_EMPTY","VT_NULL","VT_I2","VT_I4","VT_R4","VT_R8","VT_CY","VT_DATE",
119 "VT_BSTR","VT_DISPATCH","VT_ERROR","VT_BOOL","VT_VARIANT","VT_UNKNOWN",
120 "VT_DECIMAL","15","VT_I1","VT_UI1","VT_UI2","VT_UI4","VT_I8","VT_UI8",
121 "VT_INT","VT_UINT","VT_VOID","VT_HRESULT","VT_PTR","VT_SAFEARRAY",
122 "VT_CARRAY","VT_USERDEFINED","VT_LPSTR","VT_LPWSTR","32","33","34","35",
123 "VT_RECORD","VT_INT_PTR","VT_UINT_PTR","39","40","41","42","43","44","45",
124 "46","47","48","49","50","51","52","53","54","55","56","57","58","59","60",
125 "61","62","63","VT_FILETIME","VT_BLOB","VT_STREAM","VT_STORAGE",
126 "VT_STREAMED_OBJECT","VT_STORED_OBJECT","VT_BLOB_OBJECT","VT_CF","VT_CLSID"
129 static void test_validtypes(void)
136 memset(&propvar
, 0, sizeof(propvar
));
139 propvar
.vt
= VT_I2
| VT_ARRAY
;
140 hr
= PropVariantClear(&propvar
);
143 propvar
.vt
= VT_I8
| VT_ARRAY
;
144 hr
= PropVariantClear(&propvar
);
148 trace("detected prop variant v1a\n");
153 trace("detected prop variant v1\n");
159 trace("detected prop variant v0\n");
162 for (i
= 0; i
< sizeof(valid_types
)/sizeof(valid_types
[0]); i
++)
164 BOOL expected_result
;
167 hr
= PropVariantClear(&propvar
);
168 expected_result
= (valid_types
[i
].simple
<= version
? TRUE
: FALSE
);
169 ok(expected_result
== !(hr
== STG_E_INVALIDPARAMETER
),
170 "PropVariantClear(%s) should have returned 0x%08x, but returned 0x%08x\n",
172 expected_result
? S_OK
: STG_E_INVALIDPARAMETER
, hr
);
174 propvar
.vt
= i
| VT_ARRAY
;
175 hr
= PropVariantClear(&propvar
);
176 expected_result
= (valid_types
[i
].with_array
<= version
? TRUE
: FALSE
);
177 ok(expected_result
== !(hr
== STG_E_INVALIDPARAMETER
),
178 "PropVariantClear(%s|VT_ARRAY) should have returned 0x%08x, but returned 0x%08x\n",
180 expected_result
? S_OK
: STG_E_INVALIDPARAMETER
, hr
);
182 propvar
.vt
= i
| VT_VECTOR
;
183 hr
= PropVariantClear(&propvar
);
184 expected_result
= (valid_types
[i
].with_vector
<= version
? TRUE
: FALSE
);
185 ok(expected_result
== !(hr
== STG_E_INVALIDPARAMETER
),
186 "PropVariantClear(%s|VT_VECTOR) should have returned 0x%08x, but returned 0x%08x\n",
188 expected_result
? S_OK
: STG_E_INVALIDPARAMETER
, hr
);
190 propvar
.vt
= i
| VT_BYREF
;
191 hr
= PropVariantClear(&propvar
);
192 expected_result
= (valid_types
[i
].byref
<= version
? TRUE
: FALSE
);
193 ok(expected_result
== !(hr
== STG_E_INVALIDPARAMETER
),
194 "PropVariantClear(%s|VT_BYREF) should have returned 0x%08x, but returned 0x%08x\n",
196 expected_result
? S_OK
: STG_E_INVALIDPARAMETER
, hr
);
200 static void test_copy(void)
202 static char szTestString
[] = "Test String";
203 static WCHAR wszTestString
[] = {'T','e','s','t',' ','S','t','r','i','n','g',0};
204 PROPVARIANT propvarSrc
;
205 PROPVARIANT propvarDst
;
208 propvarSrc
.vt
= VT_BSTR
;
209 U(propvarSrc
).bstrVal
= SysAllocString(wszTestString
);
211 hr
= PropVariantCopy(&propvarDst
, &propvarSrc
);
212 ok(hr
== S_OK
, "PropVariantCopy(...VT_BSTR...) failed\n");
213 ok(!lstrcmpW(U(propvarSrc
).bstrVal
, U(propvarDst
).bstrVal
), "BSTR not copied properly\n");
214 hr
= PropVariantClear(&propvarSrc
);
215 ok(hr
== S_OK
, "PropVariantClear(...VT_BSTR...) failed\n");
216 hr
= PropVariantClear(&propvarDst
);
217 ok(hr
== S_OK
, "PropVariantClear(...VT_BSTR...) failed\n");
219 propvarSrc
.vt
= VT_LPWSTR
;
220 U(propvarSrc
).pwszVal
= wszTestString
;
221 hr
= PropVariantCopy(&propvarDst
, &propvarSrc
);
222 ok(hr
== S_OK
, "PropVariantCopy(...VT_LPWSTR...) failed\n");
223 ok(!lstrcmpW(U(propvarSrc
).pwszVal
, U(propvarDst
).pwszVal
), "Wide string not copied properly\n");
224 hr
= PropVariantClear(&propvarDst
);
225 ok(hr
== S_OK
, "PropVariantClear(...VT_LPWSTR...) failed\n");
226 memset(&propvarSrc
, 0, sizeof(propvarSrc
));
228 propvarSrc
.vt
= VT_LPSTR
;
229 U(propvarSrc
).pszVal
= szTestString
;
230 hr
= PropVariantCopy(&propvarDst
, &propvarSrc
);
231 ok(hr
== S_OK
, "PropVariantCopy(...VT_LPSTR...) failed\n");
232 ok(!strcmp(U(propvarSrc
).pszVal
, U(propvarDst
).pszVal
), "String not copied properly\n");
233 hr
= PropVariantClear(&propvarDst
);
234 ok(hr
== S_OK
, "PropVariantClear(...VT_LPSTR...) failed\n");
235 memset(&propvarSrc
, 0, sizeof(propvarSrc
));
238 START_TEST(propvariant
)