diff options
Diffstat (limited to 'tests/src/test-gobject-greeter.c')
-rw-r--r-- | tests/src/test-gobject-greeter.c | 86 |
1 files changed, 48 insertions, 38 deletions
diff --git a/tests/src/test-gobject-greeter.c b/tests/src/test-gobject-greeter.c index 6597b92e..4bfd4471 100644 --- a/tests/src/test-gobject-greeter.c +++ b/tests/src/test-gobject-greeter.c @@ -3,11 +3,11 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <xcb/xcb.h> #include <lightdm.h> #include "status.h" +static gchar *greeter_id; static GMainLoop *loop; static LightDMGreeter *greeter; static xcb_connection_t *connection = NULL; @@ -16,39 +16,39 @@ static GKeyFile *config; static void show_message_cb (LightDMGreeter *greeter, const gchar *text, LightDMMessageType type) { - status_notify ("GREETER %s SHOW-MESSAGE TEXT=\"%s\"", getenv ("DISPLAY"), text); + status_notify ("%s SHOW-MESSAGE TEXT=\"%s\"", greeter_id, text); } static void show_prompt_cb (LightDMGreeter *greeter, const gchar *text, LightDMPromptType type) { - status_notify ("GREETER %s SHOW-PROMPT TEXT=\"%s\"", getenv ("DISPLAY"), text); + status_notify ("%s SHOW-PROMPT TEXT=\"%s\"", greeter_id, text); } static void authentication_complete_cb (LightDMGreeter *greeter) { if (lightdm_greeter_get_authentication_user (greeter)) - status_notify ("GREETER %s AUTHENTICATION-COMPLETE USERNAME=%s AUTHENTICATED=%s", - getenv ("DISPLAY"), + status_notify ("%s AUTHENTICATION-COMPLETE USERNAME=%s AUTHENTICATED=%s", + greeter_id, lightdm_greeter_get_authentication_user (greeter), lightdm_greeter_get_is_authenticated (greeter) ? "TRUE" : "FALSE"); else - status_notify ("GREETER %s AUTHENTICATION-COMPLETE AUTHENTICATED=%s", - getenv ("DISPLAY"), + status_notify ("%s AUTHENTICATION-COMPLETE AUTHENTICATED=%s", + greeter_id, lightdm_greeter_get_is_authenticated (greeter) ? "TRUE" : "FALSE"); } static void autologin_timer_expired_cb (LightDMGreeter *greeter) { - status_notify ("GREETER %s AUTOLOGIN-TIMER-EXPIRED", getenv ("DISPLAY")); + status_notify ("%s AUTOLOGIN-TIMER-EXPIRED", greeter_id); } static void signal_cb (int signum) { - status_notify ("GREETER %s TERMINATE SIGNAL=%d", getenv ("DISPLAY"), signum); + status_notify ("%s TERMINATE SIGNAL=%d", greeter_id, signum); exit (EXIT_SUCCESS); } @@ -63,32 +63,32 @@ request_cb (const gchar *request) return; } - r = g_strdup_printf ("GREETER %s AUTHENTICATE", getenv ("DISPLAY")); + r = g_strdup_printf ("%s AUTHENTICATE", greeter_id); if (strcmp (request, r) == 0) lightdm_greeter_authenticate (greeter, NULL); g_free (r); - r = g_strdup_printf ("GREETER %s AUTHENTICATE USERNAME=", getenv ("DISPLAY")); + r = g_strdup_printf ("%s AUTHENTICATE USERNAME=", greeter_id); if (g_str_has_prefix (request, r)) lightdm_greeter_authenticate (greeter, request + strlen (r)); g_free (r); - r = g_strdup_printf ("GREETER %s AUTHENTICATE-GUEST", getenv ("DISPLAY")); + r = g_strdup_printf ("%s AUTHENTICATE-GUEST", greeter_id); if (strcmp (request, r) == 0) lightdm_greeter_authenticate_as_guest (greeter); g_free (r); - r = g_strdup_printf ("GREETER %s AUTHENTICATE-AUTOLOGIN", getenv ("DISPLAY")); + r = g_strdup_printf ("%s AUTHENTICATE-AUTOLOGIN", greeter_id); if (strcmp (request, r) == 0) lightdm_greeter_authenticate_autologin (greeter); g_free (r); - r = g_strdup_printf ("GREETER %s AUTHENTICATE-REMOTE SESSION=", getenv ("DISPLAY")); + r = g_strdup_printf ("%s AUTHENTICATE-REMOTE SESSION=", greeter_id); if (g_str_has_prefix (request, r)) lightdm_greeter_authenticate_remote (greeter, request + strlen (r), NULL); g_free (r); - r = g_strdup_printf ("GREETER %s RESPOND TEXT=\"", getenv ("DISPLAY")); + r = g_strdup_printf ("%s RESPOND TEXT=\"", greeter_id); if (g_str_has_prefix (request, r)) { gchar *text = g_strdup (request + strlen (r)); @@ -98,31 +98,31 @@ request_cb (const gchar *request) } g_free (r); - r = g_strdup_printf ("GREETER %s START-SESSION", getenv ("DISPLAY")); + r = g_strdup_printf ("%s START-SESSION", greeter_id); if (strcmp (request, r) == 0) { if (!lightdm_greeter_start_session_sync (greeter, NULL, NULL)) - status_notify ("GREETER %s SESSION-FAILED", getenv ("DISPLAY")); + status_notify ("%s SESSION-FAILED", greeter_id); } g_free (r); - r = g_strdup_printf ("GREETER %s START-SESSION SESSION=", getenv ("DISPLAY")); + r = g_strdup_printf ("%s START-SESSION SESSION=", greeter_id); if (g_str_has_prefix (request, r)) { if (!lightdm_greeter_start_session_sync (greeter, request + strlen (r), NULL)) - status_notify ("GREETER %s SESSION-FAILED", getenv ("DISPLAY")); + status_notify ("%s SESSION-FAILED", greeter_id); } g_free (r); - r = g_strdup_printf ("GREETER %s LOG-LAYOUT", getenv ("DISPLAY")); + r = g_strdup_printf ("%s LOG-LAYOUT", greeter_id); if (strcmp (request, r) == 0) { const gchar *layout; layout = lightdm_layout_get_name (lightdm_get_layout ()); - status_notify ("GREETER %s LOG-LAYOUT LAYOUT='%s'", getenv ("DISPLAY"), layout ? layout : ""); + status_notify ("%s LOG-LAYOUT LAYOUT='%s'", greeter_id, layout ? layout : ""); } - r = g_strdup_printf ("GREETER %s LOG-LAYOUT USERNAME=", getenv ("DISPLAY")); + r = g_strdup_printf ("%s LOG-LAYOUT USERNAME=", greeter_id); if (g_str_has_prefix (request, r)) { LightDMUser *user; @@ -132,11 +132,11 @@ request_cb (const gchar *request) user = lightdm_user_list_get_user_by_name (lightdm_user_list_get_instance (), username); layout = lightdm_user_get_layout (user); - status_notify ("GREETER %s LOG-LAYOUT USERNAME=%s LAYOUT='%s'", getenv ("DISPLAY"), username, layout ? layout : ""); + status_notify ("%s LOG-LAYOUT USERNAME=%s LAYOUT='%s'", greeter_id, username, layout ? layout : ""); } g_free (r); - r = g_strdup_printf ("GREETER %s LOG-LAYOUTS USERNAME=", getenv ("DISPLAY")); + r = g_strdup_printf ("%s LOG-LAYOUTS USERNAME=", greeter_id); if (g_str_has_prefix (request, r)) { LightDMUser *user; @@ -149,11 +149,11 @@ request_cb (const gchar *request) layouts = lightdm_user_get_layouts (user); for (i = 0; layouts[i]; i++) - status_notify ("GREETER %s LOG-LAYOUTS USERNAME=%s LAYOUT='%s'", getenv ("DISPLAY"), username, layouts[i]); + status_notify ("%s LOG-LAYOUTS USERNAME=%s LAYOUT='%s'", greeter_id, username, layouts[i]); } g_free (r); - r = g_strdup_printf ("GREETER %s LOG-VARIANTS LAYOUT=", getenv ("DISPLAY")); + r = g_strdup_printf ("%s LOG-VARIANTS LAYOUT=", greeter_id); if (g_str_has_prefix (request, r)) { GList *layouts, *iter; @@ -171,12 +171,12 @@ request_cb (const gchar *request) name = lightdm_layout_get_name (layout); if (g_str_has_prefix (name, layout_prefix)) - status_notify ("GREETER %s LOG-VARIANTS LAYOUT='%s'", getenv ("DISPLAY"), name); + status_notify ("%s LOG-VARIANTS LAYOUT='%s'", greeter_id, name); } } g_free (r); - r = g_strdup_printf ("GREETER %s LOG-LANGUAGE USERNAME=", getenv ("DISPLAY")); + r = g_strdup_printf ("%s LOG-LANGUAGE USERNAME=", greeter_id); if (g_str_has_prefix (request, r)) { LightDMUser *user; @@ -186,7 +186,7 @@ request_cb (const gchar *request) user = lightdm_user_list_get_user_by_name (lightdm_user_list_get_instance (), username); language = lightdm_user_get_language (user); - status_notify ("GREETER %s LOG-LANGUAGE USERNAME=%s LANGUAGE=%s", getenv ("DISPLAY"), username, language ? language : ""); + status_notify ("%s LOG-LANGUAGE USERNAME=%s LANGUAGE=%s", greeter_id, username, language ? language : ""); } g_free (r); } @@ -194,6 +194,8 @@ request_cb (const gchar *request) int main (int argc, char **argv) { + gchar *display; + signal (SIGINT, signal_cb); signal (SIGTERM, signal_cb); @@ -201,11 +203,19 @@ main (int argc, char **argv) g_type_init (); #endif + display = getenv ("DISPLAY"); + if (display == NULL) + greeter_id = g_strdup ("GREETER-?"); + else if (display[0] == ':') + greeter_id = g_strdup_printf ("GREETER-X-%s", display + 1); + else + greeter_id = g_strdup_printf ("GREETER-X-%s", display); + loop = g_main_loop_new (NULL, FALSE); status_connect (request_cb); - status_notify ("GREETER %s START", getenv ("DISPLAY")); + status_notify ("%s START", greeter_id); config = g_key_file_new (); g_key_file_load_from_file (config, g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "script", NULL), G_KEY_FILE_NONE, NULL); @@ -213,7 +223,7 @@ main (int argc, char **argv) if (g_key_file_has_key (config, "test-greeter-config", "return-value", NULL)) { int return_value = g_key_file_get_integer (config, "test-greeter-config", "return-value", NULL); - status_notify ("GREETER %s EXIT CODE=%d", getenv ("DISPLAY"), return_value); + status_notify ("%s EXIT CODE=%d", greeter_id, return_value); return return_value; } @@ -221,11 +231,11 @@ main (int argc, char **argv) if (xcb_connection_has_error (connection)) { - status_notify ("GREETER %s FAIL-CONNECT-XSERVER", getenv ("DISPLAY")); + status_notify ("%s FAIL-CONNECT-XSERVER", greeter_id); return EXIT_FAILURE; } - status_notify ("GREETER %s CONNECT-XSERVER", getenv ("DISPLAY")); + status_notify ("%s CONNECT-XSERVER", greeter_id); greeter = lightdm_greeter_new (); g_signal_connect (greeter, "show-message", G_CALLBACK (show_message_cb), NULL); @@ -233,19 +243,19 @@ main (int argc, char **argv) g_signal_connect (greeter, "authentication-complete", G_CALLBACK (authentication_complete_cb), NULL); g_signal_connect (greeter, "autologin-timer-expired", G_CALLBACK (autologin_timer_expired_cb), NULL); - status_notify ("GREETER %s CONNECT-TO-DAEMON", getenv ("DISPLAY")); + status_notify ("%s CONNECT-TO-DAEMON", greeter_id); if (!lightdm_greeter_connect_sync (greeter, NULL)) { - status_notify ("GREETER %s FAIL-CONNECT-DAEMON", getenv ("DISPLAY")); + status_notify ("%s FAIL-CONNECT-DAEMON", greeter_id); return EXIT_FAILURE; } - status_notify ("GREETER %s CONNECTED-TO-DAEMON", getenv ("DISPLAY")); + status_notify ("%s CONNECTED-TO-DAEMON", greeter_id); if (lightdm_greeter_get_select_user_hint (greeter)) - status_notify ("GREETER %s SELECT-USER-HINT USERNAME=%s", getenv ("DISPLAY"), lightdm_greeter_get_select_user_hint (greeter)); + status_notify ("%s SELECT-USER-HINT USERNAME=%s", greeter_id, lightdm_greeter_get_select_user_hint (greeter)); if (lightdm_greeter_get_lock_hint (greeter)) - status_notify ("GREETER %s LOCK-HINT", getenv ("DISPLAY")); + status_notify ("%s LOCK-HINT", greeter_id); g_main_loop_run (loop); |