CmvrControlStation/tests/joint_layout_test.cpp

31 lines
2.5 KiB
C++
Raw Permalink Normal View History

#include "taskjointeditor.h"
#include "applicationstyle.h"
#include <QApplication>
#include <QElapsedTimer>
#include <QThread>
#include <iostream>
#include <stdexcept>
static void check(bool ok,const char* message){if(!ok)throw std::runtime_error(message);}
static void settle(){QElapsedTimer timer;timer.start();while(timer.elapsed()<120){QApplication::processEvents();QThread::msleep(2);}}
int main(int argc,char** argv){QApplication app(argc,argv);ApplicationStyle::install(app);try{
for(int fontSize:{13,18})for(int width:{220,280,340}){
TaskJointEditor editor;QFont font=editor.font();font.setPixelSize(fontSize);editor.setFont(font);
editor.setFixedWidth(width);
editor.setDevice({{"jointNames",QStringList{"R_SHOULDER_P","R_SHOULDER_R","RIGHT_SHOULDER_PITCH_JOINT_EXTENDED_NAME","R_ELBOW_R","R_WRIST_P","R_WRIST_Y","R_WRIST_R"}},
{"jointLimits",QVariantMap{{"R_SHOULDER_R",QVariantMap{{"lower",-2.},{"upper",2.}}}}}});
editor.show();settle();editor.adjustSize();settle();
auto* table=editor.findChild<QTableWidget*>("taskJointTable");check(table&&table->rowCount()==7,"all joints visible");
for(int i=0;i<table->rowCount();++i){
auto* row=table->cellWidget(i,0);auto* edit=row->findChild<QLineEdit*>();check(edit,"angle input exists");
const QRect cell=table->visualRect(table->model()->index(i,0));
const QRect input(edit->mapTo(table->viewport(),QPoint()),edit->size());
if(!cell.contains(input)){std::cerr<<"width="<<width<<" font="<<fontSize<<" row="<<i<<" cell="<<cell.x()<<","<<cell.y()<<","<<cell.width()<<","<<cell.height()<<" input="<<input.x()<<","<<input.y()<<","<<input.width()<<","<<input.height()<<"\n";}
check(cell.contains(input),"input rectangle fully inside row");check(edit->height()>=edit->minimumSizeHint().height(),"input fits theme minimum height");
for(auto* label:row->findChildren<QLabel*>())check(label->height()>=label->heightForWidth(label->width()),"joint name and limits fit their wrapped text");
check(table->viewport()->rect().contains(cell),"all joint rows fit without nested scrolling");
}
if(width==280&&fontSize==13)editor.grab().save("build/tests/joint-layout.png");
}
std::cout<<"PASS: seven named joints, long names, limits, 220/280/340 widths and 13/18px fonts; inputs fully contained; no nested scrollbar\n";return 0;
}catch(const std::exception& e){std::cerr<<"FAIL: "<<e.what()<<"\n";return 1;}}