forked from qt-creator/qt-creator
SSH: Fix autotest
The SshX11InfoRetriever object must not be allocated on the stack, and the failure signal was potentially emitted too early for the test to catch it. Change-Id: Iac53546deee183c8f02bafdcc11a7910f3e392c0 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#include <QByteArrayList>
|
||||
#include <QProcess>
|
||||
#include <QTemporaryFile>
|
||||
#include <QTimer>
|
||||
|
||||
#include <botan/auto_rng.h>
|
||||
|
||||
@@ -142,8 +143,10 @@ void SshX11InfoRetriever::start()
|
||||
|
||||
void SshX11InfoRetriever::emitFailure(const QString &reason)
|
||||
{
|
||||
emit failure(tr("Could not retrieve X11 authentication cookie: %1").arg(reason));
|
||||
deleteLater();
|
||||
QTimer::singleShot(0, this, [this, reason] {
|
||||
emit failure(tr("Could not retrieve X11 authentication cookie: %1").arg(reason));
|
||||
deleteLater();
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -849,7 +849,7 @@ void tst_Ssh::x11InfoRetriever()
|
||||
QFETCH(QString, displayName);
|
||||
QFETCH(bool, successExpected);
|
||||
using namespace QSsh::Internal;
|
||||
SshX11InfoRetriever x11InfoRetriever(displayName);
|
||||
auto * const x11InfoRetriever = new SshX11InfoRetriever(displayName);
|
||||
QEventLoop loop;
|
||||
bool success;
|
||||
X11DisplayInfo displayInfo;
|
||||
@@ -859,19 +859,19 @@ void tst_Ssh::x11InfoRetriever()
|
||||
displayInfo = di;
|
||||
loop.quit();
|
||||
};
|
||||
connect(&x11InfoRetriever, &SshX11InfoRetriever::success, successHandler);
|
||||
connect(x11InfoRetriever, &SshX11InfoRetriever::success, successHandler);
|
||||
const auto failureHandler = [&loop, &success, &errorMessage](const QString &error) {
|
||||
success = false;
|
||||
errorMessage = error;
|
||||
loop.quit();
|
||||
};
|
||||
connect(&x11InfoRetriever, &SshX11InfoRetriever::failure, failureHandler);
|
||||
connect(x11InfoRetriever, &SshX11InfoRetriever::failure, failureHandler);
|
||||
QTimer timer;
|
||||
QObject::connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
|
||||
timer.setSingleShot(true);
|
||||
timer.setInterval(40000);
|
||||
timer.start();
|
||||
x11InfoRetriever.start();
|
||||
x11InfoRetriever->start();
|
||||
loop.exec();
|
||||
QVERIFY(timer.isActive());
|
||||
timer.stop();
|
||||
|
Reference in New Issue
Block a user