1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-12-28 07:21:26 +03:00

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
This commit is contained in:
Daniel Veillard 2004-11-03 17:07:05 +00:00
parent dd6d300896
commit d005b9e89d
5 changed files with 1541 additions and 412 deletions

View File

@ -1,3 +1,8 @@
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

View File

@ -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 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 nr > 0:
print "most needed type support: %s %d times" % (miss, nr)
if nr1 > 0:
print "most needed type support: %s %d times, %s %d and %s %d" % (
miss1, nr1, miss2, nr2, miss3, nr3)

80
list.c
View File

@ -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);

1741
testapi.c

File diff suppressed because it is too large Load Diff

22
tree.c
View File

@ -6688,6 +6688,7 @@ xmlBufferFree(xmlBufferPtr buf) {
*/
void
xmlBufferEmpty(xmlBufferPtr buf) {
if (buf == NULL) return;
if (buf->content == NULL) return;
buf->use = 0;
if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) {
@ -6844,6 +6845,9 @@ xmlBufferResize(xmlBufferPtr buf, unsigned int size)
unsigned int newSize;
xmlChar* rebuf = NULL;
if (buf == NULL)
return(0);
if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return(0);
/* Don't resize if we don't have to */
@ -6909,11 +6913,7 @@ int
xmlBufferAdd(xmlBufferPtr buf, const xmlChar *str, int len) {
unsigned int needSize;
if (str == NULL) {
#ifdef DEBUG_BUFFER
xmlGenericError(xmlGenericErrorContext,
"xmlBufferAdd: str == NULL\n");
#endif
if ((str == NULL) || (buf == NULL)) {
return -1;
}
if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1;
@ -6961,6 +6961,8 @@ int
xmlBufferAddHead(xmlBufferPtr buf, const xmlChar *str, int len) {
unsigned int needSize;
if (buf == NULL)
return(-1);
if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1;
if (str == NULL) {
#ifdef DEBUG_BUFFER
@ -7010,6 +7012,8 @@ xmlBufferAddHead(xmlBufferPtr buf, const xmlChar *str, int len) {
*/
int
xmlBufferCat(xmlBufferPtr buf, const xmlChar *str) {
if (buf == NULL)
return(-1);
if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1;
if (str == NULL) return -1;
return xmlBufferAdd(buf, str, -1);
@ -7029,6 +7033,8 @@ int
xmlBufferCCat(xmlBufferPtr buf, const char *str) {
const char *cur;
if (buf == NULL)
return(-1);
if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1;
if (str == NULL) {
#ifdef DEBUG_BUFFER
@ -7060,6 +7066,8 @@ xmlBufferCCat(xmlBufferPtr buf, const char *str) {
*/
void
xmlBufferWriteCHAR(xmlBufferPtr buf, const xmlChar *string) {
if (buf == NULL)
return;
if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return;
xmlBufferCat(buf, string);
}
@ -7074,6 +7082,8 @@ xmlBufferWriteCHAR(xmlBufferPtr buf, const xmlChar *string) {
*/
void
xmlBufferWriteChar(xmlBufferPtr buf, const char *string) {
if (buf == NULL)
return;
if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return;
xmlBufferCCat(buf, string);
}
@ -7091,6 +7101,8 @@ xmlBufferWriteChar(xmlBufferPtr buf, const char *string) {
void
xmlBufferWriteQuotedString(xmlBufferPtr buf, const xmlChar *string) {
const xmlChar *cur, *base;
if (buf == NULL)
return;
if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return;
if (xmlStrchr(string, '\"')) {
if (xmlStrchr(string, '\'')) {