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