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 can not exceed 32768 bytes
78 * Data in x files is preceeding by the size (32-bit) of the decompressed file including the xof header (16 bytes)
79 * It does not seem possible to generate a 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
[] =
122 static void init_function_pointers(void)
124 /* We have to use LoadLibrary as no d3dxof functions are referenced directly */
125 hd3dxof
= LoadLibraryA("d3dxof.dll");
127 pDirectXFileCreate
= (void *)GetProcAddress(hd3dxof
, "DirectXFileCreate");
130 static ULONG
getRefcount(IUnknown
*iface
)
132 IUnknown_AddRef(iface
);
133 return IUnknown_Release(iface
);
136 static void test_refcount(void)
140 LPDIRECTXFILE lpDirectXFile
= NULL
;
141 LPDIRECTXFILEENUMOBJECT lpdxfeo
;
142 LPDIRECTXFILEDATA lpdxfd
;
143 DXFILELOADMEMORY dxflm
;
145 if (!pDirectXFileCreate
)
147 win_skip("DirectXFileCreate is not available\n");
151 hr
= pDirectXFileCreate(&lpDirectXFile
);
152 ok(hr
== DXFILE_OK
, "DirectXFileCreate: %x\n", hr
);
155 skip("Couldn't create DirectXFile interface\n");
159 ref
= getRefcount( (IUnknown
*) lpDirectXFile
);
160 ok(ref
== 1, "Got refcount %d, expected 1\n", ref
);
161 ref
= IDirectXFile_AddRef(lpDirectXFile
);
162 ok(ref
== 2, "Got refcount %d, expected 2\n", ref
);
163 ref
= IDirectXFile_Release(lpDirectXFile
);
164 ok(ref
== 1, "Got refcount %d, expected 1\n", ref
);
166 hr
= IDirectXFile_RegisterTemplates(lpDirectXFile
, template, sizeof(template) - 1);
167 ok(hr
== DXFILE_OK
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
169 dxflm
.lpMemory
= &object
;
170 dxflm
.dSize
= sizeof(object
) - 1;
171 hr
= IDirectXFile_CreateEnumObject(lpDirectXFile
, &dxflm
, DXFILELOAD_FROMMEMORY
, &lpdxfeo
);
172 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
173 ref
= getRefcount( (IUnknown
*) lpDirectXFile
);
174 ok(ref
== 1, "Got refcount %d, expected 1\n", ref
);
175 ref
= getRefcount( (IUnknown
*) lpdxfeo
);
176 ok(ref
== 1, "Got refcount %d, expected 1\n", ref
);
178 hr
= IDirectXFileEnumObject_GetNextDataObject(lpdxfeo
, &lpdxfd
);
179 ok(hr
== DXFILE_OK
, "IDirectXFileEnumObject_GetNextDataObject: %x\n", hr
);
180 ref
= getRefcount( (IUnknown
*) lpDirectXFile
);
181 ok(ref
== 1, "Got refcount %d, expected 1\n", ref
);
182 ref
= getRefcount( (IUnknown
*) lpdxfeo
);
183 ok(ref
== 1, "Got refcount %d, expected 1\n", ref
);
184 /* Enum object gets references to all top level objects */
185 ref
= getRefcount( (IUnknown
*) lpdxfd
);
186 ok(ref
== 2, "Got refcount %d, expected 2\n", ref
);
188 ref
= IDirectXFile_Release(lpDirectXFile
);
189 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
190 /* Nothing changes for all other objects */
191 ref
= getRefcount( (IUnknown
*) lpdxfeo
);
192 ok(ref
== 1, "Got refcount %d, expected 1\n", ref
);
193 ref
= getRefcount( (IUnknown
*) lpdxfd
);
194 ok(ref
== 2, "Got refcount %d, expected 2\n", ref
);
196 ref
= IDirectXFileEnumObject_Release(lpdxfeo
);
197 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
198 /* Enum object releases references to all top level objects */
199 ref
= getRefcount( (IUnknown
*) lpdxfd
);
200 ok(ref
== 1, "Got refcount %d, expected 1\n", ref
);
202 ref
= IDirectXFileData_Release(lpdxfd
);
203 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
206 static void test_CreateEnumObject(void)
210 LPDIRECTXFILE lpDirectXFile
= NULL
;
211 LPDIRECTXFILEENUMOBJECT lpdxfeo
;
212 LPDIRECTXFILEDATA lpdxfd
;
213 DXFILELOADMEMORY dxflm
;
217 if (!pDirectXFileCreate
)
219 win_skip("DirectXFileCreate is not available\n");
223 hr
= pDirectXFileCreate(&lpDirectXFile
);
224 ok(hr
== DXFILE_OK
, "DirectXFileCreate: %x\n", hr
);
227 skip("Couldn't create DirectXFile interface\n");
231 hr
= IDirectXFile_RegisterTemplates(lpDirectXFile
, template, sizeof(template) - 1);
232 ok(hr
== DXFILE_OK
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
234 dxflm
.lpMemory
= &object
;
235 dxflm
.dSize
= sizeof(object
) - 1;
236 /* Check that only lowest 4 bits are relevant in DXFILELOADOPTIONS */
237 hr
= IDirectXFile_CreateEnumObject(lpDirectXFile
, &dxflm
, 0xFFFFFFF0 + DXFILELOAD_FROMMEMORY
, &lpdxfeo
);
238 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
240 hr
= IDirectXFileEnumObject_GetNextDataObject(lpdxfeo
, &lpdxfd
);
241 ok(hr
== DXFILE_OK
, "IDirectXFileEnumObject_GetNextDataObject: %x\n", hr
);
243 /* Get all data (szMember == NULL) */
244 hr
= IDirectXFileData_GetData(lpdxfd
, NULL
, &size
, (void**)&pdata
);
245 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetData: %x\n", hr
);
247 ok(size
== 8, "Retrieved data size is wrong (%u instead of 8)\n", size
);
248 ok((*((WORD
*)pdata
) == 1) && (*((WORD
*)(pdata
+2)) == 2) && (*((DWORD
*)(pdata
+4)) == 3), "Retrieved data is wrong\n");
250 /* Get only "major" member (szMember == "major") */
251 hr
= IDirectXFileData_GetData(lpdxfd
, "major", &size
, (void**)&pdata
);
252 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetData: %x\n", hr
);
254 ok(size
== 2, "Retrieved data size is wrong (%u instead of 2)\n", size
);
255 ok(*((WORD
*)pdata
) == 1, "Retrieved data is wrong (%u instead of 1)\n", *((WORD
*)pdata
));
257 /* Get only "minor" member (szMember == "minor") */
258 hr
= IDirectXFileData_GetData(lpdxfd
, "minor", &size
, (void**)&pdata
);
259 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetData: %x\n", hr
);
261 ok(size
== 2, "Retrieved data size is wrong (%u instead of 2)\n", size
);
262 ok(*((WORD
*)pdata
) == 2, "Retrieved data is wrong (%u instead of 2)\n", *((WORD
*)pdata
));
264 /* Get only "flags" member (szMember == "flags") */
265 hr
= IDirectXFileData_GetData(lpdxfd
, "flags", &size
, (void**)&pdata
);
266 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetData: %x\n", hr
);
268 ok(size
== 4, "Retrieved data size is wrong (%u instead of 4)\n", size
);
269 ok(*((WORD
*)pdata
) == 3, "Retrieved data is wrong (%u instead of 3)\n", *((WORD
*)pdata
));
271 /* Try to get not existing member (szMember == "unknown") */
272 hr
= IDirectXFileData_GetData(lpdxfd
, "unknow", &size
, (void**)&pdata
);
273 ok(hr
== DXFILEERR_BADDATAREFERENCE
, "IDirectXFileData_GetData: %x\n", hr
);
275 ref
= IDirectXFileEnumObject_Release(lpdxfeo
);
276 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
278 ref
= IDirectXFile_Release(lpDirectXFile
);
279 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
281 ref
= IDirectXFileData_Release(lpdxfd
);
282 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
285 static void test_file_types(void)
288 LPDIRECTXFILE dxfile
= NULL
;
289 LPDIRECTXFILEENUMOBJECT enum_object
;
290 DXFILELOADMEMORY lminfo
;
292 if (!pDirectXFileCreate
)
294 win_skip("DirectXFileCreate is not available\n");
298 hr
= pDirectXFileCreate(&dxfile
);
299 ok(hr
== DXFILE_OK
, "DirectXFileCreate: %x\n", hr
);
302 skip("Couldn't create DirectXFile interface\n");
306 hr
= IDirectXFile_RegisterTemplates(dxfile
, empty_txt_file
, sizeof(empty_txt_file
) - 1);
307 ok(hr
== DXFILE_OK
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
309 hr
= IDirectXFile_RegisterTemplates(dxfile
, empty_bin_file
, sizeof(empty_bin_file
) - 1);
310 ok(hr
== DXFILE_OK
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
312 hr
= IDirectXFile_RegisterTemplates(dxfile
, empty_tzip_file
, sizeof(empty_tzip_file
) - 1);
313 ok(hr
== DXFILE_OK
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
315 hr
= IDirectXFile_RegisterTemplates(dxfile
, empty_bzip_file
, sizeof(empty_bzip_file
) - 1);
316 ok(hr
== DXFILE_OK
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
318 hr
= IDirectXFile_RegisterTemplates(dxfile
, empty_cmp_file
, sizeof(empty_cmp_file
) - 1);
319 ok(hr
== DXFILEERR_BADFILETYPE
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
321 hr
= IDirectXFile_RegisterTemplates(dxfile
, empty_xxxx_file
, sizeof(empty_xxxx_file
) - 1);
322 ok(hr
== DXFILEERR_BADFILETYPE
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
324 lminfo
.lpMemory
= empty_txt_file
;
325 lminfo
.dSize
= sizeof(empty_txt_file
) - 1;
326 hr
= IDirectXFile_CreateEnumObject(dxfile
, &lminfo
, DXFILELOAD_FROMMEMORY
, &enum_object
);
327 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
328 if (hr
== DXFILE_OK
) IDirectXFileEnumObject_Release(enum_object
);
330 lminfo
.lpMemory
= empty_bin_file
;
331 lminfo
.dSize
= sizeof(empty_bin_file
) - 1;
332 hr
= IDirectXFile_CreateEnumObject(dxfile
, &lminfo
, DXFILELOAD_FROMMEMORY
, &enum_object
);
333 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
334 if (hr
== DXFILE_OK
) IDirectXFileEnumObject_Release(enum_object
);
336 lminfo
.lpMemory
= empty_tzip_file
;
337 lminfo
.dSize
= sizeof(empty_tzip_file
) - 1;
338 hr
= IDirectXFile_CreateEnumObject(dxfile
, &lminfo
, DXFILELOAD_FROMMEMORY
, &enum_object
);
339 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
340 if (hr
== DXFILE_OK
) IDirectXFileEnumObject_Release(enum_object
);
342 lminfo
.lpMemory
= empty_bzip_file
;
343 lminfo
.dSize
= sizeof(empty_bzip_file
) - 1;
344 hr
= IDirectXFile_CreateEnumObject(dxfile
, &lminfo
, DXFILELOAD_FROMMEMORY
, &enum_object
);
345 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
346 if (hr
== DXFILE_OK
) IDirectXFileEnumObject_Release(enum_object
);
348 lminfo
.lpMemory
= empty_cmp_file
;
349 lminfo
.dSize
= sizeof(empty_cmp_file
) - 1;
350 hr
= IDirectXFile_CreateEnumObject(dxfile
, &lminfo
, DXFILELOAD_FROMMEMORY
, &enum_object
);
351 ok(hr
== DXFILEERR_BADFILETYPE
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
353 lminfo
.lpMemory
= empty_xxxx_file
;
354 lminfo
.dSize
= sizeof(empty_xxxx_file
) - 1;
355 hr
= IDirectXFile_CreateEnumObject(dxfile
, &lminfo
, DXFILELOAD_FROMMEMORY
, &enum_object
);
356 ok(hr
== DXFILEERR_BADFILETYPE
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
358 IDirectXFile_Release(dxfile
);
361 static void test_compressed_files(void)
364 LPDIRECTXFILE dxfile
= NULL
;
365 LPDIRECTXFILEENUMOBJECT enum_object
;
366 LPDIRECTXFILEDATA file_data
;
367 DXFILELOADMEMORY lminfo
;
371 if (!pDirectXFileCreate
)
373 win_skip("DirectXFileCreate is not available\n");
377 hr
= pDirectXFileCreate(&dxfile
);
378 ok(hr
== DXFILE_OK
, "DirectXFileCreate: %x\n", hr
);
381 skip("Couldn't create DirectXFile interface\n");
385 hr
= IDirectXFile_RegisterTemplates(dxfile
, compressed_template
, sizeof(compressed_template
) - 1);
386 ok(hr
== DXFILE_OK
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
388 lminfo
.lpMemory
= compressed_object
;
389 lminfo
.dSize
= sizeof(compressed_object
) - 1;
390 hr
= IDirectXFile_CreateEnumObject(dxfile
, &lminfo
, DXFILELOAD_FROMMEMORY
, &enum_object
);
391 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
393 hr
= IDirectXFileEnumObject_GetNextDataObject(enum_object
, &file_data
);
394 ok(hr
== DXFILE_OK
, "IDirectXFileEnumObject_GetNextDataObject: %x\n", hr
);
396 hr
= IDirectXFileData_GetData(file_data
, NULL
, &size
, (void**)&data
);
397 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetData: %x\n", hr
);
399 ok(size
== 8, "Retrieved data size is wrong\n");
400 ok((*((WORD
*)data
) == 1) && (*((WORD
*)(data
+2)) == 2) && (*((DWORD
*)(data
+4)) == 3), "Retrieved data is wrong\n");
402 IDirectXFileData_Release(file_data
);
403 IDirectXFileEnumObject_Release(enum_object
);
404 IDirectXFile_Release(dxfile
);
407 static void test_getname(void)
411 LPDIRECTXFILE lpDirectXFile
= NULL
;
412 LPDIRECTXFILEENUMOBJECT lpdxfeo
;
413 LPDIRECTXFILEDATA lpdxfd
;
414 DXFILELOADMEMORY dxflm
;
418 if (!pDirectXFileCreate
)
420 win_skip("DirectXFileCreate is not available\n");
424 hr
= pDirectXFileCreate(&lpDirectXFile
);
425 ok(hr
== DXFILE_OK
, "DirectXFileCreate: %x\n", hr
);
428 skip("Couldn't create DirectXFile interface\n");
432 hr
= IDirectXFile_RegisterTemplates(lpDirectXFile
, template, sizeof(template) - 1);
433 ok(hr
== DXFILE_OK
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
435 /* Check object with name */
436 dxflm
.lpMemory
= &object
;
437 dxflm
.dSize
= sizeof(object
) - 1;
438 hr
= IDirectXFile_CreateEnumObject(lpDirectXFile
, &dxflm
, DXFILELOAD_FROMMEMORY
, &lpdxfeo
);
439 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
440 hr
= IDirectXFileEnumObject_GetNextDataObject(lpdxfeo
, &lpdxfd
);
441 ok(hr
== DXFILE_OK
, "IDirectXFileEnumObject_GetNextDataObject: %x\n", hr
);
443 hr
= IDirectXFileData_GetName(lpdxfd
, NULL
, NULL
);
444 ok(hr
== DXFILEERR_BADVALUE
, "IDirectXFileData_GetName: %x\n", hr
);
445 hr
= IDirectXFileData_GetName(lpdxfd
, name
, NULL
);
446 ok(hr
== DXFILEERR_BADVALUE
, "IDirectXFileData_GetName: %x\n", hr
);
447 hr
= IDirectXFileData_GetName(lpdxfd
, NULL
, &length
);
448 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetName: %x\n", hr
);
449 ok(length
== 7, "Returned length should be 7 instead of %u\n", length
);
450 length
= sizeof(name
);
451 hr
= IDirectXFileData_GetName(lpdxfd
, name
, &length
);
452 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetName: %x\n", hr
);
453 ok(length
== 7, "Returned length should be 7 instead of %u\n", length
);
454 ok(!strcmp(name
, "Object"), "Returned string should be 'Object' intead of '%s'\n", name
);
456 hr
= IDirectXFileData_GetName(lpdxfd
, name
, &length
);
457 ok(hr
== DXFILEERR_BADVALUE
, "IDirectXFileData_GetName: %x\n", hr
);
459 ref
= IDirectXFileEnumObject_Release(lpdxfeo
);
460 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
461 ref
= IDirectXFileData_Release(lpdxfd
);
462 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
464 /* Check object without name */
465 dxflm
.lpMemory
= &object_noname
;
466 dxflm
.dSize
= sizeof(object_noname
) - 1;
467 hr
= IDirectXFile_CreateEnumObject(lpDirectXFile
, &dxflm
, DXFILELOAD_FROMMEMORY
, &lpdxfeo
);
468 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
469 hr
= IDirectXFileEnumObject_GetNextDataObject(lpdxfeo
, &lpdxfd
);
470 ok(hr
== DXFILE_OK
, "IDirectXFileEnumObject_GetNextDataObject: %x\n", hr
);
472 hr
= IDirectXFileData_GetName(lpdxfd
, NULL
, &length
);
473 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetName: %x\n", hr
);
474 ok(length
== 0, "Returned length should be 0 instead of %u\n", length
);
475 length
= sizeof(name
);
476 hr
= IDirectXFileData_GetName(lpdxfd
, name
, &length
);
477 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetName: %x\n", hr
);
478 ok(length
== 0, "Returned length should be 0 instead of %u\n", length
);
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
);
484 ref
= IDirectXFile_Release(lpDirectXFile
);
485 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
488 static void test_syntax(void)
492 LPDIRECTXFILE lpDirectXFile
= NULL
;
493 LPDIRECTXFILEENUMOBJECT lpdxfeo
;
494 LPDIRECTXFILEDATA lpdxfd
;
495 DXFILELOADMEMORY dxflm
;
497 if (!pDirectXFileCreate
)
499 win_skip("DirectXFileCreate is not available\n");
503 hr
= pDirectXFileCreate(&lpDirectXFile
);
504 ok(hr
== DXFILE_OK
, "DirectXFileCreate: %x\n", hr
);
507 skip("Couldn't create DirectXFile interface\n");
511 hr
= IDirectXFile_RegisterTemplates(lpDirectXFile
, template_syntax_empty_array
, sizeof(template_syntax_empty_array
) - 1);
512 ok(hr
== DXFILE_OK
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
514 dxflm
.lpMemory
= &object_syntax_empty_array_semicolon
;
515 dxflm
.dSize
= sizeof(object_syntax_empty_array_semicolon
) - 1;
516 hr
= IDirectXFile_CreateEnumObject(lpDirectXFile
, &dxflm
, DXFILELOAD_FROMMEMORY
, &lpdxfeo
);
517 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
518 hr
= IDirectXFileEnumObject_GetNextDataObject(lpdxfeo
, &lpdxfd
);
519 ok(hr
== DXFILE_OK
, "IDirectXFileEnumObject_GetNextDataObject: %x\n", hr
);
521 ref
= IDirectXFileEnumObject_Release(lpdxfeo
);
522 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
525 ref
= IDirectXFileData_Release(lpdxfd
);
526 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
529 dxflm
.lpMemory
= &object_syntax_empty_array_nosemicolon
;
530 dxflm
.dSize
= sizeof(object_syntax_empty_array_nosemicolon
) - 1;
531 hr
= IDirectXFile_CreateEnumObject(lpDirectXFile
, &dxflm
, DXFILELOAD_FROMMEMORY
, &lpdxfeo
);
532 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
533 hr
= IDirectXFileEnumObject_GetNextDataObject(lpdxfeo
, &lpdxfd
);
534 ok(hr
== DXFILE_OK
, "IDirectXFileEnumObject_GetNextDataObject: %x\n", hr
);
536 ref
= IDirectXFileEnumObject_Release(lpdxfeo
);
537 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
540 ref
= IDirectXFileData_Release(lpdxfd
);
541 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
544 ref
= IDirectXFile_Release(lpDirectXFile
);
545 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
548 /* Set it to 1 to expand the string when dumping the object. This is useful when there is
549 * only one string in a sub-object (very common). Use with care, this may lead to a crash. */
550 #define EXPAND_STRING 0
552 static void process_data(LPDIRECTXFILEDATA lpDirectXFileData
, int* plevel
)
557 CONST GUID
* clsid_type
= NULL
;
559 char str_clsid_type
[40];
561 LPDIRECTXFILEOBJECT pChildObj
;
567 hr
= IDirectXFileData_GetId(lpDirectXFileData
, &clsid
);
568 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetId: %x\n", hr
);
569 hr
= IDirectXFileData_GetName(lpDirectXFileData
, name
, &len
);
570 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetName: %x\n", hr
);
571 hr
= IDirectXFileData_GetType(lpDirectXFileData
, &clsid_type
);
572 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetType: %x\n", hr
);
573 hr
= IDirectXFileData_GetData(lpDirectXFileData
, NULL
, &size
, (void**)&pData
);
574 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetData: %x\n", hr
);
575 for (i
= 0; i
< *plevel
; i
++)
577 debugstr_guid(str_clsid
, &clsid
);
578 debugstr_guid(str_clsid_type
, clsid_type
);
579 printf("Found object '%s' - %s - %s - %d\n", len
? name
: "", str_clsid
, str_clsid_type
, size
);
581 if (EXPAND_STRING
&& size
== 4)
583 char * str
= *(char**)pData
;
584 printf("string %s\n", str
);
588 for (k
= 0; k
< size
; k
++)
592 printf("%02x ", pData
[k
]);
597 while (SUCCEEDED(hr
= IDirectXFileData_GetNextObject(lpDirectXFileData
, &pChildObj
)))
599 LPDIRECTXFILEDATA p1
;
600 LPDIRECTXFILEDATAREFERENCE p2
;
601 LPDIRECTXFILEBINARY p3
;
604 hr
= IDirectXFileObject_QueryInterface(pChildObj
, &IID_IDirectXFileData
, (void **) &p1
);
607 for (i
= 0; i
< *plevel
; i
++)
609 printf("Found Data (%d)\n", j
);
610 process_data(p1
, plevel
);
611 IDirectXFileData_Release(p1
);
613 hr
= IDirectXFileObject_QueryInterface(pChildObj
, &IID_IDirectXFileDataReference
, (void **) &p2
);
616 LPDIRECTXFILEDATA pfdo
;
617 for (i
= 0; i
< *plevel
; i
++)
619 printf("Found Data Reference (%d)\n", j
);
621 hr
= IDirectXFileDataReference_GetId(lpDirectXFileData
, &clsid
);
622 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetId: %x\n", hr
);
623 hr
= IDirectXFileDataReference_GetName(lpDirectXFileData
, name
, &len
);
624 ok(hr
== DXFILE_OK
, "IDirectXFileData_GetName: %x\n", hr
);
626 IDirectXFileDataReference_Resolve(p2
, &pfdo
);
627 process_data(pfdo
, plevel
);
628 IDirectXFileData_Release(pfdo
);
629 IDirectXFileDataReference_Release(p2
);
631 hr
= IDirectXFileObject_QueryInterface(pChildObj
, &IID_IDirectXFileBinary
, (void **) &p3
);
634 for (i
= 0; i
< *plevel
; i
++)
636 printf("Found Binary (%d)\n", j
);
637 IDirectXFileBinary_Release(p3
);
639 IDirectXFileObject_Release(pChildObj
);
642 ok(hr
== DXFILE_OK
|| hr
== DXFILEERR_NOMOREOBJECTS
, "IDirectXFileData_GetNextObject: %x\n", hr
);
645 static void test_dump(void)
649 LPDIRECTXFILE lpDirectXFile
= NULL
;
650 LPDIRECTXFILEENUMOBJECT lpDirectXFileEnumObject
= NULL
;
651 LPDIRECTXFILEDATA lpDirectXFileData
= NULL
;
653 LPVOID pvData
= NULL
;
656 if (!pDirectXFileCreate
)
658 win_skip("DirectXFileCreate is not available\n");
662 /* Dump data only if there is an object and a template */
663 hFile
= CreateFileA("objects.txt", GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, NULL
);
664 if (hFile
== INVALID_HANDLE_VALUE
)
668 hFile
= CreateFileA("templates.txt", GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, NULL
);
669 if (hFile
== INVALID_HANDLE_VALUE
)
672 pvData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, 10000);
674 if (!ReadFile(hFile
, pvData
, 10000, &cbSize
, NULL
))
676 skip("Templates file is too big\n");
680 printf("Load templates file (%d bytes)\n", cbSize
);
682 hr
= pDirectXFileCreate(&lpDirectXFile
);
683 ok(hr
== DXFILE_OK
, "DirectXFileCreate: %x\n", hr
);
686 skip("Couldn't create DirectXFile interface\n");
690 hr
= IDirectXFile_RegisterTemplates(lpDirectXFile
, pvData
, cbSize
);
691 ok(hr
== DXFILE_OK
, "IDirectXFileImpl_RegisterTemplates: %x\n", hr
);
693 hr
= IDirectXFile_CreateEnumObject(lpDirectXFile
, (LPVOID
)"objects.txt", DXFILELOAD_FROMFILE
, &lpDirectXFileEnumObject
);
694 ok(hr
== DXFILE_OK
, "IDirectXFile_CreateEnumObject: %x\n", hr
);
696 while (SUCCEEDED(hr
= IDirectXFileEnumObject_GetNextDataObject(lpDirectXFileEnumObject
, &lpDirectXFileData
)))
700 process_data(lpDirectXFileData
, &level
);
701 IDirectXFileData_Release(lpDirectXFileData
);
703 ok(hr
== DXFILE_OK
|| hr
== DXFILEERR_NOMOREOBJECTS
, "IDirectXFileEnumObject_GetNextDataObject: %x\n", hr
);
705 ref
= IDirectXFile_Release(lpDirectXFileEnumObject
);
706 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
708 ref
= IDirectXFile_Release(lpDirectXFile
);
709 ok(ref
== 0, "Got refcount %d, expected 0\n", ref
);
714 HeapFree(GetProcessHeap(), 0, pvData
);
719 init_function_pointers();
722 test_CreateEnumObject();
724 test_compressed_files();
729 FreeLibrary(hd3dxof
);