on de035fa help sign in
88 lines 2.6 kB history raw
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Michael Terry <michael.terry@canonical.com>
18 */
20#include "SessionManager.h"
21#include <QtTest/QSignalSpy>
22#include <QtTest/QTest>
25// These tests assume the following behavior from our mock logind server:
26// * IsActive will return false
27// * Lock() will emit an ActiveChanged(true) signal
28//
29// This should lead to the following behavior from our SessionManager plugin:
30// * Starts active
31// * Becomes inactive once it connects to logind and sees IsActive result
32// * Becomes active once Lock() is called (which isn't really sensible, but
33// it's just a mock)
35class SessionManagerTest : public QObject
37 Q_OBJECT
39private Q_SLOTS:
41 void waitForChange(SessionManager *session)
42 {
43 // Wait 5 seconds for initial activeChanged signal
44 QSignalSpy spy(session, SIGNAL(activeChanged()));
45 int i = 0;
46 while (spy.count() == 0 && i++ < 50)
47 QTest::qWait(100);
48 QCOMPARE(spy.count(), 1);
49 }
51 void testAssumeActive()
52 {
53 // Test that active() starts as true before we connect to service
54 SessionManager session;
55 QCOMPARE(session.active(), true);
56 }
58 void testSafeLock()
59 {
60 // Test that lock() doesn't crash if used before we connect to service
61 // (i.e. just test that we're not being stupid about pointers)
62 SessionManager session;
63 session.lock();
64 }
66 void testInitialSignal()
67 {
68 // Test that we get notified of change once we connect to service
69 SessionManager session;
70 waitForChange(&session);
71 QCOMPARE(session.active(), false);
72 }
74 void testLock()
75 {
76 // Test that lock() gets called correctly and that we listen for
77 // the activeChanged signal too.
78 SessionManager session;
79 waitForChange(&session);
80 session.lock();
81 waitForChange(&session);
82 QCOMPARE(session.active(), true);
83 }
84};
86QTEST_MAIN(SessionManagerTest)
88#include "client.moc"