KUnitTest
tester.cpp
Go to the documentation of this file.00001
00026 #include "tester.h"
00027
00028 #include <iostream>
00029 using namespace std;
00030
00031 #include <QtCore/QMetaEnum>
00032 #include <QtCore/QRect>
00033 #include <QtCore/QVector>
00034
00035 namespace KUnitTest
00036 {
00037 SlotTester::SlotTester() : Tester()
00038 {
00039 m_total = m_results;
00040 }
00041
00042
00043 SlotTester::~SlotTester()
00044 {
00045 qDeleteAll( m_resultsList );
00046 }
00047
00048
00049 void SlotTester::invokeMember(const QString &str)
00050 {
00051 QString slotname = QString::number(QSLOT_CODE) + str;
00052 connect(this, SIGNAL(invoke()), this, slotname.toAscii().constData());
00053 emit invoke();
00054 disconnect(this, SIGNAL(invoke()), this, slotname.toAscii().constData());
00055 }
00056
00057 void SlotTester::allTests()
00058 {
00059 QVector<QByteArray> allSlots;
00060 const int methodCount = metaObject()->methodCount();
00061 const int methodOffset = metaObject()->methodOffset();
00062 allSlots.reserve( methodCount );
00063 for ( int i=0 ; i < methodCount; ++i )
00064 {
00065 QMetaMethod method = metaObject()->method( methodOffset + i );
00066 if ( method.methodType() == QMetaMethod::Slot )
00067 allSlots.append( method.signature() );
00068 }
00069
00070 if ( allSlots.contains("setUp()") )
00071 invokeMember("setUp()");
00072
00073 foreach ( const QByteArray &sl, allSlots )
00074 {
00075 if ( sl.startsWith("test") )
00076 {
00077 m_results = results(sl);
00078 Q_ASSERT( m_results );
00079 m_results->clear();
00080
00081 cout << "KUnitTest_Debug_BeginSlot[" << sl.data() << "]" << endl;
00082 invokeMember(sl);
00083 cout << "KUnitTest_Debug_EndSlot[" << sl.data() << "]" << endl;
00084 }
00085 }
00086
00087 if ( allSlots.contains("tearDown()") )
00088 invokeMember("tearDown()");
00089
00090 m_total->clear();
00091 }
00092
00093 TestResults *SlotTester::results(const char *sl)
00094 {
00095 if ( !m_resultsList.contains(sl) )
00096 m_resultsList.insert(sl, new TestResults());
00097
00098 return m_resultsList[sl];
00099 }
00100 }
00101
00102 QTextStream& operator<<( QTextStream& str, const QRect& r ) {
00103 str << "[" << r.x() << "," << r.y() << " - " << r.width() << "x" << r.height() << "]";
00104 return str;
00105 }
00106
00107 QTextStream& operator<<( QTextStream& str, const QPoint& r ) {
00108 str << "(" << r.x() << "," << r.y() << ")";
00109 return str;
00110 }
00111
00112 QTextStream& operator<<( QTextStream& str, const QSize& r ) {
00113 str << "[" << r.width() << "x" << r.height() << "]";
00114 return str;
00115 }
00116
00117 #include "tester.moc"