[OLE32_WINETEST] Sync with Wine 3.0. CORE-14225

This commit is contained in:
Amine Khaldi 2018-01-20 12:58:03 +01:00
parent 2178977b54
commit b44b1afb81
4 changed files with 1551 additions and 377 deletions

View file

@ -2,7 +2,6 @@
* Stream on HGLOBAL Tests
*
* Copyright 2006 Robert Shearman (for CodeWeavers)
* Copyright 2016 Dmitry Timoshkov
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -501,240 +500,11 @@ static void test_freed_hglobal(void)
IStream_Release(pStream);
}
static void stream_info(IStream *stream, HGLOBAL *hmem, int *size, int *pos)
{
HRESULT hr;
STATSTG stat;
LARGE_INTEGER offset;
ULARGE_INTEGER newpos;
*hmem = 0;
*size = *pos = -1;
hr = GetHGlobalFromStream(stream, hmem);
ok(hr == S_OK, "unexpected %#x\n", hr);
memset(&stat, 0x55, sizeof(stat));
hr = IStream_Stat(stream, &stat, STATFLAG_DEFAULT);
ok(hr == S_OK, "unexpected %#x\n", hr);
ok(stat.type == STGTY_STREAM, "unexpected %#x\n", stat.type);
ok(!stat.pwcsName, "unexpected %p\n", stat.pwcsName);
ok(IsEqualIID(&stat.clsid, &GUID_NULL), "unexpected %s\n", wine_dbgstr_guid(&stat.clsid));
ok(!stat.cbSize.HighPart, "unexpected %#x\n", stat.cbSize.HighPart);
*size = stat.cbSize.LowPart;
offset.QuadPart = 0;
hr = IStream_Seek(stream, offset, STREAM_SEEK_CUR, &newpos);
ok(hr == S_OK, "unexpected %#x\n", hr);
ok(!newpos.HighPart, "unexpected %#x\n", newpos.HighPart);
*pos = newpos.LowPart;
}
static void test_IStream_Clone(void)
{
static const char hello[] = "Hello World!";
char buf[32];
HRESULT hr;
IStream *stream, *clone;
HGLOBAL orig_hmem, hmem, hmem_clone;
ULARGE_INTEGER newsize;
LARGE_INTEGER offset;
int size, pos, ret;
/* test simple case for Clone */
orig_hmem = GlobalAlloc(GMEM_MOVEABLE, 0);
ok(orig_hmem != 0, "unexpected %p\n", orig_hmem);
hr = CreateStreamOnHGlobal(orig_hmem, TRUE, &stream);
ok(hr == S_OK, "unexpected %#x\n", hr);
hr = GetHGlobalFromStream(stream, NULL);
ok(hr == E_INVALIDARG, "unexpected %#x\n", hr);
hr = GetHGlobalFromStream(NULL, &hmem);
ok(hr == E_INVALIDARG, "unexpected %#x\n", hr);
stream_info(stream, &hmem, &size, &pos);
ok(hmem == orig_hmem, "handles should match\n");
ok(size == 0, "unexpected %d\n", size);
ok(pos == 0, "unexpected %d\n", pos);
hr = IStream_Clone(stream, &clone);
ok(hr == S_OK, "unexpected %#x\n", hr);
hr = IStream_Write(stream, hello, sizeof(hello), NULL);
ok(hr == S_OK, "unexpected %#x\n", hr);
stream_info(stream, &hmem, &size, &pos);
ok(hmem != 0, "unexpected %p\n", hmem);
ok(size == 13, "unexpected %d\n", size);
ok(pos == 13, "unexpected %d\n", pos);
stream_info(clone, &hmem_clone, &size, &pos);
ok(hmem_clone == hmem, "handles should match\n");
ok(size == 13, "unexpected %d\n", size);
ok(pos == 0, "unexpected %d\n", pos);
buf[0] = 0;
hr = IStream_Read(clone, buf, sizeof(buf), NULL);
ok(hr == S_OK, "unexpected %#x\n", hr);
ok(!strcmp(buf, hello), "wrong stream contents\n");
newsize.QuadPart = 0x8000;
hr = IStream_SetSize(stream, newsize);
ok(hr == S_OK, "unexpected %#x\n", hr);
stream_info(stream, &hmem, &size, &pos);
ok(hmem != 0, "unexpected %p\n", hmem);
ok(hmem == orig_hmem, "unexpected %p\n", hmem);
ok(size == 0x8000, "unexpected %#x\n", size);
ok(pos == 13, "unexpected %d\n", pos);
stream_info(clone, &hmem_clone, &size, &pos);
ok(hmem_clone == hmem, "handles should match\n");
ok(size == 0x8000, "unexpected %#x\n", size);
ok(pos == 13, "unexpected %d\n", pos);
IStream_Release(clone);
IStream_Release(stream);
/* exploit GMEM_FIXED forced move for the same base streams */
orig_hmem = GlobalAlloc(GMEM_FIXED, 1);
ok(orig_hmem != 0, "unexpected %p\n", orig_hmem);
hr = CreateStreamOnHGlobal(orig_hmem, TRUE, &stream);
ok(hr == S_OK, "unexpected %#x\n", hr);
hr = IStream_Clone(stream, &clone);
ok(hr == S_OK, "unexpected %#x\n", hr);
stream_info(stream, &hmem, &size, &pos);
ok(hmem != 0, "unexpected %p\n", hmem);
ok(size == 1, "unexpected %d\n", size);
ok(pos == 0, "unexpected %d\n", pos);
stream_info(clone, &hmem_clone, &size, &pos);
ok(hmem_clone == hmem, "handles should match\n");
ok(size == 1, "unexpected %d\n", size);
ok(pos == 0, "unexpected %d\n", pos);
newsize.QuadPart = 0x8000;
hr = IStream_SetSize(stream, newsize);
ok(hr == S_OK, "unexpected %#x\n", hr);
stream_info(stream, &hmem, &size, &pos);
ok(hmem != 0, "unexpected %p\n", hmem);
ok(hmem != orig_hmem, "unexpected %p\n", hmem);
ok(size == 0x8000, "unexpected %#x\n", size);
ok(pos == 0, "unexpected %d\n", pos);
stream_info(clone, &hmem_clone, &size, &pos);
ok(hmem_clone == hmem, "handles should match\n");
ok(size == 0x8000, "unexpected %#x\n", size);
ok(pos == 0, "unexpected %d\n", pos);
IStream_Release(stream);
IStream_Release(clone);
/* exploit GMEM_FIXED forced move for different base streams */
orig_hmem = GlobalAlloc(GMEM_FIXED, 1);
ok(orig_hmem != 0, "unexpected %p\n", orig_hmem);
hr = CreateStreamOnHGlobal(orig_hmem, TRUE, &stream);
ok(hr == S_OK, "unexpected %#x\n", hr);
hr = CreateStreamOnHGlobal(orig_hmem, TRUE, &clone);
ok(hr == S_OK, "unexpected %#x\n", hr);
stream_info(stream, &hmem, &size, &pos);
ok(hmem != 0, "unexpected %p\n", hmem);
ok(size == 1, "unexpected %d\n", size);
ok(pos == 0, "unexpected %d\n", pos);
stream_info(clone, &hmem_clone, &size, &pos);
ok(hmem_clone == hmem, "handles should match\n");
ok(size == 1, "unexpected %d\n", size);
ok(pos == 0, "unexpected %d\n", pos);
newsize.QuadPart = 0x8000;
hr = IStream_SetSize(stream, newsize);
ok(hr == S_OK, "unexpected %#x\n", hr);
stream_info(stream, &hmem, &size, &pos);
ok(hmem != 0, "unexpected %p\n", hmem);
ok(hmem != orig_hmem, "unexpected %p\n", hmem);
ok(size == 0x8000, "unexpected %#x\n", size);
ok(pos == 0, "unexpected %d\n", pos);
stream_info(clone, &hmem_clone, &size, &pos);
ok(hmem_clone != hmem, "handles should not match\n");
ok(size == 1, "unexpected %#x\n", size);
ok(pos == 0, "unexpected %d\n", pos);
IStream_Release(stream);
/* releasing clone leads to test termination under windows
IStream_Release(clone);
*/
/* test Release for a being cloned stream */
hr = CreateStreamOnHGlobal(0, TRUE, &stream);
ok(hr == S_OK, "unexpected %#x\n", hr);
hr = IStream_Clone(stream, &clone);
ok(hr == S_OK, "unexpected %#x\n", hr);
stream_info(stream, &hmem, &size, &pos);
ok(hmem != 0, "unexpected %p\n", hmem);
ok(size == 0, "unexpected %d\n", size);
ok(pos == 0, "unexpected %d\n", pos);
stream_info(clone, &hmem_clone, &size, &pos);
ok(hmem_clone == hmem, "handles should match\n");
ok(size == 0, "unexpected %#x\n", size);
ok(pos == 0, "unexpected %d\n", pos);
ret = IStream_Release(stream);
ok(ret == 0, "unexpected %d\n", ret);
newsize.QuadPart = 0x8000;
hr = IStream_SetSize(clone, newsize);
ok(hr == S_OK, "unexpected %#x\n", hr);
stream_info(clone, &hmem_clone, &size, &pos);
ok(hmem_clone == hmem, "handles should match\n");
ok(size == 0x8000, "unexpected %#x\n", size);
ok(pos == 0, "unexpected %d\n", pos);
hr = IStream_Write(clone, hello, sizeof(hello), NULL);
ok(hr == S_OK, "unexpected %#x\n", hr);
stream_info(clone, &hmem_clone, &size, &pos);
ok(hmem_clone == hmem, "handles should match\n");
ok(size == 0x8000, "unexpected %#x\n", size);
ok(pos == 13, "unexpected %d\n", pos);
offset.QuadPart = 0;
hr = IStream_Seek(clone, offset, STREAM_SEEK_SET, NULL);
ok(hr == S_OK, "unexpected %#x\n", hr);
buf[0] = 0;
hr = IStream_Read(clone, buf, sizeof(buf), NULL);
ok(hr == S_OK, "unexpected %#x\n", hr);
ok(!strcmp(buf, hello), "wrong stream contents\n");
stream_info(clone, &hmem_clone, &size, &pos);
ok(hmem_clone == hmem, "handles should match\n");
ok(size == 0x8000, "unexpected %#x\n", size);
ok(pos == 32, "unexpected %d\n", pos);
ret = IStream_Release(clone);
ok(ret == 0, "unexpected %d\n", ret);
}
START_TEST(hglobalstream)
{
HRESULT hr;
IStream *pStream;
test_IStream_Clone();
hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream);
ok_ole_success(hr, "CreateStreamOnHGlobal");

View file

@ -2955,6 +2955,12 @@ static HRESULT WINAPI local_server_GetClassID(IPersist *iface, CLSID *clsid)
hr = CoDisconnectObject((IUnknown *)iface, 0);
ok(hr == S_OK, "got %08x\n", hr);
/* Initialize and uninitialize the apartment to show that we
* remain in the autojoined mta */
hr = pCoInitializeEx( NULL, COINIT_MULTITHREADED );
ok( hr == S_FALSE, "got %08x\n", hr );
CoUninitialize();
return S_OK;
}
@ -3736,7 +3742,7 @@ START_TEST(marshal)
argc = winetest_get_mainargs( &argv );
if (argc > 2 && (!strcmp(argv[2], "-Embedding")))
{
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
pCoInitializeEx(NULL, COINIT_MULTITHREADED);
test_register_local_server();
CoUninitialize();

File diff suppressed because it is too large Load diff

View file

@ -178,31 +178,32 @@ static void test_marshal_CLIPFORMAT(void)
USER_MARSHAL_CB umcb;
MIDL_STUB_MESSAGE stub_msg;
RPC_MESSAGE rpc_msg;
unsigned char *buffer;
unsigned char *buffer, *buffer_end;
ULONG i, size;
CLIPFORMAT cf = RegisterClipboardFormatA("MyFormat");
CLIPFORMAT cf2;
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_DIFFERENTMACHINE);
size = CLIPFORMAT_UserSize(&umcb.Flags, 0, &cf);
ok(size == 8 + sizeof(cf_marshaled) ||
broken(size == 12 + sizeof(cf_marshaled)) || /* win64 adds 4 extra (unused) bytes */
broken(size == 8 + sizeof(cf_marshaled) - 2), /* win9x and winnt don't include the '\0' */
size = CLIPFORMAT_UserSize(&umcb.Flags, 1, &cf);
ok(size == 12 + sizeof(cf_marshaled) ||
broken(size == 16 + sizeof(cf_marshaled)), /* win64 adds 4 extra (unused) bytes */
"CLIPFORMAT: Wrong size %d\n", size);
buffer = HeapAlloc(GetProcessHeap(), 0, size);
memset( buffer, 0xcc, size );
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE);
CLIPFORMAT_UserMarshal(&umcb.Flags, buffer, &cf);
ok(*(LONG *)(buffer + 0) == WDT_REMOTE_CALL, "CLIPFORMAT: Context should be WDT_REMOTE_CALL instead of 0x%08x\n", *(LONG *)(buffer + 0));
ok(*(DWORD *)(buffer + 4) == cf, "CLIPFORMAT: Marshaled value should be 0x%04x instead of 0x%04x\n", cf, *(DWORD *)(buffer + 4));
ok(!memcmp(buffer + 8, cf_marshaled, min( sizeof(cf_marshaled), size-8 )), "Marshaled data differs\n");
if (size > sizeof(cf_marshaled) + 8) /* make sure the extra bytes are not used */
for (i = sizeof(cf_marshaled) + 8; i < size; i++)
buffer_end = CLIPFORMAT_UserMarshal(&umcb.Flags, buffer + 1, &cf);
ok(buffer_end == buffer + 12 + sizeof(cf_marshaled), "got %p buffer %p\n", buffer_end, buffer);
ok(*(LONG *)(buffer + 4) == WDT_REMOTE_CALL, "CLIPFORMAT: Context should be WDT_REMOTE_CALL instead of 0x%08x\n", *(LONG *)(buffer + 0));
ok(*(DWORD *)(buffer + 8) == cf, "CLIPFORMAT: Marshaled value should be 0x%04x instead of 0x%04x\n", cf, *(DWORD *)(buffer + 4));
ok(!memcmp(buffer + 12, cf_marshaled, min( sizeof(cf_marshaled), size-12 )), "Marshaled data differs\n");
if (size > sizeof(cf_marshaled) + 12) /* make sure the extra bytes are not used */
for (i = sizeof(cf_marshaled) + 12; i < size; i++)
ok( buffer[i] == 0xcc, "buffer offset %u has been set to %x\n", i, buffer[i] );
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE);
CLIPFORMAT_UserUnmarshal(&umcb.Flags, buffer, &cf2);
buffer_end = CLIPFORMAT_UserUnmarshal(&umcb.Flags, buffer + 1, &cf2);
ok(buffer_end == buffer + 12 + sizeof(cf_marshaled), "got %p buffer %p\n", buffer_end, buffer);
ok(cf == cf2, "CLIPFORMAT: Didn't unmarshal properly\n");
HeapFree(GetProcessHeap(), 0, buffer);
@ -215,25 +216,27 @@ static void test_marshal_HWND(void)
USER_MARSHAL_CB umcb;
MIDL_STUB_MESSAGE stub_msg;
RPC_MESSAGE rpc_msg;
unsigned char *buffer;
unsigned char *buffer, *buffer_end;
ULONG size;
HWND hwnd = GetDesktopWindow();
HWND hwnd2;
wireHWND wirehwnd;
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_LOCAL);
size = HWND_UserSize(&umcb.Flags, 0, &hwnd);
ok(size == sizeof(*wirehwnd), "Wrong size %d\n", size);
size = HWND_UserSize(&umcb.Flags, 1, &hwnd);
ok(size == 4 + sizeof(*wirehwnd), "Wrong size %d\n", size);
buffer = HeapAlloc(GetProcessHeap(), 0, size);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL);
HWND_UserMarshal(&umcb.Flags, buffer, &hwnd);
wirehwnd = (wireHWND)buffer;
buffer_end = HWND_UserMarshal(&umcb.Flags, buffer + 1, &hwnd);
ok(buffer_end == buffer + size, "got %p buffer %p\n", buffer_end, buffer);
wirehwnd = (wireHWND)(buffer + 4);
ok(wirehwnd->fContext == WDT_INPROC_CALL, "Context should be WDT_INPROC_CALL instead of 0x%08x\n", wirehwnd->fContext);
ok(wirehwnd->u.hInproc == (LONG_PTR)hwnd, "Marshaled value should be %p instead of %x\n", hwnd, wirehwnd->u.hRemote);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL);
HWND_UserUnmarshal(&umcb.Flags, buffer, &hwnd2);
buffer_end = HWND_UserUnmarshal(&umcb.Flags, buffer + 1, &hwnd2);
ok(buffer_end == buffer + size, "got %p buffer %p\n", buffer_end, buffer);
ok(hwnd == hwnd2, "Didn't unmarshal properly\n");
HeapFree(GetProcessHeap(), 0, buffer);
@ -335,7 +338,7 @@ static void test_marshal_HENHMETAFILE(void)
USER_MARSHAL_CB umcb;
MIDL_STUB_MESSAGE stub_msg;
RPC_MESSAGE rpc_msg;
unsigned char *buffer;
unsigned char *buffer, *buffer_end;
ULONG size;
HENHMETAFILE hemf;
HENHMETAFILE hemf2 = NULL;
@ -344,26 +347,28 @@ static void test_marshal_HENHMETAFILE(void)
hemf = create_emf();
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_DIFFERENTMACHINE);
size = HENHMETAFILE_UserSize(&umcb.Flags, 0, &hemf);
ok(size > 20, "size should be at least 20 bytes, not %d\n", size);
size = HENHMETAFILE_UserSize(&umcb.Flags, 1, &hemf);
ok(size > 24, "size should be at least 24 bytes, not %d\n", size);
buffer = HeapAlloc(GetProcessHeap(), 0, size);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE);
HENHMETAFILE_UserMarshal(&umcb.Flags, buffer, &hemf);
wirehemf = buffer;
buffer_end = HENHMETAFILE_UserMarshal(&umcb.Flags, buffer + 1, &hemf);
ok(buffer_end == buffer + size, "got %p buffer %p\n", buffer_end, buffer);
wirehemf = buffer + 4;
ok(*(DWORD *)wirehemf == WDT_REMOTE_CALL, "wirestgm + 0x0 should be WDT_REMOTE_CALL instead of 0x%08x\n", *(DWORD *)wirehemf);
wirehemf += sizeof(DWORD);
ok(*(DWORD *)wirehemf == (DWORD)(DWORD_PTR)hemf, "wirestgm + 0x4 should be hemf instead of 0x%08x\n", *(DWORD *)wirehemf);
wirehemf += sizeof(DWORD);
ok(*(DWORD *)wirehemf == (size - 0x10), "wirestgm + 0x8 should be size - 0x10 instead of 0x%08x\n", *(DWORD *)wirehemf);
ok(*(DWORD *)wirehemf == (size - 0x14), "wirestgm + 0x8 should be size - 0x14 instead of 0x%08x\n", *(DWORD *)wirehemf);
wirehemf += sizeof(DWORD);
ok(*(DWORD *)wirehemf == (size - 0x10), "wirestgm + 0xc should be size - 0x10 instead of 0x%08x\n", *(DWORD *)wirehemf);
ok(*(DWORD *)wirehemf == (size - 0x14), "wirestgm + 0xc should be size - 0x14 instead of 0x%08x\n", *(DWORD *)wirehemf);
wirehemf += sizeof(DWORD);
ok(*(DWORD *)wirehemf == EMR_HEADER, "wirestgm + 0x10 should be EMR_HEADER instead of %d\n", *(DWORD *)wirehemf);
/* ... rest of data not tested - refer to tests for GetEnhMetaFileBits
* at this point */
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE);
HENHMETAFILE_UserUnmarshal(&umcb.Flags, buffer, &hemf2);
buffer_end = HENHMETAFILE_UserUnmarshal(&umcb.Flags, buffer + 1, &hemf2);
ok(buffer_end == buffer + size, "got %p buffer %p\n", buffer_end, buffer);
ok(hemf2 != NULL, "HENHMETAFILE didn't unmarshal\n");
HeapFree(GetProcessHeap(), 0, buffer);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_DIFFERENTMACHINE);
@ -374,18 +379,20 @@ static void test_marshal_HENHMETAFILE(void)
hemf = NULL;
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_DIFFERENTMACHINE);
size = HENHMETAFILE_UserSize(&umcb.Flags, 0, &hemf);
ok(size == 8, "size should be 8 bytes, not %d\n", size);
size = HENHMETAFILE_UserSize(&umcb.Flags, 1, &hemf);
ok(size == 12, "size should be 12 bytes, not %d\n", size);
buffer = HeapAlloc(GetProcessHeap(), 0, size);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE);
HENHMETAFILE_UserMarshal(&umcb.Flags, buffer, &hemf);
wirehemf = buffer;
buffer_end = HENHMETAFILE_UserMarshal(&umcb.Flags, buffer + 1, &hemf);
ok(buffer_end == buffer + size, "got %p buffer %p\n", buffer_end, buffer);
wirehemf = buffer + 4;
ok(*(DWORD *)wirehemf == WDT_REMOTE_CALL, "wirestgm + 0x0 should be WDT_REMOTE_CALL instead of 0x%08x\n", *(DWORD *)wirehemf);
wirehemf += sizeof(DWORD);
ok(*(DWORD *)wirehemf == (DWORD)(DWORD_PTR)hemf, "wirestgm + 0x4 should be hemf instead of 0x%08x\n", *(DWORD *)wirehemf);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE);
HENHMETAFILE_UserUnmarshal(&umcb.Flags, buffer, &hemf2);
buffer_end = HENHMETAFILE_UserUnmarshal(&umcb.Flags, buffer + 1, &hemf2);
ok(buffer_end == buffer + size, "got %p buffer %p\n", buffer_end, buffer);
ok(hemf2 == NULL, "NULL HENHMETAFILE didn't unmarshal\n");
HeapFree(GetProcessHeap(), 0, buffer);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_DIFFERENTMACHINE);
@ -486,12 +493,12 @@ static void test_marshal_HMETAFILEPICT(void)
GlobalUnlock(hmfp);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_DIFFERENTMACHINE);
size = HMETAFILEPICT_UserSize(&umcb.Flags, 0, &hmfp);
ok(size > 20, "size should be at least 20 bytes, not %d\n", size);
size = HMETAFILEPICT_UserSize(&umcb.Flags, 1, &hmfp);
ok(size > 24, "size should be at least 24 bytes, not %d\n", size);
buffer = HeapAlloc(GetProcessHeap(), 0, size);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE);
buffer_end = HMETAFILEPICT_UserMarshal(&umcb.Flags, buffer, &hmfp);
wirehmfp = buffer;
buffer_end = HMETAFILEPICT_UserMarshal(&umcb.Flags, buffer + 1, &hmfp);
wirehmfp = buffer + 4;
ok(*(DWORD *)wirehmfp == WDT_REMOTE_CALL, "wirestgm + 0x0 should be WDT_REMOTE_CALL instead of 0x%08x\n", *(DWORD *)wirehmfp);
wirehmfp += sizeof(DWORD);
ok(*(DWORD *)wirehmfp == (DWORD)(DWORD_PTR)hmfp, "wirestgm + 0x4 should be hmf instead of 0x%08x\n", *(DWORD *)wirehmfp);
@ -512,16 +519,16 @@ static void test_marshal_HMETAFILEPICT(void)
wirehmfp += sizeof(DWORD);
/* Note use (buffer_end - buffer) instead of size here, because size is an
* overestimate with native */
ok(*(DWORD *)wirehmfp == (buffer_end - buffer - 0x28), "wirestgm + 0x20 should be size - 0x34 instead of 0x%08x\n", *(DWORD *)wirehmfp);
ok(*(DWORD *)wirehmfp == (buffer_end - buffer - 0x2c), "wirestgm + 0x20 should be size - 0x34 instead of 0x%08x\n", *(DWORD *)wirehmfp);
wirehmfp += sizeof(DWORD);
ok(*(DWORD *)wirehmfp == (buffer_end - buffer - 0x28), "wirestgm + 0x24 should be size - 0x34 instead of 0x%08x\n", *(DWORD *)wirehmfp);
ok(*(DWORD *)wirehmfp == (buffer_end - buffer - 0x2c), "wirestgm + 0x24 should be size - 0x34 instead of 0x%08x\n", *(DWORD *)wirehmfp);
wirehmfp += sizeof(DWORD);
ok(*(WORD *)wirehmfp == 1, "wirehmfp + 0x28 should be 1 instead of 0x%08x\n", *(DWORD *)wirehmfp);
/* ... rest of data not tested - refer to tests for GetMetaFileBits
* at this point */
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE);
HMETAFILEPICT_UserUnmarshal(&umcb.Flags, buffer, &hmfp2);
HMETAFILEPICT_UserUnmarshal(&umcb.Flags, buffer + 1, &hmfp2);
ok(hmfp2 != NULL, "HMETAFILEPICT didn't unmarshal\n");
HeapFree(GetProcessHeap(), 0, buffer);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_DIFFERENTMACHINE);
@ -535,12 +542,13 @@ static void test_marshal_HMETAFILEPICT(void)
hmfp = NULL;
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_DIFFERENTMACHINE);
size = HMETAFILEPICT_UserSize(&umcb.Flags, 0, &hmfp);
ok(size == 8, "size should be 8 bytes, not %d\n", size);
size = HMETAFILEPICT_UserSize(&umcb.Flags, 1, &hmfp);
ok(size == 12, "size should be 12 bytes, not %d\n", size);
buffer = HeapAlloc(GetProcessHeap(), 0, size);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE);
HMETAFILEPICT_UserMarshal(&umcb.Flags, buffer, &hmfp);
wirehmfp = buffer;
buffer_end = HMETAFILEPICT_UserMarshal(&umcb.Flags, buffer + 1, &hmfp);
ok(buffer_end == buffer + size, "got %p buffer %p\n", buffer_end, buffer);
wirehmfp = buffer + 4;
ok(*(DWORD *)wirehmfp == WDT_REMOTE_CALL, "wirestgm + 0x0 should be WDT_REMOTE_CALL instead of 0x%08x\n", *(DWORD *)wirehmfp);
wirehmfp += sizeof(DWORD);
ok(*(DWORD *)wirehmfp == (DWORD)(DWORD_PTR)hmfp, "wirestgm + 0x4 should be hmf instead of 0x%08x\n", *(DWORD *)wirehmfp);
@ -548,7 +556,8 @@ static void test_marshal_HMETAFILEPICT(void)
hmfp2 = NULL;
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE);
HMETAFILEPICT_UserUnmarshal(&umcb.Flags, buffer, &hmfp2);
buffer_end = HMETAFILEPICT_UserUnmarshal(&umcb.Flags, buffer + 1, &hmfp2);
ok(buffer_end == buffer + size, "got %p buffer %p\n", buffer_end, buffer);
ok(hmfp2 == NULL, "NULL HMETAFILE didn't unmarshal\n");
HeapFree(GetProcessHeap(), 0, buffer);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_DIFFERENTMACHINE);
@ -1082,23 +1091,25 @@ static void test_marshal_HDC(void)
HDC hdc = GetDC(0), hdc2;
USER_MARSHAL_CB umcb;
RPC_MESSAGE rpc_msg;
unsigned char *buffer;
unsigned char *buffer, *buffer_end;
wireHDC wirehdc;
ULONG size;
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_LOCAL);
size = HDC_UserSize(&umcb.Flags, 0, &hdc);
ok(size == sizeof(*wirehdc), "Wrong size %d\n", size);
size = HDC_UserSize(&umcb.Flags, 1, &hdc);
ok(size == 4 + sizeof(*wirehdc), "Wrong size %d\n", size);
buffer = HeapAlloc(GetProcessHeap(), 0, size);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL);
HDC_UserMarshal(&umcb.Flags, buffer, &hdc);
wirehdc = (wireHDC)buffer;
buffer_end = HDC_UserMarshal(&umcb.Flags, buffer + 1, &hdc);
ok(buffer_end == buffer + 4 + sizeof(*wirehdc), "got %p buffer %p\n", buffer_end, buffer);
wirehdc = (wireHDC)(buffer + 4);
ok(wirehdc->fContext == WDT_INPROC_CALL, "Context should be WDT_INPROC_CALL instead of 0x%08x\n", wirehdc->fContext);
ok(wirehdc->u.hInproc == (LONG_PTR)hdc, "Marshaled value should be %p instead of %x\n", hdc, wirehdc->u.hRemote);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL);
HDC_UserUnmarshal(&umcb.Flags, buffer, &hdc2);
buffer_end = HDC_UserUnmarshal(&umcb.Flags, buffer + 1, &hdc2);
ok(buffer_end == buffer + 4 + sizeof(*wirehdc), "got %p buffer %p\n", buffer_end, buffer);
ok(hdc == hdc2, "Didn't unmarshal properly\n");
HeapFree(GetProcessHeap(), 0, buffer);
@ -1114,7 +1125,7 @@ static void test_marshal_HICON(void)
HICON hIcon, hIcon2;
USER_MARSHAL_CB umcb;
RPC_MESSAGE rpc_msg;
unsigned char *buffer;
unsigned char *buffer, *buffer_end;
wireHICON wirehicon;
ULONG size;
@ -1122,18 +1133,20 @@ static void test_marshal_HICON(void)
ok(hIcon != 0, "CreateIcon failed\n");
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_LOCAL);
size = HICON_UserSize(&umcb.Flags, 0, &hIcon);
ok(size == sizeof(*wirehicon), "Wrong size %d\n", size);
size = HICON_UserSize(&umcb.Flags, 1, &hIcon);
ok(size == 4 + sizeof(*wirehicon), "Wrong size %d\n", size);
buffer = HeapAlloc(GetProcessHeap(), 0, size);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL);
HICON_UserMarshal(&umcb.Flags, buffer, &hIcon);
wirehicon = (wireHICON)buffer;
buffer_end = HICON_UserMarshal(&umcb.Flags, buffer + 1, &hIcon);
ok(buffer_end == buffer + 4 + sizeof(*wirehicon), "got %p buffer %p\n", buffer_end, buffer);
wirehicon = (wireHICON)(buffer + 4);
ok(wirehicon->fContext == WDT_INPROC_CALL, "Context should be WDT_INPROC_CALL instead of 0x%08x\n", wirehicon->fContext);
ok(wirehicon->u.hInproc == (LONG_PTR)hIcon, "Marshaled value should be %p instead of %x\n", hIcon, wirehicon->u.hRemote);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL);
HICON_UserUnmarshal(&umcb.Flags, buffer, &hIcon2);
buffer_end = HICON_UserUnmarshal(&umcb.Flags, buffer + 1, &hIcon2);
ok(buffer_end == buffer + 4 + sizeof(*wirehicon), "got %p buffer %p\n", buffer_end, buffer);
ok(hIcon == hIcon2, "Didn't unmarshal properly\n");
HeapFree(GetProcessHeap(), 0, buffer);
@ -1148,7 +1161,7 @@ static void test_marshal_HBRUSH(void)
HBRUSH hBrush, hBrush2;
USER_MARSHAL_CB umcb;
RPC_MESSAGE rpc_msg;
unsigned char *buffer;
unsigned char *buffer, *buffer_end;
LOGBRUSH logbrush;
wireHBRUSH wirehbrush;
ULONG size;
@ -1161,18 +1174,20 @@ static void test_marshal_HBRUSH(void)
ok(hBrush != 0, "CreateBrushIndirect failed\n");
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_LOCAL);
size = HBRUSH_UserSize(&umcb.Flags, 0, &hBrush);
ok(size == sizeof(*wirehbrush), "Wrong size %d\n", size);
size = HBRUSH_UserSize(&umcb.Flags, 1, &hBrush);
ok(size == 4 + sizeof(*wirehbrush), "Wrong size %d\n", size);
buffer = HeapAlloc(GetProcessHeap(), 0, size);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL);
HBRUSH_UserMarshal(&umcb.Flags, buffer, &hBrush);
wirehbrush = (wireHBRUSH)buffer;
buffer_end = HBRUSH_UserMarshal(&umcb.Flags, buffer + 1, &hBrush);
ok(buffer_end == buffer + 4 + sizeof(*wirehbrush), "got %p buffer %p\n", buffer_end, buffer);
wirehbrush = (wireHBRUSH)(buffer + 4);
ok(wirehbrush->fContext == WDT_INPROC_CALL, "Context should be WDT_INPROC_CALL instead of 0x%08x\n", wirehbrush->fContext);
ok(wirehbrush->u.hInproc == (LONG_PTR)hBrush, "Marshaled value should be %p instead of %x\n", hBrush, wirehbrush->u.hRemote);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL);
HBRUSH_UserUnmarshal(&umcb.Flags, buffer, &hBrush2);
buffer_end = HBRUSH_UserUnmarshal(&umcb.Flags, buffer + 1, &hBrush2);
ok(buffer_end == buffer + 4 + sizeof(*wirehbrush), "got %p buffer %p\n", buffer_end, buffer);
ok(hBrush == hBrush2, "Didn't unmarshal properly\n");
HeapFree(GetProcessHeap(), 0, buffer);
@ -1181,6 +1196,69 @@ static void test_marshal_HBRUSH(void)
DeleteObject(hBrush);
}
static void test_marshal_HBITMAP(void)
{
static const ULONG header_size = FIELD_OFFSET(userBITMAP, cbSize);
static BYTE bmp_bits[1024];
MIDL_STUB_MESSAGE stub_msg;
HBITMAP hBitmap, hBitmap2;
USER_MARSHAL_CB umcb;
RPC_MESSAGE rpc_msg;
unsigned char *buffer, *buffer_end;
unsigned char bitmap[1024];
ULONG size, bitmap_size;
hBitmap = CreateBitmap(16, 16, 1, 1, bmp_bits);
ok(hBitmap != 0, "CreateBitmap failed\n");
size = GetObjectA(hBitmap, sizeof(bitmap), bitmap);
ok(size != 0, "GetObject failed\n");
bitmap_size = GetBitmapBits(hBitmap, 0, NULL);
ok(bitmap_size != 0, "GetBitmapBits failed\n");
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_INPROC);
size = HBITMAP_UserSize(&umcb.Flags, 1, &hBitmap);
ok(size == 0xc, "Wrong size %d\n", size);
buffer = HeapAlloc(GetProcessHeap(), 0, size + 4);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_INPROC);
buffer_end = HBITMAP_UserMarshal(&umcb.Flags, buffer + 1, &hBitmap);
ok(buffer_end == buffer + 0xc, "HBITMAP_UserMarshal() returned wrong size %d\n", (LONG)(buffer_end - buffer));
ok(*(ULONG *)(buffer + 0x4) == WDT_INPROC_CALL, "Context should be WDT_INPROC_CALL instead of 0x%08x\n", *(ULONG *)(buffer + 0x4));
ok(*(ULONG *)(buffer + 0x8) == (ULONG)(ULONG_PTR)hBitmap, "wirestgm + 0x4 should be bitmap handle instead of 0x%08x\n", *(ULONG *)(buffer + 0x8));
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_INPROC);
HBITMAP_UserUnmarshal(&umcb.Flags, buffer + 1, &hBitmap2);
ok(hBitmap2 != NULL, "Didn't unmarshal properly\n");
HeapFree(GetProcessHeap(), 0, buffer);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_INPROC);
HBITMAP_UserFree(&umcb.Flags, &hBitmap2);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_LOCAL);
size = HBITMAP_UserSize(&umcb.Flags, 1, &hBitmap);
ok(size == 0x10 + header_size + bitmap_size ||
broken(size == 0x14 + header_size + bitmap_size), /* Windows adds 4 extra (unused) bytes */
"Wrong size %d\n", size);
buffer = HeapAlloc(GetProcessHeap(), 0, size + 4);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL);
buffer_end = HBITMAP_UserMarshal(&umcb.Flags, buffer + 1, &hBitmap);
ok(buffer_end == buffer + 0x10 + header_size + bitmap_size, "HBITMAP_UserMarshal() returned wrong size %d\n", (LONG)(buffer_end - buffer));
ok(*(ULONG *)(buffer + 0x4) == WDT_REMOTE_CALL, "Context should be WDT_REMOTE_CALL instead of 0x%08x\n", *(ULONG *)buffer);
ok(*(ULONG *)(buffer + 0x8) == (ULONG)(ULONG_PTR)hBitmap, "wirestgm + 0x4 should be bitmap handle instead of 0x%08x\n", *(ULONG *)(buffer + 0x4));
ok(*(ULONG *)(buffer + 0xc) == (ULONG)(ULONG_PTR)bitmap_size, "wirestgm + 0x8 should be bitmap size instead of 0x%08x\n", *(ULONG *)(buffer + 0x4));
ok(!memcmp(buffer + 0x10, bitmap, header_size), "buffer mismatch\n");
ok(!memcmp(buffer + 0x10 + header_size, bmp_bits, bitmap_size), "buffer mismatch\n");
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL);
HBITMAP_UserUnmarshal(&umcb.Flags, buffer + 1, &hBitmap2);
ok(hBitmap2 != NULL, "Didn't unmarshal properly\n");
HeapFree(GetProcessHeap(), 0, buffer);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_LOCAL);
HBITMAP_UserFree(&umcb.Flags, &hBitmap2);
DeleteObject(hBitmap);
}
struct obj
{
IDataObject IDataObject_iface;
@ -1344,6 +1422,7 @@ START_TEST(usrmarshal)
test_marshal_HDC();
test_marshal_HICON();
test_marshal_HBRUSH();
test_marshal_HBITMAP();
test_GetDataHere_Proxy();