permit non-date values for Expires header
[bpt/guile.git] / test-suite / standalone / test-num2integral.c
1 /* Copyright (C) 1999, 2000, 2001, 2003, 2004, 2006, 2008, 2010,
2 * 2012 Free Software Foundation, Inc.
3 *
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.
8 *
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.
13 *
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
17 * 02110-1301 USA
18 */
19
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
23
24 #include <libguile.h>
25
26 #include <stdio.h>
27 #include <assert.h>
28
29 SCM out_of_range_handler (void *data, SCM key, SCM args);
30 SCM call_num2long_long_body (void *data);
31 SCM call_num2ulong_long_body (void *data);
32
33 /* expect to catch an `out-of-range' exception */
34 SCM
35 out_of_range_handler (void *data, SCM key, SCM args)
36 {
37 assert (scm_is_eq (key, scm_from_locale_symbol ("out-of-range")));
38 return SCM_BOOL_T;
39 }
40
41 SCM
42 call_num2long_long_body (void *data)
43 {
44 scm_to_long_long (* (SCM *) data);
45 return SCM_BOOL_F;
46 }
47
48 SCM
49 call_num2ulong_long_body (void *data)
50 {
51 scm_to_ulong_long (* (SCM *) data);
52 return SCM_BOOL_F;
53 }
54
55 static void
56 test_long_long ()
57 {
58 {
59 SCM n = scm_from_long_long (SCM_I_LLONG_MIN);
60 long long result = scm_to_long_long(n);
61 assert (result == SCM_I_LLONG_MIN);
62 }
63
64 /* LLONG_MIN - 1 */
65 {
66 SCM n = scm_difference (scm_from_long_long (SCM_I_LLONG_MIN), scm_from_int (1));
67 SCM caught = scm_internal_catch (SCM_BOOL_T, call_num2long_long_body, &n,
68 out_of_range_handler, NULL);
69 assert (scm_is_true (caught));
70 }
71
72 /* SCM_I_LLONG_MIN + SCM_I_LLONG_MIN/2 */
73 {
74 SCM n = scm_sum (scm_from_long_long (SCM_I_LLONG_MIN),
75 scm_from_long_long (SCM_I_LLONG_MIN / 2));
76 SCM caught = scm_internal_catch (SCM_BOOL_T, call_num2long_long_body, &n,
77 out_of_range_handler, NULL);
78 assert (scm_is_true (caught));
79 }
80
81 /* SCM_I_LLONG_MAX + 1 */
82 {
83 SCM n = scm_sum (scm_from_long_long (SCM_I_LLONG_MAX), scm_from_int (1));
84 SCM caught = scm_internal_catch (SCM_BOOL_T, call_num2long_long_body, &n,
85 out_of_range_handler, NULL);
86 assert (scm_is_true (caught));
87 }
88
89 /* 2^1024 */
90 {
91 SCM n = scm_ash (scm_from_int (1), scm_from_int (1024));
92 SCM caught = scm_internal_catch (SCM_BOOL_T, call_num2long_long_body, &n,
93 out_of_range_handler, NULL);
94 assert (scm_is_true (caught));
95 }
96
97 /* -2^1024 */
98 {
99 SCM n = scm_difference (scm_from_int (0),
100 scm_ash (scm_from_int (1), scm_from_int (1024)));
101 SCM caught = scm_internal_catch (SCM_BOOL_T, call_num2long_long_body, &n,
102 out_of_range_handler, NULL);
103 assert (scm_is_true (caught));
104 }
105 }
106
107 static void
108 test_ulong_long ()
109 {
110 {
111 SCM n = scm_from_ulong_long (SCM_I_ULLONG_MAX);
112 unsigned long long result = scm_to_ulong_long(n);
113 assert (result == SCM_I_ULLONG_MAX);
114 }
115
116 /* -1 */
117 {
118 SCM n = scm_from_int (-1);
119 SCM caught = scm_internal_catch (SCM_BOOL_T, call_num2ulong_long_body, &n,
120 out_of_range_handler, NULL);
121 assert (scm_is_true (caught));
122 }
123
124 /* SCM_I_ULLONG_MAX + 1 */
125 {
126 SCM n = scm_sum (scm_from_ulong_long (SCM_I_ULLONG_MAX), scm_from_int (1));
127 SCM caught = scm_internal_catch (SCM_BOOL_T, call_num2ulong_long_body, &n,
128 out_of_range_handler, NULL);
129 assert (scm_is_true (caught));
130 }
131
132 /* 2^1024 */
133 {
134 SCM n = scm_ash (scm_from_int (1), scm_from_int (1024));
135 SCM caught = scm_internal_catch (SCM_BOOL_T, call_num2long_long_body, &n,
136 out_of_range_handler, NULL);
137 assert (scm_is_true (caught));
138 }
139 }
140
141 static void
142 tests (void *data, int argc, char **argv)
143 {
144 test_long_long ();
145 test_ulong_long ();
146 }
147
148 int
149 main (int argc, char *argv[])
150 {
151 scm_boot_guile (argc, argv, tests, NULL);
152 return 0;
153 }