2 * Some unit tests for d3dxof
4 * Copyright (C) 2008 Christian Costa
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
24 #include "wine/test.h"
28 static inline void debugstr_guid( char* buf
, CONST GUID
*id
)
30 sprintf(buf
, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
31 id
->Data1
, id
->Data2
, id
->Data3
,
32 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
33 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7] );
36 static HMODULE hd3dxof
;
37 static HRESULT (WINAPI
*pDirectXFileCreate
)(LPDIRECTXFILE
*);
39 static char template[] =
43 "<3D82AB43-62DA-11CF-AB39-0020AF71E433>\n"
49 /* Same version as above compressed with mszip */
50 static char compressed_template
[] =
51 "xof 0302tzip0064\x71\x00\x00\x00\x61\x00\x5a\x00"
52 "\x43\x4B\x2B\x49\xCD\x2D\xC8\x49\x2C\x49\x55\xF0\x48\x4D\x4C\x49"
53 "\x2D\xE2\xAA\xE6\xB2\x31\x76\xB1\x30\x72\x74\x32\x31\xD6\x35\x33"
54 "\x72\x71\xD4\x35\x34\x74\x76\xD3\x75\x74\x32\xB6\xD4\x35\x30\x30"
55 "\x32\x70\x74\x33\x37\x74\x35\x31\x36\xB6\xE3\x0A\xF7\x0F\x72\x51"
56 "\xC8\x4D\xCC\xCA\x2F\xB2\x86\xB2\x33\xF3\x40\x6C\x17\x30\x27\x2D"
57 "\x27\x31\xBD\xD8\x9A\xAB\x96\x8B\x0B\x00";
59 static char object
[] =
66 /* Same version as above compressed with mszip */
67 static char compressed_object
[] =
68 "xof 0302tzip0064\x2c\x00\x00\x00\x1c\x00\x20\x00"
69 "\x43\x4b\xf3\x48\x4d\x4c\x49\x2d\x52\xf0\x4f\xca\x4a\x4d\x2e\xe1"
70 "\xaa\xe6\x32\xb4\x56\x30\xb2\x56\x30\xb6\xe6\xaa\xe5\xe2\x02\x00";
72 static char empty_txt_file
[] = "xof 0302txt 0064";
73 static char empty_bin_file
[] = "xof 0302bin 0064";
74 /* MSZip data is generated with the command "MAKECAB.EXE /D Compress=ON /D CompressionType=MSZip file packed"
75 * Data in cab is after the filename (null terminated) and the 32-bit checksum:
76 * size (16-bit), packed_size (16-bit) and compressed data (with leading 16-bit CK signature)
77 * for each MSZIP chunk whose decompressed size cannot exceed 32768 bytes
78 * Data in x files is preceded by the size (32-bit) of the decompressed file including the xof header (16 bytes)
79 * It does not seem possible to generate an MSZip data chunk with no byte, so put just 1 byte here */
80 /* "\n" packed with MSZip => no text */
81 static char empty_tzip_file
[] = "xof 0302tzip0064\x11\x00\x00\x00\x01\x00\x05\x00\x43\x4b\xe3\x02\x00";
82 /* "\n" packed with MSZip => no token (token are 16-bit and there is only 1 byte) */
83 static char empty_bzip_file
[] = "xof 0302bzip0064\x11\x00\x00\x00\x01\x00\x05\x00\x43\x4b\xe3\x02\x00";
84 static char empty_cmp_file
[] = "xof 0302cmp 0064";
85 static char empty_xxxx_file
[] = "xof 0302xxxx0064";
87 static char object_noname
[] =
94 static char template_syntax_empty_array
[] =
98 "<3D82AB43-62DA-11CF-AB39-0020AF71E433>\n"
100 "array DWORD value[num_elem];\n"
104 static char object_syntax_empty_array_semicolon
[] =
113 static char object_syntax_empty_array_nosemicolon
[] =
121 static char template_syntax_string
[] =
123 "template Filename\n"
125 "<3D82AB43-62DA-11CF-AB39-0020AF71E433>\n"
129 static char object_syntax_string_normal
[] =
136 static char object_syntax_string_with_separator
[] =
143 static void init_function_pointers(void)
145 /* We have to use LoadLibrary as no d3dxof functions are referenced directly */
146 hd3dxof
= LoadLibraryA("d3dxof.dll");
148 pDirectXFileCreate
= (void *)GetProcAddress(hd3dxof
, "DirectXFileCreate");
151 static ULONG
getRefcount(IUnknown
*iface
)
153 IUnknown_AddRef(iface
);
154 return IUnknown_Release(iface
);
157 static void test_refcount(void)
161 LPDIRECTXFILE lpDirectXFile
= NULL
;
162 LPDIRECTXFILEENUMOBJECT lpdxfeo
;
163 LPDIRECTXFILEDATA lpdxfd
;
164 DXFILELOADMEMORY dxflm
;
166 if (!pDirectXFileCreate
)
168 win_skip("DirectXFileCreate is not available\n");
172 hr
= pDirectXFileCreate(&lpDirectXFile
);
173 ok(hr
== DXFILE_OK
, "DirectXFileCreate: %x\n", hr
);
176 skip("Couldn't create DirectXFile interface\n");
180 ref
= getRefcount( (IUnknown
*) lpDirectXFile
);
181 ok(ref
== 1, "Got refcount %d, expected 1\n", ref
);
182 ref
= IDirectXFile_AddRef(lpDirectXFile
);
183 ok(ref
== 2, "Got refcount %d, expected 2\n", ref
);
184 ref
= IDirectXFile_Release(lpDirectXFile
);
185 ok(ref
== 1, "Got refcount %d, expected 1\n", ref
);
187 hr
= IDirectXFile_RegisterTemplates(lpDirectXFile
, template, sizeof(template) - 1);
188 ok(hr
== DXFILE_OK
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
190 dxflm
.lpMemory
= &object
;
191 dxflm
.dSize
= sizeof(object
) - 1;
192 hr
= IDirectXFile_CreateEnumObject(lpDirectXFile
, &dxflm
, DXFILELOAD_FROMMEMORY
, &lpdxfeo
);
193 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
194 ref
= getRefcount( (IUnknown
*) lpDirectXFile
);
195 ok(ref
== 1, "Got refcount %d, expected 1\n", ref
);
196 ref
= getRefcount( (IUnknown
*) lpdxfeo
);
197 ok(ref
== 1, "Got refcount %d, expected 1\n", ref
);
199 hr
= IDirectXFileEnumObject_GetNextDataObject(lpdxfeo
, &lpdxfd
);
200 ok(hr
== DXFILE_OK
, "IDirectXFileEnumObject_GetNextDataObject: %x\n", hr
);
201 ref
= getRefcount( (IUnknown
*) lpDirectXFile
);
202 ok(ref
== 1, "Got refcount %d, expected 1\n", ref
);
203 ref
= getRefcount( (IUnknown
*) lpdxfeo
);
204 ok(ref
== 1, "Got refcount %d, expected 1\n", ref
);
205 /* Enum object gets references to all top level objects */
206 ref
= getRefcount( (IUnknown
*) lpdxfd
);
207 ok(ref
== 2, "Got refcount %d, expected 2\n", ref
);
209 ref
= IDirectXFile_Release(lpDirectXFile
);
210 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
211 /* Nothing changes for all other objects */
212 ref
= getRefcount( (IUnknown
*) lpdxfeo
);
213 ok(ref
== 1, "Got refcount %d, expected 1\n", ref
);
214 ref
= getRefcount( (IUnknown
*) lpdxfd
);
215 ok(ref
== 2, "Got refcount %d, expected 2\n", ref
);
217 ref
= IDirectXFileEnumObject_Release(lpdxfeo
);
218 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
219 /* Enum object releases references to all top level objects */
220 ref
= getRefcount( (IUnknown
*) lpdxfd
);
221 ok(ref
== 1, "Got refcount %d, expected 1\n", ref
);
223 ref
= IDirectXFileData_Release(lpdxfd
);
224 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
227 static void test_CreateEnumObject(void)
231 LPDIRECTXFILE lpDirectXFile
= NULL
;
232 LPDIRECTXFILEENUMOBJECT lpdxfeo
;
233 LPDIRECTXFILEDATA lpdxfd
;
234 DXFILELOADMEMORY dxflm
;
238 if (!pDirectXFileCreate
)
240 win_skip("DirectXFileCreate is not available\n");
244 hr
= pDirectXFileCreate(&lpDirectXFile
);
245 ok(hr
== DXFILE_OK
, "DirectXFileCreate: %x\n", hr
);
248 skip("Couldn't create DirectXFile interface\n");
252 hr
= IDirectXFile_RegisterTemplates(lpDirectXFile
, template, sizeof(template) - 1);
253 ok(hr
== DXFILE_OK
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
255 dxflm
.lpMemory
= &object
;
256 dxflm
.dSize
= sizeof(object
) - 1;
257 /* Check that only lowest 4 bits are relevant in DXFILELOADOPTIONS */
258 hr
= IDirectXFile_CreateEnumObject(lpDirectXFile
, &dxflm
, 0xFFFFFFF0 + DXFILELOAD_FROMMEMORY
, &lpdxfeo
);
259 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
261 hr
= IDirectXFileEnumObject_GetNextDataObject(lpdxfeo
, &lpdxfd
);
262 ok(hr
== DXFILE_OK
, "IDirectXFileEnumObject_GetNextDataObject: %x\n", hr
);
264 /* Get all data (szMember == NULL) */
265 hr
= IDirectXFileData_GetData(lpdxfd
, NULL
, &size
, (void**)&pdata
);
266 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetData: %x\n", hr
);
268 ok(size
== 8, "Retrieved data size is wrong (%u instead of 8)\n", size
);
269 ok((*((WORD
*)pdata
) == 1) && (*((WORD
*)(pdata
+2)) == 2) && (*((DWORD
*)(pdata
+4)) == 3), "Retrieved data is wrong\n");
271 /* Get only "major" member (szMember == "major") */
272 hr
= IDirectXFileData_GetData(lpdxfd
, "major", &size
, (void**)&pdata
);
273 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetData: %x\n", hr
);
275 ok(size
== 2, "Retrieved data size is wrong (%u instead of 2)\n", size
);
276 ok(*((WORD
*)pdata
) == 1, "Retrieved data is wrong (%u instead of 1)\n", *((WORD
*)pdata
));
278 /* Get only "minor" member (szMember == "minor") */
279 hr
= IDirectXFileData_GetData(lpdxfd
, "minor", &size
, (void**)&pdata
);
280 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetData: %x\n", hr
);
282 ok(size
== 2, "Retrieved data size is wrong (%u instead of 2)\n", size
);
283 ok(*((WORD
*)pdata
) == 2, "Retrieved data is wrong (%u instead of 2)\n", *((WORD
*)pdata
));
285 /* Get only "flags" member (szMember == "flags") */
286 hr
= IDirectXFileData_GetData(lpdxfd
, "flags", &size
, (void**)&pdata
);
287 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetData: %x\n", hr
);
289 ok(size
== 4, "Retrieved data size is wrong (%u instead of 4)\n", size
);
290 ok(*((WORD
*)pdata
) == 3, "Retrieved data is wrong (%u instead of 3)\n", *((WORD
*)pdata
));
292 /* Try to get not existing member (szMember == "unknown") */
293 hr
= IDirectXFileData_GetData(lpdxfd
, "unknow", &size
, (void**)&pdata
);
294 ok(hr
== DXFILEERR_BADDATAREFERENCE
, "IDirectXFileData_GetData: %x\n", hr
);
296 ref
= IDirectXFileEnumObject_Release(lpdxfeo
);
297 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
299 ref
= IDirectXFile_Release(lpDirectXFile
);
300 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
302 ref
= IDirectXFileData_Release(lpdxfd
);
303 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
306 static void test_file_types(void)
309 LPDIRECTXFILE dxfile
= NULL
;
310 LPDIRECTXFILEENUMOBJECT enum_object
;
311 DXFILELOADMEMORY lminfo
;
313 if (!pDirectXFileCreate
)
315 win_skip("DirectXFileCreate is not available\n");
319 hr
= pDirectXFileCreate(&dxfile
);
320 ok(hr
== DXFILE_OK
, "DirectXFileCreate: %x\n", hr
);
323 skip("Couldn't create DirectXFile interface\n");
327 hr
= IDirectXFile_RegisterTemplates(dxfile
, empty_txt_file
, sizeof(empty_txt_file
) - 1);
328 ok(hr
== DXFILE_OK
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
330 hr
= IDirectXFile_RegisterTemplates(dxfile
, empty_bin_file
, sizeof(empty_bin_file
) - 1);
331 ok(hr
== DXFILE_OK
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
333 hr
= IDirectXFile_RegisterTemplates(dxfile
, empty_tzip_file
, sizeof(empty_tzip_file
) - 1);
334 ok(hr
== DXFILE_OK
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
336 hr
= IDirectXFile_RegisterTemplates(dxfile
, empty_bzip_file
, sizeof(empty_bzip_file
) - 1);
337 ok(hr
== DXFILE_OK
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
339 hr
= IDirectXFile_RegisterTemplates(dxfile
, empty_cmp_file
, sizeof(empty_cmp_file
) - 1);
340 ok(hr
== DXFILEERR_BADFILETYPE
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
342 hr
= IDirectXFile_RegisterTemplates(dxfile
, empty_xxxx_file
, sizeof(empty_xxxx_file
) - 1);
343 ok(hr
== DXFILEERR_BADFILETYPE
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
345 lminfo
.lpMemory
= empty_txt_file
;
346 lminfo
.dSize
= sizeof(empty_txt_file
) - 1;
347 hr
= IDirectXFile_CreateEnumObject(dxfile
, &lminfo
, DXFILELOAD_FROMMEMORY
, &enum_object
);
348 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
349 if (hr
== DXFILE_OK
) IDirectXFileEnumObject_Release(enum_object
);
351 lminfo
.lpMemory
= empty_bin_file
;
352 lminfo
.dSize
= sizeof(empty_bin_file
) - 1;
353 hr
= IDirectXFile_CreateEnumObject(dxfile
, &lminfo
, DXFILELOAD_FROMMEMORY
, &enum_object
);
354 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
355 if (hr
== DXFILE_OK
) IDirectXFileEnumObject_Release(enum_object
);
357 lminfo
.lpMemory
= empty_tzip_file
;
358 lminfo
.dSize
= sizeof(empty_tzip_file
) - 1;
359 hr
= IDirectXFile_CreateEnumObject(dxfile
, &lminfo
, DXFILELOAD_FROMMEMORY
, &enum_object
);
360 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
361 if (hr
== DXFILE_OK
) IDirectXFileEnumObject_Release(enum_object
);
363 lminfo
.lpMemory
= empty_bzip_file
;
364 lminfo
.dSize
= sizeof(empty_bzip_file
) - 1;
365 hr
= IDirectXFile_CreateEnumObject(dxfile
, &lminfo
, DXFILELOAD_FROMMEMORY
, &enum_object
);
366 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
367 if (hr
== DXFILE_OK
) IDirectXFileEnumObject_Release(enum_object
);
369 lminfo
.lpMemory
= empty_cmp_file
;
370 lminfo
.dSize
= sizeof(empty_cmp_file
) - 1;
371 hr
= IDirectXFile_CreateEnumObject(dxfile
, &lminfo
, DXFILELOAD_FROMMEMORY
, &enum_object
);
372 ok(hr
== DXFILEERR_BADFILETYPE
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
374 lminfo
.lpMemory
= empty_xxxx_file
;
375 lminfo
.dSize
= sizeof(empty_xxxx_file
) - 1;
376 hr
= IDirectXFile_CreateEnumObject(dxfile
, &lminfo
, DXFILELOAD_FROMMEMORY
, &enum_object
);
377 ok(hr
== DXFILEERR_BADFILETYPE
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
379 IDirectXFile_Release(dxfile
);
382 static void test_compressed_files(void)
385 LPDIRECTXFILE dxfile
= NULL
;
386 LPDIRECTXFILEENUMOBJECT enum_object
;
387 LPDIRECTXFILEDATA file_data
;
388 DXFILELOADMEMORY lminfo
;
392 if (!pDirectXFileCreate
)
394 win_skip("DirectXFileCreate is not available\n");
398 hr
= pDirectXFileCreate(&dxfile
);
399 ok(hr
== DXFILE_OK
, "DirectXFileCreate: %x\n", hr
);
402 skip("Couldn't create DirectXFile interface\n");
406 hr
= IDirectXFile_RegisterTemplates(dxfile
, compressed_template
, sizeof(compressed_template
) - 1);
407 ok(hr
== DXFILE_OK
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
409 lminfo
.lpMemory
= compressed_object
;
410 lminfo
.dSize
= sizeof(compressed_object
) - 1;
411 hr
= IDirectXFile_CreateEnumObject(dxfile
, &lminfo
, DXFILELOAD_FROMMEMORY
, &enum_object
);
412 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
414 hr
= IDirectXFileEnumObject_GetNextDataObject(enum_object
, &file_data
);
415 ok(hr
== DXFILE_OK
, "IDirectXFileEnumObject_GetNextDataObject: %x\n", hr
);
417 hr
= IDirectXFileData_GetData(file_data
, NULL
, &size
, (void**)&data
);
418 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetData: %x\n", hr
);
420 ok(size
== 8, "Retrieved data size is wrong\n");
421 ok((*((WORD
*)data
) == 1) && (*((WORD
*)(data
+2)) == 2) && (*((DWORD
*)(data
+4)) == 3), "Retrieved data is wrong\n");
423 IDirectXFileData_Release(file_data
);
424 IDirectXFileEnumObject_Release(enum_object
);
425 IDirectXFile_Release(dxfile
);
428 static void test_getname(void)
432 LPDIRECTXFILE lpDirectXFile
= NULL
;
433 LPDIRECTXFILEENUMOBJECT lpdxfeo
;
434 LPDIRECTXFILEDATA lpdxfd
;
435 DXFILELOADMEMORY dxflm
;
439 if (!pDirectXFileCreate
)
441 win_skip("DirectXFileCreate is not available\n");
445 hr
= pDirectXFileCreate(&lpDirectXFile
);
446 ok(hr
== DXFILE_OK
, "DirectXFileCreate: %x\n", hr
);
449 skip("Couldn't create DirectXFile interface\n");
453 hr
= IDirectXFile_RegisterTemplates(lpDirectXFile
, template, sizeof(template) - 1);
454 ok(hr
== DXFILE_OK
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
456 /* Check object with name */
457 dxflm
.lpMemory
= &object
;
458 dxflm
.dSize
= sizeof(object
) - 1;
459 hr
= IDirectXFile_CreateEnumObject(lpDirectXFile
, &dxflm
, DXFILELOAD_FROMMEMORY
, &lpdxfeo
);
460 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
461 hr
= IDirectXFileEnumObject_GetNextDataObject(lpdxfeo
, &lpdxfd
);
462 ok(hr
== DXFILE_OK
, "IDirectXFileEnumObject_GetNextDataObject: %x\n", hr
);
464 hr
= IDirectXFileData_GetName(lpdxfd
, NULL
, NULL
);
465 ok(hr
== DXFILEERR_BADVALUE
, "IDirectXFileData_GetName: %x\n", hr
);
466 hr
= IDirectXFileData_GetName(lpdxfd
, name
, NULL
);
467 ok(hr
== DXFILEERR_BADVALUE
, "IDirectXFileData_GetName: %x\n", hr
);
468 hr
= IDirectXFileData_GetName(lpdxfd
, NULL
, &length
);
469 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetName: %x\n", hr
);
470 ok(length
== 7, "Returned length should be 7 instead of %u\n", length
);
471 length
= sizeof(name
);
472 hr
= IDirectXFileData_GetName(lpdxfd
, name
, &length
);
473 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetName: %x\n", hr
);
474 ok(length
== 7, "Returned length should be 7 instead of %u\n", length
);
475 ok(!strcmp(name
, "Object"), "Returned string should be 'Object' intead of '%s'\n", name
);
477 hr
= IDirectXFileData_GetName(lpdxfd
, name
, &length
);
478 ok(hr
== DXFILEERR_BADVALUE
, "IDirectXFileData_GetName: %x\n", hr
);
480 ref
= IDirectXFileEnumObject_Release(lpdxfeo
);
481 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
482 ref
= IDirectXFileData_Release(lpdxfd
);
483 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
485 /* Check object without name */
486 dxflm
.lpMemory
= &object_noname
;
487 dxflm
.dSize
= sizeof(object_noname
) - 1;
488 hr
= IDirectXFile_CreateEnumObject(lpDirectXFile
, &dxflm
, DXFILELOAD_FROMMEMORY
, &lpdxfeo
);
489 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
490 hr
= IDirectXFileEnumObject_GetNextDataObject(lpdxfeo
, &lpdxfd
);
491 ok(hr
== DXFILE_OK
, "IDirectXFileEnumObject_GetNextDataObject: %x\n", hr
);
493 hr
= IDirectXFileData_GetName(lpdxfd
, NULL
, &length
);
494 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetName: %x\n", hr
);
495 ok(length
== 0, "Returned length should be 0 instead of %u\n", length
);
496 length
= sizeof(name
);
497 hr
= IDirectXFileData_GetName(lpdxfd
, name
, &length
);
498 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetName: %x\n", hr
);
499 ok(length
== 0, "Returned length should be 0 instead of %u\n", length
);
501 ref
= IDirectXFileEnumObject_Release(lpdxfeo
);
502 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
503 ref
= IDirectXFileData_Release(lpdxfd
);
504 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
505 ref
= IDirectXFile_Release(lpDirectXFile
);
506 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
509 static void test_syntax(void)
513 LPDIRECTXFILE lpDirectXFile
= NULL
;
514 LPDIRECTXFILEENUMOBJECT lpdxfeo
;
515 LPDIRECTXFILEDATA lpdxfd
;
516 DXFILELOADMEMORY dxflm
;
520 if (!pDirectXFileCreate
)
522 win_skip("DirectXFileCreate is not available\n");
526 hr
= pDirectXFileCreate(&lpDirectXFile
);
527 ok(hr
== DXFILE_OK
, "DirectXFileCreate: %x\n", hr
);
530 skip("Couldn't create DirectXFile interface\n");
534 hr
= IDirectXFile_RegisterTemplates(lpDirectXFile
, template_syntax_empty_array
, sizeof(template_syntax_empty_array
) - 1);
535 ok(hr
== DXFILE_OK
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
537 dxflm
.lpMemory
= &object_syntax_empty_array_semicolon
;
538 dxflm
.dSize
= sizeof(object_syntax_empty_array_semicolon
) - 1;
539 hr
= IDirectXFile_CreateEnumObject(lpDirectXFile
, &dxflm
, DXFILELOAD_FROMMEMORY
, &lpdxfeo
);
540 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
541 hr
= IDirectXFileEnumObject_GetNextDataObject(lpdxfeo
, &lpdxfd
);
542 ok(hr
== DXFILE_OK
, "IDirectXFileEnumObject_GetNextDataObject: %x\n", hr
);
544 ref
= IDirectXFileEnumObject_Release(lpdxfeo
);
545 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
548 ref
= IDirectXFileData_Release(lpdxfd
);
549 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
552 dxflm
.lpMemory
= &object_syntax_empty_array_nosemicolon
;
553 dxflm
.dSize
= sizeof(object_syntax_empty_array_nosemicolon
) - 1;
554 hr
= IDirectXFile_CreateEnumObject(lpDirectXFile
, &dxflm
, DXFILELOAD_FROMMEMORY
, &lpdxfeo
);
555 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
556 hr
= IDirectXFileEnumObject_GetNextDataObject(lpdxfeo
, &lpdxfd
);
557 ok(hr
== DXFILE_OK
, "IDirectXFileEnumObject_GetNextDataObject: %x\n", hr
);
559 ref
= IDirectXFileEnumObject_Release(lpdxfeo
);
560 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
563 ref
= IDirectXFileData_Release(lpdxfd
);
564 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
567 hr
= IDirectXFile_RegisterTemplates(lpDirectXFile
, template_syntax_string
, sizeof(template_syntax_string
) - 1);
568 ok(hr
== DXFILE_OK
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
570 dxflm
.lpMemory
= &object_syntax_string_normal
;
571 dxflm
.dSize
= sizeof(object_syntax_string_normal
) - 1;
572 hr
= IDirectXFile_CreateEnumObject(lpDirectXFile
, &dxflm
, DXFILELOAD_FROMMEMORY
, &lpdxfeo
);
573 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
574 hr
= IDirectXFileEnumObject_GetNextDataObject(lpdxfeo
, &lpdxfd
);
575 ok(hr
== DXFILE_OK
, "IDirectXFileEnumObject_GetNextDataObject: %x\n", hr
);
576 hr
= IDirectXFileData_GetData(lpdxfd
, NULL
, &size
, (void**)&string
);
577 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetData: %x\n", hr
);
578 ok(size
== sizeof(char*), "Got wrong data size %d\n", size
);
579 ok(!strcmp(*string
, "foobar"), "Got string %s, expected foobar\n", *string
);
581 ref
= IDirectXFileEnumObject_Release(lpdxfeo
);
582 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
585 ref
= IDirectXFileData_Release(lpdxfd
);
586 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
589 dxflm
.lpMemory
= &object_syntax_string_with_separator
;
590 dxflm
.dSize
= sizeof(object_syntax_string_with_separator
) - 1;
591 hr
= IDirectXFile_CreateEnumObject(lpDirectXFile
, &dxflm
, DXFILELOAD_FROMMEMORY
, &lpdxfeo
);
592 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
593 hr
= IDirectXFileEnumObject_GetNextDataObject(lpdxfeo
, &lpdxfd
);
594 ok(hr
== DXFILE_OK
, "IDirectXFileEnumObject_GetNextDataObject: %x\n", hr
);
595 hr
= IDirectXFileData_GetData(lpdxfd
, NULL
, &size
, (void**)&string
);
596 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetData: %x\n", hr
);
597 ok(size
== sizeof(char*), "Got wrong data size %d\n", size
);
598 ok(!strcmp(*string
, "foo;bar"), "Got string %s, expected foo;bar\n", *string
);
600 ref
= IDirectXFileEnumObject_Release(lpdxfeo
);
601 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
604 ref
= IDirectXFileData_Release(lpdxfd
);
605 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
608 ref
= IDirectXFile_Release(lpDirectXFile
);
609 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
612 /* Set it to 1 to expand the string when dumping the object. This is useful when there is
613 * only one string in a sub-object (very common). Use with care, this may lead to a crash. */
614 #define EXPAND_STRING 0
616 static void process_data(LPDIRECTXFILEDATA lpDirectXFileData
, int* plevel
)
621 CONST GUID
* clsid_type
= NULL
;
623 char str_clsid_type
[40];
625 LPDIRECTXFILEOBJECT pChildObj
;
631 hr
= IDirectXFileData_GetId(lpDirectXFileData
, &clsid
);
632 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetId: %x\n", hr
);
633 hr
= IDirectXFileData_GetName(lpDirectXFileData
, name
, &len
);
634 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetName: %x\n", hr
);
635 hr
= IDirectXFileData_GetType(lpDirectXFileData
, &clsid_type
);
636 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetType: %x\n", hr
);
637 hr
= IDirectXFileData_GetData(lpDirectXFileData
, NULL
, &size
, (void**)&pData
);
638 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetData: %x\n", hr
);
639 for (i
= 0; i
< *plevel
; i
++)
641 debugstr_guid(str_clsid
, &clsid
);
642 debugstr_guid(str_clsid_type
, clsid_type
);
643 printf("Found object '%s' - %s - %s - %d\n", len
? name
: "", str_clsid
, str_clsid_type
, size
);
645 if (EXPAND_STRING
&& size
== 4)
647 char * str
= *(char**)pData
;
648 printf("string %s\n", str
);
652 for (k
= 0; k
< size
; k
++)
656 printf("%02x ", pData
[k
]);
661 while (SUCCEEDED(hr
= IDirectXFileData_GetNextObject(lpDirectXFileData
, &pChildObj
)))
663 LPDIRECTXFILEDATA p1
;
664 LPDIRECTXFILEDATAREFERENCE p2
;
665 LPDIRECTXFILEBINARY p3
;
668 hr
= IDirectXFileObject_QueryInterface(pChildObj
, &IID_IDirectXFileData
, (void **) &p1
);
671 for (i
= 0; i
< *plevel
; i
++)
673 printf("Found Data (%d)\n", j
);
674 process_data(p1
, plevel
);
675 IDirectXFileData_Release(p1
);
677 hr
= IDirectXFileObject_QueryInterface(pChildObj
, &IID_IDirectXFileDataReference
, (void **) &p2
);
680 LPDIRECTXFILEDATA pfdo
;
681 for (i
= 0; i
< *plevel
; i
++)
683 printf("Found Data Reference (%d)\n", j
);
685 hr
= IDirectXFileDataReference_GetId(lpDirectXFileData
, &clsid
);
686 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetId: %x\n", hr
);
687 hr
= IDirectXFileDataReference_GetName(lpDirectXFileData
, name
, &len
);
688 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetName: %x\n", hr
);
690 IDirectXFileDataReference_Resolve(p2
, &pfdo
);
691 process_data(pfdo
, plevel
);
692 IDirectXFileData_Release(pfdo
);
693 IDirectXFileDataReference_Release(p2
);
695 hr
= IDirectXFileObject_QueryInterface(pChildObj
, &IID_IDirectXFileBinary
, (void **) &p3
);
698 for (i
= 0; i
< *plevel
; i
++)
700 printf("Found Binary (%d)\n", j
);
701 IDirectXFileBinary_Release(p3
);
703 IDirectXFileObject_Release(pChildObj
);
706 ok(hr
== DXFILE_OK
|| hr
== DXFILEERR_NOMOREOBJECTS
, "IDirectXFileData_GetNextObject: %x\n", hr
);
709 static void test_dump(void)
713 LPDIRECTXFILE lpDirectXFile
= NULL
;
714 LPDIRECTXFILEENUMOBJECT lpDirectXFileEnumObject
= NULL
;
715 LPDIRECTXFILEDATA lpDirectXFileData
= NULL
;
717 LPVOID pvData
= NULL
;
720 if (!pDirectXFileCreate
)
722 win_skip("DirectXFileCreate is not available\n");
726 /* Dump data only if there is an object and a template */
727 hFile
= CreateFileA("objects.txt", GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, NULL
);
728 if (hFile
== INVALID_HANDLE_VALUE
)
732 hFile
= CreateFileA("templates.txt", GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, NULL
);
733 if (hFile
== INVALID_HANDLE_VALUE
)
736 pvData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, 10000);
738 if (!ReadFile(hFile
, pvData
, 10000, &cbSize
, NULL
))
740 skip("Templates file is too big\n");
744 printf("Load templates file (%d bytes)\n", cbSize
);
746 hr
= pDirectXFileCreate(&lpDirectXFile
);
747 ok(hr
== DXFILE_OK
, "DirectXFileCreate: %x\n", hr
);
750 skip("Couldn't create DirectXFile interface\n");
754 hr
= IDirectXFile_RegisterTemplates(lpDirectXFile
, pvData
, cbSize
);
755 ok(hr
== DXFILE_OK
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
757 hr
= IDirectXFile_CreateEnumObject(lpDirectXFile
, (LPVOID
)"objects.txt", DXFILELOAD_FROMFILE
, &lpDirectXFileEnumObject
);
758 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
760 while (SUCCEEDED(hr
= IDirectXFileEnumObject_GetNextDataObject(lpDirectXFileEnumObject
, &lpDirectXFileData
)))
764 process_data(lpDirectXFileData
, &level
);
765 IDirectXFileData_Release(lpDirectXFileData
);
767 ok(hr
== DXFILE_OK
|| hr
== DXFILEERR_NOMOREOBJECTS
, "IDirectXFileEnumObject_GetNextDataObject: %x\n", hr
);
769 ref
= IDirectXFile_Release(lpDirectXFileEnumObject
);
770 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
772 ref
= IDirectXFile_Release(lpDirectXFile
);
773 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
778 HeapFree(GetProcessHeap(), 0, pvData
);
783 init_function_pointers();
786 test_CreateEnumObject();
788 test_compressed_files();
793 FreeLibrary(hd3dxof
);