Merge commit '5b7632331e7551ac202bbaba37c572b96a791c6e'
[bpt/guile.git] / test-suite / standalone / test-loose-ends.c
CommitLineData
440ae510
NJ
1/* test-loose-ends.c
2 *
3 * Test items of the Guile C API that aren't covered by any other tests.
4 */
5
0c1f2b0e 6/* Copyright (C) 2009, 2012, 2014 Free Software Foundation, Inc.
440ae510
NJ
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 3 of
11 * the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 */
23
24#if HAVE_CONFIG_H
25# include <config.h>
26#endif
27
0c1f2b0e
LC
28#undef NDEBUG
29
440ae510
NJ
30#include <libguile.h>
31
32#include <stdio.h>
33#include <assert.h>
34#include <string.h>
35
36#ifdef HAVE_INTTYPES_H
37# include <inttypes.h>
38#endif
39
40static void
41test_scm_from_locale_keywordn ()
42{
43 SCM kw = scm_from_locale_keywordn ("thusly", 4);
44 assert (scm_is_true (scm_keyword_p (kw)));
45}
46
d062a8c1
AW
47static void
48test_scm_local_eval ()
49{
0133e13f
AW
50 SCM result;
51
52 scm_c_use_module ("ice-9 local-eval");
53 result = scm_local_eval
d062a8c1
AW
54 (scm_list_3 (scm_from_latin1_symbol ("+"),
55 scm_from_latin1_symbol ("x"),
56 scm_from_latin1_symbol ("y")),
57 scm_c_eval_string ("(let ((x 1) (y 2)) (the-environment))"));
58
59 assert (scm_is_true (scm_equal_p (result,
60 scm_from_signed_integer (3))));
61}
62
741b8a23 63static void
07c2ca0f 64test_scm_call ()
741b8a23
MW
65{
66 SCM result;
67
07c2ca0f
MW
68 result = scm_call (scm_c_public_ref ("guile", "+"),
69 scm_from_int (1),
70 scm_from_int (2),
71 SCM_UNDEFINED);
741b8a23
MW
72 assert (scm_is_true (scm_equal_p (result, scm_from_int (3))));
73
07c2ca0f
MW
74 result = scm_call (scm_c_public_ref ("guile", "list"),
75 SCM_UNDEFINED);
741b8a23
MW
76 assert (scm_is_eq (result, SCM_EOL));
77}
78
1d00abb0
MW
79static void
80test_scm_to_pointer ()
81{
82 int (*add3) (int a, int b, int c);
83 SCM int_type = scm_c_public_ref ("system foreign", "int");
84
85 add3 = scm_to_pointer
86 (scm_procedure_to_pointer (int_type,
87 scm_c_public_ref ("guile", "+"),
88 scm_list_3 (int_type,
89 int_type,
90 int_type)));
91
92 assert ((*add3) (1000000, 1000, -1) == 1000999);
93}
94
440ae510
NJ
95static void
96tests (void *data, int argc, char **argv)
97{
98 test_scm_from_locale_keywordn ();
d062a8c1 99 test_scm_local_eval ();
07c2ca0f 100 test_scm_call ();
1d00abb0 101 test_scm_to_pointer ();
440ae510
NJ
102}
103
104int
105main (int argc, char *argv[])
106{
107 scm_boot_guile (argc, argv, tests, NULL);
108 return 0;
109}