mirror of
https://github.com/GNOME/libxml2.git
synced 2025-05-09 05:11:41 +08:00
Move regexp tests to runtest
This commit is contained in:
parent
f1c32b4c78
commit
5ce893c0c4
1
.gitignore
vendored
1
.gitignore
vendored
@ -98,7 +98,6 @@ tags
|
|||||||
test.out
|
test.out
|
||||||
testAutomata
|
testAutomata
|
||||||
testModule
|
testModule
|
||||||
testRegexp
|
|
||||||
testThreads
|
testThreads
|
||||||
testapi
|
testapi
|
||||||
testapi.c.new
|
testapi.c.new
|
||||||
|
@ -511,7 +511,6 @@ if(LIBXML2_WITH_TESTS)
|
|||||||
testModule
|
testModule
|
||||||
testlimits
|
testlimits
|
||||||
testrecurse
|
testrecurse
|
||||||
testRegexp
|
|
||||||
)
|
)
|
||||||
foreach(TEST ${TESTS})
|
foreach(TEST ${TESTS})
|
||||||
add_executable(${TEST} ${TEST}.c)
|
add_executable(${TEST} ${TEST}.c)
|
||||||
|
44
Makefile.am
44
Makefile.am
@ -18,7 +18,6 @@ check_PROGRAMS = \
|
|||||||
runtest \
|
runtest \
|
||||||
runxmlconf \
|
runxmlconf \
|
||||||
testAutomata \
|
testAutomata \
|
||||||
testRegexp \
|
|
||||||
testModule \
|
testModule \
|
||||||
testThreads \
|
testThreads \
|
||||||
testapi \
|
testapi \
|
||||||
@ -117,11 +116,6 @@ testThreads_LDFLAGS =
|
|||||||
testThreads_DEPENDENCIES = $(DEPS)
|
testThreads_DEPENDENCIES = $(DEPS)
|
||||||
testThreads_LDADD= $(BASE_THREAD_LIBS) $(THREAD_LIBS) $(LDADDS)
|
testThreads_LDADD= $(BASE_THREAD_LIBS) $(THREAD_LIBS) $(LDADDS)
|
||||||
|
|
||||||
testRegexp_SOURCES=testRegexp.c
|
|
||||||
testRegexp_LDFLAGS =
|
|
||||||
testRegexp_DEPENDENCIES = $(DEPS)
|
|
||||||
testRegexp_LDADD= $(LDADDS)
|
|
||||||
|
|
||||||
testAutomata_SOURCES=testAutomata.c
|
testAutomata_SOURCES=testAutomata.c
|
||||||
testAutomata_LDFLAGS =
|
testAutomata_LDFLAGS =
|
||||||
testAutomata_DEPENDENCIES = $(DEPS)
|
testAutomata_DEPENDENCIES = $(DEPS)
|
||||||
@ -273,44 +267,6 @@ Catatests : xmlcatalog$(EXEEXT)
|
|||||||
grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0"; \
|
grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0"; \
|
||||||
rm -f $(srcdir)/result/catalogs/mycatalog)
|
rm -f $(srcdir)/result/catalogs/mycatalog)
|
||||||
|
|
||||||
Regexptests: testRegexp$(EXEEXT)
|
|
||||||
@(echo > .memdump)
|
|
||||||
@echo "## Regexp regression tests"
|
|
||||||
-@(for i in $(srcdir)/test/regexp/* ; do \
|
|
||||||
name=`basename $$i`; \
|
|
||||||
if [ ! -d $$i ] ; then \
|
|
||||||
if [ ! -f $(srcdir)/result/regexp/$$name ] ; then \
|
|
||||||
echo New test file $$name ; \
|
|
||||||
$(CHECKER) $(top_builddir)/testRegexp -i $$i > $(srcdir)/result/regexp/$$name 2> $(srcdir)/result/regexp/$$name.err ; \
|
|
||||||
if [ ! -s "$(srcdir)/result/regexp/$$name.err" ] ; then rm $(srcdir)/result/regexp/$$name.err; fi ; \
|
|
||||||
grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0";\
|
|
||||||
else \
|
|
||||||
log=`$(CHECKER) $(top_builddir)/testRegexp -i $$i > result.$$name 2> error.$$name ; \
|
|
||||||
grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0";\
|
|
||||||
diff $(srcdir)/result/regexp/$$name result.$$name ; \
|
|
||||||
if [ -s "$(srcdir)/result/regexp/$$name.err" -o -s "error.$$name" ] ; then diff $(srcdir)/result/regexp/$$name.err error.$$name ; fi` ; \
|
|
||||||
if [ -n "$$log" ] ; then echo $$name result ; echo $$log ; fi ; \
|
|
||||||
rm result.$$name error.$$name ; \
|
|
||||||
fi ; fi ; done)
|
|
||||||
|
|
||||||
# Disabled for now
|
|
||||||
Exptests: testRegexp$(EXEEXT)
|
|
||||||
@echo "## Formal expressions regression tests"
|
|
||||||
-@(for i in $(srcdir)/test/expr/* ; do \
|
|
||||||
name=`basename $$i`; \
|
|
||||||
if [ ! -d $$i ] ; then \
|
|
||||||
if [ ! -f $(srcdir)/result/expr/$$name ] ; then \
|
|
||||||
echo New test file $$name ; \
|
|
||||||
$(CHECKER) $(top_builddir)/testRegexp --expr -i $$i > $(srcdir)/result/expr/$$name; \
|
|
||||||
grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0";\
|
|
||||||
else \
|
|
||||||
log=`$(CHECKER) $(top_builddir)/testRegexp --expr -i $$i 2>&1 > result.$$name ; \
|
|
||||||
grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0";\
|
|
||||||
diff $(srcdir)/result/expr/$$name result.$$name` ; \
|
|
||||||
if [ -n "$$log" ] ; then echo $$name result ; echo "$$log" ; fi ; \
|
|
||||||
rm result.$$name ; \
|
|
||||||
fi ; fi ; done)
|
|
||||||
|
|
||||||
Automatatests: testAutomata$(EXEEXT)
|
Automatatests: testAutomata$(EXEEXT)
|
||||||
@(echo > .memdump)
|
@(echo > .memdump)
|
||||||
@echo "## Automata regression tests"
|
@echo "## Automata regression tests"
|
||||||
|
@ -1299,7 +1299,7 @@ if test "$with_regexps" = "no" ; then
|
|||||||
TEST_REGEXPS=
|
TEST_REGEXPS=
|
||||||
else
|
else
|
||||||
WITH_REGEXPS=1
|
WITH_REGEXPS=1
|
||||||
TEST_REGEXPS="Regexptests Automatatests"
|
TEST_REGEXPS="Automatatests"
|
||||||
fi
|
fi
|
||||||
AC_SUBST(WITH_REGEXPS)
|
AC_SUBST(WITH_REGEXPS)
|
||||||
AC_SUBST(TEST_REGEXPS)
|
AC_SUBST(TEST_REGEXPS)
|
||||||
|
@ -33,7 +33,6 @@ ignored_files = {
|
|||||||
"rngparser.h": "not yet integrated",
|
"rngparser.h": "not yet integrated",
|
||||||
"testAutomata.c": "test tool",
|
"testAutomata.c": "test tool",
|
||||||
"testModule.c": "test tool",
|
"testModule.c": "test tool",
|
||||||
"testRegexp.c": "test tool",
|
|
||||||
"testThreads.c": "test tool",
|
"testThreads.c": "test tool",
|
||||||
"testapi.c": "generated regression tests",
|
"testapi.c": "generated regression tests",
|
||||||
"runtest.c": "regression tests program",
|
"runtest.c": "regression tests program",
|
||||||
|
112
runtest.c
112
runtest.c
@ -4298,6 +4298,113 @@ threadsTest(const char *filename ATTRIBUTE_UNUSED,
|
|||||||
return(testThread());
|
return(testThread());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(LIBXML_REGEXP_ENABLED)
|
||||||
|
/************************************************************************
|
||||||
|
* *
|
||||||
|
* Regexp tests *
|
||||||
|
* *
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
static void testRegexp(FILE *output, xmlRegexpPtr comp, const char *value) {
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = xmlRegexpExec(comp, (const xmlChar *) value);
|
||||||
|
if (ret == 1)
|
||||||
|
fprintf(output, "%s: Ok\n", value);
|
||||||
|
else if (ret == 0)
|
||||||
|
fprintf(output, "%s: Fail\n", value);
|
||||||
|
else
|
||||||
|
fprintf(output, "%s: Error: %d\n", value, ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
regexpTest(const char *filename, const char *result, const char *err,
|
||||||
|
int options ATTRIBUTE_UNUSED) {
|
||||||
|
xmlRegexpPtr comp = NULL;
|
||||||
|
FILE *input, *output;
|
||||||
|
char *temp;
|
||||||
|
char expression[5000];
|
||||||
|
int len, ret, res = 0;
|
||||||
|
|
||||||
|
input = fopen(filename, "r");
|
||||||
|
if (input == NULL) {
|
||||||
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
|
"Cannot open %s for reading\n", filename);
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
temp = resultFilename(filename, "", ".res");
|
||||||
|
if (temp == NULL) {
|
||||||
|
fprintf(stderr, "Out of memory\n");
|
||||||
|
fatalError();
|
||||||
|
}
|
||||||
|
output = fopen(temp, "wb");
|
||||||
|
if (output == NULL) {
|
||||||
|
fprintf(stderr, "failed to open output file %s\n", temp);
|
||||||
|
free(temp);
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
while (fgets(expression, 4500, input) != NULL) {
|
||||||
|
len = strlen(expression);
|
||||||
|
len--;
|
||||||
|
while ((len >= 0) &&
|
||||||
|
((expression[len] == '\n') || (expression[len] == '\t') ||
|
||||||
|
(expression[len] == '\r') || (expression[len] == ' '))) len--;
|
||||||
|
expression[len + 1] = 0;
|
||||||
|
if (len >= 0) {
|
||||||
|
if (expression[0] == '#')
|
||||||
|
continue;
|
||||||
|
if ((expression[0] == '=') && (expression[1] == '>')) {
|
||||||
|
char *pattern = &expression[2];
|
||||||
|
|
||||||
|
if (comp != NULL) {
|
||||||
|
xmlRegFreeRegexp(comp);
|
||||||
|
comp = NULL;
|
||||||
|
}
|
||||||
|
fprintf(output, "Regexp: %s\n", pattern) ;
|
||||||
|
comp = xmlRegexpCompile((const xmlChar *) pattern);
|
||||||
|
if (comp == NULL) {
|
||||||
|
fprintf(output, " failed to compile\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (comp == NULL) {
|
||||||
|
fprintf(output, "Regexp: %s\n", expression) ;
|
||||||
|
comp = xmlRegexpCompile((const xmlChar *) expression);
|
||||||
|
if (comp == NULL) {
|
||||||
|
fprintf(output, " failed to compile\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (comp != NULL) {
|
||||||
|
testRegexp(output, comp, expression);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(output);
|
||||||
|
fclose(input);
|
||||||
|
if (comp != NULL)
|
||||||
|
xmlRegFreeRegexp(comp);
|
||||||
|
|
||||||
|
ret = compareFiles(temp, result);
|
||||||
|
if (ret) {
|
||||||
|
fprintf(stderr, "Result for %s failed in %s\n", filename, result);
|
||||||
|
res = 1;
|
||||||
|
}
|
||||||
|
if (temp != NULL) {
|
||||||
|
unlink(temp);
|
||||||
|
free(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = compareFileMem(err, testErrors, testErrorsSize);
|
||||||
|
if (ret != 0) {
|
||||||
|
fprintf(stderr, "Error for %s failed\n", filename);
|
||||||
|
res = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* *
|
* *
|
||||||
* Tests Descriptions *
|
* Tests Descriptions *
|
||||||
@ -4495,6 +4602,11 @@ testDesc testDescriptions[] = {
|
|||||||
{ "SVG parsing regression tests" ,
|
{ "SVG parsing regression tests" ,
|
||||||
oldParseTest, "./test/SVG/*.xml", "result/SVG/", "", NULL,
|
oldParseTest, "./test/SVG/*.xml", "result/SVG/", "", NULL,
|
||||||
0 },
|
0 },
|
||||||
|
#if defined(LIBXML_REGEXP_ENABLED)
|
||||||
|
{ "Regexp regression tests" ,
|
||||||
|
regexpTest, "./test/regexp/*", "result/regexp/", "", ".err",
|
||||||
|
0 },
|
||||||
|
#endif
|
||||||
{NULL, NULL, NULL, NULL, NULL, NULL, 0}
|
{NULL, NULL, NULL, NULL, NULL, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
402
testRegexp.c
402
testRegexp.c
@ -1,402 +0,0 @@
|
|||||||
/*
|
|
||||||
* testRegexp.c: simple module for testing regular expressions
|
|
||||||
*
|
|
||||||
* See Copyright for the status of this software.
|
|
||||||
*
|
|
||||||
* Daniel Veillard <veillard@redhat.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "libxml.h"
|
|
||||||
#ifdef LIBXML_REGEXP_ENABLED
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <libxml/tree.h>
|
|
||||||
#include <libxml/xmlregexp.h>
|
|
||||||
|
|
||||||
static int repeat = 0;
|
|
||||||
static int debug = 0;
|
|
||||||
|
|
||||||
static void testRegexp(xmlRegexpPtr comp, const char *value) {
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = xmlRegexpExec(comp, (const xmlChar *) value);
|
|
||||||
if (ret == 1)
|
|
||||||
printf("%s: Ok\n", value);
|
|
||||||
else if (ret == 0)
|
|
||||||
printf("%s: Fail\n", value);
|
|
||||||
else
|
|
||||||
printf("%s: Error: %d\n", value, ret);
|
|
||||||
if (repeat) {
|
|
||||||
int j;
|
|
||||||
for (j = 0;j < 999999;j++)
|
|
||||||
xmlRegexpExec(comp, (const xmlChar *) value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
testRegexpFile(const char *filename) {
|
|
||||||
xmlRegexpPtr comp = NULL;
|
|
||||||
FILE *input;
|
|
||||||
char expression[5000];
|
|
||||||
int len;
|
|
||||||
|
|
||||||
input = fopen(filename, "rb");
|
|
||||||
if (input == NULL) {
|
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
|
||||||
"Cannot open %s for reading\n", filename);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
while (fgets(expression, 4500, input) != NULL) {
|
|
||||||
len = strlen(expression);
|
|
||||||
len--;
|
|
||||||
while ((len >= 0) &&
|
|
||||||
((expression[len] == '\n') || (expression[len] == '\t') ||
|
|
||||||
(expression[len] == '\r') || (expression[len] == ' '))) len--;
|
|
||||||
expression[len + 1] = 0;
|
|
||||||
if (len >= 0) {
|
|
||||||
if (expression[0] == '#')
|
|
||||||
continue;
|
|
||||||
if ((expression[0] == '=') && (expression[1] == '>')) {
|
|
||||||
char *pattern = &expression[2];
|
|
||||||
|
|
||||||
if (comp != NULL) {
|
|
||||||
xmlRegFreeRegexp(comp);
|
|
||||||
comp = NULL;
|
|
||||||
}
|
|
||||||
printf("Regexp: %s\n", pattern) ;
|
|
||||||
comp = xmlRegexpCompile((const xmlChar *) pattern);
|
|
||||||
if (comp == NULL) {
|
|
||||||
printf(" failed to compile\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if (comp == NULL) {
|
|
||||||
printf("Regexp: %s\n", expression) ;
|
|
||||||
comp = xmlRegexpCompile((const xmlChar *) expression);
|
|
||||||
if (comp == NULL) {
|
|
||||||
printf(" failed to compile\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if (comp != NULL) {
|
|
||||||
testRegexp(comp, expression);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose(input);
|
|
||||||
if (comp != NULL)
|
|
||||||
xmlRegFreeRegexp(comp);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef LIBXML_EXPR_ENABLED
|
|
||||||
static void
|
|
||||||
runFileTest(xmlExpCtxtPtr ctxt, const char *filename) {
|
|
||||||
xmlExpNodePtr expr = NULL, sub;
|
|
||||||
FILE *input;
|
|
||||||
char expression[5000];
|
|
||||||
int len;
|
|
||||||
|
|
||||||
input = fopen(filename, "rb");
|
|
||||||
if (input == NULL) {
|
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
|
||||||
"Cannot open %s for reading\n", filename);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
while (fgets(expression, 4500, input) != NULL) {
|
|
||||||
len = strlen(expression);
|
|
||||||
len--;
|
|
||||||
while ((len >= 0) &&
|
|
||||||
((expression[len] == '\n') || (expression[len] == '\t') ||
|
|
||||||
(expression[len] == '\r') || (expression[len] == ' '))) len--;
|
|
||||||
expression[len + 1] = 0;
|
|
||||||
if (len >= 0) {
|
|
||||||
if (expression[0] == '#')
|
|
||||||
continue;
|
|
||||||
if ((expression[0] == '=') && (expression[1] == '>')) {
|
|
||||||
char *str = &expression[2];
|
|
||||||
|
|
||||||
if (expr != NULL) {
|
|
||||||
xmlExpFree(ctxt, expr);
|
|
||||||
if (xmlExpCtxtNbNodes(ctxt) != 0)
|
|
||||||
printf(" Parse/free of Expression leaked %d\n",
|
|
||||||
xmlExpCtxtNbNodes(ctxt));
|
|
||||||
expr = NULL;
|
|
||||||
}
|
|
||||||
printf("Expression: %s\n", str) ;
|
|
||||||
expr = xmlExpParse(ctxt, str);
|
|
||||||
if (expr == NULL) {
|
|
||||||
printf(" parsing Failed\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if (expr != NULL) {
|
|
||||||
int expect = -1;
|
|
||||||
int nodes1, nodes2;
|
|
||||||
|
|
||||||
if (expression[0] == '0')
|
|
||||||
expect = 0;
|
|
||||||
if (expression[0] == '1')
|
|
||||||
expect = 1;
|
|
||||||
printf("Subexp: %s", expression + 2) ;
|
|
||||||
nodes1 = xmlExpCtxtNbNodes(ctxt);
|
|
||||||
sub = xmlExpParse(ctxt, expression + 2);
|
|
||||||
if (sub == NULL) {
|
|
||||||
printf(" parsing Failed\n");
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
nodes2 = xmlExpCtxtNbNodes(ctxt);
|
|
||||||
ret = xmlExpSubsume(ctxt, expr, sub);
|
|
||||||
|
|
||||||
if ((expect == 1) && (ret == 1)) {
|
|
||||||
printf(" => accept, Ok\n");
|
|
||||||
} else if ((expect == 0) && (ret == 0)) {
|
|
||||||
printf(" => reject, Ok\n");
|
|
||||||
} else if ((expect == 1) && (ret == 0)) {
|
|
||||||
printf(" => reject, Failed\n");
|
|
||||||
} else if ((expect == 0) && (ret == 1)) {
|
|
||||||
printf(" => accept, Failed\n");
|
|
||||||
} else {
|
|
||||||
printf(" => fail internally\n");
|
|
||||||
}
|
|
||||||
if (xmlExpCtxtNbNodes(ctxt) > nodes2) {
|
|
||||||
printf(" Subsume leaked %d\n",
|
|
||||||
xmlExpCtxtNbNodes(ctxt) - nodes2);
|
|
||||||
nodes1 += xmlExpCtxtNbNodes(ctxt) - nodes2;
|
|
||||||
}
|
|
||||||
xmlExpFree(ctxt, sub);
|
|
||||||
if (xmlExpCtxtNbNodes(ctxt) > nodes1) {
|
|
||||||
printf(" Parse/free leaked %d\n",
|
|
||||||
xmlExpCtxtNbNodes(ctxt) - nodes1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (expr != NULL) {
|
|
||||||
xmlExpFree(ctxt, expr);
|
|
||||||
if (xmlExpCtxtNbNodes(ctxt) != 0)
|
|
||||||
printf(" Parse/free of Expression leaked %d\n",
|
|
||||||
xmlExpCtxtNbNodes(ctxt));
|
|
||||||
}
|
|
||||||
fclose(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
testReduce(xmlExpCtxtPtr ctxt, xmlExpNodePtr expr, const char *tst) {
|
|
||||||
xmlBufferPtr xmlExpBuf;
|
|
||||||
xmlExpNodePtr sub, deriv;
|
|
||||||
|
|
||||||
sub = xmlExpParse(ctxt, tst);
|
|
||||||
if (sub == NULL) {
|
|
||||||
printf("Subset %s failed to parse\n", tst);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
xmlExpBuf = xmlBufferCreate();
|
|
||||||
xmlExpDump(xmlExpBuf, sub);
|
|
||||||
printf("Subset parsed as: %s\n",
|
|
||||||
(const char *) xmlBufferContent(xmlExpBuf));
|
|
||||||
deriv = xmlExpExpDerive(ctxt, expr, sub);
|
|
||||||
if (deriv == NULL) {
|
|
||||||
printf("Derivation led to an internal error, report this !\n");
|
|
||||||
} else {
|
|
||||||
xmlBufferEmpty(xmlExpBuf);
|
|
||||||
xmlExpDump(xmlExpBuf, deriv);
|
|
||||||
if (xmlExpIsNillable(deriv))
|
|
||||||
printf("Resulting nillable derivation: %s\n",
|
|
||||||
(const char *) xmlBufferContent(xmlExpBuf));
|
|
||||||
else
|
|
||||||
printf("Resulting derivation: %s\n",
|
|
||||||
(const char *) xmlBufferContent(xmlExpBuf));
|
|
||||||
xmlExpFree(ctxt, deriv);
|
|
||||||
}
|
|
||||||
xmlBufferFree(xmlExpBuf);
|
|
||||||
xmlExpFree(ctxt, sub);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
exprDebug(xmlExpCtxtPtr ctxt, xmlExpNodePtr expr) {
|
|
||||||
xmlBufferPtr xmlExpBuf;
|
|
||||||
xmlExpNodePtr deriv;
|
|
||||||
const char *list[40];
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
xmlExpBuf = xmlBufferCreate();
|
|
||||||
|
|
||||||
if (expr == NULL) {
|
|
||||||
printf("Failed to parse\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
xmlExpDump(xmlExpBuf, expr);
|
|
||||||
printf("Parsed as: %s\n", (const char *) xmlBufferContent(xmlExpBuf));
|
|
||||||
printf("Max token input = %d\n", xmlExpMaxToken(expr));
|
|
||||||
if (xmlExpIsNillable(expr) == 1)
|
|
||||||
printf("Is nillable\n");
|
|
||||||
ret = xmlExpGetLanguage(ctxt, expr, (const xmlChar **) &list[0], 40);
|
|
||||||
if (ret < 0)
|
|
||||||
printf("Failed to get list: %d\n", ret);
|
|
||||||
else {
|
|
||||||
int i;
|
|
||||||
|
|
||||||
printf("Language has %d strings, testing string derivations\n", ret);
|
|
||||||
for (i = 0;i < ret;i++) {
|
|
||||||
deriv = xmlExpStringDerive(ctxt, expr, BAD_CAST list[i], -1);
|
|
||||||
if (deriv == NULL) {
|
|
||||||
printf(" %s -> derivation failed\n", list[i]);
|
|
||||||
} else {
|
|
||||||
xmlBufferEmpty(xmlExpBuf);
|
|
||||||
xmlExpDump(xmlExpBuf, deriv);
|
|
||||||
printf(" %s -> %s\n", list[i],
|
|
||||||
(const char *) xmlBufferContent(xmlExpBuf));
|
|
||||||
}
|
|
||||||
xmlExpFree(ctxt, deriv);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
xmlBufferFree(xmlExpBuf);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void usage(const char *name) {
|
|
||||||
fprintf(stderr, "Usage: %s [flags]\n", name);
|
|
||||||
fprintf(stderr, "Testing tool for libxml2 string and pattern regexps\n");
|
|
||||||
fprintf(stderr, " --debug: switch on debugging\n");
|
|
||||||
fprintf(stderr, " --repeat: loop on the operation\n");
|
|
||||||
#ifdef LIBXML_EXPR_ENABLED
|
|
||||||
fprintf(stderr, " --expr: test xmlExp and not xmlRegexp\n");
|
|
||||||
#endif
|
|
||||||
fprintf(stderr, " --input filename: use the given filename for regexp\n");
|
|
||||||
fprintf(stderr, " --input filename: use the given filename for exp\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
|
||||||
xmlRegexpPtr comp = NULL;
|
|
||||||
#ifdef LIBXML_EXPR_ENABLED
|
|
||||||
xmlExpNodePtr expr = NULL;
|
|
||||||
int use_exp = 0;
|
|
||||||
xmlExpCtxtPtr ctxt = NULL;
|
|
||||||
#endif
|
|
||||||
const char *pattern = NULL;
|
|
||||||
char *filename = NULL;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
xmlInitParser();
|
|
||||||
|
|
||||||
if (argc <= 1) {
|
|
||||||
usage(argv[0]);
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
for (i = 1; i < argc ; i++) {
|
|
||||||
if (!strcmp(argv[i], "-"))
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (argv[i][0] != '-')
|
|
||||||
continue;
|
|
||||||
if (!strcmp(argv[i], "--"))
|
|
||||||
break;
|
|
||||||
|
|
||||||
if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug"))) {
|
|
||||||
debug++;
|
|
||||||
} else if ((!strcmp(argv[i], "-repeat")) ||
|
|
||||||
(!strcmp(argv[i], "--repeat"))) {
|
|
||||||
repeat++;
|
|
||||||
#ifdef LIBXML_EXPR_ENABLED
|
|
||||||
} else if ((!strcmp(argv[i], "-expr")) ||
|
|
||||||
(!strcmp(argv[i], "--expr"))) {
|
|
||||||
use_exp++;
|
|
||||||
#endif
|
|
||||||
} else if ((!strcmp(argv[i], "-i")) || (!strcmp(argv[i], "-f")) ||
|
|
||||||
(!strcmp(argv[i], "--input")))
|
|
||||||
filename = argv[++i];
|
|
||||||
else {
|
|
||||||
fprintf(stderr, "Unknown option %s\n", argv[i]);
|
|
||||||
usage(argv[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef LIBXML_EXPR_ENABLED
|
|
||||||
if (use_exp)
|
|
||||||
ctxt = xmlExpNewCtxt(0, NULL);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (filename != NULL) {
|
|
||||||
#ifdef LIBXML_EXPR_ENABLED
|
|
||||||
if (use_exp)
|
|
||||||
runFileTest(ctxt, filename);
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
testRegexpFile(filename);
|
|
||||||
} else {
|
|
||||||
int data = 0;
|
|
||||||
#ifdef LIBXML_EXPR_ENABLED
|
|
||||||
|
|
||||||
if (use_exp) {
|
|
||||||
for (i = 1; i < argc ; i++) {
|
|
||||||
if (strcmp(argv[i], "--") == 0)
|
|
||||||
data = 1;
|
|
||||||
else if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0) ||
|
|
||||||
(data == 1)) {
|
|
||||||
if (pattern == NULL) {
|
|
||||||
pattern = argv[i];
|
|
||||||
printf("Testing expr %s:\n", pattern);
|
|
||||||
expr = xmlExpParse(ctxt, pattern);
|
|
||||||
if (expr == NULL) {
|
|
||||||
printf(" failed to compile\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (debug) {
|
|
||||||
exprDebug(ctxt, expr);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
testReduce(ctxt, expr, argv[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (expr != NULL) {
|
|
||||||
xmlExpFree(ctxt, expr);
|
|
||||||
expr = NULL;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
for (i = 1; i < argc ; i++) {
|
|
||||||
if (strcmp(argv[i], "--") == 0)
|
|
||||||
data = 1;
|
|
||||||
else if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0) ||
|
|
||||||
(data == 1)) {
|
|
||||||
if (pattern == NULL) {
|
|
||||||
pattern = argv[i];
|
|
||||||
printf("Testing %s:\n", pattern);
|
|
||||||
comp = xmlRegexpCompile((const xmlChar *) pattern);
|
|
||||||
if (comp == NULL) {
|
|
||||||
printf(" failed to compile\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (debug)
|
|
||||||
xmlRegexpPrint(stdout, comp);
|
|
||||||
} else {
|
|
||||||
testRegexp(comp, argv[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (comp != NULL)
|
|
||||||
xmlRegFreeRegexp(comp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#ifdef LIBXML_EXPR_ENABLED
|
|
||||||
if (ctxt != NULL) {
|
|
||||||
printf("Ops: %d nodes, %d cons\n",
|
|
||||||
xmlExpCtxtNbNodes(ctxt), xmlExpCtxtNbCons(ctxt));
|
|
||||||
xmlExpFreeCtxt(ctxt);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
xmlCleanupParser();
|
|
||||||
xmlMemoryDump();
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
#include <stdio.h>
|
|
||||||
int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
|
|
||||||
printf("%s : Regexp support not compiled in\n", argv[0]);
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
#endif /* LIBXML_REGEXP_ENABLED */
|
|
@ -64,7 +64,7 @@ $!
|
|||||||
$!- list of test modules to compile and link. Compare this list to the
|
$!- list of test modules to compile and link. Compare this list to the
|
||||||
$! definition of check_PROGRAMS in MAKEFILE.
|
$! definition of check_PROGRAMS in MAKEFILE.
|
||||||
$!
|
$!
|
||||||
$ check_PROGRAMS = "testThreads testAutomata testRegexp"
|
$ check_PROGRAMS = "testThreads testAutomata"
|
||||||
$!
|
$!
|
||||||
$!- set up build logicals -----------------------------------------------------\
|
$!- set up build logicals -----------------------------------------------------\
|
||||||
$!
|
$!
|
||||||
|
@ -206,7 +206,6 @@ XML_OBJS_A = $(XML_INTDIR_A)\buf.obj\
|
|||||||
UTILS = $(BINDIR)\xmllint.exe\
|
UTILS = $(BINDIR)\xmllint.exe\
|
||||||
$(BINDIR)\xmlcatalog.exe\
|
$(BINDIR)\xmlcatalog.exe\
|
||||||
$(BINDIR)\testAutomata.exe\
|
$(BINDIR)\testAutomata.exe\
|
||||||
$(BINDIR)\testRegexp.exe\
|
|
||||||
$(BINDIR)\testModule.exe\
|
$(BINDIR)\testModule.exe\
|
||||||
$(BINDIR)\runtest.exe\
|
$(BINDIR)\runtest.exe\
|
||||||
$(BINDIR)\runsuite.exe\
|
$(BINDIR)\runsuite.exe\
|
||||||
|
@ -202,7 +202,6 @@ XML_SRCS_A = $(subst .o,.c,$(subst $(XML_INTDIR_A)/,$(XML_SRCDIR)/,$(XML_OBJS_A)
|
|||||||
UTILS = $(BINDIR)/xmllint.exe\
|
UTILS = $(BINDIR)/xmllint.exe\
|
||||||
$(BINDIR)/xmlcatalog.exe\
|
$(BINDIR)/xmlcatalog.exe\
|
||||||
$(BINDIR)/testAutomata.exe\
|
$(BINDIR)/testAutomata.exe\
|
||||||
$(BINDIR)/testRegexp.exe\
|
|
||||||
$(BINDIR)/testModule.exe\
|
$(BINDIR)/testModule.exe\
|
||||||
$(BINDIR)/runtest.exe\
|
$(BINDIR)/runtest.exe\
|
||||||
$(BINDIR)/runsuite.exe\
|
$(BINDIR)/runsuite.exe\
|
||||||
|
@ -256,7 +256,6 @@ XML_OBJS_A_DLL = $(XML_OBJS_A_DLL) $(XML_INTDIR_A_DLL)\xzlib.obj
|
|||||||
UTILS = $(BINDIR)\xmllint.exe\
|
UTILS = $(BINDIR)\xmllint.exe\
|
||||||
$(BINDIR)\xmlcatalog.exe\
|
$(BINDIR)\xmlcatalog.exe\
|
||||||
$(BINDIR)\testAutomata.exe\
|
$(BINDIR)\testAutomata.exe\
|
||||||
$(BINDIR)\testRegexp.exe\
|
|
||||||
$(BINDIR)\testModule.exe\
|
$(BINDIR)\testModule.exe\
|
||||||
$(BINDIR)\runtest.exe\
|
$(BINDIR)\runtest.exe\
|
||||||
$(BINDIR)\runsuite.exe\
|
$(BINDIR)\runsuite.exe\
|
||||||
|
Loading…
x
Reference in New Issue
Block a user