4 * Copyright 1998 Jean-Claude Cote
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * - Does not test IDispatch, IUnknown, IRecordInfo, DECIMAL, CY, I8/UI8
31 #define NONAMELESSUNION
32 #define NONAMELESSSTRUCT
36 #include "wine/test.h"
46 static HMODULE hOleaut32;
48 static HRESULT (WINAPI *pVarBstrFromI1)(CHAR,LCID,ULONG,BSTR*)=NULL;
50 static HRESULT (WINAPI *pVarI1FromBool)(VARIANT_BOOL,CHAR*)=NULL;
51 static HRESULT (WINAPI *pVarI1FromDate)(DATE,CHAR*)=NULL;
52 static HRESULT (WINAPI *pVarI1FromI4)(LONG,CHAR*)=NULL;
53 static HRESULT (WINAPI *pVarI1FromR8)(double,CHAR*)=NULL;
54 static HRESULT (WINAPI *pVarI1FromStr)(OLECHAR*,LCID,ULONG,CHAR*);
55 static HRESULT (WINAPI *pVarI1FromUI1)(BYTE,CHAR*)=NULL;
57 static HRESULT (WINAPI *pVarI2FromUI2)(USHORT,short*)=NULL;
59 static HRESULT (WINAPI *pVarUI2FromBool)(VARIANT_BOOL,USHORT*)=NULL;
60 static HRESULT (WINAPI *pVarUI2FromDate)(DATE,USHORT*)=NULL;
61 static HRESULT (WINAPI *pVarUI2FromI2)(short,USHORT*)=NULL;
62 static HRESULT (WINAPI *pVarUI2FromI4)(LONG,USHORT*);
63 static HRESULT (WINAPI *pVarUI2FromR8)(double,USHORT*)=NULL;
64 static HRESULT (WINAPI *pVarUI2FromStr)(OLECHAR*,LCID,ULONG,USHORT*)=NULL;
66 static HRESULT (WINAPI *pVarUI4FromBool)(VARIANT_BOOL,ULONG*)=NULL;
67 static HRESULT (WINAPI *pVarUI4FromDate)(DATE,ULONG*)=NULL;
68 static HRESULT (WINAPI *pVarUI4FromI2)(short,ULONG*)=NULL;
69 static HRESULT (WINAPI *pVarUI4FromR8)(double,ULONG*)=NULL;
70 static HRESULT (WINAPI *pVarUI4FromStr)(OLECHAR*,LCID,ULONG,ULONG*)=NULL;
72 static HRESULT (WINAPI *pVarUdateFromDate)(DATE,ULONG,UDATE*);
73 static HRESULT (WINAPI *pVarDateFromUdate)(UDATE*,ULONG,DATE*);
74 static INT (WINAPI *pSystemTimeToVariantTime)(LPSYSTEMTIME,double*);
75 static INT (WINAPI *pVariantTimeToSystemTime)(double,LPSYSTEMTIME);
76 static INT (WINAPI *pDosDateTimeToVariantTime)(USHORT,USHORT,double*);
77 static INT (WINAPI *pVariantTimeToDosDateTime)(double,USHORT*,USHORT *);
78 static HRESULT (WINAPI *pVarFormatNumber)(LPVARIANT,int,int,int,int,ULONG,BSTR*);
79 static HRESULT (WINAPI *pVarFormat)(LPVARIANT,LPOLESTR,int,int,ULONG,BSTR*);
81 /* Get a conversion function ptr, return if function not available */
82 #define CHECKPTR(func) p##func = (void*)GetProcAddress(hOleaut32, #func); \
83 if (!p##func) { trace("function " # func " not available, not testing it\n"); return; }
85 /* Is a given function exported from oleaut32? */
86 #define HAVE_FUNC(func) ((void*)GetProcAddress(hOleaut32, #func) != NULL)
88 /* Have IRecordInfo data type? */
89 #define HAVE_OLEAUT32_RECORD HAVE_FUNC(SafeArraySetRecordInfo)
90 /* Have CY data type? */
91 #define HAVE_OLEAUT32_CY HAVE_FUNC(VarCyAdd)
92 /* Have I8/UI8 data type? */
93 #define HAVE_OLEAUT32_I8 HAVE_FUNC(VarI8FromI1)
95 /* When comparing floating point values we cannot expect an exact match
96 * because the rounding errors depend on the exact algorithm.
98 #define EQ_DOUBLE(a,b) (fabs((a)-(b))<1e-14)
100 #define MAX_BUFFER 1024
102 static char* WtoA( OLECHAR* p )
104 static char buffer[MAX_BUFFER];
105 DWORD len = WideCharToMultiByte( CP_ACP, 0, p, -1, buffer+1, sizeof(buffer)-3, NULL, NULL );
112 static OLECHAR* AtoW( const char* p )
115 DWORD len = MultiByteToWideChar( CP_ACP, 0, p, -1, NULL, 0 );
116 buffer = malloc( len * sizeof(OLECHAR) );
117 MultiByteToWideChar( CP_ACP, 0, p, -1, buffer, len );
121 static inline int strcmpW( const WCHAR *str1, const WCHAR *str2 )
123 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
124 return *str1 - *str2;
127 static const struct _vartypes {
129 HRESULT vcind1,vcind2,vcex1,vcex2;
130 int todoind1,todoind2,todowcex1,todowcex2;
132 {0, 0, 0x80070057, 0, 0x80020008,0,1 },
133 {1, 0, 0x80070057, 0, 0x80020008,0,1 },
134 {2, 0, 0, 0, 0x80020005 },
135 {3, 0, 0, 0, 0x80020005 },
136 {4, 0, 0, 0, 0x80020005 },
137 {5, 0, 0, 0, 0x80020005 },
138 {6, 0, 0, 0, 0x80020005 },
139 {7, 0, 0, 0, 0x80020005 },
140 {77,0x80020008, 0x80070057, 0, 0x80020005,0,1 },
141 {78,0x80020008, 0x80070057, 0x80020005, 0x80020005,0,1 },
142 {79,0x80020008, 0x80070057, 0x80020005, 0x80020005,0,1 },
143 {80,0x80020008, 0x80070057, 0, 0x80020005,0,1 },
144 {81,0x80020008, 0x80070057, 0x80020005, 0x80020005,0,1 },
145 {82,0x80020008, 0x80070057, 0x80020005, 0x80020005,0,1 },
146 {83,0x80020008, 0x80070057, 0, 0x80020005,0,1,1 },
147 {84,0x80020008, 0x80070057, 0x80020008, 0x80020008,0,1,1,1 },
148 {85,0x80020008, 0x80070057, 0, 0x80020005,0,1 },
149 {86,0x80020008, 0x80070057, 0, 0x80020005,0,1 },
150 {87,0x80020008, 0x80070057, 0, 0x80020005,0,1 },
151 {88,0x80020008, 0x80070057, 0, 0x80020005,0,1 },
152 {89,0x80020008, 0x80070057, 0, 0x80020005,0,1,1 },
153 {90,0x80020008, 0x80070057, 0, 0x80020005,0,1,1 },
154 {91,0x80020008, 0x80070057, 0, 0x80020005,0,1 },
155 {92,0x80020008, 0x80070057, 0, 0x80020005,0,1 },
156 {93,0x80020008, 0x80070057, 0x80020008, 0x80020008,0,1,1,1 },
157 {94,0x80020008, 0x80070057, 0x80020008, 0x80020008,0,1,1,1 },
158 {95,0x80020008, 0x80070057, 0x80020008, 0x80020008,0,1,1,1 },
159 {96,0x80020008, 0x80070057, 0x80020008, 0x80020008,0,1,1,1 },
160 {97,0x80020008, 0x80070057, 0x80020008, 0x80020008,0,1,1,1 },
161 {98,0x80020008, 0x80070057, 0x80020008, 0x80020008,0,1,1,1 },
162 {99,0x80020008, 0x80070057, 0x80020008, 0x80020008,0,1,1,1 },
165 static const char *strfromr8[] = {
196 "7.65432198765432E+15",
197 "-7.65432198765432E+15",
198 "8.76543219876543E+16",
199 "-8.76543219876543E+16",
200 "9.87654321987654E+17",
201 "-9.87654321987654E+17",
202 "1.98765432198765E+18",
203 "-1.98765432198765E+18",
204 "2.19876543219877E+19",
205 "-2.19876543219877E+19",
296 "7.65432198765432E+15",
297 "-7.65432198765432E+15",
298 "8.76543219876543E+16",
299 "-8.76543219876543E+16",
300 "9.87654321987654E+17",
301 "-9.87654321987654E+17",
302 "1.98765432198765E+18",
303 "-1.98765432198765E+18",
304 "2.19876543219877E+19",
305 "-2.19876543219877E+19",
379 /* These are the strings we use for the XxxFromStr tests.
380 * The arrays that follow define the expected results for each type.
382 static const char* _pTestStrA[] = {
435 "1000000000000000000000000000000000000000000000000000000000000000",
436 "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
437 "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
438 "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
439 "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
453 "11/11/1999:11:11:1134",
454 "11/11/1999 11:11:11:1",
455 "\t1999/\t11/21 11 :11:11am",
457 "11/11/1999 11:11:11Am",
458 "11/11/1999 11:11:11PM",
459 "11/11/199911:11:11PM",
460 "11/11/1999 0:0:11am",
461 "11/11/1999 11,11:11am",
462 "11/11/1999 11:11:11am",
463 "11/11/1999 11/11:11am",
464 "11/11/1999 11:11AM",
468 "11/11/1999 11:11:11",
476 "1999 January 3 9AM",
477 "1 January 1999 11AM",
480 "4:22 11/11/1999 AM",
482 "11-11/1999 11:11:11.12AM",
483 "1999 January 3, 9AM",
484 "December, 31, 2078",
485 "December, 31, 2078,",
505 #define NB_OLE_STRINGS (sizeof(_pTestStrA)/sizeof(*_pTestStrA))
507 static const struct _strret_date {
512 } strrets_DATE[NB_OLE_STRINGS] = {
520 { 0, 0.03402777777777, 1 },
521 { 0, 0.00347222222222, 1 },
522 { 0, 0.03541666666666, 1 },
534 { 0x80020005, 0.0, 1 },
535 { 0x80020005, 0.0, 1 },
537 { 0x80020005, 0.0, 1 },
551 { 0x80020005, 0.0, 1 },
552 { 0, 0.04309027777777, 0, 1 },
555 { 0x80020005, 0.0, 1 },
556 { 0x80020005, 0.0, 1 },
558 { 0x80020005, 0.0, 1 },
577 { 0x80020005, 0.0, 1 },
582 { 0, 36485.466099537036, 1 },
583 { 0, 36475.466099537036 },
584 { 0, 36475.966099537036 },
585 { 0x80020005, 0.0, 1 },
586 { 0, 36475.000127314815 },
588 { 0, 36475.466099537036 },
590 { 0, 36475.465972222222 },
591 { 0, 36475.041666666664, 1 },
593 { 0, 36475.466099537036 },
598 { 0x80020005, 0.0, 1 },
601 { 0, 36163.375000000000, 1 },
602 { 0, 36161.458333333336, 1 },
603 { 0, 36475.166666666664, 1 },
604 { 0x80020005, 0.0, 1 },
606 { 0x80020005, 0.0, 1 },
609 { 0x80020005, 0.0, 1 },
622 { 0, 0.045138888888889, 1 },
623 { 0, 0.086805555555556, 1 },
624 { 0, 0.128472222222222, 1 },
625 { 0, 0.170138888888889, 1 },
627 static const struct _strret_b {
630 } strrets_B[NB_OLE_STRINGS] = {
636 { 0, VARIANT_FALSE },
637 { 0, VARIANT_FALSE },
671 { 0, VARIANT_FALSE },
672 { 0, VARIANT_FALSE },
737 { 0, VARIANT_FALSE },
745 static const struct _strret_r8 {
748 } strrets_R8[NB_OLE_STRINGS] = {
768 { 0, -32768.000000 },
769 { 0, -32769.000000 },
770 { 0, 16777216.000000 },
771 { 0, 16777217.000000 },
772 { 0, -16777216.000000 },
773 { 0, 16777217.000000 },
774 { 0, 2147483647.000000 },
775 { 0, 2147483648.000000 },
776 { 0, -2147483647.000000 },
777 { 0, -2147483648.000000 },
791 { 0, 100000000000.000000 },
802 { 0, 99999999999999997e183 },
807 { 0, 4294967295.000000 },
808 { 0, 4294967296.000000 },
863 static const struct _strret_r4 {
866 } strrets_R4[NB_OLE_STRINGS] = {
884 { 0, 32767.000000F },
885 { 0, 32768.000000F },
886 { 0, -32768.000000F },
887 { 0, -32769.000000F },
888 { 0, 16777216.000000F },
889 { 0, 16777216.000000F },
890 { 0, -16777216.000000F },
891 { 0, 16777216.000000F },
892 { 0, 2147483648.000000F },
893 { 0, 2147483648.000000F },
894 { 0, -2147483648.000000F },
895 { 0, -2147483648.000000F },
909 { 0, 99999997952.000000F },
922 { 0, 65535.000000F },
923 { 0, 65535.500000F },
924 { 0, 65536.000000F },
925 { 0, 4294967296.000000F },
926 { 0, 4294967296.000000F },
981 static const struct _strret_i4 {
984 } strrets_I4[NB_OLE_STRINGS] = {
1012 { 0, -2147483647L },
1099 static const struct _strret_i2 {
1102 } strrets_I2[NB_OLE_STRINGS] = {
1217 static const struct _strret_i1 {
1220 } strrets_I1[NB_OLE_STRINGS] = {
1335 static const struct _strret_u1 {
1338 } strrets_U1[NB_OLE_STRINGS] = {
1454 static const struct _strret_U2 {
1457 } strrets_U2[NB_OLE_STRINGS] = {
1573 static const struct _strret_U4 {
1576 } strrets_U4[NB_OLE_STRINGS] = {
1692 static void test_variant(void)
1704 int* pInt = &theInt;
1706 VARIANT_BOOL* pBool = &b;
1707 unsigned short uShort = 0;
1708 unsigned short* pUShort = &uShort;
1709 unsigned long uLong = 0;
1710 unsigned long* pULong = &uLong;
1712 CHAR* pChar = &theChar;
1714 BYTE* pByte = &byte;
1718 long* pLong = &Long;
1722 double* pDouble = &d;
1726 OLECHAR* pOleChar[NB_OLE_STRINGS];
1728 for (i=0; i<NB_OLE_STRINGS;i++) {
1729 pOleChar[i]=AtoW(_pTestStrA[i]);
1731 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT );
1733 /* Start testing the Low-Level API ( the coercions )
1735 hdll=LoadLibraryA("netapi32.dll");
1736 pVarI1FromBool=(void*)GetProcAddress(hdll,"VarI1FromBool");
1737 pVarI1FromDate=(void*)GetProcAddress(hdll,"VarI1FromDate");
1738 pVarI1FromI4=(void*)GetProcAddress(hdll,"VarI1FromI4");
1739 pVarI1FromR8=(void*)GetProcAddress(hdll,"VarI1FromR8");
1740 pVarI1FromStr=(void*)GetProcAddress(hdll,"VarI1FromStr");
1741 pVarI1FromUI1=(void*)GetProcAddress(hdll,"VarI1FromUI1");
1743 pVarI2FromUI2=(void*)GetProcAddress(hdll,"VarI2FromUI2");
1745 pVarUI2FromBool=(void*)GetProcAddress(hdll,"VarUI2FromBool");
1746 pVarUI2FromDate=(void*)GetProcAddress(hdll,"VarUI2FromDate");
1747 pVarUI2FromI2=(void*)GetProcAddress(hdll,"VarUI2FromI2");
1748 pVarUI2FromI4=(void*)GetProcAddress(hdll,"VarUI2FromI4");
1749 pVarUI2FromR8=(void*)GetProcAddress(hdll,"VarUI2FromR8");
1750 pVarUI2FromStr=(void*)GetProcAddress(hdll,"VarUI2FromStr");
1752 pVarUI4FromBool=(void*)GetProcAddress(hdll,"VarUI4FromBool");
1753 pVarUI4FromDate=(void*)GetProcAddress(hdll,"VarUI4FromDate");
1754 pVarUI4FromI2=(void*)GetProcAddress(hdll,"VarUI4FromI2");
1755 pVarUI4FromR8=(void*)GetProcAddress(hdll,"VarUI4FromR8");
1756 pVarUI4FromStr=(void*)GetProcAddress(hdll,"VarUI4FromStr");
1758 /* unsigned char from...
1760 trace( "======== Testing VarUI1FromXXX ========\n");
1762 #define XOK "should return S_OK\n"
1763 #define XOV "should return DISP_E_OVERFLOW\n"
1764 /* Crashes on Win95: VarUI1FromI2( 0, NULL ) */
1766 ok(VarUI1FromStr(NULL, lcid, 0, pByte) == DISP_E_TYPEMISMATCH,"should return DISP_E_TYPEMISMATCH");
1767 ok(S_OK == VarUI1FromI2( 0, pByte ), XOK);
1768 ok(*pByte == 0,"should give 0 byte value");
1770 ok(S_OK == VarUI1FromI2( 69, pByte ), XOK);
1771 ok(*pByte == 69,"should give 69 byte value");
1773 ok(S_OK == VarUI1FromI2( 70, pByte ), XOK);
1774 ok(*pByte == 70,"should give 70 byte value");
1776 ok(S_OK == VarUI1FromI2( 128, pByte ), XOK);
1777 ok(*pByte == 128,"should give 128 byte value");
1779 ok(S_OK == VarUI1FromI2( 255, pByte ), XOK);
1780 ok(*pByte == 255,"should give 255 byte value");
1782 ok(DISP_E_OVERFLOW == VarUI1FromI2( 256, pByte ), XOV);
1783 ok(DISP_E_OVERFLOW == VarUI1FromI2( 257, pByte ), XOV);
1785 ok(S_OK == VarUI1FromR8( 0.0, pByte ), XOK);
1786 ok(*pByte == 0,"0.0 float should be converted to 0");
1788 ok(S_OK == VarUI1FromR8( 69.33, pByte ), XOK);
1789 ok(*pByte == 0x45, "expected 69 (hex 0x45) as byte value");
1791 ok(S_OK == VarUI1FromR8( 69.66, pByte ), XOK);
1792 ok(*pByte == 0x46, "expected 70 (hex 0x46) as byte value");
1794 ok(DISP_E_OVERFLOW == VarUI1FromR8( -69.33, pByte ), XOV);
1795 ok(DISP_E_OVERFLOW == VarUI1FromR8( -69.66, pByte ), XOV);
1797 ok(S_OK == VarUI1FromR8( -0.5, pByte ), XOK);
1798 ok(*pByte == 0,"-0.5 should give return 0");
1800 ok(DISP_E_OVERFLOW == VarUI1FromR8( -0.51, pByte ), XOV);
1802 ok(S_OK == VarUI1FromR8( -0.49, pByte ), XOK);
1803 ok(*pByte == 0,"-0.49 should give return 0");
1805 ok(S_OK == VarUI1FromR8( 0.5, pByte ), XOK);
1806 ok(*pByte == 0,"0.5 should give return 0");
1808 ok(S_OK == VarUI1FromR8( 0.51, pByte ), XOK);
1809 ok(*pByte == 1,"0.51 should give return 1");
1811 ok(S_OK == VarUI1FromR8( 0.49, pByte ), XOK);
1812 ok(*pByte == 0,"0.49 should give return 0");
1814 ok(S_OK == VarUI1FromDate( 0.0, pByte ), XOK);
1815 ok(*pByte == 0,"0.0 date should give return 0");
1817 ok(S_OK == VarUI1FromDate( 69.33, pByte ), XOK);
1818 ok(*pByte == 0x45,"69.33 date should give return 0x45");
1820 ok(S_OK == VarUI1FromDate( 69.66, pByte ), XOK);
1821 ok(*pByte == 0x46,"69.66 date should give return 0x46");
1823 ok(DISP_E_OVERFLOW == VarUI1FromDate( -69.33, pByte ), XOV);
1825 ok(DISP_E_OVERFLOW == VarUI1FromDate( -69.66, pByte ), XOV);
1827 ok(S_OK == VarUI1FromBool( VARIANT_TRUE, pByte ), XOK);
1828 ok(*pByte == 0xff, "true should be converted to 0xff");
1830 ok(S_OK == VarUI1FromBool( VARIANT_FALSE, pByte ), XOK);
1831 ok(*pByte == 0, "false should be converted to 0");
1833 for (i = 0; i < NB_OLE_STRINGS; i++)
1836 rc=VarUI1FromStr( pOleChar[i], lcid, 0, pByte );
1837 ok(rc == strrets_U1[i].error,
1838 "VarUI1FromStr([%d]=\"%s\") rc=%lx instead of %lx",
1839 i,_pTestStrA[i],rc,strrets_U1[i].error);
1840 if (rc == 0 && strrets_U1[i].error == 0) {
1841 ok(*pByte == strrets_U1[i].retval,
1842 "VarUI1FromStr([%d]=\"%s\") got %02x instead of %02x",
1843 i,_pTestStrA[i],*pByte,strrets_U1[i].retval);
1847 /* unsigned short from ... */
1848 trace( "======== Testing VarUI2FromXXX ========\n");
1850 if (pVarUI2FromI2) {
1851 ok(DISP_E_OVERFLOW == pVarUI2FromI2( -1, pUShort ), XOV);
1852 ok(S_OK == pVarUI2FromI2( 0, NULL ), XOK);
1854 ok(S_OK == pVarUI2FromI2( 0, pUShort ), XOK);
1855 ok(*pUShort == 0,"0 should be 0");
1856 ok(S_OK == pVarUI2FromI2( 69, pUShort ), XOK);
1857 ok(*pUShort == 69,"69 should be 69");
1858 ok(S_OK == pVarUI2FromI2( 70, pUShort ), XOK);
1859 ok(*pUShort == 70,"70 should be 70");
1861 ok(S_OK == pVarUI2FromI2( 128, pUShort ), XOK);
1862 ok(*pUShort == 128,"128 should be 128");
1865 if (pVarUI2FromI4) {
1866 ok(S_OK == pVarUI2FromI4( 65535, pUShort ), XOK);
1867 ok(*pUShort == 65535,"65535 should be 65535");
1868 ok(DISP_E_OVERFLOW == pVarUI2FromI4( 65536, pUShort ), XOV);
1869 ok(DISP_E_OVERFLOW == pVarUI2FromI4( 65537, pUShort ), XOV);
1872 if (pVarUI2FromR8) {
1873 ok(S_OK == pVarUI2FromR8( 0.0, pUShort ), XOK);
1874 ok(*pUShort == 0,"0.0 should be 0");
1875 ok(S_OK == pVarUI2FromR8( 69.33, pUShort ), XOK);
1876 ok(*pUShort == 69,"69.33 should be 69");
1877 ok(S_OK == pVarUI2FromR8( 69.66, pUShort ), XOK);
1878 ok(*pUShort == 70,"69.66 should be 70");
1880 ok(DISP_E_OVERFLOW == pVarUI2FromR8( -69.33, pUShort ), XOV);
1881 ok(DISP_E_OVERFLOW == pVarUI2FromR8( -69.66, pUShort ), XOV);
1883 ok(S_OK == pVarUI2FromR8( -0.5, pUShort ), XOK);
1884 ok(*pUShort == 0, "-0.5 -> 0");
1885 ok(DISP_E_OVERFLOW == pVarUI2FromR8( -0.51, pUShort ), XOV);
1886 ok(S_OK == pVarUI2FromR8( -0.49, pUShort ), XOK);
1887 ok(*pUShort == 0, "-0.49 -> 0");
1889 ok(S_OK == pVarUI2FromR8( 0.5, pUShort ), XOK);
1890 ok(*pUShort == 0,"0.5 should be 0");
1891 ok(S_OK == pVarUI2FromR8( 0.51, pUShort ), XOK);
1892 ok(*pUShort == 1,"0.51 should be 1");
1893 ok(S_OK == pVarUI2FromR8( 0.49, pUShort ), XOK);
1894 ok(*pUShort == 0,"0.49 should be 0");
1897 if (pVarUI2FromDate) {
1898 ok(S_OK == pVarUI2FromDate( 0.0, pUShort ), XOK);
1899 ok(*pUShort == 0,"0.0 should be 0");
1900 ok(S_OK == pVarUI2FromDate( 69.33, pUShort ), XOK);
1901 ok(*pUShort == 69,"69.33 should be 69");
1902 ok(S_OK == pVarUI2FromDate( 69.66, pUShort ), XOK);
1903 ok(*pUShort == 70,"69.66 should be 70");
1904 ok(DISP_E_OVERFLOW == pVarUI2FromDate( -69.33, pUShort ), XOV);
1905 ok(DISP_E_OVERFLOW == pVarUI2FromDate( -69.66, pUShort ), XOV);
1908 if (pVarUI2FromBool) {
1909 ok(S_OK == pVarUI2FromBool( VARIANT_TRUE, pUShort ), XOK);
1910 ok(*pUShort == 65535,"TRUE should be 65535");
1911 ok(S_OK == pVarUI2FromBool( VARIANT_FALSE, pUShort ), XOK);
1912 ok(*pUShort == 0,"FALSE should be 0");
1915 if (pVarUI2FromStr) {
1916 ok(DISP_E_TYPEMISMATCH == pVarUI2FromStr( NULL, lcid, 0, pUShort ), "should return DISP_E_TYPEMISMATCH");
1918 for (i = 0; i < NB_OLE_STRINGS; i++)
1921 rc=pVarUI2FromStr( pOleChar[i], lcid, 0, pUShort );
1922 ok(rc == strrets_U2[i].error,
1923 "VarUI2FromStr([%d]=\"%s\") rc=%lx instead of %lx",
1924 i,_pTestStrA[i],rc,strrets_U2[i].error);
1925 if (rc == 0 && strrets_U2[i].error == 0) {
1926 ok(*pUShort == strrets_U2[i].retval,
1927 "VarUI2FromStr([%d]=\"%s\") got %u instead of %u",
1928 i,_pTestStrA[i],*pUShort,strrets_U2[i].retval);
1933 /* unsigned long from ...
1935 trace( "======== Testing VarUI4FromXXX ========\n");
1937 if (pVarUI4FromI2) {
1938 ok(S_OK == pVarUI4FromI2( 0, NULL ), XOK);
1940 ok(S_OK == pVarUI4FromI2( 0, pULong ), XOK);
1941 ok(*pULong == 0,"0 should be 0");
1942 ok(S_OK == pVarUI4FromI2( 69, pULong ), XOK);
1943 ok(*pULong == 69,"69 should be 69");
1945 ok(S_OK == pVarUI4FromI2( 70, pULong ), XOK);
1946 ok(*pULong == 70,"70 should be 70");
1948 ok(S_OK == pVarUI4FromI2( 128, pULong ), XOK);
1949 ok(*pULong == 128,"128 should be 128");
1950 ok(S_OK == pVarUI4FromI2( 255, pULong ), XOK);
1951 ok(*pULong == 255,"255 should be 255");
1954 if (pVarUI4FromR8) {
1955 ok(S_OK == pVarUI4FromR8( 4294967295.0, pULong ), XOK);
1956 ok(*pULong == 4294967295U,"4294967295.0 should be 4294967295");
1957 ok(DISP_E_OVERFLOW == pVarUI4FromR8( 4294967296.0, pULong ), XOV);
1959 ok(S_OK == pVarUI4FromR8( 0.0, pULong ), XOK);
1960 ok(*pULong == 0,"0 should be 0");
1961 ok(S_OK == pVarUI4FromR8( 69.33, pULong ), XOK);
1962 ok(*pULong == 69,"69.33 should be 69");
1963 ok(S_OK == pVarUI4FromR8( 69.66, pULong ), XOK);
1964 ok(*pULong == 70,"69.66 should be 70");
1965 ok(DISP_E_OVERFLOW == pVarUI4FromR8( -69.33, pULong ), XOV);
1966 ok(DISP_E_OVERFLOW == pVarUI4FromR8( -69.66, pULong ), XOV);
1968 ok(S_OK == pVarUI4FromR8( -0.5, pULong ), XOK);
1969 ok(*pULong == 0,"-0.5 should be 0");
1971 ok(DISP_E_OVERFLOW == pVarUI4FromR8( -0.51, pULong ), XOV);
1973 ok(S_OK == pVarUI4FromR8( -0.49, pULong ), XOK);
1974 ok(*pULong == 0,"-0.49 should be 0");
1976 ok(S_OK == pVarUI4FromR8( 0.5, pULong ), XOK);
1977 ok(*pULong == 0,"0.5 should be 0");
1978 ok(S_OK == pVarUI4FromR8( 0.51, pULong ), XOK);
1979 ok(*pULong == 1,"0.51 should be 1");
1980 ok(S_OK == pVarUI4FromR8( 0.49, pULong ), XOK);
1981 ok(*pULong == 0,"0.49 should be 0");
1984 if (pVarUI4FromDate) {
1985 ok(S_OK == pVarUI4FromDate( 0.0, pULong ), XOK);
1986 ok(*pULong == 0,"0.0 should be 0");
1987 ok(S_OK == pVarUI4FromDate( 69.33, pULong ), XOK);
1988 ok(*pULong == 69,"69.33 should be 69");
1989 ok(S_OK == pVarUI4FromDate( 69.66, pULong ), XOK);
1990 ok(*pULong == 70,"69.66 should be 70");
1991 ok(DISP_E_OVERFLOW == pVarUI4FromDate( -69.33, pULong ), XOV);
1992 ok(DISP_E_OVERFLOW == pVarUI4FromDate( -69.66, pULong ), XOV);
1995 if (pVarUI4FromBool) {
1996 ok(S_OK == pVarUI4FromBool( VARIANT_TRUE, pULong ), XOK);
1997 ok(*pULong == 4294967295U, "TRUE should be 4294967295");
1998 ok(S_OK == pVarUI4FromBool( VARIANT_FALSE, pULong ), XOK);
1999 ok(*pULong == 0, "FALSE should be 0");
2002 if (pVarUI4FromStr) {
2003 ok(DISP_E_TYPEMISMATCH == pVarUI4FromStr( NULL, lcid, 0, pULong ), "should erturn DISP_E_TYPEMISMATCH");
2004 for (i = 0; i < NB_OLE_STRINGS; i++)
2007 rc=pVarUI4FromStr( pOleChar[i], lcid, 0, pULong );
2008 ok(rc == strrets_U4[i].error,
2009 "VarUI4FromStr([%d]=\"%s\") rc=%lx instead of %lx",
2010 i,_pTestStrA[i],rc,strrets_U4[i].error);
2011 if (rc == 0 && strrets_U4[i].error == 0) {
2012 ok(*pULong == strrets_U4[i].retval,
2013 "VarUI4FromStr([%d]=\"%s\") got %lu instead of %lu",
2014 i,_pTestStrA[i],*pULong,strrets_U4[i].retval);
2021 trace( "======== Testing VarI1FromXXX ========\n");
2023 if (pVarI1FromBool) {
2024 ok(S_OK == pVarI1FromBool( VARIANT_TRUE, pByte ), XOK);
2025 ok(*pByte == 0xff,"true should be 0xff");
2027 ok(S_OK == pVarI1FromBool( VARIANT_TRUE, pChar ), XOK);
2028 ok(*pChar == -1, "TRUE should be -1");
2030 ok(S_OK == pVarI1FromBool( VARIANT_FALSE, pChar ), XOK);
2031 ok(*pChar == 0, "FALSE should be 0");
2034 if (pVarI1FromUI1) {
2035 ok(DISP_E_OVERFLOW == pVarI1FromUI1( (unsigned char)32767, pChar ), XOV);
2036 ok(*pChar == 0, "should still be 0");
2037 ok(DISP_E_OVERFLOW == pVarI1FromUI1( (unsigned char)65535, pChar ), XOV);
2038 ok(*pChar == 0, "should still be 0");
2042 ok(DISP_E_OVERFLOW == pVarI1FromI4( 32767, pChar ), XOV);
2043 ok(*pChar == 0, "should still be 0");
2044 ok(DISP_E_OVERFLOW == pVarI1FromI4( 32768, pChar ), XOV);
2045 ok(*pChar == 0, "should still be 0");
2046 ok(DISP_E_OVERFLOW == pVarI1FromI4( -32768, pChar ), XOV);
2047 ok(*pChar == 0, "should still be 0");
2048 ok(DISP_E_OVERFLOW == pVarI1FromI4( -32769, pChar ), XOV);
2049 ok(*pChar == 0, "should still be 0");
2053 ok(S_OK == pVarI1FromR8( 69.33, pChar ), XOK);
2054 ok(*pChar == 69, "69.33 should be 69");
2055 ok(S_OK == pVarI1FromR8( 69.66, pChar ), XOK);
2056 ok(*pChar == 70, "69.66 should be 70");
2058 ok(S_OK == pVarI1FromR8( -69.33, pChar ), XOK);
2059 ok(*pChar == -69, "-69.33 should be -69");
2060 ok(S_OK == pVarI1FromR8( -69.66, pChar ), XOK);
2061 ok(*pChar == -70, "-69.66 should be -70");
2064 if (pVarI1FromDate) {
2065 ok(S_OK == pVarI1FromDate( -69.66, pChar ), XOK);
2066 ok(*pChar == -70, "-69.66 should be -70");
2069 if (pVarI1FromStr) {
2070 for (i = 0; i < NB_OLE_STRINGS; i++)
2073 rc=pVarI1FromStr( pOleChar[i], lcid, 0, pChar );
2074 ok(rc == strrets_I1[i].error,
2075 "VarI1FromStr([%d]=\"%s\") rc=%lx instead of %lx",
2076 i,_pTestStrA[i],rc,strrets_I1[i].error);
2077 if (rc == 0 && strrets_I1[i].error == 0) {
2078 ok(*pChar == strrets_I1[i].retval,
2079 "VarI1FromStr([%d]=\"%s\") got %d instead of %d",
2080 i,_pTestStrA[i],*pChar,strrets_I1[i].retval);
2087 trace( "======== Testing VarI2FromXXX ========\n");
2089 if (pVarI2FromUI2) {
2090 ok(S_OK == pVarI2FromUI2( 32767, pShort ), XOK);
2091 ok(*pShort == 32767, "should be 32767");
2092 ok(DISP_E_OVERFLOW == pVarI2FromUI2( 65535, pShort ), XOV);
2093 ok(*pShort == 32767, "pShort should be unchanged");
2096 ok(S_OK == VarI2FromI4( 32767, pShort ), XOK);
2097 ok(*pShort == 32767, "should be 32767");
2098 ok(DISP_E_OVERFLOW == VarI2FromI4( 32768, pShort ), XOV);
2099 ok(*pShort == 32767, "should still be 32767");
2100 ok(S_OK == VarI2FromI4( -32768, pShort ), XOK);
2101 ok(*pShort == -32768, "should be -32768");
2102 ok(DISP_E_OVERFLOW == VarI2FromI4( -32769, pShort ), XOV);
2103 ok(*pShort == -32768, "should still be -32768");
2105 ok(S_OK == VarI2FromR8( 69.33, pShort ), XOK);
2106 ok(*pShort == 69, "should be 69");
2107 ok(S_OK == VarI2FromR8( 69.66, pShort ), XOK);
2108 ok(*pShort == 70, "should be 70");
2109 ok(S_OK == VarI2FromR8( -69.33, pShort ), XOK);
2110 ok(*pShort == -69, "should be -69");
2111 ok(S_OK == VarI2FromR8( -69.66, pShort ), XOK);
2112 ok(*pShort == -70, "should be -70");
2113 ok(S_OK == VarI2FromDate( -69.66, pShort ), XOK);
2114 ok(*pShort == -70, "should be -70");
2116 for (i = 0; i < NB_OLE_STRINGS; i++)
2119 rc=VarI2FromStr( pOleChar[i], lcid, 0, pShort );
2120 ok(rc == strrets_I2[i].error,
2121 "VarI2FromStr([%d]=\"%s\") rc=%lx instead of %lx",
2122 i,_pTestStrA[i],rc,strrets_I2[i].error);
2123 if (rc == 0 && strrets_I2[i].error == 0) {
2124 ok(*pShort == strrets_I2[i].retval,
2125 "VarI2FromStr([%d]=\"%s\") got %d instead of %d",
2126 i,_pTestStrA[i],*pShort,strrets_I2[i].retval);
2132 trace( "======== Testing VarI4FromXXX ========\n");
2134 ok(S_OK == VarI4FromI2( 3, (long*)pInt ), XOK);
2135 ok(*pInt == 3,"should be 3");
2137 ok(S_OK == VarI4FromR8( 69.33, pLong ), XOK);
2138 ok(*pLong == 69,"should be 69");
2139 ok(S_OK == VarI4FromR8( 69.66, pLong ), XOK);
2140 ok(*pLong == 70,"should be 70");
2141 ok(S_OK == VarI4FromR8( -69.33, pLong ), XOK);
2142 ok(*pLong == -69,"should be -69");
2143 ok(S_OK == VarI4FromR8( -69.66, pLong ), XOK);
2144 ok(*pLong == -70,"should be -70");
2146 ok(S_OK == VarI4FromR8( 2147483647.0, pLong ), XOK);
2147 ok(*pLong == 2147483647,"should be 2147483647");
2148 ok(DISP_E_OVERFLOW == VarI4FromR8( 2147483648.0, pLong ), XOV);
2149 ok(*pLong == 2147483647,"should still be 2147483647");
2151 ok(S_OK == VarI4FromR8( -2147483647.0, pLong ), XOK);
2152 ok(*pLong == -2147483647,"should be -2147483647");
2153 ok(S_OK == VarI4FromR8( -2147483648.0, pLong ), XOK);
2154 ok(*pLong == 0x80000000L,"should be -2147483648");
2155 ok(DISP_E_OVERFLOW == VarI4FromR8( -2147483649.0, pLong ), XOV);
2156 ok(*pLong == 0x80000000L,"should still be -2147483648");
2157 ok(DISP_E_OVERFLOW == VarI4FromDate( -2147483649.0, pLong ), XOV);
2158 ok(*pLong == 0x80000000L,"should still be -2147483648");
2160 for (i = 0; i < NB_OLE_STRINGS; i++)
2163 rc=VarI4FromStr( pOleChar[i], lcid, 0, pLong );
2164 ok(rc == strrets_I4[i].error,
2165 "VarI4FromStr([%d]=\"%s\") rc=%lx instead of %lx",
2166 i,_pTestStrA[i],rc,strrets_I4[i].error);
2167 if (rc == 0 && strrets_I4[i].error == 0) {
2168 ok(*pLong == strrets_I4[i].retval,
2169 "VarI4FromStr([%d]=\"%s\") got %ld instead of %ld",
2170 i,_pTestStrA[i],*pLong,strrets_I4[i].retval);
2176 trace( "======== Testing VarR4FromXXX ========\n");
2178 ok(S_OK == VarR4FromI4( 16777216, pFloat ), XOK);
2179 ok(16777216.0 == *pFloat,"should be 16777216.0");
2181 ok(S_OK == VarR4FromI4( 16777217, pFloat ), XOK);
2182 ok(16777216.0 == *pFloat,"should be 16777216.0");
2183 ok(S_OK == VarR4FromI4( -16777216, pFloat ), XOK);
2184 ok(-16777216.0 == *pFloat,"should be -16777216.0");
2185 ok(S_OK == VarR4FromI4( -16777217, pFloat ), XOK);
2186 ok(-16777216.0 == *pFloat,"should be -16777216.0");
2188 ok(S_OK == VarR4FromR8( 16777216.0, pFloat ), XOK);
2189 ok(16777216.0 == *pFloat,"should be 16777216.0");
2190 ok(S_OK == VarR4FromR8( 16777217.0, pFloat ), XOK);
2191 ok(16777216.0 == *pFloat,"should be 16777216.0");
2192 ok(S_OK == VarR4FromR8( -16777216.0, pFloat ), XOK);
2193 ok(-16777216.0 == *pFloat,"should be -16777216.0");
2194 ok(S_OK == VarR4FromR8( -16777217.0, pFloat ), XOK);
2195 ok(-16777216.0 == *pFloat,"should be -16777216.0");
2197 ok(S_OK == VarR4FromR8( 16777218e31, pFloat ), XOK);
2198 ok(*pFloat == 167772177736353110000000000000000000000.000000,
2199 "should be 167772177736353110000000000000000000000.000000");
2200 ok(DISP_E_OVERFLOW == VarR4FromR8( 16777218e32, pFloat ), XOV);
2201 ok(*pFloat == 167772177736353110000000000000000000000.000000,
2202 "should still be 167772177736353110000000000000000000000.000000");
2203 ok(S_OK == VarR4FromDate( 16777218e31, pFloat ), XOK);
2204 ok(*pFloat == 167772177736353110000000000000000000000.000000,
2205 "should be 167772177736353110000000000000000000000.000000");
2207 for (i = 0; i < NB_OLE_STRINGS; i++)
2210 rc=VarR4FromStr( pOleChar[i], lcid, 0, pFloat );
2211 ok(rc == strrets_R4[i].error,
2212 "VarR4FromStr([%d]=\"%s\") rc=%lx instead of %lx",
2213 i,_pTestStrA[i],rc,strrets_R4[i].error);
2214 if (rc == 0 && strrets_R4[i].error == 0) {
2215 ok(*pFloat == strrets_R4[i].retval,
2216 "VarR4FromStr([%d]=\"%s\") got %f instead of %f",
2217 i,_pTestStrA[i],*pFloat,strrets_R4[i].retval);
2223 trace( "======== Testing VarR8FromXXX ========\n");
2225 ok(S_OK == VarR8FromDate( 900719925474099.0, pDouble ), XOK);
2226 ok(*pDouble == 900719925474099.000000,"should be 900719925474099.000000\n");
2227 for (i = 0; i < NB_OLE_STRINGS; i++)
2230 rc=VarR8FromStr( pOleChar[i], lcid, 0, pDouble );
2231 ok(rc == strrets_R8[i].error,
2232 "VarR8FromStr([%d]=\"%s\") rc=%lx instead of %lx",
2233 i,_pTestStrA[i],rc,strrets_R8[i].error);
2234 if (rc == 0 && strrets_R8[i].error == 0) {
2235 ok(*pDouble == strrets_R8[i].retval,
2236 "VarR8FromStr([%d]=\"%s\") got %.15f instead of %.15f",
2237 i,_pTestStrA[i],*pDouble,strrets_R8[i].retval);
2243 trace( "======== Testing VarDateFromXXX ========\n");
2245 ok(S_OK == VarDateFromI4( 2958465, pDouble ), XOK);
2246 ok(*pDouble == 2958465.000000,"should be 2958465.000000");
2247 rc=VarDateFromI4( 2958466, pDouble );
2248 ok(rc==DISP_E_OVERFLOW || rc==DISP_E_TYPEMISMATCH /* Win95 */,
2250 ok(*pDouble == 2958465.000000,"should still be 2958465.000000");
2251 ok(S_OK == VarDateFromI4( -657434, pDouble ), XOK);
2252 ok(*pDouble == -657434.000000,"should be -657434.000000");
2253 rc=VarDateFromI4( -657435, pDouble );
2254 ok(rc==DISP_E_OVERFLOW || rc==DISP_E_TYPEMISMATCH /* Win95 */,
2256 ok(*pDouble == -657434.000000,"should still be -657434.000000");
2258 ok(S_OK == VarDateFromR8( 2958465.9999, pDouble ), XOK);
2259 ok(*pDouble == 2958465.999900, "should be 2958465.999900");
2260 rc=VarDateFromR8( 2958466, pDouble );
2261 ok(rc==DISP_E_OVERFLOW || rc==DISP_E_TYPEMISMATCH /* Win95 */,
2263 ok(*pDouble == 2958465.999900, "should still be 2958465.999900");
2264 ok(S_OK == VarDateFromR8( -657434.9999, pDouble ), XOK);
2265 ok(*pDouble == -657434.999900,"should be -657434.999900");
2266 rc=VarDateFromR8( -657435, pDouble );
2267 ok(rc==DISP_E_OVERFLOW || rc==DISP_E_TYPEMISMATCH /* Win95 */,
2269 ok(*pDouble == -657434.999900,"should still be -657434.999900");
2271 ok(S_OK == VarDateFromR8( 0.0, pDouble ), XOK);
2272 ok(*pDouble == 0.0,"0.0 should be 0.0");
2273 ok(S_OK == VarDateFromR8( 1.0, pDouble ), XOK);
2274 ok(*pDouble == 1.0,"1.0 should be 1.0");
2275 ok(S_OK == VarDateFromR8( 2.25, pDouble ), XOK);
2276 ok(*pDouble == 2.25,"2.25 should be 2.25");
2277 ok(S_OK == VarDateFromR8( -2.0, pDouble ), XOK);
2278 ok(*pDouble == -2.0,"-2.0 should be -2.0");
2280 /* Need some parsing function in Linux to emulate this...
2283 for (i = 0; i < NB_OLE_STRINGS; i++)
2286 rc=VarDateFromStr( pOleChar[i], lcid, LOCALE_NOUSEROVERRIDE, pDouble );
2287 ok(i == 94 /* FIXME: Bug in native */ || rc == strrets_DATE[i].error,
2288 "VarDateFromStr([%d]=\"%s\") rc= %lx instead of %lx",
2289 i,_pTestStrA[i],rc,strrets_DATE[i].error);
2290 if (rc == 0 && strrets_DATE[i].error == 0) {
2291 ok(EQ_DOUBLE(*pDouble,strrets_DATE[i].retval),
2292 "VarDateFromStr([%d]=\"%s\") got %.15f instead of %.15f",
2293 i,_pTestStrA[i],*pDouble,strrets_DATE[i].retval);
2298 trace( "======== Testing VarBoolFromXXX ========\n");
2300 ok(S_OK == VarBoolFromI4( 0, pBool ), XOK);
2301 ok(VARIANT_FALSE == *pBool, "expected FALSE");
2302 ok(S_OK == VarBoolFromI4( 1, pBool ), XOK);
2303 ok(VARIANT_TRUE == *pBool, "expected TRUE");
2304 ok(S_OK == VarBoolFromI4( -1, pBool ), XOK);
2305 ok(VARIANT_TRUE == *pBool, "expected TRUE");
2306 ok(S_OK == VarBoolFromI4( 2, pBool ), XOK);
2307 ok(VARIANT_TRUE == *pBool, "expected TRUE");
2309 ok(S_OK == VarBoolFromUI1( ' ', pBool ), XOK);
2310 ok(VARIANT_TRUE == *pBool, "expected TRUE");
2311 ok(S_OK == VarBoolFromUI1( '\0', pBool ), XOK);
2312 ok(VARIANT_FALSE == *pBool, "expected FALSE");
2313 ok(S_OK == VarBoolFromUI1( 0x0000, pBool ), XOK);
2314 ok(VARIANT_FALSE == *pBool, "expected FALSE");
2315 ok(S_OK == VarBoolFromUI1( (unsigned char)0xFFF, pBool ), XOK);
2316 ok(VARIANT_TRUE == *pBool, "expected TRUE");
2317 ok(S_OK == VarBoolFromUI1( (unsigned char)0xFFFF, pBool ), XOK);
2318 ok(VARIANT_TRUE == *pBool, "expected TRUE");
2320 ok(S_OK == VarBoolFromR8( 0.0, pBool ), XOK);
2321 ok(VARIANT_FALSE == *pBool, "expected FALSE");
2322 ok(S_OK == VarBoolFromR8( 1.1, pBool ), XOK);
2323 ok(VARIANT_TRUE == *pBool, "expected TRUE");
2324 ok(S_OK == VarBoolFromR8( 0.5, pBool ), XOK);
2325 ok(VARIANT_TRUE == *pBool, "expected TRUE");
2326 ok(S_OK == VarBoolFromR8( 0.49, pBool ), XOK);
2327 ok(VARIANT_TRUE == *pBool, "expected TRUE");
2328 ok(S_OK == VarBoolFromR8( 0.51, pBool ), XOK);
2329 ok(VARIANT_TRUE == *pBool, "expected TRUE");
2330 ok(S_OK == VarBoolFromR8( -0.5, pBool ), XOK);
2331 ok(VARIANT_TRUE == *pBool, "expected TRUE");
2332 ok(S_OK == VarBoolFromR8( -0.49, pBool ), XOK);
2333 ok(VARIANT_TRUE == *pBool, "expected TRUE");
2334 ok(S_OK == VarBoolFromR8( -0.51, pBool ), XOK);
2335 ok(VARIANT_TRUE == *pBool, "expected TRUE");
2338 for (i = 0; i < NB_OLE_STRINGS; i++)
2341 rc=VarBoolFromStr( pOleChar[i], lcid, 0, pBool );
2342 ok(rc == strrets_B[i].error,
2343 "VarBoolFromStr([%d]=\"%s\") rc=%lx instead of %lx",
2344 i,_pTestStrA[i],rc,strrets_B[i].error);
2345 if (rc == 0 && strrets_B[i].error == 0) {
2346 ok(*pBool == strrets_B[i].retval,
2347 "VarBoolFromStr([%d]=\"%s\") got %x instead of %x",
2348 i,_pTestStrA[i],*pBool,strrets_B[i].retval);
2354 trace( "======== Testing VarBSTRFromXXX ========\n");
2358 if (pVarBstrFromI1) {
2359 ok(S_OK == pVarBstrFromI1( -100, 0, 0, &bstr ), XOK);
2360 ok(!strcmp(WtoA(bstr),"\"-100\""),"should be string -100");
2363 ok(S_OK == VarBstrFromUI1( 0x5A, 0, 0, &bstr ), XOK);
2364 ok(!strcmp(WtoA(bstr),"\"90\""),"should be string 90");
2365 ok(S_OK == VarBstrFromI4( 2958465, 0, 0, &bstr ), XOK);
2366 ok(!strcmp(WtoA(bstr),"\"2958465\""),"should be string 2958465");
2372 for( i=0; i<20; i++ )
2375 /* add an integer to the real number
2377 d += ((i%9)+1) * pow( 10, i );
2379 ok(S_OK == VarBstrFromR8( d, lcid, 0, &bstr ), XOK);
2380 sprintf(xval,"\"%s\"",strfromr8[off]);
2381 ok(!strcmp(xval,WtoA(bstr)),
2382 "d is %.15f, should be cvt. to %s, but return val is %s",
2383 d,strfromr8[off],WtoA(bstr));
2386 ok(S_OK == VarBstrFromR8( -d, lcid, 0, &bstr ), XOK);
2387 sprintf(xval,"\"%s\"",strfromr8[off]);
2388 ok(!strcmp(xval,WtoA(bstr)),
2389 "d is %.15f, should be cvt. to %s, but return val is %s",
2390 -d,strfromr8[off],WtoA(bstr));
2394 for( i=0; i<20; i++ )
2397 /* add a decimal to the real number
2399 d += ((i%9)+1) * pow( 10, (i*-1) );
2400 ok(S_OK == VarBstrFromR8( d, lcid, 0, &bstr ), XOK);
2401 sprintf(xval,"\"%s\"",strfromr8[off]);
2402 ok(!strcmp(xval,WtoA(bstr)),
2403 "d is %.15f, should be cvt. to %s, but return val is %s",
2404 d,strfromr8[off],WtoA(bstr));
2406 ok(S_OK == VarBstrFromR8( d-1, lcid, 0, &bstr ), XOK);
2407 sprintf(xval,"\"%s\"",strfromr8[off]);
2408 ok(!strcmp(xval,WtoA(bstr)),
2409 "d is %.15f, should be cvt. to %s, but return val is %s",
2410 d-1,strfromr8[off],WtoA(bstr));
2412 ok(S_OK == VarBstrFromR8( -d, lcid, 0, &bstr ), XOK);
2413 sprintf(xval,"\"%s\"",strfromr8[off]);
2414 ok(!strcmp(xval,WtoA(bstr)),
2415 "d is %.15f, should be cvt. to %s, but return val is %s",
2416 -d,strfromr8[off],WtoA(bstr));
2421 for( i=0; i<20; 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 == VarBstrFromR8( d, lcid, 0, &bstr ), XOK);
2431 sprintf(xval,"\"%s\"",strfromr8[off]);
2432 ok(!strcmp(xval,WtoA(bstr)),
2433 "d is %.15f, should be cvt. to %s, but return val is %s",
2434 d,strfromr8[off],WtoA(bstr));
2436 ok(S_OK == VarBstrFromR8( -d, lcid, 0, &bstr ), XOK);
2437 sprintf(xval,"\"%s\"",strfromr8[off]);
2438 ok(!strcmp(xval,WtoA(bstr)),
2439 "d is %.15f, should be cvt. to %s, but return val is %s",
2440 -d,strfromr8[off],WtoA(bstr));
2445 for( i=0; i<10; i++ )
2448 /* add an integer to the real number
2450 d += ((i%9)+1) * pow( 10, i );
2451 ok(S_OK == VarBstrFromR4( (float)d, lcid, 0, &bstr ), XOK);
2452 sprintf(xval,"\"%s\"",strfromr8[off]);
2453 ok(!strcmp(xval,WtoA(bstr)),
2454 "%d: d is %.8f, should be cvt. to %s, but return val is %s",
2455 i,d,strfromr8[off],WtoA(bstr));
2457 ok(S_OK == VarBstrFromR4( (float)-d, lcid, 0, &bstr ), XOK);
2458 sprintf(xval,"\"%s\"",strfromr8[off]);
2459 ok(!strcmp(xval,WtoA(bstr)),
2460 "%d: d is %.8f, should be cvt. to %s, but return val is %s",
2461 i,-d,strfromr8[off],WtoA(bstr));
2465 for( i=0; i<10; i++ )
2468 /* add a decimal to the real number
2470 d += ((i%9)+1) * pow( 10, (i*-1) );
2471 ok(S_OK == VarBstrFromR4( (float)d, lcid, 0, &bstr ), XOK);
2472 sprintf(xval,"\"%s\"",strfromr8[off]);
2473 ok(!strcmp(xval,WtoA(bstr)),
2474 "%d: d is %.8f, should be cvt. to %s, but return val is %s",
2475 i,d,strfromr8[off],WtoA(bstr));
2477 ok(S_OK == VarBstrFromR4( (float)(d-1), lcid, 0, &bstr ), XOK);
2478 sprintf(xval,"\"%s\"",strfromr8[off]);
2479 ok(!strcmp(xval,WtoA(bstr)),
2480 "%d: d is %.8f, should be cvt. to %s, but return val is %s",
2481 i,d-1,strfromr8[off],WtoA(bstr));
2483 ok(S_OK == VarBstrFromR4( (float)-d, lcid, 0, &bstr ), XOK);
2484 sprintf(xval,"\"%s\"",strfromr8[off]);
2485 ok(!strcmp(xval,WtoA(bstr)),
2486 "%d: d is %.8f, should be cvt. to %s, but return val is %s",
2487 i,-d,strfromr8[off],WtoA(bstr));
2492 for( i=0; i<10; i++ )
2494 static int istodo[10]={0,0,0,0,0,1,0,0,0,0};
2496 /* add an integer to the real number
2498 d += ((i%9)+1) * pow( 10, i );
2499 /* add a decimal to the real number
2501 d += ((i%9)+1) * pow( 10, (i*-1) );
2502 ok(S_OK == VarBstrFromR4( (float)d, lcid, 0, &bstr ), XOK);
2503 sprintf(xval,"\"%s\"",strfromr8[off]);
2506 ok(!strcmp(xval,WtoA(bstr)),
2507 "%d: d is %.8f, should be cvt. to %s, but return val is %s",
2508 i,d,strfromr8[off],WtoA(bstr));
2511 ok(!strcmp(xval,WtoA(bstr)),
2512 "%d: d is %.8f, should be cvt. to %s, but return val is %s",
2513 i,d,strfromr8[off],WtoA(bstr));
2516 ok(S_OK == VarBstrFromR4( (float)-d, lcid, 0, &bstr ), XOK);
2517 sprintf(xval,"\"%s\"",strfromr8[off]);
2520 ok(!strcmp(xval,WtoA(bstr)),
2521 "%d: d is %.8f, should be cvt. to %s, but return val is %s",
2522 i,-d,strfromr8[off],WtoA(bstr));
2525 ok(!strcmp(xval,WtoA(bstr)),
2526 "%d: d is %.8f, should be cvt. to %s, but return val is %s",
2527 i,-d,strfromr8[off],WtoA(bstr));
2532 ok(S_OK == VarBstrFromBool( 0x00, lcid, 0, &bstr ), XOK);
2533 ok(!strcmp(WtoA(bstr),"\"False\""),"should be 'False'");
2534 ok(S_OK == VarBstrFromBool( 0xFF, lcid, 0, &bstr ), XOK);
2535 ok(!strcmp(WtoA(bstr),"\"True\""),"should be 'True'");
2537 ok(S_OK == VarBstrFromDate( 0.0, lcid, LOCALE_NOUSEROVERRIDE, &bstr ), XOK);
2538 ok(!strcmp(WtoA(bstr),"\"12:00:00 AM\""),
2539 "should be '12:00:00 AM', but is %s\n",WtoA(bstr));
2541 ok(S_OK == VarBstrFromDate( 3.34, lcid, LOCALE_NOUSEROVERRIDE, &bstr ), XOK);
2542 ok(strcmp(WtoA(bstr),"\"1/2/1900 8:09:36 AM\"")==0 ||
2543 strcmp(WtoA(bstr),"\"1/2/00 8:09:36 AM\"")==0 /* Win95 */,
2544 "should be '1/2/1900 8:09:36 AM', but is %s\n",WtoA(bstr));
2546 ok(S_OK == VarBstrFromDate( 3339.34, lcid, LOCALE_NOUSEROVERRIDE, &bstr ), XOK);
2547 ok(strcmp(WtoA(bstr),"\"2/20/1909 8:09:36 AM\"")==0 ||
2548 strcmp(WtoA(bstr),"\"2/20/09 8:09:36 AM\"")==0 /* Win95 */,
2549 "should be '2/20/1909 8:09:36 AM', but is %s\n",WtoA(bstr));
2551 ok(S_OK == VarBstrFromDate( 365.00, lcid, LOCALE_NOUSEROVERRIDE, &bstr ), XOK);
2552 ok(strcmp(WtoA(bstr),"\"12/30/1900\"")==0 ||
2553 strcmp(WtoA(bstr),"\"12/30/00\"")==0 /* Win95 */,
2554 "should be '12/30/1900', but is %s\n",WtoA(bstr));
2556 ok(S_OK == VarBstrFromDate( 365.25, lcid, LOCALE_NOUSEROVERRIDE, &bstr ), XOK);
2557 ok(strcmp(WtoA(bstr),"\"12/30/1900 6:00:00 AM\"")==0 ||
2558 strcmp(WtoA(bstr),"\"12/30/00 6:00:00 AM\"")==0 /* Win95 */,
2559 "should be '12/30/1900 6:00:00 AM', but is %s\n",WtoA(bstr));
2561 ok(S_OK == VarBstrFromDate( 1461.0, lcid, LOCALE_NOUSEROVERRIDE, &bstr ), XOK);
2562 ok(strcmp(WtoA(bstr),"\"12/31/1903\"")==0 ||
2563 strcmp(WtoA(bstr),"\"12/31/03\"")==0 /* Win95 */,
2564 "should be '12/31/1903', but is %s\n",WtoA(bstr));
2566 ok(S_OK == VarBstrFromDate( 1461.5, lcid, LOCALE_NOUSEROVERRIDE, &bstr ), XOK);
2567 ok(strcmp(WtoA(bstr),"\"12/31/1903 12:00:00 PM\"")==0 ||
2568 strcmp(WtoA(bstr),"\"12/31/03 12:00:00 PM\"")==0 /* Win95 */,
2569 "should be '12/31/1903 12:00:00 PM', but is %s\n",WtoA(bstr));
2571 /* Test variant API...
2573 trace( "======== Testing Hi-Level Variant API ========\n");
2575 bstr = SysAllocString( pOleChar[4] );
2577 VariantClear( &va );
2585 V_VT(&va) = VT_BSTR;
2586 V_UNION(&va,bstrVal) = bstr;
2587 ok(S_OK == VariantClear( &va ), XOK);
2588 SysFreeString( bstr );
2589 SysFreeString( bstr );
2591 ok(S_OK == VariantCopy( &vb, &va ), XOK);
2592 ok(S_OK == VariantClear( &vb ), XOK);
2593 ok(S_OK == VariantClear( &va ), XOK);
2597 V_UNION(&va,dblVal) = d;
2598 ok(S_OK == VariantCopy( &va, &va ), XOK);
2599 ok(V_R8(&va) == 4.123,"should be 4.123");
2601 V_VT(&va) = VT_R8 | VT_BYREF;
2603 V_UNION(&va,pdblVal) = &d;
2604 ok(S_OK == VariantCopyInd( &va, &va ), XOK);
2605 ok(V_R8(&va) == 31.123,"should be 31.123");
2609 V_UNION(&va,dblVal) = d;
2610 ok(S_OK == VariantCopy( &vb, &va ), XOK);
2611 ok(V_R8(&vb) == 1.123,"should be 1.123");
2613 V_VT(&va) = VT_R8 | VT_BYREF;
2615 V_UNION(&va,pdblVal) = &d;
2616 ok(S_OK == VariantCopy( &vb, &va ), XOK);
2617 ok(*(V_R8REF(&vb)) == 123.123,"should be 123.123");
2619 V_VT(&va) = VT_R8 | VT_BYREF;
2621 V_UNION(&va,pdblVal) = &d;
2622 ok(S_OK == VariantCopyInd( &vb, &va ), XOK);
2623 ok(V_R8(&vb) == 111.2,"should be 111.2");
2625 V_VT(&va) = VT_R8 | VT_BYREF;
2627 V_UNION(&va,pdblVal) = &d;
2628 ok(S_OK == VariantChangeTypeEx( &va, &va, lcid, 0, VT_I2 ), XOK);
2629 ok(V_VT(&va) == VT_I2,"should be type VT_I2");
2632 V_UNION(&va,intVal) = 4;
2633 ok(S_OK == VariantChangeTypeEx(&vb, &va, lcid, 0, VT_BSTR ), XOK);
2634 ok(!strcmp(WtoA(V_BSTR(&vb)),"\"4\""),"should be 4");
2636 V_VT(&va) = VT_DATE;
2637 V_UNION(&va,date) = 34465.332431;
2638 ok(S_OK == VariantChangeTypeEx(&vb, &va, lcid, VARIANT_NOUSEROVERRIDE, VT_BSTR ), XOK);
2639 ok(strcmp(WtoA(V_BSTR(&vb)),"\"5/11/1994 7:58:42 AM\"")==0 ||
2640 strcmp(WtoA(V_BSTR(&vb)),"\"5/11/94 7:58:42 AM\"")==0 /* Win95 */,
2641 "should be 5/11/94 7:58:42 AM got %s",WtoA(V_BSTR(&vb)));
2644 V_VT(&va) = VT_BSTR;
2645 V_UNION(&va,bstrVal) = bstr;
2646 ok(S_OK == VariantChangeTypeEx(&vb, &va, lcid, 0, VT_R8 ), XOK);
2647 ok(V_R8(&vb) == -0.490000,"should be -0.49");
2649 V_VT(&vc) = VT_BSTR | VT_BYREF;
2650 V_UNION(&vc,pbstrVal) = &bstr;
2651 V_VT(&vb) = VT_VARIANT | VT_BYREF;
2652 V_UNION(&vb,pvarVal) = &vc;
2653 V_VT(&va) = VT_VARIANT | VT_BYREF;
2654 V_UNION(&va,pvarVal) = &vb;
2655 ok(E_INVALIDARG == VariantCopyInd( &vd, &va ), "expect E_INVALIDARG");
2657 /* test what happens when bad vartypes are passed in */
2658 trace( "======== Testing different VARTYPES ========\n" );
2660 for( i=0; i<sizeof(vartypes)/sizeof(vartypes[0]); i++ )
2662 /* Trying to use variants that are set to be BSTR but
2663 * do not contain a valid pointer makes the program crash
2664 * in Windows so we will skip those. We do not need them
2665 * anyway to illustrate the behavior.
2667 V_VT(&va) = vartypes[i].ind;
2669 V_UNION(&va,dblVal) = d;
2670 rc = VariantCopyInd( &vb, &va );
2671 if (vartypes[i].todoind1) {
2673 ok(vartypes[i].vcind1 == rc,
2674 "%d: vt %d, return value %lx, expected was %lx",
2675 i,vartypes[i].ind,rc,vartypes[i].vcind1);
2678 ok(vartypes[i].vcind1 == rc,
2679 "%d: vt %d, return value %lx, expected was %lx",
2680 i,vartypes[i].ind,rc,vartypes[i].vcind1);
2682 V_VT(&va) = vartypes[i].ind | VT_BYREF;
2684 V_UNION(&va,pdblVal) = &d;
2685 rc = VariantCopyInd( &vb, &va );
2686 ok(vartypes[i].vcind2 == rc,
2687 "%d: vt %d, return value %lx, expected was %lx",
2688 i,vartypes[i].ind,rc,vartypes[i].vcind2);
2691 V_UNION(&va,dblVal) = d;
2692 rc = VariantChangeTypeEx( &vb, &va, lcid, 0, (VARTYPE)i );
2693 if (vartypes[i].todowcex1) {
2695 ok(vartypes[i].vcex1 == rc || rc == DISP_E_BADVARTYPE,
2696 "%d: vt %d, return value %lx, expected was %lx",
2697 i,vartypes[i].ind,rc,vartypes[i].vcex1);
2700 ok(vartypes[i].vcex1 == rc || rc == DISP_E_BADVARTYPE,
2701 "%d: vt %d, return value %lx, expected was %lx",
2702 i,vartypes[i].ind,rc,vartypes[i].vcex1);
2706 V_UNION(&va,dblVal) = d;
2707 rc = VariantChangeTypeEx( &vb, &va, lcid, 0, (VARTYPE)(i | VT_BYREF) );
2708 if (vartypes[i].todowcex2) {
2710 ok(vartypes[i].vcex2 == rc || rc == DISP_E_BADVARTYPE,
2711 "%d: vt %d, return value %lx, expected was %lx",
2712 i,vartypes[i].ind,rc,vartypes[i].vcex2);
2715 ok(vartypes[i].vcex2 == rc || rc == DISP_E_BADVARTYPE,
2716 "%d: vt %d, return value %lx, expected was %lx",
2717 i,vartypes[i].ind,rc,vartypes[i].vcex2);
2722 V_UNION(&va,dblVal) = d;
2723 ok(DISP_E_BADVARTYPE == VariantClear( &va ), "should give DISP_E_BADVARTYPE");
2725 VariantClear( &va );
2726 VariantClear( &vb );
2727 VariantClear( &vc );
2728 VariantClear( &vd );
2729 VariantClear( &ve );
2730 /* There is alot of memory leaks but this is simply a test program.
2734 static void test_VariantInit(void)
2738 /* Test that VariantInit() only sets the type */
2739 memset(&v1, -1, sizeof(v1));
2741 V_VT(&v2) = VT_EMPTY;
2743 ok(!memcmp(&v1, &v2, sizeof(v1)), "VariantInit() set extra fields\n");
2746 /* All possible combinations of extra V_VT() flags */
2747 static const VARTYPE ExtraFlags[16] =
2756 VT_VECTOR|VT_RESERVED,
2757 VT_VECTOR|VT_ARRAY|VT_BYREF,
2758 VT_VECTOR|VT_ARRAY|VT_RESERVED,
2759 VT_VECTOR|VT_BYREF|VT_RESERVED,
2760 VT_VECTOR|VT_ARRAY|VT_BYREF|VT_RESERVED,
2762 VT_ARRAY|VT_RESERVED,
2763 VT_ARRAY|VT_BYREF|VT_RESERVED,
2764 VT_BYREF|VT_RESERVED,
2767 /* Determine if a vt is valid for VariantClear() */
2768 static int IsValidVariantClearVT(VARTYPE vt, VARTYPE extraFlags)
2772 /* Only the following flags/types are valid */
2773 if ((vt <= VT_LPWSTR || vt == VT_RECORD || vt == VT_CLSID) &&
2774 vt != (VARTYPE)15 &&
2775 (vt < (VARTYPE)24 || vt > (VARTYPE)31) &&
2776 (!(extraFlags & (VT_BYREF|VT_ARRAY)) || vt > VT_NULL) &&
2777 (extraFlags == 0 || extraFlags == VT_BYREF || extraFlags == VT_ARRAY ||
2778 extraFlags == (VT_ARRAY|VT_BYREF)))
2781 if ((vt == VT_RECORD && !HAVE_OLEAUT32_RECORD) ||
2782 ((vt == VT_I8 || vt == VT_UI8) && !HAVE_OLEAUT32_I8))
2783 ret = 0; /* Old versions of oleaut32 */
2787 static void test_VariantClear(void)
2794 /* Crashes: Native does not test input for NULL, so neither does Wine */
2795 hres = VariantClear(NULL);
2798 /* Only the type field is set, to VT_EMPTY */
2801 hres = VariantClear(&v);
2802 ok(hres == S_OK && V_VT(&v) == VT_EMPTY, "VariantClear: Type set to %d\n", V_VT(&v));
2803 ok(V_UI4(&v) == ~0u, "VariantClear: Overwrote value\n");
2805 /* Test all possible V_VT values.
2806 * Also demonstrates that null pointers in 'v' are not dereferenced.
2807 * Individual variant tests should test VariantClear() with non-NULL values.
2809 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2813 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
2815 HRESULT hExpected = DISP_E_BADVARTYPE;
2817 memset(&v, 0, sizeof(v));
2818 V_VT(&v) = vt | ExtraFlags[i];
2820 hres = VariantClear(&v);
2822 if (IsValidVariantClearVT(vt, ExtraFlags[i]))
2825 ok(hres == hExpected, "VariantClear: expected 0x%lX, got 0x%lX for vt %d | 0x%X\n",
2826 hExpected, hres, vt, ExtraFlags[i]);
2831 static void test_VariantCopy(void)
2833 VARIANTARG vSrc, vDst;
2836 HRESULT hres, hExpected;
2838 /* Establish that the failure/other cases are dealt with. Individual tests
2839 * for each type should verify that data is copied correctly, references
2844 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2846 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
2848 memset(&vSrc, 0, sizeof(vSrc));
2849 V_VT(&vSrc) = vt | ExtraFlags[i];
2851 hExpected = DISP_E_BADVARTYPE;
2852 /* src is allowed to be a VT_CLSID */
2853 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
2856 hres = VariantCopy(&vSrc, &vSrc);
2858 ok(hres == hExpected,
2859 "Copy(src==dst): expected 0x%lX, got 0x%lX for src==dest vt %d|0x%X\n",
2860 hExpected, hres, vt, ExtraFlags[i]);
2864 /* Test that if VariantClear() fails on dest, the function fails. This also
2865 * shows that dest is in fact cleared and not just overwritten
2867 memset(&vSrc, 0, sizeof(vSrc));
2868 V_VT(&vSrc) = VT_UI1;
2870 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2872 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
2874 hExpected = DISP_E_BADVARTYPE;
2876 memset(&vDst, 0, sizeof(vDst));
2877 V_VT(&vDst) = vt | ExtraFlags[i];
2879 if (IsValidVariantClearVT(vt, ExtraFlags[i]))
2882 hres = VariantCopy(&vDst, &vSrc);
2884 ok(hres == hExpected,
2885 "Copy(bad dst): expected 0x%lX, got 0x%lX for dest vt %d|0x%X\n",
2886 hExpected, hres, vt, ExtraFlags[i]);
2888 ok(V_VT(&vDst) == VT_UI1,
2889 "Copy(bad dst): expected vt = VT_UI1, got %d\n", V_VT(&vDst));
2893 /* Test that VariantClear() checks vSrc for validity before copying */
2894 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2896 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
2898 hExpected = DISP_E_BADVARTYPE;
2900 memset(&vDst, 0, sizeof(vDst));
2901 V_VT(&vDst) = VT_EMPTY;
2903 memset(&vSrc, 0, sizeof(vSrc));
2904 V_VT(&vSrc) = vt | ExtraFlags[i];
2906 /* src is allowed to be a VT_CLSID */
2907 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
2910 hres = VariantCopy(&vDst, &vSrc);
2912 ok(hres == hExpected,
2913 "Copy(bad src): expected 0x%lX, got 0x%lX for src vt %d|0x%X\n",
2914 hExpected, hres, vt, ExtraFlags[i]);
2916 ok(V_VT(&vDst) == (vt|ExtraFlags[i]),
2917 "Copy(bad src): expected vt = %d, got %d\n",
2918 vt | ExtraFlags[i], V_VT(&vDst));
2923 /* Determine if a vt is valid for VariantCopyInd() */
2924 static int IsValidVariantCopyIndVT(VARTYPE vt, VARTYPE extraFlags)
2928 if ((extraFlags & VT_ARRAY) ||
2929 (vt > VT_NULL && vt != (VARTYPE)15 && vt < VT_VOID &&
2930 !(extraFlags & (VT_VECTOR|VT_RESERVED))))
2937 static void test_VariantCopyInd(void)
2939 VARIANTARG vSrc, vDst, vRef, vRef2;
2943 HRESULT hres, hExpected;
2945 memset(buffer, 0, sizeof(buffer));
2948 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2950 if (ExtraFlags[i] & VT_ARRAY)
2951 continue; /* Native crashes on NULL safearray */
2953 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
2955 memset(&vSrc, 0, sizeof(vSrc));
2956 V_VT(&vSrc) = vt | ExtraFlags[i];
2958 hExpected = DISP_E_BADVARTYPE;
2959 if (!(ExtraFlags[i] & VT_BYREF))
2961 /* if src is not by-reference, acts as VariantCopy() */
2962 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
2967 if (vt == VT_SAFEARRAY || vt == VT_BSTR || vt == VT_UNKNOWN ||
2968 vt == VT_DISPATCH || vt == VT_RECORD)
2969 continue; /* Need valid ptrs for deep copies */
2971 V_BYREF(&vSrc) = &buffer;
2972 hExpected = E_INVALIDARG;
2974 if ((vt == VT_I8 || vt == VT_UI8) &&
2975 ExtraFlags[i] == VT_BYREF)
2977 if (HAVE_OLEAUT32_I8)
2978 hExpected = S_OK; /* Only valid if I8 is a known type */
2980 else if (IsValidVariantCopyIndVT(vt, ExtraFlags[i]))
2984 hres = VariantCopyInd(&vSrc, &vSrc);
2986 ok(hres == hExpected,
2987 "CopyInd(src==dst): expected 0x%lX, got 0x%lX for src==dst vt %d|0x%X\n",
2988 hExpected, hres, vt, ExtraFlags[i]);
2993 memset(&vSrc, 0, sizeof(vSrc));
2994 V_VT(&vSrc) = VT_UI1|VT_BYREF;
2995 V_BYREF(&vSrc) = &buffer;
2997 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2999 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
3001 memset(&vDst, 0, sizeof(vDst));
3002 V_VT(&vDst) = vt | ExtraFlags[i];
3004 hExpected = DISP_E_BADVARTYPE;
3006 if (IsValidVariantClearVT(vt, ExtraFlags[i]))
3009 hres = VariantCopyInd(&vDst, &vSrc);
3011 ok(hres == hExpected,
3012 "CopyInd(bad dst): expected 0x%lX, got 0x%lX for dst vt %d|0x%X\n",
3013 hExpected, hres, vt, ExtraFlags[i]);
3015 ok(V_VT(&vDst) == VT_UI1,
3016 "CopyInd(bad dst): expected vt = VT_UI1, got %d\n", V_VT(&vDst));
3021 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
3023 if (ExtraFlags[i] & VT_ARRAY)
3024 continue; /* Native crashes on NULL safearray */
3026 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
3028 memset(&vDst, 0, sizeof(vDst));
3029 V_VT(&vDst) = VT_EMPTY;
3031 memset(&vSrc, 0, sizeof(vSrc));
3032 V_VT(&vSrc) = vt | ExtraFlags[i];
3034 hExpected = DISP_E_BADVARTYPE;
3035 if (!(ExtraFlags[i] & VT_BYREF))
3037 /* if src is not by-reference, acts as VariantCopy() */
3038 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
3043 if (vt == VT_SAFEARRAY || vt == VT_BSTR || vt == VT_UNKNOWN ||
3044 vt == VT_DISPATCH || vt == VT_RECORD)
3045 continue; /* Need valid ptrs for deep copies, see vartype.c */
3047 V_BYREF(&vSrc) = &buffer;
3049 hExpected = E_INVALIDARG;
3051 if ((vt == VT_I8 || vt == VT_UI8) &&
3052 ExtraFlags[i] == VT_BYREF)
3054 if (HAVE_OLEAUT32_I8)
3055 hExpected = S_OK; /* Only valid if I8 is a known type */
3057 else if (IsValidVariantCopyIndVT(vt, ExtraFlags[i]))
3061 hres = VariantCopyInd(&vDst, &vSrc);
3063 ok(hres == hExpected,
3064 "CopyInd(bad src): expected 0x%lX, got 0x%lX for src vt %d|0x%X\n",
3065 hExpected, hres, vt, ExtraFlags[i]);
3068 if (vt == VT_VARIANT && ExtraFlags[i] == VT_BYREF)
3070 /* Type of vDst should be the type of the referenced variant.
3071 * Since we set the buffer to all zeros, its type should be
3074 ok(V_VT(&vDst) == VT_EMPTY,
3075 "CopyInd(bad src): expected dst vt = VT_EMPTY, got %d|0x%X\n",
3076 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK);
3080 ok(V_VT(&vDst) == (vt|(ExtraFlags[i] & ~VT_BYREF)),
3081 "CopyInd(bad src): expected dst vt = %d|0x%X, got %d|0x%X\n",
3082 vt, ExtraFlags[i] & ~VT_BYREF,
3083 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK);
3089 /* By-reference variants are dereferenced */
3090 V_VT(&vRef) = VT_UI1;
3091 V_UI1(&vRef) = 0x77;
3092 V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
3093 V_VARIANTREF(&vSrc) = &vRef;
3096 hres = VariantCopyInd(&vDst, &vSrc);
3097 ok(V_VT(&vDst) == VT_UI1 && V_UI1(&vDst) == 0x77,
3098 "CopyInd(deref): expected dst vt = VT_UI1, val 0x77, got %d|0x%X, 0x%2X\n",
3099 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK, V_UI1(&vDst));
3101 /* By-reference variant to a by-reference type succeeds */
3102 V_VT(&vRef) = VT_UI1|VT_BYREF;
3103 V_UI1REF(&vRef) = buffer; buffer[0] = 0x88;
3104 V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
3105 V_VARIANTREF(&vSrc) = &vRef;
3108 hres = VariantCopyInd(&vDst, &vSrc);
3109 ok(V_VT(&vDst) == VT_UI1 && V_UI1(&vDst) == 0x88,
3110 "CopyInd(deref): expected dst vt = VT_UI1, val 0x77, got %d|0x%X, 0x%2X\n",
3111 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK, V_UI1(&vDst));
3113 /* But a by-reference variant to a by-reference variant fails */
3114 V_VT(&vRef2) = VT_UI1;
3115 V_UI1(&vRef2) = 0x77;
3116 V_VT(&vRef) = VT_VARIANT|VT_BYREF;
3117 V_VARIANTREF(&vRef) = &vRef2;
3118 V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
3119 V_VARIANTREF(&vSrc) = &vRef;
3122 hres = VariantCopyInd(&vDst, &vSrc);
3123 ok(hres == E_INVALIDARG,
3124 "CopyInd(ref->ref): expected E_INVALIDARG, got 0x%08lx\n", hres);
3127 /* Macros for converting and testing the result of VarParseNumFromStr */
3129 #define CONVERTN(str,dig,flags) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)); \
3130 memset(rgb, FAILDIG, sizeof(rgb)); memset(&np,-1,sizeof(np)); np.cDig = dig; np.dwInFlags = flags; \
3131 hres = VarParseNumFromStr(buff,lcid,LOCALE_NOUSEROVERRIDE,&np,rgb)
3132 #define CONVERT(str,flags) CONVERTN(str,sizeof(rgb),flags)
3133 #define EXPECT(a,b,c,d,e,f) ok(hres == (HRESULT)S_OK, "Call failed, hres = %08lx\n", hres); \
3134 if (hres == (HRESULT)S_OK) { \
3135 ok(np.cDig == (a), "Expected cDig = %d, got %d\n", (a), np.cDig); \
3136 ok(np.dwInFlags == (b), "Expected dwInFlags = 0x%lx, got 0x%lx\n", (ULONG)(b), np.dwInFlags); \
3137 ok(np.dwOutFlags == (c), "Expected dwOutFlags = 0x%lx, got 0x%lx\n", (ULONG)(c), np.dwOutFlags); \
3138 ok(np.cchUsed == (d), "Expected cchUsed = %d, got %d\n", (d), np.cchUsed); \
3139 ok(np.nBaseShift == (e), "Expected nBaseShift = %d, got %d\n", (e), np.nBaseShift); \
3140 ok(np.nPwr10 == (f), "Expected nPwr10 = %d, got %d\n", (f), np.nPwr10); \
3142 #define EXPECTRGB(a,b) ok(rgb[a] == b, "Digit[%d], expected %d, got %d\n", a, b, rgb[a])
3143 #define EXPECTFAIL ok(hres == (HRESULT)DISP_E_TYPEMISMATCH, "Call succeeded, hres = %08lx\n", hres)
3144 #define EXPECT2(a,b) EXPECTRGB(0,a); EXPECTRGB(1,b)
3146 static void test_VarParseNumFromStr(void)
3150 /* Ensure all tests are using the same locale characters for '$', ',' etc */
3151 LCID lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
3157 /* Consume a single digit */
3159 EXPECT(1,0,0,1,0,0);
3162 /* cDig is not literal digits - zeros are suppressed and nPwr10 is increased */
3164 EXPECT(1,0,0,2,0,1);
3165 /* Note: Win32 writes the trailing zeros if they are within cDig's limits,
3166 * but then excludes them from the returned cDig count.
3167 * In our implementation we don't bother writing them at all.
3171 /* if cDig is too small and numbers follow, sets INEXACT */
3172 CONVERTN("11",1, 0);
3173 EXPECT(1,0,NUMPRS_INEXACT,2,0,1);
3176 /* Strips leading zeros */
3178 EXPECT(1,0,0,2,0,0);
3181 /* Strips leading zeros */
3182 CONVERTN("01",1, 0);
3183 EXPECT(1,0,0,2,0,0);
3187 /* Fails on non digits */
3190 EXPECTRGB(0,FAILDIG);
3192 /** NUMPRS_LEADING_WHITE/NUMPRS_TRAILING_WHITE **/
3194 /* Without flag, fails on whitespace */
3197 EXPECTRGB(0,FAILDIG);
3200 /* With flag, consumes whitespace */
3201 CONVERT(" 0", NUMPRS_LEADING_WHITE);
3202 EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
3205 /* Test TAB once, then assume it acts as space for all cases */
3206 CONVERT("\t0", NUMPRS_LEADING_WHITE);
3207 EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
3211 /* Doesn't pick up trailing whitespace without flag */
3213 EXPECT(1,0,0,1,0,0);
3216 /* With flag, consumes trailing whitespace */
3217 CONVERT("0 ", NUMPRS_TRAILING_WHITE);
3218 EXPECT(1,NUMPRS_TRAILING_WHITE,NUMPRS_TRAILING_WHITE,2,0,0);
3221 /* Leading flag only consumes leading */
3222 CONVERT(" 0 ", NUMPRS_LEADING_WHITE);
3223 EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
3226 /* Both flags consumes both */
3227 CONVERT(" 0 ", NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE);
3228 EXPECT(1,NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE,NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE,3,0,0);
3231 /** NUMPRS_LEADING_PLUS/NUMPRS_TRAILING_PLUS **/
3233 /* Without flag, fails on + */
3236 EXPECTRGB(0,FAILDIG);
3238 /* With flag, consumes + */
3239 CONVERT("+0", NUMPRS_LEADING_PLUS);
3240 EXPECT(1,NUMPRS_LEADING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
3243 /* Without flag, doesn't consume trailing + */
3245 EXPECT(1,0,0,1,0,0);
3248 /* With flag, consumes trailing + */
3249 CONVERT("0+", NUMPRS_TRAILING_PLUS);
3250 EXPECT(1,NUMPRS_TRAILING_PLUS,NUMPRS_TRAILING_PLUS,2,0,0);
3253 /* With leading flag, doesn't consume trailing + */
3254 CONVERT("+0+", NUMPRS_LEADING_PLUS);
3255 EXPECT(1,NUMPRS_LEADING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
3258 /* Trailing + doesn't get consumed if we specify both (unlike whitespace) */
3259 CONVERT("+0+", NUMPRS_LEADING_PLUS|NUMPRS_TRAILING_PLUS);
3260 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_TRAILING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
3263 /** NUMPRS_LEADING_MINUS/NUMPRS_TRAILING_MINUS **/
3265 /* Without flag, fails on - */
3268 EXPECTRGB(0,FAILDIG);
3270 /* With flag, consumes - */
3271 CONVERT("-0", NUMPRS_LEADING_MINUS);
3272 EXPECT(1,NUMPRS_LEADING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
3275 /* Without flag, doesn't consume trailing - */
3277 EXPECT(1,0,0,1,0,0);
3280 /* With flag, consumes trailing - */
3281 CONVERT("0-", NUMPRS_TRAILING_MINUS);
3282 EXPECT(1,NUMPRS_TRAILING_MINUS,NUMPRS_NEG|NUMPRS_TRAILING_MINUS,2,0,0);
3285 /* With leading flag, doesn't consume trailing - */
3286 CONVERT("-0-", NUMPRS_LEADING_MINUS);
3287 EXPECT(1,NUMPRS_LEADING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
3290 /* Trailing - doesn't get consumed if we specify both (unlike whitespace) */
3291 CONVERT("-0-", NUMPRS_LEADING_MINUS|NUMPRS_TRAILING_MINUS);
3292 EXPECT(1,NUMPRS_LEADING_MINUS|NUMPRS_TRAILING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
3295 /** NUMPRS_HEX_OCT **/
3297 /* Could be hex, octal or decimal - With flag reads as decimal */
3298 CONVERT("0", NUMPRS_HEX_OCT);
3299 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
3302 /* Doesn't recognise hex in .asm sytax */
3303 CONVERT("0h", NUMPRS_HEX_OCT);
3304 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
3307 /* Doesn't fail with valid leading string but no digits */
3308 CONVERT("0x", NUMPRS_HEX_OCT);
3309 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
3312 /* Doesn't recognise hex format humbers at all! */
3313 CONVERT("0x0", NUMPRS_HEX_OCT);
3314 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
3317 /* Doesn't recognise plain hex digits either */
3318 CONVERT("FE", NUMPRS_HEX_OCT);
3320 EXPECTRGB(0,FAILDIG);
3323 CONVERT("0100", NUMPRS_HEX_OCT);
3324 EXPECT(1,NUMPRS_HEX_OCT,0,4,0,2);
3331 EXPECTRGB(3,FAILDIG);
3333 /** NUMPRS_PARENS **/
3335 /* Empty parens = error */
3336 CONVERT("()", NUMPRS_PARENS);
3338 EXPECTRGB(0,FAILDIG);
3340 /* With flag, trailing parens not consumed */
3341 CONVERT("0()", NUMPRS_PARENS);
3342 EXPECT(1,NUMPRS_PARENS,0,1,0,0);
3345 /* With flag, Number in parens made negative and parens consumed */
3346 CONVERT("(0)", NUMPRS_PARENS);
3347 EXPECT(1,NUMPRS_PARENS,NUMPRS_NEG|NUMPRS_PARENS,3,0,0);
3350 /** NUMPRS_THOUSANDS **/
3352 /* With flag, thousands sep. not needed */
3353 CONVERT("0", NUMPRS_THOUSANDS);
3354 EXPECT(1,NUMPRS_THOUSANDS,0,1,0,0);
3357 /* With flag, thousands sep. and following digits consumed */
3358 CONVERT("1,000", NUMPRS_THOUSANDS);
3359 EXPECT(1,NUMPRS_THOUSANDS,NUMPRS_THOUSANDS,5,0,3);
3362 /* With flag and decimal point, thousands sep. but not decimals consumed */
3363 CONVERT("1,000.0", NUMPRS_THOUSANDS);
3364 EXPECT(1,NUMPRS_THOUSANDS,NUMPRS_THOUSANDS,5,0,3);
3367 /** NUMPRS_CURRENCY **/
3369 /* Without flag, chokes on currency sign */
3372 EXPECTRGB(0,FAILDIG);
3374 /* With flag, consumes currency sign */
3375 CONVERT("$11", NUMPRS_CURRENCY);
3376 EXPECT(2,NUMPRS_CURRENCY,NUMPRS_CURRENCY,3,0,0);
3378 EXPECTRGB(2,FAILDIG);
3380 /* With flag only, doesn't consume decimal point */
3381 CONVERT("$11.1", NUMPRS_CURRENCY);
3382 EXPECT(2,NUMPRS_CURRENCY,NUMPRS_CURRENCY,3,0,0);
3384 EXPECTRGB(2,FAILDIG);
3386 /* With flag and decimal flag, consumes decimal point and following digits */
3387 CONVERT("$11.1", NUMPRS_CURRENCY|NUMPRS_DECIMAL);
3388 EXPECT(3,NUMPRS_CURRENCY|NUMPRS_DECIMAL,NUMPRS_CURRENCY|NUMPRS_DECIMAL,5,0,-1);
3391 EXPECTRGB(3,FAILDIG);
3393 /* Thousands flag can only be used with currency */
3394 CONVERT("$1,234", NUMPRS_CURRENCY|NUMPRS_THOUSANDS);
3395 EXPECT(4,NUMPRS_CURRENCY|NUMPRS_THOUSANDS,NUMPRS_CURRENCY|NUMPRS_THOUSANDS,6,0,0);
3399 EXPECTRGB(4,FAILDIG);
3401 /** NUMPRS_DECIMAL **/
3403 /* With flag, consumes decimal point */
3404 CONVERT("1.1", NUMPRS_DECIMAL);
3405 EXPECT(2,NUMPRS_DECIMAL,NUMPRS_DECIMAL,3,0,-1);
3407 EXPECTRGB(2,FAILDIG);
3409 /* With flag, consumes decimal point. Skipping the decimal part is not an error */
3410 CONVERT("1.", NUMPRS_DECIMAL);
3411 EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,2,0,0);
3414 /* Consumes only one decimal point */
3415 CONVERT("1.1.", NUMPRS_DECIMAL);
3416 EXPECT(2,NUMPRS_DECIMAL,NUMPRS_DECIMAL,3,0,-1);
3418 EXPECTRGB(2,FAILDIG);
3420 /** NUMPRS_EXPONENT **/
3422 /* Without flag, doesn't consume exponent */
3424 EXPECT(1,0,0,1,0,0);
3427 /* With flag, consumes exponent */
3428 CONVERT("1e1", NUMPRS_EXPONENT);
3429 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,1);
3432 /* Negative exponents are accepted without flags */
3433 CONVERT("1e-1", NUMPRS_EXPONENT);
3434 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,-1);
3437 /* As are positive exponents and leading exponent 0's */
3438 CONVERT("1e+01", NUMPRS_EXPONENT);
3439 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,5,0,1);
3442 /* Doesn't consume a real number exponent */
3443 CONVERT("1e1.", NUMPRS_EXPONENT);
3444 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,1);
3447 /* Powers of 10 are calculated from the position of any decimal point */
3448 CONVERT("1.5e20", NUMPRS_EXPONENT|NUMPRS_DECIMAL);
3449 EXPECT(2,NUMPRS_EXPONENT|NUMPRS_DECIMAL,NUMPRS_EXPONENT|NUMPRS_DECIMAL,6,0,19);
3452 CONVERT("1.5e-20", NUMPRS_EXPONENT|NUMPRS_DECIMAL);
3453 EXPECT(2,NUMPRS_EXPONENT|NUMPRS_DECIMAL,NUMPRS_EXPONENT|NUMPRS_DECIMAL,7,0,-21);
3456 /** NUMPRS_USE_ALL **/
3458 /* Flag expects all digits */
3459 CONVERT("0", NUMPRS_USE_ALL);
3460 EXPECT(1,NUMPRS_USE_ALL,0,1,0,0);
3463 /* Rejects anything trailing */
3464 CONVERT("0 ", NUMPRS_USE_ALL);
3468 /* Unless consumed by trailing flag */
3469 CONVERT("0 ", NUMPRS_USE_ALL|NUMPRS_TRAILING_WHITE);
3470 EXPECT(1,NUMPRS_USE_ALL|NUMPRS_TRAILING_WHITE,NUMPRS_TRAILING_WHITE,2,0,0);
3473 /** Combinations **/
3475 /* Leading whitepace and plus, doesn't consume trailing whitespace */
3476 CONVERT("+ 0 ", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
3477 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,3,0,0);
3480 /* Order of whitepace and plus is unimportant */
3481 CONVERT(" +0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
3482 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,3,0,0);
3485 /* Leading whitespace can be repeated */
3486 CONVERT(" + 0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
3487 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,4,0,0);
3490 /* But plus/minus etc. cannot */
3491 CONVERT("+ +0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
3493 EXPECTRGB(0,FAILDIG);
3495 /* Inexact is not set if trailing zeros are removed */
3496 CONVERTN("10", 1, 0);
3497 EXPECT(1,0,0,2,0,1);
3500 /* Make sure a leading 0 is stripped but decimals after it get read */
3501 CONVERT("-0.51", NUMPRS_STD);
3502 EXPECT(2,NUMPRS_STD,NUMPRS_NEG|NUMPRS_DECIMAL|NUMPRS_LEADING_MINUS,5,0,-2);
3506 /* Macros for converting and testing the result of VarNumFromParseNum */
3507 #define SETRGB(indx,val) if (!indx) memset(rgb, FAILDIG, sizeof(rgb)); rgb[indx] = val
3509 #define CONVERT(a,b,c,d,e,f,bits) \
3510 np.cDig = (a); np.dwInFlags = (b); np.dwOutFlags = (c); np.cchUsed = (d); \
3511 np.nBaseShift = (e); np.nPwr10 = (f); hres = VarNumFromParseNum(&np, rgb, bits, &vOut)
3512 #define EXPECT_OVERFLOW ok(hres == (HRESULT)DISP_E_OVERFLOW, "Expected overflow, hres = %08lx\n", hres)
3513 #define EXPECT_OK ok(hres == (HRESULT)S_OK, "Call failed, hres = %08lx\n", hres); \
3514 if (hres == (HRESULT)S_OK)
3515 #define EXPECT_TYPE(typ) ok(V_VT(&vOut) == typ,"Expected Type = " #typ ", got %d\n", V_VT(&vOut))
3516 #define EXPECT_I1(val) EXPECT_OK { EXPECT_TYPE(VT_I1); \
3517 ok(V_I1(&vOut) == val, "Expected i1 = %d, got %d\n", (signed char)val, V_I1(&vOut)); }
3518 #define EXPECT_UI1(val) EXPECT_OK { EXPECT_TYPE(VT_UI1); \
3519 ok(V_UI1(&vOut) == val, "Expected ui1 = %d, got %d\n", (BYTE)val, V_UI1(&vOut)); }
3520 #define EXPECT_I2(val) EXPECT_OK { EXPECT_TYPE(VT_I2); \
3521 ok(V_I2(&vOut) == val, "Expected i2 = %d, got %d\n", (SHORT)val, V_I2(&vOut)); }
3522 #define EXPECT_UI2(val) EXPECT_OK { EXPECT_TYPE(VT_UI2); \
3523 ok(V_UI2(&vOut) == val, "Expected ui2 = %d, got %d\n", (USHORT)val, V_UI2(&vOut)); }
3524 #define EXPECT_I4(val) EXPECT_OK { EXPECT_TYPE(VT_I4); \
3525 ok(V_I4(&vOut) == val, "Expected i4 = %ld, got %ld\n", (LONG)val, V_I4(&vOut)); }
3526 #define EXPECT_UI4(val) EXPECT_OK { EXPECT_TYPE(VT_UI4); \
3527 ok(V_UI4(&vOut) == val, "Expected ui4 = %ld, got %ld\n", (ULONG)val, V_UI4(&vOut)); }
3528 #define EXPECT_I8(val) EXPECT_OK { EXPECT_TYPE(VT_I8); \
3529 ok(V_I8(&vOut) == val, "Expected i8 = %lld, got %lld\n", (LONG64)val, V_I8(&vOut)); }
3530 #define EXPECT_UI8(val) EXPECT_OK { EXPECT_TYPE(VT_UI8); \
3531 ok(V_UI8(&vOut) == val, "Expected ui8 = %lld, got %lld\n", (ULONG64)val, V_UI8(&vOut)); }
3532 #define EXPECT_R4(val) EXPECT_OK { EXPECT_TYPE(VT_R4); \
3533 ok(V_R4(&vOut) == val, "Expected r4 = %f, got %f\n", val, V_R4(&vOut)); }
3534 #define EXPECT_R8(val) EXPECT_OK { EXPECT_TYPE(VT_R8); \
3535 ok(V_R8(&vOut) == val, "Expected r8 = %g, got %g\n", val, V_R8(&vOut)); }
3536 #define CY_MULTIPLIER 10000
3537 #define EXPECT_CY(val) EXPECT_OK { EXPECT_TYPE(VT_CY); \
3538 ok(V_CY(&vOut).int64 == (LONG64)(val * CY_MULTIPLIER), "Expected r8 = %lld, got %lld\n", (LONG64)val, V_CY(&vOut).int64); }
3540 static void test_VarNumFromParseNum(void)
3547 /* Convert the number 1 to different types */
3548 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I1); EXPECT_I1(1);
3549 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_UI1); EXPECT_UI1(1);
3550 /* Prefers a signed type to unsigned of the same size */
3551 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I1|VTBIT_UI1); EXPECT_I1(1);
3552 /* But takes the smaller size if possible */
3553 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I2|VTBIT_UI1); EXPECT_UI1(1);
3555 /* Try different integer sizes */
3556 #define INTEGER_VTBITS (VTBIT_I1|VTBIT_UI1|VTBIT_I2|VTBIT_UI2|VTBIT_I4|VTBIT_UI4|VTBIT_I8|VTBIT_UI8)
3558 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, INTEGER_VTBITS); EXPECT_I1(1);
3560 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 7);
3561 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_I1(127);
3563 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 8);
3564 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_UI1(128);
3566 SETRGB(0, 2); SETRGB(1, 5); SETRGB(2, 5);
3567 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_UI1(255);
3569 SETRGB(0, 2); SETRGB(1, 5); SETRGB(2, 6);
3570 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_I2(256);
3572 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 7);
3573 CONVERT(5,0,0,5,0,0, INTEGER_VTBITS); EXPECT_I2(32767);
3575 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 8);
3576 CONVERT(5,0,0,5,0,0, INTEGER_VTBITS); EXPECT_UI2(32768);
3578 /* Assume the above pattern holds for remaining positive integers; test negative */
3581 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 8);
3582 CONVERT(3,0,NUMPRS_NEG,3,0,0, INTEGER_VTBITS); EXPECT_I1(-128);
3584 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 9);
3585 CONVERT(3,0,NUMPRS_NEG,3,0,0, INTEGER_VTBITS); EXPECT_I2(-129);
3587 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 8);
3588 CONVERT(5,0,NUMPRS_NEG,5,0,0, INTEGER_VTBITS); EXPECT_I2(-32768);
3590 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 9);
3591 CONVERT(5,0,NUMPRS_NEG,5,0,0, INTEGER_VTBITS); EXPECT_I4(-32769);
3593 /* Assume the above pattern holds for remaining negative integers */
3595 /* Negative numbers overflow if we have only unsigned outputs */
3597 SETRGB(0, 1); CONVERT(1,0,NUMPRS_NEG,1,0,0, VTBIT_UI1); EXPECT_OVERFLOW;
3599 SETRGB(0, 6); CONVERT(1,0,NUMPRS_NEG,1,0,~0u, VTBIT_UI1); EXPECT_OVERFLOW;
3601 /* Except that rounding is done first, so -0.5 to 0 are accepted as 0 */
3603 SETRGB(0, 5); CONVERT(1,0,NUMPRS_NEG,1,0,~0u, VTBIT_UI1); EXPECT_UI1(0);
3605 /* Float is acceptable for an integer input value */
3606 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R4); EXPECT_R4(1.0f);
3608 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R8); EXPECT_R8(1.0);
3609 /* As is currency */
3610 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_CY); EXPECT_CY(1);
3612 /* Float is preferred over double */
3613 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R4|VTBIT_R8); EXPECT_R4(1.0f);
3615 /* Double is preferred over currency */
3616 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R8|VTBIT_CY); EXPECT_R8(1.0);
3618 /* Currency is preferred over decimal */
3619 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_CY|VTBIT_DECIMAL); EXPECT_CY(1);
3622 #define DT2UD(dt,flags,r,d,m,y,h,mn,s,ms,dw,dy) \
3623 memset(&ud, 0, sizeof(ud)); \
3624 res = pVarUdateFromDate(dt, flags, &ud); \
3625 ok(r == res && (FAILED(r) || (ud.st.wYear == y && ud.st.wMonth == m && ud.st.wDay == d && \
3626 ud.st.wHour == h && ud.st.wMinute == mn && ud.st.wSecond == s && \
3627 ud.st.wMilliseconds == ms && ud.st.wDayOfWeek == dw && ud.wDayOfYear == dy)), \
3628 "%.16g expected %lx, %d,%d,%d,%d,%d,%d,%d %d %d, got %lx, %d,%d,%d,%d,%d,%d,%d %d %d\n", \
3629 dt, r, d, m, y, h, mn, s, ms, dw, dy, res, ud.st.wDay, ud.st.wMonth, \
3630 ud.st.wYear, ud.st.wHour, ud.st.wMinute, ud.st.wSecond, \
3631 ud.st.wMilliseconds, ud.st.wDayOfWeek, ud.wDayOfYear)
3633 static void test_VarUdateFromDate(void)
3638 CHECKPTR(VarUdateFromDate);
3639 DT2UD(29221.0,0,S_OK,1,1,1980,0,0,0,0,2,1); /* 1 Jan 1980 */
3640 DT2UD(29222.0,0,S_OK,2,1,1980,0,0,0,0,3,2); /* 2 Jan 1980 */
3641 DT2UD(33238.0,0,S_OK,31,12,1990,0,0,0,0,1,365); /* 31 Dec 1990 */
3642 DT2UD(0.0,0,S_OK,30,12,1899,0,0,0,0,6,364); /* 30 Dec 1899 - VT_DATE 0.0 */
3643 DT2UD(-657434.0,0,S_OK,1,1,100,0,0,0,0,5,1); /* 1 Jan 100 - Min */
3644 DT2UD(-657435.0,0,E_INVALIDARG,0,0,0,0,0,0,0,0,0); /* < 1 Jan 100 => err */
3645 DT2UD(2958465.0,0,S_OK,31,12,9999,0,0,0,0,5,365); /* 31 Dec 9999 - Max */
3646 DT2UD(2958466.0,0,E_INVALIDARG,0,0,0,0,0,0,0,0,0); /* > 31 Dec 9999 => err */
3648 /* VAR_VALIDDATE doesn't prevent upper and lower bounds being checked */
3649 DT2UD(-657435.0,VAR_VALIDDATE,E_INVALIDARG,0,0,0,0,0,0,0,0,0);
3650 DT2UD(2958466.0,VAR_VALIDDATE,E_INVALIDARG,0,0,0,0,0,0,0,0,0);
3653 DT2UD(29221.25,0,S_OK,1,1,1980,6,0,0,0,2,1); /* 6 AM */
3654 DT2UD(29221.33333333,0,S_OK,1,1,1980,8,0,0,0,2,1); /* 8 AM */
3655 DT2UD(29221.5,0,S_OK,1,1,1980,12,0,0,0,2,1); /* 12 AM */
3656 DT2UD(29221.9888884444,0,S_OK,1,1,1980,23,44,0,0,2,1); /* 11:44 PM */
3657 DT2UD(29221.7508765432,0,S_OK,1,1,1980,18,1,16,0,2,1); /* 6:18:02 PM */
3661 #define UD2T(d,m,y,h,mn,s,ms,dw,dy,flags,r,dt) \
3662 ud.st.wYear = (y); ud.st.wMonth = (m); ud.st.wDay = (d); ud.st.wHour = (h); \
3663 ud.st.wMinute = (mn); ud.st.wSecond = (s); ud.st.wMilliseconds = (ms); \
3664 ud.st.wDayOfWeek = (dw); ud.wDayOfYear = (dy); \
3665 res = pVarDateFromUdate(&ud, (flags), &out); \
3666 ok((r) == res && (FAILED(r) || fabs(out-(dt)) < 1.0e-11), \
3667 "expected %lx, %.16g, got %lx, %.16g\n", r, dt, res, out)
3669 static void test_VarDateFromUdate(void)
3675 CHECKPTR(VarDateFromUdate);
3676 UD2T(1,1,1980,0,0,0,0,2,1,0,S_OK,29221.0); /* 1 Jan 1980 */
3677 UD2T(2,1,1980,0,0,0,0,3,2,0,S_OK,29222.0); /* 2 Jan 1980 */
3678 UD2T(31,12,1990,0,0,0,0,0,0,0,S_OK,33238.0); /* 31 Dec 1990 */
3679 UD2T(31,12,90,0,0,0,0,0,0,0,S_OK,33238.0); /* year < 100 is 1900+year! */
3680 UD2T(30,12,1899,0,0,0,0,6,364,0,S_OK,0.0); /* 30 Dec 1899 - VT_DATE 0.0 */
3681 UD2T(1,1,100,0,0,0,0,0,0,0,S_OK,-657434.0); /* 1 Jan 100 - Min */
3682 UD2T(31,12,9999,0,0,0,0,0,0,0,S_OK,2958465.0); /* 31 Dec 9999 - Max */
3683 UD2T(1,1,10000,0,0,0,0,0,0,0,E_INVALIDARG,0.0); /* > 31 Dec 9999 => err */
3685 UD2T(1,1,1980,18,1,16,0,2,1,0,S_OK,29221.75087962963); /* 6:18:02 PM */
3687 UD2T(0,1,1980,0,0,0,0,2,1,0,S_OK,29220.0); /* Rolls back to 31 Dec 1899 */
3688 UD2T(1,13,1980,0,0,0,0,2,1,0,S_OK,29587.0); /* Rolls fwd to 1/1/1981 */
3691 #define ST2DT(d,m,y,h,mn,s,ms,r,dt) \
3692 st.wYear = y; st.wMonth = m; st.wDay = d; st.wHour = h; st.wMinute = mn; \
3693 st.wSecond = s; st.wMilliseconds = ms; st.wDayOfWeek = 0; \
3694 res = pSystemTimeToVariantTime(&st, &out); \
3695 ok(r == res && (!r || fabs(out-dt) < 1.0e-11), \
3696 "expected %d, %.16g, got %d, %.16g\n", r, dt, res, out)
3698 static void test_SystemTimeToVariantTime(void)
3704 CHECKPTR(SystemTimeToVariantTime);
3705 ST2DT(1,1,1980,0,0,0,0,TRUE,29221.0);
3706 ST2DT(2,1,1980,0,0,0,0,TRUE,29222.0);
3707 ST2DT(0,1,1980,0,0,0,0,TRUE,29220.0); /* Rolls back to 31 Dec 1899 */
3708 ST2DT(1,13,1980,0,0,0,0,FALSE,29587.0); /* Fails on invalid month */
3709 ST2DT(31,12,90,0,0,0,0,TRUE,33238.0); /* year < 100 is 1900+year! */
3712 #define DT2ST(dt,r,d,m,y,h,mn,s,ms) \
3713 memset(&st, 0, sizeof(st)); \
3714 res = pVariantTimeToSystemTime(dt, &st); \
3715 ok(r == res && (!r || (st.wYear == y && st.wMonth == m && st.wDay == d && \
3716 st.wHour == h && st.wMinute == mn && st.wSecond == s && \
3717 st.wMilliseconds == ms)), \
3718 "%.16g expected %d, %d,%d,%d,%d,%d,%d,%d, got %d, %d,%d,%d,%d,%d,%d,%d\n", \
3719 dt, r, d, m, y, h, mn, s, ms, res, st.wDay, st.wMonth, st.wYear, \
3720 st.wHour, st.wMinute, st.wSecond, st.wMilliseconds)
3722 static void test_VariantTimeToSystemTime(void)
3727 CHECKPTR(VariantTimeToSystemTime);
3728 DT2ST(29221.0,1,1,1,1980,0,0,0,0);
3729 DT2ST(29222.0,1,2,1,1980,0,0,0,0);
3732 #define MKDOSDATE(d,m,y) ((d & 0x1f) | ((m & 0xf) << 5) | (((y-1980) & 0x7f) << 9))
3733 #define MKDOSTIME(h,m,s) (((s>>1) & 0x1f) | ((m & 0x3f) << 5) | ((h & 0x1f) << 11))
3735 #define DOS2DT(d,m,y,h,mn,s,r,dt) out = 0.0; \
3736 dosDate = MKDOSDATE(d,m,y); \
3737 dosTime = MKDOSTIME(h,mn,s); \
3738 res = pDosDateTimeToVariantTime(dosDate, dosTime, &out); \
3739 ok(r == res && (!r || fabs(out-dt) < 1.0e-11), \
3740 "expected %d, %.16g, got %d, %.16g\n", r, dt, res, out)
3742 static void test_DosDateTimeToVariantTime(void)
3744 USHORT dosDate, dosTime;
3748 CHECKPTR(DosDateTimeToVariantTime);
3751 DOS2DT(1,1,1980,0,0,0,1,29221.0); /* 1/1/1980 */
3752 DOS2DT(31,12,2099,0,0,0,1,73050.0); /* 31/12/2099 */
3753 /* Dates are limited to the dos date max of 31/12/2099 */
3754 DOS2DT(31,12,2100,0,0,0,0,0.0); /* 31/12/2100 */
3755 /* Days and months of 0 cause date to roll back 1 day or month */
3756 DOS2DT(0,1,1980,0,0,0,1,29220.0); /* 0 Day => 31/12/1979 */
3757 DOS2DT(1,0,1980,0,0,0,1,29190.0); /* 0 Mth => 1/12/1979 */
3758 DOS2DT(0,0,1980,0,0,0,1,29189.0); /* 0 D/M => 30/11/1979 */
3759 /* Days > days in the month cause date to roll forward 1 month */
3760 DOS2DT(29,2,1981,0,0,0,1,29646.0); /* 29/2/1981 -> 3/1/1980 */
3761 DOS2DT(30,2,1981,0,0,0,1,29647.0); /* 30/2/1981 -> 4/1/1980 */
3762 /* Takes leap years into account when rolling forward */
3763 DOS2DT(29,2,1980,0,0,0,1,29280.0); /* 2/29/1980 */
3764 /* Months > 12 cause an error */
3765 DOS2DT(2,13,1980,0,0,0,0,0.0);
3768 DOS2DT(1,1,1980,0,0,29,1,29221.00032407407); /* 1/1/1980 12:00:28 AM */
3769 DOS2DT(1,1,1980,0,0,31,1,29221.00034722222); /* 1/1/1980 12:00:30 AM */
3770 DOS2DT(1,1,1980,0,59,0,1,29221.04097222222); /* 1/1/1980 12:59:00 AM */
3771 DOS2DT(1,1,1980,0,60,0,0,0.0); /* Invalid seconds */
3772 DOS2DT(1,1,1980,23,0,0,1,29221.95833333333); /* 1/1/1980 11:00:00 PM */
3773 DOS2DT(1,1,1980,24,0,0,0,0.0); /* Invalid hours */
3776 #define DT2DOS(dt,r,d,m,y,h,mn,s) dosTime = dosDate = 0; \
3777 expDosDate = MKDOSDATE(d,m,y); \
3778 expDosTime = MKDOSTIME(h,mn,s); \
3779 res = pVariantTimeToDosDateTime(dt, &dosDate, &dosTime); \
3780 ok(r == res && (!r || (dosTime == expDosTime && dosDate == expDosDate)), \
3781 "%g: expected %d,%d(%d/%d/%d),%d(%d:%d:%d) got %d,%d(%d/%d/%d),%d(%d:%d:%d)\n", \
3782 dt, r, expDosDate, expDosDate & 0x1f, (expDosDate >> 5) & 0xf, 1980 + (expDosDate >> 9), \
3783 expDosTime, expDosTime >> 11, (expDosTime >> 5) & 0x3f, (expDosTime & 0x1f), \
3784 res, dosDate, dosDate & 0x1f, (dosDate >> 5) & 0xf, 1980 + (dosDate >> 9), \
3785 dosTime, dosTime >> 11, (dosTime >> 5) & 0x3f, (dosTime & 0x1f))
3787 static void test_VariantTimeToDosDateTime(void)
3789 USHORT dosDate, dosTime, expDosDate, expDosTime;
3792 CHECKPTR(VariantTimeToDosDateTime);
3795 DT2DOS(29221.0,1,1,1,1980,0,0,0); /* 1/1/1980 */
3796 DT2DOS(73050.0,1,31,12,2099,0,0,0); /* 31/12/2099 */
3797 DT2DOS(29220.0,0,0,0,0,0,0,0); /* 31/12/1979 - out of range */
3798 DT2DOS(73415.0,0,0,0,0,0,0,0); /* 31/12/2100 - out of range */
3801 DT2DOS(29221.00032407407,1,1,1,1980,0,0,29); /* 1/1/1980 12:00:28 AM */
3802 DT2DOS(29221.00034722222,1,1,1,1980,0,0,31); /* 1/1/1980 12:00:30 AM */
3803 DT2DOS(29221.04097222222,1,1,1,1980,0,59,0); /* 1/1/1980 12:59:00 AM */
3804 DT2DOS(29221.95833333333,1,1,1,1980,23,0,0); /* 1/1/1980 11:00:00 PM */
3807 #define FMT_NUMBER(vt,val) \
3808 VariantInit(&v); V_VT(&v) = vt; val(&v) = 1; \
3809 hres = pVarFormatNumber(&v,2,0,0,0,0,&str); \
3810 ok(hres == S_OK, "VarFormatNumber (vt %d): returned %8lx\n", vt, hres); \
3812 ok(str && strcmpW(str,szResult1) == 0, \
3813 "VarFormatNumber (vt %d): string different\n", vt)
3815 static void test_VarFormatNumber(void)
3817 static WCHAR szSrc1[] = { '1','\0' };
3818 static WCHAR szResult1[] = { '1','.','0','0','\0' };
3819 static WCHAR szSrc2[] = { '-','1','\0' };
3820 static WCHAR szResult2[] = { '(','1','.','0','0',')','\0' };
3826 CHECKPTR(VarFormatNumber);
3828 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buff, sizeof(buff)/sizeof(char));
3829 if (buff[0] != '.' || buff[1])
3831 trace("Skipping VarFormatNumber tests as decimal seperator is '%s'\n", buff);
3835 FMT_NUMBER(VT_I1, V_I1);
3836 FMT_NUMBER(VT_UI1, V_UI1);
3837 FMT_NUMBER(VT_I2, V_I2);
3838 FMT_NUMBER(VT_UI2, V_UI2);
3839 FMT_NUMBER(VT_I4, V_I4);
3840 FMT_NUMBER(VT_UI4, V_UI4);
3842 FMT_NUMBER(VT_I8, V_I8);
3843 FMT_NUMBER(VT_UI8, V_UI8);
3845 FMT_NUMBER(VT_R4, V_R4);
3846 FMT_NUMBER(VT_R8, V_R8);
3847 FMT_NUMBER(VT_BOOL, V_BOOL);
3850 V_BSTR(&v) = SysAllocString(szSrc1);
3852 hres = pVarFormatNumber(&v,2,0,0,0,0,&str);
3853 ok(hres == S_OK, "VarFormatNumber (bstr): returned %8lx\n", hres);
3855 ok(str && strcmpW(str, szResult1) == 0, "VarFormatNumber (bstr): string different\n");
3856 SysFreeString(V_BSTR(&v));
3859 V_BSTR(&v) = SysAllocString(szSrc2);
3860 hres = pVarFormatNumber(&v,2,0,-1,0,0,&str);
3861 ok(hres == S_OK, "VarFormatNumber (bstr): returned %8lx\n", hres);
3863 ok(str && strcmpW(str, szResult2) == 0, "VarFormatNumber (-bstr): string different\n");
3864 SysFreeString(V_BSTR(&v));
3868 #define SIGNED_VTBITS (VTBIT_I1|VTBIT_I2|VTBIT_I4|VTBIT_I8|VTBIT_R4|VTBIT_R8)
3870 #define VARFMT(vt,v,val,fmt,ret,str) do { \
3871 if (out) SysFreeString(out); out = NULL; \
3872 V_VT(&in) = (vt); v(&in) = val; \
3873 if (fmt) MultiByteToWideChar(CP_ACP, 0, fmt, -1, buffW, sizeof(buffW)/sizeof(WCHAR)); \
3874 hres = pVarFormat(&in,fmt ? buffW : NULL,fd,fw,flags,&out); \
3875 if (SUCCEEDED(hres)) WideCharToMultiByte(CP_ACP, 0, out, -1, buff, sizeof(buff),0,0); \
3876 else buff[0] = '\0'; \
3877 ok(hres == ret && (FAILED(ret) || !strcmp(buff, str)), \
3878 "VT %d|0x%04x Format %s: expected 0x%08lx, '%s', got 0x%08lx, '%s'\n", \
3879 (vt)&VT_TYPEMASK,(vt)&~VT_TYPEMASK,fmt?fmt:"<null>",ret,str,hres,buff); \
3882 typedef struct tagFMTRES
3889 static const FMTRES VarFormat_results[] =
3893 { "General Number", "1", "0" },
3894 { "Percent", "100.00%", "0.00%" },
3895 { "Standard", "1.00", "0.00" },
3896 { "Scientific","1.00E+00", "0.00E+00" },
3897 { "True/False", "True", "False" },
3898 /* { "On/Off", "On", "Off" },
3899 { "Yes/No", "Yes", "No")}, */
3902 { "#.#", "1.", "." },
3904 { "00", "01", "00" },
3905 { "0.0", "1.0", "0.0" },
3906 { "00\\c\\o\\p\\y", "01copy","00copy" },
3907 { "\"pos\";\"neg\"", "pos", "pos" },
3908 { "\"pos\";\"neg\";\"zero\"","pos", "zero" }
3911 typedef struct tagFMTDATERES
3918 static const FMTDATERES VarFormat_date_results[] =
3926 { 0.0, "w", "1" }, /* First 7 entries must remain in this order! */
3927 { 2.525, "am/pm", "pm" },
3928 { 2.525, "AM/PM", "PM" },
3929 { 2.525, "A/P", "P" },
3930 { 2.525, "a/p", "p" },
3931 { 2.525, "q", "1" },
3932 { 2.525, "d", "1" },
3933 { 2.525, "dd", "01" },
3934 { 2.525, "ddd", "Mon" },
3935 { 2.525, "dddd", "Monday" },
3936 { 2.525, "mmm", "Jan" },
3937 { 2.525, "mmmm", "January" },
3938 { 2.525, "y", "1" },
3939 { 2.525, "yy", "00" },
3940 { 2.525, "yyy", "001" },
3941 { 2.525, "yyyy", "1900" },
3942 { 2.525, "dd mm yyyy hh:mm:ss", "01 01 1900 12:36:00" },
3943 { 2.525, "dd mm yyyy mm", "01 01 1900 01" },
3944 { 2.525, "dd mm yyyy :mm", "01 01 1900 :01" },
3945 { 2.525, "dd mm yyyy hh:mm", "01 01 1900 12:36" },
3946 { 2.525, "mm mm", "01 01" },
3947 { 2.525, "mm :mm:ss", "01 :01:00" },
3948 { 2.525, "mm :ss:mm", "01 :00:01" },
3949 { 2.525, "hh:mm :ss:mm", "12:36 :00:01" },
3950 { 2.525, "hh:dd :mm:mm", "12:01 :01:01" },
3951 { 2.525, "dd:hh :mm:mm", "01:12 :36:01" },
3952 { 2.525, "hh :mm:mm", "12 :36:01" },
3953 { 2.525, "dd :mm:mm", "01 :01:01" },
3954 { 2.525, "dd :mm:nn", "01 :01:36" },
3955 { 2.725, "hh:nn:ss A/P", "05:24:00 P" }
3958 #define VNUMFMT(vt,v) \
3959 for (i = 0; i < sizeof(VarFormat_results)/sizeof(FMTRES); i++) \
3961 VARFMT(vt,v,1,VarFormat_results[i].fmt,S_OK,VarFormat_results[i].one_res); \
3962 VARFMT(vt,v,0,VarFormat_results[i].fmt,S_OK,VarFormat_results[i].zero_res); \
3964 if ((1 << vt) & SIGNED_VTBITS) \
3966 VARFMT(vt,v,-1,"\"pos\";\"neg\"",S_OK,"neg"); \
3967 VARFMT(vt,v,-1,"\"pos\";\"neg\";\"zero\"",S_OK,"neg"); \
3970 static void test_VarFormat(void)
3972 static const WCHAR szTesting[] = { 't','e','s','t','i','n','g','\0' };
3977 VARIANT_BOOL bTrue = VARIANT_TRUE, bFalse = VARIANT_FALSE;
3980 BSTR bstrin, out = NULL;
3983 CHECKPTR(VarFormat);
3985 if (PRIMARYLANGID(LANGIDFROMLCID(GetUserDefaultLCID())) != LANG_ENGLISH)
3987 trace("Skipping VarFormat tests for non english language\n");
3990 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buff, sizeof(buff)/sizeof(char));
3991 if (buff[0] != '.' || buff[1])
3993 trace("Skipping VarFormat tests as decimal seperator is '%s'\n", buff);
3996 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IDIGITS, buff, sizeof(buff)/sizeof(char));
3997 if (buff[0] != '2' || buff[1])
3999 trace("Skipping VarFormat tests as decimal places is '%s'\n", buff);
4003 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"True/False",S_OK,"True");
4004 VARFMT(VT_BOOL,V_BOOL,VARIANT_FALSE,"True/False",S_OK,"False");
4006 VNUMFMT(VT_I1,V_I1);
4007 VNUMFMT(VT_I2,V_I2);
4008 VNUMFMT(VT_I4,V_I4);
4010 VNUMFMT(VT_I8,V_I8);
4012 VNUMFMT(VT_INT,V_INT);
4013 VNUMFMT(VT_UI1,V_UI1);
4014 VNUMFMT(VT_UI2,V_UI2);
4015 VNUMFMT(VT_UI4,V_UI4);
4017 VNUMFMT(VT_UI8,V_UI8);
4019 VNUMFMT(VT_UINT,V_UINT);
4020 VNUMFMT(VT_R4,V_R4);
4021 VNUMFMT(VT_R8,V_R8);
4023 /* Reference types are dereferenced */
4024 VARFMT(VT_BOOL|VT_BYREF,V_BOOLREF,&bTrue,"True/False",S_OK,"True");
4025 VARFMT(VT_BOOL|VT_BYREF,V_BOOLREF,&bFalse,"True/False",S_OK,"False");
4028 for (i = 0; i < sizeof(VarFormat_date_results)/sizeof(FMTDATERES); i++)
4031 fd = i + 1; /* Test first day */
4034 VARFMT(VT_DATE,V_DATE,VarFormat_date_results[i].val,
4035 VarFormat_date_results[i].fmt,S_OK,
4036 VarFormat_date_results[i].res);
4040 bstrin = SysAllocString(szTesting);
4041 VARFMT(VT_BSTR,V_BSTR,bstrin,"",S_OK,"testing");
4042 VARFMT(VT_BSTR,V_BSTR,bstrin,"@",S_OK,"testing");
4043 VARFMT(VT_BSTR,V_BSTR,bstrin,"&",S_OK,"testing");
4044 VARFMT(VT_BSTR,V_BSTR,bstrin,"\\x@\\x@",S_OK,"xtxesting");
4045 VARFMT(VT_BSTR,V_BSTR,bstrin,"\\x&\\x&",S_OK,"xtxesting");
4046 VARFMT(VT_BSTR,V_BSTR,bstrin,"@\\x",S_OK,"txesting");
4047 VARFMT(VT_BSTR,V_BSTR,bstrin,"@@@@@@@@",S_OK," testing");
4048 VARFMT(VT_BSTR,V_BSTR,bstrin,"@\\x@@@@@@@",S_OK," xtesting");
4049 VARFMT(VT_BSTR,V_BSTR,bstrin,"&&&&&&&&",S_OK,"testing");
4050 VARFMT(VT_BSTR,V_BSTR,bstrin,"!&&&&&&&",S_OK,"testing");
4051 VARFMT(VT_BSTR,V_BSTR,bstrin,"&&&&&&&!",S_OK,"testing");
4052 VARFMT(VT_BSTR,V_BSTR,bstrin,">&&",S_OK,"TESTING");
4053 VARFMT(VT_BSTR,V_BSTR,bstrin,"<&&",S_OK,"testing");
4054 VARFMT(VT_BSTR,V_BSTR,bstrin,"<&>&",S_OK,"testing");
4055 SysFreeString(bstrin);
4056 /* Numeric values are converted to strings then output */
4057 VARFMT(VT_I1,V_I1,1,"<&>&",S_OK,"1");
4059 /* 'out' is not cleared */
4061 pVarFormat(&in,NULL,fd,fw,flags,&out); /* Would crash if out is cleared */
4065 hres = pVarFormat(&in,NULL,fd,fw,flags,NULL);
4066 ok(hres == E_INVALIDARG, "Null out: expected E_INVALIDARG, got 0x%08lx\n", hres);
4067 hres = pVarFormat(NULL,NULL,fd,fw,flags,&out);
4068 ok(hres == E_INVALIDARG, "Null in: expected E_INVALIDARG, got 0x%08lx\n", hres);
4070 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"",E_INVALIDARG,"");
4072 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"",E_INVALIDARG,"");
4074 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"",E_INVALIDARG,"");
4076 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"",E_INVALIDARG,"");
4079 static HRESULT (WINAPI *pVarAbs)(LPVARIANT,LPVARIANT);
4081 #define VARABS(vt,val,rvt,rval) V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
4082 memset(&vDst,0,sizeof(vDst)); hres = pVarAbs(&v,&vDst); \
4083 ok(hres == S_OK && V_VT(&vDst) == VT_##rvt && V_##rvt(&vDst) == (rval), \
4084 "VarAbs: expected 0x0,%d,%d, got 0x%lX,%d,%d\n", VT_##rvt, (int)(rval), \
4085 hres, V_VT(&vDst), (int)V_##rvt(&vDst))
4087 static void test_VarAbs(void)
4089 static const WCHAR szNum[] = {'-','1','.','1','\0' };
4097 /* Test all possible V_VT values.
4099 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
4103 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
4105 HRESULT hExpected = DISP_E_BADVARTYPE;
4107 memset(&v, 0, sizeof(v));
4108 V_VT(&v) = vt | ExtraFlags[i];
4109 V_VT(&vDst) = VT_EMPTY;
4111 hres = pVarAbs(&v,&vDst);
4112 if (ExtraFlags[i] & (VT_ARRAY|VT_ARRAY) ||
4113 (!ExtraFlags[i] && (vt == VT_UNKNOWN || vt == VT_BSTR ||
4114 vt == VT_DISPATCH || vt == VT_ERROR || vt == VT_RECORD)))
4116 hExpected = DISP_E_TYPEMISMATCH;
4118 else if (ExtraFlags[i] || vt >= VT_CLSID || vt == VT_VARIANT)
4120 hExpected = DISP_E_BADVARTYPE;
4122 else if (IsValidVariantClearVT(vt, ExtraFlags[i]))
4125 /* Native always fails on some vartypes that should be valid. don't
4126 * check that Wine does the same; these are bugs in native.
4128 if (vt == VT_I8 || vt == VT_UI8 || vt == VT_INT || vt == VT_UINT ||
4129 vt == VT_I1 || vt == VT_UI2 || vt == VT_UI4)
4131 ok(hres == hExpected, "VarAbs: expected 0x%lX, got 0x%lX for vt %d | 0x%X\n",
4132 hExpected, hres, vt, ExtraFlags[i]);
4136 /* BOOL->I2, BSTR->R8, all others remain the same */
4137 VARABS(BOOL,VARIANT_TRUE,I2,-VARIANT_TRUE);
4138 VARABS(BOOL,VARIANT_FALSE,I2,VARIANT_FALSE);
4143 VARABS(UI1,1,UI1,1);
4148 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buff, sizeof(buff)/sizeof(char));
4149 if (buff[0] != '.' || buff[1])
4151 trace("Skipping VarAbs(BSTR) as decimal seperator is '%s'\n", buff);
4155 V_BSTR(&v) = (BSTR)szNum;
4156 memset(&vDst,0,sizeof(vDst));
4157 hres = pVarAbs(&v,&vDst);
4158 ok(hres == S_OK && V_VT(&vDst) == VT_R8 && V_R8(&vDst) == 1.1,
4159 "VarAbs: expected 0x0,%d,%g, got 0x%lX,%d,%g\n", VT_R8, 1.1, hres, V_VT(&vDst), V_R8(&vDst));
4162 static HRESULT (WINAPI *pVarNot)(LPVARIANT,LPVARIANT);
4164 #define VARNOT(vt,val,rvt,rval) V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
4165 memset(&vDst,0,sizeof(vDst)); hres = pVarNot(&v,&vDst); \
4166 ok(hres == S_OK && V_VT(&vDst) == VT_##rvt && V_##rvt(&vDst) == (rval), \
4167 "VarNot: expected 0x0,%d,%d, got 0x%lX,%d,%d\n", VT_##rvt, (int)(rval), \
4168 hres, V_VT(&vDst), (int)V_##rvt(&vDst))
4170 static void test_VarNot(void)
4172 static const WCHAR szNum0[] = {'0','\0' };
4173 static const WCHAR szNum1[] = {'1','\0' };
4176 DECIMAL *pdec = &V_DECIMAL(&v);
4177 CY *pcy = &V_CY(&v);
4182 /* Test all possible V_VT values */
4183 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
4187 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
4189 HRESULT hExpected = DISP_E_BADVARTYPE;
4191 memset(&v, 0, sizeof(v));
4192 V_VT(&v) = vt | ExtraFlags[i];
4193 V_VT(&vDst) = VT_EMPTY;
4195 hres = pVarNot(&v,&vDst);
4198 case VT_I1: case VT_UI1: case VT_I2: case VT_UI2:
4199 case VT_INT: case VT_UINT: case VT_I4: case VT_UI4:
4200 case VT_R4: case VT_R8:
4201 case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
4202 case VT_DATE: case VT_CY:
4205 case VT_I8: case VT_UI8:
4206 if (HAVE_OLEAUT32_I8)
4210 if (HAVE_OLEAUT32_RECORD)
4211 hExpected = DISP_E_TYPEMISMATCH;
4213 case VT_UNKNOWN: case VT_BSTR: case VT_DISPATCH: case VT_ERROR:
4214 hExpected = DISP_E_TYPEMISMATCH;
4217 if (IsValidVariantClearVT(vt, ExtraFlags[i]) && vt != VT_CLSID)
4218 hExpected = DISP_E_TYPEMISMATCH;
4222 hres = pVarNot(&v,&vDst);
4223 if (V_VT(&v) == VT_DECIMAL)
4226 ok(hres == hExpected, "VarNot: expected 0x%lX, got 0x%lX vt %d|0x%X\n",
4227 hExpected, hres, vt, ExtraFlags[i]);
4231 ok(hres == hExpected, "VarNot: expected 0x%lX, got 0x%lX vt %d|0x%X\n",
4232 hExpected, hres, vt, ExtraFlags[i]);
4235 /* R4,R8,BSTR,DECIMAL,CY->I4, all others remain the same */
4236 VARNOT(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
4237 VARNOT(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
4243 VARNOT(UI1,1,UI1,254);
4244 VARNOT(UI1,0,UI1,255);
4249 VARNOT(BSTR,(BSTR)szNum0,I4,-1);
4250 VARNOT(BSTR,(BSTR)szNum1,I4,-2);
4253 V_VT(&v) = VT_DECIMAL;
4254 pdec->u.s.sign = DECIMAL_NEG;
4255 pdec->u.s.scale = 0;
4257 pdec->u1.s1.Mid32 = 0;
4258 pdec->u1.s1.Lo32 = 1;
4259 VARNOT(DECIMAL,*pdec,I4,0);
4261 VARNOT(CY,*pcy,I4,-2);
4267 hOleaut32 = LoadLibraryA("oleaut32.dll");
4271 test_VariantClear();
4273 test_VariantCopyInd();
4274 test_VarParseNumFromStr();
4275 test_VarNumFromParseNum();
4276 test_VarUdateFromDate();
4277 test_VarDateFromUdate();
4278 test_SystemTimeToVariantTime();
4279 test_VariantTimeToSystemTime();
4280 test_DosDateTimeToVariantTime();
4281 test_VariantTimeToDosDateTime();
4282 test_VarFormatNumber();