Commit f8e1cb34 authored by Timothy M. Shead's avatar Timothy M. Shead

ENH: Implemented test case playback

BUG: About box implementation interfered with test case playback
ENH: Consistent naming of menu actions for test case recording
ENH: pqSetName, pqSetData, and pqConnect components enable easy menu generation without lots of temporaries
parent ae98ed28
......@@ -57,6 +57,8 @@ ADD_LIBRARY(QtTesting
pqEventObserverXML.h
pqEventPlayer.cxx
pqEventPlayer.h
pqEventPlayerXML.cxx
pqEventPlayerXML.h
pqEventTranslator.cxx
pqEventTranslator.h
pqLineEditEventTranslator.cxx
......@@ -79,5 +81,6 @@ ADD_LIBRARY(QtTesting
TARGET_LINK_LIBRARIES(QtTesting
${QT_LIBRARIES}
${QT_XML_LIBRARIES}
)
......@@ -24,12 +24,10 @@ pqEventObserverXML::~pqEventObserverXML()
void pqEventObserverXML::onRecordEvent(const QString& Widget, const QString& Command, const QString& Arguments)
{
this->Stream
<< "\t<pqevent><widget>"
<< Widget.toAscii().data()
<< "</widget><command>"
<< Command.toAscii().data()
<< "</command><arguments>"
<< Arguments.toAscii().data()
<< "</arguments></pqevent>\n";
<< "\t<pqevent "
<< "object=\"" << Widget.toAscii().data() << "\" "
<< "command=\"" << Command.toAscii().data() << "\" "
<< "arguments=\"" << Arguments.toAscii().data() << "\" "
<< "/>\n";
}
......@@ -17,10 +17,13 @@
#include <QCoreApplication>
#include <QObject>
#include <QStringList>
#include <QtDebug>
namespace
{
/*
/// Given a Qt object, lookup a child object by name, assuming that all names are unique
QObject* pqFindObjectByName(QObject& Object, const QString& Name)
{
......@@ -36,6 +39,21 @@ QObject* pqFindObjectByName(QObject& Object, const QString& Name)
return 0;
}
*/
/// Given a slash-delimited "path", lookup a Qt object hierarchically
QObject* pqFindObjectByTree(QObject& Root, const QString& Path)
{
QObject* object = &Root;
const QStringList paths = Path.split("/");
for(int i = 1; i < paths.size(); ++i) // Note - we're ignoring the top-level path, since it already represents the root node
{
if(object)
object = object->findChild<QObject*>(paths[i]);
}
return object;
}
} // namespace
......@@ -69,16 +87,20 @@ void pqEventPlayer::addWidgetEventPlayer(pqWidgetEventPlayer* Player)
bool pqEventPlayer::playEvent(const QString& Object, const QString& Command, const QString& Arguments)
{
QObject* object = pqFindObjectByName(RootObject, Object);
QObject* object = pqFindObjectByTree(RootObject, Object);
if(!object)
{
qCritical() << "could not locate object " << Object;
return false;
}
for(int i = 0; i != this->Players.size(); ++i)
{
if(this->Players[i]->playEvent(object, Command, Arguments))
return true;
}
qCritical() << "no player for object " << object;
return 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.
*/
#include "pqEventPlayer.h"
#include "pqEventPlayerXML.h"
#include <QFile>
#include <QtXml/QDomDocument>
void pqEventPlayerXML::playXML(pqEventPlayer& Player, const QString& Path)
{
QFile file(Path);
QDomDocument xml_document;
xml_document.setContent(&file, false);
QDomElement xml_events = xml_document.documentElement();
if(xml_events.nodeName() != "pqevents")
return;
for(QDomNode xml_event = xml_events.firstChild(); !xml_event.isNull(); xml_event = xml_event.nextSibling())
{
if(!(xml_event.isElement() && xml_event.nodeName() == "pqevent"))
continue;
const QString object = xml_event.toElement().attribute("object");
const QString command = xml_event.toElement().attribute("command");
const QString arguments = xml_event.toElement().attribute("arguments");
Player.playEvent(object, command, arguments);
}
}
/*
* 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 _pqEventPlayerXML_h
#define _pqEventPlayerXML_h
#include <QString>
class pqEventPlayer;
class pqEventPlayerXML
{
public:
void playXML(pqEventPlayer& Player, const QString& Path);
};
#endif // !_pqEventPlayerXML_h
......@@ -81,8 +81,17 @@ void pqEventTranslator::onRecordEvent(QObject* Object, const QString& Command, c
}
for(QObject* parent = Object->parent(); parent; parent = parent->parent())
{
if(parent->objectName().isEmpty())
{
qWarning() << "Incompletely-named object " << Object;
// return;
}
name = parent->objectName() + "/" + name;
}
qDebug() << "Event: " << name << " " << Command << " " << Arguments;
emit recordEvent(name, Command, Arguments);
}
......@@ -47,7 +47,7 @@ pqRecordEventsDialog::pqRecordEventsDialog(const QString& Path, QWidget* Parent)
this->Ui.label->setText(QString(tr("Recording User Input to %1")).arg(Path));
this->setWindowTitle(tr("Recording User Input"));
this->setObjectName("RecordEventsDialog");
this->setObjectName("");
}
pqRecordEventsDialog::~pqRecordEventsDialog()
......
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