Commit 79a262d1 authored by Timothy M. Shead's avatar Timothy M. Shead

ENH: Testing framework catches and reports more error conditions (such as unknown widget types)

ENH: pqEventPlayerXML reports errors to callers
parent b21dd1a4
......@@ -11,12 +11,13 @@
#include <QAction>
#include <QPushButton>
#include <QtDebug>
pqAbstractActivateEventPlayer::pqAbstractActivateEventPlayer()
{
}
bool pqAbstractActivateEventPlayer::playEvent(QObject* Object, const QString& Command, const QString& Arguments)
bool pqAbstractActivateEventPlayer::playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error)
{
if(Command != "activate")
return false;
......@@ -33,6 +34,8 @@ bool pqAbstractActivateEventPlayer::playEvent(QObject* Object, const QString& Co
return true;
}
return false;
qCritical() << "calling activate on unhandled type " << Object;
Error = true;
return true;
}
......@@ -19,7 +19,7 @@ class pqAbstractActivateEventPlayer :
public:
pqAbstractActivateEventPlayer();
bool playEvent(QObject* Object, const QString& Command, const QString& Arguments);
bool playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error);
private:
pqAbstractActivateEventPlayer(const pqAbstractActivateEventPlayer&);
......
......@@ -10,12 +10,13 @@
#include "pqAbstractBooleanEventPlayer.h"
#include <QAbstractButton>
#include <QtDebug>
pqAbstractBooleanEventPlayer::pqAbstractBooleanEventPlayer()
{
}
bool pqAbstractBooleanEventPlayer::playEvent(QObject* Object, const QString& Command, const QString& Arguments)
bool pqAbstractBooleanEventPlayer::playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error)
{
if(Command != "set_boolean")
return false;
......@@ -29,6 +30,8 @@ bool pqAbstractBooleanEventPlayer::playEvent(QObject* Object, const QString& Com
return true;
}
return false;
qCritical() << "calling set_boolean on unhandled type " << Object;
Error = true;
return true;
}
......@@ -19,7 +19,7 @@ class pqAbstractBooleanEventPlayer :
public:
pqAbstractBooleanEventPlayer();
bool playEvent(QObject* Object, const QString& Command, const QString& Arguments);
bool playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error);
private:
pqAbstractBooleanEventPlayer(const pqAbstractBooleanEventPlayer&);
......
......@@ -17,7 +17,7 @@ pqAbstractButtonEventTranslator::pqAbstractButtonEventTranslator() :
{
}
bool pqAbstractButtonEventTranslator::translateEvent(QObject* Object, QEvent* Event)
bool pqAbstractButtonEventTranslator::translateEvent(QObject* Object, QEvent* Event, bool& Error)
{
QAbstractButton* const object = qobject_cast<QAbstractButton*>(Object);
if(!object)
......
......@@ -21,7 +21,7 @@ class pqAbstractButtonEventTranslator :
public:
pqAbstractButtonEventTranslator();
virtual bool translateEvent(QObject* Object, QEvent* Event);
virtual bool translateEvent(QObject* Object, QEvent* Event, bool& Error);
private:
pqAbstractButtonEventTranslator(const pqAbstractButtonEventTranslator&);
......
......@@ -10,12 +10,13 @@
#include "pqAbstractDoubleEventPlayer.h"
#include <QDoubleSpinBox>
#include <QtDebug>
pqAbstractDoubleEventPlayer::pqAbstractDoubleEventPlayer()
{
}
bool pqAbstractDoubleEventPlayer::playEvent(QObject* Object, const QString& Command, const QString& Arguments)
bool pqAbstractDoubleEventPlayer::playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error)
{
if(Command != "set_double")
return false;
......@@ -28,6 +29,8 @@ bool pqAbstractDoubleEventPlayer::playEvent(QObject* Object, const QString& Comm
return true;
}
return false;
qCritical() << "calling set_double on unhandled type " << Object;
Error = true;
return true;
}
......@@ -19,7 +19,7 @@ class pqAbstractDoubleEventPlayer :
public:
pqAbstractDoubleEventPlayer();
bool playEvent(QObject* Object, const QString& Command, const QString& Arguments);
bool playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error);
private:
pqAbstractDoubleEventPlayer(const pqAbstractDoubleEventPlayer&);
......
......@@ -11,12 +11,13 @@
#include <QAbstractSlider>
#include <QSpinBox>
#include <QtDebug>
pqAbstractIntEventPlayer::pqAbstractIntEventPlayer()
{
}
bool pqAbstractIntEventPlayer::playEvent(QObject* Object, const QString& Command, const QString& Arguments)
bool pqAbstractIntEventPlayer::playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error)
{
if(Command != "set_int")
return false;
......@@ -35,6 +36,8 @@ bool pqAbstractIntEventPlayer::playEvent(QObject* Object, const QString& Command
return true;
}
return false;
qCritical() << "calling set_int on unhandled type " << Object;
Error = true;
return true;
}
......@@ -19,7 +19,7 @@ class pqAbstractIntEventPlayer :
public:
pqAbstractIntEventPlayer();
bool playEvent(QObject* Object, const QString& Command, const QString& Arguments);
bool playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error);
private:
pqAbstractIntEventPlayer(const pqAbstractIntEventPlayer&);
......
......@@ -17,7 +17,7 @@ pqAbstractSliderEventTranslator::pqAbstractSliderEventTranslator() :
{
}
bool pqAbstractSliderEventTranslator::translateEvent(QObject* Object, QEvent* Event)
bool pqAbstractSliderEventTranslator::translateEvent(QObject* Object, QEvent* Event, bool& Error)
{
QAbstractSlider* const object = qobject_cast<QAbstractSlider*>(Object);
if(!object)
......
......@@ -21,7 +21,7 @@ class pqAbstractSliderEventTranslator :
public:
pqAbstractSliderEventTranslator();
virtual bool translateEvent(QObject* Object, QEvent* Event);
virtual bool translateEvent(QObject* Object, QEvent* Event, bool& Error);
private:
pqAbstractSliderEventTranslator(const pqAbstractSliderEventTranslator&);
......
......@@ -11,12 +11,13 @@
#include <QComboBox>
#include <QLineEdit>
#include <QtDebug>
pqAbstractStringEventPlayer::pqAbstractStringEventPlayer()
{
}
bool pqAbstractStringEventPlayer::playEvent(QObject* Object, const QString& Command, const QString& Arguments)
bool pqAbstractStringEventPlayer::playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error)
{
if(Command != "set_string")
return false;
......@@ -35,6 +36,9 @@ bool pqAbstractStringEventPlayer::playEvent(QObject* Object, const QString& Comm
return true;
}
return false;
qCritical() << "calling set_string on unhandled type " << Object;
Error = true;
return true;
}
......@@ -19,7 +19,7 @@ class pqAbstractStringEventPlayer :
public:
pqAbstractStringEventPlayer();
bool playEvent(QObject* Object, const QString& Command, const QString& Arguments);
bool playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error);
private:
pqAbstractStringEventPlayer(const pqAbstractStringEventPlayer&);
......
......@@ -17,7 +17,7 @@ pqComboBoxEventTranslator::pqComboBoxEventTranslator() :
{
}
bool pqComboBoxEventTranslator::translateEvent(QObject* Object, QEvent* Event)
bool pqComboBoxEventTranslator::translateEvent(QObject* Object, QEvent* Event, bool& Error)
{
QComboBox* const object = qobject_cast<QComboBox*>(Object);
if(!object)
......
......@@ -21,7 +21,7 @@ class pqComboBoxEventTranslator :
public:
pqComboBoxEventTranslator();
virtual bool translateEvent(QObject* Object, QEvent* Event);
virtual bool translateEvent(QObject* Object, QEvent* Event, bool& Error);
private:
pqComboBoxEventTranslator(const pqComboBoxEventTranslator&);
......
......@@ -17,7 +17,7 @@ pqDoubleSpinBoxEventTranslator::pqDoubleSpinBoxEventTranslator() :
{
}
bool pqDoubleSpinBoxEventTranslator::translateEvent(QObject* Object, QEvent* Event)
bool pqDoubleSpinBoxEventTranslator::translateEvent(QObject* Object, QEvent* Event, bool& Error)
{
QDoubleSpinBox* const object = qobject_cast<QDoubleSpinBox*>(Object);
if(!object)
......
......@@ -21,7 +21,7 @@ class pqDoubleSpinBoxEventTranslator :
public:
pqDoubleSpinBoxEventTranslator();
virtual bool translateEvent(QObject* Object, QEvent* Event);
virtual bool translateEvent(QObject* Object, QEvent* Event, bool& Error);
private:
pqDoubleSpinBoxEventTranslator(const pqDoubleSpinBoxEventTranslator&);
......
......@@ -78,14 +78,21 @@ 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))
bool error = false;
if(this->Players[i]->playEvent(object, Command, Arguments, error))
{
if(error)
{
qCritical() << "error playing command " << Command << " object " << object;
return false;
}
QApplication::instance()->processEvents();
return true;
}
}
qCritical() << "no player for object " << object;
qCritical() << "no player for command " << Command << " object " << object;
return false;
}
......@@ -12,8 +12,9 @@
#include <QFile>
#include <QtXml/QDomDocument>
#include <QtDebug>
void pqEventPlayerXML::playXML(pqEventPlayer& Player, const QString& Path)
bool pqEventPlayerXML::playXML(pqEventPlayer& Player, const QString& Path)
{
QFile file(Path);
QDomDocument xml_document;
......@@ -21,7 +22,10 @@ void pqEventPlayerXML::playXML(pqEventPlayer& Player, const QString& Path)
QDomElement xml_events = xml_document.documentElement();
if(xml_events.nodeName() != "pqevents")
return;
{
qCritical() << Path << " is not an XML test case document";
return false;
}
for(QDomNode xml_event = xml_events.firstChild(); !xml_event.isNull(); xml_event = xml_event.nextSibling())
{
......@@ -32,7 +36,10 @@ void pqEventPlayerXML::playXML(pqEventPlayer& Player, const QString& Path)
const QString command = xml_event.toElement().attribute("command");
const QString arguments = xml_event.toElement().attribute("arguments");
Player.playEvent(object, command, arguments);
if(!Player.playEvent(object, command, arguments))
return false;
}
return true;
}
......@@ -17,7 +17,8 @@ class pqEventPlayer;
class pqEventPlayerXML
{
public:
void playXML(pqEventPlayer& Player, const QString& Path);
/// Loads an XML test case from a file, and plays it with the given player, returning true iff every command was successfully executed
bool playXML(pqEventPlayer& Player, const QString& Path);
};
#endif // !_pqEventPlayerXML_h
......
......@@ -89,8 +89,13 @@ bool pqEventTranslator::eventFilter(QObject* Object, QEvent* Event)
{
for(int i = 0; i != this->Implementation->Translators.size(); ++i)
{
if(this->Implementation->Translators[i]->translateEvent(Object, Event))
bool error = false;
if(this->Implementation->Translators[i]->translateEvent(Object, Event, error))
{
if(error)
qWarning() << "Error translating an event for object " << Object;
return false;
}
}
return false;
......
......@@ -18,7 +18,7 @@ pqLineEditEventTranslator::pqLineEditEventTranslator() :
{
}
bool pqLineEditEventTranslator::translateEvent(QObject* Object, QEvent* Event)
bool pqLineEditEventTranslator::translateEvent(QObject* Object, QEvent* Event, bool& Error)
{
QLineEdit* const object = qobject_cast<QLineEdit*>(Object);
if(!object)
......
......@@ -21,7 +21,7 @@ class pqLineEditEventTranslator :
public:
pqLineEditEventTranslator();
virtual bool translateEvent(QObject* Object, QEvent* Event);
virtual bool translateEvent(QObject* Object, QEvent* Event, bool& Error);
private:
pqLineEditEventTranslator(const pqLineEditEventTranslator&);
......
......@@ -22,7 +22,7 @@ pqMenuEventTranslator::~pqMenuEventTranslator()
clearActions();
}
bool pqMenuEventTranslator::translateEvent(QObject* Object, QEvent* Event)
bool pqMenuEventTranslator::translateEvent(QObject* Object, QEvent* Event, bool& Error)
{
QMenu* const object = qobject_cast<QMenu*>(Object);
if(!object)
......
......@@ -24,7 +24,7 @@ public:
pqMenuEventTranslator();
~pqMenuEventTranslator();
virtual bool translateEvent(QObject* Object, QEvent* Event);
virtual bool translateEvent(QObject* Object, QEvent* Event, bool& Error);
private:
pqMenuEventTranslator(const pqMenuEventTranslator&);
......
......@@ -17,7 +17,7 @@ pqSpinBoxEventTranslator::pqSpinBoxEventTranslator() :
{
}
bool pqSpinBoxEventTranslator::translateEvent(QObject* Object, QEvent* Event)
bool pqSpinBoxEventTranslator::translateEvent(QObject* Object, QEvent* Event, bool& Error)
{
QSpinBox* const object = qobject_cast<QSpinBox*>(Object);
if(!object)
......
......@@ -21,7 +21,7 @@ class pqSpinBoxEventTranslator :
public:
pqSpinBoxEventTranslator();
virtual bool translateEvent(QObject* Object, QEvent* Event);
virtual bool translateEvent(QObject* Object, QEvent* Event, bool& Error);
private:
pqSpinBoxEventTranslator(const pqSpinBoxEventTranslator&);
......
......@@ -19,7 +19,8 @@ class pqWidgetEventPlayer
public:
virtual ~pqWidgetEventPlayer() {}
virtual bool playEvent(QObject* Object, const QString& Command, const QString& Arguments) = 0;
/// Derivatives should implement this and play-back the given command, returning "true" if they handled the command, and setting Error to "true" if there were any problems.
virtual bool playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error) = 0;
protected:
pqWidgetEventPlayer() {}
......
......@@ -20,7 +20,9 @@ class pqWidgetEventTranslator :
public:
virtual ~pqWidgetEventTranslator() {}
virtual bool translateEvent(QObject* Object, QEvent* Event) = 0;
/// Derivatives should implement this and translate events into commands, returning "true" if they handled the event, and setting Error to "true" if there were any problems
virtual bool translateEvent(QObject* Object, QEvent* Event, bool& Error) = 0;
signals:
/// Derivatives should emit this signal whenever they wish to record a high-level event
......
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