diff --git a/gui/tests/CMakeLists.txt b/gui/tests/CMakeLists.txt index e5f37e8..d3d872b 100644 --- a/gui/tests/CMakeLists.txt +++ b/gui/tests/CMakeLists.txt @@ -1,3 +1,3 @@ subdirs(GUITestUtils) declare_test(simple_graph simple_graph simple_graph/main.cpp "sciqlopgui;TestUtils;GUITestUtils;Qt5::Test") -declare_test(two_sync_graph two_sync_graph two_sync_graph/main.cpp "sciqlopgui;TestUtils;GUITestUtils;Qt5::Test") +declare_test(multiple_sync_graph multiple_sync_graph multiple_sync_graph/main.cpp "sciqlopgui;TestUtils;GUITestUtils;Qt5::Test") diff --git a/gui/tests/GUITestUtils/GUITestUtils.h b/gui/tests/GUITestUtils/GUITestUtils.h index bfd086e..bb2a487 100644 --- a/gui/tests/GUITestUtils/GUITestUtils.h +++ b/gui/tests/GUITestUtils/GUITestUtils.h @@ -85,11 +85,11 @@ auto getItem(T* widget, T2 itemIndex) #define SELECT_ITEM(widget, itemIndex, item)\ auto item = getItem(widget, itemIndex);\ -{\ - auto itemCenterPos = widget->visualItemRect(item).center();\ - QTest::mouseClick(widget->viewport(), Qt::LeftButton, Qt::NoModifier, itemCenterPos);\ - QVERIFY(widget->selectedItems().size() > 0);\ - QVERIFY(widget->selectedItems().contains(item));\ + {\ + auto itemCenterPos = widget->visualItemRect(item).center();\ + QTest::mouseClick(widget->viewport(), Qt::LeftButton, Qt::NoModifier, itemCenterPos);\ + QVERIFY(widget->selectedItems().size() > 0);\ + QVERIFY(widget->selectedItems().contains(item));\ } @@ -133,12 +133,15 @@ void dragnDropItem(T1* sourceWidget, T2* destWidget, T3* item, T4* destItem=Q_NU mouseMove(sourceWidget,itemCenterPos,Qt::LeftButton); } -#define PREPARE_GUI_TEST(main_widget)\ - main_widget.setGeometry(QRect(QPoint(QApplication::desktop()->geometry().center() - QPoint(250, 250)),\ - QSize(500, 500)));\ - main_widget.show();\ - qApp->setActiveWindow(&main_widget);\ - QVERIFY(QTest::qWaitForWindowActive(&main_widget)) +template +bool prepare_gui_test(T* w) +{ + w->setGeometry(QRect(QPoint(QApplication::desktop()->geometry().center() - QPoint(250, 250)), + QSize(500, 500))); + w->show(); + qApp->setActiveWindow(w); + return QTest::qWaitForWindowActive(w); +} #define GET_CHILD_WIDGET_FOR_GUI_TESTS(parent, child, childType, childName)\ childType* child = parent.findChild(childName); \ diff --git a/gui/tests/two_sync_graph/main.cpp b/gui/tests/multiple_sync_graph/main.cpp similarity index 64% rename from gui/tests/two_sync_graph/main.cpp rename to gui/tests/multiple_sync_graph/main.cpp index 55a377d..1d49364 100644 --- a/gui/tests/two_sync_graph/main.cpp +++ b/gui/tests/multiple_sync_graph/main.cpp @@ -12,40 +12,52 @@ #include #include +#include #include #include ALIAS_TEMPLATE_FUNCTION(isReady, static_cast(qApp)->variableController().isReady) -#define A_SIMPLE_GRAPH_FIXTURE \ - VisualizationZoneWidget w;\ - PREPARE_GUI_TEST(w);\ - 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);\ - auto cent = center(&w); - +template +std::tuple< std::unique_ptr, + std::vector>, + std::vector > +build_multi_graph_test() +{ + auto w = std::make_unique(); + auto provider = std::make_shared >(); + auto range = DateTimeRange::fromDateTime(QDate(2018, 8, 7), QTime(14, 00), QDate(2018, 8, 7),QTime(16, 00)); + std::vector> variables; + std::vector graphs; + for(auto i=0;i(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); + } + auto cent = center(w.get()); + return {std::move(w), variables, graphs}; +} -class A_SimpleGraph : public QObject { +class A_MultipleSyncGraphs : public QObject { Q_OBJECT public: - explicit A_SimpleGraph(QObject *parent = Q_NULLPTR) : QObject(parent) {} + explicit A_MultipleSyncGraphs(QObject *parent = Q_NULLPTR) : QObject(parent) {} private slots: void scrolls_left_with_mouse() { - A_SIMPLE_GRAPH_FIXTURE; + auto [w, variables, graphs] = build_multi_graph_test<3>(); + QVERIFY(prepare_gui_test(w.get())); - while (!isReady(var)) - QCoreApplication::processEvents(); - auto r = var->range(); /* * Scrolling to the left implies going back in time * Scroll only implies keeping the same delta T -> shit only transformation @@ -56,11 +68,15 @@ private slots: void scrolls_right_with_mouse() { - A_SIMPLE_GRAPH_FIXTURE; + 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(); + } - while (!isReady(var)) - QCoreApplication::processEvents(); - auto r = var->range(); /* * Scrolling to the right implies going forward in time * Scroll only implies keeping the same delta T -> shit only transformation @@ -70,6 +86,7 @@ private slots: } }; + QT_BEGIN_NAMESPACE QTEST_ADD_GPU_BLACKLIST_SUPPORT_DEFS QT_END_NAMESPACE @@ -79,7 +96,7 @@ int main(int argc, char *argv[]) app.setAttribute(Qt::AA_Use96Dpi, true); QTEST_DISABLE_KEYPAD_NAVIGATION; QTEST_ADD_GPU_BLACKLIST_SUPPORT; - A_SimpleGraph tc; + A_MultipleSyncGraphs tc; QTEST_SET_MAIN_SOURCE_PATH; return QTest::qExec(&tc, argc, argv); } diff --git a/gui/tests/simple_graph/main.cpp b/gui/tests/simple_graph/main.cpp index 8b7baa4..2e5bc32 100644 --- a/gui/tests/simple_graph/main.cpp +++ b/gui/tests/simple_graph/main.cpp @@ -18,19 +18,21 @@ ALIAS_TEMPLATE_FUNCTION(isReady, static_cast(qApp)->variableController().isReady) -#define A_SIMPLE_GRAPH_FIXTURE \ - VisualizationGraphWidget w;\ - PREPARE_GUI_TEST(w);\ - 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);\ - auto cent = center(&w); - +std::tuple< std::unique_ptr, + std::shared_ptr, + DateTimeRange > +build_simple_graph_test() +{ + auto w = std::make_unique(); + 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); + w->addVariable(var, range); + while (!isReady(var)) + QCoreApplication::processEvents(); + auto cent = center(w.get()); + return {std::move(w), var, range}; +} class A_SimpleGraph : public QObject { @@ -41,12 +43,14 @@ public: private slots: void scrolls_left_with_mouse() { - A_SIMPLE_GRAPH_FIXTURE; + 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, Qt::LeftButton, Qt::NoModifier, cent, 1); - mouseMove(&w, {cent.x() + 200, cent.y()}, Qt::LeftButton); - QTest::mouseRelease(&w, Qt::LeftButton); + 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(); } @@ -63,12 +67,14 @@ private slots: void scrolls_right_with_mouse() { - A_SIMPLE_GRAPH_FIXTURE; + 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, Qt::LeftButton, Qt::NoModifier, cent, 1); - mouseMove(&w, {cent.x() - 200, cent.y()}, Qt::LeftButton); - QTest::mouseRelease(&w, Qt::LeftButton); + 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(); }