diff --git a/gui/tests/GUITestUtils/GUITestUtils.h b/gui/tests/GUITestUtils/GUITestUtils.h index bb2a487..515833a 100644 --- a/gui/tests/GUITestUtils/GUITestUtils.h +++ b/gui/tests/GUITestUtils/GUITestUtils.h @@ -11,6 +11,9 @@ #include +#include +#include + template QPoint center(T* widget) { @@ -133,6 +136,23 @@ void dragnDropItem(T1* sourceWidget, T2* destWidget, T3* item, T4* destItem=Q_NU mouseMove(sourceWidget,itemCenterPos,Qt::LeftButton); } +template +void scroll_graph(T* w, int dx) +{ + auto cent = center(w); + QTest::mousePress(w, Qt::LeftButton, Qt::NoModifier, cent, 1); + mouseMove(w, {cent.x() + dx, cent.y()}, Qt::LeftButton); + QTest::mouseRelease(w, Qt::LeftButton); +} + +ALIAS_TEMPLATE_FUNCTION(isReady, static_cast(qApp)->variableController().isReady) + +void waitForVar(std::shared_ptr var) +{ + while (!isReady(var)) + QCoreApplication::processEvents(); +} + template bool prepare_gui_test(T* w) { diff --git a/gui/tests/multiple_sync_graph/main.cpp b/gui/tests/multiple_sync_graph/main.cpp index 1d49364..b2ad723 100644 --- a/gui/tests/multiple_sync_graph/main.cpp +++ b/gui/tests/multiple_sync_graph/main.cpp @@ -16,9 +16,6 @@ #include #include - -ALIAS_TEMPLATE_FUNCTION(isReady, static_cast(qApp)->variableController().isReady) - template std::tuple< std::unique_ptr, std::vector>, @@ -70,12 +67,12 @@ private slots: { auto [w, variables, graphs] = build_multi_graph_test<3>(); QVERIFY(prepare_gui_test(w.get())); - w->show(); - for(int i=0;i<10000;i++) - { - QThread::usleep(1000); - qApp->processEvents(); - } +// w->show(); +// for(int i=0;i<10000;i++) +// { +// QThread::usleep(1000); +// qApp->processEvents(); +// } /* * Scrolling to the right implies going forward in time diff --git a/gui/tests/simple_graph/main.cpp b/gui/tests/simple_graph/main.cpp index 2e5bc32..fd1d0b1 100644 --- a/gui/tests/simple_graph/main.cpp +++ b/gui/tests/simple_graph/main.cpp @@ -14,9 +14,7 @@ #include #include #include - - -ALIAS_TEMPLATE_FUNCTION(isReady, static_cast(qApp)->variableController().isReady) +#include std::tuple< std::unique_ptr, std::shared_ptr, @@ -27,9 +25,9 @@ build_simple_graph_test() auto provider = std::make_shared >(); auto range = DateTimeRange::fromDateTime(QDate(2018, 8, 7), QTime(14, 00), QDate(2018, 8, 7),QTime(16, 00)); auto var = static_cast(qApp)->variableController().createVariable("V1", {{"", "scalar"}}, provider, range); + while (!isReady(var)) QCoreApplication::processEvents(); w->addVariable(var, range); - while (!isReady(var)) - QCoreApplication::processEvents(); + while (!isReady(var)) QCoreApplication::processEvents(); auto cent = center(w.get()); return {std::move(w), var, range}; } @@ -45,17 +43,10 @@ private slots: { auto [w, var, range] = build_simple_graph_test(); QVERIFY(prepare_gui_test(w.get())); - auto cent = center(w.get()); - for (auto i = 0; i < 100; i++) { - QTest::mousePress(w.get(), Qt::LeftButton, Qt::NoModifier, cent, 1); - mouseMove(w.get(), {cent.x() + 200, cent.y()}, Qt::LeftButton); - QTest::mouseRelease(w.get(), Qt::LeftButton); - while (!isReady(var)) - QCoreApplication::processEvents(); + scroll_graph(w.get(), 200); + waitForVar(var); } - while (!isReady(var)) - QCoreApplication::processEvents(); auto r = var->range(); /* * Scrolling to the left implies going back in time @@ -69,17 +60,10 @@ private slots: { auto [w, var, range] = build_simple_graph_test(); QVERIFY(prepare_gui_test(w.get())); - auto cent = center(w.get()); - for (auto i = 0; i < 100; i++) { - QTest::mousePress(w.get(), Qt::LeftButton, Qt::NoModifier, cent, 1); - mouseMove(w.get(), {cent.x() - 200, cent.y()}, Qt::LeftButton); - QTest::mouseRelease(w.get(), Qt::LeftButton); - while (!isReady(var)) - QCoreApplication::processEvents(); + scroll_graph(w.get(), -200); + waitForVar(var); } - while (!isReady(var)) - QCoreApplication::processEvents(); auto r = var->range(); /* * Scrolling to the right implies going forward in time