Improve test coverage

This commit is contained in:
Matthias Clasen 2011-10-15 00:09:20 -04:00
parent 52321def8f
commit 8bc8cd7aa0
3 changed files with 74 additions and 2 deletions

View File

@ -215,6 +215,9 @@ slice_LDADD = $(progs_ldadd)
TEST_PROGS += hook
hook_LDADD = $(progs_ldadd)
TEST_PROGS += mainloop
mainloop_LDADD = $(progs_ldadd)
TEST_PROGS += private
private_LDADD = $(progs_ldadd)

View File

@ -23,8 +23,61 @@
#include <glib.h>
static void
test_unref (void)
test_maincontext_basic (void)
{
GMainContext *ctx;
GSource *source;
GSourceFuncs funcs;
guint id;
ctx = g_main_context_new ();
g_assert (!g_main_context_pending (ctx));
g_assert (!g_main_context_iteration (ctx, FALSE));
source = g_source_new (&funcs, sizeof (GSource));
g_assert (g_source_get_priority (source) == G_PRIORITY_DEFAULT);
g_assert (!g_source_get_can_recurse (source));
g_assert (g_source_get_name (source) == NULL);
g_source_set_can_recurse (source, TRUE);
g_source_set_name (source, "d");
g_assert (g_source_get_can_recurse (source));
g_assert_cmpstr (g_source_get_name (source), ==, "d");
g_assert (g_main_context_find_source_by_user_data (ctx, NULL) == NULL);
g_assert (g_main_context_find_source_by_funcs_user_data (ctx, &funcs, NULL) == NULL);
id = g_source_attach (source, ctx);
g_assert_cmpint (g_source_get_id (source), ==, id);
g_assert (g_main_context_find_source_by_id (ctx, id) == source);
g_source_set_priority (source, G_PRIORITY_HIGH);
g_assert (g_source_get_priority (source) == G_PRIORITY_HIGH);
g_main_context_unref (ctx);
}
static void
test_mainloop_basic (void)
{
GMainLoop *loop;
GMainContext *ctx;
loop = g_main_loop_new (NULL, FALSE);
g_assert (!g_main_loop_is_running (loop));
g_main_loop_ref (loop);
ctx = g_main_loop_get_context (loop);
g_assert (ctx == g_main_context_default ());
g_main_loop_unref (loop);
g_assert (g_main_depth () == 0);
}
int
@ -32,7 +85,8 @@ main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/mainloop/unref", test_unref);
g_test_add_func ("/maincontext/basic", test_maincontext_basic);
g_test_add_func ("/mainloop/basic", test_mainloop_basic);
return g_test_run ();
}

View File

@ -19,6 +19,8 @@
* if advised of the possibility of such damage.
*/
#define GLIB_DISABLE_DEPRECATION_WARNINGS
#include <ctype.h>
#include <errno.h>
#include <locale.h>
@ -1269,6 +1271,18 @@ test_strsignal (void)
}
}
static void
test_strup (void)
{
gchar *s;
s = g_strdup ("lower");
g_assert_cmpstr (g_strup (s), ==, "LOWER");
g_assert_cmpstr (g_strdown (s), ==, "lower");
g_assert (g_strcasecmp ("lower", "LOWER") == 0);
g_free (s);
}
int
main (int argc,
char *argv[])
@ -1301,6 +1315,7 @@ main (int argc,
g_test_add_func ("/strfuncs/strip-context", test_strip_context);
g_test_add_func ("/strfuncs/strerror", test_strerror);
g_test_add_func ("/strfuncs/strsignal", test_strsignal);
g_test_add_func ("/strfuncs/strup", test_strup);
return g_test_run();
}