@@ -1,1 +1,1 | |||
|
1 | Subproject commit e3779b99a071447cf8b6781a8ae6b414d6106b82 | |
|
1 | Subproject commit cc47cd67a7b3418c7c0b065e7cb178abb63b0036 |
@@ -1,134 +1,134 | |||
|
1 | 1 | #ifndef GUITESTUTILS_H |
|
2 | 2 | #define GUITESTUTILS_H |
|
3 | 3 | |
|
4 | 4 | #include <Common/cpp_utils.h> |
|
5 | 5 | #include <QPoint> |
|
6 | 6 | #include <QCursor> |
|
7 | 7 | #include <QMouseEvent> |
|
8 | 8 | #include <QCoreApplication> |
|
9 | 9 | #include <QtTest> |
|
10 | 10 | #include <QDesktopWidget> |
|
11 | 11 | |
|
12 | 12 | #include <qcustomplot.h> |
|
13 | 13 | |
|
14 | QPoint center(QWidget* widget) | |
|
14 | template <typename T> | |
|
15 | QPoint center(T* widget) | |
|
15 | 16 | { |
|
16 | 17 | return QPoint{widget->width()/2,widget->height()/2}; |
|
17 | 18 | } |
|
18 | 19 | |
|
19 | 20 | HAS_METHOD(viewport) |
|
20 | 21 | |
|
22 | template <typename T> | |
|
23 | using is_QWidgetOrDerived = std::is_base_of<QWidget,T>; | |
|
24 | ||
|
25 | template <typename T> using viewport_type = decltype(std::declval<T>().viewport()); | |
|
26 | ||
|
21 | 27 | HAS_METHOD(topLevelItem) |
|
22 | 28 | |
|
23 | 29 | template<typename T> |
|
24 | 30 | void mouseMove(T* widget, QPoint pos, Qt::MouseButton mouseModifier) |
|
25 | 31 | { |
|
26 | 32 | QCursor::setPos(widget->mapToGlobal(pos)); |
|
27 | 33 | QMouseEvent event(QEvent::MouseMove, pos, Qt::NoButton, mouseModifier, Qt::NoModifier); |
|
28 | if constexpr(has_viewport<T>) | |
|
34 | if constexpr(has_viewport<T> && is_QWidgetOrDerived<viewport_type<T>>::value ) | |
|
29 | 35 | { |
|
30 | 36 | qApp->sendEvent(widget->viewport(), &event); |
|
31 | 37 | } |
|
32 | 38 | else |
|
33 | 39 | { |
|
34 | 40 | qApp->sendEvent(widget, &event); |
|
35 | 41 | } |
|
36 | 42 | qApp->processEvents(); |
|
37 | 43 | } |
|
38 | 44 | |
|
39 | 45 | |
|
40 | 46 | template <typename T> |
|
41 | 47 | void setMouseTracking(T* widget) |
|
42 | 48 | { |
|
43 | if constexpr(has_viewport<T>) | |
|
49 | if constexpr(has_viewport<T> && is_QWidgetOrDerived<viewport_type<T>>::value) | |
|
44 | 50 | { |
|
45 | 51 | widget->viewport()->setMouseTracking(true); |
|
46 | 52 | } |
|
47 | 53 | else |
|
48 | 54 | { |
|
49 | 55 | widget->setMouseTracking(true); |
|
50 | 56 | } |
|
51 | 57 | } |
|
52 | 58 | |
|
53 | template <> | |
|
54 | void setMouseTracking<QCustomPlot>(QCustomPlot* widget) | |
|
55 | { | |
|
56 | widget->setMouseTracking(true); | |
|
57 | } | |
|
58 | ||
|
59 | 59 | template <typename T, typename T2> |
|
60 | 60 | auto getItem(T* widget, T2 itemIndex) |
|
61 | 61 | { |
|
62 | 62 | if constexpr(has_topLevelItem<T>) |
|
63 | 63 | { |
|
64 | 64 | return widget->topLevelItem(itemIndex); |
|
65 | 65 | } |
|
66 | 66 | else |
|
67 | 67 | { |
|
68 | 68 | return widget->item(itemIndex); |
|
69 | 69 | } |
|
70 | 70 | } |
|
71 | 71 | |
|
72 | 72 | #define SELECT_ITEM(widget, itemIndex, item)\ |
|
73 | 73 | auto item = getItem(widget, itemIndex);\ |
|
74 | 74 | {\ |
|
75 | 75 | auto itemCenterPos = widget->visualItemRect(item).center();\ |
|
76 | 76 | QTest::mouseClick(widget->viewport(), Qt::LeftButton, Qt::NoModifier, itemCenterPos);\ |
|
77 | 77 | QVERIFY(widget->selectedItems().size() > 0);\ |
|
78 | 78 | QVERIFY(widget->selectedItems().contains(item));\ |
|
79 | 79 | } |
|
80 | 80 | |
|
81 | 81 | |
|
82 | 82 | #define GET_CHILD_WIDGET_FOR_GUI_TESTS(parent, child, childType, childName)\ |
|
83 | 83 | childType* child = parent.findChild<childType*>(childName); \ |
|
84 | 84 | QVERIFY(child!=Q_NULLPTR); \ |
|
85 | 85 | setMouseTracking(child); |
|
86 | 86 | |
|
87 | 87 | template<typename T1, typename T2, typename T3, typename T4=void> |
|
88 | 88 | void dragnDropItem(T1* sourceWidget, T2* destWidget, T3* item, T4* destItem=Q_NULLPTR) |
|
89 | 89 | { |
|
90 | 90 | auto itemCenterPos = sourceWidget->visualItemRect(item).center(); |
|
91 | 91 | if constexpr(has_viewport<T1>) |
|
92 | 92 | { |
|
93 | 93 | QTest::mousePress(sourceWidget->viewport(), Qt::LeftButton, Qt::NoModifier, itemCenterPos); |
|
94 | 94 | } |
|
95 | 95 | else |
|
96 | 96 | { |
|
97 | 97 | QTest::mousePress(sourceWidget, Qt::LeftButton, Qt::NoModifier, itemCenterPos); |
|
98 | 98 | } |
|
99 | 99 | mouseMove(sourceWidget,itemCenterPos, Qt::LeftButton); |
|
100 | 100 | itemCenterPos+=QPoint(0,-10); |
|
101 | 101 | QTimer::singleShot(100,[destWidget,destItem](){ |
|
102 | 102 | mouseMove(destWidget, destWidget->rect().center(),Qt::LeftButton); |
|
103 | 103 | mouseMove(destWidget, destWidget->rect().center()+QPoint(0,-10),Qt::LeftButton); |
|
104 | 104 | if constexpr(!std::is_same_v<void, T4>) |
|
105 | 105 | { |
|
106 | 106 | auto destItemCenterPos = destWidget->visualItemRect(destItem).center(); |
|
107 | 107 | QTest::mouseRelease(destWidget, Qt::LeftButton, Qt::NoModifier, destItemCenterPos); |
|
108 | 108 | } |
|
109 | 109 | else if constexpr(has_viewport<T2>) |
|
110 | 110 | { |
|
111 | 111 | QTest::mouseRelease(destWidget->viewport(), Qt::LeftButton); |
|
112 | 112 | } |
|
113 | 113 | else |
|
114 | 114 | { |
|
115 | 115 | QTest::mouseRelease(destWidget, Qt::LeftButton); |
|
116 | 116 | } |
|
117 | 117 | QTest::mouseRelease(destWidget->viewport(), Qt::LeftButton); |
|
118 | 118 | }); |
|
119 | 119 | mouseMove(sourceWidget,itemCenterPos,Qt::LeftButton); |
|
120 | 120 | } |
|
121 | 121 | |
|
122 | 122 | #define PREPARE_GUI_TEST(main_widget)\ |
|
123 | 123 | main_widget.setGeometry(QRect(QPoint(QApplication::desktop()->geometry().center() - QPoint(250, 250)),\ |
|
124 | 124 | QSize(500, 500)));\ |
|
125 | 125 | main_widget.show();\ |
|
126 | 126 | qApp->setActiveWindow(&main_widget);\ |
|
127 | 127 | QVERIFY(QTest::qWaitForWindowActive(&main_widget)) |
|
128 | 128 | |
|
129 | 129 | #define GET_CHILD_WIDGET_FOR_GUI_TESTS(parent, child, childType, childName)\ |
|
130 | 130 | childType* child = parent.findChild<childType*>(childName); \ |
|
131 | 131 | QVERIFY(child!=Q_NULLPTR); \ |
|
132 | 132 | setMouseTracking(child); |
|
133 | 133 | |
|
134 | 134 | #endif |
@@ -1,63 +1,82 | |||
|
1 | 1 | #include <QtTest> |
|
2 | 2 | #include <QObject> |
|
3 | 3 | #include <QString> |
|
4 | 4 | #include <QScreen> |
|
5 | 5 | #include <QMainWindow> |
|
6 | 6 | #include <QWheelEvent> |
|
7 | 7 | |
|
8 | 8 | #include <qcustomplot.h> |
|
9 | 9 | |
|
10 | 10 | #include <SqpApplication.h> |
|
11 | 11 | #include <Variable/VariableController2.h> |
|
12 | #include <Common/cpp_utils.h> | |
|
12 | 13 | |
|
13 | 14 | #include <Visualization/VisualizationGraphWidget.h> |
|
14 | 15 | #include <TestProviders.h> |
|
15 | 16 | #include <GUITestUtils.h> |
|
16 | 17 | |
|
18 | ||
|
19 | ALIAS_TEMPLATE_FUNCTION(isReady, static_cast<SqpApplication *>(qApp)->variableController().isReady) | |
|
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 | GET_CHILD_WIDGET_FOR_GUI_TESTS(w, plot, QCustomPlot, "widget");\ | |
|
33 | auto cent = center(plot);\ | |
|
34 | ||
|
35 | ||
|
17 | 36 | class A_SimpleGraph : public QObject { |
|
18 | 37 | Q_OBJECT |
|
19 | 38 | public: |
|
20 |
A_SimpleGraph(QObject* |
|
|
21 | :QObject(parent) | |
|
22 | { | |
|
23 | ||
|
24 | } | |
|
39 | explicit A_SimpleGraph(QObject *parent = Q_NULLPTR) : QObject(parent) {} | |
|
25 | 40 | |
|
26 | 41 | private slots: |
|
27 |
void scrolls_with_mouse |
|
|
42 | void scrolls_with_mouse() | |
|
28 | 43 | { |
|
29 | VisualizationGraphWidget w; | |
|
30 | PREPARE_GUI_TEST(w); | |
|
31 | auto provider = std::make_shared<SimpleRange<10>>(); | |
|
32 | auto range = DateTimeRange::fromDateTime(QDate(2018,8,7),QTime(14,00), | |
|
33 | QDate(2018,8,7),QTime(16,00)); | |
|
34 | auto var = static_cast<SqpApplication*>(qApp)->variableController().createVariable("V1", {{"","scalar"}}, provider, range); | |
|
35 | while(!static_cast<SqpApplication*>(qApp)->variableController().isReady(var))QCoreApplication::processEvents(); | |
|
36 | w.addVariable(var, range); | |
|
37 | GET_CHILD_WIDGET_FOR_GUI_TESTS(w,plot,QCustomPlot,"widget"); | |
|
38 | auto cent = center(static_cast<QWidget*>(plot)); | |
|
39 | for(auto i=0;i<10;i++) | |
|
40 | { | |
|
41 | QTest::mousePress(plot, Qt::LeftButton, Qt::NoModifier, cent, 10); | |
|
42 | QTest::mouseMove(plot, {cent.x()+100,cent.y()},10); | |
|
43 | QTest::mouseRelease(plot,Qt::LeftButton); | |
|
44 | A_SIMPLE_GRAPH_FIXTURE | |
|
45 | ||
|
46 | for (auto i = 0; i < 10; i++) { | |
|
47 | QTest::mousePress(plot, Qt::LeftButton, Qt::NoModifier, cent, 5); | |
|
48 | mouseMove(plot, {cent.x() + 200, cent.y()}, Qt::LeftButton); | |
|
49 | QTest::mouseRelease(plot, Qt::LeftButton); | |
|
50 | while (!isReady(var)) | |
|
51 | QCoreApplication::processEvents(); | |
|
52 | /* | |
|
53 | * Just for visual inspection while running tests | |
|
54 | */ | |
|
55 | plot->rescaleAxes(); | |
|
56 | plot->replot(); | |
|
57 | QCoreApplication::processEvents(); | |
|
44 | 58 | } |
|
45 | while(!static_cast<SqpApplication*>(qApp)->variableController().isReady(var))QCoreApplication::processEvents(); | |
|
59 | while (!isReady(var)) | |
|
60 | QCoreApplication::processEvents(); | |
|
61 | auto r = var->range(); | |
|
62 | QVERIFY(r.m_TEnd < range.m_TEnd); | |
|
63 | // this fails :( | |
|
64 | QVERIFY(SciQLop::numeric::almost_equal<double>(r.delta(),range.delta(),1)); | |
|
46 | 65 | } |
|
47 | 66 | }; |
|
48 | 67 | |
|
49 | 68 | QT_BEGIN_NAMESPACE |
|
50 | 69 | QTEST_ADD_GPU_BLACKLIST_SUPPORT_DEFS |
|
51 |
QT_END_NAMESPACE |
|
|
70 | QT_END_NAMESPACE | |
|
52 | 71 | int main(int argc, char *argv[]) |
|
53 | 72 | { |
|
54 | 73 | SqpApplication app{argc, argv}; |
|
55 | 74 | app.setAttribute(Qt::AA_Use96Dpi, true); |
|
56 | 75 | QTEST_DISABLE_KEYPAD_NAVIGATION |
|
57 | 76 | QTEST_ADD_GPU_BLACKLIST_SUPPORT |
|
58 | 77 | A_SimpleGraph tc; |
|
59 | 78 | QTEST_SET_MAIN_SOURCE_PATH |
|
60 | 79 | return QTest::qExec(&tc, argc, argv); |
|
61 | 80 | } |
|
62 | 81 | |
|
63 | 82 | #include "main.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now