From: Zhiyi Zhang zzhang@codeweavers.com
--- configure.ac | 1 + dlls/dcomp/tests/Makefile.in | 5 ++ dlls/dcomp/tests/dcomp.c | 152 +++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 dlls/dcomp/tests/Makefile.in create mode 100644 dlls/dcomp/tests/dcomp.c
diff --git a/configure.ac b/configure.ac index 84fadd08853..a514d658775 100644 --- a/configure.ac +++ b/configure.ac @@ -2513,6 +2513,7 @@ WINE_CONFIG_MAKEFILE(dlls/dbghelp) WINE_CONFIG_MAKEFILE(dlls/dbghelp/tests) WINE_CONFIG_MAKEFILE(dlls/dciman32) WINE_CONFIG_MAKEFILE(dlls/dcomp) +WINE_CONFIG_MAKEFILE(dlls/dcomp/tests) WINE_CONFIG_MAKEFILE(dlls/ddeml.dll16,enable_win16) WINE_CONFIG_MAKEFILE(dlls/ddraw) WINE_CONFIG_MAKEFILE(dlls/ddraw/tests) diff --git a/dlls/dcomp/tests/Makefile.in b/dlls/dcomp/tests/Makefile.in new file mode 100644 index 00000000000..f1ad3efeb4d --- /dev/null +++ b/dlls/dcomp/tests/Makefile.in @@ -0,0 +1,5 @@ +TESTDLL = dcomp.dll +IMPORTS = d3d10_1 + +C_SRCS = \ + dcomp.c diff --git a/dlls/dcomp/tests/dcomp.c b/dlls/dcomp/tests/dcomp.c new file mode 100644 index 00000000000..688991e180f --- /dev/null +++ b/dlls/dcomp/tests/dcomp.c @@ -0,0 +1,152 @@ +/* + * Unit test for DirectComposition + * + * Copyright 2023 Zhiyi Zhang for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#define COBJMACROS +#include "initguid.h" +#include <d3d10_1.h> +#include "dcomp.h" +#include "wine/test.h" + +static HRESULT (WINAPI *pDCompositionCreateDevice)(IDXGIDevice *dxgi_device, REFIID iid, void **device); + +static IDXGIDevice *create_device(unsigned int flags) +{ + IDXGIDevice *dxgi_device; + ID3D10Device1 *device; + HRESULT hr; + + hr = D3D10CreateDevice1(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, flags, D3D10_FEATURE_LEVEL_10_0, + D3D10_1_SDK_VERSION, &device); + if (SUCCEEDED(hr)) + goto success; + if (SUCCEEDED(D3D10CreateDevice1(NULL, D3D10_DRIVER_TYPE_WARP, NULL, flags, + D3D10_FEATURE_LEVEL_10_0, D3D10_1_SDK_VERSION, &device))) + goto success; + if (SUCCEEDED(D3D10CreateDevice1(NULL, D3D10_DRIVER_TYPE_REFERENCE, NULL, flags, + D3D10_FEATURE_LEVEL_10_0, D3D10_1_SDK_VERSION, &device))) + goto success; + + return NULL; + +success: + hr = ID3D10Device1_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device); + ok(SUCCEEDED(hr), "Created device does not implement IDXGIDevice.\n"); + ID3D10Device1_Release(device); + return dxgi_device; +} + +static void test_DCompositionCreateDevice(void) +{ + IDCompositionDevice2 *dcomp_device2; + IDCompositionDevice *dcomp_device; + IDXGIDevice *dxgi_device; + ULONG refcount; + HRESULT hr; + + /* D3D device created without BGRA support */ + if (!(dxgi_device = create_device(0))) + { + skip("Failed to create device.\n"); + return; + } + + hr = pDCompositionCreateDevice(dxgi_device, &IID_IDCompositionDevice, (void **)&dcomp_device); + todo_wine + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + if (SUCCEEDED(hr)) + { + refcount = IDCompositionDevice_Release(dcomp_device); + ok(!refcount, "Device has %lu references left.\n", refcount); + } + refcount = IDXGIDevice_Release(dxgi_device); + ok(!refcount, "Device has %lu references left.\n", refcount); + + /* D3D device created with BGRA support */ + if (!(dxgi_device = create_device(D3D10_CREATE_DEVICE_BGRA_SUPPORT))) + { + skip("Failed to create device.\n"); + return; + } + + hr = pDCompositionCreateDevice(dxgi_device, &IID_IDCompositionDevice, (void **)&dcomp_device); + todo_wine + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + if (SUCCEEDED(hr)) + { + /* Device created from DCompositionCreateDevice() doesn't support IDCompositionDevice2 */ + hr = IDCompositionDevice_QueryInterface(dcomp_device, &IID_IDCompositionDevice2, + (void **)&dcomp_device2); + ok(hr == E_NOINTERFACE, "Got unexpected hr %#lx.\n", hr); + refcount = IDCompositionDevice_Release(dcomp_device); + ok(!refcount, "Device has %lu references left.\n", refcount); + } + + /* Parameter checks */ + hr = pDCompositionCreateDevice(NULL, &IID_IDCompositionDevice, (void **)&dcomp_device); + todo_wine + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + if (SUCCEEDED(hr)) + { + refcount = IDCompositionDevice_Release(dcomp_device); + ok(!refcount, "Device has %lu references left.\n", refcount); + } + + /* Crash on Windows */ + if (0) + { + hr = pDCompositionCreateDevice(dxgi_device, NULL, (void **)&dcomp_device); + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + } + + hr = pDCompositionCreateDevice(dxgi_device, &IID_IDCompositionDevice2, (void **)&dcomp_device); + todo_wine + ok(hr == E_NOINTERFACE, "Got unexpected hr %#lx.\n", hr); + + hr = pDCompositionCreateDevice(dxgi_device, &IID_IDCompositionDevice, NULL); + todo_wine + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + + refcount = IDXGIDevice_Release(dxgi_device); + ok(!refcount, "Device has %lu references left.\n", refcount); +} + +START_TEST(dcomp) +{ + HMODULE module; + + module = LoadLibraryW(L"dcomp.dll"); + if (!module) + { + win_skip("dcomp.dll not found.\n"); + return; + } + + pDCompositionCreateDevice = (void *)GetProcAddress(module, "DCompositionCreateDevice"); + if (!pDCompositionCreateDevice) + { + win_skip("DCompositionCreateDevice() is unavailable.\n"); + FreeLibrary(module); + return; + } + + test_DCompositionCreateDevice(); + + FreeLibrary(module); +}