diff --git a/dlls/oleaut32/tests/safearray.c b/dlls/oleaut32/tests/safearray.c index 1d8943ad928..c28931cdab4 100644 --- a/dlls/oleaut32/tests/safearray.c +++ b/dlls/oleaut32/tests/safearray.c @@ -2003,6 +2003,63 @@ static void test_SafeArrayDestroyData (void) ok(hres == S_OK, "SAD failed, error code %x.\n", hres); } +static void test_safearray_layout(void) +{ + IRecordInfoImpl *irec; + IRecordInfo *record; + GUID guid, *guidptr; + SAFEARRAYBOUND sab; + SAFEARRAY *sa; + DWORD *dwptr; + HRESULT hr; + + sab.lLbound = 0; + sab.cElements = 10; + + /* GUID field */ + sa = SafeArrayCreate(VT_UNKNOWN, 1, &sab); + ok(sa != NULL, "got %p\n", sa); + + guidptr = (GUID*)sa - 1; + ok(IsEqualIID(guidptr, &IID_IUnknown), "got %s\n", wine_dbgstr_guid(guidptr)); + + hr = SafeArraySetIID(sa, &IID_IDispatch); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(IsEqualIID(guidptr, &IID_IDispatch), "got %s\n", wine_dbgstr_guid(guidptr)); + + memcpy(guidptr, &IID_IUnknown, sizeof(GUID)); + hr = SafeArrayGetIID(sa, &guid); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(IsEqualIID(&guid, &IID_IUnknown), "got %s\n", wine_dbgstr_guid(&guid)); + + hr = SafeArrayDestroy(sa); + ok(hr == S_OK, "got 0x%08x\n", hr); + + /* VARTYPE field */ + sa = SafeArrayCreate(VT_UI1, 1, &sab); + ok(sa != NULL, "got %p\n", sa); + + dwptr = (DWORD*)sa - 1; + ok(*dwptr == VT_UI1, "got %d\n", *dwptr); + + hr = SafeArrayDestroy(sa); + ok(hr == S_OK, "got 0x%08x\n", hr); + + /* IRecordInfo pointer */ + irec = IRecordInfoImpl_Construct(); + irec->ref = 1; + + sa = pSafeArrayCreateEx(VT_RECORD, 1, &sab, &irec->IRecordInfo_iface); + ok(sa != NULL, "failed to create array\n"); + + record = *((IRecordInfo**)sa - 1); + ok(record == &irec->IRecordInfo_iface, "got %p\n", record); + + hr = SafeArrayDestroy(sa); + ok(hr == S_OK, "got 0x%08x\n", hr); + IRecordInfo_Release(&irec->IRecordInfo_iface); +} + START_TEST(safearray) { hOleaut32 = GetModuleHandleA("oleaut32.dll"); @@ -2035,4 +2092,5 @@ START_TEST(safearray) test_SafeArrayGetPutElement_IUnknown(); test_SafeArrayRedim_IUnknown(); test_SafeArrayGetPutElement_VARIANT(); + test_safearray_layout(); }