ReactOS 0.4.17-dev-966-gf06eace
xfile.c
Go to the documentation of this file.
1/*
2 * Copyright 2012 Christian Costa
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19#include "wine/test.h"
20#include "d3dx9.h"
21#include "d3dx9xof.h"
22
23static const char templates_bad_file_type1[] =
24"xOf 0302txt 0064\n";
25
26static const char templates_bad_file_version[] =
27"xof 0102txt 0064\n";
28
29static const char templates_bad_file_type2[] =
30"xof 0302foo 0064\n";
31
32static const char templates_bad_file_float_size[] =
33"xof 0302txt 0050\n";
34
35static const char templates_parse_error[] =
36"xof 0302txt 0064"
37"foobar;\n";
38
39static const char templates[] =
40"xof 0302txt 0064"
41"template Header"
42"{"
43"<3D82AB43-62DA-11CF-AB39-0020AF71E433>"
44"WORD major;"
45"WORD minor;"
46"DWORD flags;"
47"}\n";
48
49static char objects[] =
50"xof 0302txt 0064\n"
51"Header Object\n"
52"{\n"
53"1; 2; 3;\n"
54"}\n";
55
56static char object_noname[] =
57"xof 0302txt 0064\n"
58"Header\n"
59"{\n"
60"1; 2; 3;\n"
61"}\n";
62
64"xof 0302txt 0064\n"
65"template MeshVertexColors\n"
66"{\n"
67"<1630B821-7842-11cf-8F52-0040333594A3>\n"
68"DWORD nVertexColors;\n"
69"array indexColor vertexColors[nVertexColors];\n"
70"}\n";
71
73"xof 0302txt 0064\n"
74"template MeshVertexColors\n"
75"{\n"
76"<1630B821-7842-11cf-8F52-0040333594A3>\n"
77"DWORD nVertexColors;\n"
78"array IndexColor vertexColors[nVertexColors];\n"
79"}\n";
80
81static void test_templates(void)
82{
83 ID3DXFile *d3dxfile;
85
87 ok(ret == E_POINTER, "D3DXCreateFile returned %#lx, expected %#lx\n", ret, E_POINTER);
88
89 ret = D3DXFileCreate(&d3dxfile);
90 ok(ret == S_OK, "D3DXCreateFile failed with %#lx\n", ret);
91
92 ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, templates_bad_file_type1, sizeof(templates_bad_file_type1) - 1);
93 ok(ret == D3DXFERR_BADFILETYPE, "RegisterTemplates returned %#lx, expected %#lx\n", ret, D3DXFERR_BADFILETYPE);
94
95 ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, templates_bad_file_version, sizeof(templates_bad_file_version) - 1);
96 ok(ret == D3DXFERR_BADFILEVERSION, "RegisterTemplates returned %#lx, expected %#lx\n", ret, D3DXFERR_BADFILEVERSION);
97
98 ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, templates_bad_file_type2, sizeof(templates_bad_file_type2) - 1);
99 ok(ret == D3DXFERR_BADFILETYPE, "RegisterTemplates returned %#lx, expected %#lx\n", ret, D3DXFERR_BADFILETYPE);
100
101 ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, templates_bad_file_float_size, sizeof(templates_bad_file_float_size) - 1);
102 ok(ret == D3DXFERR_BADFILEFLOATSIZE, "RegisterTemplates returned %#lx, expected %#lx\n", ret, D3DXFERR_BADFILEFLOATSIZE);
103
104 ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, templates_parse_error, sizeof(templates_parse_error) - 1);
105 ok(ret == D3DXFERR_PARSEERROR, "RegisterTemplates returned %#lx, expected %#lx\n", ret, D3DXFERR_PARSEERROR);
106
107 ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, templates, sizeof(templates) - 1);
108 ok(ret == S_OK, "RegisterTemplates failed with %#lx\n", ret);
109
110 d3dxfile->lpVtbl->Release(d3dxfile);
111}
112
113static void test_lock_unlock(void)
114{
115 ID3DXFile *d3dxfile;
117 ID3DXFileEnumObject *enum_object;
118 ID3DXFileData *data_object;
119 const void *data;
120 SIZE_T size;
121 HRESULT ret;
122
123 ret = D3DXFileCreate(&d3dxfile);
124 ok(ret == S_OK, "D3DXCreateFile failed with %#lx\n", ret);
125
126 ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, templates, sizeof(templates) - 1);
127 ok(ret == S_OK, "RegisterTemplates failed with %#lx\n", ret);
128
129 memory.lpMemory = objects;
130 memory.dSize = sizeof(objects) - 1;
131
132 ret = d3dxfile->lpVtbl->CreateEnumObject(d3dxfile, &memory, D3DXF_FILELOAD_FROMMEMORY, &enum_object);
133 ok(ret == S_OK, "CreateEnumObject failed with %#lx\n", ret);
134
135 ret = enum_object->lpVtbl->GetChild(enum_object, 0, &data_object);
136 ok(ret == S_OK, "GetChild failed with %#lx\n", ret);
137
138 ret = data_object->lpVtbl->Unlock(data_object);
139 ok(ret == S_OK, "Unlock failed with %#lx\n", ret);
140 ret = data_object->lpVtbl->Lock(data_object, &size, &data);
141 ok(ret == S_OK, "Lock failed with %#lx\n", ret);
142 ret = data_object->lpVtbl->Lock(data_object, &size, &data);
143 ok(ret == S_OK, "Lock failed with %#lx\n", ret);
144 ret = data_object->lpVtbl->Unlock(data_object);
145 ok(ret == S_OK, "Unlock failed with %#lx\n", ret);
146 ret = data_object->lpVtbl->Unlock(data_object);
147 ok(ret == S_OK, "Unlock failed with %#lx\n", ret);
148
149 data_object->lpVtbl->Release(data_object);
150 enum_object->lpVtbl->Release(enum_object);
151 d3dxfile->lpVtbl->Release(d3dxfile);
152}
153
154static void test_getname(void)
155{
156 ID3DXFile *d3dxfile;
158 ID3DXFileEnumObject *enum_object;
159 ID3DXFileData *data_object;
161 char name[100];
162 HRESULT ret;
163
164 ret = D3DXFileCreate(&d3dxfile);
165 ok(ret == S_OK, "D3DXCreateFile failed with %#lx\n", ret);
166
167 ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, templates, sizeof(templates) - 1);
168 ok(ret == S_OK, "RegisterTemplates failed with %#lx\n", ret);
169
170 /* Check object with name */
171 memory.lpMemory = objects;
172 memory.dSize = sizeof(objects) - 1;
173 ret = d3dxfile->lpVtbl->CreateEnumObject(d3dxfile, &memory, D3DXF_FILELOAD_FROMMEMORY, &enum_object);
174 ok(ret == S_OK, "CreateEnumObject failed with %#lx\n", ret);
175 ret = enum_object->lpVtbl->GetChild(enum_object, 0, &data_object);
176 ok(ret == S_OK, "GetChild failed with %#lx\n", ret);
177
178 ret = data_object->lpVtbl->GetName(data_object, NULL, NULL);
179 ok(ret == D3DXFERR_BADVALUE, "GetName returned %#lx, expected %#lx\n", ret, D3DXFERR_BADVALUE);
180 ret = data_object->lpVtbl->GetName(data_object, name, NULL);
181 ok(ret == D3DXFERR_BADVALUE, "GetName returned %#lx, expected %#lx\n", ret, D3DXFERR_BADVALUE);
182 ret = data_object->lpVtbl->GetName(data_object, NULL, &length);
183 ok(ret == S_OK, "GetName failed with %#lx\n", ret);
184 ok(length == 7, "Returned length should be 7 instead of %Id\n", length);
185 length = sizeof(name);
186 ret = data_object->lpVtbl->GetName(data_object, name, &length);
187 ok(ret == S_OK, "GetName failed with %#lx\n", ret);
188 ok(length == 7, "Returned length should be 7 instead of %Id\n", length);
189 ok(!strcmp(name, "Object"), "Returned string should be 'Object' instead of '%s'\n", name);
190 length = 3;
191 ret = data_object->lpVtbl->GetName(data_object, name, &length);
192 ok(ret== D3DXFERR_BADVALUE, "GetName returned %#lx, expected %#lx\n", ret, D3DXFERR_BADVALUE);
193
194 data_object->lpVtbl->Release(data_object);
195 enum_object->lpVtbl->Release(enum_object);
196
197 /* Check object without name */
198 memory.lpMemory = object_noname;
199 memory.dSize = sizeof(object_noname) - 1;
200 ret = d3dxfile->lpVtbl->CreateEnumObject(d3dxfile, &memory, D3DXF_FILELOAD_FROMMEMORY, &enum_object);
201 ok(ret == S_OK, "CreateEnumObject failed with %#lx\n", ret);
202 ret = enum_object->lpVtbl->GetChild(enum_object, 0, &data_object);
203 ok(ret == S_OK, "GetChild failed with %#lx\n", ret);
204
205 /* Contrary to d3dxof, d3dx9_36 returns an empty string with a null byte when no name is available.
206 * If the input size is 0, it returns a length of 1 without touching the buffer */
207 ret = data_object->lpVtbl->GetName(data_object, NULL, &length);
208 ok(ret == S_OK, "GetName failed with %#lx\n", ret);
209 ok(length == 1, "Returned length should be 1 instead of %Id\n", length);
210 length = 0;
211 name[0] = 0x7f;
212 ret = data_object->lpVtbl->GetName(data_object, name, &length);
213 ok(ret == S_OK, "GetName failed with %#lx\n", ret);
214 ok(length == 1, "Returned length should be 1 instead of %Id\n", length);
215 ok(name[0] == 0x7f, "First character is %#x instead of 0x7f\n", name[0]);
216 length = sizeof(name);
217 name[0] = 0x7f;
218 ret = data_object->lpVtbl->GetName(data_object, name, &length);
219 ok(ret == S_OK, "GetName failed with %#lx\n", ret);
220 ok(length == 1, "Returned length should be 1 instead of %Id\n", length);
221 ok(name[0] == 0, "First character is %#x instead of 0x00\n", name[0]);
222
223 data_object->lpVtbl->Release(data_object);
224 enum_object->lpVtbl->Release(enum_object);
225 d3dxfile->lpVtbl->Release(d3dxfile);
226}
227
228static void test_type_index_color(void)
229{
230 ID3DXFile *d3dxfile;
231 HRESULT ret;
232
233 ret = D3DXFileCreate(&d3dxfile);
234 ok(ret == S_OK, "D3DXCreateFile failed with %#lx\n", ret);
235
236 /* Test that 'indexColor' can be used (same as IndexedColor in standard templates) and is case sensitive */
237 ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, template_using_index_color_lower, sizeof(template_using_index_color_lower) - 1);
238 ok(ret == S_OK, "RegisterTemplates failed with %#lx\n", ret);
239 ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, template_using_index_color_upper, sizeof(template_using_index_color_upper) - 1);
240 ok(ret == D3DXFERR_PARSEERROR, "RegisterTemplates returned %#lx instead of %#lx\n", ret, D3DXFERR_PARSEERROR);
241
242 d3dxfile->lpVtbl->Release(d3dxfile);
243}
244
246{
249 test_getname();
251}
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
HRESULT WINAPI D3DXFileCreate(ID3DXFile **d3dxfile)
Definition: xfile.c:693
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3324
return ret
Definition: mutex.c:147
#define D3DXFERR_BADFILEVERSION
Definition: d3dx9xof.h:172
#define D3DXFERR_BADFILEFLOATSIZE
Definition: d3dx9xof.h:173
#define D3DXF_FILELOAD_FROMMEMORY
Definition: d3dx9xof.h:41
#define D3DXFERR_PARSEERROR
Definition: d3dx9xof.h:175
#define D3DXFERR_BADFILETYPE
Definition: d3dx9xof.h:171
#define D3DXFERR_BADVALUE
Definition: d3dx9xof.h:164
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
#define S_OK
Definition: intsafe.h:52
static char object_noname[]
Definition: xfile.c:56
static char objects[]
Definition: xfile.c:49
static void test_templates(void)
Definition: xfile.c:81
static char template_using_index_color_upper[]
Definition: xfile.c:72
static const char templates[]
Definition: xfile.c:39
static void test_getname(void)
Definition: xfile.c:154
static const char templates_bad_file_type2[]
Definition: xfile.c:29
static void test_lock_unlock(void)
Definition: xfile.c:113
static char template_using_index_color_lower[]
Definition: xfile.c:63
static const char templates_parse_error[]
Definition: xfile.c:35
static const char templates_bad_file_float_size[]
Definition: xfile.c:32
static void test_type_index_color(void)
Definition: xfile.c:228
static const char templates_bad_file_type1[]
Definition: xfile.c:23
static const char templates_bad_file_version[]
Definition: xfile.c:26
static char memory[1024 *256]
Definition: process.c:122
Definition: name.c:39
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define E_POINTER
Definition: winerror.h:3480