Merge commit '5b7632331e7551ac202bbaba37c572b96a791c6e'
[bpt/guile.git] / test-suite / standalone / test-scm-to-latin1-string.c
CommitLineData
fe133640
AW
1/* Copyright (C) 2011 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
20#ifdef HAVE_CONFIG_H
21# include <config.h>
22#endif
23
24#include <libguile.h>
25#include <stdlib.h>
26
27/*
28 This outputs:
29
30 dhansen@localhorst ~/tmp $ ./a.out
31 foo,bar
32 bar
33
34*/
35
36#define TEST(x) \
37 if (!(x)) abort()
38
39static void
40inner_main (void *data, int argc, char **argv)
41{
42 char *cstr;
43
44 SCM string, tokens, tok;
45
46 string = scm_from_latin1_string ("foo,bar");
47 tokens = scm_string_split (string, SCM_MAKE_CHAR (','));
48
49 TEST (scm_is_pair (tokens));
50 tok = scm_car (tokens);
51 TEST (scm_is_string (tok));
52 cstr = scm_to_latin1_string (tok);
53 TEST (strcmp (cstr, "foo") == 0);
54 free (cstr);
55 tokens = scm_cdr (tokens);
56
57 TEST (scm_is_pair (tokens));
58 tok = scm_car (tokens);
59 TEST (scm_is_string (tok));
60 cstr = scm_to_latin1_string (tok);
61 TEST (strcmp (cstr, "bar") == 0);
62 free (cstr);
63 tokens = scm_cdr (tokens);
64
65 TEST (scm_is_null (tokens));
66}
67
68int
69main (int argc, char **argv)
70{
71 scm_boot_guile (argc, argv, inner_main, NULL);
72
73 return EXIT_SUCCESS;
74}
75
76/* Local Variables: */
77/* compile-command: "gcc `pkg-config --cflags --libs guile-2.0` main.c" */
78/* End: */