[PATCH vkd3d 05/12] tests: Add test for creating vkd3d instances.

Józef Kucia joseph.kucia at gmail.com
Thu Jan 11 10:03:48 CST 2018


From: Józef Kucia <jkucia at codeweavers.com>

Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
 Makefile.am       | 11 +++++---
 tests/vkd3d_api.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+), 4 deletions(-)
 create mode 100644 tests/vkd3d_api.c

diff --git a/Makefile.am b/Makefile.am
index 4d32b2fde1f0..2876f6486df4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -33,6 +33,9 @@ vkd3d_demos_shaders = \
 	demos/triangle_vs.h
 
 vkd3d_tests = \
+	tests/vkd3d_api
+
+vkd3d_cross_tests = \
 	tests/d3d12
 
 vkd3d_demos = \
@@ -101,9 +104,9 @@ vkd3d_compiler_SOURCES = programs/vkd3d-compiler/main.c
 vkd3d_compiler_LDADD = libvkd3d-shader.la
 
 LDADD = libvkd3d.la libvkd3d-utils.la
-check_PROGRAMS = $(vkd3d_tests)
+check_PROGRAMS = $(vkd3d_tests) $(vkd3d_cross_tests)
 AM_DEFAULT_SOURCE_EXT = .c
-TESTS = $(vkd3d_tests)
+TESTS = $(vkd3d_tests) $(vkd3d_cross_tests)
 tests_d3d12_LDADD = $(LDADD) @PTHREAD_LIBS@
 
 DEMOS_LDADD = $(LDADD) libvkd3d-shader.la @XCB_LIBS@ @VULKAN_LIBS@
@@ -154,7 +157,7 @@ if HAS_CROSSTARGET32
 CROSS32_CC = @CROSSCC32@
 CROSS32_DLLTOOL = @CROSSTARGET32 at -dlltool
 CROSS32_IMPLIBS = $(cross_implibs:=.cross32.a)
-CROSS32_EXEFILES = $(vkd3d_tests:=.cross32.exe) $(vkd3d_demos:=.cross32.exe)
+CROSS32_EXEFILES = $(vkd3d_cross_tests:=.cross32.exe) $(vkd3d_demos:=.cross32.exe)
 CROSS32_FILES = $(CROSS32_IMPLIBS) $(CROSS32_EXEFILES)
 
 CLEANFILES += $(CROSS32_FILES)
@@ -179,7 +182,7 @@ if HAS_CROSSTARGET64
 CROSS64_CC = @CROSSCC64@
 CROSS64_DLLTOOL = @CROSSTARGET64 at -dlltool
 CROSS64_IMPLIBS = $(cross_implibs:=.cross64.a)
-CROSS64_EXEFILES = $(vkd3d_tests:=.cross64.exe) $(vkd3d_demos:=.cross64.exe)
+CROSS64_EXEFILES = $(vkd3d_cross_tests:=.cross64.exe) $(vkd3d_demos:=.cross64.exe)
 CROSS64_FILES = $(CROSS64_IMPLIBS) $(CROSS64_EXEFILES)
 
 CLEANFILES += $(CROSS64_FILES)
diff --git a/tests/vkd3d_api.c b/tests/vkd3d_api.c
new file mode 100644
index 000000000000..871dbe29349d
--- /dev/null
+++ b/tests/vkd3d_api.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2018 Józef Kucia 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
+#define INITGUID
+#define WIDL_C_INLINE_WRAPPERS
+#include "vkd3d_test.h"
+#include <vkd3d.h>
+
+static bool signal_event(HANDLE event)
+{
+    trace("Signal event %p.\n", event);
+    return true;
+}
+
+static void test_create_instance(void)
+{
+    struct vkd3d_instance_create_info create_info;
+    struct vkd3d_instance *instance;
+    ULONG refcount;
+    HRESULT hr;
+
+    memset(&create_info, 0, sizeof(create_info));
+    create_info.wchar_size = sizeof(WCHAR);
+
+    hr = vkd3d_create_instance(&create_info, &instance);
+    ok(hr == S_OK, "Failed to create instance, hr %#x.\n", hr);
+    refcount = vkd3d_instance_incref(instance);
+    ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
+    vkd3d_instance_decref(instance);
+    refcount = vkd3d_instance_decref(instance);
+    ok(!refcount, "Instance has %u references left.\n", refcount);
+
+    create_info.signal_event_pfn = signal_event;
+    hr = vkd3d_create_instance(&create_info, &instance);
+    ok(hr == S_OK, "Failed to create instance, hr %#x.\n", hr);
+    refcount = vkd3d_instance_decref(instance);
+    ok(!refcount, "Instance has %u references left.\n", refcount);
+}
+
+static bool have_d3d12_device(void)
+{
+    struct vkd3d_instance_create_info instance_create_info =
+    {
+        .wchar_size = sizeof(WCHAR),
+    };
+    struct vkd3d_device_create_info device_create_info =
+    {
+        .minimum_feature_level = D3D_FEATURE_LEVEL_11_0,
+        .instance_create_info = &instance_create_info,
+    };
+    ID3D12Device *device;
+    HRESULT hr;
+
+    if (SUCCEEDED(hr = vkd3d_create_device(&device_create_info, &IID_ID3D12Device, (void **)&device)))
+        ID3D12Device_Release(device);
+    return hr == S_OK;
+}
+
+START_TEST(vkd3d_api)
+{
+    if (!have_d3d12_device())
+    {
+        skip("D3D12 device cannot be created.\n");
+        return;
+    }
+
+    run_test(test_create_instance);
+}
-- 
2.13.6




More information about the wine-devel mailing list