CmvrControlStation/tests/mainwindow_merge_test.cpp

72 lines
3.7 KiB
C++
Raw Permalink Normal View History

// Exercise merged flow cancellation against the actual MainWindow objects.
// No server is connected; only outgoing Qt signals are observed.
#include <QtTest>
#include <QApplication>
#include <QCheckBox>
#include <QLineEdit>
#include <QSettings>
#include <QTemporaryDir>
#include <QStackedWidget>
#include <stdexcept>
#define private public
#include "../src/mainwindow.h"
#undef private
#include "../src/jointfloweditor.h"
#include "../src/robotclient.h"
static void check(bool value,const char *reason) { if(!value) throw std::runtime_error(reason); }
static void setup(MainWindow &window,double interval)
{
check(window.m_pages->count()==16 && window.m_handEye && window.m_tcpCalibration
&& window.m_touchOperation,"merged navigation lost an existing calibration page");
QObject::disconnect(window.m_client,&RobotClient::commandFinished,&window,&MainWindow::handleCommand);
window.m_demoCheck->setChecked(false); window.m_connected=true;
window.m_recordedJointPoints.clear();
for(int i=0;i<2;++i) {
MainWindow::RecordedJointPoint point;
point.name=QStringLiteral("point%1").arg(i); point.deviceId=window.m_armIdEdit->text();
point.positions={0,0,0,0,0,0}; window.m_recordedJointPoints.append(point);
}
window.m_jointFlowEditor->clear();
window.m_jointFlowEditor->addSingleNode("first","point0",interval);
window.m_jointFlowEditor->addSingleNode("second","point1",interval);
}
int main(int argc,char **argv)
{
QApplication application(argc,argv);
QTemporaryDir settings;
QCoreApplication::setOrganizationName("CMVR-Merge-Test");
QCoreApplication::setApplicationName("Merge");
QSettings::setDefaultFormat(QSettings::IniFormat);
QSettings::setPath(QSettings::IniFormat,QSettings::UserScope,settings.path());
QSettings initial; initial.setValue("connection/demo",false); initial.sync();
int failures=0;
for(int mode=0;mode<4;++mode) {
try {
MainWindow window; setup(window,.08);
QSignalSpy moves(window.m_client,&RobotClient::moveJRequested);
window.startJointPointLoop(); check(moves.size()==1,"first flow step did not dispatch");
window.handleCommand("MoveJ",true,{});
if(mode==0) window.m_client->requestSystemStopAll("*");
if(mode==1) window.m_client->requestArmStop(window.m_armIdEdit->text());
if(mode==2) window.m_client->disconnectFromServer();
if(mode==3) window.m_client->requestMoveJ(window.m_armIdEdit->text(),{0,0,0,0,0,0},.1,.1);
const int afterStop=moves.size(); QTest::qWait(160);
check(!window.m_jointPointLoopActive && moves.size()==afterStop,"stopped flow dispatched another movement");
std::printf("PASS: stop/interlock %d\n",mode);
} catch(const std::exception &error) { ++failures; std::fprintf(stderr,"FAIL: stop/interlock %d: %s\n",mode,error.what()); }
}
try {
MainWindow window; setup(window,.10);
QSignalSpy moves(window.m_client,&RobotClient::moveJRequested);
window.startJointPointLoop(); window.handleCommand("MoveJ",true,{});
window.stopJointPointLoop("replace flow"); setup(window,.45);
window.startJointPointLoop(); window.handleCommand("MoveJ",true,{});
QTest::qWait(230); check(moves.size()==2,"old flow timer advanced a new flow");
QTest::qWait(280); check(moves.size()==3,"current flow timer did not advance its own flow");
window.stopJointPointLoop("test finished");
std::printf("PASS: old timer cannot advance replacement flow\n");
} catch(const std::exception &error) { ++failures; std::fprintf(stderr,"FAIL: timer generation: %s\n",error.what()); }
return failures?1:0;
}