summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeith Isdale <keith.isdale@nokia.com>2010-07-26 16:27:24 +1000
committerKeith Isdale <keith.isdale@nokia.com>2010-07-26 16:27:24 +1000
commit748b82aece7df43d87a48849006944eecac87670 (patch)
tree6b98981ded6182e41714f48412ba94bd8a8e3c27
parent43d525056b8ff28756c886debce78907588eac7b (diff)
parentfbec276344fe360caa9871e59d9465bfd5519482 (diff)
Merge branch 'master' of git://git-nokia.trolltech.com.au/qtsoftware/research/qtuitest
-rw-r--r--libqsystemtest/qsystemtest.cpp7
-rw-r--r--libqsystemtest/testdevicecontrol.cpp112
-rw-r--r--libqsystemtest/testdevicecontrol.h41
3 files changed, 125 insertions, 35 deletions
diff --git a/libqsystemtest/qsystemtest.cpp b/libqsystemtest/qsystemtest.cpp
index 945a6b2..e50743d 100644
--- a/libqsystemtest/qsystemtest.cpp
+++ b/libqsystemtest/qsystemtest.cpp
@@ -270,6 +270,9 @@ QSystemTest::QSystemTest()
*/
QSystemTest::~QSystemTest()
{
+ if (device_control)
+ device_control->killApplications();
+
while (m_aut.count()) {
QPointer<QProcess> proc = m_aut.takeFirst();
if (proc) {
@@ -2423,7 +2426,7 @@ void QSystemTest::startApplication( const QString &application, const QStringLis
*/
}
if (device_control)
- device_control->killApplication();
+ device_control->killApplications();
// setup configuration for target, used by configTarget() later
QByteArray defTargetID = qgetenv("QTUITEST_TARGETID");
@@ -2450,7 +2453,7 @@ void QSystemTest::startApplication( const QString &application, const QStringLis
#endif
if (device_control) {
- device_control->runCustomCommand("run-standalone.sh " + application + " -style qtuitest", 3000, reply);
+ device_control->startApplication(application, true, reply);
#ifdef QTCREATOR_QTEST
testOutputPane()->append(reply);
#endif
diff --git a/libqsystemtest/testdevicecontrol.cpp b/libqsystemtest/testdevicecontrol.cpp
index 344846d..257dea0 100644
--- a/libqsystemtest/testdevicecontrol.cpp
+++ b/libqsystemtest/testdevicecontrol.cpp
@@ -46,38 +46,92 @@ using namespace Core;
namespace Qt4Test {
+// *****************************************************************
+
TestDeviceControl::TestDeviceControl( Core::SshConnectionParameters &sshParam )
{
- m_server = sshParam;
- control_mode = Idle;
+ ssh_param = sshParam;
}
TestDeviceControl::~TestDeviceControl()
{
+ killApplications();
+
+ while (device_controls.count() > 0)
+ delete device_controls.takeFirst();
}
bool TestDeviceControl::deviceConfiguration( QString &reply )
{
+ MaemoTestDeviceControl ctrl(ssh_param);
+ return ctrl.deviceConfiguration(reply);
+}
+
+bool TestDeviceControl::startApplication( const QString &application,
+ bool styleQtUITest, QString &reply )
+{
+ MaemoTestDeviceControl *ctrl = new MaemoTestDeviceControl(ssh_param);
+ device_controls.append(ctrl);
+ if (ctrl->startApplication(application, styleQtUITest, reply)) {
+ started_applications += application;
+ return true;
+ }
+ return false;
+}
+
+bool TestDeviceControl::killApplication( const QString &application, QString &reply )
+{
+ MaemoTestDeviceControl *ctrl = new MaemoTestDeviceControl(ssh_param);
+ device_controls.append(ctrl);
+ return ctrl->killApplication(application, reply);
+}
+
+void TestDeviceControl::killApplications()
+{
+ if (started_applications.count() == 0)
+ return;
+
+ QString reply;
+ foreach (QString app, started_applications) {
+ killApplication(app, reply);
+ }
+ started_applications.clear();
+}
+
+// *****************************************************************
+
+MaemoTestDeviceControl::MaemoTestDeviceControl( Core::SshConnectionParameters &sshParam ) : TestDeviceControl(sshParam)
+{
+ ssh_param = sshParam;
+ control_mode = Idle;
+}
+
+MaemoTestDeviceControl::~MaemoTestDeviceControl()
+{
+}
+
+bool MaemoTestDeviceControl::deviceConfiguration( QString &reply )
+{
runBlockingCommand( ConfigCheck, "", 10000);
reply = reply_txt;
return reply_ok;
}
-bool TestDeviceControl::runCustomCommand( const QString &cmd, int timeout, QString &reply )
+bool MaemoTestDeviceControl::runCustomCommand( const QString &cmd, int timeout, QString &reply )
{
runBlockingCommand( CustomCommand, cmd, timeout);
reply = reply_txt;
return reply_ok;
}
-bool TestDeviceControl::runCustomBlockingCommand( const QString &cmd, int timeout, QString &reply )
+bool MaemoTestDeviceControl::runCustomBlockingCommand( const QString &cmd, int timeout, QString &reply )
{
runBlockingCommand( CustomBlockingCommand, cmd, timeout);
reply = reply_txt;
return reply_ok;
}
-void TestDeviceControl::runBlockingCommand( TestDeviceControlMode mode, const QString &cmd, int timeout)
+void MaemoTestDeviceControl::runBlockingCommand( MaemoTestDeviceControlMode mode, const QString &cmd, int timeout)
{
reply_txt = "";
reply_ok = true;
@@ -88,21 +142,27 @@ void TestDeviceControl::runBlockingCommand( TestDeviceControlMode mode, const QS
cleanupConnection();
}
-bool TestDeviceControl::killApplication()
+bool MaemoTestDeviceControl::startApplication( const QString &application,
+ bool styleQtUITest, QString &reply )
+{
+ QString cmd = "run-standalone.sh " + application;
+ if (styleQtUITest) cmd += " -style qtuitest";
+
+ runBlockingCommand( CustomCommand, cmd, 10000);
+ reply = reply_txt;
+ return reply_ok;
+}
+
+bool MaemoTestDeviceControl::killApplication( const QString &application, QString &reply )
{
if (m_testProcess) {
m_testProcess->kill();
-
- QString reply;
- if (!runCustomCommand( "killall testapp1", 1000, reply)) {
- qDebug() << reply;
- return false;
- }
}
- return true;
+
+ return runCustomCommand( "killall " + application, 1000, reply);
}
-void TestDeviceControl::waitForCommandToFinish(int timeout)
+void MaemoTestDeviceControl::waitForCommandToFinish(int timeout)
{
QTime t;
t.start();
@@ -115,7 +175,7 @@ void TestDeviceControl::waitForCommandToFinish(int timeout)
}
}
-bool TestDeviceControl::initConnection()
+bool MaemoTestDeviceControl::initConnection()
{
if (m_testProcess) {
reply_ok = false;
@@ -131,12 +191,12 @@ bool TestDeviceControl::initConnection()
connect(m_connection.data(), SIGNAL(error(SshError)),
this, SLOT(handleConnectionError()));
- m_connection->connectToHost(m_server);
+ m_connection->connectToHost(ssh_param);
return true;
}
-void TestDeviceControl::handleConnected()
+void MaemoTestDeviceControl::handleConnected()
{
if (!m_connection) {
reply_ok = false;
@@ -166,7 +226,7 @@ void TestDeviceControl::handleConnected()
QTimer::singleShot(500,this,SLOT(cleanupConnection()));
}
-void TestDeviceControl::handleConnectionError()
+void MaemoTestDeviceControl::handleConnectionError()
{
reply_ok = false;
@@ -174,16 +234,16 @@ void TestDeviceControl::handleConnectionError()
reply_txt += "Invalid connection\n";
} else {
reply_txt += tr("Could not connect to host: %1:%2 %3 %4\n%5\n")
- .arg(m_server.host)
- .arg(m_server.port)
- .arg(m_server.uname)
- .arg(m_server.pwd)
+ .arg(ssh_param.host)
+ .arg(ssh_param.port)
+ .arg(ssh_param.uname)
+ .arg(ssh_param.pwd)
.arg(m_connection->errorString());
}
cleanupConnection();
}
-void TestDeviceControl::handleProcessFinished(int exitStatus)
+void MaemoTestDeviceControl::handleProcessFinished(int exitStatus)
{
Q_ASSERT(exitStatus == SshRemoteProcess::FailedToStart
|| exitStatus == SshRemoteProcess::KilledBySignal
@@ -214,7 +274,7 @@ void TestDeviceControl::handleProcessFinished(int exitStatus)
cleanupConnection();
}
-void TestDeviceControl::cleanupConnection()
+void MaemoTestDeviceControl::cleanupConnection()
{
if (m_testProcess)
disconnect(m_testProcess.data(), 0, this, 0);
@@ -225,12 +285,12 @@ void TestDeviceControl::cleanupConnection()
m_connection.clear();
}
-void TestDeviceControl::processSshOutput(const QByteArray &output)
+void MaemoTestDeviceControl::processSshOutput(const QByteArray &output)
{
m_deviceTestOutput.append(QString::fromUtf8(output));
}
-QString TestDeviceControl::parseOutput()
+QString MaemoTestDeviceControl::parseOutput()
{
if (control_mode == ConfigCheck) {
m_qtVersionOk = false;
diff --git a/libqsystemtest/testdevicecontrol.h b/libqsystemtest/testdevicecontrol.h
index 2969ab8..097451a 100644
--- a/libqsystemtest/testdevicecontrol.h
+++ b/libqsystemtest/testdevicecontrol.h
@@ -39,6 +39,7 @@
#include <QtCore/QSharedPointer>
#include <QHash>
+#include <QStringList>
namespace Core {
class SshConnection;
@@ -47,6 +48,8 @@ namespace Core {
namespace Qt4Test {
+class MaemoTestDeviceControl;
+
/**
* A class that can communicate with a device, using a secure connection.
*/
@@ -60,12 +63,37 @@ public:
enum TestDeviceControlMode {Idle, ConfigCheck, CustomCommand, CustomBlockingCommand};
bool deviceConfiguration( QString &reply );
+
+ bool startApplication( const QString &application,
+ bool styleQtUITest, QString &reply );
+ bool killApplication( const QString &application, QString &reply );
+ void killApplications();
+
+protected:
+ Core::SshConnectionParameters ssh_param;
+
+private:
+ QList<MaemoTestDeviceControl*> device_controls;
+ QStringList started_applications;
+};
+
+class MaemoTestDeviceControl : public TestDeviceControl
+{
+ Q_OBJECT
+public:
+ explicit MaemoTestDeviceControl( Core::SshConnectionParameters &sshParam );
+ ~MaemoTestDeviceControl();
+
+ bool deviceConfiguration( QString &reply );
+
+ bool startApplication( const QString &application,
+ bool styleQtUITest, QString &reply );
+ bool killApplication( const QString &application, QString &reply );
+
+protected:
bool runCustomCommand( const QString &cmd, int timeout, QString &reply );
bool runCustomBlockingCommand( const QString &cmd, int timeout, QString &reply );
-// bool startApplication( const QString &application );
- bool killApplication();
-
private slots:
void cleanupConnection();
@@ -77,17 +105,16 @@ private slots:
private:
bool initConnection();
QString parseOutput();
- void runBlockingCommand( TestDeviceControlMode mode, const QString &cmd, int timeout);
void waitForCommandToFinish(int timeout);
- TestDeviceControlMode control_mode;
+ enum MaemoTestDeviceControlMode {Idle, ConfigCheck, CustomCommand, CustomBlockingCommand};
+ MaemoTestDeviceControlMode control_mode;
+ void runBlockingCommand( MaemoTestDeviceControlMode mode, const QString &cmd, int timeout);
- Core::SshConnectionParameters m_server;
QSharedPointer<Core::SshConnection> m_connection;
QSharedPointer<Core::SshRemoteProcess> m_testProcess;
QString m_deviceTestOutput;
bool m_qtVersionOk;
-
bool reply_ok;
QString reply_txt;
QString m_cmd;