428
|
1 ;; Copyright (C) 1999 Free Software Foundation, Inc.
|
|
2
|
|
3 ;; Author: Hrvoje Niksic <hniksic@xemacs.org>
|
440
|
4 ;; Maintainers: Hrvoje Niksic <hniksic@xemacs.org>,
|
|
5 ;; Martin Buchholz <martin@xemacs.org>
|
428
|
6 ;; Created: 1999
|
|
7 ;; Keywords: tests
|
|
8
|
|
9 ;; This file is part of XEmacs.
|
|
10
|
|
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)
|
|
14 ;; any later version.
|
|
15
|
|
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.
|
|
20
|
|
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
|
|
24 ;; 02111-1307, USA.
|
|
25
|
|
26 ;;; Synched up with: Not in FSF.
|
|
27
|
|
28 ;;; Commentary:
|
|
29
|
|
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.
|
|
32
|
434
|
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.
|
|
35
|
428
|
36 ;;-----------------------------------------------------------------
|
|
37 ;; Test whether all legal chars may be safely inserted to a buffer.
|
|
38 ;;-----------------------------------------------------------------
|
|
39
|
|
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.
|
|
45
|
|
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)))
|
|
49 (list nil)
|
|
50 (i 0))
|
|
51 (while (< i max)
|
|
52 (and (not for-test-harness)
|
|
53 (zerop (% i 1000))
|
|
54 (message "%d" i))
|
|
55 (and (int-char i)
|
|
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)))
|
|
59 (setq i (1+ i)))
|
|
60 (let ((string (apply #'string (nreverse list))))
|
|
61 (if for-test-harness
|
|
62 ;; For use with test-harness, use Assert and a temporary
|
|
63 ;; buffer.
|
|
64 (with-temp-buffer
|
|
65 (insert string)
|
|
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"))
|
|
70 (erase-buffer)
|
|
71 (buffer-disable-undo)
|
|
72 (insert string)
|
|
73 (assert (equal (buffer-string) string))))))
|
|
74
|
|
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.
|
|
79 (test-chars t)
|
434
|
80
|
|
81 ;;-----------------------------------------------------------------
|
|
82 ;; Test string modification functions that modify the length of a char.
|
|
83 ;;-----------------------------------------------------------------
|
|
84
|
|
85 (when (featurep 'mule)
|
442
|
86 ;;---------------------------------------------------------------
|
434
|
87 ;; Test fillarray
|
442
|
88 ;;---------------------------------------------------------------
|
434
|
89 (macrolet
|
|
90 ((fillarray-test
|
|
91 (charset1 charset2)
|
|
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))
|
|
103
|
|
104 ;; Test aset
|
|
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))))
|
|
108
|
442
|
109 ;;---------------------------------------------------------------
|
440
|
110 ;; Test coding system functions
|
442
|
111 ;;---------------------------------------------------------------
|
440
|
112
|
|
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)))
|
|
119 (Check-Error-Message
|
|
120 error "Symbol is the canonical name of a coding system and cannot be redefined"
|
|
121 (define-coding-system-alias 'binary 'iso8859-2))
|
|
122 (Check-Error-Message
|
|
123 error "Symbol is not a coding system alias"
|
|
124 (coding-system-aliasee 'binary))
|
|
125
|
|
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)))
|
|
134
|
|
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)))
|
|
143
|
|
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)))
|
|
153
|
|
154 (Check-Error-Message
|
|
155 error "Attempt to create a coding system alias loop"
|
|
156 (define-coding-system-alias 'mule-tests-alias 'nested-mule-tests-alias))
|
|
157 (Check-Error-Message
|
|
158 error "No such coding system"
|
|
159 (define-coding-system-alias 'no-such-coding-system 'no-such-coding-system))
|
|
160 (Check-Error-Message
|
|
161 error "Attempt to create a coding system alias loop"
|
|
162 (define-coding-system-alias 'mule-tests-alias 'mule-tests-alias))
|
|
163
|
|
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)))
|
|
171 (Check-Error-Message
|
|
172 error "Symbol is the canonical name of a coding system and cannot be redefined"
|
|
173 (define-coding-system-alias 'binary 'iso8859-2))
|
|
174 (Check-Error-Message
|
|
175 error "Symbol is not a coding system alias"
|
|
176 (coding-system-aliasee 'binary))
|
|
177
|
|
178 (define-coding-system-alias 'nested-mule-tests-alias nil)
|
|
179 (define-coding-system-alias 'mule-tests-alias nil)
|
|
180
|
|
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))
|
|
190
|
|
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)))
|
|
201
|
|
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)))
|
|
214
|
|
215 (Check-Error-Message
|
|
216 error "Attempt to create a coding system alias loop"
|
|
217 (define-coding-system-alias 'mule-tests-alias 'nested-mule-tests-alias))
|
|
218 (Check-Error-Message
|
|
219 error "No such coding system"
|
|
220 (define-coding-system-alias 'no-such-coding-system 'no-such-coding-system))
|
|
221 (Check-Error-Message
|
|
222 error "Attempt to create a coding system alias loop"
|
|
223 (define-coding-system-alias 'mule-tests-alias 'mule-tests-alias))
|
|
224
|
|
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)))
|
|
231
|
442
|
232 ;;---------------------------------------------------------------
|
438
|
233 ;; Test strings waxing and waning across the 8k BIG_STRING limit (see alloc.c)
|
442
|
234 ;;---------------------------------------------------------------
|
438
|
235 (defun charset-char-string (charset)
|
|
236 (let (lo hi string n)
|
|
237 (if (= (charset-chars charset) 94)
|
|
238 (setq lo 33 hi 126)
|
|
239 (setq lo 32 hi 127))
|
|
240 (if (= (charset-dimension charset) 1)
|
|
241 (progn
|
|
242 (setq string (make-string (1+ (- hi lo)) ??))
|
|
243 (setq n 0)
|
|
244 (loop for j from lo to hi do
|
|
245 (progn
|
|
246 (aset string n (make-char charset j))
|
|
247 (incf n)))
|
|
248 string)
|
|
249 (progn
|
|
250 (setq string (make-string (* (1+ (- hi lo)) (1+ (- hi lo))) ??))
|
|
251 (setq n 0)
|
|
252 (loop for j from lo to hi do
|
|
253 (loop for k from lo to hi do
|
|
254 (progn
|
|
255 (aset string n (make-char charset j k))
|
|
256 (incf n))))
|
|
257 string))))
|
|
258
|
|
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))
|
|
262
|
|
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))))
|
|
269
|
|
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))))
|
|
276
|
|
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))))
|
|
283
|
|
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))))
|
|
290
|
442
|
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))
|
597
|
296 (prefix (concat (file-name-as-directory
|
|
297 (file-truename (temp-directory)))
|
|
298 latin2-string))
|
442
|
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)))
|
|
313
|
|
314 (ignore-file-errors (delete-file name1) (delete-file name2))))
|
|
315
|
|
316 ;; Add many more file operation tests here...
|
|
317
|
|
318 ;;---------------------------------------------------------------
|
|
319 ;; Test Unicode-related functions
|
|
320 ;;---------------------------------------------------------------
|
|
321 (let* ((scaron (make-char 'latin-iso8859-2 57)))
|
875
|
322 ;; Used to try #x0000, but you can't change ASCII or Latin-1
|
|
323 (loop for code in '(#x0100 #x2222 #x4444 #xffff) do
|
442
|
324 (progn
|
800
|
325 (set-unicode-conversion scaron code)
|
|
326 (Assert (eq code (char-to-unicode scaron)))
|
|
327 (Assert (eq scaron (unicode-to-char code '(latin-iso8859-2))))))
|
442
|
328
|
800
|
329 (Check-Error wrong-type-argument (set-unicode-conversion scaron -10000)))
|
434
|
330 )
|