d3dx9_36: Implement D3DXCreateLine and add stubbed interface for ID3DXLine + tests.
[wine.git] / dlls / d3dx9_36 / tests / texture.c
blobf2511161ecc759c0bd430db100f0669accb0c798
1 /*
2 * Tests for the D3DX9 texture functions
4 * Copyright 2009 Tony Wasserka
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
22 #include "wine/test.h"
23 #include "d3dx9tex.h"
24 #include "resources.h"
26 static inline int get_ref(IUnknown *obj)
28 IUnknown_AddRef(obj);
29 return IUnknown_Release(obj);
32 static inline void check_ref(IUnknown *obj, int exp)
34 int ref = get_ref(obj);
35 ok (exp == ref, "Invalid refcount. Expected %d, got %d\n", exp, ref);
38 static inline void check_release(IUnknown *obj, int exp)
40 int ref = IUnknown_Release(obj);
41 ok (ref == exp, "Invalid refcount. Expected %d, got %d\n", exp, ref);
44 /* 1x1 bmp (1 bpp) */
45 static const unsigned char bmp01[66] = {
46 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
47 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
48 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
49 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
50 0x00,0x00
53 /* 2x2 A8R8G8B8 pixel data */
54 static const unsigned char pixdata[] = {
55 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
58 /* invalid image file */
59 static const unsigned char noimage[4] = {
60 0x11,0x22,0x33,0x44
63 static HRESULT create_file(const char *filename, const unsigned char *data, const unsigned int size)
65 DWORD received;
66 HANDLE hfile;
68 hfile = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
69 if(hfile == INVALID_HANDLE_VALUE) return HRESULT_FROM_WIN32(GetLastError());
71 if(WriteFile(hfile, data, size, &received, NULL))
73 CloseHandle(hfile);
74 return D3D_OK;
77 CloseHandle(hfile);
78 return D3DERR_INVALIDCALL;
81 static void test_D3DXGetImageInfo(void)
83 HRESULT hr;
84 D3DXIMAGE_INFO info;
85 BOOL testdummy_ok, testbitmap_ok;
87 hr = create_file("testdummy.bmp", noimage, sizeof(noimage)); /* invalid image */
88 testdummy_ok = SUCCEEDED(hr);
90 hr = create_file("testbitmap.bmp", bmp01, sizeof(bmp01)); /* valid image */
91 testbitmap_ok = SUCCEEDED(hr);
93 /* D3DXGetImageInfoFromFile */
94 if(testbitmap_ok) {
95 todo_wine {
96 hr = D3DXGetImageInfoFromFileA("testbitmap.bmp", &info);
97 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
100 hr = D3DXGetImageInfoFromFileA("testbitmap.bmp", NULL); /* valid image, second parameter is NULL */
101 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
102 } else skip("Couldn't create \"testbitmap.bmp\"\n");
104 if(testdummy_ok) {
105 hr = D3DXGetImageInfoFromFileA("testdummy.bmp", NULL); /* invalid image, second parameter is NULL */
106 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
108 todo_wine {
109 hr = D3DXGetImageInfoFromFileA("testdummy.bmp", &info);
110 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
112 } else skip("Couldn't create \"testdummy.bmp\"\n");
114 hr = D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", &info);
115 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
117 hr = D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", NULL);
118 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
120 hr = D3DXGetImageInfoFromFileA("", &info);
121 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
123 hr = D3DXGetImageInfoFromFileA(NULL, &info);
124 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
126 hr = D3DXGetImageInfoFromFileA(NULL, NULL);
127 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
130 /* D3DXGetImageInfoFromResource */
131 todo_wine {
132 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &info); /* RT_BITMAP */
133 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
135 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), NULL);
136 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
138 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &info); /* RT_RCDATA */
139 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
142 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDS_STRING), &info);
143 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
145 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDS_STRING), NULL);
146 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
148 hr = D3DXGetImageInfoFromResourceA(NULL, "resourcedoesnotexist", &info);
149 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
151 hr = D3DXGetImageInfoFromResourceA(NULL, "resourcedoesnotexist", NULL);
152 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
154 hr = D3DXGetImageInfoFromResourceA(NULL, NULL, NULL);
155 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
158 /* D3DXGetImageInfoFromFileInMemory */
159 todo_wine {
160 hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01), &info);
161 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
163 hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01)+5, &info); /* too large size */
164 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
167 hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01), NULL);
168 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
170 hr = D3DXGetImageInfoFromFileInMemory(noimage, sizeof(noimage), NULL);
171 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
173 todo_wine {
174 hr = D3DXGetImageInfoFromFileInMemory(noimage, sizeof(noimage), &info);
175 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
177 hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01)-1, &info);
178 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
180 hr = D3DXGetImageInfoFromFileInMemory(bmp01+1, sizeof(bmp01)-1, &info);
181 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
184 hr = D3DXGetImageInfoFromFileInMemory(bmp01, 0, &info);
185 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
187 hr = D3DXGetImageInfoFromFileInMemory(bmp01, 0, NULL);
188 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
190 hr = D3DXGetImageInfoFromFileInMemory(noimage, 0, &info);
191 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
193 hr = D3DXGetImageInfoFromFileInMemory(noimage, 0, NULL);
194 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
196 hr = D3DXGetImageInfoFromFileInMemory(NULL, 0, &info);
197 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
199 hr = D3DXGetImageInfoFromFileInMemory(NULL, 4, NULL);
200 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
202 hr = D3DXGetImageInfoFromFileInMemory(NULL, 4, &info);
203 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
205 hr = D3DXGetImageInfoFromFileInMemory(NULL, 0, NULL);
206 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
208 /* cleanup */
209 if(testdummy_ok) DeleteFileA("testdummy.bmp");
210 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
213 #define check_pixel_1bpp(lockrect, x, y, color) \
214 ok(((BYTE*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch] == color, "Got color %#x, expected %#x\n", ((BYTE*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch], color)
216 #define check_pixel_2bpp(lockrect, x, y, color) \
217 ok(((WORD*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch / 2] == color, "Got color %#x, expected %#x\n", ((WORD*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch / 2], color)
219 #define check_pixel_4bpp(lockrect, x, y, color) \
220 ok(((DWORD*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch / 4] == color, "Got color %#x, expected %#x\n", ((DWORD*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch / 4], color)
221 static void test_D3DXLoadSurface(IDirect3DDevice9 *device)
223 HRESULT hr;
224 BOOL testdummy_ok, testbitmap_ok;
225 IDirect3DSurface9 *surf, *newsurf;
226 RECT rect;
227 D3DLOCKED_RECT lockrect;
228 const WORD pixdata_a8r3g3b2[] = { 0x57df, 0x98fc, 0xacdd, 0xc891 };
229 const WORD pixdata_a1r5g5b5[] = { 0x46b5, 0x99c8, 0x06a2, 0x9431 };
230 const WORD pixdata_r5g6b5[] = { 0x9ef6, 0x658d, 0x0aee, 0x42ee };
231 const DWORD pixdata_g16r16[] = { 0x07d23fbe, 0xdc7f44a4, 0xe4d8976b, 0x9a84fe89 };
232 const DWORD pixdata_a8b8g8r8[] = { 0xc3394cf0, 0x235ae892, 0x09b197fd, 0x8dc32bf6 };
233 const DWORD pixdata_a2r10g10b10[] = { 0x57395aff, 0x5b7668fd, 0xb0d856b5, 0xff2c61d6 };
235 hr = create_file("testdummy.bmp", noimage, sizeof(noimage)); /* invalid image */
236 testdummy_ok = SUCCEEDED(hr);
238 hr = create_file("testbitmap.bmp", bmp01, sizeof(bmp01)); /* valid image */
239 testbitmap_ok = SUCCEEDED(hr);
241 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf, NULL);
242 if(FAILED(hr)) {
243 skip("Failed to create a surface (%#x)\n", hr);
244 if(testdummy_ok) DeleteFileA("testdummy.bmp");
245 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
246 return;
249 /* D3DXLoadSurfaceFromFile */
250 if(testbitmap_ok) {
251 todo_wine {
252 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "testbitmap.bmp", NULL, D3DX_DEFAULT, 0, NULL);
253 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3D_OK);
256 hr = D3DXLoadSurfaceFromFileA(NULL, NULL, NULL, "testbitmap.bmp", NULL, D3DX_DEFAULT, 0, NULL);
257 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
258 } else skip("Couldn't create \"testbitmap.bmp\"\n");
260 if(testdummy_ok) {
261 todo_wine {
262 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "testdummy.bmp", NULL, D3DX_DEFAULT, 0, NULL);
263 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
265 } else skip("Couldn't create \"testdummy.bmp\"\n");
267 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0, NULL);
268 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
270 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "", NULL, D3DX_DEFAULT, 0, NULL);
271 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
274 /* D3DXLoadSurfaceFromResource */
275 todo_wine {
276 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDB_BITMAP_1x1), NULL, D3DX_DEFAULT, 0, NULL);
277 ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK);
279 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDD_BITMAPDATA_1x1), NULL, D3DX_DEFAULT, 0, NULL);
280 ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK);
283 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0, NULL);
284 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
286 hr = D3DXLoadSurfaceFromResourceA(NULL, NULL, NULL, NULL, MAKEINTRESOURCE(IDB_BITMAP_1x1), NULL, D3DX_DEFAULT, 0, NULL);
287 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
289 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDS_STRING), NULL, D3DX_DEFAULT, 0, NULL);
290 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
293 /* D3DXLoadSurfaceFromFileInMemory */
294 todo_wine {
295 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp01, sizeof(bmp01), NULL, D3DX_DEFAULT, 0, NULL);
296 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
298 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, noimage, sizeof(noimage), NULL, D3DX_DEFAULT, 0, NULL);
299 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
302 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp01, 0, NULL, D3DX_DEFAULT, 0, NULL);
303 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
305 hr = D3DXLoadSurfaceFromFileInMemory(NULL, NULL, NULL, bmp01, sizeof(bmp01), NULL, D3DX_DEFAULT, 0, NULL);
306 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
308 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, NULL, 8, NULL, D3DX_DEFAULT, 0, NULL);
309 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
311 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL);
312 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
314 hr = D3DXLoadSurfaceFromFileInMemory(NULL, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL);
315 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
318 /* D3DXLoadSurfaceFromMemory */
319 SetRect(&rect, 0, 0, 2, 2);
321 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
322 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
324 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, 0, NULL, &rect, D3DX_FILTER_NONE, 0);
325 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
327 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, NULL, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
328 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
330 hr = D3DXLoadSurfaceFromMemory(NULL, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
331 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
333 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, NULL, D3DX_DEFAULT, 0);
334 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
336 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_UNKNOWN, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
337 ok(hr == E_FAIL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, E_FAIL);
340 /* D3DXLoadSurfaceFromSurface */
341 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &newsurf, NULL);
342 if(SUCCEEDED(hr)) {
343 todo_wine {
344 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
345 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
348 hr = D3DXLoadSurfaceFromSurface(NULL, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
349 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
351 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0);
352 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
354 check_release((IUnknown*)newsurf, 0);
355 } else skip("Failed to create a second surface\n");
357 check_release((IUnknown*)surf, 0);
360 /* test color conversion */
361 /* A8R8G8B8 */
362 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf, NULL);
363 if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr);
364 else {
365 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2, D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
366 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
367 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
368 check_pixel_4bpp(lockrect, 0, 0, 0x57dbffff);
369 check_pixel_4bpp(lockrect, 1, 0, 0x98ffff00);
370 check_pixel_4bpp(lockrect, 0, 1, 0xacdbff55);
371 check_pixel_4bpp(lockrect, 1, 1, 0xc8929255);
372 IDirect3DSurface9_UnlockRect(surf);
374 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
375 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
376 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
377 check_pixel_4bpp(lockrect, 0, 0, 0x008cadad);
378 check_pixel_4bpp(lockrect, 1, 0, 0xff317342);
379 check_pixel_4bpp(lockrect, 0, 1, 0x0008ad10);
380 check_pixel_4bpp(lockrect, 1, 1, 0xff29088c);
381 IDirect3DSurface9_UnlockRect(surf);
383 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
384 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
385 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
386 check_pixel_4bpp(lockrect, 0, 0, 0xff9cdfb5);
387 check_pixel_4bpp(lockrect, 1, 0, 0xff63b26b);
388 check_pixel_4bpp(lockrect, 0, 1, 0xff085d73);
389 check_pixel_4bpp(lockrect, 1, 1, 0xff425d73);
390 IDirect3DSurface9_UnlockRect(surf);
392 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
393 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
394 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
395 todo_wine {
396 check_pixel_4bpp(lockrect, 0, 0, 0xff3f08ff);
398 check_pixel_4bpp(lockrect, 1, 0, 0xff44dcff);
399 check_pixel_4bpp(lockrect, 0, 1, 0xff97e4ff);
400 check_pixel_4bpp(lockrect, 1, 1, 0xfffe9aff);
401 IDirect3DSurface9_UnlockRect(surf);
403 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
404 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
405 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
406 check_pixel_4bpp(lockrect, 0, 0, 0xc3f04c39);
407 check_pixel_4bpp(lockrect, 1, 0, 0x2392e85a);
408 check_pixel_4bpp(lockrect, 0, 1, 0x09fd97b1);
409 check_pixel_4bpp(lockrect, 1, 1, 0x8df62bc3);
410 IDirect3DSurface9_UnlockRect(surf);
412 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
413 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
414 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
415 check_pixel_4bpp(lockrect, 0, 0, 0x555c95bf);
416 check_pixel_4bpp(lockrect, 1, 0, 0x556d663f);
417 check_pixel_4bpp(lockrect, 0, 1, 0xaac385ad);
418 todo_wine {
419 check_pixel_4bpp(lockrect, 1, 1, 0xfffcc575);
421 IDirect3DSurface9_UnlockRect(surf);
423 check_release((IUnknown*)surf, 0);
426 /* A1R5G5B5 */
427 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A1R5G5B5, D3DPOOL_DEFAULT, &surf, NULL);
428 if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr);
429 else {
430 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2, D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
431 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
432 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
433 check_pixel_2bpp(lockrect, 0, 0, 0x6fff);
434 check_pixel_2bpp(lockrect, 1, 0, 0xffe0);
435 check_pixel_2bpp(lockrect, 0, 1, 0xefea);
436 check_pixel_2bpp(lockrect, 1, 1, 0xca4a);
437 IDirect3DSurface9_UnlockRect(surf);
439 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
440 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
441 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
442 check_pixel_2bpp(lockrect, 0, 0, 0x46b5);
443 check_pixel_2bpp(lockrect, 1, 0, 0x99c8);
444 check_pixel_2bpp(lockrect, 0, 1, 0x06a2);
445 check_pixel_2bpp(lockrect, 1, 1, 0x9431);
446 IDirect3DSurface9_UnlockRect(surf);
448 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
449 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
450 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
451 check_pixel_2bpp(lockrect, 0, 0, 0xcf76);
452 check_pixel_2bpp(lockrect, 1, 0, 0xb2cd);
453 check_pixel_2bpp(lockrect, 0, 1, 0x856e);
454 check_pixel_2bpp(lockrect, 1, 1, 0xa16e);
455 IDirect3DSurface9_UnlockRect(surf);
457 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
458 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
459 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
460 todo_wine {
461 check_pixel_2bpp(lockrect, 0, 0, 0xa03f);
463 check_pixel_2bpp(lockrect, 1, 0, 0xa37f);
464 check_pixel_2bpp(lockrect, 0, 1, 0xcb9f);
465 check_pixel_2bpp(lockrect, 1, 1, 0xfe7f);
466 IDirect3DSurface9_UnlockRect(surf);
468 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
469 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
470 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
471 todo_wine {
472 check_pixel_2bpp(lockrect, 0, 0, 0xf527);
473 check_pixel_2bpp(lockrect, 1, 0, 0x4b8b);
475 check_pixel_2bpp(lockrect, 0, 1, 0x7e56);
476 check_pixel_2bpp(lockrect, 1, 1, 0xf8b8);
477 IDirect3DSurface9_UnlockRect(surf);
479 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
480 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
481 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
482 check_pixel_2bpp(lockrect, 0, 0, 0x2e57);
483 todo_wine {
484 check_pixel_2bpp(lockrect, 1, 0, 0x3588);
486 check_pixel_2bpp(lockrect, 0, 1, 0xe215);
487 check_pixel_2bpp(lockrect, 1, 1, 0xff0e);
488 IDirect3DSurface9_UnlockRect(surf);
490 check_release((IUnknown*)surf, 0);
493 /* cleanup */
494 if(testdummy_ok) DeleteFileA("testdummy.bmp");
495 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
498 START_TEST(texture)
500 HWND wnd;
501 IDirect3D9 *d3d;
502 IDirect3DDevice9 *device;
503 D3DPRESENT_PARAMETERS d3dpp;
504 HRESULT hr;
506 wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
507 d3d = Direct3DCreate9(D3D_SDK_VERSION);
508 if (!wnd) {
509 skip("Couldn't create application window\n");
510 return;
512 if (!d3d) {
513 skip("Couldn't create IDirect3D9 object\n");
514 DestroyWindow(wnd);
515 return;
518 ZeroMemory(&d3dpp, sizeof(d3dpp));
519 d3dpp.Windowed = TRUE;
520 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
521 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
522 if(FAILED(hr)) {
523 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
524 IDirect3D9_Release(d3d);
525 DestroyWindow(wnd);
526 return;
529 test_D3DXGetImageInfo();
530 test_D3DXLoadSurface(device);
532 check_release((IUnknown*)device, 0);
533 check_release((IUnknown*)d3d, 0);
534 if (wnd) DestroyWindow(wnd);