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)
90 (let ((char1 (make-char charset1 69))
91 (char2 (make-char charset2 69)))
92 `(let ((string (make-string 1000 ,char1)))
93 (fillarray string ,char2)
94 (Assert (eq (aref string 0) ,char2))
95 (Assert (eq (aref string (1- (length string))) ,char2))
96 (Assert (eq (length string) 1000))))))
97 (fillarray-test ascii latin-iso8859-1)
98 (fillarray-test ascii latin-iso8859-2)
99 (fillarray-test latin-iso8859-1 ascii)
100 (fillarray-test latin-iso8859-2 ascii))
103 (let ((string (string (make-char 'ascii 69) (make-char 'latin-iso8859-2 69))))
104 (aset string 0 (make-char 'latin-iso8859-2 42))
105 (Assert (eq (aref string 1) (make-char 'latin-iso8859-2 69))))
107 ;; Test coding system functions
109 ;; Create alias for coding system without subsidiaries
110 (Assert (coding-system-p (find-coding-system 'binary)))
111 (Assert (coding-system-canonical-name-p 'binary))
112 (Assert (not (coding-system-alias-p 'binary)))
113 (Assert (not (coding-system-alias-p 'mule-tests-alias)))
114 (Assert (not (coding-system-canonical-name-p 'mule-tests-alias)))
116 error "Symbol is the canonical name of a coding system and cannot be redefined"
117 (define-coding-system-alias 'binary 'iso8859-2))
119 error "Symbol is not a coding system alias"
120 (coding-system-aliasee 'binary))
122 (define-coding-system-alias 'mule-tests-alias 'binary)
123 (Assert (coding-system-alias-p 'mule-tests-alias))
124 (Assert (not (coding-system-canonical-name-p 'mule-tests-alias)))
125 (Assert (eq (get-coding-system 'binary) (get-coding-system 'mule-tests-alias)))
126 (Assert (eq 'binary (coding-system-aliasee 'mule-tests-alias)))
127 (Assert (not (coding-system-alias-p 'mule-tests-alias-unix)))
128 (Assert (not (coding-system-alias-p 'mule-tests-alias-dos)))
129 (Assert (not (coding-system-alias-p 'mule-tests-alias-mac)))
131 (define-coding-system-alias 'mule-tests-alias (get-coding-system 'binary))
132 (Assert (coding-system-alias-p 'mule-tests-alias))
133 (Assert (not (coding-system-canonical-name-p 'mule-tests-alias)))
134 (Assert (eq (get-coding-system 'binary) (get-coding-system 'mule-tests-alias)))
135 (Assert (eq 'binary (coding-system-aliasee 'mule-tests-alias)))
136 (Assert (not (coding-system-alias-p 'mule-tests-alias-unix)))
137 (Assert (not (coding-system-alias-p 'mule-tests-alias-dos)))
138 (Assert (not (coding-system-alias-p 'mule-tests-alias-mac)))
140 (define-coding-system-alias 'nested-mule-tests-alias 'mule-tests-alias)
141 (Assert (coding-system-alias-p 'nested-mule-tests-alias))
142 (Assert (not (coding-system-canonical-name-p 'nested-mule-tests-alias)))
143 (Assert (eq (get-coding-system 'binary) (get-coding-system 'nested-mule-tests-alias)))
144 (Assert (eq (coding-system-aliasee 'nested-mule-tests-alias) 'mule-tests-alias))
145 (Assert (eq 'mule-tests-alias (coding-system-aliasee 'nested-mule-tests-alias)))
146 (Assert (not (coding-system-alias-p 'nested-mule-tests-alias-unix)))
147 (Assert (not (coding-system-alias-p 'nested-mule-tests-alias-dos)))
148 (Assert (not (coding-system-alias-p 'nested-mule-tests-alias-mac)))
151 error "Attempt to create a coding system alias loop"
152 (define-coding-system-alias 'mule-tests-alias 'nested-mule-tests-alias))
154 error "No such coding system"
155 (define-coding-system-alias 'no-such-coding-system 'no-such-coding-system))
157 error "Attempt to create a coding system alias loop"
158 (define-coding-system-alias 'mule-tests-alias 'mule-tests-alias))
160 (define-coding-system-alias 'nested-mule-tests-alias nil)
161 (define-coding-system-alias 'mule-tests-alias nil)
162 (Assert (coding-system-p (find-coding-system 'binary)))
163 (Assert (coding-system-canonical-name-p 'binary))
164 (Assert (not (coding-system-alias-p 'binary)))
165 (Assert (not (coding-system-alias-p 'mule-tests-alias)))
166 (Assert (not (coding-system-canonical-name-p 'mule-tests-alias)))
168 error "Symbol is the canonical name of a coding system and cannot be redefined"
169 (define-coding-system-alias 'binary 'iso8859-2))
171 error "Symbol is not a coding system alias"
172 (coding-system-aliasee 'binary))
174 (define-coding-system-alias 'nested-mule-tests-alias nil)
175 (define-coding-system-alias 'mule-tests-alias nil)
177 ;; Create alias for coding system with subsidiaries
178 (define-coding-system-alias 'mule-tests-alias 'iso-8859-7)
179 (Assert (coding-system-alias-p 'mule-tests-alias))
180 (Assert (not (coding-system-canonical-name-p 'mule-tests-alias)))
181 (Assert (eq (get-coding-system 'iso-8859-7) (get-coding-system 'mule-tests-alias)))
182 (Assert (eq 'iso-8859-7 (coding-system-aliasee 'mule-tests-alias)))
183 (Assert (coding-system-alias-p 'mule-tests-alias-unix))
184 (Assert (coding-system-alias-p 'mule-tests-alias-dos))
185 (Assert (coding-system-alias-p 'mule-tests-alias-mac))
187 (define-coding-system-alias 'mule-tests-alias (get-coding-system 'iso-8859-7))
188 (Assert (coding-system-alias-p 'mule-tests-alias))
189 (Assert (not (coding-system-canonical-name-p 'mule-tests-alias)))
190 (Assert (eq (get-coding-system 'iso-8859-7) (get-coding-system 'mule-tests-alias)))
191 (Assert (eq 'iso-8859-7 (coding-system-aliasee 'mule-tests-alias)))
192 (Assert (coding-system-alias-p 'mule-tests-alias-unix))
193 (Assert (coding-system-alias-p 'mule-tests-alias-dos))
194 (Assert (coding-system-alias-p 'mule-tests-alias-mac))
195 (Assert (eq (find-coding-system 'mule-tests-alias-mac)
196 (find-coding-system 'iso-8859-7-mac)))
198 (define-coding-system-alias 'nested-mule-tests-alias 'mule-tests-alias)
199 (Assert (coding-system-alias-p 'nested-mule-tests-alias))
200 (Assert (not (coding-system-canonical-name-p 'nested-mule-tests-alias)))
201 (Assert (eq (get-coding-system 'iso-8859-7)
202 (get-coding-system 'nested-mule-tests-alias)))
203 (Assert (eq (coding-system-aliasee 'nested-mule-tests-alias) 'mule-tests-alias))
204 (Assert (eq 'mule-tests-alias (coding-system-aliasee 'nested-mule-tests-alias)))
205 (Assert (coding-system-alias-p 'nested-mule-tests-alias-unix))
206 (Assert (coding-system-alias-p 'nested-mule-tests-alias-dos))
207 (Assert (coding-system-alias-p 'nested-mule-tests-alias-mac))
208 (Assert (eq (find-coding-system 'nested-mule-tests-alias-unix)
209 (find-coding-system 'iso-8859-7-unix)))
212 error "Attempt to create a coding system alias loop"
213 (define-coding-system-alias 'mule-tests-alias 'nested-mule-tests-alias))
215 error "No such coding system"
216 (define-coding-system-alias 'no-such-coding-system 'no-such-coding-system))
218 error "Attempt to create a coding system alias loop"
219 (define-coding-system-alias 'mule-tests-alias 'mule-tests-alias))
221 ;; Test dangling alias deletion
222 (define-coding-system-alias 'mule-tests-alias nil)
223 (Assert (not (coding-system-alias-p 'mule-tests-alias)))
224 (Assert (not (coding-system-alias-p 'mule-tests-alias-unix)))
225 (Assert (not (coding-system-alias-p 'nested-mule-tests-alias)))
226 (Assert (not (coding-system-alias-p 'nested-mule-tests-alias-dos)))
228 ;; Test strings waxing and waning across the 8k BIG_STRING limit (see alloc.c)
229 (defun charset-char-string (charset)
230 (let (lo hi string n)
231 (if (= (charset-chars charset) 94)
234 (if (= (charset-dimension charset) 1)
236 (setq string (make-string (1+ (- hi lo)) ??))
238 (loop for j from lo to hi do
240 (aset string n (make-char charset j))
244 (setq string (make-string (* (1+ (- hi lo)) (1+ (- hi lo))) ??))
246 (loop for j from lo to hi do
247 (loop for k from lo to hi do
249 (aset string n (make-char charset j k))
253 ;; The following two used to crash xemacs!
254 (Assert (charset-char-string 'japanese-jisx0208))
255 (aset (make-string 9003 ??) 1 (make-char 'latin-iso8859-1 77))
257 (let ((greek-string (charset-char-string 'greek-iso8859-7))
258 (string (make-string (* 96 60) ??)))
259 (loop for j from 0 below (length string) do
260 (aset string j (aref greek-string (mod j 96))))
261 (loop for k in '(0 1 58 59) do
262 (Assert (equal (substring string (* 96 k) (* 96 (1+ k))) greek-string))))
264 (let ((greek-string (charset-char-string 'greek-iso8859-7))
265 (string (make-string (* 96 60) ??)))
266 (loop for j from (1- (length string)) downto 0 do
267 (aset string j (aref greek-string (mod j 96))))
268 (loop for k in '(0 1 58 59) do
269 (Assert (equal (substring string (* 96 k) (* 96 (1+ k))) greek-string))))
271 (let ((ascii-string (charset-char-string 'ascii))
272 (string (make-string (* 94 60) (make-char 'greek-iso8859-7 57))))
273 (loop for j from 0 below (length string) do
274 (aset string j (aref ascii-string (mod j 94))))
275 (loop for k in '(0 1 58 59) do
276 (Assert (equal (substring string (* 94 k) (+ 94 (* 94 k))) ascii-string))))
278 (let ((ascii-string (charset-char-string 'ascii))
279 (string (make-string (* 94 60) (make-char 'greek-iso8859-7 57))))
280 (loop for j from (1- (length string)) downto 0 do
281 (aset string j (aref ascii-string (mod j 94))))
282 (loop for k in '(0 1 58 59) do
283 (Assert (equal (substring string (* 94 k) (* 94 (1+ k))) ascii-string))))