1 ;;; -*- show-trailing-whitespace: t; indent-tabs: nil -*-
3 ;;; Copyright (c) 2007 David Lichteblau. All rights reserved.
5 ;;; Redistribution and use in source and binary forms, with or without
6 ;;; modification, are permitted provided that the following conditions
9 ;;; * Redistributions of source code must retain the above copyright
10 ;;; notice, this list of conditions and the following disclaimer.
12 ;;; * Redistributions in binary form must reproduce the above
13 ;;; copyright notice, this list of conditions and the following
14 ;;; disclaimer in the documentation and/or other materials
15 ;;; provided with the distribution.
17 ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
18 ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21 ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 (in-package :cxml-rng
)
32 (defun system-directory (&optional
(system :cxml-rng
))
33 (asdf:component-relative-pathname
(asdf:find-system system
)))
36 (&optional
(p (merge-pathnames
37 "cxml-rng-test/spec-split/*" (system-directory)))
38 (output-file (merge-pathnames "TEST" (system-directory))))
39 (dribble output-file
:if-exists
:rename-and-delete
)
42 (*package
* (find-package :cxml-rng
))
44 (dolist (d (directory p
))
45 (let ((name (car (last (pathname-directory d
)))))
46 (when (parse-integer name
:junk-allowed t
)
47 (let ((xml (directory (merge-pathnames "*.xml" d
))))
48 (incf total
(1+ (length xml
)))
49 (multiple-value-bind (ok grammar
) (test1 d
)
52 (incf pass
(1+ (run-validation-tests name grammar xml
))))
55 (format t
"~A-~D: FAIL: cannot run test~%"
57 (pathname-name x
))))))))))
58 (format t
"Passed ~D/~D tests.~%" pass total
))
61 (defvar *compatibility-test-p
* nil
)
64 (&optional
(p (merge-pathnames
65 "cxml-rng-test/dtd-split/*" (system-directory)))
66 (q (merge-pathnames "DTDTEST" (system-directory))))
67 (let ((*compatibility-test-p
* t
))
71 (n &optional
(p (merge-pathnames
72 "cxml-rng-test/dtd-split/*" (system-directory))))
73 (let ((*break-on-signals
* 'error
))
76 (defun run-validation-test
77 (m n
&optional
(p "/home/david/src/lisp/cxml-rng/spec-split/"))
78 (let ((d (merge-pathnames (format nil
"~3,'0D/" m
) p
))
79 (*break-on-signals
* 'error
)
82 (run-validation-tests m
83 (nth-value 1 (test1 d
))
84 (list (let ((v (merge-pathnames
85 (format nil
"~A.v.xml" n
)
90 (format nil
"~A.i.xml" n
)
93 (defun run-validation-tests (name grammar tests
)
96 (format t
"~A-~D: " name
(pathname-name x
))
98 (cxml:parse-file x
(make-dtd-compatibility-handler
100 (make-validator grammar
)))))
101 (if (find #\v (pathname-name x
))
108 (format t
"FAIL: ~A~%" c
)))
112 (format t
"FAIL: didn't detect invalid document~%"))
113 (dtd-compatibility-error (c)
115 (*compatibility-test-p
*
117 (format t
"PASS: ~A~%" (type-of c
)))
119 (format t
"FAIL: incorrect condition type (a): ~A~%" c
))))
122 (*compatibility-test-p
*
123 (format t
"FAIL: incorrect condition type (b): ~A~%" c
))
126 (format t
"PASS: ~A~%" (type-of c
)))))
128 (format t
"FAIL: incorrect condition type (c): ~A~%" c
))))))
131 (defun run-test (n &optional
(p "/home/david/src/lisp/cxml-rng/spec-split/"))
132 (test1 (merge-pathnames (format nil
"~3,'0D/" n
) p
)))
134 (defun parse-test (n &optional
(p "/home/david/src/lisp/cxml-rng/spec-split/"))
136 (d (merge-pathnames (format nil
"~3,'0D/" n
) p
))
137 (i (merge-pathnames "i.rng" d
))
138 (c (merge-pathnames "c.rng" d
))
139 (rng (if (probe-file c
) c i
)))
140 (format t
"~A: " (car (last (pathname-directory d
))))
145 (let* ((i (merge-pathnames "i.rng" d
))
146 (c (merge-pathnames "c.rng" d
)))
147 (format t
"~A: " (car (last (pathname-directory d
))))
150 (let ((grammar (parse-schema c
)))
154 (format t
" FAIL: ~A~%" c
)
159 (format t
" FAIL: didn't detect invalid schema~%")
161 (dtd-compatibility-error (c)
163 (*compatibility-test-p
*
164 (format t
" PASS: ~A~%" (type-of c
))
167 (format t
" FAIL: incorrect condition type (A): ~A~%" c
)
171 (*compatibility-test-p
*
172 (format t
" FAIL: incorrect condition type (B): ~A~%" c
)
175 (format t
" PASS: ~A~%" (type-of c
))
178 (format t
" FAIL: incorrect condition type (C): ~A~%" c
)
181 (defvar *test-xmllint
*)
183 (defun run-nist-tests
185 &optional
(p #p
"/home/david/NISTSchemaTests/NISTXMLSchemaTestSuite.xml"))
186 (dribble (if *test-xmllint
*
187 "/home/david/src/lisp/cxml-rng/NIST-xmllint"
188 "/home/david/src/lisp/cxml-rng/NIST")
189 :if-exists
:rename-and-delete
)
190 (klacks:with-open-source
(s (cxml:make-source p
))
194 while
(klacks:find-element s
"Link")
196 (multiple-value-bind (n i
)
197 (run-nist-tests/link
(klacks:get-attribute s
"href") p
)
201 (format t
"Passed ~D/~D tests.~%" pass total
)))
204 (defun run-nist-tests/link
(href base
)
205 (klacks:with-open-source
(r (cxml:make-source
(merge-pathnames href base
)))
210 (multiple-value-bind (key uri lname
)
215 (when (eq key
:start-element
)
217 ((equal lname
"Schema")
219 (let ((href (klacks:get-attribute r
"href")))
221 (if (or (search "-enumeration-" href
)
222 (search "-whiteSpace-" href
))
224 (read-nist-grammar href base
))))
227 ((equal lname
"Instance")
229 (when (run-nist-test/Instance schema
230 (klacks:get-attribute r
"href")
233 (values total pass
))))
235 (defun run-nist-test/Instance
(schema href base
)
238 (format t
"PASS INSTANCE ~A: (ignored)~%" href
)
241 (assert *test-xmllint
*)
242 (let ((asdf::*VERBOSE-OUT
* (make-string-output-stream)))
244 ((zerop (asdf:run-shell-command
245 "xmllint -relaxng ~A ~A"
247 (namestring (merge-pathnames href base
))))
248 (format t
"PASS INSTANCE ~A~%" href
)
251 (format t
"FAIL INSTANCE ~A: failed to validate:~_ ~A~%"
253 (get-output-stream-string asdf
::*VERBOSE-OUT
*))
258 (cxml:parse-file
(merge-pathnames href base
)
259 (make-validator schema
))
260 (format t
"PASS INSTANCE ~A~%" href
)
263 (format t
"FAIL INSTANCE ~A: failed to validate:~_ ~A~%" href c
)
266 (format t
"FAIL INSTANCE ~A: (BOGUS CONDITON) failed to validate:~_ ~A~%" href c
)
269 (format t
"FAIL ~A: no schema~%" href
)
272 (defun read-nist-grammar (href base
)
273 (let ((p (make-pathname :type
"rng" :defaults href
)))
277 (namestring (merge-pathnames p base
))
278 (parse-schema (merge-pathnames p base
)))
279 (format t
"PASS ~A~%" href
)
283 ((search ":NAME whiteSpace" (princ-to-string c
))
284 (format t
"PASS ~A: whiteSpace forbidden~%" href
)
286 ((search ":NAME enumeration" (princ-to-string c
))
287 (format t
"PASS ~A: enumeration forbidden~%" href
)
290 (format t
"FAIL ~A: failed to parse:~_ ~A~%" href c
)
293 (format t
"FAIL ~A: (BOGUS CONDITION) failed to parse:~_ ~A~%" href c
)