diff options
author | Martin Jones <martin.jones@nokia.com> | 2010-01-29 01:53:32 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2010-01-29 01:53:32 (GMT) |
commit | 91a0da8d3674d832fde87c9c1bc5a4bdb959ac3d (patch) | |
tree | ef09bd890041b3c44f7be3322321c96174e94054 /tests | |
parent | 687d50f05a1a2d9355f0990e845967930c57b985 (diff) | |
parent | fe129a59ab54e6c0194c546a02bc64e886c252d5 (diff) | |
download | Qt-91a0da8d3674d832fde87c9c1bc5a4bdb959ac3d.zip Qt-91a0da8d3674d832fde87c9c1bc5a4bdb959ac3d.tar.gz Qt-91a0da8d3674d832fde87c9c1bc5a4bdb959ac3d.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'tests')
26 files changed, 761 insertions, 1070 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 9b91c7d..3198a65 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -569,3 +569,21 @@ contains(QT_CONFIG, webkit): SUBDIRS += \ qwebhistory contains(QT_CONFIG, declarative): SUBDIRS += declarative + +# Following tests depends on private API +!contains(QT_CONFIG, private_tests): SUBDIRS -= \ + qcssparser \ + qgraphicssceneindex \ + qhttpnetworkconnection \ + qhttpnetworkreply \ + qnativesocketengine \ + qnetworkreply \ + qpathclipper \ + qsocketnotifier \ + qsocks5socketengine \ + qstylesheetstyle \ + qtextpiecetable \ + xmlpatternsdiagnosticsts \ + xmlpatternsview \ + xmlpatternsxqts \ + xmlpatternsxslts diff --git a/tests/auto/declarative/qmlecmascript/data/assignBasicTypes.2.qml b/tests/auto/declarative/qmlecmascript/data/assignBasicTypes.2.qml new file mode 100644 index 0000000..db7f2b5 --- /dev/null +++ b/tests/auto/declarative/qmlecmascript/data/assignBasicTypes.2.qml @@ -0,0 +1,26 @@ +import Qt.test 1.0 + +MyTypeObject { + flagProperty: if(1) "FlagVal1 | FlagVal3" + enumProperty: if(1) "EnumVal2" + stringProperty: if(1) "Hello World!" + uintProperty: if(1) 10 + intProperty: if(1) -19 + realProperty: if(1) 23.2 + doubleProperty: if(1) -19.7 + floatProperty: if(1) 8.5 + colorProperty: if(1) "red" + dateProperty: if(1) "1982-11-25" + timeProperty: if(1) "11:11:32" + dateTimeProperty: if(1) "2009-05-12T13:22:01" + pointProperty: if(1) "99,13" + pointFProperty: if(1) "-10.1,12.3" + sizeProperty: if(1) "99x13" + sizeFProperty: if(1) "0.1x0.2" + rectProperty: if(1) "9,7,100x200" + rectFProperty: if(1) "1000.1,-10.9,400x90.99" + boolProperty: if(1) true + variantProperty: if(1) "Hello World!" + vectorProperty: if(1) "10,1,2.2" + urlProperty: if(1) "main.qml" +} diff --git a/tests/auto/declarative/qmlecmascript/data/undefinedResetsProperty.qml b/tests/auto/declarative/qmlecmascript/data/undefinedResetsProperty.qml new file mode 100644 index 0000000..eceff60 --- /dev/null +++ b/tests/auto/declarative/qmlecmascript/data/undefinedResetsProperty.qml @@ -0,0 +1,7 @@ +import Qt.test 1.0 + +MyQmlObject { + property bool setUndefined: false + + resettableProperty: setUndefined?undefined:92 +} diff --git a/tests/auto/declarative/qmlecmascript/testtypes.h b/tests/auto/declarative/qmlecmascript/testtypes.h index fff9246..09c850d 100644 --- a/tests/auto/declarative/qmlecmascript/testtypes.h +++ b/tests/auto/declarative/qmlecmascript/testtypes.h @@ -48,7 +48,13 @@ #include <QtCore/qsize.h> #include <QtDeclarative/qmllist.h> #include <QtCore/qrect.h> +#include <QtGui/qmatrix.h> +#include <QtGui/qcolor.h> +#include <QtGui/qvector3d.h> +#include <QtCore/qdatetime.h> #include <QtScript/qscriptvalue.h> +#include <QtDeclarative/qmlscriptstring.h> +#include <QtDeclarative/qmlcomponent.h> class MyQmlAttachedObject : public QObject { @@ -73,9 +79,10 @@ class MyQmlObject : public QObject Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty NOTIFY objectChanged) Q_PROPERTY(QmlList<QObject *> *objectQmlListProperty READ objectQmlListProperty CONSTANT) Q_PROPERTY(QList<QObject *> *objectListProperty READ objectListProperty CONSTANT) + Q_PROPERTY(int resettableProperty READ resettableProperty WRITE setResettableProperty RESET resetProperty) public: - MyQmlObject(): m_methodCalled(false), m_methodIntCalled(false), m_object(0), m_value(0) {} + MyQmlObject(): m_methodCalled(false), m_methodIntCalled(false), m_object(0), m_value(0), m_resetProperty(13) {} enum MyEnum { EnumValue1 = 0, EnumValue2 = 1 }; enum MyEnum2 { EnumValue3 = 2, EnumValue4 = 3 }; @@ -117,6 +124,11 @@ public: int value() const { return m_value; } void setValue(int v) { m_value = v; } + + int resettableProperty() const { return m_resetProperty; } + void setResettableProperty(int v) { m_resetProperty = v; } + void resetProperty() { m_resetProperty = 13; } + signals: void basicSignal(); void argumentSignal(int a, QString b, qreal c); @@ -141,6 +153,7 @@ private: QmlConcreteList<QObject *> m_objectQmlList; QList<QObject *> m_objectQList; int m_value; + int m_resetProperty; }; QML_DECLARE_TYPEINFO(MyQmlObject, QML_HAS_ATTACHED_PROPERTIES) @@ -149,7 +162,7 @@ QML_DECLARE_TYPE(MyQmlObject); class MyQmlContainer : public QObject { Q_OBJECT - Q_PROPERTY(QList<MyQmlObject*>* children READ children) + Q_PROPERTY(QList<MyQmlObject*>* children READ children CONSTANT) public: MyQmlContainer() {} @@ -271,15 +284,164 @@ QML_DECLARE_TYPE(MyExtendedObject); class MyTypeObject : public QObject { Q_OBJECT + Q_ENUMS(MyEnum) + Q_FLAGS(MyFlags) + + Q_PROPERTY(QString id READ id WRITE setId); + Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty); + Q_PROPERTY(QmlComponent *componentProperty READ componentProperty WRITE setComponentProperty); + Q_PROPERTY(MyFlags flagProperty READ flagProperty WRITE setFlagProperty); + Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty); + Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty); + Q_PROPERTY(uint uintProperty READ uintProperty WRITE setUintProperty); + Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty); + Q_PROPERTY(qreal realProperty READ realProperty WRITE setRealProperty); + Q_PROPERTY(double doubleProperty READ doubleProperty WRITE setDoubleProperty); + Q_PROPERTY(float floatProperty READ floatProperty WRITE setFloatProperty); + Q_PROPERTY(QColor colorProperty READ colorProperty WRITE setColorProperty); + Q_PROPERTY(QDate dateProperty READ dateProperty WRITE setDateProperty); + Q_PROPERTY(QTime timeProperty READ timeProperty WRITE setTimeProperty); + Q_PROPERTY(QDateTime dateTimeProperty READ dateTimeProperty WRITE setDateTimeProperty); Q_PROPERTY(QPoint pointProperty READ pointProperty WRITE setPointProperty); Q_PROPERTY(QPointF pointFProperty READ pointFProperty WRITE setPointFProperty); Q_PROPERTY(QSize sizeProperty READ sizeProperty WRITE setSizeProperty); Q_PROPERTY(QSizeF sizeFProperty READ sizeFProperty WRITE setSizeFProperty); Q_PROPERTY(QRect rectProperty READ rectProperty WRITE setRectProperty NOTIFY rectPropertyChanged); + Q_PROPERTY(QRect rectProperty2 READ rectProperty2 WRITE setRectProperty2); Q_PROPERTY(QRectF rectFProperty READ rectFProperty WRITE setRectFProperty); - + Q_PROPERTY(bool boolProperty READ boolProperty WRITE setBoolProperty); + Q_PROPERTY(QVariant variantProperty READ variantProperty WRITE setVariantProperty); + Q_PROPERTY(QVector3D vectorProperty READ vectorProperty WRITE setVectorProperty); + Q_PROPERTY(QUrl urlProperty READ urlProperty WRITE setUrlProperty); + + Q_PROPERTY(QmlScriptString scriptProperty READ scriptProperty WRITE setScriptProperty); + public: - MyTypeObject() {} + MyTypeObject() + : objectPropertyValue(0), componentPropertyValue(0) {} + + QString idValue; + QString id() const { + return idValue; + } + void setId(const QString &v) { + idValue = v; + } + + QObject *objectPropertyValue; + QObject *objectProperty() const { + return objectPropertyValue; + } + void setObjectProperty(QObject *v) { + objectPropertyValue = v; + } + + QmlComponent *componentPropertyValue; + QmlComponent *componentProperty() const { + return componentPropertyValue; + } + void setComponentProperty(QmlComponent *v) { + componentPropertyValue = v; + } + + enum MyFlag { FlagVal1 = 0x01, FlagVal2 = 0x02, FlagVal3 = 0x04 }; + Q_DECLARE_FLAGS(MyFlags, MyFlag) + MyFlags flagPropertyValue; + MyFlags flagProperty() const { + return flagPropertyValue; + } + void setFlagProperty(MyFlags v) { + flagPropertyValue = v; + } + + enum MyEnum { EnumVal1, EnumVal2 }; + MyEnum enumPropertyValue; + MyEnum enumProperty() const { + return enumPropertyValue; + } + void setEnumProperty(MyEnum v) { + enumPropertyValue = v; + } + + QString stringPropertyValue; + QString stringProperty() const { + return stringPropertyValue; + } + void setStringProperty(const QString &v) { + stringPropertyValue = v; + } + + uint uintPropertyValue; + uint uintProperty() const { + return uintPropertyValue; + } + void setUintProperty(const uint &v) { + uintPropertyValue = v; + } + + int intPropertyValue; + int intProperty() const { + return intPropertyValue; + } + void setIntProperty(const int &v) { + intPropertyValue = v; + } + + qreal realPropertyValue; + qreal realProperty() const { + return realPropertyValue; + } + void setRealProperty(const qreal &v) { + realPropertyValue = v; + } + + double doublePropertyValue; + double doubleProperty() const { + return doublePropertyValue; + } + void setDoubleProperty(const double &v) { + doublePropertyValue = v; + } + + float floatPropertyValue; + float floatProperty() const { + return floatPropertyValue; + } + void setFloatProperty(const float &v) { + floatPropertyValue = v; + } + + QColor colorPropertyValue; + QColor colorProperty() const { + return colorPropertyValue; + } + void setColorProperty(const QColor &v) { + colorPropertyValue = v; + } + + QDate datePropertyValue; + QDate dateProperty() const { + return datePropertyValue; + } + void setDateProperty(const QDate &v) { + datePropertyValue = v; + } + + QTime timePropertyValue; + QTime timeProperty() const { + return timePropertyValue; + } + void setTimeProperty(const QTime &v) { + timePropertyValue = v; + } + + QDateTime dateTimePropertyValue; + QDateTime dateTimeProperty() const { + return dateTimePropertyValue; + } + void setDateTimeProperty(const QDateTime &v) { + dateTimePropertyValue = v; + } QPoint pointPropertyValue; QPoint pointProperty() const { @@ -319,6 +481,15 @@ public: } void setRectProperty(const QRect &v) { rectPropertyValue = v; + emit rectPropertyChanged(); + } + + QRect rectPropertyValue2; + QRect rectProperty2() const { + return rectPropertyValue2; + } + void setRectProperty2(const QRect &v) { + rectPropertyValue2 = v; } QRectF rectFPropertyValue; @@ -329,7 +500,52 @@ public: rectFPropertyValue = v; } + bool boolPropertyValue; + bool boolProperty() const { + return boolPropertyValue; + } + void setBoolProperty(const bool &v) { + boolPropertyValue = v; + } + + QVariant variantPropertyValue; + QVariant variantProperty() const { + return variantPropertyValue; + } + void setVariantProperty(const QVariant &v) { + variantPropertyValue = v; + } + + QVector3D vectorPropertyValue; + QVector3D vectorProperty() const { + return vectorPropertyValue; + } + void setVectorProperty(const QVector3D &v) { + vectorPropertyValue = v; + } + + QUrl urlPropertyValue; + QUrl urlProperty() const { + return urlPropertyValue; + } + void setUrlProperty(const QUrl &v) { + urlPropertyValue = v; + } + + QmlScriptString scriptPropertyValue; + QmlScriptString scriptProperty() const { + return scriptPropertyValue; + } + void setScriptProperty(const QmlScriptString &v) { + scriptPropertyValue = v; + } + + void doAction() { emit action(); } +signals: + void action(); + void rectPropertyChanged(); }; +Q_DECLARE_OPERATORS_FOR_FLAGS(MyTypeObject::MyFlags) QML_DECLARE_TYPE(MyTypeObject); Q_DECLARE_METATYPE(QScriptValue); diff --git a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp index 4c9721a..c41e248 100644 --- a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp +++ b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp @@ -76,6 +76,7 @@ public: tst_qmlecmascript() {} private slots: + void assignBasicTypes(); void idShortcutInvalidates(); void boolPropertiesEvaluateAsBool(); void methods(); @@ -116,6 +117,8 @@ private slots: void externalScript(); void compositePropertyType(); void jsObject(); + void undefinedResetsProperty(); + void listToVariant(); void bug1(); @@ -124,6 +127,66 @@ private: QmlEngine engine; }; +void tst_qmlecmascript::assignBasicTypes() +{ + { + QmlComponent component(&engine, TEST_FILE("assignBasicTypes.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->flagProperty(), MyTypeObject::FlagVal1 | MyTypeObject::FlagVal3); + QCOMPARE(object->enumProperty(), MyTypeObject::EnumVal2); + QCOMPARE(object->stringProperty(), QString("Hello World!")); + QCOMPARE(object->uintProperty(), uint(10)); + QCOMPARE(object->intProperty(), -19); + QCOMPARE((float)object->realProperty(), float(23.2)); + QCOMPARE((float)object->doubleProperty(), float(-19.7)); + QCOMPARE((float)object->floatProperty(), float(8.5)); + QCOMPARE(object->colorProperty(), QColor("red")); + QCOMPARE(object->dateProperty(), QDate(1982, 11, 25)); + QCOMPARE(object->timeProperty(), QTime(11, 11, 32)); + QCOMPARE(object->dateTimeProperty(), QDateTime(QDate(2009, 5, 12), QTime(13, 22, 1))); + QCOMPARE(object->pointProperty(), QPoint(99,13)); + QCOMPARE(object->pointFProperty(), QPointF(-10.1, 12.3)); + QCOMPARE(object->sizeProperty(), QSize(99, 13)); + QCOMPARE(object->sizeFProperty(), QSizeF(0.1, 0.2)); + QCOMPARE(object->rectProperty(), QRect(9, 7, 100, 200)); + QCOMPARE(object->rectFProperty(), QRectF(1000.1, -10.9, 400, 90.99)); + QCOMPARE(object->boolProperty(), true); + QCOMPARE(object->variantProperty(), QVariant("Hello World!")); + QCOMPARE(object->vectorProperty(), QVector3D(10, 1, 2.2)); + QCOMPARE(object->urlProperty(), component.url().resolved(QUrl("main.qml"))); + delete object; + } + { + QmlComponent component(&engine, TEST_FILE("assignBasicTypes.2.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->flagProperty(), MyTypeObject::FlagVal1 | MyTypeObject::FlagVal3); + QCOMPARE(object->enumProperty(), MyTypeObject::EnumVal2); + QCOMPARE(object->stringProperty(), QString("Hello World!")); + QCOMPARE(object->uintProperty(), uint(10)); + QCOMPARE(object->intProperty(), -19); + QCOMPARE((float)object->realProperty(), float(23.2)); + QCOMPARE((float)object->doubleProperty(), float(-19.7)); + QCOMPARE((float)object->floatProperty(), float(8.5)); + QCOMPARE(object->colorProperty(), QColor("red")); + QCOMPARE(object->dateProperty(), QDate(1982, 11, 25)); + QCOMPARE(object->timeProperty(), QTime(11, 11, 32)); + QCOMPARE(object->dateTimeProperty(), QDateTime(QDate(2009, 5, 12), QTime(13, 22, 1))); + QCOMPARE(object->pointProperty(), QPoint(99,13)); + QCOMPARE(object->pointFProperty(), QPointF(-10.1, 12.3)); + QCOMPARE(object->sizeProperty(), QSize(99, 13)); + QCOMPARE(object->sizeFProperty(), QSizeF(0.1, 0.2)); + QCOMPARE(object->rectProperty(), QRect(9, 7, 100, 200)); + QCOMPARE(object->rectFProperty(), QRectF(1000.1, -10.9, 400, 90.99)); + QCOMPARE(object->boolProperty(), true); + QCOMPARE(object->variantProperty(), QVariant("Hello World!")); + QCOMPARE(object->vectorProperty(), QVector3D(10, 1, 2.2)); + QCOMPARE(object->urlProperty(), component.url().resolved(QUrl("main.qml"))); + delete object; + } +} + void tst_qmlecmascript::idShortcutInvalidates() { { @@ -1075,6 +1138,40 @@ void tst_qmlecmascript::jsObject() delete object; } +void tst_qmlecmascript::undefinedResetsProperty() +{ + { + QmlComponent component(&engine, TEST_FILE("undefinedResetsProperty.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("resettableProperty").toInt(), 92); + + object->setProperty("setUndefined", true); + + QCOMPARE(object->property("resettableProperty").toInt(), 13); + + object->setProperty("setUndefined", false); + + QCOMPARE(object->property("resettableProperty").toInt(), 92); + + delete object; + } + { + QmlComponent component(&engine, TEST_FILE("undefinedResetsProperty.2.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("resettableProperty").toInt(), 19); + + QMetaObject::invokeMethod(object, "doReset"); + + QCOMPARE(object->property("resettableProperty").toInt(), 13); + + delete object; + } +} + // QTBUG-6781 void tst_qmlecmascript::bug1() { @@ -1497,6 +1594,25 @@ void tst_qmlecmascript::callQtInvokables() QCOMPARE(o.actuals().at(1), QVariant(11)); } +// QTBUG-5675 +void tst_qmlecmascript::listToVariant() +{ + QmlComponent component(&engine, TEST_FILE("listToVariant.qml")); + + MyQmlContainer container; + + QmlContext context(engine.rootContext()); + context.addDefaultObject(&container); + + QObject *object = component.create(&context); + QVERIFY(object != 0); + + QCOMPARE(object->property("test"), QVariant::fromValue(container.children())); + + delete object; + +} + QTEST_MAIN(tst_qmlecmascript) #include "tst_qmlecmascript.moc" diff --git a/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp b/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp index a44ea6e..ec6b87f 100644 --- a/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp +++ b/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp @@ -113,6 +113,7 @@ private slots: void name(); void read(); void write(); + void reset(); // Functionality void writeObjectToList(); @@ -153,6 +154,7 @@ void tst_qmlmetaproperty::qmlmetaproperty() QCOMPARE(prop.isDefault(), false); QCOMPARE(prop.isWritable(), false); QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), false); QCOMPARE(prop.object(), (QObject *)0); QCOMPARE(prop.propertyCategory(), QmlMetaProperty::InvalidProperty); @@ -178,9 +180,12 @@ class PropertyObject : public QObject Q_PROPERTY(QRect rectProperty READ rectProperty); Q_PROPERTY(QRect wrectProperty READ wrectProperty WRITE setWRectProperty); Q_PROPERTY(QUrl url READ url WRITE setUrl); + Q_PROPERTY(int resettableProperty READ resettableProperty WRITE setResettableProperty RESET resetProperty); Q_CLASSINFO("DefaultProperty", "defaultProperty"); public: + PropertyObject() : m_resetProperty(9) {} + int defaultProperty() { return 10; } QRect rectProperty() { return QRect(10, 10, 1, 209); } @@ -190,10 +195,15 @@ public: QUrl url() { return m_url; } void setUrl(const QUrl &u) { m_url = u; } + int resettableProperty() const { return m_resetProperty; } + void setResettableProperty(int r) { m_resetProperty = r; } + void resetProperty() { m_resetProperty = 9; } + signals: void clicked(); private: + int m_resetProperty; QRect m_rect; QUrl m_url; }; @@ -230,6 +240,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object() QCOMPARE(prop.isDefault(), false); QCOMPARE(prop.isWritable(), false); QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), false); QCOMPARE(prop.object(), (QObject *)0); QCOMPARE(prop.propertyCategory(), QmlMetaProperty::InvalidProperty); @@ -276,6 +287,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object() QCOMPARE(prop.isDefault(), true); QCOMPARE(prop.isWritable(), false); QCOMPARE(prop.isDesignable(), true); + QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), true); QCOMPARE(prop.object(), &dobject); QCOMPARE(prop.propertyCategory(), QmlMetaProperty::Normal); @@ -329,6 +341,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string() QCOMPARE(prop.isDefault(), false); QCOMPARE(prop.isWritable(), false); QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), false); QCOMPARE(prop.object(), (QObject *)0); QCOMPARE(prop.propertyCategory(), QmlMetaProperty::InvalidProperty); @@ -375,6 +388,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string() QCOMPARE(prop.isDefault(), false); QCOMPARE(prop.isWritable(), false); QCOMPARE(prop.isDesignable(), true); + QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), true); QCOMPARE(prop.object(), &dobject); QCOMPARE(prop.propertyCategory(), QmlMetaProperty::Normal); @@ -423,6 +437,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string() QCOMPARE(prop.isDefault(), false); QCOMPARE(prop.isWritable(), false); QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), true); QCOMPARE(prop.object(), &dobject); QCOMPARE(prop.propertyCategory(), QmlMetaProperty::InvalidProperty); @@ -475,6 +490,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_context() QCOMPARE(prop.isDefault(), false); QCOMPARE(prop.isWritable(), false); QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), false); QCOMPARE(prop.object(), (QObject *)0); QCOMPARE(prop.propertyCategory(), QmlMetaProperty::InvalidProperty); @@ -521,6 +537,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_context() QCOMPARE(prop.isDefault(), true); QCOMPARE(prop.isWritable(), false); QCOMPARE(prop.isDesignable(), true); + QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), true); QCOMPARE(prop.object(), &dobject); QCOMPARE(prop.propertyCategory(), QmlMetaProperty::Normal); @@ -574,6 +591,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string_context() QCOMPARE(prop.isDefault(), false); QCOMPARE(prop.isWritable(), false); QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), false); QCOMPARE(prop.object(), (QObject *)0); QCOMPARE(prop.propertyCategory(), QmlMetaProperty::InvalidProperty); @@ -620,6 +638,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string_context() QCOMPARE(prop.isDefault(), false); QCOMPARE(prop.isWritable(), false); QCOMPARE(prop.isDesignable(), true); + QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), true); QCOMPARE(prop.object(), &dobject); QCOMPARE(prop.propertyCategory(), QmlMetaProperty::Normal); @@ -668,6 +687,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string_context() QCOMPARE(prop.isDefault(), false); QCOMPARE(prop.isWritable(), false); QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), true); QCOMPARE(prop.object(), &dobject); QCOMPARE(prop.propertyCategory(), QmlMetaProperty::InvalidProperty); @@ -973,6 +993,79 @@ void tst_qmlmetaproperty::write() } } +void tst_qmlmetaproperty::reset() +{ + // Invalid + { + QmlMetaProperty p; + QCOMPARE(p.isResettable(), false); + QCOMPARE(p.reset(), false); + } + + // Read-only default prop + { + PropertyObject o; + QmlMetaProperty p(&o); + QCOMPARE(p.isResettable(), false); + QCOMPARE(p.reset(), false); + } + + // Invalid default prop + { + QObject o; + QmlMetaProperty p(&o); + QCOMPARE(p.isResettable(), false); + QCOMPARE(p.reset(), false); + } + + // Non-resettable-only prop by name + { + PropertyObject o; + QmlMetaProperty p(&o, QString("defaultProperty")); + QCOMPARE(p.isResettable(), false); + QCOMPARE(p.reset(), false); + } + + // Resettable prop by name + { + PropertyObject o; + QmlMetaProperty p(&o, QString("resettableProperty")); + + QCOMPARE(p.read(), QVariant(9)); + QCOMPARE(p.write(QVariant(11)), true); + QCOMPARE(p.read(), QVariant(11)); + + QCOMPARE(p.isResettable(), true); + QCOMPARE(p.reset(), true); + + QCOMPARE(p.read(), QVariant(9)); + } + + // Deleted object + { + PropertyObject *o = new PropertyObject; + + QmlMetaProperty p(o, QString("resettableProperty")); + + QCOMPARE(p.isResettable(), true); + QCOMPARE(p.reset(), true); + + delete o; + + QCOMPARE(p.isResettable(), false); + QCOMPARE(p.reset(), false); + } + + // Signal property + { + PropertyObject o; + QmlMetaProperty p(&o, "onClicked"); + + QCOMPARE(p.isResettable(), false); + QCOMPARE(p.reset(), false); + } +} + void tst_qmlmetaproperty::writeObjectToList() { QmlComponent containerComponent(&engine); diff --git a/tests/auto/qbytearray/tst_qbytearray.cpp b/tests/auto/qbytearray/tst_qbytearray.cpp index 35e4463..5c72c7a 100644 --- a/tests/auto/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/qbytearray/tst_qbytearray.cpp @@ -76,6 +76,7 @@ private slots: void qCompress(); void qUncompress_data(); void qUncompress(); + void qCompressionZeroTermination(); #endif void constByteArray(); void leftJustified(); @@ -261,6 +262,14 @@ void tst_QByteArray::qUncompress() } QCOMPARE(res, out); } + +void tst_QByteArray::qCompressionZeroTermination() +{ + QString s = "Hello, I'm a string."; + QByteArray ba = ::qUncompress(::qCompress(s.toLocal8Bit())); + QVERIFY((int) *(ba.data() + ba.size()) == 0); +} + #endif void tst_QByteArray::constByteArray() diff --git a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp index 51e2a57..795431b 100644 --- a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp +++ b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp @@ -71,6 +71,7 @@ private slots: void colorize(); void drawPixmapItem(); void deviceCoordinateTranslateCaching(); + void inheritOpacity(); }; void tst_QGraphicsEffect::initTestCase() @@ -79,8 +80,8 @@ void tst_QGraphicsEffect::initTestCase() class CustomItem : public QGraphicsRectItem { public: - CustomItem(qreal x, qreal y, qreal width, qreal height) - : QGraphicsRectItem(x, y, width, height), numRepaints(0), + CustomItem(qreal x, qreal y, qreal width, qreal height, QGraphicsItem *parent = 0) + : QGraphicsRectItem(x, y, width, height, parent), numRepaints(0), m_painter(0), m_styleOption(0) {} @@ -560,6 +561,35 @@ void tst_QGraphicsEffect::deviceCoordinateTranslateCaching() QVERIFY(item->numRepaints == numRepaints); } +void tst_QGraphicsEffect::inheritOpacity() +{ + QGraphicsScene scene; + QGraphicsRectItem *rectItem = new QGraphicsRectItem(0, 0, 10, 10); + CustomItem *item = new CustomItem(0, 0, 10, 10, rectItem); + + scene.addItem(rectItem); + + item->setGraphicsEffect(new DeviceEffect); + item->setPen(Qt::NoPen); + item->setBrush(Qt::red); + + rectItem->setOpacity(0.5); + + QGraphicsView view(&scene); + view.show(); + QTest::qWaitForWindowShown(&view); + + QTRY_VERIFY(item->numRepaints >= 1); + + int numRepaints = item->numRepaints; + + rectItem->setOpacity(1); + QTest::qWait(50); + + // item should have been rerendered due to opacity changing + QTRY_VERIFY(item->numRepaints > numRepaints); +} + QTEST_MAIN(tst_QGraphicsEffect) #include "tst_qgraphicseffect.moc" diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index 8e43bce..14b9ef0 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -316,6 +316,7 @@ private slots: void childrenBoundingRectTransformed(); void childrenBoundingRect2(); void childrenBoundingRect3(); + void childrenBoundingRect4(); void group(); void setGroup(); void setGroup2(); @@ -417,6 +418,7 @@ private slots: void task197802_childrenVisibility(); void QTBUG_4233_updateCachedWithSceneRect(); void QTBUG_5418_textItemSetDefaultColor(); + void QTBUG_6738_missingUpdateWithSetParent(); private: QList<QGraphicsItem *> paintedItems; @@ -3257,6 +3259,32 @@ void tst_QGraphicsItem::childrenBoundingRect3() QCOMPARE(subTreeRect.height(), qreal(251.7766952966369)); } +void tst_QGraphicsItem::childrenBoundingRect4() +{ + QGraphicsScene scene; + + QGraphicsRectItem *rect = scene.addRect(QRectF(0, 0, 10, 10)); + QGraphicsRectItem *rect2 = scene.addRect(QRectF(0, 0, 20, 20)); + QGraphicsRectItem *rect3 = scene.addRect(QRectF(0, 0, 30, 30)); + rect2->setParentItem(rect); + rect3->setParentItem(rect); + + QGraphicsView view(&scene); + view.show(); + + QTest::qWaitForWindowShown(&view); + + // Try to mess up the cached bounding rect. + rect->childrenBoundingRect(); + rect2->childrenBoundingRect(); + + rect3->setOpacity(0.0); + rect3->setParentItem(rect2); + + QCOMPARE(rect->childrenBoundingRect(), rect3->boundingRect()); + QCOMPARE(rect2->childrenBoundingRect(), rect3->boundingRect()); +} + void tst_QGraphicsItem::group() { QGraphicsScene scene; @@ -9869,5 +9897,63 @@ void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor() QCOMPARE(i->painted, 0); //same color as before should not trigger an update (QTBUG-6242) } +void tst_QGraphicsItem::QTBUG_6738_missingUpdateWithSetParent() +{ + // In all 3 test cases below the reparented item should disappear + EventTester *parent = new EventTester; + EventTester *child = new EventTester(parent); + EventTester *child2 = new EventTester(parent); + EventTester *child3 = new EventTester(parent); + EventTester *child4 = new EventTester(parent); + + child->setPos(10, 10); + child2->setPos(20, 20); + child3->setPos(30, 30); + child4->setPos(40, 40); + + QGraphicsScene scene; + scene.addItem(parent); + + class MyGraphicsView : public QGraphicsView + { public: + int repaints; + QRegion paintedRegion; + MyGraphicsView(QGraphicsScene *scene) : QGraphicsView(scene), repaints(0) {} + void paintEvent(QPaintEvent *e) + { + ++repaints; + paintedRegion += e->region(); + QGraphicsView::paintEvent(e); + } + void reset() { repaints = 0; paintedRegion = QRegion(); } + }; + + MyGraphicsView view(&scene); + view.show(); + QTest::qWaitForWindowShown(&view); + QTRY_VERIFY(view.repaints > 0); + + // test case #1 + view.reset(); + child2->setVisible(false); + child2->setParentItem(child); + + QTRY_VERIFY(view.repaints == 1); + + // test case #2 + view.reset(); + child3->setOpacity(0.0); + child3->setParentItem(child); + + QTRY_VERIFY(view.repaints == 1); + + // test case #3 + view.reset(); + child4->setParentItem(child); + child4->setVisible(false); + + QTRY_VERIFY(view.repaints == 1); +} + QTEST_MAIN(tst_QGraphicsItem) #include "tst_qgraphicsitem.moc" diff --git a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp index c08a628e..6743fbe 100644 --- a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp @@ -270,6 +270,7 @@ private slots: void initialFocus_data(); void initialFocus(); void polishItems(); + void polishItems2(); void isActive(); void siblingIndexAlwaysValid(); @@ -3942,14 +3943,23 @@ void tst_QGraphicsScene::initialFocus() class PolishItem : public QGraphicsTextItem { public: - PolishItem(QGraphicsItem *parent = 0) : QGraphicsTextItem(parent) { } + PolishItem(QGraphicsItem *parent = 0) + : QGraphicsTextItem(parent), polished(false), deleteChildrenInPolish(true), addChildrenInPolish(false) { } + bool polished; + bool deleteChildrenInPolish; + bool addChildrenInPolish; protected: QVariant itemChange(GraphicsItemChange change, const QVariant& value) { if (change == ItemVisibleChange) { - if (value.toBool()) + polished = true; + if (deleteChildrenInPolish) qDeleteAll(childItems()); + if (addChildrenInPolish) { + for (int i = 0; i < 10; ++i) + new PolishItem(this); + } } return QGraphicsItem::itemChange(change, value); } @@ -3966,6 +3976,35 @@ void tst_QGraphicsScene::polishItems() QMetaObject::invokeMethod(&scene,"_q_polishItems"); } +void tst_QGraphicsScene::polishItems2() +{ + QGraphicsScene scene; + PolishItem *item = new PolishItem; + item->addChildrenInPolish = true; + item->deleteChildrenInPolish = true; + // These children should be deleted in the polish. + for (int i = 0; i < 20; ++i) + new PolishItem(item); + scene.addItem(item); + + // Wait for the polish event to be delivered. + QVERIFY(!item->polished); + QApplication::sendPostedEvents(&scene, QEvent::MetaCall); + QVERIFY(item->polished); + + // We deleted the children we added above, but we also + // added 10 new children. These should be polished in the next + // event loop iteration. + QList<QGraphicsItem *> children = item->childItems(); + QCOMPARE(children.count(), 10); + foreach (QGraphicsItem *child, children) + QVERIFY(!static_cast<PolishItem *>(child)->polished); + + QApplication::sendPostedEvents(&scene, QEvent::MetaCall); + foreach (QGraphicsItem *child, children) + QVERIFY(static_cast<PolishItem *>(child)->polished); +} + void tst_QGraphicsScene::isActive() { QGraphicsScene scene1; diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp index 909ea54..d3132fe 100644 --- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp @@ -163,6 +163,7 @@ private slots: void addChildInpolishEvent(); void polishEvent(); void polishEvent2(); + void initialShow(); // Task fixes void task236127_bspTreeIndexFails(); @@ -2856,6 +2857,30 @@ void tst_QGraphicsWidget::polishEvent2() QVERIFY(widget->events.contains(QEvent::Polish)); } +void tst_QGraphicsWidget::initialShow() +{ + class MyGraphicsWidget : public QGraphicsWidget + { public: + MyGraphicsWidget() : repaints(0) {} + int repaints; + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget*) { ++repaints; } + void polishEvent() { update(); } + }; + + QGraphicsScene scene; + MyGraphicsWidget *widget = new MyGraphicsWidget; + + QGraphicsView view(&scene); + view.show(); + QTest::qWaitForWindowShown(&view); + + QTest::qWait(100); + scene.addItem(widget); + QTest::qWait(100); + + QCOMPARE(widget->repaints, 1); +} + void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems() { QGraphicsScene scene; diff --git a/tests/auto/qpixmap/tst_qpixmap.cpp b/tests/auto/qpixmap/tst_qpixmap.cpp index 2340ef5..8bcd5e8 100644 --- a/tests/auto/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/qpixmap/tst_qpixmap.cpp @@ -171,6 +171,8 @@ private slots: void preserveDepth(); void splash_crash(); + + void loadAsBitmapOrPixmap(); }; static bool lenientCompare(const QPixmap &actual, const QPixmap &expected) @@ -1510,5 +1512,41 @@ void tst_QPixmap::preserveDepth() QCOMPARE(depth, source.depth()); } +void tst_QPixmap::loadAsBitmapOrPixmap() +{ + QImage tmp(10, 10, QImage::Format_RGB32); + tmp.save("tmp.png"); + + bool ok; + + // Check that we can load the pixmap as a pixmap and that it then turns into a pixmap + QPixmap pixmap("tmp.png"); + QVERIFY(!pixmap.isNull()); + QVERIFY(pixmap.depth() > 1); + QVERIFY(!pixmap.isQBitmap()); + + pixmap = QPixmap(); + ok = pixmap.load("tmp.png"); + QVERIFY(ok); + QVERIFY(!pixmap.isNull()); + QVERIFY(pixmap.depth() > 1); + QVERIFY(!pixmap.isQBitmap()); + + // The do the same check for bitmaps.. + QBitmap bitmap("tmp.png"); + QVERIFY(!bitmap.isNull()); + QVERIFY(bitmap.depth() == 1); + QVERIFY(bitmap.isQBitmap()); + + bitmap = QBitmap(); + ok = bitmap.load("tmp.png"); + QVERIFY(ok); + QVERIFY(!bitmap.isNull()); + QVERIFY(bitmap.depth() == 1); + QVERIFY(bitmap.isQBitmap()); +} + + + QTEST_MAIN(tst_QPixmap) #include "tst_qpixmap.moc" diff --git a/tests/auto/qsslcertificate/more-certificates/malformed-just-begin-no-newline.pem b/tests/auto/qsslcertificate/more-certificates/malformed-just-begin-no-newline.pem new file mode 100644 index 0000000..75f3c32 --- /dev/null +++ b/tests/auto/qsslcertificate/more-certificates/malformed-just-begin-no-newline.pem @@ -0,0 +1 @@ +-----BEGIN CERTIFICATE-----
\ No newline at end of file diff --git a/tests/auto/qsslcertificate/more-certificates/malformed-just-begin.pem b/tests/auto/qsslcertificate/more-certificates/malformed-just-begin.pem new file mode 100644 index 0000000..a71aecf --- /dev/null +++ b/tests/auto/qsslcertificate/more-certificates/malformed-just-begin.pem @@ -0,0 +1 @@ +-----BEGIN CERTIFICATE----- diff --git a/tests/auto/qsslcertificate/more-certificates/no-ending-newline.pem b/tests/auto/qsslcertificate/more-certificates/no-ending-newline.pem new file mode 100644 index 0000000..f8056c7 --- /dev/null +++ b/tests/auto/qsslcertificate/more-certificates/no-ending-newline.pem @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIIB8zCCAVwCAREwDQYJKoZIhvcNAQEFBQAwWzELMAkGA1UEBhMCQVUxEzARBgNV +BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRswGQYD +VQQDExJUZXN0IENBICgxMDI0IGJpdCkwHhcNMDcwNDE3MDc0MDI2WhcNMDcwNTE3 +MDc0MDI2WjApMRowGAYDVQQDExFuYW1lL3dpdGgvc2xhc2hlczELMAkGA1UEBhMC +Tk8wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAOud6QOsME+pWANExxgmL0iT +1ayg++hTxHsqAYnm/FoMxfUh+NdKkgJn2/GfNppinfPOSI667VqonU+7JBZDTLV5 +CPbZIo9fFQpDJQN6naev4yaxU1VeYFfI7S8c8zYKeGSR+RenNNeLvfH80YxPpZZ1 +snv8IfDH2V8MVxiyr7lLAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAleaU4pgzV6KY ++q9QuXapUYMsC2GiNtDmkG3k+MTHUO8XlE4hqPrIM6rRf7zKQdZ950R2wL9FSnYl +Qm1Tdv38dCka6ivMBqvRuOt9axH3m0G7nzHL7U3zaCbtEx3yVln+b3yYtiVpTuq0 +3MLrt7tQGAW6ra8ISf6YY1W65/uVXZE= +-----END CERTIFICATE-----
\ No newline at end of file diff --git a/tests/auto/qsslcertificate/tst_qsslcertificate.cpp b/tests/auto/qsslcertificate/tst_qsslcertificate.cpp index 44f8522..c76c11f 100644 --- a/tests/auto/qsslcertificate/tst_qsslcertificate.cpp +++ b/tests/auto/qsslcertificate/tst_qsslcertificate.cpp @@ -543,6 +543,9 @@ void tst_QSslCertificate::fromPath_data() QTest::newRow("\"d.*/c.*.pem\" wildcard der") << QString("d.*/c.*.pem") << int(QRegExp::Wildcard) << false << 0; QTest::newRow("trailing-whitespace") << QString("more-certificates/trailing-whitespace.pem") << int(QRegExp::FixedString) << true << 1; + QTest::newRow("no-ending-newline") << QString("more-certificates/no-ending-newline.pem") << int(QRegExp::FixedString) << true << 1; + QTest::newRow("malformed-just-begin") << QString("more-certificates/malformed-just-begin.pem") << int(QRegExp::FixedString) << true << 0; + QTest::newRow("malformed-just-begin-no-newline") << QString("more-certificates/malformed-just-begin-no-newline.pem") << int(QRegExp::FixedString) << true << 0; } void tst_QSslCertificate::fromPath() diff --git a/tests/auto/qtableview/tst_qtableview.cpp b/tests/auto/qtableview/tst_qtableview.cpp index 7a5e68f..430712c 100644 --- a/tests/auto/qtableview/tst_qtableview.cpp +++ b/tests/auto/qtableview/tst_qtableview.cpp @@ -3024,6 +3024,14 @@ void tst_QTableView::spans_data() << QPoint(0, 0) << 1 << 1; + + QTest::newRow("QTBUG-6004 (follow-up): No failing Q_ASSERT, then it passes.") + << 10 << 10 + << (SpanList() << QRect(2, 2, 1, 3) << QRect(2, 2, 1, 1)) + << false + << QPoint(0, 0) + << 1 + << 1; } void tst_QTableView::spans() diff --git a/tests/auto/qurl/tst_qurl.cpp b/tests/auto/qurl/tst_qurl.cpp index ecd6f09..33812fe 100644 --- a/tests/auto/qurl/tst_qurl.cpp +++ b/tests/auto/qurl/tst_qurl.cpp @@ -90,7 +90,6 @@ public slots: private slots: void getSetCheck(); void constructing(); - void isDetached(); void assignment(); void comparison(); void copying(); @@ -319,25 +318,6 @@ void tst_QUrl::constructing() QVERIFY(!buildUNC.isEmpty()); } -void tst_QUrl::isDetached() -{ - QUrl url; - QVERIFY(!url.isDetached()); - - url = "http://qt.nokia.com/"; - QVERIFY(url.isDetached()); - - url.clear(); - QVERIFY(!url.isDetached()); - - url.setHost("qt.nokia.com"); - QVERIFY(url.isDetached()); - - QUrl url2 = url; - QVERIFY(!url.isDetached()); - QVERIFY(!url2.isDetached()); -} - void tst_QUrl::assignment() { QUrl url("http://qt.nokia.com/"); diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index ee4e726..ea90ae3 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -5439,26 +5439,24 @@ public: QRegion r; }; -template<typename R, typename C> -void verifyColor(R const& region, C const& color) -{ - const QRegion r = QRegion(region); - for (int i = 0; i < r.rects().size(); ++i) { - const QRect rect = r.rects().at(i); - for (int t = 0; t < 5; t++) { - const QPixmap pixmap = QPixmap::grabWindow(QDesktopWidget().winId(), - rect.left(), rect.top(), - rect.width(), rect.height()); - QCOMPARE(pixmap.size(), rect.size()); - QPixmap expectedPixmap(pixmap); /* ensure equal formats */ - expectedPixmap.fill(color); - if (pixmap.toImage().pixel(0,0) != QColor(color).rgb() && t < 4 ) - { QTest::qWait(200); continue; } - QCOMPARE(pixmap.toImage().pixel(0,0), QColor(color).rgb()); - QCOMPARE(pixmap, expectedPixmap); - break; - } - } +#define VERIFY_COLOR(region, color) { \ + const QRegion r = QRegion(region); \ + for (int i = 0; i < r.rects().size(); ++i) { \ + const QRect rect = r.rects().at(i); \ + for (int t = 0; t < 5; t++) { \ + const QPixmap pixmap = QPixmap::grabWindow(QDesktopWidget().winId(), \ + rect.left(), rect.top(), \ + rect.width(), rect.height()); \ + QCOMPARE(pixmap.size(), rect.size()); \ + QPixmap expectedPixmap(pixmap); /* ensure equal formats */ \ + expectedPixmap.fill(color); \ + if (pixmap.toImage().pixel(0,0) != QColor(color).rgb() && t < 4 ) \ + { QTest::qWait(200); continue; } \ + QCOMPARE(pixmap.toImage().pixel(0,0), QColor(color).rgb()); \ + QCOMPARE(pixmap, expectedPixmap); \ + break; \ + } \ + } \ } void tst_QWidget::moveChild_data() @@ -5499,9 +5497,9 @@ void tst_QWidget::moveChild() #endif QTRY_COMPARE(parent.r, QRegion(parent.rect()) - child.geometry()); QTRY_COMPARE(child.r, QRegion(child.rect())); - verifyColor(child.geometry().translated(tlwOffset), + VERIFY_COLOR(child.geometry().translated(tlwOffset), child.color); - verifyColor(QRegion(parent.geometry()) - child.geometry().translated(tlwOffset), + VERIFY_COLOR(QRegion(parent.geometry()) - child.geometry().translated(tlwOffset), parent.color); parent.reset(); child.reset(); @@ -5520,9 +5518,9 @@ void tst_QWidget::moveChild() // should be scrolled in backingstore QCOMPARE(child.r, QRegion()); #endif - verifyColor(child.geometry().translated(tlwOffset), + VERIFY_COLOR(child.geometry().translated(tlwOffset), child.color); - verifyColor(QRegion(parent.geometry()) - child.geometry().translated(tlwOffset), + VERIFY_COLOR(QRegion(parent.geometry()) - child.geometry().translated(tlwOffset), parent.color); } @@ -5553,8 +5551,8 @@ void tst_QWidget::showAndMoveChild() child.move(desktopDimensions.width()/2, desktopDimensions.height()/2); qApp->processEvents(); - verifyColor(child.geometry().translated(tlwOffset), Qt::blue); - verifyColor(QRegion(parent.geometry()) - child.geometry().translated(tlwOffset), Qt::red); + VERIFY_COLOR(child.geometry().translated(tlwOffset), Qt::blue); + VERIFY_COLOR(QRegion(parent.geometry()) - child.geometry().translated(tlwOffset), Qt::red); } void tst_QWidget::subtractOpaqueSiblings() diff --git a/tests/benchmarks/declarative/declarative.pro b/tests/benchmarks/declarative/declarative.pro index 2f85265..8433de5 100644 --- a/tests/benchmarks/declarative/declarative.pro +++ b/tests/benchmarks/declarative/declarative.pro @@ -6,7 +6,5 @@ SUBDIRS += \ qmlcomponent \ qmlgraphicsimage \ qmlmetaproperty \ - qmlpainting \ script \ - text # qmltime diff --git a/tests/benchmarks/declarative/qmlpainting/qmlpainting.pro b/tests/benchmarks/declarative/qmlpainting/qmlpainting.pro deleted file mode 100644 index 971e18d..0000000 --- a/tests/benchmarks/declarative/qmlpainting/qmlpainting.pro +++ /dev/null @@ -1,6 +0,0 @@ -load(qttest_p4) -TEMPLATE = app -TARGET = tst_qmlpainting -macx:CONFIG -= app_bundle - -SOURCES += tst_qmlpainting.cpp diff --git a/tests/benchmarks/declarative/qmlpainting/tst_qmlpainting.cpp b/tests/benchmarks/declarative/qmlpainting/tst_qmlpainting.cpp deleted file mode 100644 index e14531f..0000000 --- a/tests/benchmarks/declarative/qmlpainting/tst_qmlpainting.cpp +++ /dev/null @@ -1,574 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <qtest.h> -#include <QPainter> -#include <QImage> - -#include <math.h> -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - -class tst_QmlPainting : public QObject -{ - Q_OBJECT - - public: - tst_QmlPainting() {} - -private slots: - void drawRoundedRect(); - void drawScaledRoundedRect(); - void drawTransformedRoundedRect(); - - void drawAntialiasedRoundedRect(); - void drawScaledAntialiasedRoundedRect_data(); - void drawScaledAntialiasedRoundedRect(); - void drawTransformedAntialiasedRoundedRect_data(); - void drawTransformedAntialiasedRoundedRect(); - - void drawImageRoundedRect(); - void drawScaledImageRoundedRect_data(); - void drawScaledImageRoundedRect(); - void drawTransformedImageRoundedRect_data(); - void drawTransformedImageRoundedRect(); - - void drawScaleGridRoundedRect(); - void drawScaledScaleGridRoundedRect_data(); - void drawScaledScaleGridRoundedRect(); - void drawTransformedScaleGridRoundedRect_data(); - void drawTransformedScaleGridRoundedRect(); - - void drawTransformedTransparentImage_data(); - void drawTransformedTransparentImage(); - void drawTransformedSemiTransparentImage_data(); - void drawTransformedSemiTransparentImage(); - void drawTransformedFilledImage_data(); - void drawTransformedFilledImage(); -}; - -const qreal inv_dist_to_plane = 1. / 1024.; -QTransform transformForAngle(qreal angle) -{ - QTransform transform; - - QTransform rotTrans; - rotTrans.translate(-40, 0); - QTransform rotTrans2; - rotTrans2.translate(40, 0); - - qreal rad = angle * 2. * M_PI / 360.; - qreal c = ::cos(rad); - qreal s = ::sin(rad); - - qreal x = 0; - qreal y = 80; - qreal z = 0; - - qreal len = x * x + y * y + z * z; - if (len != 1.) { - len = ::sqrt(len); - x /= len; - y /= len; - z /= len; - } - - QTransform rot(x*x*(1-c)+c, x*y*(1-c)-z*s, x*z*(1-c)+y*s*inv_dist_to_plane, - y*x*(1-c)+z*s, y*y*(1-c)+c, y*z*(1-c)-x*s*inv_dist_to_plane, - 0, 0, 1); - - transform *= rotTrans; - transform *= rot; - transform *= rotTrans2; - - return transform; -} - -void tst_QmlPainting::drawRoundedRect() -{ - QImage surface(100, 100, QImage::Format_RGB16); - surface.fill(QColor(255,255,255).rgb()); - QPainter p(&surface); - - p.setPen(QPen(Qt::black, 1)); - p.setBrush(Qt::red); - - QBENCHMARK { - p.drawRoundedRect(QRectF(.5, .5, 80, 80), 10, 10); - } - //surface.save("regular.png"); -} - -void tst_QmlPainting::drawScaledRoundedRect() -{ - QImage surface(400, 400, QImage::Format_RGB16); - surface.fill(QColor(255,255,255).rgb()); - QPainter p(&surface); - - p.setPen(QPen(Qt::black, 1)); - p.setBrush(Qt::red); - p.scale(3, 3); - - QBENCHMARK { - p.drawRoundedRect(10, 10, 80, 80, 10, 10); - } - //surface.save("scaled.png"); -} - -void tst_QmlPainting::drawTransformedRoundedRect() -{ - QImage surface(400, 400, QImage::Format_RGB16); - surface.fill(QColor(255,255,255).rgb()); - QPainter p(&surface); - - p.setPen(QPen(Qt::black, 1)); - p.setBrush(Qt::red); - - QBENCHMARK { - p.setWorldTransform(QTransform(0.956957, 0, 0.000704124, 0, 1, 0, 16.141, 0, 0.735953)); - p.drawRoundedRect(100, 100, 80, 80, 10, 10); - } - //surface.save("transformed.png"); -} - -void tst_QmlPainting::drawAntialiasedRoundedRect() -{ - QImage surface(100, 100, QImage::Format_RGB16); - surface.fill(QColor(255,255,255).rgb()); - QPainter p(&surface); - - p.setRenderHint(QPainter::Antialiasing, true); - p.setPen(QPen(Qt::black, 1)); - p.setBrush(Qt::red); - - QBENCHMARK { - p.drawRoundedRect(QRectF(.5, .5, 80, 80), 10, 10); - } - //surface.save("aar.png"); -} - -void tst_QmlPainting::drawScaledAntialiasedRoundedRect_data() -{ - QTest::addColumn<float>("scale"); - - for (float i = 0; i < 3; i += .1) - QTest::newRow(QString(QLatin1String("scale=%1")).arg(i).toLatin1()) << i; -} - -void tst_QmlPainting::drawScaledAntialiasedRoundedRect() -{ - QFETCH(float, scale); - - QImage surface(400, 400, QImage::Format_RGB16); - surface.fill(QColor(255,255,255).rgb()); - QPainter p(&surface); - - p.setRenderHint(QPainter::Antialiasing, true); - p.setPen(QPen(Qt::black, 1)); - p.setBrush(Qt::red); - p.scale(scale, scale); - - QBENCHMARK { - p.drawRoundedRect(10, 10, 80, 80, 10, 10); - } - //surface.save("aas.png"); -} - -void tst_QmlPainting::drawTransformedAntialiasedRoundedRect_data() -{ - QTest::addColumn<QTransform>("transform"); - - for (float angle = 0; angle < 360; angle += 10) - QTest::newRow(QString(QLatin1String("angle=%1")).arg(angle).toLatin1()) << transformForAngle(angle); -} - -void tst_QmlPainting::drawTransformedAntialiasedRoundedRect() -{ - QFETCH(QTransform, transform); - - QImage surface(400, 400, QImage::Format_RGB16); - surface.fill(QColor(255,255,255).rgb()); - QPainter p(&surface); - - p.setRenderHint(QPainter::Antialiasing, true); - p.setPen(QPen(Qt::black, 1)); - p.setBrush(Qt::red); - - QBENCHMARK { - p.setWorldTransform(transform); - p.drawRoundedRect(100, 100, 80, 80, 10, 10); - } - //surface.save("aat.png"); -} - -void tst_QmlPainting::drawImageRoundedRect() -{ - //setup image - const int radius = 10; - QImage rectImage(81, 81, QImage::Format_ARGB32_Premultiplied); - rectImage.fill(0); - QPainter rp(&rectImage); - rp.setRenderHint(QPainter::Antialiasing); - rp.setPen(Qt::black); - rp.setBrush(Qt::red); - rp.drawRoundedRect(QRectF(.5, .5, 80, 80), radius, radius); - - //setup surface - QImage surface(100, 100, QImage::Format_RGB16); - surface.fill(QColor(255,255,255).rgb()); - QPainter p(&surface); - - QBENCHMARK { - p.drawImage(0,0, rectImage); - } - //surface.save("ri.png"); -} - -void tst_QmlPainting::drawScaledImageRoundedRect_data() -{ - QTest::addColumn<int>("imageType"); - - QTest::newRow("imagetype=ARGB32_Pre") << (int)QImage::Format_ARGB32_Premultiplied; - QTest::newRow("imagetype=ARGB8565_Pre") << (int)QImage::Format_ARGB8565_Premultiplied; -} - -void tst_QmlPainting::drawScaledImageRoundedRect() -{ - QFETCH(int, imageType); - - //setup image - const int radius = 10; - QImage rectImage(81, 81, (QImage::Format)imageType); - rectImage.fill(0); - QPainter rp(&rectImage); - rp.setRenderHint(QPainter::Antialiasing); - rp.setPen(Qt::black); - rp.setBrush(Qt::red); - rp.drawRoundedRect(QRectF(.5, .5, 80, 80), radius, radius); - - //setup surface - QImage surface(400, 400, QImage::Format_RGB16); - surface.fill(QColor(255,255,255).rgb()); - QPainter p(&surface); - p.scale(3, 3); - - QBENCHMARK { - p.drawImage(0,0, rectImage); - } - //surface.save("si.png"); -} - -void tst_QmlPainting::drawTransformedImageRoundedRect_data() -{ - QTest::addColumn<int>("imageType"); - - QTest::newRow("imagetype=ARGB32_Pre") << (int)QImage::Format_ARGB32_Premultiplied; - QTest::newRow("imagetype=ARGB8565_Pre") << (int)QImage::Format_ARGB8565_Premultiplied; -} - -void tst_QmlPainting::drawTransformedImageRoundedRect() -{ - QFETCH(int, imageType); - - //setup image - const int radius = 10; - QImage rectImage(81, 81, (QImage::Format)imageType); - rectImage.fill(0); - QPainter rp(&rectImage); - rp.setRenderHint(QPainter::Antialiasing); - rp.setPen(Qt::black); - rp.setBrush(Qt::red); - rp.drawRoundedRect(QRectF(.5, .5, 80, 80), radius, radius); - - //setup surface - QImage surface(400, 400, QImage::Format_RGB16); - surface.fill(QColor(255,255,255).rgb()); - QPainter p(&surface); - - QBENCHMARK { - p.setWorldTransform(QTransform(0.956957, 0, 0.000704124, 0, 1, 0, 16.141, 0, 0.735953)); - p.drawImage(100,100, rectImage); - } - //surface.save("ti.png"); -} - -//code from QmlGraphicsRectangle for drawing rounded rects -void tst_QmlPainting::drawScaleGridRoundedRect() -{ - //setup image - const int pw = 1; - const int radius = 10; - QImage rectImage(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2, QImage::Format_ARGB32_Premultiplied); - rectImage.fill(0); - QPainter rp(&rectImage); - rp.setRenderHint(QPainter::Antialiasing); - rp.setPen(Qt::black); - rp.setBrush(Qt::red); - if (pw%2) - rp.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, rectImage.width()-(pw+1), rectImage.height()-(pw+1)), radius, radius); - else - rp.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, rectImage.width()-pw, rectImage.height()-pw), radius, radius); - QPixmap rectPixmap = QPixmap::fromImage(rectImage); - - //setup surface - QImage surface(100, 100, QImage::Format_RGB16); - surface.fill(QColor(255,255,255).rgb()); - QPainter p(&surface); - - QBENCHMARK { - const int pw = 2; - int width = 80; - int height = 80; - - int xOffset = (rectPixmap.width()-1)/2; - int yOffset = (rectPixmap.height()-1)/2; - Q_ASSERT(rectPixmap.width() == 2*xOffset + 1); - Q_ASSERT(rectPixmap.height() == 2*yOffset + 1); - - QMargins margins(xOffset, yOffset, xOffset, yOffset); - QTileRules rules(Qt::StretchTile, Qt::StretchTile); - //NOTE: even though our item may have qreal-based width and height, qDrawBorderPixmap only supports QRects - qDrawBorderPixmap(&p, QRect(-pw/2, -pw/2, width+pw, height+pw), margins, rectPixmap, rectPixmap.rect(), margins, rules); - } - //surface.save("rsg.png"); -} - -void tst_QmlPainting::drawScaledScaleGridRoundedRect_data() -{ - QTest::addColumn<float>("scale"); - QTest::addColumn<int>("imageType"); - - for (float i = 0; i < 3; i += .1) - QTest::newRow(QString(QLatin1String("scale=%1; imagetype=ARGB32_Pre")).arg(i).toLatin1()) << i << (int)QImage::Format_ARGB32_Premultiplied; - //for (float i = 0; i < 3; i += .1) - // QTest::newRow(QString(QLatin1String("scale=%1; imagetype=ARGB8565_Pre")).arg(i).toLatin1()) << i << (int)QImage::Format_ARGB8565_Premultiplied; -} - -//code from QmlGraphicsRectangle for drawing rounded rects -void tst_QmlPainting::drawScaledScaleGridRoundedRect() -{ - QFETCH(float, scale); - QFETCH(int, imageType); - - //setup image - const int pw = 1; - const int radius = 10; - QImage rectImage(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2, (QImage::Format)imageType); - rectImage.fill(0); - QPainter rp(&rectImage); - rp.setRenderHint(QPainter::Antialiasing); - rp.setPen(Qt::black); - rp.setBrush(Qt::red); - if (pw%2) - rp.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, rectImage.width()-(pw+1), rectImage.height()-(pw+1)), radius, radius); - else - rp.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, rectImage.width()-pw, rectImage.height()-pw), radius, radius); - - QPixmap rectPixmap = QPixmap::fromImage(rectImage); - - //setup surface - QImage surface(400, 400, QImage::Format_RGB16); - surface.fill(QColor(255,255,255).rgb()); - QPainter p(&surface); - p.scale(scale, scale); - - QBENCHMARK { - const int pw = 2; - int width = 80; - int height = 80; - - int xOffset = (rectPixmap.width()-1)/2; - int yOffset = (rectPixmap.height()-1)/2; - Q_ASSERT(rectPixmap.width() == 2*xOffset + 1); - Q_ASSERT(rectPixmap.height() == 2*yOffset + 1); - - QMargins margins(xOffset, yOffset, xOffset, yOffset); - QTileRules rules(Qt::StretchTile, Qt::StretchTile); - //NOTE: even though our item may have qreal-based width and height, qDrawBorderPixmap only supports QRects - qDrawBorderPixmap(&p, QRect(-pw/2, -pw/2, width+pw, height+pw), margins, rectPixmap, rectPixmap.rect(), margins, rules); - } - //surface.save("ssg.png"); -} - -void tst_QmlPainting::drawTransformedScaleGridRoundedRect_data() -{ - QTest::addColumn<QTransform>("transform"); - QTest::addColumn<int>("imageType"); - - for (float angle = 0; angle < 360; angle += 10) - QTest::newRow(QString(QLatin1String("angle=%1; imagetype=ARGB32_Pre")).arg(angle).toLatin1()) << transformForAngle(angle) << (int)QImage::Format_ARGB32_Premultiplied; - //for (float angle = 0; angle < 360; angle += 10) - // QTest::newRow(QString(QLatin1String("angle=%1; imagetype=ARGB8565_Pre")).arg(angle).toLatin1()) << transformForAngle(angle) << (int)QImage::Format_ARGB8565_Premultiplied; - -} - -//code from QmlGraphicsRectangle for drawing rounded rects -void tst_QmlPainting::drawTransformedScaleGridRoundedRect() -{ - QFETCH(QTransform, transform); - QFETCH(int, imageType); - - //setup image - const int pw = 1; - const int radius = 10; - QImage rectImage(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2, (QImage::Format)imageType); - rectImage.fill(0); - QPainter rp(&rectImage); - rp.setRenderHint(QPainter::Antialiasing); - rp.setPen(Qt::black); - rp.setBrush(Qt::red); - if (pw%2) - rp.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, rectImage.width()-(pw+1), rectImage.height()-(pw+1)), radius, radius); - else - rp.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, rectImage.width()-pw, rectImage.height()-pw), radius, radius); - - QPixmap rectPixmap = QPixmap::fromImage(rectImage); - - //setup surface - QImage surface(400, 400, QImage::Format_RGB16); - surface.fill(QColor(255,255,255).rgb()); - QPainter p(&surface); - - QBENCHMARK { - p.setWorldTransform(transform); - const int pw = 2; - //int offset = int(radius+1.5+pw); - int width = 80; - int height = 80; - - int xOffset = (rectPixmap.width()-1)/2; - int yOffset = (rectPixmap.height()-1)/2; - Q_ASSERT(rectPixmap.width() == 2*xOffset + 1); - Q_ASSERT(rectPixmap.height() == 2*yOffset + 1); - - QMargins margins(xOffset, yOffset, xOffset, yOffset); - QTileRules rules(Qt::StretchTile, Qt::StretchTile); - //NOTE: even though our item may have qreal-based width and height, qDrawBorderPixmap only supports QRects - qDrawBorderPixmap(&p, QRect(-pw/2, -pw/2, width+pw, height+pw), margins, rectPixmap, rectPixmap.rect(), margins, rules); - } - //surface.save("tsg.png"); -} - -void tst_QmlPainting::drawTransformedTransparentImage_data() -{ - QTest::addColumn<int>("imageType"); - - QTest::newRow("imagetype=ARGB32_Pre") << (int)QImage::Format_ARGB32_Premultiplied; - QTest::newRow("imagetype=ARGB8565_Pre") << (int)QImage::Format_ARGB8565_Premultiplied; -} - -void tst_QmlPainting::drawTransformedTransparentImage() -{ - QFETCH(int, imageType); - - //setup image - QImage transImage(200, 200, (QImage::Format)imageType); - transImage.fill(0); - - //setup surface - QImage surface(200, 200, QImage::Format_RGB16); - surface.fill(QColor(255,255,255).rgb()); - QPainter p(&surface); - - QBENCHMARK { - p.setWorldTransform(QTransform(0.956957, 0, 0.000704124, 0, 1, 0, 16.141, 0, 0.735953)); - p.drawImage(0,0, transImage); - } -} - -void tst_QmlPainting::drawTransformedSemiTransparentImage_data() -{ - QTest::addColumn<int>("imageType"); - - QTest::newRow("imagetype=ARGB32_Pre") << (int)QImage::Format_ARGB32_Premultiplied; - QTest::newRow("imagetype=ARGB8565_Pre") << (int)QImage::Format_ARGB8565_Premultiplied; -} - -void tst_QmlPainting::drawTransformedSemiTransparentImage() -{ - QFETCH(int, imageType); - - //setup image - QImage transImage(200, 200, (QImage::Format)imageType); - transImage.fill(QColor(0,0,0, 128).rgba()); - - //setup surface - QImage surface(200, 200, QImage::Format_RGB16); - surface.fill(QColor(255,255,255).rgb()); - QPainter p(&surface); - - QBENCHMARK { - p.setWorldTransform(QTransform(0.956957, 0, 0.000704124, 0, 1, 0, 16.141, 0, 0.735953)); - p.drawImage(0,0, transImage); - } -} - -void tst_QmlPainting::drawTransformedFilledImage_data() -{ - QTest::addColumn<int>("imageType"); - - QTest::newRow("imagetype=ARGB32_Pre") << (int)QImage::Format_ARGB32_Premultiplied; - QTest::newRow("imagetype=ARGB8565_Pre") << (int)QImage::Format_ARGB8565_Premultiplied; -} - -void tst_QmlPainting::drawTransformedFilledImage() -{ - QFETCH(int, imageType); - - //setup image - QImage filledImage(200, 200, (QImage::Format)imageType); - filledImage.fill(QColor(0,0,0).rgb()); - - //setup surface - QImage surface(200, 200, QImage::Format_RGB16); - surface.fill(QColor(255,255,255).rgb()); - QPainter p(&surface); - - QBENCHMARK { - p.setWorldTransform(QTransform(0.956957, 0, 0.000704124, 0, 1, 0, 16.141, 0, 0.735953)); - p.drawImage(0,0, filledImage); - } -} - -QTEST_MAIN(tst_QmlPainting) - -#include "tst_qmlpainting.moc" diff --git a/tests/benchmarks/declarative/signalemission/signalemission.pro b/tests/benchmarks/declarative/signalemission/signalemission.pro deleted file mode 100644 index 0119aff..0000000 --- a/tests/benchmarks/declarative/signalemission/signalemission.pro +++ /dev/null @@ -1,7 +0,0 @@ -load(qttest_p4) -TEMPLATE = app -TARGET = tst_signalemission -macx:CONFIG -= app_bundle - -SOURCES += tst_signalemission.cpp - diff --git a/tests/benchmarks/declarative/signalemission/tst_signalemission.cpp b/tests/benchmarks/declarative/signalemission/tst_signalemission.cpp deleted file mode 100644 index 8327638..0000000 --- a/tests/benchmarks/declarative/signalemission/tst_signalemission.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <qtest.h> -#include <QObject> -#include <QDebug> - -class LotsOfSignals : public QObject -{ - Q_OBJECT -public: - LotsOfSignals() {} - -signals: - void extraSignal1(); - void extraSignal2(); - void extraSignal3(); - void extraSignal4(); - void extraSignal5(); - void extraSignal6(); - void extraSignal7(); - void extraSignal8(); - void extraSignal9(); - void extraSignal10(); - void extraSignal12(); - void extraSignal13(); - void extraSignal14(); - void extraSignal15(); - void extraSignal16(); - void extraSignal17(); - void extraSignal18(); - void extraSignal19(); - void extraSignal20(); - void extraSignal21(); - void extraSignal22(); - void extraSignal23(); - void extraSignal24(); - void extraSignal25(); - void extraSignal26(); - void extraSignal27(); - void extraSignal28(); - void extraSignal29(); - void extraSignal30(); - void extraSignal31(); - void extraSignal32(); - void extraSignal33(); - void extraSignal34(); - void extraSignal35(); - void extraSignal36(); - void extraSignal37(); - void extraSignal38(); - void extraSignal39(); - void extraSignal40(); - void extraSignal41(); - void extraSignal42(); - void extraSignal43(); - void extraSignal44(); - void extraSignal45(); - void extraSignal46(); - void extraSignal47(); - void extraSignal48(); - void extraSignal49(); - void extraSignal50(); - void extraSignal51(); - void extraSignal52(); - void extraSignal53(); - void extraSignal54(); - void extraSignal55(); - void extraSignal56(); - void extraSignal57(); - void extraSignal58(); - void extraSignal59(); - void extraSignal60(); - void extraSignal61(); - void extraSignal62(); - void extraSignal63(); - void extraSignal64(); - void extraSignal65(); - void extraSignal66(); - void extraSignal67(); - void extraSignal68(); - void extraSignal69(); - void extraSignal70(); -}; - -class tst_signalemission : public QObject -{ - Q_OBJECT -public: - tst_signalemission() {} - -private slots: - void unconnected_data(); - void unconnected(); -}; - -void tst_signalemission::unconnected_data() -{ - QTest::addColumn<int>("signal_index"); - QTest::newRow("9") << 9; - QTest::newRow("32") << 32; - QTest::newRow("33") << 33; - QTest::newRow("64") << 64; - QTest::newRow("65") << 65; - QTest::newRow("70") << 70; -} - -void tst_signalemission::unconnected() -{ - LotsOfSignals *obj = new LotsOfSignals; - QFETCH(int, signal_index); - QVERIFY(obj->metaObject()->methodCount() == 73); - void *v; - QBENCHMARK { - //+1 because QObject has one slot - QMetaObject::metacall(obj, QMetaObject::InvokeMetaMethod, signal_index+1, &v); - } - delete obj; -} - -QTEST_MAIN(tst_signalemission) -#include "tst_signalemission.moc" diff --git a/tests/benchmarks/declarative/text/text.pro b/tests/benchmarks/declarative/text/text.pro deleted file mode 100644 index 3320f53..0000000 --- a/tests/benchmarks/declarative/text/text.pro +++ /dev/null @@ -1,7 +0,0 @@ -load(qttest_p4) -TEMPLATE = app -TARGET = tst_text -macx:CONFIG -= app_bundle - -SOURCES += tst_text.cpp - diff --git a/tests/benchmarks/declarative/text/tst_text.cpp b/tests/benchmarks/declarative/text/tst_text.cpp deleted file mode 100644 index 33ee237..0000000 --- a/tests/benchmarks/declarative/text/tst_text.cpp +++ /dev/null @@ -1,260 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <qtest.h> -#include <QTextLayout> -#include <QPainter> -#include <QSize> -#include <qmath.h> -#include <private/qtextcontrol_p.h> - -class tst_text : public QObject -{ - Q_OBJECT -public: - tst_text() - { - m_text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."; - } - -private slots: - void layout(); - void paintLayoutToPixmap(); - void paintLayoutToPixmap_painterFill(); - void document(); - void paintDocToPixmap(); - void paintDocToPixmap_painterFill(); - void control(); - void paintControlToPixmap(); - void paintControlToPixmap_painterFill(); - void constructControl(); - void constructDocument(); - -private: - QString m_text; -}; - -QSize setupTextLayout(QTextLayout *layout) -{ - bool wrap = true; - int wrapWidth = 300; - layout->setCacheEnabled(true); - - int height = 0; - qreal widthUsed = 0; - qreal lineWidth = 0; - - //set manual width - if (wrap) - lineWidth = wrapWidth; - - layout->beginLayout(); - - while (1) { - QTextLine line = layout->createLine(); - if (!line.isValid()) - break; - - if (wrap) - line.setLineWidth(lineWidth); - } - layout->endLayout(); - - for (int i = 0; i < layout->lineCount(); ++i) { - QTextLine line = layout->lineAt(i); - widthUsed = qMax(widthUsed, line.naturalTextWidth()); - line.setPosition(QPointF(0, height)); - height += int(line.height()); - } - return QSize(qCeil(widthUsed), height); -} - -void tst_text::layout() -{ - //get rid of initialization effects - QTextLayout layout(m_text); - setupTextLayout(&layout); - - QBENCHMARK { - QTextLayout layout(m_text); - setupTextLayout(&layout); - } -} - -void tst_text::paintLayoutToPixmap() -{ - QTextLayout layout(m_text); - QSize size = setupTextLayout(&layout); - - QBENCHMARK { - QPixmap img(size); - img.fill(Qt::transparent); - QPainter p(&img); - layout.draw(&p, QPointF(0, 0)); - } -} - -void tst_text::paintLayoutToPixmap_painterFill() -{ - QTextLayout layout(m_text); - QSize size = setupTextLayout(&layout); - - QBENCHMARK { - QPixmap img(size); - QPainter p(&img); - p.setCompositionMode(QPainter::CompositionMode_Source); - p.fillRect(0, 0, img.width(), img.height(), Qt::transparent); - p.setCompositionMode(QPainter::CompositionMode_SourceOver); - layout.draw(&p, QPointF(0, 0)); - } -} - -void tst_text::document() -{ - QTextDocument *doc = new QTextDocument; - - QBENCHMARK { - QTextDocument *doc = new QTextDocument; - doc->setHtml(m_text); - } -} - -void tst_text::paintDocToPixmap() -{ - QTextDocument *doc = new QTextDocument; - doc->setHtml(m_text); - doc->setTextWidth(300); - QSize size = doc->size().toSize(); - - QBENCHMARK { - QPixmap img(size); - img.fill(Qt::transparent); - QPainter p(&img); - doc->drawContents(&p); - } -} - -void tst_text::paintDocToPixmap_painterFill() -{ - QTextDocument *doc = new QTextDocument; - doc->setHtml(m_text); - doc->setTextWidth(300); - QSize size = doc->size().toSize(); - - QBENCHMARK { - QPixmap img(size); - QPainter p(&img); - p.setCompositionMode(QPainter::CompositionMode_Source); - p.fillRect(0, 0, img.width(), img.height(), Qt::transparent); - p.setCompositionMode(QPainter::CompositionMode_SourceOver); - doc->drawContents(&p); - } -} - -void tst_text::control() -{ - QTextControl *control = new QTextControl(m_text); - - QBENCHMARK { - QTextControl *control = new QTextControl; - QTextDocument *doc = control->document(); - doc->setHtml(m_text); - } -} - -void tst_text::paintControlToPixmap() -{ - QTextControl *control = new QTextControl; - QTextDocument *doc = control->document(); - doc->setHtml(m_text); - doc->setTextWidth(300); - QSize size = doc->size().toSize(); - - QBENCHMARK { - QPixmap img(size); - img.fill(Qt::transparent); - QPainter p(&img); - control->drawContents(&p, QRectF(QPointF(0, 0), QSizeF(size))); - } -} - -void tst_text::paintControlToPixmap_painterFill() -{ - QTextControl *control = new QTextControl; - QTextDocument *doc = control->document(); - doc->setHtml(m_text); - doc->setTextWidth(300); - QSize size = doc->size().toSize(); - - QBENCHMARK { - QPixmap img(size); - QPainter p(&img); - p.setCompositionMode(QPainter::CompositionMode_Source); - p.fillRect(0, 0, img.width(), img.height(), Qt::transparent); - p.setCompositionMode(QPainter::CompositionMode_SourceOver); - control->drawContents(&p, QRectF(QPointF(0, 0), QSizeF(size))); - } -} - -void tst_text::constructControl() -{ - QTextControl *control = new QTextControl; - delete control; - - QBENCHMARK { - QTextControl *control = new QTextControl; - delete control; - } -} - -void tst_text::constructDocument() -{ - QTextDocument *doc = new QTextDocument; - delete doc; - - QBENCHMARK { - QTextDocument *doc = new QTextDocument; - delete doc; - } -} - -QTEST_MAIN(tst_text) -#include "tst_text.moc" |