blob: fb37eda42050bcc90017ad6a0f0ad4e94dd5e016 [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
Daniel Veillard34099b42004-11-04 17:34:35 +00006import os
Daniel Veillard36e5cd52004-11-02 14:52:23 +00007import string
8try:
9 import libxml2
10except:
11 print "libxml2 python bindings not available, skipping testapi.c generation"
12 sys.exit(0)
13
14#
William M. Brack094dd862004-11-14 14:28:34 +000015# Modules we want to skip in API test
Daniel Veillard36e5cd52004-11-02 14:52:23 +000016#
Daniel Veillard2a4fb5a2004-11-08 14:02:18 +000017skipped_modules = [ "SAX", "xlink", "threads", "globals",
Daniel Veillarda82b1822004-11-08 16:24:57 +000018 "xmlmemory", "xmlversion", "xmlexports",
19 #deprecated
20 "DOCBparser",
Daniel Veillardd005b9e2004-11-03 17:07:05 +000021]
Daniel Veillard36e5cd52004-11-02 14:52:23 +000022
23#
Daniel Veillarda521d282004-11-09 14:59:59 +000024# defines for each module
25#
26modules_defines = {
27 "HTMLparser": "LIBXML_HTML_ENABLED",
28 "catalog": "LIBXML_CATALOG_ENABLED",
29 "xmlreader": "LIBXML_READER_ENABLED",
30 "relaxng": "LIBXML_SCHEMAS_ENABLED",
31 "schemasInternals": "LIBXML_SCHEMAS_ENABLED",
32 "xmlschemas": "LIBXML_SCHEMAS_ENABLED",
33 "xmlschemastypes": "LIBXML_SCHEMAS_ENABLED",
34 "xpath": "LIBXML_XPATH_ENABLED",
35 "xpathInternals": "LIBXML_XPATH_ENABLED",
36 "xinclude": "LIBXML_XINCLUDE_ENABLED",
37 "xpointer": "LIBXML_XPTR_ENABLED",
38 "xmlregexp" : "LIBXML_REGEXP_ENABLED",
39 "xmlautomata" : "LIBXML_AUTOMATA_ENABLED",
40 "xmlsave" : "LIBXML_OUTPUT_ENABLED",
41 "DOCBparser" : "LIBXML_DOCB_ENABLED",
42}
43
44#
45# defines for specific functions
46#
47function_defines = {
48 "htmlDefaultSAXHandlerInit": "LIBXML_HTML_ENABLED",
49 "xmlSAX2EndElement" : "LIBXML_SAX1_ENABLED",
50 "xmlSAX2StartElement" : "LIBXML_SAX1_ENABLED",
51 "xmlSAXDefaultVersion" : "LIBXML_SAX1_ENABLED",
52 "UTF8Toisolat1" : "LIBXML_OUTPUT_ENABLED",
53 "xmlCleanupPredefinedEntities": "LIBXML_LEGACY_ENABLED",
54 "xmlInitializePredefinedEntities": "LIBXML_LEGACY_ENABLED",
55 "xmlSetFeature": "LIBXML_LEGACY_ENABLED",
56 "xmlGetFeature": "LIBXML_LEGACY_ENABLED",
57 "xmlGetFeaturesList": "LIBXML_LEGACY_ENABLED",
58 "xmlIOParseDTD": "LIBXML_VALID_ENABLED",
59 "xmlParseDTD": "LIBXML_VALID_ENABLED",
60 "xmlParseDoc": "LIBXML_SAX1_ENABLED",
61 "xmlParseMemory": "LIBXML_SAX1_ENABLED",
62 "xmlRecoverDoc": "LIBXML_SAX1_ENABLED",
63 "xmlParseFile": "LIBXML_SAX1_ENABLED",
64 "xmlRecoverFile": "LIBXML_SAX1_ENABLED",
65 "xmlRecoverMemory": "LIBXML_SAX1_ENABLED",
66 "xmlSAXParseFileWithData": "LIBXML_SAX1_ENABLED",
67 "xmlSAXParseMemory": "LIBXML_SAX1_ENABLED",
68 "xmlSAXUserParseMemory": "LIBXML_SAX1_ENABLED",
69 "xmlSAXParseDoc": "LIBXML_SAX1_ENABLED",
70 "xmlSAXParseDTD": "LIBXML_SAX1_ENABLED",
71 "xmlSAXUserParseFile": "LIBXML_SAX1_ENABLED",
72 "xmlParseEntity": "LIBXML_SAX1_ENABLED",
73 "xmlParseExternalEntity": "LIBXML_SAX1_ENABLED",
74 "xmlSAXParseMemoryWithData": "LIBXML_SAX1_ENABLED",
75 "xmlParseBalancedChunkMemory": "LIBXML_SAX1_ENABLED",
76 "xmlParseBalancedChunkMemoryRecover": "LIBXML_SAX1_ENABLED",
77 "xmlSetupParserForBuffer": "LIBXML_SAX1_ENABLED",
78 "xmlStopParser": "LIBXML_PUSH_ENABLED",
79 "xmlAttrSerializeTxtContent": "LIBXML_OUTPUT_ENABLED",
80 "xmlSAXParseFile": "LIBXML_SAX1_ENABLED",
81 "xmlSAXParseEntity": "LIBXML_SAX1_ENABLED",
82 "xmlNewTextChild": "LIBXML_TREE_ENABLED",
83 "xmlNewDocRawNode": "LIBXML_TREE_ENABLED",
84 "xmlNewProp": "LIBXML_TREE_ENABLED",
85 "xmlReconciliateNs": "LIBXML_TREE_ENABLED",
86 "xmlValidateNCName": "LIBXML_TREE_ENABLED",
87 "xmlValidateNMToken": "LIBXML_TREE_ENABLED",
88 "xmlValidateName": "LIBXML_TREE_ENABLED",
89 "xmlNewChild": "LIBXML_TREE_ENABLED",
90 "xmlValidateQName": "LIBXML_TREE_ENABLED",
91 "xmlSprintfElementContent": "LIBXML_OUTPUT_ENABLED",
92 "xmlValidGetPotentialChildren" : "LIBXML_VALID_ENABLED",
93 "xmlValidGetValidElements" : "LIBXML_VALID_ENABLED",
94 "docbDefaultSAXHandlerInit" : "LIBXML_DOCB_ENABLED",
Daniel Veillardd0cf7f62004-11-09 16:17:02 +000095 "xmlTextReaderPreservePattern" : "LIBXML_PATTERN_ENABLED",
Daniel Veillarda521d282004-11-09 14:59:59 +000096}
97
98#
William M. Brack094dd862004-11-14 14:28:34 +000099# Some functions really need to be skipped for the tests.
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000100#
Daniel Veillarddd6d3002004-11-03 14:20:29 +0000101skipped_functions = [
102# block on I/O
103"xmlFdRead", "xmlReadFd", "xmlCtxtReadFd",
104"htmlFdRead", "htmlReadFd", "htmlCtxtReadFd",
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000105"xmlReaderNewFd", "xmlReaderForFd",
Daniel Veillardb1b3a3e2004-11-03 23:25:47 +0000106"xmlIORead", "xmlReadIO", "xmlCtxtReadIO",
107"htmlIORead", "htmlReadIO", "htmlCtxtReadIO",
Daniel Veillard27f20102004-11-05 11:50:11 +0000108"xmlReaderNewIO", "xmlBufferDump", "xmlNanoFTPConnect",
109"xmlNanoFTPConnectTo",
Daniel Veillard42595322004-11-08 10:52:06 +0000110# Complex I/O APIs
111"xmlCreateIOParserCtxt", "xmlParserInputBufferCreateIO",
112"xmlRegisterInputCallbacks", "xmlReaderForIO",
113"xmlOutputBufferCreateIO", "xmlRegisterOutputCallbacks",
114"xmlSaveToIO",
Daniel Veillarddd6d3002004-11-03 14:20:29 +0000115# library state cleanup, generate false leak informations and other
116# troubles, heavillyb tested otherwise.
Daniel Veillardce244ad2004-11-05 10:03:46 +0000117"xmlCleanupParser", "xmlRelaxNGCleanupTypes", "xmlSetListDoc",
118"xmlSetTreeDoc", "xmlUnlinkNode",
Daniel Veillarddd6d3002004-11-03 14:20:29 +0000119# hard to avoid leaks in the tests
Daniel Veillardd5cc0f72004-11-06 19:24:28 +0000120"xmlStrcat", "xmlStrncat", "xmlCatalogAddLocal", "xmlNewTextWriterDoc",
Daniel Veillarda82b1822004-11-08 16:24:57 +0000121"xmlXPathNewValueTree", "xmlXPathWrapString",
Daniel Veillarddd6d3002004-11-03 14:20:29 +0000122# unimplemented
123"xmlTextReaderReadInnerXml", "xmlTextReaderReadOuterXml",
Daniel Veillardd005b9e2004-11-03 17:07:05 +0000124"xmlTextReaderReadString",
125# destructor
Daniel Veillard27f20102004-11-05 11:50:11 +0000126"xmlListDelete", "xmlOutputBufferClose", "xmlNanoFTPClose",
Daniel Veillardd005b9e2004-11-03 17:07:05 +0000127# deprecated
128"xmlCatalogGetPublic", "xmlCatalogGetSystem", "xmlEncodeEntities",
Daniel Veillard2a4fb5a2004-11-08 14:02:18 +0000129"xmlNewGlobalNs", "xmlHandleEntity", "xmlNamespaceParseNCName",
130"xmlNamespaceParseNSDef", "xmlNamespaceParseQName",
131"xmlParseNamespace", "xmlParseQuotedString", "xmlParserHandleReference",
132"xmlScanName",
Daniel Veillarda82b1822004-11-08 16:24:57 +0000133"xmlDecodeEntities",
Daniel Veillardb1b3a3e2004-11-03 23:25:47 +0000134# allocators
135"xmlMemFree",
Daniel Veillardc2c894f2004-11-07 12:17:35 +0000136# verbosity
Daniel Veillarda82b1822004-11-08 16:24:57 +0000137"xmlCatalogSetDebug", "xmlShellPrintXPathError", "xmlShellPrintNode",
Daniel Veillard2a4fb5a2004-11-08 14:02:18 +0000138# Internal functions, no user space should really call them
139"xmlParseAttribute", "xmlParseAttributeListDecl", "xmlParseName",
140"xmlParseNmtoken", "xmlParseEntityValue", "xmlParseAttValue",
141"xmlParseSystemLiteral", "xmlParsePubidLiteral", "xmlParseCharData",
142"xmlParseExternalID", "xmlParseComment", "xmlParsePITarget", "xmlParsePI",
143"xmlParseNotationDecl", "xmlParseEntityDecl", "xmlParseDefaultDecl",
144"xmlParseNotationType", "xmlParseEnumerationType", "xmlParseEnumeratedType",
145"xmlParseAttributeType", "xmlParseAttributeListDecl",
146"xmlParseElementMixedContentDecl", "xmlParseElementChildrenContentDecl",
147"xmlParseElementContentDecl", "xmlParseElementDecl", "xmlParseMarkupDecl",
148"xmlParseCharRef", "xmlParseEntityRef", "xmlParseReference",
149"xmlParsePEReference", "xmlParseDocTypeDecl", "xmlParseAttribute",
150"xmlParseStartTag", "xmlParseEndTag", "xmlParseCDSect", "xmlParseContent",
151"xmlParseElement", "xmlParseVersionNum", "xmlParseVersionInfo",
152"xmlParseEncName", "xmlParseEncodingDecl", "xmlParseSDDecl",
153"xmlParseXMLDecl", "xmlParseTextDecl", "xmlParseMisc",
154"xmlParseExternalSubset", "xmlParserHandlePEReference",
155"xmlSkipBlankChars",
Daniel Veillarddd6d3002004-11-03 14:20:29 +0000156]
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000157
158#
William M. Brack094dd862004-11-14 14:28:34 +0000159# These functions have side effects on the global state
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000160# and hence generate errors on memory allocation tests
161#
162skipped_memcheck = [ "xmlLoadCatalog", "xmlAddEncodingAlias",
163 "xmlSchemaInitTypes", "xmlNanoFTPProxy", "xmlNanoFTPScanProxy",
164 "xmlNanoHTTPScanProxy", "xmlResetLastError", "xmlCatalogConvert",
165 "xmlCatalogRemove", "xmlLoadCatalogs", "xmlCleanupCharEncodingHandlers",
Daniel Veillarda03e3652004-11-02 18:45:30 +0000166 "xmlInitCharEncodingHandlers", "xmlCatalogCleanup",
Daniel Veillard42595322004-11-08 10:52:06 +0000167 "xmlSchemaGetBuiltInType",
Daniel Veillard29614c72004-11-26 10:47:26 +0000168 "htmlParseFile", "htmlCtxtReadFile" # loads the catalogs
Daniel Veillarda03e3652004-11-02 18:45:30 +0000169]
170
171#
172# Extra code needed for some test cases
173#
Daniel Veillard34099b42004-11-04 17:34:35 +0000174extra_pre_call = {
Daniel Veillarda521d282004-11-09 14:59:59 +0000175 "xmlSAXUserParseFile": """
176#ifdef LIBXML_SAX1_ENABLED
177 if (sax == (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) user_data = NULL;
178#endif
179""",
180 "xmlSAXUserParseMemory": """
181#ifdef LIBXML_SAX1_ENABLED
182 if (sax == (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) user_data = NULL;
183#endif
184""",
185 "xmlParseBalancedChunkMemory": """
186#ifdef LIBXML_SAX1_ENABLED
187 if (sax == (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) user_data = NULL;
188#endif
189""",
190 "xmlParseBalancedChunkMemoryRecover": """
191#ifdef LIBXML_SAX1_ENABLED
192 if (sax == (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) user_data = NULL;
193#endif
194""",
Daniel Veillardd5cc0f72004-11-06 19:24:28 +0000195 "xmlParserInputBufferCreateFd":
196 "if (fd >= 0) fd = -1;",
Daniel Veillard34099b42004-11-04 17:34:35 +0000197}
Daniel Veillarda03e3652004-11-02 18:45:30 +0000198extra_post_call = {
199 "xmlAddChild":
200 "if (ret_val == NULL) { xmlFreeNode(cur) ; cur = NULL ; }",
201 "xmlAddChildList":
202 "if (ret_val == NULL) { xmlFreeNodeList(cur) ; cur = NULL ; }",
203 "xmlAddSibling":
204 "if (ret_val == NULL) { xmlFreeNode(elem) ; elem = NULL ; }",
205 "xmlAddNextSibling":
206 "if (ret_val == NULL) { xmlFreeNode(elem) ; elem = NULL ; }",
207 "xmlAddPrevSibling":
208 "if (ret_val == NULL) { xmlFreeNode(elem) ; elem = NULL ; }",
209 "xmlDocSetRootElement":
210 "if (doc == NULL) { xmlFreeNode(root) ; root = NULL ; }",
211 "xmlReplaceNode":
Daniel Veillardce244ad2004-11-05 10:03:46 +0000212 """if (cur != NULL) {
213 xmlUnlinkNode(cur);
214 xmlFreeNode(cur) ; cur = NULL ; }
215 if (old != NULL) {
216 xmlUnlinkNode(old);
217 xmlFreeNode(old) ; old = NULL ; }
218 ret_val = NULL;""",
Daniel Veillarda03e3652004-11-02 18:45:30 +0000219 "xmlTextMerge":
220 """if ((first != NULL) && (first->type != XML_TEXT_NODE)) {
Daniel Veillardce244ad2004-11-05 10:03:46 +0000221 xmlUnlinkNode(second);
Daniel Veillarda03e3652004-11-02 18:45:30 +0000222 xmlFreeNode(second) ; second = NULL ; }""",
Daniel Veillard8a32fe42004-11-02 22:10:16 +0000223 "xmlBuildQName":
224 """if ((ret_val != NULL) && (ret_val != ncname) &&
225 (ret_val != prefix) && (ret_val != memory))
226 xmlFree(ret_val);
227 ret_val = NULL;""",
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000228 "xmlDictReference": "xmlDictFree(dict);",
Daniel Veillard3d97e662004-11-04 10:49:00 +0000229 # Functions which deallocates one of their parameters
230 "xmlXPathConvertBoolean": """val = NULL;""",
231 "xmlXPathConvertNumber": """val = NULL;""",
232 "xmlXPathConvertString": """val = NULL;""",
233 "xmlSaveFileTo": """buf = NULL;""",
Daniel Veillard34099b42004-11-04 17:34:35 +0000234 "xmlSaveFormatFileTo": """buf = NULL;""",
235 "xmlIOParseDTD": "input = NULL;",
Daniel Veillardce244ad2004-11-05 10:03:46 +0000236 "xmlRemoveProp": "cur = NULL;",
Daniel Veillardd5cc0f72004-11-06 19:24:28 +0000237 "xmlNewNs": "if ((node == NULL) && (ret_val != NULL)) xmlFreeNs(ret_val);",
238 "xmlCopyNamespace": "if (ret_val != NULL) xmlFreeNs(ret_val);",
239 "xmlCopyNamespaceList": "if (ret_val != NULL) xmlFreeNsList(ret_val);",
240 "xmlNewTextWriter": "if (ret_val != NULL) out = NULL;",
Daniel Veillarda521d282004-11-09 14:59:59 +0000241 "xmlNewTextWriterPushParser": "if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;} if (ret_val != NULL) ctxt = NULL;",
Daniel Veillard42595322004-11-08 10:52:06 +0000242 "xmlNewIOInputStream": "if (ret_val != NULL) input = NULL;",
Daniel Veillarda521d282004-11-09 14:59:59 +0000243 "htmlParseChunk": "if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;}",
244 "htmlParseDocument": "if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;}",
245 "xmlParseDocument": "if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;}",
246 "xmlParseChunk": "if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;}",
247 "xmlParseExtParsedEnt": "if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;}",
Daniel Veillarda03e3652004-11-02 18:45:30 +0000248}
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000249
250modules = []
251
252def is_skipped_module(name):
253 for mod in skipped_modules:
254 if mod == name:
255 return 1
256 return 0
257
258def is_skipped_function(name):
259 for fun in skipped_functions:
260 if fun == name:
261 return 1
262 # Do not test destructors
263 if string.find(name, 'Free') != -1:
264 return 1
265 return 0
266
267def is_skipped_memcheck(name):
268 for fun in skipped_memcheck:
269 if fun == name:
270 return 1
271 return 0
272
273missing_types = {}
274def add_missing_type(name, func):
275 try:
276 list = missing_types[name]
277 list.append(func)
278 except:
279 missing_types[name] = [func]
280
Daniel Veillardce682bc2004-11-05 17:22:25 +0000281generated_param_types = []
282def add_generated_param_type(name):
283 generated_param_types.append(name)
284
285generated_return_types = []
286def add_generated_return_type(name):
287 generated_return_types.append(name)
288
Daniel Veillard34099b42004-11-04 17:34:35 +0000289missing_functions = {}
Daniel Veillard0ea9c9f2004-11-05 14:30:41 +0000290missing_functions_nr = 0
Daniel Veillard34099b42004-11-04 17:34:35 +0000291def add_missing_functions(name, module):
Daniel Veillard0ea9c9f2004-11-05 14:30:41 +0000292 global missing_functions_nr
293
294 missing_functions_nr = missing_functions_nr + 1
Daniel Veillard34099b42004-11-04 17:34:35 +0000295 try:
296 list = missing_functions[module]
297 list.append(name)
298 except:
299 missing_functions[module] = [name]
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000300
301#
302# Provide the type generators and destructors for the parameters
303#
304
Daniel Veillarda03e3652004-11-02 18:45:30 +0000305def type_convert(str, name, info, module, function, pos):
Daniel Veillardd5cc0f72004-11-06 19:24:28 +0000306# res = string.replace(str, " ", " ")
307# res = string.replace(str, " ", " ")
308# res = string.replace(str, " ", " ")
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000309 res = string.replace(str, " *", "_ptr")
Daniel Veillardd5cc0f72004-11-06 19:24:28 +0000310# res = string.replace(str, "*", "_ptr")
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000311 res = string.replace(res, " ", "_")
312 if res == 'const_char_ptr':
313 if string.find(name, "file") != -1 or \
314 string.find(name, "uri") != -1 or \
315 string.find(name, "URI") != -1 or \
316 string.find(info, "filename") != -1 or \
317 string.find(info, "URI") != -1 or \
318 string.find(info, "URL") != -1:
William M. Brack83d9c372004-11-08 02:26:08 +0000319 if string.find(function, "Save") != -1 or \
320 string.find(function, "Create") != -1 or \
321 string.find(function, "Write") != -1:
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000322 return('fileoutput')
323 return('filepath')
324 if res == 'void_ptr':
325 if module == 'nanoftp' and name == 'ctx':
326 return('xmlNanoFTPCtxtPtr')
Daniel Veillardb1b3a3e2004-11-03 23:25:47 +0000327 if function == 'xmlNanoFTPNewCtxt':
328 return('xmlNanoFTPCtxtPtr')
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000329 if module == 'nanohttp' and name == 'ctx':
330 return('xmlNanoHTTPCtxtPtr')
Daniel Veillardb1b3a3e2004-11-03 23:25:47 +0000331 if function == 'xmlIOHTTPOpenW':
332 return('xmlNanoHTTPCtxtPtr')
Daniel Veillard8a32fe42004-11-02 22:10:16 +0000333 if string.find(name, "data") != -1:
William M. Brack094dd862004-11-14 14:28:34 +0000334 return('userdata')
Daniel Veillardd005b9e2004-11-03 17:07:05 +0000335 if string.find(name, "user") != -1:
William M. Brack094dd862004-11-14 14:28:34 +0000336 return('userdata')
Daniel Veillard3d97e662004-11-04 10:49:00 +0000337 if res == 'xmlDoc_ptr':
William M. Brack094dd862004-11-14 14:28:34 +0000338 res = 'xmlDocPtr'
Daniel Veillard3d97e662004-11-04 10:49:00 +0000339 if res == 'xmlNode_ptr':
William M. Brack094dd862004-11-14 14:28:34 +0000340 res = 'xmlNodePtr'
Daniel Veillard3d97e662004-11-04 10:49:00 +0000341 if res == 'xmlDict_ptr':
William M. Brack094dd862004-11-14 14:28:34 +0000342 res = 'xmlDictPtr'
Daniel Veillarda03e3652004-11-02 18:45:30 +0000343 if res == 'xmlNodePtr' and pos != 0:
344 if (function == 'xmlAddChild' and pos == 2) or \
345 (function == 'xmlAddChildList' and pos == 2) or \
346 (function == 'xmlAddNextSibling' and pos == 2) or \
347 (function == 'xmlAddSibling' and pos == 2) or \
348 (function == 'xmlDocSetRootElement' and pos == 2) or \
349 (function == 'xmlReplaceNode' and pos == 2) or \
350 (function == 'xmlTextMerge') or \
351 (function == 'xmlAddPrevSibling' and pos == 2):
352 return('xmlNodePtr_in');
Daniel Veillard34099b42004-11-04 17:34:35 +0000353 if res == 'const xmlBufferPtr':
William M. Brack094dd862004-11-14 14:28:34 +0000354 res = 'xmlBufferPtr'
Daniel Veillard27f20102004-11-05 11:50:11 +0000355 if res == 'xmlChar_ptr' and name == 'name' and \
356 string.find(function, "EatName") != -1:
357 return('eaten_name')
Daniel Veillardd5cc0f72004-11-06 19:24:28 +0000358 if res == 'void_ptr*':
359 res = 'void_ptr_ptr'
360 if res == 'char_ptr*':
361 res = 'char_ptr_ptr'
362 if res == 'xmlChar_ptr*':
363 res = 'xmlChar_ptr_ptr'
364 if res == 'const_xmlChar_ptr*':
365 res = 'const_xmlChar_ptr_ptr'
366 if res == 'const_char_ptr*':
367 res = 'const_char_ptr_ptr'
Daniel Veillarda82b1822004-11-08 16:24:57 +0000368 if res == 'FILE_ptr' and module == 'debugXML':
369 res = 'debug_FILE_ptr';
Daniel Veillard6128c012004-11-08 17:16:15 +0000370 if res == 'int' and name == 'options':
371 if module == 'parser' or module == 'xmlreader':
372 res = 'parseroptions'
William M. Brack094dd862004-11-14 14:28:34 +0000373
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000374 return res
375
Daniel Veillard34099b42004-11-04 17:34:35 +0000376known_param_types = []
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000377
Daniel Veillardce682bc2004-11-05 17:22:25 +0000378def is_known_param_type(name, rtype):
379 global test
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000380 for type in known_param_types:
381 if type == name:
382 return 1
Daniel Veillardce682bc2004-11-05 17:22:25 +0000383 for type in generated_param_types:
384 if type == name:
385 return 1
386
387 if name[-3:] == 'Ptr' or name[-4:] == '_ptr':
388 if rtype[0:6] == 'const ':
389 crtype = rtype[6:]
390 else:
391 crtype = rtype
392
Daniel Veillarda521d282004-11-09 14:59:59 +0000393 define = 0
394 if modules_defines.has_key(module):
395 test.write("#ifdef %s\n" % (modules_defines[module]))
396 define = 1
Daniel Veillardce682bc2004-11-05 17:22:25 +0000397 test.write("""
398#define gen_nb_%s 1
399static %s gen_%s(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
400 return(NULL);
401}
402static void des_%s(int no ATTRIBUTE_UNUSED, %s val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
403}
404""" % (name, crtype, name, name, rtype))
Daniel Veillarda521d282004-11-09 14:59:59 +0000405 if define == 1:
406 test.write("#endif\n\n")
Daniel Veillardce682bc2004-11-05 17:22:25 +0000407 add_generated_param_type(name)
408 return 1
409
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000410 return 0
411
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000412#
413# Provide the type destructors for the return values
414#
415
Daniel Veillard34099b42004-11-04 17:34:35 +0000416known_return_types = []
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000417
418def is_known_return_type(name):
419 for type in known_return_types:
420 if type == name:
421 return 1
422 return 0
423
Daniel Veillard34099b42004-11-04 17:34:35 +0000424#
425# Copy the beginning of the C test program result
426#
427
428input = open("testapi.c", "r")
429test = open('testapi.c.new', 'w')
430
431def compare_and_save():
432 global test
433
434 test.close()
435 input = open("testapi.c", "r").read()
436 test = open('testapi.c.new', "r").read()
437 if input != test:
438 os.system("rm testapi.c ; mv testapi.c.new testapi.c")
439 print("Updated testapi.c")
440 else:
441 print("Generated testapi.c is identical")
442
443line = input.readline()
444while line != "":
445 if line == "/* CUT HERE: everything below that line is generated */\n":
446 break;
447 if line[0:15] == "#define gen_nb_":
448 type = string.split(line[15:])[0]
449 known_param_types.append(type)
450 if line[0:19] == "static void desret_":
451 type = string.split(line[19:], '(')[0]
452 known_return_types.append(type)
453 test.write(line)
454 line = input.readline()
455input.close()
456
457if line == "":
458 print "Could not find the CUT marker in testapi.c skipping generation"
459 test.close()
460 sys.exit(0)
461
462print("Scanned testapi.c: found %d parameters types and %d return types\n" % (
463 len(known_param_types), len(known_return_types)))
464test.write("/* CUT HERE: everything below that line is generated */\n")
465
466
467#
468# Open the input API description
469#
470doc = libxml2.readFile('doc/libxml2-api.xml', None, 0)
471if doc == None:
472 print "Failed to load doc/libxml2-api.xml"
473 sys.exit(1)
474ctxt = doc.xpathNewContext()
Daniel Veillard57b25162004-11-06 14:50:18 +0000475
476#
William M. Brack094dd862004-11-14 14:28:34 +0000477# Generate a list of all function parameters and select only
478# those used in the api tests
479#
480argtypes = {}
481args = ctxt.xpathEval("/api/symbols/function/arg")
482for arg in args:
483 mod = arg.xpathEval('string(../@file)')
484 func = arg.xpathEval('string(../@name)')
485 if (mod not in skipped_modules) and (func not in skipped_functions):
486 type = arg.xpathEval('string(@type)')
487 if not argtypes.has_key(type):
488 argtypes[type] = func
489
490# similarly for return types
491rettypes = {}
492rets = ctxt.xpathEval("/api/symbols/function/return")
493for ret in rets:
494 mod = ret.xpathEval('string(../@file)')
495 func = ret.xpathEval('string(../@name)')
496 if (mod not in skipped_modules) and (func not in skipped_functions):
497 type = ret.xpathEval('string(@type)')
498 if not rettypes.has_key(type):
499 rettypes[type] = func
500
501#
Daniel Veillard57b25162004-11-06 14:50:18 +0000502# Generate constructors and return type handling for all enums
William M. Brack094dd862004-11-14 14:28:34 +0000503# which are used as function parameters
Daniel Veillard57b25162004-11-06 14:50:18 +0000504#
505enums = ctxt.xpathEval("/api/symbols/typedef[@type='enum']")
506for enum in enums:
Daniel Veillarda521d282004-11-09 14:59:59 +0000507 module = enum.xpathEval('string(@file)')
William M. Brack094dd862004-11-14 14:28:34 +0000508 name = enum.xpathEval('string(@name)')
509 #
510 # Skip any enums which are not in our filtered lists
511 #
512 if (name == None) or ((name not in argtypes) and (name not in rettypes)):
513 continue;
Daniel Veillarda521d282004-11-09 14:59:59 +0000514 define = 0
Daniel Veillard57b25162004-11-06 14:50:18 +0000515
William M. Brack094dd862004-11-14 14:28:34 +0000516 if argtypes.has_key(name) and is_known_param_type(name, name) == 0:
Daniel Veillard57b25162004-11-06 14:50:18 +0000517 values = ctxt.xpathEval("/api/symbols/enum[@type='%s']" % name)
518 i = 0
519 vals = []
520 for value in values:
521 vname = value.xpathEval('string(@name)')
522 if vname == None:
523 continue;
524 i = i + 1
525 if i >= 5:
526 break;
527 vals.append(vname)
528 if vals == []:
William M. Brack094dd862004-11-14 14:28:34 +0000529 print "Didn't find any value for enum %s" % (name)
Daniel Veillard57b25162004-11-06 14:50:18 +0000530 continue
Daniel Veillarda521d282004-11-09 14:59:59 +0000531 if modules_defines.has_key(module):
532 test.write("#ifdef %s\n" % (modules_defines[module]))
533 define = 1
Daniel Veillard57b25162004-11-06 14:50:18 +0000534 test.write("#define gen_nb_%s %d\n" % (name, len(vals)))
535 test.write("""static %s gen_%s(int no, int nr ATTRIBUTE_UNUSED) {\n""" %
536 (name, name))
537 i = 1
538 for value in vals:
539 test.write(" if (no == %d) return(%s);\n" % (i, value))
540 i = i + 1
541 test.write(""" return(0);
542}
William M. Brack094dd862004-11-14 14:28:34 +0000543
544static void des_%s(int no ATTRIBUTE_UNUSED, %s val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
545}
546
547""" % (name, name));
Daniel Veillard57b25162004-11-06 14:50:18 +0000548 known_param_types.append(name)
549
William M. Brack094dd862004-11-14 14:28:34 +0000550 if (is_known_return_type(name) == 0) and (name in rettypes):
Daniel Veillarda521d282004-11-09 14:59:59 +0000551 if define == 0 and modules_defines.has_key(module):
552 test.write("#ifdef %s\n" % (modules_defines[module]))
553 define = 1
William M. Brack094dd862004-11-14 14:28:34 +0000554 test.write("""static void desret_%s(%s val ATTRIBUTE_UNUSED) {
Daniel Veillard57b25162004-11-06 14:50:18 +0000555}
556
William M. Brack094dd862004-11-14 14:28:34 +0000557""" % (name, name))
Daniel Veillard57b25162004-11-06 14:50:18 +0000558 known_return_types.append(name)
Daniel Veillarda521d282004-11-09 14:59:59 +0000559 if define == 1:
560 test.write("#endif\n\n")
Daniel Veillard34099b42004-11-04 17:34:35 +0000561
562#
563# Load the interfaces
564#
Daniel Veillard57b25162004-11-06 14:50:18 +0000565headers = ctxt.xpathEval("/api/files/file")
Daniel Veillard34099b42004-11-04 17:34:35 +0000566for file in headers:
567 name = file.xpathEval('string(@name)')
568 if (name == None) or (name == ''):
569 continue
570
571 #
572 # Some module may be skipped because they don't really consists
573 # of user callable APIs
574 #
575 if is_skipped_module(name):
576 continue
577
578 #
579 # do not test deprecated APIs
580 #
581 desc = file.xpathEval('string(description)')
582 if string.find(desc, 'DEPRECATED') != -1:
583 print "Skipping deprecated interface %s" % name
584 continue;
585
586 test.write("#include <libxml/%s.h>\n" % name)
587 modules.append(name)
588
589#
590# Generate the callers signatures
591#
592for module in modules:
593 test.write("static int test_%s(void);\n" % module);
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000594
595#
596# Generate the top caller
597#
598
599test.write("""
600/**
601 * testlibxml2:
602 *
603 * Main entry point of the tester for the full libxml2 module,
604 * it calls all the tester entry point for each module.
605 *
606 * Returns the number of error found
607 */
608static int
609testlibxml2(void)
610{
Daniel Veillard42595322004-11-08 10:52:06 +0000611 int test_ret = 0;
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000612
613""")
614
615for module in modules:
Daniel Veillard42595322004-11-08 10:52:06 +0000616 test.write(" test_ret += test_%s();\n" % module)
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000617
618test.write("""
Daniel Veillard3d97e662004-11-04 10:49:00 +0000619 printf("Total: %d functions, %d tests, %d errors\\n",
Daniel Veillard42595322004-11-08 10:52:06 +0000620 function_tests, call_tests, test_ret);
621 return(test_ret);
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000622}
623
624""")
625
626#
627# How to handle a function
628#
629nb_tests = 0
630
631def generate_test(module, node):
632 global test
633 global nb_tests
634 nb_cond = 0
635 no_gen = 0
636
637 name = node.xpathEval('string(@name)')
638 if is_skipped_function(name):
639 return
640
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000641 #
642 # check we know how to handle the args and return values
643 # and store the informations for the generation
644 #
645 try:
646 args = node.xpathEval("arg")
647 except:
648 args = []
649 t_args = []
Daniel Veillarda03e3652004-11-02 18:45:30 +0000650 n = 0
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000651 for arg in args:
Daniel Veillarda03e3652004-11-02 18:45:30 +0000652 n = n + 1
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000653 rtype = arg.xpathEval("string(@type)")
654 if rtype == 'void':
655 break;
656 info = arg.xpathEval("string(@info)")
657 nam = arg.xpathEval("string(@name)")
Daniel Veillarda03e3652004-11-02 18:45:30 +0000658 type = type_convert(rtype, nam, info, module, name, n)
Daniel Veillardce682bc2004-11-05 17:22:25 +0000659 if is_known_param_type(type, rtype) == 0:
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000660 add_missing_type(type, name);
661 no_gen = 1
William M. Brackf13f77f2004-11-12 16:03:48 +0000662 if (type[-3:] == 'Ptr' or type[-4:] == '_ptr') and \
663 rtype[0:6] == 'const ':
664 crtype = rtype[6:]
665 else:
666 crtype = rtype
667 t_args.append((nam, type, rtype, crtype, info))
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000668
669 try:
670 rets = node.xpathEval("return")
671 except:
672 rets = []
673 t_ret = None
674 for ret in rets:
675 rtype = ret.xpathEval("string(@type)")
676 info = ret.xpathEval("string(@info)")
Daniel Veillarda03e3652004-11-02 18:45:30 +0000677 type = type_convert(rtype, 'return', info, module, name, 0)
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000678 if rtype == 'void':
679 break
680 if is_known_return_type(type) == 0:
681 add_missing_type(type, name);
682 no_gen = 1
683 t_ret = (type, rtype, info)
684 break
685
Daniel Veillard0ea9c9f2004-11-05 14:30:41 +0000686 test.write("""
687static int
688test_%s(void) {
Daniel Veillard42595322004-11-08 10:52:06 +0000689 int test_ret = 0;
Daniel Veillard0ea9c9f2004-11-05 14:30:41 +0000690
691""" % (name))
692
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000693 if no_gen == 1:
Daniel Veillard34099b42004-11-04 17:34:35 +0000694 add_missing_functions(name, module)
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000695 test.write("""
696 /* missing type support */
Daniel Veillard42595322004-11-08 10:52:06 +0000697 return(test_ret);
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000698}
699
700""")
701 return
702
703 try:
704 conds = node.xpathEval("cond")
705 for cond in conds:
706 test.write("#ifdef %s\n" % (cond.get_content()))
707 nb_cond = nb_cond + 1
708 except:
709 pass
Daniel Veillarda521d282004-11-09 14:59:59 +0000710
711 define = 0
712 if function_defines.has_key(name):
713 test.write("#ifdef %s\n" % (function_defines[name]))
714 define = 1
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000715
716 # Declare the memory usage counter
717 no_mem = is_skipped_memcheck(name)
718 if no_mem == 0:
719 test.write(" int mem_base;\n");
720
721 # Declare the return value
722 if t_ret != None:
723 test.write(" %s ret_val;\n" % (t_ret[1]))
724
725 # Declare the arguments
726 for arg in t_args:
William M. Brackf13f77f2004-11-12 16:03:48 +0000727 (nam, type, rtype, crtype, info) = arg;
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000728 # add declaration
Daniel Veillardce682bc2004-11-05 17:22:25 +0000729 test.write(" %s %s; /* %s */\n" % (crtype, nam, info))
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000730 test.write(" int n_%s;\n" % (nam))
731 test.write("\n")
732
733 # Cascade loop on of each argument list of values
734 for arg in t_args:
William M. Brackf13f77f2004-11-12 16:03:48 +0000735 (nam, type, rtype, crtype, info) = arg;
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000736 #
737 test.write(" for (n_%s = 0;n_%s < gen_nb_%s;n_%s++) {\n" % (
738 nam, nam, type, nam))
739
740 # log the memory usage
741 if no_mem == 0:
742 test.write(" mem_base = xmlMemBlocks();\n");
743
744 # prepare the call
Daniel Veillard3d97e662004-11-04 10:49:00 +0000745 i = 0;
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000746 for arg in t_args:
William M. Brackf13f77f2004-11-12 16:03:48 +0000747 (nam, type, rtype, crtype, info) = arg;
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000748 #
Daniel Veillard3d97e662004-11-04 10:49:00 +0000749 test.write(" %s = gen_%s(n_%s, %d);\n" % (nam, type, nam, i))
750 i = i + 1;
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000751
752 # do the call, and clanup the result
Daniel Veillard34099b42004-11-04 17:34:35 +0000753 if extra_pre_call.has_key(name):
754 test.write(" %s\n"% (extra_pre_call[name]))
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000755 if t_ret != None:
756 test.write("\n ret_val = %s(" % (name))
757 need = 0
758 for arg in t_args:
William M. Brackf13f77f2004-11-12 16:03:48 +0000759 (nam, type, rtype, crtype, info) = arg
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000760 if need:
761 test.write(", ")
762 else:
763 need = 1
William M. Brackf13f77f2004-11-12 16:03:48 +0000764 if rtype != crtype:
765 test.write("(%s)" % rtype)
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000766 test.write("%s" % nam);
Daniel Veillard8a32fe42004-11-02 22:10:16 +0000767 test.write(");\n")
768 if extra_post_call.has_key(name):
769 test.write(" %s\n"% (extra_post_call[name]))
770 test.write(" desret_%s(ret_val);\n" % t_ret[0])
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000771 else:
772 test.write("\n %s(" % (name));
773 need = 0;
774 for arg in t_args:
William M. Brackf13f77f2004-11-12 16:03:48 +0000775 (nam, type, rtype, crtype, info) = arg;
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000776 if need:
777 test.write(", ")
778 else:
779 need = 1
William M. Brackf13f77f2004-11-12 16:03:48 +0000780 if rtype != crtype:
781 test.write("(%s)" % rtype)
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000782 test.write("%s" % nam)
783 test.write(");\n")
Daniel Veillard8a32fe42004-11-02 22:10:16 +0000784 if extra_post_call.has_key(name):
785 test.write(" %s\n"% (extra_post_call[name]))
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000786
Daniel Veillard8a32fe42004-11-02 22:10:16 +0000787 test.write(" call_tests++;\n");
Daniel Veillarda03e3652004-11-02 18:45:30 +0000788
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000789 # Free the arguments
Daniel Veillard3d97e662004-11-04 10:49:00 +0000790 i = 0;
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000791 for arg in t_args:
William M. Brackf13f77f2004-11-12 16:03:48 +0000792 (nam, type, rtype, crtype, info) = arg;
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000793 #
William M. Brackf13f77f2004-11-12 16:03:48 +0000794 test.write(" des_%s(n_%s, " % (type, nam))
795 if rtype != crtype:
796 test.write("(%s)" % rtype)
797 test.write("%s, %d);\n" % (nam, i))
Daniel Veillard3d97e662004-11-04 10:49:00 +0000798 i = i + 1;
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000799
800 test.write(" xmlResetLastError();\n");
801 # Check the memory usage
802 if no_mem == 0:
803 test.write(""" if (mem_base != xmlMemBlocks()) {
Daniel Veillarda03e3652004-11-02 18:45:30 +0000804 printf("Leak of %%d blocks found in %s",
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000805 xmlMemBlocks() - mem_base);
Daniel Veillard42595322004-11-08 10:52:06 +0000806 test_ret++;
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000807""" % (name));
Daniel Veillarda03e3652004-11-02 18:45:30 +0000808 for arg in t_args:
William M. Brackf13f77f2004-11-12 16:03:48 +0000809 (nam, type, rtype, crtype, info) = arg;
Daniel Veillarda03e3652004-11-02 18:45:30 +0000810 test.write(""" printf(" %%d", n_%s);\n""" % (nam))
811 test.write(""" printf("\\n");\n""")
812 test.write(" }\n")
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000813
814 for arg in t_args:
815 test.write(" }\n")
816
Daniel Veillardd0cf7f62004-11-09 16:17:02 +0000817 test.write(" function_tests++;\n")
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000818 #
819 # end of conditional
820 #
821 while nb_cond > 0:
822 test.write("#endif\n")
823 nb_cond = nb_cond -1
Daniel Veillarda521d282004-11-09 14:59:59 +0000824 if define == 1:
825 test.write("#endif\n")
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000826
827 nb_tests = nb_tests + 1;
828
829 test.write("""
Daniel Veillard42595322004-11-08 10:52:06 +0000830 return(test_ret);
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000831}
832
833""")
834
835#
836# Generate all module callers
837#
838for module in modules:
839 # gather all the functions exported by that module
840 try:
841 functions = ctxt.xpathEval("/api/symbols/function[@file='%s']" % (module))
842 except:
843 print "Failed to gather functions from module %s" % (module)
844 continue;
845
846 # iterate over all functions in the module generating the test
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000847 i = 0
848 nb_tests_old = nb_tests
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000849 for function in functions:
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000850 i = i + 1
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000851 generate_test(module, function);
852
853 # header
854 test.write("""static int
855test_%s(void) {
Daniel Veillard42595322004-11-08 10:52:06 +0000856 int test_ret = 0;
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000857
Daniel Veillardd0cf7f62004-11-09 16:17:02 +0000858 if (quiet == 0) printf("Testing %s : %d of %d functions ...\\n");
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000859""" % (module, module, nb_tests - nb_tests_old, i))
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000860
861 # iterate over all functions in the module generating the call
862 for function in functions:
863 name = function.xpathEval('string(@name)')
864 if is_skipped_function(name):
865 continue
Daniel Veillard42595322004-11-08 10:52:06 +0000866 test.write(" test_ret += test_%s();\n" % (name))
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000867
868 # footer
869 test.write("""
Daniel Veillard42595322004-11-08 10:52:06 +0000870 if (test_ret != 0)
871 printf("Module %s: %%d errors\\n", test_ret);
872 return(test_ret);
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000873}
874""" % (module))
875
Daniel Veillardce244ad2004-11-05 10:03:46 +0000876#
877# Generate direct module caller
878#
879test.write("""static int
880test_module(const char *module) {
881""");
882for module in modules:
883 test.write(""" if (!strcmp(module, "%s")) return(test_%s());\n""" % (
884 module, module))
885test.write(""" return(0);
886}
887""");
888
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000889print "Generated test for %d modules and %d functions" %(len(modules), nb_tests)
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000890
Daniel Veillard34099b42004-11-04 17:34:35 +0000891compare_and_save()
892
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000893missing_list = []
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000894for missing in missing_types.keys():
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000895 if missing == 'va_list' or missing == '...':
Daniel Veillardb1b3a3e2004-11-03 23:25:47 +0000896 continue;
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000897
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000898 n = len(missing_types[missing])
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000899 missing_list.append((n, missing))
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000900
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000901def compare_missing(a, b):
902 return b[0] - a[0]
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000903
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000904missing_list.sort(compare_missing)
Daniel Veillard0ea9c9f2004-11-05 14:30:41 +0000905print "Missing support for %d functions and %d types see missing.lst" % (missing_functions_nr, len(missing_list))
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000906lst = open("missing.lst", "w")
Daniel Veillard34099b42004-11-04 17:34:35 +0000907lst.write("Missing support for %d types" % (len(missing_list)))
908lst.write("\n")
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000909for miss in missing_list:
910 lst.write("%s: %d :" % (miss[1], miss[0]))
911 i = 0
912 for n in missing_types[miss[1]]:
913 i = i + 1
914 if i > 5:
915 lst.write(" ...")
916 break
917 lst.write(" %s" % (n))
918 lst.write("\n")
Daniel Veillard34099b42004-11-04 17:34:35 +0000919lst.write("\n")
920lst.write("\n")
921lst.write("Missing support per module");
922for module in missing_functions.keys():
923 lst.write("module %s:\n %s\n" % (module, missing_functions[module]))
Daniel Veillard1ba06bb2004-11-04 12:32:18 +0000924
925lst.close()
Daniel Veillardb1b3a3e2004-11-03 23:25:47 +0000926
Daniel Veillard36e5cd52004-11-02 14:52:23 +0000927