main.cpp
109 lines
| 3.4 KiB
| text/x-c
|
CppLexer
r1368 | #include <QtTest> | |||
#include <QObject> | ||||
#include <QString> | ||||
#include <QScreen> | ||||
#include <QMainWindow> | ||||
#include <QWheelEvent> | ||||
#include <qcustomplot.h> | ||||
#include <SqpApplication.h> | ||||
#include <Variable/VariableController2.h> | ||||
#include <Common/cpp_utils.h> | ||||
#include <Visualization/VisualizationZoneWidget.h> | ||||
r1369 | #include <Visualization/VisualizationGraphWidget.h> | |||
r1368 | #include <TestProviders.h> | |||
#include <GUITestUtils.h> | ||||
r1369 | template <int GraphCount=2> | |||
std::tuple< std::unique_ptr<VisualizationZoneWidget>, | ||||
std::vector<std::shared_ptr<Variable>>, | ||||
r1371 | std::vector<VisualizationGraphWidget*>, | |||
DateTimeRange> | ||||
r1369 | build_multi_graph_test() | |||
{ | ||||
auto w = std::make_unique<VisualizationZoneWidget>(); | ||||
auto provider = std::make_shared<SimpleRange<10> >(); | ||||
auto range = DateTimeRange::fromDateTime(QDate(2018, 8, 7), QTime(14, 00), QDate(2018, 8, 7),QTime(16, 00)); | ||||
std::vector<std::shared_ptr<Variable>> variables; | ||||
std::vector<VisualizationGraphWidget*> graphs; | ||||
for(auto i=0;i<GraphCount;i++) | ||||
{ | ||||
auto var = static_cast<SqpApplication *>(qApp)->variableController().createVariable( | ||||
QString("V%1").arg(i), {{"", "scalar"}}, provider, range); | ||||
auto graph = new VisualizationGraphWidget(); | ||||
graph->addVariable(var, range); | ||||
while (!isReady(var)) | ||||
QCoreApplication::processEvents(); | ||||
variables.push_back(var); | ||||
graphs.push_back(graph); | ||||
w->addGraph(graph); | ||||
} | ||||
r1371 | return {std::move(w), variables, graphs, range}; | |||
r1369 | } | |||
r1368 | ||||
r1369 | class A_MultipleSyncGraphs : public QObject { | |||
r1368 | Q_OBJECT | |||
public: | ||||
r1369 | explicit A_MultipleSyncGraphs(QObject *parent = Q_NULLPTR) : QObject(parent) {} | |||
r1368 | ||||
private slots: | ||||
void scrolls_left_with_mouse() | ||||
{ | ||||
r1371 | auto [w, variables, graphs, range] = build_multi_graph_test<3>(); | |||
auto var = variables.front(); | ||||
auto graph = graphs.front(); | ||||
r1369 | QVERIFY(prepare_gui_test(w.get())); | |||
r1371 | for (auto i = 0; i < 100; i++) { | |||
scroll_graph(graph, -200); | ||||
waitForVar(var); | ||||
} | ||||
auto r = variables.back()->range(); | ||||
r1368 | ||||
/* | ||||
* Scrolling to the left implies going back in time | ||||
* Scroll only implies keeping the same delta T -> shit only transformation | ||||
*/ | ||||
r1371 | QVERIFY(r.m_TEnd < range.m_TEnd); | |||
QVERIFY(SciQLop::numeric::almost_equal<double>(r.delta(),range.delta(),1)); | ||||
r1368 | } | |||
void scrolls_right_with_mouse() | ||||
{ | ||||
r1371 | auto [w, variables, graphs, range] = build_multi_graph_test<3>(); | |||
auto var = variables.front(); | ||||
auto graph = graphs.front(); | ||||
r1369 | QVERIFY(prepare_gui_test(w.get())); | |||
r1371 | for (auto i = 0; i < 100; i++) { | |||
scroll_graph(graph, 200); | ||||
waitForVar(var); | ||||
} | ||||
auto r = variables.back()->range(); | ||||
r1368 | ||||
/* | ||||
* Scrolling to the right implies going forward in time | ||||
* Scroll only implies keeping the same delta T -> shit only transformation | ||||
*/ | ||||
r1371 | QVERIFY(r.m_TEnd > range.m_TEnd); | |||
QVERIFY(SciQLop::numeric::almost_equal<double>(r.delta(),range.delta(),1)); | ||||
r1368 | } | |||
}; | ||||
r1369 | ||||
r1368 | QT_BEGIN_NAMESPACE | |||
QTEST_ADD_GPU_BLACKLIST_SUPPORT_DEFS | ||||
QT_END_NAMESPACE | ||||
int main(int argc, char *argv[]) | ||||
{ | ||||
SqpApplication app{argc, argv}; | ||||
app.setAttribute(Qt::AA_Use96Dpi, true); | ||||
QTEST_DISABLE_KEYPAD_NAVIGATION; | ||||
QTEST_ADD_GPU_BLACKLIST_SUPPORT; | ||||
r1369 | A_MultipleSyncGraphs tc; | |||
r1368 | QTEST_SET_MAIN_SOURCE_PATH; | |||
return QTest::qExec(&tc, argc, argv); | ||||
} | ||||
#include "main.moc" | ||||