[libxml2] Move automata test to runtest.c
- From: Nick Wellnhofer <nwellnhof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxml2] Move automata test to runtest.c
- Date: Fri, 2 Sep 2022 16:52:04 +0000 (UTC)
commit caef85633ea2cc738bf3c4c92e2c57ac0db1d303
Author: Nick Wellnhofer <wellnhofer aevum de>
Date: Fri Sep 2 17:26:47 2022 +0200
Move automata test to runtest.c
.gitignore | 1 -
CMakeLists.txt | 1 -
Makefile.am | 26 -----
doc/apibuild.py | 1 -
runtest.c | 250 ++++++++++++++++++++++++++++++++++++++++-
testAutomata.c | 309 ---------------------------------------------------
win32/Makefile.bcb | 1 -
win32/Makefile.mingw | 1 -
win32/Makefile.msvc | 1 -
9 files changed, 248 insertions(+), 343 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 5053db20..842be311 100644
--- a/.gitignore
+++ b/.gitignore
@@ -96,7 +96,6 @@ runxmlconf.log
stamp-h1
tags
test.out
-testAutomata
testModule
testThreads
testapi
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9762e6af..bb3697d7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -505,7 +505,6 @@ if(LIBXML2_WITH_TESTS)
runxmlconf
runsuite
testapi
- testAutomata
testchar
testdict
testModule
diff --git a/Makefile.am b/Makefile.am
index 22e5856c..6b79dc9a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -15,7 +15,6 @@ check_PROGRAMS = \
runsuite \
runtest \
runxmlconf \
- testAutomata \
testModule \
testThreads \
testapi \
@@ -156,10 +155,6 @@ testThreads_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
testThreads_DEPENDENCIES = $(DEPS)
testThreads_LDADD= $(BASE_THREAD_LIBS) $(THREAD_LIBS) $(LDADDS)
-testAutomata_SOURCES=testAutomata.c
-testAutomata_DEPENDENCIES = $(DEPS)
-testAutomata_LDADD= $(LDADDS)
-
testModule_SOURCES=testModule.c
testModule_DEPENDENCIES = $(DEPS)
testModule_LDADD= $(LDADDS)
@@ -219,9 +214,6 @@ endif
if WITH_DEBUG_SOURCES
OLD_TESTS += Scripttests
endif
-if WITH_REGEXPS_SOURCES
-OLD_TESTS += Automatatests
-endif
if WITH_SCHEMAS_SOURCES
if WITH_PYTHON
OLD_TESTS += RelaxNGPythonTests SchemasPythonTests
@@ -311,24 +303,6 @@ Catatests : xmlcatalog$(EXEEXT)
grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0"; \
rm -f $(srcdir)/result/catalogs/mycatalog)
-Automatatests: testAutomata$(EXEEXT)
- @(echo > .memdump)
- @echo "## Automata regression tests"
- -@(for i in $(srcdir)/test/automata/* ; do \
- name=`basename $$i`; \
- if [ ! -d $$i ] ; then \
- if [ ! -f $(srcdir)/result/automata/$$name ] ; then \
- echo New test file $$name ; \
- $(CHECKER) $(top_builddir)/testAutomata $$i > $(srcdir)/result/automata/$$name; \
- grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0";\
- else \
- log=`$(CHECKER) $(top_builddir)/testAutomata $$i 2>&1 > result.$$name ; \
- grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0";\
- diff $(srcdir)/result/automata/$$name result.$$name` ; \
- if [ -n "$$log" ] ; then echo $$name result ; echo "$$log" ; fi ; \
- rm result.$$name ; \
- fi ; fi ; done)
-
dba100000.xml: dbgenattr.pl
@echo "## generating dba100000.xml"
@($(PERL) $(top_srcdir)/dbgenattr.pl 100000 > dba100000.xml)
diff --git a/doc/apibuild.py b/doc/apibuild.py
index dff5c573..00e0bc35 100755
--- a/doc/apibuild.py
+++ b/doc/apibuild.py
@@ -29,7 +29,6 @@ ignored_files = {
"testOOMlib.h": "out of memory tester",
"testOOMlib.c": "out of memory tester",
"rngparser.c": "not yet integrated",
- "testAutomata.c": "test tool",
"testModule.c": "test tool",
"testThreads.c": "test tool",
"testapi.c": "generated regression tests",
diff --git a/runtest.c b/runtest.c
index ff2e3c96..46a56ad4 100644
--- a/runtest.c
+++ b/runtest.c
@@ -4323,7 +4323,9 @@ regexpTest(const char *filename, const char *result, const char *err,
char expression[5000];
int len, ret, res = 0;
- input = fopen(filename, "r");
+ nb_tests++;
+
+ input = fopen(filename, "rb");
if (input == NULL) {
xmlGenericError(xmlGenericErrorContext,
"Cannot open %s for reading\n", filename);
@@ -4399,7 +4401,246 @@ regexpTest(const char *filename, const char *result, const char *err,
return(res);
}
-#endif
+#endif /* LIBXML_REGEXPS_ENABLED */
+
+#ifdef LIBXML_AUTOMATA_ENABLED
+/************************************************************************
+ * *
+ * Automata tests *
+ * *
+ ************************************************************************/
+
+static int scanNumber(char **ptr) {
+ int ret = 0;
+ char *cur;
+
+ cur = *ptr;
+ while ((*cur >= '0') && (*cur <= '9')) {
+ ret = ret * 10 + (*cur - '0');
+ cur++;
+ }
+ *ptr = cur;
+ return(ret);
+}
+
+static int
+automataTest(const char *filename, const char *result,
+ const char *err ATTRIBUTE_UNUSED, int options ATTRIBUTE_UNUSED) {
+ FILE *input, *output;
+ char *temp;
+ char expr[5000];
+ int len;
+ int ret;
+ int i;
+ int res = 0;
+ xmlAutomataPtr am;
+ xmlAutomataStatePtr states[1000];
+ xmlRegexpPtr regexp = NULL;
+ xmlRegExecCtxtPtr exec = NULL;
+
+ nb_tests++;
+
+ for (i = 0;i<1000;i++)
+ states[i] = NULL;
+
+ input = fopen(filename, "rb");
+ 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);
+ }
+
+ am = xmlNewAutomata();
+ if (am == NULL) {
+ xmlGenericError(xmlGenericErrorContext,
+ "Cannot create automata\n");
+ fclose(input);
+ return(-1);
+ }
+ states[0] = xmlAutomataGetInitState(am);
+ if (states[0] == NULL) {
+ xmlGenericError(xmlGenericErrorContext,
+ "Cannot get start state\n");
+ xmlFreeAutomata(am);
+ fclose(input);
+ return(-1);
+ }
+ ret = 0;
+
+ while (fgets(expr, 4500, input) != NULL) {
+ if (expr[0] == '#')
+ continue;
+ len = strlen(expr);
+ len--;
+ while ((len >= 0) &&
+ ((expr[len] == '\n') || (expr[len] == '\t') ||
+ (expr[len] == '\r') || (expr[len] == ' '))) len--;
+ expr[len + 1] = 0;
+ if (len >= 0) {
+ if ((am != NULL) && (expr[0] == 't') && (expr[1] == ' ')) {
+ char *ptr = &expr[2];
+ int from, to;
+
+ from = scanNumber(&ptr);
+ if (*ptr != ' ') {
+ xmlGenericError(xmlGenericErrorContext,
+ "Bad line %s\n", expr);
+ break;
+ }
+ if (states[from] == NULL)
+ states[from] = xmlAutomataNewState(am);
+ ptr++;
+ to = scanNumber(&ptr);
+ if (*ptr != ' ') {
+ xmlGenericError(xmlGenericErrorContext,
+ "Bad line %s\n", expr);
+ break;
+ }
+ if (states[to] == NULL)
+ states[to] = xmlAutomataNewState(am);
+ ptr++;
+ xmlAutomataNewTransition(am, states[from], states[to],
+ BAD_CAST ptr, NULL);
+ } else if ((am != NULL) && (expr[0] == 'e') && (expr[1] == ' ')) {
+ char *ptr = &expr[2];
+ int from, to;
+
+ from = scanNumber(&ptr);
+ if (*ptr != ' ') {
+ xmlGenericError(xmlGenericErrorContext,
+ "Bad line %s\n", expr);
+ break;
+ }
+ if (states[from] == NULL)
+ states[from] = xmlAutomataNewState(am);
+ ptr++;
+ to = scanNumber(&ptr);
+ if (states[to] == NULL)
+ states[to] = xmlAutomataNewState(am);
+ xmlAutomataNewEpsilon(am, states[from], states[to]);
+ } else if ((am != NULL) && (expr[0] == 'f') && (expr[1] == ' ')) {
+ char *ptr = &expr[2];
+ int state;
+
+ state = scanNumber(&ptr);
+ if (states[state] == NULL) {
+ xmlGenericError(xmlGenericErrorContext,
+ "Bad state %d : %s\n", state, expr);
+ break;
+ }
+ xmlAutomataSetFinalState(am, states[state]);
+ } else if ((am != NULL) && (expr[0] == 'c') && (expr[1] == ' ')) {
+ char *ptr = &expr[2];
+ int from, to;
+ int min, max;
+
+ from = scanNumber(&ptr);
+ if (*ptr != ' ') {
+ xmlGenericError(xmlGenericErrorContext,
+ "Bad line %s\n", expr);
+ break;
+ }
+ if (states[from] == NULL)
+ states[from] = xmlAutomataNewState(am);
+ ptr++;
+ to = scanNumber(&ptr);
+ if (*ptr != ' ') {
+ xmlGenericError(xmlGenericErrorContext,
+ "Bad line %s\n", expr);
+ break;
+ }
+ if (states[to] == NULL)
+ states[to] = xmlAutomataNewState(am);
+ ptr++;
+ min = scanNumber(&ptr);
+ if (*ptr != ' ') {
+ xmlGenericError(xmlGenericErrorContext,
+ "Bad line %s\n", expr);
+ break;
+ }
+ ptr++;
+ max = scanNumber(&ptr);
+ if (*ptr != ' ') {
+ xmlGenericError(xmlGenericErrorContext,
+ "Bad line %s\n", expr);
+ break;
+ }
+ ptr++;
+ xmlAutomataNewCountTrans(am, states[from], states[to],
+ BAD_CAST ptr, min, max, NULL);
+ } else if ((am != NULL) && (expr[0] == '-') && (expr[1] == '-')) {
+ /* end of the automata */
+ regexp = xmlAutomataCompile(am);
+ xmlFreeAutomata(am);
+ am = NULL;
+ if (regexp == NULL) {
+ xmlGenericError(xmlGenericErrorContext,
+ "Failed to compile the automata");
+ break;
+ }
+ } else if ((expr[0] == '=') && (expr[1] == '>')) {
+ if (regexp == NULL) {
+ fprintf(output, "=> failed not compiled\n");
+ } else {
+ if (exec == NULL)
+ exec = xmlRegNewExecCtxt(regexp, NULL, NULL);
+ if (ret == 0) {
+ ret = xmlRegExecPushString(exec, NULL, NULL);
+ }
+ if (ret == 1)
+ fprintf(output, "=> Passed\n");
+ else if ((ret == 0) || (ret == -1))
+ fprintf(output, "=> Failed\n");
+ else if (ret < 0)
+ fprintf(output, "=> Error\n");
+ xmlRegFreeExecCtxt(exec);
+ exec = NULL;
+ }
+ ret = 0;
+ } else if (regexp != NULL) {
+ if (exec == NULL)
+ exec = xmlRegNewExecCtxt(regexp, NULL, NULL);
+ ret = xmlRegExecPushString(exec, BAD_CAST expr, NULL);
+ } else {
+ xmlGenericError(xmlGenericErrorContext,
+ "Unexpected line %s\n", expr);
+ }
+ }
+ }
+ fclose(output);
+ fclose(input);
+ if (regexp != NULL)
+ xmlRegFreeRegexp(regexp);
+ if (exec != NULL)
+ xmlRegFreeExecCtxt(exec);
+ if (am != NULL)
+ xmlFreeAutomata(am);
+
+ 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);
+ }
+
+ return(res);
+}
+
+#endif /* LIBXML_AUTOMATA_ENABLED */
/************************************************************************
* *
@@ -4607,6 +4848,11 @@ testDesc testDescriptions[] = {
{ "Regexp regression tests" ,
regexpTest, "./test/regexp/*", "result/regexp/", "", ".err",
0 },
+#endif
+#if defined(LIBXML_AUTOMATA_ENABLED)
+ { "Automata regression tests" ,
+ automataTest, "./test/automata/*", "result/automata/", "", NULL,
+ 0 },
#endif
{NULL, NULL, NULL, NULL, NULL, NULL, 0}
};
diff --git a/win32/Makefile.bcb b/win32/Makefile.bcb
index 1064b807..43b5ab95 100644
--- a/win32/Makefile.bcb
+++ b/win32/Makefile.bcb
@@ -205,7 +205,6 @@ XML_OBJS_A = $(XML_INTDIR_A)\buf.obj\
# Xmllint and friends executables.
UTILS = $(BINDIR)\xmllint.exe\
$(BINDIR)\xmlcatalog.exe\
- $(BINDIR)\testAutomata.exe\
$(BINDIR)\testModule.exe\
$(BINDIR)\runtest.exe\
$(BINDIR)\runsuite.exe\
diff --git a/win32/Makefile.mingw b/win32/Makefile.mingw
index 81f261bc..b10738d2 100644
--- a/win32/Makefile.mingw
+++ b/win32/Makefile.mingw
@@ -201,7 +201,6 @@ XML_SRCS_A = $(subst .o,.c,$(subst $(XML_INTDIR_A)/,$(XML_SRCDIR)/,$(XML_OBJS_A)
# Xmllint and friends executables.
UTILS = $(BINDIR)/xmllint.exe\
$(BINDIR)/xmlcatalog.exe\
- $(BINDIR)/testAutomata.exe\
$(BINDIR)/testModule.exe\
$(BINDIR)/runtest.exe\
$(BINDIR)/runsuite.exe\
diff --git a/win32/Makefile.msvc b/win32/Makefile.msvc
index 80e64e22..bd3e2ec1 100644
--- a/win32/Makefile.msvc
+++ b/win32/Makefile.msvc
@@ -255,7 +255,6 @@ XML_OBJS_A_DLL = $(XML_OBJS_A_DLL) $(XML_INTDIR_A_DLL)\xzlib.obj
# Xmllint and friends executables.
UTILS = $(BINDIR)\xmllint.exe\
$(BINDIR)\xmlcatalog.exe\
- $(BINDIR)\testAutomata.exe\
$(BINDIR)\testModule.exe\
$(BINDIR)\runtest.exe\
$(BINDIR)\runsuite.exe\
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]