mirror of
https://github.com/GNOME/libxml2.git
synced 2025-05-09 05:11:41 +08:00
test: Make gentest.py use Doxygen XML
This adds Python code to look up the required feature macros for a symbol in tools/xmlmod.py.
This commit is contained in:
parent
bbe5827c94
commit
97f3ec7708
@ -153,10 +153,8 @@ testdso_la_SOURCES = testdso.c
|
|||||||
testdso_la_LDFLAGS = $(AM_LDFLAGS) \
|
testdso_la_LDFLAGS = $(AM_LDFLAGS) \
|
||||||
-module -no-undefined -avoid-version -rpath $(libdir)
|
-module -no-undefined -avoid-version -rpath $(libdir)
|
||||||
|
|
||||||
# that one forces the rebuild when "make rebuild" is run on doc/
|
|
||||||
rebuild_testapi:
|
rebuild_testapi:
|
||||||
-@(if [ "$(PYTHON)" != "" ] ; then \
|
cd $(srcdir) && python3 tools/gentest.py $(abs_builddir)
|
||||||
$(PYTHON) $(srcdir)/tools/gentest.py $(srcdir) ; fi )
|
|
||||||
|
|
||||||
testapi_SOURCES=testapi.c
|
testapi_SOURCES=testapi.c
|
||||||
testapi_DEPENDENCIES = $(DEPS)
|
testapi_DEPENDENCIES = $(DEPS)
|
||||||
@ -204,7 +202,7 @@ CLEANFILES = missing.lst runsuite.log runxmlconf.log test.out \
|
|||||||
EXTRA_DIST = Copyright libxml2-config.cmake.in autogen.sh \
|
EXTRA_DIST = Copyright libxml2-config.cmake.in autogen.sh \
|
||||||
libxml.h \
|
libxml.h \
|
||||||
html5ent.inc iso8859x.inc \
|
html5ent.inc iso8859x.inc \
|
||||||
tools/gentest.py \
|
tools/gentest.py tools/xmlmod.py \
|
||||||
tools/genChRanges.py tools/genEscape.py tools/genUnicode.py \
|
tools/genChRanges.py tools/genEscape.py tools/genUnicode.py \
|
||||||
timsort.h \
|
timsort.h \
|
||||||
README.zOS README.md \
|
README.zOS README.md \
|
||||||
|
32
testapi.c
32
testapi.c
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* testapi.c: libxml2 API tester program.
|
* testapi.c: libxml2 API tester program.
|
||||||
*
|
*
|
||||||
* Automatically generated by gentest.py from libxml2-api.xml
|
* Automatically generated by gentest.py
|
||||||
*
|
*
|
||||||
* See Copyright for the status of this software.
|
* See Copyright for the status of this software.
|
||||||
*/
|
*/
|
||||||
@ -41,6 +41,7 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
|
|||||||
xmlInitParser();
|
xmlInitParser();
|
||||||
xmlSetStructuredErrorFunc(NULL, ignoreError);
|
xmlSetStructuredErrorFunc(NULL, ignoreError);
|
||||||
|
|
||||||
|
xmlFreeParserInputBuffer(__xmlParserInputBufferCreateFilename(NULL, 0));
|
||||||
xmlAddAttributeDecl(NULL, NULL, NULL, NULL, NULL, 0, 0, NULL, NULL);
|
xmlAddAttributeDecl(NULL, NULL, NULL, NULL, NULL, 0, 0, NULL, NULL);
|
||||||
xmlFreeNode(xmlAddChild(NULL, NULL));
|
xmlFreeNode(xmlAddChild(NULL, NULL));
|
||||||
xmlFreeNode(xmlAddChildList(NULL, NULL));
|
xmlFreeNode(xmlAddChildList(NULL, NULL));
|
||||||
@ -728,34 +729,6 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
|
|||||||
#endif /* LIBXML_PUSH_ENABLED */
|
#endif /* LIBXML_PUSH_ENABLED */
|
||||||
#endif /* LIBXML_HTML_ENABLED */
|
#endif /* LIBXML_HTML_ENABLED */
|
||||||
|
|
||||||
#ifdef LIBXML_HTTP_ENABLED
|
|
||||||
xmlIOHTTPClose(NULL);
|
|
||||||
xmlIOHTTPMatch(NULL);
|
|
||||||
xmlIOHTTPOpen(NULL);
|
|
||||||
xmlIOHTTPRead(NULL, NULL, 0);
|
|
||||||
xmlNanoHTTPAuthHeader(NULL);
|
|
||||||
xmlNanoHTTPCleanup();
|
|
||||||
xmlNanoHTTPClose(NULL);
|
|
||||||
xmlNanoHTTPContentLength(NULL);
|
|
||||||
xmlNanoHTTPEncoding(NULL);
|
|
||||||
xmlNanoHTTPFetch(NULL, NULL, NULL);
|
|
||||||
xmlNanoHTTPInit();
|
|
||||||
xmlNanoHTTPMethod(NULL, NULL, NULL, NULL, NULL, 0);
|
|
||||||
xmlNanoHTTPMethodRedir(NULL, NULL, NULL, NULL, NULL, NULL, 0);
|
|
||||||
xmlNanoHTTPMimeType(NULL);
|
|
||||||
xmlNanoHTTPOpen(NULL, NULL);
|
|
||||||
xmlNanoHTTPOpenRedir(NULL, NULL, NULL);
|
|
||||||
xmlNanoHTTPRead(NULL, NULL, 0);
|
|
||||||
xmlNanoHTTPRedir(NULL);
|
|
||||||
xmlNanoHTTPReturnCode(NULL);
|
|
||||||
xmlNanoHTTPScanProxy(NULL);
|
|
||||||
#ifdef LIBXML_OUTPUT_ENABLED
|
|
||||||
xmlIOHTTPOpenW(NULL, 0);
|
|
||||||
xmlNanoHTTPSave(NULL, NULL);
|
|
||||||
xmlRegisterHTTPPostCallbacks();
|
|
||||||
#endif /* LIBXML_OUTPUT_ENABLED */
|
|
||||||
#endif /* LIBXML_HTTP_ENABLED */
|
|
||||||
|
|
||||||
#ifdef LIBXML_MODULES_ENABLED
|
#ifdef LIBXML_MODULES_ENABLED
|
||||||
xmlModuleClose(NULL);
|
xmlModuleClose(NULL);
|
||||||
xmlModuleFree(NULL);
|
xmlModuleFree(NULL);
|
||||||
@ -764,6 +737,7 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
|
|||||||
#endif /* LIBXML_MODULES_ENABLED */
|
#endif /* LIBXML_MODULES_ENABLED */
|
||||||
|
|
||||||
#ifdef LIBXML_OUTPUT_ENABLED
|
#ifdef LIBXML_OUTPUT_ENABLED
|
||||||
|
xmlOutputBufferClose(__xmlOutputBufferCreateFilename(NULL, NULL, 0));
|
||||||
xmlOutputBufferClose(xmlAllocOutputBuffer(NULL));
|
xmlOutputBufferClose(xmlAllocOutputBuffer(NULL));
|
||||||
xmlAttrSerializeTxtContent(NULL, NULL, NULL, NULL);
|
xmlAttrSerializeTxtContent(NULL, NULL, NULL, NULL);
|
||||||
xmlBufNodeDump(NULL, NULL, NULL, 0, 0);
|
xmlBufNodeDump(NULL, NULL, NULL, 0, 0);
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import xml.etree.ElementTree as etree
|
import xml.etree.ElementTree as etree
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -133,36 +134,44 @@ blockList = {
|
|||||||
# Parse document
|
# Parse document
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
srcPref = sys.argv[1] + '/'
|
buildDir = sys.argv[1]
|
||||||
else:
|
else:
|
||||||
srcPref = ''
|
buildDir = '.'
|
||||||
|
|
||||||
doc = etree.parse(srcPref + 'doc/libxml2-api.xml')
|
xmlDocDir = buildDir + '/doc/xml'
|
||||||
|
|
||||||
# Create map of symbols to filenames
|
|
||||||
|
|
||||||
filenames = {}
|
filenames = {}
|
||||||
|
|
||||||
for file in doc.find('files').findall('file'):
|
|
||||||
filename = file.get('name')
|
|
||||||
|
|
||||||
for export in file.findall('exports'):
|
|
||||||
filenames[export.get('symbol')] = filename
|
|
||||||
|
|
||||||
# Process functions
|
|
||||||
|
|
||||||
functions = {}
|
functions = {}
|
||||||
|
|
||||||
for func in doc.find('symbols').findall('function'):
|
for file in os.listdir(xmlDocDir):
|
||||||
name = func.get('name')
|
if not file.endswith('_8h.xml'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
doc = etree.parse(xmlDocDir + '/' + file)
|
||||||
|
|
||||||
|
compound = doc.find('compounddef')
|
||||||
|
module = compound.find('compoundname').text
|
||||||
|
if not module.endswith('.h'):
|
||||||
|
continue
|
||||||
|
module = module[:-2]
|
||||||
|
|
||||||
|
for section in compound.findall('sectiondef'):
|
||||||
|
if section.get('kind') != 'func':
|
||||||
|
continue
|
||||||
|
|
||||||
|
for func in section.findall('memberdef'):
|
||||||
|
name = func.find('name').text
|
||||||
if name in blockList:
|
if name in blockList:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
module1, module2 = xmlmod.findModules(filenames[name], name)
|
module1, module2 = xmlmod.findModules(module, name)
|
||||||
|
|
||||||
cargs = []
|
cargs = []
|
||||||
for arg in func.findall('arg'):
|
for arg in func.findall('param'):
|
||||||
atype = arg.get('type')
|
atype = etree.tostring(arg.find('type'),
|
||||||
|
method='text', encoding='unicode').rstrip()
|
||||||
|
if atype == 'void':
|
||||||
|
continue
|
||||||
if re.search(r'(Ptr|\*)$', atype):
|
if re.search(r'(Ptr|\*)$', atype):
|
||||||
cargs.append('NULL')
|
cargs.append('NULL')
|
||||||
else:
|
else:
|
||||||
@ -175,28 +184,29 @@ for func in doc.find('symbols').findall('function'):
|
|||||||
|
|
||||||
mmfunc = mfunc.get(module2)
|
mmfunc = mfunc.get(module2)
|
||||||
if mmfunc is None:
|
if mmfunc is None:
|
||||||
mmfunc = []
|
mmfunc = {}
|
||||||
mfunc[module2] = mmfunc
|
mfunc[module2] = mmfunc
|
||||||
|
|
||||||
code = f'{name}({', '.join(cargs)})'
|
code = f'{name}({', '.join(cargs)})'
|
||||||
|
|
||||||
rtype = func.find('return').get('type')
|
rtype = etree.tostring(func.find('type'),
|
||||||
|
method='text', encoding='unicode').rstrip()
|
||||||
dtor = dtors.get(rtype)
|
dtor = dtors.get(rtype)
|
||||||
if dtor is not None:
|
if dtor is not None:
|
||||||
code = f'{dtor}({code})'
|
code = f'{dtor}({code})'
|
||||||
elif rtype == 'xmlHashTablePtr':
|
elif rtype == 'xmlHashTablePtr':
|
||||||
code = f'xmlHashFree({code}, NULL)'
|
code = f'xmlHashFree({code}, NULL)'
|
||||||
|
|
||||||
mmfunc.append(f' {code};')
|
mmfunc[name] = f' {code};\n'
|
||||||
|
|
||||||
# Write output
|
# Write output
|
||||||
|
|
||||||
test = open(srcPref + 'testapi.c', 'w')
|
test = open('testapi.c', 'w')
|
||||||
|
|
||||||
test.write("""/*
|
test.write("""/*
|
||||||
* testapi.c: libxml2 API tester program.
|
* testapi.c: libxml2 API tester program.
|
||||||
*
|
*
|
||||||
* Automatically generated by gentest.py from libxml2-api.xml
|
* Automatically generated by gentest.py
|
||||||
*
|
*
|
||||||
* See Copyright for the status of this software.
|
* See Copyright for the status of this software.
|
||||||
*/
|
*/
|
||||||
@ -250,8 +260,8 @@ for module1 in sorted(functions.keys()):
|
|||||||
if module2 != '':
|
if module2 != '':
|
||||||
test.write(f'#ifdef LIBXML_{module2}_ENABLED\n')
|
test.write(f'#ifdef LIBXML_{module2}_ENABLED\n')
|
||||||
|
|
||||||
for code in mmfunc:
|
for name in sorted(mmfunc.keys()):
|
||||||
test.write(code + '\n')
|
test.write(mmfunc[name])
|
||||||
|
|
||||||
if module2 != '':
|
if module2 != '':
|
||||||
test.write(f'#endif /* LIBXML_{module2}_ENABLED */\n')
|
test.write(f'#endif /* LIBXML_{module2}_ENABLED */\n')
|
||||||
|
@ -42,6 +42,7 @@ symbolMap1 = {
|
|||||||
|
|
||||||
'xmlRegisterHTTPPostCallbacks': 'HTTP',
|
'xmlRegisterHTTPPostCallbacks': 'HTTP',
|
||||||
|
|
||||||
|
'__xmlOutputBufferCreateFilename': 'OUTPUT',
|
||||||
'xmlAttrSerializeTxtContent': 'OUTPUT',
|
'xmlAttrSerializeTxtContent': 'OUTPUT',
|
||||||
'xmlUTF8ToIsolat1': 'OUTPUT',
|
'xmlUTF8ToIsolat1': 'OUTPUT',
|
||||||
'xmlSprintfElementContent': 'OUTPUT',
|
'xmlSprintfElementContent': 'OUTPUT',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user