• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KUnitTest

  • sources
  • kde-4.14
  • kdelibs
  • kde3support
  • kunittest
tester.cpp
Go to the documentation of this file.
1 
26 #include "tester.h"
27 
28 #include <iostream>
29 using namespace std;
30 
31 #include <QtCore/QMetaEnum>
32 #include <QtCore/QRect>
33 #include <QtCore/QVector>
34 
35 namespace KUnitTest
36 {
37  SlotTester::SlotTester() : Tester()
38  {
39  m_total = m_results;
40  }
41 
42 
43  SlotTester::~SlotTester()
44  {
45  qDeleteAll( m_resultsList );
46  }
47 
48 
49  void SlotTester::invokeMember(const QString &str)
50  {
51  QString slotname = QString::number(QSLOT_CODE) + str;
52  connect(this, SIGNAL(invoke()), this, slotname.toLatin1().constData());
53  emit invoke();
54  disconnect(this, SIGNAL(invoke()), this, slotname.toLatin1().constData());
55  }
56 
57  void SlotTester::allTests()
58  {
59  QVector<QByteArray> allSlots;
60  const int methodCount = metaObject()->methodCount();
61  const int methodOffset = metaObject()->methodOffset();
62  allSlots.reserve( methodCount );
63  for ( int i=0 ; i < methodCount; ++i )
64  {
65  QMetaMethod method = metaObject()->method( methodOffset + i );
66  if ( method.methodType() == QMetaMethod::Slot )
67  allSlots.append( method.signature() );
68  }
69 
70  if ( allSlots.contains("setUp()") )
71  invokeMember("setUp()");
72 
73  foreach ( const QByteArray &sl, allSlots )
74  {
75  if ( sl.startsWith("test") )
76  {
77  m_results = results(sl);
78  Q_ASSERT( m_results );
79  m_results->clear();
80 
81  cout << "KUnitTest_Debug_BeginSlot[" << sl.data() << "]" << endl;
82  invokeMember(sl);
83  cout << "KUnitTest_Debug_EndSlot[" << sl.data() << "]" << endl;
84  }
85  }
86 
87  if ( allSlots.contains("tearDown()") )
88  invokeMember("tearDown()");
89 
90  m_total->clear();
91  }
92 
93  TestResults *SlotTester::results(const char *sl)
94  {
95  if ( !m_resultsList.contains(sl) )
96  m_resultsList.insert(sl, new TestResults());
97 
98  return m_resultsList[sl];
99  }
100 }
101 
102 QTextStream& operator<<( QTextStream& str, const QRect& r ) {
103  str << "[" << r.x() << "," << r.y() << " - " << r.width() << "x" << r.height() << "]";
104  return str;
105 }
106 
107 QTextStream& operator<<( QTextStream& str, const QPoint& r ) {
108  str << "(" << r.x() << "," << r.y() << ")";
109  return str;
110 }
111 
112 QTextStream& operator<<( QTextStream& str, const QSize& r ) {
113  str << "[" << r.width() << "x" << r.height() << "]";
114  return str;
115 }
116 
117 #include "tester.moc"
KUnitTest::Tester
Definition: tester.h:516
QHash::insert
iterator insert(const Key &key, const T &value)
QSize::width
int width() const
QVector::append
void append(const T &value)
QByteArray
KUnitTest::TestResults::clear
virtual void clear()
Definition: tester.h:437
tester.h
QByteArray::startsWith
bool startsWith(const QByteArray &ba) const
QObject::metaObject
virtual const QMetaObject * metaObject() const
QRect::height
int height() const
QRect::x
int x() const
QRect::y
int y() const
QPoint
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QPoint::x
int x() const
QPoint::y
int y() const
QTextStream
QRect
QString::number
QString number(int n, int base)
QVector::contains
bool contains(const T &value) const
QMetaObject::methodCount
int methodCount() const
QByteArray::constData
const char * constData() const
QMetaObject::methodOffset
int methodOffset() const
QMetaMethod::signature
const char * signature() const
QString
QVector::reserve
void reserve(int size)
QSize
KUnitTest::SlotTester::invoke
void invoke()
KUnitTest::SlotTester::~SlotTester
virtual ~SlotTester()
Definition: tester.cpp:43
QMetaMethod::methodType
MethodType methodType() const
KUnitTest::TestResults
Definition: tester.h:426
QString::toLatin1
QByteArray toLatin1() const
QRect::width
int width() const
QVector
QSize::height
int height() const
QByteArray::data
char * data()
QHash::contains
bool contains(const Key &key) const
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KUnitTest::Tester::m_results
TestResults * m_results
Definition: tester.h:671
KUnitTest::SlotTester::results
virtual TestResults * results() const
Definition: tester.h:692
QMetaObject::method
QMetaMethod method(int index) const
operator<<
QTextStream & operator<<(QTextStream &str, const QRect &r)
Definition: tester.cpp:102
QMetaMethod
KUnitTest::SlotTester::allTests
void allTests()
Definition: tester.cpp:57
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:26:57 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KUnitTest

Skip menu "KUnitTest"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal