##// END OF EJS Templates
Again a dmg fix :)...
Again a dmg fix :) Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r1422:a323cf6b7201
r1470:04e52d50cd7a
Show More
GUITestUtils.h
171 lines | 5.3 KiB | text/x-c | CLexer
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 #ifndef GUITESTUTILS_H
#define GUITESTUTILS_H
#include <Common/cpp_utils.h>
New Catalogue API WIP, basic models and views implemented...
r1406 #include <QCoreApplication>
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 #include <QCursor>
New Catalogue API WIP, basic models and views implemented...
r1406 #include <QDesktopWidget>
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 #include <QMouseEvent>
New Catalogue API WIP, basic models and views implemented...
r1406 #include <QPoint>
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 #include <QtTest>
More GUI tests refactoring, this will allow more complex tests and ease sync graph tests...
r1370 #include <SqpApplication.h>
New Catalogue API WIP, basic models and views implemented...
r1406 #include <Variable/VariableController2.h>
#include <qcustomplot.h>
More GUI tests refactoring, this will allow more complex tests and ease sync graph tests...
r1370
simple graph unit test: simple scroll implemented...
r1361 template <typename T>
QPoint center(T* widget)
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 {
New Catalogue API WIP, basic models and views implemented...
r1406 return QPoint { widget->width() / 2, widget->height() / 2 };
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 }
HAS_METHOD(viewport)
simple graph unit test: simple scroll implemented...
r1361 template <typename T>
New Catalogue API WIP, basic models and views implemented...
r1406 static inline constexpr bool is_QWidgetOrDerived = std::is_base_of<QWidget, T>::value;
simple graph unit test: simple scroll implemented...
r1361
New Catalogue API WIP, basic models and views implemented...
r1406 template <typename T>
using viewport_type = decltype(std::declval<T>().viewport());
simple graph unit test: simple scroll implemented...
r1361
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 HAS_METHOD(topLevelItem)
New Catalogue API WIP, basic models and views implemented...
r1406 template <typename T>
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 void mouseMove(T* widget, QPoint pos, Qt::MouseButton mouseModifier)
{
QCursor::setPos(widget->mapToGlobal(pos));
QMouseEvent event(QEvent::MouseMove, pos, Qt::NoButton, mouseModifier, Qt::NoModifier);
New Catalogue API WIP, basic models and views implemented...
r1406 if constexpr (has_viewport<T>)
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 {
New Catalogue API WIP, basic models and views implemented...
r1406 if constexpr (is_QWidgetOrDerived<viewport_type<T>>)
Partly reimplemented Graph event handling + bugfix...
r1362 {
qApp->sendEvent(widget->viewport(), &event);
}
else
{
qApp->sendEvent(widget, &event);
}
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 }
else
{
qApp->sendEvent(widget, &event);
}
qApp->processEvents();
}
template <typename T>
void setMouseTracking(T* widget)
{
New Catalogue API WIP, basic models and views implemented...
r1406 if constexpr (has_viewport<T>)
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 {
New Catalogue API WIP, basic models and views implemented...
r1406 if constexpr (is_QWidgetOrDerived<viewport_type<T>>)
Partly reimplemented Graph event handling + bugfix...
r1362 {
widget->viewport()->setMouseTracking(true);
}
else
{
widget->setMouseTracking(true);
}
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 }
else
{
widget->setMouseTracking(true);
}
}
template <typename T, typename T2>
auto getItem(T* widget, T2 itemIndex)
{
New Catalogue API WIP, basic models and views implemented...
r1406 if constexpr (has_topLevelItem<T>)
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 {
New Catalogue API WIP, basic models and views implemented...
r1406 return widget->topLevelItem(itemIndex);
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 }
else
{
New Catalogue API WIP, basic models and views implemented...
r1406 return widget->item(itemIndex);
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 }
}
New Catalogue API WIP, basic models and views implemented...
r1406 #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)); \
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 }
New Catalogue API WIP, basic models and views implemented...
r1406 #define GET_CHILD_WIDGET_FOR_GUI_TESTS(parent, child, childType, childName) \
childType* child = parent.findChild<childType*>(childName); \
QVERIFY(child != Q_NULLPTR); \
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 setMouseTracking(child);
New Catalogue API WIP, basic models and views implemented...
r1406 template <typename T1, typename T2, typename T3, typename T4 = void>
void dragnDropItem(T1* sourceWidget, T2* destWidget, T3* item, T4* destItem = Q_NULLPTR)
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 {
auto itemCenterPos = sourceWidget->visualItemRect(item).center();
New Catalogue API WIP, basic models and views implemented...
r1406 if constexpr (has_viewport<T1>)
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 {
QTest::mousePress(sourceWidget->viewport(), Qt::LeftButton, Qt::NoModifier, itemCenterPos);
}
else
{
QTest::mousePress(sourceWidget, Qt::LeftButton, Qt::NoModifier, itemCenterPos);
}
New Catalogue API WIP, basic models and views implemented...
r1406 mouseMove(sourceWidget, itemCenterPos, Qt::LeftButton);
itemCenterPos += QPoint(0, -10);
QTimer::singleShot(100, [destWidget, destItem]() {
mouseMove(destWidget, destWidget->rect().center(), Qt::LeftButton);
mouseMove(destWidget, destWidget->rect().center() + QPoint(0, -10), Qt::LeftButton);
if constexpr (!std::is_same_v<void, T4>)
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 {
auto destItemCenterPos = destWidget->visualItemRect(destItem).center();
QTest::mouseRelease(destWidget, Qt::LeftButton, Qt::NoModifier, destItemCenterPos);
}
New Catalogue API WIP, basic models and views implemented...
r1406 else if constexpr (has_viewport<T2>)
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 {
QTest::mouseRelease(destWidget->viewport(), Qt::LeftButton);
}
else
{
QTest::mouseRelease(destWidget, Qt::LeftButton);
}
QTest::mouseRelease(destWidget->viewport(), Qt::LeftButton);
});
New Catalogue API WIP, basic models and views implemented...
r1406 mouseMove(sourceWidget, itemCenterPos, Qt::LeftButton);
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 }
More GUI tests refactoring, this will allow more complex tests and ease sync graph tests...
r1370 template <typename T>
void scroll_graph(T* w, int dx)
{
auto cent = center(w);
QTest::mousePress(w, Qt::LeftButton, Qt::NoModifier, cent, 1);
New Catalogue API WIP, basic models and views implemented...
r1406 mouseMove(w, { cent.x() + dx, cent.y() }, Qt::LeftButton);
More GUI tests refactoring, this will allow more complex tests and ease sync graph tests...
r1370 QTest::mouseRelease(w, Qt::LeftButton);
}
New Catalogue API WIP, basic models and views implemented...
r1406 ALIAS_TEMPLATE_FUNCTION(isReady, static_cast<SqpApplication*>(qApp)->variableController().isReady)
More GUI tests refactoring, this will allow more complex tests and ease sync graph tests...
r1370
Switched to new TS impl but quite broken!...
r1420 void waitForVar(std::shared_ptr<Variable2> var)
More GUI tests refactoring, this will allow more complex tests and ease sync graph tests...
r1370 {
while (!isReady(var))
QCoreApplication::processEvents();
}
New Catalogue API WIP, basic models and views implemented...
r1406 template <typename T>
Some test refac and prepared synchronized graph test...
r1369 bool prepare_gui_test(T* w)
{
New Catalogue API WIP, basic models and views implemented...
r1406 w->setGeometry(QRect(
QPoint(QApplication::desktop()->geometry().center() - QPoint(250, 250)), QSize(500, 500)));
Some test refac and prepared synchronized graph test...
r1369 w->show();
qApp->setActiveWindow(w);
return QTest::qWaitForWindowActive(w);
}
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360
New Catalogue API WIP, basic models and views implemented...
r1406 #define GET_CHILD_WIDGET_FOR_GUI_TESTS(parent, child, childType, childName) \
childType* child = parent.findChild<childType*>(childName); \
QVERIFY(child != Q_NULLPTR); \
Added GUI Test Utils lib to share boilerplate code for UI testing...
r1360 setMouseTracking(child);
#endif