Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 1 | #!/usr/bin/python -u |
| 2 | # |
| 3 | # generate a tester program for the API |
| 4 | # |
| 5 | import sys |
| 6 | import string |
| 7 | try: |
| 8 | import libxml2 |
| 9 | except: |
| 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 | # |
| 16 | skipped_modules = [ "SAX", "SAX2", "xlink", "threads", "globals", |
| 17 | "xpathInternals", "xmlunicode", "parserInternals", "xmlmemory", |
Daniel Veillard | b1b3a3e | 2004-11-03 23:25:47 +0000 | [diff] [blame] | 18 | "xmlversion", "debugXML", "xmlexports", "DOCBparser", |
Daniel Veillard | d005b9e | 2004-11-03 17:07:05 +0000 | [diff] [blame] | 19 | |
| 20 | # temporary |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 21 | "xmlautomata", "xmlregexp", "c14n", |
Daniel Veillard | d005b9e | 2004-11-03 17:07:05 +0000 | [diff] [blame] | 22 | |
| 23 | ] |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 24 | |
| 25 | # |
| 26 | # Some function really need to be skipped for the tests. |
| 27 | # |
Daniel Veillard | dd6d300 | 2004-11-03 14:20:29 +0000 | [diff] [blame] | 28 | skipped_functions = [ |
| 29 | # block on I/O |
| 30 | "xmlFdRead", "xmlReadFd", "xmlCtxtReadFd", |
| 31 | "htmlFdRead", "htmlReadFd", "htmlCtxtReadFd", |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 32 | "xmlReaderNewFd", "xmlReaderForFd", |
Daniel Veillard | b1b3a3e | 2004-11-03 23:25:47 +0000 | [diff] [blame] | 33 | "xmlIORead", "xmlReadIO", "xmlCtxtReadIO", |
| 34 | "htmlIORead", "htmlReadIO", "htmlCtxtReadIO", |
| 35 | "xmlReaderNewIO", |
Daniel Veillard | dd6d300 | 2004-11-03 14:20:29 +0000 | [diff] [blame] | 36 | # 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 Veillard | b1b3a3e | 2004-11-03 23:25:47 +0000 | [diff] [blame] | 40 | "xmlStrcat", "xmlStrncat", "xmlCatalogAddLocal", |
Daniel Veillard | dd6d300 | 2004-11-03 14:20:29 +0000 | [diff] [blame] | 41 | # unimplemented |
| 42 | "xmlTextReaderReadInnerXml", "xmlTextReaderReadOuterXml", |
Daniel Veillard | d005b9e | 2004-11-03 17:07:05 +0000 | [diff] [blame] | 43 | "xmlTextReaderReadString", |
| 44 | # destructor |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 45 | "xmlListDelete", "xmlOutputBufferClose", |
Daniel Veillard | d005b9e | 2004-11-03 17:07:05 +0000 | [diff] [blame] | 46 | # deprecated |
| 47 | "xmlCatalogGetPublic", "xmlCatalogGetSystem", "xmlEncodeEntities", |
Daniel Veillard | b1b3a3e | 2004-11-03 23:25:47 +0000 | [diff] [blame] | 48 | # allocators |
| 49 | "xmlMemFree", |
Daniel Veillard | dd6d300 | 2004-11-03 14:20:29 +0000 | [diff] [blame] | 50 | ] |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 51 | |
| 52 | # |
| 53 | # Those functions have side effect on the global state |
| 54 | # and hence generate errors on memory allocation tests |
| 55 | # |
| 56 | skipped_memcheck = [ "xmlLoadCatalog", "xmlAddEncodingAlias", |
| 57 | "xmlSchemaInitTypes", "xmlNanoFTPProxy", "xmlNanoFTPScanProxy", |
| 58 | "xmlNanoHTTPScanProxy", "xmlResetLastError", "xmlCatalogConvert", |
| 59 | "xmlCatalogRemove", "xmlLoadCatalogs", "xmlCleanupCharEncodingHandlers", |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 60 | "xmlInitCharEncodingHandlers", "xmlCatalogCleanup", |
| 61 | "htmlParseFile" # loads the catalogs |
| 62 | ] |
| 63 | |
| 64 | # |
| 65 | # Extra code needed for some test cases |
| 66 | # |
| 67 | extra_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 Veillard | 8a32fe4 | 2004-11-02 22:10:16 +0000 | [diff] [blame] | 86 | "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 Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 91 | "xmlDictReference": "xmlDictFree(dict);", |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 92 | # 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 Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 98 | } |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 99 | |
| 100 | modules = [] |
| 101 | |
| 102 | def is_skipped_module(name): |
| 103 | for mod in skipped_modules: |
| 104 | if mod == name: |
| 105 | return 1 |
| 106 | return 0 |
| 107 | |
| 108 | def 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 | |
| 117 | def is_skipped_memcheck(name): |
| 118 | for fun in skipped_memcheck: |
| 119 | if fun == name: |
| 120 | return 1 |
| 121 | return 0 |
| 122 | |
| 123 | missing_types = {} |
| 124 | def 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 | # |
| 134 | doc = libxml2.readFile('doc/libxml2-api.xml', None, 0) |
| 135 | if doc == None: |
| 136 | print "Failed to load doc/libxml2-api.xml" |
| 137 | sys.exit(1) |
| 138 | test = open('testapi.c', 'w') |
| 139 | ctxt = doc.xpathNewContext() |
| 140 | headers = ctxt.xpathEval("/api/files/file") |
| 141 | |
| 142 | # |
| 143 | # Generate the test header |
| 144 | # |
| 145 | test.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 Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 157 | #include <libxml/relaxng.h> |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 158 | |
| 159 | static int testlibxml2(void); |
| 160 | |
| 161 | static int generic_errors = 0; |
| 162 | static int call_tests = 0; |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 163 | static int function_tests = 0; |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 164 | |
Daniel Veillard | 348636d | 2004-11-02 22:34:52 +0000 | [diff] [blame] | 165 | static xmlChar chartab[1024] = " chartab\\n"; |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 166 | static int inttab[1024]; |
| 167 | static unsigned long longtab[1024]; |
Daniel Veillard | 8a32fe4 | 2004-11-02 22:10:16 +0000 | [diff] [blame] | 168 | |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 169 | static void |
| 170 | structured_errors(void *userData ATTRIBUTE_UNUSED, |
| 171 | xmlErrorPtr error ATTRIBUTE_UNUSED) { |
| 172 | generic_errors++; |
| 173 | } |
| 174 | |
| 175 | int main(void) { |
| 176 | int ret; |
| 177 | int blocks, mem; |
| 178 | |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 179 | xmlInitParser(); |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 180 | #ifdef LIBXML_SCHEMAS_ENABLED |
Daniel Veillard | dd6d300 | 2004-11-03 14:20:29 +0000 | [diff] [blame] | 181 | xmlRelaxNGInitTypes(); |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 182 | #endif |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 183 | |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 184 | 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 | # |
| 206 | for file in headers: |
| 207 | name = file.xpathEval('string(@name)') |
| 208 | if (name == None) or (name == ''): |
| 209 | continue |
| 210 | |
| 211 | # |
Daniel Veillard | b1b3a3e | 2004-11-03 23:25:47 +0000 | [diff] [blame] | 212 | # 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 Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 219 | # 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 Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 226 | test.write("#include <libxml/%s.h>\n" % name) |
| 227 | modules.append(name) |
| 228 | |
| 229 | # |
| 230 | # Generate the callers signatures |
| 231 | # |
| 232 | for 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 Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 239 | def type_convert(str, name, info, module, function, pos): |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 240 | res = string.replace(str, " *", "_ptr") |
| 241 | res = string.replace(res, " ", "_") |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 242 | res = string.replace(res, "htmlNode", "xmlNode") |
| 243 | res = string.replace(res, "htmlDoc", "xmlDoc") |
| 244 | res = string.replace(res, "htmlParser", "xmlParser") |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 245 | 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 Veillard | b1b3a3e | 2004-11-03 23:25:47 +0000 | [diff] [blame] | 258 | if function == 'xmlNanoFTPNewCtxt': |
| 259 | return('xmlNanoFTPCtxtPtr') |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 260 | if module == 'nanohttp' and name == 'ctx': |
| 261 | return('xmlNanoHTTPCtxtPtr') |
Daniel Veillard | b1b3a3e | 2004-11-03 23:25:47 +0000 | [diff] [blame] | 262 | if function == 'xmlIOHTTPOpenW': |
| 263 | return('xmlNanoHTTPCtxtPtr') |
Daniel Veillard | 8a32fe4 | 2004-11-02 22:10:16 +0000 | [diff] [blame] | 264 | if string.find(name, "data") != -1: |
| 265 | return('userdata'); |
Daniel Veillard | d005b9e | 2004-11-03 17:07:05 +0000 | [diff] [blame] | 266 | if string.find(name, "user") != -1: |
| 267 | return('userdata'); |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 268 | if res == 'xmlDoc_ptr': |
| 269 | res = 'xmlDocPtr'; |
| 270 | if res == 'xmlNode_ptr': |
| 271 | res = 'xmlNodePtr'; |
| 272 | if res == 'xmlDict_ptr': |
| 273 | res = 'xmlDictPtr'; |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 274 | 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 Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 284 | |
| 285 | return res |
| 286 | |
| 287 | known_param_types = [ "int", "const_char_ptr", "const_xmlChar_ptr", |
Daniel Veillard | e43cc57 | 2004-11-03 11:50:29 +0000 | [diff] [blame] | 288 | "xmlParserCtxtPtr", "xmlDocPtr", "filepath", "fileoutput", |
| 289 | "xmlNodePtr", "xmlNodePtr_in", "userdata", "xmlChar_ptr", |
Daniel Veillard | d005b9e | 2004-11-03 17:07:05 +0000 | [diff] [blame] | 290 | "xmlTextWriterPtr", "xmlTextReaderPtr", "xmlBufferPtr", |
Daniel Veillard | c0be74b | 2004-11-03 19:16:55 +0000 | [diff] [blame] | 291 | "xmlListPtr", "xmlXPathObjectPtr", "xmlHashTablePtr", "xmlValidCtxtPtr", |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 292 | "void_ptr", "xmlOutputBufferPtr", "xmlCharEncoding", |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 293 | "unsigned_int", "long", "unsigned_long", "const_void_ptr", |
| 294 | "unsigned_long_ptr", "int_ptr", "FILE_ptr", "xmlDictPtr", |
Daniel Veillard | d005b9e | 2004-11-03 17:07:05 +0000 | [diff] [blame] | 295 | ] |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 296 | |
| 297 | def is_known_param_type(name): |
| 298 | for type in known_param_types: |
| 299 | if type == name: |
| 300 | return 1 |
| 301 | return 0 |
| 302 | |
| 303 | test.write(""" |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 304 | #define gen_nb_void_ptr 2 |
Daniel Veillard | b1b3a3e | 2004-11-03 23:25:47 +0000 | [diff] [blame] | 305 | |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 306 | static void *gen_void_ptr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | b1b3a3e | 2004-11-03 23:25:47 +0000 | [diff] [blame] | 307 | return(NULL); |
| 308 | } |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 309 | static void des_void_ptr(int no ATTRIBUTE_UNUSED, void *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | b1b3a3e | 2004-11-03 23:25:47 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 312 | #define gen_nb_const_void_ptr 2 |
| 313 | |
| 314 | static 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 | } |
| 318 | static void des_const_void_ptr(int no ATTRIBUTE_UNUSED, const void *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { |
| 319 | } |
| 320 | |
Daniel Veillard | 8a32fe4 | 2004-11-02 22:10:16 +0000 | [diff] [blame] | 321 | #define gen_nb_userdata 3 |
| 322 | |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 323 | static void *gen_userdata(int no, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | 8a32fe4 | 2004-11-02 22:10:16 +0000 | [diff] [blame] | 324 | if (no == 0) return((void *) &call_tests); |
| 325 | if (no == 1) return((void *) -1); |
| 326 | return(NULL); |
| 327 | } |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 328 | static void des_userdata(int no ATTRIBUTE_UNUSED, void *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | 8a32fe4 | 2004-11-02 22:10:16 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 332 | #define gen_nb_int 4 |
| 333 | |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 334 | static 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 | |
| 342 | static void des_int(int no ATTRIBUTE_UNUSED, int val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { |
| 343 | } |
| 344 | |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 345 | #define gen_nb_long 4 |
| 346 | |
| 347 | static 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 | |
| 355 | static void des_long(int no ATTRIBUTE_UNUSED, long val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { |
| 356 | } |
| 357 | |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 358 | #define gen_nb_unsigned_int 3 |
| 359 | |
| 360 | static unsigned int gen_unsigned_int(int no, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 361 | if (no == 0) return(0); |
| 362 | if (no == 1) return(1); |
| 363 | if (no == 2) return(122); |
| 364 | return(-1); |
| 365 | } |
| 366 | |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 367 | static void des_unsigned_int(int no ATTRIBUTE_UNUSED, unsigned int val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 368 | } |
| 369 | |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 370 | #define gen_nb_unsigned_long 3 |
| 371 | |
| 372 | static 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 | |
| 379 | static 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 | |
| 384 | static unsigned long *gen_unsigned_long_ptr(int no, int nr) { |
| 385 | if (no == 0) return(&longtab[nr]); |
| 386 | return(NULL); |
| 387 | } |
| 388 | |
| 389 | static 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 | |
| 394 | static int *gen_int_ptr(int no, int nr) { |
| 395 | if (no == 0) return(&inttab[nr]); |
| 396 | return(NULL); |
| 397 | } |
| 398 | |
| 399 | static void des_int_ptr(int no ATTRIBUTE_UNUSED, int *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { |
| 400 | } |
| 401 | |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 402 | #define gen_nb_const_char_ptr 4 |
| 403 | |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 404 | static const char *gen_const_char_ptr(int no, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 405 | if (no == 0) return("foo"); |
| 406 | if (no == 1) return("<foo/>"); |
| 407 | if (no == 2) return("test/ent2"); |
| 408 | return(NULL); |
| 409 | } |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 410 | static void des_const_char_ptr(int no ATTRIBUTE_UNUSED, const char *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Daniel Veillard | 8a32fe4 | 2004-11-02 22:10:16 +0000 | [diff] [blame] | 413 | #define gen_nb_xmlChar_ptr 2 |
| 414 | |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 415 | static xmlChar *gen_xmlChar_ptr(int no, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | d005b9e | 2004-11-03 17:07:05 +0000 | [diff] [blame] | 416 | if (no == 0) return(&chartab[0]); |
Daniel Veillard | 8a32fe4 | 2004-11-02 22:10:16 +0000 | [diff] [blame] | 417 | return(NULL); |
| 418 | } |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 419 | static void des_xmlChar_ptr(int no ATTRIBUTE_UNUSED, xmlChar *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | 8a32fe4 | 2004-11-02 22:10:16 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 422 | #define gen_nb_FILE_ptr 2 |
| 423 | |
| 424 | static FILE *gen_FILE_ptr(int no, int nr ATTRIBUTE_UNUSED) { |
| 425 | if (no == 0) return(fopen("test.out", "a+")); |
| 426 | return(NULL); |
| 427 | } |
| 428 | static void des_FILE_ptr(int no ATTRIBUTE_UNUSED, FILE *val, int nr ATTRIBUTE_UNUSED) { |
| 429 | if (val != NULL) fclose(val); |
| 430 | } |
| 431 | |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 432 | #define gen_nb_const_xmlChar_ptr 5 |
| 433 | |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 434 | static const xmlChar *gen_const_xmlChar_ptr(int no, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 435 | 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 Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 441 | static void des_const_xmlChar_ptr(int no ATTRIBUTE_UNUSED, const xmlChar *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | #define gen_nb_filepath 8 |
| 445 | |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 446 | static const char *gen_filepath(int no, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 447 | 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 Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 451 | if (no == 4) return("test/valid/dtds/xhtml1-strict.dtd"); |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 452 | if (no == 5) return("http://missing.example.org/"); |
| 453 | if (no == 6) return("http://missing. example.org/"); |
| 454 | return(NULL); |
| 455 | } |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 456 | static void des_filepath(int no ATTRIBUTE_UNUSED, const char *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | #define gen_nb_fileoutput 6 |
| 460 | |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 461 | static const char *gen_fileoutput(int no, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 462 | 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 Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 469 | static void des_fileoutput(int no ATTRIBUTE_UNUSED, const char *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | #define gen_nb_xmlParserCtxtPtr 2 |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 473 | static xmlParserCtxtPtr gen_xmlParserCtxtPtr(int no, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 474 | if (no == 0) return(xmlNewParserCtxt()); |
| 475 | return(NULL); |
| 476 | } |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 477 | static void des_xmlParserCtxtPtr(int no ATTRIBUTE_UNUSED, xmlParserCtxtPtr val, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 478 | if (val != NULL) |
| 479 | xmlFreeParserCtxt(val); |
| 480 | } |
| 481 | |
Daniel Veillard | c0be74b | 2004-11-03 19:16:55 +0000 | [diff] [blame] | 482 | #define gen_nb_xmlValidCtxtPtr 2 |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 483 | static xmlValidCtxtPtr gen_xmlValidCtxtPtr(int no, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | c0be74b | 2004-11-03 19:16:55 +0000 | [diff] [blame] | 484 | if (no == 0) return(xmlNewValidCtxt()); |
| 485 | return(NULL); |
| 486 | } |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 487 | static void des_xmlValidCtxtPtr(int no ATTRIBUTE_UNUSED, xmlValidCtxtPtr val, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | c0be74b | 2004-11-03 19:16:55 +0000 | [diff] [blame] | 488 | if (val != NULL) |
| 489 | xmlFreeValidCtxt(val); |
| 490 | } |
| 491 | |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 492 | #define gen_nb_xmlDocPtr 3 |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 493 | static xmlDocPtr gen_xmlDocPtr(int no, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 494 | if (no == 0) return(xmlNewDoc(BAD_CAST "1.0")); |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 495 | if (no == 1) return(xmlReadMemory("<foo/>", 6, "test", NULL, 0)); |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 496 | return(NULL); |
| 497 | } |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 498 | static void des_xmlDocPtr(int no ATTRIBUTE_UNUSED, xmlDocPtr val, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 499 | if (val != NULL) |
| 500 | xmlFreeDoc(val); |
| 501 | } |
| 502 | |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 503 | #define gen_nb_xmlDictPtr 2 |
| 504 | static xmlDictPtr gen_xmlDictPtr(int no, int nr ATTRIBUTE_UNUSED) { |
| 505 | if (no == 0) return(xmlDictCreate()); |
| 506 | return(NULL); |
| 507 | } |
| 508 | static void des_xmlDictPtr(int no ATTRIBUTE_UNUSED, xmlDictPtr val, int nr ATTRIBUTE_UNUSED) { |
| 509 | if (val != NULL) |
| 510 | xmlDictFree(val); |
| 511 | } |
| 512 | |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 513 | #define gen_nb_xmlNodePtr 2 |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 514 | static xmlNodePtr gen_xmlNodePtr(int no, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 515 | if (no == 0) return(xmlNewPI(BAD_CAST "test", NULL)); |
| 516 | return(NULL); |
| 517 | } |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 518 | static void des_xmlNodePtr(int no ATTRIBUTE_UNUSED, xmlNodePtr val, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 519 | if (val != NULL) { |
| 520 | xmlUnlinkNode(val); |
| 521 | xmlFreeNode(val); |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | #define gen_nb_xmlNodePtr_in 3 |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 526 | static xmlNodePtr gen_xmlNodePtr_in(int no, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 527 | if (no == 0) return(xmlNewPI(BAD_CAST "test", NULL)); |
| 528 | if (no == 0) return(xmlNewText(BAD_CAST "text")); |
| 529 | return(NULL); |
| 530 | } |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 531 | static void des_xmlNodePtr_in(int no ATTRIBUTE_UNUSED, xmlNodePtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 532 | } |
| 533 | |
Daniel Veillard | e43cc57 | 2004-11-03 11:50:29 +0000 | [diff] [blame] | 534 | #define gen_nb_xmlTextWriterPtr 2 |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 535 | static xmlTextWriterPtr gen_xmlTextWriterPtr(int no, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | e43cc57 | 2004-11-03 11:50:29 +0000 | [diff] [blame] | 536 | if (no == 0) return(xmlNewTextWriterFilename("test.out", 0)); |
| 537 | return(NULL); |
| 538 | } |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 539 | static void des_xmlTextWriterPtr(int no ATTRIBUTE_UNUSED, xmlTextWriterPtr val, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | e43cc57 | 2004-11-03 11:50:29 +0000 | [diff] [blame] | 540 | if (val != NULL) xmlFreeTextWriter(val); |
| 541 | } |
| 542 | |
Daniel Veillard | dd6d300 | 2004-11-03 14:20:29 +0000 | [diff] [blame] | 543 | #define gen_nb_xmlTextReaderPtr 4 |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 544 | static xmlTextReaderPtr gen_xmlTextReaderPtr(int no, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | dd6d300 | 2004-11-03 14:20:29 +0000 | [diff] [blame] | 545 | 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 Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 550 | static void des_xmlTextReaderPtr(int no ATTRIBUTE_UNUSED, xmlTextReaderPtr val, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | dd6d300 | 2004-11-03 14:20:29 +0000 | [diff] [blame] | 551 | if (val != NULL) xmlFreeTextReader(val); |
| 552 | } |
| 553 | |
Daniel Veillard | d005b9e | 2004-11-03 17:07:05 +0000 | [diff] [blame] | 554 | #define gen_nb_xmlBufferPtr 2 |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 555 | static xmlBufferPtr gen_xmlBufferPtr(int no, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | d005b9e | 2004-11-03 17:07:05 +0000 | [diff] [blame] | 556 | if (no == 0) return(xmlBufferCreate()); |
| 557 | return(NULL); |
| 558 | } |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 559 | static void des_xmlBufferPtr(int no ATTRIBUTE_UNUSED, xmlBufferPtr val, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | d005b9e | 2004-11-03 17:07:05 +0000 | [diff] [blame] | 560 | if (val != NULL) { |
| 561 | xmlBufferFree(val); |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | #define gen_nb_xmlListPtr 2 |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 566 | static xmlListPtr gen_xmlListPtr(int no, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | d005b9e | 2004-11-03 17:07:05 +0000 | [diff] [blame] | 567 | if (no == 0) return(xmlListCreate(NULL, NULL)); |
| 568 | return(NULL); |
| 569 | } |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 570 | static void des_xmlListPtr(int no ATTRIBUTE_UNUSED, xmlListPtr val, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | d005b9e | 2004-11-03 17:07:05 +0000 | [diff] [blame] | 571 | if (val != NULL) { |
| 572 | xmlListDelete(val); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | #define gen_nb_xmlHashTablePtr 2 |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 577 | static xmlHashTablePtr gen_xmlHashTablePtr(int no, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | d005b9e | 2004-11-03 17:07:05 +0000 | [diff] [blame] | 578 | if (no == 0) return(xmlHashCreate(10)); |
| 579 | return(NULL); |
| 580 | } |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 581 | static void des_xmlHashTablePtr(int no ATTRIBUTE_UNUSED, xmlHashTablePtr val, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | d005b9e | 2004-11-03 17:07:05 +0000 | [diff] [blame] | 582 | if (val != NULL) { |
| 583 | xmlHashFree(val, NULL); |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | #include <libxml/xpathInternals.h> |
| 588 | |
| 589 | #define gen_nb_xmlXPathObjectPtr 5 |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 590 | static xmlXPathObjectPtr gen_xmlXPathObjectPtr(int no, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | d005b9e | 2004-11-03 17:07:05 +0000 | [diff] [blame] | 591 | 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 Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 597 | static void des_xmlXPathObjectPtr(int no ATTRIBUTE_UNUSED, xmlXPathObjectPtr val, int nr ATTRIBUTE_UNUSED) { |
Daniel Veillard | d005b9e | 2004-11-03 17:07:05 +0000 | [diff] [blame] | 598 | if (val != NULL) { |
| 599 | xmlXPathFreeObject(val); |
| 600 | } |
| 601 | } |
| 602 | |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 603 | #define gen_nb_xmlOutputBufferPtr 2 |
| 604 | static xmlOutputBufferPtr gen_xmlOutputBufferPtr(int no, int nr ATTRIBUTE_UNUSED) { |
| 605 | if (no == 0) return(xmlOutputBufferCreateFilename("test.out", NULL, 0)); |
| 606 | return(NULL); |
| 607 | } |
| 608 | static 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 |
| 615 | static 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 | } |
| 621 | static void des_xmlCharEncoding(int no ATTRIBUTE_UNUSED, xmlCharEncoding val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { |
| 622 | } |
| 623 | |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 624 | """); |
| 625 | |
| 626 | # |
| 627 | # Provide the type destructors for the return values |
| 628 | # |
| 629 | |
Daniel Veillard | 8a32fe4 | 2004-11-02 22:10:16 +0000 | [diff] [blame] | 630 | known_return_types = [ "int", "const_char_ptr", "xmlDocPtr", "xmlNodePtr", |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 631 | "xmlChar_ptr", "const_xmlChar_ptr", "void_ptr", |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 632 | "xmlXPathObjectPtr", "xmlCharEncoding", "long", |
| 633 | "const_void_ptr", "double", "xmlTextReaderPtr", |
| 634 | "xmlDictPtr", |
| 635 | ] |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 636 | |
| 637 | def is_known_return_type(name): |
| 638 | for type in known_return_types: |
| 639 | if type == name: |
| 640 | return 1 |
| 641 | return 0 |
| 642 | |
| 643 | test.write(""" |
| 644 | static void desret_int(int val ATTRIBUTE_UNUSED) { |
| 645 | } |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 646 | static void desret_long(long val ATTRIBUTE_UNUSED) { |
| 647 | } |
| 648 | static void desret_double(double val ATTRIBUTE_UNUSED) { |
| 649 | } |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 650 | static void desret_xmlCharEncoding(xmlCharEncoding val ATTRIBUTE_UNUSED) { |
| 651 | } |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 652 | static void desret_const_void_ptr(void *val ATTRIBUTE_UNUSED) { |
| 653 | } |
Daniel Veillard | b1b3a3e | 2004-11-03 23:25:47 +0000 | [diff] [blame] | 654 | static void desret_void_ptr(void *val ATTRIBUTE_UNUSED) { |
| 655 | } |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 656 | static void desret_const_char_ptr(const char *val ATTRIBUTE_UNUSED) { |
| 657 | } |
Daniel Veillard | d005b9e | 2004-11-03 17:07:05 +0000 | [diff] [blame] | 658 | static void desret_const_xmlChar_ptr(const xmlChar *val ATTRIBUTE_UNUSED) { |
| 659 | } |
Daniel Veillard | 8a32fe4 | 2004-11-02 22:10:16 +0000 | [diff] [blame] | 660 | static void desret_xmlChar_ptr(xmlChar *val) { |
| 661 | if (val != NULL) |
| 662 | xmlFree(val); |
| 663 | } |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 664 | static void desret_xmlDocPtr(xmlDocPtr val) { |
| 665 | xmlFreeDoc(val); |
| 666 | } |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 667 | static void desret_xmlDictPtr(xmlDictPtr val) { |
| 668 | xmlDictFree(val); |
| 669 | } |
| 670 | static void desret_xmlTextReaderPtr(xmlTextReaderPtr val) { |
| 671 | xmlFreeTextReader(val); |
| 672 | } |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 673 | static void desret_xmlNodePtr(xmlNodePtr val) { |
| 674 | xmlUnlinkNode(val); |
| 675 | xmlFreeNode(val); |
| 676 | } |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 677 | static void desret_xmlXPathObjectPtr(xmlXPathObjectPtr val) { |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 678 | xmlXPathFreeObject(val); |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 679 | } |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 680 | """); |
| 681 | |
| 682 | # |
| 683 | # Generate the top caller |
| 684 | # |
| 685 | |
| 686 | test.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 | */ |
| 695 | static int |
| 696 | testlibxml2(void) |
| 697 | { |
| 698 | int ret = 0; |
| 699 | |
| 700 | """) |
| 701 | |
| 702 | for module in modules: |
| 703 | test.write(" ret += test_%s();\n" % module) |
| 704 | |
| 705 | test.write(""" |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 706 | printf("Total: %d functions, %d tests, %d errors\\n", |
| 707 | function_tests, call_tests, ret); |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 708 | return(ret); |
| 709 | } |
| 710 | |
| 711 | """) |
| 712 | |
| 713 | # |
| 714 | # How to handle a function |
| 715 | # |
| 716 | nb_tests = 0 |
| 717 | |
| 718 | def 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(""" |
| 729 | static int |
| 730 | test_%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 Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 744 | n = 0 |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 745 | for arg in args: |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 746 | n = n + 1 |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 747 | rtype = arg.xpathEval("string(@type)") |
| 748 | if rtype == 'void': |
| 749 | break; |
| 750 | info = arg.xpathEval("string(@info)") |
| 751 | nam = arg.xpathEval("string(@name)") |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 752 | type = type_convert(rtype, nam, info, module, name, n) |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 753 | 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 Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 766 | type = type_convert(rtype, 'return', info, module, name, 0) |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 767 | 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 Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 821 | i = 0; |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 822 | for arg in t_args: |
| 823 | (nam, type, rtype, info) = arg; |
| 824 | # |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 825 | test.write(" %s = gen_%s(n_%s, %d);\n" % (nam, type, nam, i)) |
| 826 | i = i + 1; |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 827 | |
| 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 Veillard | 8a32fe4 | 2004-11-02 22:10:16 +0000 | [diff] [blame] | 839 | 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 Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 843 | 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 Veillard | 8a32fe4 | 2004-11-02 22:10:16 +0000 | [diff] [blame] | 854 | if extra_post_call.has_key(name): |
| 855 | test.write(" %s\n"% (extra_post_call[name])) |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 856 | |
Daniel Veillard | 8a32fe4 | 2004-11-02 22:10:16 +0000 | [diff] [blame] | 857 | test.write(" call_tests++;\n"); |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 858 | |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 859 | # Free the arguments |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 860 | i = 0; |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 861 | for arg in t_args: |
| 862 | (nam, type, rtype, info) = arg; |
| 863 | # |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 864 | test.write(" des_%s(n_%s, %s, %d);\n" % (type, nam, nam, i)) |
| 865 | i = i + 1; |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 866 | |
| 867 | test.write(" xmlResetLastError();\n"); |
| 868 | # Check the memory usage |
| 869 | if no_mem == 0: |
| 870 | test.write(""" if (mem_base != xmlMemBlocks()) { |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 871 | printf("Leak of %%d blocks found in %s", |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 872 | xmlMemBlocks() - mem_base); |
| 873 | ret++; |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 874 | """ % (name)); |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 875 | 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 Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 880 | |
| 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 Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 894 | function_tests++; |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 895 | return(ret); |
| 896 | } |
| 897 | |
| 898 | """) |
| 899 | |
| 900 | # |
| 901 | # Generate all module callers |
| 902 | # |
| 903 | for 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 Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 912 | i = 0 |
| 913 | nb_tests_old = nb_tests |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 914 | for function in functions: |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 915 | i = i + 1 |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 916 | generate_test(module, function); |
| 917 | |
| 918 | # header |
| 919 | test.write("""static int |
| 920 | test_%s(void) { |
| 921 | int ret = 0; |
| 922 | |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 923 | printf("Testing %s : %d of %d functions ...\\n"); |
| 924 | """ % (module, module, nb_tests - nb_tests_old, i)) |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 925 | |
| 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 | |
| 941 | print "Generated test for %d modules and %d functions" %(len(modules), nb_tests) |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 942 | |
| 943 | missing_list = [] |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 944 | for missing in missing_types.keys(): |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 945 | if missing == 'va_list' or missing == '...': |
Daniel Veillard | b1b3a3e | 2004-11-03 23:25:47 +0000 | [diff] [blame] | 946 | continue; |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 947 | |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 948 | n = len(missing_types[missing]) |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 949 | missing_list.append((n, missing)) |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 950 | |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 951 | def compare_missing(a, b): |
| 952 | return b[0] - a[0] |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 953 | |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame^] | 954 | missing_list.sort(compare_missing) |
| 955 | print "Missing support for %d types see missing.lst" % (len(missing_list)) |
| 956 | lst = open("missing.lst", "w") |
| 957 | for 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 | |
| 968 | lst.close() |
| 969 | test.close() |
Daniel Veillard | b1b3a3e | 2004-11-03 23:25:47 +0000 | [diff] [blame] | 970 | |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 971 | |