pqTestUtility.h 4.64 KB
Newer Older
Clinton Stimpson's avatar
Clinton Stimpson committed
1 2 3 4 5
/*=========================================================================

   Program: ParaView
   Module:    pqTestUtility.h

6
   Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
Clinton Stimpson's avatar
Clinton Stimpson committed
7 8 9
   All rights reserved.

   ParaView is a free software; you can redistribute it and/or modify it
10
   under the terms of the ParaView license version 1.2. 
Clinton Stimpson's avatar
Clinton Stimpson committed
11

12
   See License_v1.2.txt for the full ParaView license.
Clinton Stimpson's avatar
Clinton Stimpson committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
   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 _pqTestUtility_h
#define _pqTestUtility_h

#include <QObject>
#include <QMap>
#include <QSet>
#include <QTextStream>
#include <QFile>
41
#include <QDir>
42
#include <QStringList>
Clinton Stimpson's avatar
Clinton Stimpson committed
43 44 45 46 47 48 49 50 51

#include "QtTestingExport.h"
#include "pqEventDispatcher.h"
#include "pqEventPlayer.h"
#include "pqEventTranslator.h"
class pqEventObserver;
class pqEventSource;

/// Organizes basic functionality for regression testing
52
class QTTESTING_EXPORT pqTestUtility : public QObject
Clinton Stimpson's avatar
Clinton Stimpson committed
53 54 55 56 57 58 59 60 61
{
  Q_OBJECT

public:
  pqTestUtility(QObject* parent = 0);
  ~pqTestUtility();

public:

62
  /// Get the event dispatcher. Dispatcher is used to play tests back.
Clinton Stimpson's avatar
Clinton Stimpson committed
63
  pqEventDispatcher* dispatcher();
64 65 66 67

  /// Get the event player. This the test-file-interpreter (if you will), that
  /// parses the test file and creates events from it that can be dispatched by
  /// the pqEventDispatcher.
Clinton Stimpson's avatar
Clinton Stimpson committed
68
  pqEventPlayer* eventPlayer();
69 70

  /// Get the event translator. This is used for recording tests.
Clinton Stimpson's avatar
Clinton Stimpson committed
71 72 73 74 75 76 77 78 79 80 81 82 83
  pqEventTranslator* eventTranslator();

  /// add an event source for playback of files
  /// An pqXMLEventSource is automatically added if XML support is enabled.
  /// A pqPythonEventSource is automatically added if Python support is enabled.
  void addEventSource(const QString& fileExtension, pqEventSource* source);
  
  /// add an event observer for recording files
  /// An pqXMLEventObserver is automatically added if XML support is enabled.
  /// A pqPythonEventObserver is automatically added if Python support is enabled.
  void addEventObserver(const QString& fileExtension, 
                          pqEventObserver* translator);

84 85 86
  /// Returns if the utility is currently playing a test.
  bool playingTest() const
    { return this->PlayingTest; }
87

88 89 90 91
  /// Plays back the test given by the filename(s). This is a blocking call i.e.
  /// it does not return until the test has been played or aborted due to
  /// failure. Returns true if the test played successfully.
  virtual bool playTests(const QStringList& filenames);
Clinton Stimpson's avatar
Clinton Stimpson committed
92

93
  /// start the recording of tests to a file
94
  Q_INVOKABLE void recordTests(const QString& filename);
Clinton Stimpson's avatar
Clinton Stimpson committed
95

96 97 98 99
  /// Add custom object properties, which will be saved during the recording
  /// and restored before the playback
  void addObjectStateProperty(QObject* object, const QString& property);
  QMap<QObject*, QString> objectStateProperty() const;
100 101 102 103 104 105 106 107 108 109 110 111
  /// add a directory for recording/playback of file dialogs
  void addDataDirectory(const QString& label, const QDir& path);

  /// remove a directory for recording/playback of file dialogs
  void removeDataDirectory(const QString& label);

  /// given filename convert to one of the data directories
  QString convertToDataDirectory(const QString& file);

  /// give a filename convert from one of the data directories
  QString convertFromDataDirectory(const QString& file);

112 113 114 115 116 117 118 119 120 121 122
public slots:
  void playTests(const QString& filename);
  void openPlayerDialog();
  void stopTests();

signals:
  void started();
  void stopped();
  void started(const QString& filename);
  void stopped(const QString& filename, bool error);

Clinton Stimpson's avatar
Clinton Stimpson committed
123 124 125 126
protected:
  pqEventDispatcher Dispatcher;
  pqEventPlayer Player;
  pqEventTranslator Translator;
127
  bool PlayingTest;
Clinton Stimpson's avatar
Clinton Stimpson committed
128 129 130

  QMap<QString, pqEventSource*> EventSources;
  QMap<QString, pqEventObserver*> EventObservers;
131

132 133
  QMap<QString, QDir>      DataDirectories;
  QMap<QObject*, QString>  ObjectStateProperty;
134

Clinton Stimpson's avatar
Clinton Stimpson committed
135 136 137
};

#endif // !_pqTestUtility_h