mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
Improve boxed test coverage
This commit add basic tests for all GLib types that are registered as boxed types.
This commit is contained in:
parent
e7c0f10ee0
commit
bebbc69081
@ -292,6 +292,33 @@ test_boxed_regex (void)
|
||||
g_value_unset (&value);
|
||||
}
|
||||
|
||||
static void
|
||||
test_boxed_matchinfo (void)
|
||||
{
|
||||
GRegex *r;
|
||||
GMatchInfo *info, *info2;
|
||||
gboolean ret;
|
||||
GValue value = G_VALUE_INIT;
|
||||
|
||||
g_value_init (&value, G_TYPE_MATCH_INFO);
|
||||
g_assert (G_VALUE_HOLDS_BOXED (&value));
|
||||
|
||||
r = g_regex_new ("ab", 0, 0, NULL);
|
||||
ret = g_regex_match (r, "blabla abab bla", 0, &info);
|
||||
g_assert (ret);
|
||||
g_value_take_boxed (&value, info);
|
||||
|
||||
info2 = g_value_get_boxed (&value);
|
||||
g_assert (info == info2);
|
||||
|
||||
info2 = g_value_dup_boxed (&value);
|
||||
g_assert (info == info2); /* matchinfo uses ref/unref for copy/free */
|
||||
g_match_info_unref (info2);
|
||||
|
||||
g_value_unset (&value);
|
||||
g_regex_unref (r);
|
||||
}
|
||||
|
||||
static void
|
||||
test_boxed_varianttype (void)
|
||||
{
|
||||
@ -367,6 +394,116 @@ test_boxed_error (void)
|
||||
g_value_unset (&value);
|
||||
}
|
||||
|
||||
static void
|
||||
test_boxed_keyfile (void)
|
||||
{
|
||||
GKeyFile *k, *k2;
|
||||
GValue value = G_VALUE_INIT;
|
||||
|
||||
g_value_init (&value, G_TYPE_KEY_FILE);
|
||||
g_assert (G_VALUE_HOLDS_BOXED (&value));
|
||||
|
||||
k = g_key_file_new ();
|
||||
g_value_take_boxed (&value, k);
|
||||
|
||||
k2 = g_value_get_boxed (&value);
|
||||
g_assert (k == k2);
|
||||
|
||||
k2 = g_value_dup_boxed (&value);
|
||||
g_assert (k == k2); /* keyfile uses ref/unref for copy/free */
|
||||
g_key_file_unref (k2);
|
||||
|
||||
g_value_unset (&value);
|
||||
}
|
||||
|
||||
static void
|
||||
test_boxed_mainloop (void)
|
||||
{
|
||||
GMainLoop *l, *l2;
|
||||
GValue value = G_VALUE_INIT;
|
||||
|
||||
g_value_init (&value, G_TYPE_MAIN_LOOP);
|
||||
g_assert (G_VALUE_HOLDS_BOXED (&value));
|
||||
|
||||
l = g_main_loop_new (NULL, FALSE);
|
||||
g_value_take_boxed (&value, l);
|
||||
|
||||
l2 = g_value_get_boxed (&value);
|
||||
g_assert (l == l2);
|
||||
|
||||
l2 = g_value_dup_boxed (&value);
|
||||
g_assert (l == l2); /* mainloop uses ref/unref for copy/free */
|
||||
g_main_loop_unref (l2);
|
||||
|
||||
g_value_unset (&value);
|
||||
}
|
||||
|
||||
static void
|
||||
test_boxed_maincontext (void)
|
||||
{
|
||||
GMainContext *c, *c2;
|
||||
GValue value = G_VALUE_INIT;
|
||||
|
||||
g_value_init (&value, G_TYPE_MAIN_CONTEXT);
|
||||
g_assert (G_VALUE_HOLDS_BOXED (&value));
|
||||
|
||||
c = g_main_context_new ();
|
||||
g_value_take_boxed (&value, c);
|
||||
|
||||
c2 = g_value_get_boxed (&value);
|
||||
g_assert (c == c2);
|
||||
|
||||
c2 = g_value_dup_boxed (&value);
|
||||
g_assert (c == c2); /* maincontext uses ref/unref for copy/free */
|
||||
g_main_context_unref (c2);
|
||||
|
||||
g_value_unset (&value);
|
||||
}
|
||||
|
||||
static void
|
||||
test_boxed_source (void)
|
||||
{
|
||||
GSource *s, *s2;
|
||||
GValue value = G_VALUE_INIT;
|
||||
|
||||
g_value_init (&value, G_TYPE_SOURCE);
|
||||
g_assert (G_VALUE_HOLDS_BOXED (&value));
|
||||
|
||||
s = g_idle_source_new ();
|
||||
g_value_take_boxed (&value, s);
|
||||
|
||||
s2 = g_value_get_boxed (&value);
|
||||
g_assert (s == s2);
|
||||
|
||||
s2 = g_value_dup_boxed (&value);
|
||||
g_assert (s == s2); /* source uses ref/unref for copy/free */
|
||||
g_source_unref (s2);
|
||||
|
||||
g_value_unset (&value);
|
||||
}
|
||||
|
||||
static void
|
||||
test_boxed_variantbuilder (void)
|
||||
{
|
||||
GVariantBuilder *v, *v2;
|
||||
GValue value = G_VALUE_INIT;
|
||||
|
||||
g_value_init (&value, G_TYPE_VARIANT_BUILDER);
|
||||
g_assert (G_VALUE_HOLDS_BOXED (&value));
|
||||
|
||||
v = g_variant_builder_new (G_VARIANT_TYPE_OBJECT_PATH_ARRAY);
|
||||
g_value_take_boxed (&value, v);
|
||||
|
||||
v2 = g_value_get_boxed (&value);
|
||||
g_assert (v == v2);
|
||||
|
||||
v2 = g_value_dup_boxed (&value);
|
||||
g_assert (v == v2); /* variantbuilder uses ref/unref for copy/free */
|
||||
g_variant_builder_unref (v2);
|
||||
|
||||
g_value_unset (&value);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
@ -386,6 +523,12 @@ main (int argc, char *argv[])
|
||||
g_test_add_func ("/boxed/varianttype", test_boxed_varianttype);
|
||||
g_test_add_func ("/boxed/error", test_boxed_error);
|
||||
g_test_add_func ("/boxed/datetime", test_boxed_datetime);
|
||||
g_test_add_func ("/boxed/matchinfo", test_boxed_matchinfo);
|
||||
g_test_add_func ("/boxed/keyfile", test_boxed_keyfile);
|
||||
g_test_add_func ("/boxed/mainloop", test_boxed_mainloop);
|
||||
g_test_add_func ("/boxed/maincontext", test_boxed_maincontext);
|
||||
g_test_add_func ("/boxed/source", test_boxed_source);
|
||||
g_test_add_func ("/boxed/variantbuilder", test_boxed_variantbuilder);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user