blob: 9244a90bc357089f0bf8ecefdd3b3a929a6f3625 [file] [log] [blame]
Daniel Veillard36e5cd52004-11-02 14:52:23 +00001#!/usr/bin/python -u
2#
3# generate a tester program for the API
4#
5import sys
6import string
7try:
8 import libxml2
9except:
10 print "libxml2 python bindings not available, skipping testapi.c generation"
11 sys.exit(0)
12
13#
14# Modules we don't want skip in API test
15#
16skipped_modules = [ "SAX", "SAX2", "xlink", "threads", "globals",
17 "xpathInternals", "xmlunicode", "parserInternals", "xmlmemory",
Daniel Veillardb1b3a3e2004-11-03 23:25:47 +000018 "xmlversion", "debugXML", "xmlexports", "DOCBparser",
Daniel Veillardd005b9e2004-11-03 17:07:05 +000019
20 # temporary
Daniel Veillard3d97e662004-11-04 10:49:00 +000021 "xmlautomata", "xmlregexp", "c14n",
Daniel Veillardd005b9e2004-11-03 17:07:05 +000022
23]
Daniel Veillard36e5cd52004-11-02 14:52:23 +000024
25#
26# Some function really need to be skipped for the tests.
27#
Daniel Veillarddd6d3002004-11-03 14:20:29 +000028skipped_functions = [
29# block on I/O
30"xmlFdRead", "xmlReadFd", "xmlCtxtReadFd",
31"htmlFdRead", "htmlReadFd", "htmlCtxtReadFd",
Daniel Veillard1ba06bb2004-11-04 12:32:18 +000032"xmlReaderNewFd", "xmlReaderForFd",
Daniel Veillardb1b3a3e2004-11-03 23:25:47 +000033"xmlIORead", "xmlReadIO", "xmlCtxtReadIO",
34"htmlIORead", "htmlReadIO", "htmlCtxtReadIO",
35"xmlReaderNewIO",
Daniel Veillarddd6d3002004-11-03 14:20:29 +000036# library state cleanup, generate false leak informations and other
37# troubles, heavillyb tested otherwise.
38"xmlCleanupParser", "xmlRelaxNGCleanupTypes",
39# hard to avoid leaks in the tests
Daniel Veillardb1b3a3e2004-11-03 23:25:47 +000040"xmlStrcat", "xmlStrncat", "xmlCatalogAddLocal",
Daniel Veillarddd6d3002004-11-03 14:20:29 +000041# unimplemented
42"xmlTextReaderReadInnerXml", "xmlTextReaderReadOuterXml",
Daniel Veillardd005b9e2004-11-03 17:07:05 +000043"xmlTextReaderReadString",
44# destructor
Daniel Veillard3d97e662004-11-04 10:49:00 +000045"xmlListDelete", "xmlOutputBufferClose",
Daniel Veillardd005b9e2004-11-03 17:07:05 +000046# deprecated
47"xmlCatalogGetPublic", "xmlCatalogGetSystem", "xmlEncodeEntities",
Daniel Veillardb1b3a3e2004-11-03 23:25:47 +000048# allocators
49"xmlMemFree",
Daniel Veillarddd6d3002004-11-03 14:20:29 +000050]
Daniel Veillard36e5cd52004-11-02 14:52:23 +000051
52#
53# Those functions have side effect on the global state
54# and hence generate errors on memory allocation tests
55#
56skipped_memcheck = [ "xmlLoadCatalog", "xmlAddEncodingAlias",
57 "xmlSchemaInitTypes", "xmlNanoFTPProxy", "xmlNanoFTPScanProxy",
58 "xmlNanoHTTPScanProxy", "xmlResetLastError", "xmlCatalogConvert",
59 "xmlCatalogRemove", "xmlLoadCatalogs", "xmlCleanupCharEncodingHandlers",
Daniel Veillarda03e3652004-11-02 18:45:30 +000060 "xmlInitCharEncodingHandlers", "xmlCatalogCleanup",
61 "htmlParseFile" # loads the catalogs
62]
63
64#
65# Extra code needed for some test cases
66#
67extra_post_call = {
68 "xmlAddChild":
69 "if (ret_val == NULL) { xmlFreeNode(cur) ; cur = NULL ; }",
70 "xmlAddChildList":
71 "if (ret_val == NULL) { xmlFreeNodeList(cur) ; cur = NULL ; }",
72 "xmlAddSibling":
73 "if (ret_val == NULL) { xmlFreeNode(elem) ; elem = NULL ; }",
74 "xmlAddNextSibling":
75 "if (ret_val == NULL) { xmlFreeNode(elem) ; elem = NULL ; }",
76 "xmlAddPrevSibling":
77 "if (ret_val == NULL) { xmlFreeNode(elem) ; elem = NULL ; }",
78 "xmlDocSetRootElement":
79 "if (doc == NULL) { xmlFreeNode(root) ; root = NULL ; }",
80 "xmlReplaceNode":
81 """if ((old == NULL) || (old->parent == NULL)) {
82 xmlFreeNode(cur) ; cur = NULL ; }""",
83 "xmlTextMerge":
84 """if ((first != NULL) && (first->type != XML_TEXT_NODE)) {
85 xmlFreeNode(second) ; second = NULL ; }""",
Daniel Veillard8a32fe42004-11-02 22:10:16 +000086 "xmlBuildQName":
87 """if ((ret_val != NULL) && (ret_val != ncname) &&
88 (ret_val != prefix) && (ret_val != memory))
89 xmlFree(ret_val);
90 ret_val = NULL;""",
Daniel Veillard1ba06bb2004-11-04 12:32:18 +000091 "xmlDictReference": "xmlDictFree(dict);",
Daniel Veillard3d97e662004-11-04 10:49:00 +000092 # Functions which deallocates one of their parameters
93 "xmlXPathConvertBoolean": """val = NULL;""",
94 "xmlXPathConvertNumber": """val = NULL;""",
95 "xmlXPathConvertString": """val = NULL;""",
96 "xmlSaveFileTo": """buf = NULL;""",
97 "xmlSaveFormatFileTo": """buf = NULL;"""
Daniel Veillarda03e3652004-11-02 18:45:30 +000098}
Daniel Veillard36e5cd52004-11-02 14:52:23 +000099
100modules = []
101
102def is_skipped_module(name):
103 for mod in skipped_modules:
104 if mod == name:
105 return 1
106 return 0
107
108def is_skipped_function(name):
109 for fun in skipped_functions:
110 if fun == name:
111 return 1
112 # Do not test destructors
113 if string.find(name, 'Free') != -1:
114 return 1
115 return 0
116
117def is_skipped_memcheck(name):
118 for fun in skipped_memcheck:
119 if fun == name:
120 return 1
121 return 0
122
123missing_types = {}
124def add_missing_type(name, func):
125 try:
126 list = missing_types[name]
127 list.append(func)
128 except:
129 missing_types[name] = [func]
130
131#
132# Open the input API description and the C test program result
133#
134doc = libxml2.readFile('doc/libxml2-api.xml', None, 0)
135if doc == None:
136 print "Failed to load doc/libxml2-api.xml"
137 sys.exit(1)
138test = open('testapi.c', 'w')
139ctxt = doc.xpathNewContext()
140headers = ctxt.xpathEval("/api/files/file")
141
142#
143# Generate the test header
144#
145test.write("""/*
146 * testapi.c: libxml2 API tester program.
147 *
148 * Automatically generated by gentest.py from libxml2-api.xml
149 *
150 * See Copyright for the status of this software.
151 *
152 * daniel@veillard.com
153 */
154
155#include <stdio.h>
156#include <libxml/xmlerror.h>
Daniel Veillard3d97e662004-11-04 10:49:00 +0000157#include <libxml/relaxng.h>
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000158
159static int testlibxml2(void);
160
161static int generic_errors = 0;
162static int call_tests = 0;
Daniel Veillard3d97e662004-11-04 10:49:00 +0000163static int function_tests = 0;
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000164
Daniel Veillard348636d2004-11-02 22:34:52 +0000165static xmlChar chartab[1024] = " chartab\\n";
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000166static int inttab[1024];
167static unsigned long longtab[1024];
Daniel Veillard8a32fe42004-11-02 22:10:16 +0000168
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000169static void
170structured_errors(void *userData ATTRIBUTE_UNUSED,
171 xmlErrorPtr error ATTRIBUTE_UNUSED) {
172 generic_errors++;
173}
174
175int main(void) {
176 int ret;
177 int blocks, mem;
178
Daniel Veillarda03e3652004-11-02 18:45:30 +0000179 xmlInitParser();
Daniel Veillard3d97e662004-11-04 10:49:00 +0000180#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillarddd6d3002004-11-03 14:20:29 +0000181 xmlRelaxNGInitTypes();
Daniel Veillard3d97e662004-11-04 10:49:00 +0000182#endif
Daniel Veillarda03e3652004-11-02 18:45:30 +0000183
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000184 LIBXML_TEST_VERSION
185
186 xmlSetStructuredErrorFunc(NULL, structured_errors);
187
188 ret = testlibxml2();
189
190 xmlCleanupParser();
191 blocks = xmlMemBlocks();
192 mem = xmlMemUsed();
193 if ((blocks != 0) || (mem != 0)) {
194 printf("testapi leaked %d bytes in %d blocks\\n", mem, blocks);
195 }
196 xmlMemoryDump();
197
198 return (ret != 0);
199}
200
201""");
202
203#
204# Load the interfaces
205#
206for file in headers:
207 name = file.xpathEval('string(@name)')
208 if (name == None) or (name == ''):
209 continue
210
211 #
Daniel Veillardb1b3a3e2004-11-03 23:25:47 +0000212 # Some module may be skipped because they don't really consists
213 # of user callable APIs
214 #
215 if is_skipped_module(name):
216 continue
217
218 #
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000219 # do not test deprecated APIs
220 #
221 desc = file.xpathEval('string(description)')
222 if string.find(desc, 'DEPRECATED') != -1:
223 print "Skipping deprecated interface %s" % name
224 continue;
225
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000226 test.write("#include <libxml/%s.h>\n" % name)
227 modules.append(name)
228
229#
230# Generate the callers signatures
231#
232for module in modules:
233 test.write("static int test_%s(void);\n" % module);
234
235#
236# Provide the type generators and destructors for the parameters
237#
238
Daniel Veillarda03e3652004-11-02 18:45:30 +0000239def type_convert(str, name, info, module, function, pos):
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000240 res = string.replace(str, " *", "_ptr")
241 res = string.replace(res, " ", "_")
Daniel Veillarda03e3652004-11-02 18:45:30 +0000242 res = string.replace(res, "htmlNode", "xmlNode")
243 res = string.replace(res, "htmlDoc", "xmlDoc")
244 res = string.replace(res, "htmlParser", "xmlParser")
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000245 if res == 'const_char_ptr':
246 if string.find(name, "file") != -1 or \
247 string.find(name, "uri") != -1 or \
248 string.find(name, "URI") != -1 or \
249 string.find(info, "filename") != -1 or \
250 string.find(info, "URI") != -1 or \
251 string.find(info, "URL") != -1:
252 if string.find(function, "Save") != -1:
253 return('fileoutput')
254 return('filepath')
255 if res == 'void_ptr':
256 if module == 'nanoftp' and name == 'ctx':
257 return('xmlNanoFTPCtxtPtr')
Daniel Veillardb1b3a3e2004-11-03 23:25:47 +0000258 if function == 'xmlNanoFTPNewCtxt':
259 return('xmlNanoFTPCtxtPtr')
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000260 if module == 'nanohttp' and name == 'ctx':
261 return('xmlNanoHTTPCtxtPtr')
Daniel Veillardb1b3a3e2004-11-03 23:25:47 +0000262 if function == 'xmlIOHTTPOpenW':
263 return('xmlNanoHTTPCtxtPtr')
Daniel Veillard8a32fe42004-11-02 22:10:16 +0000264 if string.find(name, "data") != -1:
265 return('userdata');
Daniel Veillardd005b9e2004-11-03 17:07:05 +0000266 if string.find(name, "user") != -1:
267 return('userdata');
Daniel Veillard3d97e662004-11-04 10:49:00 +0000268 if res == 'xmlDoc_ptr':
269 res = 'xmlDocPtr';
270 if res == 'xmlNode_ptr':
271 res = 'xmlNodePtr';
272 if res == 'xmlDict_ptr':
273 res = 'xmlDictPtr';
Daniel Veillarda03e3652004-11-02 18:45:30 +0000274 if res == 'xmlNodePtr' and pos != 0:
275 if (function == 'xmlAddChild' and pos == 2) or \
276 (function == 'xmlAddChildList' and pos == 2) or \
277 (function == 'xmlAddNextSibling' and pos == 2) or \
278 (function == 'xmlAddSibling' and pos == 2) or \
279 (function == 'xmlDocSetRootElement' and pos == 2) or \
280 (function == 'xmlReplaceNode' and pos == 2) or \
281 (function == 'xmlTextMerge') or \
282 (function == 'xmlAddPrevSibling' and pos == 2):
283 return('xmlNodePtr_in');
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000284
285 return res
286
287known_param_types = [ "int", "const_char_ptr", "const_xmlChar_ptr",
Daniel Veillarde43cc572004-11-03 11:50:29 +0000288 "xmlParserCtxtPtr", "xmlDocPtr", "filepath", "fileoutput",
289 "xmlNodePtr", "xmlNodePtr_in", "userdata", "xmlChar_ptr",
Daniel Veillardd005b9e2004-11-03 17:07:05 +0000290 "xmlTextWriterPtr", "xmlTextReaderPtr", "xmlBufferPtr",
Daniel Veillardc0be74b2004-11-03 19:16:55 +0000291 "xmlListPtr", "xmlXPathObjectPtr", "xmlHashTablePtr", "xmlValidCtxtPtr",
Daniel Veillard3d97e662004-11-04 10:49:00 +0000292 "void_ptr", "xmlOutputBufferPtr", "xmlCharEncoding",
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000293 "unsigned_int", "long", "unsigned_long", "const_void_ptr",
294 "unsigned_long_ptr", "int_ptr", "FILE_ptr", "xmlDictPtr",
Daniel Veillardd005b9e2004-11-03 17:07:05 +0000295]
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000296
297def is_known_param_type(name):
298 for type in known_param_types:
299 if type == name:
300 return 1
301 return 0
302
303test.write("""
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000304#define gen_nb_void_ptr 2
Daniel Veillardb1b3a3e2004-11-03 23:25:47 +0000305
Daniel Veillard3d97e662004-11-04 10:49:00 +0000306static void *gen_void_ptr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
Daniel Veillardb1b3a3e2004-11-03 23:25:47 +0000307 return(NULL);
308}
Daniel Veillard3d97e662004-11-04 10:49:00 +0000309static void des_void_ptr(int no ATTRIBUTE_UNUSED, void *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
Daniel Veillardb1b3a3e2004-11-03 23:25:47 +0000310}
311
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000312#define gen_nb_const_void_ptr 2
313
314static const void *gen_const_void_ptr(int no, int nr ATTRIBUTE_UNUSED) {
315 if (no == 0) return((const void *) "immutable string");
316 return(NULL);
317}
318static void des_const_void_ptr(int no ATTRIBUTE_UNUSED, const void *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
319}
320
Daniel Veillard8a32fe42004-11-02 22:10:16 +0000321#define gen_nb_userdata 3
322
Daniel Veillard3d97e662004-11-04 10:49:00 +0000323static void *gen_userdata(int no, int nr ATTRIBUTE_UNUSED) {
Daniel Veillard8a32fe42004-11-02 22:10:16 +0000324 if (no == 0) return((void *) &call_tests);
325 if (no == 1) return((void *) -1);
326 return(NULL);
327}
Daniel Veillard3d97e662004-11-04 10:49:00 +0000328static void des_userdata(int no ATTRIBUTE_UNUSED, void *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
Daniel Veillard8a32fe42004-11-02 22:10:16 +0000329}
330
331
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000332#define gen_nb_int 4
333
Daniel Veillard3d97e662004-11-04 10:49:00 +0000334static int gen_int(int no, int nr ATTRIBUTE_UNUSED) {
335 if (no == 0) return(0);
336 if (no == 1) return(1);
337 if (no == 1) return(-1);
338 if (no == 2) return(122);
339 return(-1);
340}
341
342static void des_int(int no ATTRIBUTE_UNUSED, int val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
343}
344
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000345#define gen_nb_long 4
346
347static long gen_long(int no, int nr ATTRIBUTE_UNUSED) {
348 if (no == 0) return(0);
349 if (no == 1) return(1);
350 if (no == 1) return(-1);
351 if (no == 2) return(122);
352 return(-1);
353}
354
355static void des_long(int no ATTRIBUTE_UNUSED, long val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
356}
357
Daniel Veillard3d97e662004-11-04 10:49:00 +0000358#define gen_nb_unsigned_int 3
359
360static unsigned int gen_unsigned_int(int no, int nr ATTRIBUTE_UNUSED) {
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000361 if (no == 0) return(0);
362 if (no == 1) return(1);
363 if (no == 2) return(122);
364 return(-1);
365}
366
Daniel Veillard3d97e662004-11-04 10:49:00 +0000367static void des_unsigned_int(int no ATTRIBUTE_UNUSED, unsigned int val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000368}
369
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000370#define gen_nb_unsigned_long 3
371
372static unsigned long gen_unsigned_long(int no, int nr ATTRIBUTE_UNUSED) {
373 if (no == 0) return(0);
374 if (no == 1) return(1);
375 if (no == 2) return(122);
376 return(-1);
377}
378
379static void des_unsigned_long(int no ATTRIBUTE_UNUSED, unsigned long val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
380}
381
382#define gen_nb_unsigned_long_ptr 2
383
384static unsigned long *gen_unsigned_long_ptr(int no, int nr) {
385 if (no == 0) return(&longtab[nr]);
386 return(NULL);
387}
388
389static void des_unsigned_long_ptr(int no ATTRIBUTE_UNUSED, unsigned long *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
390}
391
392#define gen_nb_int_ptr 2
393
394static int *gen_int_ptr(int no, int nr) {
395 if (no == 0) return(&inttab[nr]);
396 return(NULL);
397}
398
399static void des_int_ptr(int no ATTRIBUTE_UNUSED, int *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
400}
401
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000402#define gen_nb_const_char_ptr 4
403
Daniel Veillard3d97e662004-11-04 10:49:00 +0000404static const char *gen_const_char_ptr(int no, int nr ATTRIBUTE_UNUSED) {
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000405 if (no == 0) return("foo");
406 if (no == 1) return("<foo/>");
407 if (no == 2) return("test/ent2");
408 return(NULL);
409}
Daniel Veillard3d97e662004-11-04 10:49:00 +0000410static void des_const_char_ptr(int no ATTRIBUTE_UNUSED, const char *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000411}
412
Daniel Veillard8a32fe42004-11-02 22:10:16 +0000413#define gen_nb_xmlChar_ptr 2
414
Daniel Veillard3d97e662004-11-04 10:49:00 +0000415static xmlChar *gen_xmlChar_ptr(int no, int nr ATTRIBUTE_UNUSED) {
Daniel Veillardd005b9e2004-11-03 17:07:05 +0000416 if (no == 0) return(&chartab[0]);
Daniel Veillard8a32fe42004-11-02 22:10:16 +0000417 return(NULL);
418}
Daniel Veillard3d97e662004-11-04 10:49:00 +0000419static void des_xmlChar_ptr(int no ATTRIBUTE_UNUSED, xmlChar *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
Daniel Veillard8a32fe42004-11-02 22:10:16 +0000420}
421
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000422#define gen_nb_FILE_ptr 2
423
424static FILE *gen_FILE_ptr(int no, int nr ATTRIBUTE_UNUSED) {
425 if (no == 0) return(fopen("test.out", "a+"));
426 return(NULL);
427}
428static void des_FILE_ptr(int no ATTRIBUTE_UNUSED, FILE *val, int nr ATTRIBUTE_UNUSED) {
429 if (val != NULL) fclose(val);
430}
431
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000432#define gen_nb_const_xmlChar_ptr 5
433
Daniel Veillard3d97e662004-11-04 10:49:00 +0000434static const xmlChar *gen_const_xmlChar_ptr(int no, int nr ATTRIBUTE_UNUSED) {
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000435 if (no == 0) return((const xmlChar *) "foo");
436 if (no == 1) return((const xmlChar *) "<foo/>");
437 if (no == 2) return((const xmlChar *) "nøne");
438 if (no == 3) return((const xmlChar *) " 2ab ");
439 return(NULL);
440}
Daniel Veillard3d97e662004-11-04 10:49:00 +0000441static void des_const_xmlChar_ptr(int no ATTRIBUTE_UNUSED, const xmlChar *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000442}
443
444#define gen_nb_filepath 8
445
Daniel Veillard3d97e662004-11-04 10:49:00 +0000446static const char *gen_filepath(int no, int nr ATTRIBUTE_UNUSED) {
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000447 if (no == 0) return("missing.xml");
448 if (no == 1) return("<foo/>");
449 if (no == 2) return("test/ent2");
450 if (no == 3) return("test/valid/REC-xml-19980210.xml");
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000451 if (no == 4) return("test/valid/dtds/xhtml1-strict.dtd");
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000452 if (no == 5) return("http://missing.example.org/");
453 if (no == 6) return("http://missing. example.org/");
454 return(NULL);
455}
Daniel Veillard3d97e662004-11-04 10:49:00 +0000456static void des_filepath(int no ATTRIBUTE_UNUSED, const char *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000457}
458
459#define gen_nb_fileoutput 6
460
Daniel Veillard3d97e662004-11-04 10:49:00 +0000461static const char *gen_fileoutput(int no, int nr ATTRIBUTE_UNUSED) {
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000462 if (no == 0) return("/missing.xml");
463 if (no == 1) return("<foo/>");
464 if (no == 2) return("ftp://missing.example.org/foo");
465 if (no == 3) return("http://missing.example.org/");
466 if (no == 4) return("http://missing. example.org/");
467 return(NULL);
468}
Daniel Veillard3d97e662004-11-04 10:49:00 +0000469static void des_fileoutput(int no ATTRIBUTE_UNUSED, const char *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000470}
471
472#define gen_nb_xmlParserCtxtPtr 2
Daniel Veillard3d97e662004-11-04 10:49:00 +0000473static xmlParserCtxtPtr gen_xmlParserCtxtPtr(int no, int nr ATTRIBUTE_UNUSED) {
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000474 if (no == 0) return(xmlNewParserCtxt());
475 return(NULL);
476}
Daniel Veillard3d97e662004-11-04 10:49:00 +0000477static void des_xmlParserCtxtPtr(int no ATTRIBUTE_UNUSED, xmlParserCtxtPtr val, int nr ATTRIBUTE_UNUSED) {
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000478 if (val != NULL)
479 xmlFreeParserCtxt(val);
480}
481
Daniel Veillardc0be74b2004-11-03 19:16:55 +0000482#define gen_nb_xmlValidCtxtPtr 2
Daniel Veillard3d97e662004-11-04 10:49:00 +0000483static xmlValidCtxtPtr gen_xmlValidCtxtPtr(int no, int nr ATTRIBUTE_UNUSED) {
Daniel Veillardc0be74b2004-11-03 19:16:55 +0000484 if (no == 0) return(xmlNewValidCtxt());
485 return(NULL);
486}
Daniel Veillard3d97e662004-11-04 10:49:00 +0000487static void des_xmlValidCtxtPtr(int no ATTRIBUTE_UNUSED, xmlValidCtxtPtr val, int nr ATTRIBUTE_UNUSED) {
Daniel Veillardc0be74b2004-11-03 19:16:55 +0000488 if (val != NULL)
489 xmlFreeValidCtxt(val);
490}
491
Daniel Veillarda03e3652004-11-02 18:45:30 +0000492#define gen_nb_xmlDocPtr 3
Daniel Veillard3d97e662004-11-04 10:49:00 +0000493static xmlDocPtr gen_xmlDocPtr(int no, int nr ATTRIBUTE_UNUSED) {
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000494 if (no == 0) return(xmlNewDoc(BAD_CAST "1.0"));
Daniel Veillarda03e3652004-11-02 18:45:30 +0000495 if (no == 1) return(xmlReadMemory("<foo/>", 6, "test", NULL, 0));
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000496 return(NULL);
497}
Daniel Veillard3d97e662004-11-04 10:49:00 +0000498static void des_xmlDocPtr(int no ATTRIBUTE_UNUSED, xmlDocPtr val, int nr ATTRIBUTE_UNUSED) {
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000499 if (val != NULL)
500 xmlFreeDoc(val);
501}
502
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000503#define gen_nb_xmlDictPtr 2
504static xmlDictPtr gen_xmlDictPtr(int no, int nr ATTRIBUTE_UNUSED) {
505 if (no == 0) return(xmlDictCreate());
506 return(NULL);
507}
508static void des_xmlDictPtr(int no ATTRIBUTE_UNUSED, xmlDictPtr val, int nr ATTRIBUTE_UNUSED) {
509 if (val != NULL)
510 xmlDictFree(val);
511}
512
Daniel Veillarda03e3652004-11-02 18:45:30 +0000513#define gen_nb_xmlNodePtr 2
Daniel Veillard3d97e662004-11-04 10:49:00 +0000514static xmlNodePtr gen_xmlNodePtr(int no, int nr ATTRIBUTE_UNUSED) {
Daniel Veillarda03e3652004-11-02 18:45:30 +0000515 if (no == 0) return(xmlNewPI(BAD_CAST "test", NULL));
516 return(NULL);
517}
Daniel Veillard3d97e662004-11-04 10:49:00 +0000518static void des_xmlNodePtr(int no ATTRIBUTE_UNUSED, xmlNodePtr val, int nr ATTRIBUTE_UNUSED) {
Daniel Veillarda03e3652004-11-02 18:45:30 +0000519 if (val != NULL) {
520 xmlUnlinkNode(val);
521 xmlFreeNode(val);
522 }
523}
524
525#define gen_nb_xmlNodePtr_in 3
Daniel Veillard3d97e662004-11-04 10:49:00 +0000526static xmlNodePtr gen_xmlNodePtr_in(int no, int nr ATTRIBUTE_UNUSED) {
Daniel Veillarda03e3652004-11-02 18:45:30 +0000527 if (no == 0) return(xmlNewPI(BAD_CAST "test", NULL));
528 if (no == 0) return(xmlNewText(BAD_CAST "text"));
529 return(NULL);
530}
Daniel Veillard3d97e662004-11-04 10:49:00 +0000531static void des_xmlNodePtr_in(int no ATTRIBUTE_UNUSED, xmlNodePtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
Daniel Veillarda03e3652004-11-02 18:45:30 +0000532}
533
Daniel Veillarde43cc572004-11-03 11:50:29 +0000534#define gen_nb_xmlTextWriterPtr 2
Daniel Veillard3d97e662004-11-04 10:49:00 +0000535static xmlTextWriterPtr gen_xmlTextWriterPtr(int no, int nr ATTRIBUTE_UNUSED) {
Daniel Veillarde43cc572004-11-03 11:50:29 +0000536 if (no == 0) return(xmlNewTextWriterFilename("test.out", 0));
537 return(NULL);
538}
Daniel Veillard3d97e662004-11-04 10:49:00 +0000539static void des_xmlTextWriterPtr(int no ATTRIBUTE_UNUSED, xmlTextWriterPtr val, int nr ATTRIBUTE_UNUSED) {
Daniel Veillarde43cc572004-11-03 11:50:29 +0000540 if (val != NULL) xmlFreeTextWriter(val);
541}
542
Daniel Veillarddd6d3002004-11-03 14:20:29 +0000543#define gen_nb_xmlTextReaderPtr 4
Daniel Veillard3d97e662004-11-04 10:49:00 +0000544static xmlTextReaderPtr gen_xmlTextReaderPtr(int no, int nr ATTRIBUTE_UNUSED) {
Daniel Veillarddd6d3002004-11-03 14:20:29 +0000545 if (no == 0) return(xmlNewTextReaderFilename("test/ent2"));
546 if (no == 1) return(xmlNewTextReaderFilename("test/valid/REC-xml-19980210.xml"));
547 if (no == 2) return(xmlNewTextReaderFilename("test/valid/dtds/xhtml1-strict.dtd"));
548 return(NULL);
549}
Daniel Veillard3d97e662004-11-04 10:49:00 +0000550static void des_xmlTextReaderPtr(int no ATTRIBUTE_UNUSED, xmlTextReaderPtr val, int nr ATTRIBUTE_UNUSED) {
Daniel Veillarddd6d3002004-11-03 14:20:29 +0000551 if (val != NULL) xmlFreeTextReader(val);
552}
553
Daniel Veillardd005b9e2004-11-03 17:07:05 +0000554#define gen_nb_xmlBufferPtr 2
Daniel Veillard3d97e662004-11-04 10:49:00 +0000555static xmlBufferPtr gen_xmlBufferPtr(int no, int nr ATTRIBUTE_UNUSED) {
Daniel Veillardd005b9e2004-11-03 17:07:05 +0000556 if (no == 0) return(xmlBufferCreate());
557 return(NULL);
558}
Daniel Veillard3d97e662004-11-04 10:49:00 +0000559static void des_xmlBufferPtr(int no ATTRIBUTE_UNUSED, xmlBufferPtr val, int nr ATTRIBUTE_UNUSED) {
Daniel Veillardd005b9e2004-11-03 17:07:05 +0000560 if (val != NULL) {
561 xmlBufferFree(val);
562 }
563}
564
565#define gen_nb_xmlListPtr 2
Daniel Veillard3d97e662004-11-04 10:49:00 +0000566static xmlListPtr gen_xmlListPtr(int no, int nr ATTRIBUTE_UNUSED) {
Daniel Veillardd005b9e2004-11-03 17:07:05 +0000567 if (no == 0) return(xmlListCreate(NULL, NULL));
568 return(NULL);
569}
Daniel Veillard3d97e662004-11-04 10:49:00 +0000570static void des_xmlListPtr(int no ATTRIBUTE_UNUSED, xmlListPtr val, int nr ATTRIBUTE_UNUSED) {
Daniel Veillardd005b9e2004-11-03 17:07:05 +0000571 if (val != NULL) {
572 xmlListDelete(val);
573 }
574}
575
576#define gen_nb_xmlHashTablePtr 2
Daniel Veillard3d97e662004-11-04 10:49:00 +0000577static xmlHashTablePtr gen_xmlHashTablePtr(int no, int nr ATTRIBUTE_UNUSED) {
Daniel Veillardd005b9e2004-11-03 17:07:05 +0000578 if (no == 0) return(xmlHashCreate(10));
579 return(NULL);
580}
Daniel Veillard3d97e662004-11-04 10:49:00 +0000581static void des_xmlHashTablePtr(int no ATTRIBUTE_UNUSED, xmlHashTablePtr val, int nr ATTRIBUTE_UNUSED) {
Daniel Veillardd005b9e2004-11-03 17:07:05 +0000582 if (val != NULL) {
583 xmlHashFree(val, NULL);
584 }
585}
586
587#include <libxml/xpathInternals.h>
588
589#define gen_nb_xmlXPathObjectPtr 5
Daniel Veillard3d97e662004-11-04 10:49:00 +0000590static xmlXPathObjectPtr gen_xmlXPathObjectPtr(int no, int nr ATTRIBUTE_UNUSED) {
Daniel Veillardd005b9e2004-11-03 17:07:05 +0000591 if (no == 0) return(xmlXPathNewString(BAD_CAST "string object"));
592 if (no == 1) return(xmlXPathNewFloat(1.1));
593 if (no == 2) return(xmlXPathNewBoolean(1));
594 if (no == 3) return(xmlXPathNewNodeSet(NULL));
595 return(NULL);
596}
Daniel Veillard3d97e662004-11-04 10:49:00 +0000597static void des_xmlXPathObjectPtr(int no ATTRIBUTE_UNUSED, xmlXPathObjectPtr val, int nr ATTRIBUTE_UNUSED) {
Daniel Veillardd005b9e2004-11-03 17:07:05 +0000598 if (val != NULL) {
599 xmlXPathFreeObject(val);
600 }
601}
602
Daniel Veillard3d97e662004-11-04 10:49:00 +0000603#define gen_nb_xmlOutputBufferPtr 2
604static xmlOutputBufferPtr gen_xmlOutputBufferPtr(int no, int nr ATTRIBUTE_UNUSED) {
605 if (no == 0) return(xmlOutputBufferCreateFilename("test.out", NULL, 0));
606 return(NULL);
607}
608static void des_xmlOutputBufferPtr(int no ATTRIBUTE_UNUSED, xmlOutputBufferPtr val, int nr ATTRIBUTE_UNUSED) {
609 if (val != NULL) {
610 xmlOutputBufferClose(val);
611 }
612}
613
614#define gen_nb_xmlCharEncoding 4
615static xmlCharEncoding gen_xmlCharEncoding(int no, int nr ATTRIBUTE_UNUSED) {
616 if (no == 0) return(XML_CHAR_ENCODING_UTF8);
617 if (no == 1) return(XML_CHAR_ENCODING_NONE);
618 if (no == 0) return(XML_CHAR_ENCODING_8859_1);
619 return(XML_CHAR_ENCODING_ERROR);
620}
621static void des_xmlCharEncoding(int no ATTRIBUTE_UNUSED, xmlCharEncoding val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
622}
623
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000624""");
625
626#
627# Provide the type destructors for the return values
628#
629
Daniel Veillard8a32fe42004-11-02 22:10:16 +0000630known_return_types = [ "int", "const_char_ptr", "xmlDocPtr", "xmlNodePtr",
Daniel Veillard3d97e662004-11-04 10:49:00 +0000631 "xmlChar_ptr", "const_xmlChar_ptr", "void_ptr",
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000632 "xmlXPathObjectPtr", "xmlCharEncoding", "long",
633 "const_void_ptr", "double", "xmlTextReaderPtr",
634 "xmlDictPtr",
635]
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000636
637def is_known_return_type(name):
638 for type in known_return_types:
639 if type == name:
640 return 1
641 return 0
642
643test.write("""
644static void desret_int(int val ATTRIBUTE_UNUSED) {
645}
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000646static void desret_long(long val ATTRIBUTE_UNUSED) {
647}
648static void desret_double(double val ATTRIBUTE_UNUSED) {
649}
Daniel Veillard3d97e662004-11-04 10:49:00 +0000650static void desret_xmlCharEncoding(xmlCharEncoding val ATTRIBUTE_UNUSED) {
651}
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000652static void desret_const_void_ptr(void *val ATTRIBUTE_UNUSED) {
653}
Daniel Veillardb1b3a3e2004-11-03 23:25:47 +0000654static void desret_void_ptr(void *val ATTRIBUTE_UNUSED) {
655}
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000656static void desret_const_char_ptr(const char *val ATTRIBUTE_UNUSED) {
657}
Daniel Veillardd005b9e2004-11-03 17:07:05 +0000658static void desret_const_xmlChar_ptr(const xmlChar *val ATTRIBUTE_UNUSED) {
659}
Daniel Veillard8a32fe42004-11-02 22:10:16 +0000660static void desret_xmlChar_ptr(xmlChar *val) {
661 if (val != NULL)
662 xmlFree(val);
663}
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000664static void desret_xmlDocPtr(xmlDocPtr val) {
665 xmlFreeDoc(val);
666}
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000667static void desret_xmlDictPtr(xmlDictPtr val) {
668 xmlDictFree(val);
669}
670static void desret_xmlTextReaderPtr(xmlTextReaderPtr val) {
671 xmlFreeTextReader(val);
672}
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000673static void desret_xmlNodePtr(xmlNodePtr val) {
674 xmlUnlinkNode(val);
675 xmlFreeNode(val);
676}
Daniel Veillard3d97e662004-11-04 10:49:00 +0000677static void desret_xmlXPathObjectPtr(xmlXPathObjectPtr val) {
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000678 xmlXPathFreeObject(val);
Daniel Veillard3d97e662004-11-04 10:49:00 +0000679}
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000680""");
681
682#
683# Generate the top caller
684#
685
686test.write("""
687/**
688 * testlibxml2:
689 *
690 * Main entry point of the tester for the full libxml2 module,
691 * it calls all the tester entry point for each module.
692 *
693 * Returns the number of error found
694 */
695static int
696testlibxml2(void)
697{
698 int ret = 0;
699
700""")
701
702for module in modules:
703 test.write(" ret += test_%s();\n" % module)
704
705test.write("""
Daniel Veillard3d97e662004-11-04 10:49:00 +0000706 printf("Total: %d functions, %d tests, %d errors\\n",
707 function_tests, call_tests, ret);
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000708 return(ret);
709}
710
711""")
712
713#
714# How to handle a function
715#
716nb_tests = 0
717
718def generate_test(module, node):
719 global test
720 global nb_tests
721 nb_cond = 0
722 no_gen = 0
723
724 name = node.xpathEval('string(@name)')
725 if is_skipped_function(name):
726 return
727
728 test.write("""
729static int
730test_%s(void) {
731 int ret = 0;
732
733""" % (name))
734
735 #
736 # check we know how to handle the args and return values
737 # and store the informations for the generation
738 #
739 try:
740 args = node.xpathEval("arg")
741 except:
742 args = []
743 t_args = []
Daniel Veillarda03e3652004-11-02 18:45:30 +0000744 n = 0
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000745 for arg in args:
Daniel Veillarda03e3652004-11-02 18:45:30 +0000746 n = n + 1
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000747 rtype = arg.xpathEval("string(@type)")
748 if rtype == 'void':
749 break;
750 info = arg.xpathEval("string(@info)")
751 nam = arg.xpathEval("string(@name)")
Daniel Veillarda03e3652004-11-02 18:45:30 +0000752 type = type_convert(rtype, nam, info, module, name, n)
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000753 if is_known_param_type(type) == 0:
754 add_missing_type(type, name);
755 no_gen = 1
756 t_args.append((nam, type, rtype, info))
757
758 try:
759 rets = node.xpathEval("return")
760 except:
761 rets = []
762 t_ret = None
763 for ret in rets:
764 rtype = ret.xpathEval("string(@type)")
765 info = ret.xpathEval("string(@info)")
Daniel Veillarda03e3652004-11-02 18:45:30 +0000766 type = type_convert(rtype, 'return', info, module, name, 0)
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000767 if rtype == 'void':
768 break
769 if is_known_return_type(type) == 0:
770 add_missing_type(type, name);
771 no_gen = 1
772 t_ret = (type, rtype, info)
773 break
774
775 if no_gen == 1:
776 test.write("""
777 /* missing type support */
778 return(ret);
779}
780
781""")
782 return
783
784 try:
785 conds = node.xpathEval("cond")
786 for cond in conds:
787 test.write("#ifdef %s\n" % (cond.get_content()))
788 nb_cond = nb_cond + 1
789 except:
790 pass
791
792 # Declare the memory usage counter
793 no_mem = is_skipped_memcheck(name)
794 if no_mem == 0:
795 test.write(" int mem_base;\n");
796
797 # Declare the return value
798 if t_ret != None:
799 test.write(" %s ret_val;\n" % (t_ret[1]))
800
801 # Declare the arguments
802 for arg in t_args:
803 (nam, type, rtype, info) = arg;
804 # add declaration
805 test.write(" %s %s; /* %s */\n" % (rtype, nam, info))
806 test.write(" int n_%s;\n" % (nam))
807 test.write("\n")
808
809 # Cascade loop on of each argument list of values
810 for arg in t_args:
811 (nam, type, rtype, info) = arg;
812 #
813 test.write(" for (n_%s = 0;n_%s < gen_nb_%s;n_%s++) {\n" % (
814 nam, nam, type, nam))
815
816 # log the memory usage
817 if no_mem == 0:
818 test.write(" mem_base = xmlMemBlocks();\n");
819
820 # prepare the call
Daniel Veillard3d97e662004-11-04 10:49:00 +0000821 i = 0;
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000822 for arg in t_args:
823 (nam, type, rtype, info) = arg;
824 #
Daniel Veillard3d97e662004-11-04 10:49:00 +0000825 test.write(" %s = gen_%s(n_%s, %d);\n" % (nam, type, nam, i))
826 i = i + 1;
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000827
828 # do the call, and clanup the result
829 if t_ret != None:
830 test.write("\n ret_val = %s(" % (name))
831 need = 0
832 for arg in t_args:
833 (nam, type, rtype, info) = arg
834 if need:
835 test.write(", ")
836 else:
837 need = 1
838 test.write("%s" % nam);
Daniel Veillard8a32fe42004-11-02 22:10:16 +0000839 test.write(");\n")
840 if extra_post_call.has_key(name):
841 test.write(" %s\n"% (extra_post_call[name]))
842 test.write(" desret_%s(ret_val);\n" % t_ret[0])
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000843 else:
844 test.write("\n %s(" % (name));
845 need = 0;
846 for arg in t_args:
847 (nam, type, rtype, info) = arg;
848 if need:
849 test.write(", ")
850 else:
851 need = 1
852 test.write("%s" % nam)
853 test.write(");\n")
Daniel Veillard8a32fe42004-11-02 22:10:16 +0000854 if extra_post_call.has_key(name):
855 test.write(" %s\n"% (extra_post_call[name]))
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000856
Daniel Veillard8a32fe42004-11-02 22:10:16 +0000857 test.write(" call_tests++;\n");
Daniel Veillarda03e3652004-11-02 18:45:30 +0000858
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000859 # Free the arguments
Daniel Veillard3d97e662004-11-04 10:49:00 +0000860 i = 0;
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000861 for arg in t_args:
862 (nam, type, rtype, info) = arg;
863 #
Daniel Veillard3d97e662004-11-04 10:49:00 +0000864 test.write(" des_%s(n_%s, %s, %d);\n" % (type, nam, nam, i))
865 i = i + 1;
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000866
867 test.write(" xmlResetLastError();\n");
868 # Check the memory usage
869 if no_mem == 0:
870 test.write(""" if (mem_base != xmlMemBlocks()) {
Daniel Veillarda03e3652004-11-02 18:45:30 +0000871 printf("Leak of %%d blocks found in %s",
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000872 xmlMemBlocks() - mem_base);
873 ret++;
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000874""" % (name));
Daniel Veillarda03e3652004-11-02 18:45:30 +0000875 for arg in t_args:
876 (nam, type, rtype, info) = arg;
877 test.write(""" printf(" %%d", n_%s);\n""" % (nam))
878 test.write(""" printf("\\n");\n""")
879 test.write(" }\n")
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000880
881 for arg in t_args:
882 test.write(" }\n")
883
884 #
885 # end of conditional
886 #
887 while nb_cond > 0:
888 test.write("#endif\n")
889 nb_cond = nb_cond -1
890
891 nb_tests = nb_tests + 1;
892
893 test.write("""
Daniel Veillard3d97e662004-11-04 10:49:00 +0000894 function_tests++;
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000895 return(ret);
896}
897
898""")
899
900#
901# Generate all module callers
902#
903for module in modules:
904 # gather all the functions exported by that module
905 try:
906 functions = ctxt.xpathEval("/api/symbols/function[@file='%s']" % (module))
907 except:
908 print "Failed to gather functions from module %s" % (module)
909 continue;
910
911 # iterate over all functions in the module generating the test
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000912 i = 0
913 nb_tests_old = nb_tests
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000914 for function in functions:
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000915 i = i + 1
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000916 generate_test(module, function);
917
918 # header
919 test.write("""static int
920test_%s(void) {
921 int ret = 0;
922
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000923 printf("Testing %s : %d of %d functions ...\\n");
924""" % (module, module, nb_tests - nb_tests_old, i))
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000925
926 # iterate over all functions in the module generating the call
927 for function in functions:
928 name = function.xpathEval('string(@name)')
929 if is_skipped_function(name):
930 continue
931 test.write(" ret += test_%s();\n" % (name))
932
933 # footer
934 test.write("""
935 if (ret != 0)
936 printf("Module %s: %%d errors\\n", ret);
937 return(ret);
938}
939""" % (module))
940
941print "Generated test for %d modules and %d functions" %(len(modules), nb_tests)
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000942
943missing_list = []
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000944for missing in missing_types.keys():
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000945 if missing == 'va_list' or missing == '...':
Daniel Veillardb1b3a3e2004-11-03 23:25:47 +0000946 continue;
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000947
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000948 n = len(missing_types[missing])
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000949 missing_list.append((n, missing))
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000950
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000951def compare_missing(a, b):
952 return b[0] - a[0]
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000953
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000954missing_list.sort(compare_missing)
955print "Missing support for %d types see missing.lst" % (len(missing_list))
956lst = open("missing.lst", "w")
957for miss in missing_list:
958 lst.write("%s: %d :" % (miss[1], miss[0]))
959 i = 0
960 for n in missing_types[miss[1]]:
961 i = i + 1
962 if i > 5:
963 lst.write(" ...")
964 break
965 lst.write(" %s" % (n))
966 lst.write("\n")
967
968lst.close()
969test.close()
Daniel Veillardb1b3a3e2004-11-03 23:25:47 +0000970
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000971