| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#ifndef QQMLTESTUTILS_H |
| 5 |
#define QQMLTESTUTILS_H |
| 6 |
|
| 7 |
#include <QtCore/QDir> |
| 8 |
#include <QtCore/QUrl> |
| 9 |
#include <QtCore/QCoreApplication> |
| 10 |
#include <QtCore/QStringList> |
| 11 |
#include <QtTest/QTest> |
| 12 |
|
| 13 |
QT_FORWARD_DECLARE_CLASS(QQmlComponent) |
| 14 |
QT_FORWARD_DECLARE_CLASS(QQmlEngine) |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
class QQmlDataTest : public QObject |
| 19 |
{ |
| 20 |
Q_OBJECT |
| 21 |
public: |
| 22 |
QQmlDataTest(); |
| 23 |
virtual ~QQmlDataTest(); |
| 24 |
|
| 25 |
QString testFile(const QString &fileName) const; |
| 26 |
inline QString testFile(const char *fileName) const |
| 27 |
{ return testFile(QLatin1String(fileName)); } |
| 28 |
inline QUrl testFileUrl(const QString &fileName) const |
| 29 |
{ return QUrl::fromLocalFile(testFile(fileName)); } |
| 30 |
inline QUrl testFileUrl(const char *fileName) const |
| 31 |
{ return testFileUrl(QLatin1String(fileName)); } |
| 32 |
|
| 33 |
inline QString dataDirectory() const { return m_dataDirectory; } |
| 34 |
inline QUrl dataDirectoryUrl() const { return m_dataDirectoryUrl; } |
| 35 |
inline QString directory() const { return m_directory; } |
| 36 |
|
| 37 |
static inline QQmlDataTest *instance() { return m_instance; } |
| 38 |
|
| 39 |
static QByteArray msgComponentError(const QQmlComponent &, |
| 40 |
const QQmlEngine *engine = 0); |
| 41 |
|
| 42 |
public slots: |
| 43 |
virtual void initTestCase(); |
| 44 |
|
| 45 |
private: |
| 46 |
static QQmlDataTest *m_instance; |
| 47 |
|
| 48 |
const QString m_dataDirectory; |
| 49 |
const QUrl m_dataDirectoryUrl; |
| 50 |
QString m_directory; |
| 51 |
}; |
| 52 |
|
| 53 |
class QQmlTestMessageHandler |
| 54 |
{ |
| 55 |
Q_DISABLE_COPY(QQmlTestMessageHandler) |
| 56 |
public: |
| 57 |
QQmlTestMessageHandler(); |
| 58 |
~QQmlTestMessageHandler(); |
| 59 |
|
| 60 |
const QStringList &messages() const { return m_messages; } |
| 61 |
const QString messageString() const { return m_messages.join(QLatin1Char('\n')); } |
| 62 |
|
| 63 |
void clear() { m_messages.clear(); } |
| 64 |
|
| 65 |
private: |
| 66 |
static void messageHandler(QtMsgType, const QMessageLogContext &, const QString &message); |
| 67 |
|
| 68 |
static QQmlTestMessageHandler *m_instance; |
| 69 |
QStringList m_messages; |
| 70 |
QtMessageHandler m_oldHandler; |
| 71 |
}; |
| 72 |
|
| 73 |
#endif |