]> rtime.felk.cvut.cz Git - sojka/lightdm.git/commitdiff
Add SwitchToUser test
authorRobert Ancell <robert.ancell@canonical.com>
Mon, 4 Jul 2011 05:30:05 +0000 (15:30 +1000)
committerRobert Ancell <robert.ancell@canonical.com>
Mon, 4 Jul 2011 05:30:05 +0000 (15:30 +1000)
tests/Makefile.am
tests/src/test-runner.c
tests/test-switch-to-user [new file with mode: 0755]

index ac8f46a0aa88892fcb8a4e6bd2d19b6e7eb6dd0e..ddf153a225d183f6696d7ef2863f884ec9ce9db7 100644 (file)
@@ -3,6 +3,7 @@ SUBDIRS = src
 TESTS = \
        test-headless \
        test-show-greeter \
+       test-switch-to-user \
        test-autologin \
        test-autologin-logout \
        test-login-gobject \
@@ -60,4 +61,6 @@ EXTRA_DIST = \
        scripts/login-gobject-xserver-crash.script \
        scripts/no-config.script \
        scripts/show-greeter.conf \
-       scripts/show-greeter.script
+       scripts/show-greeter.script \
+       scripts/switch-to-user.conf \
+       scripts/switch-to-user.script
index ee94f461793b8b7bf5d5ce2a8819c4114e53d7ae..2903a9155bdf688fc65a16710dcec7574ceca665 100644 (file)
@@ -129,6 +129,9 @@ run_commands ()
     while (TRUE)
     {
         gchar *command = get_script_line ();
+        gchar **args, *name;
+        GHashTable *params;
+        gint i;
 
         if (!command)
             break;
@@ -137,14 +140,25 @@ run_commands ()
         if (command[0] != '*')
             break;
         statuses = g_list_append (statuses, g_strdup (command));
-        command++;
         script_iter = script_iter->next;
 
-        if (strcmp (command, "WAIT") == 0)
+        args = g_strsplit (command, " ", -1);
+        name = g_strdup (args[0] + 1);
+        params = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+        for (i = 1; args[i]; i++)
+        {
+            gchar **v;
+            v = g_strsplit (args[i], "=", 2);
+            g_hash_table_insert (params, g_strdup (v[0]), g_strdup (v[1]));
+            g_strfreev (v);
+        }
+        g_strfreev (args);
+
+        if (strcmp (name, "WAIT") == 0)
         {
             sleep (1);
         }
-        else if (strcmp (command, "SHOW-GREETER") == 0)
+        else if (strcmp (name, "SHOW-GREETER") == 0)
         {
             g_dbus_connection_call_sync (g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL),
                                          "org.freedesktop.DisplayManager",
@@ -159,17 +173,40 @@ run_commands ()
                                          NULL);
             check_status ("RUNNER SHOW-GREETER");
         }
-        else if (strcmp (command, "STOP-DAEMON") == 0)
+        else if (strcmp (name, "SWITCH-TO-USER") == 0)
+        {
+            gchar *status_text, *username;
+          
+            username = g_hash_table_lookup (params, "USERNAME");
+            g_dbus_connection_call_sync (g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL),
+                                         "org.freedesktop.DisplayManager",
+                                         "/org/freedesktop/DisplayManager",                                         
+                                         "org.freedesktop.DisplayManager",
+                                         "SwitchToUser",
+                                         g_variant_new ("(s)", username),
+                                         G_VARIANT_TYPE ("()"),
+                                         G_DBUS_CALL_FLAGS_NONE,
+                                         0,
+                                         NULL,
+                                         NULL);
+            status_text = g_strdup_printf ("RUNNER SWITCH-TO-USER USERNAME=%s", username);
+            check_status (status_text);
+            g_free (status_text);
+        }
+        else if (strcmp (name, "STOP-DAEMON") == 0)
         {
             expect_exit = TRUE;
             stop_daemon ();
         }
         else
         {
-            g_printerr ("Unknown command %s\n", command);
+            g_printerr ("Unknown command '%s'\n", name);
             quit (EXIT_FAILURE);
             return;
         }
+
+        g_free (name);
+        g_hash_table_unref (params);
     }
 
     /* Stop at the end of the script */
diff --git a/tests/test-switch-to-user b/tests/test-switch-to-user
new file mode 100755 (executable)
index 0000000..172822e
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/test-runner switch-to-user