safearray.c

来自「Wine-20031016」· C语言 代码 · 共 409 行 · 第 1/2 页

C
409
字号
/* * SafeArray test program * * Copyright 2002 Marcus Meissner * * 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 * */#include <stdarg.h>#include <stdio.h>#include <stdlib.h>#include <math.h>#include <float.h>#include <time.h>#include "wine/test.h"#include "windef.h"#include "winbase.h"#include "winuser.h"#include "wingdi.h"#include "winnls.h"#include "winsock.h"#include "winerror.h"#include "winnt.h"#include "wtypes.h"#include "oleauto.h"static HRESULT (WINAPI *pSafeArrayAllocDescriptorEx)(VARTYPE,UINT,struct tagSAFEARRAY**)=NULL;static HRESULT (WINAPI *pSafeArrayCopyData)(struct tagSAFEARRAY*,struct tagSAFEARRAY*)=NULL;static HRESULT (WINAPI *pSafeArrayGetIID)(struct tagSAFEARRAY*,GUID*)=NULL;static HRESULT (WINAPI *pSafeArraySetIID)(struct tagSAFEARRAY*,REFGUID)=NULL;static HRESULT (WINAPI *pSafeArrayGetVartype)(struct tagSAFEARRAY*,VARTYPE*)=NULL;#define VARTYPE_NOT_SUPPORTED 0static struct {	VARTYPE vt;    /* VT */	UINT elemsize; /* elementsize by VT */	UINT expflags; /* fFeatures from SafeArrayAllocDescriptorEx */	UINT addflags; /* additional fFeatures from SafeArrayCreate */} vttypes[] = {{VT_EMPTY,    VARTYPE_NOT_SUPPORTED,FADF_HAVEVARTYPE,0},{VT_NULL,     VARTYPE_NOT_SUPPORTED,FADF_HAVEVARTYPE,0},{VT_I2,       2,                    FADF_HAVEVARTYPE,0},{VT_I4,       4,                    FADF_HAVEVARTYPE,0},{VT_R4,       4,                    FADF_HAVEVARTYPE,0},{VT_R8,       8,                    FADF_HAVEVARTYPE,0},{VT_CY,       8,                    FADF_HAVEVARTYPE,0},{VT_DATE,     8,                    FADF_HAVEVARTYPE,0},{VT_BSTR,     sizeof(BSTR),         FADF_HAVEVARTYPE,FADF_BSTR},{VT_DISPATCH, sizeof(LPDISPATCH),   FADF_HAVEIID,    FADF_DISPATCH},{VT_ERROR,    4,                    FADF_HAVEVARTYPE,0},{VT_BOOL,     2,                    FADF_HAVEVARTYPE,0},{VT_VARIANT,  sizeof(VARIANT),      FADF_HAVEVARTYPE,FADF_VARIANT},{VT_UNKNOWN,  sizeof(LPUNKNOWN),    FADF_HAVEIID,    FADF_UNKNOWN},{VT_DECIMAL,  sizeof(DECIMAL),      FADF_HAVEVARTYPE,0},{15,          VARTYPE_NOT_SUPPORTED,FADF_HAVEVARTYPE,0}, /* no VT_xxx */{VT_I1,       1,	            FADF_HAVEVARTYPE,0},{VT_UI1,      1,		    FADF_HAVEVARTYPE,0},{VT_UI2,      2,                    FADF_HAVEVARTYPE,0},{VT_UI4,      4,                    FADF_HAVEVARTYPE,0},{VT_I8,       VARTYPE_NOT_SUPPORTED,FADF_HAVEVARTYPE,0},{VT_UI8,      VARTYPE_NOT_SUPPORTED,FADF_HAVEVARTYPE,0},{VT_INT,      sizeof(INT),          FADF_HAVEVARTYPE,0},{VT_UINT,     sizeof(UINT),         FADF_HAVEVARTYPE,0},{VT_VOID,     VARTYPE_NOT_SUPPORTED,FADF_HAVEVARTYPE,0},{VT_HRESULT,  VARTYPE_NOT_SUPPORTED,FADF_HAVEVARTYPE,0},{VT_PTR,      VARTYPE_NOT_SUPPORTED,FADF_HAVEVARTYPE,0},{VT_SAFEARRAY,VARTYPE_NOT_SUPPORTED,FADF_HAVEVARTYPE,0},{VT_CARRAY,   VARTYPE_NOT_SUPPORTED,FADF_HAVEVARTYPE,0},{VT_USERDEFINED,VARTYPE_NOT_SUPPORTED,FADF_HAVEVARTYPE,0},{VT_LPSTR,    VARTYPE_NOT_SUPPORTED,FADF_HAVEVARTYPE,0},{VT_LPWSTR,   VARTYPE_NOT_SUPPORTED,FADF_HAVEVARTYPE,0},{VT_FILETIME, VARTYPE_NOT_SUPPORTED,FADF_HAVEVARTYPE,0},{VT_RECORD,   VARTYPE_NOT_SUPPORTED,FADF_RECORD,0},{VT_BLOB,     VARTYPE_NOT_SUPPORTED,FADF_HAVEVARTYPE,0},{VT_STREAM,   VARTYPE_NOT_SUPPORTED,FADF_HAVEVARTYPE,0},{VT_STORAGE,  VARTYPE_NOT_SUPPORTED,FADF_HAVEVARTYPE,0},{VT_STREAMED_OBJECT,VARTYPE_NOT_SUPPORTED,FADF_HAVEVARTYPE,0},{VT_STORED_OBJECT,VARTYPE_NOT_SUPPORTED,FADF_HAVEVARTYPE,0},{VT_BLOB_OBJECT,VARTYPE_NOT_SUPPORTED,FADF_HAVEVARTYPE,0},{VT_CF,       VARTYPE_NOT_SUPPORTED,FADF_HAVEVARTYPE,0},{VT_CLSID,    VARTYPE_NOT_SUPPORTED,FADF_HAVEVARTYPE,0},};START_TEST(safearray){	HMODULE hdll;	SAFEARRAY 	*a, b, *c;	unsigned int 	i;	long		indices[2];	HRESULT 	hres;	SAFEARRAYBOUND	bound, bounds[2];	VARIANT		v;	LPVOID		data;	IID		iid;	VARTYPE		vt;	LONG		l;	unsigned char	*ptr1, *ptr2;    hdll=LoadLibraryA("oleaut32.dll");    pSafeArrayAllocDescriptorEx=(void*)GetProcAddress(hdll,"SafeArrayAllocDescriptorEx");    pSafeArrayCopyData=(void*)GetProcAddress(hdll,"SafeArrayCopyData");    pSafeArrayGetIID=(void*)GetProcAddress(hdll,"SafeArrayGetIID");    pSafeArraySetIID=(void*)GetProcAddress(hdll,"SafeArraySetIID");    pSafeArrayGetVartype=(void*)GetProcAddress(hdll,"SafeArrayGetVartype");	hres = SafeArrayAllocDescriptor(0,&a);	ok(E_INVALIDARG == hres,"SAAD(0) failed with hres %lx",hres);	hres=SafeArrayAllocDescriptor(1,&a);	ok(S_OK == hres,"SAAD(1) failed with %lx",hres);	for (i=1;i<100;i++) {		hres=SafeArrayAllocDescriptor(i,&a);		ok(S_OK == hres,"SAAD(%d) failed with %lx",i,hres);				ok(a->cDims == i,"a->cDims not initialised?");		hres=SafeArrayDestroyDescriptor(a);		ok(S_OK == hres,"SADD failed with %lx",hres);	}	hres=SafeArrayAllocDescriptor(65535,&a);	ok(S_OK == hres,"SAAD(65535) failed with %lx",hres);	hres=SafeArrayDestroyDescriptor(a);	ok(S_OK == hres,"SADD failed with %lx",hres);	hres=SafeArrayAllocDescriptor(65536,&a);	ok(E_INVALIDARG == hres,"SAAD(65536) failed with %lx",hres);	/* Crashes on Win95: SafeArrayAllocDescriptor(xxx,NULL) */		bound.cElements	= 1;	bound.lLbound	= 0;	a = SafeArrayCreate(-1, 1, &bound);	ok(NULL == a,"SAC(-1,1,[1,0]) not failed?");	bounds[0].cElements = 42;	bounds[0].lLbound =  1;	bounds[1].cElements =  2;	bounds[1].lLbound = 23;    a = SafeArrayCreate(VT_I4,2,bounds);    ok(a != NULL,"SAC(VT_INT32,2,...) failed.");	hres = SafeArrayGetLBound (a, 0, &l);	ok (hres == DISP_E_BADINDEX, "SAGLB 0 failed with %lx", hres);	hres = SafeArrayGetLBound (a, 1, &l);	ok (hres == S_OK, "SAGLB 1 failed with %lx", hres);	ok (l == 1, "SAGLB 1 returned %ld instead of 1", l);	hres = SafeArrayGetLBound (a, 2, &l);	ok (hres == S_OK, "SAGLB 2 failed with %lx", hres);	ok (l == 23, "SAGLB 2 returned %ld instead of 1", l);	hres = SafeArrayGetLBound (a, 3, &l);	ok (hres == DISP_E_BADINDEX, "SAGLB 3 failed with %lx", hres);	hres = SafeArrayGetUBound (a, 0, &l);	ok (hres == DISP_E_BADINDEX, "SAGUB 0 failed with %lx", hres);	hres = SafeArrayGetUBound (a, 1, &l);	ok (hres == S_OK, "SAGUB 1 failed with %lx", hres);	ok (l == 42, "SAGUB 1 returned %ld instead of 1", l);	hres = SafeArrayGetUBound (a, 2, &l);	ok (hres == S_OK, "SAGUB 2 failed with %lx", hres);	ok (l == 24, "SAGUB 2 returned %ld instead of 24", l);	hres = SafeArrayGetUBound (a, 3, &l);	ok (hres == DISP_E_BADINDEX, "SAGUB 3 failed with %lx", hres);	i = SafeArrayGetDim(a);	ok(i == 2, "getdims of 2 din array returned %d",i);	indices[0] = 0;	indices[1] = 23;	hres = SafeArrayGetElement(a, indices, &i);	ok(DISP_E_BADINDEX == hres,"SAGE failed [0,23], hres 0x%lx",hres);	indices[0] = 1;	indices[1] = 22;	hres = SafeArrayGetElement(a, indices, &i);	ok(DISP_E_BADINDEX == hres,"SAGE failed [1,22], hres 0x%lx",hres);	indices[0] = 1;	indices[1] = 23;	hres = SafeArrayGetElement(a, indices, &i);	ok(S_OK == hres,"SAGE failed [1,23], hres 0x%lx",hres);	indices[0] = 1;	indices[1] = 25;	hres = SafeArrayGetElement(a, indices, &i);	ok(DISP_E_BADINDEX == hres,"SAGE failed [1,24], hres 0x%lx",hres);	indices[0] = 3;	indices[1] = 23;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?