Squish: Make static helper to member functions

Change-Id: Id9e67ba58ecaad2d4a9f907cc598930908c5b117
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2023-01-03 14:58:35 +01:00
parent 3d7baa65f9
commit 01f85a1e1e
2 changed files with 33 additions and 50 deletions

View File

@@ -78,16 +78,6 @@ static QString toolsStateName(SquishTools::State state)
return "UnexpectedState"; return "UnexpectedState";
} }
static void logRunnerStateChange(RunnerState from, RunnerState to)
{
qCInfo(LOG) << "Runner state change:" << runnerStateName(from) << ">" << runnerStateName(to);
}
static void logToolsStateChange(SquishTools::State from, SquishTools::State to)
{
qCInfo(LOG) << "State change:" << toolsStateName(from) << ">" << toolsStateName(to);
}
class SquishLocationMark : public TextEditor::TextMark class SquishLocationMark : public TextEditor::TextMark
{ {
public: public:
@@ -126,8 +116,7 @@ SquishTools::SquishTools(QObject *parent)
m_perspective.initPerspective(); m_perspective.initPerspective();
connect(&m_perspective, &SquishPerspective::interruptRequested, connect(&m_perspective, &SquishPerspective::interruptRequested,
this, [this] { this, [this] {
logRunnerStateChange(m_squishRunnerState, RunnerState::InterruptRequested); logAndChangeRunnerState(RunnerState::InterruptRequested);
m_squishRunnerState = RunnerState::InterruptRequested;
if (m_primaryRunner && m_primaryRunner->processId() != -1) if (m_primaryRunner && m_primaryRunner->processId() != -1)
interruptRunner(); interruptRunner();
}); });
@@ -135,8 +124,7 @@ SquishTools::SquishTools(QObject *parent)
bool interrupted = m_squishRunnerState == RunnerState::Interrupted; bool interrupted = m_squishRunnerState == RunnerState::Interrupted;
RunnerState state = interrupted ? RunnerState::CancelRequestedWhileInterrupted RunnerState state = interrupted ? RunnerState::CancelRequestedWhileInterrupted
: RunnerState::CancelRequested; : RunnerState::CancelRequested;
logRunnerStateChange(m_squishRunnerState, state); logAndChangeRunnerState(state);
m_squishRunnerState = state;
if (interrupted) if (interrupted)
handlePrompt(); handlePrompt();
else if (m_primaryRunner && m_primaryRunner->processId() != -1) else if (m_primaryRunner && m_primaryRunner->processId() != -1)
@@ -328,31 +316,38 @@ void SquishTools::writeServerSettingsChanges(const QList<QStringList> &changes)
startSquishServer(ServerConfigChangeRequested); startSquishServer(ServerConfigChangeRequested);
} }
void SquishTools::logAndChangeRunnerState(RunnerState to)
{
qCInfo(LOG) << "Runner state change:" << runnerStateName(m_squishRunnerState) << ">" << runnerStateName(to);
m_squishRunnerState = to;
}
void SquishTools::logAndChangeToolsState(SquishTools::State to)
{
qCInfo(LOG) << "State change:" << toolsStateName(m_state) << ">" << toolsStateName(to);
m_state = to;
}
void SquishTools::onServerStateChanged(SquishProcessState state) void SquishTools::onServerStateChanged(SquishProcessState state)
{ {
switch (state) { switch (state) {
case Starting: case Starting:
logToolsStateChange(m_state, SquishTools::ServerStarting); logAndChangeToolsState(SquishTools::ServerStarting);
m_state = SquishTools::ServerStarting;
break; break;
case Started: case Started:
logToolsStateChange(m_state, SquishTools::ServerStarted); logAndChangeToolsState(SquishTools::ServerStarted);
m_state = SquishTools::ServerStarted;
onServerStarted(); onServerStarted();
break; break;
case StartFailed: case StartFailed:
logToolsStateChange(m_state, SquishTools::ServerStartFailed); logAndChangeToolsState(SquishTools::ServerStartFailed);
m_state = SquishTools::ServerStartFailed;
onServerStartFailed(); onServerStartFailed();
break; break;
case Stopped: case Stopped:
logToolsStateChange(m_state, SquishTools::ServerStopped); logAndChangeToolsState(SquishTools::ServerStopped);
m_state = SquishTools::ServerStopped;
onServerStopped(); onServerStopped();
break; break;
case StopFailed: case StopFailed:
logToolsStateChange(m_state, SquishTools::ServerStopFailed); logAndChangeToolsState(SquishTools::ServerStopFailed);
m_state = SquishTools::ServerStopFailed;
onServerStopFailed(); onServerStopFailed();
break; break;
default: default:
@@ -431,9 +426,7 @@ void SquishTools::onServerStopFailed()
void SquishTools::setState(SquishTools::State state) void SquishTools::setState(SquishTools::State state)
{ {
qCInfo(LOG) << "State change:" << toolsStateName(m_state) << ">" << toolsStateName(state); logAndChangeToolsState(state);
// TODO check whether state transition is legal
m_state = state;
switch (m_state) { switch (m_state) {
case Idle: case Idle:
@@ -468,8 +461,7 @@ void SquishTools::setState(SquishTools::State state)
} else { } else {
m_xmlOutputHandler->clearForNextRun(); m_xmlOutputHandler->clearForNextRun();
m_perspective.setPerspectiveMode(SquishPerspective::Running); m_perspective.setPerspectiveMode(SquishPerspective::Running);
logRunnerStateChange(m_squishRunnerState, RunnerState::Starting); logAndChangeRunnerState(RunnerState::Starting);
m_squishRunnerState = RunnerState::Starting;
startSquishRunner(); startSquishRunner();
} }
break; break;
@@ -530,8 +522,7 @@ void SquishTools::startSquishServer(Request request)
m_perspective.showControlBar(nullptr); m_perspective.showControlBar(nullptr);
m_perspective.select(); m_perspective.select();
logRunnerStateChange(m_squishRunnerState, RunnerState::Starting); logAndChangeRunnerState(RunnerState::Starting);
m_squishRunnerState = RunnerState::Starting;
if (m_request == RecordTestRequested) if (m_request == RecordTestRequested)
m_perspective.updateStatus(Tr::tr("Recording test case")); m_perspective.updateStatus(Tr::tr("Recording test case"));
else else
@@ -683,8 +674,7 @@ void SquishTools::onRunnerFinished()
{ {
qCDebug(LOG) << "Runner finished"; qCDebug(LOG) << "Runner finished";
if (!m_shutdownInitiated) { if (!m_shutdownInitiated) {
logRunnerStateChange(m_squishRunnerState, RunnerState::Finished); logAndChangeRunnerState(RunnerState::Finished);
m_squishRunnerState = RunnerState::Finished;
if (m_request == RunTestRequested) if (m_request == RunTestRequested)
m_perspective.updateStatus(Tr::tr("Test run finished.")); m_perspective.updateStatus(Tr::tr("Test run finished."));
else if (m_request == RecordTestRequested) else if (m_request == RecordTestRequested)
@@ -839,9 +829,7 @@ void SquishTools::onRunnerErrorOutput()
if (trimmed.startsWith("QSocketNotifier: Invalid socket")) { if (trimmed.startsWith("QSocketNotifier: Invalid socket")) {
// we've lost connection to the AUT - if Interrupted, try to cancel the runner // we've lost connection to the AUT - if Interrupted, try to cancel the runner
if (m_squishRunnerState == RunnerState::Interrupted) { if (m_squishRunnerState == RunnerState::Interrupted) {
logRunnerStateChange(m_squishRunnerState, logAndChangeRunnerState(RunnerState::CancelRequestedWhileInterrupted);
RunnerState::CancelRequestedWhileInterrupted);
m_squishRunnerState = RunnerState::CancelRequestedWhileInterrupted;
handlePrompt(); handlePrompt();
} }
} else if (trimmed.contains("could not be started.") } else if (trimmed.contains("could not be started.")
@@ -957,8 +945,7 @@ void SquishTools::handlePrompt(const QString &fileName, int line, int column)
case RunnerState::CancelRequested: case RunnerState::CancelRequested:
case RunnerState::CancelRequestedWhileInterrupted: case RunnerState::CancelRequestedWhileInterrupted:
stopRecorder(); stopRecorder();
logRunnerStateChange(m_squishRunnerState, RunnerState::Canceling); logAndChangeRunnerState(RunnerState::Canceling);
m_squishRunnerState = RunnerState::Canceling;
break; break;
case RunnerState::Canceled: case RunnerState::Canceled:
QTC_CHECK(false); QTC_CHECK(false);
@@ -977,8 +964,7 @@ void SquishTools::handlePrompt(const QString &fileName, int line, int column)
onRunnerRunRequested(StepMode::Continue); onRunnerRunRequested(StepMode::Continue);
} else { } else {
m_perspective.setPerspectiveMode(SquishPerspective::Interrupted); m_perspective.setPerspectiveMode(SquishPerspective::Interrupted);
logRunnerStateChange(m_squishRunnerState, RunnerState::Interrupted); logAndChangeRunnerState(RunnerState::Interrupted);
m_squishRunnerState = RunnerState::Interrupted;
restoreQtCreatorWindows(); restoreQtCreatorWindows();
// request local variables // request local variables
m_primaryRunner->write("print variables\n"); m_primaryRunner->write("print variables\n");
@@ -992,13 +978,11 @@ void SquishTools::handlePrompt(const QString &fileName, int line, int column)
case RunnerState::CancelRequestedWhileInterrupted: case RunnerState::CancelRequestedWhileInterrupted:
m_primaryRunner->write("exit\n"); m_primaryRunner->write("exit\n");
clearLocationMarker(); clearLocationMarker();
logRunnerStateChange(m_squishRunnerState, RunnerState::Canceling); logAndChangeRunnerState(RunnerState::Canceling);
m_squishRunnerState = RunnerState::Canceling;
break; break;
case RunnerState::Canceling: case RunnerState::Canceling:
m_primaryRunner->write("quit\n"); m_primaryRunner->write("quit\n");
logRunnerStateChange(m_squishRunnerState, RunnerState::Canceled); logAndChangeRunnerState(RunnerState::Canceled);
m_squishRunnerState = RunnerState::Canceled;
break; break;
case RunnerState::Canceled: case RunnerState::Canceled:
QTC_CHECK(false); QTC_CHECK(false);
@@ -1006,8 +990,7 @@ void SquishTools::handlePrompt(const QString &fileName, int line, int column)
default: default:
if (line != -1 && column != -1) { if (line != -1 && column != -1) {
m_perspective.setPerspectiveMode(SquishPerspective::Interrupted); m_perspective.setPerspectiveMode(SquishPerspective::Interrupted);
logRunnerStateChange(m_squishRunnerState, RunnerState::Interrupted); logAndChangeRunnerState(RunnerState::Interrupted);
m_squishRunnerState = RunnerState::Interrupted;
restoreQtCreatorWindows(); restoreQtCreatorWindows();
// if we're returning from a function we might end up without a file information // if we're returning from a function we might end up without a file information
if (fileName.isEmpty()) { if (fileName.isEmpty()) {
@@ -1145,8 +1128,7 @@ void SquishTools::onRunnerRunRequested(StepMode step)
delete m_requestVarsTimer; delete m_requestVarsTimer;
m_requestVarsTimer = nullptr; m_requestVarsTimer = nullptr;
} }
logRunnerStateChange(m_squishRunnerState, RunnerState::RunRequested); logAndChangeRunnerState(RunnerState::RunRequested);
m_squishRunnerState = RunnerState::RunRequested;
QTC_ASSERT(m_primaryRunner, return); QTC_ASSERT(m_primaryRunner, return);
if (step == StepMode::Continue) if (step == StepMode::Continue)
@@ -1165,8 +1147,7 @@ void SquishTools::onRunnerRunRequested(StepMode step)
if (m_perspective.perspectiveMode() == SquishPerspective::Interrupted) if (m_perspective.perspectiveMode() == SquishPerspective::Interrupted)
m_perspective.setPerspectiveMode(SquishPerspective::Running); m_perspective.setPerspectiveMode(SquishPerspective::Running);
logRunnerStateChange(m_squishRunnerState, RunnerState::Running); logAndChangeRunnerState(RunnerState::Running);
m_squishRunnerState = RunnerState::Running;
} }
void SquishTools::interruptRunner() void SquishTools::interruptRunner()

View File

@@ -89,6 +89,8 @@ private:
enum RunnerQuery { ServerInfo, GetGlobalScriptDirs, SetGlobalScriptDirs }; enum RunnerQuery { ServerInfo, GetGlobalScriptDirs, SetGlobalScriptDirs };
void logAndChangeRunnerState(RunnerState to);
void logAndChangeToolsState(SquishTools::State to);
void onServerStateChanged(SquishProcessState state); void onServerStateChanged(SquishProcessState state);
void onServerStarted(); void onServerStarted();
void onServerStopped(); void onServerStopped();