ole32/tests: Add some tests for stream data.

This commit is contained in:
Huw Davies 2009-03-31 12:07:14 +01:00 committed by Alexandre Julliard
parent d28d731b61
commit 61fa9bb061
1 changed files with 64 additions and 11 deletions

View File

@ -21,6 +21,7 @@
#define COBJMACROS
#include <stdarg.h>
#include <stdio.h>
#include "windef.h"
#include "winbase.h"
@ -37,6 +38,15 @@
(fe).lindex=-1;\
};
static inline char *dump_fmtetc(FORMATETC *fmt)
{
static char buf[100];
snprintf(buf, sizeof(buf), "cf %04x ptd %p aspect %x lindex %d tymed %x",
fmt->cfFormat, fmt->ptd, fmt->dwAspect, fmt->lindex, fmt->tymed);
return buf;
}
typedef struct DataObjectImpl {
const IDataObjectVtbl *lpVtbl;
LONG ref;
@ -61,9 +71,10 @@ typedef struct EnumFormatImpl {
static BOOL expect_DataObjectImpl_QueryGetData = TRUE;
static ULONG DataObjectImpl_GetData_calls = 0;
static ULONG DataObjectImpl_GetDataHere_calls = 0;
static ULONG DataObjectImpl_EnumFormatEtc_calls = 0;
static UINT cf_stream, cf_storage, cf_another, cf_onemore;
static UINT cf_stream, cf_storage, cf_global, cf_another, cf_onemore;
static HRESULT EnumFormatImpl_Create(FORMATETC *fmtetc, UINT size, LPENUMFORMATETC *lplpformatetc);
@ -216,6 +227,8 @@ static HRESULT WINAPI DataObjectImpl_GetData(IDataObject* iface, FORMATETC *pfor
UINT i;
BOOL foundFormat = FALSE;
trace("getdata: %s\n", dump_fmtetc(pformatetc));
DataObjectImpl_GetData_calls++;
if(pformatetc->lindex != -1)
@ -231,7 +244,7 @@ static HRESULT WINAPI DataObjectImpl_GetData(IDataObject* iface, FORMATETC *pfor
pmedium->pUnkForRelease = (LPUNKNOWN)iface;
IUnknown_AddRef(pmedium->pUnkForRelease);
if(pformatetc->cfFormat == CF_TEXT)
if(pformatetc->cfFormat == CF_TEXT || pformatetc->cfFormat == cf_global)
U(*pmedium).hGlobal = This->text;
else if(pformatetc->cfFormat == cf_stream)
U(*pmedium).pstm = This->stm;
@ -247,7 +260,9 @@ static HRESULT WINAPI DataObjectImpl_GetData(IDataObject* iface, FORMATETC *pfor
static HRESULT WINAPI DataObjectImpl_GetDataHere(IDataObject* iface, FORMATETC *pformatetc, STGMEDIUM *pmedium)
{
ok(0, "unexpected call\n");
trace("getdatahere: %s\n", dump_fmtetc(pformatetc));
DataObjectImpl_GetDataHere_calls++;
return E_NOTIMPL;
}
@ -257,6 +272,7 @@ static HRESULT WINAPI DataObjectImpl_QueryGetData(IDataObject* iface, FORMATETC
UINT i;
BOOL foundFormat = FALSE;
trace("querygetdata: %s\n", dump_fmtetc(pformatetc));
if (!expect_DataObjectImpl_QueryGetData)
ok(0, "unexpected call to DataObjectImpl_QueryGetData\n");
@ -357,11 +373,12 @@ static HRESULT DataObjectImpl_CreateText(LPCSTR text, LPDATAOBJECT *lplpdataobj)
return S_OK;
}
const char *cmpl_stm_data = "complex stream";
const char *cmpl_text_data = "complex text";
static HRESULT DataObjectImpl_CreateComplex(LPDATAOBJECT *lplpdataobj)
{
DataObjectImpl *obj;
const char *stm_data = "complex stream";
const char *text_data = "complex text";
ILockBytes *lbs;
static const WCHAR devname[] = {'m','y','d','e','v',0};
DEVMODEW dm;
@ -369,17 +386,17 @@ static HRESULT DataObjectImpl_CreateComplex(LPDATAOBJECT *lplpdataobj)
obj = HeapAlloc(GetProcessHeap(), 0, sizeof(DataObjectImpl));
obj->lpVtbl = &VT_DataObjectImpl;
obj->ref = 1;
obj->text = GlobalAlloc(GMEM_MOVEABLE, strlen(text_data) + 1);
strcpy(GlobalLock(obj->text), text_data);
obj->text = GlobalAlloc(GMEM_MOVEABLE, strlen(cmpl_text_data) + 1);
strcpy(GlobalLock(obj->text), cmpl_text_data);
GlobalUnlock(obj->text);
CreateStreamOnHGlobal(NULL, TRUE, &obj->stm);
IStream_Write(obj->stm, stm_data, strlen(stm_data), NULL);
IStream_Write(obj->stm, cmpl_stm_data, strlen(cmpl_stm_data), NULL);
CreateILockBytesOnHGlobal(NULL, TRUE, &lbs);
StgCreateDocfileOnILockBytes(lbs, STGM_CREATE|STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, &obj->stg);
ILockBytes_Release(lbs);
obj->fmtetc_cnt = 5;
obj->fmtetc_cnt = 8;
/* zeroing here since FORMATETC has a hole in it, and it's confusing to have this uninitialised. */
obj->fmtetc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, obj->fmtetc_cnt*sizeof(FORMATETC));
InitFormatEtc(obj->fmtetc[0], CF_TEXT, TYMED_HGLOBAL);
@ -399,8 +416,11 @@ static HRESULT DataObjectImpl_CreateComplex(LPDATAOBJECT *lplpdataobj)
lstrcpyW((WCHAR*)obj->fmtetc[3].ptd->tdData, devname);
memcpy(obj->fmtetc[3].ptd->tdData + sizeof(devname), &dm, dm.dmSize + dm.dmDriverExtra);
InitFormatEtc(obj->fmtetc[4], cf_stream, 0xfffff);
obj->fmtetc[4].dwAspect = DVASPECT_ICON;
InitFormatEtc(obj->fmtetc[4], cf_global, TYMED_HGLOBAL);
InitFormatEtc(obj->fmtetc[5], cf_another, TYMED_HGLOBAL);
InitFormatEtc(obj->fmtetc[6], cf_another, 0xfffff);
InitFormatEtc(obj->fmtetc[7], cf_another, 0xfffff);
obj->fmtetc[7].dwAspect = DVASPECT_ICON;
*lplpdataobj = (LPDATAOBJECT)obj;
return S_OK;
@ -533,6 +553,7 @@ static void test_enum_fmtetc(IDataObject *src)
ok(src != NULL, "shouldn't be here\n");
hr = IEnumFORMATETC_Next(src_enum, 1, &src_fmt, NULL);
ok(hr == S_OK, "%d: got %08x\n", count, hr);
trace("%d: cf %04x aspect %x tymed %x\n", count, fmt.cfFormat, fmt.dwAspect, fmt.tymed);
ok(fmt.cfFormat == src_fmt.cfFormat, "%d: %04x %04x\n", count, fmt.cfFormat, src_fmt.cfFormat);
ok(fmt.dwAspect == src_fmt.dwAspect, "%d: %08x %08x\n", count, fmt.dwAspect, src_fmt.dwAspect);
ok(fmt.lindex == src_fmt.lindex, "%d: %08x %08x\n", count, fmt.lindex, src_fmt.lindex);
@ -673,6 +694,36 @@ static void test_cf_dataobject(IDataObject *data)
}
}
}
else if(cf == cf_stream)
{
HGLOBAL h;
void *ptr;
DWORD size;
DataObjectImpl_GetDataHere_calls = 0;
h = GetClipboardData(cf);
ok(DataObjectImpl_GetDataHere_calls == 1, "got %d\n", DataObjectImpl_GetDataHere_calls);
ptr = GlobalLock(h);
size = GlobalSize(h);
ok(size == strlen(cmpl_stm_data), "expected %d got %d\n", strlen(cmpl_stm_data), size);
ok(!memcmp(ptr, cmpl_stm_data, size), "mismatch\n");
GlobalUnlock(h);
}
else if(cf == cf_global)
{
HGLOBAL h;
void *ptr;
DWORD size;
DataObjectImpl_GetDataHere_calls = 0;
h = GetClipboardData(cf);
ok(DataObjectImpl_GetDataHere_calls == 0, "got %d\n", DataObjectImpl_GetDataHere_calls);
ptr = GlobalLock(h);
size = GlobalSize(h);
ok(size == strlen(cmpl_text_data) + 1, "expected %d got %d\n", strlen(cmpl_text_data) + 1, size);
ok(!memcmp(ptr, cmpl_text_data, size), "mismatch\n");
GlobalUnlock(h);
}
} while(cf);
CloseClipboard();
ok(found_dataobject, "didn't find cf_dataobject\n");
@ -688,6 +739,7 @@ static void test_set_clipboard(void)
cf_stream = RegisterClipboardFormatA("stream format");
cf_storage = RegisterClipboardFormatA("storage format");
cf_global = RegisterClipboardFormatA("global format");
cf_another = RegisterClipboardFormatA("another format");
cf_onemore = RegisterClipboardFormatA("one more format");
@ -779,6 +831,7 @@ static void test_set_clipboard(void)
ok(h == NULL, "got %p\n", h);
CloseClipboard();
trace("setting complex\n");
hr = OleSetClipboard(data_cmpl);
ok(hr == S_OK, "failed to set clipboard to complex data, hr = 0x%08x\n", hr);
test_cf_dataobject(data_cmpl);