on xenial help sign in
Don't crash because we blocked a method from returning while deleting qml objects; instead just delay signal emission
commit3ddfbee20ba3bfe68d4ab75bd5c1825ebd0ef2eb authorMichael Terry <michael.terry@canonical.com> dateThu 31 Jul 2014, 16:59 (12 years ago) parent551a661
5 files changed+19−35
tests/mocks/LightDM/Greeter.cpp+11 tests/mocks/LightDM/Greeter.h+3 tests/mocks/LightDM/full/GreeterPrivate.cpp+3−13 tests/mocks/LightDM/single-passphrase/GreeterPrivate.cpp+1−11 tests/mocks/LightDM/single-pin/GreeterPrivate.cpp+1−11
tests/mocks/LightDM/Greeter.cpp+11
@@ -19,6 +19,7 @@
1919#include "Greeter.h"
2020#include "GreeterPrivate.h"
2121#include <QtCore/QCoreApplication>
22+#include <QTimer>
2223
2324namespace QLightDM
2425{
@@ -164,4 +165,14 @@ void Greeter::respond(const QString &response)
164165 d->handleRespond(response);
165166}
166167
168+void Greeter::sendAuthenticationComplete()
169+{
170+ if (qgetenv("UNITY_TESTING").isEmpty()) {
171+ // simulate PAM's delay
172+ QTimer::singleShot(1000, this, SIGNAL(authenticationComplete()));
173+ } else {
174+ Q_EMIT authenticationComplete();
175+ }
176+}
177+
167178}
tests/mocks/LightDM/Greeter.h+3
@@ -96,6 +96,9 @@ Q_SIGNALS:
9696 void authenticationComplete();
9797 void autologinTimerExpired();
9898
99+protected:
100+ void sendAuthenticationComplete();
101+
99102private:
100103 GreeterPrivate *d_ptr;
101104 Q_DECLARE_PRIVATE(Greeter)
tests/mocks/LightDM/full/GreeterPrivate.cpp+3−13
@@ -19,9 +19,6 @@
1919#include "../Greeter.h"
2020#include "../GreeterPrivate.h"
2121
22−#include <QEventLoop>
23−#include <QTimer>
24−
2522namespace QLightDM
2623{
2724
@@ -72,13 +69,6 @@ void GreeterPrivate::handleRespond(const QString &response)
7269{
7370 Q_Q(Greeter);
7471
75− if (qgetenv("UNITY_TESTING").isEmpty()) {
76− // simulate PAM's delay
77− QEventLoop loop;
78− QTimer::singleShot(1000, &loop, SLOT(quit()));
79− loop.exec();
80− }
81−
8272 if (authenticationUser == "no-response")
8373 return;
8474 else if (authenticationUser == "two-factor") {
@@ -88,11 +78,11 @@ void GreeterPrivate::handleRespond(const QString &response)
8878 Q_EMIT q->showPrompt("otp", Greeter::PromptTypeQuestion);
8979 } else {
9080 authenticated = false;
91− Q_EMIT q->authenticationComplete();
81+ q->sendAuthenticationComplete();
9282 }
9383 } else {
9484 authenticated = (response == "otp");
95− Q_EMIT q->authenticationComplete();
85+ q->sendAuthenticationComplete();
9686 }
9787 return;
9888 }
@@ -102,7 +92,7 @@ void GreeterPrivate::handleRespond(const QString &response)
10292 } else {
10393 authenticated = (response == "password");
10494 }
105− Q_EMIT q->authenticationComplete();
95+ q->sendAuthenticationComplete();
10696}
10797
10898}
tests/mocks/LightDM/single-passphrase/GreeterPrivate.cpp+1−11
@@ -19,9 +19,6 @@
1919#include "../Greeter.h"
2020#include "../GreeterPrivate.h"
2121
22−#include <QEventLoop>
23−#include <QTimer>
24−
2522namespace QLightDM
2623{
2724
@@ -42,15 +39,8 @@ void GreeterPrivate::handleRespond(const QString &response)
4239{
4340 Q_Q(Greeter);
4441
45− if (qgetenv("UNITY_TESTING").isEmpty()) {
46− // simulate PAM's delay
47− QEventLoop loop;
48− QTimer::singleShot(1000, &loop, SLOT(quit()));
49− loop.exec();
50− }
51−
5242 authenticated = (response == "password");
53− Q_EMIT q->authenticationComplete();
43+ q->sendAuthenticationComplete();
5444}
5545
5646}
tests/mocks/LightDM/single-pin/GreeterPrivate.cpp+1−11
@@ -19,9 +19,6 @@
1919#include "../Greeter.h"
2020#include "../GreeterPrivate.h"
2121
22−#include <QEventLoop>
23−#include <QTimer>
24−
2522namespace QLightDM
2623{
2724
@@ -42,15 +39,8 @@ void GreeterPrivate::handleRespond(const QString &response)
4239{
4340 Q_Q(Greeter);
4441
45− if (qgetenv("UNITY_TESTING").isEmpty()) {
46− // simulate PAM's delay
47− QEventLoop loop;
48− QTimer::singleShot(1000, &loop, SLOT(quit()));
49− loop.exec();
50− }
51−
5242 authenticated = (response == "1234");
53− Q_EMIT q->authenticationComplete();
43+ q->sendAuthenticationComplete();
5444}
5545
5646}