d3dx8: Add a few tests for MatrixStack.
[wine] / dlls / dxgi / tests / device.c
1 /*
2  * Copyright 2008 Henri Verbeet for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #define COBJMACROS
20 #include "initguid.h"
21 #include "d3d10.h"
22 #include "wine/test.h"
23
24 HRESULT WINAPI DXGID3D10CreateDevice(HMODULE d3d10core, IDXGIFactory *factory,
25         IDXGIAdapter *adapter, UINT flags, DWORD arg5, void **device);
26
27 static IDXGIDevice *create_device(HMODULE d3d10core)
28 {
29     IDXGIDevice *dxgi_device = NULL;
30     IDXGIFactory *factory = NULL;
31     IDXGIAdapter *adapter = NULL;
32     IUnknown *device = NULL;
33     HRESULT hr;
34
35     hr = CreateDXGIFactory(&IID_IDXGIFactory, (void *)&factory);
36     ok(SUCCEEDED(hr), "CreateDXGIFactory failed, hr %#x\n", hr);
37     if (FAILED(hr)) goto cleanup;
38
39     hr = IDXGIFactory_EnumAdapters(factory, 0, &adapter);
40     ok(SUCCEEDED(hr), "EnumAdapters failed, hr %#x\n", hr);
41     if (FAILED(hr)) goto cleanup;
42
43     hr = DXGID3D10CreateDevice(d3d10core, factory, adapter, 0, 0, (void **)&device);
44     if (FAILED(hr))
45     {
46         HMODULE d3d10ref;
47
48         trace("Failed to create a HW device, trying REF\n");
49         IDXGIAdapter_Release(adapter);
50         adapter = NULL;
51
52         d3d10ref = LoadLibraryA("d3d10ref.dll");
53         if (!d3d10ref)
54         {
55             trace("d3d10ref.dll not available, unable to create a REF device\n");
56             goto cleanup;
57         }
58
59         hr = IDXGIFactory_CreateSoftwareAdapter(factory, d3d10ref, &adapter);
60         FreeLibrary(d3d10ref);
61         ok(SUCCEEDED(hr), "CreateSoftwareAdapter failed, hr %#x\n", hr);
62         if (FAILED(hr)) goto cleanup;
63
64         hr = DXGID3D10CreateDevice(d3d10core, factory, adapter, 0, 0, (void **)&device);
65         ok(SUCCEEDED(hr), "Failed to create a REF device, hr %#x\n", hr);
66         if (FAILED(hr)) goto cleanup;
67     }
68
69     hr = IUnknown_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
70     ok(SUCCEEDED(hr), "Created device does not implement IDXGIDevice\n");
71     IUnknown_Release(device);
72
73 cleanup:
74     if (adapter) IDXGIAdapter_Release(adapter);
75     if (factory) IDXGIFactory_Release(factory);
76
77     return dxgi_device;
78 }
79
80 static void test_device_interfaces(IDXGIDevice *device)
81 {
82     IUnknown *obj;
83     HRESULT hr;
84
85     if (SUCCEEDED(hr = IDXGIDevice_QueryInterface(device, &IID_IUnknown, (void **)&obj)))
86         IUnknown_Release(obj);
87     ok(SUCCEEDED(hr), "IDXGIDevice does not implement IUnknown\n");
88
89     if (SUCCEEDED(hr = IDXGIDevice_QueryInterface(device, &IID_IDXGIObject, (void **)&obj)))
90         IUnknown_Release(obj);
91     ok(SUCCEEDED(hr), "IDXGIDevice does not implement IDXGIObject\n");
92
93     if (SUCCEEDED(hr = IDXGIDevice_QueryInterface(device, &IID_IDXGIDevice, (void **)&obj)))
94         IUnknown_Release(obj);
95     ok(SUCCEEDED(hr), "IDXGIDevice does not implement IDXGIDevice\n");
96
97     if (SUCCEEDED(hr = IDXGIDevice_QueryInterface(device, &IID_ID3D10Device, (void **)&obj)))
98         IUnknown_Release(obj);
99     ok(SUCCEEDED(hr), "IDXGIDevice does not implement ID3D10Device\n");
100 }
101
102 START_TEST(device)
103 {
104     HMODULE d3d10core = LoadLibraryA("d3d10core.dll");
105     IDXGIDevice *device;
106     ULONG refcount;
107
108     if (!d3d10core)
109     {
110         win_skip("d3d10core.dll not available, skipping tests\n");
111         return;
112     }
113
114     device = create_device(d3d10core);
115     if (!device)
116     {
117         skip("Failed to create device, skipping tests\n");
118         FreeLibrary(d3d10core);
119         return;
120     }
121
122     test_device_interfaces(device);
123
124     refcount = IDXGIDevice_Release(device);
125     ok(!refcount, "Device has %u references left\n", refcount);
126     FreeLibrary(d3d10core);
127 }