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 run-tests (&optional
(p "/home/david/src/lisp/cxml-rng/spec-split/*")
33 (output-file "/home/david/src/lisp/cxml-rng/TEST"))
34 (dribble output-file
:if-exists
:rename-and-delete
)
37 (*package
* (find-package :cxml-rng
))
39 (dolist (d (directory p
))
40 (let ((name (car (last (pathname-directory d
)))))
41 (when (parse-integer name
:junk-allowed t
)
42 (let ((xml (directory (merge-pathnames "*.xml" d
))))
43 (incf total
(1+ (length xml
)))
44 (multiple-value-bind (ok grammar
) (test1 d
)
47 (incf pass
(1+ (run-validation-tests name grammar xml
))))
50 (format t
"~A-~D: FAIL: cannot run test~%"
52 (pathname-name x
))))))))))
53 (format t
"Passed ~D/~D tests.~%" pass total
))
56 (defvar *compatibility-test-p
* nil
)
59 (&optional
(p "/home/david/src/lisp/cxml-rng/dtd-split/*")
60 (q "/home/david/src/lisp/cxml-rng/DTDTEST"))
61 (let ((*compatibility-test-p
* t
))
65 (n &optional
(p "/home/david/src/lisp/cxml-rng/dtd-split/*"))
66 (let ((*break-on-signals
* 'error
))
69 (defun run-validation-test
70 (m n
&optional
(p "/home/david/src/lisp/cxml-rng/spec-split/"))
71 (let ((d (merge-pathnames (format nil
"~3,'0D/" m
) p
))
72 (*break-on-signals
* 'error
)
75 (run-validation-tests m
76 (nth-value 1 (test1 d
))
77 (list (let ((v (merge-pathnames
78 (format nil
"~A.v.xml" n
)
83 (format nil
"~A.i.xml" n
)
86 (defun run-validation-tests (name grammar tests
)
89 (format t
"~A-~D: " name
(pathname-name x
))
91 (cxml:parse-file x
(make-validator grammar
))))
92 (if (find #\v (pathname-name x
))
99 (format t
"FAIL: ~A~%" c
)))
103 (format t
"FAIL: didn't detect invalid document~%"))
104 (dtd-compatibility-error (c)
106 (*compatibility-test-p
*
108 (format t
"PASS: ~A~%" (type-of c
)))
110 (format t
"FAIL: incorrect condition type: ~A~%" c
))))
113 (*compatibility-test-p
*
114 (format t
"FAIL: incorrect condition type: ~A~%" c
))
117 (format t
"PASS: ~A~%" (type-of c
)))))
119 (format t
"FAIL: incorrect condition type: ~A~%" c
))))))
122 (defun run-test (n &optional
(p "/home/david/src/lisp/cxml-rng/spec-split/"))
123 (test1 (merge-pathnames (format nil
"~3,'0D/" n
) p
)))
125 (defun parse-test (n &optional
(p "/home/david/src/lisp/cxml-rng/spec-split/"))
127 (d (merge-pathnames (format nil
"~3,'0D/" n
) p
))
128 (i (merge-pathnames "i.rng" d
))
129 (c (merge-pathnames "c.rng" d
))
130 (rng (if (probe-file c
) c i
)))
131 (format t
"~A: " (car (last (pathname-directory d
))))
136 (let* ((i (merge-pathnames "i.rng" d
))
137 (c (merge-pathnames "c.rng" d
)))
138 (format t
"~A: " (car (last (pathname-directory d
))))
141 (let ((grammar (parse-schema c
)))
145 (format t
" FAIL: ~A~%" c
)
150 (format t
" FAIL: didn't detect invalid schema~%")
152 (dtd-compatibility-error (c)
154 (*compatibility-test-p
*
155 (format t
" PASS: ~A~%" (type-of c
))
158 (format t
" FAIL: incorrect condition type: ~A~%" c
)
162 (*compatibility-test-p
*
163 (format t
" FAIL: incorrect condition type: ~A~%" c
)
166 (format t
" PASS: ~A~%" (type-of c
))
169 (format t
" FAIL: incorrect condition type: ~A~%" c
)
172 (defvar *test-xmllint
*)
174 (defun run-nist-tests
176 &optional
(p #p
"/home/david/NISTSchemaTests/NISTXMLSchemaTestSuite.xml"))
177 (dribble (if *test-xmllint
*
178 "/home/david/src/lisp/cxml-rng/NIST-xmllint"
179 "/home/david/src/lisp/cxml-rng/NIST")
180 :if-exists
:rename-and-delete
)
181 (klacks:with-open-source
(s (cxml:make-source p
))
185 while
(klacks:find-element s
"Link")
187 (multiple-value-bind (n i
)
188 (run-nist-tests/link
(klacks:get-attribute s
"href") p
)
192 (format t
"Passed ~D/~D tests.~%" pass total
)))
195 (defun run-nist-tests/link
(href base
)
196 (klacks:with-open-source
(r (cxml:make-source
(merge-pathnames href base
)))
201 (multiple-value-bind (key uri lname
)
206 (when (eq key
:start-element
)
208 ((equal lname
"Schema")
210 (let ((href (klacks:get-attribute r
"href")))
212 (if (or (search "-enumeration-" href
)
213 (search "-whiteSpace-" href
))
215 (read-nist-grammar href base
))))
218 ((equal lname
"Instance")
220 (when (run-nist-test/Instance schema
221 (klacks:get-attribute r
"href")
224 (values total pass
))))
226 (defun run-nist-test/Instance
(schema href base
)
229 (format t
"PASS INSTANCE ~A: (ignored)~%" href
)
232 (assert *test-xmllint
*)
233 (let ((asdf::*VERBOSE-OUT
* (make-string-output-stream)))
235 ((zerop (asdf:run-shell-command
236 "xmllint -relaxng ~A ~A"
238 (namestring (merge-pathnames href base
))))
239 (format t
"PASS INSTANCE ~A~%" href
)
242 (format t
"FAIL INSTANCE ~A: failed to validate:~_ ~A~%"
244 (get-output-stream-string asdf
::*VERBOSE-OUT
*))
249 (cxml:parse-file
(merge-pathnames href base
)
250 (make-validator schema
))
251 (format t
"PASS INSTANCE ~A~%" href
)
254 (format t
"FAIL INSTANCE ~A: failed to validate:~_ ~A~%" href c
)
257 (format t
"FAIL INSTANCE ~A: (BOGUS CONDITON) failed to validate:~_ ~A~%" href c
)
260 (format t
"FAIL ~A: no schema~%" href
)
263 (defun read-nist-grammar (href base
)
264 (let ((p (make-pathname :type
"rng" :defaults href
)))
268 (namestring (merge-pathnames p base
))
269 (parse-schema (merge-pathnames p base
)))
270 (format t
"PASS ~A~%" href
)
274 ((search ":NAME whiteSpace" (princ-to-string c
))
275 (format t
"PASS ~A: whiteSpace forbidden~%" href
)
277 ((search ":NAME enumeration" (princ-to-string c
))
278 (format t
"PASS ~A: enumeration forbidden~%" href
)
281 (format t
"FAIL ~A: failed to parse:~_ ~A~%" href c
)
284 (format t
"FAIL ~A: (BOGUS CONDITION) failed to parse:~_ ~A~%" href c
)