45 #include <QtTest/qtest_global.h> 47 #include <QtCore/qnamespace.h> 48 #include <QtCore/qmetatype.h> 56 #define QVERIFY(statement) \ 58 if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\ 62 #define QFAIL(message) \ 64 QTest::qFail(message, __FILE__, __LINE__);\ 68 #define QVERIFY2(statement, description) \ 71 if (!QTest::qVerify(true, #statement, (description), __FILE__, __LINE__))\ 74 if (!QTest::qVerify(false, #statement, (description), __FILE__, __LINE__))\ 79 #define QCOMPARE(actual, expected) \ 81 if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\ 85 #define QSKIP(statement, mode) \ 87 QTest::qSkip(statement, QTest::mode, __FILE__, __LINE__);\ 91 #define QEXPECT_FAIL(dataIndex, comment, mode)\ 93 if (!QTest::qExpectFail(dataIndex, comment, QTest::mode, __FILE__, __LINE__))\ 97 #define QFETCH(type, name)\ 98 type name = *static_cast<type *>(QTest::qData(#name, ::qMetaTypeId<type >())) 100 #define QFETCH_GLOBAL(type, name)\ 101 type name = *static_cast<type *>(QTest::qGlobalData(#name, ::qMetaTypeId<type >())) 103 #define DEPENDS_ON(funcName) 105 #define QTEST(actual, testElement)\ 107 if (!QTest::qTest(actual, testElement, #actual, #testElement, __FILE__, __LINE__))\ 117 #define QTEST_COMPARE_DECL(KLASS)\ 118 template<> Q_TESTLIB_EXPORT char *toString<KLASS >(const KLASS &); 122 template <
typename T>
137 const char *file,
int line);
141 const char *file,
int line);
162 const char *expected,
const char *actual,
163 const char *file,
int line);
167 template <
typename T>
174 template <
typename T>
175 inline bool qCompare(T
const &t1, T
const &t2,
const char *actual,
const char *expected,
176 const char *file,
int line)
181 toString<T>(t1), toString<T>(t2), actual, expected, file, line);
187 const char *actual,
const char *expected,
const char *file,
int line);
191 const char *actual,
const char *expected,
const char *file,
int line);
194 const char *expected,
const char *file,
int line)
203 const char *expected,
const char *file,
int line);
221 #ifndef QTEST_NO_SPECIALIZATIONS 222 template <
typename T1,
typename T2>
223 bool qCompare(T1
const &, T2
const &,
const char *,
const char *,
const char *,
int);
225 #if defined(QT_COORD_TYPE) && (defined(QT_ARCH_ARM) || defined(QT_NO_FPU) || defined(QT_ARCH_WINDOWSCE)) 227 inline bool qCompare<qreal, float>(
qreal const &t1,
float const &t2,
const char *actual,
228 const char *expected,
const char *file,
int line)
230 return qCompare<qreal>(t1,
qreal(t2), actual, expected, file, line);
234 inline bool qCompare<float, qreal>(
float const &t1,
qreal const &t2,
const char *actual,
235 const char *expected,
const char *file,
int line)
237 return qCompare<qreal>(
qreal(t1), t2, actual, expected, file, line);
240 #elif defined(QT_COORD_TYPE) || defined(QT_ARCH_ARM) || defined(QT_NO_FPU) || defined(QT_ARCH_WINDOWSCE) || defined(QT_ARCH_SYMBIAN) 242 inline bool qCompare<qreal, double>(
qreal const &t1,
double const &t2,
const char *actual,
243 const char *expected,
const char *file,
int line)
245 return qCompare<float>(float(t1), float(t2), actual, expected, file, line);
249 inline bool qCompare<double, qreal>(
double const &t1,
qreal const &t2,
const char *actual,
250 const char *expected,
const char *file,
int line)
252 return qCompare<float>(float(t1), float(t2), actual, expected, file, line);
257 template <
typename T>
258 inline bool qCompare(
const T *t1,
const T *t2,
const char *actual,
const char *expected,
259 const char *file,
int line)
263 template <
typename T>
264 inline bool qCompare(T *t1, T *t2,
const char *actual,
const char *expected,
265 const char *file,
int line)
270 template <
typename T1,
typename T2>
271 inline bool qCompare(
const T1 *t1,
const T2 *t2,
const char *actual,
const char *expected,
272 const char *file,
int line)
274 return compare_ptr_helper(t1, static_cast<const T1 *>(t2), actual, expected, file, line);
276 template <
typename T1,
typename T2>
277 inline bool qCompare(T1 *t1, T2 *t2,
const char *actual,
const char *expected,
278 const char *file,
int line)
281 static_cast<const T1 *>(const_cast<const T2 *>(t2)), actual, expected, file, line);
285 const char *expected,
const char *file,
int line)
290 inline bool qCompare<char>(
char *t1,
char *t2,
const char *actual,
const char *expected,
291 const char *file,
int line)
299 #if defined(QT_ARCH_SYMBIAN) 300 template <
typename T1,
typename T2>
301 bool qCompare(T1
const &, T2
const &,
const char *,
const char *,
const char *,
int);
304 inline bool qCompare<qreal, double>(
qreal const &t1,
double const &t2,
const char *actual,
305 const char *expected,
const char *file,
int line)
307 return qCompare<float>(float(t1), float(t2), actual, expected, file, line);
311 inline bool qCompare<double, qreal>(
double const &t1,
qreal const &t2,
const char *actual,
312 const char *expected,
const char *file,
int line)
314 return qCompare<float>(float(t1), float(t2), actual, expected, file, line);
318 inline bool qCompare(
const char *t1,
const char *t2,
const char *actual,
319 const char *expected,
const char *file,
int line)
324 inline bool qCompare(
char *t1,
char *t2,
const char *actual,
const char *expected,
325 const char *file,
int line)
334 #ifndef QTEST_NO_SPECIALIZATIONS 337 inline bool qCompare(
char *t1,
const char *t2,
const char *actual,
338 const char *expected,
const char *file,
int line)
342 #ifndef QTEST_NO_SPECIALIZATIONS 345 inline bool qCompare(
const char *t1,
char *t2,
const char *actual,
346 const char *expected,
const char *file,
int line)
352 #ifndef QTEST_NO_SPECIALIZATIONS 355 inline bool qCompare(
bool const &t1,
int const &t2,
356 const char *actual,
const char *expected,
const char *file,
int line)
358 return qCompare<int>(int(t1), t2, actual, expected, file, line);
363 inline bool qTest(
const T& actual,
const char *elementName,
const char *actualStr,
364 const char *expected,
const char *file,
int line)
367 qMetaTypeId<T>())), actualStr, expected, file, line);
371 #undef QTEST_COMPARE_DECL bool qCompare(QString const &t1, QLatin1String const &t2, const char *actual, const char *expected, const char *file, int line)
#define QT_END_NAMESPACE
This macro expands to.
static const char * currentAppName
Q_TESTLIB_EXPORT const char * currentTestFunction()
Returns the name of the test function that is currently executed.
Q_TESTLIB_EXPORT QObject * testObject()
Q_TESTLIB_EXPORT void ignoreMessage(QtMsgType type, const char *message)
Ignores messages created by qDebug() or qWarning().
SkipMode
This enum describes the modes for skipping tests during execution of the test data.
Q_TESTLIB_EXPORT void * qElementData(const char *elementName, int metaTypeId)
Q_TESTLIB_EXPORT bool qExpectFail(const char *dataIndex, const char *comment, TestFailMode mode, const char *file, int line)
void addColumn(const char *name, T *=0)
Adds a column with type T to the current test data.
Q_TESTLIB_EXPORT void addColumnInternal(int id, const char *name)
Q_TESTLIB_EXPORT int qExec(QObject *testObject, int argc=0, char **argv=0)
Executes tests declared in testObject.
The QObject class is the base class of all Qt objects.
QtMsgType
This enum describes the messages that can be sent to a message handler (QtMsgHandler).
Q_TESTLIB_EXPORT void qFail(const char *statementStr, const char *file, int line)
Q_TESTLIB_EXPORT void * qData(const char *tagName, int typeId)
#define QT_BEGIN_NAMESPACE
This macro expands to.
char * toHexRepresentation(const char *ba, int length)
Returns a pointer to a string that is the string ba represented as a space-separated sequence of hex ...
bool qCompare< char >(const char *t1, const char *t2, const char *actual, const char *expected, const char *file, int line)
The QStringList class provides a list of strings.
char * toString(const QLatin1String &str)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Q_TESTLIB_EXPORT bool qCompare< double >(double const &t1, double const &t2, const char *actual, const char *expected, const char *file, int line)
Q_TESTLIB_EXPORT const char * currentDataTag()
Returns the name of the current test data.
Q_TESTLIB_EXPORT void qWarn(const char *message)
Q_TESTLIB_EXPORT bool qCompare< float >(float const &t1, float const &t2, const char *actual, const char *expected, const char *file, int line)
#define QTEST_COMPARE_DECL(KLASS)
Q_TESTLIB_EXPORT bool qVerify(bool statement, const char *statementStr, const char *description, const char *file, int line)
Q_TESTLIB_EXPORT void qSkip(const char *message, SkipMode mode, const char *file, int line)
TestFailMode
This enum describes the modes for handling an expected failure of the QVERIFY() or QCOMPARE() macros...
Q_TESTLIB_EXPORT char keyToAscii(Qt::Key key)
Convert a Qt Key to an ascii char value.
Q_TESTLIB_EXPORT bool compare_helper(bool success, const char *msg, const char *file, int line)
Q_TESTLIB_EXPORT void * qGlobalData(const char *tagName, int typeId)
bool compare_ptr_helper(const void *t1, const void *t2, const char *actual, const char *expected, const char *file, int line)
Q_TESTLIB_EXPORT Qt::Key asciiToKey(char ascii)
Convert an ascii char key value to a Qt Key value.
Q_TESTLIB_EXPORT bool currentTestFailed()
Returns true if the current test function failed, otherwise false.
Q_TESTLIB_EXPORT QTestData & newRow(const char *dataTag)
Appends a new row to the current test data.
Q_TESTLIB_EXPORT bool compare_string_helper(const char *t1, const char *t2, const char *actual, const char *expected, const char *file, int line)
bool qTest(const T &actual, const char *elementName, const char *actualStr, const char *expected, const char *file, int line)
The QTest namespace contains all the functions and declarations that are related to the QTestLib tool...
Q_TESTLIB_EXPORT void qSleep(int ms)
Sleeps for ms milliseconds, blocking execution of the test.