3 (:export
#:run-all-tests
))
6 (defun get-attribute (element name
)
7 (rod-string (dom:get-attribute element name
)))
9 (defparameter *bad-tests
*
11 ;; http://lists.w3.org/Archives/Public/public-xml-testsuite/2002Mar/0001.html
12 "ibm-valid-P28-ibm28v02.xml"
13 "ibm-valid-P29-ibm29v01.xml"
14 "ibm-valid-P29-ibm29v02.xml"))
16 (defun test-class (test)
18 ((not (and (let ((version (get-attribute test
"RECOMMENDATION")))
20 ((or (equal version
"") ;XXX
21 (equal version
"XML1.0")
22 (equal version
"NS1.0"))
24 ((equal (get-attribute test
"NAMESPACE") "no")
25 (format t
"~A: test applies to parsers without namespace support, skipping~%"
26 (get-attribute test
"URI"))
30 ((equal version
"XML1.1")
34 (warn "unrecognized RECOMMENDATION value: ~S" version
)
36 (not (member (get-attribute test
"ID") *bad-tests
* :test
'equal
))))
38 ((equal (get-attribute test
"TYPE") "valid") :valid
)
39 ((equal (get-attribute test
"TYPE") "invalid") :invalid
)
40 ((equal (get-attribute test
"TYPE") "not-wf") :not-wf
)
43 (defun test-pathnames (directory test
)
46 for parent
= test then
(dom:parent-node parent
)
47 for base
= (get-attribute parent
"xml:base")
48 until
(plusp (length base
))
49 finally
(return (merge-pathnames base directory
))))
50 (uri (get-attribute test
"URI"))
51 (output (get-attribute test
"OUTPUT")))
52 (values (merge-pathnames uri sub-directory
)
53 (when (plusp (length output
))
54 (merge-pathnames output sub-directory
)))))
56 (defmethod serialize-document ((document t
))
57 (dom:map-document
(cxml:make-octet-vector-sink
:canonical
2)
59 :include-doctype
:canonical-notations
60 :include-default-values t
))
62 (defun file-contents (pathname)
63 (with-open-file (s pathname
:element-type
'(unsigned-byte 8))
65 (make-array (file-length s
) :element-type
'(unsigned-byte 8))))
66 (read-sequence result s
)
69 (defun dribble-tests (parser-fn directory
)
70 (let ((base (slot-value (asdf:find-system
:cxml
) 'asdf
::relative-pathname
)))
71 (with-open-file (*standard-output
*
72 (merge-pathnames "XMLCONF" base
)
74 :external-format
:iso-8859-1
75 :if-exists
:supersede
)
76 (run-all-tests parser-fn directory
))))
78 (defvar *parser-fn
* 'sax-test
)
80 (defun sax-test (filename handler
&rest args
)
81 (apply #'cxml
:parse-file filename handler
:recode nil args
))
83 (defun klacks-test (filename handler
&rest args
)
84 (klacks:with-open-source
85 (s (apply #'cxml
:make-source
(pathname filename
) args
))
86 (klacks:serialize-source s handler
)))
88 (defun run-all-tests (parser-fn directory
)
89 (let* ((*parser-fn
* parser-fn
)
90 (pathname (merge-pathnames "xmlconf.xml" directory
))
91 (builder (rune-dom:make-dom-builder
))
92 (xmlconf (cxml:parse-file pathname builder
:recode nil
))
96 ;; XXX someone found it funny to include invalid URIs in the
97 ;; test suite. And no, in "invalid" not "not-wf".
98 (puri:*strict-parse
* nil
))
99 (dom:do-node-list
(test (dom:get-elements-by-tag-name xmlconf
"TEST"))
105 (if (dom:text-node-p child
)
106 (rod-string (dom:data child
))
108 (dom:child-nodes test
))))
109 (class (test-class test
)))
113 (multiple-value-bind (pathname output
)
114 (test-pathnames directory test
)
115 (princ (enough-namestring pathname directory
))
116 (unless (probe-file pathname
)
117 (error "file not found: ~A" pathname
))
118 (with-simple-restart (skip-test "Skip this test")
119 (unless (run-test class pathname output description
)
124 (format t
"~&~D/~D tests failed; ~D test~:P were skipped"
125 nfailed ntried nskipped
)))
127 (defmethod run-test :around
(class pathname output description
&rest args
)
128 (declare (ignore class pathname output args
))
131 (serious-condition (c)
132 (format t
" FAILED:~% ~A~%[~A]~%" c description
)
135 (defmethod run-test ((class null
) pathname output description
&rest args
)
136 (declare (ignore description
))
137 (let ((document (apply *parser-fn
*
139 (rune-dom:make-dom-builder
)
141 ;; If we got here, parsing worked. Let's try to serialize the same
142 ;; document. (We do the same thing in canonical mode below to check the
143 ;; content model of the output, but that doesn't even catch obvious
144 ;; errors in DTD serialization, so even a simple here is an
146 (apply *parser-fn
* pathname
(cxml:make-rod-sink
) args
)
150 ((equalp (file-contents output
) (serialize-document document
))
151 (format t
" input/output"))
153 (let ((error-output (make-pathname :type
"error" :defaults output
)))
154 (with-open-file (s error-output
155 :element-type
'(unsigned-byte 8)
157 :if-exists
:supersede
)
158 (write-sequence (serialize-document document
) s
))
159 (error "well-formed, but output ~S not the expected ~S~%"
160 error-output output
))))
164 ((class (eql :valid
)) pathname output description
&rest args
)
167 (format t
" [not validating:]")
168 (run-test nil pathname output description
:validate nil
))
170 (format t
" [validating:]")
171 (run-test nil pathname output description
:validate t
))))
174 ((class (eql :invalid
)) pathname output description
&rest args
)
177 (format t
" [not validating:]")
178 (run-test nil pathname output description
:validate nil
))
181 (format t
" [validating:]")
184 (rune-dom:make-dom-builder
)
186 (error "validity error not detected")
188 (cxml:validity-error
()
189 (format t
" invalid")
193 ((class (eql :not-wf
)) pathname output description
&rest args
)
197 (format t
" [not validating:]")
200 (rune-dom:make-dom-builder
)
202 (error "well-formedness violation not detected")
206 (format t
" unexpected-error")
208 (cxml:well-formedness-violation
()
213 (format t
" [validating:]")
216 (rune-dom:make-dom-builder
)
218 (error "well-formedness violation not detected")
222 (format t
" unexpected-error")
224 (cxml:well-formedness-violation
()
227 (cxml:validity-error
()
228 ;; das erlauben wir mal auch, denn valide => wf
229 (format t
" invalid")
233 (xmlconf::run-all-tests
'xmlconf
::sax-test
234 "/home/david/2001/XML-Test-Suite/xmlconf/")
237 (xmlconf::run-all-tests
'xmlconf
::klacks-test
238 "/home/david/2001/XML-Test-Suite/xmlconf/")