2 * Copyright 2016 Nikolay Sivov 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
23 #include "wine/test.h"
25 static void test_D3DX11CreateAsyncMemoryLoader(void)
27 ID3DX11DataLoader
*loader
;
33 hr
= D3DX11CreateAsyncMemoryLoader(NULL
, 0, NULL
);
34 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
36 hr
= D3DX11CreateAsyncMemoryLoader(NULL
, 0, &loader
);
37 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
39 hr
= D3DX11CreateAsyncMemoryLoader(&data
, 0, &loader
);
40 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
43 hr
= ID3DX11DataLoader_Decompress(loader
, &ptr
, &size
);
44 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
45 ok(ptr
== &data
, "Got data pointer %p, original %p.\n", ptr
, &data
);
46 ok(!size
, "Got unexpected data size.\n");
48 /* Load() is no-op. */
49 hr
= ID3DX11DataLoader_Load(loader
);
50 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
52 hr
= ID3DX11DataLoader_Destroy(loader
);
53 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
56 hr
= D3DX11CreateAsyncMemoryLoader(&data
, sizeof(data
), &loader
);
57 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
59 /* Load() is no-op. */
60 hr
= ID3DX11DataLoader_Load(loader
);
61 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
63 hr
= ID3DX11DataLoader_Decompress(loader
, &ptr
, &size
);
64 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
65 ok(ptr
== &data
, "Got data pointer %p, original %p.\n", ptr
, &data
);
66 ok(size
== sizeof(data
), "Got unexpected data size.\n");
68 hr
= ID3DX11DataLoader_Destroy(loader
);
69 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
72 static void create_testfile(WCHAR
*path
, const void *data
, int data_len
)
74 static const WCHAR test_filename
[] = {'a','s','y','n','c','l','o','a','d','e','r','.','d','a','t','a',0};
79 GetTempPathW(MAX_PATH
, path
);
80 lstrcatW(path
, test_filename
);
82 file
= CreateFileW(path
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0);
83 ok(file
!= INVALID_HANDLE_VALUE
, "Test file creation failed, at %s, error %d.\n",
84 wine_dbgstr_w(path
), GetLastError());
86 ret
= WriteFile(file
, data
, data_len
, &written
, NULL
);
87 ok(ret
, "Write to test file failed.\n");
92 static void test_D3DX11CreateAsyncFileLoader(void)
94 static const char test_data1
[] = "test data";
95 static const char test_data2
[] = "more test data";
96 ID3DX11DataLoader
*loader
;
103 hr
= D3DX11CreateAsyncFileLoaderA(NULL
, NULL
);
104 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
106 hr
= D3DX11CreateAsyncFileLoaderA(NULL
, &loader
);
107 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
109 hr
= D3DX11CreateAsyncFileLoaderA("nonexistentfilename", &loader
);
110 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
112 hr
= ID3DX11DataLoader_Decompress(loader
, &ptr
, &size
);
113 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
115 hr
= ID3DX11DataLoader_Load(loader
);
116 ok(hr
== D3D11_ERROR_FILE_NOT_FOUND
, "Got unexpected hr %#x.\n", hr
);
118 hr
= ID3DX11DataLoader_Decompress(loader
, &ptr
, &size
);
119 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
121 hr
= ID3DX11DataLoader_Destroy(loader
);
122 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
124 /* Test file sharing using dummy empty file. */
125 create_testfile(path
, test_data1
, sizeof(test_data1
));
127 hr
= D3DX11CreateAsyncFileLoaderW(path
, &loader
);
128 ok(SUCCEEDED(hr
), "Failed to create file loader, hr %#x.\n", hr
);
130 ret
= DeleteFileW(path
);
131 ok(ret
, "DeleteFile() failed, ret %d, error %d.\n", ret
, GetLastError());
133 /* File was removed before Load(). */
134 hr
= ID3DX11DataLoader_Load(loader
);
135 ok(hr
== D3D11_ERROR_FILE_NOT_FOUND
, "Load() returned unexpected result, hr %#x.\n", hr
);
137 /* Create it again. */
138 create_testfile(path
, test_data1
, sizeof(test_data1
));
139 hr
= ID3DX11DataLoader_Load(loader
);
140 ok(SUCCEEDED(hr
), "Load() failed, hr %#x.\n", hr
);
142 /* Already loaded. */
143 hr
= ID3DX11DataLoader_Load(loader
);
144 ok(SUCCEEDED(hr
), "Load() failed, hr %#x.\n", hr
);
146 ret
= DeleteFileW(path
);
147 ok(ret
, "DeleteFile() failed, ret %d, error %d.\n", ret
, GetLastError());
149 /* Already loaded, file removed. */
150 hr
= ID3DX11DataLoader_Load(loader
);
151 ok(hr
== D3D11_ERROR_FILE_NOT_FOUND
, "Load() returned unexpected result, hr %#x.\n", hr
);
153 /* Decompress still works. */
155 hr
= ID3DX11DataLoader_Decompress(loader
, &ptr
, &size
);
156 ok(SUCCEEDED(hr
), "Decompress() failed, hr %#x.\n", hr
);
157 ok(ptr
!= NULL
, "Got unexpected ptr %p.\n", ptr
);
158 ok(size
== sizeof(test_data1
), "Got unexpected decompressed size.\n");
159 if (size
== sizeof(test_data1
))
160 ok(!memcmp(ptr
, test_data1
, size
), "Got unexpected file data.\n");
162 /* Create it again, with different data. */
163 create_testfile(path
, test_data2
, sizeof(test_data2
));
165 hr
= ID3DX11DataLoader_Load(loader
);
166 ok(SUCCEEDED(hr
), "Load() failed, hr %#x.\n", hr
);
169 hr
= ID3DX11DataLoader_Decompress(loader
, &ptr
, &size
);
170 ok(SUCCEEDED(hr
), "Decompress() failed, hr %#x.\n", hr
);
171 ok(ptr
!= NULL
, "Got unexpected ptr %p.\n", ptr
);
172 ok(size
== sizeof(test_data2
), "Got unexpected decompressed size.\n");
173 if (size
== sizeof(test_data2
))
174 ok(!memcmp(ptr
, test_data2
, size
), "Got unexpected file data.\n");
176 hr
= ID3DX11DataLoader_Destroy(loader
);
177 ok(SUCCEEDED(hr
), "Destroy() failed, hr %#x.\n", hr
);
179 ret
= DeleteFileW(path
);
180 ok(ret
, "DeleteFile() failed, ret %d, error %d.\n", ret
, GetLastError());
183 static void test_D3DX11CreateAsyncResourceLoader(void)
185 static const WCHAR resource_name
[] = {'n','o','n','a','m','e',0};
186 ID3DX11DataLoader
*loader
;
189 hr
= D3DX11CreateAsyncResourceLoaderA(NULL
, NULL
, NULL
);
190 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
192 hr
= D3DX11CreateAsyncResourceLoaderA(NULL
, NULL
, &loader
);
193 ok(hr
== D3DX11_ERR_INVALID_DATA
, "Got unexpected hr %#x.\n", hr
);
195 hr
= D3DX11CreateAsyncResourceLoaderA(NULL
, "noname", &loader
);
196 ok(hr
== D3DX11_ERR_INVALID_DATA
, "Got unexpected hr %#x.\n", hr
);
198 hr
= D3DX11CreateAsyncResourceLoaderW(NULL
, NULL
, NULL
);
199 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
201 hr
= D3DX11CreateAsyncResourceLoaderW(NULL
, NULL
, &loader
);
202 ok(hr
== D3DX11_ERR_INVALID_DATA
, "Got unexpected hr %#x.\n", hr
);
204 hr
= D3DX11CreateAsyncResourceLoaderW(NULL
, resource_name
, &loader
);
205 ok(hr
== D3DX11_ERR_INVALID_DATA
, "Got unexpected hr %#x.\n", hr
);
210 test_D3DX11CreateAsyncMemoryLoader();
211 test_D3DX11CreateAsyncFileLoader();
212 test_D3DX11CreateAsyncResourceLoader();