comparison src/tests.c @ 3417:abdb33cc1f52

[xemacs-hg @ 2006-05-23 13:02:05 by stephent] Fix c-tests autodetection bugs in in tests.c. <877j4czzm6.fsf@tleepslib.sk.tsukuba.ac.jp>
author stephent
date Tue, 23 May 2006 13:02:07 +0000
parents d674024a8674
children 4d0f773d5e21
comparison
equal deleted inserted replaced
3416:59d576895891 3417:abdb33cc1f52
1 /* C support for testing XEmacs - see tests/automated/c-tests.el 1 /* C support for testing XEmacs - see tests/automated/c-tests.el
2 Copyright (C) 2000 Martin Buchholz 2 Copyright (C) 2000 Martin Buchholz
3 Copyright (C) 2001, 2002 Ben Wing. 3 Copyright (C) 2001, 2002 Ben Wing.
4 Copyright (C) 2006 The Free Software Foundation, Inc.
4 5
5 This file is part of XEmacs. 6 This file is part of XEmacs.
6 7
7 XEmacs is free software; you can redistribute it and/or modify it 8 XEmacs is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the 9 under the terms of the GNU General Public License as published by the
30 #include "lisp.h" 31 #include "lisp.h"
31 #include "buffer.h" 32 #include "buffer.h"
32 #include "lstream.h" 33 #include "lstream.h"
33 #include "elhash.h" 34 #include "elhash.h"
34 #include "opaque.h" 35 #include "opaque.h"
36 #include "file-coding.h" /* XCODING_SYSTEM_EOL_TYPE and its values */
35 37
36 static Lisp_Object Vtest_function_list; 38 static Lisp_Object Vtest_function_list;
37 39
38 40
39 DEFUN ("test-data-format-conversion", Ftest_data_format_conversion, 0, 0, "", /* 41 DEFUN ("test-data-format-conversion", Ftest_data_format_conversion, 0, 0, "", /*
61 Lisp_Object string_latin2 = make_string (int_latin2, sizeof (int_latin2) - 1); 63 Lisp_Object string_latin2 = make_string (int_latin2, sizeof (int_latin2) - 1);
62 #endif 64 #endif
63 Lisp_Object opaque_latin = make_opaque (ext_latin, sizeof (ext_latin) - 1); 65 Lisp_Object opaque_latin = make_opaque (ext_latin, sizeof (ext_latin) - 1);
64 Lisp_Object opaque0_latin = make_opaque (ext_latin, sizeof (ext_latin)); 66 Lisp_Object opaque0_latin = make_opaque (ext_latin, sizeof (ext_latin));
65 Lisp_Object string_latin1 = make_string (int_latin1, sizeof (int_latin1) - 1); 67 Lisp_Object string_latin1 = make_string (int_latin1, sizeof (int_latin1) - 1);
68 int autodetect_eol_p =
69 !NILP (Fsymbol_value (intern ("eol-detection-enabled-p")));
66 70
67 /* Check for expected strings before and after conversion. 71 /* Check for expected strings before and after conversion.
68 Conversions depend on whether MULE is defined. */ 72 Conversions depend on whether MULE is defined. */
69 #ifdef MULE 73 #ifdef MULE
70 #define DFC_CHECK_DATA_COND_MULE(ptr,len, \ 74 #define DFC_CHECK_DATA_COND_MULE(ptr,len, \
84 constant_string_mule, \ 88 constant_string_mule, \
85 constant_string_non_mule) \ 89 constant_string_non_mule) \
86 DFC_CHECK_DATA_NUL (ptr, len, constant_string_non_mule) 90 DFC_CHECK_DATA_NUL (ptr, len, constant_string_non_mule)
87 #endif 91 #endif
88 92
93 /* These now only apply to base coding systems, and
94 need to test `eol-detection-enabled-p' at runtime. */
89 #define DFC_CHECK_DATA_COND_EOL(ptr,len, \ 95 #define DFC_CHECK_DATA_COND_EOL(ptr,len, \
90 constant_string_eol, \ 96 constant_string_eol, \
91 constant_string_non_eol) \ 97 constant_string_non_eol) do { \
92 DFC_CHECK_DATA (ptr, len, constant_string_eol) 98 if (autodetect_eol_p) \
99 DFC_CHECK_DATA (ptr, len, constant_string_eol); \
100 else \
101 DFC_CHECK_DATA (ptr, len, constant_string_non_eol); \
102 } while (0)
93 #define DFC_CHECK_DATA_COND_EOL_NUL(ptr,len, \ 103 #define DFC_CHECK_DATA_COND_EOL_NUL(ptr,len, \
94 constant_string_eol, \ 104 constant_string_eol, \
95 constant_string_non_eol) \ 105 constant_string_non_eol) do { \
96 DFC_CHECK_DATA_NUL (ptr, len, constant_string_eol) 106 if (autodetect_eol_p) \
107 DFC_CHECK_DATA_NUL (ptr, len, constant_string_eol); \
108 else \
109 DFC_CHECK_DATA_NUL (ptr, len, constant_string_non_eol); \
110 } while (0)
97 111
98 /* Check for expected strings before and after conversion. */ 112 /* Check for expected strings before and after conversion. */
99 #define DFC_CHECK_DATA(ptr,len, constant_string) do { \ 113 #define DFC_CHECK_DATA(ptr,len, constant_string) do { \
100 assert ((len) == sizeof (constant_string) - 1); \ 114 assert ((len) == sizeof (constant_string) - 1); \
101 assert (!memcmp (ptr, constant_string, len)); \ 115 assert (!memcmp (ptr, constant_string, len)); \
309 LISP_STRING, string, 323 LISP_STRING, string,
310 intern ("iso-8859-1")); 324 intern ("iso-8859-1"));
311 DFC_CHECK_DATA_COND_MULE_NUL (XSTRING_DATA (string), 325 DFC_CHECK_DATA_COND_MULE_NUL (XSTRING_DATA (string),
312 XSTRING_LENGTH (string), int_latin1, ext_latin); 326 XSTRING_LENGTH (string), int_latin1, ext_latin);
313 327
314 328 /* This next group used to use the COND_EOL macros, but with the new Mule,
329 they all specify an EOL convention, and all XEmacsen can grok them. */
315 ptr = NULL, len = rand(); 330 ptr = NULL, len = rand();
316 TO_EXTERNAL_FORMAT (DATA, (int_foo, sizeof (int_foo)), 331 TO_EXTERNAL_FORMAT (DATA, (int_foo, sizeof (int_foo)),
317 MALLOC, (ptr, len), 332 MALLOC, (ptr, len),
318 Qbinary); 333 Qbinary);
319 DFC_CHECK_DATA_COND_EOL_NUL (ptr, len, ext_unix, int_foo); 334 DFC_CHECK_DATA_NUL (ptr, len, ext_unix);
320 xfree (ptr, void *); 335 xfree (ptr, void *);
321 336
322 ptr = NULL, len = rand(); 337 ptr = NULL, len = rand();
323 TO_EXTERNAL_FORMAT (DATA, (int_foo, sizeof (int_foo) - 1), 338 TO_EXTERNAL_FORMAT (DATA, (int_foo, sizeof (int_foo) - 1),
324 LISP_OPAQUE, opaque, 339 LISP_OPAQUE, opaque,
325 intern ("raw-text-mac")); 340 intern ("raw-text-mac"));
326 DFC_CHECK_DATA_COND_EOL (XOPAQUE_DATA (opaque), 341 DFC_CHECK_DATA (XOPAQUE_DATA (opaque), XOPAQUE_SIZE (opaque), ext_mac);
327 XOPAQUE_SIZE (opaque), ext_mac, int_foo);
328 342
329 ptr = NULL, len = rand(); 343 ptr = NULL, len = rand();
330 TO_EXTERNAL_FORMAT (LISP_STRING, string_foo, 344 TO_EXTERNAL_FORMAT (LISP_STRING, string_foo,
331 ALLOCA, (ptr, len), 345 ALLOCA, (ptr, len),
332 intern ("raw-text-dos")); 346 intern ("raw-text-dos"));
333 DFC_CHECK_DATA_COND_EOL (ptr, len, ext_dos, int_foo); 347 DFC_CHECK_DATA (ptr, len, ext_dos);
334 348
335 ptr = NULL, len = rand(); 349 ptr = NULL, len = rand();
336 TO_EXTERNAL_FORMAT (DATA, (int_foo, sizeof (int_foo) - 1), 350 TO_EXTERNAL_FORMAT (DATA, (int_foo, sizeof (int_foo) - 1),
337 ALLOCA, (ptr, len), 351 ALLOCA, (ptr, len),
338 intern ("raw-text-unix")); 352 intern ("raw-text-unix"));
339 DFC_CHECK_DATA_COND_EOL (ptr, len, ext_unix, int_foo); 353 DFC_CHECK_DATA (ptr, len, ext_unix);
340 354
341 ptr = NULL, len = rand(); 355 ptr = NULL, len = rand();
342 TO_EXTERNAL_FORMAT (LISP_STRING, string_foo, 356 TO_EXTERNAL_FORMAT (LISP_STRING, string_foo,
343 MALLOC, (ptr, len), 357 MALLOC, (ptr, len),
344 intern ("no-conversion-mac")); 358 intern ("no-conversion-mac"));
345 DFC_CHECK_DATA_COND_EOL (ptr, len, ext_mac, int_foo); 359 DFC_CHECK_DATA (ptr, len, ext_mac);
346 xfree (ptr, void *); 360 xfree (ptr, void *);
347 361
348 ptr = NULL, len = rand(); 362 ptr = NULL, len = rand();
349 TO_EXTERNAL_FORMAT (DATA, (int_foo, sizeof (int_foo) - 1), 363 TO_EXTERNAL_FORMAT (DATA, (int_foo, sizeof (int_foo) - 1),
350 ALLOCA, (ptr, len), 364 ALLOCA, (ptr, len),
351 intern ("no-conversion-dos")); 365 intern ("no-conversion-dos"));
352 DFC_CHECK_DATA_COND_EOL (ptr, len, ext_dos, int_foo); 366 DFC_CHECK_DATA (ptr, len, ext_dos);
353 367
354 ptr = NULL, len = rand(); 368 ptr = NULL, len = rand();
355 TO_EXTERNAL_FORMAT (DATA, (int_foo, sizeof (int_foo)), 369 TO_EXTERNAL_FORMAT (DATA, (int_foo, sizeof (int_foo)),
356 ALLOCA, (ptr, len), 370 ALLOCA, (ptr, len),
357 intern ("no-conversion-unix")); 371 intern ("no-conversion-unix"));
358 DFC_CHECK_DATA_COND_EOL_NUL (ptr, len, ext_unix, int_foo); 372 DFC_CHECK_DATA_NUL (ptr, len, ext_unix);
359 373
374 /* Oh, Lawdy, Lawdy, Lawdy, this done broke mah heart!
375
376 I tried using the technique
377
378 Fget_coding_system (call2
379 (intern ("coding-system-change-eol-conversion"),
380 intern ("undecided"), $EOL_TYPE));
381 XCODING_SYSTEM_EOL_TYPE (cs_to_use) = $EOL_DETECT_TYPE;
382
383 with EOL_TYPE = Qlf (for no-detect) and Qnil (for auto-detect),
384 and with EOL_DETECT_TYPE = EOL_LF and EOL_AUTODETECT
385 respectively, but this doesn't seem to work on the `undecided'
386 coding system. The coding-system-eol-type attribute on the
387 coding system itself needs to be changed, too. I'm not sure at
388 the moment how `set-eol-detection' works its magic, but the code
389 below gives correct test results without default EOL detection,
390 with default EOL detection, and with Mule. Ship it!
391
392 Mule. You'll envy the dead.
393 */
394
395 {
396 /* Check eol autodetection doesn't happen when disabled -- cheat. */
397 Lisp_Object cs_to_use = Fget_coding_system (intern ("undecided-unix"));
398 TO_INTERNAL_FORMAT (LISP_OPAQUE, opaque_dos,
399 LISP_BUFFER, Fcurrent_buffer(),
400 cs_to_use);
401 DFC_CHECK_DATA (BUF_BYTE_ADDRESS (current_buffer, BUF_PT (current_buffer)),
402 sizeof (ext_dos) - 1, ext_dos);
403
404 /* Check eol autodetection works when enabled -- honest. */
405 cs_to_use =
406 Fget_coding_system (call2
407 (intern ("coding-system-change-eol-conversion"),
408 intern ("undecided"), Qnil));
409 XCODING_SYSTEM_EOL_TYPE (cs_to_use) = EOL_AUTODETECT;
410 TO_INTERNAL_FORMAT (LISP_OPAQUE, opaque_dos,
411 LISP_BUFFER, Fcurrent_buffer(),
412 cs_to_use);
413 DFC_CHECK_DATA (BUF_BYTE_ADDRESS (current_buffer, BUF_PT (current_buffer)),
414 sizeof (int_foo) - 1, int_foo);
415 /* reset to default */
416 XCODING_SYSTEM_EOL_TYPE (cs_to_use) =
417 autodetect_eol_p ? EOL_AUTODETECT : EOL_LF;
418 }
419
420 /* Does eol-detection-enabled-p reflect the actual state of affairs?
421 This probably could be tested in Lisp somehow. Should it? */
360 TO_INTERNAL_FORMAT (LISP_OPAQUE, opaque_dos, 422 TO_INTERNAL_FORMAT (LISP_OPAQUE, opaque_dos,
361 LISP_BUFFER, Fcurrent_buffer(), 423 LISP_BUFFER, Fcurrent_buffer(),
362 intern ("undecided")); 424 intern ("undecided"));
363 /* &&#### needs some 8-bit work here */ 425 if (autodetect_eol_p)
364 DFC_CHECK_DATA (BUF_BYTE_ADDRESS (current_buffer, BUF_PT (current_buffer)), 426 DFC_CHECK_DATA (BUF_BYTE_ADDRESS (current_buffer,
365 sizeof (int_foo) - 1, int_foo); 427 BUF_PT (current_buffer)),
428 sizeof (int_foo) - 1, int_foo);
429 else
430 DFC_CHECK_DATA (BUF_BYTE_ADDRESS (current_buffer,
431 BUF_PT (current_buffer)),
432 sizeof (ext_dos) - 1, ext_dos);
366 433
367 TO_INTERNAL_FORMAT (DATA, (ext_mac, sizeof (ext_mac) - 1), 434 TO_INTERNAL_FORMAT (DATA, (ext_mac, sizeof (ext_mac) - 1),
368 LISP_STRING, string, 435 LISP_STRING, string,
369 intern ("iso-8859-1")); 436 intern ("iso-8859-1"));
370 DFC_CHECK_DATA_COND_EOL (XSTRING_DATA (string), 437 DFC_CHECK_DATA_COND_EOL (XSTRING_DATA (string),