1 /* Copyright (C) 1999,2000,2001,2003,2004, 2006, 2008, 2010 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 License
5 * as published by the Free Software Foundation; either version 3 of
6 * the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful, but
9 * 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
28 SCM
out_of_range_handler (void *data
, SCM key
, SCM args
);
29 SCM
call_num2long_long_body (void *data
);
30 SCM
call_num2ulong_long_body (void *data
);
32 /* expect to catch an `out-of-range' exception */
34 out_of_range_handler (void *data
, SCM key
, SCM args
)
36 assert (scm_equal_p (key
, scm_from_locale_symbol ("out-of-range")));
41 call_num2long_long_body (void *data
)
43 scm_to_long_long (* (SCM
*) data
);
48 call_num2ulong_long_body (void *data
)
50 scm_to_ulong_long (* (SCM
*) data
);
58 SCM n
= scm_from_long_long (SCM_I_LLONG_MIN
);
59 long long result
= scm_to_long_long(n
);
60 assert (result
== SCM_I_LLONG_MIN
);
65 SCM n
= scm_difference (scm_from_long_long (SCM_I_LLONG_MIN
), scm_from_int (1));
66 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2long_long_body
, &n
,
67 out_of_range_handler
, NULL
);
68 assert (scm_is_true (caught
));
71 /* SCM_I_LLONG_MIN + SCM_I_LLONG_MIN/2 */
73 SCM n
= scm_sum (scm_from_long_long (SCM_I_LLONG_MIN
),
74 scm_from_long_long (SCM_I_LLONG_MIN
/ 2));
75 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2long_long_body
, &n
,
76 out_of_range_handler
, NULL
);
77 assert (scm_is_true (caught
));
80 /* SCM_I_LLONG_MAX + 1 */
82 SCM n
= scm_sum (scm_from_long_long (SCM_I_LLONG_MAX
), scm_from_int (1));
83 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2long_long_body
, &n
,
84 out_of_range_handler
, NULL
);
85 assert (scm_is_true (caught
));
90 SCM n
= scm_ash (scm_from_int (1), scm_from_int (1024));
91 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2long_long_body
, &n
,
92 out_of_range_handler
, NULL
);
93 assert (scm_is_true (caught
));
98 SCM n
= scm_difference (scm_from_int (0),
99 scm_ash (scm_from_int (1), scm_from_int (1024)));
100 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2long_long_body
, &n
,
101 out_of_range_handler
, NULL
);
102 assert (scm_is_true (caught
));
110 SCM n
= scm_from_ulong_long (SCM_I_ULLONG_MAX
);
111 unsigned long long result
= scm_to_ulong_long(n
);
112 assert (result
== SCM_I_ULLONG_MAX
);
117 SCM n
= scm_from_int (-1);
118 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2ulong_long_body
, &n
,
119 out_of_range_handler
, NULL
);
120 assert (scm_is_true (caught
));
123 /* SCM_I_ULLONG_MAX + 1 */
125 SCM n
= scm_sum (scm_from_ulong_long (SCM_I_ULLONG_MAX
), scm_from_int (1));
126 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2ulong_long_body
, &n
,
127 out_of_range_handler
, NULL
);
128 assert (scm_is_true (caught
));
133 SCM n
= scm_ash (scm_from_int (1), scm_from_int (1024));
134 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2long_long_body
, &n
,
135 out_of_range_handler
, NULL
);
136 assert (scm_is_true (caught
));
141 tests (void *data
, int argc
, char **argv
)
148 main (int argc
, char *argv
[])
150 scm_boot_guile (argc
, argv
, tests
, NULL
);