1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
/*
clientconnectiontest.cpp
This file is part of GammaRay, the Qt application inspection and manipulation tool.
SPDX-FileCopyrightText: 2017 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
Author: Filipe Azevedo <filipe.azevedo@kdab.com>
SPDX-License-Identifier: GPL-2.0-or-later
Contact KDAB at <info@kdab.com> for commercial licensing options.
*/
#include <config-gammaray.h>
#include <gammaray-test-config.h>
#include "testhelpers.h"
#include <client/clientconnectionmanager.h>
#include <common/endpoint.h>
#include <launcher/core/launcher.h>
#include <launcher/core/launchoptions.h>
#include <launcher/core/probeabidetector.h>
#include <launcher/core/probefinder.h>
#include <QProcess>
#include <QSignalSpy>
#include <QTest>
#ifdef Q_OS_WIN
#include <qt_windows.h>
#endif
using namespace GammaRay;
using namespace TestHelpers;
class ClientConnectionTest : public QObject
{
Q_OBJECT
public:
explicit ClientConnectionTest(QObject *parent = nullptr)
: QObject(parent)
{
}
private slots:
void initTestCase()
{
ClientConnectionManager::init();
m_process.setProcessChannelMode(QProcess::ForwardedChannels);
m_process.start(QLatin1String(TESTBIN_DIR "/minimalwidgetapplication"), QStringList {});
QVERIFY(m_process.waitForStarted());
QTest::qWait(1000); // give the target some time to actually load the QtCore DLL, otherwise ABI detection fails
{
LaunchOptions options;
options.setUiMode(LaunchOptions::NoUi);
options.setProbeSetting(QStringLiteral("ServerAddress"), GAMMARAY_DEFAULT_LOCAL_TCP_URL);
options.setPid(m_process.processId());
ProbeABIDetector detector;
options.setProbeABI(ProbeFinder::findBestMatchingABI(detector.abiForProcess(options.pid())));
Launcher launcher(options);
QSignalSpy spy(&launcher, &Launcher::attached);
QVERIFY(spy.isValid());
QVERIFY(launcher.start());
spy.wait(30000);
QCOMPARE(spy.size(), 1);
m_serverUrl = launcher.serverAddress();
QVERIFY(m_serverUrl.isValid());
QVERIFY(m_serverUrl.port() != -1);
}
}
void testMultipleConnection()
{
ClientConnectionManager connector(nullptr, false);
QSignalSpy spyReady(&connector, &ClientConnectionManager::ready);
QSignalSpy spyError(&connector, &ClientConnectionManager::persistentConnectionError);
QSignalSpy spyDisconnected(&connector, &ClientConnectionManager::disconnected);
QVERIFY(spyReady.isValid());
QVERIFY(spyError.isValid());
QVERIFY(spyDisconnected.isValid());
for (int i = 0; i < 5; ++i) {
qWarning("Phase: #%i", i);
spyReady.clear();
spyError.clear();
spyDisconnected.clear();
connector.connectToHost(m_serverUrl);
int loops = 0;
while (loops++ < (30000 / 10)) {
QTest::qWait(10);
if (!spyReady.isEmpty()
|| !spyError.isEmpty()
|| !spyDisconnected.isEmpty()) {
break;
}
}
QVERIFY(spyReady.size() == 1);
QVERIFY(Endpoint::isConnected());
QCOMPARE(m_process.processId(), Endpoint::instance()->pid());
QVERIFY(spyError.isEmpty());
QVERIFY(spyDisconnected.isEmpty());
connector.disconnectFromHost();
QTest::qWait(1);
QVERIFY(spyDisconnected.size() == 1);
QVERIFY(!Endpoint::isConnected());
}
}
void cleanupTestCase()
{
QVERIFY(m_process.state() == QProcess::Running);
m_process.terminate();
m_process.kill();
QVERIFY(m_process.waitForFinished(5000));
}
private:
QProcess m_process;
QUrl m_serverUrl;
};
QTEST_MAIN(ClientConnectionTest)
#include "clientconnectiontest.moc"
|