Updates will be applied tomorrow - Jan 26th, at 12pm EST (UTC-0500). GitLlab could be a little slow between 12 - 12:30pm EST.

Commit dac049b0 authored by Benjamin Long's avatar Benjamin Long

ENH: Modify the QtTesting recording

Create a new class pqEventRecorder to be charged of the QtTesting record.
 - Added a new behavior to be able to flush the record after each actions
recorded.
 This behavior is only possible if your custom observer write in the
TextStream after each actions.
parent ca088972
......@@ -109,6 +109,7 @@ QT4_WRAP_CPP(MOC_BUILT_SOURCES
pqNativeFileDialogEventPlayer.h
pqNativeFileDialogEventTranslator.h
pqPlayBackEventsDialog.h
pqEventRecorder.h
pqRecordEventsDialog.h
pqSpinBoxEventTranslator.h
pqStdoutEventObserver.h
......@@ -163,6 +164,7 @@ SET(QtTesting_SOURCES
pqNativeFileDialogEventTranslator.cxx
pqObjectNaming.cxx
pqPlayBackEventsDialog.cxx
pqEventRecorder.cxx
pqRecordEventsDialog.cxx
pqSpinBoxEventTranslator.cxx
pqStdoutEventObserver.cxx
......@@ -205,6 +207,7 @@ SET(QtTesting_DEVEL_HEADERS
pqNativeFileDialogEventTranslator.h
pqObjectNaming.h
pqPlayBackEventsDialog.h
pqEventRecorder.h
pqRecordEventsDialog.h
pqSpinBoxEventTranslator.h
pqStdoutEventObserver.h
......
......@@ -65,6 +65,11 @@ public slots:
const QString& Command,
const QString& Arguments) = 0;
signals:
void eventRecorded(const QString& Widget,
const QString& Command,
const QString& Arguments);
protected:
QTextStream* Stream;
};
......
/*=========================================================================
Program: ParaView
Module: pqEventDispatcher.h
Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
// Qt includes
#include <QDebug>
#include <QIODevice>
#include <QTextStream>
// QtTesting includes
#include "pqEventObserver.h"
#include "pqEventRecorder.h"
#include "pqEventTranslator.h"
// ----------------------------------------------------------------------------
pqEventRecorder::pqEventRecorder(QObject *parent)
: Superclass(parent)
{
this->ActiveObserver = 0;
this->ActiveTranslator = 0;
this->ContinuousFlush = false;
}
// ----------------------------------------------------------------------------
pqEventRecorder::~pqEventRecorder()
{
this->ActiveObserver = 0;
this->ActiveTranslator = 0;
}
// ----------------------------------------------------------------------------
void pqEventRecorder::setContinuousFlush(bool value)
{
if (value)
{
QObject::connect(this->ActiveObserver,
SIGNAL(eventRecorded(QString,QString,QString)),
this, SLOT(flush()));
}
else
{
QObject::disconnect(this->ActiveObserver,
SIGNAL(eventRecorded(QString,QString,QString)),
this, SLOT(flush()));
}
this->ContinuousFlush = value;
}
// ----------------------------------------------------------------------------
bool pqEventRecorder::continuousFlush() const
{
return this->ContinuousFlush;
}
// ----------------------------------------------------------------------------
void pqEventRecorder::setFile(QIODevice* file)
{
this->File = file;
}
// ----------------------------------------------------------------------------
QIODevice* pqEventRecorder::file() const
{
return this->File;
}
// ----------------------------------------------------------------------------
void pqEventRecorder::setObserver(pqEventObserver* observer)
{
this->ActiveObserver = observer;
}
// ----------------------------------------------------------------------------
pqEventObserver* pqEventRecorder::observer() const
{
return this->ActiveObserver;
}
// ----------------------------------------------------------------------------
void pqEventRecorder::setTranslator(pqEventTranslator* translator)
{
this->ActiveTranslator = translator;
}
// ----------------------------------------------------------------------------
pqEventTranslator* pqEventRecorder::translator() const
{
return this->ActiveTranslator;
}
// ----------------------------------------------------------------------------
void pqEventRecorder::recordEvents(pqEventTranslator* translator,
pqEventObserver* observer,
QIODevice* file,
bool continuousFlush)
{
this->setTranslator(translator);
this->setObserver(observer);
this->setFile(file);
this->setContinuousFlush(continuousFlush);
this->start();
}
// ----------------------------------------------------------------------------
void pqEventRecorder::flush()
{
this->Stream.flush();
}
// ----------------------------------------------------------------------------
void pqEventRecorder::start()
{
if (!this->File || !this->ActiveObserver || !this->ActiveTranslator)
{
return;
}
QObject::connect(
this->ActiveTranslator,
SIGNAL(recordEvent(QString,QString,QString)),
this->ActiveObserver,
SLOT(onRecordEvent(QString,QString,QString)));
// Set the device
this->Stream.setDevice(this->File);
// Set the Stream to the Observer
this->ActiveObserver->setStream(&this->Stream);
// Start the Translator
this->ActiveTranslator->start();
emit this->started();
}
// ----------------------------------------------------------------------------
void pqEventRecorder::stop()
{
QObject::disconnect(
this->ActiveTranslator,
SIGNAL(recordEvent(QString,QString,QString)),
this->ActiveObserver,
SLOT(onRecordEvent(QString,QString,QString)));
this->ActiveObserver->setStream(NULL);
this->flush();
this->ActiveTranslator->stop();
emit this->stopped();
}
// ----------------------------------------------------------------------------
void pqEventRecorder::pause()
{
// To be implemented
}
/*=========================================================================
Program: ParaView
Module: pqEventDispatcher.h
Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
#ifndef _pqEventRecorder_h
#define _pqEventRecorder_h
// Qt includes
#include <QIODevice>
#include <QObject>
#include <QTextStream>
// QtTesting includes
#include "QtTestingExport.h"
class pqEventObserver;
class pqEventTranslator;
/// Class to provide the recording.
/// Two behaviors :
/// - Either Continuous Flush is true, the file is written after each new actions
/// Indeed if the QtTesting/Application crashs, part of the script is written.
/// - Or the file is written only when we stop the record.
/// A simple call to the function "recordEvent" with good parameters, will start
/// the record.
class QTTESTING_EXPORT pqEventRecorder : public QObject
{
Q_OBJECT
Q_PROPERTY(bool continuousFlush READ continuousFlush WRITE setContinuousFlush)
typedef QObject Superclass;
public:
explicit pqEventRecorder(QObject *parent = 0);
~pqEventRecorder();
void setContinuousFlush(bool value);
bool continuousFlush() const;
void setFile(QIODevice* file);
QIODevice* file() const;
void setObserver(pqEventObserver* observer);
pqEventObserver* observer() const;
void setTranslator(pqEventTranslator* translator);
pqEventTranslator* translator() const;
void recordEvents(pqEventTranslator* translator,
pqEventObserver* observer,
QIODevice* file,
bool continuousFlush);
signals:
void started();
void stopped();
void paused(bool);
public slots:
void flush();
void start();
void stop();
void pause();
protected:
pqEventObserver* ActiveObserver;
pqEventTranslator* ActiveTranslator;
QIODevice* File;
bool ContinuousFlush;
QTextStream Stream;
};
#endif // !_pqEventRecorder_h
......@@ -101,8 +101,8 @@ pqNativeFileDialogEventPlayer::pqNativeFileDialogEventPlayer(pqTestUtility* util
loop = new QEventLoop();
}
QObject::connect(util, SIGNAL(started()), this, SLOT(start()));
QObject::connect(util, SIGNAL(stopped()), this, SLOT(stop()));
QObject::connect(util, SIGNAL(playbackStarted()), this, SLOT(start()));
QObject::connect(util, SIGNAL(playbackStopped()), this, SLOT(stop()));
}
pqNativeFileDialogEventPlayer::~pqNativeFileDialogEventPlayer()
......
......@@ -151,12 +151,12 @@ void pqPlayBackEventsDialog::pqImplementation::init(pqPlayBackEventsDialog* dial
QObject::connect(this->Ui.stepButton, SIGNAL(clicked()),
dialog, SLOT(onOneStep()));
QObject::connect(this->TestUtility, SIGNAL(started(QString)),
QObject::connect(this->TestUtility, SIGNAL(playbackStarted(QString)),
dialog, SLOT(onStarted(QString)));
QObject::connect(this->TestUtility, SIGNAL(started()),
QObject::connect(this->TestUtility, SIGNAL(playbackStarted()),
dialog, SLOT(onStarted()));
QObject::connect(this->TestUtility, SIGNAL(stopped()),
QObject::connect(this->TestUtility, SIGNAL(playbackStopped()),
dialog, SLOT(onStopped()));
QObject::connect(&this->Dispatcher, SIGNAL(paused()),
dialog, SLOT(updateUi()));
......
......@@ -30,104 +30,74 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
#include "pqEventTranslator.h"
// Qt includes
#include <QDebug>
#include <QFile>
#include <QFileDialog>
#include <QTextStream>
#include <QTimer>
#include <QPushButton>
// QtTesting includes
#include "pqEventRecorder.h"
#include "pqRecordEventsDialog.h"
#include "pqEventObserver.h"
#include "pqTestUtility.h"
#include "ui_pqRecordEventsDialog.h"
#include <QPushButton>
#include <QTimer>
#include <QFile>
#include <QTextStream>
//////////////////////////////////////////////////////////////////////////////////
// pqImplementation
struct pqRecordEventsDialog::pqImplementation
{
public:
pqImplementation(pqEventTranslator& translator,
pqEventObserver& observer)
: Translator(translator), Observer(observer)
pqImplementation(pqEventRecorder* recorder,
pqTestUtility* testUtility)
: Recorder(recorder), TestUtility(testUtility)
{
}
~pqImplementation()
{
this->Recorder = 0;
this->TestUtility = 0;
}
Ui::pqRecordEventsDialog Ui;
pqEventTranslator& Translator;
pqEventObserver& Observer;
QFile File;
QTextStream Stream;
pqEventRecorder* Recorder;
pqTestUtility* TestUtility;
};
///////////////////////////////////////////////////////////////////////////////////
// pqRecordEventsDialog
pqRecordEventsDialog::pqRecordEventsDialog(pqEventTranslator& Translator,
pqEventObserver& observer,
const QString& Path,
QWidget* Parent)
// ----------------------------------------------------------------------------
pqRecordEventsDialog::pqRecordEventsDialog(pqEventRecorder* recorder,
pqTestUtility* testUtility,
QWidget* Parent)
: QDialog(Parent),
Implementation(new pqImplementation(Translator, observer))
Implementation(new pqImplementation(recorder, testUtility))
{
this->Implementation->Ui.setupUi(this);
this->Implementation->Ui.label->setText(QString(tr("Recording User Input to %1")).arg(Path));
this->Implementation->Translator.ignoreObject(this->Implementation->Ui.stopButton);
this->Implementation->Translator.ignoreObject(this);
this->Implementation->TestUtility->eventTranslator()->ignoreObject(this->Implementation->Ui.stopButton);
this->Implementation->TestUtility->eventTranslator()->ignoreObject(this);
this->setWindowTitle(tr("Recording User Input"));
this->setObjectName("");
QObject::connect(
&this->Implementation->Translator,
SIGNAL(recordEvent(const QString&, const QString&, const QString&)),
&this->Implementation->Observer,
SLOT(onRecordEvent(const QString&, const QString&, const QString&)));
this->Implementation->File.setFileName(Path);
this->Implementation->File.open(QIODevice::WriteOnly);
this->Implementation->Stream.setDevice(&this->Implementation->File);
this->Implementation->Observer.setStream(&this->Implementation->Stream);
this->Implementation->Translator.start();
}
// ----------------------------------------------------------------------------
pqRecordEventsDialog::~pqRecordEventsDialog()
{
this->Implementation->Translator.stop();
QObject::disconnect(
&this->Implementation->Translator,
SIGNAL(recordEvent(const QString&, const QString&, const QString&)),
&this->Implementation->Observer,
SLOT(onRecordEvent(const QString&, const QString&, const QString&)));
this->Implementation->Observer.setStream(NULL);
this->Implementation->Stream.flush();
this->Implementation->File.close();
delete Implementation;
}
void pqRecordEventsDialog::accept()
{
QDialog::accept();
QTimer::singleShot(0, this, SLOT(onAutoDelete()));
}
void pqRecordEventsDialog::reject()
{
QDialog::reject();
QTimer::singleShot(0, this, SLOT(onAutoDelete()));
}
void pqRecordEventsDialog::onAutoDelete()
// ----------------------------------------------------------------------------
void pqRecordEventsDialog::done(int value)
{
delete this;
this->Implementation->TestUtility->stopRecords();
QDialog::done(value);
}
......@@ -36,8 +36,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "QtTestingExport.h"
#include <QDialog>
class pqEventTranslator;
class pqEventObserver;
class pqEventRecorder;
class pqTestUtility;
/// Provides a standard dialog that will record user input to an XML file as long as the dialog remains open
class QTTESTING_EXPORT pqRecordEventsDialog :
......@@ -49,13 +49,12 @@ public:
/**
Creates the dialog and begins translating user input with the supplied translator.
*/
pqRecordEventsDialog(pqEventTranslator& Translator, pqEventObserver& observer,
const QString& File, QWidget* Parent);
pqRecordEventsDialog(pqEventRecorder* recorder,
pqTestUtility* testUtility,
QWidget* Parent);
private slots:
void accept();
void reject();
void onAutoDelete();
virtual void done(int);
private:
pqRecordEventsDialog(const pqRecordEventsDialog&);
......
<ui version="4.0" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>pqRecordEventsDialog</class>
<widget class="QDialog" name="pqRecordEventsDialog" >
<property name="geometry" >
<widget class="QDialog" name="pqRecordEventsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>366</width>
<height>76</height>
<width>389</width>
<height>72</height>
</rect>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>8</number>
</property>
<property name="spacing" >
<layout class="QVBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>8</number>
</property>
<item>
<widget class="QLabel" name="label" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>5</hsizetype>
<vsizetype>3</vsizetype>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text" >
<string>Recording User Events to /home/tshead/test_cases/foo</string>
<property name="text">
<string>Recording User Events</string>
</property>
<property name="alignment" >
<property name="alignment">
<set>Qt::AlignHCenter</set>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<spacer>
<property name="orientation" >
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0">
<size>
<width>131</width>
<height>31</height>
......@@ -62,8 +58,8 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="stopButton" >
<property name="text" >
<widget class="QPushButton" name="stopButton">
<property name="text">
<string>Stop Recording</string>
</property>
</widget>
......@@ -72,7 +68,6 @@
</item>
</layout>
</widget>
<pixmapfunction></pixmapfunction>
<resources/>
<connections>
<connection>
......@@ -81,11 +76,11 @@
<receiver>pqRecordEventsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<hint type="sourcelabel">
<x>313</x>
<y>46</y>
</hint>
<hint type="destinationlabel" >
<hint type="destinationlabel">
<x>84</x>
<y>36</y>
</hint>
......
......@@ -30,28 +30,37 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
#include "pqTestUtility.h"
#include <QFileInfo>
#include <QDebug>
// Qt includes
#include <QApplication>
#include <QDebug>
#include <QFileDialog>
#include <QFileInfo>
#include <QTemporaryFile>