1 ;; Copyright (C) 1999 Free Software Foundation, Inc.
3 ;; Author: Hrvoje Niksic <hniksic@xemacs.org>
4 ;; Maintainers: Hrvoje Niksic <hniksic@xemacs.org>,
5 ;; Martin Buchholz <martin@xemacs.org>
9 ;; This file is part of XEmacs.
11 ;; XEmacs is free software; you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; XEmacs is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 ;;; Synched up with: Not in FSF.
30 ;; Test some Mule functionality (most of these remain to be written) .
31 ;; See test-harness.el for instructions on how to run these tests.
33 ;; This file will be (read)ed by a non-mule XEmacs, so don't use
34 ;; literal non-Latin1 characters. Use (make-char) instead.
36 ;;-----------------------------------------------------------------
37 ;; Test whether all legal chars may be safely inserted to a buffer.
38 ;;-----------------------------------------------------------------
40 (defun test-chars (&optional for-test-harness)
41 "Insert all characters in a buffer, to see if XEmacs will crash.
42 This is done by creating a string with all the legal characters
43 in [0, 2^19) range, inserting it into the buffer, and checking
44 that the buffer's contents are equivalent to the string.
46 If FOR-TEST-HARNESS is specified, a temporary buffer is used, and
47 the Assert macro checks for correctness."
48 (let ((max (expt 2 (if (featurep 'mule) 19 8)))
52 (and (not for-test-harness)
56 ;; Don't aset to a string directly because random string
57 ;; access is O(n) under Mule.
58 (setq list (cons (int-char i) list)))
60 (let ((string (apply #'string (nreverse list))))
62 ;; For use with test-harness, use Assert and a temporary
66 (Assert (equal (buffer-string) string)))
67 ;; For use without test harness: use a normal buffer, so that
68 ;; you can also test whether redisplay works.
69 (switch-to-buffer (get-buffer-create "test"))
73 (assert (equal (buffer-string) string))))))
75 ;; It would be really *really* nice if test-harness allowed a way to
76 ;; run a test in byte-compiled mode only. It's tedious to have
77 ;; time-consuming tests like this one run twice, once interpreted and
78 ;; once compiled, for no good reason.
81 ;;-----------------------------------------------------------------
82 ;; Test string modification functions that modify the length of a char.
83 ;;-----------------------------------------------------------------
85 (when (featurep 'mule)
86 ;;---------------------------------------------------------------
88 ;;---------------------------------------------------------------
92 (let ((char1 (make-char charset1 69))
93 (char2 (make-char charset2 69)))
94 `(let ((string (make-string 1000 ,char1)))
95 (fillarray string ,char2)
96 (Assert (eq (aref string 0) ,char2))
97 (Assert (eq (aref string (1- (length string))) ,char2))
98 (Assert (eq (length string) 1000))))))
99 (fillarray-test ascii latin-iso8859-1)
100 (fillarray-test ascii latin-iso8859-2)
101 (fillarray-test latin-iso8859-1 ascii)
102 (fillarray-test latin-iso8859-2 ascii))
105 (let ((string (string (make-char 'ascii 69) (make-char 'latin-iso8859-2 69))))
106 (aset string 0 (make-char 'latin-iso8859-2 42))
107 (Assert (eq (aref string 1) (make-char 'latin-iso8859-2 69))))
109 ;;---------------------------------------------------------------
110 ;; Test coding system functions
111 ;;---------------------------------------------------------------
113 ;; Create alias for coding system without subsidiaries
114 (Assert (coding-system-p (find-coding-system 'binary)))
115 (Assert (coding-system-canonical-name-p 'binary))
116 (Assert (not (coding-system-alias-p 'binary)))
117 (Assert (not (coding-system-alias-p 'mule-tests-alias)))
118 (Assert (not (coding-system-canonical-name-p 'mule-tests-alias)))
120 error "Symbol is the canonical name of a coding system and cannot be redefined"
121 (define-coding-system-alias 'binary 'iso8859-2))
123 error "Symbol is not a coding system alias"
124 (coding-system-aliasee 'binary))
126 (define-coding-system-alias 'mule-tests-alias 'binary)
127 (Assert (coding-system-alias-p 'mule-tests-alias))
128 (Assert (not (coding-system-canonical-name-p 'mule-tests-alias)))
129 (Assert (eq (get-coding-system 'binary) (get-coding-system 'mule-tests-alias)))
130 (Assert (eq 'binary (coding-system-aliasee 'mule-tests-alias)))
131 (Assert (not (coding-system-alias-p 'mule-tests-alias-unix)))
132 (Assert (not (coding-system-alias-p 'mule-tests-alias-dos)))
133 (Assert (not (coding-system-alias-p 'mule-tests-alias-mac)))
135 (define-coding-system-alias 'mule-tests-alias (get-coding-system 'binary))
136 (Assert (coding-system-alias-p 'mule-tests-alias))
137 (Assert (not (coding-system-canonical-name-p 'mule-tests-alias)))
138 (Assert (eq (get-coding-system 'binary) (get-coding-system 'mule-tests-alias)))
139 (Assert (eq 'binary (coding-system-aliasee 'mule-tests-alias)))
140 (Assert (not (coding-system-alias-p 'mule-tests-alias-unix)))
141 (Assert (not (coding-system-alias-p 'mule-tests-alias-dos)))
142 (Assert (not (coding-system-alias-p 'mule-tests-alias-mac)))
144 (define-coding-system-alias 'nested-mule-tests-alias 'mule-tests-alias)
145 (Assert (coding-system-alias-p 'nested-mule-tests-alias))
146 (Assert (not (coding-system-canonical-name-p 'nested-mule-tests-alias)))
147 (Assert (eq (get-coding-system 'binary) (get-coding-system 'nested-mule-tests-alias)))
148 (Assert (eq (coding-system-aliasee 'nested-mule-tests-alias) 'mule-tests-alias))
149 (Assert (eq 'mule-tests-alias (coding-system-aliasee 'nested-mule-tests-alias)))
150 (Assert (not (coding-system-alias-p 'nested-mule-tests-alias-unix)))
151 (Assert (not (coding-system-alias-p 'nested-mule-tests-alias-dos)))
152 (Assert (not (coding-system-alias-p 'nested-mule-tests-alias-mac)))
155 error "Attempt to create a coding system alias loop"
156 (define-coding-system-alias 'mule-tests-alias 'nested-mule-tests-alias))
158 error "No such coding system"
159 (define-coding-system-alias 'no-such-coding-system 'no-such-coding-system))
161 error "Attempt to create a coding system alias loop"
162 (define-coding-system-alias 'mule-tests-alias 'mule-tests-alias))
164 (define-coding-system-alias 'nested-mule-tests-alias nil)
165 (define-coding-system-alias 'mule-tests-alias nil)
166 (Assert (coding-system-p (find-coding-system 'binary)))
167 (Assert (coding-system-canonical-name-p 'binary))
168 (Assert (not (coding-system-alias-p 'binary)))
169 (Assert (not (coding-system-alias-p 'mule-tests-alias)))
170 (Assert (not (coding-system-canonical-name-p 'mule-tests-alias)))
172 error "Symbol is the canonical name of a coding system and cannot be redefined"
173 (define-coding-system-alias 'binary 'iso8859-2))
175 error "Symbol is not a coding system alias"
176 (coding-system-aliasee 'binary))
178 (define-coding-system-alias 'nested-mule-tests-alias nil)
179 (define-coding-system-alias 'mule-tests-alias nil)
181 ;; Create alias for coding system with subsidiaries
182 (define-coding-system-alias 'mule-tests-alias 'iso-8859-7)
183 (Assert (coding-system-alias-p 'mule-tests-alias))
184 (Assert (not (coding-system-canonical-name-p 'mule-tests-alias)))
185 (Assert (eq (get-coding-system 'iso-8859-7) (get-coding-system 'mule-tests-alias)))
186 (Assert (eq 'iso-8859-7 (coding-system-aliasee 'mule-tests-alias)))
187 (Assert (coding-system-alias-p 'mule-tests-alias-unix))
188 (Assert (coding-system-alias-p 'mule-tests-alias-dos))
189 (Assert (coding-system-alias-p 'mule-tests-alias-mac))
191 (define-coding-system-alias 'mule-tests-alias (get-coding-system 'iso-8859-7))
192 (Assert (coding-system-alias-p 'mule-tests-alias))
193 (Assert (not (coding-system-canonical-name-p 'mule-tests-alias)))
194 (Assert (eq (get-coding-system 'iso-8859-7) (get-coding-system 'mule-tests-alias)))
195 (Assert (eq 'iso-8859-7 (coding-system-aliasee 'mule-tests-alias)))
196 (Assert (coding-system-alias-p 'mule-tests-alias-unix))
197 (Assert (coding-system-alias-p 'mule-tests-alias-dos))
198 (Assert (coding-system-alias-p 'mule-tests-alias-mac))
199 (Assert (eq (find-coding-system 'mule-tests-alias-mac)
200 (find-coding-system 'iso-8859-7-mac)))
202 (define-coding-system-alias 'nested-mule-tests-alias 'mule-tests-alias)
203 (Assert (coding-system-alias-p 'nested-mule-tests-alias))
204 (Assert (not (coding-system-canonical-name-p 'nested-mule-tests-alias)))
205 (Assert (eq (get-coding-system 'iso-8859-7)
206 (get-coding-system 'nested-mule-tests-alias)))
207 (Assert (eq (coding-system-aliasee 'nested-mule-tests-alias) 'mule-tests-alias))
208 (Assert (eq 'mule-tests-alias (coding-system-aliasee 'nested-mule-tests-alias)))
209 (Assert (coding-system-alias-p 'nested-mule-tests-alias-unix))
210 (Assert (coding-system-alias-p 'nested-mule-tests-alias-dos))
211 (Assert (coding-system-alias-p 'nested-mule-tests-alias-mac))
212 (Assert (eq (find-coding-system 'nested-mule-tests-alias-unix)
213 (find-coding-system 'iso-8859-7-unix)))
216 error "Attempt to create a coding system alias loop"
217 (define-coding-system-alias 'mule-tests-alias 'nested-mule-tests-alias))
219 error "No such coding system"
220 (define-coding-system-alias 'no-such-coding-system 'no-such-coding-system))
222 error "Attempt to create a coding system alias loop"
223 (define-coding-system-alias 'mule-tests-alias 'mule-tests-alias))
225 ;; Test dangling alias deletion
226 (define-coding-system-alias 'mule-tests-alias nil)
227 (Assert (not (coding-system-alias-p 'mule-tests-alias)))
228 (Assert (not (coding-system-alias-p 'mule-tests-alias-unix)))
229 (Assert (not (coding-system-alias-p 'nested-mule-tests-alias)))
230 (Assert (not (coding-system-alias-p 'nested-mule-tests-alias-dos)))
232 ;;---------------------------------------------------------------
233 ;; Test strings waxing and waning across the 8k BIG_STRING limit (see alloc.c)
234 ;;---------------------------------------------------------------
235 (defun charset-char-string (charset)
236 (let (lo hi string n)
237 (if (= (charset-chars charset) 94)
240 (if (= (charset-dimension charset) 1)
242 (setq string (make-string (1+ (- hi lo)) ??))
244 (loop for j from lo to hi do
246 (aset string n (make-char charset j))
250 (setq string (make-string (* (1+ (- hi lo)) (1+ (- hi lo))) ??))
252 (loop for j from lo to hi do
253 (loop for k from lo to hi do
255 (aset string n (make-char charset j k))
259 ;; The following two used to crash xemacs!
260 (Assert (charset-char-string 'japanese-jisx0208))
261 (aset (make-string 9003 ??) 1 (make-char 'latin-iso8859-1 77))
263 (let ((greek-string (charset-char-string 'greek-iso8859-7))
264 (string (make-string (* 96 60) ??)))
265 (loop for j from 0 below (length string) do
266 (aset string j (aref greek-string (mod j 96))))
267 (loop for k in '(0 1 58 59) do
268 (Assert (equal (substring string (* 96 k) (* 96 (1+ k))) greek-string))))
270 (let ((greek-string (charset-char-string 'greek-iso8859-7))
271 (string (make-string (* 96 60) ??)))
272 (loop for j from (1- (length string)) downto 0 do
273 (aset string j (aref greek-string (mod j 96))))
274 (loop for k in '(0 1 58 59) do
275 (Assert (equal (substring string (* 96 k) (* 96 (1+ k))) greek-string))))
277 (let ((ascii-string (charset-char-string 'ascii))
278 (string (make-string (* 94 60) (make-char 'greek-iso8859-7 57))))
279 (loop for j from 0 below (length string) do
280 (aset string j (aref ascii-string (mod j 94))))
281 (loop for k in '(0 1 58 59) do
282 (Assert (equal (substring string (* 94 k) (+ 94 (* 94 k))) ascii-string))))
284 (let ((ascii-string (charset-char-string 'ascii))
285 (string (make-string (* 94 60) (make-char 'greek-iso8859-7 57))))
286 (loop for j from (1- (length string)) downto 0 do
287 (aset string j (aref ascii-string (mod j 94))))
288 (loop for k in '(0 1 58 59) do
289 (Assert (equal (substring string (* 94 k) (* 94 (1+ k))) ascii-string))))
291 ;;---------------------------------------------------------------
292 ;; Test file-system character conversion (and, en passant, file ops)
293 ;;---------------------------------------------------------------
294 (let* ((scaron (make-char 'latin-iso8859-2 57))
295 (latin2-string (make-string 4 scaron))
296 (prefix (concat (file-name-as-directory
297 (file-truename (temp-directory)))
299 (name1 (make-temp-name prefix))
300 (name2 (make-temp-name prefix))
301 (file-name-coding-system 'iso-8859-2))
302 ;; This is how you suppress output from `message', called by `write-region'
303 (flet ((append-message (&rest args) ()))
304 (Assert (not (equal name1 name2)))
305 (Assert (not (file-exists-p name1)))
306 (write-region (point-min) (point-max) name1)
307 (Assert (file-exists-p name1))
308 (when (fboundp 'make-symbolic-link)
309 (make-symbolic-link name1 name2)
310 (Assert (file-exists-p name2))
311 (Assert (equal (file-truename name2) name1))
312 (Assert (equal (file-truename name1) name1)))
314 (ignore-file-errors (delete-file name1) (delete-file name2))))
316 ;; Add many more file operation tests here...
318 ;;---------------------------------------------------------------
319 ;; Test Unicode-related functions
320 ;;---------------------------------------------------------------
321 (let* ((scaron (make-char 'latin-iso8859-2 57)))
322 (loop for code in '(#x0000 #x2222 #x4444 #xffff) do
324 (set-ucs-char code scaron)
325 (Assert (eq scaron (ucs-char code)))))
327 (Assert (eq nil (set-ucs-char #x1ffff scaron)))
328 (Check-Error wrong-type-argument (set-ucs-char -10000 scaron)))