4 * Copyright 1998 Jean-Claude Cote
6 * The purpose of this program is validate the implementation
7 * of the APIs related to VARIANTs. The validation is done
8 * by comparing the results given by the Windows implementation
9 * versus the Wine implementation.
11 * This program tests the creation/coercion/destruction of VARIANTs.
13 * The program does not currently test any API that takes
14 * arguments of type: IDispatch, IUnknown, DECIMAL, CURRENCY.
16 * Since the purpose of this program is to compare the results
17 * from Windows and Wine it is written so that with a simple
18 * define it can be compiled either in Windows or Linux.
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License as published by the Free Software Foundation; either
23 * version 2.1 of the License, or (at your option) any later version.
25 * This library is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
30 * You should have received a copy of the GNU Lesser General Public
31 * License along with this library; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 * - The Variant structure in Windows has a non-named union. This means
36 * the member of the union are accessible simply by doing
37 * pVariant->pfltVal. With gcc it is not possible to have non-named
38 * union so it has been named 'u'. So it's members are accessible
39 * using this name like so pVariant->u.pfltVal. So if this program is
40 * compiled in Windows the references to 'u' will need to be take out
43 * - Also the printf is a little different so the format specifiers may
44 * need to be tweaked if this file is compile in Windows.
45 * Printf is also different in that it continues printing numbers
46 * even after there is no more significative digits left to print. These
47 * number are garbage and in windows they are set to zero but not
50 * - The VarDateFromStr is not implemented yet.
52 * - The date and floating point format may not be the exact same
53 * format has the one inwindows depending on what the Internatinal
54 * setting are in windows.
66 #include "wine/test.h"
78 #define MAX_BUFFER 1024
80 static char* WtoA( OLECHAR
* p
)
82 static char buffer
[MAX_BUFFER
];
83 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, p
, -1, buffer
+1, sizeof(buffer
)-3, NULL
, NULL
);
90 static OLECHAR
* AtoW( char* p
)
93 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, p
, -1, NULL
, 0 );
94 buffer
= malloc( len
* sizeof(OLECHAR
) );
95 MultiByteToWideChar( CP_ACP
, 0, p
, -1, buffer
, len
);
99 static const struct _vartypes
{
101 DWORD vcind1
,vcind2
,vcex1
,vcex2
;
103 {0, 0, 0x80070057, 0, 0x80020008 },
104 {1, 0, 0x80070057, 0, 0x80020008 },
105 {2, 0, 0, 0, 0x80020005 },
106 {3, 0, 0, 0, 0x80020005 },
107 {4, 0, 0, 0, 0x80020005 },
108 {5, 0, 0, 0, 0x80020005 },
109 {6, 0, 0, 0, 0x80020005 },
110 {7, 0, 0, 0, 0x80020005 },
111 {77,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
112 {78,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
113 {79,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
114 {80,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
115 {81,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
116 {82,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
117 {83,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
118 {84,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
119 {85,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
120 {86,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
121 {87,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
122 {88,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
123 {89,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
124 {90,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
125 {91,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
126 {92,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
127 {93,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
128 {94,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
129 {95,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
130 {96,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
131 {97,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
132 {98,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
133 {99,0x80020008, 0x80070057, 0x80020008, 0x80020008 },
136 static const char *strfromr8
[] = {
167 "7.65432198765432e+15",
168 "-7.65432198765432e+15",
169 "8.76543219876543e+16",
170 "-8.76543219876543e+16",
171 "9.87654321987654e+17",
172 "-9.87654321987654e+17",
173 "1.98765432198765e+18",
174 "-1.98765432198765e+18",
175 "2.19876543219877e+19",
176 "-2.19876543219877e+19",
267 "7.65432198765432e+15",
268 "-7.65432198765432e+15",
269 "8.76543219876543e+16",
270 "-8.76543219876543e+16",
271 "9.87654321987654e+17",
272 "-9.87654321987654e+17",
273 "1.98765432198765e+18",
274 "-1.98765432198765e+18",
275 "2.19876543219877e+19",
276 "-2.19876543219877e+19",
311 "0.2345001", /* FIXME: should be 0.2345 ? */
338 "654322.2", /* FIXME: should be 654322.3 */
339 "-654322.2",/* FIXME: should be -654322.3 */
350 /* These are the strings we use for the XxxFromStr tests.
351 * The arrays that follow define the expected results for each type.
353 static char* _pTestStrA
[] = {
406 "1000000000000000000000000000000000000000000000000000000000000000",
407 "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
408 "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
409 "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
410 "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
424 "11/11/1999:11:11:1134",
425 "11/11/1999 11:11:11:1",
426 "\t1999/\t11/21 11 :11:11am",
428 "11/11/1999 11:11:11Am",
429 "11/11/1999 11:11:11PM",
430 "11/11/199911:11:11PM",
431 "11/11/1999 0:0:11am",
432 "11/11/1999 11,11:11am",
433 "11/11/1999 11:11:11am",
434 "11/11/1999 11/11:11am",
435 "11/11/1999 11:11AM",
439 "11/11/1999 11:11:11",
447 "1999 January 3 9AM",
448 "1 January 1999 11AM",
451 "4:22 11/11/1999 AM",
453 "11-11/1999 11:11:11.12AM",
454 "1999 January 3, 9AM",
455 "December, 31, 2078",
456 "December, 31, 2078,",
476 #define NB_OLE_STRINGS (sizeof(_pTestStrA)/sizeof(*_pTestStrA))
478 static const struct _strret_date
{
483 } strrets_DATE
[NB_OLE_STRINGS
] = {
505 { 0x80020005, 0, 1 },
506 { 0x80020005, 0, 1 },
508 { 0x80020005, 0, 1 },
518 { 0, 35797.000000, 1 },
522 { 0x80020005, 0, 1 },
523 { 0, 0.043090, 0, 1 },
526 { 0x80020005, 0, 1 },
527 { 0x80020005, 0, 1 },
529 { 0x80020005, 0, 1 },
544 { 0, 36161.000000, 1 },
548 { 0x80020005, 0, 1 },
553 { 0, 36485.466100, 1 },
554 { 0, 36475.466100, 0, 1 },
555 { 0, 36475.966100, 0, 1 },
556 { 0x80020005, 0, 1 },
557 { 0, 36475.000127, 0, 1 },
559 { 0, 36475.466100, 0, 1 },
561 { 0, 36475.465972, 0, 1 },
562 { 0, 36475.041667, 1 },
563 { 0, 36475.000000, 1 },
564 { 0, 36475.466100, 0, 1 },
565 { 0, 36477.000000, 1 },
567 { 0, 36477.000000, 1 },
569 { 0x80020005, 0, 1 },
570 { 0, 36526.000000, 1 },
572 { 0, 36163.375000, 1 },
573 { 0, 36161.458333, 1 },
574 { 0, 36475.166667, 1 },
575 { 0x80020005, 0, 1 },
577 { 0x80020005, 0, 1 },
580 { 0x80020005, 0, 1 },
582 { 0, 36465.000000, 1 },
583 { 0, 36465.000000, 1 },
598 static const struct _strret_b
{
601 } strrets_B
[NB_OLE_STRINGS
] = {
607 { 0, VARIANT_FALSE
},
608 { 0, VARIANT_FALSE
},
642 { 0, VARIANT_FALSE
},
643 { 0, VARIANT_FALSE
},
708 { 0, VARIANT_FALSE
},
716 static const struct _strret_r8
{
719 } strrets_R8
[NB_OLE_STRINGS
] = {
739 { 0, -32768.000000 },
740 { 0, -32769.000000 },
741 { 0, 16777216.000000 },
742 { 0, 16777217.000000 },
743 { 0, -16777216.000000 },
744 { 0, 16777217.000000 },
745 { 0, 2147483647.000000 },
746 { 0, 2147483648.000000 },
747 { 0, -2147483647.000000 },
748 { 0, -2147483648.000000 },
762 { 0, 100000000000.000000 },
773 { 0, 99999999999999997e183
},
778 { 0, 4294967295.000000 },
779 { 0, 4294967296.000000 },
834 static const struct _strret_r4
{
837 } strrets_R4
[NB_OLE_STRINGS
] = {
855 { 0, 32767.000000F
},
856 { 0, 32768.000000F
},
857 { 0, -32768.000000F
},
858 { 0, -32769.000000F
},
859 { 0, 16777216.000000F
},
860 { 0, 16777216.000000F
},
861 { 0, -16777216.000000F
},
862 { 0, 16777216.000000F
},
863 { 0, 2147483648.000000F
},
864 { 0, 2147483648.000000F
},
865 { 0, -2147483648.000000F
},
866 { 0, -2147483648.000000F
},
880 { 0, 99999997952.000000F
},
893 { 0, 65535.000000F
},
894 { 0, 65535.500000F
},
895 { 0, 65536.000000F
},
896 { 0, 4294967296.000000F
},
897 { 0, 4294967296.000000F
},
952 static const struct _strret_i4
{
955 } strrets_I4
[NB_OLE_STRINGS
] = {
1070 static const struct _strret_i2
{
1073 } strrets_I2
[NB_OLE_STRINGS
] = {
1188 static const struct _strret_i1
{
1191 } strrets_I1
[NB_OLE_STRINGS
] = {
1306 static const struct _strret_u1
{
1309 } strrets_U1
[NB_OLE_STRINGS
] = {
1425 static const struct _strret_U2
{
1428 } strrets_U2
[NB_OLE_STRINGS
] = {
1544 static const struct _strret_U4
{
1547 } strrets_U4
[NB_OLE_STRINGS
] = {
1673 int* pInt
= &theInt
;
1675 VARIANT_BOOL
* pBool
= &b
;
1676 unsigned short uShort
= 0;
1677 unsigned short* pUShort
= &uShort
;
1678 unsigned long uLong
= 0;
1679 unsigned long* pULong
= &uLong
;
1681 CHAR
* pChar
= &theChar
;
1683 BYTE
* pByte
= &byte
;
1687 long* pLong
= &Long
;
1691 double* pDouble
= &d
;
1695 OLECHAR
* pOleChar
[NB_OLE_STRINGS
];
1697 for (i
=0; i
<NB_OLE_STRINGS
;i
++) {
1698 pOleChar
[i
]=AtoW(_pTestStrA
[i
]);
1701 /* Start testing the Low-Level API ( the coercions )
1705 /* unsigned char from...
1707 trace( "\n\n======== Testing VarUI1FromXXX ========\n");
1709 #define XOK "should return S_OK"
1710 #define XOV "should return DISP_E_OVERFLOW"
1711 /* ok(S_OK == VarUI1FromI2( 0, NULL ), XOK);
1713 trace( "VarUI1FromI2: passing in NULL as return val makes it crash, need to write proper test.\n" );
1715 ok(VarUI1FromStr(NULL
,0,0,pByte
) == DISP_E_TYPEMISMATCH
,"should return DISP_E_TYPEMISMATCH");
1716 ok(S_OK
== VarUI1FromI2( 0, pByte
), XOK
);
1717 ok(*pByte
== 0,"should give 0 byte value");
1719 ok(S_OK
== VarUI1FromI2( 69, pByte
), XOK
);
1720 ok(*pByte
== 69,"should give 69 byte value");
1722 ok(S_OK
== VarUI1FromI2( 70, pByte
), XOK
);
1723 ok(*pByte
== 70,"should give 70 byte value");
1725 ok(S_OK
== VarUI1FromI2( 128, pByte
), XOK
);
1726 ok(*pByte
== 128,"should give 128 byte value");
1728 ok(S_OK
== VarUI1FromI2( 255, pByte
), XOK
);
1729 ok(*pByte
== 255,"should give 255 byte value");
1731 ok(DISP_E_OVERFLOW
== VarUI1FromI2( 256, pByte
), XOV
);
1732 ok(DISP_E_OVERFLOW
== VarUI1FromI2( 257, pByte
), XOV
);
1734 ok(S_OK
== VarUI1FromR8( 0.0, pByte
), XOK
);
1735 ok(*pByte
== 0,"0.0 float should be converted to 0");
1737 ok(S_OK
== VarUI1FromR8( 69.33, pByte
), XOK
);
1738 ok(*pByte
== 0x45, "expected 69 (hex 0x45) as byte value");
1740 ok(S_OK
== VarUI1FromR8( 69.66, pByte
), XOK
);
1741 ok(*pByte
== 0x46, "expected 70 (hex 0x46) as byte value");
1743 ok(DISP_E_OVERFLOW
== VarUI1FromR8( -69.33, pByte
), XOV
);
1744 ok(DISP_E_OVERFLOW
== VarUI1FromR8( -69.66, pByte
), XOV
);
1746 ok(S_OK
== VarUI1FromR8( -0.5, pByte
), XOK
);
1747 ok(*pByte
== 0,"-0.5 should give return 0");
1749 ok(DISP_E_OVERFLOW
== VarUI1FromR8( -0.51, pByte
), XOV
);
1751 ok(S_OK
== VarUI1FromR8( -0.49, pByte
), XOK
);
1752 ok(*pByte
== 0,"-0.49 should give return 0");
1754 ok(S_OK
== VarUI1FromR8( 0.5, pByte
), XOK
);
1755 ok(*pByte
== 0,"0.5 should give return 0");
1757 ok(S_OK
== VarUI1FromR8( 0.51, pByte
), XOK
);
1758 ok(*pByte
== 1,"0.51 should give return 1");
1760 ok(S_OK
== VarUI1FromR8( 0.49, pByte
), XOK
);
1761 ok(*pByte
== 0,"0.49 should give return 0");
1763 ok(S_OK
== VarUI1FromDate( 0.0, pByte
), XOK
);
1764 ok(*pByte
== 0,"0.0 date should give return 0");
1766 ok(S_OK
== VarUI1FromDate( 69.33, pByte
), XOK
);
1767 ok(*pByte
== 0x45,"69.33 date should give return 0x45");
1769 ok(S_OK
== VarUI1FromDate( 69.66, pByte
), XOK
);
1770 ok(*pByte
== 0x46,"69.66 date should give return 0x46");
1772 ok(DISP_E_OVERFLOW
== VarUI1FromDate( -69.33, pByte
), XOV
);
1774 ok(DISP_E_OVERFLOW
== VarUI1FromDate( -69.66, pByte
), XOV
);
1776 ok(S_OK
== VarUI1FromBool( VARIANT_TRUE
, pByte
), XOK
);
1777 ok(*pByte
== 0xff, "true should be converted to 0xff");
1779 ok(S_OK
== VarUI1FromBool( VARIANT_FALSE
, pByte
), XOK
);
1780 ok(*pByte
== 0, "false should be converted to 0");
1782 for (i
= 0; i
< NB_OLE_STRINGS
; i
++)
1785 rc
=VarUI1FromStr( pOleChar
[i
], 0, 0, pByte
);
1786 ok(rc
== strrets_U1
[i
].error
,
1787 "VarUI1FromStr([%d]=\"%s\") rc=%lx instead of %lx",
1788 i
,_pTestStrA
[i
],rc
,strrets_U1
[i
].error
);
1789 if (rc
== 0 && strrets_U1
[i
].error
== 0) {
1790 ok(*pByte
== strrets_U1
[i
].retval
,
1791 "VarUI1FromStr([%d]=\"%s\") got %02x instead of %02x",
1792 i
,_pTestStrA
[i
],*pByte
,strrets_U1
[i
].retval
);
1796 /* unsigned short from ... */
1797 trace( "\n\n======== Testing VarUI2FromXXX ========\n");
1799 ok(DISP_E_OVERFLOW
== VarUI2FromI2( -1, pUShort
), XOV
);
1800 /* ok(S_OK == VarUI2FromI2( 0, NULL ), XOK);
1802 trace("VarUI2FromI2: passing in NULL as return val makes it crash, needs to be fixed.\n");
1804 ok(DISP_E_TYPEMISMATCH
== VarUI2FromStr( NULL
, 0, 0, pUShort
), "should return DISP_E_TYPEMISMATCH");
1806 ok(S_OK
== VarUI2FromI2( 0, pUShort
), XOK
);
1807 ok(*pUShort
== 0,"0 should be 0");
1808 ok(S_OK
== VarUI2FromI2( 69, pUShort
), XOK
);
1809 ok(*pUShort
== 69,"69 should be 69");
1810 ok(S_OK
== VarUI2FromI2( 70, pUShort
), XOK
);
1811 ok(*pUShort
== 70,"70 should be 70");
1813 ok(S_OK
== VarUI2FromI2( 128, pUShort
), XOK
);
1814 ok(*pUShort
== 128,"128 should be 128");
1816 ok(S_OK
== VarUI2FromI4( 65535, pUShort
), XOK
);
1817 ok(*pUShort
== 65535,"65535 should be 65535");
1818 ok(DISP_E_OVERFLOW
== VarUI2FromI4( 65536, pUShort
), XOV
);
1819 ok(DISP_E_OVERFLOW
== VarUI2FromI4( 65537, pUShort
), XOV
);
1820 ok(S_OK
== VarUI2FromR8( 0.0, pUShort
), XOK
);
1821 ok(*pUShort
== 0,"0.0 should be 0");
1822 ok(S_OK
== VarUI2FromR8( 69.33, pUShort
), XOK
);
1823 ok(*pUShort
== 69,"69.33 should be 69");
1824 ok(S_OK
== VarUI2FromR8( 69.66, pUShort
), XOK
);
1825 ok(*pUShort
== 70,"69.66 should be 70");
1827 ok(DISP_E_OVERFLOW
== VarUI2FromR8( -69.33, pUShort
), XOV
);
1828 ok(DISP_E_OVERFLOW
== VarUI2FromR8( -69.66, pUShort
), XOV
);
1830 ok(S_OK
== VarUI2FromR8( -0.5, pUShort
), XOK
);
1831 ok(*pUShort
== 0, "-0.5 -> 0");
1832 ok(DISP_E_OVERFLOW
== VarUI2FromR8( -0.51, pUShort
), XOV
);
1833 ok(S_OK
== VarUI2FromR8( -0.49, pUShort
), XOK
);
1834 ok(*pUShort
== 0, "-0.49 -> 0");
1836 ok(S_OK
== VarUI2FromR8( 0.5, pUShort
), XOK
);
1837 ok(*pUShort
== 0,"0.5 should be 0");
1838 ok(S_OK
== VarUI2FromR8( 0.51, pUShort
), XOK
);
1839 ok(*pUShort
== 1,"0.51 should be 1");
1840 ok(S_OK
== VarUI2FromR8( 0.49, pUShort
), XOK
);
1841 ok(*pUShort
== 0,"0.49 should be 0");
1843 ok(S_OK
== VarUI2FromDate( 0.0, pUShort
), XOK
);
1844 ok(*pUShort
== 0,"0.0 should be 0");
1845 ok(S_OK
== VarUI2FromDate( 69.33, pUShort
), XOK
);
1846 ok(*pUShort
== 69,"69.33 should be 69");
1847 ok(S_OK
== VarUI2FromDate( 69.66, pUShort
), XOK
);
1848 ok(*pUShort
== 70,"69.66 should be 70");
1849 ok(DISP_E_OVERFLOW
== VarUI2FromDate( -69.33, pUShort
), XOV
);
1850 ok(DISP_E_OVERFLOW
== VarUI2FromDate( -69.66, pUShort
), XOV
);
1852 ok(S_OK
== VarUI2FromBool( VARIANT_TRUE
, pUShort
), XOK
);
1853 ok(*pUShort
== 65535,"TRUE should be 65535");
1854 ok(S_OK
== VarUI2FromBool( VARIANT_FALSE
, pUShort
), XOK
);
1855 ok(*pUShort
== 0,"FALSE should be 0");
1857 for (i
= 0; i
< NB_OLE_STRINGS
; i
++)
1860 rc
=VarUI2FromStr( pOleChar
[i
], 0, 0, pUShort
);
1861 ok(rc
== strrets_U2
[i
].error
,
1862 "VarUI2FromStr([%d]=\"%s\") rc=%lx instead of %lx",
1863 i
,_pTestStrA
[i
],rc
,strrets_U2
[i
].error
);
1864 if (rc
== 0 && strrets_U2
[i
].error
== 0) {
1865 ok(*pUShort
== strrets_U2
[i
].retval
,
1866 "VarUI2FromStr([%d]=\"%s\") got %u instead of %u",
1867 i
,_pTestStrA
[i
],*pUShort
,strrets_U2
[i
].retval
);
1871 /* unsigned long from ...
1873 trace( "\n\n======== Testing VarUI4FromXXX ========\n");
1874 /*ok(S_OK == VarUI4FromI2( 0, NULL ), XOK);
1876 trace( "VarUI4FromI2: passing in NULL as return val makes it crash, implement me.\n");
1878 ok(DISP_E_TYPEMISMATCH
== VarUI4FromStr( NULL
, 0, 0, pULong
), "should erturn DISP_E_TYPEMISMATCH");
1880 ok(S_OK
== VarUI4FromI2( 0, pULong
), XOK
);
1881 ok(*pULong
== 0,"0 should be 0");
1882 ok(S_OK
== VarUI4FromI2( 69, pULong
), XOK
);
1883 ok(*pULong
== 69,"69 should be 69");
1885 ok(S_OK
== VarUI4FromI2( 70, pULong
), XOK
);
1886 ok(*pULong
== 70,"70 should be 70");
1888 ok(S_OK
== VarUI4FromI2( 128, pULong
), XOK
);
1889 ok(*pULong
== 128,"128 should be 128");
1890 ok(S_OK
== VarUI4FromI2( 255, pULong
), XOK
);
1891 ok(*pULong
== 255,"255 should be 255");
1893 ok(S_OK
== VarUI4FromR8( 4294967295.0, pULong
), XOK
);
1894 ok(*pULong
== 4294967295U,"4294967295.0 should be 4294967295");
1895 ok(DISP_E_OVERFLOW
== VarUI4FromR8( 4294967296.0, pULong
), XOV
);
1897 ok(S_OK
== VarUI4FromR8( 0.0, pULong
), XOK
);
1898 ok(*pULong
== 0,"0 should be 0");
1899 ok(S_OK
== VarUI4FromR8( 69.33, pULong
), XOK
);
1900 ok(*pULong
== 69,"69.33 should be 69");
1901 ok(S_OK
== VarUI4FromR8( 69.66, pULong
), XOK
);
1902 ok(*pULong
== 70,"69.66 should be 70");
1903 ok(DISP_E_OVERFLOW
== VarUI4FromR8( -69.33, pULong
), XOV
);
1904 ok(DISP_E_OVERFLOW
== VarUI4FromR8( -69.66, pULong
), XOV
);
1906 ok(S_OK
== VarUI4FromR8( -0.5, pULong
), XOK
);
1907 ok(*pULong
== 0,"-0.5 should be 0");
1909 ok(DISP_E_OVERFLOW
== VarUI4FromR8( -0.51, pULong
), XOV
);
1911 ok(S_OK
== VarUI4FromR8( -0.49, pULong
), XOK
);
1912 ok(*pULong
== 0,"-0.49 should be 0");
1914 ok(S_OK
== VarUI4FromR8( 0.5, pULong
), XOK
);
1915 ok(*pULong
== 0,"0.5 should be 0");
1916 ok(S_OK
== VarUI4FromR8( 0.51, pULong
), XOK
);
1917 ok(*pULong
== 1,"0.51 should be 1");
1918 ok(S_OK
== VarUI4FromR8( 0.49, pULong
), XOK
);
1919 ok(*pULong
== 0,"0.49 should be 0");
1921 ok(S_OK
== VarUI4FromDate( 0.0, pULong
), XOK
);
1922 ok(*pULong
== 0,"0.0 should be 0");
1923 ok(S_OK
== VarUI4FromDate( 69.33, pULong
), XOK
);
1924 ok(*pULong
== 69,"69.33 should be 69");
1925 ok(S_OK
== VarUI4FromDate( 69.66, pULong
), XOK
);
1926 ok(*pULong
== 70,"69.66 should be 70");
1927 ok(DISP_E_OVERFLOW
== VarUI4FromDate( -69.33, pULong
), XOV
);
1928 ok(DISP_E_OVERFLOW
== VarUI4FromDate( -69.66, pULong
), XOV
);
1930 ok(S_OK
== VarUI4FromBool( VARIANT_TRUE
, pULong
), XOK
);
1931 ok(*pULong
== 4294967295U, "TRUE should be 4294967295");
1932 ok(S_OK
== VarUI4FromBool( VARIANT_FALSE
, pULong
), XOK
);
1933 ok(*pULong
== 0, "FALSE should be 0");
1935 for (i
= 0; i
< NB_OLE_STRINGS
; i
++)
1938 rc
=VarUI4FromStr( pOleChar
[i
], 0, 0, pULong
);
1939 ok(rc
== strrets_U4
[i
].error
,
1940 "VarUI4FromStr([%d]=\"%s\") rc=%lx instead of %lx",
1941 i
,_pTestStrA
[i
],rc
,strrets_U4
[i
].error
);
1942 if (rc
== 0 && strrets_U4
[i
].error
== 0) {
1943 ok(*pULong
== strrets_U4
[i
].retval
,
1944 "VarUI4FromStr([%d]=\"%s\") got %lu instead of %lu",
1945 i
,_pTestStrA
[i
],*pULong
,strrets_U4
[i
].retval
);
1951 trace( "\n\n======== Testing VarI1FromXXX ========\n");
1953 ok(S_OK
== VarI1FromBool( VARIANT_TRUE
, pByte
), XOK
);
1954 ok(*pByte
== 255, " TRUE should be 255");
1956 ok(S_OK
== VarI1FromBool( VARIANT_TRUE
, pChar
), XOK
);
1957 ok(*pChar
== -1, "TRUE should be -1");
1959 ok(S_OK
== VarI1FromBool( VARIANT_FALSE
, pChar
), XOK
);
1960 ok(*pChar
== 0, "FALSE should be 0");
1962 ok(DISP_E_OVERFLOW
== VarI1FromUI1( (unsigned char)32767, pChar
), XOV
);
1963 ok(*pChar
== 0, "should still be 0");
1964 ok(DISP_E_OVERFLOW
== VarI1FromUI1( (unsigned char)65535, pChar
), XOV
);
1965 ok(*pChar
== 0, "should still be 0");
1967 ok(DISP_E_OVERFLOW
== VarI1FromI4( 32767, pChar
), XOV
);
1968 ok(*pChar
== 0, "should still be 0");
1969 ok(DISP_E_OVERFLOW
== VarI1FromI4( 32768, pChar
), XOV
);
1970 ok(*pChar
== 0, "should still be 0");
1971 ok(DISP_E_OVERFLOW
== VarI1FromI4( -32768, pChar
), XOV
);
1972 ok(*pChar
== 0, "should still be 0");
1973 ok(DISP_E_OVERFLOW
== VarI1FromI4( -32769, pChar
), XOV
);
1974 ok(*pChar
== 0, "should still be 0");
1976 ok(S_OK
== VarI1FromR8( 69.33, pChar
), XOK
);
1977 ok(*pChar
== 69, "69.33 should be 69");
1978 ok(S_OK
== VarI1FromR8( 69.66, pChar
), XOK
);
1979 ok(*pChar
== 70, "69.66 should be 70");
1981 ok(S_OK
== VarI1FromR8( -69.33, pChar
), XOK
);
1982 ok(*pChar
== -69, "-69.33 should be -69");
1983 ok(S_OK
== VarI1FromR8( -69.66, pChar
), XOK
);
1984 ok(*pChar
== -70, "-69.66 should be -70");
1985 ok(S_OK
== VarI1FromDate( -69.66, pChar
), XOK
);
1986 ok(*pChar
== -70, "-69.66 should be -70");
1988 for (i
= 0; i
< NB_OLE_STRINGS
; i
++)
1991 rc
=VarI1FromStr( pOleChar
[i
], 0, 0, pChar
);
1992 ok(rc
== strrets_I1
[i
].error
,
1993 "VarI1FromStr([%d]=\"%s\") rc=%lx instead of %lx",
1994 i
,_pTestStrA
[i
],rc
,strrets_I1
[i
].error
);
1995 if (rc
== 0 && strrets_I1
[i
].error
== 0) {
1996 ok(*pChar
== strrets_I1
[i
].retval
,
1997 "VarI1FromStr([%d]=\"%s\") got %d instead of %d",
1998 i
,_pTestStrA
[i
],*pChar
,strrets_I1
[i
].retval
);
2004 trace( "\n\n======== Testing VarI2FromXXX ========\n");
2006 ok(S_OK
== VarI2FromUI2( 32767, pShort
), XOK
);
2007 ok(*pShort
== 32767, "should be 32767");
2008 ok(DISP_E_OVERFLOW
== VarI2FromUI2( 65535, pShort
), XOV
);
2009 ok(*pShort
== 32767, "pShort should be unchanged");
2011 ok(S_OK
== VarI2FromI4( 32767, pShort
), XOK
);
2012 ok(*pShort
== 32767, "should be 32767");
2013 ok(DISP_E_OVERFLOW
== VarI2FromI4( 32768, pShort
), XOV
);
2014 ok(*pShort
== 32767, "should still be 32767");
2015 ok(S_OK
== VarI2FromI4( -32768, pShort
), XOK
);
2016 ok(*pShort
== -32768, "should be -32768");
2017 ok(DISP_E_OVERFLOW
== VarI2FromI4( -32769, pShort
), XOV
);
2018 ok(*pShort
== -32768, "should still be -32768");
2020 ok(S_OK
== VarI2FromR8( 69.33, pShort
), XOK
);
2021 ok(*pShort
== 69, "should be 69");
2022 ok(S_OK
== VarI2FromR8( 69.66, pShort
), XOK
);
2023 ok(*pShort
== 70, "should be 70");
2024 ok(S_OK
== VarI2FromR8( -69.33, pShort
), XOK
);
2025 ok(*pShort
== -69, "should be -69");
2026 ok(S_OK
== VarI2FromR8( -69.66, pShort
), XOK
);
2027 ok(*pShort
== -70, "should be -70");
2028 ok(S_OK
== VarI2FromDate( -69.66, pShort
), XOK
);
2029 ok(*pShort
== -70, "should be -70");
2031 for (i
= 0; i
< NB_OLE_STRINGS
; i
++)
2034 rc
=VarI2FromStr( pOleChar
[i
], 0, 0, pShort
);
2035 ok(rc
== strrets_I2
[i
].error
,
2036 "VarI2FromStr([%d]=\"%s\") rc=%lx instead of %lx",
2037 i
,_pTestStrA
[i
],rc
,strrets_I2
[i
].error
);
2038 if (rc
== 0 && strrets_I2
[i
].error
== 0) {
2039 ok(*pShort
== strrets_I2
[i
].retval
,
2040 "VarI2FromStr([%d]=\"%s\") got %d instead of %d",
2041 i
,_pTestStrA
[i
],*pShort
,strrets_I2
[i
].retval
);
2047 trace( "\n\n======== Testing VarI4FromXXX ========\n");
2049 ok(S_OK
== VarI4FromI2( 3, (long*)pInt
), XOK
);
2050 ok(*pInt
== 3,"should be 3");
2052 ok(S_OK
== VarI4FromR8( 69.33, pLong
), XOK
);
2053 ok(*pLong
== 69,"should be 69");
2054 ok(S_OK
== VarI4FromR8( 69.66, pLong
), XOK
);
2055 ok(*pLong
== 70,"should be 70");
2056 ok(S_OK
== VarI4FromR8( -69.33, pLong
), XOK
);
2057 ok(*pLong
== -69,"should be -69");
2058 ok(S_OK
== VarI4FromR8( -69.66, pLong
), XOK
);
2059 ok(*pLong
== -70,"should be -70");
2061 ok(S_OK
== VarI4FromR8( 2147483647.0, pLong
), XOK
);
2062 ok(*pLong
== 2147483647,"should be 2147483647");
2063 ok(DISP_E_OVERFLOW
== VarI4FromR8( 2147483648.0, pLong
), XOV
);
2064 ok(*pLong
== 2147483647,"should still be 2147483647");
2066 ok(S_OK
== VarI4FromR8( -2147483647.0, pLong
), XOK
);
2067 ok(*pLong
== -2147483647,"should be -2147483647");
2068 ok(S_OK
== VarI4FromR8( -2147483648.0, pLong
), XOK
);
2069 ok(*pLong
== 0x80000000L
,"should be -2147483648");
2070 ok(DISP_E_OVERFLOW
== VarI4FromR8( -2147483649.0, pLong
), XOV
);
2071 ok(*pLong
== 0x80000000L
,"should still be -2147483648");
2072 ok(DISP_E_OVERFLOW
== VarI4FromDate( -2147483649.0, pLong
), XOV
);
2073 ok(*pLong
== 0x80000000L
,"should still be -2147483648");
2075 for (i
= 0; i
< NB_OLE_STRINGS
; i
++)
2078 rc
=VarI4FromStr( pOleChar
[i
], 0, 0, pLong
);
2079 ok(rc
== strrets_I4
[i
].error
,
2080 "VarI4FromStr([%d]=\"%s\") rc=%lx instead of %lx",
2081 i
,_pTestStrA
[i
],rc
,strrets_I4
[i
].error
);
2082 if (rc
== 0 && strrets_I4
[i
].error
== 0) {
2083 ok(*pLong
== strrets_I4
[i
].retval
,
2084 "VarI4FromStr([%d]=\"%s\") got %ld instead of %ld",
2085 i
,_pTestStrA
[i
],*pLong
,strrets_I4
[i
].retval
);
2091 trace( "\n\n======== Testing VarR4FromXXX ========\n");
2093 ok(S_OK
== VarR4FromI4( 16777216, pFloat
), XOK
);
2094 ok(16777216.0 == *pFloat
,"should be 16777216.0");
2096 ok(S_OK
== VarR4FromI4( 16777217, pFloat
), XOK
);
2097 ok(16777216.0 == *pFloat
,"should be 16777216.0");
2098 ok(S_OK
== VarR4FromI4( -16777216, pFloat
), XOK
);
2099 ok(-16777216.0 == *pFloat
,"should be -16777216.0");
2100 ok(S_OK
== VarR4FromI4( -16777217, pFloat
), XOK
);
2101 ok(-16777216.0 == *pFloat
,"should be -16777216.0");
2103 ok(S_OK
== VarR4FromR8( 16777216.0, pFloat
), XOK
);
2104 ok(16777216.0 == *pFloat
,"should be 16777216.0");
2105 ok(S_OK
== VarR4FromR8( 16777217.0, pFloat
), XOK
);
2106 ok(16777216.0 == *pFloat
,"should be 16777216.0");
2107 ok(S_OK
== VarR4FromR8( -16777216.0, pFloat
), XOK
);
2108 ok(-16777216.0 == *pFloat
,"should be -16777216.0");
2109 ok(S_OK
== VarR4FromR8( -16777217.0, pFloat
), XOK
);
2110 ok(-16777216.0 == *pFloat
,"should be -16777216.0");
2112 ok(S_OK
== VarR4FromR8( 16777218e31
, pFloat
), XOK
);
2113 ok(*pFloat
== 167772177736353110000000000000000000000.000000,
2114 "should be 167772177736353110000000000000000000000.000000");
2115 ok(DISP_E_OVERFLOW
== VarR4FromR8( 16777218e32
, pFloat
), XOV
);
2116 ok(*pFloat
== 167772177736353110000000000000000000000.000000,
2117 "should still be 167772177736353110000000000000000000000.000000");
2118 ok(S_OK
== VarR4FromDate( 16777218e31
, pFloat
), XOK
);
2119 ok(*pFloat
== 167772177736353110000000000000000000000.000000,
2120 "should be 167772177736353110000000000000000000000.000000");
2122 for (i
= 0; i
< NB_OLE_STRINGS
; i
++)
2125 rc
=VarR4FromStr( pOleChar
[i
], 0, 0, pFloat
);
2126 ok(rc
== strrets_R4
[i
].error
,
2127 "VarR4FromStr([%d]=\"%s\") rc=%lx instead of %lx",
2128 i
,_pTestStrA
[i
],rc
,strrets_R4
[i
].error
);
2129 if (rc
== 0 && strrets_R4
[i
].error
== 0) {
2130 ok(*pFloat
== strrets_R4
[i
].retval
,
2131 "VarR4FromStr([%d]=\"%s\") got %f instead of %f",
2132 i
,_pTestStrA
[i
],*pFloat
,strrets_R4
[i
].retval
);
2138 trace( "\n\n======== Testing VarR8FromXXX ========\n");
2140 ok(S_OK
== VarR8FromDate( 900719925474099.0, pDouble
), XOK
);
2141 ok(*pDouble
== 900719925474099.000000,"should be 900719925474099.000000\n");
2142 for (i
= 0; i
< NB_OLE_STRINGS
; i
++)
2145 rc
=VarR8FromStr( pOleChar
[i
], 0, 0, pDouble
);
2146 ok(rc
== strrets_R8
[i
].error
,
2147 "VarR8FromStr([%d]=\"%s\") rc=%lx instead of %lx",
2148 i
,_pTestStrA
[i
],rc
,strrets_R8
[i
].error
);
2149 if (rc
== 0 && strrets_R8
[i
].error
== 0) {
2150 ok(*pDouble
== strrets_R8
[i
].retval
,
2151 "VarR8FromStr([%d]=\"%s\") got %g instead of %g",
2152 i
,_pTestStrA
[i
],*pDouble
,strrets_R8
[i
].retval
);
2158 trace( "\n\n======== Testing VarDateFromXXX ========\n");
2160 ok(S_OK
== VarDateFromI4( 2958465, pDouble
), XOK
);
2161 ok(*pDouble
== 2958465.000000,"should be 2958465.000000");
2162 ok(DISP_E_OVERFLOW
== VarDateFromI4( 2958466, pDouble
), XOV
);
2163 ok(*pDouble
== 2958465.000000,"should still be 2958465.000000");
2164 ok(S_OK
== VarDateFromI4( -657434, pDouble
), XOK
);
2165 ok(*pDouble
== -657434.000000,"should be -657434.000000");
2166 ok(DISP_E_OVERFLOW
== VarDateFromI4( -657435, pDouble
), XOV
);
2167 ok(*pDouble
== -657434.000000,"should still be -657434.000000");
2169 ok(S_OK
== VarDateFromR8( 2958465.9999, pDouble
), XOK
);
2170 ok(*pDouble
== 2958465.999900, "should be 2958465.999900");
2171 ok(DISP_E_OVERFLOW
== VarDateFromR8( 2958466, pDouble
), XOV
);
2172 ok(*pDouble
== 2958465.999900, "should still be 2958465.999900");
2173 ok(S_OK
== VarDateFromR8( -657434.9999, pDouble
), XOK
);
2174 ok(*pDouble
== -657434.999900,"should be -657434.999900");
2175 ok(DISP_E_OVERFLOW
== VarDateFromR8( -657435, pDouble
), XOV
);
2176 ok(*pDouble
== -657434.999900,"should still be -657434.999900");
2178 ok(S_OK
== VarDateFromR8( 0.0, pDouble
), XOK
);
2179 ok(*pDouble
== 0.0,"0.0 should be 0.0");
2180 ok(S_OK
== VarDateFromR8( 1.0, pDouble
), XOK
);
2181 ok(*pDouble
== 1.0,"1.0 should be 1.0");
2182 ok(S_OK
== VarDateFromR8( 2.25, pDouble
), XOK
);
2183 ok(*pDouble
== 2.25,"2.25 should be 2.25");
2184 ok(S_OK
== VarDateFromR8( -2.0, pDouble
), XOK
);
2185 ok(*pDouble
== -2.0,"-2.0 should be -2.0");
2187 /* Need some parsing function in Linux to emulate this...
2190 for (i
= 0; i
< NB_OLE_STRINGS
; i
++)
2193 rc
=VarDateFromStr( pOleChar
[i
], 0, 0, pDouble
);
2194 if (strrets_DATE
[i
].todo_rc
) {
2196 ok(rc
== strrets_DATE
[i
].error
,
2197 "VarDateFromStr([%d]=\"%s\") rc= %lx instead of %lx",
2198 i
,_pTestStrA
[i
],rc
,strrets_DATE
[i
].error
);
2201 ok(rc
== strrets_DATE
[i
].error
,
2202 "VarDateFromStr([%d]=\"%s\") rc= %lx instead of %lx",
2203 i
,_pTestStrA
[i
],rc
,strrets_DATE
[i
].error
);
2205 if (strrets_DATE
[i
].todo_rc
|| strrets_DATE
[i
].todo_val
) {
2207 if (rc
== 0 && strrets_DATE
[i
].error
== 0) {
2208 ok(*pDouble
== strrets_DATE
[i
].retval
,
2209 "VarDateFromStr([%d]=\"%s\") got %g instead of %g",
2210 i
,_pTestStrA
[i
],*pDouble
,strrets_DATE
[i
].retval
);
2214 if (rc
== 0 && strrets_DATE
[i
].error
== 0) {
2215 ok(*pDouble
== strrets_DATE
[i
].retval
,
2216 "VarDateFromStr([%d]=\"%s\") got %g instead of %g",
2217 i
,_pTestStrA
[i
],*pDouble
,strrets_DATE
[i
].retval
);
2223 trace( "\n\n======== Testing VarBoolFromXXX ========\n");
2225 ok(S_OK
== VarBoolFromI4( 0, pBool
), XOK
);
2226 ok(VARIANT_FALSE
== *pBool
, "expected FALSE");
2227 ok(S_OK
== VarBoolFromI4( 1, pBool
), XOK
);
2228 ok(VARIANT_TRUE
== *pBool
, "expected TRUE");
2229 ok(S_OK
== VarBoolFromI4( -1, pBool
), XOK
);
2230 ok(VARIANT_TRUE
== *pBool
, "expected TRUE");
2231 ok(S_OK
== VarBoolFromI4( 2, pBool
), XOK
);
2232 ok(VARIANT_TRUE
== *pBool
, "expected TRUE");
2234 ok(S_OK
== VarBoolFromUI1( ' ', pBool
), XOK
);
2235 ok(VARIANT_TRUE
== *pBool
, "expected TRUE");
2236 ok(S_OK
== VarBoolFromUI1( '\0', pBool
), XOK
);
2237 ok(VARIANT_FALSE
== *pBool
, "expected FALSE");
2238 ok(S_OK
== VarBoolFromUI1( 0x0000, pBool
), XOK
);
2239 ok(VARIANT_FALSE
== *pBool
, "expected FALSE");
2240 ok(S_OK
== VarBoolFromUI1( (unsigned char)0xFFF, pBool
), XOK
);
2241 ok(VARIANT_TRUE
== *pBool
, "expected TRUE");
2242 ok(S_OK
== VarBoolFromUI1( (unsigned char)0xFFFF, pBool
), XOK
);
2243 ok(VARIANT_TRUE
== *pBool
, "expected TRUE");
2245 ok(S_OK
== VarBoolFromR8( 0.0, pBool
), XOK
);
2246 ok(VARIANT_FALSE
== *pBool
, "expected FALSE");
2247 ok(S_OK
== VarBoolFromR8( 1.1, pBool
), XOK
);
2248 ok(VARIANT_TRUE
== *pBool
, "expected TRUE");
2249 ok(S_OK
== VarBoolFromR8( 0.5, pBool
), XOK
);
2250 ok(VARIANT_TRUE
== *pBool
, "expected TRUE");
2251 ok(S_OK
== VarBoolFromR8( 0.49, pBool
), XOK
);
2252 ok(VARIANT_TRUE
== *pBool
, "expected TRUE");
2253 ok(S_OK
== VarBoolFromR8( 0.51, pBool
), XOK
);
2254 ok(VARIANT_TRUE
== *pBool
, "expected TRUE");
2255 ok(S_OK
== VarBoolFromR8( -0.5, pBool
), XOK
);
2256 ok(VARIANT_TRUE
== *pBool
, "expected TRUE");
2257 ok(S_OK
== VarBoolFromR8( -0.49, pBool
), XOK
);
2258 ok(VARIANT_TRUE
== *pBool
, "expected TRUE");
2259 ok(S_OK
== VarBoolFromR8( -0.51, pBool
), XOK
);
2260 ok(VARIANT_TRUE
== *pBool
, "expected TRUE");
2263 for (i
= 0; i
< NB_OLE_STRINGS
; i
++)
2266 rc
=VarBoolFromStr( pOleChar
[i
], 0, 0, pBool
);
2267 ok(rc
== strrets_B
[i
].error
,
2268 "VarBoolFromStr([%d]=\"%s\") rc=%lx instead of %lx",
2269 i
,_pTestStrA
[i
],rc
,strrets_B
[i
].error
);
2270 if (rc
== 0 && strrets_B
[i
].error
== 0) {
2271 ok(*pBool
== strrets_B
[i
].retval
,
2272 "VarBoolFromStr([%d]=\"%s\") got %x instead of %x",
2273 i
,_pTestStrA
[i
],*pBool
,strrets_B
[i
].retval
);
2277 ok(S_OK
== VarI1FromBool( VARIANT_TRUE
, pByte
), XOK
);
2278 ok(*pByte
== 0xff,"true should be 0xff");
2279 ok(DISP_E_OVERFLOW
== VarUI2FromI2( -1, pUShort
), XOV
);
2283 trace( "\n\n======== Testing VarBSTRFromXXX ========\n");
2287 ok(S_OK
== VarBstrFromI1( -100, 0, 0, &bstr
), XOK
);
2288 ok(!strcmp(WtoA(bstr
),"\"-100\""),"should be string -100");
2290 ok(S_OK
== VarBstrFromUI1( 0x5A, 0, 0, &bstr
), XOK
);
2291 ok(!strcmp(WtoA(bstr
),"\"90\""),"should be string 90");
2292 ok(S_OK
== VarBstrFromI4( 2958465, 0, 0, &bstr
), XOK
);
2293 ok(!strcmp(WtoA(bstr
),"\"2958465\""),"should be string 2958465");
2299 for( i
=0; i
<20; i
++ )
2302 /* add an integer to the real number
2304 d
+= ((i
%9)+1) * pow( 10, i
);
2306 ok(S_OK
== VarBstrFromR8( d
, 0, 0, &bstr
), XOK
);
2307 sprintf(xval
,"\"%s\"",strfromr8
[off
]);
2308 ok(!strcmp(xval
,WtoA(bstr
)),
2309 "d is %g, should be cvt. to %s, but return val is %s",
2310 d
,strfromr8
[off
],WtoA(bstr
));
2313 ok(S_OK
== VarBstrFromR8( -d
, 0, 0, &bstr
), XOK
);
2314 sprintf(xval
,"\"%s\"",strfromr8
[off
]);
2315 ok(!strcmp(xval
,WtoA(bstr
)),
2316 "d is %g, should be cvt. to %s, but return val is %s",
2317 -d
,strfromr8
[off
],WtoA(bstr
));
2321 for( i
=0; i
<20; i
++ )
2324 /* add a decimal to the real number
2326 d
+= ((i
%9)+1) * pow( 10, (i
*-1) );
2327 ok(S_OK
== VarBstrFromR8( d
, 0, 0, &bstr
), XOK
);
2328 sprintf(xval
,"\"%s\"",strfromr8
[off
]);
2329 ok(!strcmp(xval
,WtoA(bstr
)),
2330 "d is %g, should be cvt. to %s, but return val is %s",
2331 d
,strfromr8
[off
],WtoA(bstr
));
2333 ok(S_OK
== VarBstrFromR8( d
-1, 0, 0, &bstr
), XOK
);
2334 sprintf(xval
,"\"%s\"",strfromr8
[off
]);
2335 ok(!strcmp(xval
,WtoA(bstr
)),
2336 "d is %g, should be cvt. to %s, but return val is %s",
2337 d
-1,strfromr8
[off
],WtoA(bstr
));
2339 ok(S_OK
== VarBstrFromR8( -d
, 0, 0, &bstr
), XOK
);
2340 sprintf(xval
,"\"%s\"",strfromr8
[off
]);
2341 ok(!strcmp(xval
,WtoA(bstr
)),
2342 "d is %g, should be cvt. to %s, but return val is %s",
2343 -d
,strfromr8
[off
],WtoA(bstr
));
2348 for( i
=0; i
<20; i
++ )
2351 /* add an integer to the real number
2353 d
+= ((i
%9)+1) * pow( 10, i
);
2354 /* add a decimal to the real number
2356 d
+= ((i
%9)+1) * pow( 10, (i
*-1) );
2357 ok(S_OK
== VarBstrFromR8( d
, 0, 0, &bstr
), XOK
);
2358 sprintf(xval
,"\"%s\"",strfromr8
[off
]);
2359 ok(!strcmp(xval
,WtoA(bstr
)),
2360 "d is %g, should be cvt. to %s, but return val is %s",
2361 d
,strfromr8
[off
],WtoA(bstr
));
2363 ok(S_OK
== VarBstrFromR8( -d
, 0, 0, &bstr
), XOK
);
2364 sprintf(xval
,"\"%s\"",strfromr8
[off
]);
2365 ok(!strcmp(xval
,WtoA(bstr
)),
2366 "d is %g, should be cvt. to %s, but return val is %s",
2367 -d
,strfromr8
[off
],WtoA(bstr
));
2374 for( i
=0; i
<10; i
++ )
2377 /* add an integer to the real number
2379 d
+= ((i
%9)+1) * pow( 10, i
);
2380 ok(S_OK
== VarBstrFromR4( (float)d
, 0, 0, &bstr
), XOK
);
2381 sprintf(xval
,"\"%s\"",strfromr8
[off
]);
2382 ok(!strcmp(xval
,WtoA(bstr
)),
2383 "d is %g, should be cvt. to %s, but return val is %s",
2384 d
,strfromr8
[off
],WtoA(bstr
));
2386 ok(S_OK
== VarBstrFromR4( (float)-d
, 0, 0, &bstr
), XOK
);
2387 sprintf(xval
,"\"%s\"",strfromr8
[off
]);
2388 ok(!strcmp(xval
,WtoA(bstr
)),
2389 "d is %g, should be cvt. to %s, but return val is %s",
2390 -d
,strfromr8
[off
],WtoA(bstr
));
2394 for( i
=0; i
<10; i
++ )
2397 /* add a decimal to the real number
2399 d
+= ((i
%9)+1) * pow( 10, (i
*-1) );
2400 ok(S_OK
== VarBstrFromR4( (float)d
, 0, 0, &bstr
), XOK
);
2401 sprintf(xval
,"\"%s\"",strfromr8
[off
]);
2402 ok(!strcmp(xval
,WtoA(bstr
)),
2403 "d is %g, should be cvt. to %s, but return val is %s",
2404 d
,strfromr8
[off
],WtoA(bstr
));
2406 ok(S_OK
== VarBstrFromR4( (float)d
-1, 0, 0, &bstr
), XOK
);
2407 sprintf(xval
,"\"%s\"",strfromr8
[off
]);
2408 ok(!strcmp(xval
,WtoA(bstr
)),
2409 "d is %g, should be cvt. to %s, but return val is %s",
2410 d
-1,strfromr8
[off
],WtoA(bstr
));
2412 ok(S_OK
== VarBstrFromR4( (float)-d
, 0, 0, &bstr
), XOK
);
2413 sprintf(xval
,"\"%s\"",strfromr8
[off
]);
2414 ok(!strcmp(xval
,WtoA(bstr
)),
2415 "d is %g, should be cvt. to %s, but return val is %s",
2416 -d
,strfromr8
[off
],WtoA(bstr
));
2421 for( i
=0; i
<10; i
++ )
2424 /* add an integer to the real number
2426 d
+= ((i
%9)+1) * pow( 10, i
);
2427 /* add a decimal to the real number
2429 d
+= ((i
%9)+1) * pow( 10, (i
*-1) );
2430 ok(S_OK
== VarBstrFromR4( (float)d
, 0, 0, &bstr
), XOK
);
2431 sprintf(xval
,"\"%s\"",strfromr8
[off
]);
2432 ok(!strcmp(xval
,WtoA(bstr
)),
2433 "d is %g, should be cvt. to %s, but return val is %s",
2434 d
,strfromr8
[off
],WtoA(bstr
));
2436 ok(S_OK
== VarBstrFromR4( (float)-d
, 0, 0, &bstr
), XOK
);
2437 sprintf(xval
,"\"%s\"",strfromr8
[off
]);
2438 ok(!strcmp(xval
,WtoA(bstr
)),
2439 "d is %g, should be cvt. to %s, but return val is %s",
2440 -d
,strfromr8
[off
],WtoA(bstr
));
2444 ok(S_OK
== VarBstrFromBool( 0x00, 0, 0, &bstr
), XOK
);
2445 ok(!strcmp(WtoA(bstr
),"\"False\""),"should be 'False'");
2446 ok(S_OK
== VarBstrFromBool( 0xFF, 0, 0, &bstr
), XOK
);
2447 ok(!strcmp(WtoA(bstr
),"\"True\""),"should be 'True'");
2449 ok(S_OK
== VarBstrFromDate( 0.0, 0, 0, &bstr
), XOK
);
2451 ok(!strcmp(WtoA(bstr
),"\"12:00:00 AM\""),
2452 "should be '12:00:00 AM', but is %s\n",WtoA(bstr
));
2455 ok(S_OK
== VarBstrFromDate( 3.34, 0, 0, &bstr
), XOK
);
2457 ok(!strcmp(WtoA(bstr
),"\"1/2/1900 8:09:36 AM\""),
2458 "should be '1/2/1900 8:09:36 AM', but is %s\n",WtoA(bstr
));
2461 ok(S_OK
== VarBstrFromDate( 3339.34, 0, 0, &bstr
), XOK
);
2463 ok(!strcmp(WtoA(bstr
),"\"2/20/1909 8:09:36 AM\""),
2464 "should be '2/20/1909 8:09:36 AM', but is %s\n",WtoA(bstr
));
2467 ok(S_OK
== VarBstrFromDate( 365.00, 0, 0, &bstr
), XOK
);
2469 ok(!strcmp(WtoA(bstr
),"\"12/30/1900\""),
2470 "should be '12/30/1900', but is %s\n",WtoA(bstr
));
2473 ok(S_OK
== VarBstrFromDate( 365.25, 0, 0, &bstr
), XOK
);
2475 ok(!strcmp(WtoA(bstr
),"\"12/30/1900 6:00:00 AM\""),
2476 "should be '12/30/1900 6:00:00 AM', but is %s\n",WtoA(bstr
));
2479 ok(S_OK
== VarBstrFromDate( 1461.0, 0, 0, &bstr
), XOK
);
2481 ok(!strcmp(WtoA(bstr
),"\"12/31/1903\""),
2482 "should be '12/31/1903', but is %s\n",WtoA(bstr
));
2485 ok(S_OK
== VarBstrFromDate( 1461.5, 0, 0, &bstr
), XOK
);
2487 ok(!strcmp(WtoA(bstr
),"\"12/31/1903 12:00:00 PM\""),
2488 "should be '12/31/1903 12:00:00 PM', but is %s\n",WtoA(bstr
));
2491 /* Test variant API...
2493 trace( "\n\n======== Testing Hi-Level Variant API ========\n");
2495 bstr
= SysAllocString( pOleChar
[4] );
2497 VariantClear( &va
);
2505 V_VT(&va
) = VT_BSTR
;
2506 V_UNION(&va
,bstrVal
) = bstr
;
2507 ok(S_OK
== VariantClear( &va
), XOK
);
2508 SysFreeString( bstr
);
2509 SysFreeString( bstr
);
2511 ok(S_OK
== VariantCopy( &vb
, &va
), XOK
);
2512 ok(S_OK
== VariantClear( &vb
), XOK
);
2513 ok(S_OK
== VariantClear( &va
), XOK
);
2517 V_UNION(&va
,dblVal
) = d
;
2518 ok(S_OK
== VariantCopy( &va
, &va
), XOK
);
2519 ok(V_R8(&va
) == 4.123,"should be 4.123");
2521 V_VT(&va
) = VT_R8
| VT_BYREF
;
2523 V_UNION(&va
,pdblVal
) = &d
;
2524 ok(S_OK
== VariantCopyInd( &va
, &va
), XOK
);
2525 ok(V_R8(&va
) == 31.123,"should be 31.123");
2529 V_UNION(&va
,dblVal
) = d
;
2530 ok(S_OK
== VariantCopy( &vb
, &va
), XOK
);
2531 ok(V_R8(&vb
) == 1.123,"should be 1.123");
2533 V_VT(&va
) = VT_R8
| VT_BYREF
;
2535 V_UNION(&va
,pdblVal
) = &d
;
2536 ok(S_OK
== VariantCopy( &vb
, &va
), XOK
);
2537 ok(*(V_R8REF(&vb
)) == 123.123,"should be 123.123");
2539 V_VT(&va
) = VT_R8
| VT_BYREF
;
2541 V_UNION(&va
,pdblVal
) = &d
;
2542 ok(S_OK
== VariantCopyInd( &vb
, &va
), XOK
);
2543 ok(V_R8(&vb
) == 111.2,"should be 111.2");
2545 V_VT(&va
) = VT_R8
| VT_BYREF
;
2547 V_UNION(&va
,pdblVal
) = &d
;
2548 ok(S_OK
== VariantChangeTypeEx( &va
, &va
, 0, 0, VT_I2
), XOK
);
2549 ok(V_VT(&va
) == VT_I2
,"should be type VT_I2");
2552 V_UNION(&va
,intVal
) = 4;
2553 ok(S_OK
== VariantChangeTypeEx(&vb
, &va
, 0, 0, VT_BSTR
), XOK
);
2554 ok(!strcmp(WtoA(V_BSTR(&vb
)),"\"4\""),"should be 4");
2556 V_VT(&va
) = VT_DATE
;
2557 V_UNION(&va
,date
) = 34465.332431;
2558 ok(S_OK
== VariantChangeTypeEx(&vb
, &va
, 0, 0, VT_BSTR
), XOK
);
2560 ok(!strcmp(WtoA(V_BSTR(&vb
)),"\"5/11/94 7:58:42 AM\""),"should be 5/11/94 7:58:42 AM");
2564 V_VT(&va
) = VT_BSTR
;
2565 V_UNION(&va
,bstrVal
) = bstr
;
2566 ok(S_OK
== VariantChangeTypeEx(&vb
, &va
, 0, 0, VT_R8
), XOK
);
2567 ok(V_R8(&vb
) == -0.490000,"should be -0.49");
2569 V_VT(&vc
) = VT_BSTR
| VT_BYREF
;
2570 V_UNION(&vc
,pbstrVal
) = &bstr
;
2571 V_VT(&vb
) = VT_VARIANT
| VT_BYREF
;
2572 V_UNION(&vb
,pvarVal
) = &vc
;
2573 V_VT(&va
) = VT_VARIANT
| VT_BYREF
;
2574 V_UNION(&va
,pvarVal
) = &vb
;
2575 ok(E_INVALIDARG
== VariantCopyInd( &vd
, &va
), "expect E_INVALIDARG");
2577 /* test what happens when bad vartypes are passed in */
2578 trace( "-------------- Testing different VARTYPES ----------------\n" );
2581 for( i
=0; i
<sizeof(vartypes
)/sizeof(vartypes
[0]); i
++ )
2583 /* Trying to use variants that are set to be BSTR but
2584 * do not contain a valid pointer makes the program crash
2585 * in Windows so we will skip those. We do not need them
2586 * anyway to illustrate the behavior.
2588 V_VT(&va
) = vartypes
[i
].ind
;
2590 V_UNION(&va
,dblVal
) = d
;
2591 rc
= VariantCopyInd( &vb
, &va
);
2592 sprintf(msg
,"vt %d, return value %lx, expected was %lx",vartypes
[i
].ind
,rc
,vartypes
[i
].vcind1
);
2593 ok(vartypes
[i
].vcind1
== rc
, msg
);
2594 V_VT(&va
) = vartypes
[i
].ind
| VT_BYREF
;
2596 V_UNION(&va
,pdblVal
) = &d
;
2597 rc
= VariantCopyInd( &vb
, &va
);
2598 sprintf(msg
,"vt %d, return value %lx, expected was %lx",vartypes
[i
].ind
,rc
,vartypes
[i
].vcind2
);
2599 ok(vartypes
[i
].vcind2
== rc
, msg
);
2602 V_UNION(&va
,dblVal
) = d
;
2603 rc
= VariantChangeTypeEx( &vb
, &va
, 0, 0, i
);
2604 sprintf(msg
,"vt %d, return value %lx, expected was %lx",vartypes
[i
].ind
,rc
,vartypes
[i
].vcex1
);
2605 ok(vartypes
[i
].vcex1
== rc
, msg
);
2608 V_UNION(&va
,dblVal
) = d
;
2609 rc
= VariantChangeTypeEx( &vb
, &va
, 0, 0, i
| VT_BYREF
);
2610 sprintf(msg
,"vt %d, return value %lx, expected was %lx",vartypes
[i
].ind
,rc
,vartypes
[i
].vcex1
);
2611 ok(vartypes
[i
].vcex2
== rc
, msg
);
2615 V_UNION(&va
,dblVal
) = d
;
2616 ok(DISP_E_BADVARTYPE
== VariantClear( &va
), "should give DISP_E_BADVARTYPE");
2619 VariantClear( &va
);
2620 VariantClear( &vb
);
2621 VariantClear( &vc
);
2622 VariantClear( &vd
);
2623 VariantClear( &ve
);
2624 /* There is alot of memory leaks but this is simply a test program.