Skip to content

Commit

Permalink
added first test for the patterns a few fixes Daniel
Browse files Browse the repository at this point in the history
* Makefile.am configure.in result/pattern/simple
  test/pattern/simple.*: added first test for the patterns
* pattern.c xmllint.c: a few fixes
Daniel
  • Loading branch information
Daniel Veillard committed Jan 30, 2005
1 parent 8f2efae commit f9d1691
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 7 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Sun Jan 30 23:35:19 CET 2005 Daniel Veillard <[email protected]>

* Makefile.am configure.in result/pattern/simple
test/pattern/simple.*: added first test for the patterns
* pattern.c xmllint.c: a few fixes

Sun Jan 30 19:27:23 CET 2005 Daniel Veillard <[email protected]>

* pattern.c include/libxml/pattern.h xmllint.c: added a
Expand Down
26 changes: 25 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ check-local: all tests

testall : tests SVGtests SAXtests

tests: XMLtests XMLenttests NStests IDtests Errtests APItests @READER_TEST@ @TEST_SAX@ @TEST_PUSH@ @TEST_HTML@ @TEST_PHTML@ @TEST_VALID@ URItests @TEST_XPATH@ @TEST_XPTR@ @TEST_XINCLUDE@ @TEST_C14N@ @TEST_DEBUG@ @TEST_CATALOG@ @TEST_REGEXPS@ @TEST_SCHEMAS@ @TEST_THREADS@ Timingtests @TEST_VTIME@ @PYTHON_TESTS@ @TEST_MODULES@
tests: XMLtests XMLenttests NStests IDtests Errtests APItests @READER_TEST@ @TEST_SAX@ @TEST_PUSH@ @TEST_HTML@ @TEST_PHTML@ @TEST_VALID@ URItests @TEST_PATTERN@ @TEST_XPATH@ @TEST_XPTR@ @TEST_XINCLUDE@ @TEST_C14N@ @TEST_DEBUG@ @TEST_CATALOG@ @TEST_REGEXPS@ @TEST_SCHEMAS@ @TEST_THREADS@ Timingtests @TEST_VTIME@ @PYTHON_TESTS@ @TEST_MODULES@
@(if [ "@PYTHON_SUBDIR@" != "" ] ; then cd python ; \
$(MAKE) MAKEFLAGS+=--silent tests ; fi)
@(cd doc/examples ; $(MAKE) MAKEFLAGS+=--silent tests)
Expand Down Expand Up @@ -1001,6 +1001,30 @@ SchemasPythonTests:
fi)
@(if [ -x $(PYTHON) -a -d xstc ] ; then cd xstc ; $(MAKE) CHECKER="$(CHECKER)" MAKEFLAGS+=--silent pytests ; fi)

Patterntests: xmllint$(EXEEXT)
@(echo > .memdump)
@echo "## Pattern regression tests"
-@(for i in $(srcdir)/test/pattern/*.pat ; do \
name=`basename $$i .pat`; \
if [ -f $(srcdir)/test/pattern/$$name.xml ] ; then \
if [ ! -f $(srcdir)/result/pattern/$$name ] ; then \
rm -f result.$$name ; \
echo New test file $$name ; \
for pat in `cat $$i` ; do \
$(CHECKER) $(top_builddir)/xmllint --stream --pattern $$pat $(srcdir)/test/pattern/$$name.xml >> $(srcdir)/result/pattern/$$name ; \
grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0";\
done ;\
else \
rm -f result.$$name ; \
lst=`cat $$i` ; \
log=`for pat in $$lst ; do $(CHECKER) $(top_builddir)/xmllint --stream --pattern $$pat $(srcdir)/test/pattern/$$name.xml 2>&1 >> result.$$name ; \
grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0";\
done ;\
diff $(srcdir)/result/pattern/$$name result.$$name` ; \
if [ -n "$$log" ] ; then echo $$name result ; echo $$log ; fi ; \
rm result.$$name ; \
fi ; fi ; done ;)

ModuleTests: testModule$(EXEEXT) testdso.la
@echo "## Module tests"
@(./testModule$(EXEEXT))
Expand Down
6 changes: 3 additions & 3 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -866,13 +866,13 @@ AC_SUBST(WITH_WRITER)
if test "$with_pattern" = "no" ; then
echo Disabling the xmlPattern parsing interface
WITH_PATTERN=0
PATTERN_TEST=
TEST_PATTERN=
else
WITH_PATTERN=1
PATTERN_TEST=Patterntests
TEST_PATTERN=Patterntests
fi
AC_SUBST(WITH_PATTERN)
AC_SUBST(PATTERN_TEST)
AC_SUBST(TEST_PATTERN)

if test "$with_sax1" = "no" ; then
echo Disabling the older SAX1 interface
Expand Down
15 changes: 14 additions & 1 deletion pattern.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@
* [email protected]
*/

/*
* TODO:
* - compilation flags to check for specific syntaxes
* using flags of xmlPatterncompile()
* - making clear how pattern starting with / or . need to be handled,
* currently push(NULL, NULL) means a reset of the streaming context
* and indicating we are on / (the document node), probably need
* something similar for .
* - xmlPatterncompile support of namespaces arguments, I'm not sure
* it's implemented and definitely not tested
* - handling of disjunction "pattern1 | pattern2" mean needed to build
* and check a list internally
*/

#define IN_LIBXML
#include "libxml.h"

Expand Down Expand Up @@ -1348,7 +1362,6 @@ xmlStreamPush(xmlStreamCtxtPtr stream,
}
} else if (!(comp->steps[step].flags & XML_STREAM_STEP_DESC)) {
/* didn't match, discard */
printf("discard %d\n", i);
stream->states[2 * i] = -1;
}
}
Expand Down
12 changes: 12 additions & 0 deletions result/pattern/simple
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Node /a matches pattern a
Node /a/b matches pattern b
Node /a/b matches pattern b
Node /a matches pattern /a
Node /a/b matches pattern a/b
Node /a/b/c matches pattern a/b/c
Node /a matches pattern //a
Node /a/b matches pattern //b
Node /a/b/c matches pattern //c
Node /a/b matches pattern a//b
Node /a/b/c matches pattern a//c
Node /a/b/c matches pattern b//c
15 changes: 15 additions & 0 deletions test/pattern/simple.pat
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
a
b
b
/a
/b
/c
a/b
a/b/c
//a
//b
//c
a//b
a//c
b//c

5 changes: 5 additions & 0 deletions test/pattern/simple.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<a>
<b>
<c d="attr">text</c>
</b>
</a>
4 changes: 2 additions & 2 deletions xmllint.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,6 @@ static void processNode(xmlTextReaderPtr reader) {
fprintf(stderr,
" pattern %s node %s\n",
pattern, path);
if (path != NULL)
xmlFree(path);
}


Expand All @@ -879,6 +877,8 @@ static void processNode(xmlTextReaderPtr reader) {
}
}
}
if (path != NULL)
xmlFree(path);
}
#endif
}
Expand Down

0 comments on commit f9d1691

Please sign in to comment.