]> git.donarmstrong.com Git - lilypond.git/blob - guile18/test-suite/standalone/test-gh.c
Import guile-1.8 as multiple upstream tarball component
[lilypond.git] / guile18 / test-suite / standalone / test-gh.c
1 /* Copyright (C) 1999,2000,2001,2003, 2006, 2008 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
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but 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 02110-1301 USA
16  */
17
18 /* some bits originally by Jim Blandy <jimb@red-bean.com> */
19
20 #ifndef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
23
24 #include <libguile.h>
25 #include <libguile/gh.h>
26
27 #include <assert.h>
28 #include <string.h>
29
30 #if SCM_ENABLE_DEPRECATED
31
32 static int
33 string_equal (SCM str, char *lit)
34 {
35   int len = strlen (lit);
36   int result;
37  
38   result = ((scm_i_string_length (str) == len)
39             && (!memcmp (scm_i_string_chars (str), lit, len)));
40   scm_remember_upto_here_1 (str);
41   return result;
42 }
43
44 static void
45 test_gh_set_substr ()
46 {
47   SCM string;
48
49   string = gh_str02scm ("Free, darnit!");
50   assert (gh_string_p (string));
51
52   gh_set_substr ("dammit", string, 6, 6);
53   assert (string_equal (string, "Free, dammit!"));
54   
55   /* Make sure that we can use the string itself as a source.
56
57      I guess this behavior isn't really visible, since the GH API
58      doesn't provide any direct access to the string contents.  But I
59      think it should, eventually.  You can't write efficient string
60      code if you have to copy the string just to look at it.  */
61
62   /* Copy a substring to an overlapping region to its right.  */
63   gh_set_substr (scm_i_string_chars (string), string, 4, 6);
64   assert (string_equal (string, "FreeFree, it!"));
65   
66   string = gh_str02scm ("Free, darnit!");
67   assert (gh_string_p (string));
68
69   /* Copy a substring to an overlapping region to its left.  */
70   gh_set_substr (scm_i_string_chars (string) + 6, string, 2, 6);
71   assert (string_equal (string, "Frdarnitrnit!"));
72 }
73
74 static void
75 tests (void *data, int argc, char **argv)
76 {
77   test_gh_set_substr ();
78 }
79
80 int
81 main (int argc, char *argv[])
82 {
83   scm_boot_guile (argc, argv, tests, NULL);
84   return 0;
85 }
86
87 #else
88
89 int 
90 main (int argc, char *argv[])
91 {
92   return 0;
93 }
94
95 #endif /* !SCM_ENABLE_DEPRECATED */