CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkTestApplication.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Library: CTK
4 
5  Copyright (c) Kitware Inc.
6 
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0.txt
12 
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18 
19 =========================================================================*/
20 /*=========================================================================
21 
22  Program: Visualization Toolkit
23  Module: $RCSfile: QTestApp.h,v $
24 
25  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
26  All rights reserved.
27  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
28 
29  This software is distributed WITHOUT ANY WARRANTY; without even
30  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
31  PURPOSE. See the above copyright notice for more information.
32 
33 =========================================================================*/
34 /*-------------------------------------------------------------------------
35  Copyright 2008 Sandia Corporation.
36  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
37  the U.S. Government retains certain rights in this software.
38 -------------------------------------------------------------------------*/
39 
40 #ifndef __ctkTestApplication_h
41 #define __ctkTestApplication_h
42 
43 // Qt includes
44 #include <QApplication>
45 #include <QVector>
46 #include <QByteArray>
47 #include <QTimer>
48 
50 #define QCTK_DECLARE_TEST(TEST_NAME) \
51 namespace \
52 { \
53 class _TEST_NAME : public ctkTestApplication \
54 { \
55 public: \
56  _TEST_NAME(int _argc, char * _argv []): \
57  ctkTestApplication(_argc, _argv){} \
58  virtual void runTest(); \
59 }; \
60  \
61 void _TEST_NAME::runTest() \
62 
64 #define QCTK_RUN_TEST(TEST_NAME) \
65 } \
66  \
67 int TEST_NAME(int _argc, char * _argv [] ) \
68 { \
69  _TEST_NAME app(_argc, _argv); \
70  QTimer::singleShot(0, &app, SLOT(runTestSlot())); \
71  return _TEST_NAME::exec(); \
72 }
73 
75 #define QCTK_EXIT_TEST(_status) \
76  QCoreApplication::exit(_status); \
77  return;
78 
79 #include "ctkWidgetsExport.h"
80 
81 
83 class CTK_WIDGETS_EXPORT ctkTestApplication : public QObject
84 {
85  Q_OBJECT
86 
87 public:
88  ctkTestApplication(int _argc, char** _argv);
90 
93  virtual void runTest();
94 
99  static int exec(bool reportErrorsOnExit=false);
100 
101 #if QT_VERSION >= 0x50000
102  static void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);
103 #else
104  static void messageHandler(QtMsgType type, const char *msg);
105 #endif
106 
107  static void delay(int ms);
108 
109  static bool simulateEvent(QWidget* w, QEvent* e);
110 
111  static void keyUp(QWidget* w, Qt::Key key, Qt::KeyboardModifiers mod, int ms);
112 
113  static void keyDown(QWidget* w, Qt::Key key, Qt::KeyboardModifiers mod, int ms);
114 
115  static void keyClick(QWidget* w, Qt::Key key, Qt::KeyboardModifiers mod, int ms);
116 
117  static void mouseDown(QWidget* w, QPoint pos, Qt::MouseButton btn,
118  Qt::KeyboardModifiers mod, int ms);
119 
120  static void mouseUp(QWidget* w, QPoint pos, Qt::MouseButton btn,
121  Qt::KeyboardModifiers mod, int ms);
122 
123  static void mouseMove(QWidget* w, QPoint pos, Qt::MouseButton btn,
124  Qt::KeyboardModifiers mod, int ms);
125 
126  static void mouseClick(QWidget* w, QPoint pos, Qt::MouseButton btn,
127  Qt::KeyboardModifiers mod, int ms);
128 
129  static void mouseDClick(QWidget* w, QPoint pos, Qt::MouseButton btn,
130  Qt::KeyboardModifiers mod, int ms);
131 
132 public Q_SLOTS:
133 
136  void runTestSlot();
137 
138 private:
139  QApplication* App;
140  static int Error;
141  QList<QByteArray> Argv;
142  QVector<char*> Argvp;
143  int Argc;
144 };
145 
146 #endif
static void keyUp(QWidget *w, Qt::Key key, Qt::KeyboardModifiers mod, int ms)
ctkTestApplication(int _argc, char **_argv)
virtual void runTest()
static void keyDown(QWidget *w, Qt::Key key, Qt::KeyboardModifiers mod, int ms)
static int exec(bool reportErrorsOnExit=false)
static void mouseDown(QWidget *w, QPoint pos, Qt::MouseButton btn, Qt::KeyboardModifiers mod, int ms)
static void mouseUp(QWidget *w, QPoint pos, Qt::MouseButton btn, Qt::KeyboardModifiers mod, int ms)
static void mouseDClick(QWidget *w, QPoint pos, Qt::MouseButton btn, Qt::KeyboardModifiers mod, int ms)
static void mouseMove(QWidget *w, QPoint pos, Qt::MouseButton btn, Qt::KeyboardModifiers mod, int ms)
static void messageHandler(QtMsgType type, const char *msg)
static void mouseClick(QWidget *w, QPoint pos, Qt::MouseButton btn, Qt::KeyboardModifiers mod, int ms)
static void keyClick(QWidget *w, Qt::Key key, Qt::KeyboardModifiers mod, int ms)
static bool simulateEvent(QWidget *w, QEvent *e)
static void delay(int ms)