d3dxof: Fix file types checks + tests.

This commit is contained in:
Christian Costa 2010-03-01 09:36:25 +01:00 committed by Alexandre Julliard
parent 074465b675
commit aed6a4a4f8
2 changed files with 110 additions and 13 deletions

View File

@ -42,6 +42,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3dxof);
#define XOFFILE_FORMAT_VERSION_303 MAKEFOUR('0','3','0','3')
#define XOFFILE_FORMAT_BINARY MAKEFOUR('b','i','n',' ')
#define XOFFILE_FORMAT_TEXT MAKEFOUR('t','x','t',' ')
#define XOFFILE_FORMAT_BINARY_MSZIP MAKEFOUR('b','z','i','p')
#define XOFFILE_FORMAT_TEXT_MSZIP MAKEFOUR('t','z','i','p')
#define XOFFILE_FORMAT_COMPRESSED MAKEFOUR('c','m','p',' ')
#define XOFFILE_FORMAT_FLOAT_BITS_32 MAKEFOUR('0','0','3','2')
#define XOFFILE_FORMAT_FLOAT_BITS_64 MAKEFOUR('0','0','6','4')
@ -58,6 +60,15 @@ static HRESULT IDirectXFileDataReferenceImpl_Create(IDirectXFileDataReferenceImp
static HRESULT IDirectXFileEnumObjectImpl_Create(IDirectXFileEnumObjectImpl** ppObj);
static HRESULT IDirectXFileSaveObjectImpl_Create(IDirectXFileSaveObjectImpl** ppObj);
/* FOURCC to string conversion for debug messages */
const char *debugstr_fourcc(DWORD fourcc)
{
if (!fourcc) return "'null'";
return wine_dbg_sprintf ("\'%c%c%c%c\'",
(char)(fourcc), (char)(fourcc >> 8),
(char)(fourcc >> 16), (char)(fourcc >> 24));
}
HRESULT IDirectXFileImpl_Create(IUnknown* pUnkOuter, LPVOID* ppObj)
{
IDirectXFileImpl* object;
@ -247,16 +258,18 @@ static HRESULT WINAPI IDirectXFileImpl_CreateEnumObject(IDirectXFile* iface, LPV
goto error;
}
if ((header[2] != XOFFILE_FORMAT_BINARY) && (header[2] != XOFFILE_FORMAT_TEXT) && (header[2] != XOFFILE_FORMAT_COMPRESSED))
if ((header[2] != XOFFILE_FORMAT_BINARY) && (header[2] != XOFFILE_FORMAT_TEXT) &&
(header[2] != XOFFILE_FORMAT_BINARY_MSZIP) && (header[2] != XOFFILE_FORMAT_TEXT_MSZIP))
{
WARN("File type %s unknown\n", debugstr_fourcc(header[2]));
hr = DXFILEERR_BADFILETYPE;
goto error;
}
if (header[2] == XOFFILE_FORMAT_COMPRESSED)
if ((header[2] == XOFFILE_FORMAT_BINARY_MSZIP) || (header[2] == XOFFILE_FORMAT_TEXT_MSZIP))
{
FIXME("Compressed formats not supported yet\n");
hr = DXFILEERR_BADVALUE;
FIXME("Compressed format %s not supported yet\n", debugstr_fourcc(header[2]));
hr = DXFILEERR_BADALLOC;
goto error;
}
@ -381,19 +394,21 @@ static HRESULT WINAPI IDirectXFileImpl_RegisterTemplates(IDirectXFile* iface, LP
read_bytes(&buf, &token_header, 4);
if ((token_header != XOFFILE_FORMAT_BINARY) && (token_header != XOFFILE_FORMAT_TEXT) && (token_header != XOFFILE_FORMAT_COMPRESSED))
if ((token_header != XOFFILE_FORMAT_BINARY) && (token_header != XOFFILE_FORMAT_TEXT) &&
(token_header != XOFFILE_FORMAT_BINARY_MSZIP) && (token_header != XOFFILE_FORMAT_TEXT_MSZIP))
{
WARN("File type %s unknown\n", debugstr_fourcc(token_header));
return DXFILEERR_BADFILETYPE;
}
if ((token_header == XOFFILE_FORMAT_BINARY_MSZIP) || (token_header == XOFFILE_FORMAT_TEXT_MSZIP))
{
FIXME("Compressed format %s not supported yet\n", debugstr_fourcc(token_header));
return DXFILEERR_BADALLOC;
}
if (token_header == XOFFILE_FORMAT_TEXT)
{
buf.txt = TRUE;
}
if (token_header == XOFFILE_FORMAT_COMPRESSED)
{
FIXME("Compressed formats not supported yet\n");
return DXFILEERR_BADVALUE;
}
read_bytes(&buf, &token_header, 4);

View File

@ -53,6 +53,13 @@ char object[] =
"1; 2; 3;\n"
"}\n";
char empty_txt_file[] = "xof 0302txt 0064";
char empty_bin_file[] = "xof 0302bin 0064";
char empty_tzip_file[] = "xof 0302tzip0064";
char empty_bzip_file[] = "xof 0302bzip0064";
char empty_cmp_file[] = "xof 0302cmp 0064";
char empty_xxxx_file[] = "xof 0302xxxx0064";
static void init_function_pointers(void)
{
/* We have to use LoadLibrary as no d3dxof functions are referenced directly */
@ -190,6 +197,80 @@ static void test_CreateEnumObject(void)
ok(ref == 0, "Got refcount %d, expected 0\n", ref);
}
static void test_file_types(void)
{
HRESULT hr;
LPDIRECTXFILE dxfile = NULL;
LPDIRECTXFILEENUMOBJECT enum_object;
DXFILELOADMEMORY lminfo;
if (!pDirectXFileCreate)
{
win_skip("DirectXFileCreate is not available\n");
return;
}
hr = pDirectXFileCreate(&dxfile);
ok(hr == DXFILE_OK, "DirectXFileCreate: %x\n", hr);
if (!dxfile)
{
skip("Couldn't create DirectXFile interface\n");
return;
}
hr = IDirectXFile_RegisterTemplates(dxfile, empty_txt_file, strlen(empty_txt_file));
ok(hr == DXFILE_OK, "IDirectXFileImpl_RegisterTemplates: %x\n", hr);
hr = IDirectXFile_RegisterTemplates(dxfile, empty_bin_file, strlen(empty_bin_file));
ok(hr == DXFILE_OK, "IDirectXFileImpl_RegisterTemplates: %x\n", hr);
hr = IDirectXFile_RegisterTemplates(dxfile, empty_tzip_file, strlen(empty_tzip_file));
ok(hr == DXFILEERR_BADALLOC, "IDirectXFileImpl_RegisterTemplates: %x\n", hr);
hr = IDirectXFile_RegisterTemplates(dxfile, empty_bzip_file, strlen(empty_bzip_file));
ok(hr == DXFILEERR_BADALLOC, "IDirectXFileImpl_RegisterTemplates: %x\n", hr);
hr = IDirectXFile_RegisterTemplates(dxfile, empty_cmp_file, strlen(empty_cmp_file));
ok(hr == DXFILEERR_BADFILETYPE, "IDirectXFileImpl_RegisterTemplates: %x\n", hr);
hr = IDirectXFile_RegisterTemplates(dxfile, empty_xxxx_file, strlen(empty_xxxx_file));
ok(hr == DXFILEERR_BADFILETYPE, "IDirectXFileImpl_RegisterTemplates: %x\n", hr);
lminfo.lpMemory = empty_txt_file;
lminfo.dSize = strlen(empty_txt_file);
hr = IDirectXFile_CreateEnumObject(dxfile, &lminfo, DXFILELOAD_FROMMEMORY, &enum_object);
ok(hr == DXFILE_OK, "IDirectXFile_CreateEnumObject: %x\n", hr);
if (hr == DXFILE_OK) IDirectXFileEnumObject_Release(enum_object);
lminfo.lpMemory = empty_bin_file;
lminfo.dSize = strlen(empty_bin_file);
hr = IDirectXFile_CreateEnumObject(dxfile, &lminfo, DXFILELOAD_FROMMEMORY, &enum_object);
ok(hr == DXFILE_OK, "IDirectXFile_CreateEnumObject: %x\n", hr);
if (hr == DXFILE_OK) IDirectXFileEnumObject_Release(enum_object);
lminfo.lpMemory = empty_tzip_file;
lminfo.dSize = strlen(empty_tzip_file);
hr = IDirectXFile_CreateEnumObject(dxfile, &lminfo, DXFILELOAD_FROMMEMORY, &enum_object);
ok(hr == DXFILEERR_BADALLOC, "IDirectXFile_CreateEnumObject: %x\n", hr);
lminfo.lpMemory = empty_bzip_file;
lminfo.dSize = strlen(empty_bzip_file);
hr = IDirectXFile_CreateEnumObject(dxfile, &lminfo, DXFILELOAD_FROMMEMORY, &enum_object);
ok(hr == DXFILEERR_BADALLOC, "IDirectXFile_CreateEnumObject: %x\n", hr);
lminfo.lpMemory = empty_cmp_file;
lminfo.dSize = strlen(empty_cmp_file);
hr = IDirectXFile_CreateEnumObject(dxfile, &lminfo, DXFILELOAD_FROMMEMORY, &enum_object);
ok(hr == DXFILEERR_BADFILETYPE, "IDirectXFile_CreateEnumObject: %x\n", hr);
lminfo.lpMemory = empty_xxxx_file;
lminfo.dSize = strlen(empty_xxxx_file);
hr = IDirectXFile_CreateEnumObject(dxfile, &lminfo, DXFILELOAD_FROMMEMORY, &enum_object);
ok(hr == DXFILEERR_BADFILETYPE, "IDirectXFile_CreateEnumObject: %x\n", hr);
IDirectXFile_Release(dxfile);
}
/* Set it to 1 to expand the string when dumping the object. This is useful when there is
* only one string in a sub-object (very common). Use with care, this may lead to a crash. */
#define EXPAND_STRING 0
@ -364,6 +445,7 @@ START_TEST(d3dxof)
test_refcount();
test_CreateEnumObject();
test_file_types();
test_dump();
FreeLibrary(hd3dxof);