diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/test/qfxtestengine.cpp | 54 | ||||
-rw-r--r-- | src/declarative/test/qfxtestobjects.cpp | 84 | ||||
-rw-r--r-- | src/declarative/test/qfxtestobjects.h | 12 | ||||
-rw-r--r-- | src/declarative/test/qfxtestview.cpp | 3 |
4 files changed, 84 insertions, 69 deletions
diff --git a/src/declarative/test/qfxtestengine.cpp b/src/declarative/test/qfxtestengine.cpp index 70e600d..0d7e5df 100644 --- a/src/declarative/test/qfxtestengine.cpp +++ b/src/declarative/test/qfxtestengine.cpp @@ -62,7 +62,7 @@ class QFxTestEnginePrivate : public QAbstractAnimation { public: QFxTestEnginePrivate(QFxTestEngine *p) - : q(p), canvas(0), testMode(QFxTestEngine::NoTest), fullFrame(true), + : q(p), canvas(0), testMode(QFxTestEngine::NoTest), fullFrame(true), status(Working), exitOnFail(true), mismatchedFrames(0), lastFrameMismatch(false) {} @@ -106,20 +106,25 @@ public: bool compare(const QImage &img1, const QImage &img2); virtual int duration() const { return -1; } + + int elapsed() { return currentTime(); } }; bool QFxTestEnginePrivate::compare(const QImage &img1, const QImage &img2) { - if (img1.size() != img2.size()) + if (img1.size() != img2.size()) { + qWarning() << "Image size mismatch" << img1.size() << img2.size(); return false; + } int errorCount = 0; for (int yy = 0; yy < img1.height(); ++yy) { for (int xx = 0; xx < img1.width(); ++xx) { if (img1.pixel(xx, yy) != img2.pixel(xx, yy)) { errorCount++; - if (errorCount > MAX_MISMATCHED_PIXELS) + if (errorCount > MAX_MISMATCHED_PIXELS) { return false; + } } } } @@ -142,7 +147,7 @@ QFxTestEngine::QFxTestEngine(TestMode mode, const QString &dir, qWarning("QFxTestEngine: Record ON"); } else if (d->testMode == PlaybackTest) { - QString fileName(d->testDirectory + QLatin1String("/manifest.xml")); + QString fileName(d->testDirectory + QLatin1String("/manifest.qml")); QFile f(fileName); if (!f.open(QIODevice::ReadOnly)) { qWarning() << "QFxTestEngine: Unable to open file" << fileName; @@ -150,13 +155,13 @@ QFxTestEngine::QFxTestEngine(TestMode mode, const QString &dir, } QByteArray data = f.readAll(); - QmlComponent c(&d->engine, data, QUrl(d->testDirectory + QLatin1String("/manifest.xml"))); + QmlComponent c(&d->engine, data, QUrl(d->testDirectory + QLatin1String("/manifest.qml"))); QObject *o = c.create(); TestLog *log = qobject_cast<TestLog *>(o); if (log) { log->setParent(this); d->playbackTestData.actions() = log->actions(); - qWarning("QFxTestEngine: Playback ON"); + qWarning() << "QFxTestEngine: Playback ON," << d->playbackTestData.actions().count() << "actions"; } else { delete o; qWarning() << "QFxTestEngine: File" << fileName << "is corrupt."; @@ -165,7 +170,6 @@ QFxTestEngine::QFxTestEngine(TestMode mode, const QString &dir, } if (d->testMode != NoTest) { - QUnifiedTimer::instance()->setConsistentTiming(true); QObject::connect(canvas, SIGNAL(framePainted()), this, SLOT(framePainted())); @@ -173,7 +177,7 @@ QFxTestEngine::QFxTestEngine(TestMode mode, const QString &dir, canvas->installEventFilter(this); for (int ii = 0; ii < d->playbackTestData.actions().count(); ++ii) { TestObject *o = d->playbackTestData.actions().at(ii); - if (TestMouse *m = qobject_cast<TestMouse *>(o)) + if (TestMouse *m = qobject_cast<TestMouse *>(o)) d->toPost << m; else if (TestKey *k = qobject_cast<TestKey *>(o)) d->toPost << k; @@ -201,7 +205,7 @@ void QFxTestEngine::framePainted() void QFxTestEnginePrivate::recordFullFrameEvent(const QImage &img) { TestFullFrame *ff = new TestFullFrame(q); - ff->setTime(QUnifiedTimer::instance()->elapsedTime()); + ff->setTime(elapsed()); ff->setFrameId(fullFrames.count()); fullFrames << img; @@ -211,7 +215,8 @@ void QFxTestEnginePrivate::recordFullFrameEvent(const QImage &img) TestFullFrame *pf = qobject_cast<TestFullFrame *>(playbackTestData.next()); QString filename = testDirectory + QLatin1String("/image") + QString::number(pf->frameId()) + QLatin1String(".png"); QImage recImg(filename); - if (!pf || !compare(recImg, img) || pf->time() != QUnifiedTimer::instance()->elapsedTime()) { + if (!pf || !compare(recImg, img) || pf->time() != elapsed()) { + qDebug() << pf << pf->time() << elapsed(); message(Fail, "FFrame mismatch"); } else { message(Success, "FFrame OK"); @@ -249,14 +254,14 @@ void QFxTestEnginePrivate::recordFrameEvent(const QImage &img) hexResult.append(toHex(result.at(ii))); TestFrame *f = new TestFrame(q); - f->setTime(QUnifiedTimer::instance()->elapsedTime()); + f->setTime(elapsed()); f->setHash(QLatin1String(hexResult)); testData.actions() << f; if (testMode == QFxTestEngine::PlaybackTest) { TestObject *o = playbackTestData.next(); TestFrame *f = qobject_cast<TestFrame *>(o); - if (!f || f->time() != QUnifiedTimer::instance()->elapsedTime() || + if (!f || f->time() != elapsed() || f->hash() != QLatin1String(hexResult)) { mismatchedFrames++; if (mismatchedFrames > MAX_MISMATCHED_FRAMES || @@ -280,14 +285,13 @@ void QFxTestEnginePrivate::updateCurrentTime(int) return; while(!toPost.isEmpty()) { - int t = QUnifiedTimer::instance()->elapsedTime(); + int t = elapsed(); TestObject *o = toPost.first(); if (testMode == QFxTestEngine::RecordTest) o->setTime(t); else if (o->time() != t) return; toPost.takeFirst(); - if (TestMouse *m = qobject_cast<TestMouse *>(o)) { QMouseEvent e((QEvent::Type)m->type(), m->pos(), m->globalPos(), (Qt::MouseButton)m->button(), (Qt::MouseButtons)m->buttons(), (Qt::KeyboardModifiers)0); postedEvents.insert(&e); @@ -336,7 +340,7 @@ bool QFxTestEngine::eventFilter(QObject *, QEvent *event) void QFxTestEnginePrivate::recordMouseEvent(QMouseEvent *e) { TestMouse *m = new TestMouse(q); - m->setTime(QUnifiedTimer::instance()->elapsedTime()); + m->setTime(elapsed()); m->setType(e->type()); m->setButton(e->button()); m->setButtons(e->buttons()); @@ -346,14 +350,16 @@ void QFxTestEnginePrivate::recordMouseEvent(QMouseEvent *e) if (testMode == QFxTestEngine::PlaybackTest) { TestMouse *m = qobject_cast<TestMouse *>(playbackTestData.next()); - if (!m || m->time() != QUnifiedTimer::instance()->elapsedTime() || + if (!m || m->time() != elapsed() || m->type() != e->type() || m->button() != e->button() || m->buttons() != e->buttons() || - m->globalPos() != e->globalPos() || - m->pos() != e->pos()) +// m->globalPos() != e->globalPos() || + m->pos() != e->pos()) { + if (m) + qWarning() << m->time() << elapsed(); message(Fail, "Mouse mismatch"); - else + } else message(Success, "Mouse OK"); testPass(); @@ -366,7 +372,7 @@ void QFxTestEnginePrivate::recordMouseEvent(QMouseEvent *e) void QFxTestEnginePrivate::recordKeyEvent(QKeyEvent *e) { TestKey *k = new TestKey(q); - k->setTime(QUnifiedTimer::instance()->elapsedTime()); + k->setTime(elapsed()); k->setType(e->type()); k->setModifiers(e->QInputEvent::modifiers()); k->setText(e->text()); @@ -374,7 +380,7 @@ void QFxTestEnginePrivate::recordKeyEvent(QKeyEvent *e) testData.actions() << k; if (testMode == QFxTestEngine::PlaybackTest) { TestKey *f = qobject_cast<TestKey *>(playbackTestData.next()); - if (!f || f->time() != QUnifiedTimer::instance()->elapsedTime() || + if (!f || f->time() != elapsed() || f->type() != e->type() || f->modifiers() != e->QInputEvent::modifiers() || f->text() != e->text() || @@ -400,7 +406,7 @@ void QFxTestEnginePrivate::message(MessageType t, const char *message) qWarning("%s", message); if (t == Fail) { if (exitOnFail) { - save(QLatin1String("manifest-fail.xml"), false); + save(QLatin1String("manifest-fail.qml"), false); qFatal("Failed"); } else { status = Failed; @@ -428,7 +434,7 @@ void QFxTestEngine::save() if (d->testMode != RecordTest) return; - d->save(QLatin1String("manifest.xml")); + d->save(QLatin1String("manifest.qml")); } void QFxTestEnginePrivate::testPass() @@ -436,7 +442,7 @@ void QFxTestEnginePrivate::testPass() if (playbackTestData.atEnd()) { qWarning("Test PASSED"); if (exitOnFail) { - save(QLatin1String("manifest-play.xml")); + save(QLatin1String("manifest-play.qml")); exit(0); } else { status = Passed; diff --git a/src/declarative/test/qfxtestobjects.cpp b/src/declarative/test/qfxtestobjects.cpp index be1ab07..905e83e 100644 --- a/src/declarative/test/qfxtestobjects.cpp +++ b/src/declarative/test/qfxtestobjects.cpp @@ -42,7 +42,8 @@ #include "qfxtestobjects.h" #include <qml.h> -#include <QIODevice> +#include <QDebug> +#include <QTextStream> QT_BEGIN_NAMESPACE @@ -59,6 +60,14 @@ QML_DEFINE_TYPE(TestKey,TestKey); QML_DECLARE_TYPE(TestLog); QML_DEFINE_TYPE(TestLog,TestLog); +static QString padding(int pad) +{ + QString p; + while (pad--) + p += QLatin1Char(' '); + return p; +} + TestObject::TestObject(QObject *parent) : QObject(parent), _time(-1) { @@ -77,11 +86,11 @@ void TestObject::setTime(int t) emit dataChanged(); } -void TestObject::save(QXmlStreamWriter *device) +void TestObject::save(QTextStream &device, int pad) { - device->writeStartElement(QLatin1String("TestObject")); - device->writeAttribute(QLatin1String("time"), QString::number(time())); - device->writeEndElement(); + device << padding(pad) << QLatin1String("TestObject {") << endl; + device << padding(pad) << QLatin1String("time: ") << QString::number(time()) << endl; + device << padding(pad) << QLatin1String("}") << endl; } @@ -103,12 +112,12 @@ void TestFrame::setHash(const QString &h) emit frameChanged(); } -void TestFrame::save(QXmlStreamWriter *device) +void TestFrame::save(QTextStream &device, int pad) { - device->writeStartElement(QLatin1String("TestFrame")); - device->writeAttribute(QLatin1String("time"), QLatin1String(QByteArray::number(time()))); - device->writeAttribute(QLatin1String("hash"), hash()); - device->writeEndElement(); + device << padding(pad) << QLatin1String("TestFrame {") << endl; + device << padding(pad+4) << QLatin1String("time: ") << QLatin1String(QByteArray::number(time())) << endl; + device << padding(pad+4)<< QLatin1String("hash: '") << hash() << QLatin1String("'") << endl; + device << padding(pad) << QLatin1Char('}') << endl; } TestFullFrame::TestFullFrame(QObject *parent) @@ -129,12 +138,12 @@ void TestFullFrame::setFrameId(int id) emit frameChanged(); } -void TestFullFrame::save(QXmlStreamWriter *device) +void TestFullFrame::save(QTextStream &device, int pad) { - device->writeStartElement(QLatin1String("TestFullFrame")); - device->writeAttribute(QLatin1String("time"), QLatin1String(QByteArray::number(time()))); - device->writeAttribute(QLatin1String("frameId"), QLatin1String(QByteArray::number(frameId()))); - device->writeEndElement(); + device << padding(pad) << QLatin1String("TestFullFrame {") << endl; + device << padding(pad+4) << QLatin1String("time: ") << QLatin1String(QByteArray::number(time())) << endl; + device << padding(pad+4) << QLatin1String("frameId: ") << QLatin1String(QByteArray::number(frameId())) << endl; + device << padding(pad) << padding(pad) << QLatin1String("}") << endl; } TestMouse::TestMouse(QObject *parent) @@ -207,16 +216,16 @@ void TestMouse::setPos(const QPoint &p) emit mouseChanged(); } -void TestMouse::save(QXmlStreamWriter *device) +void TestMouse::save(QTextStream &device, int pad) { - device->writeStartElement(QLatin1String("TestMouse")); - device->writeAttribute(QLatin1String("time"), QString::number(time())); - device->writeAttribute(QLatin1String("type"), QString::number(type())); - device->writeAttribute(QLatin1String("button"), QString::number(button())); - device->writeAttribute(QLatin1String("buttons"), QString::number(buttons())); - device->writeAttribute(QLatin1String("globalPos"), QString::number(globalPos().x()) + QLatin1String(",") + QString::number(globalPos().y())); - device->writeAttribute(QLatin1String("pos"), QString::number(pos().x()) + QLatin1String(",") + QString::number(pos().y())); - device->writeEndElement(); + device << padding(pad) << QLatin1String("TestMouse {") << endl; + device << padding(pad+4) << QLatin1String("time: ") << QString::number(time()) << endl; + device << padding(pad+4) << QLatin1String("type: ") << QString::number(type()) << endl; + device << padding(pad+4) << QLatin1String("button: ") << QString::number(button()) << endl; + device << padding(pad+4) << QLatin1String("buttons: ") << QString::number(buttons()) << endl; + device << padding(pad+4) << QLatin1String("globalPos: '") << QString::number(globalPos().x()) + QLatin1String(",") + QString::number(globalPos().y()) << QLatin1String("'") << endl; + device << padding(pad+4) << QLatin1String("pos: '") << QString::number(pos().x()) + QLatin1String(",") + QString::number(pos().y()) << QLatin1String("'") << endl; + device << padding(pad) << QLatin1String("}") << endl; } TestKey::TestKey(QObject *parent) @@ -276,16 +285,16 @@ void TestKey::setKey(int k) emit keyChanged(); } -void TestKey::save(QXmlStreamWriter *device) +void TestKey::save(QTextStream &device, int pad) { - device->writeStartElement(QLatin1String("TestKey")); - device->writeAttribute(QLatin1String("time"), QString::number(time())); - device->writeAttribute(QLatin1String("type"), QString::number(type())); - device->writeAttribute(QLatin1String("modifiers"), QString::number(modifiers())); - device->writeAttribute(QLatin1String("key"), QString::number(key())); + device << padding(pad) << QLatin1String("TestKey {") << endl; + device << padding(pad+4) << QLatin1String("time: ") << QString::number(time()) << endl; + device << padding(pad+4) << QLatin1String("type: ") << QString::number(type()) << endl; + device << padding(pad+4) << QLatin1String("modifiers: ") << QString::number(modifiers()) << endl; + device << padding(pad+4) << QLatin1String("key: ") << QString::number(key()) << endl; if (key() != Qt::Key_Escape) - device->writeAttribute(QLatin1String("text"), text()); - device->writeEndElement(); + device << padding(pad+4) << QLatin1String("text: '") << text() << QLatin1String("'")<< endl; + device << padding(pad) << QLatin1String("}") << endl; } TestLog::TestLog(QObject *parent) @@ -313,14 +322,11 @@ void TestLog::save(QIODevice *device) // Order correctly qStableSort(_actions.begin(), _actions.end(), lessThan); - QXmlStreamWriter writer(device); - writer.setAutoFormatting(true); - writer.writeStartDocument(QLatin1String("1.0")); - writer.writeStartElement(QLatin1String("TestLog")); + QTextStream writer(device); + writer << QLatin1String("TestLog {") << endl; for (int ii = 0; ii < _actions.count(); ++ii) - _actions.at(ii)->save(&writer); - writer.writeEndElement(); - writer.writeEndDocument(); + _actions.at(ii)->save(writer, 4); + writer << QLatin1String("}") << endl; } TestObject *TestLog::next() diff --git a/src/declarative/test/qfxtestobjects.h b/src/declarative/test/qfxtestobjects.h index 653656e..de4d94b 100644 --- a/src/declarative/test/qfxtestobjects.h +++ b/src/declarative/test/qfxtestobjects.h @@ -45,7 +45,7 @@ #include <QtCore/QObject> #include <QtCore/QPoint> #include <QtCore/QList> -#include <QtCore/QXmlStreamWriter> +#include <QtCore/QTextStream> QT_BEGIN_HEADER @@ -64,7 +64,7 @@ public: int time() const; void setTime(int); - virtual void save(QXmlStreamWriter *); + virtual void save(QTextStream &, int pad); Q_SIGNALS: void dataChanged(); @@ -82,7 +82,7 @@ public: QString hash() const; void setHash(const QString &); - virtual void save(QXmlStreamWriter *); + virtual void save(QTextStream &, int pad); Q_SIGNALS: void frameChanged(); @@ -100,7 +100,7 @@ public: int frameId() const; void setFrameId(int); - virtual void save(QXmlStreamWriter *); + virtual void save(QTextStream &, int pad); Q_SIGNALS: void frameChanged(); @@ -134,7 +134,7 @@ public: QPoint pos() const; void setPos(const QPoint &); - virtual void save(QXmlStreamWriter *); + virtual void save(QTextStream &, int pad); Q_SIGNALS: void mouseChanged(); @@ -169,7 +169,7 @@ public: int key() const; void setKey(int); - virtual void save(QXmlStreamWriter *); + virtual void save(QTextStream &, int pad); Q_SIGNALS: void keyChanged(); diff --git a/src/declarative/test/qfxtestview.cpp b/src/declarative/test/qfxtestview.cpp index 94bcb30..0bd5a6b 100644 --- a/src/declarative/test/qfxtestview.cpp +++ b/src/declarative/test/qfxtestview.cpp @@ -57,6 +57,7 @@ QFxTestView::QFxTestView(const QString &filename, const QString &testdir) testEngine = new QFxTestEngine(QFxTestEngine::PlaybackTest, testdir, this, this); + qWarning() << "Testing:" << filename; QFile file(filename); file.open(QFile::ReadOnly); QString qml = QString::fromUtf8(file.readAll()); @@ -67,6 +68,8 @@ QFxTestView::QFxTestView(const QString &filename, const QString &testdir) void QFxTestView::setSceneSize(QSize s) { + if (s.isNull()) + qWarning() << "Scene size is invalid"; setFixedSize(s); } |