mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-11 20:06:18 +01:00
Improve the g_string_append test
Test the inline versions too, and test passing -1 for len.
This commit is contained in:
parent
57de9af06f
commit
84780536a4
@ -206,17 +206,35 @@ static void
|
|||||||
test_string_append (void)
|
test_string_append (void)
|
||||||
{
|
{
|
||||||
GString *string;
|
GString *string;
|
||||||
|
char *tmp;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
tmp = g_strdup ("more");
|
||||||
|
|
||||||
/* append */
|
/* append */
|
||||||
string = g_string_new ("firsthalf");
|
string = g_string_new ("firsthalf");
|
||||||
g_string_append (string, "lasthalf");
|
g_string_append (string, "last");
|
||||||
|
(g_string_append) (string, "half");
|
||||||
|
|
||||||
g_assert_cmpstr (string->str, ==, "firsthalflasthalf");
|
g_assert_cmpstr (string->str, ==, "firsthalflasthalf");
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
g_string_append (string, &tmp[i++]);
|
||||||
|
(g_string_append) (string, &tmp[i++]);
|
||||||
|
g_assert_true (i == 2);
|
||||||
|
|
||||||
|
g_assert_cmpstr (string->str, ==, "firsthalflasthalfmoreore");
|
||||||
|
|
||||||
g_string_free (string, TRUE);
|
g_string_free (string, TRUE);
|
||||||
|
|
||||||
/* append_len */
|
/* append_len */
|
||||||
string = g_string_new ("firsthalf");
|
string = g_string_new ("firsthalf");
|
||||||
g_string_append_len (string, "lasthalfjunkjunk", strlen ("lasthalf"));
|
g_string_append_len (string, "lasthalfjunkjunk", strlen ("last"));
|
||||||
g_assert_cmpstr (string->str, ==, "firsthalflasthalf");
|
(g_string_append_len) (string, "halfjunkjunk", strlen ("half"));
|
||||||
|
g_string_append_len (string, "more", -1);
|
||||||
|
(g_string_append_len) (string, "ore", -1);
|
||||||
|
|
||||||
|
g_assert_cmpstr (string->str, ==, "firsthalflasthalfmoreore");
|
||||||
g_string_free (string, TRUE);
|
g_string_free (string, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user