From dea042b85514f997df0f77006cdcca063486097b Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 5 Jul 2010 03:09:36 -0400 Subject: [PATCH] Misc test additions --- gio/tests/Makefile.am | 7 ++++ gio/tests/appinfo.c | 27 ++++++++++++- gio/tests/contenttype.c | 4 ++ gio/tests/file.c | 64 ++++++++++++++++++++++++++++++ gio/tests/gsettings.c | 56 ++++++++++++++++++++++++++ gio/tests/live-g-file.c | 9 +++++ gio/tests/org.gtk.test.gschema.xml | 3 ++ 7 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 gio/tests/file.c diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am index faa764081..988fc45cf 100644 --- a/gio/tests/Makefile.am +++ b/gio/tests/Makefile.am @@ -60,6 +60,7 @@ TEST_PROGS += \ appinfo \ icons \ contenttype \ + file \ $(NULL) endif @@ -280,6 +281,9 @@ icons_LDADD = $(progs_ldadd) contenttype_SOURCES = contenttype.c contenttype_LDADD = $(progs_ldadd) +file_SOURCES = file.c +file_LDADD = $(progs_ldadd) + schema_tests = \ schema-tests/array-default-not-in-choices.gschema.xml \ schema-tests/bad-choice.gschema.xml \ @@ -361,6 +365,9 @@ EXTRA_DIST += \ de.po \ $(schema_tests) \ appinfo-test.desktop \ + appinfo-test2.desktop \ + appinfo-test-gnome.desktop \ + appinfo-test-notgnome.desktop \ gdbus-testserver.py MISC_STUFF = test.mo diff --git a/gio/tests/appinfo.c b/gio/tests/appinfo.c index be63a92da..6d8910be7 100644 --- a/gio/tests/appinfo.c +++ b/gio/tests/appinfo.c @@ -8,11 +8,17 @@ static void test_launch (void) { GAppInfo *appinfo; + GError *error; appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (SRCDIR "/appinfo-test.desktop"); g_assert (appinfo != NULL); - g_assert (g_app_info_launch (appinfo, NULL, NULL, NULL)); + error = NULL; + g_assert (g_app_info_launch (appinfo, NULL, NULL, &error)); + g_assert_no_error (error); + + g_assert (g_app_info_launch_uris (appinfo, NULL, NULL, &error)); + g_assert_no_error (error); } static void @@ -65,6 +71,7 @@ static void test_basic (void) { GAppInfo *appinfo; + GAppInfo *appinfo2; GIcon *icon, *icon2; appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (SRCDIR "/appinfo-test.desktop"); @@ -79,7 +86,12 @@ test_basic (void) g_assert (g_icon_equal (icon, icon2)); g_object_unref (icon2); + appinfo2 = g_app_info_dup (appinfo); + g_assert (g_app_info_get_id (appinfo) == g_app_info_get_id (appinfo2)); + g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, g_app_info_get_commandline (appinfo2)); + g_object_unref (appinfo); + g_object_unref (appinfo2); } static void @@ -160,19 +172,30 @@ test_launch_context (void) g_object_unref (context); } +static void +test_tryexec (void) +{ + GAppInfo *appinfo; + + appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (SRCDIR "/appinfo-test2.desktop"); + + g_assert (appinfo == NULL); +} + int main (int argc, char *argv[]) { g_type_init (); g_test_init (&argc, &argv, NULL); - g_test_add_func ("/appinfo/basic", test_basic); g_test_add_func ("/appinfo/text", test_text); g_test_add_func ("/appinfo/launch", test_launch); g_test_add_func ("/appinfo/show-in", test_show_in); g_test_add_func ("/appinfo/commandline", test_commandline); g_test_add_func ("/appinfo/launch-context", test_launch_context); + g_test_add_func ("/appinfo/tryexec", test_tryexec); + return g_test_run (); } diff --git a/gio/tests/contenttype.c b/gio/tests/contenttype.c index 1ae6b18c2..db31ba136 100644 --- a/gio/tests/contenttype.c +++ b/gio/tests/contenttype.c @@ -94,6 +94,10 @@ test_executable (void) type = g_content_type_from_mime_type ("text/plain"); g_assert (g_content_type_can_be_executable (type)); g_free (type); + + type = g_content_type_from_mime_type ("image/png"); + g_assert (!g_content_type_can_be_executable (type)); + g_free (type); } static void diff --git a/gio/tests/file.c b/gio/tests/file.c new file mode 100644 index 000000000..8a35f8a56 --- /dev/null +++ b/gio/tests/file.c @@ -0,0 +1,64 @@ +#include + +static void +test_basic (void) +{ + GFile *file; + gchar *s; + + file = g_file_new_for_path ("./some/directory/testfile"); + + s = g_file_get_basename (file); + g_assert_cmpstr (s, ==, "testfile"); + g_free (s); + + s = g_file_get_uri (file); + g_assert (g_str_has_prefix (s, "file://")); + g_assert (g_str_has_suffix (s, "/some/directory/testfile")); + g_free (s); + + g_assert (g_file_has_uri_scheme (file, "file")); + s = g_file_get_uri_scheme (file); + g_assert_cmpstr (s, ==, "file"); + g_free (s); + + g_object_unref (file); +} + +static void +test_parent (void) +{ + GFile *file; + GFile *file2; + GFile *parent; + GFile *root; + + file = g_file_new_for_path ("./some/directory/testfile"); + file2 = g_file_new_for_path ("./some/directory"); + root = g_file_new_for_path ("/"); + + g_assert (g_file_has_parent (file, file2)); + + parent = g_file_get_parent (file); + g_assert (g_file_equal (parent, file2)); + g_object_unref (parent); + + g_assert (g_file_get_parent (root) == NULL); + + g_object_unref (file); + g_object_unref (file2); + g_object_unref (root); +} + +int +main (int argc, char *argv[]) +{ + g_type_init (); + + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/file/basic", test_basic); + g_test_add_func ("/file/parent", test_parent); + + return g_test_run (); +} diff --git a/gio/tests/gsettings.c b/gio/tests/gsettings.c index 0e435069e..5e611a9e2 100644 --- a/gio/tests/gsettings.c +++ b/gio/tests/gsettings.c @@ -810,6 +810,7 @@ test_simple_binding (void) guint64 u64; gdouble d; gchar *s; + GVariant *value; settings = g_settings_new ("org.gtk.test.binding"); obj = test_object_new (); @@ -864,6 +865,13 @@ test_simple_binding (void) g_assert_cmpstr (s, ==, "bla bla"); g_free (s); + g_settings_bind (settings, "chararray", obj, "string", G_SETTINGS_BIND_DEFAULT); + + g_object_set (obj, "string", "non-unicode:\315", NULL); + value = g_settings_get_value (settings, "chararray"); + g_assert_cmpstr (g_variant_get_byte_array (value, NULL), ==, "non-unicode:\315"); + g_variant_unref (value); + g_settings_bind (settings, "double", obj, "double", G_SETTINGS_BIND_DEFAULT); g_object_set (obj, "double", G_MAXFLOAT, NULL); @@ -879,6 +887,51 @@ test_simple_binding (void) g_settings_set_double (settings, "double", -G_MINDOUBLE); g_object_get (obj, "double", &d, NULL); g_assert_cmpfloat (d, ==, -G_MINDOUBLE); + + g_object_unref (obj); + g_object_unref (settings); +} + +static void +test_unbind (void) +{ + TestObject *obj; + GSettings *settings; + + settings = g_settings_new ("org.gtk.test.binding"); + obj = test_object_new (); + + g_settings_bind (settings, "int", obj, "int", G_SETTINGS_BIND_DEFAULT); + + g_object_set (obj, "int", 12345, NULL); + g_assert_cmpint (g_settings_get_int (settings, "int"), ==, 12345); + + g_settings_unbind (obj, "int"); + + g_object_set (obj, "int", 54321, NULL); + g_assert_cmpint (g_settings_get_int (settings, "int"), ==, 12345); + + g_object_unref (obj); + g_object_unref (settings); +} + +static void +test_bind_writable (void) +{ + TestObject *obj; + GSettings *settings; + gboolean b; + + settings = g_settings_new ("org.gtk.test.binding"); + obj = test_object_new (); + + g_object_set (obj, "bool", FALSE, NULL); + + g_settings_bind_writable (settings, "int", obj, "bool", G_SETTINGS_BIND_DEFAULT); + + g_object_get (obj, "bool", &b, NULL); + g_assert (b); + g_object_unref (obj); g_object_unref (settings); } @@ -1467,10 +1520,13 @@ main (int argc, char *argv[]) g_test_add_func ("/gsettings/delay-apply", test_delay_apply); g_test_add_func ("/gsettings/delay-revert", test_delay_revert); g_test_add_func ("/gsettings/atomic", test_atomic); + g_test_add_func ("/gsettings/simple-binding", test_simple_binding); g_test_add_func ("/gsettings/directional-binding", test_directional_binding); g_test_add_func ("/gsettings/custom-binding", test_custom_binding); g_test_add_func ("/gsettings/no-change-binding", test_no_change_binding); + g_test_add_func ("/gsettings/unbinding", test_unbind); + g_test_add_func ("/gsettings/writable-binding", test_bind_writable); if (!backend_set) { diff --git a/gio/tests/live-g-file.c b/gio/tests/live-g-file.c index 1ca70ce50..75ff5de75 100644 --- a/gio/tests/live-g-file.c +++ b/gio/tests/live-g-file.c @@ -506,6 +506,8 @@ traverse_recurse_dirs (GFile * parent, GFile * root) g_assert (enumerator != NULL); g_assert_no_error (error); + g_assert (g_file_enumerator_get_container (enumerator) == parent); + error = NULL; info = g_file_enumerator_next_file (enumerator, NULL, &error); while ((info) && (!error)) @@ -545,6 +547,9 @@ traverse_recurse_dirs (GFile * parent, GFile * root) res = g_file_enumerator_close (enumerator, NULL, &error); g_assert_cmpint (res, ==, TRUE); g_assert_no_error (error); + g_assert (g_file_enumerator_is_closed (enumerator)); + + g_object_unref (enumerator); } static void @@ -642,6 +647,8 @@ test_enumerate (gconstpointer test_data) res = g_file_enumerator_close (enumerator, NULL, &error); g_assert_cmpint (res, ==, TRUE); g_assert_no_error (error); + + g_object_unref (enumerator); } g_object_unref (child); } @@ -1083,6 +1090,8 @@ cleanup_dir_recurse (GFile *parent, GFile *root) res = g_file_enumerator_close (enumerator, NULL, &error); g_assert_cmpint (res, ==, TRUE); g_assert_no_error (error); + + g_object_unref (enumerator); } static void diff --git a/gio/tests/org.gtk.test.gschema.xml b/gio/tests/org.gtk.test.gschema.xml index c7d3d974a..b2dff0b51 100644 --- a/gio/tests/org.gtk.test.gschema.xml +++ b/gio/tests/org.gtk.test.gschema.xml @@ -90,6 +90,9 @@ "" + + [48, 49] + -- 2.34.1