summaryrefslogtreecommitdiff
path: root/test-suite/standalone/test-num2integral.c
diff options
context:
space:
mode:
authorKevin Ryde <user42@zip.com.au>2004-04-27 23:19:35 +0000
committerKevin Ryde <user42@zip.com.au>2004-04-27 23:19:35 +0000
commitb313d73a1916517e06abbd07c2080b809a51b415 (patch)
treea48e898aacbdf61fde1f505a0721f1c13b8b07b4 /test-suite/standalone/test-num2integral.c
parentf93df18fea2e514ef6d059edfde0aaa295dd87fc (diff)
downloadguile-b313d73a1916517e06abbd07c2080b809a51b415.tar.gz
(test_long_long): Exercise
out-of-range errors on various cases. (test_ulong_long): New function, split from test_long_long and similarly exercising out-of-range.
Diffstat (limited to 'test-suite/standalone/test-num2integral.c')
-rw-r--r--test-suite/standalone/test-num2integral.c106
1 files changed, 105 insertions, 1 deletions
diff --git a/test-suite/standalone/test-num2integral.c b/test-suite/standalone/test-num2integral.c
index 1a2aeb79b..13513ed15 100644
--- a/test-suite/standalone/test-num2integral.c
+++ b/test-suite/standalone/test-num2integral.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999,2000,2001,2003 Free Software Foundation, Inc.
+/* Copyright (C) 1999,2000,2001,2003,2004 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -29,6 +29,33 @@
# endif
#endif
+
+SCM out_of_range_handler (void *data, SCM key, SCM args);
+SCM call_num2long_long_body (void *data);
+SCM call_num2ulong_long_body (void *data);
+
+/* expect to catch an `out-of-range' exception */
+SCM
+out_of_range_handler (void *data, SCM key, SCM args)
+{
+ assert (scm_equal_p (key, scm_str2symbol ("out-of-range")));
+ return SCM_BOOL_T;
+}
+
+SCM
+call_num2long_long_body (void *data)
+{
+ scm_num2long_long (* (SCM *) data, SCM_ARG1, "call_num2long_long_body");
+ return SCM_BOOL_F;
+}
+
+SCM
+call_num2ulong_long_body (void *data)
+{
+ scm_num2ulong_long (* (SCM *) data, SCM_ARG1, "call_num2ulong_long_body");
+ return SCM_BOOL_F;
+}
+
static void
test_long_long ()
{
@@ -38,11 +65,87 @@ test_long_long ()
long long result = scm_num2long_long(n, 0, "main");
assert (result == LLONG_MIN);
}
+
+ /* LLONG_MIN - 1 */
+ {
+ SCM n = scm_difference (scm_long_long2num (LLONG_MIN), SCM_MAKINUM(1));
+ SCM caught = scm_internal_catch (SCM_BOOL_T, call_num2long_long_body, &n,
+ out_of_range_handler, NULL);
+ assert (! SCM_FALSEP (caught));
+ }
+
+ /* LLONG_MIN + LLONG_MIN/2 */
+ {
+ SCM n = scm_sum (scm_long_long2num (LLONG_MIN),
+ scm_long_long2num (LLONG_MIN / 2));
+ SCM caught = scm_internal_catch (SCM_BOOL_T, call_num2long_long_body, &n,
+ out_of_range_handler, NULL);
+ assert (! SCM_FALSEP (caught));
+ }
+
+ /* LLONG_MAX + 1 */
+ {
+ SCM n = scm_sum (scm_long_long2num (LLONG_MAX), SCM_MAKINUM(1));
+ SCM caught = scm_internal_catch (SCM_BOOL_T, call_num2long_long_body, &n,
+ out_of_range_handler, NULL);
+ assert (! SCM_FALSEP (caught));
+ }
+
+ /* 2^1024 */
+ {
+ SCM n = scm_ash (SCM_MAKINUM (1), SCM_MAKINUM (1024));
+ SCM caught = scm_internal_catch (SCM_BOOL_T, call_num2long_long_body, &n,
+ out_of_range_handler, NULL);
+ assert (! SCM_FALSEP (caught));
+ }
+
+ /* -2^1024 */
+ {
+ SCM n = scm_difference (SCM_MAKINUM (0),
+ scm_ash (SCM_MAKINUM (1), SCM_MAKINUM (1024)));
+ SCM caught = scm_internal_catch (SCM_BOOL_T, call_num2long_long_body, &n,
+ out_of_range_handler, NULL);
+ assert (! SCM_FALSEP (caught));
+ }
+
+#endif /* SCM_SIZEOF_LONG_LONG != 0 */
+}
+
+static void
+test_ulong_long ()
+{
+#if SCM_SIZEOF_LONG_LONG != 0
+
{
SCM n = scm_ulong_long2num (ULLONG_MAX);
unsigned long long result = scm_num2ulong_long(n, 0, "main");
assert (result == ULLONG_MAX);
}
+
+ /* -1 */
+ {
+ SCM n = SCM_MAKINUM (-1);
+ SCM caught = scm_internal_catch (SCM_BOOL_T, call_num2ulong_long_body, &n,
+ out_of_range_handler, NULL);
+ assert (! SCM_FALSEP (caught));
+ }
+
+ /* ULLONG_MAX + 1 */
+ {
+ SCM n = scm_sum (scm_ulong_long2num (ULLONG_MAX), SCM_MAKINUM(1));
+ SCM caught = scm_internal_catch (SCM_BOOL_T, call_num2ulong_long_body, &n,
+ out_of_range_handler, NULL);
+ assert (! SCM_FALSEP (caught));
+ }
+
+ /* 2^1024 */
+ {
+ SCM n = scm_ash (SCM_MAKINUM (1), SCM_MAKINUM (1024));
+ SCM caught = scm_internal_catch (SCM_BOOL_T, call_num2long_long_body, &n,
+ out_of_range_handler, NULL);
+ assert (! SCM_FALSEP (caught));
+ }
+
#endif /* SCM_SIZEOF_LONG_LONG != 0 */
}
@@ -51,5 +154,6 @@ main (int argc, char *argv[])
{
scm_init_guile();
test_long_long ();
+ test_ulong_long ();
return 0;
}