Commit d2bd50b4 authored by Timothy M. Shead's avatar Timothy M. Shead
Browse files

ENH: Testing framework gives Qt a chance to process events between each...

ENH: Testing framework gives Qt a chance to process events between each executed command, to simulate user interaction more closely
ENH: Testing framework translates pqAbstractButton events uniformly, replacing separate check box and push button translators
parent 6ece0440
......@@ -13,8 +13,8 @@ INCLUDE_DIRECTORIES(
)
QT4_WRAP_CPP(MOC_BUILT_SOURCES
pqAbstractButtonEventTranslator.h
pqAbstractSliderEventTranslator.h
pqCheckBoxEventTranslator.h
pqComboBoxEventTranslator.h
pqDoubleSpinBoxEventTranslator.h
pqEventObserverStdout.h
......@@ -23,7 +23,6 @@ QT4_WRAP_CPP(MOC_BUILT_SOURCES
pqLineEditEventTranslator.h
pqMenuEventTranslator.h
pqMenuEventTranslatorAdaptor.h
pqPushButtonEventTranslator.h
pqRecordEventsDialog.h
pqSpinBoxEventTranslator.h
pqWidgetEventTranslator.h
......@@ -38,6 +37,8 @@ ADD_LIBRARY(QtTesting
pqAbstractActivateEventPlayer.h
pqAbstractBooleanEventPlayer.cxx
pqAbstractBooleanEventPlayer.h
pqAbstractButtonEventTranslator.cxx
pqAbstractButtonEventTranslator.h
pqAbstractDoubleEventPlayer.cxx
pqAbstractDoubleEventPlayer.h
pqAbstractIntEventPlayer.cxx
......@@ -46,8 +47,6 @@ ADD_LIBRARY(QtTesting
pqAbstractSliderEventTranslator.h
pqAbstractStringEventPlayer.cxx
pqAbstractStringEventPlayer.h
pqCheckBoxEventTranslator.cxx
pqCheckBoxEventTranslator.h
pqComboBoxEventTranslator.cxx
pqComboBoxEventTranslator.h
pqDoubleSpinBoxEventTranslator.cxx
......@@ -68,8 +67,6 @@ ADD_LIBRARY(QtTesting
pqMenuEventTranslator.h
pqMenuEventTranslatorAdaptor.cxx
pqMenuEventTranslatorAdaptor.h
pqPushButtonEventTranslator.cxx
pqPushButtonEventTranslator.h
pqRecordEventsDialog.cxx
pqRecordEventsDialog.h
pqSpinBoxEventTranslator.cxx
......
......@@ -9,7 +9,7 @@
#include "pqAbstractBooleanEventPlayer.h"
#include <QCheckBox>
#include <QAbstractButton>
pqAbstractBooleanEventPlayer::pqAbstractBooleanEventPlayer()
{
......@@ -22,7 +22,7 @@ bool pqAbstractBooleanEventPlayer::playEvent(QObject* Object, const QString& Com
const bool value = Arguments == "true" ? true : false;
if(QCheckBox* const object = qobject_cast<QCheckBox*>(Object))
if(QAbstractButton* const object = qobject_cast<QAbstractButton*>(Object))
{
if(value != object->isChecked())
object->setChecked(value);
......
......@@ -7,19 +7,19 @@
* statement of authorship are reproduced on all copies.
*/
#include "pqPushButtonEventTranslator.h"
#include "pqAbstractButtonEventTranslator.h"
#include <QPushButton>
#include <QAbstractButton>
#include <QEvent>
pqPushButtonEventTranslator::pqPushButtonEventTranslator() :
pqAbstractButtonEventTranslator::pqAbstractButtonEventTranslator() :
CurrentObject(0)
{
}
bool pqPushButtonEventTranslator::translateEvent(QObject* Object, QEvent* Event)
bool pqAbstractButtonEventTranslator::translateEvent(QObject* Object, QEvent* Event)
{
QPushButton* const object = qobject_cast<QPushButton*>(Object);
QAbstractButton* const object = qobject_cast<QAbstractButton*>(Object);
if(!object)
return false;
......@@ -27,7 +27,10 @@ bool pqPushButtonEventTranslator::translateEvent(QObject* Object, QEvent* Event)
{
case QEvent::Enter:
this->CurrentObject = Object;
connect(object, SIGNAL(clicked(bool)), this, SLOT(onClicked(bool)));
if(object->isCheckable())
connect(object, SIGNAL(clicked(bool)), this, SLOT(onToggled(bool)));
else
connect(object, SIGNAL(clicked(bool)), this, SLOT(onClicked(bool)));
break;
case QEvent::Leave:
disconnect(Object, 0, this, 0);
......@@ -38,7 +41,13 @@ bool pqPushButtonEventTranslator::translateEvent(QObject* Object, QEvent* Event)
return true;
}
void pqPushButtonEventTranslator::onClicked(bool)
void pqAbstractButtonEventTranslator::onClicked(bool)
{
emit recordEvent(this->CurrentObject, "activate", "");
}
void pqAbstractButtonEventTranslator::onToggled(bool Checked)
{
emit recordEvent(this->CurrentObject, "set_boolean", Checked ? "true" : "false");
}
......@@ -7,31 +7,32 @@
* statement of authorship are reproduced on all copies.
*/
#ifndef _pqPushButtonEventTranslator_h
#define _pqPushButtonEventTranslator_h
#ifndef _pqAbstractButtonEventTranslator_h
#define _pqAbstractButtonEventTranslator_h
#include "pqWidgetEventTranslator.h"
/// Translates low-level Qt push button events into high-level ParaQ events that can be recorded as test cases
class pqPushButtonEventTranslator :
class pqAbstractButtonEventTranslator :
public pqWidgetEventTranslator
{
Q_OBJECT
public:
pqPushButtonEventTranslator();
pqAbstractButtonEventTranslator();
virtual bool translateEvent(QObject* Object, QEvent* Event);
private:
pqPushButtonEventTranslator(const pqPushButtonEventTranslator&);
pqPushButtonEventTranslator& operator=(const pqPushButtonEventTranslator&);
pqAbstractButtonEventTranslator(const pqAbstractButtonEventTranslator&);
pqAbstractButtonEventTranslator& operator=(const pqAbstractButtonEventTranslator&);
QObject* CurrentObject;
private slots:
void onClicked(bool);
void onClicked(bool);
void onToggled(bool);
};
#endif // !_pqPushButtonEventTranslator_h
#endif // !_pqAbstractButtonEventTranslator_h
/*
* Copyright 2004 Sandia Corporation.
* Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
* license for use of this work by or on behalf of the
* U.S. Government. Redistribution and use in source and binary forms, with
* or without modification, are permitted provided that this Notice and any
* statement of authorship are reproduced on all copies.
*/
#include "pqCheckBoxEventTranslator.h"
#include <QCheckBox>
#include <QEvent>
pqCheckBoxEventTranslator::pqCheckBoxEventTranslator() :
CurrentObject(0)
{
}
bool pqCheckBoxEventTranslator::translateEvent(QObject* Object, QEvent* Event)
{
QCheckBox* const object = qobject_cast<QCheckBox*>(Object);
if(!object)
return false;
switch(Event->type())
{
case QEvent::Enter:
this->CurrentObject = Object;
connect(object, SIGNAL(stateChanged(int)), this, SLOT(onStateChanged(int)));
break;
case QEvent::Leave:
disconnect(Object, 0, this, 0);
this->CurrentObject = 0;
break;
}
return true;
}
void pqCheckBoxEventTranslator::onStateChanged(int State)
{
emit recordEvent(this->CurrentObject, "set_boolean", State ? "true" : "false");
}
/*
* Copyright 2004 Sandia Corporation.
* Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
* license for use of this work by or on behalf of the
* U.S. Government. Redistribution and use in source and binary forms, with
* or without modification, are permitted provided that this Notice and any
* statement of authorship are reproduced on all copies.
*/
#ifndef _pqCheckBoxEventTranslator_h
#define _pqCheckBoxEventTranslator_h
#include "pqWidgetEventTranslator.h"
/// Translates low-level Qt checkbox events into high-level ParaQ events that can be recorded as test cases
class pqCheckBoxEventTranslator :
public pqWidgetEventTranslator
{
Q_OBJECT
public:
pqCheckBoxEventTranslator();
virtual bool translateEvent(QObject* Object, QEvent* Event);
private:
pqCheckBoxEventTranslator(const pqCheckBoxEventTranslator&);
pqCheckBoxEventTranslator& operator=(const pqCheckBoxEventTranslator&);
QObject* CurrentObject;
private slots:
void onStateChanged(int);
};
#endif // !_pqCheckBoxEventTranslator_h
......@@ -15,7 +15,7 @@
#include "pqEventPlayer.h"
#include <QCoreApplication>
#include <QApplication>
#include <QObject>
#include <QStringList>
#include <QtDebug>
......@@ -23,24 +23,6 @@
namespace
{
/*
/// Given a Qt object, lookup a child object by name, assuming that all names are unique
QObject* pqFindObjectByName(QObject& Object, const QString& Name)
{
if(QObject* child = Object.findChild<QObject*>(Name))
return child;
QObjectList children = Object.children();
for(int i = 0; i != children.size(); ++i)
{
if(QObject* child = pqFindObjectByName(*children[i], Name))
return child;
}
return 0;
}
*/
/// Given a slash-delimited "path", lookup a Qt object hierarchically
QObject* pqFindObjectByTree(QObject& Root, const QString& Path)
{
......@@ -97,7 +79,10 @@ bool pqEventPlayer::playEvent(const QString& Object, const QString& Command, con
for(int i = 0; i != this->Players.size(); ++i)
{
if(this->Players[i]->playEvent(object, Command, Arguments))
{
QApplication::instance()->processEvents();
return true;
}
}
qCritical() << "no player for object " << object;
......
......@@ -7,13 +7,12 @@
* statement of authorship are reproduced on all copies.
*/
#include "pqAbstractButtonEventTranslator.h"
#include "pqAbstractSliderEventTranslator.h"
#include "pqCheckBoxEventTranslator.h"
#include "pqComboBoxEventTranslator.h"
#include "pqDoubleSpinBoxEventTranslator.h"
#include "pqLineEditEventTranslator.h"
#include "pqMenuEventTranslator.h"
#include "pqPushButtonEventTranslator.h"
#include "pqSpinBoxEventTranslator.h"
#include "pqEventTranslator.h"
......@@ -58,13 +57,12 @@ pqEventTranslator::~pqEventTranslator()
void pqEventTranslator::addDefaultWidgetEventTranslators()
{
addWidgetEventTranslator(new pqAbstractButtonEventTranslator());
addWidgetEventTranslator(new pqAbstractSliderEventTranslator());
addWidgetEventTranslator(new pqCheckBoxEventTranslator());
addWidgetEventTranslator(new pqComboBoxEventTranslator());
addWidgetEventTranslator(new pqDoubleSpinBoxEventTranslator());
addWidgetEventTranslator(new pqLineEditEventTranslator());
addWidgetEventTranslator(new pqMenuEventTranslator());
addWidgetEventTranslator(new pqPushButtonEventTranslator());
addWidgetEventTranslator(new pqSpinBoxEventTranslator());
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment