Merge commit 'fb7dd00169304a5922838e4d2f25253640a35def'
[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
d062a8c1 6/* Copyright (C) 2009, 2012 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
28#include <libguile.h>
29
30#include <stdio.h>
31#include <assert.h>
32#include <string.h>
33
34#ifdef HAVE_INTTYPES_H
35# include <inttypes.h>
36#endif
37
38static void
39test_scm_from_locale_keywordn ()
40{
41 SCM kw = scm_from_locale_keywordn ("thusly", 4);
42 assert (scm_is_true (scm_keyword_p (kw)));
43}
44
d062a8c1
AW
45static void
46test_scm_local_eval ()
47{
0133e13f
AW
48 SCM result;
49
50 scm_c_use_module ("ice-9 local-eval");
51 result = scm_local_eval
d062a8c1
AW
52 (scm_list_3 (scm_from_latin1_symbol ("+"),
53 scm_from_latin1_symbol ("x"),
54 scm_from_latin1_symbol ("y")),
55 scm_c_eval_string ("(let ((x 1) (y 2)) (the-environment))"));
56
57 assert (scm_is_true (scm_equal_p (result,
58 scm_from_signed_integer (3))));
59}
60
741b8a23 61static void
07c2ca0f 62test_scm_call ()
741b8a23
MW
63{
64 SCM result;
65
07c2ca0f
MW
66 result = scm_call (scm_c_public_ref ("guile", "+"),
67 scm_from_int (1),
68 scm_from_int (2),
69 SCM_UNDEFINED);
741b8a23
MW
70 assert (scm_is_true (scm_equal_p (result, scm_from_int (3))));
71
07c2ca0f
MW
72 result = scm_call (scm_c_public_ref ("guile", "list"),
73 SCM_UNDEFINED);
741b8a23
MW
74 assert (scm_is_eq (result, SCM_EOL));
75}
76
1d00abb0
MW
77static void
78test_scm_to_pointer ()
79{
80 int (*add3) (int a, int b, int c);
81 SCM int_type = scm_c_public_ref ("system foreign", "int");
82
83 add3 = scm_to_pointer
84 (scm_procedure_to_pointer (int_type,
85 scm_c_public_ref ("guile", "+"),
86 scm_list_3 (int_type,
87 int_type,
88 int_type)));
89
90 assert ((*add3) (1000000, 1000, -1) == 1000999);
91}
92
440ae510
NJ
93static void
94tests (void *data, int argc, char **argv)
95{
96 test_scm_from_locale_keywordn ();
d062a8c1 97 test_scm_local_eval ();
07c2ca0f 98 test_scm_call ();
1d00abb0 99 test_scm_to_pointer ();
440ae510
NJ
100}
101
102int
103main (int argc, char *argv[])
104{
105 scm_boot_guile (argc, argv, tests, NULL);
106 return 0;
107}