[glib] Improve test coverage in the GString tests
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Improve test coverage in the GString tests
- Date: Tue, 4 Oct 2011 04:47:06 +0000 (UTC)
commit e6fa27a5f80f05a6661b803620639e6f0ae96852
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Oct 4 00:45:42 2011 -0400
Improve test coverage in the GString tests
glib/tests/string.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 50 insertions(+), 1 deletions(-)
---
diff --git a/glib/tests/string.c b/glib/tests/string.c
index ff172bd..1143414 100644
--- a/glib/tests/string.c
+++ b/glib/tests/string.c
@@ -90,6 +90,29 @@ test_string_new (void)
g_string_free (string1, TRUE);
g_string_free (string2, TRUE);
+
+ string1 = g_string_new_len ("foo", -1);
+ string2 = g_string_new_len ("foobar", 3);
+
+ g_assert_cmpstr (string1->str, ==, "foo");
+ g_assert_cmpint (string1->len, ==, 3);
+ g_assert_cmpstr (string2->str, ==, "foo");
+ g_assert_cmpint (string2->len, ==, 3);
+
+ g_string_free (string1, TRUE);
+ g_string_free (string2, TRUE);
+}
+
+void
+my_string_printf (GString *string,
+ const gchar *format,
+ ...)
+{
+ va_list args;
+
+ va_start (args, format);
+ g_string_vprintf (string, format, args);
+ va_end (args);
}
static void
@@ -114,7 +137,15 @@ test_string_printf (void)
" wuss. everyone agrees.\n",
10, 666, 15, 15, 666.666666666, 666.666666666);
#endif
-
+
+ g_string_free (string, TRUE);
+
+ string = g_string_new (NULL);
+ g_string_printf (string, "bla %s %d", "foo", 99);
+ g_assert_cmpstr (string->str, ==, "bla foo 99");
+ my_string_printf (string, "%d,%s,%d", 1, "two", 3);
+ g_assert_cmpstr (string->str, ==, "1,two,3");
+
g_string_free (string, TRUE);
}
@@ -362,6 +393,11 @@ test_string_overwrite (void)
g_assert ('\0' == string->str[15]);
g_assert (g_str_equal ("test NOT-blabla", string->str));
+ g_string_overwrite_len (string, 4, "BLABL", 0);
+ g_assert (g_str_equal ("test NOT-blabla", string->str));
+ g_string_overwrite_len (string, 4, "BLABL", -1);
+ g_assert (g_str_equal ("testBLABLblabla", string->str));
+
g_string_free (string, TRUE);
}
@@ -417,6 +453,18 @@ test_string_up_down (void)
g_assert_cmpstr (s->str, ==, "MIXED CASE STRING !?");
}
+static void
+test_string_set_size (void)
+{
+ GString *s;
+
+ s = g_string_new ("foo");
+ g_string_set_size (s, 30);
+
+ g_assert_cmpstr (s->str, ==, "foo");
+ g_assert_cmpint (s->len, ==, 30);
+}
+
int
main (int argc,
char *argv[])
@@ -439,6 +487,7 @@ main (int argc,
g_test_add_func ("/string/test-string-overwrite", test_string_overwrite);
g_test_add_func ("/string/test-string-nul-handling", test_string_nul_handling);
g_test_add_func ("/string/test-string-up-down", test_string_up_down);
+ g_test_add_func ("/string/test-string-set-size", test_string_set_size);
return g_test_run();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]