1 /* Copyright (C) 1999,2000,2001,2003,2004, 2006, 2008 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 #if SCM_ENABLE_DISCOURAGED == 1
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_equal_p (key
, scm_str2symbol ("out-of-range")));
43 call_num2long_long_body (void *data
)
45 scm_num2long_long (* (SCM
*) data
, SCM_ARG1
, "call_num2long_long_body");
50 call_num2ulong_long_body (void *data
)
52 scm_num2ulong_long (* (SCM
*) data
, SCM_ARG1
, "call_num2ulong_long_body");
59 #if SCM_SIZEOF_LONG_LONG != 0
61 SCM n
= scm_long_long2num (SCM_I_LLONG_MIN
);
62 long long result
= scm_num2long_long(n
, 0, "main");
63 assert (result
== SCM_I_LLONG_MIN
);
68 SCM n
= scm_difference (scm_long_long2num (SCM_I_LLONG_MIN
), scm_from_int (1));
69 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2long_long_body
, &n
,
70 out_of_range_handler
, NULL
);
71 assert (scm_is_true (caught
));
74 /* SCM_I_LLONG_MIN + SCM_I_LLONG_MIN/2 */
76 SCM n
= scm_sum (scm_long_long2num (SCM_I_LLONG_MIN
),
77 scm_long_long2num (SCM_I_LLONG_MIN
/ 2));
78 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2long_long_body
, &n
,
79 out_of_range_handler
, NULL
);
80 assert (scm_is_true (caught
));
83 /* SCM_I_LLONG_MAX + 1 */
85 SCM n
= scm_sum (scm_long_long2num (SCM_I_LLONG_MAX
), scm_from_int (1));
86 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2long_long_body
, &n
,
87 out_of_range_handler
, NULL
);
88 assert (scm_is_true (caught
));
93 SCM n
= scm_ash (scm_from_int (1), scm_from_int (1024));
94 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2long_long_body
, &n
,
95 out_of_range_handler
, NULL
);
96 assert (scm_is_true (caught
));
101 SCM n
= scm_difference (scm_from_int (0),
102 scm_ash (scm_from_int (1), scm_from_int (1024)));
103 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2long_long_body
, &n
,
104 out_of_range_handler
, NULL
);
105 assert (scm_is_true (caught
));
108 #endif /* SCM_SIZEOF_LONG_LONG != 0 */
114 #if SCM_SIZEOF_LONG_LONG != 0
117 SCM n
= scm_ulong_long2num (SCM_I_ULLONG_MAX
);
118 unsigned long long result
= scm_num2ulong_long(n
, 0, "main");
119 assert (result
== SCM_I_ULLONG_MAX
);
124 SCM n
= scm_from_int (-1);
125 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2ulong_long_body
, &n
,
126 out_of_range_handler
, NULL
);
127 assert (scm_is_true (caught
));
130 /* SCM_I_ULLONG_MAX + 1 */
132 SCM n
= scm_sum (scm_ulong_long2num (SCM_I_ULLONG_MAX
), scm_from_int (1));
133 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2ulong_long_body
, &n
,
134 out_of_range_handler
, NULL
);
135 assert (scm_is_true (caught
));
140 SCM n
= scm_ash (scm_from_int (1), scm_from_int (1024));
141 SCM caught
= scm_internal_catch (SCM_BOOL_T
, call_num2long_long_body
, &n
,
142 out_of_range_handler
, NULL
);
143 assert (scm_is_true (caught
));
146 #endif /* SCM_SIZEOF_LONG_LONG != 0 */
150 tests (void *data
, int argc
, char **argv
)
157 main (int argc
, char *argv
[])
159 scm_boot_guile (argc
, argv
, tests
, NULL
);
163 #else /* SCM_ENABLE_DISCOURAGED == 0 */
166 main (int argc
, char *argv
[])
171 #endif /* SCM_ENABLE_DISCOURAGED == 0 */