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

more fixes and extending the tests coverage bunch of cleanups and 2 leaks

* gentest.py testapi.c: more fixes and extending the tests coverage
* valid.c: bunch of cleanups and 2 leaks removed
Daniel
parent d005b9e8
Wed Nov 3 20:16:24 CET 2004 Daniel Veillard <daniel@veillard.com>
* gentest.py testapi.c: more fixes and extending the tests coverage
* valid.c: bunch of cleanups and 2 leaks removed
Wed Nov 3 18:06:44 CET 2004 Daniel Veillard <daniel@veillard.com>
 
* gentest.py testapi.c: more fixes and extending the tests coverage
......
......@@ -260,7 +260,7 @@ known_param_types = [ "int", "const_char_ptr", "const_xmlChar_ptr",
"xmlParserCtxtPtr", "xmlDocPtr", "filepath", "fileoutput",
"xmlNodePtr", "xmlNodePtr_in", "userdata", "xmlChar_ptr",
"xmlTextWriterPtr", "xmlTextReaderPtr", "xmlBufferPtr",
"xmlListPtr", "xmlXPathObjectPtr", "xmlHashTablePtr",
"xmlListPtr", "xmlXPathObjectPtr", "xmlHashTablePtr", "xmlValidCtxtPtr",
]
def is_known_param_type(name):
......@@ -363,6 +363,16 @@ static void des_xmlParserCtxtPtr(int no ATTRIBUTE_UNUSED, xmlParserCtxtPtr val)
xmlFreeParserCtxt(val);
}
#define gen_nb_xmlValidCtxtPtr 2
static xmlValidCtxtPtr gen_xmlValidCtxtPtr(int no) {
if (no == 0) return(xmlNewValidCtxt());
return(NULL);
}
static void des_xmlValidCtxtPtr(int no ATTRIBUTE_UNUSED, xmlValidCtxtPtr val) {
if (val != NULL)
xmlFreeValidCtxt(val);
}
#define gen_nb_xmlDocPtr 3
static xmlDocPtr gen_xmlDocPtr(int no) {
if (no == 0) return(xmlNewDoc(BAD_CAST "1.0"));
......
......@@ -202,6 +202,16 @@ static void des_xmlParserCtxtPtr(int no ATTRIBUTE_UNUSED, xmlParserCtxtPtr val)
xmlFreeParserCtxt(val);
}
#define gen_nb_xmlValidCtxtPtr 2
static xmlValidCtxtPtr gen_xmlValidCtxtPtr(int no) {
if (no == 0) return(xmlNewValidCtxt());
return(NULL);
}
static void des_xmlValidCtxtPtr(int no ATTRIBUTE_UNUSED, xmlValidCtxtPtr val) {
if (val != NULL)
xmlFreeValidCtxt(val);
}
#define gen_nb_xmlDocPtr 3
static xmlDocPtr gen_xmlDocPtr(int no) {
if (no == 0) return(xmlNewDoc(BAD_CAST "1.0"));
......@@ -10948,8 +10958,59 @@ static int
test_xmlValidCtxtNormalizeAttributeValue(void) {
int ret = 0;
#ifdef LIBXML_VALID_ENABLED
int mem_base;
xmlChar * ret_val;
xmlValidCtxtPtr ctxt; /* the validation context or NULL */
int n_ctxt;
xmlDocPtr doc; /* the document */
int n_doc;
xmlNodePtr elem; /* the parent */
int n_elem;
const xmlChar * name; /* the attribute name */
int n_name;
const xmlChar * value; /* the attribute value */
int n_value;
for (n_ctxt = 0;n_ctxt < gen_nb_xmlValidCtxtPtr;n_ctxt++) {
for (n_doc = 0;n_doc < gen_nb_xmlDocPtr;n_doc++) {
for (n_elem = 0;n_elem < gen_nb_xmlNodePtr;n_elem++) {
for (n_name = 0;n_name < gen_nb_const_xmlChar_ptr;n_name++) {
for (n_value = 0;n_value < gen_nb_const_xmlChar_ptr;n_value++) {
mem_base = xmlMemBlocks();
ctxt = gen_xmlValidCtxtPtr(n_ctxt);
doc = gen_xmlDocPtr(n_doc);
elem = gen_xmlNodePtr(n_elem);
name = gen_const_xmlChar_ptr(n_name);
value = gen_const_xmlChar_ptr(n_value);
ret_val = xmlValidCtxtNormalizeAttributeValue(ctxt, doc, elem, name, value);
desret_xmlChar_ptr(ret_val);
call_tests++;
des_xmlValidCtxtPtr(n_ctxt, ctxt);
des_xmlDocPtr(n_doc, doc);
des_xmlNodePtr(n_elem, elem);
des_const_xmlChar_ptr(n_name, name);
des_const_xmlChar_ptr(n_value, value);
xmlResetLastError();
if (mem_base != xmlMemBlocks()) {
printf("Leak of %d blocks found in xmlValidCtxtNormalizeAttributeValue",
xmlMemBlocks() - mem_base);
ret++;
printf(" %d", n_ctxt);
printf(" %d", n_doc);
printf(" %d", n_elem);
printf(" %d", n_name);
printf(" %d", n_value);
printf("\n");
}
}
}
}
}
}
#endif
/* missing type support */
return(ret);
}
......@@ -11052,8 +11113,38 @@ static int
test_xmlValidateDocument(void) {
int ret = 0;
#ifdef LIBXML_VALID_ENABLED
int mem_base;
int ret_val;
xmlValidCtxtPtr ctxt; /* the validation context */
int n_ctxt;
xmlDocPtr doc; /* a document instance */
int n_doc;
for (n_ctxt = 0;n_ctxt < gen_nb_xmlValidCtxtPtr;n_ctxt++) {
for (n_doc = 0;n_doc < gen_nb_xmlDocPtr;n_doc++) {
mem_base = xmlMemBlocks();
ctxt = gen_xmlValidCtxtPtr(n_ctxt);
doc = gen_xmlDocPtr(n_doc);
ret_val = xmlValidateDocument(ctxt, doc);
desret_int(ret_val);
call_tests++;
des_xmlValidCtxtPtr(n_ctxt, ctxt);
des_xmlDocPtr(n_doc, doc);
xmlResetLastError();
if (mem_base != xmlMemBlocks()) {
printf("Leak of %d blocks found in xmlValidateDocument",
xmlMemBlocks() - mem_base);
ret++;
printf(" %d", n_ctxt);
printf(" %d", n_doc);
printf("\n");
}
}
}
#endif
/* missing type support */
return(ret);
}
......@@ -11062,8 +11153,38 @@ static int
test_xmlValidateDocumentFinal(void) {
int ret = 0;
#ifdef LIBXML_VALID_ENABLED
int mem_base;
int ret_val;
xmlValidCtxtPtr ctxt; /* the validation context */
int n_ctxt;
xmlDocPtr doc; /* a document instance */
int n_doc;
for (n_ctxt = 0;n_ctxt < gen_nb_xmlValidCtxtPtr;n_ctxt++) {
for (n_doc = 0;n_doc < gen_nb_xmlDocPtr;n_doc++) {
mem_base = xmlMemBlocks();
ctxt = gen_xmlValidCtxtPtr(n_ctxt);
doc = gen_xmlDocPtr(n_doc);
ret_val = xmlValidateDocumentFinal(ctxt, doc);
desret_int(ret_val);
call_tests++;
des_xmlValidCtxtPtr(n_ctxt, ctxt);
des_xmlDocPtr(n_doc, doc);
xmlResetLastError();
if (mem_base != xmlMemBlocks()) {
printf("Leak of %d blocks found in xmlValidateDocumentFinal",
xmlMemBlocks() - mem_base);
ret++;
printf(" %d", n_ctxt);
printf(" %d", n_doc);
printf("\n");
}
}
}
#endif
/* missing type support */
return(ret);
}
......@@ -11082,8 +11203,38 @@ static int
test_xmlValidateDtdFinal(void) {
int ret = 0;
#ifdef LIBXML_VALID_ENABLED
int mem_base;
int ret_val;
xmlValidCtxtPtr ctxt; /* the validation context */
int n_ctxt;
xmlDocPtr doc; /* a document instance */
int n_doc;
for (n_ctxt = 0;n_ctxt < gen_nb_xmlValidCtxtPtr;n_ctxt++) {
for (n_doc = 0;n_doc < gen_nb_xmlDocPtr;n_doc++) {
mem_base = xmlMemBlocks();
ctxt = gen_xmlValidCtxtPtr(n_ctxt);
doc = gen_xmlDocPtr(n_doc);
ret_val = xmlValidateDtdFinal(ctxt, doc);
desret_int(ret_val);
call_tests++;
des_xmlValidCtxtPtr(n_ctxt, ctxt);
des_xmlDocPtr(n_doc, doc);
xmlResetLastError();
if (mem_base != xmlMemBlocks()) {
printf("Leak of %d blocks found in xmlValidateDtdFinal",
xmlMemBlocks() - mem_base);
ret++;
printf(" %d", n_ctxt);
printf(" %d", n_doc);
printf("\n");
}
}
}
#endif
/* missing type support */
return(ret);
}
......@@ -11092,8 +11243,45 @@ static int
test_xmlValidateElement(void) {
int ret = 0;
#ifdef LIBXML_VALID_ENABLED
int mem_base;
int ret_val;
xmlValidCtxtPtr ctxt; /* the validation context */
int n_ctxt;
xmlDocPtr doc; /* a document instance */
int n_doc;
xmlNodePtr elem; /* an element instance */
int n_elem;
for (n_ctxt = 0;n_ctxt < gen_nb_xmlValidCtxtPtr;n_ctxt++) {
for (n_doc = 0;n_doc < gen_nb_xmlDocPtr;n_doc++) {
for (n_elem = 0;n_elem < gen_nb_xmlNodePtr;n_elem++) {
mem_base = xmlMemBlocks();
ctxt = gen_xmlValidCtxtPtr(n_ctxt);
doc = gen_xmlDocPtr(n_doc);
elem = gen_xmlNodePtr(n_elem);
ret_val = xmlValidateElement(ctxt, doc, elem);
desret_int(ret_val);
call_tests++;
des_xmlValidCtxtPtr(n_ctxt, ctxt);
des_xmlDocPtr(n_doc, doc);
des_xmlNodePtr(n_elem, elem);
xmlResetLastError();
if (mem_base != xmlMemBlocks()) {
printf("Leak of %d blocks found in xmlValidateElement",
xmlMemBlocks() - mem_base);
ret++;
printf(" %d", n_ctxt);
printf(" %d", n_doc);
printf(" %d", n_elem);
printf("\n");
}
}
}
}
#endif
/* missing type support */
return(ret);
}
......@@ -11254,8 +11442,45 @@ static int
test_xmlValidateNotationUse(void) {
int ret = 0;
#ifdef LIBXML_VALID_ENABLED
int mem_base;
int ret_val;
xmlValidCtxtPtr ctxt; /* the validation context */
int n_ctxt;
xmlDocPtr doc; /* the document */
int n_doc;
const xmlChar * notationName; /* the notation name to check */
int n_notationName;
for (n_ctxt = 0;n_ctxt < gen_nb_xmlValidCtxtPtr;n_ctxt++) {
for (n_doc = 0;n_doc < gen_nb_xmlDocPtr;n_doc++) {
for (n_notationName = 0;n_notationName < gen_nb_const_xmlChar_ptr;n_notationName++) {
mem_base = xmlMemBlocks();
ctxt = gen_xmlValidCtxtPtr(n_ctxt);
doc = gen_xmlDocPtr(n_doc);
notationName = gen_const_xmlChar_ptr(n_notationName);
ret_val = xmlValidateNotationUse(ctxt, doc, notationName);
desret_int(ret_val);
call_tests++;
des_xmlValidCtxtPtr(n_ctxt, ctxt);
des_xmlDocPtr(n_doc, doc);
des_const_xmlChar_ptr(n_notationName, notationName);
xmlResetLastError();
if (mem_base != xmlMemBlocks()) {
printf("Leak of %d blocks found in xmlValidateNotationUse",
xmlMemBlocks() - mem_base);
ret++;
printf(" %d", n_ctxt);
printf(" %d", n_doc);
printf(" %d", n_notationName);
printf("\n");
}
}
}
}
#endif
/* missing type support */
return(ret);
}
......@@ -11274,8 +11499,45 @@ static int
test_xmlValidateOneElement(void) {
int ret = 0;
#ifdef LIBXML_VALID_ENABLED
int mem_base;
int ret_val;
xmlValidCtxtPtr ctxt; /* the validation context */
int n_ctxt;
xmlDocPtr doc; /* a document instance */
int n_doc;
xmlNodePtr elem; /* an element instance */
int n_elem;
for (n_ctxt = 0;n_ctxt < gen_nb_xmlValidCtxtPtr;n_ctxt++) {
for (n_doc = 0;n_doc < gen_nb_xmlDocPtr;n_doc++) {
for (n_elem = 0;n_elem < gen_nb_xmlNodePtr;n_elem++) {
mem_base = xmlMemBlocks();
ctxt = gen_xmlValidCtxtPtr(n_ctxt);
doc = gen_xmlDocPtr(n_doc);
elem = gen_xmlNodePtr(n_elem);
ret_val = xmlValidateOneElement(ctxt, doc, elem);
desret_int(ret_val);
call_tests++;
des_xmlValidCtxtPtr(n_ctxt, ctxt);
des_xmlDocPtr(n_doc, doc);
des_xmlNodePtr(n_elem, elem);
xmlResetLastError();
if (mem_base != xmlMemBlocks()) {
printf("Leak of %d blocks found in xmlValidateOneElement",
xmlMemBlocks() - mem_base);
ret++;
printf(" %d", n_ctxt);
printf(" %d", n_doc);
printf(" %d", n_elem);
printf("\n");
}
}
}
}
#endif
/* missing type support */
return(ret);
}
......@@ -11294,8 +11556,52 @@ static int
test_xmlValidatePopElement(void) {
int ret = 0;
#ifdef LIBXML_REGEXP_ENABLED
int mem_base;
int ret_val;
xmlValidCtxtPtr ctxt; /* the validation context */
int n_ctxt;
xmlDocPtr doc; /* a document instance */
int n_doc;
xmlNodePtr elem; /* an element instance */
int n_elem;
const xmlChar * qname; /* the qualified name as appearing in the serialization */
int n_qname;
for (n_ctxt = 0;n_ctxt < gen_nb_xmlValidCtxtPtr;n_ctxt++) {
for (n_doc = 0;n_doc < gen_nb_xmlDocPtr;n_doc++) {
for (n_elem = 0;n_elem < gen_nb_xmlNodePtr;n_elem++) {
for (n_qname = 0;n_qname < gen_nb_const_xmlChar_ptr;n_qname++) {
mem_base = xmlMemBlocks();
ctxt = gen_xmlValidCtxtPtr(n_ctxt);
doc = gen_xmlDocPtr(n_doc);
elem = gen_xmlNodePtr(n_elem);
qname = gen_const_xmlChar_ptr(n_qname);
ret_val = xmlValidatePopElement(ctxt, doc, elem, qname);
desret_int(ret_val);
call_tests++;
des_xmlValidCtxtPtr(n_ctxt, ctxt);
des_xmlDocPtr(n_doc, doc);
des_xmlNodePtr(n_elem, elem);
des_const_xmlChar_ptr(n_qname, qname);
xmlResetLastError();
if (mem_base != xmlMemBlocks()) {
printf("Leak of %d blocks found in xmlValidatePopElement",
xmlMemBlocks() - mem_base);
ret++;
printf(" %d", n_ctxt);
printf(" %d", n_doc);
printf(" %d", n_elem);
printf(" %d", n_qname);
printf("\n");
}
}
}
}
}
#endif
/* missing type support */
return(ret);
}
......@@ -11304,8 +11610,45 @@ static int
test_xmlValidatePushCData(void) {
int ret = 0;
#ifdef LIBXML_REGEXP_ENABLED
int mem_base;
int ret_val;
xmlValidCtxtPtr ctxt; /* the validation context */
int n_ctxt;
const xmlChar * data; /* some character data read */
int n_data;
int len; /* the lenght of the data */
int n_len;
for (n_ctxt = 0;n_ctxt < gen_nb_xmlValidCtxtPtr;n_ctxt++) {
for (n_data = 0;n_data < gen_nb_const_xmlChar_ptr;n_data++) {
for (n_len = 0;n_len < gen_nb_int;n_len++) {
mem_base = xmlMemBlocks();
ctxt = gen_xmlValidCtxtPtr(n_ctxt);
data = gen_const_xmlChar_ptr(n_data);
len = gen_int(n_len);
ret_val = xmlValidatePushCData(ctxt, data, len);
desret_int(ret_val);
call_tests++;
des_xmlValidCtxtPtr(n_ctxt, ctxt);
des_const_xmlChar_ptr(n_data, data);
des_int(n_len, len);
xmlResetLastError();
if (mem_base != xmlMemBlocks()) {
printf("Leak of %d blocks found in xmlValidatePushCData",
xmlMemBlocks() - mem_base);
ret++;
printf(" %d", n_ctxt);
printf(" %d", n_data);
printf(" %d", n_len);
printf("\n");
}
}
}
}
#endif
/* missing type support */
return(ret);
}
......@@ -11314,8 +11657,52 @@ static int
test_xmlValidatePushElement(void) {
int ret = 0;
#ifdef LIBXML_REGEXP_ENABLED
int mem_base;
int ret_val;
xmlValidCtxtPtr ctxt; /* the validation context */
int n_ctxt;
xmlDocPtr doc; /* a document instance */
int n_doc;
xmlNodePtr elem; /* an element instance */
int n_elem;
const xmlChar * qname; /* the qualified name as appearing in the serialization */
int n_qname;
for (n_ctxt = 0;n_ctxt < gen_nb_xmlValidCtxtPtr;n_ctxt++) {
for (n_doc = 0;n_doc < gen_nb_xmlDocPtr;n_doc++) {
for (n_elem = 0;n_elem < gen_nb_xmlNodePtr;n_elem++) {
for (n_qname = 0;n_qname < gen_nb_const_xmlChar_ptr;n_qname++) {
mem_base = xmlMemBlocks();
ctxt = gen_xmlValidCtxtPtr(n_ctxt);
doc = gen_xmlDocPtr(n_doc);
elem = gen_xmlNodePtr(n_elem);
qname = gen_const_xmlChar_ptr(n_qname);
ret_val = xmlValidatePushElement(ctxt, doc, elem, qname);
desret_int(ret_val);
call_tests++;
des_xmlValidCtxtPtr(n_ctxt, ctxt);
des_xmlDocPtr(n_doc, doc);
des_xmlNodePtr(n_elem, elem);
des_const_xmlChar_ptr(n_qname, qname);
xmlResetLastError();
if (mem_base != xmlMemBlocks()) {
printf("Leak of %d blocks found in xmlValidatePushElement",
xmlMemBlocks() - mem_base);
ret++;
printf(" %d", n_ctxt);
printf(" %d", n_doc);
printf(" %d", n_elem);
printf(" %d", n_qname);
printf("\n");
}
}
}
}
}
#endif
/* missing type support */
return(ret);
}
......@@ -11324,8 +11711,38 @@ static int
test_xmlValidateRoot(void) {
int ret = 0;
#ifdef LIBXML_VALID_ENABLED
int mem_base;
int ret_val;
xmlValidCtxtPtr ctxt; /* the validation context */
int n_ctxt;
xmlDocPtr doc; /* a document instance */
int n_doc;
for (n_ctxt = 0;n_ctxt < gen_nb_xmlValidCtxtPtr;n_ctxt++) {
for (n_doc = 0;n_doc < gen_nb_xmlDocPtr;n_doc++) {
mem_base = xmlMemBlocks();
ctxt = gen_xmlValidCtxtPtr(n_ctxt);
doc = gen_xmlDocPtr(n_doc);
ret_val = xmlValidateRoot(ctxt, doc);
desret_int(ret_val);
call_tests++;
des_xmlValidCtxtPtr(n_ctxt, ctxt);
des_xmlDocPtr(n_doc, doc);
xmlResetLastError();
if (mem_base != xmlMemBlocks()) {
printf("Leak of %d blocks found in xmlValidateRoot",
xmlMemBlocks() - mem_base);
ret++;
printf(" %d", n_ctxt);
printf(" %d", n_doc);
printf("\n");
}
}
}
#endif
/* missing type support */
return(ret);
}
......
......@@ -885,6 +885,10 @@ xmlValidCtxtPtr xmlNewValidCtxt(void) {
*/
void
xmlFreeValidCtxt(xmlValidCtxtPtr cur) {
if (cur->vstateTab != NULL)
xmlFree(cur->vstateTab);
if (cur->nodeTab != NULL)
xmlFree(cur->nodeTab);
xmlFree(cur);
}
......@@ -5388,7 +5392,9 @@ xmlValidGetElemDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
xmlElementPtr elemDecl = NULL;
const xmlChar *prefix = NULL;
if ((elem == NULL) || (elem->name == NULL)) return(NULL);
if ((ctxt == NULL) || (doc == NULL) ||
(elem == NULL) || (elem->name == NULL))
return(NULL);
if (extsubset != NULL)
*extsubset = 0;
......@@ -5450,6 +5456,8 @@ xmlValidatePushElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
xmlElementPtr eDecl;
int extsubset = 0;
if (ctxt == NULL)
return(0);
/* printf("PushElem %s\n", qname); */
if ((ctxt->vstateNr > 0) && (ctxt->vstate != NULL)) {
xmlValidStatePtr state = ctxt->vstate;
......@@ -5539,6 +5547,8 @@ xmlValidatePushCData(xmlValidCtxtPtr ctxt, const xmlChar *data, int len) {
int ret = 1;
/* printf("CDATA %s %d\n", data, len); */
if (ctxt == NULL)
return(0);
if (len <= 0)
return(ret);
if ((ctxt->vstateNr > 0) && (ctxt->vstate != NULL)) {
......@@ -5612,6 +5622,8 @@ xmlValidatePopElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc ATTRIBUTE_UNUSED,
const xmlChar *qname ATTRIBUTE_UNUSED) {
int ret = 1;
if (ctxt == NULL)
return(0);
/* printf("PopElem %s\n", qname); */
if ((ctxt->vstateNr > 0) && (ctxt->vstate != NULL)) {
xmlValidStatePtr state = ctxt->vstate;
......@@ -6299,6 +6311,8 @@ int
xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt, xmlDocPtr doc) {
xmlRefTablePtr table;
if (ctxt == NULL)
return(0);
if (doc == NULL) {
xmlErrValid(ctxt, XML_DTD_NO_DOC,
"xmlValidateDocumentFinal: doc == NULL\n", NULL);
......@@ -6530,6 +6544,8 @@ xmlValidateDocument(xmlValidCtxtPtr ctxt, xmlDocPtr doc) {
int ret;
xmlNodePtr root;
if (doc == NULL)
return(0);
if ((doc->intSubset == NULL) && (doc->extSubset == NULL)) {
xmlErrValid(ctxt, XML_DTD_NO_DTD,
"no DTD found!\n", NULL);
......