d3dx10/tests: Introduce create_file() and delete_file().

Signed-off-by: Ziqing Hui <zhui@codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Ziqing Hui 2020-09-08 22:41:49 +02:00 committed by Alexandre Julliard
parent 94edc0b3f1
commit ccf3964ba2
1 changed files with 46 additions and 26 deletions

View File

@ -540,6 +540,8 @@ test_image[] =
},
};
static WCHAR temp_dir[MAX_PATH];
static BOOL compare_float(float f, float g, unsigned int ulps)
{
int x = *(int *)&f;
@ -556,6 +558,43 @@ static BOOL compare_float(float f, float g, unsigned int ulps)
return TRUE;
}
static BOOL create_file(const WCHAR *filename, const void *data, unsigned int size, WCHAR *out_path)
{
WCHAR path[MAX_PATH];
DWORD written;
HANDLE file;
if (!temp_dir[0])
GetTempPathW(ARRAY_SIZE(temp_dir), temp_dir);
lstrcpyW(path, temp_dir);
lstrcatW(path, filename);
file = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (file == INVALID_HANDLE_VALUE)
return FALSE;
if (WriteFile(file, data, size, &written, NULL))
{
CloseHandle(file);
if (out_path)
lstrcpyW(out_path, path);
return TRUE;
}
CloseHandle(file);
return FALSE;
}
static BOOL delete_file(const WCHAR *filename)
{
WCHAR path[MAX_PATH];
lstrcpyW(path, temp_dir);
lstrcatW(path, filename);
return DeleteFileW(path);
}
static ID3D10Device *create_device(void)
{
ID3D10Device *device;
@ -1168,28 +1207,9 @@ static void test_D3DX10CreateAsyncMemoryLoader(void)
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
}
static void create_testfile(WCHAR *path, const void *data, int data_len)
{
static const WCHAR test_filename[] = {'a','s','y','n','c','l','o','a','d','e','r','.','d','a','t','a',0};
DWORD written;
HANDLE file;
BOOL ret;
GetTempPathW(MAX_PATH, path);
lstrcatW(path, test_filename);
file = CreateFileW(path, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
ok(file != INVALID_HANDLE_VALUE, "Test file creation failed, at %s, error %d.\n", wine_dbgstr_w(path),
GetLastError());
ret = WriteFile(file, data, data_len, &written, NULL);
ok(ret, "Write to test file failed.\n");
CloseHandle(file);
}
static void test_D3DX10CreateAsyncFileLoader(void)
{
static const WCHAR test_filename[] = L"asyncloader.data";
static const char test_data1[] = "test data";
static const char test_data2[] = "more test data";
ID3DX10DataLoader *loader;
@ -1221,12 +1241,12 @@ static void test_D3DX10CreateAsyncFileLoader(void)
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
/* Test file sharing using dummy empty file. */
create_testfile(path, test_data1, sizeof(test_data1));
create_file(test_filename, test_data1, sizeof(test_data1), path);
hr = D3DX10CreateAsyncFileLoaderW(path, &loader);
ok(SUCCEEDED(hr), "Failed to create file loader, hr %#x.\n", hr);
ret = DeleteFileW(path);
ret = delete_file(test_filename);
ok(ret, "DeleteFile() failed, ret %d, error %d.\n", ret, GetLastError());
/* File was removed before Load(). */
@ -1234,7 +1254,7 @@ static void test_D3DX10CreateAsyncFileLoader(void)
ok(hr == D3D10_ERROR_FILE_NOT_FOUND, "Load() returned unexpected result, hr %#x.\n", hr);
/* Create it again. */
create_testfile(path, test_data1, sizeof(test_data1));
create_file(test_filename, test_data1, sizeof(test_data1), NULL);
hr = ID3DX10DataLoader_Load(loader);
ok(SUCCEEDED(hr), "Load() failed, hr %#x.\n", hr);
@ -1242,7 +1262,7 @@ static void test_D3DX10CreateAsyncFileLoader(void)
hr = ID3DX10DataLoader_Load(loader);
ok(SUCCEEDED(hr), "Load() failed, hr %#x.\n", hr);
ret = DeleteFileW(path);
ret = delete_file(test_filename);
ok(ret, "DeleteFile() failed, ret %d, error %d.\n", ret, GetLastError());
/* Already loaded, file removed. */
@ -1259,7 +1279,7 @@ static void test_D3DX10CreateAsyncFileLoader(void)
ok(!memcmp(ptr, test_data1, size), "Got unexpected file data.\n");
/* Create it again, with different data. */
create_testfile(path, test_data2, sizeof(test_data2));
create_file(test_filename, test_data2, sizeof(test_data2), NULL);
hr = ID3DX10DataLoader_Load(loader);
ok(SUCCEEDED(hr), "Load() failed, hr %#x.\n", hr);
@ -1275,7 +1295,7 @@ static void test_D3DX10CreateAsyncFileLoader(void)
hr = ID3DX10DataLoader_Destroy(loader);
ok(SUCCEEDED(hr), "Destroy() failed, hr %#x.\n", hr);
ret = DeleteFileW(path);
ret = delete_file(test_filename);
ok(ret, "DeleteFile() failed, ret %d, error %d.\n", ret, GetLastError());
}