[ATL][ATL_APITEST] Implement some basic functionality for CComVariant + tests. CORE...
[reactos.git] / rostests / apitests / atl / CComVariant.cpp
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test for CComVariant
5 * PROGRAMMER: Mark Jansen
6 */
7
8 /* In case we are building against the MS headers, we need to disable assertions. */
9 #define ATLASSERT(x)
10 #define _ATL_NO_VARIANT_THROW
11
12 #include <apitest.h>
13 #include <atlbase.h>
14 #include <atlcom.h>
15
16 void expect_bool_imp(const CComVariant& ccv, bool value)
17 {
18 winetest_ok(V_VT(&ccv) == VT_BOOL, "Expected .vt to be BOOL, was %u\n", V_VT(&ccv));
19 VARIANT_BOOL expected = (value ? VARIANT_TRUE : VARIANT_FALSE);
20 winetest_ok(V_BOOL(&ccv) == expected, "Expected value to be %u, was: %u\n", expected, V_BOOL(&ccv));
21 }
22
23 void expect_int_imp(const CComVariant& ccv, int value, unsigned short type)
24 {
25 winetest_ok(V_VT(&ccv) == type, "Expected .vt to be %u, was %u\n", type, V_VT(&ccv));
26 winetest_ok(V_I4(&ccv) == value, "Expected value to be %d, was: %ld\n", value, V_I4(&ccv));
27 }
28
29 void expect_uint_imp(const CComVariant& ccv, unsigned int value, unsigned short type)
30 {
31 winetest_ok(V_VT(&ccv) == type, "Expected .vt to be %u, was %u\n", type, V_VT(&ccv));
32 winetest_ok(V_UI4(&ccv) == value, "Expected value to be %u, was: %lu\n", value, V_UI4(&ccv));
33 }
34
35 void expect_double_imp(const CComVariant& ccv, double value, unsigned short type)
36 {
37 winetest_ok(V_VT(&ccv) == type, "Expected .vt to be %u, was %u\n", type, V_VT(&ccv));
38 winetest_ok(V_R8(&ccv) == value, "Expected value to be %f, was: %f\n", value, V_R8(&ccv));
39 }
40
41 void expect_error_imp(const CComVariant& ccv, SCODE value)
42 {
43 winetest_ok(V_VT(&ccv) == VT_ERROR, "Expected .vt to be VT_ERROR, was %u\n", V_VT(&ccv));
44 winetest_ok(V_ERROR(&ccv) == value, "Expected value to be %lx, was: %lx\n", value, V_ERROR(&ccv));
45 }
46
47 void expect_empty_imp(const CComVariant& ccv)
48 {
49 winetest_ok(V_VT(&ccv) == VT_EMPTY, "Expected .vt to be VT_EMPTY, was %u\n", V_VT(&ccv));
50 winetest_ok(V_I8(&ccv) == 0ll, "Expected value to be 0, was: %I64d\n", V_I8(&ccv));
51 }
52
53 #define expect_bool (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_bool_imp
54 #define expect_int (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_int_imp
55 #define expect_uint (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_uint_imp
56 #define expect_double (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_double_imp
57 #define expect_error (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_error_imp
58 #define expect_empty (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_empty_imp
59
60
61 static void test_construction()
62 {
63 {
64 CComVariant empty;
65 expect_empty(empty);
66 }
67 {
68 CComBSTR bstr(L"TESTW");
69 CComVariant olestr((LPCOLESTR)bstr), comstr(bstr);
70 ok(V_VT(&olestr) == VT_BSTR, "Expected .vt to be VT_LPWSTR, was %u\n", V_VT(&olestr));
71 ok(!wcscmp(V_BSTR(&olestr), L"TESTW"), "Expected value to be L\"TESTW\", was: %s\n", wine_dbgstr_w(V_BSTR(&olestr)));
72 ok(V_VT(&comstr) == VT_BSTR, "Expected .vt to be VT_LPWSTR, was %u\n", V_VT(&comstr));
73 ok(!wcscmp(V_BSTR(&comstr), L"TESTW"), "Expected value to be L\"TESTW\", was: %s\n", wine_dbgstr_w(V_BSTR(&comstr)));
74 }
75 {
76 CComVariant cstr((LPCSTR)"TESTA");
77 ok(V_VT(&cstr) == VT_BSTR, "Expected .vt to be VT_LPWSTR, was %u\n", V_VT(&cstr));
78 ok(!wcscmp(V_BSTR(&cstr), L"TESTA"), "Expected value to be L\"TESTW\", was: %s\n", wine_dbgstr_w(V_BSTR(&cstr)));
79 }
80 {
81 CComVariant trueVal(true), falseVal(false);
82 ok(V_VT(&trueVal) == VT_BOOL, "Expected .vt to be BOOL, was %u\n", V_VT(&trueVal));
83 ok(V_BOOL(&trueVal) == VARIANT_TRUE, "Expected value to be VARIANT_TRUE, was: %u\n", V_BOOL(&trueVal));
84 ok(V_VT(&falseVal) == VT_BOOL, "Expected .vt to be BOOL, was %u\n", V_VT(&falseVal));
85 ok(V_BOOL(&falseVal) == VARIANT_FALSE, "Expected value to be VARIANT_TRUE, was: %u\n", V_BOOL(&falseVal));
86 }
87 {
88 CComVariant b1((BYTE)33);
89 ok(V_VT(&b1) == VT_UI1, "Expected .vt to be VT_UI1, was %u\n", V_VT(&b1));
90 ok(V_UI1(&b1) == (BYTE)33, "Expected value to be 33, was: %u\n", V_UI1(&b1));
91 }
92 {
93 CComVariant c1((char)33);
94 ok(V_VT(&c1) == VT_I1, "Expected .vt to be VT_I1, was %u\n", V_VT(&c1));
95 ok(V_I1(&c1) == (char)33, "Expected value to be 33, was: %d\n", V_I1(&c1));
96 }
97 {
98 CComVariant s1((short)12345);
99 ok(V_VT(&s1) == VT_I2, "Expected .vt to be VT_I2, was %u\n", V_VT(&s1));
100 ok(V_I2(&s1) == (short)12345, "Expected value to be 12345, was: %d\n", V_I1(&s1));
101 }
102 {
103 CComVariant us1((unsigned short)12345);
104 ok(V_VT(&us1) == VT_UI2, "Expected .vt to be VT_UI2, was %u\n", V_VT(&us1));
105 ok(V_UI2(&us1) == (unsigned short)12345, "Expected value to be 12345, was: %u\n", V_UI2(&us1));
106 }
107 {
108 CComVariant i1((int)4, VT_I4), i2((int)3, VT_INT), i3((int)2, VT_I2), i4((int)1);
109 expect_int(i1, 4, VT_I4);
110 expect_int(i2, 3, VT_INT);
111 expect_error(i3, E_INVALIDARG);
112 expect_int(i4, 1, VT_I4);
113 }
114 {
115 CComVariant ui1((unsigned int)4, VT_UI4), ui2((unsigned int)3, VT_UINT), ui3((unsigned int)2, VT_UI2), ui4((unsigned int)1);
116 expect_uint(ui1, 4, VT_UI4);
117 expect_uint(ui2, 3, VT_UINT);
118 expect_error(ui3, E_INVALIDARG);
119 expect_uint(ui4, 1, VT_UI4);
120 }
121 {
122 CComVariant l1((long)4, VT_I4), l2((long)3, VT_INT), l3((long)2, VT_ERROR), l4((long)1);
123 expect_int(l1, 4, VT_I4);
124 expect_error(l2, E_INVALIDARG);
125 expect_error(l3, 2);
126 expect_int(l4, 1, VT_I4);
127 }
128 {
129 CComVariant ul1((unsigned long)33);
130 expect_uint(ul1, 33, VT_UI4);
131 }
132 {
133 CComVariant f1(3.4f);
134 ok(V_VT(&f1) == VT_R4, "Expected .vt to be VT_R4, was %u\n", V_VT(&f1));
135 ok(V_R4(&f1) == 3.4f, "Expected value to be 3.4f, was: %f\n", V_R4(&f1));
136 }
137 {
138 CComVariant d1(3.4, VT_R8), d2(3.4, VT_DATE), d3(8.8, VT_I1), d4(1.9);
139 expect_double(d1, 3.4, VT_R8);
140 expect_double(d2, 3.4, VT_DATE);
141 expect_error(d3, E_INVALIDARG);
142 expect_double(d4, 1.9, VT_R8);
143 }
144 {
145 LONGLONG lv = 12030912309123ll;
146 CComVariant l1(lv);
147 ok(V_VT(&l1) == VT_I8, "Expected .vt to be VT_I8, was %u\n", V_VT(&l1));
148 ok(V_I8(&l1) == lv, "Expected value to be %s, was: %s\n", wine_dbgstr_longlong(lv), wine_dbgstr_longlong(V_I8(&l1)));
149 }
150 {
151 ULONGLONG lv = 12030912309123llu;
152 CComVariant l1(lv);
153 ok(V_VT(&l1) == VT_UI8, "Expected .vt to be VT_UI8, was %u\n", V_VT(&l1));
154 ok(V_UI8(&l1) == lv, "Expected value to be %s, was: %s\n", wine_dbgstr_longlong(lv), wine_dbgstr_longlong(V_UI8(&l1)));
155 }
156 {
157 CY cy;
158 cy.int64 = 12030912309123ll;
159 CComVariant c1(cy);
160 ok(V_VT(&c1) == VT_CY, "Expected .vt to be VT_CY, was %u\n", V_VT(&c1));
161 ok(V_CY(&c1).int64 == cy.int64, "Expected value to be %s, was: %s\n", wine_dbgstr_longlong(cy.int64), wine_dbgstr_longlong(V_CY(&c1).int64));
162 }
163 // IDispatch
164 // IUnknown
165 }
166
167
168 static void test_copyconstructor()
169 {
170 {
171 CComVariant empty;
172 CComVariant empty2(empty);
173 expect_empty(empty2);
174 }
175 {
176 CComBSTR bstr(L"TESTW");
177 CComVariant olestr((LPCOLESTR)bstr);
178 CComVariant olestr2(olestr);
179 ok(V_VT(&olestr2) == VT_BSTR, "Expected .vt to be VT_LPWSTR, was %u\n", V_VT(&olestr2));
180 ok(!wcscmp(V_BSTR(&olestr2), L"TESTW"), "Expected value to be L\"TESTW\", was: %s\n", wine_dbgstr_w(V_BSTR(&olestr2)));
181 }
182 {
183 CComVariant trueVal(true);
184 CComVariant trueVal2(trueVal);
185 ok(V_VT(&trueVal2) == VT_BOOL, "Expected .vt to be BOOL, was %u\n", V_VT(&trueVal2));
186 ok(V_BOOL(&trueVal2) == VARIANT_TRUE, "Expected value to be VARIANT_TRUE, was: %u\n", V_BOOL(&trueVal2));
187 }
188 {
189 CComVariant b1((BYTE)33);
190 CComVariant b2(b1);
191 ok(V_VT(&b2) == VT_UI1, "Expected .vt to be VT_UI1, was %u\n", V_VT(&b2));
192 ok(V_UI1(&b2) == (BYTE)33, "Expected value to be 33, was: %u\n", V_UI1(&b2));
193 }
194 {
195 CComVariant c1((char)33);
196 CComVariant c2(c1);
197 ok(V_VT(&c2) == VT_I1, "Expected .vt to be VT_I1, was %u\n", V_VT(&c2));
198 ok(V_I1(&c2) == (char)33, "Expected value to be 33, was: %d\n", V_I1(&c2));
199 }
200 {
201 CComVariant s1((short)12345);
202 CComVariant s2(s1);
203 ok(V_VT(&s2) == VT_I2, "Expected .vt to be VT_I2, was %u\n", V_VT(&s2));
204 ok(V_I2(&s2) == (short)12345, "Expected value to be 12345, was: %d\n", V_I1(&s2));
205 }
206 {
207 CComVariant us1((unsigned short)12345);
208 CComVariant us2(us1);
209 ok(V_VT(&us2) == VT_UI2, "Expected .vt to be VT_UI2, was %u\n", V_VT(&us2));
210 ok(V_UI2(&us2) == (unsigned short)12345, "Expected value to be 12345, was: %u\n", V_UI2(&us2));
211 }
212 {
213 CComVariant i1((int)4, VT_I4);
214 CComVariant i2(i1);
215 expect_int(i2, 4, VT_I4);
216 }
217 {
218 CComVariant ui1((unsigned int)4, VT_UI4);
219 CComVariant ui2(ui1);
220 expect_uint(ui2, 4, VT_UI4);
221 }
222 {
223 CComVariant l1((long)4, VT_I4);
224 CComVariant l2(l1);
225 expect_uint(l2, 4, VT_I4);
226 }
227 {
228 CComVariant ul1((unsigned long)33);
229 CComVariant ul2(ul1);
230 expect_uint(ul2, 33, VT_UI4);
231 }
232 {
233 CComVariant f1(3.4f);
234 CComVariant f2(f1);
235 ok(V_VT(&f2) == VT_R4, "Expected .vt to be VT_R4, was %u\n", V_VT(&f2));
236 ok(V_R4(&f2) == 3.4f, "Expected value to be 3.4f, was: %f\n", V_R4(&f2));
237 }
238 {
239 CComVariant d1(3.4, VT_R8);
240 CComVariant d2(d1);
241 expect_double(d2, 3.4, VT_R8);
242 }
243 {
244 LONGLONG lv = 12030912309123ll;
245 CComVariant l1(lv);
246 CComVariant l2(l1);
247 ok(V_VT(&l2) == VT_I8, "Expected .vt to be VT_I8, was %u\n", V_VT(&l2));
248 ok(V_I8(&l2) == lv, "Expected value to be %s, was: %s\n", wine_dbgstr_longlong(lv), wine_dbgstr_longlong(V_I8(&l2)));
249 }
250 {
251 ULONGLONG lv = 12030912309123llu;
252 CComVariant l1(lv);
253 CComVariant l2(l1);
254 ok(V_VT(&l2) == VT_UI8, "Expected .vt to be VT_UI8, was %u\n", V_VT(&l2));
255 ok(V_UI8(&l2) == lv, "Expected value to be %s, was: %s\n", wine_dbgstr_longlong(lv), wine_dbgstr_longlong(V_UI8(&l2)));
256 }
257 {
258 CY cy;
259 cy.int64 = 12030912309123ll;
260 CComVariant c1(cy);
261 CComVariant c2(c1);
262 ok(V_VT(&c2) == VT_CY, "Expected .vt to be VT_I8, was %u\n", V_VT(&c2));
263 ok(V_CY(&c2).int64 == cy.int64, "Expected value to be %s, was: %s\n", wine_dbgstr_longlong(cy.int64), wine_dbgstr_longlong(V_CY(&c2).int64));
264 }
265 // IDispatch
266 // IUnknown
267 }
268
269 static void test_assign()
270 {
271 {
272 CComVariant empty;
273 CComVariant empty2 = empty;
274 expect_empty(empty2);
275 }
276 {
277 CComBSTR bstr(L"TESTW");
278 CComVariant olestr = (LPCOLESTR)bstr;
279 ok(V_VT(&olestr) == VT_BSTR, "Expected .vt to be VT_LPWSTR, was %u\n", V_VT(&olestr));
280 ok(!wcscmp(V_BSTR(&olestr), L"TESTW"), "Expected value to be L\"TESTW\", was: %s\n", wine_dbgstr_w(V_BSTR(&olestr)));
281 CComVariant olestr2 = olestr;
282 ok(V_VT(&olestr2) == VT_BSTR, "Expected .vt to be VT_LPWSTR, was %u\n", V_VT(&olestr2));
283 ok(!wcscmp(V_BSTR(&olestr2), L"TESTW"), "Expected value to be L\"TESTW\", was: %s\n", wine_dbgstr_w(V_BSTR(&olestr2)));
284 }
285 {
286 CComVariant trueVal = true;
287 ok(V_VT(&trueVal) == VT_BOOL, "Expected .vt to be BOOL, was %u\n", V_VT(&trueVal));
288 ok(V_BOOL(&trueVal) == VARIANT_TRUE, "Expected value to be VARIANT_TRUE, was: %u\n", V_BOOL(&trueVal));
289 CComVariant trueVal2 = trueVal;
290 ok(V_VT(&trueVal2) == VT_BOOL, "Expected .vt to be BOOL, was %u\n", V_VT(&trueVal2));
291 ok(V_BOOL(&trueVal2) == VARIANT_TRUE, "Expected value to be VARIANT_TRUE, was: %u\n", V_BOOL(&trueVal2));
292 }
293 {
294 CComVariant b1 = (BYTE)33;
295 ok(V_VT(&b1) == VT_UI1, "Expected .vt to be VT_UI1, was %u\n", V_VT(&b1));
296 ok(V_UI1(&b1) == (BYTE)33, "Expected value to be 33, was: %u\n", V_UI1(&b1));
297 CComVariant b2 = b1;
298 ok(V_VT(&b2) == VT_UI1, "Expected .vt to be VT_UI1, was %u\n", V_VT(&b2));
299 ok(V_UI1(&b2) == (BYTE)33, "Expected value to be 33, was: %u\n", V_UI1(&b2));
300 }
301 {
302 CComVariant c1 = (char)33;
303 ok(V_VT(&c1) == VT_I1, "Expected .vt to be VT_I1, was %u\n", V_VT(&c1));
304 ok(V_I1(&c1) == (char)33, "Expected value to be 33, was: %d\n", V_I1(&c1));
305 CComVariant c2 = c1;
306 ok(V_VT(&c2) == VT_I1, "Expected .vt to be VT_I1, was %u\n", V_VT(&c2));
307 ok(V_I1(&c2) == (char)33, "Expected value to be 33, was: %d\n", V_I1(&c2));
308 }
309 {
310 CComVariant s1 = (short)12345;
311 ok(V_VT(&s1) == VT_I2, "Expected .vt to be VT_I2, was %u\n", V_VT(&s1));
312 ok(V_I2(&s1) == (short)12345, "Expected value to be 12345, was: %d\n", V_I1(&s1));
313 CComVariant s2 = s1;
314 ok(V_VT(&s2) == VT_I2, "Expected .vt to be VT_I2, was %u\n", V_VT(&s2));
315 ok(V_I2(&s2) == (short)12345, "Expected value to be 12345, was: %d\n", V_I1(&s2));
316 }
317 {
318 CComVariant us1 = (unsigned short)12345;
319 ok(V_VT(&us1) == VT_UI2, "Expected .vt to be VT_UI2, was %u\n", V_VT(&us1));
320 ok(V_UI2(&us1) == (unsigned short)12345, "Expected value to be 12345, was: %u\n", V_UI2(&us1));
321 CComVariant us2 = us1;
322 ok(V_VT(&us2) == VT_UI2, "Expected .vt to be VT_UI2, was %u\n", V_VT(&us2));
323 ok(V_UI2(&us2) == (unsigned short)12345, "Expected value to be 12345, was: %u\n", V_UI2(&us2));
324 }
325 {
326 CComVariant i1 = (int)4;
327 expect_int(i1, 4, VT_I4);
328 CComVariant i2 = i1;
329 expect_int(i2, 4, VT_I4);
330 }
331 {
332 CComVariant ui1 = (unsigned int)4;
333 expect_uint(ui1, 4, VT_UI4);
334 CComVariant ui2 = ui1;
335 expect_uint(ui2, 4, VT_UI4);
336 }
337 {
338 CComVariant l1 = (long)4;
339 expect_uint(l1, 4, VT_I4);
340 CComVariant l2 = l1;
341 expect_uint(l2, 4, VT_I4);
342 }
343 {
344 CComVariant ul1 = (unsigned long)33;
345 expect_uint(ul1, 33, VT_UI4);
346 CComVariant ul2 = ul1;
347 expect_uint(ul2, 33, VT_UI4);
348 }
349 {
350 CComVariant f1 = 3.4f;
351 ok(V_VT(&f1) == VT_R4, "Expected .vt to be VT_R4, was %u\n", V_VT(&f1));
352 ok(V_R4(&f1) == 3.4f, "Expected value to be 3.4f, was: %f\n", V_R4(&f1));
353 CComVariant f2 = f1;
354 ok(V_VT(&f2) == VT_R4, "Expected .vt to be VT_R4, was %u\n", V_VT(&f2));
355 ok(V_R4(&f2) == 3.4f, "Expected value to be 3.4f, was: %f\n", V_R4(&f2));
356 }
357 {
358 CComVariant d1 = 3.4;
359 expect_double(d1, 3.4, VT_R8);
360 CComVariant d2 = d1;
361 expect_double(d2, 3.4, VT_R8);
362 }
363 {
364 LONGLONG lv = 12030912309123ll;
365 CComVariant l1 = lv;
366 ok(V_VT(&l1) == VT_I8, "Expected .vt to be VT_I8, was %u\n", V_VT(&l1));
367 ok(V_I8(&l1) == lv, "Expected value to be %s, was: %s\n", wine_dbgstr_longlong(lv), wine_dbgstr_longlong(V_I8(&l1)));
368 CComVariant l2 = l1;
369 ok(V_VT(&l2) == VT_I8, "Expected .vt to be VT_I8, was %u\n", V_VT(&l2));
370 ok(V_I8(&l2) == lv, "Expected value to be %s, was: %s\n", wine_dbgstr_longlong(lv), wine_dbgstr_longlong(V_I8(&l2)));
371 }
372 {
373 ULONGLONG lv = 12030912309123llu;
374 CComVariant l1 = lv;
375 ok(V_VT(&l1) == VT_UI8, "Expected .vt to be VT_UI8, was %u\n", V_VT(&l1));
376 ok(V_UI8(&l1) == lv, "Expected value to be %s, was: %s\n", wine_dbgstr_longlong(lv), wine_dbgstr_longlong(V_UI8(&l1)));
377 CComVariant l2 = l1;
378 ok(V_VT(&l2) == VT_UI8, "Expected .vt to be VT_UI8, was %u\n", V_VT(&l2));
379 ok(V_UI8(&l2) == lv, "Expected value to be %s, was: %s\n", wine_dbgstr_longlong(lv), wine_dbgstr_longlong(V_UI8(&l2)));
380 }
381 {
382 CY cy;
383 cy.int64 = 12030912309123ll;
384 CComVariant c1 = cy;
385 ok(V_VT(&c1) == VT_CY, "Expected .vt to be VT_I8, was %u\n", V_VT(&c1));
386 ok(V_CY(&c1).int64 == cy.int64, "Expected value to be %s, was: %s\n", wine_dbgstr_longlong(cy.int64), wine_dbgstr_longlong(V_CY(&c1).int64));
387 CComVariant c2 = c1;
388 ok(V_VT(&c2) == VT_CY, "Expected .vt to be VT_I8, was %u\n", V_VT(&c2));
389 ok(V_CY(&c2).int64 == cy.int64, "Expected value to be %s, was: %s\n", wine_dbgstr_longlong(cy.int64), wine_dbgstr_longlong(V_CY(&c2).int64));
390 }
391 // IDispatch
392 // IUnknown
393 }
394
395 static void test_misc()
396 {
397 HRESULT hr;
398 {
399 CComVariant empty;
400 hr = empty.Clear();
401 ok(SUCCEEDED(hr), "Expected .Clear() to succeed, but it failed: 0x%lx\n", hr);
402 expect_empty(empty);
403 }
404
405 {
406 CComBSTR bstr(L"TESTW");
407 CComVariant olestr((LPCOLESTR)bstr), empty;
408
409 hr = empty.Copy(&olestr); // VARIANT*
410 ok(SUCCEEDED(hr), "Expected .Copy() to succeed, but it failed: 0x%lx\n", hr);
411 ok(V_VT(&empty) == VT_BSTR, "Expected .vt to be VT_LPWSTR, was %u\n", V_VT(&empty));
412 ok(!wcscmp(V_BSTR(&empty), L"TESTW"), "Expected value to be L\"TESTW\", was: %s\n", wine_dbgstr_w(V_BSTR(&empty)));
413
414 /* Clear does not null out the rest, it just sets .vt! */
415 hr = olestr.Clear();
416 ok(SUCCEEDED(hr), "Expected .Clear() to succeed, but it failed: 0x%lx\n", hr);
417 ok(V_VT(&olestr) == VT_EMPTY, "Expected .vt to be VT_EMPTY, was %u\n", V_VT(&olestr));
418 }
419
420 {
421 CComVariant d1(3.4, VT_R8), empty;
422 hr = empty.Copy(&d1);
423 ok(SUCCEEDED(hr), "Expected .Copy() to succeed, but it failed: 0x%lx\n", hr);
424 expect_double(empty, 3.4, VT_R8);
425 }
426
427 {
428 LONGLONG lv = 12030912309123ll;
429 CComVariant l1(lv);
430 CComVariant empty;
431 hr = empty.Copy(&l1);
432 ok(SUCCEEDED(hr), "Expected .Copy() to succeed, but it failed: 0x%lx\n", hr);
433 ok(V_VT(&empty) == VT_I8, "Expected .vt to be VT_I8, was %u\n", V_VT(&empty));
434 ok(V_I8(&empty) == lv, "Expected value to be %s, was: %s\n", wine_dbgstr_longlong(lv), wine_dbgstr_longlong(V_I8(&empty)));
435 }
436
437 {
438 CY cy;
439 cy.int64 = 12030912309123ll;
440 CComVariant c1(cy);
441 CComVariant empty;
442 hr = empty.Copy(&c1);
443 ok(SUCCEEDED(hr), "Expected .Copy() to succeed, but it failed: 0x%lx\n", hr);
444 ok(V_VT(&empty) == VT_CY, "Expected .vt to be VT_I8, was %u\n", V_VT(&empty));
445 ok(V_CY(&empty).int64 == cy.int64, "Expected value to be %s, was: %s\n", wine_dbgstr_longlong(cy.int64), wine_dbgstr_longlong(V_CY(&empty).int64));
446 }
447 {
448 CComVariant var = (int)333;
449 CComVariant var2;
450 // var2 = var changed to bstr
451 HRESULT hr = var2.ChangeType(VT_BSTR, &var);
452 ok(SUCCEEDED(hr), "Expected .ChangeType() to succeed, but it failed: 0x%lx\n", hr);
453 expect_int(var, 333, VT_I4);
454 ok(V_VT(&var2) == VT_BSTR, "Expected .vt to be VT_LPWSTR, was %u\n", V_VT(&var2));
455 ok(!wcscmp(V_BSTR(&var2), L"333"), "Expected value to be L\"TESTW\", was: %s\n", wine_dbgstr_w(V_BSTR(&var2)));
456
457 // change in place
458 hr = var.ChangeType(VT_BSTR);
459 ok(SUCCEEDED(hr), "Expected .ChangeType() to succeed, but it failed: 0x%lx\n", hr);
460 ok(V_VT(&var) == VT_BSTR, "Expected .vt to be VT_LPWSTR, was %u\n", V_VT(&var));
461 ok(!wcscmp(V_BSTR(&var), L"333"), "Expected value to be L\"TESTW\", was: %s\n", wine_dbgstr_w(V_BSTR(&var)));
462 }
463 }
464
465
466 START_TEST(CComVariant)
467 {
468 test_construction();
469 test_copyconstructor();
470 test_assign();
471 test_misc();
472 }