ctkEventTranslatorPlayerWidget.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkEventTranslatorPlayerWidget_h
  15. #define __ctkEventTranslatorPlayerWidget_h
  16. // Qt includes
  17. #include <QDateTime>
  18. #include <QMainWindow>
  19. // CTK includes
  20. #if !defined(NO_SYMBOL_EXPORT)
  21. # include "ctkQtTestingExport.h"
  22. #else
  23. # define CTK_QTTESTING_EXPORT
  24. #endif
  25. class ctkCallback;
  26. class ctkEventTranslatorPlayerWidgetPrivate;
  27. // QtTesting includes
  28. class pqTestUtility;
  29. class pqWidgetEventPlayer;
  30. class pqWidgetEventTranslator;
  31. //-----------------------------------------------------------------------------
  32. #define CTKCOMPARE(actual, expected) \
  33. do \
  34. {\
  35. if (!ctkEventTranslatorPlayerWidget::compare(actual, expected, #actual, #expected, __FILE__, __LINE__))\
  36. { \
  37. return;\
  38. } \
  39. } while (0)
  40. //-----------------------------------------------------------------------------
  41. class CTK_QTTESTING_EXPORT ctkEventTranslatorPlayerWidget
  42. : public QMainWindow
  43. {
  44. Q_OBJECT
  45. public:
  46. typedef QMainWindow Superclass;
  47. ctkEventTranslatorPlayerWidget();
  48. ~ctkEventTranslatorPlayerWidget();
  49. void addTestCase(QWidget* widget, QString fileName, void(*newCallback)(void* data));
  50. void addTestCase(QDialog* dialog, QString fileName, void(*newCallback)(void* data));
  51. void setTestUtility(pqTestUtility* newTestUtility);
  52. pqTestUtility* testUtility() const;
  53. void addWidgetEventPlayer(pqWidgetEventPlayer* player);
  54. void addWidgetEventTranslator(pqWidgetEventTranslator* translator);
  55. static const char* enumValueToKey(QObject* object, const char* enumName, int value);
  56. static bool compare(const double& actual, const double& expected,
  57. const char* actualName, const char* expectedName, const char * function, int line);
  58. static bool compare(const int& actual, const int& expected,
  59. const char* actualName, const char* expectedName, const char * function, int line);
  60. static bool compare(const QString& actual,const QString& expected,
  61. const char* actualName, const char* expectedName, const char * function, int line);
  62. static bool compare(const QStringList& actual,const QStringList& expected,
  63. const char* actualName, const char* expectedName, const char * function, int line);
  64. static bool compare(const QDateTime& actual,const QDateTime& expected,
  65. const char* actualName, const char* expectedName, const char * function, int line);
  66. static bool compare(const QColor& actual,const QColor& expected,
  67. const char* actualName, const char* expectedName, const char * function, int line);
  68. static bool compare(const QImage& actual,const QImage& expected,
  69. const char* actualName, const char* expectedName, const char * function, int line);
  70. public slots:
  71. void play();
  72. protected slots:
  73. void record(int currentTestCase);
  74. bool play(int currentTestCase);
  75. void popupDialog();
  76. void onClickedPlayback(bool);
  77. void onClickedRecord(bool);
  78. void switchTestCase(int testCase);
  79. signals:
  80. void startPlayerBack(QWidget* widget);
  81. void playerDone(QWidget* widget);
  82. void recordDone(QWidget* widget);
  83. protected:
  84. QScopedPointer< ctkEventTranslatorPlayerWidgetPrivate > d_ptr;
  85. private:
  86. Q_DECLARE_PRIVATE(ctkEventTranslatorPlayerWidget);
  87. Q_DISABLE_COPY(ctkEventTranslatorPlayerWidget);
  88. struct InfoTestCase {
  89. QWidget* Widget;
  90. ctkCallback* Callback;
  91. QString FileName;
  92. bool Dialog;
  93. };
  94. };
  95. #endif