Commit d005b9e8 authored by Daniel Veillard's avatar Daniel Veillard
Browse files

more fixes and extending the tests coverage more fixes and hardening

* gentest.py testapi.c: more fixes and extending the tests coverage
* list.c tree.c: more fixes and hardening
Daniel
parent dd6d3008
Wed Nov 3 18:06:44 CET 2004 Daniel Veillard <daniel@veillard.com>
* gentest.py testapi.c: more fixes and extending the tests coverage
* list.c tree.c: more fixes and hardening
Wed Nov 3 15:19:22 CET 2004 Daniel Veillard <daniel@veillard.com>
 
* gentest.py testapi.c: more fixes and extending the tests coverage
......
......@@ -15,7 +15,12 @@ except:
#
skipped_modules = [ "SAX", "SAX2", "xlink", "threads", "globals",
"xpathInternals", "xmlunicode", "parserInternals", "xmlmemory",
"xmlversion", "debugXML", "xmlexports" ]
"xmlversion", "debugXML", "xmlexports",
# temporary
"xmlautomata", "xmlregexp",
]
#
# Some function really need to be skipped for the tests.
......@@ -32,7 +37,11 @@ skipped_functions = [
"xmlStrcat", "xmlStrncat",
# unimplemented
"xmlTextReaderReadInnerXml", "xmlTextReaderReadOuterXml",
"xmlTextReaderReadString"
"xmlTextReaderReadString",
# destructor
"xmlListDelete",
# deprecated
"xmlCatalogGetPublic", "xmlCatalogGetSystem", "xmlEncodeEntities",
]
#
......@@ -232,6 +241,8 @@ def type_convert(str, name, info, module, function, pos):
return('xmlNanoHTTPCtxtPtr')
if string.find(name, "data") != -1:
return('userdata');
if string.find(name, "user") != -1:
return('userdata');
if res == 'xmlNodePtr' and pos != 0:
if (function == 'xmlAddChild' and pos == 2) or \
(function == 'xmlAddChildList' and pos == 2) or \
......@@ -248,7 +259,9 @@ def type_convert(str, name, info, module, function, pos):
known_param_types = [ "int", "const_char_ptr", "const_xmlChar_ptr",
"xmlParserCtxtPtr", "xmlDocPtr", "filepath", "fileoutput",
"xmlNodePtr", "xmlNodePtr_in", "userdata", "xmlChar_ptr",
"xmlTextWriterPtr", "xmlTextReaderPtr" ];
"xmlTextWriterPtr", "xmlTextReaderPtr", "xmlBufferPtr",
"xmlListPtr", "xmlXPathObjectPtr", "xmlHashTablePtr",
]
def is_known_param_type(name):
for type in known_param_types:
......@@ -294,7 +307,7 @@ static void des_const_char_ptr(int no ATTRIBUTE_UNUSED, const char *val ATTRIBUT
#define gen_nb_xmlChar_ptr 2
static xmlChar *gen_xmlChar_ptr(int no) {
if (no == 0) return(&chartab);
if (no == 0) return(&chartab[0]);
return(NULL);
}
static void des_xmlChar_ptr(int no ATTRIBUTE_UNUSED, xmlChar *val ATTRIBUTE_UNUSED) {
......@@ -402,6 +415,55 @@ static void des_xmlTextReaderPtr(int no ATTRIBUTE_UNUSED, xmlTextReaderPtr val)
if (val != NULL) xmlFreeTextReader(val);
}
#define gen_nb_xmlBufferPtr 2
static xmlBufferPtr gen_xmlBufferPtr(int no) {
if (no == 0) return(xmlBufferCreate());
return(NULL);
}
static void des_xmlBufferPtr(int no ATTRIBUTE_UNUSED, xmlBufferPtr val) {
if (val != NULL) {
xmlBufferFree(val);
}
}
#define gen_nb_xmlListPtr 2
static xmlListPtr gen_xmlListPtr(int no) {
if (no == 0) return(xmlListCreate(NULL, NULL));
return(NULL);
}
static void des_xmlListPtr(int no ATTRIBUTE_UNUSED, xmlListPtr val) {
if (val != NULL) {
xmlListDelete(val);
}
}
#define gen_nb_xmlHashTablePtr 2
static xmlHashTablePtr gen_xmlHashTablePtr(int no) {
if (no == 0) return(xmlHashCreate(10));
return(NULL);
}
static void des_xmlHashTablePtr(int no ATTRIBUTE_UNUSED, xmlHashTablePtr val) {
if (val != NULL) {
xmlHashFree(val, NULL);
}
}
#include <libxml/xpathInternals.h>
#define gen_nb_xmlXPathObjectPtr 5
static xmlXPathObjectPtr gen_xmlXPathObjectPtr(int no) {
if (no == 0) return(xmlXPathNewString(BAD_CAST "string object"));
if (no == 1) return(xmlXPathNewFloat(1.1));
if (no == 2) return(xmlXPathNewBoolean(1));
if (no == 3) return(xmlXPathNewNodeSet(NULL));
return(NULL);
}
static void des_xmlXPathObjectPtr(int no ATTRIBUTE_UNUSED, xmlXPathObjectPtr val) {
if (val != NULL) {
xmlXPathFreeObject(val);
}
}
""");
#
......@@ -409,7 +471,7 @@ static void des_xmlTextReaderPtr(int no ATTRIBUTE_UNUSED, xmlTextReaderPtr val)
#
known_return_types = [ "int", "const_char_ptr", "xmlDocPtr", "xmlNodePtr",
"xmlChar_ptr" ];
"xmlChar_ptr", "const_xmlChar_ptr" ];
def is_known_return_type(name):
for type in known_return_types:
......@@ -422,6 +484,8 @@ static void desret_int(int val ATTRIBUTE_UNUSED) {
}
static void desret_const_char_ptr(const char *val ATTRIBUTE_UNUSED) {
}
static void desret_const_xmlChar_ptr(const xmlChar *val ATTRIBUTE_UNUSED) {
}
static void desret_xmlChar_ptr(xmlChar *val) {
if (val != NULL)
xmlFree(val);
......@@ -686,15 +750,32 @@ test_%s(void) {
""" % (module))
print "Generated test for %d modules and %d functions" %(len(modules), nb_tests)
nr = 0
miss = 'none'
nr1 = 0
miss1 = 'none'
nr2 = 0
miss2 = 'none'
nr3 = 0
miss3 = 'none'
for missing in missing_types.keys():
n = len(missing_types[missing])
if n > nr:
miss = missing
nr = n
if nr > 0:
print "most needed type support: %s %d times" % (miss, nr)
if n > nr1:
miss3 = miss2
nr3 = nr2
miss2 = miss1
nr2 = nr1
miss1 = missing
nr1 = n
elif n > nr2:
miss3 = miss2
nr3 = nr2
miss2 = missing
nr2 = n
elif n > nr3:
miss3 = missing
nr3 = n
if nr1 > 0:
print "most needed type support: %s %d times, %s %d and %s %d" % (
miss1, nr1, miss2, nr2, miss3, nr3)
......@@ -99,6 +99,8 @@ xmlListLowerSearch(xmlListPtr l, void *data)
{
xmlLinkPtr lk;
if (l == NULL)
return(NULL);
for(lk = l->sentinel->next;lk != l->sentinel && l->linkCompare(lk->data, data) <0 ;lk = lk->next);
return lk;
}
......@@ -117,6 +119,8 @@ xmlListHigherSearch(xmlListPtr l, void *data)
{
xmlLinkPtr lk;
if (l == NULL)
return(NULL);
for(lk = l->sentinel->prev;lk != l->sentinel && l->linkCompare(lk->data, data) >0 ;lk = lk->prev);
return lk;
}
......@@ -134,6 +138,8 @@ static xmlLinkPtr
xmlListLinkSearch(xmlListPtr l, void *data)
{
xmlLinkPtr lk;
if (l == NULL)
return(NULL);
lk = xmlListLowerSearch(l, data);
if (lk == l->sentinel)
return NULL;
......@@ -157,6 +163,8 @@ static xmlLinkPtr
xmlListLinkReverseSearch(xmlListPtr l, void *data)
{
xmlLinkPtr lk;
if (l == NULL)
return(NULL);
lk = xmlListHigherSearch(l, data);
if (lk == l->sentinel)
return NULL;
......@@ -223,6 +231,8 @@ void *
xmlListSearch(xmlListPtr l, void *data)
{
xmlLinkPtr lk;
if (l == NULL)
return(NULL);
lk = xmlListLinkSearch(l, data);
if (lk)
return (lk->data);
......@@ -242,6 +252,8 @@ void *
xmlListReverseSearch(xmlListPtr l, void *data)
{
xmlLinkPtr lk;
if (l == NULL)
return(NULL);
lk = xmlListLinkReverseSearch(l, data);
if (lk)
return (lk->data);
......@@ -262,6 +274,8 @@ xmlListInsert(xmlListPtr l, void *data)
{
xmlLinkPtr lkPlace, lkNew;
if (l == NULL)
return(1);
lkPlace = xmlListLowerSearch(l, data);
/* Add the new link */
lkNew = (xmlLinkPtr) xmlMalloc(sizeof(xmlLink));
......@@ -292,6 +306,8 @@ int xmlListAppend(xmlListPtr l, void *data)
{
xmlLinkPtr lkPlace, lkNew;
if (l == NULL)
return(1);
lkPlace = xmlListHigherSearch(l, data);
/* Add the new link */
lkNew = (xmlLinkPtr) xmlMalloc(sizeof(xmlLink));
......@@ -338,6 +354,8 @@ xmlListRemoveFirst(xmlListPtr l, void *data)
{
xmlLinkPtr lk;
if (l == NULL)
return(0);
/*Find the first instance of this data */
lk = xmlListLinkSearch(l, data);
if (lk != NULL) {
......@@ -361,6 +379,8 @@ xmlListRemoveLast(xmlListPtr l, void *data)
{
xmlLinkPtr lk;
if (l == NULL)
return(0);
/*Find the last instance of this data */
lk = xmlListLinkReverseSearch(l, data);
if (lk != NULL) {
......@@ -384,6 +404,8 @@ xmlListRemoveAll(xmlListPtr l, void *data)
{
int count=0;
if (l == NULL)
return(0);
while(xmlListRemoveFirst(l, data))
count++;
......@@ -399,8 +421,11 @@ xmlListRemoveAll(xmlListPtr l, void *data)
void
xmlListClear(xmlListPtr l)
{
xmlLinkPtr lk = l->sentinel->next;
xmlLinkPtr lk;
if (l == NULL)
return;
lk = l->sentinel->next;
while(lk != l->sentinel) {
xmlLinkPtr next = lk->next;
......@@ -415,11 +440,13 @@ xmlListClear(xmlListPtr l)
*
* Is the list empty ?
*
* Returns 1 if the list is empty, 0 otherwise
* Returns 1 if the list is empty, 0 if not empty and -1 in case of error
*/
int
xmlListEmpty(xmlListPtr l)
{
if (l == NULL)
return(-1);
return (l->sentinel->next == l->sentinel);
}
......@@ -434,6 +461,8 @@ xmlListEmpty(xmlListPtr l)
xmlLinkPtr
xmlListFront(xmlListPtr l)
{
if (l == NULL)
return(NULL);
return (l->sentinel->next);
}
......@@ -448,6 +477,8 @@ xmlListFront(xmlListPtr l)
xmlLinkPtr
xmlListEnd(xmlListPtr l)
{
if (l == NULL)
return(NULL);
return (l->sentinel->prev);
}
......@@ -457,7 +488,7 @@ xmlListEnd(xmlListPtr l)
*
* Get the number of elements in the list
*
* Returns the number of elements in the list
* Returns the number of elements in the list or -1 in case of error
*/
int
xmlListSize(xmlListPtr l)
......@@ -465,6 +496,8 @@ xmlListSize(xmlListPtr l)
xmlLinkPtr lk;
int count=0;
if (l == NULL)
return(-1);
/* TODO: keep a counter in xmlList instead */
for(lk = l->sentinel->next; lk != l->sentinel; lk = lk->next, count++);
return count;
......@@ -510,6 +543,8 @@ xmlListPushFront(xmlListPtr l, void *data)
{
xmlLinkPtr lkPlace, lkNew;
if (l == NULL)
return(0);
lkPlace = l->sentinel;
/* Add the new link */
lkNew = (xmlLinkPtr) xmlMalloc(sizeof(xmlLink));
......@@ -540,6 +575,8 @@ xmlListPushBack(xmlListPtr l, void *data)
{
xmlLinkPtr lkPlace, lkNew;
if (l == NULL)
return(0);
lkPlace = l->sentinel->prev;
/* Add the new link */
if (NULL ==(lkNew = (xmlLinkPtr )xmlMalloc(sizeof(xmlLink)))) {
......@@ -566,6 +603,8 @@ xmlListPushBack(xmlListPtr l, void *data)
void *
xmlLinkGetData(xmlLinkPtr lk)
{
if (lk == NULL)
return(NULL);
return lk->data;
}
......@@ -576,18 +615,22 @@ xmlLinkGetData(xmlLinkPtr lk)
* Reverse the order of the elements in the list
*/
void
xmlListReverse(xmlListPtr l) {
xmlLinkPtr lk;
xmlLinkPtr lkPrev = l->sentinel;
for(lk = l->sentinel->next; lk != l->sentinel; lk = lk->next) {
xmlListReverse(xmlListPtr l)
{
xmlLinkPtr lk;
xmlLinkPtr lkPrev;
if (l == NULL)
return;
lkPrev = l->sentinel;
for (lk = l->sentinel->next; lk != l->sentinel; lk = lk->next) {
lkPrev->next = lkPrev->prev;
lkPrev->prev = lk;
lkPrev = lk;
}
/* Fix up the last node */
lkPrev->next = lkPrev->prev;
lkPrev->prev = lk;
lkPrev = lk;
}
/* Fix up the last node */
lkPrev->next = lkPrev->prev;
lkPrev->prev = lk;
}
/**
......@@ -601,6 +644,8 @@ xmlListSort(xmlListPtr l)
{
xmlListPtr lTemp;
if (l == NULL)
return;
if(xmlListEmpty(l))
return;
......@@ -631,6 +676,8 @@ void
xmlListWalk(xmlListPtr l, xmlListWalker walker, const void *user) {
xmlLinkPtr lk;
if ((l == NULL) || (walker == NULL))
return;
for(lk = l->sentinel->next; lk != l->sentinel; lk = lk->next) {
if((walker(lk->data, user)) == 0)
break;
......@@ -650,6 +697,8 @@ void
xmlListReverseWalk(xmlListPtr l, xmlListWalker walker, const void *user) {
xmlLinkPtr lk;
if ((l == NULL) || (walker == NULL))
return;
for(lk = l->sentinel->prev; lk != l->sentinel; lk = lk->prev) {
if((walker(lk->data, user)) == 0)
break;
......@@ -683,6 +732,9 @@ xmlListPtr
xmlListDup(const xmlListPtr old)
{
xmlListPtr cur;
if (old == NULL)
return(NULL);
/* Hmmm, how to best deal with allocation issues when copying
* lists. If there is a de-allocator, should responsibility lie with
* the new list or the old list. Surely not both. I'll arbitrarily
......@@ -711,6 +763,8 @@ xmlListCopy(xmlListPtr cur, const xmlListPtr old)
/* Walk the old tree and insert the data into the new one */
xmlLinkPtr lk;
if ((old == NULL) || (cur == NULL))
return(1);
for(lk = old->sentinel->next; lk != old->sentinel; lk = lk->next) {
if (0 !=xmlListInsert(cur, lk->data)) {
xmlListDelete(cur);
......
......@@ -69,10 +69,8 @@ int main(void) {
#include <libxml/valid.h>
#include <libxml/xinclude.h>
#include <libxml/xmlIO.h>
#include <libxml/xmlautomata.h>
#include <libxml/xmlerror.h>
#include <libxml/xmlreader.h>
#include <libxml/xmlregexp.h>
#include <libxml/xmlsave.h>
#include <libxml/xmlschemas.h>
#include <libxml/xmlschemastypes.h>
......@@ -101,10 +99,8 @@ static int test_uri(void);
static int test_valid(void);
static int test_xinclude(void);
static int test_xmlIO(void);
static int test_xmlautomata(void);
static int test_xmlerror(void);
static int test_xmlreader(void);
static int test_xmlregexp(void);
static int test_xmlsave(void);
static int test_xmlschemas(void);
static int test_xmlschemastypes(void);
......@@ -150,7 +146,7 @@ static void des_const_char_ptr(int no ATTRIBUTE_UNUSED, const char *val ATTRIBUT
#define gen_nb_xmlChar_ptr 2
static xmlChar *gen_xmlChar_ptr(int no) {
if (no == 0) return(&chartab);
if (no == 0) return(&chartab[0]);
return(NULL);
}
static void des_xmlChar_ptr(int no ATTRIBUTE_UNUSED, xmlChar *val ATTRIBUTE_UNUSED) {
......@@ -258,11 +254,62 @@ static void des_xmlTextReaderPtr(int no ATTRIBUTE_UNUSED, xmlTextReaderPtr val)
if (val != NULL) xmlFreeTextReader(val);
}
#define gen_nb_xmlBufferPtr 2
static xmlBufferPtr gen_xmlBufferPtr(int no) {
if (no == 0) return(xmlBufferCreate());
return(NULL);
}
static void des_xmlBufferPtr(int no ATTRIBUTE_UNUSED, xmlBufferPtr val) {
if (val != NULL) {
xmlBufferFree(val);
}
}
#define gen_nb_xmlListPtr 2
static xmlListPtr gen_xmlListPtr(int no) {
if (no == 0) return(xmlListCreate(NULL, NULL));
return(NULL);
}
static void des_xmlListPtr(int no ATTRIBUTE_UNUSED, xmlListPtr val) {
if (val != NULL) {
xmlListDelete(val);
}
}
#define gen_nb_xmlHashTablePtr 2
static xmlHashTablePtr gen_xmlHashTablePtr(int no) {
if (no == 0) return(xmlHashCreate(10));
return(NULL);
}
static void des_xmlHashTablePtr(int no ATTRIBUTE_UNUSED, xmlHashTablePtr val) {
if (val != NULL) {
xmlHashFree(val, NULL);
}
}
#include <libxml/xpathInternals.h>
#define gen_nb_xmlXPathObjectPtr 5
static xmlXPathObjectPtr gen_xmlXPathObjectPtr(int no) {
if (no == 0) return(xmlXPathNewString(BAD_CAST "string object"));
if (no == 1) return(xmlXPathNewFloat(1.1));
if (no == 2) return(xmlXPathNewBoolean(1));
if (no == 3) return(xmlXPathNewNodeSet(NULL));
return(NULL);
}
static void des_xmlXPathObjectPtr(int no ATTRIBUTE_UNUSED, xmlXPathObjectPtr val) {
if (val != NULL) {
xmlXPathFreeObject(val);
}
}
static void desret_int(int val ATTRIBUTE_UNUSED) {
}
static void desret_const_char_ptr(const char *val ATTRIBUTE_UNUSED) {
}
static void desret_const_xmlChar_ptr(const xmlChar *val ATTRIBUTE_UNUSED) {
}
static void desret_xmlChar_ptr(xmlChar *val) {
if (val != NULL)
xmlFree(val);
......@@ -309,10 +356,8 @@ testlibxml2(void)
ret += test_valid();
ret += test_xinclude();
ret += test_xmlIO();
ret += test_xmlautomata();
ret += test_xmlerror();
ret += test_xmlreader();
ret += test_xmlregexp();
ret += test_xmlsave();
ret += test_xmlschemas();
ret += test_xmlschemastypes();
......@@ -1366,8 +1411,31 @@ static int
test_htmlGetMetaEncoding(void) {
int ret = 0;
#ifdef LIBXML_HTML_ENABLED
int mem_base;
const xmlChar * ret_val;
htmlDocPtr doc; /* the document */
int n_doc;
for (n_doc = 0;n_doc < gen_nb_xmlDocPtr;n_doc++) {
mem_base = xmlMemBlocks();
doc = gen_xmlDocPtr(n_doc);
ret_val = htmlGetMetaEncoding(doc);
desret_const_xmlChar_ptr(ret_val);
call_tests++;
des_xmlDocPtr(n_doc, doc);
xmlResetLastError();
if (mem_base != xmlMemBlocks()) {
printf("Leak of %d blocks found in htmlGetMetaEncoding",
xmlMemBlocks() - mem_base);
ret++;
printf(" %d", n_doc);
printf("\n");
}
}
#endif
/* missing type support */
return(ret);
}
......@@ -1489,8 +1557,47 @@ static int
test_htmlNodeDump(void) {
int ret = 0;
#ifdef LIBXML_HTML_ENABLED
#ifdef LIBXML_OUTPUT_ENABLED
int mem_base;
int ret_val;
xmlBufferPtr buf; /* the HTML buffer output */
int n_buf;
xmlDocPtr doc; /* the document */
int n_doc;
xmlNodePtr cur; /* the current node */
int n_cur;
for (n_buf = 0;n_buf < gen_nb_xmlBufferPtr;n_buf++) {
for (n_doc = 0;n_doc < gen_nb_xmlDocPtr;n_doc++) {
for (n_cur = 0;n_cur < gen_nb_xmlNodePtr;n_cur++) {
mem_base = xmlMemBlocks();
buf = gen_xmlBufferPtr(n_buf);
doc = gen_xmlDocPtr(n_doc);
cur = gen_xmlNodePtr(n_cur);
ret_val = htmlNodeDump(buf, doc, cur);
desret_int(ret_val);
call_tests++;
des_xmlBufferPtr(n_buf, buf);
des_xmlDocPtr(n_doc, doc);
des_xmlNodePtr(n_cur, cur);
xmlResetLastError();
if (mem_base != xmlMemBlocks()) {
printf("Leak of %d blocks found in htmlNodeDump",
xmlMemBlocks() - mem_base);
ret++;
printf(" %d", n_buf);
printf(" %d", n_doc);
printf(" %d", n_cur);
printf("\n");
}
}
}
}
#endif
#endif
/* missing type support */
return(ret);
}
......@@ -1984,26 +2091,6 @@ test_xmlCatalogGetDefaults(void) {
}
static int
test_xmlCatalogGetPublic(void) {
int ret = 0;
/* missing type support */
return(ret);
}
static int
test_xmlCatalogGetSystem(void) {
int ret = 0;
/* missing type support */
return(ret);
}
static int
test_xmlCatalogIsEmpty(void) {
int ret = 0;
......@@ -2410,8 +2497,6 @@ test_catalog(void) {
ret += test_xmlCatalogConvert();
ret += test_xmlCatalogDump();
ret += test_xmlCatalogGetDefaults();
ret += test_xmlCatalogGetPublic();
ret += test_xmlCatalogGetSystem();
ret += test_xmlCatalogIsEmpty();
ret += test_xmlCatalogLocalResolve();