winex11: Don't use the vulkan driver interface for xrandr.
[wine.git] / dlls / d3dx9_36 / tests / line.c
blob8056e021c954a4100d17e41d43ce7371777804dc
1 /*
2 * Copyright 2010 Christian Costa
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 #include "wine/test.h"
20 #include "d3dx9.h"
22 #define admitted_error 0.0001f
24 #define relative_error(exp, out) ((exp == 0.0f) ? fabs(exp - out) : (fabs(1.0f - out/ exp) ))
26 static inline BOOL compare_matrix(const D3DXMATRIX *m1, const D3DXMATRIX *m2)
28 int i, j;
30 for (i = 0; i < 4; ++i)
32 for (j = 0; j < 4; ++j)
34 if (relative_error(m1->m[i][j], m2->m[i][j]) > admitted_error)
35 return FALSE;
39 return TRUE;
42 #define expect_mat(expectedmat, gotmat) \
43 do { \
44 const D3DXMATRIX *__m1 = (expectedmat); \
45 const D3DXMATRIX *__m2 = (gotmat); \
46 ok(compare_matrix(__m1, __m2), "Expected matrix=\n(%f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n)\n\n" \
47 "Got matrix=\n(%f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f)\n", \
48 __m1->m[0][0], __m1->m[0][1], __m1->m[0][2], __m1->m[0][3], \
49 __m1->m[1][0], __m1->m[1][1], __m1->m[1][2], __m1->m[1][3], \
50 __m1->m[2][0], __m1->m[2][1], __m1->m[2][2], __m1->m[2][3], \
51 __m1->m[3][0], __m1->m[3][1], __m1->m[3][2], __m1->m[3][3], \
52 __m2->m[0][0], __m2->m[0][1], __m2->m[0][2], __m2->m[0][3], \
53 __m2->m[1][0], __m2->m[1][1], __m2->m[1][2], __m2->m[1][3], \
54 __m2->m[2][0], __m2->m[2][1], __m2->m[2][2], __m2->m[2][3], \
55 __m2->m[3][0], __m2->m[3][1], __m2->m[3][2], __m2->m[3][3]); \
56 } while(0)
58 static void test_create_line(IDirect3DDevice9* device)
60 HRESULT hr;
61 ID3DXLine *line = NULL;
62 struct IDirect3DDevice9 *return_device;
63 D3DXMATRIX world, identity, result;
64 FLOAT r11, r12, r13, r14;
65 ULONG ref;
67 /* Arbitrary values for matrix tests. */
68 r11 = 0.1421; r12 = 0.2114; r13 = 0.8027; r14 = 0.4587;
70 hr = D3DXCreateLine(NULL, &line);
71 ok(hr == D3DERR_INVALIDCALL, "Got result %lx, expected %lx (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
73 hr = D3DXCreateLine(device, NULL);
74 ok(hr == D3DERR_INVALIDCALL, "Got result %lx, expected %lx (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
76 hr = D3DXCreateLine(device, &line);
77 ok(hr == D3D_OK, "Got result %lx, expected 0 (D3D_OK)\n", hr);
79 if (FAILED(hr))
81 return;
84 hr = ID3DXLine_GetDevice(line, NULL);
85 ok(hr == D3DERR_INVALIDCALL, "Got result %lx, expected %lx (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
87 hr = ID3DXLine_GetDevice(line, &return_device);
88 ok(hr == D3D_OK, "Got result %lx, expected %lx (D3D_OK)\n", hr, D3D_OK);
89 ok(return_device == device, "Expected line device %p, got %p\n", device, return_device);
91 D3DXMatrixIdentity(&world);
92 D3DXMatrixIdentity(&identity);
93 world._11 = r11; world._12 = r12; world._13 = r13; world._14 = r14;
95 hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLD, &world);
96 ok(hr == D3D_OK, "Got result %lx, expected %lx (D3D_OK)\n", hr, D3D_OK);
98 hr = ID3DXLine_Begin(line);
99 ok(hr == D3D_OK, "Got result %lx, expected %lx (D3D_OK)\n", hr, D3D_OK);
101 hr = IDirect3DDevice9_GetTransform(device, D3DTS_WORLD, &result);
102 ok(hr == D3D_OK, "Got result %lx, expected %lx (D3D_OK)\n", hr, D3D_OK);
103 expect_mat(&identity, &result);
105 hr = ID3DXLine_End(line);
106 ok(hr == D3D_OK, "Got result %lx, expected %lx (D3D_OK)\n", hr, D3D_OK);
108 hr = IDirect3DDevice9_GetTransform(device, D3DTS_WORLD, &result);
109 ok(hr == D3D_OK, "Got result %lx, expected %lx (D3D_OK)\n", hr, D3D_OK);
110 expect_mat(&world, &result);
112 IDirect3DDevice9_Release(return_device);
114 ref = ID3DXLine_Release(line);
115 ok(ref == 0, "Got %lx references to line %p, expected 0\n", ref, line);
118 static void test_line_width(IDirect3DDevice9* device)
120 ID3DXLine *line = NULL;
121 ULONG refcount;
122 float width;
123 HRESULT hr;
125 hr = D3DXCreateLine(device, &line);
126 ok(hr == D3D_OK, "Failed to create a line, hr %#lx.\n", hr);
128 width = ID3DXLine_GetWidth(line);
129 ok(width == 1.0f, "Unexpected line width %.8e.\n", width);
131 hr = ID3DXLine_SetWidth(line, 0.0f);
132 ok(hr == D3DERR_INVALIDCALL, "Unexpected hr %#lx.\n", hr);
133 width = ID3DXLine_GetWidth(line);
134 ok(width == 1.0f, "Unexpected line width %.8e.\n", width);
136 hr = ID3DXLine_SetWidth(line, -1.0f);
137 ok(hr == D3DERR_INVALIDCALL, "Unexpected hr %#lx.\n", hr);
138 width = ID3DXLine_GetWidth(line);
139 ok(width == 1.0f, "Unexpected line width %.8e.\n", width);
141 hr = ID3DXLine_SetWidth(line, 10.0f);
142 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
143 width = ID3DXLine_GetWidth(line);
144 ok(width == 10.0f, "Unexpected line width %.8e.\n", width);
146 refcount = ID3DXLine_Release(line);
147 ok(!refcount, "Got %lu references to line.\n", refcount);
150 START_TEST(line)
152 HWND wnd;
153 IDirect3D9* d3d;
154 IDirect3DDevice9* device;
155 D3DPRESENT_PARAMETERS d3dpp;
156 HRESULT hr;
158 if (!(wnd = CreateWindowA("static", "d3dx9_test", WS_OVERLAPPEDWINDOW, 0, 0,
159 640, 480, NULL, NULL, NULL, NULL)))
161 skip("Couldn't create application window\n");
162 return;
164 if (!(d3d = Direct3DCreate9(D3D_SDK_VERSION)))
166 skip("Couldn't create IDirect3D9 object\n");
167 DestroyWindow(wnd);
168 return;
171 ZeroMemory(&d3dpp, sizeof(d3dpp));
172 d3dpp.Windowed = TRUE;
173 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
174 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device);
175 if (FAILED(hr)) {
176 skip("Failed to create IDirect3DDevice9 object %#lx\n", hr);
177 IDirect3D9_Release(d3d);
178 DestroyWindow(wnd);
179 return;
182 test_create_line(device);
183 test_line_width(device);
185 IDirect3DDevice9_Release(device);
186 IDirect3D9_Release(d3d);
187 DestroyWindow(wnd);