vartest.c
来自「Wine-20031016」· C语言 代码 · 共 2,336 行 · 第 1/5 页
C
2,336 行
/* * VARIANT test program * * Copyright 1998 Jean-Claude Cote * * The purpose of this program is validate the implementation * of the APIs related to VARIANTs. The validation is done * by comparing the results given by the Windows implementation * versus the Wine implementation. * * This program tests the creation/coercion/destruction of VARIANTs. * * The program does not currently test any API that takes * arguments of type: IDispatch, IUnknown, DECIMAL, CURRENCY. * * Since the purpose of this program is to compare the results * from Windows and Wine it is written so that with a simple * define it can be compiled either in Windows or Linux. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * NOTES * - The Variant structure in Windows has a non-named union. This means * the member of the union are accessible simply by doing * pVariant->pfltVal. With gcc it is not possible to have non-named * union so it has been named 'u'. So it's members are accessible * using this name like so pVariant->u.pfltVal. So if this program is * compiled in Windows the references to 'u' will need to be take out * of this file. * * - Also the printf is a little different so the format specifiers may * need to be tweaked if this file is compile in Windows. * Printf is also different in that it continues printing numbers * even after there is no more significative digits left to print. These * number are garbage and in windows they are set to zero but not * on Linux. * * - The VarDateFromStr is not implemented yet. * * - The date and floating point format may not be the exact same * format has the one inwindows depending on what the Internatinal * setting are in windows. * */#include <stdarg.h>#include <stdio.h>#include <stdlib.h>#include <math.h>#include <float.h>#include <time.h>#include "windef.h"#include "winbase.h"#include "winsock.h"#include "wine/test.h"#include "winuser.h"#include "wingdi.h"#include "winnls.h"#include "winerror.h"#include "winnt.h"#include "wtypes.h"#include "oleauto.h"static HRESULT (WINAPI *pVarBstrFromI1)(CHAR,LCID,ULONG,BSTR*)=NULL;static HRESULT (WINAPI *pVarI1FromBool)(VARIANT_BOOL,CHAR*)=NULL;static HRESULT (WINAPI *pVarI1FromDate)(DATE,CHAR*)=NULL;static HRESULT (WINAPI *pVarI1FromI4)(LONG,CHAR*)=NULL;static HRESULT (WINAPI *pVarI1FromR8)(double,CHAR*)=NULL;static HRESULT (WINAPI *pVarI1FromStr)(OLECHAR*,LCID,ULONG,CHAR*);static HRESULT (WINAPI *pVarI1FromUI1)(BYTE,CHAR*)=NULL;static HRESULT (WINAPI *pVarI2FromUI2)(USHORT,short*)=NULL;static HRESULT (WINAPI *pVarUI2FromBool)(VARIANT_BOOL,USHORT*)=NULL;static HRESULT (WINAPI *pVarUI2FromDate)(DATE,USHORT*)=NULL;static HRESULT (WINAPI *pVarUI2FromI2)(short,USHORT*)=NULL;static HRESULT (WINAPI *pVarUI2FromI4)(LONG,USHORT*);static HRESULT (WINAPI *pVarUI2FromR8)(double,USHORT*)=NULL;static HRESULT (WINAPI *pVarUI2FromStr)(OLECHAR*,LCID,ULONG,USHORT*)=NULL;static HRESULT (WINAPI *pVarUI4FromBool)(VARIANT_BOOL,ULONG*)=NULL;static HRESULT (WINAPI *pVarUI4FromDate)(DATE,ULONG*)=NULL;static HRESULT (WINAPI *pVarUI4FromI2)(short,ULONG*)=NULL;static HRESULT (WINAPI *pVarUI4FromR8)(double,ULONG*)=NULL;static HRESULT (WINAPI *pVarUI4FromStr)(OLECHAR*,LCID,ULONG,ULONG*)=NULL;/* When comparing floating point values we cannot expect an exact match * because the rounding errors depend on the exact algorithm. */#define EQ_DOUBLE(a,b) (fabs((a)-(b))<1e-14)#define MAX_BUFFER 1024static char* WtoA( OLECHAR* p ){ static char buffer[MAX_BUFFER]; DWORD len = WideCharToMultiByte( CP_ACP, 0, p, -1, buffer+1, sizeof(buffer)-3, NULL, NULL ); buffer[0] = '\"'; buffer[len] = '\"'; buffer[len+1] = 0; return buffer;}static OLECHAR* AtoW( const char* p ){ OLECHAR *buffer; DWORD len = MultiByteToWideChar( CP_ACP, 0, p, -1, NULL, 0 ); buffer = malloc( len * sizeof(OLECHAR) ); MultiByteToWideChar( CP_ACP, 0, p, -1, buffer, len ); return buffer;}static const struct _vartypes { int ind; HRESULT vcind1,vcind2,vcex1,vcex2; int todoind1,todoind2,todowcex1,todowcex2;} vartypes[] = { {0, 0, 0x80070057, 0, 0x80020008,0,1 }, {1, 0, 0x80070057, 0, 0x80020008,0,1 }, {2, 0, 0, 0, 0x80020005 }, {3, 0, 0, 0, 0x80020005 }, {4, 0, 0, 0, 0x80020005 }, {5, 0, 0, 0, 0x80020005 }, {6, 0, 0, 0, 0x80020005 }, {7, 0, 0, 0, 0x80020005 }, {77,0x80020008, 0x80070057, 0, 0x80020005,0,1 }, {78,0x80020008, 0x80070057, 0x80020005, 0x80020005,0,1 }, {79,0x80020008, 0x80070057, 0x80020005, 0x80020005,0,1 }, {80,0x80020008, 0x80070057, 0, 0x80020005,0,1 }, {81,0x80020008, 0x80070057, 0x80020005, 0x80020005,0,1 }, {82,0x80020008, 0x80070057, 0x80020005, 0x80020005,0,1 }, {83,0x80020008, 0x80070057, 0, 0x80020005,0,1,1 }, {84,0x80020008, 0x80070057, 0x80020008, 0x80020008,0,1,1,1 }, {85,0x80020008, 0x80070057, 0, 0x80020005,0,1 }, {86,0x80020008, 0x80070057, 0, 0x80020005,0,1 }, {87,0x80020008, 0x80070057, 0, 0x80020005,0,1 }, {88,0x80020008, 0x80070057, 0, 0x80020005,0,1 }, {89,0x80020008, 0x80070057, 0, 0x80020005,0,1,1 }, {90,0x80020008, 0x80070057, 0, 0x80020005,0,1,1 }, {91,0x80020008, 0x80070057, 0, 0x80020005,0,1 }, {92,0x80020008, 0x80070057, 0, 0x80020005,0,1 }, {93,0x80020008, 0x80070057, 0x80020008, 0x80020008,0,1,1,1 }, {94,0x80020008, 0x80070057, 0x80020008, 0x80020008,0,1,1,1 }, {95,0x80020008, 0x80070057, 0x80020008, 0x80020008,0,1,1,1 }, {96,0x80020008, 0x80070057, 0x80020008, 0x80020008,0,1,1,1 }, {97,0x80020008, 0x80070057, 0x80020008, 0x80020008,0,1,1,1 }, {98,0x80020008, 0x80070057, 0x80020008, 0x80020008,0,1,1,1 }, {99,0x80020008, 0x80070057, 0x80020008, 0x80020008,0,1,1,1 },};static const char *strfromr8[] = {"1","-1","21","-21","321","-321","4321","-4321","54321","-54321","654321","-654321","7654321","-7654321","87654321","-87654321","987654321","-987654321","1987654321","-1987654321","21987654321","-21987654321","321987654321","-321987654321","4321987654321","-4321987654321","54321987654321","-54321987654321","654321987654321","-654321987654321","7.65432198765432E+15","-7.65432198765432E+15","8.76543219876543E+16","-8.76543219876543E+16","9.87654321987654E+17","-9.87654321987654E+17","1.98765432198765E+18","-1.98765432198765E+18","2.19876543219877E+19","-2.19876543219877E+19","1","0","-1","1.2","0.2","-1.2","1.23","0.23","-1.23","1.234","0.234","-1.234","1.2345","0.2345","-1.2345","1.23456","0.23456","-1.23456","1.234567","0.234567","-1.234567","1.2345678","0.2345678","-1.2345678","1.23456789","0.23456789","-1.23456789","1.234567891","0.234567891","-1.234567891","1.2345678912","0.2345678912","-1.2345678912","1.23456789123","0.23456789123","-1.23456789123","1.234567891234","0.234567891234","-1.234567891234","1.2345678912345","0.2345678912345","-1.2345678912345","1.23456789123456","0.23456789123456","-1.23456789123456","1.23456789123457","0.234567891234567","-1.23456789123457","1.23456789123457","0.234567891234568","-1.23456789123457","1.23456789123457","0.234567891234568","-1.23456789123457","1.23456789123457","0.234567891234568","-1.23456789123457","1.23456789123457","0.234567891234568","-1.23456789123457","2","-2","22.2","-22.2","322.23","-322.23","4322.234","-4322.234","54322.2345","-54322.2345","654322.23456","-654322.23456","7654322.234567","-7654322.234567","87654322.2345678","-87654322.2345678","987654322.234568","-987654322.234568","1987654322.23457","-1987654322.23457","21987654322.2346","-21987654322.2346","321987654322.235","-321987654322.235","4321987654322.23","-4321987654322.23","54321987654322.2","-54321987654322.2","654321987654322","-654321987654322","7.65432198765432E+15","-7.65432198765432E+15","8.76543219876543E+16","-8.76543219876543E+16","9.87654321987654E+17","-9.87654321987654E+17","1.98765432198765E+18","-1.98765432198765E+18","2.19876543219877E+19","-2.19876543219877E+19",/* r4 tests */"1","-1","21","-21","321","-321","4321","-4321","54321","-54321","654321","-654321","7654321","-7654321","8.765432E+07","-8.765432E+07","9.876543E+08","-9.876543E+08","1.987654E+09","-1.987654E+09","1","0","-1","1.2","0.2","-1.2","1.23","0.23","-1.23","1.234","0.234","-1.234","1.2345","0.2345","-1.2345","1.23456","0.23456","-1.23456","1.234567","0.234567","-1.234567","1.234568","0.2345678","-1.234568","1.234568","0.2345679","-1.234568","1.234568","0.2345679","-1.234568","2","-2","22.2","-22.2","322.23","-322.23","4322.234","-4322.234","54322.23","-54322.23","654322.3","-654322.3","7654322","-7654322","8.765432E+07","-8.765432E+07","9.876543E+08","-9.876543E+08","1.987654E+09","-1.987654E+09",};/* These are the strings we use for the XxxFromStr tests. * The arrays that follow define the expected results for each type. */static const char* _pTestStrA[] = { "-2", "-1", "-0.51", "-0.5", "-0.49", "-0.0", "0.0", "0.49", "0.5", "0.51", "1", "127", "128", "129", "255", "256", "257", "32767", "32768", "-32768", "-32769", "16777216", "16777217", "-16777216", "16777217", "2147483647", "2147483648", "-2147483647", "-2147483648", "", " ", "1F", "1G", " 1 ", " 1 2 ", "1,2,3", "1 2 3", "1,2, 3", "1;2;3", "1.2.3", "0.", ".0", "0.1E12", "2.4,E1", " +3.2,E1", "4E2.5", " 2E+2", "1 E+2", ".", ".E2", "1000000000000000000000000000000000000000000000000000000000000000", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "65535", "65535.5", "65536", "4294967295", "4294967296", "1 January 99", "December 31, 2078", "January 1, 1900", "January 2 1900", "11.11.1999", "11/11/1999", " 11 / 11 / 1999", "11/11/1999:11:11:1134", "11/11/1999 11:11:11:1", "\t1999/\t11/21 11 :11:11am", "11/11/1999 11:11:11Am", "11/11/1999 11:11:11PM", "11/11/199911:11:11PM", "11/11/1999 0:0:11am", "11/11/1999 11,11:11am", "11/11/1999 11:11:11am", "11/11/1999 11/11:11am", "11/11/1999 11:11AM", "11/11/1999 1AM", "11/11/1999 0AM",
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?