#include <gio/gio.h>
#include <gio/gdesktopappinfo.h>
-static const gchar *datapath;
-static const gchar *binpath;
-
static void
test_launch (void)
{
GError *error;
GFile *file;
GList *l;
- gchar *path;
+ const gchar *path;
+ gchar *uri;
+
+ if (g_getenv ("DISPLAY") == NULL || g_getenv ("DISPLAY")[0] == '\0')
+ {
+ g_printerr ("No DISPLAY. Skipping test. ");
+ return;
+ }
- path = g_build_filename (datapath, "appinfo-test.desktop", NULL);
+ 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);
- g_free (path);
error = NULL;
g_assert (g_app_info_launch (appinfo, NULL, NULL, &error));
g_assert (g_app_info_launch_uris (appinfo, NULL, NULL, &error));
g_assert_no_error (error);
- path = g_build_filename (datapath, "appinfo-test.desktop", NULL);
file = g_file_new_for_path (path);
- g_free (path);
l = NULL;
l = g_list_append (l, file);
g_object_unref (file);
l = NULL;
- path = g_strconcat ("file://", datapath, "/appinfo-test.desktop", NULL);
- l = g_list_append (l, path);
+ uri = g_strconcat ("file://", g_test_get_dir (G_TEST_DIST), "/appinfo-test.desktop", NULL);
+ l = g_list_append (l, uri);
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);
- g_free (path);
+ g_free (uri);
g_object_unref (appinfo);
}
{
GAppInfo *appinfo;
const gchar *orig;
- gchar *path;
+ const gchar *path;
orig = setlocale (LC_ALL, NULL);
g_setenv ("LANGUAGE", locale, TRUE);
setlocale (LC_ALL, "");
- path = g_build_filename (datapath, "appinfo-test.desktop", NULL);
+ path = g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL);
appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
- g_free (path);
if (g_strcmp0 (locale, "C") == 0)
{
GAppInfo *appinfo;
GAppInfo *appinfo2;
GIcon *icon, *icon2;
- gchar *path;
+ const gchar *path;
- path = g_build_filename (datapath, "appinfo-test.desktop", NULL);
+ path = g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL);
appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
- g_free (path);
g_assert_cmpstr (g_app_info_get_id (appinfo), ==, "appinfo-test.desktop");
g_assert (strstr (g_app_info_get_executable (appinfo), "appinfo-test") != NULL);
test_show_in (void)
{
GAppInfo *appinfo;
- gchar *path;
+ const gchar *path;
g_desktop_app_info_set_desktop_env ("GNOME");
- path = g_build_filename (datapath, "appinfo-test.desktop", NULL);
+ path = g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL);
appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
g_assert (g_app_info_should_show (appinfo));
g_object_unref (appinfo);
- g_free (path);
- path = g_build_filename (datapath, "appinfo-test-gnome.desktop", NULL);
+ path = g_test_get_filename (G_TEST_DIST, "appinfo-test-gnome.desktop", NULL);
appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
g_assert (g_app_info_should_show (appinfo));
g_object_unref (appinfo);
- g_free (path);
- path = g_build_filename (datapath, "appinfo-test-notgnome.desktop", NULL);
+ path = g_test_get_filename (G_TEST_DIST, "appinfo-test-notgnome.desktop", NULL);
appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
g_assert (!g_app_info_should_show (appinfo));
g_object_unref (appinfo);
- g_free (path);
}
static void
gchar *cmdline;
gchar *cmdline_out;
- cmdline = g_strconcat (binpath, "/appinfo-test --option", NULL);
+ cmdline = g_strconcat (g_test_get_dir (G_TEST_BUILT), "/appinfo-test --option", NULL);
cmdline_out = g_strconcat (cmdline, " %u", NULL);
error = NULL;
gchar *str;
gchar *cmdline;
- cmdline = g_strconcat (binpath, "/appinfo-test --option", NULL);
+ cmdline = g_strconcat (g_test_get_dir (G_TEST_BUILT), "/appinfo-test --option", NULL);
context = g_app_launch_context_new ();
appinfo = g_app_info_create_from_commandline (cmdline,
GError *error = NULL;
gchar *cmdline;
- cmdline = g_strconcat (binpath, "/appinfo-test --option", NULL);
+ cmdline = g_strconcat (g_test_get_dir (G_TEST_BUILT), "/appinfo-test --option", NULL);
context = g_app_launch_context_new ();
g_signal_connect (context, "launched", G_CALLBACK (launched), NULL);
test_tryexec (void)
{
GAppInfo *appinfo;
- gchar *path;
+ const gchar *path;
- path = g_build_filename (datapath, "appinfo-test2.desktop", NULL);
+ path = g_test_get_filename (G_TEST_DIST, "appinfo-test2.desktop", NULL);
appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
g_assert (appinfo == NULL);
-
- g_free (path);
}
/* Test that we can set an appinfo as default for a mime type or
GList *list;
gchar *cmdline;
- cmdline = g_strconcat (binpath, "/appinfo-test --option", NULL);
+ cmdline = g_strconcat (g_test_get_dir (G_TEST_BUILT), "/appinfo-test --option", NULL);
appinfo = g_app_info_create_from_commandline (cmdline,
"cmdline-app-test",
G_APP_INFO_CREATE_SUPPORTS_URIS,
{
GDesktopAppInfo *appinfo;
const char *wm_class;
- gchar *path;
+ const gchar *path;
- path = g_build_filename (datapath, "appinfo-test.desktop", NULL);
+ path = g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL);
appinfo = g_desktop_app_info_new_from_filename (path);
wm_class = g_desktop_app_info_get_startup_wm_class (appinfo);
g_assert_cmpstr (wm_class, ==, "appinfo-class");
g_object_unref (appinfo);
- g_free (path);
}
static void
{
GAppInfo *appinfo;
const char * const *content_types;
- gchar *path;
+ const gchar *path;
- path = g_build_filename (datapath, "appinfo-test.desktop", NULL);
+ path = g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL);
appinfo = G_APP_INFO (g_desktop_app_info_new_from_filename (path));
content_types = g_app_info_get_supported_types (appinfo);
g_assert_cmpstr (content_types[0], ==, "image/png");
g_object_unref (appinfo);
- g_free (path);
}
static void
gchar **keywords;
const gchar *file;
const gchar *name;
- gchar *path;
+ const gchar *path;
- path = g_build_filename (datapath, "appinfo-test.desktop", NULL);
+ path = g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL);
kf = g_key_file_new ();
g_key_file_load_from_file (kf, path, G_KEY_FILE_NONE, &error);
g_assert_no_error (error);
info = g_desktop_app_info_new_from_keyfile (kf);
g_key_file_free (kf);
g_assert (info != NULL);
- g_free (path);
g_object_get (info, "filename", &file, NULL);
g_assert (file == NULL);
int
main (int argc, char *argv[])
{
- if (g_getenv ("G_TEST_DATA"))
- datapath = binpath = g_getenv ("G_TEST_DATA");
- else
- {
- datapath = SRCDIR;
- binpath = BUILDDIR;
- }
-
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/appinfo/basic", test_basic);