]> rtime.felk.cvut.cz Git - sojka/lightdm.git/commitdiff
Merge with trunk
authorRobert Ancell <robert.ancell@canonical.com>
Mon, 15 Apr 2013 22:40:27 +0000 (10:40 +1200)
committerRobert Ancell <robert.ancell@canonical.com>
Mon, 15 Apr 2013 22:40:27 +0000 (10:40 +1200)
33 files changed:
.bzrignore
configure.ac
liblightdm-gobject/power.c
liblightdm-qt/Makefile.am
liblightdm-qt/QLightDM/power.h
liblightdm-qt/liblightdm-qt-3.pc.in [moved from liblightdm-qt/liblightdm-qt-2.pc.in with 100% similarity]
liblightdm-qt/liblightdm-qt5-3.pc.in [moved from liblightdm-qt/liblightdm-qt5-2.pc.in with 100% similarity]
liblightdm-qt/power.cpp
tests/Makefile.am
tests/scripts/power-no-console-kit.conf [new file with mode: 0644]
tests/scripts/power-no-login1.conf [new file with mode: 0644]
tests/scripts/power-no-services.conf [new file with mode: 0644]
tests/scripts/power.conf [new file with mode: 0644]
tests/src/test-gobject-greeter.c
tests/src/test-python-greeter
tests/src/test-qt-greeter.cpp
tests/src/test-runner.c
tests/test-gobject-power [new file with mode: 0755]
tests/test-gobject-power-no-console-kit [new file with mode: 0755]
tests/test-gobject-power-no-login1 [new file with mode: 0755]
tests/test-gobject-power-no-services [new file with mode: 0755]
tests/test-python-power [new file with mode: 0755]
tests/test-python-power-no-console-kit [new file with mode: 0755]
tests/test-python-power-no-login1 [new file with mode: 0755]
tests/test-python-power-no-services [new file with mode: 0755]
tests/test-qt4-power [new file with mode: 0755]
tests/test-qt4-power-no-console-kit [new file with mode: 0755]
tests/test-qt4-power-no-login1 [new file with mode: 0755]
tests/test-qt4-power-no-services [new file with mode: 0755]
tests/test-qt5-power [new file with mode: 0755]
tests/test-qt5-power-no-console-kit [new file with mode: 0755]
tests/test-qt5-power-no-login1 [new file with mode: 0755]
tests/test-qt5-power-no-services [new file with mode: 0755]

index 0af43c337b2e52f98dc281f8fd73418b27c7e0f0..894064c0e51139aaa9d718dd6f503c167992a619 100644 (file)
@@ -41,7 +41,7 @@ greeters/qt/ui_*.h
 liblightdm-gobject/*.gir
 liblightdm-gobject/*.typelib
 liblightdm-gobject/liblightdm-gobject-*.pc
-liblightdm-qt/liblightdm-qt4-*.pc
+liblightdm-qt/liblightdm-qt-*.pc
 liblightdm-qt/liblightdm-qt5-*.pc
 liblightdm-qt/*_moc*.cpp
 m4/*
index 8151d1cbba8e6cf6389b1792fda7ad82b9217869..224b1bdf0273c1d6af025eddc88cd2bb20551aca 100644 (file)
@@ -199,8 +199,8 @@ help/Makefile
 liblightdm-gobject/liblightdm-gobject-1.pc
 liblightdm-gobject/Makefile
 liblightdm-qt/Makefile
-liblightdm-qt/liblightdm-qt-2.pc
-liblightdm-qt/liblightdm-qt5-2.pc
+liblightdm-qt/liblightdm-qt-3.pc
+liblightdm-qt/liblightdm-qt5-3.pc
 po/Makefile.in
 src/Makefile
 tests/Makefile
index 739362cd95c30f6e6a22236574c55c36e75b79d3..628dc2ad93757232e6e22780024a4fac56ea660b 100644 (file)
@@ -19,11 +19,10 @@ static GDBusProxy *upower_proxy = NULL;
 static GDBusProxy *ck_proxy = NULL;
 static GDBusProxy *login1_proxy = NULL;
 
-static gboolean
-upower_call_function (const gchar *function, gboolean default_result, GError **error)
+static GVariant *
+upower_call_function (const gchar *function, GError **error)
 {
     GVariant *result;
-    gboolean function_result = FALSE;
 
     if (!upower_proxy)
     {
@@ -36,24 +35,16 @@ upower_call_function (const gchar *function, gboolean default_result, GError **e
                                                       NULL,
                                                       error);
         if (!upower_proxy)
-            return FALSE;
+            return NULL;
     }
 
-    result = g_dbus_proxy_call_sync (upower_proxy,
-                                     function,
-                                     NULL,
-                                     G_DBUS_CALL_FLAGS_NONE,
-                                     -1,
-                                     NULL,
-                                     error);
-    if (!result)
-        return default_result;
-
-    if (g_variant_is_of_type (result, G_VARIANT_TYPE ("(b)")))
-        g_variant_get (result, "(b)", &function_result);
-
-    g_variant_unref (result);
-    return function_result;
+    return g_dbus_proxy_call_sync (upower_proxy,
+                                   function,
+                                   NULL,
+                                   G_DBUS_CALL_FLAGS_NONE,
+                                   -1,
+                                   NULL,
+                                   error);
 }
 
 /**
@@ -66,7 +57,18 @@ upower_call_function (const gchar *function, gboolean default_result, GError **e
 gboolean
 lightdm_get_can_suspend (void)
 {
-    return upower_call_function ("SuspendAllowed", FALSE, NULL);
+    GVariant *result;
+    gboolean can_suspend = FALSE;
+
+    result = upower_call_function ("SuspendAllowed", NULL);
+    if (!result)
+        return FALSE;
+
+    if (g_variant_is_of_type (result, G_VARIANT_TYPE ("(b)")))
+        g_variant_get (result, "(b)", &can_suspend);
+    g_variant_unref (result);
+
+    return can_suspend;
 }
 
 /**
@@ -80,7 +82,15 @@ lightdm_get_can_suspend (void)
 gboolean
 lightdm_suspend (GError **error)
 {
-    return upower_call_function ("Suspend", TRUE, error);
+    GVariant *result;
+  
+    result = upower_call_function ("Suspend", error);
+    if (!result)
+        return FALSE;
+
+    g_variant_unref (result);
+
+    return TRUE;
 }
 
 /**
@@ -93,7 +103,18 @@ lightdm_suspend (GError **error)
 gboolean
 lightdm_get_can_hibernate (void)
 {
-    return upower_call_function ("HibernateAllowed", FALSE, NULL);
+    GVariant *result;
+    gboolean can_hibernate = FALSE;
+  
+    result = upower_call_function ("HibernateAllowed", NULL);
+    if (!result)
+        return FALSE;
+
+    if (g_variant_is_of_type (result, G_VARIANT_TYPE ("(b)")))
+        g_variant_get (result, "(b)", &can_hibernate);
+    g_variant_unref (result);
+
+    return can_hibernate;
 }
 
 /**
@@ -107,7 +128,15 @@ lightdm_get_can_hibernate (void)
 gboolean
 lightdm_hibernate (GError **error)
 {
-    return upower_call_function ("Hibernate", TRUE, error);
+    GVariant *result;
+  
+    result = upower_call_function ("Hibernate", error);
+    if (!result)
+        return FALSE;
+
+    g_variant_unref (result);
+
+    return TRUE;
 }
 
 static GVariant *
index 26f15684f6ad059de0ea980c05d90694a2a95036..7969458b21e5c8d20ec1262c3f72cccf7176056c 100644 (file)
@@ -7,10 +7,10 @@
 common_libadd = \
        -L$(top_builddir)/liblightdm-gobject \
        -llightdm-gobject-1
-liblightdm_qt_2_la_LIBADD = \
+liblightdm_qt_3_la_LIBADD = \
        $(LIBLIGHTDM_QT4_LIBS) \
        $(common_libadd)
-liblightdm_qt5_2_la_LIBADD = \
+liblightdm_qt5_3_la_LIBADD = \
        $(LIBLIGHTDM_QT5_LIBS) \
        $(common_libadd)
 
@@ -19,10 +19,10 @@ common_cflags = \
        $(LIBLIGHTDM_GOBJECT_CFLAGS) \
        -DQT_NO_KEYWORDS \
        -DXSESSIONS_DIR=\"$(datadir)/xsessions\"
-liblightdm_qt_2_la_CXXFLAGS = \
+liblightdm_qt_3_la_CXXFLAGS = \
        $(LIBLIGHTDM_QT4_CFLAGS) \
        $(common_cflags)
-liblightdm_qt5_2_la_CXXFLAGS = \
+liblightdm_qt5_3_la_CXXFLAGS = \
        -fPIC \
        -DQT_DISABLE_DEPRECATED_BEFORE="QT_VERSION_CHECK(4, 0, 0)" \
        $(LIBLIGHTDM_QT5_CFLAGS) \
@@ -38,20 +38,20 @@ common_headers = \
        QLightDM/sessionsmodel.h \
        QLightDM/usersmodel.h
 
-liblightdm_qt_2includedir=$(includedir)/lightdm-qt-2/QLightDM
-liblightdm_qt5_2includedir=$(includedir)/lightdm-qt5-2/QLightDM
+liblightdm_qt_3includedir=$(includedir)/lightdm-qt-3/QLightDM
+liblightdm_qt5_3includedir=$(includedir)/lightdm-qt5-3/QLightDM
 
 common_sources = \
        greeter.cpp \
        power.cpp \
        sessionsmodel.cpp \
        usersmodel.cpp
-liblightdm_qt_2_la_SOURCES = \
+liblightdm_qt_3_la_SOURCES = \
        $(common_sources) \
-       $(liblightdm_qt_2include_HEADERS)
-liblightdm_qt5_2_la_SOURCES = \
+       $(liblightdm_qt_3include_HEADERS)
+liblightdm_qt5_3_la_SOURCES = \
        $(common_sources) \
-       $(liblightdm_qt5_2include_HEADERS)
+       $(liblightdm_qt5_3include_HEADERS)
 
 pkgconfigdir = $(libdir)/pkgconfig
 
@@ -67,15 +67,15 @@ BUILT_SOURCES =
 pkgconfig_DATA =
 
 if COMPILE_LIBLIGHTDM_QT4
-lib_LTLIBRARIES += liblightdm-qt-2.la
-liblightdm_qt_2include_HEADERS = $(common_headers)
+lib_LTLIBRARIES += liblightdm-qt-3.la
+liblightdm_qt_3include_HEADERS = $(common_headers)
 BUILT_SOURCES += $(common_sources:.cpp=_moc4.cpp)
-pkgconfig_DATA += liblightdm-qt-2.pc
+pkgconfig_DATA += liblightdm-qt-3.pc
 endif
 
 if COMPILE_LIBLIGHTDM_QT5
-lib_LTLIBRARIES += liblightdm-qt5-2.la
-liblightdm_qt5_2include_HEADERS = $(common_headers)
+lib_LTLIBRARIES += liblightdm-qt5-3.la
+liblightdm_qt5_3include_HEADERS = $(common_headers)
 BUILT_SOURCES += $(common_sources:.cpp=_moc5.cpp)
-pkgconfig_DATA += liblightdm-qt5-2.pc
+pkgconfig_DATA += liblightdm-qt5-3.pc
 endif
index b00081badefff5496fd2a82e2043e9b7fe026dd0..44d9e2c49f547b786ee3caad5ef80a0f93a59c7e 100644 (file)
@@ -34,10 +34,10 @@ namespace QLightDM
         bool canRestart();
 
     public Q_SLOTS:
-        void suspend();
-        void hibernate();
-        void shutdown();
-        void restart();
+        bool suspend();
+        bool hibernate();
+        bool shutdown();
+        bool restart();
 
     private:
         class PowerInterfacePrivate;
index 3eabc23f8283a91c9b783c7b6b8cfbf5a57a141a..47bd5a05ec25c76b15de36f486cd395ef2e405aa 100644 (file)
@@ -60,9 +60,10 @@ bool PowerInterface::canSuspend()
     }
 }
 
-void PowerInterface::suspend()
+bool PowerInterface::suspend()
 {
-    d->powerManagementInterface->call("Suspend");
+    QDBusReply<void> reply = d->powerManagementInterface->call("Suspend");
+    return reply.isValid ();
 }
 
 bool PowerInterface::canHibernate()
@@ -76,9 +77,10 @@ bool PowerInterface::canHibernate()
     }
 }
 
-void PowerInterface::hibernate()
+bool PowerInterface::hibernate()
 {
-    d->powerManagementInterface->call("Hibernate");
+    QDBusReply<void> reply = d->powerManagementInterface->call("Hibernate");
+    return reply.isValid ();
 }
 
 bool PowerInterface::canShutdown()
@@ -99,12 +101,14 @@ bool PowerInterface::canShutdown()
     return false;
 }
 
-void PowerInterface::shutdown()
+bool PowerInterface::shutdown()
 {
+    QDBusReply<void> reply;
     if (d->login1Interface->isValid())
-        d->login1Interface->call("PowerOff", false);
+        reply = d->login1Interface->call("PowerOff", false);
     else
-        d->consoleKitInterface->call("Stop");
+        reply = d->consoleKitInterface->call("Stop");
+    return reply.isValid();
 }
 
 bool PowerInterface::canRestart()
@@ -125,12 +129,14 @@ bool PowerInterface::canRestart()
     return false;
 }
 
-void PowerInterface::restart()
+bool PowerInterface::restart()
 {
+    QDBusReply<void> reply;
     if (d->login1Interface->isValid())
-        d->login1Interface->call("Reboot", false);
+        reply = d->login1Interface->call("Reboot", false);
     else
-        d->consoleKitInterface->call("Restart");
+        reply = d->consoleKitInterface->call("Restart");
+    return reply.isValid();
 }
 
 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
index 1301d95080fc3210c9465210db23ec20ba7bb2da..c415cc8c99c0445f1f73100a772286804cb3d507 100644 (file)
@@ -137,6 +137,14 @@ TESTS = \
        test-no-console-kit \
        test-no-login1 \
        test-no-console-kit-or-login1 \
+       test-gobject-power \
+       test-gobject-power-no-console-kit \
+       test-gobject-power-no-login1 \
+       test-gobject-power-no-services \
+       test-python-power \
+       test-python-power-no-console-kit \
+       test-python-power-no-login1 \
+       test-python-power-no-services \
        test-open-file-descriptors \
        test-xdmcp-open-file-descriptors
 
@@ -172,7 +180,11 @@ TESTS += \
        test-login-qt4-guest-no-setup-script \
        test-login-qt4-guest-fail-setup-script \
        test-login-qt4-guest-logout \
-       test-login-qt4-remote-session
+       test-login-qt4-remote-session \
+       test-qt4-power \
+       test-qt4-power-no-console-kit \
+       test-qt4-power-no-login1 \
+       test-qt4-power-no-services
 endif
 
 if COMPILE_LIBLIGHTDM_QT5
@@ -201,7 +213,11 @@ TESTS += \
        test-login-qt5-guest-no-setup-script \
        test-login-qt5-guest-fail-setup-script \
        test-login-qt5-guest-logout \
-       test-login-qt5-remote-session
+       test-login-qt5-remote-session \
+       test-qt4-power \
+       test-qt4-power-no-console-kit \
+       test-qt4-power-no-login1 \
+       test-qt4-power-no-services
 endif
 
 EXTRA_DIST = \
@@ -292,6 +308,10 @@ EXTRA_DIST = \
        scripts/no-login1.conf \
        scripts/open-file-descriptors.conf \
        scripts/pam.conf \
+       scripts/power.conf \
+       scripts/power-no-console-kit.conf \
+       scripts/power-no-services.conf \
+       scripts/power-no-login1.conf \
        scripts/plymouth-active-vt.conf \
        scripts/plymouth-inactive-vt.conf \
        scripts/plymouth-no-seat.conf \
diff --git a/tests/scripts/power-no-console-kit.conf b/tests/scripts/power-no-console-kit.conf
new file mode 100644 (file)
index 0000000..e346add
--- /dev/null
@@ -0,0 +1,68 @@
+#
+# Check can do power operations from the greeter when no ConsoleKit service
+#
+
+[test-runner-config]
+disable-console-kit=true
+
+[LightDM]
+minimum-display-number=50
+
+#?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 :50 START
+#?XSERVER :50 ACCEPT-CONNECT
+#?GREETER :50 CONNECT-XSERVER
+#?GREETER :50 CONNECT-TO-DAEMON
+#?GREETER :50 CONNECTED-TO-DAEMON
+
+# See if can suspend
+#?*GREETER :50 GET-CAN-SUSPEND
+#?UPOWER SUSPEND-ALLOWED
+#?GREETER :50 CAN-SUSPEND ALLOWED=TRUE
+
+# Suspend
+#?*GREETER :50 SUSPEND
+#?UPOWER SUSPEND
+
+# See if can hibernate
+#?*GREETER :50 GET-CAN-HIBERNATE
+#?UPOWER HIBERNATE-ALLOWED
+#?GREETER :50 CAN-HIBERNATE ALLOWED=TRUE
+
+# Hibernate
+#?*GREETER :50 HIBERNATE
+#?UPOWER HIBERNATE
+
+# See if can restart
+#?*GREETER :50 GET-CAN-RESTART
+#?LOGIN1 CAN-REBOOT
+#?GREETER :50 CAN-RESTART ALLOWED=TRUE
+
+# Restart
+#?*GREETER :50 RESTART
+#?LOGIN1 REBOOT
+
+# See if can shutdown
+#?*GREETER :50 GET-CAN-SHUTDOWN
+#?LOGIN1 CAN-POWER-OFF
+#?GREETER :50 CAN-SHUTDOWN ALLOWED=TRUE
+
+# Shutdown
+#?*GREETER :50 SHUTDOWN
+#?LOGIN1 POWER-OFF
+
+# Cleanup
+#?*STOP-DAEMON
+# Don't know what order they will terminate
+#?(GREETER :50 TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)
+#?(GREETER :50 TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)
+#?RUNNER DAEMON-EXIT STATUS=0
diff --git a/tests/scripts/power-no-login1.conf b/tests/scripts/power-no-login1.conf
new file mode 100644 (file)
index 0000000..0381294
--- /dev/null
@@ -0,0 +1,68 @@
+#
+# Check can do power operations from the greeter when no login1 service (falls back to ConsoleKit)
+#
+
+[test-runner-config]
+disable-login1=true
+
+[LightDM]
+minimum-display-number=50
+
+#?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 :50 START
+#?XSERVER :50 ACCEPT-CONNECT
+#?GREETER :50 CONNECT-XSERVER
+#?GREETER :50 CONNECT-TO-DAEMON
+#?GREETER :50 CONNECTED-TO-DAEMON
+
+# See if can suspend
+#?*GREETER :50 GET-CAN-SUSPEND
+#?UPOWER SUSPEND-ALLOWED
+#?GREETER :50 CAN-SUSPEND ALLOWED=TRUE
+
+# Suspend
+#?*GREETER :50 SUSPEND
+#?UPOWER SUSPEND
+
+# See if can hibernate
+#?*GREETER :50 GET-CAN-HIBERNATE
+#?UPOWER HIBERNATE-ALLOWED
+#?GREETER :50 CAN-HIBERNATE ALLOWED=TRUE
+
+# Hibernate
+#?*GREETER :50 HIBERNATE
+#?UPOWER HIBERNATE
+
+# See if can restart
+#?*GREETER :50 GET-CAN-RESTART
+#?CONSOLE-KIT CAN-RESTART
+#?GREETER :50 CAN-RESTART ALLOWED=TRUE
+
+# Restart
+#?*GREETER :50 RESTART
+#?CONSOLE-KIT RESTART
+
+# See if can shutdown
+#?*GREETER :50 GET-CAN-SHUTDOWN
+#?CONSOLE-KIT CAN-STOP
+#?GREETER :50 CAN-SHUTDOWN ALLOWED=TRUE
+
+# Shutdown
+#?*GREETER :50 SHUTDOWN
+#?CONSOLE-KIT STOP
+
+# Cleanup
+#?*STOP-DAEMON
+# Don't know what order they will terminate
+#?(GREETER :50 TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)
+#?(GREETER :50 TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)
+#?RUNNER DAEMON-EXIT STATUS=0
diff --git a/tests/scripts/power-no-services.conf b/tests/scripts/power-no-services.conf
new file mode 100644 (file)
index 0000000..d2fb628
--- /dev/null
@@ -0,0 +1,66 @@
+#
+# Check can do power operations from the greeter when no services running
+#
+
+[test-runner-config]
+disable-upower=true
+disable-console-kit=true
+disable-login1=true
+
+[LightDM]
+minimum-display-number=50
+
+#?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 :50 START
+#?XSERVER :50 ACCEPT-CONNECT
+#?GREETER :50 CONNECT-XSERVER
+#?GREETER :50 CONNECT-TO-DAEMON
+#?GREETER :50 CONNECTED-TO-DAEMON
+
+# See if can suspend
+#?*GREETER :50 GET-CAN-SUSPEND
+#?GREETER :50 CAN-SUSPEND ALLOWED=FALSE
+
+# Suspend
+#?*GREETER :50 SUSPEND
+#?GREETER :50 FAIL-SUSPEND
+
+# See if can hibernate
+#?*GREETER :50 GET-CAN-HIBERNATE
+#?GREETER :50 CAN-HIBERNATE ALLOWED=FALSE
+
+# Hibernate
+#?*GREETER :50 HIBERNATE
+#?GREETER :50 FAIL-HIBERNATE
+
+# See if can restart
+#?*GREETER :50 GET-CAN-RESTART
+#?GREETER :50 CAN-RESTART ALLOWED=FALSE
+
+# Restart
+#?*GREETER :50 RESTART
+#?GREETER :50 FAIL-RESTART
+
+# See if can shutdown
+#?*GREETER :50 GET-CAN-SHUTDOWN
+#?GREETER :50 CAN-SHUTDOWN ALLOWED=FALSE
+
+# Shutdown
+#?*GREETER :50 SHUTDOWN
+#?GREETER :50 FAIL-SHUTDOWN
+
+# Cleanup
+#?*STOP-DAEMON
+# Don't know what order they will terminate
+#?(GREETER :50 TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)
+#?(GREETER :50 TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)
+#?RUNNER DAEMON-EXIT STATUS=0
diff --git a/tests/scripts/power.conf b/tests/scripts/power.conf
new file mode 100644 (file)
index 0000000..a068fe9
--- /dev/null
@@ -0,0 +1,65 @@
+#
+# Check can do power operations from the greeter
+#
+
+[LightDM]
+minimum-display-number=50
+
+#?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 :50 START
+#?XSERVER :50 ACCEPT-CONNECT
+#?GREETER :50 CONNECT-XSERVER
+#?GREETER :50 CONNECT-TO-DAEMON
+#?GREETER :50 CONNECTED-TO-DAEMON
+
+# See if can suspend
+#?*GREETER :50 GET-CAN-SUSPEND
+#?UPOWER SUSPEND-ALLOWED
+#?GREETER :50 CAN-SUSPEND ALLOWED=TRUE
+
+# Suspend
+#?*GREETER :50 SUSPEND
+#?UPOWER SUSPEND
+
+# See if can hibernate
+#?*GREETER :50 GET-CAN-HIBERNATE
+#?UPOWER HIBERNATE-ALLOWED
+#?GREETER :50 CAN-HIBERNATE ALLOWED=TRUE
+
+# Hibernate
+#?*GREETER :50 HIBERNATE
+#?UPOWER HIBERNATE
+
+# See if can restart
+#?*GREETER :50 GET-CAN-RESTART
+#?LOGIN1 CAN-REBOOT
+#?GREETER :50 CAN-RESTART ALLOWED=TRUE
+
+# Restart
+#?*GREETER :50 RESTART
+#?LOGIN1 REBOOT
+
+# See if can shutdown
+#?*GREETER :50 GET-CAN-SHUTDOWN
+#?LOGIN1 CAN-POWER-OFF
+#?GREETER :50 CAN-SHUTDOWN ALLOWED=TRUE
+
+# Shutdown
+#?*GREETER :50 SHUTDOWN
+#?LOGIN1 POWER-OFF
+
+# Cleanup
+#?*STOP-DAEMON
+# Don't know what order they will terminate
+#?(GREETER :50 TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)
+#?(GREETER :50 TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)
+#?RUNNER DAEMON-EXIT STATUS=0
index b80b705a85901917ee70e70b9a0486a65151a45d..6244c91a6d785de75f0b94482882a2eb61b81f1c 100644 (file)
@@ -194,6 +194,78 @@ request_cb (const gchar *request)
         status_notify ("GREETER %s LOG-LANGUAGE USERNAME=%s LANGUAGE=%s", getenv ("DISPLAY"), username, language ? language : "");
     }
     g_free (r);
+
+    r = g_strdup_printf ("GREETER %s GET-CAN-SUSPEND", getenv ("DISPLAY"));
+    if (strcmp (request, r) == 0)
+    {
+        gboolean can_suspend = lightdm_get_can_suspend ();
+        status_notify ("GREETER %s CAN-SUSPEND ALLOWED=%s", getenv ("DISPLAY"), can_suspend ? "TRUE" : "FALSE");
+    }
+    g_free (r);
+
+    r = g_strdup_printf ("GREETER %s SUSPEND", getenv ("DISPLAY"));
+    if (strcmp (request, r) == 0)
+    {
+        GError *error = NULL;
+        if (!lightdm_suspend (&error))
+            status_notify ("GREETER %s FAIL-SUSPEND", getenv ("DISPLAY"));
+        g_clear_error (&error);
+    }
+    g_free (r);
+
+    r = g_strdup_printf ("GREETER %s GET-CAN-HIBERNATE", getenv ("DISPLAY"));
+    if (strcmp (request, r) == 0)
+    {
+        gboolean can_hibernate = lightdm_get_can_hibernate ();
+        status_notify ("GREETER %s CAN-HIBERNATE ALLOWED=%s", getenv ("DISPLAY"), can_hibernate ? "TRUE" : "FALSE");
+    }
+    g_free (r);
+
+    r = g_strdup_printf ("GREETER %s HIBERNATE", getenv ("DISPLAY"));
+    if (strcmp (request, r) == 0)
+    {
+        GError *error = NULL;
+        if (!lightdm_hibernate (&error))
+            status_notify ("GREETER %s FAIL-HIBERNATE", getenv ("DISPLAY"));
+        g_clear_error (&error);
+    }
+    g_free (r);
+
+    r = g_strdup_printf ("GREETER %s GET-CAN-RESTART", getenv ("DISPLAY"));
+    if (strcmp (request, r) == 0)
+    {
+        gboolean can_restart = lightdm_get_can_restart ();
+        status_notify ("GREETER %s CAN-RESTART ALLOWED=%s", getenv ("DISPLAY"), can_restart ? "TRUE" : "FALSE");
+    }
+    g_free (r);
+
+    r = g_strdup_printf ("GREETER %s RESTART", getenv ("DISPLAY"));
+    if (strcmp (request, r) == 0)
+    {
+        GError *error = NULL;
+        if (!lightdm_restart (&error))
+            status_notify ("GREETER %s FAIL-RESTART", getenv ("DISPLAY"));
+        g_clear_error (&error);
+    }
+    g_free (r);
+
+    r = g_strdup_printf ("GREETER %s GET-CAN-SHUTDOWN", getenv ("DISPLAY"));
+    if (strcmp (request, r) == 0)
+    {
+        gboolean can_shutdown = lightdm_get_can_shutdown ();
+        status_notify ("GREETER %s CAN-SHUTDOWN ALLOWED=%s", getenv ("DISPLAY"), can_shutdown ? "TRUE" : "FALSE");
+    }
+    g_free (r);
+
+    r = g_strdup_printf ("GREETER %s SHUTDOWN", getenv ("DISPLAY"));
+    if (strcmp (request, r) == 0)
+    {
+        GError *error = NULL;
+        if (!lightdm_shutdown (&error))
+            status_notify ("GREETER %s FAIL-SHUTDOWN", getenv ("DISPLAY"));
+        g_clear_error (&error);
+    }
+    g_free (r);
 }
 
 int
index 91050f180d3dfe1d3dd2ed75ef526c80dd3a177c..ca45b7b356ab1dc94c414e3c97a5aa34f87d39d0 100755 (executable)
@@ -94,6 +94,66 @@ def request_cb (channel, condition):
             language = ''
         status_notify ('GREETER %s LOG-LANGUAGE USERNAME=%s LANGUAGE=%s' % (os.getenv ('DISPLAY'), username, language))
 
+    r = 'GREETER %s GET-CAN-SUSPEND' % os.getenv ('DISPLAY')
+    if request == r:
+        if LightDM.get_can_suspend ():
+            allowed = "TRUE"
+        else:
+            allowed = "FALSE"
+        status_notify ('GREETER %s CAN-SUSPEND ALLOWED=%s' % (os.getenv ('DISPLAY'), allowed))
+
+    r = 'GREETER %s SUSPEND' % os.getenv ('DISPLAY')
+    if request == r:
+        try:
+            LightDM.suspend ()
+        except:
+            status_notify ('GREETER %s FAIL-SUSPEND' % os.getenv ('DISPLAY'))
+
+    r = 'GREETER %s GET-CAN-HIBERNATE' % os.getenv ('DISPLAY')
+    if request == r:
+        if LightDM.get_can_hibernate ():
+            allowed = "TRUE"
+        else:
+            allowed = "FALSE"
+        status_notify ('GREETER %s CAN-HIBERNATE ALLOWED=%s' % (os.getenv ('DISPLAY'), allowed))
+
+    r = 'GREETER %s HIBERNATE' % os.getenv ('DISPLAY')
+    if request == r:
+        try:
+            LightDM.hibernate ()
+        except:
+            status_notify ('GREETER %s FAIL-HIBERNATE' % os.getenv ('DISPLAY'))
+
+    r = 'GREETER %s GET-CAN-RESTART' % os.getenv ('DISPLAY')
+    if request == r:
+        if LightDM.get_can_restart ():
+            allowed = "TRUE"
+        else:
+            allowed = "FALSE"
+        status_notify ('GREETER %s CAN-RESTART ALLOWED=%s' % (os.getenv ('DISPLAY'), allowed))
+
+    r = 'GREETER %s RESTART' % os.getenv ('DISPLAY')
+    if request == r:
+        try:
+            LightDM.restart ()
+        except:
+            status_notify ('GREETER %s FAIL-RESTART' % os.getenv ('DISPLAY'))
+
+    r = 'GREETER %s GET-CAN-SHUTDOWN' % os.getenv ('DISPLAY')
+    if request == r:
+        if LightDM.get_can_shutdown ():
+            allowed = "TRUE"
+        else:
+            allowed = "FALSE"
+        status_notify ('GREETER %s CAN-SHUTDOWN ALLOWED=%s' % (os.getenv ('DISPLAY'), allowed))
+
+    r = 'GREETER %s SHUTDOWN' % os.getenv ('DISPLAY')
+    if request == r:
+        try:
+            LightDM.shutdown ()
+        except:
+            status_notify ('GREETER %s FAIL-SHUTDOWN' % os.getenv ('DISPLAY'))
+
     return True
 
 path = os.getenv ('LIGHTDM_TEST_ROOT') + '/.status-socket'
index 65926250b7c1d1abed56f5a537e28ecd515f9e11..b7ae3631477d07c6bc48e327a3a32910e33b2570 100644 (file)
@@ -5,6 +5,7 @@
 #include <glib-object.h>
 #include <xcb/xcb.h>
 #include <QLightDM/Greeter>
+#include <QLightDM/Power>
 #include <QtCore/QSettings>
 #include <QtCore/QDebug>
 #include <QtCore/QCoreApplication>
@@ -14,6 +15,7 @@
 
 static QCoreApplication *app = NULL;
 static QSettings *config = NULL;
+static QLightDM::PowerInterface *power = NULL;
 static TestGreeter *greeter = NULL;
 
 TestGreeter::TestGreeter ()
@@ -122,6 +124,70 @@ request_cb (const gchar *request)
             status_notify ("GREETER %s SESSION-FAILED", getenv ("DISPLAY"));
     }
     g_free (r);
+
+    r = g_strdup_printf ("GREETER %s GET-CAN-SUSPEND", getenv ("DISPLAY"));
+    if (strcmp (request, r) == 0)
+    {
+        gboolean can_suspend = power->canSuspend ();
+        status_notify ("GREETER %s CAN-SUSPEND ALLOWED=%s", getenv ("DISPLAY"), can_suspend ? "TRUE" : "FALSE");
+    }
+    g_free (r);
+
+    r = g_strdup_printf ("GREETER %s SUSPEND", getenv ("DISPLAY"));
+    if (strcmp (request, r) == 0)
+    {
+        if (!power->suspend ())
+            status_notify ("GREETER %s FAIL-SUSPEND", getenv ("DISPLAY"));
+    }
+    g_free (r);
+
+    r = g_strdup_printf ("GREETER %s GET-CAN-HIBERNATE", getenv ("DISPLAY"));
+    if (strcmp (request, r) == 0)
+    {
+        gboolean can_hibernate = power->canHibernate ();
+        status_notify ("GREETER %s CAN-HIBERNATE ALLOWED=%s", getenv ("DISPLAY"), can_hibernate ? "TRUE" : "FALSE");
+    }
+    g_free (r);
+
+    r = g_strdup_printf ("GREETER %s HIBERNATE", getenv ("DISPLAY"));
+    if (strcmp (request, r) == 0)
+    {
+        if (!power->hibernate ())
+            status_notify ("GREETER %s FAIL-HIBERNATE", getenv ("DISPLAY"));
+    }
+    g_free (r);
+
+    r = g_strdup_printf ("GREETER %s GET-CAN-RESTART", getenv ("DISPLAY"));
+    if (strcmp (request, r) == 0)
+    {
+        gboolean can_restart = power->canRestart ();
+        status_notify ("GREETER %s CAN-RESTART ALLOWED=%s", getenv ("DISPLAY"), can_restart ? "TRUE" : "FALSE");
+    }
+    g_free (r);
+
+    r = g_strdup_printf ("GREETER %s RESTART", getenv ("DISPLAY"));
+    if (strcmp (request, r) == 0)
+    {
+        if (!power->restart ())
+            status_notify ("GREETER %s FAIL-RESTART", getenv ("DISPLAY"));
+    }
+    g_free (r);
+
+    r = g_strdup_printf ("GREETER %s GET-CAN-SHUTDOWN", getenv ("DISPLAY"));
+    if (strcmp (request, r) == 0)
+    {
+        gboolean can_shutdown = power->canShutdown ();
+        status_notify ("GREETER %s CAN-SHUTDOWN ALLOWED=%s", getenv ("DISPLAY"), can_shutdown ? "TRUE" : "FALSE");
+    }
+    g_free (r);
+
+    r = g_strdup_printf ("GREETER %s SHUTDOWN", getenv ("DISPLAY"));
+    if (strcmp (request, r) == 0)
+    {
+        if (!power->shutdown ())
+            status_notify ("GREETER %s FAIL-SHUTDOWN", getenv ("DISPLAY"));
+    }
+    g_free (r);
 }
 
 int
@@ -152,6 +218,8 @@ main(int argc, char *argv[])
 
     status_notify ("GREETER %s CONNECT-XSERVER", getenv ("DISPLAY"));
 
+    power = new QLightDM::PowerInterface();
+
     greeter = new TestGreeter();
   
     status_notify ("GREETER %s CONNECT-TO-DAEMON", getenv ("DISPLAY"));
index 813a3733a33131417ce30ca33973ce91032b7e3d..ceb8a7f2884fa8cf711e67708f1621b107e70a6c 100644 (file)
@@ -625,6 +625,101 @@ load_script (const gchar *filename)
     g_strfreev (lines);
 }
 
+static void
+handle_upower_call (GDBusConnection       *connection,
+                    const gchar           *sender,
+                    const gchar           *object_path,
+                    const gchar           *interface_name,
+                    const gchar           *method_name,
+                    GVariant              *parameters,
+                    GDBusMethodInvocation *invocation,
+                    gpointer               user_data)
+{
+    if (strcmp (method_name, "SuspendAllowed") == 0)
+    {
+        check_status ("UPOWER SUSPEND-ALLOWED");
+        g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", TRUE));
+    }
+    else if (strcmp (method_name, "Suspend") == 0)
+    {
+        check_status ("UPOWER SUSPEND");
+        g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
+    }
+    else if (strcmp (method_name, "HibernateAllowed") == 0)
+    {
+        check_status ("UPOWER HIBERNATE-ALLOWED");
+        g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", TRUE));
+    }
+    else if (strcmp (method_name, "Hibernate") == 0)
+    {
+        check_status ("UPOWER HIBERNATE");
+        g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
+    }
+    else
+        g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No such method: %s", method_name);
+}
+
+static void
+upower_name_acquired_cb (GDBusConnection *connection,
+                         const gchar     *name,
+                         gpointer         user_data)
+{
+    const gchar *upower_interface =
+        "<node>"
+        "  <interface name='org.freedesktop.UPower'>"
+        "    <method name='SuspendAllowed'>"
+        "      <arg name='allowed' direction='out' type='b'/>"
+        "    </method>"
+        "    <method name='Suspend'/>"
+        "    <method name='HibernateAllowed'>"
+        "      <arg name='allowed' direction='out' type='b'/>"
+        "    </method>"
+        "    <method name='Hibernate'/>"
+        "  </interface>"
+        "</node>";
+    static const GDBusInterfaceVTable upower_vtable =
+    {
+        handle_upower_call,
+    };
+    GDBusNodeInfo *upower_info;
+    GError *error = NULL;
+
+    upower_info = g_dbus_node_info_new_for_xml (upower_interface, &error);
+    if (error)
+        g_warning ("Failed to parse D-Bus interface: %s", error->message);  
+    g_clear_error (&error);
+    if (!upower_info)
+        return;
+    g_dbus_connection_register_object (connection,
+                                       "/org/freedesktop/UPower",
+                                       upower_info->interfaces[0],
+                                       &upower_vtable,
+                                       NULL, NULL,
+                                       &error);
+    if (error)
+        g_warning ("Failed to register UPower service: %s", error->message);
+    g_clear_error (&error);
+    g_dbus_node_info_unref (upower_info);
+
+    service_count--;
+    if (service_count == 0)
+        run_lightdm ();
+}
+
+static void
+start_upower_daemon ()
+{
+    service_count++;
+    g_bus_own_name (G_BUS_TYPE_SYSTEM,
+                    "org.freedesktop.UPower",
+                    G_BUS_NAME_OWNER_FLAGS_NONE,
+                    upower_name_acquired_cb,
+                    NULL,
+                    NULL,
+                    NULL,
+                    NULL);
+}
+
 static CKSession *
 open_ck_session (GVariant *params)
 {
@@ -678,9 +773,15 @@ handle_ck_call (GDBusConnection       *connection,
                 gpointer               user_data)
 {
     if (strcmp (method_name, "CanRestart") == 0)
+    {
+        check_status ("CONSOLE-KIT CAN-RESTART");
         g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", TRUE));
+    }
     else if (strcmp (method_name, "CanStop") == 0)
+    {
+        check_status ("CONSOLE-KIT CAN-STOP");
         g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", TRUE));
+    }
     else if (strcmp (method_name, "CloseSession") == 0)
         g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", TRUE));
     else if (strcmp (method_name, "OpenSession") == 0)
@@ -715,9 +816,15 @@ handle_ck_call (GDBusConnection       *connection,
         g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Unable to find session for cookie");
     }
     else if (strcmp (method_name, "Restart") == 0)
+    {
+        check_status ("CONSOLE-KIT RESTART");
         g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
+    }
     else if (strcmp (method_name, "Stop") == 0)
+    {
+        check_status ("CONSOLE-KIT STOP");
         g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
+    }
     else
         g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No such method: %s", method_name);
 }
@@ -848,19 +955,27 @@ handle_login1_call (GDBusConnection       *connection,
                     gpointer               user_data)
 {
     if (strcmp (method_name, "CanReboot") == 0)
+    {
+        check_status ("LOGIN1 CAN-REBOOT");
         g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", "yes"));
+    }
     else if (strcmp (method_name, "Reboot") == 0)
     {
         gboolean interactive;
         g_variant_get (parameters, "(b)", &interactive);
+        check_status ("LOGIN1 REBOOT");
         g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
     }
-    if (strcmp (method_name, "CanPowerOff") == 0)
+    else if (strcmp (method_name, "CanPowerOff") == 0)
+    {
+        check_status ("LOGIN1 CAN-POWER-OFF");
         g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", "yes"));
+    }
     else if (strcmp (method_name, "PowerOff") == 0)
     {
         gboolean interactive;
         g_variant_get (parameters, "(b)", &interactive);
+        check_status ("LOGIN1 POWER-OFF");
         g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
     }
     else
@@ -1567,6 +1682,8 @@ main (int argc, char **argv)
     g_string_free (group_data, TRUE);
 
     /* Start D-Bus services */
+    if (!g_key_file_get_boolean (config, "test-runner-config", "disable-upower", NULL))
+        start_upower_daemon ();
     if (!g_key_file_get_boolean (config, "test-runner-config", "disable-console-kit", NULL))
         start_console_kit_daemon ();
     if (!g_key_file_get_boolean (config, "test-runner-config", "disable-login1", NULL))
diff --git a/tests/test-gobject-power b/tests/test-gobject-power
new file mode 100755 (executable)
index 0000000..da2743a
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner power test-gobject-greeter
diff --git a/tests/test-gobject-power-no-console-kit b/tests/test-gobject-power-no-console-kit
new file mode 100755 (executable)
index 0000000..3bd175c
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner power-no-console-kit test-gobject-greeter
diff --git a/tests/test-gobject-power-no-login1 b/tests/test-gobject-power-no-login1
new file mode 100755 (executable)
index 0000000..c59b888
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner power-no-login1 test-gobject-greeter
diff --git a/tests/test-gobject-power-no-services b/tests/test-gobject-power-no-services
new file mode 100755 (executable)
index 0000000..bf0b47e
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner power-no-services test-gobject-greeter
diff --git a/tests/test-python-power b/tests/test-python-power
new file mode 100755 (executable)
index 0000000..8cc7ec4
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner power test-python-greeter
diff --git a/tests/test-python-power-no-console-kit b/tests/test-python-power-no-console-kit
new file mode 100755 (executable)
index 0000000..7136108
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner power-no-console-kit test-python-greeter
diff --git a/tests/test-python-power-no-login1 b/tests/test-python-power-no-login1
new file mode 100755 (executable)
index 0000000..526abc2
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner power-no-login1 test-python-greeter
diff --git a/tests/test-python-power-no-services b/tests/test-python-power-no-services
new file mode 100755 (executable)
index 0000000..fa3381a
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner power-no-services test-python-greeter
diff --git a/tests/test-qt4-power b/tests/test-qt4-power
new file mode 100755 (executable)
index 0000000..11d7cb2
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner power test-qt4-greeter
diff --git a/tests/test-qt4-power-no-console-kit b/tests/test-qt4-power-no-console-kit
new file mode 100755 (executable)
index 0000000..91df1a1
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner power-no-console-kit test-qt4-greeter
diff --git a/tests/test-qt4-power-no-login1 b/tests/test-qt4-power-no-login1
new file mode 100755 (executable)
index 0000000..929176f
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner power-no-login1 test-qt4-greeter
diff --git a/tests/test-qt4-power-no-services b/tests/test-qt4-power-no-services
new file mode 100755 (executable)
index 0000000..866c577
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner power-no-services test-qt4-greeter
diff --git a/tests/test-qt5-power b/tests/test-qt5-power
new file mode 100755 (executable)
index 0000000..de0f4f0
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner power test-qt5-greeter
diff --git a/tests/test-qt5-power-no-console-kit b/tests/test-qt5-power-no-console-kit
new file mode 100755 (executable)
index 0000000..f8d2718
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner power-no-console-kit test-qt5-greeter
diff --git a/tests/test-qt5-power-no-login1 b/tests/test-qt5-power-no-login1
new file mode 100755 (executable)
index 0000000..6fe8689
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner power-no-login1 test-qt5-greeter
diff --git a/tests/test-qt5-power-no-services b/tests/test-qt5-power-no-services
new file mode 100755 (executable)
index 0000000..a0a39bd
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner power-no-services test-qt5-greeter