Commit 0f33bcf4 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Merge pull request #22 from mwestphal/QtTestingCheck

Qt testing check
parents 8a6abd75 548cbbea
......@@ -97,47 +97,55 @@ GET_DIRECTORY_PROPERTY(include_dirs_tmp INCLUDE_DIRECTORIES)
SET_DIRECTORY_PROPERTIES(PROPERTIES INCLUDE_DIRECTORIES "${MOC_INCLUDE_DIRS}")
SET(MOC_SRCS
pq3DViewEventTranslator.h
pq3DViewEventPlayer.h
pq3DViewEventTranslator.h
pqAbstractActivateEventPlayer.h
pqAbstractButtonEventTranslator.h
pqAbstractBooleanEventPlayer.h
pqAbstractButtonEventTranslator.h
pqAbstractDoubleEventPlayer.h
pqAbstractIntEventPlayer.h
pqAbstractItemViewEventPlayer.h
pqAbstractItemViewEventPlayerBase.h
pqAbstractItemViewEventTranslator.h
pqAbstractItemViewEventTranslatorBase.h
pqAbstractMiscellaneousEventPlayer.h
pqAbstractSliderEventTranslator.h
pqAbstractStringEventPlayer.h
pqBasicWidgetEventTranslator.h
pqBasicWidgetEventPlayer.h
pqBasicWidgetEventTranslator.h
pqCheckEventOverlay.h
pqComboBoxEventTranslator.h
pqComboBoxEventPlayer.h
pqCommentEventPlayer.h
pqDoubleSpinBoxEventTranslator.h
pqEventComment.h
pqEventDispatcher.h
pqEventObserver.h
pqEventPlayer.h
pqEventRecorder.h
pqEventSource.h
pqEventTranslator.h
pqLineEditEventTranslator.h
pqListViewEventPlayer.h
pqListViewEventTranslator.h
pqMenuEventTranslator.h
pqNativeFileDialogEventPlayer.h
pqNativeFileDialogEventTranslator.h
pqPlayBackEventsDialog.h
pqEventRecorder.h
pqRecordEventsDialog.h
pqSpinBoxEventTranslator.h
pqStdoutEventObserver.h
pqTabBarEventPlayer.h
pqTabBarEventTranslator.h
pqTableViewEventPlayer.h
pqTableViewEventTranslator.h
pqTestUtility.h
pqThreadedEventSource.h
pqTimer.h
pqTreeViewEventPlayer.h
pqTreeViewEventTranslator.h
pqWidgetEventTranslator.h
pqWidgetEventPlayer.h
pqWidgetEventTranslator.h
)
IF(QtTesting_QT_VERSION VERSION_GREATER "4")
......@@ -185,76 +193,95 @@ SET(QtTesting_SOURCES
pqAbstractDoubleEventPlayer.cxx
pqAbstractIntEventPlayer.cxx
pqAbstractItemViewEventPlayer.cxx
pqAbstractItemViewEventPlayerBase.cxx
pqAbstractItemViewEventTranslator.cxx
pqAbstractItemViewEventTranslatorBase.cxx
pqAbstractMiscellaneousEventPlayer.cxx
pqAbstractSliderEventTranslator.cxx
pqAbstractStringEventPlayer.cxx
pqBasicWidgetEventPlayer.cxx
pqBasicWidgetEventTranslator.cxx
pqCheckEventOverlay.cxx
pqComboBoxEventTranslator.cxx
pqComboBoxEventPlayer.cxx
pqCommentEventPlayer.cxx
pqDoubleSpinBoxEventTranslator.cxx
pqEventComment.cxx
pqEventDispatcher.cxx
pqEventObserver.cxx
pqEventPlayer.cxx
pqEventRecorder.cxx
pqEventTranslator.cxx
pqLineEditEventTranslator.cxx
pqListViewEventPlayer.cxx
pqListViewEventTranslator.cxx
pqMenuEventTranslator.cxx
pqNativeFileDialogEventPlayer.cxx
pqNativeFileDialogEventTranslator.cxx
pqObjectNaming.cxx
pqPlayBackEventsDialog.cxx
pqEventRecorder.cxx
pqRecordEventsDialog.cxx
pqSpinBoxEventTranslator.cxx
pqStdoutEventObserver.cxx
pqTabBarEventPlayer.cxx
pqTabBarEventTranslator.cxx
pqTableViewEventPlayer.cxx
pqTableViewEventTranslator.cxx
pqTestUtility.cxx
pqThreadedEventSource.cxx
pqTimer.cxx
pqTreeViewEventPlayer.cxx
pqTreeViewEventTranslator.cxx
pqWidgetEventPlayer.cxx
pqWidgetEventTranslator.cxx
)
SET(QtTesting_DEVEL_HEADERS
QtTestingExport.h
pq3DViewEventPlayer.h
pq3DViewEventTranslator.h
pqAbstractActivateEventPlayer.h
pqAbstractMiscellaneousEventPlayer.h
pqAbstractDoubleEventPlayer.h
pqAbstractBooleanEventPlayer.h
pqAbstractButtonEventTranslator.h
pqAbstractDoubleEventPlayer.h
pqAbstractIntEventPlayer.h
pqAbstractItemViewEventPlayer.h
pqAbstractItemViewEventPlayerBase.h
pqAbstractItemViewEventTranslator.h
pqAbstractItemViewEventTranslatorBase.h
pqAbstractMiscellaneousEventPlayer.h
pqAbstractSliderEventTranslator.h
pqAbstractStringEventPlayer.h
pqBasicWidgetEventPlayer.h
pqBasicWidgetEventTranslator.h
pqCheckEventOverlay.h
pqComboBoxEventTranslator.h
pqComboBoxEventPlayer.h
pqCommentEventPlayer.h
pqDoubleSpinBoxEventTranslator.h
pqEventComment.h
pqEventDispatcher.h
pqEventObserver.h
pqEventPlayer.h
pqEventRecorder.h
pqEventSource.h
pqEventTranslator.h
pqEventTypes.h
pqLineEditEventTranslator.h
pqListViewEventPlayer.h
pqListViewEventTranslator.h
pqMenuEventTranslator.h
pqNativeFileDialogEventPlayer.h
pqNativeFileDialogEventTranslator.h
pqObjectNaming.h
pqPlayBackEventsDialog.h
pqEventRecorder.h
pqRecordEventsDialog.h
pqSpinBoxEventTranslator.h
pqStdoutEventObserver.h
pqTabBarEventPlayer.h
pqTabBarEventTranslator.h
pqTableViewEventPlayer.h
pqTableViewEventTranslator.h
pqTestUtility.h
pqThreadedEventSource.h
pqTimer.h
......@@ -262,7 +289,6 @@ SET(QtTesting_DEVEL_HEADERS
pqTreeViewEventTranslator.h
pqWidgetEventPlayer.h
pqWidgetEventTranslator.h
QtTestingExport.h
${QtTesting_BINARY_DIR}/QtTestingConfigure.h
)
......
......@@ -59,13 +59,20 @@ protected:
}
virtual void onRecordEvent(const QString& widget, const QString& command,
const QString& arguments)
const QString& arguments, const int& eventType)
{
if(this->XMLStream)
{
this->XMLStream->writeStartElement("event");
this->XMLStream->writeAttribute("widget", widget);
this->XMLStream->writeAttribute("command", command);
if (eventType == pqEventTypes::ACTION_EVENT)
{
this->XMLStream->writeAttribute("command", command);
}
else // if(eventType == pqEventTypes::CHECK_EVENT)
{
this->XMLStream->writeAttribute("property", command);
}
this->XMLStream->writeAttribute("arguments", arguments);
this->XMLStream->writeEndElement();
}
......@@ -118,7 +125,7 @@ protected:
}
int getNextEvent(QString& widget, QString& command, QString&
arguments)
arguments,int& eventType)
{
if (this->XMLStream->atEnd())
{
......@@ -139,6 +146,7 @@ protected:
{
return DONE;
}
eventType = pqEventTypes::ACTION_EVENT;
widget = this->XMLStream->attributes().value("widget").toString();
command = this->XMLStream->attributes().value("command").toString();
arguments = this->XMLStream->attributes().value("arguments").toString();
......
......@@ -60,12 +60,14 @@ Design
~~~~~~~~~~~~~~~~~~~~~~~~~
Recording
********************************************
Test case recording centers around the pqWidgetEventTranslator abstract interface class. Derivatives of this class are responsible for converting low-level Qt events ("mouse move", "button down", "button up", etc) into the high-level events (e.g: "button activated") that can be serialized and played back. pqWidgetEventTranslator derivatives may be particular to a specific widget type, such as pqComboBoxEventTranslator, or may represent a class of related widgets, such as pqAbstractSliderEventTranslator, which can translate events for any widget that derives from QAbstractSlider, including QDial, QScrollBar, and QSlider. pqWidgetEventTranslator derivatives implement the translateEvent() method, where they determine whether they can handle a Qt event, and if they can, convert it into a high-level event which consists of two strings: a command, and the corresponding command arguments (which may be empty). The translator then emits the recordEvent() signal one-or-more times to pass the high-level event(s) to its container. It is intended that the test framework eventually include pqEventWidgetTranslator derivatives for all "stock" Qt widgets.
Test case recording centers around the pqWidgetEventTranslator abstract interface class. Derivatives of this class are responsible for converting low-level Qt events ("mouse move", "button down", "button up", etc) into the high-level events (e.g: "button activated") that can be serialized and played back. pqWidgetEventTranslator derivatives may be particular to a specific widget type, such as pqComboBoxEventTranslator, or may represent a class of related widgets, such as pqAbstractSliderEventTranslator, which can translate events for any widget that derives from QAbstractSlider, including QDial, QScrollBar, and QSlider. pqWidgetEventTranslator derivatives implement the translateEvent() method, where they determine whether they can handle a Qt event, and if they can, convert it into a high-level event which consists of two strings: a command, and the corresponding command arguments (which may be empty). The translator then emits the recordEvent() signal one-or-more times to pass the high-level event(s) to its container. It is intended that the test framework eventually include pqEventWidgetTranslator derivatives for all "stock" Qt widgets. Some events are generic for every kind of widgets ( eg. contextMenu ) and are handled by pqWidgetEventTranslator, so any derivatives should call the superclass::translateEvent method when an event cannot be treated.
A collection of pqWidgetEventTranslator objects is maintained at runtime by an instance of pqEventTranslator. pqEventTranslator hooks itself into the Qt event loop as a top-level event filter, so it receives every Qt event that occurs at runtime for the entire application. pqEventTranslator passes the Qt event to each of its pqWidgetEventTranslator instances in-turn, until one of the instances signals that the event has been "consumed". When a pqWidgetEventTranslator emits a high-level event, the event is "caught" by the pqEventTranslator instance and combined with the serializable address of the widget to which the high-level event applies. The three strings (address, command, and arguments) of the complete high-level event are emitted from the pqEventTranslator as a Qt signal.
The high-level event emitted from pqEventTranslator may be caught by any observer with the correct Qt slot. It is up to the observer(s) to serialize the high-level event for later playback. At this time the framework includes two observers, pqEventObserverStdout and pqEventObserverXML, which serialize the high-level events to stdout and an XML file respectively. Developers can create their own observers to implement custom functionality, such as serializing events to a logfile, a Python script, etc.
It is also possible to record check event, ( by using the check button on the recordDialog ). When checking, an overlay is drawned over the widget hovered by the mouse. If the overlay is green, then it means that the widget can be checked, if it's red, that it cannot. When clicking on the widget to check, a check event is recorded, associated with a QString value representing the widget "value". Translator managing check event should handle only two types QEvent, MouseMove to see if widget is checkable, and MouseButtonRelease, to record check events.
Playback
********************************************
Test case playback is basically a mirror-image of recording. The pqEventSource provides an abstract interface for objects capable of providing a "stream" of high-level events. The pqXMLEventSource provides a concrete implementation of pqEventSource, and is capable of reading the XML files generated by pqEventObserverXML.
......@@ -110,4 +112,29 @@ Checkout the application example in the "Examples" directory, and follow these s
- Link UI buttons to the myQtTestUtility "record" and "play" slots::
QObject::connect(Ui.RecordButton, SIGNAL(clicked(bool)), this, SLOT(record()));
QObject::connect(Ui.PlayBackButton, SIGNAL(clicked(bool)), this, SLOT(play()));
\ No newline at end of file
QObject::connect(Ui.PlayBackButton, SIGNAL(clicked(bool)), this, SLOT(play()));
Writing new Translators/Player
************************************************************
A new translator must at least reimplement the translateEvent(QObject object, QEvent event, int eventType, bool& error) method.
For starters, it must check that the object is of correct class
Then it should handle the pqEventTypes::ACTION_EVENT case, recording meaningfull events with identifiable command and associated arguments
And it should also handle the pqEventTypes::CHECK_EVENT case, only for two different QEvent
For QEvent::MouseMove it should return true only if a check event can be recorded
For QEvent::MouseButtonRelease , it should record a check event, associated to the value you want to check and an existing qt property or
an identified command
A new player, symmetrically, should at least reimplement the
playEvent(QObject* object, const QString& command, const QString& arguments, int eventType, bool& error) method
First it should handle the pqEventTypes::ACTION_EVENT, converting provided command and arguments into qt instructions, returning true for event that it can handle.
Then, if the the translator can record check command, it should hendle the pqEventTypes::CHECK_EVENT, checking the current value of qt object using provided command and arguments, positionning error to false
when a value differ, but returning true for all handled check event, even failed one.
Property to check are handled by pqBasicWidgetEventPlayer
See the pqLineEditEventTranslator and pqLineEditEventPlayer for a simple example and
pqAbstractItemViewEventTranslatorBase/pqAbstractItemViewEventPlayerBase for a advanced example.
<RCC>
<qresource prefix="/">
<file>Icons/check.png</file>
<file>Icons/frameForward.png</file>
<file>Icons/pause.png</file>
<file>Icons/repeat.png</file>
......
include(../CMake/qtTestingMacroGenerateMocs.cmake)
IF(QtTesting_QT_VERSION VERSION_GREATER "4")
FIND_PACKAGE(Qt5Test REQUIRED)
ADD_DEFINITIONS(${Qt5Test_DEFINITIONS})
INCLUDE_DIRECTORIES(${Qt5Test_INCLUDE_DIRS})
SET(TEST_LIBRARIES ${Qt5Test_LIBRARIES})
ELSE()
SET(TEST_LIBRARIES ${QT_QTTEST_LIBRARY})
ENDIF()
set(KIT ${PROJECT_NAME})
set(TEST_SOURCES
......@@ -39,7 +48,7 @@ else()
endif()
add_executable(${KIT}CppTests ${Tests} ${TEST_MOC_SRCS})
target_link_libraries(${KIT}CppTests ${PROJECT_NAME} ${QT_QTTEST_LIBRARY})
target_link_libraries(${KIT}CppTests ${PROJECT_NAME} ${TEST_LIBRARIES})
set_target_properties(${KIT}CppTests PROPERTIES
COMPILE_FLAGS "${Qt5Test_EXECUTABLE_COMPILE_FLAGS}")
......
......@@ -85,7 +85,11 @@ void pqAbstractButtonEventTranslatorTester::init()
this->ToolButton->resize(200,200);
this->ToolButton->show();
#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0)
QTest::qWaitForWindowShown(this->ToolButton);
#else
QTest::qWaitForWindowExposed(this->ToolButton);
#endif
// Start to record events
this->TestUtility->recordTestsBySuffix("xml");
......@@ -100,7 +104,7 @@ void pqAbstractButtonEventTranslatorTester::cleanup()
{
this->EventObserver->Text = QString();
this->TestUtility->stopRecords(0);
this->ToolButton->deleteLater();
delete this->ToolButton;
this->ToolButton = 0;
}
......@@ -177,8 +181,8 @@ void pqAbstractButtonEventTranslatorTester::testToolButton_data()
//QTest::newRow("fail") << 2 << false << false << true << false<< "toolButton, activate, #";
for (int i = 0; i < 0x20; ++i)
{
int popup = i & 0x01 ? QToolButton::ToolButtonPopupMode::DelayedPopup :
QToolButton::ToolButtonPopupMode::InstantPopup;
int popup = i & 0x01 ? QToolButton::DelayedPopup :
QToolButton::InstantPopup;
const bool withDefaultAction = i & 0x02;
const bool checkable = i & 0x04;
const bool withMenu = i & 0x08;
......@@ -193,7 +197,7 @@ void pqAbstractButtonEventTranslatorTester::testToolButton_data()
.arg(longClick);
bool longActivate = withMenu
&& popup == QToolButton::ToolButtonPopupMode::DelayedPopup
&& popup == QToolButton::DelayedPopup
&& longClick;
QString recordEmitted = QString("toolButton%1, %2, %3#")
.arg(withDefaultAction && !longActivate ? "/action" : "")
......
......@@ -37,6 +37,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// QtTesting includes
#include "pqTestUtility.h"
#include "pqEventTypes.h"
#include "pqTest.h"
......@@ -107,7 +108,14 @@ void pqDoubleSpinBoxEventPlayerTester::testPlayBackCommandSetDouble()
QString("doubleSpinBoxTest"), QString("set_double"),
QString::number(value), error);
QCOMPARE(error, false);
QCOMPARE(this->DoubleSpinBox->value(), result);
this->TestUtility->eventPlayer()->playEvent(
QString("doubleSpinBoxTest"), QString("value"),
QString::number(result), pqEventTypes::CHECK_EVENT, error);
QCOMPARE(error, false);
QCOMPARE(spy.count(), count);
}
......
......@@ -66,6 +66,9 @@ private Q_SLOTS:
void testRecordComplexClick();
void testRecordCheckMouseClick();
void testRecordCheckMouseClick_data();
private:
QDoubleSpinBox* DoubleSpinBox;
......@@ -303,6 +306,31 @@ void pqDoubleSpinBoxEventTranslatorTester::testRecordComplexClick()
recordExpected.append(QString("doubleSpinBoxTest, set_double, 0#"));
QCOMPARE(this->EventObserver->Text, recordExpected);
this->EventObserver->Text = QString();
}
// ----------------------------------------------------------------------------
void pqDoubleSpinBoxEventTranslatorTester::testRecordCheckMouseClick()
{
this->EventObserver->Text = QString();
this->DoubleSpinBox->clear();
this->DoubleSpinBox->setValue(17.17);
this->TestUtility->recorder()->check(true);
QFETCH(QString, recordEmitted);
QTest::mouseClick(this->DoubleSpinBox, Qt::LeftButton);
QCOMPARE(this->EventObserver->Text, recordEmitted);
this->EventObserver->Text = QString();
}
// ----------------------------------------------------------------------------
void pqDoubleSpinBoxEventTranslatorTester::testRecordCheckMouseClick_data()
{
QTest::addColumn<QString>("recordEmitted");
QTest::newRow("Click") << QString("%1#%2#")
.arg(QString("doubleSpinBoxTest, set_double, 17.17"),
QString("Check, doubleSpinBoxTest, value, 17.17"));
}
// ----------------------------------------------------------------------------
......
......@@ -203,16 +203,19 @@ void pqEventPlayerTester::testAddDefaultWidgetEventPlayers_data()
QTest::newRow("0") << 0 << "pqNativeFileDialogEventPlayer";
QTest::newRow("1") << 1 << "pq3DViewEventPlayer";
QTest::newRow("2") << 2 << "pqAbstractMiscellaneousEventPlayer";
QTest::newRow("3") << 3 << "pqTreeViewEventPlayer";
QTest::newRow("4") << 4 << "pqTabBarEventPlayer";
QTest::newRow("5") << 5 << "pqAbstractStringEventPlayer";
QTest::newRow("6") << 6 << "pqAbstractItemViewEventPlayer";
QTest::newRow("7") << 7 << "pqAbstractIntEventPlayer";
QTest::newRow("8") << 8 << "pqAbstractDoubleEventPlayer";
QTest::newRow("9") << 9 << "pqAbstractBooleanEventPlayer";
QTest::newRow("10") << 10 << "pqAbstractActivateEventPlayer";
QTest::newRow("11") << 11 << "pqBasicWidgetEventPlayer";
QTest::newRow("12") << 12 << "pqCommentEventPlayer";
QTest::newRow("3") << 3 << "pqListViewEventPlayer";
QTest::newRow("4") << 4 << "pqTableViewEventPlayer";
QTest::newRow("5") << 5 << "pqTreeViewEventPlayer";
QTest::newRow("6") << 6 << "pqComboBoxEventPlayer";
QTest::newRow("7") << 7 << "pqTabBarEventPlayer";
QTest::newRow("8") << 8 << "pqAbstractStringEventPlayer";
QTest::newRow("9") << 9 << "pqAbstractItemViewEventPlayer";
QTest::newRow("10") << 10 << "pqAbstractIntEventPlayer";
QTest::newRow("11") << 11 << "pqAbstractDoubleEventPlayer";
QTest::newRow("12") << 12 << "pqAbstractBooleanEventPlayer";
QTest::newRow("13") << 13 << "pqAbstractActivateEventPlayer";
QTest::newRow("14") << 14 << "pqBasicWidgetEventPlayer";
QTest::newRow("15") << 15 << "pqCommentEventPlayer";
}
// ----------------------------------------------------------------------------
......
......@@ -202,19 +202,20 @@ void pqEventTranslatorTester::testAddDefaultWidgetEventTranslators_data()
QTest::newRow("0") << 0 << "pqNativeFileDialogEventTranslator";
QTest::newRow("1") << 1 << "pq3DViewEventTranslator";
QTest::newRow("2") << 2 << "pqTreeViewEventTranslator";
QTest::newRow("3") << 3 << "pqTabBarEventTranslator";
QTest::newRow("4") << 4 << "pqSpinBoxEventTranslator";
QTest::newRow("5") << 5 << "pqMenuEventTranslator";
QTest::newRow("6") << 6 << "pqLineEditEventTranslator";
QTest::newRow("7") << 7 << "pqDoubleSpinBoxEventTranslator";
QTest::newRow("8") << 8 << "pqComboBoxEventTranslator";
QTest::newRow("9") << 9 << "pqAbstractSliderEventTranslator";
QTest::newRow("10") << 10 << "pqAbstractItemViewEventTranslator";
QTest::newRow("11") << 11 << "pqAbstractButtonEventTranslator";
QTest::newRow("12") << 12 << "pqBasicWidgetEventTranslator";
QTest::newRow("2") << 2 << "pqListViewEventTranslator";
QTest::newRow("3") << 3 << "pqTableViewEventTranslator";
QTest::newRow("4") << 4 << "pqTreeViewEventTranslator";
QTest::newRow("5") << 5 << "pqTabBarEventTranslator";
QTest::newRow("6") << 6 << "pqSpinBoxEventTranslator";
QTest::newRow("7") << 7 << "pqMenuEventTranslator";
QTest::newRow("8") << 8 << "pqLineEditEventTranslator";
QTest::newRow("9") << 9 << "pqDoubleSpinBoxEventTranslator";
QTest::newRow("10") << 10 << "pqComboBoxEventTranslator";
QTest::newRow("11") << 11 << "pqAbstractSliderEventTranslator";
QTest::newRow("12") << 12 << "pqAbstractItemViewEventTranslator";
QTest::newRow("13") << 13 << "pqAbstractButtonEventTranslator";
QTest::newRow("14") << 14 << "pqBasicWidgetEventTranslator";
}
// ----------------------------------------------------------------------------
CTK_TEST_MAIN(pqEventTranslatorTest)
#include "moc_pqEventTranslatorTest.cpp"
......@@ -35,6 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QtTest/QtTest>
// QtTesting includes
#include "pqEventTypes.h"
#include "pqTestUtility.h"
#include "pqTest.h"
......@@ -105,6 +106,11 @@ void pqSpinBoxEventPlayerTester::testPlayBackCommandSetInt()
QString("spinBoxTest"), QString("set_int"), QString::number(value), error);
QCOMPARE(this->SpinBox->value(), result);
QCOMPARE(error, false);
this->TestUtility->eventPlayer()->playEvent(
QString("spinBoxTest"), QString("value"), QString::number(result), pqEventTypes::CHECK_EVENT, error);
QCOMPARE(error, false);
QCOMPARE(spy.count(), count);
}
......
......@@ -66,6 +66,9 @@ private Q_SLOTS:
void testRecordComplexClick();
void testRecordCheckMouseClick();
void testRecordCheckMouseClick_data();
private:
QSpinBox* SpinBox;
......@@ -289,6 +292,31 @@ void pqSpinBoxEventTranslatorTester::testRecordComplexClick()
recordExpected.append(QString("spinBoxTest, set_int, 0#"));
QCOMPARE(this->EventObserver->Text, recordExpected);
this->EventObserver->Text = QString();
}
// ----------------------------------------------------------------------------
void pqSpinBoxEventTranslatorTester::testRecordCheckMouseClick()
{
this->EventObserver->Text = QString();
this->SpinBox->clear();
this->SpinBox->setValue(17);
this->TestUtility->recorder()->check(true);
QFETCH(QString, recordEmitted);
QTest::mouseClick(this->SpinBox, Qt::LeftButton);
QCOMPARE(this->EventObserver->Text, recordEmitted);
this->EventObserver->Text = QString();
}
// ----------------------------------------------------------------------------
void pqSpinBoxEventTranslatorTester::testRecordCheckMouseClick_data()
{
QTest::addColumn<QString>("recordEmitted");
QTest::newRow("Click") << QString("%1#%2#")
.arg(QString("spinBoxTest, set_int, 17"),
QString("Check, spinBoxTest, value, 17"));
}
// ----------------------------------------------------------------------------
......
......@@ -76,11 +76,21 @@ public:
public slots:
virtual void onRecordEvent(const QString& widget,
const QString& command,
const QString& arguments)
const QString& arguments,
const int& eventType)
{
if (eventType == pqEventTypes::CHECK_EVENT)
{
this->Text.append(QString("Check, %1, %2, %3#").arg(widget,
command,
arguments));
}
else
{
this->Text.append(QString("%1, %2, %3#").arg(widget,
command,
arguments));
}
}
};
......@@ -103,7 +113,8 @@ protected:
int getNextEvent(QString& /*widget*/,
QString& /*command*/,
QString& /*arguments*/)
QString& /*arguments*/,
int& /*eventType*/)
{
return 0;
}
......
......@@ -47,7 +47,7 @@ pq3DViewEventPlayer::pq3DViewEventPlayer(const QByteArray& classname, QObject *
bool pq3DViewEventPlayer::playEvent(QObject* Object,
const QString& Command,
const QString& Arguments,
bool& pqNotUsed(Error))
bool& Error)
{
QWidget* widget = qobject_cast<QWidget*>(Object);
if(widget && Object->inherits(mClassType.data()))
......@@ -75,6 +75,6 @@ bool pq3DViewEventPlayer::playEvent(QObject* Object,
return true;
}
}
return false;
return this->Superclass::playEvent(Object, Command, Arguments, Error);
}
......@@ -45,6 +45,7 @@ class QTTESTING_EXPORT pq3DViewEventPlayer :
public pqWidgetEventPlayer
{
Q_OBJECT
typedef pqWidgetEventPlayer Superclass;
public:
pq3DViewEventPlayer(const QByteArray& classname, QObject* p = 0);
......
......@@ -49,105 +49,106 @@ pq3DViewEventTranslator::~pq3DViewEventTranslator()
}
bool pq3DViewEventTranslator::translateEvent(QObject* Object, QEvent* Event,
bool& /*Error*/)
bool& Error)
{
QWidget* widget = qobject_cast<QWidget*>(Object);
if(!widget || !Object->inherits(mClassType.data()))
QWidget* widget = qobject_cast<QWidget*>(Object);
if(!widget || !Object->inherits(mClassType.data()))
{
return false;
return false;
}
bool handled = false;
switch(Event->type())
{
switch(Event->type())
{
case QEvent::ContextMenu:
handled=true;
{
return true;
break;
}
case QEvent::MouseButtonPress:
{
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(Event);
if (mouseEvent)
{
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(Event);
if (mouseEvent)
{
QSize size = widget->size();
double normalized_x = mouseEvent->x()/static_cast<double>(size.width());
double normalized_y = mouseEvent->y()/static_cast<double>(size.height());
int button = mouseEvent->button();
int buttons = mouseEvent->buttons();
int modifiers = mouseEvent->modifiers();
emit recordEvent(Object, "mousePress", QString("(%1,%2,%3,%4,%5)")
.arg(normalized_x)
.arg(normalized_y)
.arg(button)
.arg(buttons)
.arg(modifiers));
}
QSize size = widget->size();
double normalized_x = mouseEvent->x()/static_cast<double>(size.width());
double normalized_y = mouseEvent->y()/static_cast<double>(size.height());
int button = mouseEvent->button();
int buttons = mouseEvent->buttons();
int modifiers = mouseEvent->modifiers();
emit recordEvent(Object, "mousePress", QString("(%1,%2,%3,%4,%5)")
.arg(normalized_x)
.arg(normalized_y)
.arg(button)
.arg(buttons)
.arg(modifiers));
}
// reset lastMoveEvent
QMouseEvent e(QEvent::MouseButtonPress, QPoint(), Qt::MouseButton(),
Qt::MouseButtons(), Qt::KeyboardModifiers());
// reset lastMoveEvent
QMouseEvent e(QEvent::MouseButtonPress, QPoint(), Qt::MouseButton(),
Qt::MouseButtons(), Qt::KeyboardModifiers());
lastMoveEvent = e;
}
handled = true;
lastMoveEvent = e;
return true;
break;
}
case QEvent::MouseMove:
case QEvent::MouseMove:
{
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(Event);
if (mouseEvent)
{
QMouseEvent e(QEvent::MouseMove, QPoint(mouseEvent->x(), mouseEvent->y()),
mouseEvent->button(), mouseEvent->buttons(),
mouseEvent->modifiers());
lastMoveEvent = e;
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(Event);
if (mouseEvent)
{
QMouseEvent e(QEvent::MouseMove, QPoint(mouseEvent->x(), mouseEvent->y()),
mouseEvent->button(), mouseEvent->buttons(),
mouseEvent->modifiers());
lastMoveEvent = e;
}
}
handled = true;
return true;
break;
}
case QEvent::MouseButtonRelease:
{
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(Event);
if (mouseEvent)
{
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(Event);
if (mouseEvent)
QSize size = widget->size();
// record last move event if it is valid
if(lastMoveEvent.type() == QEvent::MouseMove)
{
QSize size = widget->size();