]> rtime.felk.cvut.cz Git - sojka/lightdm.git/commitdiff
Add regression tests for getting the user language and layout
authorRobert Ancell <robert.ancell@canonical.com>
Mon, 23 Jan 2012 06:51:12 +0000 (17:51 +1100)
committerRobert Ancell <robert.ancell@canonical.com>
Mon, 23 Jan 2012 06:51:12 +0000 (17:51 +1100)
13 files changed:
NEWS
liblightdm-gobject/user.c
tests/Makefile.am
tests/scripts/keyboard-layout.conf [new file with mode: 0644]
tests/scripts/language.conf [new file with mode: 0644]
tests/scripts/no-keyboard-layout.conf [new file with mode: 0644]
tests/scripts/no-language.conf [new file with mode: 0644]
tests/src/test-gobject-greeter.c
tests/src/test-runner.c
tests/test-keyboard-layout [new file with mode: 0755]
tests/test-language [new file with mode: 0755]
tests/test-no-keyboard-layout [new file with mode: 0755]
tests/test-no-language [new file with mode: 0755]

diff --git a/NEWS b/NEWS
index e8e27369c97921a28a7fb11185f03a04350685e1..e783ef0bcf3bc298641d6d57e7610e1bf4bc9658 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+Overview of changes in lightdm 1.1.2
+
+    * Add regression tests for getting the user language and layout
+
 Overview of changes in lightdm 1.1.1
 
     * Add a --disable-tests option
index 0c9025fb48b1d0e4a4d1dbef4ddcb0bd0a34333e..c8fbf7d41d8ee01dbe67f285accd164bdc657c66 100644 (file)
@@ -1173,6 +1173,12 @@ get_string_property (GDBusProxy *proxy, const gchar *property)
     }
 
     g_variant_get (answer, "s", &rv);
+  
+    if (strcmp (rv, "") == 0)
+    {
+        g_free (rv);
+        rv = NULL;
+    }
 
     g_variant_unref (answer);
     return rv;
@@ -1295,16 +1301,6 @@ lightdm_user_get_logged_in (LightDMUser *user)
 static void
 lightdm_user_init (LightDMUser *user)
 {
-    LightDMUserPrivate *priv = GET_USER_PRIVATE (user);
-
-    priv->name = g_strdup ("");
-    priv->real_name = g_strdup ("");
-    priv->home_directory = g_strdup ("");
-    priv->image = g_strdup ("");
-    priv->background = g_strdup ("");
-    priv->language = g_strdup ("");
-    priv->layout = g_strdup ("");
-    priv->session = g_strdup ("");
 }
 
 static void
index 9b8db1c3c0c47e990bdec22c0b38c364b09b29e8..9508f31c6918fb50dde1e6afa0307dff74648b92 100644 (file)
@@ -17,6 +17,8 @@ TESTS = \
        test-autologin-guest \
        test-autologin-guest-fail-setup-script \
        test-autologin-guest-logout \
+       test-keyboard-layout \
+       test-no-keyboard-layout \
        test-login-gobject \
        test-login-gobject-manual \
        test-login-gobject-manual-previous-session \
@@ -100,6 +102,8 @@ EXTRA_DIST = \
        scripts/greeter-xserver-crash.conf \
        scripts/headless.conf \
        scripts/home-dir-on-authenticate.conf \
+       scripts/keyboard-layout.conf \
+       scripts/language.conf \
        scripts/login.conf \
        scripts/login-guest.conf \
        scripts/login-guest-disabled.conf \
@@ -120,6 +124,8 @@ EXTRA_DIST = \
        scripts/no-accounts-service.conf \
        scripts/no-config.conf \
        scripts/no-console-kit.conf \
+       scripts/no-keyboard-layout.conf \
+       scripts/no-language.conf \
        scripts/plymouth-active-vt.conf \
        scripts/plymouth-inactive-vt.conf \
        scripts/plymouth-no-seat.conf \
diff --git a/tests/scripts/keyboard-layout.conf b/tests/scripts/keyboard-layout.conf
new file mode 100644 (file)
index 0000000..1f00813
--- /dev/null
@@ -0,0 +1,35 @@
+#
+# Check returns correct layout for a user
+#
+
+[LightDM]
+minimum-display-number=50
+
+[test-greeter-config]
+log-keyboard-layout=bob
+
+#?RUNNER DAEMON-START
+
+# X server starts
+#?XSERVER :50 START
+#?XSERVER :50 INDICATE-READY
+
+# LightDM connects to X server
+#?XSERVER :50 ACCEPT-CONNECT
+
+# Greeter starts
+#?GREETER START
+#?XSERVER :50 ACCEPT-CONNECT
+#?GREETER CONNECT-XSERVER :50
+#?GREETER CONNECT-TO-DAEMON
+#?GREETER CONNECTED-TO-DAEMON
+
+# Correct layout is found
+#?GREETER GET-LAYOUT USERNAME=bob LAYOUT=us
+
+# Cleanup
+#?*STOP-DAEMON
+# Don't know what order they will terminate
+#?(GREETER TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)
+#?(GREETER TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)
+#?RUNNER DAEMON-EXIT STATUS=0
diff --git a/tests/scripts/language.conf b/tests/scripts/language.conf
new file mode 100644 (file)
index 0000000..9a2c3ed
--- /dev/null
@@ -0,0 +1,35 @@
+#
+# Check returns correct language for a user
+#
+
+[LightDM]
+minimum-display-number=50
+
+[test-greeter-config]
+log-language=bob
+
+#?RUNNER DAEMON-START
+
+# X server starts
+#?XSERVER :50 START
+#?XSERVER :50 INDICATE-READY
+
+# LightDM connects to X server
+#?XSERVER :50 ACCEPT-CONNECT
+
+# Greeter starts
+#?GREETER START
+#?XSERVER :50 ACCEPT-CONNECT
+#?GREETER CONNECT-XSERVER :50
+#?GREETER CONNECT-TO-DAEMON
+#?GREETER CONNECTED-TO-DAEMON
+
+# Correct layout is found
+#?GREETER GET-LANGUAGE USERNAME=bob LANGUAGE=en_AU
+
+# Cleanup
+#?*STOP-DAEMON
+# Don't know what order they will terminate
+#?(GREETER TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)
+#?(GREETER TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)
+#?RUNNER DAEMON-EXIT STATUS=0
diff --git a/tests/scripts/no-keyboard-layout.conf b/tests/scripts/no-keyboard-layout.conf
new file mode 100644 (file)
index 0000000..c56a92d
--- /dev/null
@@ -0,0 +1,35 @@
+#
+# Check handles user that has no keyboard layout
+#
+
+[LightDM]
+minimum-display-number=50
+
+[test-greeter-config]
+log-keyboard-layout=alice
+
+#?RUNNER DAEMON-START
+
+# X server starts
+#?XSERVER :50 START
+#?XSERVER :50 INDICATE-READY
+
+# LightDM connects to X server
+#?XSERVER :50 ACCEPT-CONNECT
+
+# Greeter starts
+#?GREETER START
+#?XSERVER :50 ACCEPT-CONNECT
+#?GREETER CONNECT-XSERVER :50
+#?GREETER CONNECT-TO-DAEMON
+#?GREETER CONNECTED-TO-DAEMON
+
+# Correct layout is found
+#?GREETER GET-LAYOUT USERNAME=alice LAYOUT=
+
+# Cleanup
+#?*STOP-DAEMON
+# Don't know what order they will terminate
+#?(GREETER TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)
+#?(GREETER TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)
+#?RUNNER DAEMON-EXIT STATUS=0
diff --git a/tests/scripts/no-language.conf b/tests/scripts/no-language.conf
new file mode 100644 (file)
index 0000000..98fc93c
--- /dev/null
@@ -0,0 +1,35 @@
+#
+# Check handles user that has no language set
+#
+
+[LightDM]
+minimum-display-number=50
+
+[test-greeter-config]
+log-language=alice
+
+#?RUNNER DAEMON-START
+
+# X server starts
+#?XSERVER :50 START
+#?XSERVER :50 INDICATE-READY
+
+# LightDM connects to X server
+#?XSERVER :50 ACCEPT-CONNECT
+
+# Greeter starts
+#?GREETER START
+#?XSERVER :50 ACCEPT-CONNECT
+#?GREETER CONNECT-XSERVER :50
+#?GREETER CONNECT-TO-DAEMON
+#?GREETER CONNECTED-TO-DAEMON
+
+# Correct layout is found
+#?GREETER GET-LANGUAGE USERNAME=alice LANGUAGE=
+
+# Cleanup
+#?*STOP-DAEMON
+# Don't know what order they will terminate
+#?(GREETER TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)
+#?(GREETER TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)
+#?RUNNER DAEMON-EXIT STATUS=0
index 1ae98e4bc7cae15a4f4f0bab8e349adddb3bf3f2..4613c6d9e55dde103f41f6d24c07c9c10ab6b582 100644 (file)
@@ -2,7 +2,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <xcb/xcb.h>
-#include <lightdm/greeter.h>
+#include <lightdm.h>
 
 #include "status.h"
 
@@ -69,6 +69,7 @@ main (int argc, char **argv)
 {
     GMainLoop *main_loop;
     LightDMGreeter *greeter;
+    gchar *layout_username, *language_username;
 
     signal (SIGINT, signal_cb);
     signal (SIGTERM, signal_cb);
@@ -113,6 +114,30 @@ main (int argc, char **argv)
 
     notify_status ("GREETER CONNECTED-TO-DAEMON");
 
+    layout_username = g_key_file_get_string (config, "test-greeter-config", "log-keyboard-layout", NULL);
+    if (layout_username)
+    {
+        LightDMUser *user;
+        const gchar *layout;
+
+        user = lightdm_user_list_get_user_by_name (lightdm_user_list_get_instance (), layout_username);
+        layout = lightdm_user_get_layout (user);
+
+        notify_status ("GREETER GET-LAYOUT USERNAME=%s LAYOUT=%s", layout_username, layout ? layout : "");
+    }
+
+    language_username = g_key_file_get_string (config, "test-greeter-config", "log-language", NULL);
+    if (language_username)
+    {
+        LightDMUser *user;
+        const gchar *language;
+
+        user = lightdm_user_list_get_user_by_name (lightdm_user_list_get_instance (), language_username);
+        language = lightdm_user_get_language (user);
+
+        notify_status ("GREETER GET-LANGUAGE USERNAME=%s LANGUAGE=%s", language_username, language ? language : "");
+    }
+
     if (g_key_file_get_boolean (config, "test-greeter-config", "crash-xserver", NULL))
     {
         gchar *crash_lock;
index 671734bc7fa11ec50e41028728a77f721bc77bbd..7be4a8dddbed6782059e8a7a671d0095ce596dc6 100644 (file)
@@ -48,8 +48,12 @@ static GDBusNodeInfo *user_info;
 typedef struct
 {
     guint uid;
-    gchar *username;
+    gchar *user_name;
+    gchar *real_name;
+    gchar *home_directory;
+    gchar *path;
     guint id;
+    gchar *language;
     gchar *xsession;
 } AccountsUser;
 static GList *accounts_users = NULL;
@@ -657,19 +661,87 @@ start_console_kit_daemon ()
                     NULL);
 }
 
-static AccountsUser *
-find_accounts_user (guint uid)
+static void
+load_passwd_file ()
 {
-    GList *link;
+    gchar *data, **lines;
+    int i;
+
+    g_file_get_contents (g_getenv ("LIGHTDM_TEST_PASSWD_FILE"), &data, NULL, NULL);
+    lines = g_strsplit (data, "\n", -1);
+    g_free (data);
 
-    for (link = accounts_users; link; link = link->next)
+    for (i = 0; lines[i]; i++)
     {
-        AccountsUser *user = link->data;
-        if (user->uid == uid)
-            return user;
+        gchar **fields;
+        guint uid;
+        gchar *user_name, *real_name;
+        GList *link;
+        AccountsUser *user = NULL;
+        GError *error = NULL;
+
+        fields = g_strsplit (lines[i], ":", -1);
+        if (fields == NULL || g_strv_length (fields) < 7)
+            continue;
+
+        user_name = fields[0];
+        uid = atoi (fields[2]);
+        real_name = fields[4];
+
+        for (link = accounts_users; link; link = link->next)
+        {
+            AccountsUser *u = link->data;
+            if (u->uid == uid)
+            {
+                user = u;
+                break;
+            }
+        }
+        if (!user)
+        {
+            gchar *path;
+            GKeyFile *dmrc_file;
+
+            user = g_malloc0 (sizeof (AccountsUser));
+            accounts_users = g_list_append (accounts_users, user);
+
+            dmrc_file = g_key_file_new ();
+            path = g_build_filename (temp_dir, "home", user_name, ".dmrc", NULL);
+            g_key_file_load_from_file (dmrc_file, path, G_KEY_FILE_NONE, NULL);
+            g_free (path);
+
+            user->uid = uid;
+            user->user_name = g_strdup (user_name);
+            user->real_name = g_strdup (real_name);
+            user->home_directory = g_build_filename (temp_dir, "home", user_name, NULL);
+            user->language = g_key_file_get_string (dmrc_file, "Desktop", "Language", NULL);
+            /* DMRC contains a locale, strip the codeset off it to get the language */
+            if (user->language)
+            {
+                gchar *c = strchr (user->language, '.');
+                if (c)
+                    *c = '\0';
+            }
+            user->xsession = g_key_file_get_string (dmrc_file, "Desktop", "Session", NULL);
+            user->path = g_strdup_printf ("/org/freedesktop/Accounts/User%d", uid);
+            user->id = g_dbus_connection_register_object (accounts_connection,
+                                                          user->path,
+                                                          user_info->interfaces[0],
+                                                          &user_vtable,
+                                                          user,
+                                                          NULL,
+                                                          &error);
+            if (error)
+                g_warning ("Failed to register user: %s", error->message);
+            g_clear_error (&error);
+          
+            g_key_file_unref (dmrc_file);
+        }
+
+        g_strfreev (fields);
     }
 
-    return NULL;
+    g_strfreev (lines);
 }
 
 static void
@@ -682,62 +754,44 @@ handle_accounts_call (GDBusConnection       *connection,
                       GDBusMethodInvocation *invocation,
                       gpointer               user_data)
 {
-    if (strcmp (method_name, "FindUserByName") == 0)
+    if (strcmp (method_name, "ListCachedUsers") == 0)
     {
-        gchar *name, *data, **lines;
-        int i;
+        GVariantBuilder builder;
+        GList *link;
 
-        g_variant_get (parameters, "(&s)", &name);
+        g_variant_builder_init (&builder, G_VARIANT_TYPE ("ao"));
 
-        g_file_get_contents (g_getenv ("LIGHTDM_TEST_PASSWD_FILE"), &data, NULL, NULL);
-        lines = g_strsplit (data, "\n", -1);
-        g_free (data);
-
-        for (i = 0; lines[i]; i++)
+        load_passwd_file ();      
+        for (link = accounts_users; link; link = link->next)
         {
-            gchar **fields;
-            fields = g_strsplit (lines[i], ":", -1);
-            if (strcmp (fields[0], name) == 0)
-            {
-                gchar *path;
-                GError *error = NULL;
-                guint uid;
-                AccountsUser *user;
+            AccountsUser *user = link->data;
+            g_variant_builder_add_value (&builder, g_variant_new_object_path (user->path));
+        }
+
+        g_dbus_method_invocation_return_value (invocation, g_variant_new ("(ao)", &builder));
+    }
+    else if (strcmp (method_name, "FindUserByName") == 0)
+    {
+        GList *link;
+        AccountsUser *user = NULL;
+        gchar *user_name;
 
-                uid = atoi (fields[2]);
-                path = g_strdup_printf ("/org/freedesktop/Accounts/User%d", uid);
+        g_variant_get (parameters, "(&s)", &user_name);
 
-                user = find_accounts_user (uid);
-                if (!user)
-                {
-                    user = g_malloc0 (sizeof (AccountsUser));
-                    accounts_users = g_list_append (accounts_users, user);
-
-                    user->uid = uid;
-                    user->username = g_strdup (name);
-                    if (strcmp (name, "carol") == 0)
-                        user->xsession = g_strdup ("alternative");
-                    else
-                        user->xsession = NULL;
-                    user->id = g_dbus_connection_register_object (accounts_connection,
-                                                                  path,
-                                                                  user_info->interfaces[0],
-                                                                  &user_vtable,
-                                                                  user,
-                                                                  NULL,
-                                                                  &error);
-                    if (error)
-                        g_warning ("Failed to register user: %s", error->message);
-                    g_clear_error (&error);
-                }              
-
-                g_dbus_method_invocation_return_value (invocation, g_variant_new ("(o)", path));
-                g_free (path);
-                return;
+        load_passwd_file ();
+        for (link = accounts_users; link; link = link->next)
+        {
+            AccountsUser *u = link->data;
+            if (strcmp (u->user_name, user_name) == 0)
+            {
+                user = u;
+                break;
             }
         }
-      
-        g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No such user: %s", name);
+        if (user)
+            g_dbus_method_invocation_return_value (invocation, g_variant_new ("(o)", user->path));
+        else
+            g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No such user: %s", user_name);
     }
     else
         g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No such method: %s", method_name);    
@@ -781,10 +835,16 @@ handle_user_get_property (GDBusConnection       *connection,
 {
     AccountsUser *user = user_data;
 
-    if (strcmp (property_name, "BackgroundFile") == 0)
+    if (strcmp (property_name, "UserName") == 0)
+        return g_variant_new_string (user->user_name);
+    else if (strcmp (property_name, "RealName") == 0)
+        return g_variant_new_string (user->real_name);
+    else if (strcmp (property_name, "HomeDirectory") == 0)
+        return g_variant_new_string (user->home_directory);
+    else if (strcmp (property_name, "BackgroundFile") == 0)
         return g_variant_new_string ("");
     else if (strcmp (property_name, "Language") == 0)
-        return g_variant_new_string ("en_US");
+        return g_variant_new_string (user->language ? user->language : "");
     else if (strcmp (property_name, "XSession") == 0)
         return g_variant_new_string (user->xsession ? user->xsession : "");
 
@@ -799,6 +859,9 @@ accounts_name_acquired_cb (GDBusConnection *connection,
     const gchar *accounts_interface =
         "<node>"
         "  <interface name='org.freedesktop.Accounts'>"
+        "    <method name='ListCachedUsers'>"
+        "      <arg name='user' direction='out' type='ao'/>"
+        "    </method>"
         "    <method name='FindUserByName'>"
         "      <arg name='name' direction='in' type='s'/>"
         "      <arg name='user' direction='out' type='o'/>"
@@ -815,6 +878,9 @@ accounts_name_acquired_cb (GDBusConnection *connection,
         "    <method name='SetXSession'>"
         "      <arg name='x_session' direction='in' type='s'/>"
         "    </method>"
+        "    <property name='UserName' type='s' access='read'/>"
+        "    <property name='RealName' type='s' access='read'/>"
+        "    <property name='HomeDirectory' type='s' access='read'/>"
         "    <property name='BackgroundFile' type='s' access='read'/>"
         "    <property name='Language' type='s' access='read'/>"
         "    <property name='XSession' type='s' access='read'/>"
@@ -1038,21 +1104,26 @@ main (int argc, char **argv)
         gboolean have_home_dir;
         gchar *real_name;
         gchar *xsession;
+        gchar *layout;
+        gchar *language;
         gint uid;
     } users[] =
     {
-        {"root",    "",         TRUE,  "root",       NULL,             0},
-        {"lightdm", "",         TRUE,  "",           NULL,           100},
-        {"alice",   "password", TRUE,  "Alice User", NULL,          1000},
-        {"bob",     "",         TRUE,  "Bob User",   NULL,          1001},
-        {"carol",   "",         TRUE,  "Carol User", "alternative", 1002},
-        {"dave",    "",         FALSE, "Dave User",  NULL,          1003},
-        {NULL,      NULL,       FALSE, NULL,         NULL,             0}
+        {"root",    "",         TRUE,  "root",       NULL,          NULL, NULL,             0},
+        {"lightdm", "",         TRUE,  "",           NULL,          NULL, NULL,           100},
+        {"alice",   "password", TRUE,  "Alice User", NULL,          NULL, NULL,          1000},
+        {"bob",     "",         TRUE,  "Bob User",   NULL,          "us", "en_AU.utf8",  1001},
+        {"carol",   "",         TRUE,  "Carol User", "alternative", "fr", "fr_FR.UTF-8", 1002},
+        {"dave",    "",         FALSE, "Dave User",  NULL,          NULL, NULL,          1003},
+        {NULL,      NULL,       FALSE, NULL,         NULL,          NULL, NULL,             0}
     };
     passwd_data = g_string_new ("");
     int i;
     for (i = 0; users[i].user_name; i++)
     {
+        GKeyFile *dmrc_file;
+        gboolean save_dmrc = FALSE;
+
         if (users[i].have_home_dir)
         {
             path = g_build_filename (home_dir, users[i].user_name, NULL);
@@ -1060,11 +1131,32 @@ main (int argc, char **argv)
             g_free (path);
         }
 
+        dmrc_file = g_key_file_new ();
         if (users[i].xsession)
         {
+            g_key_file_set_string (dmrc_file, "Desktop", "Session", users[i].xsession);
+            save_dmrc = TRUE;
+        }
+        if (users[i].layout)
+        {
+            g_key_file_set_string (dmrc_file, "Desktop", "Layout", users[i].layout);
+            save_dmrc = TRUE;
+        }
+        if (users[i].language)
+        {
+            g_key_file_set_string (dmrc_file, "Desktop", "Language", users[i].language);
+            save_dmrc = TRUE;
+        }
+
+        if (save_dmrc)
+        {
+            gchar *data;
+
             path = g_build_filename (home_dir, users[i].user_name, ".dmrc", NULL);
-            g_file_set_contents (path, g_strdup_printf ("[Desktop]\nSession=%s", users[i].xsession), -1, NULL);
-            g_free (path);
+            data = g_key_file_to_data (dmrc_file, NULL, NULL);
+            g_file_set_contents (path, data, -1, NULL);
+            g_free (data);
+            g_free (path);         
         }
 
         g_string_append_printf (passwd_data, "%s:%s:%d:%d:%s:%s/home/%s:/bin/sh\n", users[i].user_name, users[i].password, users[i].uid, users[i].uid, users[i].real_name, temp_dir, users[i].user_name);
diff --git a/tests/test-keyboard-layout b/tests/test-keyboard-layout
new file mode 100755 (executable)
index 0000000..d3186d1
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner keyboard-layout test-gobject-greeter
diff --git a/tests/test-language b/tests/test-language
new file mode 100755 (executable)
index 0000000..f595d46
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner language test-gobject-greeter
diff --git a/tests/test-no-keyboard-layout b/tests/test-no-keyboard-layout
new file mode 100755 (executable)
index 0000000..cb478e1
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner no-keyboard-layout test-gobject-greeter
diff --git a/tests/test-no-language b/tests/test-no-language
new file mode 100755 (executable)
index 0000000..fd97529
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner no-language test-gobject-greeter