398
|
1 ;; Copyright (C) 1999 Free Software Foundation, Inc.
|
|
2
|
|
3 ;; Author: Hrvoje Niksic <hniksic@xemacs.org>
|
|
4 ;; Maintainers: Hrvoje Niksic <hniksic@xemacs.org>,
|
|
5 ;; Martin Buchholz <martin@xemacs.org>
|
|
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
|
|
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
|
|
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)
|
|
80
|
|
81 ;;-----------------------------------------------------------------
|
|
82 ;; Test string modification functions that modify the length of a char.
|
|
83 ;;-----------------------------------------------------------------
|
|
84
|
|
85 (when (featurep 'mule)
|
|
86 ;; Test fillarray
|
|
87 (macrolet
|
|
88 ((fillarray-test
|
|
89 (charset1 charset2)
|
|
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))
|
|
101
|
|
102 ;; Test aset
|
|
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))))
|
|
106
|
|
107 ;; Test coding system functions
|
|
108
|
|
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)))
|
|
115 (Check-Error-Message
|
|
116 error "Symbol is the canonical name of a coding system and cannot be redefined"
|
|
117 (define-coding-system-alias 'binary 'iso8859-2))
|
|
118 (Check-Error-Message
|
|
119 error "Symbol is not a coding system alias"
|
|
120 (coding-system-aliasee 'binary))
|
|
121
|
|
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)))
|
|
130
|
|
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)))
|
|
139
|
|
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)))
|
|
149
|
|
150 (Check-Error-Message
|
|
151 error "Attempt to create a coding system alias loop"
|
|
152 (define-coding-system-alias 'mule-tests-alias 'nested-mule-tests-alias))
|
|
153 (Check-Error-Message
|
|
154 error "No such coding system"
|
|
155 (define-coding-system-alias 'no-such-coding-system 'no-such-coding-system))
|
|
156 (Check-Error-Message
|
|
157 error "Attempt to create a coding system alias loop"
|
|
158 (define-coding-system-alias 'mule-tests-alias 'mule-tests-alias))
|
|
159
|
|
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)))
|
|
167 (Check-Error-Message
|
|
168 error "Symbol is the canonical name of a coding system and cannot be redefined"
|
|
169 (define-coding-system-alias 'binary 'iso8859-2))
|
|
170 (Check-Error-Message
|
|
171 error "Symbol is not a coding system alias"
|
|
172 (coding-system-aliasee 'binary))
|
|
173
|
|
174 (define-coding-system-alias 'nested-mule-tests-alias nil)
|
|
175 (define-coding-system-alias 'mule-tests-alias nil)
|
|
176
|
|
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))
|
|
186
|
|
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)))
|
|
197
|
|
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)))
|
|
210
|
|
211 (Check-Error-Message
|
|
212 error "Attempt to create a coding system alias loop"
|
|
213 (define-coding-system-alias 'mule-tests-alias 'nested-mule-tests-alias))
|
|
214 (Check-Error-Message
|
|
215 error "No such coding system"
|
|
216 (define-coding-system-alias 'no-such-coding-system 'no-such-coding-system))
|
|
217 (Check-Error-Message
|
|
218 error "Attempt to create a coding system alias loop"
|
|
219 (define-coding-system-alias 'mule-tests-alias 'mule-tests-alias))
|
|
220
|
|
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)))
|
|
227
|
|
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)
|
|
232 (setq lo 33 hi 126)
|
|
233 (setq lo 32 hi 127))
|
|
234 (if (= (charset-dimension charset) 1)
|
|
235 (progn
|
|
236 (setq string (make-string (1+ (- hi lo)) ??))
|
|
237 (setq n 0)
|
|
238 (loop for j from lo to hi do
|
|
239 (progn
|
|
240 (aset string n (make-char charset j))
|
|
241 (incf n)))
|
|
242 string)
|
|
243 (progn
|
|
244 (setq string (make-string (* (1+ (- hi lo)) (1+ (- hi lo))) ??))
|
|
245 (setq n 0)
|
|
246 (loop for j from lo to hi do
|
|
247 (loop for k from lo to hi do
|
|
248 (progn
|
|
249 (aset string n (make-char charset j k))
|
|
250 (incf n))))
|
|
251 string))))
|
|
252
|
|
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))
|
|
256
|
|
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))))
|
|
263
|
|
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))))
|
|
270
|
|
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))))
|
|
277
|
|
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))))
|
|
284
|
|
285 )
|