From: Mohamad Al-Jaf mohamadaljaf@gmail.com
--- dlls/wintypes/tests/wintypes.c | 104 ++++++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 1 deletion(-)
diff --git a/dlls/wintypes/tests/wintypes.c b/dlls/wintypes/tests/wintypes.c index 90bd32513f8..727c36511f3 100644 --- a/dlls/wintypes/tests/wintypes.c +++ b/dlls/wintypes/tests/wintypes.c @@ -17,6 +17,7 @@ */ #define COBJMACROS #include <stdarg.h> +#include <stdint.h>
#include "windef.h" #include "winbase.h" @@ -134,9 +135,23 @@ static void test_interfaces(void) RoUninitialize(); }
+static UINT32 get_max_capacity(void) +{ + SYSTEM_INFO sys_info; + UINT_PTR max_addr; + + if (is_wow64) return 0x7FFEFFFF; + + GetNativeSystemInfo( &sys_info ); + max_addr = (UINT_PTR)sys_info.lpMaximumApplicationAddress; + + return (max_addr > UINT32_MAX) ? UINT32_MAX : max_addr; +} + static void test_IBufferStatics(void) { static const WCHAR *class_name = L"Windows.Storage.Streams.Buffer"; + UINT32 capacity, max_capacity, length; IBufferFactory *buffer_factory = NULL; IActivationFactory *factory = NULL; IBuffer *buffer = NULL; @@ -175,8 +190,95 @@ static void test_IBufferStatics(void) hr = IBufferFactory_Create(buffer_factory, 0, &buffer); todo_wine ok(hr == S_OK, "IBufferFactory_Create failed, hr %#lx.\n", hr); - if (hr == S_OK) IBuffer_Release(buffer); + if (hr != S_OK) goto done; + + check_interface(buffer, &IID_IAgileObject, TRUE); + + if (0) /* Crash on Windows */ + { + hr = IBuffer_get_Capacity(buffer, NULL); + ok(hr == E_INVALIDARG, "IBuffer_get_Capacity failed, hr %#lx.\n", hr); + } + + capacity = 0xdeadbeef; + hr = IBuffer_get_Capacity(buffer, &capacity); + todo_wine + ok(hr == S_OK, "IBuffer_get_Capacity failed, hr %#lx.\n", hr); + todo_wine + ok(capacity == 0, "IBuffer_get_Capacity returned capacity %u.\n", capacity); + + if (0) /* Crash on Windows */ + { + hr = IBuffer_get_Length(buffer, NULL); + ok(hr == E_INVALIDARG, "IBuffer_get_Length failed, hr %#lx.\n", hr); + } + + length = 0xdeadbeef; + hr = IBuffer_get_Length(buffer, &length); + todo_wine + ok(hr == S_OK, "IBuffer_get_Length failed, hr %#lx.\n", hr); + todo_wine + ok(length == 0, "IBuffer_get_Length returned length %u.\n", length); + + hr = IBuffer_put_Length(buffer, 1); + todo_wine + ok(hr == E_INVALIDARG, "IBuffer_put_Length failed, hr %#lx.\n", hr); + + IBuffer_Release(buffer); + + capacity = 0xdeadbeef; + max_capacity = get_max_capacity(); + buffer = (void *)0xdeadbeef; + hr = IBufferFactory_Create(buffer_factory, capacity, &buffer); + todo_wine + ok(hr == S_OK || (hr == E_OUTOFMEMORY && capacity > max_capacity), "IBufferFactory_Create failed, hr %#lx.\n", hr); + if (hr == E_OUTOFMEMORY) /* 32-bit memory limitation, Large Address Aware is ignored */ + { + todo_wine + ok(buffer == NULL, "IBufferFactory_Create returned buffer %p.\n", buffer); + goto done; + } + + capacity = 0; + hr = IBuffer_get_Capacity(buffer, &capacity); + todo_wine + ok(hr == S_OK, "IBuffer_get_Capacity failed, hr %#lx.\n", hr); + todo_wine + ok(capacity == 0xdeadbeef, "IBuffer_get_Capacity returned capacity %u.\n", capacity); + + length = 0xdeadbeef; + hr = IBuffer_get_Length(buffer, &length); + todo_wine + ok(hr == S_OK, "IBuffer_get_Length failed, hr %#lx.\n", hr); + todo_wine + ok(length == 0, "IBuffer_get_Length returned length %u.\n", length); + + hr = IBuffer_put_Length(buffer, 1); + todo_wine + ok(hr == S_OK, "IBuffer_put_Length failed, hr %#lx.\n", hr); + length = 0xdeadbeef; + hr = IBuffer_get_Length(buffer, &length); + todo_wine + ok(hr == S_OK, "IBuffer_get_Length failed, hr %#lx.\n", hr); + todo_wine + ok(length == 1, "IBuffer_get_Length returned length %u.\n", length); + + hr = IBuffer_put_Length(buffer, 0xdeadbeef + 1); + todo_wine + ok(hr == E_INVALIDARG, "IBuffer_put_Length failed, hr %#lx.\n", hr); + + hr = IBuffer_put_Length(buffer, 0xdeadbeef); + todo_wine + ok(hr == S_OK, "IBuffer_put_Length failed, hr %#lx.\n", hr); + length = 0; + hr = IBuffer_get_Length(buffer, &length); + todo_wine + ok(hr == S_OK, "IBuffer_get_Length failed, hr %#lx.\n", hr); + todo_wine + ok(length == 0xdeadbeef, "IBuffer_get_Length returned length %u.\n", length);
+ IBuffer_Release(buffer); +done: IBufferFactory_Release(buffer_factory); IActivationFactory_Release(factory); RoUninitialize();