shlwapi: Beginning implementation of IUnknown_QueryServiceForWebBrowserApp.
[wine] / dlls / d3d10core / 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 D3D10CoreCreateDevice(IDXGIFactory *factory, IDXGIAdapter *adapter,
25         UINT flags, void *unknown0, ID3D10Device **device);
26
27 static ID3D10Device *create_device(void)
28 {
29     IDXGIFactory *factory = NULL;
30     IDXGIAdapter *adapter = NULL;
31     ID3D10Device *device = NULL;
32     HRESULT hr;
33
34     hr = CreateDXGIFactory(&IID_IDXGIFactory, (void *)&factory);
35     if (FAILED(hr)) goto cleanup;
36
37     hr = IDXGIFactory_EnumAdapters(factory, 0, &adapter);
38     ok(SUCCEEDED(hr), "EnumAdapters failed, hr %#x\n", hr);
39     if (FAILED(hr)) goto cleanup;
40
41     hr = D3D10CoreCreateDevice(factory, adapter, 0, NULL, &device);
42     if (FAILED(hr))
43     {
44         HMODULE d3d10ref;
45
46         trace("Failed to create a HW device, trying REF\n");
47         IDXGIAdapter_Release(adapter);
48         adapter = NULL;
49
50         d3d10ref = LoadLibraryA("d3d10ref.dll");
51         if (!d3d10ref)
52         {
53             trace("d3d10ref.dll not available, unable to create a REF device\n");
54             goto cleanup;
55         }
56
57         hr = IDXGIFactory_CreateSoftwareAdapter(factory, d3d10ref, &adapter);
58         FreeLibrary(d3d10ref);
59         ok(SUCCEEDED(hr), "CreateSoftwareAdapter failed, hr %#x\n", hr);
60         if (FAILED(hr)) goto cleanup;
61
62         hr = D3D10CoreCreateDevice(factory, adapter, 0, NULL, &device);
63         ok(SUCCEEDED(hr), "Failed to create a REF device, hr %#x\n", hr);
64         if (FAILED(hr)) goto cleanup;
65     }
66
67 cleanup:
68     if (adapter) IDXGIAdapter_Release(adapter);
69     if (factory) IDXGIFactory_Release(factory);
70
71     return device;
72 }
73
74 static void test_device_interfaces(ID3D10Device *device)
75 {
76     IUnknown *obj;
77     HRESULT hr;
78
79     if (SUCCEEDED(hr = ID3D10Device_QueryInterface(device, &IID_IUnknown, (void **)&obj)))
80         IUnknown_Release(obj);
81     ok(SUCCEEDED(hr), "ID3D10Device does not implement IUnknown\n");
82
83     if (SUCCEEDED(hr = ID3D10Device_QueryInterface(device, &IID_IDXGIObject, (void **)&obj)))
84         IUnknown_Release(obj);
85     ok(SUCCEEDED(hr), "ID3D10Device does not implement IDXGIObject\n");
86
87     if (SUCCEEDED(hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&obj)))
88         IUnknown_Release(obj);
89     ok(SUCCEEDED(hr), "ID3D10Device does not implement IDXGIDevice\n");
90
91     if (SUCCEEDED(hr = ID3D10Device_QueryInterface(device, &IID_ID3D10Device, (void **)&obj)))
92         IUnknown_Release(obj);
93     ok(SUCCEEDED(hr), "ID3D10Device does not implement ID3D10Device\n");
94 }
95
96 static void test_create_texture(ID3D10Device *device)
97 {
98     D3D10_TEXTURE2D_DESC desc;
99     ID3D10Texture2D *texture;
100     IDXGISurface *surface;
101     HRESULT hr;
102
103     desc.Width = 512;
104     desc.Height = 512;
105     desc.MipLevels = 1;
106     desc.ArraySize = 1;
107     desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
108     desc.SampleDesc.Count = 1;
109     desc.SampleDesc.Quality = 0;
110     desc.Usage = D3D10_USAGE_DEFAULT;
111     desc.BindFlags = D3D10_BIND_RENDER_TARGET;
112     desc.CPUAccessFlags = 0;
113     desc.MiscFlags = 0;
114
115     hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
116     ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
117
118     hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
119     ok(SUCCEEDED(hr), "Texture should implement IDXGISurface\n");
120     if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
121     ID3D10Texture2D_Release(texture);
122
123     desc.MipLevels = 0;
124     hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
125     ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
126
127     hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
128     ok(FAILED(hr), "Texture should not implement IDXGISurface\n");
129     if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
130     ID3D10Texture2D_Release(texture);
131
132     desc.MipLevels = 1;
133     desc.ArraySize = 2;
134     hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
135     ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
136
137     hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
138     ok(FAILED(hr), "Texture should not implement IDXGISurface\n");
139     if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
140     ID3D10Texture2D_Release(texture);
141 }
142
143 static void test_create_rendertarget_view(ID3D10Device *device)
144 {
145     D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
146     D3D10_TEXTURE2D_DESC texture_desc;
147     D3D10_BUFFER_DESC buffer_desc;
148     ID3D10RenderTargetView *rtview;
149     ID3D10Texture2D *texture;
150     ID3D10Buffer *buffer;
151     HRESULT hr;
152
153     buffer_desc.ByteWidth = 1024;
154     buffer_desc.Usage = D3D10_USAGE_DEFAULT;
155     buffer_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
156     buffer_desc.CPUAccessFlags = 0;
157     buffer_desc.MiscFlags = 0;
158
159     hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
160     ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x\n", hr);
161
162     rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
163     rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_BUFFER;
164     U(rtv_desc).Buffer.ElementOffset = 0;
165     U(rtv_desc).Buffer.ElementWidth = 64;
166
167     hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)buffer, &rtv_desc, &rtview);
168     ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x\n", hr);
169
170     ID3D10RenderTargetView_Release(rtview);
171     ID3D10Buffer_Release(buffer);
172
173     texture_desc.Width = 512;
174     texture_desc.Height = 512;
175     texture_desc.MipLevels = 1;
176     texture_desc.ArraySize = 1;
177     texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
178     texture_desc.SampleDesc.Count = 1;
179     texture_desc.SampleDesc.Quality = 0;
180     texture_desc.Usage = D3D10_USAGE_DEFAULT;
181     texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
182     texture_desc.CPUAccessFlags = 0;
183     texture_desc.MiscFlags = 0;
184
185     hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
186     ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
187
188     /* For texture resources it's allowed to specify NULL as desc */
189     hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtview);
190     ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x\n", hr);
191
192     ID3D10RenderTargetView_GetDesc(rtview, &rtv_desc);
193     ok(rtv_desc.Format == texture_desc.Format, "Expected format %#x, got %#x\n", texture_desc.Format, rtv_desc.Format);
194     ok(rtv_desc.ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2D,
195             "Expected view dimension D3D10_RTV_DIMENSION_TEXTURE2D, got %#x\n", rtv_desc.ViewDimension);
196     ok(U(rtv_desc).Texture2D.MipSlice == 0, "Expected mip slice 0, got %#x\n", U(rtv_desc).Texture2D.MipSlice);
197
198     ID3D10RenderTargetView_Release(rtview);
199     ID3D10Texture2D_Release(texture);
200 }
201
202 START_TEST(device)
203 {
204     ID3D10Device *device;
205     ULONG refcount;
206
207     device = create_device();
208     if (!device)
209     {
210         skip("Failed to create device, skipping tests\n");
211         return;
212     }
213
214     test_device_interfaces(device);
215     test_create_texture(device);
216     test_create_rendertarget_view(device);
217
218     refcount = ID3D10Device_Release(device);
219     ok(!refcount, "Device has %u references left\n", refcount);
220 }