on xenial help sign in
Add test for watch code
commitdb71975d301e146adb0cd775fb2f8187caf64d31 authorMichael Terry <michael.terry@canonical.com> dateTue 8 Mar 2016, 13:07 (11 years ago) parent9ed586e
5 files changed+133−7
plugins/IntegratedLightDM/liblightdm/CMakeLists.txt+12−3 plugins/IntegratedLightDM/liblightdm/UsersModelPrivate.cpp+2−2 tests/plugins/AccountsService/PropertiesServer.cpp+3−2 tests/plugins/IntegratedLightDM/CMakeLists.txt+25 tests/plugins/IntegratedLightDM/integrated.cpp+91
plugins/IntegratedLightDM/liblightdm/CMakeLists.txt+12−3
@@ -1,7 +1,5 @@
11pkg_check_modules(LIBUSERMETRICSOUTPUT REQUIRED libusermetricsoutput-1)
22
3−add_definitions(-DSM_BUSNAME=systemBus)
4−
53set(LibLightDM_SOURCES
64 Greeter.cpp
75 UsersModel.cpp
@@ -12,6 +10,7 @@ set(LibLightDM_SOURCES
1210 )
1311
1412add_library(integratedLightDM STATIC ${LibLightDM_SOURCES})
13+add_library(integratedLightDMSession STATIC ${LibLightDM_SOURCES})
1514add_library(MockLightDM-demo-shared SHARED ${LibLightDM_SOURCES})
1615
1716include_directories(
@@ -26,6 +25,11 @@ target_link_libraries(integratedLightDM
2625 ${LIBUSERMETRICSOUTPUT_LDFLAGS}
2726 -lpam
2827)
28+target_link_libraries(integratedLightDMSession
29+ ${GLIB_LIBRARIES}
30+ ${LIBUSERMETRICSOUTPUT_LDFLAGS}
31+ -lpam
32+)
2933target_link_libraries(MockLightDM-demo-shared
3034 ${GLIB_LIBRARIES}
3135 ${LIBUSERMETRICSOUTPUT_LDFLAGS}
@@ -33,10 +37,15 @@ target_link_libraries(MockLightDM-demo-shared
3337)
3438
3539qt5_use_modules(integratedLightDM Concurrent DBus Gui)
40+qt5_use_modules(integratedLightDMSession Concurrent DBus Gui)
3641qt5_use_modules(MockLightDM-demo-shared Concurrent DBus Gui)
3742
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")
3947set_target_properties(MockLightDM-demo-shared PROPERTIES
48+ COMPILE_FLAGS "-DSM_BUSNAME=systemBus"
4049 OUTPUT_NAME lightdm-qt5-2)
4150
4251install(TARGETS MockLightDM-demo-shared
plugins/IntegratedLightDM/liblightdm/UsersModelPrivate.cpp+2−2
@@ -19,6 +19,7 @@
1919#include "UsersModelPrivate.h"
2020
2121#include "AccountsServiceDBusAdaptor.h"
22+#include "UsersModel.h"
2223
2324#include <glib.h>
2425#include <QDebug>
@@ -30,7 +31,7 @@ namespace QLightDM
3031{
3132
3233UsersModelPrivate::UsersModelPrivate(UsersModel* parent)
33− : QObject((QObject*)parent),
34+ : QObject(parent),
3435 q_ptr(parent),
3536 m_service(new AccountsServiceDBusAdaptor(this))
3637{
@@ -85,7 +86,6 @@ void UsersModelPrivate::updateName(bool async)
8586 });
8687 if (!async) {
8788 watcher->waitForFinished();
88− delete watcher;
8989 }
9090}
9191
tests/plugins/AccountsService/PropertiesServer.cpp+3−2
@@ -57,8 +57,8 @@ void PropertiesServer::Set(const QString &interface, const QString &property, co
5757
5858 oldValue = newValue;
5959
60− // Special case for Background file.
61− if (interface == "org.freedesktop.Accounts.User" && property == "BackgroundFile") {
60+ // Special case for user properties.
61+ if (interface == "org.freedesktop.Accounts.User") {
6262 Q_EMIT Changed();
6363 } else {
6464 QVariantMap propertyChanges;
@@ -88,4 +88,5 @@ void PropertiesServer::Reset()
8888 m_properties["com.ubuntu.location.providers.here.AccountsService"]["LicenseAccepted"] = false;
8989 m_properties["com.ubuntu.location.providers.here.AccountsService"]["LicenseBasePath"] = "";
9090 m_properties["org.freedesktop.Accounts.User"]["BackgroundFile"] = "";
91+ m_properties["org.freedesktop.Accounts.User"]["RealName"] = "";
9192}
tests/plugins/IntegratedLightDM/CMakeLists.txt+25
@@ -65,3 +65,28 @@ add_unity8_uitest(GreeterUsers GreeterUsersModelTestExec
6565 DEPENDS MockLightDM
6666 LIGHTDM
6767 )
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"