mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-04 02:06:18 +01:00
tests: Port desktop-app-info to use g_assert_*()
g_assert() is for runtime code, and can be compiled out. g_assert_*() cannot be compiled out, and give more helpful failure messages for specific types. Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
parent
13730c27c0
commit
528d537da8
@ -40,13 +40,13 @@ create_app_info (const char *name)
|
|||||||
name,
|
name,
|
||||||
G_APP_INFO_CREATE_NONE,
|
G_APP_INFO_CREATE_NONE,
|
||||||
&error);
|
&error);
|
||||||
g_assert (error == NULL);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
/* this is necessary to ensure that the info is saved */
|
/* this is necessary to ensure that the info is saved */
|
||||||
g_app_info_set_as_default_for_type (info, "application/x-blah", &error);
|
g_app_info_set_as_default_for_type (info, "application/x-blah", &error);
|
||||||
g_assert (error == NULL);
|
g_assert_no_error (error);
|
||||||
g_app_info_remove_supports_type (info, "application/x-blah", &error);
|
g_app_info_remove_supports_type (info, "application/x-blah", &error);
|
||||||
g_assert (error == NULL);
|
g_assert_no_error (error);
|
||||||
g_app_info_reset_type_associations ("application/x-blah");
|
g_app_info_reset_type_associations ("application/x-blah");
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
@ -64,34 +64,34 @@ test_delete (void)
|
|||||||
info = create_app_info ("Blah");
|
info = create_app_info ("Blah");
|
||||||
|
|
||||||
id = g_app_info_get_id (info);
|
id = g_app_info_get_id (info);
|
||||||
g_assert (id != NULL);
|
g_assert_nonnull (id);
|
||||||
|
|
||||||
filename = g_build_filename (basedir, "applications", id, NULL);
|
filename = g_build_filename (basedir, "applications", id, NULL);
|
||||||
|
|
||||||
res = g_file_test (filename, G_FILE_TEST_EXISTS);
|
res = g_file_test (filename, G_FILE_TEST_EXISTS);
|
||||||
g_assert (res);
|
g_assert_true (res);
|
||||||
|
|
||||||
res = g_app_info_can_delete (info);
|
res = g_app_info_can_delete (info);
|
||||||
g_assert (res);
|
g_assert_true (res);
|
||||||
|
|
||||||
res = g_app_info_delete (info);
|
res = g_app_info_delete (info);
|
||||||
g_assert (res);
|
g_assert_true (res);
|
||||||
|
|
||||||
res = g_file_test (filename, G_FILE_TEST_EXISTS);
|
res = g_file_test (filename, G_FILE_TEST_EXISTS);
|
||||||
g_assert (!res);
|
g_assert_false (res);
|
||||||
|
|
||||||
g_object_unref (info);
|
g_object_unref (info);
|
||||||
|
|
||||||
if (g_file_test ("/usr/share/applications/gedit.desktop", G_FILE_TEST_EXISTS))
|
if (g_file_test ("/usr/share/applications/gedit.desktop", G_FILE_TEST_EXISTS))
|
||||||
{
|
{
|
||||||
info = (GAppInfo*)g_desktop_app_info_new_from_filename ("/usr/share/applications/gedit.desktop");
|
info = (GAppInfo*)g_desktop_app_info_new_from_filename ("/usr/share/applications/gedit.desktop");
|
||||||
g_assert (info);
|
g_assert_nonnull (info);
|
||||||
|
|
||||||
res = g_app_info_can_delete (info);
|
res = g_app_info_can_delete (info);
|
||||||
g_assert (!res);
|
g_assert_false (res);
|
||||||
|
|
||||||
res = g_app_info_delete (info);
|
res = g_app_info_delete (info);
|
||||||
g_assert (!res);
|
g_assert_false (res);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (filename);
|
g_free (filename);
|
||||||
@ -109,33 +109,33 @@ test_default (void)
|
|||||||
info3 = create_app_info ("Blah3");
|
info3 = create_app_info ("Blah3");
|
||||||
|
|
||||||
g_app_info_set_as_default_for_type (info1, "application/x-test", &error);
|
g_app_info_set_as_default_for_type (info1, "application/x-test", &error);
|
||||||
g_assert (error == NULL);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
g_app_info_set_as_default_for_type (info2, "application/x-test", &error);
|
g_app_info_set_as_default_for_type (info2, "application/x-test", &error);
|
||||||
g_assert (error == NULL);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
info = g_app_info_get_default_for_type ("application/x-test", FALSE);
|
info = g_app_info_get_default_for_type ("application/x-test", FALSE);
|
||||||
g_assert (info != NULL);
|
g_assert_nonnull (info);
|
||||||
g_assert_cmpstr (g_app_info_get_id (info), ==, g_app_info_get_id (info2));
|
g_assert_cmpstr (g_app_info_get_id (info), ==, g_app_info_get_id (info2));
|
||||||
g_object_unref (info);
|
g_object_unref (info);
|
||||||
|
|
||||||
/* now try adding something, but not setting as default */
|
/* now try adding something, but not setting as default */
|
||||||
g_app_info_add_supports_type (info3, "application/x-test", &error);
|
g_app_info_add_supports_type (info3, "application/x-test", &error);
|
||||||
g_assert (error == NULL);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
/* check that info2 is still default */
|
/* check that info2 is still default */
|
||||||
info = g_app_info_get_default_for_type ("application/x-test", FALSE);
|
info = g_app_info_get_default_for_type ("application/x-test", FALSE);
|
||||||
g_assert (info != NULL);
|
g_assert_nonnull (info);
|
||||||
g_assert_cmpstr (g_app_info_get_id (info), ==, g_app_info_get_id (info2));
|
g_assert_cmpstr (g_app_info_get_id (info), ==, g_app_info_get_id (info2));
|
||||||
g_object_unref (info);
|
g_object_unref (info);
|
||||||
|
|
||||||
/* now remove info1 again */
|
/* now remove info1 again */
|
||||||
g_app_info_remove_supports_type (info1, "application/x-test", &error);
|
g_app_info_remove_supports_type (info1, "application/x-test", &error);
|
||||||
g_assert (error == NULL);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
/* and make sure info2 is still default */
|
/* and make sure info2 is still default */
|
||||||
info = g_app_info_get_default_for_type ("application/x-test", FALSE);
|
info = g_app_info_get_default_for_type ("application/x-test", FALSE);
|
||||||
g_assert (info != NULL);
|
g_assert_nonnull (info);
|
||||||
g_assert_cmpstr (g_app_info_get_id (info), ==, g_app_info_get_id (info2));
|
g_assert_cmpstr (g_app_info_get_id (info), ==, g_app_info_get_id (info2));
|
||||||
g_object_unref (info);
|
g_object_unref (info);
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ test_default (void)
|
|||||||
g_app_info_reset_type_associations ("application/x-test");
|
g_app_info_reset_type_associations ("application/x-test");
|
||||||
|
|
||||||
list = g_app_info_get_all_for_type ("application/x-test");
|
list = g_app_info_get_all_for_type ("application/x-test");
|
||||||
g_assert (list == NULL);
|
g_assert_null (list);
|
||||||
|
|
||||||
g_app_info_delete (info1);
|
g_app_info_delete (info1);
|
||||||
g_app_info_delete (info2);
|
g_app_info_delete (info2);
|
||||||
@ -165,17 +165,17 @@ test_fallback (void)
|
|||||||
info1 = create_app_info ("Test1");
|
info1 = create_app_info ("Test1");
|
||||||
info2 = create_app_info ("Test2");
|
info2 = create_app_info ("Test2");
|
||||||
|
|
||||||
g_assert (g_content_type_is_a ("text/x-python", "text/plain"));
|
g_assert_true (g_content_type_is_a ("text/x-python", "text/plain"));
|
||||||
|
|
||||||
apps = g_app_info_get_all_for_type ("text/x-python");
|
apps = g_app_info_get_all_for_type ("text/x-python");
|
||||||
old_length = g_list_length (apps);
|
old_length = g_list_length (apps);
|
||||||
g_list_free_full (apps, g_object_unref);
|
g_list_free_full (apps, g_object_unref);
|
||||||
|
|
||||||
g_app_info_add_supports_type (info1, "text/x-python", &error);
|
g_app_info_add_supports_type (info1, "text/x-python", &error);
|
||||||
g_assert (error == NULL);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
g_app_info_add_supports_type (info2, "text/plain", &error);
|
g_app_info_add_supports_type (info2, "text/plain", &error);
|
||||||
g_assert (error == NULL);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
/* check that both apps are registered */
|
/* check that both apps are registered */
|
||||||
apps = g_app_info_get_all_for_type ("text/x-python");
|
apps = g_app_info_get_all_for_type ("text/x-python");
|
||||||
@ -183,18 +183,18 @@ test_fallback (void)
|
|||||||
|
|
||||||
/* check that Test1 is among the recommended apps */
|
/* check that Test1 is among the recommended apps */
|
||||||
recomm = g_app_info_get_recommended_for_type ("text/x-python");
|
recomm = g_app_info_get_recommended_for_type ("text/x-python");
|
||||||
g_assert (recomm != NULL);
|
g_assert_nonnull (recomm);
|
||||||
for (l = recomm; l; l = l->next)
|
for (l = recomm; l; l = l->next)
|
||||||
{
|
{
|
||||||
app = l->data;
|
app = l->data;
|
||||||
if (g_app_info_equal (info1, app))
|
if (g_app_info_equal (info1, app))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
g_assert (g_app_info_equal (info1, app));
|
g_assert_true (g_app_info_equal (info1, app));
|
||||||
|
|
||||||
/* and that Test2 is among the fallback apps */
|
/* and that Test2 is among the fallback apps */
|
||||||
fallback = g_app_info_get_fallback_for_type ("text/x-python");
|
fallback = g_app_info_get_fallback_for_type ("text/x-python");
|
||||||
g_assert (fallback != NULL);
|
g_assert_nonnull (fallback);
|
||||||
for (l = fallback; l; l = l->next)
|
for (l = fallback; l; l = l->next)
|
||||||
{
|
{
|
||||||
app = l->data;
|
app = l->data;
|
||||||
@ -205,11 +205,11 @@ test_fallback (void)
|
|||||||
|
|
||||||
/* check that recomm + fallback = all applications */
|
/* check that recomm + fallback = all applications */
|
||||||
list = g_list_concat (g_list_copy (recomm), g_list_copy (fallback));
|
list = g_list_concat (g_list_copy (recomm), g_list_copy (fallback));
|
||||||
g_assert (g_list_length (list) == g_list_length (apps));
|
g_assert_cmpuint (g_list_length (list), ==, g_list_length (apps));
|
||||||
|
|
||||||
for (l = list, m = apps; l != NULL && m != NULL; l = l->next, m = m->next)
|
for (l = list, m = apps; l != NULL && m != NULL; l = l->next, m = m->next)
|
||||||
{
|
{
|
||||||
g_assert (g_app_info_equal (l->data, m->data));
|
g_assert_true (g_app_info_equal (l->data, m->data));
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_free (list);
|
g_list_free (list);
|
||||||
@ -239,32 +239,32 @@ test_last_used (void)
|
|||||||
info2 = create_app_info ("Test2");
|
info2 = create_app_info ("Test2");
|
||||||
|
|
||||||
g_app_info_set_as_default_for_type (info1, "application/x-test", &error);
|
g_app_info_set_as_default_for_type (info1, "application/x-test", &error);
|
||||||
g_assert (error == NULL);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
g_app_info_add_supports_type (info2, "application/x-test", &error);
|
g_app_info_add_supports_type (info2, "application/x-test", &error);
|
||||||
g_assert (error == NULL);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
applications = g_app_info_get_recommended_for_type ("application/x-test");
|
applications = g_app_info_get_recommended_for_type ("application/x-test");
|
||||||
g_assert (g_list_length (applications) == 2);
|
g_assert_cmpuint (g_list_length (applications), ==, 2);
|
||||||
|
|
||||||
/* the first should be the default app now */
|
/* the first should be the default app now */
|
||||||
g_assert (g_app_info_equal (g_list_nth_data (applications, 0), info1));
|
g_assert_true (g_app_info_equal (g_list_nth_data (applications, 0), info1));
|
||||||
g_assert (g_app_info_equal (g_list_nth_data (applications, 1), info2));
|
g_assert_true (g_app_info_equal (g_list_nth_data (applications, 1), info2));
|
||||||
|
|
||||||
g_list_free_full (applications, g_object_unref);
|
g_list_free_full (applications, g_object_unref);
|
||||||
|
|
||||||
g_app_info_set_as_last_used_for_type (info2, "application/x-test", &error);
|
g_app_info_set_as_last_used_for_type (info2, "application/x-test", &error);
|
||||||
g_assert (error == NULL);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
applications = g_app_info_get_recommended_for_type ("application/x-test");
|
applications = g_app_info_get_recommended_for_type ("application/x-test");
|
||||||
g_assert (g_list_length (applications) == 2);
|
g_assert_cmpuint (g_list_length (applications), ==, 2);
|
||||||
|
|
||||||
default_app = g_app_info_get_default_for_type ("application/x-test", FALSE);
|
default_app = g_app_info_get_default_for_type ("application/x-test", FALSE);
|
||||||
g_assert (g_app_info_equal (default_app, info1));
|
g_assert_true (g_app_info_equal (default_app, info1));
|
||||||
|
|
||||||
/* the first should be the other app now */
|
/* the first should be the other app now */
|
||||||
g_assert (g_app_info_equal (g_list_nth_data (applications, 0), info2));
|
g_assert_true (g_app_info_equal (g_list_nth_data (applications, 0), info2));
|
||||||
g_assert (g_app_info_equal (g_list_nth_data (applications, 1), info1));
|
g_assert_true (g_app_info_equal (g_list_nth_data (applications, 1), info1));
|
||||||
|
|
||||||
g_list_free_full (applications, g_object_unref);
|
g_list_free_full (applications, g_object_unref);
|
||||||
|
|
||||||
@ -366,10 +366,10 @@ test_extra_getters (void)
|
|||||||
setlocale (LC_ALL, "");
|
setlocale (LC_ALL, "");
|
||||||
|
|
||||||
appinfo = g_desktop_app_info_new_from_filename (g_test_get_filename (G_TEST_BUILT, "appinfo-test.desktop", NULL));
|
appinfo = g_desktop_app_info_new_from_filename (g_test_get_filename (G_TEST_BUILT, "appinfo-test.desktop", NULL));
|
||||||
g_assert (appinfo != NULL);
|
g_assert_nonnull (appinfo);
|
||||||
|
|
||||||
g_assert (g_desktop_app_info_has_key (appinfo, "Terminal"));
|
g_assert_true (g_desktop_app_info_has_key (appinfo, "Terminal"));
|
||||||
g_assert (!g_desktop_app_info_has_key (appinfo, "Bratwurst"));
|
g_assert_false (g_desktop_app_info_has_key (appinfo, "Bratwurst"));
|
||||||
|
|
||||||
s = g_desktop_app_info_get_string (appinfo, "StartupWMClass");
|
s = g_desktop_app_info_get_string (appinfo, "StartupWMClass");
|
||||||
g_assert_cmpstr (s, ==, "appinfo-class");
|
g_assert_cmpstr (s, ==, "appinfo-class");
|
||||||
@ -387,7 +387,7 @@ test_extra_getters (void)
|
|||||||
g_free (s);
|
g_free (s);
|
||||||
|
|
||||||
b = g_desktop_app_info_get_boolean (appinfo, "Terminal");
|
b = g_desktop_app_info_get_boolean (appinfo, "Terminal");
|
||||||
g_assert (b);
|
g_assert_true (b);
|
||||||
|
|
||||||
g_object_unref (appinfo);
|
g_object_unref (appinfo);
|
||||||
|
|
||||||
@ -400,7 +400,7 @@ wait_for_file (const gchar *want_this,
|
|||||||
const gchar *but_not_this,
|
const gchar *but_not_this,
|
||||||
const gchar *or_this)
|
const gchar *or_this)
|
||||||
{
|
{
|
||||||
gint retries = 600;
|
guint retries = 600;
|
||||||
|
|
||||||
/* I hate time-based conditions in tests, but this will wait up to one
|
/* I hate time-based conditions in tests, but this will wait up to one
|
||||||
* whole minute for "touch file" to finish running. I think it should
|
* whole minute for "touch file" to finish running. I think it should
|
||||||
@ -411,12 +411,12 @@ wait_for_file (const gchar *want_this,
|
|||||||
while (access (want_this, F_OK) != 0)
|
while (access (want_this, F_OK) != 0)
|
||||||
{
|
{
|
||||||
g_usleep (100000); /* 100ms */
|
g_usleep (100000); /* 100ms */
|
||||||
g_assert (retries);
|
g_assert_cmpuint (retries, >, 0);
|
||||||
retries--;
|
retries--;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_assert (access (but_not_this, F_OK) != 0);
|
g_assert_cmpuint (access (but_not_this, F_OK), !=, 0);
|
||||||
g_assert (access (or_this, F_OK) != 0);
|
g_assert_cmpuint (access (or_this, F_OK), !=, 0);
|
||||||
|
|
||||||
unlink (want_this);
|
unlink (want_this);
|
||||||
unlink (but_not_this);
|
unlink (but_not_this);
|
||||||
@ -431,7 +431,7 @@ test_actions (void)
|
|||||||
gchar *name;
|
gchar *name;
|
||||||
|
|
||||||
appinfo = g_desktop_app_info_new_from_filename (g_test_get_filename (G_TEST_DIST, "appinfo-test-actions.desktop", NULL));
|
appinfo = g_desktop_app_info_new_from_filename (g_test_get_filename (G_TEST_DIST, "appinfo-test-actions.desktop", NULL));
|
||||||
g_assert (appinfo != NULL);
|
g_assert_nonnull (appinfo);
|
||||||
|
|
||||||
actions = g_desktop_app_info_list_actions (appinfo);
|
actions = g_desktop_app_info_list_actions (appinfo);
|
||||||
g_assert_cmpstr (actions[0], ==, "frob");
|
g_assert_cmpstr (actions[0], ==, "frob");
|
||||||
@ -453,8 +453,8 @@ test_actions (void)
|
|||||||
g_free (name);
|
g_free (name);
|
||||||
|
|
||||||
name = g_desktop_app_info_get_action_name (appinfo, "broken");
|
name = g_desktop_app_info_get_action_name (appinfo, "broken");
|
||||||
g_assert (name != NULL);
|
g_assert_nonnull (name);
|
||||||
g_assert (g_utf8_validate (name, -1, NULL));
|
g_assert_true (g_utf8_validate (name, -1, NULL));
|
||||||
g_free (name);
|
g_free (name);
|
||||||
|
|
||||||
unlink ("frob"); unlink ("tweak"); unlink ("twiddle");
|
unlink ("frob"); unlink ("tweak"); unlink ("twiddle");
|
||||||
@ -528,8 +528,8 @@ run_apps (const gchar *command,
|
|||||||
envp = g_environ_unsetenv (envp, "XDG_CURRENT_DESKTOP");
|
envp = g_environ_unsetenv (envp, "XDG_CURRENT_DESKTOP");
|
||||||
|
|
||||||
success = g_spawn_sync (NULL, argv, envp, 0, NULL, NULL, &out, NULL, &status, NULL);
|
success = g_spawn_sync (NULL, argv, envp, 0, NULL, NULL, &out, NULL, &status, NULL);
|
||||||
g_assert (success);
|
g_assert_true (success);
|
||||||
g_assert (status == 0);
|
g_assert_cmpuint (status, ==, 0);
|
||||||
|
|
||||||
g_strfreev (envp);
|
g_strfreev (envp);
|
||||||
g_strfreev (argv);
|
g_strfreev (argv);
|
||||||
|
Loading…
Reference in New Issue
Block a user