ReactOS 0.4.17-dev-966-gf06eace
xfile.c File Reference
#include "wine/test.h"
#include "d3dx9.h"
#include "d3dx9xof.h"
Include dependency graph for xfile.c:

Go to the source code of this file.

Functions

static void test_templates (void)
 
static void test_lock_unlock (void)
 
static void test_getname (void)
 
static void test_type_index_color (void)
 
 START_TEST (xfile)
 

Variables

static const char templates_bad_file_type1 []
 
static const char templates_bad_file_version []
 
static const char templates_bad_file_type2 []
 
static const char templates_bad_file_float_size []
 
static const char templates_parse_error []
 
static const char templates []
 
static char objects []
 
static char object_noname []
 
static char template_using_index_color_lower []
 
static char template_using_index_color_upper []
 

Function Documentation

◆ START_TEST()

START_TEST ( xfile  )

Definition at line 245 of file xfile.c.

246{
249 test_getname();
251}
static void test_templates(void)
Definition: xfile.c:81
static void test_getname(void)
Definition: xfile.c:154
static void test_lock_unlock(void)
Definition: xfile.c:113
static void test_type_index_color(void)
Definition: xfile.c:228

◆ test_getname()

static void test_getname ( void  )
static

Definition at line 154 of file xfile.c.

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}
#define ok(value,...)
Definition: atltest.h:57
#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 D3DXF_FILELOAD_FROMMEMORY
Definition: d3dx9xof.h:41
#define D3DXFERR_BADVALUE
Definition: d3dx9xof.h:164
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 const char templates[]
Definition: xfile.c:39
static char memory[1024 *256]
Definition: process.c:122
Definition: name.c:39
ULONG_PTR SIZE_T
Definition: typedefs.h:80

Referenced by START_TEST().

◆ test_lock_unlock()

static void test_lock_unlock ( void  )
static

Definition at line 113 of file xfile.c.

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}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919

Referenced by START_TEST().

◆ test_templates()

static void test_templates ( void  )
static

Definition at line 81 of file xfile.c.

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}
#define D3DXFERR_BADFILEVERSION
Definition: d3dx9xof.h:172
#define D3DXFERR_BADFILEFLOATSIZE
Definition: d3dx9xof.h:173
#define D3DXFERR_PARSEERROR
Definition: d3dx9xof.h:175
#define D3DXFERR_BADFILETYPE
Definition: d3dx9xof.h:171
static const char templates_bad_file_type2[]
Definition: xfile.c:29
static const char templates_parse_error[]
Definition: xfile.c:35
static const char templates_bad_file_float_size[]
Definition: xfile.c:32
static const char templates_bad_file_type1[]
Definition: xfile.c:23
static const char templates_bad_file_version[]
Definition: xfile.c:26
#define E_POINTER
Definition: winerror.h:3480

Referenced by START_TEST().

◆ test_type_index_color()

static void test_type_index_color ( void  )
static

Definition at line 228 of file xfile.c.

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}
static char template_using_index_color_upper[]
Definition: xfile.c:72
static char template_using_index_color_lower[]
Definition: xfile.c:63

Referenced by START_TEST().

Variable Documentation

◆ object_noname

char object_noname[]
static
Initial value:
=
"xof 0302txt 0064\n"
"Header\n"
"{\n"
"1; 2; 3;\n"
"}\n"

Definition at line 56 of file xfile.c.

Referenced by test_getname().

◆ objects

char objects[]
static
Initial value:
=
"xof 0302txt 0064\n"
"Header Object\n"
"{\n"
"1; 2; 3;\n"
"}\n"

Definition at line 49 of file xfile.c.

Referenced by test_getname(), and test_lock_unlock().

◆ template_using_index_color_lower

char template_using_index_color_lower[]
static
Initial value:
=
"xof 0302txt 0064\n"
"template MeshVertexColors\n"
"{\n"
"<1630B821-7842-11cf-8F52-0040333594A3>\n"
"DWORD nVertexColors;\n"
"array indexColor vertexColors[nVertexColors];\n"
"}\n"

Definition at line 63 of file xfile.c.

Referenced by test_type_index_color().

◆ template_using_index_color_upper

char template_using_index_color_upper[]
static
Initial value:
=
"xof 0302txt 0064\n"
"template MeshVertexColors\n"
"{\n"
"<1630B821-7842-11cf-8F52-0040333594A3>\n"
"DWORD nVertexColors;\n"
"array IndexColor vertexColors[nVertexColors];\n"
"}\n"

Definition at line 72 of file xfile.c.

Referenced by test_type_index_color().

◆ templates

const char templates[]
static
Initial value:
=
"xof 0302txt 0064"
"template Header"
"{"
"<3D82AB43-62DA-11CF-AB39-0020AF71E433>"
"WORD major;"
"WORD minor;"
"DWORD flags;"
"}\n"

Definition at line 39 of file xfile.c.

Referenced by test_getname(), test_lock_unlock(), and test_templates().

◆ templates_bad_file_float_size

const char templates_bad_file_float_size[]
static
Initial value:
=
"xof 0302txt 0050\n"

Definition at line 32 of file xfile.c.

Referenced by test_templates().

◆ templates_bad_file_type1

const char templates_bad_file_type1[]
static
Initial value:
=
"xOf 0302txt 0064\n"

Definition at line 23 of file xfile.c.

Referenced by test_templates().

◆ templates_bad_file_type2

const char templates_bad_file_type2[]
static
Initial value:
=
"xof 0302foo 0064\n"

Definition at line 29 of file xfile.c.

Referenced by test_templates().

◆ templates_bad_file_version

const char templates_bad_file_version[]
static
Initial value:
=
"xof 0102txt 0064\n"

Definition at line 26 of file xfile.c.

Referenced by test_templates().

◆ templates_parse_error

const char templates_parse_error[]
static
Initial value:
=
"xof 0302txt 0064"
"foobar;\n"

Definition at line 35 of file xfile.c.

Referenced by test_templates().