Qt 4.8
Public Types | Static Public Functions | List of all members
QTestResult Class Reference

#include <qtestresult_p.h>

Public Types

enum  TestLocation {
  NoWhere = 0, DataFunc = 1, InitFunc = 2, Func = 3,
  CleanupFunc = 4
}
 

Static Public Functions

static void addFailure (const char *message, const char *file, int line)
 
static void addSkip (const char *message, QTest::SkipMode mode, const char *file, int line)
 
static bool allDataPassed ()
 
static bool compare (bool success, const char *msg, const char *file, int line)
 
static bool compare (bool success, const char *msg, char *val1, char *val2, const char *actual, const char *expected, const char *file, int line)
 
static const char * currentAppName ()
 
static const char * currentDataTag ()
 
static const char * currentGlobalDataTag ()
 
static QTestDatacurrentGlobalTestData ()
 
static QTestDatacurrentTestData ()
 
static bool currentTestFailed ()
 
static const char * currentTestFunction ()
 
static TestLocation currentTestLocation ()
 
static const char * currentTestObjectName ()
 
static bool expectFail (const char *dataIndex, const char *comment, QTest::TestFailMode mode, const char *file, int line)
 
static int failCount ()
 
static void finishedCurrentTestFunction ()
 
static void ignoreMessage (QtMsgType type, const char *msg)
 
static int passCount ()
 
static void reset ()
 
static void setCurrentAppName (const char *appName)
 
static void setCurrentGlobalTestData (QTestData *data)
 
static void setCurrentTestData (QTestData *data)
 
static void setCurrentTestFunction (const char *func)
 
static void setCurrentTestLocation (TestLocation loc)
 
static void setCurrentTestObject (const char *name)
 
static void setSkipCurrentTest (bool value)
 
static int skipCount ()
 
static bool skipCurrentTest ()
 
static bool testFailed ()
 
static bool verify (bool statement, const char *statementStr, const char *extraInfo, const char *file, int line)
 

Detailed Description

Definition at line 63 of file qtestresult_p.h.

Enumerations

◆ TestLocation

Enumerator
NoWhere 
DataFunc 
InitFunc 
Func 
CleanupFunc 

Definition at line 66 of file qtestresult_p.h.

Functions

◆ addFailure()

void QTestResult::addFailure ( const char *  message,
const char *  file,
int  line 
)
static

Definition at line 280 of file qtestresult.cpp.

Referenced by checkStatement(), QTest::messageHandler(), QTest::qExec(), QTest::qFail(), and QTest::qInvokeTestMethodDataEntry().

281 {
282  clearExpectFail();
283 
284  QTestLog::addFail(message, file, line);
285  QTest::failed = true;
286  QTest::dataFailed = true;
287  ++QTest::fails;
288 }
static bool dataFailed
Definition: qtestresult.cpp:61
static void addFail(const char *msg, const char *file, int line)
Definition: qtestlog.cpp:264
static void clearExpectFail()
static int fails
Definition: qtestresult.cpp:65
static bool failed
Definition: qtestresult.cpp:60

◆ addSkip()

void QTestResult::addSkip ( const char *  message,
QTest::SkipMode  mode,
const char *  file,
int  line 
)
static

Definition at line 290 of file qtestresult.cpp.

Referenced by QTest::qSkip().

292 {
293  clearExpectFail();
294 
295  QTestLog::addSkip(message, mode, file, line);
296  ++QTest::skips;
297 }
static void addSkip(const char *msg, QTest::SkipMode mode, const char *file, int line)
Definition: qtestlog.cpp:289
static void clearExpectFail()
static int skips
Definition: qtestresult.cpp:67

◆ allDataPassed()

bool QTestResult::allDataPassed ( )
static

Definition at line 93 of file qtestresult.cpp.

94 {
95  return !QTest::failed;
96 }
static bool failed
Definition: qtestresult.cpp:60

◆ compare() [1/2]

bool QTestResult::compare ( bool  success,
const char *  msg,
const char *  file,
int  line 
)
static

Definition at line 253 of file qtestresult.cpp.

Referenced by QTest::compare_helper().

254 {
255  if (QTestLog::verboseLevel() >= 2) {
256  QTestLog::info(msg, file, line);
257  }
258 
259  return checkStatement(success, msg, file, line);
260 }
static int verboseLevel()
Definition: qtestlog.cpp:363
static bool checkStatement(bool statement, const char *msg, const char *file, int line)
static void info(const char *msg, const char *file, int line)
Definition: qtestlog.cpp:340

◆ compare() [2/2]

bool QTestResult::compare ( bool  success,
const char *  msg,
char *  val1,
char *  val2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
static

Definition at line 262 of file qtestresult.cpp.

264 {
265  QTEST_ASSERT(expected);
266  QTEST_ASSERT(actual);
267 
268  if (!val1 && !val2)
269  return compare(success, msg, file, line);
270 
271  char buf[1024];
272  QTest::qt_snprintf(buf, 1024, "%s\n Actual (%s): %s\n Expected (%s): %s", msg,
273  actual, val1 ? val1 : "<null>",
274  expected, val2 ? val2 : "<null>");
275  delete [] val1;
276  delete [] val2;
277  return compare(success, buf, file, line);
278 }
static bool compare(bool success, const char *msg, const char *file, int line)
int Q_TESTLIB_EXPORT qt_snprintf(char *str, int size, const char *format,...)
Definition: qtestcase.cpp:961
#define QTEST_ASSERT(cond)
Definition: qtestassert.h:53

◆ currentAppName()

const char * QTestResult::currentAppName ( )
static

Definition at line 358 of file qtestresult.cpp.

Referenced by QTest::currentAppName().

359 {
360  return QTest::currentAppName;
361 }
static const char * currentAppName
Definition: qtestresult.cpp:72

◆ currentDataTag()

const char * QTestResult::currentDataTag ( )
static

Definition at line 167 of file qtestresult.cpp.

Referenced by QXmlTestLogger::addIncident(), QXmlTestLogger::addMessage(), QTestLogger::addTag(), QTest::currentDataTag(), QTest::printMessage(), and QTest::qInvokeTestMethodDataEntry().

168 {
170  : static_cast<const char *>(0);
171 }
const char * dataTag() const
Definition: qtestdata.cpp:112
static QTestData * currentTestData
Definition: qtestresult.cpp:56

◆ currentGlobalDataTag()

const char * QTestResult::currentGlobalDataTag ( )
static

Definition at line 173 of file qtestresult.cpp.

Referenced by QXmlTestLogger::addIncident(), QXmlTestLogger::addMessage(), QTestLogger::addTag(), and QTest::printMessage().

174 {
176  : static_cast<const char *>(0);
177 }
const char * dataTag() const
Definition: qtestdata.cpp:112
static QTestData * currentGlobalTestData
Definition: qtestresult.cpp:57

◆ currentGlobalTestData()

QTestData * QTestResult::currentGlobalTestData ( )
static

Definition at line 103 of file qtestresult.cpp.

Referenced by QTest::qGlobalData().

104 {
106 }
static QTestData * currentGlobalTestData
Definition: qtestresult.cpp:57

◆ currentTestData()

QTestData * QTestResult::currentTestData ( )
static

Definition at line 108 of file qtestresult.cpp.

Referenced by QTest::qData(), and QTest::qElementData().

109 {
110  return QTest::currentTestData;
111 }
static QTestData * currentTestData
Definition: qtestresult.cpp:56

◆ currentTestFailed()

bool QTestResult::currentTestFailed ( )
static

Definition at line 98 of file qtestresult.cpp.

Referenced by QTest::currentTestFailed().

99 {
100  return QTest::dataFailed;
101 }
static bool dataFailed
Definition: qtestresult.cpp:61

◆ currentTestFunction()

const char * QTestResult::currentTestFunction ( )
static

Definition at line 162 of file qtestresult.cpp.

Referenced by QTest::currentTestFunction(), QTest::printMessage(), and QTest::qExec().

163 {
164  return QTest::currentTestFunc;
165 }
static const char * currentTestFunc
Definition: qtestresult.cpp:58

◆ currentTestLocation()

QTestResult::TestLocation QTestResult::currentTestLocation ( )
static

Definition at line 299 of file qtestresult.cpp.

300 {
301  return QTest::location;
302 }
static QTestResult::TestLocation location
Definition: qtestresult.cpp:63

◆ currentTestObjectName()

const char * QTestResult::currentTestObjectName ( )
static

◆ expectFail()

bool QTestResult::expectFail ( const char *  dataIndex,
const char *  comment,
QTest::TestFailMode  mode,
const char *  file,
int  line 
)
static

Definition at line 190 of file qtestresult.cpp.

Referenced by QTest::qExpectFail().

192 {
193  QTEST_ASSERT(comment);
194  QTEST_ASSERT(mode > 0);
195 
196  if (!isExpectFailData(dataIndex)) {
197  delete[] comment;
198  return true; // we don't care
199  }
200 
201  if (QTest::expectFailMode) {
202  delete[] comment;
203  clearExpectFail();
204  addFailure("Already expecting a fail", file, line);
205  return false;
206  }
207 
208  QTest::expectFailMode = mode;
209  QTest::expectFailComment = comment;
210  return true;
211 }
static void addFailure(const char *message, const char *file, int line)
static int expectFailMode
Definition: qtestresult.cpp:70
static void clearExpectFail()
static bool isExpectFailData(const char *dataIndex)
#define QTEST_ASSERT(cond)
Definition: qtestassert.h:53
static const char * expectFailComment
Definition: qtestresult.cpp:69

◆ failCount()

int QTestResult::failCount ( )
static

Definition at line 324 of file qtestresult.cpp.

Referenced by QTest::qExec(), and QPlainTestLogger::stopLogging().

325 {
326  return QTest::fails;
327 }
static int fails
Definition: qtestresult.cpp:65

◆ finishedCurrentTestFunction()

void QTestResult::finishedCurrentTestFunction ( )
static

Definition at line 141 of file qtestresult.cpp.

Referenced by QTest::qExec(), QTest::qInvokeTestMethod(), and QTest::qInvokeTestMethods().

142 {
145  addFailure("Not all expected messages were received", 0, 0);
146  }
147 
149  QTestLog::addPass("");
150  ++QTest::passes;
151  }
153  QTest::failed = false;
154  QTest::dataFailed = false;
156 
158 
159  clearExpectFail();
160 }
static void addPass(const char *msg)
Definition: qtestlog.cpp:253
static bool dataFailed
Definition: qtestresult.cpp:61
static bool skipCurrentTest
Definition: qtestresult.cpp:62
static const char * currentTestFunc
Definition: qtestresult.cpp:58
static void addFailure(const char *message, const char *file, int line)
static int unhandledIgnoreMessages()
Definition: qtestlog.cpp:217
static void printUnhandledIgnoreMessages()
Definition: qtestlog.cpp:239
static void clearExpectFail()
static int passes
Definition: qtestresult.cpp:66
static bool failed
Definition: qtestresult.cpp:60
static QTestResult::TestLocation location
Definition: qtestresult.cpp:63
static void leaveTestFunction()
Definition: qtestlog.cpp:228

◆ ignoreMessage()

void QTestResult::ignoreMessage ( QtMsgType  type,
const char *  msg 
)
static

Definition at line 334 of file qtestresult.cpp.

Referenced by QTest::ignoreMessage().

335 {
337 }
int type
Definition: qmetatype.cpp:239
static void addIgnoreMessage(QtMsgType type, const char *msg)
Definition: qtestlog.cpp:368

◆ passCount()

int QTestResult::passCount ( )
static

Definition at line 319 of file qtestresult.cpp.

Referenced by QPlainTestLogger::stopLogging().

320 {
321  return QTest::passes;
322 }
static int passes
Definition: qtestresult.cpp:66

◆ reset()

void QTestResult::reset ( )
static

Definition at line 75 of file qtestresult.cpp.

Referenced by QTest::qExec().

76 {
81  QTest::failed = false;
82  QTest::dataFailed = false;
84 
85  QTest::fails = 0;
86  QTest::passes = 0;
87  QTest::skips = 0;
88 
91 }
static bool dataFailed
Definition: qtestresult.cpp:61
static const char * currentTestFunc
Definition: qtestresult.cpp:58
static int expectFailMode
Definition: qtestresult.cpp:70
static int fails
Definition: qtestresult.cpp:65
static int passes
Definition: qtestresult.cpp:66
static bool failed
Definition: qtestresult.cpp:60
static QTestResult::TestLocation location
Definition: qtestresult.cpp:63
static QTestData * currentTestData
Definition: qtestresult.cpp:56
static const char * expectFailComment
Definition: qtestresult.cpp:69
static int skips
Definition: qtestresult.cpp:67
static const char * currentTestObjectName
Definition: qtestresult.cpp:59
static QTestData * currentGlobalTestData
Definition: qtestresult.cpp:57

◆ setCurrentAppName()

void QTestResult::setCurrentAppName ( const char *  appName)
static

Definition at line 354 of file qtestresult.cpp.

Referenced by QTest::qExec().

355 {
357 }
static const char * currentAppName
Definition: qtestresult.cpp:72
static QString appName

◆ setCurrentGlobalTestData()

void QTestResult::setCurrentGlobalTestData ( QTestData data)
static

Definition at line 113 of file qtestresult.cpp.

Referenced by QTest::qInvokeTestMethod().

114 {
116 }
static const char * data(const QByteArray &arr)
static QTestData * currentGlobalTestData
Definition: qtestresult.cpp:57

◆ setCurrentTestData()

void QTestResult::setCurrentTestData ( QTestData data)
static

Definition at line 118 of file qtestresult.cpp.

Referenced by QTest::qInvokeTestMethod(), QTest::QTestDataSetter::QTestDataSetter(), and QTest::QTestDataSetter::~QTestDataSetter().

119 {
121  QTest::dataFailed = false;
122 }
static bool dataFailed
Definition: qtestresult.cpp:61
static const char * data(const QByteArray &arr)
static QTestData * currentTestData
Definition: qtestresult.cpp:56

◆ setCurrentTestFunction()

void QTestResult::setCurrentTestFunction ( const char *  func)
static

Definition at line 124 of file qtestresult.cpp.

Referenced by QTest::qExec(), QTest::qInvokeTestMethod(), and QTest::qInvokeTestMethods().

125 {
126  QTest::currentTestFunc = func;
127  QTest::failed = false;
128  if (!func)
130  if (func)
132 }
static const char * currentTestFunc
Definition: qtestresult.cpp:58
static void enterTestFunction(const char *function)
Definition: qtestlog.cpp:206
static bool failed
Definition: qtestresult.cpp:60
static QTestResult::TestLocation location
Definition: qtestresult.cpp:63

◆ setCurrentTestLocation()

void QTestResult::setCurrentTestLocation ( TestLocation  loc)
static

Definition at line 304 of file qtestresult.cpp.

Referenced by QTest::qInvokeTestMethod(), QTest::qInvokeTestMethodDataEntry(), and QTest::qInvokeTestMethods().

305 {
306  QTest::location = loc;
307 }
static QTestResult::TestLocation location
Definition: qtestresult.cpp:63

◆ setCurrentTestObject()

void QTestResult::setCurrentTestObject ( const char *  name)
static

Definition at line 309 of file qtestresult.cpp.

Referenced by QTest::qExec().

310 {
312 }
const char * name
static const char * currentTestObjectName
Definition: qtestresult.cpp:59

◆ setSkipCurrentTest()

void QTestResult::setSkipCurrentTest ( bool  value)
static

Definition at line 344 of file qtestresult.cpp.

Referenced by QTest::qInvokeTestMethod(), QTest::qInvokeTestMethods(), and QTest::qSkip().

345 {
346  QTest::skipCurrentTest = value;
347 }
static bool skipCurrentTest
Definition: qtestresult.cpp:62

◆ skipCount()

int QTestResult::skipCount ( )
static

Definition at line 329 of file qtestresult.cpp.

Referenced by QPlainTestLogger::stopLogging().

330 {
331  return QTest::skips;
332 }
static int skips
Definition: qtestresult.cpp:67

◆ skipCurrentTest()

bool QTestResult::skipCurrentTest ( )
static

Definition at line 349 of file qtestresult.cpp.

Referenced by QTest::qInvokeTestMethod(), QTest::qInvokeTestMethodDataEntry(), and QTest::qInvokeTestMethods().

350 {
351  return QTest::skipCurrentTest;
352 }
static bool skipCurrentTest
Definition: qtestresult.cpp:62

◆ testFailed()

bool QTestResult::testFailed ( )
static

Definition at line 339 of file qtestresult.cpp.

Referenced by QTest::qInvokeTestMethods().

340 {
341  return QTest::failed;
342 }
static bool failed
Definition: qtestresult.cpp:60

◆ verify()

bool QTestResult::verify ( bool  statement,
const char *  statementStr,
const char *  extraInfo,
const char *  file,
int  line 
)
static

Definition at line 238 of file qtestresult.cpp.

Referenced by QTest::qVerify().

240 {
241  char msg[1024];
242 
243  if (QTestLog::verboseLevel() >= 2) {
244  QTest::qt_snprintf(msg, 1024, "QVERIFY(%s)", statementStr);
245  QTestLog::info(msg, file, line);
246  }
247 
248  QTest::qt_snprintf(msg, 1024, "'%s' returned FALSE. (%s)", statementStr, description);
249 
250  return checkStatement(statement, msg, file, line);
251 }
static int verboseLevel()
Definition: qtestlog.cpp:363
int Q_TESTLIB_EXPORT qt_snprintf(char *str, int size, const char *format,...)
Definition: qtestcase.cpp:961
static bool checkStatement(bool statement, const char *msg, const char *file, int line)
static void info(const char *msg, const char *file, int line)
Definition: qtestlog.cpp:340

The documentation for this class was generated from the following files: