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 (gc-cons-threshold most-positive-fixnum))
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))
251 (setq string (make-string (* (1+ (- hi lo)) (1+ (- hi lo))) ??))
253 (loop for j from lo to hi do
254 (loop for k from lo to hi do
256 (aset string n (make-char charset j k))
261 ;; The following two used to crash xemacs!
262 (Assert (charset-char-string 'japanese-jisx0208))
263 (aset (make-string 9003 ??) 1 (make-char 'latin-iso8859-1 77))
265 (let ((greek-string (charset-char-string 'greek-iso8859-7))
266 (string (make-string (* 96 60) ??)))
267 (loop for j from 0 below (length string) do
268 (aset string j (aref greek-string (mod j 96))))
269 (loop for k in '(0 1 58 59) do
270 (Assert (equal (substring string (* 96 k) (* 96 (1+ k))) greek-string))))
272 (let ((greek-string (charset-char-string 'greek-iso8859-7))
273 (string (make-string (* 96 60) ??)))
274 (loop for j from (1- (length string)) downto 0 do
275 (aset string j (aref greek-string (mod j 96))))
276 (loop for k in '(0 1 58 59) do
277 (Assert (equal (substring string (* 96 k) (* 96 (1+ k))) greek-string))))
279 (let ((ascii-string (charset-char-string 'ascii))
280 (string (make-string (* 94 60) (make-char 'greek-iso8859-7 57))))
281 (loop for j from 0 below (length string) do
282 (aset string j (aref ascii-string (mod j 94))))
283 (loop for k in '(0 1 58 59) do
284 (Assert (equal (substring string (* 94 k) (+ 94 (* 94 k))) ascii-string))))
286 (let ((ascii-string (charset-char-string 'ascii))
287 (string (make-string (* 94 60) (make-char 'greek-iso8859-7 57))))
288 (loop for j from (1- (length string)) downto 0 do
289 (aset string j (aref ascii-string (mod j 94))))
290 (loop for k in '(0 1 58 59) do
291 (Assert (equal (substring string (* 94 k) (* 94 (1+ k))) ascii-string))))
293 ;;---------------------------------------------------------------
294 ;; Test file-system character conversion (and, en passant, file ops)
295 ;;---------------------------------------------------------------
296 (let* ((scaron (make-char 'latin-iso8859-2 57))
297 (latin2-string (make-string 4 scaron))
298 (prefix (concat (file-name-as-directory
299 (file-truename (temp-directory)))
301 (name1 (make-temp-name prefix))
302 (name2 (make-temp-name prefix))
303 (file-name-coding-system 'iso-8859-2))
304 ;; This is how you suppress output from `message', called by `write-region'
305 (flet ((append-message (&rest args) ()))
306 (Assert (not (equal name1 name2)))
307 ;; Kludge to handle Mac OS X which groks only UTF-8.
308 (cond ((eq system-type 'darwin)
309 (Check-Error-Message 'file-error "Opening output file"
310 (write-region (point-min) (point-max) name1))
312 (setq file-name-coding-system 'utf-8)))
313 (Assert (not (file-exists-p name1)))
314 (write-region (point-min) (point-max) name1)
315 (Assert (file-exists-p name1))
316 (when (fboundp 'make-symbolic-link)
317 (make-symbolic-link name1 name2)
318 (Assert (file-exists-p name2))
319 (Assert (equal (file-truename name2) name1))
320 (Assert (equal (file-truename name1) name1)))
322 (ignore-file-errors (delete-file name1) (delete-file name2))))
323 ;; Is a non-Latin-1 directory name preserved for call-process?
325 ;; The bug should manifest itself on Windows, but I've no access
326 ;; to a Windows machine to verify that any test works.
327 (eq directory-sep-char ?/)
328 ;; file-name-coding-system on Darwin is _always_ UTF-8--the system
329 ;; enforces this--which coding system we don't have available in
330 ;; 21.4, outside of packages. I could jump through lots of hoops to
331 ;; have the test work anyway, but I'm not really into that right
333 (not (eq system-type 'darwin)))
334 (let ((process-coding-system-alist '((".*" . iso-8859-1)))
335 (file-name-coding-system 'iso-8859-1)
337 (make-directory (concat (temp-directory) "/\260\354"))
338 (setq file-name-coding-system 'euc-jp)
339 (setq default-directory (format "%s/%c/" (temp-directory)
340 (make-char 'japanese-jisx0208 48 108)))
341 (Assert (equal (shell-command-to-string "pwd")
342 (format "%s/\260\354\n" (temp-directory))))
343 (delete-directory default-directory)))
345 ;; Add many more file operation tests here...
347 ;;---------------------------------------------------------------
348 ;; Test Unicode-related functions
349 ;;---------------------------------------------------------------
350 (let* ((scaron (make-char 'latin-iso8859-2 57)))
351 (loop for code in '(#x0000 #x2222 #x4444 #xffff) do
353 (set-ucs-char code scaron)
354 (Assert (eq scaron (ucs-char code)))))
356 (Assert (eq nil (set-ucs-char #x1ffff scaron)))
357 (Check-Error wrong-type-argument (set-ucs-char -10000 scaron)))