6 #define sfail(k,p) if (s->str [p] != k) { g_string_free (s,TRUE); return FAILED("Got %s, Failed at %d, expected '%c'", s->str, p, k);}
11 GString *s = g_string_new_len ("My stuff", 2);
15 if (strcmp (s->str, "My") != 0)
16 return "Expected only 'My' on the string";
17 g_string_free (s, TRUE);
19 s = g_string_new_len ("My\0\0Rest", 6);
21 return "Null was not copied";
22 if (strcmp (s->str+4, "Re") != 0){
23 return "Did not find the 'Re' part";
26 g_string_append (s, "lalalalalalalalalalalalalalalalalalalalalalal");
28 return "Null as not copied";
29 if (strncmp (s->str+4, "Relala", 6) != 0){
30 return FAILED("Did not copy correctly, got: %s", s->str+4);
33 g_string_free (s, TRUE);
34 s = g_string_new ("");
35 for (i = 0; i < 1024; i++){
36 g_string_append (s, "x");
38 if (strlen (s->str) != 1024){
39 return FAILED("Incorrect string size, got: %s %d", s->str, strlen (s->str));
41 g_string_free (s, TRUE);
43 s = g_string_new ("");
44 for (i = 0; i < 1024; i++){
45 g_string_append_c (s, 'x');
47 if (strlen (s->str) != 1024){
48 return FAILED("Incorrect string size, got: %s %d\n", s->str, strlen (s->str));
50 g_string_free (s, TRUE);
52 s = g_string_new ("hola");
53 g_string_sprintfa (s, "%s%d", ", bola", 5);
54 if (strcmp (s->str, "hola, bola5") != 0){
55 return FAILED("Incorrect data, got: %s\n", s->str);
57 g_string_free (s, TRUE);
59 s = g_string_new ("Hola");
60 g_string_printf (s, "Dingus");
62 /* Test that it does not release it */
63 ret = g_string_free (s, FALSE);
66 s = g_string_new_len ("H\000H", 3);
67 g_string_append_len (s, "1\0002", 3);
74 g_string_free (s, TRUE);
79 static Test string_tests [] = {
80 {"GString", test_gstring},
84 DEFINE_TEST_GROUP_INIT(string_tests_init, string_tests)