d3d11/tests: Add test for D3D11CreateDevice.
[wine.git] / dlls / d3d11 / tests / d3d11.c
blobf31380611b41d01a77fa847150ee2be60df692aa
1 /*
2 * Copyright 2015 Józef Kucia for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
20 #include "initguid.h"
21 #include "d3d11.h"
22 #include "wine/test.h"
24 static ULONG get_refcount(IUnknown *iface)
26 IUnknown_AddRef(iface);
27 return IUnknown_Release(iface);
30 static ID3D11Device *create_device(D3D_FEATURE_LEVEL feature_level)
32 ID3D11Device *device;
34 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &feature_level, 1, D3D11_SDK_VERSION,
35 &device, NULL, NULL)))
36 return device;
37 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, 0, &feature_level, 1, D3D11_SDK_VERSION,
38 &device, NULL, NULL)))
39 return device;
40 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, 0, &feature_level, 1, D3D11_SDK_VERSION,
41 &device, NULL, NULL)))
42 return device;
44 return NULL;
47 static void test_create_device(void)
49 D3D_FEATURE_LEVEL feature_level, supported_feature_level;
50 ID3D11DeviceContext *immediate_context = NULL;
51 ID3D11Device *device;
52 ULONG refcount;
53 HRESULT hr;
55 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, &device,
56 NULL, NULL);
57 if (FAILED(hr))
59 skip("Failed to create HAL device, skipping tests.\n");
60 return;
63 supported_feature_level = ID3D11Device_GetFeatureLevel(device);
64 ID3D11Device_Release(device);
66 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL, NULL);
67 ok(SUCCEEDED(hr), "D3D11CreateDevice failed %#x.\n", hr);
69 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL,
70 &feature_level, NULL);
71 ok(SUCCEEDED(hr), "D3D11CreateDevice failed %#x.\n", hr);
72 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
73 feature_level, supported_feature_level);
75 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL,
76 &immediate_context);
77 ok(SUCCEEDED(hr), "D3D11CreateDevice failed %#x.\n", hr);
79 todo_wine ok(!!immediate_context, "Immediate context is NULL.\n");
80 if (!immediate_context) return;
82 refcount = get_refcount((IUnknown *)immediate_context);
83 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
85 ID3D11DeviceContext_GetDevice(immediate_context, &device);
86 refcount = ID3D11Device_Release(device);
87 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
89 refcount = ID3D11DeviceContext_Release(immediate_context);
90 ok(!refcount, "ID3D11DeviceContext has %u references left.\n", refcount);
93 static void test_device_interfaces(void)
95 static const D3D_FEATURE_LEVEL feature_levels[] =
97 D3D_FEATURE_LEVEL_11_1,
98 D3D_FEATURE_LEVEL_11_0,
99 D3D_FEATURE_LEVEL_10_1,
100 D3D_FEATURE_LEVEL_10_0,
101 D3D_FEATURE_LEVEL_9_3,
102 D3D_FEATURE_LEVEL_9_2,
103 D3D_FEATURE_LEVEL_9_1
105 ID3D11Device *device;
106 IUnknown *iface;
107 ULONG refcount;
108 unsigned int i;
109 HRESULT hr;
111 for (i = 0; i < sizeof(feature_levels) / sizeof(*feature_levels); i++)
113 if (!(device = create_device(feature_levels[i])))
115 skip("Failed to create device for feature level %#x, skipping tests.\n", feature_levels[i]);
116 continue;
119 hr = ID3D11Device_QueryInterface(device, &IID_IUnknown, (void **)&iface);
120 ok(SUCCEEDED(hr), "Device should implement IUnknown interface, hr %#x.\n", hr);
121 IUnknown_Release(iface);
123 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIObject, (void **)&iface);
124 ok(SUCCEEDED(hr), "Device should implement IDXGIObject interface, hr %#x.\n", hr);
125 IUnknown_Release(iface);
127 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&iface);
128 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice interface, hr %#x.\n", hr);
129 IUnknown_Release(iface);
131 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Multithread, (void **)&iface);
132 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
133 "Device should implement ID3D10Multithread interface, hr %#x.\n", hr);
134 if (SUCCEEDED(hr)) IUnknown_Release(iface);
136 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Device, (void **)&iface);
137 todo_wine ok(hr == E_NOINTERFACE, "Device should not implement ID3D10Device interface, hr %#x.\n", hr);
138 if (SUCCEEDED(hr)) IUnknown_Release(iface);
140 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Device1, (void **)&iface);
141 todo_wine ok(hr == E_NOINTERFACE, "Device should not implement ID3D10Device1 interface, hr %#x.\n", hr);
142 if (SUCCEEDED(hr)) IUnknown_Release(iface);
144 refcount = ID3D11Device_Release(device);
145 ok(!refcount, "Device has %u references left.\n", refcount);
149 START_TEST(d3d11)
151 test_create_device();
152 test_device_interfaces();