d3dx9/tests: Test D3DXAssembleShader() with both terminated and not terminated include data.

Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Matteo Bruni 2022-03-30 19:37:21 +02:00 committed by Alexandre Julliard
parent 90f766fa76
commit 0c7090a1da

View file

@ -81,31 +81,46 @@ static void delete_directory(const char *name)
RemoveDirectoryA(path); RemoveDirectoryA(path);
} }
struct test_include
{
ID3DXInclude ID3DXInclude_iface;
BOOL terminated_data;
};
static inline struct test_include *impl_from_ID3DXInclude(ID3DXInclude *iface)
{
return CONTAINING_RECORD(iface, struct test_include, ID3DXInclude_iface);
}
static HRESULT WINAPI testD3DXInclude_open(ID3DXInclude *iface, D3DXINCLUDE_TYPE include_type, static HRESULT WINAPI testD3DXInclude_open(ID3DXInclude *iface, D3DXINCLUDE_TYPE include_type,
const char *filename, const void *parent_data, const void **data, UINT *bytes) const char *filename, const void *parent_data, const void **data, UINT *bytes)
{ {
char *buffer;
static const char shader[] = static const char shader[] =
"#include \"incl.vsh\"\n" "#include \"incl.vsh\"\n"
"mov REGISTER, v0\n"; "mov REGISTER, v0\n";
static const char include[] = "#define REGISTER r0\nvs.1.1\n"; static const char include[] = "#define REGISTER r0\nvs.1.1\n";
static const char include2[] = "#include \"incl3.vsh\"\n"; static const char include2[] = "#include \"incl3.vsh\"\n";
static const char include3[] = "vs.1.1\n"; static const char include3[] = "vs.1.1\n";
struct test_include *test_include = impl_from_ID3DXInclude(iface);
unsigned int size;
char *buffer;
trace("filename %s.\n", filename); trace("filename %s.\n", filename);
trace("parent_data %p: %s.\n", parent_data, parent_data ? (char *)parent_data : "(null)"); trace("parent_data %p.\n", parent_data);
if (!strcmp(filename, "shader.vsh")) if (!strcmp(filename, "shader.vsh"))
{ {
buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(shader)); size = test_include->terminated_data ? sizeof(shader) : sizeof(shader) - 1;
memcpy(buffer, shader, sizeof(shader)); buffer = HeapAlloc(GetProcessHeap(), 0, size);
*bytes = sizeof(shader); memcpy(buffer, shader, size);
*bytes = size;
} }
else if (!strcmp(filename, "incl.vsh")) else if (!strcmp(filename, "incl.vsh"))
{ {
buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(include)); size = test_include->terminated_data ? sizeof(include) : sizeof(include) - 1;
memcpy(buffer, include, sizeof(include)); buffer = HeapAlloc(GetProcessHeap(), 0, size);
*bytes = sizeof(include); memcpy(buffer, include, size);
*bytes = size;
/* This is included from the first D3DXAssembleShader with non-null ID3DXInclude test /* This is included from the first D3DXAssembleShader with non-null ID3DXInclude test
* (parent_data == NULL) and from shader.vsh / shader[] (with matching parent_data). * (parent_data == NULL) and from shader.vsh / shader[] (with matching parent_data).
* Allow both cases. */ * Allow both cases. */
@ -113,24 +128,26 @@ static HRESULT WINAPI testD3DXInclude_open(ID3DXInclude *iface, D3DXINCLUDE_TYPE
} }
else if (!strcmp(filename, "incl2.vsh")) else if (!strcmp(filename, "incl2.vsh"))
{ {
buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(include2)); size = test_include->terminated_data ? sizeof(include2) : sizeof(include2) - 1;
memcpy(buffer, include2, sizeof(include2)); buffer = HeapAlloc(GetProcessHeap(), 0, size);
*bytes = sizeof(include2); memcpy(buffer, include2, size);
*bytes = size;
} }
else if (!strcmp(filename, "incl3.vsh")) else if (!strcmp(filename, "incl3.vsh"))
{ {
buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(include3)); size = test_include->terminated_data ? sizeof(include3) : sizeof(include3) - 1;
memcpy(buffer, include3, sizeof(include3)); buffer = HeapAlloc(GetProcessHeap(), 0, size);
*bytes = sizeof(include3); memcpy(buffer, include3, size);
/* Also check for the correct parent_data content */ *bytes = size;
ok(parent_data != NULL && !strncmp(include2, parent_data, strlen(include2)), "wrong parent_data value\n"); ok(parent_data != NULL && !strncmp(include2, parent_data, strlen(include2)), "wrong parent_data value.\n");
} }
else if (!strcmp(filename, "include/incl3.vsh")) else if (!strcmp(filename, "include/incl3.vsh"))
{ {
buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(include)); size = test_include->terminated_data ? sizeof(include) : sizeof(include) - 1;
memcpy(buffer, include, sizeof(include)); buffer = HeapAlloc(GetProcessHeap(), 0, size);
*bytes = sizeof(include); memcpy(buffer, include, size);
ok(!parent_data, "wrong parent_data value\n"); *bytes = size;
ok(!parent_data, "wrong parent_data value.\n");
} }
else else
{ {
@ -147,15 +164,12 @@ static HRESULT WINAPI testD3DXInclude_close(ID3DXInclude *iface, const void *dat
return S_OK; return S_OK;
} }
static const struct ID3DXIncludeVtbl D3DXInclude_Vtbl = { static const struct ID3DXIncludeVtbl test_include_vtbl =
{
testD3DXInclude_open, testD3DXInclude_open,
testD3DXInclude_close testD3DXInclude_close
}; };
struct D3DXIncludeImpl {
ID3DXInclude ID3DXInclude_iface;
};
static void assembleshader_test(void) static void assembleshader_test(void)
{ {
static const char test1[] = static const char test1[] =
@ -180,8 +194,6 @@ static void assembleshader_test(void)
"vs.1.1\n"; "vs.1.1\n";
static const char testincl4_wrong[] = static const char testincl4_wrong[] =
"#error \"wrong include\"\n"; "#error \"wrong include\"\n";
HRESULT hr;
ID3DXBuffer *shader, *messages;
static const D3DXMACRO defines[] = { static const D3DXMACRO defines[] = {
{ {
"DEF1", "10 + 15" "DEF1", "10 + 15"
@ -193,8 +205,11 @@ static void assembleshader_test(void)
NULL, NULL NULL, NULL
} }
}; };
struct D3DXIncludeImpl include;
char shader_vsh_path[MAX_PATH], shader3_vsh_path[MAX_PATH]; char shader_vsh_path[MAX_PATH], shader3_vsh_path[MAX_PATH];
ID3DXBuffer *shader, *messages;
struct test_include include;
unsigned int i;
HRESULT hr;
/* pDefines test */ /* pDefines test */
shader = NULL; shader = NULL;
@ -229,56 +244,67 @@ static void assembleshader_test(void)
} }
/* pInclude test */ /* pInclude test */
shader = NULL; for (i = 0; i < 2; ++i)
messages = NULL;
include.ID3DXInclude_iface.lpVtbl = &D3DXInclude_Vtbl;
hr = D3DXAssembleShader(testshader, strlen(testshader), NULL, &include.ID3DXInclude_iface,
D3DXSHADER_SKIPVALIDATION, &shader, &messages);
ok(hr == D3D_OK, "pInclude test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
if(messages) {
trace("D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
ID3DXBuffer_Release(messages);
}
if(shader) ID3DXBuffer_Release(shader);
/* "unexpected #include file from memory" test */
shader = NULL;
messages = NULL;
hr = D3DXAssembleShader(testshader, strlen(testshader),
NULL, NULL, D3DXSHADER_SKIPVALIDATION,
&shader, &messages);
ok(hr == D3DXERR_INVALIDDATA, "D3DXAssembleShader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
if(messages) {
trace("D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
ID3DXBuffer_Release(messages);
}
if(shader) ID3DXBuffer_Release(shader);
/* recursive #include test */
shader = NULL;
messages = NULL;
hr = D3DXAssembleShader(testshader2, strlen(testshader2), NULL, &include.ID3DXInclude_iface,
D3DXSHADER_SKIPVALIDATION, &shader, &messages);
todo_wine ok(hr == D3D_OK, "D3DXAssembleShader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
if(messages) {
trace("recursive D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
ID3DXBuffer_Release(messages);
}
if(shader) ID3DXBuffer_Release(shader);
/* #include with a path. */
shader = NULL;
messages = NULL;
hr = D3DXAssembleShader(testshader3, strlen(testshader3), NULL, &include.ID3DXInclude_iface,
D3DXSHADER_SKIPVALIDATION, &shader, &messages);
ok(hr == D3D_OK, "D3DXAssembleShader test failed with error 0x%x - %d\n", hr, hr & 0x0000ffff);
if (messages)
{ {
trace("Path search D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages)); shader = NULL;
ID3DXBuffer_Release(messages); messages = NULL;
include.ID3DXInclude_iface.lpVtbl = &test_include_vtbl;
include.terminated_data = i;
winetest_push_context(i ? "terminated include data" : "nonterminated include data");
hr = D3DXAssembleShader(testshader, strlen(testshader), NULL, &include.ID3DXInclude_iface,
D3DXSHADER_SKIPVALIDATION, &shader, &messages);
ok(hr == D3D_OK, "Unexpected hr %#x.\n", hr);
if (messages)
{
trace("D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
ID3DXBuffer_Release(messages);
}
if (shader)
ID3DXBuffer_Release(shader);
/* "unexpected #include file from memory" test */
shader = NULL;
messages = NULL;
hr = D3DXAssembleShader(testshader, strlen(testshader), NULL, NULL, D3DXSHADER_SKIPVALIDATION,
&shader, &messages);
ok(hr == D3DXERR_INVALIDDATA, "Unexpected hr %#x.\n", hr);
if (messages)
{
trace("D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
ID3DXBuffer_Release(messages);
}
if (shader)
ID3DXBuffer_Release(shader);
/* recursive #include test */
shader = NULL;
messages = NULL;
hr = D3DXAssembleShader(testshader2, strlen(testshader2), NULL, &include.ID3DXInclude_iface,
D3DXSHADER_SKIPVALIDATION, &shader, &messages);
todo_wine_if(i) ok(hr == (i ? D3D_OK : D3DXERR_INVALIDDATA), "Unexpected hr %#x.\n", hr);
if (messages)
{
trace("Recursive D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
ID3DXBuffer_Release(messages);
}
if (shader)
ID3DXBuffer_Release(shader);
/* #include with a path. */
shader = NULL;
messages = NULL;
hr = D3DXAssembleShader(testshader3, strlen(testshader3), NULL, &include.ID3DXInclude_iface,
D3DXSHADER_SKIPVALIDATION, &shader, &messages);
ok(hr == D3D_OK, "Unexpected hr %#x.\n", hr);
if (messages)
{
trace("Path search D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
ID3DXBuffer_Release(messages);
}
if (shader)
ID3DXBuffer_Release(shader);
winetest_pop_context();
} }
if (shader)
ID3DXBuffer_Release(shader);
if (create_file("shader.vsh", testshader, sizeof(testshader) - 1, shader_vsh_path)) if (create_file("shader.vsh", testshader, sizeof(testshader) - 1, shader_vsh_path))
{ {
@ -443,7 +469,7 @@ static void d3dxpreprocess_test(void)
HRESULT hr; HRESULT hr;
ID3DXBuffer *shader, *messages; ID3DXBuffer *shader, *messages;
char shader_vsh_path[MAX_PATH], shader3_vsh_path[MAX_PATH]; char shader_vsh_path[MAX_PATH], shader3_vsh_path[MAX_PATH];
static struct D3DXIncludeImpl include = {{&D3DXInclude_Vtbl}}; static struct test_include include = {{&test_include_vtbl}, TRUE};
if (create_file("shader.vsh", testshader, sizeof(testshader) - 1, shader_vsh_path)) if (create_file("shader.vsh", testshader, sizeof(testshader) - 1, shader_vsh_path))
{ {