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