1 /* Copyright (C) 1999,2000,2001,2003,2004, 2006 Free Software Foundation, Inc.
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 test_1 (const char *str
, scm_t_intmax min
, scm_t_intmax max
,
28 int r
= scm_is_signed_integer (scm_c_eval_string (str
), min
, max
);
31 fprintf (stderr
, "fail: scm_is_signed_integer (%s, %Ld, %Ld) == %d\n",
32 str
, min
, max
, result
);
38 test_is_signed_integer ()
41 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
44 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
46 test_1 ("(inexact->exact 3.0)",
47 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
50 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
52 test_1 ("most-positive-fixnum",
53 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
55 test_1 ("(+ most-positive-fixnum 1)",
56 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
58 test_1 ("most-negative-fixnum",
59 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
61 test_1 ("(- most-negative-fixnum 1)",
62 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
64 if (sizeof (scm_t_intmax
) == 8)
66 test_1 ("(- (expt 2 63) 1)",
67 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
69 test_1 ("(expt 2 63)",
70 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
72 test_1 ("(- (expt 2 63))",
73 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
75 test_1 ("(- (- (expt 2 63)) 1)",
76 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
79 else if (sizeof (scm_t_intmax
) == 4)
81 test_1 ("(- (expt 2 31) 1)",
82 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
84 test_1 ("(expt 2 31)",
85 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
87 test_1 ("(- (expt 2 31))",
88 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
90 test_1 ("(- (- (expt 2 31)) 1)",
91 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
95 fprintf (stderr
, "NOTE: skipped some tests.\n");
97 /* bignum with range that fits into fixnum. */
98 test_1 ("(+ most-positive-fixnum 1)",
102 /* bignum with range that doesn't fit into fixnum, but probably
104 test_1 ("(+ most-positive-fixnum 1)",
105 SCM_MOST_NEGATIVE_FIXNUM
-1, SCM_MOST_POSITIVE_FIXNUM
+1,
110 test_2 (const char *str
, scm_t_uintmax min
, scm_t_uintmax max
,
113 int r
= scm_is_unsigned_integer (scm_c_eval_string (str
), min
, max
);
116 fprintf (stderr
, "fail: scm_is_unsigned_integer (%s, %Lu, %Lu) == %d\n",
117 str
, min
, max
, result
);
123 test_is_unsigned_integer ()
126 0, SCM_T_UINTMAX_MAX
,
129 0, SCM_T_UINTMAX_MAX
,
131 test_2 ("(inexact->exact 3.0)",
132 0, SCM_T_UINTMAX_MAX
,
135 0, SCM_T_UINTMAX_MAX
,
137 test_2 ("most-positive-fixnum",
138 0, SCM_T_UINTMAX_MAX
,
140 test_2 ("(+ most-positive-fixnum 1)",
141 0, SCM_T_UINTMAX_MAX
,
143 test_2 ("most-negative-fixnum",
144 0, SCM_T_UINTMAX_MAX
,
146 test_2 ("(- most-negative-fixnum 1)",
147 0, SCM_T_UINTMAX_MAX
,
149 if (sizeof (scm_t_intmax
) == 8)
151 test_2 ("(- (expt 2 64) 1)",
152 0, SCM_T_UINTMAX_MAX
,
154 test_2 ("(expt 2 64)",
155 0, SCM_T_UINTMAX_MAX
,
158 else if (sizeof (scm_t_intmax
) == 4)
160 test_2 ("(- (expt 2 32) 1)",
161 0, SCM_T_UINTMAX_MAX
,
163 test_2 ("(expt 2 32)",
164 0, SCM_T_UINTMAX_MAX
,
168 fprintf (stderr
, "NOTE: skipped some tests.\n");
170 /* bignum with range that fits into fixnum. */
171 test_2 ("(+ most-positive-fixnum 1)",
175 /* bignum with range that doesn't fit into fixnum, but probably
177 test_2 ("(+ most-positive-fixnum 1)",
178 0, SCM_MOST_POSITIVE_FIXNUM
+1,
184 scm_t_intmax min
, max
;
189 out_of_range_handler (void *data
, SCM key
, SCM args
)
191 return scm_equal_p (key
, scm_from_locale_symbol ("out-of-range"));
195 wrong_type_handler (void *data
, SCM key
, SCM args
)
197 return scm_equal_p (key
, scm_from_locale_symbol ("wrong-type-arg"));
201 misc_error_handler (void *data
, SCM key
, SCM args
)
203 return scm_equal_p (key
, scm_from_locale_symbol ("misc-error"));
207 any_handler (void *data
, SCM key
, SCM args
)
213 to_signed_integer_body (void *data
)
215 to_signed_data
*d
= (to_signed_data
*)data
;
216 d
->result
= scm_to_signed_integer (d
->val
, d
->min
, d
->max
);
221 test_3 (const char *str
, scm_t_intmax min
, scm_t_intmax max
,
222 scm_t_intmax result
, int range_error
, int type_error
)
225 data
.val
= scm_c_eval_string (str
);
231 if (scm_is_false (scm_internal_catch (SCM_BOOL_T
,
232 to_signed_integer_body
, &data
,
233 out_of_range_handler
, NULL
)))
236 "fail: scm_to_signed_int (%s, %Ld, %Ld) -> out of range\n",
243 if (scm_is_false (scm_internal_catch (SCM_BOOL_T
,
244 to_signed_integer_body
, &data
,
245 wrong_type_handler
, NULL
)))
248 "fail: scm_to_signed_int (%s, %Ld, %Ld) -> wrong type\n",
255 if (scm_is_true (scm_internal_catch (SCM_BOOL_T
,
256 to_signed_integer_body
, &data
,
258 || data
.result
!= result
)
261 "fail: scm_to_signed_int (%s, %Ld, %Ld) = %Ld\n",
262 str
, min
, max
, result
);
269 test_to_signed_integer ()
272 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
275 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
278 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
286 test_3 ("most-positive-fixnum",
287 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
288 SCM_MOST_POSITIVE_FIXNUM
, 0, 0);
289 test_3 ("most-negative-fixnum",
290 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
291 SCM_MOST_NEGATIVE_FIXNUM
, 0, 0);
292 test_3 ("(+ most-positive-fixnum 1)",
293 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
294 SCM_MOST_POSITIVE_FIXNUM
+1, 0, 0);
295 test_3 ("(- most-negative-fixnum 1)",
296 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
297 SCM_MOST_NEGATIVE_FIXNUM
-1, 0, 0);
298 if (sizeof (scm_t_intmax
) == 8)
300 test_3 ("(- (expt 2 63) 1)",
301 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
302 SCM_T_INTMAX_MAX
, 0, 0);
303 test_3 ("(+ (- (expt 2 63)) 1)",
304 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
305 SCM_T_INTMAX_MIN
+1, 0, 0);
306 test_3 ("(- (expt 2 63))",
307 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
308 SCM_T_INTMAX_MIN
, 0, 0);
309 test_3 ("(expt 2 63)",
310 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
312 test_3 ("(- (- (expt 2 63)) 1)",
313 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
316 else if (sizeof (scm_t_intmax
) == 4)
318 test_3 ("(- (expt 2 31) 1)",
319 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
320 SCM_T_INTMAX_MAX
, 0, 0);
321 test_3 ("(+ (- (expt 2 31)) 1)",
322 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
323 SCM_T_INTMAX_MIN
+1, 0, 0);
324 test_3 ("(- (expt 2 31))",
325 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
326 SCM_T_INTMAX_MIN
, 0, 0);
327 test_3 ("(expt 2 31)",
328 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
330 test_3 ("(- (- (expt 2 31)) 1)",
331 SCM_T_INTMAX_MIN
, SCM_T_INTMAX_MAX
,
335 fprintf (stderr
, "NOTE: skipped some tests.\n");
340 scm_t_uintmax min
, max
;
341 scm_t_uintmax result
;
345 to_unsigned_integer_body (void *data
)
347 to_unsigned_data
*d
= (to_unsigned_data
*)data
;
348 d
->result
= scm_to_unsigned_integer (d
->val
, d
->min
, d
->max
);
353 test_4 (const char *str
, scm_t_uintmax min
, scm_t_uintmax max
,
354 scm_t_uintmax result
, int range_error
, int type_error
)
356 to_unsigned_data data
;
357 data
.val
= scm_c_eval_string (str
);
363 if (scm_is_false (scm_internal_catch (SCM_BOOL_T
,
364 to_unsigned_integer_body
, &data
,
365 out_of_range_handler
, NULL
)))
368 "fail: scm_to_unsigned_int (%s, %Lu, %Lu) -> out of range\n",
375 if (scm_is_false (scm_internal_catch (SCM_BOOL_T
,
376 to_unsigned_integer_body
, &data
,
377 wrong_type_handler
, NULL
)))
380 "fail: scm_to_unsigned_int (%s, %Lu, %Lu) -> wrong type\n",
387 if (scm_is_true (scm_internal_catch (SCM_BOOL_T
,
388 to_unsigned_integer_body
, &data
,
390 || data
.result
!= result
)
393 "fail: scm_to_unsigned_int (%s, %Lu, %Lu) == %Lu\n",
394 str
, min
, max
, result
);
401 test_to_unsigned_integer ()
404 0, SCM_T_UINTMAX_MAX
,
407 0, SCM_T_UINTMAX_MAX
,
410 0, SCM_T_UINTMAX_MAX
,
415 test_4 ("most-positive-fixnum",
416 0, SCM_T_UINTMAX_MAX
,
417 SCM_MOST_POSITIVE_FIXNUM
, 0, 0);
418 test_4 ("(+ most-positive-fixnum 1)",
419 0, SCM_T_UINTMAX_MAX
,
420 SCM_MOST_POSITIVE_FIXNUM
+1, 0, 0);
421 if (sizeof (scm_t_intmax
) == 8)
423 test_4 ("(- (expt 2 64) 1)",
424 0, SCM_T_UINTMAX_MAX
,
425 SCM_T_UINTMAX_MAX
, 0, 0);
426 test_4 ("(expt 2 64)",
427 0, SCM_T_UINTMAX_MAX
,
430 else if (sizeof (scm_t_intmax
) == 4)
432 test_4 ("(- (expt 2 32) 1)",
433 0, SCM_T_UINTMAX_MAX
,
434 SCM_T_UINTMAX_MAX
, 0, 0);
435 test_4 ("(expt 2 32)",
436 0, SCM_T_UINTMAX_MAX
,
440 fprintf (stderr
, "NOTE: skipped some tests.\n");
444 test_5 (scm_t_intmax val
, const char *result
)
446 SCM res
= scm_c_eval_string (result
);
447 if (scm_is_false (scm_equal_p (scm_from_signed_integer (val
), res
)))
449 fprintf (stderr
, "fail: scm_from_signed_integer (%Ld) == %s\n",
456 test_from_signed_integer ()
459 if (sizeof (scm_t_intmax
) == 8)
461 test_5 (SCM_T_INTMAX_MAX
, "(- (expt 2 63) 1)");
462 test_5 (SCM_T_INTMAX_MIN
, "(- (expt 2 63))");
464 else if (sizeof (scm_t_intmax
) == 4)
466 test_5 (SCM_T_INTMAX_MAX
, "(- (expt 2 31) 1)");
467 test_5 (SCM_T_INTMAX_MIN
, "(- (expt 2 31))");
469 test_5 (SCM_MOST_POSITIVE_FIXNUM
, "most-positive-fixnum");
470 test_5 (SCM_MOST_NEGATIVE_FIXNUM
, "most-negative-fixnum");
471 test_5 (SCM_MOST_POSITIVE_FIXNUM
+1, "(+ most-positive-fixnum 1)");
472 test_5 (SCM_MOST_NEGATIVE_FIXNUM
-1, "(- most-negative-fixnum 1)");
476 test_6 (scm_t_uintmax val
, const char *result
)
478 SCM res
= scm_c_eval_string (result
);
479 if (scm_is_false (scm_equal_p (scm_from_unsigned_integer (val
), res
)))
481 fprintf (stderr
, "fail: scm_from_unsigned_integer (%Lu) == %s\n",
488 test_from_unsigned_integer ()
491 if (sizeof (scm_t_intmax
) == 8)
493 test_6 (SCM_T_UINTMAX_MAX
, "(- (expt 2 64) 1)");
495 else if (sizeof (scm_t_intmax
) == 4)
497 test_6 (SCM_T_UINTMAX_MAX
, "(- (expt 2 32) 1)");
499 test_6 (SCM_MOST_POSITIVE_FIXNUM
, "most-positive-fixnum");
500 test_6 (SCM_MOST_POSITIVE_FIXNUM
+1, "(+ most-positive-fixnum 1)");
504 test_7s (SCM n
, scm_t_intmax c_n
, const char *result
, const char *func
)
506 SCM r
= scm_c_eval_string (result
);
508 if (scm_is_false (scm_equal_p (n
, r
)))
510 fprintf (stderr
, "fail: %s (%Ld) == %s\n", func
, c_n
, result
);
515 #define TEST_7S(func,arg,res) test_7s (func(arg), arg, res, #func)
518 test_7u (SCM n
, scm_t_uintmax c_n
, const char *result
, const char *func
)
520 SCM r
= scm_c_eval_string (result
);
522 if (scm_is_false (scm_equal_p (n
, r
)))
524 fprintf (stderr
, "fail: %s (%Lu) == %s\n", func
, c_n
, result
);
529 #define TEST_7U(func,arg,res) test_7u (func(arg), arg, res, #func)
533 scm_t_intmax (*func
) (SCM
);
535 } to_signed_func_data
;
538 to_signed_func_body (void *data
)
540 to_signed_func_data
*d
= (to_signed_func_data
*)data
;
541 d
->result
= d
->func (d
->val
);
546 test_8s (const char *str
, scm_t_intmax (*func
) (SCM
), const char *func_name
,
547 scm_t_intmax result
, int range_error
, int type_error
)
549 to_signed_func_data data
;
550 data
.val
= scm_c_eval_string (str
);
555 if (scm_is_false (scm_internal_catch (SCM_BOOL_T
,
556 to_signed_func_body
, &data
,
557 out_of_range_handler
, NULL
)))
560 "fail: %s (%s) -> out of range\n", func_name
, str
);
566 if (scm_is_false (scm_internal_catch (SCM_BOOL_T
,
567 to_signed_func_body
, &data
,
568 wrong_type_handler
, NULL
)))
571 "fail: %s (%s) -> wrong type\n", func_name
, str
);
577 if (scm_is_true (scm_internal_catch (SCM_BOOL_T
,
578 to_signed_func_body
, &data
,
580 || data
.result
!= result
)
583 "fail: %s (%s) = %Ld\n", func_name
, str
, result
);
591 scm_t_uintmax (*func
) (SCM
);
592 scm_t_uintmax result
;
593 } to_unsigned_func_data
;
596 to_unsigned_func_body (void *data
)
598 to_unsigned_func_data
*d
= (to_unsigned_func_data
*)data
;
599 d
->result
= d
->func (d
->val
);
604 test_8u (const char *str
, scm_t_uintmax (*func
) (SCM
), const char *func_name
,
605 scm_t_uintmax result
, int range_error
, int type_error
)
607 to_unsigned_func_data data
;
608 data
.val
= scm_c_eval_string (str
);
613 if (scm_is_false (scm_internal_catch (SCM_BOOL_T
,
614 to_unsigned_func_body
, &data
,
615 out_of_range_handler
, NULL
)))
618 "fail: %s (%s) -> out of range\n", func_name
, str
);
624 if (scm_is_false (scm_internal_catch (SCM_BOOL_T
,
625 to_unsigned_func_body
, &data
,
626 wrong_type_handler
, NULL
)))
629 "fail: %s (%s) -> wrong type\n", func_name
, str
);
635 if (scm_is_true (scm_internal_catch (SCM_BOOL_T
,
636 to_unsigned_func_body
, &data
,
638 || data
.result
!= result
)
641 "fail: %s (%s) = %Ld\n", func_name
, str
, result
);
647 /* We can't rely on the scm_to functions being proper functions but we
648 want to pass them to test_8s and test_8u, so we wrap'em. Also, we
649 need to give them a common return type.
652 #define DEFSTST(f) static scm_t_intmax tst_##f (SCM x) { return f(x); }
653 #define DEFUTST(f) static scm_t_uintmax tst_##f (SCM x) { return f(x); }
655 DEFSTST (scm_to_schar
);
656 DEFUTST (scm_to_uchar
);
657 DEFSTST (scm_to_char
);
658 DEFSTST (scm_to_short
);
659 DEFUTST (scm_to_ushort
);
660 DEFSTST (scm_to_int
);
661 DEFUTST (scm_to_uint
);
662 DEFSTST (scm_to_long
);
663 DEFUTST (scm_to_ulong
);
664 #if SCM_SIZEOF_LONG_LONG != 0
665 DEFSTST (scm_to_long_long
);
666 DEFUTST (scm_to_ulong_long
);
668 DEFSTST (scm_to_ssize_t
);
669 DEFUTST (scm_to_size_t
);
671 DEFSTST (scm_to_int8
);
672 DEFUTST (scm_to_uint8
);
673 DEFSTST (scm_to_int16
);
674 DEFUTST (scm_to_uint16
);
675 DEFSTST (scm_to_int32
);
676 DEFUTST (scm_to_uint32
);
677 #ifdef SCM_HAVE_T_INT64
678 DEFSTST (scm_to_int64
);
679 DEFUTST (scm_to_uint64
);
682 #define TEST_8S(v,f,r,re,te) test_8s (v, tst_##f, #f, r, re, te)
683 #define TEST_8U(v,f,r,re,te) test_8u (v, tst_##f, #f, r, re, te)
689 TEST_7U (scm_from_uchar
, 91, "91");
690 TEST_7S (scm_from_schar
, 91, "91");
691 TEST_7S (scm_from_char
, 91, "91");
692 TEST_7S (scm_from_short
, -911, "-911");
693 TEST_7U (scm_from_ushort
, 911, "911");
694 TEST_7S (scm_from_int
, 911, "911");
695 TEST_7U (scm_from_uint
, 911, "911");
696 TEST_7S (scm_from_long
, 911, "911");
697 TEST_7U (scm_from_ulong
, 911, "911");
698 #if SCM_SIZEOF_LONG_LONG != 0
699 TEST_7S (scm_from_long_long
, 911, "911");
700 TEST_7U (scm_from_ulong_long
, 911, "911");
702 TEST_7U (scm_from_size_t
, 911, "911");
703 TEST_7S (scm_from_ssize_t
, 911, "911");
705 TEST_7S (scm_from_int8
, -128, "-128");
706 TEST_7S (scm_from_int8
, 127, "127");
707 TEST_7S (scm_from_int8
, 128, "-128");
708 TEST_7U (scm_from_uint8
, 255, "255");
710 TEST_7S (scm_from_int16
, -32768, "-32768");
711 TEST_7S (scm_from_int16
, 32767, "32767");
712 TEST_7S (scm_from_int16
, 32768, "-32768");
713 TEST_7U (scm_from_uint16
, 65535, "65535");
715 TEST_7S (scm_from_int32
, SCM_T_INT32_MIN
, "-2147483648");
716 TEST_7S (scm_from_int32
, SCM_T_INT32_MAX
, "2147483647");
717 TEST_7S (scm_from_int32
, SCM_T_INT32_MAX
+1LL, "-2147483648");
718 TEST_7U (scm_from_uint32
, SCM_T_UINT32_MAX
, "4294967295");
721 TEST_7S (scm_from_int64
, SCM_T_INT64_MIN
, "-9223372036854775808");
722 TEST_7S (scm_from_int64
, SCM_T_INT64_MAX
, "9223372036854775807");
723 TEST_7U (scm_from_uint64
, SCM_T_UINT64_MAX
, "18446744073709551615");
726 TEST_8S ("91", scm_to_schar
, 91, 0, 0);
727 TEST_8U ("91", scm_to_uchar
, 91, 0, 0);
728 TEST_8S ("91", scm_to_char
, 91, 0, 0);
729 TEST_8S ("-911", scm_to_short
, -911, 0, 0);
730 TEST_8U ("911", scm_to_ushort
, 911, 0, 0);
731 TEST_8S ("-911", scm_to_int
, -911, 0, 0);
732 TEST_8U ("911", scm_to_uint
, 911, 0, 0);
733 TEST_8S ("-911", scm_to_long
, -911, 0, 0);
734 TEST_8U ("911", scm_to_ulong
, 911, 0, 0);
735 #if SCM_SIZEOF_LONG_LONG != 0
736 TEST_8S ("-911", scm_to_long_long
, -911, 0, 0);
737 TEST_8U ("911", scm_to_ulong_long
, 911, 0, 0);
739 TEST_8U ("911", scm_to_size_t
, 911, 0, 0);
740 TEST_8S ("911", scm_to_ssize_t
, 911, 0, 0);
742 TEST_8S ("-128", scm_to_int8
, SCM_T_INT8_MIN
, 0, 0);
743 TEST_8S ("127", scm_to_int8
, SCM_T_INT8_MAX
, 0, 0);
744 TEST_8S ("128", scm_to_int8
, 0, 1, 0);
745 TEST_8S ("#f", scm_to_int8
, 0, 0, 1);
746 TEST_8U ("255", scm_to_uint8
, SCM_T_UINT8_MAX
, 0, 0);
747 TEST_8U ("256", scm_to_uint8
, 0, 1, 0);
748 TEST_8U ("-1", scm_to_uint8
, 0, 1, 0);
749 TEST_8U ("#f", scm_to_uint8
, 0, 0, 1);
751 TEST_8S ("-32768", scm_to_int16
, SCM_T_INT16_MIN
, 0, 0);
752 TEST_8S ("32767", scm_to_int16
, SCM_T_INT16_MAX
, 0, 0);
753 TEST_8S ("32768", scm_to_int16
, 0, 1, 0);
754 TEST_8S ("#f", scm_to_int16
, 0, 0, 1);
755 TEST_8U ("65535", scm_to_uint16
, SCM_T_UINT16_MAX
, 0, 0);
756 TEST_8U ("65536", scm_to_uint16
, 0, 1, 0);
757 TEST_8U ("-1", scm_to_uint16
, 0, 1, 0);
758 TEST_8U ("#f", scm_to_uint16
, 0, 0, 1);
760 TEST_8S ("-2147483648", scm_to_int32
, SCM_T_INT32_MIN
, 0, 0);
761 TEST_8S ("2147483647", scm_to_int32
, SCM_T_INT32_MAX
, 0, 0);
762 TEST_8S ("2147483648", scm_to_int32
, 0, 1, 0);
763 TEST_8S ("#f", scm_to_int32
, 0, 0, 1);
764 TEST_8U ("4294967295", scm_to_uint32
, SCM_T_UINT32_MAX
, 0, 0);
765 TEST_8U ("4294967296", scm_to_uint32
, 0, 1, 0);
766 TEST_8U ("-1", scm_to_uint32
, 0, 1, 0);
767 TEST_8U ("#f", scm_to_uint32
, 0, 0, 1);
770 TEST_8S ("-9223372036854775808", scm_to_int64
, SCM_T_INT64_MIN
, 0, 0);
771 TEST_8S ("9223372036854775807", scm_to_int64
, SCM_T_INT64_MAX
, 0, 0);
772 TEST_8S ("9223372036854775808", scm_to_int64
, 0, 1, 0);
773 TEST_8S ("#f", scm_to_int64
, 0, 0, 1);
774 TEST_8U ("18446744073709551615", scm_to_uint64
, SCM_T_UINT64_MAX
, 0, 0);
775 TEST_8U ("18446744073709551616", scm_to_uint64
, 0, 1, 0);
776 TEST_8U ("-1", scm_to_uint64
, 0, 1, 0);
777 TEST_8U ("#f", scm_to_uint64
, 0, 0, 1);
783 test_9 (double val
, const char *result
)
785 SCM res
= scm_c_eval_string (result
);
786 if (scm_is_false (scm_eqv_p (res
, scm_from_double (val
))))
788 fprintf (stderr
, "fail: scm_from_double (%g) == %s\n", val
, result
);
797 test_9 (0.25, "0.25");
799 test_9 (1.0/0.0, "+inf.0");
800 test_9 (-1.0/0.0, "-inf.0");
801 test_9 (0.0/0.0, "+nan.0");
810 to_double_body (void *data
)
812 to_double_data
*d
= (to_double_data
*)data
;
813 d
->result
= scm_to_double (d
->val
);
818 test_10 (const char *val
, double result
, int type_error
)
821 data
.val
= scm_c_eval_string (val
);
825 if (scm_is_false (scm_internal_catch (SCM_BOOL_T
,
826 to_double_body
, &data
,
827 wrong_type_handler
, NULL
)))
830 "fail: scm_double (%s) -> wrong type\n", val
);
836 if (scm_is_true (scm_internal_catch (SCM_BOOL_T
,
837 to_double_body
, &data
,
839 || data
.result
!= result
)
842 "fail: scm_to_double (%s) = %g\n", val
, result
);
851 test_10 ("#f", 0.0, 1);
852 test_10 ("12", 12.0, 0);
853 test_10 ("0.25", 0.25, 0);
854 test_10 ("1/4", 0.25, 0);
855 test_10 ("+inf.0", 1.0/0.0, 0);
856 test_10 ("-inf.0", -1.0/0.0, 0);
857 test_10 ("+1i", 0.0, 1);
863 } to_locale_string_data
;
866 to_locale_string_body (void *data
)
868 to_locale_string_data
*d
= (to_locale_string_data
*)data
;
869 d
->result
= scm_to_locale_string (d
->val
);
874 test_11 (const char *str
, const char *result
, int misc_error
, int type_error
)
876 to_locale_string_data data
;
877 data
.val
= scm_c_eval_string (str
);
882 if (scm_is_false (scm_internal_catch (SCM_BOOL_T
,
883 to_locale_string_body
, &data
,
884 misc_error_handler
, NULL
)))
887 "fail: scm_to_locale_string (%s) -> misc error\n", str
);
893 if (scm_is_false (scm_internal_catch (SCM_BOOL_T
,
894 to_locale_string_body
, &data
,
895 wrong_type_handler
, NULL
)))
898 "fail: scm_to_locale_string (%s) -> wrong type\n", str
);
904 if (scm_is_true (scm_internal_catch (SCM_BOOL_T
,
905 to_locale_string_body
, &data
,
907 || data
.result
== NULL
|| strcmp (data
.result
, result
))
910 "fail: scm_to_locale_string (%s) = %s\n", str
, result
);
919 test_locale_strings ()
921 const char *lstr
= "This is not a string.";
927 if (!scm_is_string (scm_c_eval_string ("\"foo\"")))
929 fprintf (stderr
, "fail: scm_is_string (\"foo\") = true\n");
933 str
= scm_from_locale_string (lstr
);
935 if (!scm_is_string (str
))
937 fprintf (stderr
, "fail: scm_is_string (str) = true\n");
941 lstr2
= scm_to_locale_string (str
);
942 if (strcmp (lstr
, lstr2
))
944 fprintf (stderr
, "fail: lstr = lstr2\n");
950 len
= scm_to_locale_stringbuf (str
, buf
, 15);
951 if (len
!= strlen (lstr
))
953 fprintf (stderr
, "fail: scm_to_locale_stringbuf (...) = strlen(lstr)\n");
958 fprintf (stderr
, "fail: scm_to_locale_stringbuf (...) no overrun\n");
961 if (strncmp (lstr
, buf
, 15))
963 fprintf (stderr
, "fail: scm_to_locale_stringbuf (...) = lstr\n");
967 str2
= scm_from_locale_stringn (lstr
, 10);
969 if (!scm_is_string (str2
))
971 fprintf (stderr
, "fail: scm_is_string (str2) = true\n");
975 lstr2
= scm_to_locale_string (str2
);
976 if (strncmp (lstr
, lstr2
, 10))
978 fprintf (stderr
, "fail: lstr = lstr2\n");
984 len
= scm_to_locale_stringbuf (str2
, buf
, 20);
987 fprintf (stderr
, "fail: scm_to_locale_stringbuf (...) = 10\n");
992 fprintf (stderr
, "fail: scm_to_locale_stringbuf (...) no overrun\n");
995 if (strncmp (lstr
, buf
, 10))
997 fprintf (stderr
, "fail: scm_to_locale_stringbuf (...) = lstr\n");
1001 lstr2
= scm_to_locale_stringn (str2
, &len
);
1004 fprintf (stderr
, "fail: scm_to_locale_stringn, len = 10\n");
1008 test_11 ("#f", NULL
, 0, 1);
1009 test_11 ("\"foo\"", "foo", 0, 0);
1010 test_11 ("(string #\\f #\\nul)", NULL
, 1, 0);
1014 tests (void *data
, int argc
, char **argv
)
1016 test_is_signed_integer ();
1017 test_is_unsigned_integer ();
1018 test_to_signed_integer ();
1019 test_to_unsigned_integer ();
1020 test_from_signed_integer ();
1021 test_from_unsigned_integer ();
1023 test_from_double ();
1025 test_locale_strings ();
1029 main (int argc
, char *argv
[])
1031 scm_boot_guile (argc
, argv
, tests
, NULL
);