#include #include #define private public #include "taskorchestrationwidget.h" #undef private #include "workflowcanvas.h" #include "workflowgraph.h" #include "taskprotoeditor.h" #include "applicationstyle.h" static void check(bool value,const char *message){if(!value)throw std::runtime_error(message);} int main(int argc,char **argv){QApplication app(argc,argv);ApplicationStyle::install(app); const QString storage=QCoreApplication::applicationDirPath()+"/data/task_orchestration.json"; QFile old(storage);const bool existed=old.exists();old.open(QIODevice::ReadOnly);const auto backup=old.readAll();old.close();int status=0; try {QFile fixture("build/tests/interop-fixture/workflow.json");check(fixture.open(QIODevice::ReadOnly),"fixture");auto graph=QJsonDocument::fromJson(fixture.readAll()).object(); TaskOrchestrationWidget w;QString error;check(w.restoreGraph(graph,error),qPrintable(error));w.save(); w.setDeviceInfo("armA",QVariantMap{{"jointNames",QStringList{"J1","J2"}}});w.resize(1480,920);w.show();QApplication::processEvents(); auto *canvas=static_cast(w.m_flowView);QGraphicsItem *move=nullptr; for(auto *item:w.m_flowScene->items())if(item->data(7010)=="move")move=item; check(move,"device node rendered");move->setSelected(true);QApplication::processEvents(); bool visibleEditor=false;for(auto *editor:w.findChildren())visibleEditor|=editor->isVisible();check(visibleEditor,"typed parameter editor in sidebar"); w.grab().save("build/tests/workflow-graph-ui.png"); QString start;for(const auto &v:w.m_graph.value("nodes").toArray())if(v.toObject().value("type")=="start")start=v.toObject().value("id").toString(); const auto childBefore=WorkflowGraph::node(w.m_graph,"move");const auto loopBefore=WorkflowGraph::node(w.m_graph,"loop"); const QPointF delta(77,133);WorkflowGraph::position(w.m_graph,"loop",QPointF(loopBefore["x"].toDouble(),loopBefore["y"].toDouble())+delta); check(WorkflowGraph::node(w.m_graph,"move")["x"].toDouble()==childBefore["x"].toDouble()+77,"moving container moves children"); canvas->connectionRemoved(start,"enable");check(!w.m_graph.value("edges").toArray().isEmpty(),"remaining edges"); QFile saved(storage);check(saved.open(QIODevice::ReadOnly),"storage");auto root=QJsonDocument::fromJson(saved.readAll()).object(); check(root.contains("flows")&&!root.contains("groups")&&!root.contains("version"),"canonical flow records"); auto record=root.value("flows").toArray().at(w.m_activeGroup).toObject();auto persisted=QJsonDocument::fromJson(record.value("flowData").toString().toUtf8()).object(); check(persisted==w.m_graph,"saved exact graph"); TaskOrchestrationWidget reopened;check(reopened.m_graph==persisted,"reopen preserves disconnected draft and positions"); QString source;for(const auto &v:reopened.m_graph.value("edges").toArray())if(v.toObject().value("targetNodeId")=="enable")source=v.toObject().value("sourceNodeId").toString();check(source.isEmpty(),"deleted edge not reconstructed on reload"); check(canvas->connectionRequested(start,"enable",error),qPrintable(error));w.save();check(!WorkflowGraph::order(w.m_graph,error).isEmpty(),qPrintable(error)); puts("PASS canonical storage, exact disconnected draft reload, deleted-edge persistence, container movement and typed sidebar"); }catch(const std::exception &e){fprintf(stderr,"FAIL %s\n",e.what());status=1;} if(existed){QFile restore(storage);restore.open(QIODevice::WriteOnly);restore.write(backup);}else QFile::remove(storage);return status; }