1 ;;; -*- show-trailing-whitespace: t; indent-tabs: nil -*-
3 ;;; Copyright (c) 2007 David Lichteblau. All rights reserved.
4 ;;; (but mostly transcribed from nu/xom/tests/*)
6 ;;; Redistribution and use in source and binary forms, with or without
7 ;;; modification, are permitted provided that the following conditions
10 ;;; * Redistributions of source code must retain the above copyright
11 ;;; notice, this list of conditions and the following disclaimer.
13 ;;; * Redistributions in binary form must reproduce the above
14 ;;; copyright notice, this list of conditions and the following
15 ;;; disclaimer in the documentation and/or other materials
16 ;;; provided with the distribution.
18 ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
19 ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 (defpackage :cxml-stp-test
33 (in-package :cxml-stp-test
)
35 (defmethod xmlconf::serialize-document
((document node
))
36 (serialize document
(cxml:make-octet-vector-sink
:canonical
2)))
38 (defun stp-test (filename handler
&rest args
)
39 (declare (ignore handler
))
40 (apply #'cxml
:parse-file
42 (read-from-string "#.(cxml-stp:make-builder)")
48 (let ((cxml-stp::*serialize-canonical-notations-only-p
* t
))
49 (xmlconf::run-all-tests
'xmlconf
::stp-test
50 "/home/david/2001/XML-Test-Suite/xmlconf/"))
53 (defun assert-equal (a b
)
55 (error "assertion failed: ~S and ~S are not EQUAL" a b
)))
57 (defmacro expect-condition
(form type
)
61 (error "expected a condition of type ~A" ',type
))
64 (defun serialize-to-string (node)
65 (let ((sink (cxml:make-string-sink
)))
67 (sax:end-document sink
)))
69 (defmacro define-exception-test
(name form type
)
72 (expect-condition ,form
,type
)
80 (deftest text.constructor
81 (data (make-text "test"))
85 (let ((text (make-text "name")))
86 (dolist (str '("Hello"
88 " spaces on both ends "
89 " quotes \" \" quotes"
91 " both double and single \"\'\"\' quotes"
92 " angle brackets < > <<<"
93 #.
(format nil
" carriage returns ~C~C"
94 (code-char 13) (code-char 13))
95 #.
(format nil
" newlines ~C~C"
96 (code-char 10) (code-char 10))
97 #.
(format nil
" both ~C~C"
98 (code-char 13) (code-char 10))
99 #.
(format nil
" tab ~C foo"
102 " <![CDATA[ CDATA end: ]]>"
104 " ampersands & &&& &name; "))
105 (setf (data text
) str
)
106 (assert-equal (data text
) str
)
107 (assert-equal (string-value text
) str
))
111 (let ((text (make-text "name")))
112 (setf (data text
) nil
)
116 (define-exception-test text.illegal
117 (let ((text (make-text "name")))
118 (setf (data text
) (format nil
"test ~C test" (code-char 0))))
121 (deftest text.serialize
122 (let ((text (make-text "name"))
125 " spaces on both ends "
126 ;; zzz CXML traditionally escapes quotes without good
128 (" quotes \" \" quotes"
129 " quotes " " quotes")
130 (" both double and single \"\'\"\' quotes"
131 " both double and single "\'"\' quotes")
132 " single \'\' quotes"
134 ("&" "&amp;")
136 (#.
(string (code-char 13)) " ")
137 "=,.!@#$%^*()_-'[]{}+/?;:`|\\")))
139 for
(in out
) in
(mapcar (lambda (x) (if (listp x
) x
(list x x
)))
142 (setf (data text
) in
)
143 (assert-equal (serialize-to-string text
) out
))
147 (let* ((c1 (make-text "test"))
149 (assert (not (eq c1 c2
)))
150 (assert-equal (data c1
) (data c2
))
151 (assert-equal nil
(parent c2
))
152 (assert-equal (type-of c2
) 'text
)
155 ;;; zzz surrogate testing is going to be a mess, because cxml will have to
156 ;;; support both Lisps with 16 bit and with 21 bit characters. Not the
157 ;;; mention all the surrogate-related bugs we've got.
161 ;;; - testHighSurrogateWithNoLowSurrogate
163 (deftest text.leaf-node
164 (let ((c1 (make-text "data")))
165 (assert-equal 0 (count-children-if #'identity c1
))
166 (expect-condition (nth-child 0 c1
) error
)
167 (assert-equal nil
(parent c1
))
168 (let ((e (make-element "test")))
170 (assert-equal e
(parent c1
))
171 (assert-equal c1
(nth-child 0 e
))
173 (assert-equal 0 (count-children-if #'identity e
)))
179 (deftest comment.constructor
180 (data (make-comment "test"))
183 (deftest comment.constructor2
184 (data (make-comment ""))
187 (deftest comment.constructor3
188 (data (make-comment "- - "))
191 (deftest comment.copy
192 (let* ((c1 (make-comment "test"))
194 (assert (not (eq c1 c2
)))
195 (assert-equal (data c1
) (data c2
))
196 (assert-equal nil
(parent c2
))
197 (assert-equal (type-of c2
) 'comment
)
200 (deftest comment.serialize
201 (let ((c (make-comment "0123456789012345678901234567890123456789")))
202 (assert-equal (serialize-to-string c
)
203 "<!--0123456789012345678901234567890123456789-->")
206 ;;; zzz das pruefen wir nicht
207 ;; (define-exception-test comment.cr
208 ;; (make-comment (format nil "foo ~C bar" (code-char 13)))
211 (deftest comment.setf
212 (let ((c (make-comment "test")))
213 (setf (data c
) "legal")
214 (assert-equal (data c
) "legal")
215 (assert-equal (string-value c
) "legal")
216 (expect-condition (setf (data c
) "test -- test") stp-error
)
217 (expect-condition (setf (data c
) "test-") stp-error
)
219 (assert-equal (data c
) "")
224 ;;; - testForbidUnmatchedSurrogatesInComments
226 (deftest comment.leaf-node
227 (let ((c1 (make-comment "data")))
228 (assert-equal 0 (count-children-if #'identity c1
))
229 (expect-condition (nth-child 0 c1
) error
)
230 (assert-equal nil
(parent c1
))
231 (let ((e (make-element "test")))
233 (assert-equal e
(parent c1
))
234 (assert-equal c1
(nth-child 0 e
))
236 (assert-equal 0 (count-children-if #'identity e
)))
239 (deftest comment.document
240 (let ((c1 (make-comment "data"))
241 (root (make-element "root")))
242 (assert-equal nil
(document c1
))
243 (append-child root c1
)
244 (assert-equal nil
(document c1
))
245 (let ((document (make-document root
)))
246 (assert-equal document
(document c1
)))
249 (deftest comment.funny-characters-allowed
250 (assert-equal (serialize-to-string (make-comment "<test>&&greater;"))
251 "<!--<test>&&greater;-->")
254 (define-exception-test comment.only-char-allowed
255 (make-comment (format nil
" ~C " (code-char 1)))
259 ;;;; PROCESSING-INSTRUCTION
261 (deftest pi.constructor
.1
262 (let ((p-i (make-processing-instruction "abc" "def")))
263 (assert-equal (target p-i
) "abc")
264 (assert-equal (data p-i
) "def")
267 (deftest pi.constructor
.2
268 (data (make-processing-instruction "abc" ""))
271 (deftest pi.constructor
.3
272 (data (make-processing-instruction "abc" nil
))
275 (deftest pi.constructor
.4
276 (target (make-processing-instruction "abc123" nil
))
279 (deftest pi.constructor.illegal
281 (expect-condition (make-processing-instruction "test:test" "test")
283 (expect-condition (make-processing-instruction "" "test")
285 (expect-condition (make-processing-instruction nil
"test")
287 (expect-condition (make-processing-instruction "12345" "test")
291 (deftest pi.serialize
292 (serialize-to-string (make-processing-instruction "abc" "def"))
295 (deftest pi.serialize
.2
296 (serialize-to-string (make-processing-instruction "abc" ""))
299 (deftest pi.serialize
.3
301 (make-processing-instruction "target" "<test>&&greater;"))
302 "<?target <test>&&greater;?>")
305 (let* ((c1 (make-processing-instruction "target" "data"))
307 (assert (not (eq c1 c2
)))
308 (assert-equal (data c1
) (data c2
))
309 (assert-equal (target c1
) (target c2
))
310 (assert-equal nil
(parent c2
))
311 (assert-equal (type-of c2
) 'processing-instruction
)
315 (let* ((p-i (make-processing-instruction "target" "data")))
316 (expect-condition (setf (data p-i
) "?>") stp-error
)
317 (expect-condition (setf (data p-i
) "uhesta ?>") stp-error
)
318 (expect-condition (setf (data p-i
) "uhesta ?> hst") stp-error
)
319 (setf (data p-i
) nil
)
320 (assert-equal (data p-i
) "")
321 (dolist (str '("<html></html>"
325 "salkdhsalkjhdkjsadhkj sadhsajkdh"
329 (setf (data p-i
) str
)
330 (assert-equal (data p-i
) str
))
333 ;;; zzz testCorrectSurrogates
334 ;;; zzz testSurrogates
336 (deftest pi.leaf-node
337 (let ((c1 (make-processing-instruction "target" "data")))
338 (assert-equal 0 (count-children-if #'identity c1
))
339 (expect-condition (nth-child 0 c1
) error
)
340 (assert-equal nil
(parent c1
))
341 (let ((e (make-element "test")))
343 (assert-equal e
(parent c1
))
344 (assert-equal c1
(nth-child 0 e
))
346 (assert-equal 0 (count-children-if #'identity e
)))
349 ;;; zzz das pruefen wir nicht
350 ;; (define-exception-test pi.cr
351 ;; (make-processing-instruction "target" (format nil "foo ~C bar" (code-char 13)))
355 (dolist (str (list " initial spaces"
356 (format nil
"~Cinitial tab" (code-char 9))
357 (format nil
"~Cinitial newline" (code-char 10))
358 (format nil
"~Cinitial cr" (code-char 13)))
360 (expect-condition (make-processing-instruction "target" str
) stp-error
)))
362 (deftest pi.invalid.xml
363 (dolist (str (list "xml" "XML" "Xml")
365 (expect-condition (make-processing-instruction str
"data") stp-error
)))
367 (deftest pi.invalid.colon
368 (dolist (str (list "pre:target" "pre:" ":target")
370 (expect-condition (make-processing-instruction str
"data") stp-error
)))