2010-07-03 18:49:46 +02:00
|
|
|
|
|
|
|
#include <locale.h>
|
2013-05-20 22:33:00 +02:00
|
|
|
#include <string.h>
|
2010-07-03 18:49:46 +02:00
|
|
|
|
2017-02-24 10:46:36 +01:00
|
|
|
#include <glib/gstdio.h>
|
2010-06-07 19:25:39 +02:00
|
|
|
#include <gio/gio.h>
|
|
|
|
#include <gio/gdesktopappinfo.h>
|
|
|
|
|
|
|
|
static void
|
2017-12-07 23:10:58 +01:00
|
|
|
test_launch_for_app_info (GAppInfo *appinfo)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-07-05 09:09:36 +02:00
|
|
|
GError *error;
|
2012-08-19 08:23:32 +02:00
|
|
|
GFile *file;
|
|
|
|
GList *l;
|
2013-05-29 00:03:17 +02:00
|
|
|
const gchar *path;
|
|
|
|
gchar *uri;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2013-11-24 04:24:00 +01:00
|
|
|
if (g_getenv ("DISPLAY") == NULL || g_getenv ("DISPLAY")[0] == '\0')
|
Rework the build system for a new tests approach
Perform a substantial cleanup of the build system with respect to
building and installing testcases.
First, Makefile.decl has been renamed glib.mk and substantially
expanded. We intend to add more stuff here in the future, like canned
rules for mkenums, marshallers, resources, etc.
By default, tests are no longer compiled as part of 'make'. They will
be built when 'make check' is run. The old behaviour can be obtained
with --enable-always-build-tests.
--disable-modular-tests is gone (because tests are no longer built by
default). There is no longer any way to cause 'make check' to be a
no-op, but that's not very useful anyway.
A new glibtests.m4 file is introduced. Along with glib.mk, this
provides for consistent handling of --enable-installed-tests and
--enable-always-build-tests (mentioned above).
Port our various test-installing Makefiles to the new framework.
This patch substantially improves the situation in the toplevel tests/
directory. Things are now somewhat under control there. There were
some tests being built that weren't even being run and we run those now.
The long-running GObject performance tests in this directory have been
removed from 'make check' because they take too long.
As an experiment, 'make check' now runs the testcases on win32 builds,
by default. We can't run them under gtester (since it uses a pipe to
communicate with the subprocess) so just toss them in TESTS. Most of
them are passing on win32.
Things are not quite done here, but this patch is already a substantial
improvement. More to come.
2013-05-30 06:07:32 +02:00
|
|
|
{
|
2018-07-11 15:58:48 +02:00
|
|
|
g_test_skip ("No DISPLAY set");
|
Rework the build system for a new tests approach
Perform a substantial cleanup of the build system with respect to
building and installing testcases.
First, Makefile.decl has been renamed glib.mk and substantially
expanded. We intend to add more stuff here in the future, like canned
rules for mkenums, marshallers, resources, etc.
By default, tests are no longer compiled as part of 'make'. They will
be built when 'make check' is run. The old behaviour can be obtained
with --enable-always-build-tests.
--disable-modular-tests is gone (because tests are no longer built by
default). There is no longer any way to cause 'make check' to be a
no-op, but that's not very useful anyway.
A new glibtests.m4 file is introduced. Along with glib.mk, this
provides for consistent handling of --enable-installed-tests and
--enable-always-build-tests (mentioned above).
Port our various test-installing Makefiles to the new framework.
This patch substantially improves the situation in the toplevel tests/
directory. Things are now somewhat under control there. There were
some tests being built that weren't even being run and we run those now.
The long-running GObject performance tests in this directory have been
removed from 'make check' because they take too long.
As an experiment, 'make check' now runs the testcases on win32 builds,
by default. We can't run them under gtester (since it uses a pipe to
communicate with the subprocess) so just toss them in TESTS. Most of
them are passing on win32.
Things are not quite done here, but this patch is already a substantial
improvement. More to come.
2013-05-30 06:07:32 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-05 09:09:36 +02:00
|
|
|
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);
|
2012-08-19 08:23:32 +02:00
|
|
|
|
2017-12-07 23:10:58 +01:00
|
|
|
path = g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL);
|
2013-05-20 14:46:21 +02:00
|
|
|
file = g_file_new_for_path (path);
|
2012-08-19 08:23:32 +02:00
|
|
|
l = NULL;
|
|
|
|
l = g_list_append (l, file);
|
|
|
|
|
|
|
|
g_assert (g_app_info_launch (appinfo, l, NULL, &error));
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_list_free (l);
|
|
|
|
g_object_unref (file);
|
|
|
|
|
|
|
|
l = NULL;
|
2013-05-29 14:49:16 +02:00
|
|
|
uri = g_strconcat ("file://", g_test_get_dir (G_TEST_DIST), "/appinfo-test.desktop", NULL);
|
2013-05-29 00:03:17 +02:00
|
|
|
l = g_list_append (l, uri);
|
2012-08-19 08:23:32 +02:00
|
|
|
l = g_list_append (l, "file:///etc/group#adm");
|
|
|
|
|
|
|
|
g_assert (g_app_info_launch_uris (appinfo, l, NULL, &error));
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_list_free (l);
|
2013-05-29 00:03:17 +02:00
|
|
|
g_free (uri);
|
2017-12-07 23:10:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_launch (void)
|
|
|
|
{
|
|
|
|
GAppInfo *appinfo;
|
|
|
|
const gchar *path;
|
2012-08-25 02:43:54 +02:00
|
|
|
|
2017-12-07 23:10:58 +01:00
|
|
|
path = g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL);
|
|
|
|
appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
|
|
|
|
g_assert (appinfo != NULL);
|
|
|
|
|
|
|
|
test_launch_for_app_info (appinfo);
|
2012-08-25 02:43:54 +02:00
|
|
|
g_object_unref (appinfo);
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
2017-12-07 23:10:58 +01:00
|
|
|
static void
|
|
|
|
test_launch_no_app_id (void)
|
|
|
|
{
|
|
|
|
const gchar desktop_file_base_contents[] =
|
|
|
|
"[Desktop Entry]\n"
|
|
|
|
"Type=Application\n"
|
|
|
|
"GenericName=generic-appinfo-test\n"
|
|
|
|
"Name=appinfo-test\n"
|
|
|
|
"Name[de]=appinfo-test-de\n"
|
|
|
|
"X-GNOME-FullName=example\n"
|
|
|
|
"X-GNOME-FullName[de]=Beispiel\n"
|
|
|
|
"Comment=GAppInfo example\n"
|
|
|
|
"Comment[de]=GAppInfo Beispiel\n"
|
|
|
|
"Icon=testicon.svg\n"
|
|
|
|
"Terminal=true\n"
|
|
|
|
"StartupNotify=true\n"
|
|
|
|
"StartupWMClass=appinfo-class\n"
|
|
|
|
"MimeType=image/png;image/jpeg;\n"
|
|
|
|
"Keywords=keyword1;test keyword;\n"
|
|
|
|
"Categories=GNOME;GTK;\n";
|
|
|
|
|
|
|
|
const char *exec_line_variants[] = {
|
|
|
|
"Exec=./appinfo-test --option %U %i --name %c --filename %k %m %%",
|
|
|
|
"Exec=./appinfo-test --option %u %i --name %c --filename %k %m %%"
|
|
|
|
};
|
|
|
|
|
|
|
|
gsize i;
|
|
|
|
|
|
|
|
g_test_bug ("791337");
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (exec_line_variants); i++)
|
|
|
|
{
|
|
|
|
gchar *desktop_file_contents;
|
|
|
|
GKeyFile *fake_desktop_file;
|
|
|
|
GAppInfo *appinfo;
|
|
|
|
gboolean loaded;
|
|
|
|
|
|
|
|
g_test_message ("Exec line variant #%" G_GSIZE_FORMAT, i);
|
|
|
|
|
|
|
|
desktop_file_contents = g_strdup_printf ("%s\n%s",
|
|
|
|
desktop_file_base_contents,
|
|
|
|
exec_line_variants[i]);
|
|
|
|
|
|
|
|
/* We load a desktop file from memory to force the app not
|
|
|
|
* to have an app ID, which would check different codepaths.
|
|
|
|
*/
|
|
|
|
fake_desktop_file = g_key_file_new ();
|
|
|
|
loaded = g_key_file_load_from_data (fake_desktop_file, desktop_file_contents, -1, G_KEY_FILE_NONE, NULL);
|
|
|
|
g_assert_true (loaded);
|
|
|
|
|
|
|
|
appinfo = (GAppInfo*)g_desktop_app_info_new_from_keyfile (fake_desktop_file);
|
|
|
|
g_assert (appinfo != NULL);
|
|
|
|
|
|
|
|
test_launch_for_app_info (appinfo);
|
|
|
|
|
|
|
|
g_free (desktop_file_contents);
|
|
|
|
g_object_unref (appinfo);
|
|
|
|
g_key_file_unref (fake_desktop_file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-03 18:49:46 +02:00
|
|
|
static void
|
|
|
|
test_locale (const char *locale)
|
|
|
|
{
|
|
|
|
GAppInfo *appinfo;
|
2018-06-27 10:54:06 +02:00
|
|
|
gchar *orig = NULL;
|
2013-05-29 00:03:17 +02:00
|
|
|
const gchar *path;
|
2010-07-03 18:49:46 +02:00
|
|
|
|
2018-06-27 10:54:06 +02:00
|
|
|
orig = g_strdup (setlocale (LC_ALL, NULL));
|
2010-07-03 18:49:46 +02:00
|
|
|
g_setenv ("LANGUAGE", locale, TRUE);
|
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
|
2013-05-29 14:49:16 +02:00
|
|
|
path = g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL);
|
2013-05-20 14:46:21 +02:00
|
|
|
appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
|
2010-07-03 18:49:46 +02:00
|
|
|
|
|
|
|
if (g_strcmp0 (locale, "C") == 0)
|
|
|
|
{
|
|
|
|
g_assert_cmpstr (g_app_info_get_name (appinfo), ==, "appinfo-test");
|
|
|
|
g_assert_cmpstr (g_app_info_get_description (appinfo), ==, "GAppInfo example");
|
|
|
|
g_assert_cmpstr (g_app_info_get_display_name (appinfo), ==, "example");
|
|
|
|
}
|
|
|
|
else if (g_str_has_prefix (locale, "en"))
|
|
|
|
{
|
|
|
|
g_assert_cmpstr (g_app_info_get_name (appinfo), ==, "appinfo-test");
|
|
|
|
g_assert_cmpstr (g_app_info_get_description (appinfo), ==, "GAppInfo example");
|
|
|
|
g_assert_cmpstr (g_app_info_get_display_name (appinfo), ==, "example");
|
|
|
|
}
|
|
|
|
else if (g_str_has_prefix (locale, "de"))
|
|
|
|
{
|
|
|
|
g_assert_cmpstr (g_app_info_get_name (appinfo), ==, "appinfo-test-de");
|
|
|
|
g_assert_cmpstr (g_app_info_get_description (appinfo), ==, "GAppInfo Beispiel");
|
|
|
|
g_assert_cmpstr (g_app_info_get_display_name (appinfo), ==, "Beispiel");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (appinfo);
|
|
|
|
|
|
|
|
g_setenv ("LANGUAGE", orig, TRUE);
|
|
|
|
setlocale (LC_ALL, "");
|
2018-06-27 10:54:06 +02:00
|
|
|
g_free (orig);
|
2010-07-03 18:49:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_text (void)
|
|
|
|
{
|
|
|
|
test_locale ("C");
|
|
|
|
test_locale ("en_US");
|
|
|
|
test_locale ("de");
|
|
|
|
test_locale ("de_DE.UTF-8");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_basic (void)
|
|
|
|
{
|
|
|
|
GAppInfo *appinfo;
|
2010-07-05 09:09:36 +02:00
|
|
|
GAppInfo *appinfo2;
|
2010-07-03 18:49:46 +02:00
|
|
|
GIcon *icon, *icon2;
|
2013-05-29 00:03:17 +02:00
|
|
|
const gchar *path;
|
2010-07-03 18:49:46 +02:00
|
|
|
|
2013-05-29 14:49:16 +02:00
|
|
|
path = g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL);
|
2013-05-20 14:46:21 +02:00
|
|
|
appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
|
2010-07-03 18:49:46 +02:00
|
|
|
|
2013-04-22 19:12:12 +02:00
|
|
|
g_assert_cmpstr (g_app_info_get_id (appinfo), ==, "appinfo-test.desktop");
|
2013-05-20 22:33:00 +02:00
|
|
|
g_assert (strstr (g_app_info_get_executable (appinfo), "appinfo-test") != NULL);
|
2010-07-03 18:49:46 +02:00
|
|
|
|
|
|
|
icon = g_app_info_get_icon (appinfo);
|
|
|
|
g_assert (G_IS_THEMED_ICON (icon));
|
|
|
|
icon2 = g_themed_icon_new ("testicon");
|
|
|
|
g_assert (g_icon_equal (icon, icon2));
|
|
|
|
g_object_unref (icon2);
|
|
|
|
|
2010-07-05 09:09:36 +02:00
|
|
|
appinfo2 = g_app_info_dup (appinfo);
|
2013-04-22 19:12:12 +02:00
|
|
|
g_assert_cmpstr (g_app_info_get_id (appinfo), ==, g_app_info_get_id (appinfo2));
|
2010-07-05 09:09:36 +02:00
|
|
|
g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, g_app_info_get_commandline (appinfo2));
|
|
|
|
|
2010-07-03 18:49:46 +02:00
|
|
|
g_object_unref (appinfo);
|
2010-07-05 09:09:36 +02:00
|
|
|
g_object_unref (appinfo2);
|
2010-07-03 18:49:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_show_in (void)
|
|
|
|
{
|
|
|
|
GAppInfo *appinfo;
|
2013-05-29 00:03:17 +02:00
|
|
|
const gchar *path;
|
2010-07-03 18:49:46 +02:00
|
|
|
|
2013-05-29 14:49:16 +02:00
|
|
|
path = g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL);
|
2013-05-20 14:46:21 +02:00
|
|
|
appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
|
2010-07-03 18:49:46 +02:00
|
|
|
g_assert (g_app_info_should_show (appinfo));
|
|
|
|
g_object_unref (appinfo);
|
|
|
|
|
2013-05-29 14:49:16 +02:00
|
|
|
path = g_test_get_filename (G_TEST_DIST, "appinfo-test-gnome.desktop", NULL);
|
2013-05-20 14:46:21 +02:00
|
|
|
appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
|
2010-07-03 18:49:46 +02:00
|
|
|
g_assert (g_app_info_should_show (appinfo));
|
|
|
|
g_object_unref (appinfo);
|
|
|
|
|
2013-05-29 14:49:16 +02:00
|
|
|
path = g_test_get_filename (G_TEST_DIST, "appinfo-test-notgnome.desktop", NULL);
|
2013-05-20 14:46:21 +02:00
|
|
|
appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
|
2010-07-03 18:49:46 +02:00
|
|
|
g_assert (!g_app_info_should_show (appinfo));
|
|
|
|
g_object_unref (appinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_commandline (void)
|
|
|
|
{
|
|
|
|
GAppInfo *appinfo;
|
|
|
|
GError *error;
|
2013-05-20 14:46:21 +02:00
|
|
|
gchar *cmdline;
|
|
|
|
gchar *cmdline_out;
|
|
|
|
|
2013-05-29 00:03:17 +02:00
|
|
|
cmdline = g_strconcat (g_test_get_dir (G_TEST_BUILT), "/appinfo-test --option", NULL);
|
2013-05-20 14:46:21 +02:00
|
|
|
cmdline_out = g_strconcat (cmdline, " %u", NULL);
|
2010-07-03 18:49:46 +02:00
|
|
|
|
|
|
|
error = NULL;
|
2013-05-20 14:46:21 +02:00
|
|
|
appinfo = g_app_info_create_from_commandline (cmdline,
|
2010-07-03 18:49:46 +02:00
|
|
|
"cmdline-app-test",
|
|
|
|
G_APP_INFO_CREATE_SUPPORTS_URIS,
|
|
|
|
&error);
|
|
|
|
g_assert (appinfo != NULL);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert_cmpstr (g_app_info_get_name (appinfo), ==, "cmdline-app-test");
|
2013-05-20 14:46:21 +02:00
|
|
|
g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, cmdline_out);
|
2010-07-03 18:49:46 +02:00
|
|
|
g_assert (g_app_info_supports_uris (appinfo));
|
|
|
|
g_assert (!g_app_info_supports_files (appinfo));
|
|
|
|
|
|
|
|
g_object_unref (appinfo);
|
|
|
|
|
2013-05-20 14:46:21 +02:00
|
|
|
g_free (cmdline_out);
|
|
|
|
cmdline_out = g_strconcat (cmdline, " %f", NULL);
|
|
|
|
|
2010-07-03 18:49:46 +02:00
|
|
|
error = NULL;
|
2013-05-20 14:46:21 +02:00
|
|
|
appinfo = g_app_info_create_from_commandline (cmdline,
|
2010-07-03 18:49:46 +02:00
|
|
|
"cmdline-app-test",
|
|
|
|
G_APP_INFO_CREATE_NONE,
|
|
|
|
&error);
|
|
|
|
g_assert (appinfo != NULL);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert_cmpstr (g_app_info_get_name (appinfo), ==, "cmdline-app-test");
|
2013-05-20 14:46:21 +02:00
|
|
|
g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, cmdline_out);
|
2010-07-03 18:49:46 +02:00
|
|
|
g_assert (!g_app_info_supports_uris (appinfo));
|
|
|
|
g_assert (g_app_info_supports_files (appinfo));
|
|
|
|
|
|
|
|
g_object_unref (appinfo);
|
2013-05-20 14:46:21 +02:00
|
|
|
|
|
|
|
g_free (cmdline);
|
|
|
|
g_free (cmdline_out);
|
2010-07-03 18:49:46 +02:00
|
|
|
}
|
|
|
|
|
2010-07-05 05:41:40 +02:00
|
|
|
static void
|
|
|
|
test_launch_context (void)
|
|
|
|
{
|
|
|
|
GAppLaunchContext *context;
|
|
|
|
GAppInfo *appinfo;
|
|
|
|
gchar *str;
|
2013-05-20 14:46:21 +02:00
|
|
|
gchar *cmdline;
|
|
|
|
|
2013-05-29 00:03:17 +02:00
|
|
|
cmdline = g_strconcat (g_test_get_dir (G_TEST_BUILT), "/appinfo-test --option", NULL);
|
2010-07-05 05:41:40 +02:00
|
|
|
|
|
|
|
context = g_app_launch_context_new ();
|
2013-05-20 14:46:21 +02:00
|
|
|
appinfo = g_app_info_create_from_commandline (cmdline,
|
2010-07-05 05:41:40 +02:00
|
|
|
"cmdline-app-test",
|
|
|
|
G_APP_INFO_CREATE_SUPPORTS_URIS,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
str = g_app_launch_context_get_display (context, appinfo, NULL);
|
|
|
|
g_assert (str == NULL);
|
|
|
|
|
|
|
|
str = g_app_launch_context_get_startup_notify_id (context, appinfo, NULL);
|
|
|
|
g_assert (str == NULL);
|
|
|
|
|
|
|
|
g_object_unref (appinfo);
|
|
|
|
g_object_unref (context);
|
2013-05-20 14:46:21 +02:00
|
|
|
|
|
|
|
g_free (cmdline);
|
2010-07-05 05:41:40 +02:00
|
|
|
}
|
|
|
|
|
2012-11-21 23:39:19 +01:00
|
|
|
static gboolean launched_reached;
|
|
|
|
|
|
|
|
static void
|
|
|
|
launched (GAppLaunchContext *context,
|
|
|
|
GAppInfo *info,
|
|
|
|
GVariant *platform_data,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
gint pid;
|
|
|
|
|
|
|
|
pid = 0;
|
|
|
|
g_assert (g_variant_lookup (platform_data, "pid", "i", &pid));
|
|
|
|
g_assert (pid != 0);
|
|
|
|
|
|
|
|
launched_reached = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
launch_failed (GAppLaunchContext *context,
|
|
|
|
const gchar *startup_notify_id)
|
|
|
|
{
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_launch_context_signals (void)
|
|
|
|
{
|
|
|
|
GAppLaunchContext *context;
|
|
|
|
GAppInfo *appinfo;
|
|
|
|
GError *error = NULL;
|
2013-05-20 14:46:21 +02:00
|
|
|
gchar *cmdline;
|
|
|
|
|
2013-05-29 00:03:17 +02:00
|
|
|
cmdline = g_strconcat (g_test_get_dir (G_TEST_BUILT), "/appinfo-test --option", NULL);
|
2012-11-21 23:39:19 +01:00
|
|
|
|
|
|
|
context = g_app_launch_context_new ();
|
|
|
|
g_signal_connect (context, "launched", G_CALLBACK (launched), NULL);
|
|
|
|
g_signal_connect (context, "launch_failed", G_CALLBACK (launch_failed), NULL);
|
2013-05-20 14:46:21 +02:00
|
|
|
appinfo = g_app_info_create_from_commandline (cmdline,
|
2012-11-21 23:39:19 +01:00
|
|
|
"cmdline-app-test",
|
|
|
|
G_APP_INFO_CREATE_SUPPORTS_URIS,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
g_assert (g_app_info_launch (appinfo, NULL, context, &error));
|
|
|
|
g_assert_no_error (error);
|
|
|
|
|
|
|
|
g_assert (launched_reached);
|
|
|
|
|
|
|
|
g_object_unref (appinfo);
|
|
|
|
g_object_unref (context);
|
2013-05-20 14:46:21 +02:00
|
|
|
|
|
|
|
g_free (cmdline);
|
2012-11-21 23:39:19 +01:00
|
|
|
}
|
|
|
|
|
2010-07-05 09:09:36 +02:00
|
|
|
static void
|
|
|
|
test_tryexec (void)
|
|
|
|
{
|
|
|
|
GAppInfo *appinfo;
|
2013-05-29 00:03:17 +02:00
|
|
|
const gchar *path;
|
2010-07-05 09:09:36 +02:00
|
|
|
|
2013-05-29 14:49:16 +02:00
|
|
|
path = g_test_get_filename (G_TEST_DIST, "appinfo-test2.desktop", NULL);
|
2013-05-20 14:46:21 +02:00
|
|
|
appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
|
2010-07-05 09:09:36 +02:00
|
|
|
|
|
|
|
g_assert (appinfo == NULL);
|
|
|
|
}
|
|
|
|
|
2010-07-28 22:59:11 +02:00
|
|
|
/* Test that we can set an appinfo as default for a mime type or
|
|
|
|
* file extension, and also add and remove handled mime types.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
test_associations (void)
|
|
|
|
{
|
|
|
|
GAppInfo *appinfo;
|
|
|
|
GAppInfo *appinfo2;
|
|
|
|
GError *error;
|
|
|
|
gboolean result;
|
|
|
|
GList *list;
|
2013-05-20 14:46:21 +02:00
|
|
|
gchar *cmdline;
|
2010-07-28 22:59:11 +02:00
|
|
|
|
2013-05-29 00:03:17 +02:00
|
|
|
cmdline = g_strconcat (g_test_get_dir (G_TEST_BUILT), "/appinfo-test --option", NULL);
|
2013-05-20 14:46:21 +02:00
|
|
|
appinfo = g_app_info_create_from_commandline (cmdline,
|
2010-07-28 22:59:11 +02:00
|
|
|
"cmdline-app-test",
|
|
|
|
G_APP_INFO_CREATE_SUPPORTS_URIS,
|
|
|
|
NULL);
|
2018-06-27 10:57:21 +02:00
|
|
|
g_free (cmdline);
|
2010-07-28 22:59:11 +02:00
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
result = g_app_info_set_as_default_for_type (appinfo, "application/x-glib-test", &error);
|
|
|
|
|
|
|
|
g_assert (result);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
|
|
|
|
appinfo2 = g_app_info_get_default_for_type ("application/x-glib-test", FALSE);
|
|
|
|
|
|
|
|
g_assert (appinfo2);
|
|
|
|
g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, g_app_info_get_commandline (appinfo2));
|
|
|
|
|
|
|
|
g_object_unref (appinfo2);
|
|
|
|
|
|
|
|
result = g_app_info_set_as_default_for_extension (appinfo, "gio-tests", &error);
|
|
|
|
g_assert (result);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
|
|
|
|
appinfo2 = g_app_info_get_default_for_type ("application/x-extension-gio-tests", FALSE);
|
|
|
|
|
|
|
|
g_assert (appinfo2);
|
|
|
|
g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, g_app_info_get_commandline (appinfo2));
|
|
|
|
|
|
|
|
g_object_unref (appinfo2);
|
|
|
|
|
|
|
|
result = g_app_info_add_supports_type (appinfo, "application/x-gio-test", &error);
|
|
|
|
g_assert (result);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
|
|
|
|
list = g_app_info_get_all_for_type ("application/x-gio-test");
|
|
|
|
g_assert_cmpint (g_list_length (list), ==, 1);
|
|
|
|
appinfo2 = list->data;
|
|
|
|
g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, g_app_info_get_commandline (appinfo2));
|
|
|
|
g_object_unref (appinfo2);
|
|
|
|
g_list_free (list);
|
|
|
|
|
|
|
|
g_assert (g_app_info_can_remove_supports_type (appinfo));
|
|
|
|
g_assert (g_app_info_remove_supports_type (appinfo, "application/x-gio-test", &error));
|
|
|
|
g_assert_no_error (error);
|
|
|
|
|
|
|
|
g_assert (g_app_info_can_delete (appinfo));
|
|
|
|
g_assert (g_app_info_delete (appinfo));
|
|
|
|
g_object_unref (appinfo);
|
|
|
|
}
|
|
|
|
|
2011-10-16 06:08:42 +02:00
|
|
|
static void
|
|
|
|
test_environment (void)
|
|
|
|
{
|
|
|
|
GAppLaunchContext *ctx;
|
|
|
|
gchar **env;
|
2012-06-03 22:30:58 +02:00
|
|
|
const gchar *path;
|
|
|
|
|
|
|
|
g_unsetenv ("FOO");
|
|
|
|
g_unsetenv ("BLA");
|
|
|
|
path = g_getenv ("PATH");
|
2011-10-16 06:08:42 +02:00
|
|
|
|
|
|
|
ctx = g_app_launch_context_new ();
|
2012-06-03 22:30:58 +02:00
|
|
|
|
|
|
|
env = g_app_launch_context_get_environment (ctx);
|
|
|
|
|
|
|
|
g_assert (g_environ_getenv (env, "FOO") == NULL);
|
2013-03-07 02:32:14 +01:00
|
|
|
g_assert (g_environ_getenv (env, "BLA") == NULL);
|
2012-06-03 22:30:58 +02:00
|
|
|
g_assert_cmpstr (g_environ_getenv (env, "PATH"), ==, path);
|
|
|
|
|
|
|
|
g_strfreev (env);
|
|
|
|
|
2011-10-16 06:08:42 +02:00
|
|
|
g_app_launch_context_setenv (ctx, "FOO", "bar");
|
|
|
|
g_app_launch_context_setenv (ctx, "BLA", "bla");
|
|
|
|
|
|
|
|
env = g_app_launch_context_get_environment (ctx);
|
|
|
|
|
|
|
|
g_assert_cmpstr (g_environ_getenv (env, "FOO"), ==, "bar");
|
|
|
|
g_assert_cmpstr (g_environ_getenv (env, "BLA"), ==, "bla");
|
2012-06-03 22:30:58 +02:00
|
|
|
g_assert_cmpstr (g_environ_getenv (env, "PATH"), ==, path);
|
2011-10-16 06:08:42 +02:00
|
|
|
|
|
|
|
g_strfreev (env);
|
|
|
|
|
|
|
|
g_app_launch_context_setenv (ctx, "FOO", "baz");
|
|
|
|
g_app_launch_context_unsetenv (ctx, "BLA");
|
|
|
|
|
|
|
|
env = g_app_launch_context_get_environment (ctx);
|
|
|
|
|
|
|
|
g_assert_cmpstr (g_environ_getenv (env, "FOO"), ==, "baz");
|
|
|
|
g_assert (g_environ_getenv (env, "BLA") == NULL);
|
|
|
|
|
|
|
|
g_strfreev (env);
|
|
|
|
|
|
|
|
g_object_unref (ctx);
|
|
|
|
}
|
|
|
|
|
2012-04-05 23:26:12 +02:00
|
|
|
static void
|
|
|
|
test_startup_wm_class (void)
|
|
|
|
{
|
|
|
|
GDesktopAppInfo *appinfo;
|
|
|
|
const char *wm_class;
|
2013-05-29 00:03:17 +02:00
|
|
|
const gchar *path;
|
2012-04-05 23:26:12 +02:00
|
|
|
|
2013-05-29 14:49:16 +02:00
|
|
|
path = g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL);
|
2013-05-20 14:46:21 +02:00
|
|
|
appinfo = g_desktop_app_info_new_from_filename (path);
|
2012-04-05 23:26:12 +02:00
|
|
|
wm_class = g_desktop_app_info_get_startup_wm_class (appinfo);
|
|
|
|
|
|
|
|
g_assert_cmpstr (wm_class, ==, "appinfo-class");
|
|
|
|
|
|
|
|
g_object_unref (appinfo);
|
|
|
|
}
|
|
|
|
|
2012-04-14 19:34:00 +02:00
|
|
|
static void
|
|
|
|
test_supported_types (void)
|
|
|
|
{
|
|
|
|
GAppInfo *appinfo;
|
|
|
|
const char * const *content_types;
|
2013-05-29 00:03:17 +02:00
|
|
|
const gchar *path;
|
2012-04-14 19:34:00 +02:00
|
|
|
|
2013-05-29 14:49:16 +02:00
|
|
|
path = g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL);
|
2013-05-20 14:46:21 +02:00
|
|
|
appinfo = G_APP_INFO (g_desktop_app_info_new_from_filename (path));
|
2012-04-14 19:34:00 +02:00
|
|
|
content_types = g_app_info_get_supported_types (appinfo);
|
|
|
|
|
|
|
|
g_assert_cmpint (g_strv_length ((char**)content_types), ==, 2);
|
|
|
|
g_assert_cmpstr (content_types[0], ==, "image/png");
|
|
|
|
|
|
|
|
g_object_unref (appinfo);
|
|
|
|
}
|
|
|
|
|
2012-08-19 08:23:32 +02:00
|
|
|
static void
|
|
|
|
test_from_keyfile (void)
|
|
|
|
{
|
|
|
|
GDesktopAppInfo *info;
|
|
|
|
GKeyFile *kf;
|
|
|
|
GError *error = NULL;
|
|
|
|
const gchar *categories;
|
gdesktopappinfo: add get_string_list() function
The X-Flatpak-RenamedFrom key is used in .desktop files to identify past
names for the desktop file. It is defined to be a list of strings.
However, there was previously no correct way to retrieve a list of
strings from the GKeyFile wrapped by GDesktopAppInfo, short of
re-parsing the file with GKeyFile.
Note that doing something like:
g_strsplit (g_desktop_app_info_get_string (...), ";", -1)
is not correct: the raw value "a\;b;" represents the one-element list
["a;b"], but g_key_file_get_string() rejects the sequence "\;", and so
g_desktop_app_info_get_string() returns NULL in this case. (Of course, a
.desktop file with a semicolon in its name is a pathological case.)
Add g_desktop_app_info_get_string_list(), a trivial wrapper around
g_key_file_get_string_list(), similar to g_desktop_app_info_get_string()
and co.
The change from g_key_file_free() to g_key_file_unref() in the test is
needed because g_key_file_free() clears the contents of the keyfile.
This is fine for all the fields which are eagerly loaded and copied into
GDesktopAppInfo, but not when we want to access arbitrary stuff from the
keyfile.
2018-09-20 17:26:55 +02:00
|
|
|
gchar **categories_list;
|
|
|
|
gsize categories_count;
|
2012-08-19 08:23:32 +02:00
|
|
|
gchar **keywords;
|
|
|
|
const gchar *file;
|
|
|
|
const gchar *name;
|
2013-05-29 00:03:17 +02:00
|
|
|
const gchar *path;
|
2012-08-19 08:23:32 +02:00
|
|
|
|
2013-05-29 14:49:16 +02:00
|
|
|
path = g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL);
|
2012-08-19 08:23:32 +02:00
|
|
|
kf = g_key_file_new ();
|
2013-05-20 14:46:21 +02:00
|
|
|
g_key_file_load_from_file (kf, path, G_KEY_FILE_NONE, &error);
|
2012-08-19 08:23:32 +02:00
|
|
|
g_assert_no_error (error);
|
|
|
|
info = g_desktop_app_info_new_from_keyfile (kf);
|
gdesktopappinfo: add get_string_list() function
The X-Flatpak-RenamedFrom key is used in .desktop files to identify past
names for the desktop file. It is defined to be a list of strings.
However, there was previously no correct way to retrieve a list of
strings from the GKeyFile wrapped by GDesktopAppInfo, short of
re-parsing the file with GKeyFile.
Note that doing something like:
g_strsplit (g_desktop_app_info_get_string (...), ";", -1)
is not correct: the raw value "a\;b;" represents the one-element list
["a;b"], but g_key_file_get_string() rejects the sequence "\;", and so
g_desktop_app_info_get_string() returns NULL in this case. (Of course, a
.desktop file with a semicolon in its name is a pathological case.)
Add g_desktop_app_info_get_string_list(), a trivial wrapper around
g_key_file_get_string_list(), similar to g_desktop_app_info_get_string()
and co.
The change from g_key_file_free() to g_key_file_unref() in the test is
needed because g_key_file_free() clears the contents of the keyfile.
This is fine for all the fields which are eagerly loaded and copied into
GDesktopAppInfo, but not when we want to access arbitrary stuff from the
keyfile.
2018-09-20 17:26:55 +02:00
|
|
|
g_key_file_unref (kf);
|
2012-08-19 08:23:32 +02:00
|
|
|
g_assert (info != NULL);
|
|
|
|
|
|
|
|
g_object_get (info, "filename", &file, NULL);
|
|
|
|
g_assert (file == NULL);
|
|
|
|
|
|
|
|
file = g_desktop_app_info_get_filename (info);
|
|
|
|
g_assert (file == NULL);
|
|
|
|
categories = g_desktop_app_info_get_categories (info);
|
|
|
|
g_assert_cmpstr (categories, ==, "GNOME;GTK;");
|
gdesktopappinfo: add get_string_list() function
The X-Flatpak-RenamedFrom key is used in .desktop files to identify past
names for the desktop file. It is defined to be a list of strings.
However, there was previously no correct way to retrieve a list of
strings from the GKeyFile wrapped by GDesktopAppInfo, short of
re-parsing the file with GKeyFile.
Note that doing something like:
g_strsplit (g_desktop_app_info_get_string (...), ";", -1)
is not correct: the raw value "a\;b;" represents the one-element list
["a;b"], but g_key_file_get_string() rejects the sequence "\;", and so
g_desktop_app_info_get_string() returns NULL in this case. (Of course, a
.desktop file with a semicolon in its name is a pathological case.)
Add g_desktop_app_info_get_string_list(), a trivial wrapper around
g_key_file_get_string_list(), similar to g_desktop_app_info_get_string()
and co.
The change from g_key_file_free() to g_key_file_unref() in the test is
needed because g_key_file_free() clears the contents of the keyfile.
This is fine for all the fields which are eagerly loaded and copied into
GDesktopAppInfo, but not when we want to access arbitrary stuff from the
keyfile.
2018-09-20 17:26:55 +02:00
|
|
|
categories_list = g_desktop_app_info_get_string_list (info, "Categories", &categories_count);
|
|
|
|
g_assert_cmpint (categories_count, ==, 2);
|
|
|
|
g_assert_cmpint (g_strv_length (categories_list), ==, 2);
|
|
|
|
g_assert_cmpstr (categories_list[0], ==, "GNOME");
|
|
|
|
g_assert_cmpstr (categories_list[1], ==, "GTK");
|
2012-08-19 08:23:32 +02:00
|
|
|
keywords = (gchar **)g_desktop_app_info_get_keywords (info);
|
|
|
|
g_assert_cmpint (g_strv_length (keywords), ==, 2);
|
|
|
|
g_assert_cmpstr (keywords[0], ==, "keyword1");
|
|
|
|
g_assert_cmpstr (keywords[1], ==, "test keyword");
|
|
|
|
name = g_desktop_app_info_get_generic_name (info);
|
|
|
|
g_assert_cmpstr (name, ==, "generic-appinfo-test");
|
|
|
|
g_assert (!g_desktop_app_info_get_nodisplay (info));
|
|
|
|
|
gdesktopappinfo: add get_string_list() function
The X-Flatpak-RenamedFrom key is used in .desktop files to identify past
names for the desktop file. It is defined to be a list of strings.
However, there was previously no correct way to retrieve a list of
strings from the GKeyFile wrapped by GDesktopAppInfo, short of
re-parsing the file with GKeyFile.
Note that doing something like:
g_strsplit (g_desktop_app_info_get_string (...), ";", -1)
is not correct: the raw value "a\;b;" represents the one-element list
["a;b"], but g_key_file_get_string() rejects the sequence "\;", and so
g_desktop_app_info_get_string() returns NULL in this case. (Of course, a
.desktop file with a semicolon in its name is a pathological case.)
Add g_desktop_app_info_get_string_list(), a trivial wrapper around
g_key_file_get_string_list(), similar to g_desktop_app_info_get_string()
and co.
The change from g_key_file_free() to g_key_file_unref() in the test is
needed because g_key_file_free() clears the contents of the keyfile.
This is fine for all the fields which are eagerly loaded and copied into
GDesktopAppInfo, but not when we want to access arbitrary stuff from the
keyfile.
2018-09-20 17:26:55 +02:00
|
|
|
g_strfreev (categories_list);
|
2012-08-19 08:23:32 +02:00
|
|
|
g_object_unref (info);
|
|
|
|
}
|
|
|
|
|
2010-06-07 19:25:39 +02:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2017-02-24 10:46:36 +01:00
|
|
|
const gchar *build_dir;
|
|
|
|
|
2014-05-08 22:16:35 +02:00
|
|
|
g_setenv ("XDG_CURRENT_DESKTOP", "GNOME", TRUE);
|
|
|
|
|
2010-06-07 19:25:39 +02:00
|
|
|
g_test_init (&argc, &argv, NULL);
|
2017-12-07 23:10:58 +01:00
|
|
|
g_test_bug_base ("https://bugzilla.gnome.org/show_bug.cgi?id=");
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2017-02-24 10:46:36 +01:00
|
|
|
/* With Meson build we need to change into right directory, so that the
|
|
|
|
* appinfo-test binary can be found. */
|
|
|
|
build_dir = g_getenv ("G_TEST_BUILDDIR");
|
|
|
|
if (build_dir)
|
|
|
|
g_chdir (build_dir);
|
|
|
|
|
2010-07-03 18:49:46 +02:00
|
|
|
g_test_add_func ("/appinfo/basic", test_basic);
|
|
|
|
g_test_add_func ("/appinfo/text", test_text);
|
2010-06-07 19:25:39 +02:00
|
|
|
g_test_add_func ("/appinfo/launch", test_launch);
|
2017-12-07 23:10:58 +01:00
|
|
|
g_test_add_func ("/appinfo/launch/no-appid", test_launch_no_app_id);
|
2010-07-03 18:49:46 +02:00
|
|
|
g_test_add_func ("/appinfo/show-in", test_show_in);
|
|
|
|
g_test_add_func ("/appinfo/commandline", test_commandline);
|
2010-07-05 05:41:40 +02:00
|
|
|
g_test_add_func ("/appinfo/launch-context", test_launch_context);
|
2012-11-21 23:39:19 +01:00
|
|
|
g_test_add_func ("/appinfo/launch-context-signals", test_launch_context_signals);
|
2010-07-05 09:09:36 +02:00
|
|
|
g_test_add_func ("/appinfo/tryexec", test_tryexec);
|
2010-07-28 22:59:11 +02:00
|
|
|
g_test_add_func ("/appinfo/associations", test_associations);
|
2011-10-16 06:08:42 +02:00
|
|
|
g_test_add_func ("/appinfo/environment", test_environment);
|
2012-04-05 23:26:12 +02:00
|
|
|
g_test_add_func ("/appinfo/startup-wm-class", test_startup_wm_class);
|
2012-04-14 19:34:00 +02:00
|
|
|
g_test_add_func ("/appinfo/supported-types", test_supported_types);
|
2012-08-19 08:23:32 +02:00
|
|
|
g_test_add_func ("/appinfo/from-keyfile", test_from_keyfile);
|
2010-07-05 09:09:36 +02:00
|
|
|
|
2010-06-07 19:25:39 +02:00
|
|
|
return g_test_run ();
|
|
|
|
}
|
|
|
|
|