Merge commit '5b7632331e7551ac202bbaba37c572b96a791c6e'
[bpt/guile.git] / test-suite / standalone / test-scm-values.c
1 /* Copyright (C) 2012, 2014 Free Software Foundation, Inc.
2 *
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.
7 *
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.
12 *
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
16 * 02110-1301 USA
17 */
18
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22
23 #undef NDEBUG
24
25 #include <assert.h>
26 #include <libguile.h>
27 #include <stdlib.h>
28 #include <string.h>
29
30 static void
31 test_scm_c_value_ref_on_multiple_values ()
32 {
33 SCM values = scm_values (scm_list_3 (scm_from_latin1_string ("foo"),
34 scm_from_latin1_string ("bar"),
35 scm_from_latin1_string ("baz")));
36
37 char *foo = scm_to_latin1_string (scm_c_value_ref (values, 0));
38 char *bar = scm_to_latin1_string (scm_c_value_ref (values, 1));
39 char *baz = scm_to_latin1_string (scm_c_value_ref (values, 2));
40
41 assert (strcmp (foo, "foo") == 0);
42 assert (strcmp (bar, "bar") == 0);
43 assert (strcmp (baz, "baz") == 0);
44
45 free (foo);
46 free (bar);
47 free (baz);
48 }
49
50 static void
51 test_scm_c_value_ref_on_a_single_value ()
52 {
53 SCM value = scm_from_latin1_string ("foo");
54 char *foo = scm_to_latin1_string (scm_c_value_ref (value, 0));
55 assert (strcmp (foo, "foo") == 0);
56 free (foo);
57 }
58
59 static void
60 tests (void *data, int argc, char **argv)
61 {
62 test_scm_c_value_ref_on_multiple_values ();
63 test_scm_c_value_ref_on_a_single_value ();
64 }
65
66 int
67 main (int argc, char *argv[])
68 {
69 scm_boot_guile (argc, argv, tests, NULL);
70 return 0;
71 }