##// END OF EJS Templates
Some test refac and prepared synchronized graph test...
jeandet -
r1369:8a5759a257ef
parent child
Show More
@@ -1,3 +1,3
1 1 subdirs(GUITestUtils)
2 2 declare_test(simple_graph simple_graph simple_graph/main.cpp "sciqlopgui;TestUtils;GUITestUtils;Qt5::Test")
3 declare_test(two_sync_graph two_sync_graph two_sync_graph/main.cpp "sciqlopgui;TestUtils;GUITestUtils;Qt5::Test")
3 declare_test(multiple_sync_graph multiple_sync_graph multiple_sync_graph/main.cpp "sciqlopgui;TestUtils;GUITestUtils;Qt5::Test")
@@ -133,12 +133,15 void dragnDropItem(T1* sourceWidget, T2* destWidget, T3* item, T4* destItem=Q_NU
133 133 mouseMove(sourceWidget,itemCenterPos,Qt::LeftButton);
134 134 }
135 135
136 #define PREPARE_GUI_TEST(main_widget)\
137 main_widget.setGeometry(QRect(QPoint(QApplication::desktop()->geometry().center() - QPoint(250, 250)),\
138 QSize(500, 500)));\
139 main_widget.show();\
140 qApp->setActiveWindow(&main_widget);\
141 QVERIFY(QTest::qWaitForWindowActive(&main_widget))
136 template<typename T>
137 bool prepare_gui_test(T* w)
138 {
139 w->setGeometry(QRect(QPoint(QApplication::desktop()->geometry().center() - QPoint(250, 250)),
140 QSize(500, 500)));
141 w->show();
142 qApp->setActiveWindow(w);
143 return QTest::qWaitForWindowActive(w);
144 }
142 145
143 146 #define GET_CHILD_WIDGET_FOR_GUI_TESTS(parent, child, childType, childName)\
144 147 childType* child = parent.findChild<childType*>(childName); \
@@ -12,40 +12,52
12 12 #include <Common/cpp_utils.h>
13 13
14 14 #include <Visualization/VisualizationZoneWidget.h>
15 #include <Visualization/VisualizationGraphWidget.h>
15 16 #include <TestProviders.h>
16 17 #include <GUITestUtils.h>
17 18
18 19
19 20 ALIAS_TEMPLATE_FUNCTION(isReady, static_cast<SqpApplication *>(qApp)->variableController().isReady)
20 21
21 #define A_SIMPLE_GRAPH_FIXTURE \
22 VisualizationZoneWidget w;\
23 PREPARE_GUI_TEST(w);\
24 auto provider = std::make_shared<SimpleRange<10> >();\
25 auto range = DateTimeRange::fromDateTime(QDate(2018, 8, 7), QTime(14, 00), QDate(2018, 8, 7),\
26 QTime(16, 00));\
27 auto var = static_cast<SqpApplication *>(qApp)->variableController().createVariable(\
28 "V1", {{"", "scalar"}}, provider, range);\
29 while (!isReady(var))\
30 QCoreApplication::processEvents();\
31 //w.addVariable(var, range);\
32 auto cent = center(&w);
33
22 template <int GraphCount=2>
23 std::tuple< std::unique_ptr<VisualizationZoneWidget>,
24 std::vector<std::shared_ptr<Variable>>,
25 std::vector<VisualizationGraphWidget*> >
26 build_multi_graph_test()
27 {
28 auto w = std::make_unique<VisualizationZoneWidget>();
29 auto provider = std::make_shared<SimpleRange<10> >();
30 auto range = DateTimeRange::fromDateTime(QDate(2018, 8, 7), QTime(14, 00), QDate(2018, 8, 7),QTime(16, 00));
31 std::vector<std::shared_ptr<Variable>> variables;
32 std::vector<VisualizationGraphWidget*> graphs;
33 for(auto i=0;i<GraphCount;i++)
34 {
35 auto var = static_cast<SqpApplication *>(qApp)->variableController().createVariable(
36 QString("V%1").arg(i), {{"", "scalar"}}, provider, range);
37 auto graph = new VisualizationGraphWidget();
38 graph->addVariable(var, range);
39 while (!isReady(var))
40 QCoreApplication::processEvents();
41 variables.push_back(var);
42 graphs.push_back(graph);
43 w->addGraph(graph);
44 }
45 auto cent = center(w.get());
46 return {std::move(w), variables, graphs};
47 }
34 48
35 49
36 class A_SimpleGraph : public QObject {
50 class A_MultipleSyncGraphs : public QObject {
37 51 Q_OBJECT
38 52 public:
39 explicit A_SimpleGraph(QObject *parent = Q_NULLPTR) : QObject(parent) {}
53 explicit A_MultipleSyncGraphs(QObject *parent = Q_NULLPTR) : QObject(parent) {}
40 54
41 55 private slots:
42 56 void scrolls_left_with_mouse()
43 57 {
44 A_SIMPLE_GRAPH_FIXTURE;
58 auto [w, variables, graphs] = build_multi_graph_test<3>();
59 QVERIFY(prepare_gui_test(w.get()));
45 60
46 while (!isReady(var))
47 QCoreApplication::processEvents();
48 auto r = var->range();
49 61 /*
50 62 * Scrolling to the left implies going back in time
51 63 * Scroll only implies keeping the same delta T -> shit only transformation
@@ -56,11 +68,15 private slots:
56 68
57 69 void scrolls_right_with_mouse()
58 70 {
59 A_SIMPLE_GRAPH_FIXTURE;
71 auto [w, variables, graphs] = build_multi_graph_test<3>();
72 QVERIFY(prepare_gui_test(w.get()));
73 w->show();
74 for(int i=0;i<10000;i++)
75 {
76 QThread::usleep(1000);
77 qApp->processEvents();
78 }
60 79
61 while (!isReady(var))
62 QCoreApplication::processEvents();
63 auto r = var->range();
64 80 /*
65 81 * Scrolling to the right implies going forward in time
66 82 * Scroll only implies keeping the same delta T -> shit only transformation
@@ -70,6 +86,7 private slots:
70 86 }
71 87 };
72 88
89
73 90 QT_BEGIN_NAMESPACE
74 91 QTEST_ADD_GPU_BLACKLIST_SUPPORT_DEFS
75 92 QT_END_NAMESPACE
@@ -79,7 +96,7 int main(int argc, char *argv[])
79 96 app.setAttribute(Qt::AA_Use96Dpi, true);
80 97 QTEST_DISABLE_KEYPAD_NAVIGATION;
81 98 QTEST_ADD_GPU_BLACKLIST_SUPPORT;
82 A_SimpleGraph tc;
99 A_MultipleSyncGraphs tc;
83 100 QTEST_SET_MAIN_SOURCE_PATH;
84 101 return QTest::qExec(&tc, argc, argv);
85 102 }
@@ -18,19 +18,21
18 18
19 19 ALIAS_TEMPLATE_FUNCTION(isReady, static_cast<SqpApplication *>(qApp)->variableController().isReady)
20 20
21 #define A_SIMPLE_GRAPH_FIXTURE \
22 VisualizationGraphWidget w;\
23 PREPARE_GUI_TEST(w);\
24 auto provider = std::make_shared<SimpleRange<10> >();\
25 auto range = DateTimeRange::fromDateTime(QDate(2018, 8, 7), QTime(14, 00), QDate(2018, 8, 7),\
26 QTime(16, 00));\
27 auto var = static_cast<SqpApplication *>(qApp)->variableController().createVariable(\
28 "V1", {{"", "scalar"}}, provider, range);\
29 while (!isReady(var))\
30 QCoreApplication::processEvents();\
31 w.addVariable(var, range);\
32 auto cent = center(&w);
33
21 std::tuple< std::unique_ptr<VisualizationGraphWidget>,
22 std::shared_ptr<Variable>,
23 DateTimeRange >
24 build_simple_graph_test()
25 {
26 auto w = std::make_unique<VisualizationGraphWidget>();
27 auto provider = std::make_shared<SimpleRange<10> >();
28 auto range = DateTimeRange::fromDateTime(QDate(2018, 8, 7), QTime(14, 00), QDate(2018, 8, 7),QTime(16, 00));
29 auto var = static_cast<SqpApplication *>(qApp)->variableController().createVariable("V1", {{"", "scalar"}}, provider, range);
30 w->addVariable(var, range);
31 while (!isReady(var))
32 QCoreApplication::processEvents();
33 auto cent = center(w.get());
34 return {std::move(w), var, range};
35 }
34 36
35 37
36 38 class A_SimpleGraph : public QObject {
@@ -41,12 +43,14 public:
41 43 private slots:
42 44 void scrolls_left_with_mouse()
43 45 {
44 A_SIMPLE_GRAPH_FIXTURE;
46 auto [w, var, range] = build_simple_graph_test();
47 QVERIFY(prepare_gui_test(w.get()));
48 auto cent = center(w.get());
45 49
46 50 for (auto i = 0; i < 100; i++) {
47 QTest::mousePress(&w, Qt::LeftButton, Qt::NoModifier, cent, 1);
48 mouseMove(&w, {cent.x() + 200, cent.y()}, Qt::LeftButton);
49 QTest::mouseRelease(&w, Qt::LeftButton);
51 QTest::mousePress(w.get(), Qt::LeftButton, Qt::NoModifier, cent, 1);
52 mouseMove(w.get(), {cent.x() + 200, cent.y()}, Qt::LeftButton);
53 QTest::mouseRelease(w.get(), Qt::LeftButton);
50 54 while (!isReady(var))
51 55 QCoreApplication::processEvents();
52 56 }
@@ -63,12 +67,14 private slots:
63 67
64 68 void scrolls_right_with_mouse()
65 69 {
66 A_SIMPLE_GRAPH_FIXTURE;
70 auto [w, var, range] = build_simple_graph_test();
71 QVERIFY(prepare_gui_test(w.get()));
72 auto cent = center(w.get());
67 73
68 74 for (auto i = 0; i < 100; i++) {
69 QTest::mousePress(&w, Qt::LeftButton, Qt::NoModifier, cent, 1);
70 mouseMove(&w, {cent.x() - 200, cent.y()}, Qt::LeftButton);
71 QTest::mouseRelease(&w, Qt::LeftButton);
75 QTest::mousePress(w.get(), Qt::LeftButton, Qt::NoModifier, cent, 1);
76 mouseMove(w.get(), {cent.x() - 200, cent.y()}, Qt::LeftButton);
77 QTest::mouseRelease(w.get(), Qt::LeftButton);
72 78 while (!isReady(var))
73 79 QCoreApplication::processEvents();
74 80 }
General Comments 0
You need to be logged in to leave comments. Login now