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