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("");
14 for(i
= 0; i
< 1024; i
++) {
15 g_string_append(s
, "x");
18 if(strlen (s
->str
) != 1024) {
19 return FAILED("Incorrect string size, got: %s %d",
20 s
->str
, strlen(s
->str
));
23 g_string_free (s
, TRUE
);
31 GString
*s
= g_string_new("");
34 for(i
= 0; i
< 1024; i
++) {
35 g_string_append_c(s
, 'x');
38 if(strlen(s
->str
) != 1024) {
39 return FAILED("Incorrect string size, got: %s %d", s
->str
,
43 g_string_free(s
, TRUE
);
51 GString
*s
= g_string_new_len ("My stuff", 2);
55 if (strcmp (s
->str
, "My") != 0)
56 return "Expected only 'My' on the string";
57 g_string_free (s
, TRUE
);
59 s
= g_string_new_len ("My\0\0Rest", 6);
61 return "Null was not copied";
62 if (strcmp (s
->str
+4, "Re") != 0){
63 return "Did not find the 'Re' part";
66 g_string_append (s
, "lalalalalalalalalalalalalalalalalalalalalalal");
68 return "Null as not copied";
69 if (strncmp (s
->str
+4, "Relala", 6) != 0){
70 return FAILED("Did not copy correctly, got: %s", s
->str
+4);
73 g_string_free (s
, TRUE
);
75 s
= g_string_new ("");
76 for (i
= 0; i
< 1024; i
++){
77 g_string_append_c (s
, 'x');
79 if (strlen (s
->str
) != 1024){
80 return FAILED("Incorrect string size, got: %s %d\n", s
->str
, strlen (s
->str
));
82 g_string_free (s
, TRUE
);
84 s
= g_string_new ("hola");
85 g_string_sprintfa (s
, "%s%d", ", bola", 5);
86 if (strcmp (s
->str
, "hola, bola5") != 0){
87 return FAILED("Incorrect data, got: %s\n", s
->str
);
89 g_string_free (s
, TRUE
);
91 s
= g_string_new ("Hola");
92 g_string_printf (s
, "Dingus");
94 /* Test that it does not release it */
95 ret
= g_string_free (s
, FALSE
);
98 s
= g_string_new_len ("H" "\000" "H", 3);
99 g_string_append_len (s
, "1" "\000" "2", 3);
106 g_string_free (s
, TRUE
);
114 GString
*s
= g_string_sized_new (20);
117 return FAILED ("Expected an empty string");
119 return FAILED ("Expected an empty len");
121 g_string_free (s
, TRUE
);
129 GString
*s
= g_string_new ("0123456789");
130 g_string_truncate (s
, 3);
132 if (strlen (s
->str
) != 3)
133 return FAILED ("size of string should have been 3, instead it is [%s]\n", s
->str
);
134 g_string_free (s
, TRUE
);
136 s
= g_string_new ("a");
137 s
= g_string_truncate (s
, 10);
138 if (strlen (s
->str
) != 1)
139 return FAILED ("The size is not 1");
140 g_string_truncate (s
, (gsize
)-1);
141 if (strlen (s
->str
) != 1)
142 return FAILED ("The size is not 1");
143 g_string_truncate (s
, 0);
144 if (strlen (s
->str
) != 0)
145 return FAILED ("The size is not 0");
147 g_string_free (s
, TRUE
);
155 GString
*s
= g_string_new ("dingus");
156 g_string_prepend (s
, "one");
158 if (strcmp (s
->str
, "onedingus") != 0)
159 return FAILED ("Failed, expected onedingus, got [%s]", s
->str
);
161 g_string_free (s
, TRUE
);
163 /* This is to force the code that where stuff does not fit in the allocated block */
164 s
= g_string_sized_new (1);
165 g_string_prepend (s
, "one");
166 if (strcmp (s
->str
, "one") != 0)
167 return FAILED ("Got erroneous result, expected [one] got [%s]", s
->str
);
168 g_string_free (s
, TRUE
);
170 /* This is to force the path where things fit */
171 s
= g_string_new ("123123123123123123123123");
172 g_string_truncate (s
, 1);
173 if (strcmp (s
->str
, "1") != 0)
174 return FAILED ("Expected [1] string, got [%s]", s
->str
);
176 g_string_prepend (s
, "pre");
177 if (strcmp (s
->str
, "pre1") != 0)
178 return FAILED ("Expected [pre1], got [%s]", s
->str
);
179 g_string_free (s
, TRUE
);
187 GString
*s
= g_string_new ("");
189 g_string_append_len (s
, "boo\000x", 0);
191 return FAILED ("The length is not zero %d", s
->len
);
192 g_string_append_len (s
, "boo\000x", 5);
194 return FAILED ("The length is not five %d", s
->len
);
195 g_string_append_len (s
, "ha", -1);
197 return FAILED ("The length is not seven %d", s
->len
);
199 g_string_free (s
, TRUE
);
207 char *s
= g_strdup (G_STRLOC
);
208 char *p
= strchr (s
+ 2, ':');
212 return FAILED ("Did not find a separator");
215 return FAILED ("did not find a valid line number");
218 if (strcmp (s
+ strlen(s
) - 8 , "string.c") != 0)
219 return FAILED ("This did not store the filename on G_STRLOC");
225 static Test string_tests
[] = {
226 {"append-speed", test_append_speed
},
227 {"append_c-speed", test_append_c_speed
},
228 {"ctor+append", test_gstring
},
229 {"ctor+sized", test_sized
},
230 {"truncate", test_truncate
},
231 {"prepend", test_prepend
},
232 {"append_len", test_appendlen
},
233 {"macros", test_macros
},
237 DEFINE_TEST_GROUP_INIT(string_tests_init
, string_tests
)