From 0cda0d00f95cbcd292f4b1f5ed4a47d43e0ac825 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 3 Nov 2009 18:29:34 +1000 Subject: QmlMetaType test --- tests/auto/declarative/declarative.pro | 1 + tests/auto/declarative/qmlmetatype/qmlmetatype.pro | 6 + .../declarative/qmlmetatype/tst_qmlmetatype.cpp | 220 +++++++++++++++++++++ 3 files changed, 227 insertions(+) create mode 100644 tests/auto/declarative/qmlmetatype/qmlmetatype.pro create mode 100644 tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 0d55391..26e8346 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -23,6 +23,7 @@ SUBDIRS += anchors \ qmllist \ qmllistaccessor \ qmlmetaproperty \ + qmlmetatype \ qmlpropertymap \ qmltimer \ repeater \ diff --git a/tests/auto/declarative/qmlmetatype/qmlmetatype.pro b/tests/auto/declarative/qmlmetatype/qmlmetatype.pro new file mode 100644 index 0000000..3a9a400 --- /dev/null +++ b/tests/auto/declarative/qmlmetatype/qmlmetatype.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +SOURCES += tst_qmlmetatype.cpp +macx:CONFIG -= app_bundle + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp b/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp new file mode 100644 index 0000000..06a47c0 --- /dev/null +++ b/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp @@ -0,0 +1,220 @@ +/**************************************************************************** +** +** 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class tst_qmlmetatype : public QObject +{ + Q_OBJECT +public: + tst_qmlmetatype() {} + +private slots: + void copy(); +}; + +#define COPY_TEST(cpptype, metatype, value, defaultvalue) \ +{ \ + cpptype v = (value); cpptype v2 = (value); \ + QVERIFY(QmlMetaType::copy(QMetaType:: metatype, &v, 0)); \ + QVERIFY(v == (defaultvalue)); \ + QVERIFY(QmlMetaType::copy(QMetaType:: metatype, &v, &v2)); \ + QVERIFY(v == (value)); \ +} + +#define QT_COPY_TEST(type, value) \ +{ \ + type v = (value); type v2 = (value); \ + QVERIFY(QmlMetaType::copy(QMetaType:: type, &v, 0)); \ + QVERIFY(v == (type ())); \ + QVERIFY(QmlMetaType::copy(QMetaType:: type, &v, &v2)); \ + QVERIFY(v == (value)); \ +} + +void tst_qmlmetatype::copy() +{ + QVERIFY(QmlMetaType::copy(QMetaType::Void, 0, 0)); + + COPY_TEST(bool, Bool, true, false); + COPY_TEST(int, Int, 10, 0); + COPY_TEST(unsigned int, UInt, 10, 0); + COPY_TEST(long long, LongLong, 10, 0); + COPY_TEST(unsigned long long, ULongLong, 10, 0); + COPY_TEST(double, Double, 19.2, 0); + + QT_COPY_TEST(QChar, QChar('a')); + + QVariantMap variantMap; + variantMap.insert("Hello World!", QVariant(10)); + QT_COPY_TEST(QVariantMap, variantMap); + + QT_COPY_TEST(QVariantList, QVariantList() << QVariant(19.2)); + QT_COPY_TEST(QString, QString("QML Rocks!")); + QT_COPY_TEST(QStringList, QStringList() << "QML" << "Rocks"); + QT_COPY_TEST(QByteArray, QByteArray("0x1102DDD")); + QT_COPY_TEST(QBitArray, QBitArray(102, true)); + QT_COPY_TEST(QDate, QDate::currentDate()); + QT_COPY_TEST(QTime, QTime::currentTime()); + QT_COPY_TEST(QDateTime, QDateTime::currentDateTime()); + QT_COPY_TEST(QUrl, QUrl("http://www.nokia.com")); + QT_COPY_TEST(QLocale, QLocale(QLocale::English, QLocale::Australia)); + QT_COPY_TEST(QRect, QRect(-10, 10, 102, 99)); + QT_COPY_TEST(QRectF, QRectF(-10.2, 1.2, 102, 99.6)); + QT_COPY_TEST(QSize, QSize(100, 2)); + QT_COPY_TEST(QSizeF, QSizeF(20.2, -100234.2)); + QT_COPY_TEST(QLine, QLine(0, 0, 100, 100)); + QT_COPY_TEST(QLineF, QLineF(-10.2, 0, 103, 1)); + QT_COPY_TEST(QPoint, QPoint(-1912, 1613)); + QT_COPY_TEST(QPointF, QPointF(-908.1, 1612)); + QT_COPY_TEST(QRegExp, QRegExp("(\\d+)(?:\\s*)(cm|inch)")); + + QVariantHash variantHash; + variantHash.insert("Hello World!", QVariant(19)); + QT_COPY_TEST(QVariantHash, variantHash); + +#ifdef QT3_SUPPORT + QT_COPY_TEST(QColorGroup, QColorGroup(Qt::red, Qt::red, Qt::red, Qt::red, Qt::red, Qt::red, Qt::red)); +#endif + + QT_COPY_TEST(QFont, QFont("Helvetica", 1024)); + + { + QPixmap v = QPixmap(100, 100); QPixmap v2 = QPixmap(100, 100); + QVERIFY(QmlMetaType::copy(QMetaType::QPixmap, &v, 0)); + QVERIFY(v.size() == QPixmap().size()); + QVERIFY(QmlMetaType::copy(QMetaType::QPixmap , &v, &v2)); + QVERIFY(v.size() == QPixmap(100,100).size()); + } + + QT_COPY_TEST(QBrush, QBrush(Qt::blue)); + QT_COPY_TEST(QColor, QColor("lightsteelblue")); + QT_COPY_TEST(QPalette, QPalette(Qt::green)); + + { + QPixmap icon(100, 100); + + QIcon v = QIcon(icon); QIcon v2 = QIcon(icon); + QVERIFY(QmlMetaType::copy(QMetaType::QIcon, &v, 0)); + QVERIFY(v.isNull() == QIcon().isNull()); + QVERIFY(QmlMetaType::copy(QMetaType::QIcon , &v, &v2)); + QVERIFY(v.isNull() == QIcon(icon).isNull()); + } + + { + QImage v = QImage(100, 100, QImage::Format_RGB32); + QImage v2 = QImage(100, 100, QImage::Format_RGB32); + QVERIFY(QmlMetaType::copy(QMetaType::QImage, &v, 0)); + QVERIFY(v.size() == QImage().size()); + QVERIFY(QmlMetaType::copy(QMetaType::QImage , &v, &v2)); + QVERIFY(v.size() == QImage(100,100, QImage::Format_RGB32).size()); + } + + QT_COPY_TEST(QPolygon, QPolygon(QRect(100, 100, 200, 103))); + QT_COPY_TEST(QRegion, QRegion(QRect(0, 10, 99, 87))); + + { + QBitmap v = QBitmap(100, 100); QBitmap v2 = QBitmap(100, 100); + QVERIFY(QmlMetaType::copy(QMetaType::QBitmap, &v, 0)); + QVERIFY(v.size() == QBitmap().size()); + QVERIFY(QmlMetaType::copy(QMetaType::QBitmap , &v, &v2)); + QVERIFY(v.size() == QBitmap(100,100).size()); + } + + { + QCursor v = QCursor(Qt::SizeFDiagCursor); QCursor v2 = QCursor(Qt::SizeFDiagCursor); + QVERIFY(QmlMetaType::copy(QMetaType::QCursor, &v, 0)); + QVERIFY(v.shape() == QCursor().shape()); + QVERIFY(QmlMetaType::copy(QMetaType::QCursor , &v, &v2)); + QVERIFY(v.shape() == QCursor(Qt::SizeFDiagCursor).shape()); + } + + QT_COPY_TEST(QSizePolicy, QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Maximum)); + QT_COPY_TEST(QKeySequence, QKeySequence("Ctrl+O")); + QT_COPY_TEST(QPen, QPen(Qt::red)); + QT_COPY_TEST(QTextLength, QTextLength(QTextLength::FixedLength, 10.2)); + QT_COPY_TEST(QMatrix, QMatrix().translate(10, 10)); + QT_COPY_TEST(QTransform, QTransform().translate(10, 10)); + QT_COPY_TEST(QMatrix4x4, QMatrix4x4().translate(10, 10)); + QT_COPY_TEST(QVector2D, QVector2D(10.2, 1)); + QT_COPY_TEST(QVector3D, QVector3D(10.2, 1, -2)); + QT_COPY_TEST(QVector4D, QVector4D(10.2, 1, -2, 1.2)); + QT_COPY_TEST(QQuaternion, QQuaternion(1.0, 10.2, 1, -2)); + + int voidValue; + COPY_TEST(void *, VoidStar, (void *)&voidValue, (void *)0); + COPY_TEST(long, Long, 10, 0); + COPY_TEST(short, Short, 10, 0); + COPY_TEST(char, Char, 'a', 0); + COPY_TEST(unsigned long, ULong, 10, 0); + COPY_TEST(unsigned short, UShort, 10, 0); + COPY_TEST(unsigned char, UChar, 'a', 0); + COPY_TEST(float, Float, 10.5, 0); + + QObject objectValue; + QWidget widgetValue; + COPY_TEST(QObject *, QObjectStar, &objectValue, 0); + COPY_TEST(QWidget *, QWidgetStar, &widgetValue, 0); + COPY_TEST(qreal, QReal, 10.2, 0); + + +#if 0 + enum Type { + + QReal = 0, + User = 256 + }; +#endif +} + +QTEST_MAIN(tst_qmlmetatype) + +#include "tst_qmlmetatype.moc" -- cgit v0.12 From d5c34887e0a563511ff124b497e5e869a64cda34 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 3 Nov 2009 19:14:58 +1000 Subject: Fix incorrect assert QT-2432 --- src/declarative/qml/qmlcompiler.cpp | 2 +- tests/auto/declarative/qmllanguage/data/crash2.qml | 5 +++++ tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qmllanguage/data/crash2.qml diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index b93a9b3..3253e72 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -2366,7 +2366,7 @@ bool QmlCompiler::buildBinding(QmlParser::Value *value, QmlParser::Property *prop, const BindingContext &ctxt) { - Q_ASSERT(prop->index); + Q_ASSERT(prop->index != -1); Q_ASSERT(prop->parent); Q_ASSERT(prop->parent->metaObject()); diff --git a/tests/auto/declarative/qmllanguage/data/crash2.qml b/tests/auto/declarative/qmllanguage/data/crash2.qml new file mode 100644 index 0000000..ae6f650 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/crash2.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +Object { + objectName: "Hello" + "World" +} diff --git a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp index 128fa87..da586d9 100644 --- a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp +++ b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp @@ -123,6 +123,7 @@ private slots: // regression tests for crashes void crash1(); + void crash2(); private: QmlEngine engine; @@ -1152,6 +1153,11 @@ void tst_qmllanguage::crash1() QmlComponent component(&engine, "Component {}"); } +void tst_qmllanguage::crash2() +{ + QmlComponent component(&engine, TEST_FILE("crash2.qml")); +} + QTEST_MAIN(tst_qmllanguage) #include "tst_qmllanguage.moc" -- cgit v0.12 From 337263994aafa64fd96d503d49a8a3316bdb1827 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 3 Nov 2009 19:16:18 +1000 Subject: Remove dead code --- tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp b/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp index 06a47c0..ed102a5 100644 --- a/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp +++ b/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp @@ -204,15 +204,6 @@ void tst_qmlmetatype::copy() COPY_TEST(QObject *, QObjectStar, &objectValue, 0); COPY_TEST(QWidget *, QWidgetStar, &widgetValue, 0); COPY_TEST(qreal, QReal, 10.2, 0); - - -#if 0 - enum Type { - - QReal = 0, - User = 256 - }; -#endif } QTEST_MAIN(tst_qmlmetatype) -- cgit v0.12 From a36694346164f0865e16003745839279dad7f61e Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 3 Nov 2009 19:16:37 +1000 Subject: qfxtext -> qmlgraphicstext --- tests/auto/declarative/declarative.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 26e8346..73269e1 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -11,7 +11,6 @@ SUBDIRS += anchors \ pathview \ qfxloader \ qfxpixmapcache \ - qfxtext \ qfxtextedit \ qfxtextinput \ qfxwebview \ @@ -19,6 +18,7 @@ SUBDIRS += anchors \ qmlcontext \ qmldom \ qmlecmascript \ + qmlgraphicstext \ qmllanguage \ qmllist \ qmllistaccessor \ -- cgit v0.12 From d1a1d5df2ec9e34cdbed340685fc8e8dd8e9bece Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 26 Oct 2009 12:40:33 +0100 Subject: introduce int QTextDocument::available{Undo,Redo}Steps() const; Formerly, QTextDocument::revision() could be used to guesstimate the number of available undo steps that was used in Qt Creator to store cursor positions in parallel to the actual text contents. Now that revision() is strictly increasing, another means is needed, therefore the new functions providing the needed data. Reviewed-by: mae --- src/gui/text/qtextdocument.cpp | 27 +++++++++++++++++++++++++++ src/gui/text/qtextdocument.h | 3 +++ src/gui/text/qtextdocument_p.h | 3 +++ 3 files changed, 33 insertions(+) diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 6978b6c..1aad385 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -958,6 +958,8 @@ QString QTextDocument::defaultStyleSheet() const /*! Returns true if undo is available; otherwise returns false. + + \sa isRedoAvailable(), availableUndoSteps() */ bool QTextDocument::isUndoAvailable() const { @@ -967,6 +969,8 @@ bool QTextDocument::isUndoAvailable() const /*! Returns true if redo is available; otherwise returns false. + + \sa isUndoAvailable(), availableRedoSteps() */ bool QTextDocument::isRedoAvailable() const { @@ -974,6 +978,29 @@ bool QTextDocument::isRedoAvailable() const return d->isRedoAvailable(); } +/*! \since 4.6 + + Returns the number of available undo steps. + + \sa isUndoAvailable() +*/ +int QTextDocument::availableUndoSteps() const +{ + Q_D(const QTextDocument); + return d->availableUndoSteps(); +} + +/*! \since 4.6 + + Returns the number of available redo steps. + + \sa isRedoAvailable() +*/ +int QTextDocument::availableRedoSteps() const +{ + Q_D(const QTextDocument); + return d->availableRedoSteps(); +} /*! \since 4.4 diff --git a/src/gui/text/qtextdocument.h b/src/gui/text/qtextdocument.h index e52716a..d217a4d 100644 --- a/src/gui/text/qtextdocument.h +++ b/src/gui/text/qtextdocument.h @@ -142,6 +142,9 @@ public: bool isUndoAvailable() const; bool isRedoAvailable() const; + int availableUndoSteps() const; + int availableRedoSteps() const; + int revision() const; void setDocumentLayout(QAbstractTextDocumentLayout *layout); diff --git a/src/gui/text/qtextdocument_p.h b/src/gui/text/qtextdocument_p.h index ce25c57..c10855b 100644 --- a/src/gui/text/qtextdocument_p.h +++ b/src/gui/text/qtextdocument_p.h @@ -212,6 +212,9 @@ public: inline bool isUndoAvailable() const { return undoEnabled && undoState > 0; } inline bool isRedoAvailable() const { return undoEnabled && undoState < undoStack.size(); } + inline int availableUndoSteps() const { return undoEnabled ? undoState : 0; } + inline int availableRedoSteps() const { return undoEnabled ? qMax(undoStack.size() - undoState - 1, 0) : 0; } + inline QString buffer() const { return text; } QString plainText() const; inline int length() const { return fragments.length(); } -- cgit v0.12 From 356fe6a0474c07dc6dd8ffd9b52f1e2060e3a450 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 4 Nov 2009 08:28:17 +1000 Subject: Add missing files. --- tests/auto/declarative/animatedimage/data/stickman.qml | 5 +++++ tests/auto/declarative/animatedimage/data/stickmanpause.qml | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 tests/auto/declarative/animatedimage/data/stickman.qml create mode 100644 tests/auto/declarative/animatedimage/data/stickmanpause.qml diff --git a/tests/auto/declarative/animatedimage/data/stickman.qml b/tests/auto/declarative/animatedimage/data/stickman.qml new file mode 100644 index 0000000..a70db5d --- /dev/null +++ b/tests/auto/declarative/animatedimage/data/stickman.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +AnimatedImage { + source: "stickman.gif" +} diff --git a/tests/auto/declarative/animatedimage/data/stickmanpause.qml b/tests/auto/declarative/animatedimage/data/stickmanpause.qml new file mode 100644 index 0000000..7ab17d4 --- /dev/null +++ b/tests/auto/declarative/animatedimage/data/stickmanpause.qml @@ -0,0 +1,7 @@ +import Qt 4.6 + +AnimatedImage { + source: "stickman.gif" + paused: true + currentFrame: 2 +} -- cgit v0.12