diff options
Diffstat (limited to 'tests/auto')
12 files changed, 1713 insertions, 46 deletions
diff --git a/tests/auto/declarative/animatedimage/tst_animatedimage.cpp b/tests/auto/declarative/animatedimage/tst_animatedimage.cpp index f6141cb..6ae2112 100644 --- a/tests/auto/declarative/animatedimage/tst_animatedimage.cpp +++ b/tests/auto/declarative/animatedimage/tst_animatedimage.cpp @@ -61,34 +61,40 @@ private slots: void tst_animatedimage::play() { - QmlGraphicsAnimatedImageItem anim; - anim.setSource(QUrl("file://" SRCDIR "/data/stickman.gif")); - QVERIFY(anim.isPlaying()); + QmlEngine engine; + QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/stickman.qml")); + QmlGraphicsAnimatedImageItem *anim = qobject_cast<QmlGraphicsAnimatedImageItem *>(component.create()); + QVERIFY(anim); + QVERIFY(anim->isPlaying()); } void tst_animatedimage::pause() { - QmlGraphicsAnimatedImageItem anim; - anim.setSource(QUrl("file://" SRCDIR "/data/stickman.gif")); - anim.setPaused(true); - QVERIFY(!anim.isPlaying()); + QmlEngine engine; + QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/stickmanpause.qml")); + QmlGraphicsAnimatedImageItem *anim = qobject_cast<QmlGraphicsAnimatedImageItem *>(component.create()); + QVERIFY(anim); + QVERIFY(anim->isPlaying()); + QVERIFY(anim->isPaused()); } void tst_animatedimage::setFrame() { - QmlGraphicsAnimatedImageItem anim; - anim.setSource(QUrl("file://" SRCDIR "/data/stickman.gif")); - anim.setPaused(true); - QVERIFY(!anim.isPlaying()); - anim.setCurrentFrame(2); - QCOMPARE(anim.currentFrame(), 2); + QmlEngine engine; + QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/stickmanpause.qml")); + QmlGraphicsAnimatedImageItem *anim = qobject_cast<QmlGraphicsAnimatedImageItem *>(component.create()); + QVERIFY(anim); + QVERIFY(anim->isPlaying()); + QCOMPARE(anim->currentFrame(), 2); } void tst_animatedimage::frameCount() { - QmlGraphicsAnimatedImageItem anim; - anim.setSource(QUrl("file://" SRCDIR "/data/stickman.gif")); - QCOMPARE(anim.frameCount(), 299); + QmlEngine engine; + QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/stickman.qml")); + QmlGraphicsAnimatedImageItem *anim = qobject_cast<QmlGraphicsAnimatedImageItem *>(component.create()); + QVERIFY(anim); + QCOMPARE(anim->frameCount(), 299); } QTEST_MAIN(tst_animatedimage) diff --git a/tests/auto/declarative/behaviors/data/simple.qml b/tests/auto/declarative/behaviors/data/simple.qml index a715f7b..37c3915 100644 --- a/tests/auto/declarative/behaviors/data/simple.qml +++ b/tests/auto/declarative/behaviors/data/simple.qml @@ -6,7 +6,10 @@ Rectangle { id: rect objectName: "MyRect" width: 100; height: 100; color: "green" - x: Behavior { NumberAnimation { duration: 200; } } + x: Behavior { + objectName: "MyBehavior"; + NumberAnimation { duration: 200; } + } } MouseRegion { id: clicker diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp index 9803a9d..29c631d 100644 --- a/tests/auto/declarative/behaviors/tst_behaviors.cpp +++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp @@ -43,6 +43,7 @@ #include <QtDeclarative/qmlcomponent.h> #include <QtDeclarative/qmlview.h> #include <private/qmlgraphicsrectangle_p.h> +#include <private/qmlbehavior_p.h> #include <private/qmlanimation_p.h> class tst_behaviors : public QObject @@ -60,6 +61,9 @@ private slots: void replaceBinding(); //void transitionOverrides(); void group(); + void emptyBehavior(); + void nonSelectingBehavior(); + void reassignedAnimation(); }; void tst_behaviors::simpleBehavior() @@ -68,6 +72,7 @@ void tst_behaviors::simpleBehavior() QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/simple.qml")); QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); QVERIFY(rect); + QVERIFY(qobject_cast<QmlBehavior*>(rect->findChild<QmlBehavior*>("MyBehavior"))->animation()); rect->setState("moved"); QTest::qWait(100); @@ -189,6 +194,44 @@ void tst_behaviors::group() } } +void tst_behaviors::emptyBehavior() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/empty.qml")); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + qreal x = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect"))->x(); + QCOMPARE(x, qreal(200)); //should change immediately +} + +void tst_behaviors::nonSelectingBehavior() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/nonSelecting.qml")); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + qreal x = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect"))->x(); + QCOMPARE(x, qreal(200)); //should change immediately +} + +void tst_behaviors::reassignedAnimation() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/reassignedAnimation.qml")); + QTest::ignoreMessage(QtWarningMsg, "QML QmlBehavior (file://" SRCDIR "/data/reassignedAnimation.qml:9:12) Can't change the animation assigned to a Behavior."); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + QTest::qWait(200 + 100); + qreal x = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect"))->x(); + QCOMPARE(x, qreal(200)); //i.e. the right behavior has been triggered +} + QTEST_MAIN(tst_behaviors) #include "tst_behaviors.moc" diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 40cdb58..0d55391 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -15,6 +15,7 @@ SUBDIRS += anchors \ qfxtextedit \ qfxtextinput \ qfxwebview \ + qmetaobjectbuilder \ qmlcontext \ qmldom \ qmlecmascript \ diff --git a/tests/auto/declarative/examples/data/webbrowser/webbrowser.qml b/tests/auto/declarative/examples/data/webbrowser/webbrowser.qml new file mode 100644 index 0000000..bdf3290 --- /dev/null +++ b/tests/auto/declarative/examples/data/webbrowser/webbrowser.qml @@ -0,0 +1,6 @@ +import Qt.VisualTest 4.6 + +VisualTest { + Frame { msec: 0 } + Frame { msec: 1000 } +} diff --git a/tests/auto/declarative/examples/tst_examples.cpp b/tests/auto/declarative/examples/tst_examples.cpp index ac12204..d758101 100644 --- a/tests/auto/declarative/examples/tst_examples.cpp +++ b/tests/auto/declarative/examples/tst_examples.cpp @@ -42,6 +42,7 @@ #include <QLibraryInfo> #include <QDir> #include <QProcess> +#include <QDebug> class tst_examples : public QObject { @@ -179,9 +180,12 @@ void tst_examples::examples() { QFETCH(QString, file); + QFileInfo fi(file); + QFileInfo dir(fi.path()); + QFileInfo testdata("data/"+dir.baseName()+"/"+fi.baseName()); QStringList arguments; - arguments << "-script" << "data/dummytest" - << "-scriptopts" << "play,exitoncomplete,exitonfailure" + arguments << "-script" << (testdata.exists() ? testdata.filePath() : QLatin1String("data/dummytest")) + << "-scriptopts" << "play,testerror,exitoncomplete,exitonfailure" << file; QProcess p; p.start(qmlviewer, arguments); diff --git a/tests/auto/declarative/qmetaobjectbuilder/qmetaobjectbuilder.pro b/tests/auto/declarative/qmetaobjectbuilder/qmetaobjectbuilder.pro new file mode 100644 index 0000000..94ffe4b --- /dev/null +++ b/tests/auto/declarative/qmetaobjectbuilder/qmetaobjectbuilder.pro @@ -0,0 +1,7 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +macx:CONFIG -= app_bundle + +SOURCES += \ + tst_qmetaobjectbuilder.cpp + diff --git a/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp b/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp new file mode 100644 index 0000000..9beec17 --- /dev/null +++ b/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp @@ -0,0 +1,1059 @@ +/**************************************************************************** +** +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <QtCore/qlocale.h> +#include <private/qmetaobjectbuilder_p.h> + +class tst_QMetaObjectBuilder : public QObject +{ + Q_OBJECT +public: + tst_QMetaObjectBuilder() {} + ~tst_QMetaObjectBuilder() {} + +private slots: + void mocVersionCheck(); + void create(); + void className(); + void superClass(); + void method(); + void slot(); + void signal(); + void constructor(); + void property(); + void notifySignal(); + void enumerator(); + void classInfo(); + void relatedMetaObject(); + void staticMetacall(); + void copyMetaObject(); + void serialize(); + +private: + static bool checkForSideEffects + (const QMetaObjectBuilder& builder, + QMetaObjectBuilder::AddMembers members); + static bool sameMetaObject + (const QMetaObject *meta1, const QMetaObject *meta2); +}; + +void tst_QMetaObjectBuilder::mocVersionCheck() +{ + // This test will fail when the moc version number is changed. + // It is intended as a reminder to also update QMetaObjectBuilder + // whenenver moc changes. Once QMetaObjectBuilder has been + // updated, this test can be changed to check for the next version. + QCOMPARE(int(QObject::staticMetaObject.d.data[0]), 4); + QCOMPARE(int(staticMetaObject.d.data[0]), 4); +} + +void tst_QMetaObjectBuilder::create() +{ + QMetaObjectBuilder builder; + QVERIFY(builder.className().isEmpty()); + QVERIFY(builder.superClass() == &QObject::staticMetaObject); + QCOMPARE(builder.methodCount(), 0); + QCOMPARE(builder.constructorCount(), 0); + QCOMPARE(builder.propertyCount(), 0); + QCOMPARE(builder.enumeratorCount(), 0); + QCOMPARE(builder.classInfoCount(), 0); + QCOMPARE(builder.relatedMetaObjectCount(), 0); + QVERIFY(builder.staticMetacallFunction() == 0); +} + +void tst_QMetaObjectBuilder::className() +{ + QMetaObjectBuilder builder; + + // Change the class name. + builder.setClassName("Foo"); + QCOMPARE(builder.className(), QByteArray("Foo")); + + // Change it again. + builder.setClassName("Bar"); + QCOMPARE(builder.className(), QByteArray("Bar")); + + // Clone the class name off a static QMetaObject. + builder.addMetaObject(&QObject::staticMetaObject, QMetaObjectBuilder::ClassName); + QCOMPARE(builder.className(), QByteArray("QObject")); + + // Check that nothing else changed. + QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::ClassName)); +} + +void tst_QMetaObjectBuilder::superClass() +{ + QMetaObjectBuilder builder; + + // Change the super class. + builder.setSuperClass(&QObject::staticMetaObject); + QVERIFY(builder.superClass() == &QObject::staticMetaObject); + + // Change it again. + builder.setSuperClass(&staticMetaObject); + QVERIFY(builder.superClass() == &staticMetaObject); + + // Clone the super class off a static QMetaObject. + builder.addMetaObject(&QObject::staticMetaObject, QMetaObjectBuilder::SuperClass); + QVERIFY(builder.superClass() == 0); + builder.addMetaObject(&staticMetaObject, QMetaObjectBuilder::SuperClass); + QVERIFY(builder.superClass() == staticMetaObject.superClass()); + + // Check that nothing else changed. + QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::SuperClass)); +} + +void tst_QMetaObjectBuilder::method() +{ + QMetaObjectBuilder builder; + + // Add a method and check its attributes. + QMetaMethodBuilder method1 = builder.addMethod("foo(const QString&, int)"); + QCOMPARE(method1.signature(), QByteArray("foo(QString,int)")); + QVERIFY(method1.methodType() == QMetaMethod::Method); + QVERIFY(method1.returnType().isEmpty()); + QVERIFY(method1.parameterNames().isEmpty()); + QVERIFY(method1.tag().isEmpty()); + QVERIFY(method1.access() == QMetaMethod::Public); + QCOMPARE(method1.attributes(), 0); + QCOMPARE(method1.index(), 0); + QCOMPARE(builder.methodCount(), 1); + + // Add another method and check again. + QMetaMethodBuilder method2 = builder.addMethod("bar(QString)"); + QCOMPARE(method2.signature(), QByteArray("bar(QString)")); + QVERIFY(method2.methodType() == QMetaMethod::Method); + QVERIFY(method2.returnType().isEmpty()); + QVERIFY(method2.parameterNames().isEmpty()); + QVERIFY(method2.tag().isEmpty()); + QVERIFY(method2.access() == QMetaMethod::Public); + QCOMPARE(method2.attributes(), 0); + QCOMPARE(method2.index(), 1); + QCOMPARE(builder.methodCount(), 2); + + // Perform index-based lookup. + QCOMPARE(builder.indexOfMethod("foo(const QString&, int)"), 0); + QCOMPARE(builder.indexOfMethod("bar(QString)"), 1); + QCOMPARE(builder.indexOfMethod("baz()"), -1); + + // Modify the attributes on method1. + method1.setReturnType("int"); + method1.setParameterNames(QList<QByteArray>() << "a" << "b"); + method1.setTag("tag"); + method1.setAccess(QMetaMethod::Private); + method1.setAttributes(42); + + // Check that method1 is changed, but method2 is not. + QCOMPARE(method1.signature(), QByteArray("foo(QString,int)")); + QVERIFY(method1.methodType() == QMetaMethod::Method); + QCOMPARE(method1.returnType(), QByteArray("int")); + QCOMPARE(method1.parameterNames(), QList<QByteArray>() << "a" << "b"); + QCOMPARE(method1.tag(), QByteArray("tag")); + QVERIFY(method1.access() == QMetaMethod::Private); + QCOMPARE(method1.attributes(), 42); + QCOMPARE(method1.index(), 0); + QCOMPARE(method2.signature(), QByteArray("bar(QString)")); + QVERIFY(method2.methodType() == QMetaMethod::Method); + QVERIFY(method2.returnType().isEmpty()); + QVERIFY(method2.parameterNames().isEmpty()); + QVERIFY(method2.tag().isEmpty()); + QVERIFY(method2.access() == QMetaMethod::Public); + QCOMPARE(method2.attributes(), 0); + QCOMPARE(method2.index(), 1); + QCOMPARE(builder.methodCount(), 2); + + // Modify the attributes on method2. + method2.setReturnType("QString"); + method2.setParameterNames(QList<QByteArray>() << "c"); + method2.setTag("Q_FOO"); + method2.setAccess(QMetaMethod::Protected); + method2.setAttributes(24); + + // This time check that only method2 changed. + QCOMPARE(method1.signature(), QByteArray("foo(QString,int)")); + QVERIFY(method1.methodType() == QMetaMethod::Method); + QCOMPARE(method1.returnType(), QByteArray("int")); + QCOMPARE(method1.parameterNames(), QList<QByteArray>() << "a" << "b"); + QCOMPARE(method1.tag(), QByteArray("tag")); + QVERIFY(method1.access() == QMetaMethod::Private); + QCOMPARE(method1.attributes(), 42); + QCOMPARE(method1.index(), 0); + QCOMPARE(method2.signature(), QByteArray("bar(QString)")); + QVERIFY(method2.methodType() == QMetaMethod::Method); + QCOMPARE(method2.returnType(), QByteArray("QString")); + QCOMPARE(method2.parameterNames(), QList<QByteArray>() << "c"); + QCOMPARE(method2.tag(), QByteArray("Q_FOO")); + QVERIFY(method2.access() == QMetaMethod::Protected); + QCOMPARE(method2.attributes(), 24); + QCOMPARE(method2.index(), 1); + QCOMPARE(builder.methodCount(), 2); + + // Remove method1 and check that method2 becomes index 0. + builder.removeMethod(0); + QCOMPARE(builder.methodCount(), 1); + method2 = builder.method(0); + QCOMPARE(method2.signature(), QByteArray("bar(QString)")); + QVERIFY(method2.methodType() == QMetaMethod::Method); + QCOMPARE(method2.returnType(), QByteArray("QString")); + QCOMPARE(method2.parameterNames(), QList<QByteArray>() << "c"); + QCOMPARE(method2.tag(), QByteArray("Q_FOO")); + QVERIFY(method2.access() == QMetaMethod::Protected); + QCOMPARE(method2.attributes(), 24); + QCOMPARE(method2.index(), 0); + + // Perform index-based lookup again. + QCOMPARE(builder.indexOfMethod("foo(const QString&, int)"), -1); + QCOMPARE(builder.indexOfMethod("bar(QString)"), 0); + QCOMPARE(builder.indexOfMethod("baz()"), -1); + + // Check that nothing else changed. + QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::Methods)); +} + +void tst_QMetaObjectBuilder::slot() +{ + QMetaObjectBuilder builder; + + // Add a slot and check its attributes. + QMetaMethodBuilder method1 = builder.addSlot("foo(const QString&, int)"); + QCOMPARE(method1.signature(), QByteArray("foo(QString,int)")); + QVERIFY(method1.methodType() == QMetaMethod::Slot); + QVERIFY(method1.returnType().isEmpty()); + QVERIFY(method1.parameterNames().isEmpty()); + QVERIFY(method1.tag().isEmpty()); + QVERIFY(method1.access() == QMetaMethod::Public); + QCOMPARE(method1.attributes(), 0); + QCOMPARE(method1.index(), 0); + QCOMPARE(builder.methodCount(), 1); + + // Add another slot and check again. + QMetaMethodBuilder method2 = builder.addSlot("bar(QString)"); + QCOMPARE(method2.signature(), QByteArray("bar(QString)")); + QVERIFY(method2.methodType() == QMetaMethod::Slot); + QVERIFY(method2.returnType().isEmpty()); + QVERIFY(method2.parameterNames().isEmpty()); + QVERIFY(method2.tag().isEmpty()); + QVERIFY(method2.access() == QMetaMethod::Public); + QCOMPARE(method2.attributes(), 0); + QCOMPARE(method2.index(), 1); + QCOMPARE(builder.methodCount(), 2); + + // Check that nothing else changed. + QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::Methods)); +} + +void tst_QMetaObjectBuilder::signal() +{ + QMetaObjectBuilder builder; + + // Add a signal and check its attributes. + QMetaMethodBuilder method1 = builder.addSignal("foo(const QString&, int)"); + QCOMPARE(method1.signature(), QByteArray("foo(QString,int)")); + QVERIFY(method1.methodType() == QMetaMethod::Signal); + QVERIFY(method1.returnType().isEmpty()); + QVERIFY(method1.parameterNames().isEmpty()); + QVERIFY(method1.tag().isEmpty()); + QVERIFY(method1.access() == QMetaMethod::Protected); + QCOMPARE(method1.attributes(), 0); + QCOMPARE(method1.index(), 0); + QCOMPARE(builder.methodCount(), 1); + + // Add another signal and check again. + QMetaMethodBuilder method2 = builder.addSignal("bar(QString)"); + QCOMPARE(method2.signature(), QByteArray("bar(QString)")); + QVERIFY(method2.methodType() == QMetaMethod::Signal); + QVERIFY(method2.returnType().isEmpty()); + QVERIFY(method2.parameterNames().isEmpty()); + QVERIFY(method2.tag().isEmpty()); + QVERIFY(method2.access() == QMetaMethod::Protected); + QCOMPARE(method2.attributes(), 0); + QCOMPARE(method2.index(), 1); + QCOMPARE(builder.methodCount(), 2); + + // Check that nothing else changed. + QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::Methods)); +} + +void tst_QMetaObjectBuilder::constructor() +{ + QMetaObjectBuilder builder; + + // Add a constructor and check its attributes. + QMetaMethodBuilder ctor1 = builder.addConstructor("foo(const QString&, int)"); + QCOMPARE(ctor1.signature(), QByteArray("foo(QString,int)")); + QVERIFY(ctor1.methodType() == QMetaMethod::Constructor); + QVERIFY(ctor1.returnType().isEmpty()); + QVERIFY(ctor1.parameterNames().isEmpty()); + QVERIFY(ctor1.tag().isEmpty()); + QVERIFY(ctor1.access() == QMetaMethod::Public); + QCOMPARE(ctor1.attributes(), 0); + QCOMPARE(ctor1.index(), 0); + QCOMPARE(builder.constructorCount(), 1); + + // Add another constructor and check again. + QMetaMethodBuilder ctor2 = builder.addConstructor("bar(QString)"); + QCOMPARE(ctor2.signature(), QByteArray("bar(QString)")); + QVERIFY(ctor2.methodType() == QMetaMethod::Constructor); + QVERIFY(ctor2.returnType().isEmpty()); + QVERIFY(ctor2.parameterNames().isEmpty()); + QVERIFY(ctor2.tag().isEmpty()); + QVERIFY(ctor2.access() == QMetaMethod::Public); + QCOMPARE(ctor2.attributes(), 0); + QCOMPARE(ctor2.index(), 1); + QCOMPARE(builder.constructorCount(), 2); + + // Perform index-based lookup. + QCOMPARE(builder.indexOfConstructor("foo(const QString&, int)"), 0); + QCOMPARE(builder.indexOfConstructor("bar(QString)"), 1); + QCOMPARE(builder.indexOfConstructor("baz()"), -1); + + // Modify the attributes on ctor1. + ctor1.setReturnType("int"); + ctor1.setParameterNames(QList<QByteArray>() << "a" << "b"); + ctor1.setTag("tag"); + ctor1.setAccess(QMetaMethod::Private); + ctor1.setAttributes(42); + + // Check that ctor1 is changed, but ctor2 is not. + QCOMPARE(ctor1.signature(), QByteArray("foo(QString,int)")); + QVERIFY(ctor1.methodType() == QMetaMethod::Constructor); + QCOMPARE(ctor1.returnType(), QByteArray("int")); + QCOMPARE(ctor1.parameterNames(), QList<QByteArray>() << "a" << "b"); + QCOMPARE(ctor1.tag(), QByteArray("tag")); + QVERIFY(ctor1.access() == QMetaMethod::Private); + QCOMPARE(ctor1.attributes(), 42); + QCOMPARE(ctor1.index(), 0); + QCOMPARE(ctor2.signature(), QByteArray("bar(QString)")); + QVERIFY(ctor2.methodType() == QMetaMethod::Constructor); + QVERIFY(ctor2.returnType().isEmpty()); + QVERIFY(ctor2.parameterNames().isEmpty()); + QVERIFY(ctor2.tag().isEmpty()); + QVERIFY(ctor2.access() == QMetaMethod::Public); + QCOMPARE(ctor2.attributes(), 0); + QCOMPARE(ctor2.index(), 1); + QCOMPARE(builder.constructorCount(), 2); + + // Modify the attributes on ctor2. + ctor2.setReturnType("QString"); + ctor2.setParameterNames(QList<QByteArray>() << "c"); + ctor2.setTag("Q_FOO"); + ctor2.setAccess(QMetaMethod::Protected); + ctor2.setAttributes(24); + + // This time check that only ctor2 changed. + QCOMPARE(ctor1.signature(), QByteArray("foo(QString,int)")); + QVERIFY(ctor1.methodType() == QMetaMethod::Constructor); + QCOMPARE(ctor1.returnType(), QByteArray("int")); + QCOMPARE(ctor1.parameterNames(), QList<QByteArray>() << "a" << "b"); + QCOMPARE(ctor1.tag(), QByteArray("tag")); + QVERIFY(ctor1.access() == QMetaMethod::Private); + QCOMPARE(ctor1.attributes(), 42); + QCOMPARE(ctor1.index(), 0); + QCOMPARE(ctor2.signature(), QByteArray("bar(QString)")); + QVERIFY(ctor2.methodType() == QMetaMethod::Constructor); + QCOMPARE(ctor2.returnType(), QByteArray("QString")); + QCOMPARE(ctor2.parameterNames(), QList<QByteArray>() << "c"); + QCOMPARE(ctor2.tag(), QByteArray("Q_FOO")); + QVERIFY(ctor2.access() == QMetaMethod::Protected); + QCOMPARE(ctor2.attributes(), 24); + QCOMPARE(ctor2.index(), 1); + QCOMPARE(builder.constructorCount(), 2); + + // Remove ctor1 and check that ctor2 becomes index 0. + builder.removeConstructor(0); + QCOMPARE(builder.constructorCount(), 1); + ctor2 = builder.constructor(0); + QCOMPARE(ctor2.signature(), QByteArray("bar(QString)")); + QVERIFY(ctor2.methodType() == QMetaMethod::Constructor); + QCOMPARE(ctor2.returnType(), QByteArray("QString")); + QCOMPARE(ctor2.parameterNames(), QList<QByteArray>() << "c"); + QCOMPARE(ctor2.tag(), QByteArray("Q_FOO")); + QVERIFY(ctor2.access() == QMetaMethod::Protected); + QCOMPARE(ctor2.attributes(), 24); + QCOMPARE(ctor2.index(), 0); + + // Perform index-based lookup again. + QCOMPARE(builder.indexOfConstructor("foo(const QString&, int)"), -1); + QCOMPARE(builder.indexOfConstructor("bar(QString)"), 0); + QCOMPARE(builder.indexOfConstructor("baz()"), -1); + + // Check that nothing else changed. + QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::Constructors)); +} + +void tst_QMetaObjectBuilder::property() +{ + QMetaObjectBuilder builder; + + // Add a property and check its attributes. + QMetaPropertyBuilder prop1 = builder.addProperty("foo", "const QString &"); + QCOMPARE(prop1.name(), QByteArray("foo")); + QCOMPARE(prop1.type(), QByteArray("QString")); + QVERIFY(!prop1.hasNotifySignal()); + QVERIFY(prop1.isReadable()); + QVERIFY(prop1.isWritable()); + QVERIFY(!prop1.isResettable()); + QVERIFY(!prop1.isDesignable()); + QVERIFY(!prop1.isScriptable()); + QVERIFY(!prop1.isStored()); + QVERIFY(!prop1.isEditable()); + QVERIFY(!prop1.isUser()); + QVERIFY(!prop1.hasStdCppSet()); + QVERIFY(!prop1.isEnumOrFlag()); + QCOMPARE(prop1.index(), 0); + QCOMPARE(builder.propertyCount(), 1); + + // Add another property and check again. + QMetaPropertyBuilder prop2 = builder.addProperty("bar", "int"); + QCOMPARE(prop2.name(), QByteArray("bar")); + QCOMPARE(prop2.type(), QByteArray("int")); + QVERIFY(!prop2.hasNotifySignal()); + QVERIFY(prop2.isReadable()); + QVERIFY(prop2.isWritable()); + QVERIFY(!prop2.isResettable()); + QVERIFY(!prop2.isDesignable()); + QVERIFY(!prop2.isScriptable()); + QVERIFY(!prop2.isStored()); + QVERIFY(!prop2.isEditable()); + QVERIFY(!prop2.isUser()); + QVERIFY(!prop2.hasStdCppSet()); + QVERIFY(!prop2.isEnumOrFlag()); + QCOMPARE(prop2.index(), 1); + QCOMPARE(builder.propertyCount(), 2); + + // Perform index-based lookup. + QCOMPARE(builder.indexOfProperty("foo"), 0); + QCOMPARE(builder.indexOfProperty("bar"), 1); + QCOMPARE(builder.indexOfProperty("baz"), -1); + + // Modify the attributes on prop1. + prop1.setReadable(false); + prop1.setWritable(false); + prop1.setResettable(true); + prop1.setDesignable(true); + prop1.setScriptable(true); + prop1.setStored(true); + prop1.setEditable(true); + prop1.setUser(true); + prop1.setStdCppSet(true); + prop1.setEnumOrFlag(true); + + // Check that prop1 is changed, but prop2 is not. + QCOMPARE(prop1.name(), QByteArray("foo")); + QCOMPARE(prop1.type(), QByteArray("QString")); + QVERIFY(!prop1.isReadable()); + QVERIFY(!prop1.isWritable()); + QVERIFY(prop1.isResettable()); + QVERIFY(prop1.isDesignable()); + QVERIFY(prop1.isScriptable()); + QVERIFY(prop1.isStored()); + QVERIFY(prop1.isEditable()); + QVERIFY(prop1.isUser()); + QVERIFY(prop1.hasStdCppSet()); + QVERIFY(prop1.isEnumOrFlag()); + QVERIFY(prop2.isReadable()); + QVERIFY(prop2.isWritable()); + QCOMPARE(prop2.name(), QByteArray("bar")); + QCOMPARE(prop2.type(), QByteArray("int")); + QVERIFY(!prop2.isResettable()); + QVERIFY(!prop2.isDesignable()); + QVERIFY(!prop2.isScriptable()); + QVERIFY(!prop2.isStored()); + QVERIFY(!prop2.isEditable()); + QVERIFY(!prop2.isUser()); + QVERIFY(!prop2.hasStdCppSet()); + QVERIFY(!prop2.isEnumOrFlag()); + + // Remove prop1 and check that prop2 becomes index 0. + builder.removeProperty(0); + QCOMPARE(builder.propertyCount(), 1); + prop2 = builder.property(0); + QCOMPARE(prop2.name(), QByteArray("bar")); + QCOMPARE(prop2.type(), QByteArray("int")); + QVERIFY(!prop2.isResettable()); + QVERIFY(!prop2.isDesignable()); + QVERIFY(!prop2.isScriptable()); + QVERIFY(!prop2.isStored()); + QVERIFY(!prop2.isEditable()); + QVERIFY(!prop2.isUser()); + QVERIFY(!prop2.hasStdCppSet()); + QVERIFY(!prop2.isEnumOrFlag()); + QCOMPARE(prop2.index(), 0); + + // Perform index-based lookup again. + QCOMPARE(builder.indexOfProperty("foo"), -1); + QCOMPARE(builder.indexOfProperty("bar"), 0); + QCOMPARE(builder.indexOfProperty("baz"), -1); + + // Check for side-effects between the flags on prop2. + // Setting a flag to true shouldn't set any of the others to true. + // This checks for cut-and-paste bugs in the implementation where + // the flag code was pasted but the flag name was not changed. +#define CLEAR_FLAGS() \ + do { \ + prop2.setReadable(false); \ + prop2.setWritable(false); \ + prop2.setResettable(false); \ + prop2.setDesignable(false); \ + prop2.setScriptable(false); \ + prop2.setStored(false); \ + prop2.setEditable(false); \ + prop2.setUser(false); \ + prop2.setStdCppSet(false); \ + prop2.setEnumOrFlag(false); \ + } while (0) +#define COUNT_FLAGS() \ + ((prop2.isReadable() ? 1 : 0) + \ + (prop2.isWritable() ? 1 : 0) + \ + (prop2.isResettable() ? 1 : 0) + \ + (prop2.isDesignable() ? 1 : 0) + \ + (prop2.isScriptable() ? 1 : 0) + \ + (prop2.isStored() ? 1 : 0) + \ + (prop2.isEditable() ? 1 : 0) + \ + (prop2.isUser() ? 1 : 0) + \ + (prop2.hasStdCppSet() ? 1 : 0) + \ + (prop2.isEnumOrFlag() ? 1 : 0)) +#define CHECK_FLAG(setFunc,isFunc) \ + do { \ + CLEAR_FLAGS(); \ + QCOMPARE(COUNT_FLAGS(), 0); \ + prop2.setFunc(true); \ + QVERIFY(prop2.isFunc()); \ + QCOMPARE(COUNT_FLAGS(), 1); \ + } while (0) + CHECK_FLAG(setReadable, isReadable); + CHECK_FLAG(setWritable, isWritable); + CHECK_FLAG(setResettable, isResettable); + CHECK_FLAG(setDesignable, isDesignable); + CHECK_FLAG(setScriptable, isScriptable); + CHECK_FLAG(setStored, isStored); + CHECK_FLAG(setEditable, isEditable); + CHECK_FLAG(setUser, isUser); + CHECK_FLAG(setStdCppSet, hasStdCppSet); + CHECK_FLAG(setEnumOrFlag, isEnumOrFlag); + + // Check that nothing else changed. + QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::Properties)); +} + +void tst_QMetaObjectBuilder::notifySignal() +{ + QMetaObjectBuilder builder; + + QMetaPropertyBuilder prop = builder.addProperty("foo", "const QString &"); + builder.addSlot("setFoo(QString)"); + QMetaMethodBuilder notify = builder.addSignal("fooChanged(QString)"); + + QVERIFY(!prop.hasNotifySignal()); + QCOMPARE(prop.notifySignal().index(), 0); + + prop.setNotifySignal(notify); + QVERIFY(prop.hasNotifySignal()); + QCOMPARE(prop.notifySignal().index(), 1); + + prop.setNotifySignal(QMetaMethodBuilder()); + QVERIFY(!prop.hasNotifySignal()); + QCOMPARE(prop.notifySignal().index(), 0); + + prop.setNotifySignal(notify); + prop.removeNotifySignal(); + QVERIFY(!prop.hasNotifySignal()); + QCOMPARE(prop.notifySignal().index(), 0); + + QCOMPARE(builder.methodCount(), 2); + QCOMPARE(builder.propertyCount(), 1); + + // Check that nothing else changed except methods and properties. + QVERIFY(checkForSideEffects + (builder, QMetaObjectBuilder::Methods | QMetaObjectBuilder::Properties)); +} + +void tst_QMetaObjectBuilder::enumerator() +{ + QMetaObjectBuilder builder; + + // Add an enumerator and check its attributes. + QMetaEnumBuilder enum1 = builder.addEnumerator("foo"); + QCOMPARE(enum1.name(), QByteArray("foo")); + QVERIFY(!enum1.isFlag()); + QCOMPARE(enum1.keyCount(), 0); + QCOMPARE(enum1.index(), 0); + QCOMPARE(builder.enumeratorCount(), 1); + + // Add another enumerator and check again. + QMetaEnumBuilder enum2 = builder.addEnumerator("bar"); + QCOMPARE(enum2.name(), QByteArray("bar")); + QVERIFY(!enum2.isFlag()); + QCOMPARE(enum2.keyCount(), 0); + QCOMPARE(enum2.index(), 1); + QCOMPARE(builder.enumeratorCount(), 2); + + // Perform index-based lookup. + QCOMPARE(builder.indexOfEnumerator("foo"), 0); + QCOMPARE(builder.indexOfEnumerator("bar"), 1); + QCOMPARE(builder.indexOfEnumerator("baz"), -1); + + // Modify the attributes on enum1. + enum1.setIsFlag(true); + QCOMPARE(enum1.addKey("ABC", 0), 0); + QCOMPARE(enum1.addKey("DEF", 1), 1); + QCOMPARE(enum1.addKey("GHI", -1), 2); + + // Check that enum1 is changed, but enum2 is not. + QCOMPARE(enum1.name(), QByteArray("foo")); + QVERIFY(enum1.isFlag()); + QCOMPARE(enum1.keyCount(), 3); + QCOMPARE(enum1.index(), 0); + QCOMPARE(enum1.key(0), QByteArray("ABC")); + QCOMPARE(enum1.key(1), QByteArray("DEF")); + QCOMPARE(enum1.key(2), QByteArray("GHI")); + QCOMPARE(enum1.value(0), 0); + QCOMPARE(enum1.value(1), 1); + QCOMPARE(enum1.value(2), -1); + QCOMPARE(enum2.name(), QByteArray("bar")); + QVERIFY(!enum2.isFlag()); + QCOMPARE(enum2.keyCount(), 0); + QCOMPARE(enum2.index(), 1); + + // Modify the attributes on enum2. + enum2.setIsFlag(true); + QCOMPARE(enum2.addKey("XYZ", 10), 0); + QCOMPARE(enum2.addKey("UVW", 19), 1); + + // This time check that only method2 changed. + QCOMPARE(enum1.name(), QByteArray("foo")); + QVERIFY(enum1.isFlag()); + QCOMPARE(enum1.keyCount(), 3); + QCOMPARE(enum1.index(), 0); + QCOMPARE(enum1.key(0), QByteArray("ABC")); + QCOMPARE(enum1.key(1), QByteArray("DEF")); + QCOMPARE(enum1.key(2), QByteArray("GHI")); + QCOMPARE(enum1.value(0), 0); + QCOMPARE(enum1.value(1), 1); + QCOMPARE(enum1.value(2), -1); + QCOMPARE(enum2.name(), QByteArray("bar")); + QVERIFY(enum2.isFlag()); + QCOMPARE(enum2.keyCount(), 2); + QCOMPARE(enum2.index(), 1); + QCOMPARE(enum2.key(0), QByteArray("XYZ")); + QCOMPARE(enum2.key(1), QByteArray("UVW")); + QCOMPARE(enum2.value(0), 10); + QCOMPARE(enum2.value(1), 19); + + // Remove enum1 and check that enum2 becomes index 0. + builder.removeEnumerator(0); + QCOMPARE(builder.enumeratorCount(), 1); + enum2 = builder.enumerator(0); + QCOMPARE(enum2.name(), QByteArray("bar")); + QVERIFY(enum2.isFlag()); + QCOMPARE(enum2.keyCount(), 2); + QCOMPARE(enum2.index(), 0); + QCOMPARE(enum2.key(0), QByteArray("XYZ")); + QCOMPARE(enum2.key(1), QByteArray("UVW")); + QCOMPARE(enum2.value(0), 10); + QCOMPARE(enum2.value(1), 19); + + // Perform index-based lookup again. + QCOMPARE(builder.indexOfEnumerator("foo"), -1); + QCOMPARE(builder.indexOfEnumerator("bar"), 0); + QCOMPARE(builder.indexOfEnumerator("baz"), -1); + + // Check that nothing else changed. + QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::Enumerators)); +} + +void tst_QMetaObjectBuilder::classInfo() +{ + QMetaObjectBuilder builder; + + // Add two items of class information and check their attributes. + QCOMPARE(builder.addClassInfo("foo", "value1"), 0); + QCOMPARE(builder.addClassInfo("bar", "value2"), 1); + QCOMPARE(builder.classInfoName(0), QByteArray("foo")); + QCOMPARE(builder.classInfoValue(0), QByteArray("value1")); + QCOMPARE(builder.classInfoName(1), QByteArray("bar")); + QCOMPARE(builder.classInfoValue(1), QByteArray("value2")); + QCOMPARE(builder.classInfoCount(), 2); + + // Perform index-based lookup. + QCOMPARE(builder.indexOfClassInfo("foo"), 0); + QCOMPARE(builder.indexOfClassInfo("bar"), 1); + QCOMPARE(builder.indexOfClassInfo("baz"), -1); + + // Remove the first one and check again. + builder.removeClassInfo(0); + QCOMPARE(builder.classInfoName(0), QByteArray("bar")); + QCOMPARE(builder.classInfoValue(0), QByteArray("value2")); + QCOMPARE(builder.classInfoCount(), 1); + + // Perform index-based lookup again. + QCOMPARE(builder.indexOfClassInfo("foo"), -1); + QCOMPARE(builder.indexOfClassInfo("bar"), 0); + QCOMPARE(builder.indexOfClassInfo("baz"), -1); + + // Check that nothing else changed. + QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::ClassInfos)); +} + +void tst_QMetaObjectBuilder::relatedMetaObject() +{ + QMetaObjectBuilder builder; + + // Add two related meta objects and check their attributes. + QCOMPARE(builder.addRelatedMetaObject(&QObject::staticMetaObject), 0); + QCOMPARE(builder.addRelatedMetaObject(&staticMetaObject), 1); + QVERIFY(builder.relatedMetaObject(0) == &QObject::staticMetaObject); + QVERIFY(builder.relatedMetaObject(1) == &staticMetaObject); + QCOMPARE(builder.relatedMetaObjectCount(), 2); + + // Remove the first one and check again. + builder.removeRelatedMetaObject(0); + QVERIFY(builder.relatedMetaObject(0) == &staticMetaObject); + QCOMPARE(builder.relatedMetaObjectCount(), 1); + + // Check that nothing else changed. + QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::RelatedMetaObjects)); +} + +static int smetacall(QMetaObject::Call, int, void **) +{ + return 0; +} + +void tst_QMetaObjectBuilder::staticMetacall() +{ + QMetaObjectBuilder builder; + QVERIFY(!builder.staticMetacallFunction()); + builder.setStaticMetacallFunction(smetacall); + QVERIFY(builder.staticMetacallFunction() == smetacall); + QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::StaticMetacall)); +} + +// Dummy class that has something of every type of thing moc can generate. +class SomethingOfEverything : public QObject +{ + Q_OBJECT + Q_CLASSINFO("ci_foo", "ABC") + Q_CLASSINFO("ci_bar", "DEF") + Q_PROPERTY(QString prop READ prop WRITE setProp NOTIFY propChanged) + Q_PROPERTY(QString prop2 READ prop WRITE setProp) + Q_PROPERTY(SomethingEnum eprop READ eprop) + Q_PROPERTY(SomethingFlagEnum fprop READ fprop) + Q_PROPERTY(QLocale::Language language READ language) + Q_ENUMS(SomethingEnum) + Q_FLAGS(SomethingFlagEnum) +public: + Q_INVOKABLE SomethingOfEverything() {} + ~SomethingOfEverything() {} + + enum SomethingEnum + { + GHI, + JKL = 10 + }; + + enum SomethingFlagEnum + { + XYZ = 1, + UVW = 8 + }; + + Q_INVOKABLE Q_SCRIPTABLE void method1() {} + + QString prop() const { return QString(); } + void setProp(const QString& v) { Q_UNUSED(v); } + + SomethingOfEverything::SomethingEnum eprop() const { return GHI; } + SomethingOfEverything::SomethingFlagEnum fprop() const { return XYZ; } + QLocale::Language language() const { return QLocale::English; } + +public slots: + void slot1(const QString&) {} + void slot2(int, const QString&) {} + +private slots: + void slot3() {} + +protected slots: + Q_SCRIPTABLE void slot4(int) {} + void slot5(int a, const QString& b) { Q_UNUSED(a); Q_UNUSED(b); } + +signals: + void sig1(); + void sig2(int x, const QString& y); + void propChanged(const QString&); +}; + +// Copy the entire contents of a static QMetaObject and then check +// that QMetaObjectBuilder will produce an exact copy as output. +void tst_QMetaObjectBuilder::copyMetaObject() +{ + QMetaObjectBuilder builder(&QObject::staticMetaObject); + QMetaObject *meta = builder.toMetaObject(); + QVERIFY(sameMetaObject(meta, &QObject::staticMetaObject)); + qFree(meta); + + QMetaObjectBuilder builder2(&staticMetaObject); + meta = builder2.toMetaObject(); + QVERIFY(sameMetaObject(meta, &staticMetaObject)); + qFree(meta); + + QMetaObjectBuilder builder3(&SomethingOfEverything::staticMetaObject); + meta = builder3.toMetaObject(); + QVERIFY(sameMetaObject(meta, &SomethingOfEverything::staticMetaObject)); + qFree(meta); +} + +// Serialize and deserialize a meta object and check that +// it round-trips to the exact same value. +void tst_QMetaObjectBuilder::serialize() +{ + QMetaObjectBuilder builder(&SomethingOfEverything::staticMetaObject); + QMetaObject *meta = builder.toMetaObject(); + + QByteArray data; + QDataStream stream(&data, QIODevice::WriteOnly | QIODevice::Append); + builder.serialize(stream); + + QMetaObjectBuilder builder2; + QDataStream stream2(data); + QMap<QByteArray, const QMetaObject *> references; + references.insert(QByteArray("QLocale"), &QLocale::staticMetaObject); + builder2.deserialize(stream2, references); + builder2.setStaticMetacallFunction(builder.staticMetacallFunction()); + QMetaObject *meta2 = builder2.toMetaObject(); + + QVERIFY(sameMetaObject(meta, meta2)); + qFree(meta); + qFree(meta2); +} + +// Check that the only changes to a "builder" relative to the default +// state is specified by "members". +bool tst_QMetaObjectBuilder::checkForSideEffects + (const QMetaObjectBuilder& builder, + QMetaObjectBuilder::AddMembers members) +{ + if ((members & QMetaObjectBuilder::ClassName) == 0) { + if (!builder.className().isEmpty()) + return false; + } + + if ((members & QMetaObjectBuilder::SuperClass) == 0) { + if (builder.superClass() != &QObject::staticMetaObject) + return false; + } + + if ((members & QMetaObjectBuilder::Methods) == 0) { + if (builder.methodCount() != 0) + return false; + } + + if ((members & QMetaObjectBuilder::Constructors) == 0) { + if (builder.constructorCount() != 0) + return false; + } + + if ((members & QMetaObjectBuilder::Properties) == 0) { + if (builder.propertyCount() != 0) + return false; + } + + if ((members & QMetaObjectBuilder::Enumerators) == 0) { + if (builder.enumeratorCount() != 0) + return false; + } + + if ((members & QMetaObjectBuilder::ClassInfos) == 0) { + if (builder.classInfoCount() != 0) + return false; + } + + if ((members & QMetaObjectBuilder::RelatedMetaObjects) == 0) { + if (builder.relatedMetaObjectCount() != 0) + return false; + } + + if ((members & QMetaObjectBuilder::StaticMetacall) == 0) { + if (builder.staticMetacallFunction() != 0) + return false; + } + + return true; +} + +static bool sameMethod(const QMetaMethod& method1, const QMetaMethod& method2) +{ + if (QByteArray(method1.signature()) != QByteArray(method2.signature())) + return false; + + if (QByteArray(method1.typeName()) != QByteArray(method2.typeName())) + return false; + + if (method1.parameterNames() != method2.parameterNames()) + return false; + + if (QByteArray(method1.tag()) != QByteArray(method2.tag())) + return false; + + if (method1.access() != method2.access()) + return false; + + if (method1.methodType() != method2.methodType()) + return false; + + if (method1.attributes() != method2.attributes()) + return false; + + return true; +} + +static bool sameProperty(const QMetaProperty& prop1, const QMetaProperty& prop2) +{ + if (QByteArray(prop1.name()) != QByteArray(prop2.name())) + return false; + + if (QByteArray(prop1.typeName()) != QByteArray(prop2.typeName())) + return false; + + if (prop1.isReadable() != prop2.isReadable() || + prop1.isWritable() != prop2.isWritable() || + prop1.isResettable() != prop2.isResettable() || + prop1.isDesignable() != prop2.isDesignable() || + prop1.isScriptable() != prop2.isScriptable() || + prop1.isStored() != prop2.isStored() || + prop1.isEditable() != prop2.isEditable() || + prop1.isUser() != prop2.isUser() || + prop1.isFlagType() != prop2.isFlagType() || + prop1.isEnumType() != prop2.isEnumType() || + prop1.hasNotifySignal() != prop2.hasNotifySignal() || + prop1.hasStdCppSet() != prop2.hasStdCppSet()) + return false; + + if (prop1.hasNotifySignal()) { + if (prop1.notifySignalIndex() != prop2.notifySignalIndex()) + return false; + } + + return true; +} + +static bool sameEnumerator(const QMetaEnum& enum1, const QMetaEnum& enum2) +{ + if (QByteArray(enum1.name()) != QByteArray(enum2.name())) + return false; + + if (enum1.isFlag() != enum2.isFlag()) + return false; + + if (enum1.keyCount() != enum2.keyCount()) + return false; + + for (int index = 0; index < enum1.keyCount(); ++index) { + if (QByteArray(enum1.key(index)) != QByteArray(enum2.key(index))) + return false; + if (enum1.value(index) != enum2.value(index)) + return false; + } + + if (QByteArray(enum1.scope()) != QByteArray(enum2.scope())) + return false; + + return true; +} + +// Determine if two meta objects are identical. +bool tst_QMetaObjectBuilder::sameMetaObject + (const QMetaObject *meta1, const QMetaObject *meta2) +{ + int index; + + if (strcmp(meta1->className(), meta2->className()) != 0) + return false; + + if (meta1->superClass() != meta2->superClass()) + return false; + + if (meta1->constructorCount() != meta2->constructorCount() || + meta1->methodCount() != meta2->methodCount() || + meta1->enumeratorCount() != meta2->enumeratorCount() || + meta1->propertyCount() != meta2->propertyCount() || + meta1->classInfoCount() != meta2->classInfoCount()) + return false; + + for (index = 0; index < meta1->constructorCount(); ++index) { + if (!sameMethod(meta1->constructor(index), meta2->constructor(index))) + return false; + } + + for (index = 0; index < meta1->methodCount(); ++index) { + if (!sameMethod(meta1->method(index), meta2->method(index))) + return false; + } + + for (index = 0; index < meta1->propertyCount(); ++index) { + if (!sameProperty(meta1->property(index), meta2->property(index))) + return false; + } + + for (index = 0; index < meta1->enumeratorCount(); ++index) { + if (!sameEnumerator(meta1->enumerator(index), meta2->enumerator(index))) + return false; + } + + for (index = 0; index < meta1->classInfoCount(); ++index) { + if (QByteArray(meta1->classInfo(index).name()) != + QByteArray(meta2->classInfo(index).name())) + return false; + if (QByteArray(meta1->classInfo(index).value()) != + QByteArray(meta2->classInfo(index).value())) + return false; + } + + const QMetaObject **objects1 = 0; + const QMetaObject **objects2 = 0; + if (meta1->d.data[0] == meta2->d.data[0] && meta1->d.data[0] >= 2) { + QMetaObjectExtraData *extra1 = (QMetaObjectExtraData *)(meta1->d.extradata); + QMetaObjectExtraData *extra2 = (QMetaObjectExtraData *)(meta2->d.extradata); + if (extra1 && !extra2) + return false; + if (extra2 && !extra1) + return false; + if (extra1 && extra2) { + if (extra1->static_metacall != extra2->static_metacall) + return false; + objects1 = extra1->objects; + objects2 = extra1->objects; + } + } else if (meta1->d.data[0] == meta2->d.data[0] && meta1->d.data[0] == 1) { + objects1 = (const QMetaObject **)(meta1->d.extradata); + objects2 = (const QMetaObject **)(meta2->d.extradata); + } + if (objects1 && !objects2) + return false; + if (objects2 && !objects1) + return false; + if (objects1 && objects2) { + while (*objects1 != 0 && *objects2 != 0) { + if (*objects1 != *objects2) + return false; + ++objects1; + ++objects2; + } + } + + return true; +} + +QTEST_MAIN(tst_QMetaObjectBuilder) + +#include "tst_qmetaobjectbuilder.moc" diff --git a/tests/auto/declarative/qmlcontext/tst_qmlcontext.cpp b/tests/auto/declarative/qmlcontext/tst_qmlcontext.cpp index 69d9091..3c60b2b 100644 --- a/tests/auto/declarative/qmlcontext/tst_qmlcontext.cpp +++ b/tests/auto/declarative/qmlcontext/tst_qmlcontext.cpp @@ -44,6 +44,7 @@ #include <QmlEngine> #include <QmlContext> #include <QmlComponent> +#include <QmlExpression> class tst_qmlcontext : public QObject { @@ -58,6 +59,7 @@ private slots: void parentContext(); void setContextProperty(); void addDefaultObject(); + void destruction(); private: QmlEngine engine; @@ -111,6 +113,14 @@ void tst_qmlcontext::resolvedUrl() QCOMPARE(ctxt2.resolvedUrl(QUrl("main2.qml")), QUrl()); } + + // Absolute + { + QmlContext ctxt(&engine); + + QCOMPARE(ctxt.resolvedUrl(QUrl("http://www.nokia.com/main2.qml")), QUrl("http://www.nokia.com/main2.qml")); + QCOMPARE(ctxt.resolvedUrl(QUrl("file:///main2.qml")), QUrl("file:///main2.qml")); + } } void tst_qmlcontext::engineMethod() @@ -256,10 +266,10 @@ void tst_qmlcontext::setContextProperty() // Static context properties ctxt.setContextProperty("a", QVariant(10)); ctxt.setContextProperty("b", QVariant(9)); + ctxt2.setContextProperty("d", &obj2); ctxt2.setContextProperty("b", QVariant(19)); ctxt2.setContextProperty("c", QVariant(QString("Hello World!"))); ctxt.setContextProperty("d", &obj1); - ctxt2.setContextProperty("d", &obj2); ctxt.setContextProperty("e", &obj1); TEST_CONTEXT_PROPERTY(&ctxt2, a, QVariant(10)); @@ -334,6 +344,26 @@ void tst_qmlcontext::setContextProperty() delete obj; } + + // Setting an object-variant context property + { + QmlComponent component(&engine); + component.setData("import Qt 4.6; Object { id: root; property int a: 10; property int test: ctxtProp.a; property var obj: root; }", QUrl()); + + QmlContext ctxt(engine.rootContext()); + ctxt.setContextProperty("ctxtProp", QVariant()); + + QTest::ignoreMessage(QtWarningMsg, "<Unknown File>:1: TypeError: Result of expression 'ctxtProp' [undefined] is not an object."); + QObject *obj = component.create(&ctxt); + + QVariant v = obj->property("obj"); + + ctxt.setContextProperty("ctxtProp", v); + + QCOMPARE(obj->property("test"), QVariant(10)); + + delete obj; + } } void tst_qmlcontext::addDefaultObject() @@ -382,6 +412,23 @@ void tst_qmlcontext::addDefaultObject() } } +void tst_qmlcontext::destruction() +{ + QmlContext *ctxt = new QmlContext(&engine); + + QObject obj; + QmlEngine::setContextForObject(&obj, ctxt); + QmlExpression expr(ctxt, "a", 0); + + QCOMPARE(ctxt, QmlEngine::contextForObject(&obj)); + QCOMPARE(ctxt, expr.context()); + + delete ctxt; ctxt = 0; + + QCOMPARE(ctxt, QmlEngine::contextForObject(&obj)); + QCOMPARE(ctxt, expr.context()); +} + QTEST_MAIN(tst_qmlcontext) #include "tst_qmlcontext.moc" diff --git a/tests/auto/declarative/visual/selftest_noimages/data/selftest_noimages.qml b/tests/auto/declarative/visual/selftest_noimages/data/selftest_noimages.qml new file mode 100644 index 0000000..3104906 --- /dev/null +++ b/tests/auto/declarative/visual/selftest_noimages/data/selftest_noimages.qml @@ -0,0 +1,470 @@ +import Qt.VisualTest 4.6 + +VisualTest { + Frame { + msec: 0 + } + Frame { + msec: 16 + } + Frame { + msec: 32 + } + Frame { + msec: 48 + } + Frame { + msec: 64 + } + Frame { + msec: 80 + } + Frame { + msec: 96 + } + Frame { + msec: 112 + } + Frame { + msec: 128 + } + Frame { + msec: 144 + } + Frame { + msec: 160 + } + Frame { + msec: 176 + } + Frame { + msec: 192 + } + Frame { + msec: 208 + } + Frame { + msec: 224 + } + Frame { + msec: 240 + } + Frame { + msec: 256 + } + Frame { + msec: 272 + } + Frame { + msec: 288 + } + Frame { + msec: 304 + } + Frame { + msec: 320 + } + Frame { + msec: 336 + } + Frame { + msec: 352 + } + Frame { + msec: 368 + } + Frame { + msec: 384 + } + Frame { + msec: 400 + } + Frame { + msec: 416 + } + Frame { + msec: 432 + } + Frame { + msec: 448 + } + Frame { + msec: 464 + } + Frame { + msec: 480 + } + Frame { + msec: 496 + } + Frame { + msec: 512 + } + Frame { + msec: 528 + } + Frame { + msec: 544 + } + Frame { + msec: 560 + } + Frame { + msec: 576 + } + Frame { + msec: 592 + } + Frame { + msec: 608 + } + Frame { + msec: 624 + } + Frame { + msec: 640 + } + Frame { + msec: 656 + } + Frame { + msec: 672 + } + Frame { + msec: 688 + } + Frame { + msec: 704 + } + Frame { + msec: 720 + } + Frame { + msec: 736 + } + Frame { + msec: 752 + } + Frame { + msec: 768 + } + Frame { + msec: 784 + } + Frame { + msec: 800 + } + Frame { + msec: 816 + } + Frame { + msec: 832 + } + Frame { + msec: 848 + } + Frame { + msec: 864 + } + Frame { + msec: 880 + } + Frame { + msec: 896 + } + Frame { + msec: 912 + } + Frame { + msec: 928 + } + Frame { + msec: 944 + } + Frame { + msec: 960 + } + Frame { + msec: 976 + } + Frame { + msec: 992 + } + Frame { + msec: 1008 + } + Frame { + msec: 1024 + } + Frame { + msec: 1040 + } + Frame { + msec: 1056 + } + Frame { + msec: 1072 + } + Frame { + msec: 1088 + } + Frame { + msec: 1104 + } + Frame { + msec: 1120 + } + Frame { + msec: 1136 + } + Frame { + msec: 1152 + } + Frame { + msec: 1168 + } + Frame { + msec: 1184 + } + Frame { + msec: 1200 + } + Frame { + msec: 1216 + } + Frame { + msec: 1232 + } + Frame { + msec: 1248 + } + Frame { + msec: 1264 + } + Frame { + msec: 1280 + } + Frame { + msec: 1296 + } + Frame { + msec: 1312 + } + Frame { + msec: 1328 + } + Frame { + msec: 1344 + } + Frame { + msec: 1360 + } + Mouse { + type: 2 + button: 1 + buttons: 1 + x: 77; y: 7 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 1376 + } + Frame { + msec: 1392 + } + Frame { + msec: 1408 + } + Frame { + msec: 1424 + } + Frame { + msec: 1440 + } + Mouse { + type: 3 + button: 1 + buttons: 0 + x: 77; y: 7 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 1456 + } + Frame { + msec: 1472 + } + Frame { + msec: 1488 + } + Frame { + msec: 1504 + } + Frame { + msec: 1520 + } + Frame { + msec: 1536 + } + Frame { + msec: 1552 + } + Frame { + msec: 1568 + } + Frame { + msec: 1584 + } + Frame { + msec: 1600 + } + Frame { + msec: 1616 + } + Frame { + msec: 1632 + } + Frame { + msec: 1648 + } + Frame { + msec: 1664 + } + Frame { + msec: 1680 + } + Frame { + msec: 1696 + } + Frame { + msec: 1712 + } + Frame { + msec: 1728 + } + Frame { + msec: 1744 + } + Frame { + msec: 1760 + } + Frame { + msec: 1776 + } + Frame { + msec: 1792 + } + Frame { + msec: 1808 + } + Frame { + msec: 1824 + } + Frame { + msec: 1840 + } + Frame { + msec: 1856 + } + Frame { + msec: 1872 + } + Frame { + msec: 1888 + } + Frame { + msec: 1904 + } + Frame { + msec: 1920 + } + Frame { + msec: 1936 + } + Frame { + msec: 1952 + } + Frame { + msec: 1968 + } + Frame { + msec: 1984 + } + Frame { + msec: 2000 + } + Frame { + msec: 2016 + } + Frame { + msec: 2032 + } + Frame { + msec: 2048 + } + Frame { + msec: 2064 + } + Frame { + msec: 2080 + } + Frame { + msec: 2096 + } + Frame { + msec: 2112 + } + Frame { + msec: 2128 + } + Frame { + msec: 2144 + } + Frame { + msec: 2160 + } + Frame { + msec: 2176 + } + Frame { + msec: 2192 + } + Frame { + msec: 2208 + } + Frame { + msec: 2224 + } + Frame { + msec: 2240 + } + Frame { + msec: 2256 + } + Frame { + msec: 2272 + } + Frame { + msec: 2288 + } + Frame { + msec: 2304 + } + Frame { + msec: 2320 + } + Frame { + msec: 2336 + } + Frame { + msec: 2352 + } + Frame { + msec: 2368 + } + Frame { + msec: 2384 + } +} diff --git a/tests/auto/declarative/visual/selftest_noimages/selftest_noimages.qml b/tests/auto/declarative/visual/selftest_noimages/selftest_noimages.qml new file mode 100644 index 0000000..21a19bc --- /dev/null +++ b/tests/auto/declarative/visual/selftest_noimages/selftest_noimages.qml @@ -0,0 +1,9 @@ +import Qt 4.6 +Text { + property string error: "not pressed" + text: (new Date()).valueOf() + MouseRegion { + anchors.fill: parent + onPressed: error="" + } +} diff --git a/tests/auto/declarative/visual/tst_visual.cpp b/tests/auto/declarative/visual/tst_visual.cpp index a79b6f9..0cd712b 100644 --- a/tests/auto/declarative/visual/tst_visual.cpp +++ b/tests/auto/declarative/visual/tst_visual.cpp @@ -47,7 +47,7 @@ #include <QProcess> #include <QFile> -enum Mode { Record, Play, TestVisuals, UpdateVisuals, UpdatePlatformVisuals, Test }; +enum Mode { Record, RecordNoVisuals, Play, TestVisuals, RemoveVisuals, UpdateVisuals, UpdatePlatformVisuals, Test }; static QString testdir; class tst_visual : public QObject @@ -115,7 +115,7 @@ void tst_visual::visual() QStringList arguments; arguments << "-script" << testdata - << "-scriptopts" << "play,testimages,exitoncomplete,exitonfailure" + << "-scriptopts" << "play,testimages,testerror,exitoncomplete,exitonfailure" << file; QProcess p; p.start(qmlviewer, arguments); @@ -208,38 +208,44 @@ void action(Mode mode, const QString &file) QString testdata = tst_visual::toTestScript(file,mode); - if (Record == mode) { - QStringList arguments; - arguments << "-script" << testdata + QStringList arguments; + switch (mode) { + case Test: + // Don't run qmlviewer + break; + case Record: + arguments << "-script" << testdata + << "-scriptopts" << "record,testimages,saveonexit" + << file; + break; + case RecordNoVisuals: + arguments << "-script" << testdata << "-scriptopts" << "record,saveonexit" << file; - QProcess p; - p.setProcessChannelMode(QProcess::ForwardedChannels); - p.start(tst_visual::viewer(), arguments); - p.waitForFinished(); - } else if (Play == mode) { - QStringList arguments; - arguments << "-script" << testdata - << "-scriptopts" << "play,testimages,exitoncomplete" + break; + case Play: + arguments << "-script" << testdata + << "-scriptopts" << "play,testimages,testerror,exitoncomplete" << file; - QProcess p; - p.setProcessChannelMode(QProcess::ForwardedChannels); - p.start(tst_visual::viewer(), arguments); - p.waitForFinished(); - } else if (TestVisuals == mode) { - QStringList arguments; + break; + case TestVisuals: arguments << "-script" << testdata << "-scriptopts" << "play" << file; - QProcess p; - p.setProcessChannelMode(QProcess::ForwardedChannels); - p.start(tst_visual::viewer(), arguments); - p.waitForFinished(); - } else if (UpdateVisuals == mode || UpdatePlatformVisuals == mode) { - QStringList arguments; - arguments << "-script" << testdata + break; + case UpdateVisuals: + case UpdatePlatformVisuals: + arguments << "-script" << testdata + << "-scriptopts" << "play,record,testimages,exitoncomplete,saveonexit" + << file; + break; + case RemoveVisuals: + arguments << "-script" << testdata << "-scriptopts" << "play,record,exitoncomplete,saveonexit" << file; + break; + } + if (!arguments.isEmpty()) { QProcess p; p.setProcessChannelMode(QProcess::ForwardedChannels); p.start(tst_visual::viewer(), arguments); @@ -278,9 +284,15 @@ int main(int argc, char **argv) } else if (arg == "-record" && (ii + 1) < argc) { mode = Record; file = argv[++ii]; + } else if (arg == "-recordnovisuals" && (ii + 1) < argc) { + mode = RecordNoVisuals; + file = argv[++ii]; } else if (arg == "-testvisuals" && (ii + 1) < argc) { mode = TestVisuals; file = argv[++ii]; + } else if (arg == "-removevisuals" && (ii + 1) < argc) { + mode = RemoveVisuals; + file = argv[++ii]; } else if (arg == "-updatevisuals" && (ii + 1) < argc) { mode = UpdateVisuals; file = argv[++ii]; |