2 * SafeArray test program
4 * Copyright 2002 Marcus Meissner
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "wine/test.h"
42 static HMODULE hOleaut32
;
44 static HRESULT (WINAPI
*pSafeArrayAllocDescriptorEx
)(VARTYPE
,UINT
,SAFEARRAY
**);
45 static HRESULT (WINAPI
*pSafeArrayCopyData
)(SAFEARRAY
*,SAFEARRAY
*);
46 static HRESULT (WINAPI
*pSafeArrayGetIID
)(SAFEARRAY
*,GUID
*);
47 static HRESULT (WINAPI
*pSafeArraySetIID
)(SAFEARRAY
*,REFGUID
);
48 static HRESULT (WINAPI
*pSafeArrayGetVartype
)(SAFEARRAY
*,VARTYPE
*);
49 static HRESULT (WINAPI
*pSafeArrayGetRecordInfo
)(SAFEARRAY
*,IRecordInfo
**);
50 static SAFEARRAY
* (WINAPI
*pSafeArrayCreateEx
)(VARTYPE
,UINT
,SAFEARRAYBOUND
*,LPVOID
);
51 static SAFEARRAY
* (WINAPI
*pSafeArrayCreateVector
)(VARTYPE
,LONG
,ULONG
);
53 #define GETPTR(func) p##func = (void*)GetProcAddress(hOleaut32, #func)
55 /* Is a given function exported from oleaut32? */
56 #define HAVE_FUNC(func) ((void*)GetProcAddress(hOleaut32, #func) != NULL)
58 /* Have IRecordInfo data type? */
59 #define HAVE_OLEAUT32_RECORD HAVE_FUNC(SafeArraySetRecordInfo)
60 /* Have R8 data type? */
61 #define HAVE_OLEAUT32_R8 HAVE_FUNC(VarR8FromI1)
62 /* Have I8/UI8 data type? */
63 #define HAVE_OLEAUT32_I8 HAVE_FUNC(VarI8FromI1)
64 /* Have the decimal type? */
65 #define HAVE_OLEAUT32_DECIMAL HAVE_FUNC(VarDecAdd)
66 /* Have INT_PTR/UINT_PTR type? */
67 static BOOL HAVE_OLEAUT32_INT_PTR
;
69 /* very old version? */
70 #define IS_ANCIENT (!HAVE_FUNC(VarI1FromI2))
72 #define START_REF_COUNT 1
73 #define RECORD_SIZE 64
74 #define RECORD_SIZE_FAIL 17
75 /************************************************************************
76 * Dummy IRecordInfo Implementation
78 typedef struct IRecordInfoImpl
80 const IRecordInfoVtbl
*lpvtbl
;
86 static const IRecordInfoVtbl IRecordInfoImpl_VTable
;
88 static IRecordInfoImpl
*IRecordInfoImpl_Construct(void)
92 rec
= HeapAlloc(GetProcessHeap(), 0, sizeof(IRecordInfoImpl
));
93 rec
->lpvtbl
= &IRecordInfoImpl_VTable
;
94 rec
->ref
= START_REF_COUNT
;
100 static ULONG CALLBACK
IRecordInfoImpl_AddRef(IRecordInfo
*iface
)
102 IRecordInfoImpl
* This
=(IRecordInfoImpl
*)iface
;
103 return InterlockedIncrement(&This
->ref
);
106 static ULONG CALLBACK
IRecordInfoImpl_Release(IRecordInfo
*iface
)
108 IRecordInfoImpl
* This
=(IRecordInfoImpl
*)iface
;
109 return InterlockedDecrement(&This
->ref
);
112 static BOOL fail_GetSize
; /* Whether to fail the GetSize call */
114 static HRESULT CALLBACK
IRecordInfoImpl_RecordClear(IRecordInfo
*iface
, PVOID pvExisting
)
116 IRecordInfoImpl
* This
=(IRecordInfoImpl
*)iface
;
121 static HRESULT CALLBACK
IRecordInfoImpl_GetSize(IRecordInfo
*iface
, ULONG
* size
)
123 IRecordInfoImpl
* This
=(IRecordInfoImpl
*)iface
;
132 static HRESULT CALLBACK
IRecordInfoImpl_Dummy(IRecordInfo
*iface
)
134 trace("Called an unexpected IRecordInfo method - please report!\n");
135 /* Quit because we'll just crash anyway */
140 static const IRecordInfoVtbl IRecordInfoImpl_VTable
=
142 (PVOID
)IRecordInfoImpl_Dummy
,
143 IRecordInfoImpl_AddRef
,
144 IRecordInfoImpl_Release
,
145 (PVOID
)IRecordInfoImpl_Dummy
,
146 IRecordInfoImpl_RecordClear
,
147 (PVOID
)IRecordInfoImpl_Dummy
,
148 (PVOID
)IRecordInfoImpl_Dummy
,
149 (PVOID
)IRecordInfoImpl_Dummy
,
150 (PVOID
)IRecordInfoImpl_GetSize
,
151 (PVOID
)IRecordInfoImpl_Dummy
,
152 (PVOID
)IRecordInfoImpl_Dummy
,
153 (PVOID
)IRecordInfoImpl_Dummy
,
154 (PVOID
)IRecordInfoImpl_Dummy
,
155 (PVOID
)IRecordInfoImpl_Dummy
,
156 (PVOID
)IRecordInfoImpl_Dummy
,
157 (PVOID
)IRecordInfoImpl_Dummy
,
158 (PVOID
)IRecordInfoImpl_Dummy
,
159 (PVOID
)IRecordInfoImpl_Dummy
,
160 (PVOID
)IRecordInfoImpl_Dummy
163 static DWORD
SAFEARRAY_GetVTSize(VARTYPE vt
)
168 case VT_UI1
: return sizeof(BYTE
);
171 case VT_UI2
: return sizeof(SHORT
);
175 case VT_ERROR
: return sizeof(LONG
);
177 if (HAVE_OLEAUT32_R8
)
178 return sizeof(LONG64
);
181 if (HAVE_OLEAUT32_I8
)
182 return sizeof(LONG64
);
185 case VT_UINT
: return sizeof(INT
);
188 if (HAVE_OLEAUT32_INT_PTR
)
189 return sizeof(UINT_PTR
);
191 case VT_CY
: return sizeof(CY
);
192 case VT_DATE
: return sizeof(DATE
);
193 case VT_BSTR
: return sizeof(BSTR
);
194 case VT_DISPATCH
: return sizeof(LPDISPATCH
);
195 case VT_VARIANT
: return sizeof(VARIANT
);
196 case VT_UNKNOWN
: return sizeof(LPUNKNOWN
);
198 if (HAVE_OLEAUT32_DECIMAL
)
199 return sizeof(DECIMAL
);
205 static void check_for_VT_INT_PTR(void)
207 /* Set a global flag if VT_INT_PTR is supported */
210 SAFEARRAYBOUND bound
;
213 a
= SafeArrayCreate(VT_INT_PTR
, 1, &bound
);
215 trace("VT_INT_PTR is supported\n");
216 HAVE_OLEAUT32_INT_PTR
= TRUE
;
220 trace("VT_INT_PTR is not supported\n");
221 HAVE_OLEAUT32_INT_PTR
= FALSE
;
225 #define VARTYPE_NOT_SUPPORTED 0
228 UINT elemsize
; /* elementsize by VT */
229 UINT expflags
; /* fFeatures from SafeArrayAllocDescriptorEx */
230 UINT addflags
; /* additional fFeatures from SafeArrayCreate */
232 {VT_EMPTY
, VARTYPE_NOT_SUPPORTED
,FADF_HAVEVARTYPE
,0},
233 {VT_NULL
, VARTYPE_NOT_SUPPORTED
,FADF_HAVEVARTYPE
,0},
234 {VT_I2
, 2, FADF_HAVEVARTYPE
,0},
235 {VT_I4
, 4, FADF_HAVEVARTYPE
,0},
236 {VT_R4
, 4, FADF_HAVEVARTYPE
,0},
237 {VT_R8
, 8, FADF_HAVEVARTYPE
,0},
238 {VT_CY
, 8, FADF_HAVEVARTYPE
,0},
239 {VT_DATE
, 8, FADF_HAVEVARTYPE
,0},
240 {VT_BSTR
, sizeof(BSTR
), FADF_HAVEVARTYPE
,FADF_BSTR
},
241 {VT_DISPATCH
, sizeof(LPDISPATCH
), FADF_HAVEIID
, FADF_DISPATCH
},
242 {VT_ERROR
, 4, FADF_HAVEVARTYPE
,0},
243 {VT_BOOL
, 2, FADF_HAVEVARTYPE
,0},
244 {VT_VARIANT
, sizeof(VARIANT
), FADF_HAVEVARTYPE
,FADF_VARIANT
},
245 {VT_UNKNOWN
, sizeof(LPUNKNOWN
), FADF_HAVEIID
, FADF_UNKNOWN
},
246 {VT_DECIMAL
, sizeof(DECIMAL
), FADF_HAVEVARTYPE
,0},
247 {15, VARTYPE_NOT_SUPPORTED
,FADF_HAVEVARTYPE
,0}, /* no VT_xxx */
248 {VT_I1
, 1, FADF_HAVEVARTYPE
,0},
249 {VT_UI1
, 1, FADF_HAVEVARTYPE
,0},
250 {VT_UI2
, 2, FADF_HAVEVARTYPE
,0},
251 {VT_UI4
, 4, FADF_HAVEVARTYPE
,0},
252 {VT_I8
, VARTYPE_NOT_SUPPORTED
,FADF_HAVEVARTYPE
,0},
253 {VT_UI8
, VARTYPE_NOT_SUPPORTED
,FADF_HAVEVARTYPE
,0},
254 {VT_INT
, sizeof(INT
), FADF_HAVEVARTYPE
,0},
255 {VT_UINT
, sizeof(UINT
), FADF_HAVEVARTYPE
,0},
256 {VT_VOID
, VARTYPE_NOT_SUPPORTED
,FADF_HAVEVARTYPE
,0},
257 {VT_HRESULT
, VARTYPE_NOT_SUPPORTED
,FADF_HAVEVARTYPE
,0},
258 {VT_PTR
, VARTYPE_NOT_SUPPORTED
,FADF_HAVEVARTYPE
,0},
259 {VT_SAFEARRAY
,VARTYPE_NOT_SUPPORTED
,FADF_HAVEVARTYPE
,0},
260 {VT_CARRAY
, VARTYPE_NOT_SUPPORTED
,FADF_HAVEVARTYPE
,0},
261 {VT_USERDEFINED
,VARTYPE_NOT_SUPPORTED
,FADF_HAVEVARTYPE
,0},
262 {VT_LPSTR
, VARTYPE_NOT_SUPPORTED
,FADF_HAVEVARTYPE
,0},
263 {VT_LPWSTR
, VARTYPE_NOT_SUPPORTED
,FADF_HAVEVARTYPE
,0},
264 {VT_FILETIME
, VARTYPE_NOT_SUPPORTED
,FADF_HAVEVARTYPE
,0},
265 {VT_RECORD
, VARTYPE_NOT_SUPPORTED
,FADF_RECORD
,0},
266 {VT_BLOB
, VARTYPE_NOT_SUPPORTED
,FADF_HAVEVARTYPE
,0},
267 {VT_STREAM
, VARTYPE_NOT_SUPPORTED
,FADF_HAVEVARTYPE
,0},
268 {VT_STORAGE
, VARTYPE_NOT_SUPPORTED
,FADF_HAVEVARTYPE
,0},
269 {VT_STREAMED_OBJECT
,VARTYPE_NOT_SUPPORTED
,FADF_HAVEVARTYPE
,0},
270 {VT_STORED_OBJECT
,VARTYPE_NOT_SUPPORTED
,FADF_HAVEVARTYPE
,0},
271 {VT_BLOB_OBJECT
,VARTYPE_NOT_SUPPORTED
,FADF_HAVEVARTYPE
,0},
272 {VT_CF
, VARTYPE_NOT_SUPPORTED
,FADF_HAVEVARTYPE
,0},
273 {VT_CLSID
, VARTYPE_NOT_SUPPORTED
,FADF_HAVEVARTYPE
,0},
276 static void test_safearray(void)
282 SAFEARRAYBOUND bound
, bounds
[2];
288 unsigned char *ptr1
, *ptr2
;
290 hres
= SafeArrayDestroy( NULL
);
291 ok( hres
== S_OK
, "SafeArrayDestroy( NULL) returned 0x%x\n", hres
);
295 a
= SafeArrayCreate(-1, 1, &bound
);
296 ok(NULL
== a
,"SAC(-1,1,[1,0]) not failed?\n");
300 a
= SafeArrayCreate(VT_I4
, 1, &bound
);
301 ok(NULL
!= a
,"SAC(VT_I4,1,[0,0]) failed.\n");
303 hres
= SafeArrayGetLBound(a
, 1, &l
);
304 ok(hres
== S_OK
, "SAGLB of 0 size dimensioned array failed with %x\n",hres
);
305 ok(l
== 42, "SAGLB of 0 size dimensioned array failed to return 42, but returned %d\n",l
);
306 hres
= SafeArrayGetUBound(a
, 1, &l
);
307 ok(hres
== S_OK
, "SAGUB of 0 size dimensioned array failed with %x\n",hres
);
308 ok(l
== 41, "SAGUB of 0 size dimensioned array failed to return 41, but returned %d\n",l
);
310 hres
= SafeArrayAccessData(a
, &data
);
311 ok(hres
== S_OK
, "SafeArrayAccessData of 0 size dimensioned array failed with %x\n", hres
);
312 SafeArrayUnaccessData(a
);
315 hres
= SafeArrayRedim(a
, &bound
);
316 ok(hres
== S_OK
,"SAR of a 0 elements dimension failed with hres %x\n", hres
);
318 hres
= SafeArrayRedim(a
, &bound
);
319 ok(hres
== S_OK
|| hres
== E_OUTOFMEMORY
,
320 "SAR to a 0 elements dimension failed with hres %x\n", hres
);
321 hres
= SafeArrayDestroy(a
);
322 ok(hres
== S_OK
,"SAD of 0 dim array faild with hres %x\n", hres
);
324 SafeArrayAllocDescriptor(2, &a
);
325 a
->rgsabound
[0].cElements
= 2;
326 a
->rgsabound
[0].lLbound
= 1;
327 a
->rgsabound
[1].cElements
= 4;
328 a
->rgsabound
[1].lLbound
= 1;
330 SafeArrayAllocData(a
);
334 hres
= SafeArrayPtrOfIndex(a
, indices
, (void **)&ptr1
);
335 ok(hres
== S_OK
, "SAPOI failed with hres %x\n", hres
);
336 SafeArrayAccessData(a
, (void **)&ptr2
);
337 ok(ptr1
- ptr2
== 14, "SAPOI got wrong ptr\n");
338 *(WORD
*)ptr1
= 0x55aa;
339 SafeArrayUnaccessData(a
);
341 bound
.cElements
= 10;
343 SafeArrayRedim(a
, &bound
);
345 SafeArrayPtrOfIndex(a
, indices
, (void **)&ptr1
);
346 ok(*(WORD
*)ptr1
== 0x55aa, "Data not preserved when resizing array\n");
348 bound
.cElements
= 10;
350 SafeArrayRedim(a
, &bound
);
351 SafeArrayPtrOfIndex(a
, indices
, (void **)&ptr1
);
352 ok(*(WORD
*)ptr1
== 0, "Expanded area not zero-initialized\n");
355 SafeArrayPtrOfIndex(a
, indices
, (void **)&ptr1
);
356 ok(*(WORD
*)ptr1
== 0x55aa, "Data not preserved when resizing array\n");
358 bounds
[0].cElements
= 0; bounds
[0].lLbound
= 1;
359 bounds
[1].cElements
= 2; bounds
[1].lLbound
= 23;
360 a
= SafeArrayCreate(VT_I4
,2,bounds
);
361 ok(a
!= NULL
,"SAC(VT_INT32,2,...) with 0 element dim failed.\n");
362 bounds
[0].cElements
= 1; bounds
[0].lLbound
= 1;
363 bounds
[1].cElements
= 0; bounds
[1].lLbound
= 23;
364 a
= SafeArrayCreate(VT_I4
,2,bounds
);
365 ok(a
!= NULL
,"SAC(VT_INT32,2,...) with 0 element dim failed.\n");
367 bounds
[0].cElements
= 42; bounds
[0].lLbound
= 1;
368 bounds
[1].cElements
= 2; bounds
[1].lLbound
= 23;
369 a
= SafeArrayCreate(VT_I4
,2,bounds
);
370 ok(a
!= NULL
,"SAC(VT_INT32,2,...) failed.\n");
372 hres
= SafeArrayGetLBound (a
, 0, &l
);
373 ok (hres
== DISP_E_BADINDEX
, "SAGLB 0 failed with %x\n", hres
);
374 hres
= SafeArrayGetLBound (a
, 1, &l
);
375 ok (hres
== S_OK
, "SAGLB 1 failed with %x\n", hres
);
376 ok (l
== 1, "SAGLB 1 returned %d instead of 1\n", l
);
377 hres
= SafeArrayGetLBound (a
, 2, &l
);
378 ok (hres
== S_OK
, "SAGLB 2 failed with %x\n", hres
);
379 ok (l
== 23, "SAGLB 2 returned %d instead of 23\n", l
);
380 hres
= SafeArrayGetLBound (a
, 3, &l
);
381 ok (hres
== DISP_E_BADINDEX
, "SAGLB 3 failed with %x\n", hres
);
383 hres
= SafeArrayGetUBound (a
, 0, &l
);
384 ok (hres
== DISP_E_BADINDEX
, "SAGUB 0 failed with %x\n", hres
);
385 hres
= SafeArrayGetUBound (a
, 1, &l
);
386 ok (hres
== S_OK
, "SAGUB 1 failed with %x\n", hres
);
387 ok (l
== 42, "SAGUB 1 returned %d instead of 42\n", l
);
388 hres
= SafeArrayGetUBound (a
, 2, &l
);
389 ok (hres
== S_OK
, "SAGUB 2 failed with %x\n", hres
);
390 ok (l
== 24, "SAGUB 2 returned %d instead of 24\n", l
);
391 hres
= SafeArrayGetUBound (a
, 3, &l
);
392 ok (hres
== DISP_E_BADINDEX
, "SAGUB 3 failed with %x\n", hres
);
394 i
= SafeArrayGetDim(a
);
395 ok(i
== 2, "getdims of 2 din array returned %d\n",i
);
399 hres
= SafeArrayGetElement(a
, indices
, &i
);
400 ok(DISP_E_BADINDEX
== hres
,"SAGE failed [0,23], hres 0x%x\n",hres
);
404 hres
= SafeArrayGetElement(a
, indices
, &i
);
405 ok(DISP_E_BADINDEX
== hres
,"SAGE failed [1,22], hres 0x%x\n",hres
);
409 hres
= SafeArrayGetElement(a
, indices
, &i
);
410 ok(S_OK
== hres
,"SAGE failed [1,23], hres 0x%x\n",hres
);
414 hres
= SafeArrayGetElement(a
, indices
, &i
);
415 ok(DISP_E_BADINDEX
== hres
,"SAGE failed [1,24], hres 0x%x\n",hres
);
419 hres
= SafeArrayGetElement(a
, indices
, &i
);
420 ok(S_OK
== hres
,"SAGE failed [42,23], hres 0x%x\n",hres
);
422 hres
= SafeArrayAccessData(a
, (void**)&ptr1
);
423 ok(S_OK
== hres
, "SAAD failed with 0x%x\n", hres
);
427 hres
= SafeArrayPtrOfIndex(a
, indices
, (void**)&ptr2
);
428 ok(S_OK
== hres
,"SAPOI failed [1,23], hres 0x%x\n",hres
);
429 ok(ptr2
- ptr1
== 8,"ptr difference is not 8, but %d (%p vs %p)\n", ptr2
-ptr1
, ptr2
, ptr1
);
433 hres
= SafeArrayPtrOfIndex(a
, indices
, (void**)&ptr2
);
434 ok(S_OK
== hres
,"SAPOI failed [5,24], hres 0x%x\n",hres
);
435 ok(ptr2
- ptr1
== 176,"ptr difference is not 176, but %d (%p vs %p)\n", ptr2
-ptr1
, ptr2
, ptr1
);
439 hres
= SafeArrayPtrOfIndex(a
, indices
, (void**)&ptr2
);
440 ok(S_OK
== hres
,"SAPOI failed [20,23], hres 0x%x\n",hres
);
441 ok(ptr2
- ptr1
== 76,"ptr difference is not 76, but %d (%p vs %p)\n", ptr2
-ptr1
, ptr2
, ptr1
);
443 hres
= SafeArrayUnaccessData(a
);
444 ok(S_OK
== hres
, "SAUAD failed with 0x%x\n", hres
);
446 for (i
=0;i
<sizeof(vttypes
)/sizeof(vttypes
[0]);i
++) {
447 if ((i
== VT_I8
|| i
== VT_UI8
) && HAVE_OLEAUT32_I8
)
449 vttypes
[i
].elemsize
= sizeof(LONG64
);
452 a
= SafeArrayCreate(vttypes
[i
].vt
, 1, &bound
);
454 ok((!a
&& !vttypes
[i
].elemsize
) ||
455 (a
&& vttypes
[i
].elemsize
== a
->cbElements
) ||
456 (IS_ANCIENT
&& (vttypes
[i
].vt
== VT_DECIMAL
|| vttypes
[i
].vt
== VT_I1
||
457 vttypes
[i
].vt
== VT_UI2
|| vttypes
[i
].vt
== VT_UI4
|| vttypes
[i
].vt
== VT_INT
||
458 vttypes
[i
].vt
== VT_UINT
)),
459 "SAC(%d,1,[1,0]), %p result %d, expected %d\n",
460 vttypes
[i
].vt
,a
,(a
?a
->cbElements
:0),vttypes
[i
].elemsize
);
464 if (!HAVE_OLEAUT32_RECORD
)
465 vttypes
[i
].expflags
= 0;
466 ok(a
->fFeatures
== (vttypes
[i
].expflags
| vttypes
[i
].addflags
),
467 "SAC of %d returned feature flags %x, expected %x\n",
468 vttypes
[i
].vt
, a
->fFeatures
,
469 vttypes
[i
].expflags
|vttypes
[i
].addflags
);
470 ok(SafeArrayGetElemsize(a
) == vttypes
[i
].elemsize
,
471 "SAGE for vt %d returned elemsize %d instead of expected %d\n",
472 vttypes
[i
].vt
, SafeArrayGetElemsize(a
),vttypes
[i
].elemsize
);
477 if (pSafeArrayGetVartype
)
479 hres
= pSafeArrayGetVartype(a
, &vt
);
480 ok(hres
== S_OK
, "SAGVT of arra y with vt %d failed with %x\n", vttypes
[i
].vt
, hres
);
481 if (vttypes
[i
].vt
== VT_DISPATCH
) {
482 /* Special case. Checked against Windows. */
483 ok(vt
== VT_UNKNOWN
, "SAGVT of a rray with VT_DISPATCH returned not VT_UNKNOWN, but %d\n", vt
);
485 ok(vt
== vttypes
[i
].vt
, "SAGVT of array with vt %d returned %d\n", vttypes
[i
].vt
, vt
);
489 hres
= SafeArrayCopy(a
, &c
);
490 ok(hres
== S_OK
, "failed to copy safearray of vt %d with hres %x\n", vttypes
[i
].vt
, hres
);
492 ok(vttypes
[i
].elemsize
== c
->cbElements
,"copy of SAC(%d,1,[1,0]), result %d, expected %d\n",vttypes
[i
].vt
,(c
?c
->cbElements
:0),vttypes
[i
].elemsize
494 ok(c
->fFeatures
== (vttypes
[i
].expflags
| vttypes
[i
].addflags
),"SAC of %d returned feature flags %x, expected %x\n", vttypes
[i
].vt
, c
->fFeatures
, vttypes
[i
].expflags
|vttypes
[i
].addflags
);
495 ok(SafeArrayGetElemsize(c
) == vttypes
[i
].elemsize
,"SAGE for vt %d returned elemsize %d instead of expected %d\n",vttypes
[i
].vt
, SafeArrayGetElemsize(c
),vttypes
[i
].elemsize
);
497 if (pSafeArrayGetVartype
) {
498 hres
= pSafeArrayGetVartype(c
, &vt
);
499 ok(hres
== S_OK
, "SAGVT of array with vt %d failed with %x\n", vttypes
[i
].vt
, hres
);
500 if (vttypes
[i
].vt
== VT_DISPATCH
) {
501 /* Special case. Checked against Windows. */
502 ok(vt
== VT_UNKNOWN
, "SAGVT of array with VT_DISPATCH returned not VT_UNKNOWN, but %d\n", vt
);
504 ok(vt
== vttypes
[i
].vt
, "SAGVT of array with vt %d returned %d\n", vttypes
[i
].vt
, vt
);
508 if (pSafeArrayCopyData
) {
509 hres
= pSafeArrayCopyData(a
, c
);
510 ok(hres
== S_OK
, "failed to copy safearray data of vt %d with hres %x\n", vttypes
[i
].vt
, hres
);
512 hres
= SafeArrayDestroyData(c
);
513 ok(hres
== S_OK
,"SADD of copy of array with vt %d failed with hres %x\n", vttypes
[i
].vt
, hres
);
516 hres
= SafeArrayDestroy(a
);
517 ok(hres
== S_OK
,"SAD of array with vt %d failed with hres %x\n", vttypes
[i
].vt
, hres
);
520 /* Test conversion of type|VT_ARRAY <-> VT_BSTR */
522 bound
.cElements
= 10;
523 a
= SafeArrayCreate(VT_UI1
, 1, &bound
);
524 ok(a
!= NULL
, "SAC failed.\n");
525 ok(S_OK
== SafeArrayAccessData(a
, &data
),"SACD failed\n");
526 memcpy(data
,"Hello World\n",10);
527 ok(S_OK
== SafeArrayUnaccessData(a
),"SAUD failed\n");
528 V_VT(&v
) = VT_ARRAY
|VT_UI1
;
530 hres
= VariantChangeTypeEx(&v
, &v
, 0, 0, VT_BSTR
);
531 ok(hres
==S_OK
, "CTE VT_ARRAY|VT_UI1 -> VT_BSTR failed with %x\n",hres
);
532 ok(V_VT(&v
) == VT_BSTR
,"CTE VT_ARRAY|VT_UI1 -> VT_BSTR did not return VT_BSTR, but %d.v\n",V_VT(&v
));
533 ok(V_BSTR(&v
)[0] == 0x6548,"First letter are not 'He', but %x\n", V_BSTR(&v
)[0]);
535 /* check locking functions */
536 a
= SafeArrayCreate(VT_I4
, 1, &bound
);
537 ok(a
!=NULL
,"SAC should not fail\n");
539 hres
= SafeArrayAccessData(a
, &data
);
540 ok(hres
== S_OK
,"SAAD failed with hres %x\n",hres
);
542 hres
= SafeArrayDestroy(a
);
543 ok(hres
== DISP_E_ARRAYISLOCKED
,"locked safe array destroy not failed with DISP_E_ARRAYISLOCKED, but with hres %x\n", hres
);
545 hres
= SafeArrayDestroyData(a
);
546 ok(hres
== DISP_E_ARRAYISLOCKED
,"locked safe array destroy data not failed with DISP_E_ARRAYISLOCKED, but with hres %x\n", hres
);
548 hres
= SafeArrayDestroyDescriptor(a
);
549 ok(hres
== DISP_E_ARRAYISLOCKED
,"locked safe array destroy descriptor not failed with DISP_E_ARRAYISLOCKED, but with hres %x\n", hres
);
551 hres
= SafeArrayUnaccessData(a
);
552 ok(hres
== S_OK
,"SAUD failed after lock/destroy test\n");
554 hres
= SafeArrayDestroy(a
);
555 ok(hres
== S_OK
,"SAD failed after lock/destroy test\n");
557 /* Test if we need to destroy data before descriptor */
558 a
= SafeArrayCreate(VT_I4
, 1, &bound
);
559 ok(a
!=NULL
,"SAC should not fail\n");
560 hres
= SafeArrayDestroyDescriptor(a
);
561 ok(hres
== S_OK
,"SADD with data in array failed with hres %x\n",hres
);
565 /* init a small stack safearray */
566 if (pSafeArraySetIID
) {
567 memset(&b
, 0, sizeof(b
));
569 memset(&iid
, 0x42, sizeof(IID
));
570 hres
= pSafeArraySetIID(&b
,&iid
);
571 ok(hres
== E_INVALIDARG
,"SafeArraySetIID of non IID capable safearray did not return E_INVALIDARG, but %x\n",hres
);
573 hres
= SafeArrayAllocDescriptor(1,&a
);
574 ok((a
->fFeatures
& FADF_HAVEIID
) == 0,"newly allocated descriptor with SAAD should not have FADF_HAVEIID\n");
575 hres
= pSafeArraySetIID(a
,&iid
);
576 ok(hres
== E_INVALIDARG
,"SafeArraySetIID of newly allocated descriptor with SAAD should return E_INVALIDARG, but %x\n",hres
);
579 if (!pSafeArrayAllocDescriptorEx
)
582 for (i
=0;i
<sizeof(vttypes
)/sizeof(vttypes
[0]);i
++) {
584 hres
= pSafeArrayAllocDescriptorEx(vttypes
[i
].vt
,1,&a
);
585 ok(a
->fFeatures
== vttypes
[i
].expflags
,"SAADE(%d) resulted with flags %x, expected %x\n", vttypes
[i
].vt
, a
->fFeatures
, vttypes
[i
].expflags
);
586 if (a
->fFeatures
& FADF_HAVEIID
) {
587 hres
= pSafeArrayGetIID(a
, &iid
);
588 ok(hres
== S_OK
,"SAGIID failed for vt %d with hres %x\n", vttypes
[i
].vt
,hres
);
589 switch (vttypes
[i
].vt
) {
591 ok(IsEqualGUID(((GUID
*)a
)-1,&IID_IUnknown
),"guid for VT_UNKNOWN is not IID_IUnknown\n");
592 ok(IsEqualGUID(&iid
, &IID_IUnknown
),"SAGIID returned wrong GUID for IUnknown\n");
595 ok(IsEqualGUID(((GUID
*)a
)-1,&IID_IDispatch
),"guid for VT_UNKNOWN is not IID_IDispatch\n");
596 ok(IsEqualGUID(&iid
, &IID_IDispatch
),"SAGIID returned wrong GUID for IDispatch\n");
599 ok(FALSE
,"unknown vt %d with FADF_HAVEIID\n",vttypes
[i
].vt
);
603 hres
= pSafeArrayGetIID(a
, &iid
);
604 ok(hres
== E_INVALIDARG
,"SAGIID did not fail for vt %d with hres %x\n", vttypes
[i
].vt
,hres
);
606 if (a
->fFeatures
& FADF_RECORD
) {
607 ok(vttypes
[i
].vt
== VT_RECORD
,"FADF_RECORD for non record %d\n",vttypes
[i
].vt
);
609 if (a
->fFeatures
& FADF_HAVEVARTYPE
) {
610 ok(vttypes
[i
].vt
== ((DWORD
*)a
)[-1], "FADF_HAVEVARTYPE set, but vt %d mismatch stored %d\n",vttypes
[i
].vt
,((DWORD
*)a
)[-1]);
613 hres
= pSafeArrayGetVartype(a
, &vt
);
614 ok(hres
== S_OK
, "SAGVT of array with vt %d failed with %x\n", vttypes
[i
].vt
, hres
);
616 if (vttypes
[i
].vt
== VT_DISPATCH
) {
617 /* Special case. Checked against Windows. */
618 ok(vt
== VT_UNKNOWN
, "SAGVT of array with VT_DISPATCH returned not VT_UNKNOWN, but %d\n", vt
);
620 ok(vt
== vttypes
[i
].vt
, "SAGVT of array with vt %d returned %d\n", vttypes
[i
].vt
, vt
);
623 if (a
->fFeatures
& FADF_HAVEIID
) {
624 hres
= pSafeArraySetIID(a
, &IID_IStorage
); /* random IID */
625 ok(hres
== S_OK
,"SASIID failed with FADF_HAVEIID set for vt %d with %x\n", vttypes
[i
].vt
, hres
);
626 hres
= pSafeArrayGetIID(a
, &iid
);
627 ok(hres
== S_OK
,"SAGIID failed with FADF_HAVEIID set for vt %d with %x\n", vttypes
[i
].vt
, hres
);
628 ok(IsEqualGUID(&iid
, &IID_IStorage
),"returned iid is not IID_IStorage\n");
630 hres
= pSafeArraySetIID(a
, &IID_IStorage
); /* random IID */
631 ok(hres
== E_INVALIDARG
,"SASIID did not failed with !FADF_HAVEIID set for vt %d with %x\n", vttypes
[i
].vt
, hres
);
633 hres
= SafeArrayDestroyDescriptor(a
);
634 ok(hres
== S_OK
,"SADD failed with hres %x\n",hres
);
638 static void test_SafeArrayAllocDestroyDescriptor(void)
645 hres
= SafeArrayAllocDescriptor(0, &sa
);
646 ok(hres
== E_INVALIDARG
, "0 dimensions gave hres 0x%x\n", hres
);
648 hres
= SafeArrayAllocDescriptor(65536, &sa
);
649 ok(IS_ANCIENT
|| hres
== E_INVALIDARG
,
650 "65536 dimensions gave hres 0x%x\n", hres
);
654 /* Crashes on 95: XP & Wine return E_POINTER */
655 hres
=SafeArrayAllocDescriptor(1, NULL
);
656 ok(hres
== E_POINTER
,"NULL parm gave hres 0x%x\n", hres
);
659 /* Test up to the dimension boundary case */
660 for (i
= 5; i
<= 65535; i
+= 30)
662 hres
= SafeArrayAllocDescriptor(i
, &sa
);
663 ok(hres
== S_OK
, "%d dimensions failed; hres 0x%x\n", i
, hres
);
667 ok(SafeArrayGetDim(sa
) == (UINT
)i
, "Dimension is %d; should be %d\n",
668 SafeArrayGetDim(sa
), i
);
670 hres
= SafeArrayDestroyDescriptor(sa
);
671 ok(hres
== S_OK
, "destroy failed; hres 0x%x\n", hres
);
675 if (!pSafeArrayAllocDescriptorEx
)
678 hres
= pSafeArrayAllocDescriptorEx(VT_UI1
, 0, &sa
);
679 ok(hres
== E_INVALIDARG
, "0 dimensions gave hres 0x%x\n", hres
);
681 hres
= pSafeArrayAllocDescriptorEx(VT_UI1
, 65536, &sa
);
682 ok(hres
== E_INVALIDARG
, "65536 dimensions gave hres 0x%x\n", hres
);
684 hres
= pSafeArrayAllocDescriptorEx(VT_UI1
, 1, NULL
);
685 ok(hres
== E_POINTER
,"NULL parm gave hres 0x%x\n", hres
);
687 hres
= pSafeArrayAllocDescriptorEx(-1, 1, &sa
);
688 ok(hres
== S_OK
, "VT = -1 gave hres 0x%x\n", hres
);
690 sa
->rgsabound
[0].cElements
= 0;
691 sa
->rgsabound
[0].lLbound
= 1;
693 hres
= SafeArrayAllocData(sa
);
694 ok(hres
== S_OK
, "SafeArrayAllocData gave hres 0x%x\n", hres
);
697 static void test_SafeArrayCreateLockDestroy(void)
699 SAFEARRAYBOUND sab
[4];
705 #define NUM_DIMENSIONS (int)(sizeof(sab) / sizeof(sab[0]))
707 for (dimension
= 0; dimension
< NUM_DIMENSIONS
; dimension
++)
709 sab
[dimension
].lLbound
= 0;
710 sab
[dimension
].cElements
= 8;
714 /* This test crashes very early versions with no error checking...
715 sa = SafeArrayCreate(VT_UI1, 1, NULL);
716 ok(sa == NULL, "NULL bounds didn't fail\n");
718 sa
= SafeArrayCreate(VT_UI1
, 65536, sab
);
719 ok(IS_ANCIENT
|| !sa
, "Max bounds didn't fail\n");
721 memset(sab
, 0, sizeof(sab
));
723 /* Don't test 0 sized dimensions, as Windows has a bug which allows this */
725 for (dimension
= 0; dimension
< NUM_DIMENSIONS
; dimension
++)
726 sab
[dimension
].cElements
= 8;
728 /* Test all VARTYPES in 1-4 dimensions */
729 for (dimension
= 1; dimension
< 4; dimension
++)
731 for (vt
= VT_EMPTY
; vt
< VT_CLSID
; vt
++)
733 DWORD dwLen
= SAFEARRAY_GetVTSize(vt
);
735 sa
= SafeArrayCreate(vt
, dimension
, sab
);
738 ok(sa
|| (IS_ANCIENT
&& (vt
== VT_DECIMAL
|| vt
== VT_I1
|| vt
== VT_UI2
||
739 vt
== VT_UI4
|| vt
== VT_INT
|| vt
== VT_UINT
)),
740 "VARTYPE %d (@%d dimensions) failed\n", vt
, dimension
);
742 ok(sa
== NULL
|| vt
== VT_R8
,
743 "VARTYPE %d (@%d dimensions) succeeded!\n", vt
, dimension
);
747 ok(SafeArrayGetDim(sa
) == (UINT
)dimension
,
748 "VARTYPE %d (@%d dimensions) cDims is %d, expected %d\n",
749 vt
, dimension
, SafeArrayGetDim(sa
), dimension
);
750 ok(SafeArrayGetElemsize(sa
) == dwLen
|| vt
== VT_R8
,
751 "VARTYPE %d (@%d dimensions) cbElements is %d, expected %d\n",
752 vt
, dimension
, SafeArrayGetElemsize(sa
), dwLen
);
754 if (vt
!= VT_UNKNOWN
&& vt
!= VT_DISPATCH
)
756 ok((sa
->fFeatures
& FADF_HAVEIID
) == 0,
757 "Non interface type should not have FADF_HAVEIID\n");
758 if (pSafeArraySetIID
)
760 hres
= pSafeArraySetIID(sa
, &IID_IUnknown
);
761 ok(hres
== E_INVALIDARG
,
762 "Non interface type allowed SetIID(), hres %x\n", hres
);
768 ok(IS_ANCIENT
|| sa
->fFeatures
& FADF_HAVEVARTYPE
,
769 "Non interface type should have FADF_HAVEVARTYPE\n");
770 if (pSafeArrayGetVartype
)
772 hres
= pSafeArrayGetVartype(sa
, &aVt
);
773 ok(hres
== S_OK
&& aVt
== vt
,
774 "Non interface type %d: bad type %d, hres %x\n", vt
, aVt
, hres
);
780 ok(IS_ANCIENT
|| sa
->fFeatures
& FADF_HAVEIID
,
781 "Interface type should have FADF_HAVEIID\n");
782 if (pSafeArraySetIID
)
784 hres
= pSafeArraySetIID(sa
, &IID_IUnknown
);
786 "Non interface type disallowed SetIID(), hres %x\n", hres
);
788 ok((sa
->fFeatures
& FADF_HAVEVARTYPE
) == 0,
789 "Interface type %d should not have FADF_HAVEVARTYPE\n", vt
);
792 hres
= SafeArrayLock(sa
);
793 ok(hres
== S_OK
, "Lock VARTYPE %d (@%d dimensions) failed; hres 0x%x\n",
794 vt
, dimension
, hres
);
798 hres
= SafeArrayDestroy(sa
);
799 ok(hres
== DISP_E_ARRAYISLOCKED
,"Destroy() got hres %x\n", hres
);
801 hres
= SafeArrayDestroyData(sa
);
802 ok(hres
== DISP_E_ARRAYISLOCKED
,"DestroyData() got hres %x\n", hres
);
804 hres
= SafeArrayDestroyDescriptor(sa
);
805 ok(hres
== DISP_E_ARRAYISLOCKED
,"DestroyDescriptor() got hres %x\n", hres
);
807 hres
= SafeArrayUnlock(sa
);
808 ok(hres
== S_OK
, "Unlock VARTYPE %d (@%d dims) hres 0x%x\n",
809 vt
, dimension
, hres
);
811 hres
= SafeArrayDestroyDescriptor(sa
);
812 ok(hres
== S_OK
, "destroy VARTYPE %d (@%d dims) hres 0x%x\n",
813 vt
, dimension
, hres
);
820 static void test_VectorCreateLockDestroy(void)
827 if (!pSafeArrayCreateVector
)
829 sa
= pSafeArrayCreateVector(VT_UI1
, 0, 0);
830 ok(sa
!= NULL
, "SACV with 0 elements failed.\n");
832 /* Test all VARTYPES in different lengths */
833 for (element
= 1; element
<= 101; element
+= 10)
835 for (vt
= VT_EMPTY
; vt
< VT_CLSID
; vt
++)
837 DWORD dwLen
= SAFEARRAY_GetVTSize(vt
);
839 sa
= pSafeArrayCreateVector(vt
, 0, element
);
842 ok(sa
!= NULL
, "VARTYPE %d (@%d elements) failed\n", vt
, element
);
844 ok(sa
== NULL
, "VARTYPE %d (@%d elements) succeeded!\n", vt
, element
);
848 ok(SafeArrayGetDim(sa
) == 1, "VARTYPE %d (@%d elements) cDims %d, not 1\n",
849 vt
, element
, SafeArrayGetDim(sa
));
850 ok(SafeArrayGetElemsize(sa
) == dwLen
,
851 "VARTYPE %d (@%d elements) cbElements is %d, expected %d\n",
852 vt
, element
, SafeArrayGetElemsize(sa
), dwLen
);
854 hres
= SafeArrayLock(sa
);
855 ok(hres
== S_OK
, "Lock VARTYPE %d (@%d elements) failed; hres 0x%x\n",
860 hres
= SafeArrayUnlock(sa
);
861 ok(hres
== S_OK
, "Unlock VARTYPE %d (@%d elements) failed; hres 0x%x\n",
864 hres
= SafeArrayDestroyDescriptor(sa
);
865 ok(hres
== S_OK
, "destroy VARTYPE %d (@%d elements) failed; hres 0x%x\n",
873 static void test_LockUnlock(void)
875 SAFEARRAYBOUND sab
[4];
878 BOOL bVector
= FALSE
;
882 hres
= SafeArrayLock(NULL
);
883 ok(hres
== E_INVALIDARG
, "Lock NULL array hres 0x%x\n", hres
);
884 hres
= SafeArrayUnlock(NULL
);
885 ok(hres
== E_INVALIDARG
, "Lock NULL array hres 0x%x\n", hres
);
887 for (dimension
= 0; dimension
< NUM_DIMENSIONS
; dimension
++)
889 sab
[dimension
].lLbound
= 0;
890 sab
[dimension
].cElements
= 8;
893 sa
= SafeArrayCreate(VT_UI1
, NUM_DIMENSIONS
, sab
);
895 /* Test maximum locks */
896 test_LockUnlock_Vector
:
901 hres
= SafeArrayUnlock(sa
);
902 ok (hres
== E_UNEXPECTED
, "Bad %sUnlock gave hres 0x%x\n",
903 bVector
? "vector " : "\n", hres
);
905 while ((hres
= SafeArrayLock(sa
)) == S_OK
)
907 ok (count
== 65535 && hres
== E_UNEXPECTED
, "Lock %sfailed at %d; hres 0x%x\n",
908 bVector
? "vector " : "\n", count
, hres
);
910 if (count
== 65535 && hres
== E_UNEXPECTED
)
912 while ((hres
= SafeArrayUnlock(sa
)) == S_OK
)
914 ok (count
== 0 && hres
== E_UNEXPECTED
, "Unlock %sfailed at %d; hres 0x%x\n",
915 bVector
? "vector " : "\n", count
, hres
);
918 SafeArrayDestroy(sa
);
921 if (bVector
== FALSE
&& pSafeArrayCreateVector
)
923 /* Test again with a vector */
924 sa
= pSafeArrayCreateVector(VT_UI1
, 0, 100);
926 goto test_LockUnlock_Vector
;
930 static void test_SafeArrayGetPutElement(void)
932 SAFEARRAYBOUND sab
[4];
933 LONG indices
[NUM_DIMENSIONS
];
936 int value
= 0, gotvalue
, dimension
;
937 unsigned int x
,y
,z
,a
;
939 for (dimension
= 0; dimension
< NUM_DIMENSIONS
; dimension
++)
941 sab
[dimension
].lLbound
= dimension
* 2 + 1;
942 sab
[dimension
].cElements
= dimension
* 3 + 1;
945 sa
= SafeArrayCreate(VT_INT
, NUM_DIMENSIONS
, sab
);
947 return; /* Some early versions can't handle > 3 dims */
949 ok(sa
->cbElements
== sizeof(value
), "int size mismatch\n");
950 if (sa
->cbElements
!= sizeof(value
))
954 for (x
= 0; x
< NUM_DIMENSIONS
; x
++)
956 indices
[0] = sab
[0].lLbound
;
957 indices
[1] = sab
[1].lLbound
;
958 indices
[2] = sab
[2].lLbound
;
959 indices
[3] = sab
[3].lLbound
;
961 indices
[x
] = indices
[x
] - 1;
962 hres
= SafeArrayPutElement(sa
, indices
, &value
);
963 ok(hres
== DISP_E_BADINDEX
, "Put allowed too small index in dimension %d\n", x
);
964 hres
= SafeArrayGetElement(sa
, indices
, &value
);
965 ok(hres
== DISP_E_BADINDEX
, "Get allowed too small index in dimension %d\n", x
);
967 indices
[x
] = sab
[x
].lLbound
+ sab
[x
].cElements
;
968 hres
= SafeArrayPutElement(sa
, indices
, &value
);
969 ok(hres
== DISP_E_BADINDEX
, "Put allowed too big index in dimension %d\n", x
);
970 hres
= SafeArrayGetElement(sa
, indices
, &value
);
971 ok(hres
== DISP_E_BADINDEX
, "Get allowed too big index in dimension %d\n", x
);
974 indices
[0] = sab
[0].lLbound
;
975 indices
[1] = sab
[1].lLbound
;
976 indices
[2] = sab
[2].lLbound
;
977 indices
[3] = sab
[3].lLbound
;
979 hres
= SafeArrayPutElement(NULL
, indices
, &value
);
980 ok(hres
== E_INVALIDARG
, "Put NULL array hres 0x%x\n", hres
);
981 hres
= SafeArrayGetElement(NULL
, indices
, &value
);
982 ok(hres
== E_INVALIDARG
, "Get NULL array hres 0x%x\n", hres
);
984 hres
= SafeArrayPutElement(sa
, NULL
, &value
);
985 ok(hres
== E_INVALIDARG
, "Put NULL indices hres 0x%x\n", hres
);
986 hres
= SafeArrayGetElement(sa
, NULL
, &value
);
987 ok(hres
== E_INVALIDARG
, "Get NULL indices hres 0x%x\n", hres
);
991 /* This is retarded. Windows checks every case of invalid parameters
992 * except the following, which crashes. We ERR this in Wine.
994 hres
= SafeArrayPutElement(sa
, indices
, NULL
);
995 ok(hres
== E_INVALIDARG
, "Put NULL value hres 0x%x\n", hres
);
998 hres
= SafeArrayGetElement(sa
, indices
, NULL
);
999 ok(hres
== E_INVALIDARG
, "Get NULL value hres 0x%x\n", hres
);
1003 /* Make sure we can read and get back the correct values in 4 dimensions,
1004 * Each with a different size and lower bound.
1006 for (x
= 0; x
< sab
[0].cElements
; x
++)
1008 indices
[0] = sab
[0].lLbound
+ x
;
1009 for (y
= 0; y
< sab
[1].cElements
; y
++)
1011 indices
[1] = sab
[1].lLbound
+ y
;
1012 for (z
= 0; z
< sab
[2].cElements
; z
++)
1014 indices
[2] = sab
[2].lLbound
+ z
;
1015 for (a
= 0; a
< sab
[3].cElements
; a
++)
1017 indices
[3] = sab
[3].lLbound
+ a
;
1018 hres
= SafeArrayPutElement(sa
, indices
, &value
);
1019 ok(hres
== S_OK
, "Failed to put element at (%d,%d,%d,%d) hres 0x%x\n",
1029 for (x
= 0; x
< sab
[0].cElements
; x
++)
1031 indices
[0] = sab
[0].lLbound
+ x
;
1032 for (y
= 0; y
< sab
[1].cElements
; y
++)
1034 indices
[1] = sab
[1].lLbound
+ y
;
1035 for (z
= 0; z
< sab
[2].cElements
; z
++)
1037 indices
[2] = sab
[2].lLbound
+ z
;
1038 for (a
= 0; a
< sab
[3].cElements
; a
++)
1040 indices
[3] = sab
[3].lLbound
+ a
;
1041 gotvalue
= value
/ 3;
1042 hres
= SafeArrayGetElement(sa
, indices
, &gotvalue
);
1043 ok(hres
== S_OK
, "Failed to get element at (%d,%d,%d,%d) hres 0x%x\n",
1046 ok(value
== gotvalue
, "Got value %d instead of %d at (%d,%d,%d,%d)\n",
1047 gotvalue
, value
, x
, y
, z
, a
);
1053 SafeArrayDestroy(sa
);
1056 static void test_SafeArrayGetPutElement_BSTR(void)
1062 BSTR value
= 0, gotvalue
;
1063 const OLECHAR szTest
[5] = { 'T','e','s','t','\0' };
1068 sa
= SafeArrayCreate(VT_BSTR
, 1, &sab
);
1069 ok(sa
!= NULL
, "BSTR test couldn't create array\n");
1073 ok(sa
->cbElements
== sizeof(BSTR
), "BSTR size mismatch\n");
1074 if (sa
->cbElements
!= sizeof(BSTR
))
1077 indices
[0] = sab
.lLbound
;
1078 value
= SysAllocString(szTest
);
1079 ok (value
!= NULL
, "Expected non-NULL\n");
1080 hres
= SafeArrayPutElement(sa
, indices
, value
);
1081 ok(hres
== S_OK
, "Failed to put bstr element hres 0x%x\n", hres
);
1083 hres
= SafeArrayGetElement(sa
, indices
, &gotvalue
);
1084 ok(hres
== S_OK
, "Failed to get bstr element at hres 0x%x\n", hres
);
1086 ok(SysStringLen(value
) == SysStringLen(gotvalue
), "Got len %d instead of %d\n", SysStringLen(gotvalue
), SysStringLen(value
));
1087 SafeArrayDestroy(sa
);
1090 static int tunk_xref
= 0;
1091 static HRESULT WINAPI
tunk_QueryInterface(LPUNKNOWN punk
,REFIID riid
, LPVOID
*x
) {
1094 static ULONG WINAPI
tunk_AddRef(LPUNKNOWN punk
) {
1098 static ULONG WINAPI
tunk_Release(LPUNKNOWN punk
) {
1102 static const IUnknownVtbl xtunk_vtbl
= {
1103 tunk_QueryInterface
,
1108 static struct xtunk_iface
{
1109 const IUnknownVtbl
*lpvtbl
;
1113 static void test_SafeArrayGetPutElement_IUnknown(void)
1119 LPUNKNOWN value
= 0, gotvalue
;
1123 sa
= SafeArrayCreate(VT_UNKNOWN
, 1, &sab
);
1124 ok(sa
!= NULL
, "UNKNOWN test couldn't create array\n");
1128 ok(sa
->cbElements
== sizeof(LPUNKNOWN
), "LPUNKNOWN size mismatch\n");
1129 if (sa
->cbElements
!= sizeof(LPUNKNOWN
))
1132 indices
[0] = sab
.lLbound
;
1133 xtunk_iface
.lpvtbl
= &xtunk_vtbl
;
1134 value
= (LPUNKNOWN
)&xtunk_iface
;
1136 ok (value
!= NULL
, "Expected non-NULL\n");
1137 hres
= SafeArrayPutElement(sa
, indices
, value
);
1138 ok(hres
== S_OK
, "Failed to put bstr element hres 0x%x\n", hres
);
1139 ok(tunk_xref
== 2,"Failed to increment refcount of iface.\n");
1141 hres
= SafeArrayGetElement(sa
, indices
, &gotvalue
);
1142 ok(tunk_xref
== 3,"Failed to increment refcount of iface.\n");
1143 ok(hres
== S_OK
, "Failed to get bstr element at hres 0x%x\n", hres
);
1145 ok(value
== gotvalue
, "Got %p instead of %p\n", gotvalue
, value
);
1146 SafeArrayDestroy(sa
);
1147 ok(tunk_xref
== 2,"Failed to decrement refcount of iface.\n");
1150 static void test_SafeArrayRedim_IUnknown(void)
1160 sa
= SafeArrayCreate(VT_UNKNOWN
, 1, &sab
);
1161 ok(sa
!= NULL
, "UNKNOWN test couldn't create array\n");
1165 ok(sa
->cbElements
== sizeof(LPUNKNOWN
), "LPUNKNOWN size mismatch\n");
1166 if (sa
->cbElements
!= sizeof(LPUNKNOWN
))
1170 xtunk_iface
.lpvtbl
= &xtunk_vtbl
;
1171 value
= (LPUNKNOWN
)&xtunk_iface
;
1173 hres
= SafeArrayPutElement(sa
, indices
, value
);
1174 ok(hres
== S_OK
, "Failed to put IUnknown element hres 0x%x\n", hres
);
1175 ok(tunk_xref
== 2,"Failed to increment refcount of iface.\n");
1177 hres
= SafeArrayRedim(sa
, &sab
);
1178 ok(hres
== S_OK
, "Failed to shrink array hres 0x%x\n", hres
);
1179 ok(tunk_xref
== 1, "Failed to decrement refcount\n");
1180 SafeArrayDestroy(sa
);
1183 static void test_SafeArrayGetPutElement_VARIANT(void)
1189 VARIANT value
, gotvalue
;
1193 sa
= SafeArrayCreate(VT_VARIANT
, 1, &sab
);
1194 ok(sa
!= NULL
, "VARIANT test couldn't create array\n");
1198 ok(sa
->cbElements
== sizeof(VARIANT
), "VARIANT size mismatch\n");
1199 if (sa
->cbElements
!= sizeof(VARIANT
))
1202 indices
[0] = sab
.lLbound
;
1203 V_VT(&value
) = VT_I4
;
1204 V_I4(&value
) = 0x42424242;
1205 hres
= SafeArrayPutElement(sa
, indices
, &value
);
1206 ok(hres
== S_OK
, "Failed to put Variant I4 element hres 0x%x\n", hres
);
1208 V_VT(&gotvalue
) = 0xdead;
1209 hres
= SafeArrayGetElement(sa
, indices
, &gotvalue
);
1210 ok(hres
== S_OK
, "Failed to get variant element at hres 0x%x\n", hres
);
1212 V_VT(&gotvalue
) = VT_EMPTY
;
1213 hres
= SafeArrayGetElement(sa
, indices
, &gotvalue
);
1214 ok(hres
== S_OK
, "Failed to get variant element at hres 0x%x\n", hres
);
1216 ok(V_VT(&value
) == V_VT(&gotvalue
), "Got type 0x%x instead of 0x%x\n", V_VT(&value
), V_VT(&gotvalue
));
1217 if (V_VT(&value
) == V_VT(&gotvalue
))
1218 ok(V_I4(&value
) == V_I4(&gotvalue
), "Got %d instead of %d\n", V_I4(&value
), V_VT(&gotvalue
));
1220 SafeArrayDestroy(sa
);
1224 static void test_SafeArrayCopyData(void)
1226 SAFEARRAYBOUND sab
[4];
1230 int dimension
,size
=1;
1232 if (!pSafeArrayCopyData
)
1235 for (dimension
= 0; dimension
< NUM_DIMENSIONS
; dimension
++)
1237 sab
[dimension
].lLbound
= dimension
* 2 + 2;
1238 sab
[dimension
].cElements
= dimension
* 3 + 1;
1239 size
*= sab
[dimension
].cElements
;
1242 sa
= SafeArrayCreate(VT_INT
, NUM_DIMENSIONS
, sab
);
1243 ok(sa
!= NULL
, "Copy test couldn't create array\n");
1244 sacopy
= SafeArrayCreate(VT_INT
, NUM_DIMENSIONS
, sab
);
1245 ok(sacopy
!= NULL
, "Copy test couldn't create copy array\n");
1250 ok(sa
->cbElements
== sizeof(int), "int size mismatch\n");
1251 if (sa
->cbElements
!= sizeof(int))
1254 /* Fill the source array with some data; it doesn't matter what */
1255 for (dimension
= 0; dimension
< size
; dimension
++)
1257 int* data
= (int*)sa
->pvData
;
1258 data
[dimension
] = dimension
;
1261 hres
= pSafeArrayCopyData(sa
, sacopy
);
1262 ok(hres
== S_OK
, "copy data failed hres 0x%x\n", hres
);
1265 ok(!memcmp(sa
->pvData
, sacopy
->pvData
, size
* sizeof(int)), "compared different\n");
1269 hres
= pSafeArrayCopyData(NULL
, sacopy
);
1270 ok(hres
== E_INVALIDARG
, "Null copy source hres 0x%x\n", hres
);
1271 hres
= pSafeArrayCopyData(sa
, NULL
);
1272 ok(hres
== E_INVALIDARG
, "Null copy hres 0x%x\n", hres
);
1274 sacopy
->rgsabound
[0].cElements
+= 1;
1275 hres
= pSafeArrayCopyData(sa
, sacopy
);
1276 ok(hres
== E_INVALIDARG
, "Bigger copy first dimension hres 0x%x\n", hres
);
1278 sacopy
->rgsabound
[0].cElements
-= 2;
1279 hres
= pSafeArrayCopyData(sa
, sacopy
);
1280 ok(hres
== E_INVALIDARG
, "Smaller copy first dimension hres 0x%x\n", hres
);
1281 sacopy
->rgsabound
[0].cElements
+= 1;
1283 sacopy
->rgsabound
[3].cElements
+= 1;
1284 hres
= pSafeArrayCopyData(sa
, sacopy
);
1285 ok(hres
== E_INVALIDARG
, "Bigger copy last dimension hres 0x%x\n", hres
);
1287 sacopy
->rgsabound
[3].cElements
-= 2;
1288 hres
= pSafeArrayCopyData(sa
, sacopy
);
1289 ok(hres
== E_INVALIDARG
, "Smaller copy last dimension hres 0x%x\n", hres
);
1290 sacopy
->rgsabound
[3].cElements
+= 1;
1292 SafeArrayDestroy(sacopy
);
1294 hres
= pSafeArrayCopyData(sa
, sacopy
);
1295 ok(hres
== E_INVALIDARG
, "->Null copy hres 0x%x\n", hres
);
1297 hres
= SafeArrayCopy(sa
, &sacopy
);
1298 ok(hres
== S_OK
, "copy failed hres 0x%x\n", hres
);
1301 ok(SafeArrayGetElemsize(sa
) == SafeArrayGetElemsize(sacopy
),"elemsize wrong\n");
1302 ok(SafeArrayGetDim(sa
) == SafeArrayGetDim(sacopy
),"dimensions wrong\n");
1303 ok(!memcmp(sa
->pvData
, sacopy
->pvData
, size
* sizeof(int)), "compared different\n");
1306 SafeArrayDestroy(sa
);
1309 static void test_SafeArrayCreateEx(void)
1311 IRecordInfoImpl
* iRec
;
1312 SAFEARRAYBOUND sab
[4];
1317 if (!pSafeArrayCreateEx
)
1320 for (dimension
= 0; dimension
< NUM_DIMENSIONS
; dimension
++)
1322 sab
[dimension
].lLbound
= 0;
1323 sab
[dimension
].cElements
= 8;
1327 sa
= pSafeArrayCreateEx(VT_UI1
, 1, NULL
, NULL
);
1328 ok(sa
== NULL
, "CreateEx NULL bounds didn't fail\n");
1330 /* test IID storage & defaulting */
1331 sa
= pSafeArrayCreateEx(VT_DISPATCH
, 1, sab
, (PVOID
)&IID_ITypeInfo
);
1332 ok(sa
!= NULL
, "CreateEx (ITypeInfo) failed\n");
1337 if (pSafeArrayGetIID
)
1339 hres
= pSafeArrayGetIID(sa
, &guid
);
1340 ok(hres
== S_OK
, "CreateEx (ITypeInfo) no IID hres 0x%x\n", hres
);
1343 ok(IsEqualGUID(&guid
, &IID_ITypeInfo
), "CreateEx (ITypeInfo) bad IID\n");
1346 if (pSafeArraySetIID
)
1348 hres
= pSafeArraySetIID(sa
, &IID_IUnknown
);
1349 ok(hres
== S_OK
, "Failed to set IID, hres = %8x\n", hres
);
1350 if (hres
== S_OK
&& pSafeArrayGetIID
)
1352 hres
= pSafeArrayGetIID(sa
, &guid
);
1353 ok(hres
== S_OK
&& IsEqualGUID(&guid
, &IID_IUnknown
), "Set bad IID\n");
1356 SafeArrayDestroy(sa
);
1359 sa
= pSafeArrayCreateEx(VT_DISPATCH
, 1, sab
, NULL
);
1360 ok(sa
!= NULL
, "CreateEx (NULL) failed\n");
1365 if (pSafeArrayGetIID
)
1367 hres
= pSafeArrayGetIID(sa
, &guid
);
1368 ok(hres
== S_OK
, "CreateEx (NULL) no IID hres 0x%x\n", hres
);
1371 ok(IsEqualGUID(&guid
, &IID_IDispatch
), "CreateEx (NULL) bad IID\n");
1374 SafeArrayDestroy(sa
);
1377 sa
= pSafeArrayCreateEx(VT_UNKNOWN
, 1, sab
, NULL
);
1378 ok(sa
!= NULL
, "CreateEx (NULL-Unk) failed\n");
1383 if (pSafeArrayGetIID
)
1385 hres
= pSafeArrayGetIID(sa
, &guid
);
1386 ok(hres
== S_OK
, "CreateEx (NULL-Unk) no IID hres 0x%x\n", hres
);
1389 ok(IsEqualGUID(&guid
, &IID_IUnknown
), "CreateEx (NULL-Unk) bad IID\n");
1392 SafeArrayDestroy(sa
);
1395 /* VT_RECORD failure case */
1396 sa
= pSafeArrayCreateEx(VT_RECORD
, 1, sab
, NULL
);
1397 ok(sa
== NULL
, "CreateEx (NULL-Rec) succeded\n");
1399 iRec
= IRecordInfoImpl_Construct();
1401 /* Win32 doesn't care if GetSize fails */
1402 fail_GetSize
= TRUE
;
1403 sa
= pSafeArrayCreateEx(VT_RECORD
, 1, sab
, (LPVOID
)iRec
);
1404 ok(sa
!= NULL
, "CreateEx (Fail Size) failed\n");
1405 ok(iRec
->ref
== START_REF_COUNT
+ 1, "Wrong iRec refcount %d\n", iRec
->ref
);
1406 ok(iRec
->sizeCalled
== 1, "GetSize called %d times\n", iRec
->sizeCalled
);
1407 ok(iRec
->clearCalled
== 0, "Clear called %d times\n", iRec
->clearCalled
);
1410 ok(sa
->cbElements
== RECORD_SIZE_FAIL
, "Altered size to %d\n", sa
->cbElements
);
1411 SafeArrayDestroy(sa
);
1412 ok(iRec
->clearCalled
== sab
[0].cElements
, "Destroy->Clear called %d times\n", iRec
->clearCalled
);
1415 /* Test VT_RECORD array */
1416 fail_GetSize
= FALSE
;
1417 iRec
->ref
= START_REF_COUNT
;
1418 iRec
->sizeCalled
= 0;
1419 iRec
->clearCalled
= 0;
1420 sa
= pSafeArrayCreateEx(VT_RECORD
, 1, sab
, (LPVOID
)iRec
);
1421 ok(sa
!= NULL
, "CreateEx (Rec) failed\n");
1422 ok(iRec
->ref
== START_REF_COUNT
+ 1, "Wrong iRec refcount %d\n", iRec
->ref
);
1423 ok(iRec
->sizeCalled
== 1, "GetSize called %d times\n", iRec
->sizeCalled
);
1424 ok(iRec
->clearCalled
== 0, "Clear called %d times\n", iRec
->clearCalled
);
1425 if (sa
&& pSafeArrayGetRecordInfo
)
1427 IRecordInfo
* saRec
= NULL
;
1428 hres
= pSafeArrayGetRecordInfo(sa
, &saRec
);
1430 ok(hres
== S_OK
,"GRI failed\n");
1431 ok(saRec
== (IRecordInfo
*)iRec
,"Different saRec\n");
1432 ok(iRec
->ref
== START_REF_COUNT
+ 2, "Didn't AddRef %d\n", iRec
->ref
);
1433 if (iRec
->ref
== START_REF_COUNT
+ 2)
1434 IRecordInfo_Release(saRec
);
1436 ok(sa
->cbElements
== RECORD_SIZE
,"Elemsize is %d\n", sa
->cbElements
);
1438 SafeArrayDestroy(sa
);
1439 ok(iRec
->sizeCalled
== 1, "Destroy->GetSize called %d times\n", iRec
->sizeCalled
);
1440 ok(iRec
->clearCalled
== sab
[0].cElements
, "Destroy->Clear called %d times\n", iRec
->clearCalled
);
1441 ok(iRec
->ref
== START_REF_COUNT
, "Wrong iRec refcount %d\n", iRec
->ref
);
1445 static void test_SafeArrayClear(void)
1454 sa
= SafeArrayCreate(VT_UI1
, 1, &sab
);
1455 ok(sa
!= NULL
, "Create() failed.\n");
1459 /* Test clearing non-NULL variants containing arrays */
1460 V_VT(&v
) = VT_ARRAY
|VT_UI1
;
1462 hres
= VariantClear(&v
);
1463 ok(hres
== S_OK
&& V_VT(&v
) == VT_EMPTY
, "VariantClear: hres 0x%x, Type %d\n", hres
, V_VT(&v
));
1464 ok(V_ARRAY(&v
) == sa
, "VariantClear: Overwrote value\n");
1466 sa
= SafeArrayCreate(VT_UI1
, 1, &sab
);
1467 ok(sa
!= NULL
, "Create() failed.\n");
1471 V_VT(&v
) = VT_SAFEARRAY
;
1473 hres
= VariantClear(&v
);
1474 ok(hres
== DISP_E_BADVARTYPE
, "VariantClear: hres 0x%x\n", hres
);
1476 V_VT(&v
) = VT_SAFEARRAY
|VT_BYREF
;
1477 V_ARRAYREF(&v
) = &sa
;
1478 hres
= VariantClear(&v
);
1479 ok(hres
== DISP_E_BADVARTYPE
, "VariantClear: hres 0x%x\n", hres
);
1481 SafeArrayDestroy(sa
);
1484 static void test_SafeArrayCopy(void)
1487 SAFEARRAY
*sa
, *sa2
;
1488 VARIANTARG vSrc
, vDst
;
1493 sa
= SafeArrayCreate(VT_UI1
, 1, &sab
);
1494 ok(sa
!= NULL
, "Create() failed.\n");
1498 /* Test copying non-NULL variants containing arrays */
1499 V_VT(&vSrc
) = (VT_ARRAY
|VT_BYREF
|VT_UI1
);
1500 V_ARRAYREF(&vSrc
) = &sa
;
1501 V_VT(&vDst
) = VT_EMPTY
;
1503 hres
= VariantCopy(&vDst
, &vSrc
);
1504 ok(hres
== S_OK
&& V_VT(&vDst
) == (VT_ARRAY
|VT_BYREF
|VT_UI1
),
1505 "VariantCopy: hres 0x%x, Type %d\n", hres
, V_VT(&vDst
));
1506 ok(V_ARRAYREF(&vDst
) == &sa
, "VariantClear: Performed deep copy\n");
1508 V_VT(&vSrc
) = (VT_ARRAY
|VT_UI1
);
1509 V_ARRAY(&vSrc
) = sa
;
1510 V_VT(&vDst
) = VT_EMPTY
;
1512 hres
= VariantCopy(&vDst
, &vSrc
);
1513 ok(hres
== S_OK
&& V_VT(&vDst
) == (VT_ARRAY
|VT_UI1
),
1514 "VariantCopy: hres 0x%x, Type %d\n", hres
, V_VT(&vDst
));
1515 ok(V_ARRAY(&vDst
) != sa
, "VariantClear: Performed shallow copy\n");
1517 SafeArrayDestroy(V_ARRAY(&vSrc
));
1518 SafeArrayDestroy(V_ARRAY(&vDst
));
1520 hres
= SafeArrayAllocDescriptor(1, &sa
);
1521 ok(hres
== S_OK
, "SafeArrayAllocDescriptor failed with error 0x%08x\n", hres
);
1523 hres
= SafeArrayCopy(sa
, &sa2
);
1524 ok(hres
== E_INVALIDARG
,
1525 "SafeArrayCopy with empty array should have failed with error E_INVALIDARG instead of 0x%08x\n",
1527 sa
->cbElements
= 16;
1528 hres
= SafeArrayCopy(sa
, &sa2
);
1529 ok(hres
== S_OK
, "SafeArrayCopy failed with error 0x%08x\n", hres
);
1531 SafeArrayDestroy(sa
);
1534 #define MKARRAY(low,num,typ) sab.lLbound = low; sab.cElements = num; \
1535 sa = SafeArrayCreate(typ, 1, &sab); ok(sa != NULL, "Create() failed.\n"); \
1537 V_VT(&v) = VT_ARRAY|typ; V_ARRAY(&v) = sa; VariantInit(&v2)
1539 #define MKARRAYCONT(low,num,typ) sab.lLbound = low; sab.cElements = num; \
1540 sa = SafeArrayCreate(typ, 1, &sab); if (!sa) continue; \
1541 V_VT(&v) = VT_ARRAY|typ; V_ARRAY(&v) = sa; VariantInit(&v2)
1543 static void test_SafeArrayChangeTypeEx(void)
1545 static const char *szHello
= "Hello World";
1552 /* VT_ARRAY|VT_UI1 -> VT_BSTR */
1553 MKARRAY(0,strlen(szHello
)+1,VT_UI1
);
1554 memcpy(sa
->pvData
, szHello
, strlen(szHello
)+1);
1556 hres
= VariantChangeTypeEx(&v2
, &v
, 0, 0, VT_BSTR
);
1557 ok(hres
== S_OK
, "CTE VT_ARRAY|VT_UI1 -> VT_BSTR failed with %x\n", hres
);
1560 ok(V_VT(&v2
) == VT_BSTR
, "CTE VT_ARRAY|VT_UI1 -> VT_BSTR did not return VT_BSTR, but %d.\n",V_VT(&v2
));
1561 ok(strcmp((char*)V_BSTR(&v2
),szHello
) == 0,"Expected string '%s', got '%s'\n", szHello
,
1562 (char*)V_BSTR(&v2
));
1566 /* VT_VECTOR|VT_UI1 -> VT_BSTR */
1567 SafeArrayDestroy(sa
);
1568 if (pSafeArrayCreateVector
)
1570 sa
= pSafeArrayCreateVector(VT_UI1
, 0, strlen(szHello
)+1);
1571 ok(sa
!= NULL
, "CreateVector() failed.\n");
1575 memcpy(sa
->pvData
, szHello
, strlen(szHello
)+1);
1576 V_VT(&v
) = VT_VECTOR
|VT_UI1
;
1580 hres
= VariantChangeTypeEx(&v2
, &v
, 0, 0, VT_BSTR
);
1581 ok(hres
== DISP_E_BADVARTYPE
, "CTE VT_VECTOR|VT_UI1 returned %x\n", hres
);
1583 /* (vector)VT_ARRAY|VT_UI1 -> VT_BSTR (In place) */
1584 V_VT(&v
) = VT_ARRAY
|VT_UI1
;
1585 hres
= VariantChangeTypeEx(&v
, &v
, 0, 0, VT_BSTR
);
1586 ok(hres
== S_OK
, "CTE VT_ARRAY|VT_UI1 -> VT_BSTR failed with %x\n", hres
);
1589 ok(V_VT(&v
) == VT_BSTR
, "CTE VT_ARRAY|VT_UI1 -> VT_BSTR did not return VT_BSTR, but %d.\n",V_VT(&v
));
1590 ok(strcmp((char*)V_BSTR(&v
),szHello
) == 0,"Expected string '%s', got '%s'\n", szHello
,
1596 /* To/from BSTR only works with arrays of VT_UI1 */
1597 for (vt
= 0; vt
<= VT_CLSID
; vt
++)
1602 MKARRAYCONT(0,1,vt
);
1603 hres
= VariantChangeTypeEx(&v2
, &v
, 0, 0, VT_BSTR
);
1604 ok(hres
!= S_OK
, "CTE VT_ARRAY|VT %d->BSTR succeeded\n", vt
);
1608 /* Can't change an array of one type into array of another type , even
1609 * if the other type is the same size
1611 if (pSafeArrayCreateVector
)
1613 sa
= pSafeArrayCreateVector(VT_UI1
, 0, 1);
1614 ok(sa
!= NULL
, "CreateVector() failed.\n");
1618 V_VT(&v
) = VT_ARRAY
|VT_UI1
;
1620 hres
= VariantChangeTypeEx(&v2
, &v
, 0, 0, VT_ARRAY
|VT_I1
);
1621 ok(hres
== DISP_E_TYPEMISMATCH
, "CTE VT_ARRAY|VT_UI1->VT_ARRAY|VT_I1 returned %x\n", hres
);
1623 /* But can change to the same array type */
1624 SafeArrayDestroy(sa
);
1625 sa
= pSafeArrayCreateVector(VT_UI1
, 0, 1);
1626 ok(sa
!= NULL
, "CreateVector() failed.\n");
1629 V_VT(&v
) = VT_ARRAY
|VT_UI1
;
1631 hres
= VariantChangeTypeEx(&v2
, &v
, 0, 0, VT_ARRAY
|VT_UI1
);
1632 ok(hres
== S_OK
, "CTE VT_ARRAY|VT_UI1->VT_ARRAY|VT_UI1 returned %x\n", hres
);
1636 MKARRAY(0,1,VT_UI1
);
1637 hres
= VariantChangeTypeEx(&v2
, &v
, 0, 0, VT_NULL
);
1638 ok(hres
== DISP_E_TYPEMISMATCH
, "CTE VT_ARRAY|VT_UI1 returned %x\n", hres
);
1639 MKARRAY(0,1,VT_UI1
);
1640 hres
= VariantChangeTypeEx(&v2
, &v
, 0, 0, VT_EMPTY
);
1641 ok(hres
== DISP_E_TYPEMISMATCH
, "CTE VT_ARRAY|VT_UI1 returned %x\n", hres
);
1645 static void test_SafeArrayDestroyData (void)
1650 int value
= 0xdeadbeef;
1652 void HUGEP
*temp_pvData
;
1656 sa
= SafeArrayCreate(VT_INT
, 1, &sab
);
1657 ok(sa
!= NULL
, "Create() failed.\n");
1661 SafeArrayPutElement (sa
, index
, &value
);
1663 /* SafeArrayDestroyData shouldn't free pvData if FADF_STATIC is set. */
1664 sa
->fFeatures
|= FADF_STATIC
;
1665 temp_pvData
= sa
->pvData
;
1666 hres
= SafeArrayDestroyData(sa
);
1667 ok(hres
== S_OK
, "SADData FADF_STATIC failed, error code %x.\n",hres
);
1668 ok(sa
->pvData
== temp_pvData
, "SADData FADF_STATIC: pvData=%p, expected %p (fFeatures = %d).\n",
1669 sa
->pvData
, temp_pvData
, sa
->fFeatures
);
1670 SafeArrayGetElement (sa
, index
, &value
);
1671 ok(value
== 0, "Data not cleared after SADData\n");
1673 /* Clear FADF_STATIC, now really destroy the data. */
1674 sa
->fFeatures
^= FADF_STATIC
;
1675 hres
= SafeArrayDestroyData(sa
);
1676 ok(hres
== S_OK
, "SADData !FADF_STATIC failed, error code %x.\n",hres
);
1677 ok(sa
->pvData
== NULL
, "SADData !FADF_STATIC: pvData=%p, expected NULL.\n", sa
->pvData
);
1679 hres
= SafeArrayDestroy(sa
);
1680 ok(hres
== S_OK
, "SAD failed, error code %x.\n", hres
);
1683 START_TEST(safearray
)
1685 hOleaut32
= LoadLibraryA("oleaut32.dll");
1687 GETPTR(SafeArrayAllocDescriptorEx
);
1688 GETPTR(SafeArrayCopyData
);
1689 GETPTR(SafeArrayGetIID
);
1690 GETPTR(SafeArraySetIID
);
1691 GETPTR(SafeArrayGetVartype
);
1692 GETPTR(SafeArrayCreateEx
);
1693 GETPTR(SafeArrayCreateVector
);
1695 check_for_VT_INT_PTR();
1697 test_SafeArrayAllocDestroyDescriptor();
1698 test_SafeArrayCreateLockDestroy();
1699 test_VectorCreateLockDestroy();
1701 test_SafeArrayChangeTypeEx();
1702 test_SafeArrayCopy();
1703 test_SafeArrayClear();
1704 test_SafeArrayCreateEx();
1705 test_SafeArrayCopyData();
1706 test_SafeArrayDestroyData();
1707 test_SafeArrayGetPutElement();
1708 test_SafeArrayGetPutElement_BSTR();
1709 test_SafeArrayGetPutElement_IUnknown();
1710 test_SafeArrayRedim_IUnknown();
1711 test_SafeArrayGetPutElement_VARIANT();