@@ -0,0 +1,120 @@
1+/*
2+ * Copyright (C) 2013 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 "Greeter.h"
18+
19+#include <QDBusInterface>
20+#include <QDBusReply>
21+#include <QSignalSpy>
22+#include <QQuickItem>
23+#include <QQuickView>
24+#include <QtTestGui>
25+
26+class GreeterDBusTest : public QObject
27+{
28+ Q_OBJECT
29+
30+private Q_SLOTS:
31+
32+ void init()
33+ {
34+ view = new QQuickView();
35+ view->setSource(QUrl::fromLocalFile(CURRENT_SOURCE_DIR "/greeter.qml"));
36+ greeter = dynamic_cast<Greeter*>(view->rootObject()->property("greeter").value<QObject*>());
37+ QVERIFY(greeter);
38+ QVERIFY(greeter->authenticationUser() == "");
39+ view->show();
40+ QTest::qWaitForWindowExposed(view);
41+
42+ dbusList = new QDBusInterface("com.canonical.UnityGreeter",
43+ "/list",
44+ "com.canonical.UnityGreeter.List",
45+ QDBusConnection::sessionBus(), view);
46+ QVERIFY(dbusList->isValid());
47+ }
48+
49+ void cleanup()
50+ {
51+ delete view;
52+ }
53+
54+ void testGetActiveEntry()
55+ {
56+ greeter->authenticate("has-password");
57+
58+ QDBusReply<QString> reply = dbusList->call("GetActiveEntry");
59+ QVERIFY(reply.isValid());
60+ QVERIFY(reply.value() == "has-password");
61+ }
62+
63+ void testSetActiveEntry()
64+ {
65+ QSignalSpy spy(greeter, SIGNAL(requestAuthenticationUser(QString)));
66+ QDBusReply<void> reply = dbusList->call("SetActiveEntry", "has-password");
67+ QVERIFY(reply.isValid());
68+ spy.wait();
69+
70+ QCOMPARE(spy.count(), 1);
71+ QList<QVariant> arguments = spy.takeFirst();
72+ QVERIFY(arguments.at(0).toString() == "has-password");
73+ }
74+
75+ void testEntrySelectedSignal()
76+ {
77+ QSignalSpy spy(dbusList, SIGNAL(EntrySelected(QString)));
78+ greeter->authenticate("has-password");
79+ spy.wait();
80+
81+ QCOMPARE(spy.count(), 1);
82+ QList<QVariant> arguments = spy.takeFirst();
83+ QVERIFY(arguments.at(0).toString() == "has-password");
84+ }
85+
86+ void testActiveEntryGet()
87+ {
88+ greeter->authenticate("has-password");
89+ QVERIFY(dbusList->property("ActiveEntry").toString() == "has-password");
90+ }
91+
92+ void testActiveEntrySet()
93+ {
94+ QSignalSpy spy(greeter, SIGNAL(requestAuthenticationUser(QString)));
95+ QVERIFY(dbusList->setProperty("ActiveEntry", "has-password"));
96+ spy.wait();
97+
98+ QCOMPARE(spy.count(), 1);
99+ QList<QVariant> arguments = spy.takeFirst();
100+ QVERIFY(arguments.at(0).toString() == "has-password");
101+ }
102+
103+ void testEntryIsLockedGet()
104+ {
105+ greeter->authenticate("has-password");
106+ QVERIFY(dbusList->property("EntryIsLocked").toBool());
107+
108+ greeter->authenticate("no-password");
109+ QVERIFY(!dbusList->property("EntryIsLocked").toBool());
110+ }
111+
112+private:
113+ QQuickView *view;
114+ Greeter *greeter;
115+ QDBusInterface *dbusList;
116+};
117+
118+QTEST_MAIN(GreeterDBusTest)
119+
120+#include "dbus.moc"