1 /* Copyright (C) 1999, 2000, 2001, 2003, 2004, 2006, 2008, 2010, 2011
2 * 2012 Free Software Foundation, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public License
6 * as published by the Free Software Foundation; either version 3 of
7 * the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30 SCM
out_of_range_handler (void *data
, SCM key
, SCM args
);
31 SCM
call_num2long_long_body (void *data
);
32 SCM
call_num2ulong_long_body (void *data
);
34 /* expect to catch an `out-of-range' exception */
36 out_of_range_handler (void *data
, SCM key
, SCM args
)
38 assert (scm_is_eq (key
, scm_from_locale_symbol ("out-of-range")));
43 call_num2long_long_body (void *data
)
45 scm_to_long_long (* (SCM
*) data
);
50 call_num2ulong_long_body (void *data
)
52 scm_to_ulong_long (* (SCM
*) data
);
60 SCM n
= scm_from_long_long (LLONG_MIN
);
61 long long result
= scm_to_long_long(n
);
62 assert (result
== LLONG_MIN
);
67 SCM n
= scm_difference (scm_from_long_long (LLONG_MIN
), scm_from_int (1));
68 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2long_long_body
, &n
,
69 out_of_range_handler
, NULL
);
70 assert (scm_is_true (caught
));
73 /* SCM_I_LLONG_MIN + SCM_I_LLONG_MIN/2 */
75 SCM n
= scm_sum (scm_from_long_long (LLONG_MIN
),
76 scm_from_long_long (LLONG_MIN
/ 2));
77 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2long_long_body
, &n
,
78 out_of_range_handler
, NULL
);
79 assert (scm_is_true (caught
));
82 /* SCM_I_LLONG_MAX + 1 */
84 SCM n
= scm_sum (scm_from_long_long (LLONG_MAX
), scm_from_int (1));
85 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2long_long_body
, &n
,
86 out_of_range_handler
, NULL
);
87 assert (scm_is_true (caught
));
92 SCM n
= scm_ash (scm_from_int (1), scm_from_int (1024));
93 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2long_long_body
, &n
,
94 out_of_range_handler
, NULL
);
95 assert (scm_is_true (caught
));
100 SCM n
= scm_difference (scm_from_int (0),
101 scm_ash (scm_from_int (1), scm_from_int (1024)));
102 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2long_long_body
, &n
,
103 out_of_range_handler
, NULL
);
104 assert (scm_is_true (caught
));
112 SCM n
= scm_from_ulong_long (ULLONG_MAX
);
113 unsigned long long result
= scm_to_ulong_long(n
);
114 assert (result
== ULLONG_MAX
);
119 SCM n
= scm_from_int (-1);
120 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2ulong_long_body
, &n
,
121 out_of_range_handler
, NULL
);
122 assert (scm_is_true (caught
));
125 /* SCM_I_ULLONG_MAX + 1 */
127 SCM n
= scm_sum (scm_from_ulong_long (ULLONG_MAX
), scm_from_int (1));
128 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2ulong_long_body
, &n
,
129 out_of_range_handler
, NULL
);
130 assert (scm_is_true (caught
));
135 SCM n
= scm_ash (scm_from_int (1), scm_from_int (1024));
136 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2long_long_body
, &n
,
137 out_of_range_handler
, NULL
);
138 assert (scm_is_true (caught
));
143 tests (void *data
, int argc
, char **argv
)
150 main (int argc
, char *argv
[])
152 scm_boot_guile (argc
, argv
, tests
, NULL
);