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 (dribble "/home/david/src/lisp/cxml-rng/TEST" :if-exists
:rename-and-delete
)
36 (*package
* (find-package :cxml-rng
))
38 (dolist (d (directory p
))
39 (let ((name (car (last (pathname-directory d
)))))
40 (when (parse-integer name
:junk-allowed t
)
41 (let ((xml (directory (merge-pathnames "*.xml" d
))))
42 (incf total
(1+ (length xml
)))
43 (multiple-value-bind (ok grammar
) (test1 d
)
46 (incf pass
(1+ (run-validation-tests name grammar xml
))))
49 (format t
"~A-~D: FAIL: cannot run test~%"
51 (pathname-name x
))))))))))
52 (format t
"Passed ~D/~D tests.~%" pass total
))
55 (defun run-validation-test
56 (m n
&optional
(p "/home/david/src/lisp/cxml-rng/spec-split/"))
57 (let ((d (merge-pathnames (format nil
"~3,'0D/" m
) p
))
58 (*break-on-signals
* 'error
)
61 (run-validation-tests m
62 (nth-value 1 (test1 d
))
63 (list (let ((v (merge-pathnames
64 (format nil
"~A.v.xml" n
)
69 (format nil
"~A.i.xml" n
)
72 (defun run-validation-tests (name grammar tests
)
75 (format t
"~A-~D: " name
(pathname-name x
))
77 (cxml:parse-file x
(make-validator grammar
))))
78 (if (find #\v (pathname-name x
))
85 (format t
"FAIL: ~A~%" c
)))
89 (format t
"FAIL: didn't detect invalid document~%"))
92 (format t
"PASS: ~A~%" (type-of c
)))
94 (format t
"FAIL: incorrect condition type: ~A~%" c
))))))
97 (defun run-test (n &optional
(p "/home/david/src/lisp/cxml-rng/spec-split/"))
98 (test1 (merge-pathnames (format nil
"~3,'0D/" n
) p
)))
100 (defun parse-test (n &optional
(p "/home/david/src/lisp/cxml-rng/spec-split/"))
102 (d (merge-pathnames (format nil
"~3,'0D/" n
) p
))
103 (i (merge-pathnames "i.rng" d
))
104 (c (merge-pathnames "c.rng" d
))
105 (rng (if (probe-file c
) c i
)))
106 (format t
"~A: " (car (last (pathname-directory d
))))
111 (let* ((i (merge-pathnames "i.rng" d
))
112 (c (merge-pathnames "c.rng" d
)))
113 (format t
"~A: " (car (last (pathname-directory d
))))
116 (let ((grammar (parse-schema c
)))
120 (format t
" FAIL: ~A~%" c
)
125 (format t
" FAIL: didn't detect invalid schema~%")
128 (format t
" PASS: ~S~%" (type-of c
))
131 (format t
" FAIL: incorrect condition type: ~A~%" c
)
134 (defun run-nist-tests
135 (&optional
(p #p
"/home/david/NISTSchemaTests/NISTXMLSchemaTestSuite.xml"))
136 (dribble "/home/david/src/lisp/cxml-rng/NIST" :if-exists
:rename-and-delete
)
137 (klacks:with-open-source
(s (cxml:make-source p
))
141 while
(klacks:find-element s
"Link")
143 (multiple-value-bind (n i
)
144 (run-nist-tests/link
(klacks:get-attribute s
"href") p
)
148 (format t
"Passed ~D/~D tests.~%" pass total
)))
151 (defun run-nist-tests/link
(href base
)
152 (klacks:with-open-source
(r (cxml:make-source
(merge-pathnames href base
)))
157 (multiple-value-bind (key uri lname
)
162 (when (eq key
:start-element
)
164 ((equal lname
"Schema")
167 (read-nist-grammar (klacks:get-attribute r
"href")
171 ((equal lname
"Instance")
173 (when (run-nist-test/Instance schema
174 (klacks:get-attribute r
"href")
177 (values total pass
))))
179 (defun run-nist-test/Instance
(schema href base
)
184 (cxml:parse-file
(merge-pathnames href base
)
185 (make-validator schema
))
186 (format t
"PASS INSTANCE ~A~%" href
)
189 (format t
"FAIL INSTANCE ~A: failed to validate:~_ ~A~%" href c
)
192 (format t
"FAIL INSTANCE ~A: (BOGUS CONDITON) failed to validate:~_ ~A~%" href c
)
195 (format t
"FAIL ~A: no schema~%" href
)
198 (defun read-nist-grammar (href base
)
199 (let ((p (make-pathname :type
"rng" :defaults href
)))
202 (parse-schema (merge-pathnames p base
))
203 (format t
"PASS ~A~%" href
)
206 (format t
"FAIL ~A: failed to parse:~_ ~A~%" href c
)
209 (format t
"FAIL ~A: (BOGUS CONDITION) failed to parse:~_ ~A~%" href c
)