1 /* C support for testing XEmacs - see tests/automated/c-tests.el
2 Copyright (C) 2000 Martin Buchholz
4 This file is part of XEmacs.
6 XEmacs is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with XEmacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Author: Martin Buchholz
23 This file provides support for running tests for XEmacs that cannot
24 be written entirely in Lisp. These tests are run automatically via
25 tests/automated/c-tests.el, or can be run by hand using M-x */
34 static Lisp_Object Vtest_function_list;
37 DEFUN ("test-data-format-conversion", Ftest_data_format_conversion, 0, 0, "", /*
38 Test TO_EXTERNAL_FORMAT() and TO_INTERNAL_FORMAT()
42 void *ptr; size_t len;
43 Lisp_Object string, opaque;
45 Bufbyte int_foo[] = "\n\nfoo\nbar";
46 Extbyte ext_unix[]= "\n\nfoo\nbar";
48 Extbyte ext_dos[] = "\r\n\r\nfoo\r\nbar";
49 Extbyte ext_mac[] = "\r\rfoo\rbar";
50 Lisp_Object opaque_dos = make_opaque (ext_dos, sizeof (ext_dos) - 1);
51 Lisp_Object string_foo = make_string (int_foo, sizeof (int_foo) - 1);
53 Extbyte ext_latin[] = "f\372b\343\340";
54 Bufbyte int_latin1[] = "f\201\372b\201\343\201\340";
55 Bufbyte int_latin2[] = "f\202\372b\202\343\202\340";
57 Extbyte ext_latin12[]= "f\033-A\372b\343\340\033-B";
58 Extbyte ext_tilde[] = "f~b~~";
59 Lisp_Object string_latin2 = make_string (int_latin2, sizeof (int_latin2) - 1);
61 Lisp_Object opaque_latin = make_opaque (ext_latin, sizeof (ext_latin) - 1);
62 Lisp_Object opaque0_latin = make_opaque (ext_latin, sizeof (ext_latin));
63 Lisp_Object string_latin1 = make_string (int_latin1, sizeof (int_latin1) - 1);
65 /* Check for expected strings before and after conversion.
66 Conversions depend on whether MULE is defined,
67 and on whether FILE_CODING is defined. */
69 #define DFC_CHECK_DATA_COND_MULE(ptr,len, \
70 constant_string_mule, \
71 constant_string_non_mule) \
72 DFC_CHECK_DATA (ptr, len, constant_string_mule)
73 #define DFC_CHECK_DATA_COND_MULE_NUL(ptr,len, \
74 constant_string_mule, \
75 constant_string_non_mule) \
76 DFC_CHECK_DATA_NUL (ptr, len, constant_string_mule)
78 #define DFC_CHECK_DATA_COND_MULE(ptr,len, \
79 constant_string_mule, \
80 constant_string_non_mule) \
81 DFC_CHECK_DATA (ptr, len, constant_string_non_mule)
82 #define DFC_CHECK_DATA_COND_MULE_NUL(ptr,len, \
83 constant_string_mule, \
84 constant_string_non_mule) \
85 DFC_CHECK_DATA_NUL (ptr, len, constant_string_non_mule)
89 #define DFC_CHECK_DATA_COND_EOL(ptr,len, \
90 constant_string_eol, \
91 constant_string_non_eol) \
92 DFC_CHECK_DATA (ptr, len, constant_string_eol)
93 #define DFC_CHECK_DATA_COND_EOL_NUL(ptr,len, \
94 constant_string_eol, \
95 constant_string_non_eol) \
96 DFC_CHECK_DATA_NUL (ptr, len, constant_string_eol)
98 #define DFC_CHECK_DATA_COND_EOL(ptr,len, \
99 constant_string_eol, \
100 constant_string_non_eol) \
101 DFC_CHECK_DATA (ptr, len, constant_string_non_eol)
102 #define DFC_CHECK_DATA_COND_EOL_NUL(ptr,len, \
103 constant_string_eol, \
104 constant_string_non_eol) \
105 DFC_CHECK_DATA_NUL (ptr, len, constant_string_non_eol)
108 /* Check for expected strings before and after conversion. */
109 #define DFC_CHECK_DATA(ptr,len, constant_string) do { \
110 assert ((len) == sizeof (constant_string) - 1); \
111 assert (!memcmp (ptr, constant_string, len)); \
114 /* Macro version that includes the trailing NULL byte. */
115 #define DFC_CHECK_DATA_NUL(ptr,len,constant_string) do {\
116 assert ((len) == sizeof (constant_string)); \
117 assert (!memcmp (ptr, constant_string, len)); \
121 ptr = NULL, len = rand();
122 TO_EXTERNAL_FORMAT (DATA, (int_latin2, sizeof (int_latin2)),
124 Fget_coding_system (intern ("iso-8859-2")));
125 DFC_CHECK_DATA_NUL (ptr, len, ext_latin);
127 ptr = NULL, len = rand();
128 TO_EXTERNAL_FORMAT (LISP_STRING, string_latin2,
130 Fget_coding_system (intern ("iso-8859-2")));
131 DFC_CHECK_DATA (ptr, len, ext_latin);
133 ptr = NULL, len = rand();
134 TO_EXTERNAL_FORMAT (LISP_STRING, string_latin1,
136 Fget_coding_system (intern ("iso-8859-2")));
137 DFC_CHECK_DATA (ptr, len, ext_latin12);
139 ptr = NULL, len = rand();
140 TO_EXTERNAL_FORMAT (DATA, (int_latin2, sizeof (int_latin2) - 1),
142 Fget_coding_system (intern ("iso-8859-2")));
143 DFC_CHECK_DATA (ptr, len, ext_latin);
146 TO_EXTERNAL_FORMAT (DATA, (int_latin2, sizeof (int_latin2) - 1),
148 Fget_coding_system (intern ("iso-8859-2")));
149 DFC_CHECK_DATA (XOPAQUE_DATA (opaque), XOPAQUE_SIZE (opaque), ext_latin);
151 ptr = NULL, len = rand();
152 TO_INTERNAL_FORMAT (DATA, (ext_latin, sizeof (ext_latin) - 1),
154 intern ("iso-8859-2"));
155 DFC_CHECK_DATA (ptr, len, int_latin2);
157 ptr = NULL, len = rand();
158 TO_INTERNAL_FORMAT (DATA, (ext_latin, sizeof (ext_latin) - 1),
160 intern ("iso-8859-2"));
161 DFC_CHECK_DATA (ptr, len, int_latin2);
164 TO_INTERNAL_FORMAT (DATA, (ext_latin, sizeof (ext_latin) - 1),
166 intern ("iso-8859-2"));
167 DFC_CHECK_DATA (XSTRING_DATA (string), XSTRING_LENGTH (string), int_latin2);
169 TO_INTERNAL_FORMAT (LISP_OPAQUE, opaque_latin,
171 intern ("iso-8859-2"));
172 DFC_CHECK_DATA (XSTRING_DATA (string), XSTRING_LENGTH (string), int_latin2);
174 TO_INTERNAL_FORMAT (LISP_OPAQUE, opaque0_latin,
176 intern ("iso-8859-2"));
177 DFC_CHECK_DATA_NUL (XSTRING_DATA (string), XSTRING_LENGTH (string), int_latin2);
179 TO_INTERNAL_FORMAT (LISP_OPAQUE, opaque0_latin,
180 LISP_BUFFER, Fcurrent_buffer(),
181 intern ("iso-8859-2"));
182 DFC_CHECK_DATA_NUL (BUF_BYTE_ADDRESS (current_buffer, BUF_PT (current_buffer)),
183 sizeof (int_latin2), int_latin2);
185 TO_INTERNAL_FORMAT (LISP_OPAQUE, opaque_latin,
186 LISP_BUFFER, Fcurrent_buffer(),
187 intern ("iso-8859-1"));
188 DFC_CHECK_DATA (BUF_BYTE_ADDRESS (current_buffer, BUF_PT (current_buffer)),
189 sizeof (int_latin1) - 1, int_latin1);
191 TO_INTERNAL_FORMAT (DATA, (ext_latin12, sizeof (ext_latin12) - 1),
193 intern ("iso-8859-2"));
194 DFC_CHECK_DATA (ptr, len, int_latin1);
198 ptr = NULL, len = rand();
199 TO_EXTERNAL_FORMAT (DATA, (int_latin1, sizeof (int_latin1) - 1),
202 DFC_CHECK_DATA_COND_MULE (ptr, len, ext_latin, int_latin1);
204 ptr = NULL, len = rand();
205 TO_EXTERNAL_FORMAT (DATA, (int_latin1, sizeof (int_latin1)),
208 DFC_CHECK_DATA_COND_MULE_NUL (ptr, len, ext_latin, int_latin1);
210 ptr = NULL, len = rand();
211 TO_EXTERNAL_FORMAT (DATA, (int_latin2, sizeof (int_latin2) - 1),
213 Fget_coding_system (Qbinary));
214 DFC_CHECK_DATA_COND_MULE (ptr, len, ext_tilde, int_latin2);
216 ptr = NULL, len = rand();
217 TO_EXTERNAL_FORMAT (DATA, (int_latin1, sizeof (int_latin1) - 1),
219 intern ("iso-8859-1"));
220 DFC_CHECK_DATA_COND_MULE (ptr, len, ext_latin, int_latin1);
223 ptr = NULL, len = rand();
224 TO_EXTERNAL_FORMAT (LISP_STRING, string_latin1,
227 DFC_CHECK_DATA_COND_MULE (ptr, len, ext_latin, int_latin1);
229 ptr = NULL, len = rand();
230 TO_EXTERNAL_FORMAT (LISP_STRING, string_latin1,
232 Fget_coding_system (Qbinary));
233 DFC_CHECK_DATA_COND_MULE (ptr, len, ext_latin, int_latin1);
235 ptr = NULL, len = rand();
236 TO_EXTERNAL_FORMAT (LISP_STRING, string_latin1,
238 intern ("iso-8859-1"));
239 DFC_CHECK_DATA_COND_MULE (ptr, len, ext_latin, int_latin1);
241 ptr = NULL, len = rand();
242 TO_EXTERNAL_FORMAT (DATA, (int_latin1, sizeof (int_latin1) - 1),
245 DFC_CHECK_DATA_COND_MULE (ptr, len, ext_latin, int_latin1);
248 ptr = NULL, len = rand();
249 TO_EXTERNAL_FORMAT (DATA, (int_latin2, sizeof (int_latin2)),
251 Fget_coding_system (Qbinary));
252 DFC_CHECK_DATA_COND_MULE_NUL (ptr, len, ext_tilde, int_latin2);
255 ptr = NULL, len = rand();
256 TO_EXTERNAL_FORMAT (DATA, (int_latin1, sizeof (int_latin1) - 1),
258 intern ("iso-8859-1"));
259 DFC_CHECK_DATA_COND_MULE (ptr, len, ext_latin, int_latin1);
262 TO_EXTERNAL_FORMAT (DATA, (int_latin1, sizeof (int_latin1) - 1),
265 DFC_CHECK_DATA_COND_MULE (XOPAQUE_DATA (opaque),
266 XOPAQUE_SIZE (opaque), ext_latin, int_latin1);
268 TO_EXTERNAL_FORMAT (DATA, (int_latin2, sizeof (int_latin2)),
270 Fget_coding_system (Qbinary));
271 DFC_CHECK_DATA_COND_MULE_NUL (XOPAQUE_DATA (opaque),
272 XOPAQUE_SIZE (opaque), ext_tilde, int_latin2);
274 TO_EXTERNAL_FORMAT (DATA, (int_latin1, sizeof (int_latin1) - 1),
276 intern ("iso-8859-1"));
277 DFC_CHECK_DATA_COND_MULE (XOPAQUE_DATA (opaque),
278 XOPAQUE_SIZE (opaque), ext_latin, int_latin1);
280 ptr = NULL, len = rand();
281 TO_INTERNAL_FORMAT (DATA, (ext_latin, sizeof (ext_latin) - 1),
284 DFC_CHECK_DATA_COND_MULE (ptr, len, int_latin1, ext_latin);
286 ptr = NULL, len = rand();
287 TO_INTERNAL_FORMAT (DATA, (ext_latin, sizeof (ext_latin)),
289 intern ("iso-8859-1"));
290 DFC_CHECK_DATA_COND_MULE_NUL (ptr, len, int_latin1, ext_latin);
292 ptr = NULL, len = rand();
293 TO_INTERNAL_FORMAT (DATA, (ext_latin, sizeof (ext_latin)),
295 intern ("iso-8859-1"));
296 DFC_CHECK_DATA_COND_MULE_NUL (ptr, len, int_latin1, ext_latin);
299 ptr = NULL, len = rand();
300 TO_INTERNAL_FORMAT (DATA, (ext_latin, sizeof (ext_latin)),
303 DFC_CHECK_DATA_COND_MULE_NUL (ptr, len, int_latin1, ext_latin);
306 TO_INTERNAL_FORMAT (DATA, (ext_latin, sizeof (ext_latin) - 1),
308 intern ("iso-8859-1"));
309 DFC_CHECK_DATA_COND_MULE (XSTRING_DATA (string),
310 XSTRING_LENGTH (string), int_latin1, ext_latin);
312 TO_INTERNAL_FORMAT (LISP_OPAQUE, opaque_latin,
314 intern ("iso-8859-1"));
315 DFC_CHECK_DATA_COND_MULE (XSTRING_DATA (string),
316 XSTRING_LENGTH (string), int_latin1, ext_latin);
318 TO_INTERNAL_FORMAT (LISP_OPAQUE, opaque0_latin,
320 intern ("iso-8859-1"));
321 DFC_CHECK_DATA_COND_MULE_NUL (XSTRING_DATA (string),
322 XSTRING_LENGTH (string), int_latin1, ext_latin);
325 ptr = NULL, len = rand();
326 TO_EXTERNAL_FORMAT (DATA, (int_foo, sizeof (int_foo)),
328 Fget_coding_system (Qbinary));
329 DFC_CHECK_DATA_COND_EOL_NUL (ptr, len, ext_unix, int_foo);
332 ptr = NULL, len = rand();
333 TO_EXTERNAL_FORMAT (DATA, (int_foo, sizeof (int_foo) - 1),
335 intern ("raw-text-mac"));
336 DFC_CHECK_DATA_COND_EOL (XOPAQUE_DATA (opaque),
337 XOPAQUE_SIZE (opaque), ext_mac, int_foo);
339 ptr = NULL, len = rand();
340 TO_EXTERNAL_FORMAT (LISP_STRING, string_foo,
342 intern ("raw-text-dos"));
343 DFC_CHECK_DATA_COND_EOL (ptr, len, ext_dos, int_foo);
345 ptr = NULL, len = rand();
346 TO_EXTERNAL_FORMAT (DATA, (int_foo, sizeof (int_foo) - 1),
348 intern ("raw-text-unix"));
349 DFC_CHECK_DATA_COND_EOL (ptr, len, ext_unix, int_foo);
351 ptr = NULL, len = rand();
352 TO_EXTERNAL_FORMAT (LISP_STRING, string_foo,
354 intern ("no-conversion-mac"));
355 DFC_CHECK_DATA_COND_EOL (ptr, len, ext_mac, int_foo);
358 ptr = NULL, len = rand();
359 TO_EXTERNAL_FORMAT (DATA, (int_foo, sizeof (int_foo) - 1),
361 Fget_coding_system (intern ("no-conversion-dos")));
362 DFC_CHECK_DATA_COND_EOL (ptr, len, ext_dos, int_foo);
364 ptr = NULL, len = rand();
365 TO_EXTERNAL_FORMAT (DATA, (int_foo, sizeof (int_foo)),
367 intern ("no-conversion-unix"));
368 DFC_CHECK_DATA_COND_EOL_NUL (ptr, len, ext_unix, int_foo);
371 TO_INTERNAL_FORMAT (LISP_OPAQUE, opaque_dos,
372 LISP_BUFFER, Fcurrent_buffer(),
373 intern ("undecided"));
374 DFC_CHECK_DATA (BUF_BYTE_ADDRESS (current_buffer, BUF_PT (current_buffer)),
375 sizeof (int_foo) - 1, int_foo);
377 #endif /* FILE_CODING */
379 TO_INTERNAL_FORMAT (DATA, (ext_mac, sizeof (ext_mac) - 1),
381 intern ("iso-8859-1"));
382 DFC_CHECK_DATA_COND_EOL (XSTRING_DATA (string),
383 XSTRING_LENGTH (string), int_foo, ext_mac);
387 make_fixed_buffer_input_stream (ext_dos, sizeof (ext_dos) - 1);
388 TO_INTERNAL_FORMAT (LISP_LSTREAM, stream,
390 intern ("iso-8859-1"));
391 DFC_CHECK_DATA_COND_EOL (XSTRING_DATA (string),
392 XSTRING_LENGTH (string), int_foo, ext_dos);
395 TO_INTERNAL_FORMAT (DATA, (ext_unix, sizeof (ext_unix) - 1),
397 intern ("no-conversion"));
398 DFC_CHECK_DATA_COND_EOL (XSTRING_DATA (string),
399 XSTRING_LENGTH (string), int_foo, ext_unix);
402 ptr = NULL, len = rand();
403 TO_EXTERNAL_FORMAT (LISP_OPAQUE, opaque_dos,
406 DFC_CHECK_DATA (ptr, len, ext_dos);
408 return intern ("PASS");
413 #define TESTS_DEFSUBR(Fname) do { \
415 Vtest_function_list = \
416 Fcons (intern (subr_name (&S##Fname)), \
417 Vtest_function_list); \
423 Vtest_function_list = Qnil;
425 TESTS_DEFSUBR (Ftest_data_format_conversion);
426 /* Add other test functions here with TESTS_DEFSUBR */
432 DEFVAR_LISP ("test-function-list", &Vtest_function_list /*
433 List of all test functions defined in tests.c.
434 For use by the automated test suite. See tests/automated/c-tests.