on xenial help sign in
Add test for watch code
db71975Michael Terry
plugins/IntegratedLightDM/liblightdm/CMakeLists.txt+12−3
@@ -1,7 +1,5 @@
1pkg_check_modules(LIBUSERMETRICSOUTPUT REQUIRED libusermetricsoutput-1)
1pkg_check_modules(LIBUSERMETRICSOUTPUT REQUIRED libusermetricsoutput-1)
2
2
3−add_definitions(-DSM_BUSNAME=systemBus)
4−
5set(LibLightDM_SOURCES
3set(LibLightDM_SOURCES
6 Greeter.cpp
4 Greeter.cpp
7 UsersModel.cpp
5 UsersModel.cpp
@@ -12,6 +10,7 @@ set(LibLightDM_SOURCES
12 )
10 )
13
11
14add_library(integratedLightDM STATIC ${LibLightDM_SOURCES})
12add_library(integratedLightDM STATIC ${LibLightDM_SOURCES})
13+add_library(integratedLightDMSession STATIC ${LibLightDM_SOURCES})
15add_library(MockLightDM-demo-shared SHARED ${LibLightDM_SOURCES})
14add_library(MockLightDM-demo-shared SHARED ${LibLightDM_SOURCES})
16
15
17include_directories(
16include_directories(
@@ -26,6 +25,11 @@ target_link_libraries(integratedLightDM
26 ${LIBUSERMETRICSOUTPUT_LDFLAGS}
25 ${LIBUSERMETRICSOUTPUT_LDFLAGS}
27 -lpam
26 -lpam
28)
27)
28+target_link_libraries(integratedLightDMSession
29+ ${GLIB_LIBRARIES}
30+ ${LIBUSERMETRICSOUTPUT_LDFLAGS}
31+ -lpam
32+)
29target_link_libraries(MockLightDM-demo-shared
33target_link_libraries(MockLightDM-demo-shared
30 ${GLIB_LIBRARIES}
34 ${GLIB_LIBRARIES}
31 ${LIBUSERMETRICSOUTPUT_LDFLAGS}
35 ${LIBUSERMETRICSOUTPUT_LDFLAGS}
@@ -33,10 +37,15 @@ target_link_libraries(MockLightDM-demo-shared
33)
37)
34
38
35qt5_use_modules(integratedLightDM Concurrent DBus Gui)
39qt5_use_modules(integratedLightDM Concurrent DBus Gui)
40+qt5_use_modules(integratedLightDMSession Concurrent DBus Gui)
36qt5_use_modules(MockLightDM-demo-shared Concurrent DBus Gui)
41qt5_use_modules(MockLightDM-demo-shared Concurrent DBus Gui)
37
42
38−set_target_properties(integratedLightDM PROPERTIES COMPILE_FLAGS -fPIC)
43+set_target_properties(integratedLightDM PROPERTIES
44+ COMPILE_FLAGS "-DSM_BUSNAME=systemBus -fPIC")
45+set_target_properties(integratedLightDMSession PROPERTIES
46+ COMPILE_FLAGS "-DSM_BUSNAME=sessionBus -fPIC")
39set_target_properties(MockLightDM-demo-shared PROPERTIES
47set_target_properties(MockLightDM-demo-shared PROPERTIES
48+ COMPILE_FLAGS "-DSM_BUSNAME=systemBus"
40 OUTPUT_NAME lightdm-qt5-2)
49 OUTPUT_NAME lightdm-qt5-2)
41
50
42install(TARGETS MockLightDM-demo-shared
51install(TARGETS MockLightDM-demo-shared
plugins/IntegratedLightDM/liblightdm/UsersModelPrivate.cpp+2−2
@@ -19,6 +19,7 @@
19#include "UsersModelPrivate.h"
19#include "UsersModelPrivate.h"
20
20
21#include "AccountsServiceDBusAdaptor.h"
21#include "AccountsServiceDBusAdaptor.h"
22+#include "UsersModel.h"
22
23
23#include <glib.h>
24#include <glib.h>
24#include <QDebug>
25#include <QDebug>
@@ -30,7 +31,7 @@ namespace QLightDM
30{
31{
31
32
32UsersModelPrivate::UsersModelPrivate(UsersModel* parent)
33UsersModelPrivate::UsersModelPrivate(UsersModel* parent)
33− : QObject((QObject*)parent),
34+ : QObject(parent),
34 q_ptr(parent),
35 q_ptr(parent),
35 m_service(new AccountsServiceDBusAdaptor(this))
36 m_service(new AccountsServiceDBusAdaptor(this))
36{
37{
@@ -85,7 +86,6 @@ void UsersModelPrivate::updateName(bool async)
85 });
86 });
86 if (!async) {
87 if (!async) {
87 watcher->waitForFinished();
88 watcher->waitForFinished();
88− delete watcher;
89 }
89 }
90}
90}
91
91
tests/plugins/AccountsService/PropertiesServer.cpp+3−2
@@ -57,8 +57,8 @@ void PropertiesServer::Set(const QString &interface, const QString &property, co
57
57
58 oldValue = newValue;
58 oldValue = newValue;
59
59
60− // Special case for Background file.
60+ // Special case for user properties.
61− if (interface == "org.freedesktop.Accounts.User" && property == "BackgroundFile") {
61+ if (interface == "org.freedesktop.Accounts.User") {
62 Q_EMIT Changed();
62 Q_EMIT Changed();
63 } else {
63 } else {
64 QVariantMap propertyChanges;
64 QVariantMap propertyChanges;
@@ -88,4 +88,5 @@ void PropertiesServer::Reset()
88 m_properties["com.ubuntu.location.providers.here.AccountsService"]["LicenseAccepted"] = false;
88 m_properties["com.ubuntu.location.providers.here.AccountsService"]["LicenseAccepted"] = false;
89 m_properties["com.ubuntu.location.providers.here.AccountsService"]["LicenseBasePath"] = "";
89 m_properties["com.ubuntu.location.providers.here.AccountsService"]["LicenseBasePath"] = "";
90 m_properties["org.freedesktop.Accounts.User"]["BackgroundFile"] = "";
90 m_properties["org.freedesktop.Accounts.User"]["BackgroundFile"] = "";
91+ m_properties["org.freedesktop.Accounts.User"]["RealName"] = "";
91}
92}
tests/plugins/IntegratedLightDM/CMakeLists.txt+25
@@ -65,3 +65,28 @@ add_unity8_uitest(GreeterUsers GreeterUsersModelTestExec
65 DEPENDS MockLightDM
65 DEPENDS MockLightDM
66 LIGHTDM
66 LIGHTDM
67 )
67 )
68+
69+add_executable(GreeterIntegratedTestExec
70+ integrated.cpp
71+ )
72+qt5_use_modules(GreeterIntegratedTestExec Core DBus Quick Test)
73+target_link_libraries(GreeterIntegratedTestExec
74+ ${GLIB_LIBRARIES}
75+ integratedLightDMSession
76+ )
77+target_include_directories(GreeterIntegratedTestExec PUBLIC
78+ ${GLIB_INCLUDE_DIRS}
79+ ${CMAKE_SOURCE_DIR}/plugins/IntegratedLightDM/liblightdm
80+ )
81+add_unity8_unittest(GreeterIntegrated dbus-test-runner
82+ ENVIRONMENT LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/plugins/IntegratedLightDM/liblightdm/
83+ ARG_PREFIX "--parameter"
84+ ARGS
85+ --task $<TARGET_FILE:mock-server>
86+ --task-name server
87+ --ignore-return
88+ --task $<TARGET_FILE:GreeterIntegratedTestExec>
89+ --task-name client
90+ --wait-for org.freedesktop.Accounts
91+ DEPENDS integratedLightDMSession
92+ )
tests/plugins/IntegratedLightDM/integrated.cppnew file+91
@@ -0,0 +1,91 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "UsersModel.h"
18+
19+#include <glib.h>
20+#include <QDBusInterface>
21+#include <QDBusReply>
22+#include <QtTest>
23+
24+class GreeterIntegratedTest : public QObject
25+{
26+ Q_OBJECT
27+
28+private Q_SLOTS:
29+
30+ void init()
31+ {
32+ m_accounts = new QDBusInterface(QStringLiteral("org.freedesktop.Accounts"),
33+ QStringLiteral("/org/freedesktop/Accounts"),
34+ QStringLiteral("org.freedesktop.Accounts"),
35+ QDBusConnection::sessionBus());
36+ QDBusReply<bool> addReply = m_accounts->call(QStringLiteral("AddUser"),
37+ g_get_user_name());
38+ QVERIFY(addReply.isValid());
39+ QCOMPARE(addReply.value(), true);
40+
41+ m_user = new QDBusInterface(QStringLiteral("org.freedesktop.Accounts"),
42+ QStringLiteral("/%1").arg(g_get_user_name()),
43+ QStringLiteral("org.freedesktop.DBus.Properties"),
44+ QDBusConnection::sessionBus());
45+
46+ m_model = new QLightDM::UsersModel();
47+ QVERIFY(m_model);
48+ }
49+
50+ void cleanup()
51+ {
52+ QDBusReply<bool> addReply = m_accounts->call(QStringLiteral("RemoveUser"),
53+ g_get_user_name());
54+ QVERIFY(addReply.isValid());
55+ QCOMPARE(addReply.value(), true);
56+
57+ delete m_model;
58+ delete m_accounts;
59+ delete m_user;
60+ }
61+
62+ void testWatchRealName()
63+ {
64+ auto index = m_model->index(0, 0);
65+
66+ QCOMPARE(m_model->data(index, QLightDM::UsersModel::RealNameRole).toString(),
67+ QStringLiteral(""));
68+
69+ // The real AccountsService doesn't let you set via dbus properties. You
70+ // have to call SetRealName instead (so that they can protect the call
71+ // via policykit). But our test server does let us.
72+ QVariant wrapped = QVariant::fromValue(QDBusVariant(QStringLiteral("Test User")));
73+ QDBusReply<void> reply = m_user->call(QStringLiteral("Set"),
74+ QStringLiteral("org.freedesktop.Accounts.User"),
75+ QStringLiteral("RealName"),
76+ wrapped);
77+ QVERIFY(reply.isValid());
78+
79+ QTRY_COMPARE(m_model->data(index, QLightDM::UsersModel::RealNameRole).toString(),
80+ QStringLiteral("Test User"));
81+ }
82+
83+private:
84+ QLightDM::UsersModel *m_model;
85+ QDBusInterface *m_accounts;
86+ QDBusInterface *m_user;
87+};
88+
89+QTEST_MAIN(GreeterIntegratedTest)
90+
91+#include "integrated.moc"