Mercurial > hg > xemacs-beta
comparison tests/mule-tests.el @ 361:7347b34c275b r21-1-10
Import from CVS: tag r21-1-10
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:58:40 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
360:0f00b38cfccb | 361:7347b34c275b |
---|---|
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 (when (not (featurep 'mule)) | |
82 ;; prevent non-mule errors and warnings - Ugh! | |
83 (defun make-char (&rest args) nil) | |
84 (defvar file-name-coding-system) | |
85 ) | |
86 (when (featurep 'mule) | |
87 ;;--------------------------------------------------------------- | |
88 ;; Test fillarray | |
89 ;;--------------------------------------------------------------- | |
90 (macrolet | |
91 ((fillarray-test | |
92 (charset1 charset2) | |
93 (let ((char1 (make-char charset1 69)) | |
94 (char2 (make-char charset2 69))) | |
95 `(let ((string (make-string 1000 ,char1))) | |
96 (fillarray string ,char2) | |
97 (Assert (eq (aref string 0) ,char2)) | |
98 (Assert (eq (aref string (1- (length string))) ,char2)) | |
99 (Assert (eq (length string) 1000)))))) | |
100 (fillarray-test ascii latin-iso8859-1) | |
101 (fillarray-test ascii latin-iso8859-2) | |
102 (fillarray-test latin-iso8859-1 ascii) | |
103 (fillarray-test latin-iso8859-2 ascii)) | |
104 | |
105 ;; Test aset | |
106 (let ((string (string (make-char 'ascii 69) (make-char 'latin-iso8859-2 69)))) | |
107 (aset string 0 (make-char 'latin-iso8859-2 42)) | |
108 (Assert (eq (aref string 1) (make-char 'latin-iso8859-2 69)))) | |
109 | |
110 ;;--------------------------------------------------------------- | |
111 ;; Test strings waxing and waning across the 8k BIG_STRING limit (see alloc.c) | |
112 ;;--------------------------------------------------------------- | |
113 (defun charset-char-string (charset) | |
114 (let (lo hi string n) | |
115 (if (= (charset-chars charset) 94) | |
116 (setq lo 33 hi 126) | |
117 (setq lo 32 hi 127)) | |
118 (if (= (charset-dimension charset) 1) | |
119 (progn | |
120 (setq string (make-string (1+ (- hi lo)) ??)) | |
121 (setq n 0) | |
122 (loop for j from lo to hi do | |
123 (progn | |
124 (aset string n (make-char charset j)) | |
125 (incf n))) | |
126 string) | |
127 (progn | |
128 (setq string (make-string (* (1+ (- hi lo)) (1+ (- hi lo))) ??)) | |
129 (setq n 0) | |
130 (loop for j from lo to hi do | |
131 (loop for k from lo to hi do | |
132 (progn | |
133 (aset string n (make-char charset j k)) | |
134 (incf n)))) | |
135 string)))) | |
136 | |
137 ;; The following two used to crash xemacs! | |
138 (Assert (charset-char-string 'japanese-jisx0208)) | |
139 (aset (make-string 9003 ??) 1 (make-char 'latin-iso8859-1 77)) | |
140 | |
141 (let ((greek-string (charset-char-string 'greek-iso8859-7)) | |
142 (string (make-string (* 96 60) ??))) | |
143 (loop for j from 0 below (length string) do | |
144 (aset string j (aref greek-string (mod j 96)))) | |
145 (loop for k in '(0 1 58 59) do | |
146 (Assert (equal (substring string (* 96 k) (* 96 (1+ k))) greek-string)))) | |
147 | |
148 (let ((greek-string (charset-char-string 'greek-iso8859-7)) | |
149 (string (make-string (* 96 60) ??))) | |
150 (loop for j from (1- (length string)) downto 0 do | |
151 (aset string j (aref greek-string (mod j 96)))) | |
152 (loop for k in '(0 1 58 59) do | |
153 (Assert (equal (substring string (* 96 k) (* 96 (1+ k))) greek-string)))) | |
154 | |
155 (let ((ascii-string (charset-char-string 'ascii)) | |
156 (string (make-string (* 94 60) (make-char 'greek-iso8859-7 57)))) | |
157 (loop for j from 0 below (length string) do | |
158 (aset string j (aref ascii-string (mod j 94)))) | |
159 (loop for k in '(0 1 58 59) do | |
160 (Assert (equal (substring string (* 94 k) (+ 94 (* 94 k))) ascii-string)))) | |
161 | |
162 (let ((ascii-string (charset-char-string 'ascii)) | |
163 (string (make-string (* 94 60) (make-char 'greek-iso8859-7 57)))) | |
164 (loop for j from (1- (length string)) downto 0 do | |
165 (aset string j (aref ascii-string (mod j 94)))) | |
166 (loop for k in '(0 1 58 59) do | |
167 (Assert (equal (substring string (* 94 k) (* 94 (1+ k))) ascii-string)))) | |
168 | |
169 ;;--------------------------------------------------------------- | |
170 ;; Test file-system character conversion (and, en passant, file ops) | |
171 ;;--------------------------------------------------------------- | |
172 (let* ((scaron (make-char 'latin-iso8859-2 57)) | |
173 (latin2-string (make-string 4 scaron)) | |
174 (prefix (concat (file-name-as-directory (temp-directory)) latin2-string)) | |
175 (name1 (make-temp-name prefix)) | |
176 (name2 (make-temp-name prefix)) | |
177 (file-name-coding-system 'iso-8859-2)) | |
178 ;; This is how you suppress output from `message', called by `write-region' | |
179 (flet ((append-message (&rest args) ())) | |
180 (Assert (not (equal name1 name2))) | |
181 (Assert (not (file-exists-p name1))) | |
182 (write-region (point-min) (point-max) name1) | |
183 (Assert (file-exists-p name1)) | |
184 (when (fboundp 'make-symbolic-link) | |
185 (make-symbolic-link name1 name2) | |
186 (Assert (file-exists-p name2)) | |
187 (Assert (equal (file-truename name2) name1)) | |
188 (Assert (equal (file-truename name1) name1))) | |
189 | |
190 (condition-case nil | |
191 (progn | |
192 (delete-file name1) | |
193 (delete-file name2)) | |
194 (file-error nil)))) | |
195 | |
196 ;; Add many more file operation tests here... | |
197 | |
198 ) |