~peter-pearse/ubuntu/natty/guile-1.8/prop001

« back to all changes in this revision

Viewing changes to test-suite/tests/c-api/strings.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Schepler
  • Date: 2006-11-09 03:11:16 UTC
  • Revision ID: james.westby@ubuntu.com-20061109031116-hu0q1jxqg12y6yeg
Tags: upstream-1.8.1+1
ImportĀ upstreamĀ versionĀ 1.8.1+1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/* NOTE: this code was never being run.  The same tests have been
 
3
   migrated to standalone/test-gh.c */
 
4
 
 
5
/* strings.c --- test the Guile C API's string handling functions
 
6
   Jim Blandy <jimb@red-bean.com> --- August 1999  */
 
7
 
 
8
#include <guile/gh.h>
 
9
 
 
10
#include "testlib.h"
 
11
 
 
12
static int
 
13
string_equal (SCM str, char *lit)
 
14
{
 
15
  int len = strlen (lit);
 
16
  
 
17
  return (SCM_LENGTH (str) == len
 
18
          && ! memcmp (SCM_ROCHARS (str), lit, len));
 
19
}
 
20
 
 
21
void
 
22
test_gh_set_substr ()
 
23
{
 
24
  test_context_t cx = test_enter_context ("gh_set_substr");
 
25
  SCM string;
 
26
 
 
27
  string = gh_str02scm ("Free, darnit!");
 
28
  test_pass_if ("make a string", gh_string_p (string));
 
29
 
 
30
  gh_set_substr ("dammit", string, 6, 6);
 
31
  test_pass_if ("gh_set_substr from literal",
 
32
                string_equal (string, "Free, dammit!"));
 
33
  
 
34
  /* Make sure that we can use the string itself as a source.
 
35
 
 
36
     I guess this behavior isn't really visible, since the GH API
 
37
     doesn't provide any direct access to the string contents.  But I
 
38
     think it should, eventually.  You can't write efficient string
 
39
     code if you have to copy the string just to look at it.  */
 
40
 
 
41
  /* Copy a substring to an overlapping region to its right.  */
 
42
  gh_set_substr (SCM_CHARS (string), string, 4, 6);
 
43
  test_pass_if ("gh_set_substr shifting right",
 
44
                string_equal (string, "FreeFree, it!"));
 
45
  
 
46
  string = gh_str02scm ("Free, darnit!");
 
47
  test_pass_if ("make another string", gh_string_p (string));
 
48
 
 
49
  /* Copy a substring to an overlapping region to its left.  */
 
50
  gh_set_substr (SCM_CHARS (string) + 6, string, 2, 6);
 
51
  test_pass_if ("gh_set_substr shifting right",
 
52
                string_equal (string, "Frdarnitrnit!"));
 
53
 
 
54
  test_restore_context (cx);
 
55
}
 
56
 
 
57
void 
 
58
main_prog (int argc, char *argv[])
 
59
{
 
60
  test_context_t strings = test_enter_context ("strings.c");
 
61
 
 
62
  test_gh_set_substr ();
 
63
 
 
64
  test_restore_context (strings);
 
65
 
 
66
  exit (test_summarize ());
 
67
}
 
68
 
 
69
int 
 
70
main (int argc, char *argv[])
 
71
{
 
72
  gh_enter (argc, argv, main_prog);
 
73
  return 0;
 
74
}