TesterApplication.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "Qt.h"
00024 #include "TesterApplication.h"
00025 #include "Imports.cpp"
00026
00027 TesterApplication::TesterApplication (int & argc, char ** argv)
00028 : QCoreApplication (argc, argv), cppUnitException(), timeoutTimer()
00029 {
00030 timeoutTimer.setSingleShot (true);
00031 QObject::connect (&timeoutTimer, SIGNAL (timeout()),
00032 this, SLOT (timeout()));
00033 }
00034
00036 int TesterApplication::exec (int maxTime)
00037 {
00038 TesterApplication *app = dynamic_cast <TesterApplication *> (
00039 QCoreApplication::instance());
00040 Q_ASSERT (app != 0);
00041 if (maxTime > 0)
00042 app->timeoutTimer.start (maxTime);
00043
00044
00045
00046
00047 QCoreApplication::processEvents (QEventLoop::DeferredDeletion);
00048
00049
00050 int ret = QCoreApplication::exec();
00051 app->timeoutTimer.stop();
00052
00053
00054 if (app->cppUnitException.get()) {
00055 Exception exception (*app->cppUnitException);
00056 app->cppUnitException.reset();
00057 throw exception;
00058 }
00059 return ret;
00060 }
00061
00063 bool TesterApplication::notify (QObject *receiver, QEvent *event)
00064 {
00065 try {
00066 return QCoreApplication::notify (receiver, event);
00067 } catch (CPPUNIT_NS::Exception e) {
00068 cppUnitException.reset (e.clone());
00069 exit(1);
00070 return false;
00071 }
00072 }
00073
00074 void TesterApplication::timeout()
00075 {
00076 exit (-1);
00077 }