summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/extra/qmlfontloader.cpp2
-rw-r--r--src/declarative/graphicsitems/qmlgraphicstext.cpp4
-rw-r--r--src/declarative/qml/qmlcompiler.cpp2
-rw-r--r--src/gui/text/qtextdocument.cpp27
-rw-r--r--src/gui/text/qtextdocument.h3
-rw-r--r--src/gui/text/qtextdocument_p.h3
-rw-r--r--tests/auto/declarative/animatedimage/data/stickman.qml5
-rw-r--r--tests/auto/declarative/animatedimage/data/stickmanpause.qml7
-rw-r--r--tests/auto/declarative/behaviors/tst_behaviors.cpp8
-rw-r--r--tests/auto/declarative/declarative.pro4
-rw-r--r--tests/auto/declarative/qmlfontloader/data/dummy.ttf0
-rw-r--r--tests/auto/declarative/qmlfontloader/qmlfontloader.pro3
-rw-r--r--tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp65
-rw-r--r--tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp47
-rw-r--r--tests/auto/declarative/qmllanguage/data/crash2.qml5
-rw-r--r--tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp6
-rw-r--r--tests/auto/declarative/qmlmetatype/qmlmetatype.pro6
-rw-r--r--tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp211
-rw-r--r--tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp18
19 files changed, 404 insertions, 22 deletions
diff --git a/src/declarative/extra/qmlfontloader.cpp b/src/declarative/extra/qmlfontloader.cpp
index 8c17d0f..e8db649 100644
--- a/src/declarative/extra/qmlfontloader.cpp
+++ b/src/declarative/extra/qmlfontloader.cpp
@@ -163,6 +163,8 @@ void QmlFontLoader::setName(const QString &name)
return;
d->name = name;
emit nameChanged();
+ d->status = Ready;
+ emit statusChanged();
}
/*!
diff --git a/src/declarative/graphicsitems/qmlgraphicstext.cpp b/src/declarative/graphicsitems/qmlgraphicstext.cpp
index 6790923..d640fc9 100644
--- a/src/declarative/graphicsitems/qmlgraphicstext.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicstext.cpp
@@ -534,7 +534,7 @@ void QmlGraphicsTextPrivate::updateSize()
void QmlGraphicsTextPrivate::drawOutline()
{
- QPixmap img = QPixmap(imgCache.size());
+ QPixmap img = QPixmap(imgStyleCache.width()+2,imgStyleCache.height()+2);
img.fill(Qt::transparent);
QPainter ppm(&img);
@@ -558,7 +558,7 @@ void QmlGraphicsTextPrivate::drawOutline()
void QmlGraphicsTextPrivate::drawOutline(int yOffset)
{
- QPixmap img = QPixmap(imgCache.size());
+ QPixmap img = QPixmap(imgStyleCache.width()+2,imgStyleCache.height()+2);
img.fill(Qt::transparent);
QPainter ppm(&img);
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/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(); }
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
+}
diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp
index 29c631d..da910d9 100644
--- a/tests/auto/declarative/behaviors/tst_behaviors.cpp
+++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp
@@ -225,11 +225,9 @@ void tst_behaviors::reassignedAnimation()
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
+ QCOMPARE(qobject_cast<QmlNumberAnimation*>(
+ qobject_cast<QmlBehavior*>(
+ rect->findChild<QmlBehavior*>("MyBehavior"))->animation())->duration(), 200);
}
QTEST_MAIN(tst_behaviors)
diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro
index 0d55391..86cf175 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,10 +18,13 @@ SUBDIRS += anchors \
qmlcontext \
qmldom \
qmlecmascript \
+ qmlgraphicstext \
+ qmlfontloader \
qmllanguage \
qmllist \
qmllistaccessor \
qmlmetaproperty \
+ qmlmetatype \
qmlpropertymap \
qmltimer \
repeater \
diff --git a/tests/auto/declarative/qmlfontloader/data/dummy.ttf b/tests/auto/declarative/qmlfontloader/data/dummy.ttf
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/auto/declarative/qmlfontloader/data/dummy.ttf
diff --git a/tests/auto/declarative/qmlfontloader/qmlfontloader.pro b/tests/auto/declarative/qmlfontloader/qmlfontloader.pro
index 0ecfde0..bc89639 100644
--- a/tests/auto/declarative/qmlfontloader/qmlfontloader.pro
+++ b/tests/auto/declarative/qmlfontloader/qmlfontloader.pro
@@ -3,3 +3,6 @@ contains(QT_CONFIG,declarative): QT += declarative gui
macx:CONFIG -= app_bundle
SOURCES += tst_qmlfontloader.cpp
+
+# Define SRCDIR equal to test's source directory
+DEFINES += SRCDIR=\\\"$$PWD\\\"
diff --git a/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp
index a65ecf4..efc86cd 100644
--- a/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp
+++ b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp
@@ -42,6 +42,7 @@
#include <QtDeclarative/qmlengine.h>
#include <QtDeclarative/qmlcomponent.h>
#include <private/qmlfontloader_p.h>
+#include "../../../shared/util.h"
class tst_qmlfontloader : public QObject
@@ -51,8 +52,12 @@ public:
tst_qmlfontloader();
private slots:
- void namedfont();
- void localfont();
+ void noFont();
+ void namedFont();
+ void localFont();
+ void failLocalFont();
+ void webFont();
+ void failWebFont();
private slots:
@@ -64,7 +69,20 @@ tst_qmlfontloader::tst_qmlfontloader()
{
}
-void tst_qmlfontloader::namedfont()
+void tst_qmlfontloader::noFont()
+{
+ QString componentStr = "import Qt 4.6\nFontLoader { }";
+ QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://"));
+ QmlFontLoader *fontObject = qobject_cast<QmlFontLoader*>(component.create());
+
+ QVERIFY(fontObject != 0);
+ QCOMPARE(fontObject->name(), QString(""));
+ QTRY_VERIFY(fontObject->status() == QmlFontLoader::Null);
+
+ delete fontObject;
+}
+
+void tst_qmlfontloader::namedFont()
{
QString componentStr = "import Qt 4.6\nFontLoader { name: \"Helvetica\" }";
QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://"));
@@ -72,16 +90,51 @@ void tst_qmlfontloader::namedfont()
QVERIFY(fontObject != 0);
QCOMPARE(fontObject->name(), QString("Helvetica"));
+ QTRY_VERIFY(fontObject->status() == QmlFontLoader::Ready);
+}
+
+void tst_qmlfontloader::localFont()
+{
+ QString componentStr = "import Qt 4.6\nFontLoader { source: \"" SRCDIR "/data/Fontin-Bold.ttf\" }";
+ QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://"));
+ QmlFontLoader *fontObject = qobject_cast<QmlFontLoader*>(component.create());
+
+ QVERIFY(fontObject != 0);
+ QTRY_COMPARE(fontObject->name(), QString("Fontin"));
+ QTRY_VERIFY(fontObject->status() == QmlFontLoader::Ready);
+}
+
+void tst_qmlfontloader::failLocalFont()
+{
+ QString componentStr = "import Qt 4.6\nFontLoader { source: \"" SRCDIR "/data/dummy.ttf\" }";
+ QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://"));
+ QmlFontLoader *fontObject = qobject_cast<QmlFontLoader*>(component.create());
+
+ QVERIFY(fontObject != 0);
+ QTRY_COMPARE(fontObject->name(), QString(""));
+ QTRY_VERIFY(fontObject->status() == QmlFontLoader::Error);
+}
+
+void tst_qmlfontloader::webFont()
+{
+ QString componentStr = "import Qt 4.6\nFontLoader { source: \"http://www.princexml.com/fonts/steffmann/Starburst.ttf\" }";
+ QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://"));
+ QmlFontLoader *fontObject = qobject_cast<QmlFontLoader*>(component.create());
+
+ QVERIFY(fontObject != 0);
+ QTRY_COMPARE(fontObject->name(), QString("Starburst"));
+ QTRY_VERIFY(fontObject->status() == QmlFontLoader::Ready);
}
-void tst_qmlfontloader::localfont()
+void tst_qmlfontloader::failWebFont()
{
- QString componentStr = "import Qt 4.6\nFontLoader { source: \"data/Fontin-Bold.ttf\" }";
+ QString componentStr = "import Qt 4.6\nFontLoader { source: \"http://wrong.address.com/Starburst.ttf\" }";
QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://"));
QmlFontLoader *fontObject = qobject_cast<QmlFontLoader*>(component.create());
QVERIFY(fontObject != 0);
- QCOMPARE(fontObject->name(), QString("Fontin"));
+ QTRY_COMPARE(fontObject->name(), QString(""));
+ QTRY_VERIFY(fontObject->status() == QmlFontLoader::Error);
}
QTEST_MAIN(tst_qmlfontloader)
diff --git a/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp
index d53de59..b9c12ee 100644
--- a/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp
+++ b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp
@@ -57,6 +57,7 @@ private slots:
void width();
void wrap();
void elide();
+ void textFormat();
// ### these tests may be trivial
void horizontalAlignment();
@@ -145,6 +146,9 @@ void tst_qmlgraphicstext::text()
QVERIFY(textObject != 0);
QCOMPARE(textObject->text(), QString(""));
+ QVERIFY(textObject->width() == 0);
+
+ delete textObject;
}
for (int i = 0; i < standard.size(); i++)
@@ -155,6 +159,7 @@ void tst_qmlgraphicstext::text()
QVERIFY(textObject != 0);
QCOMPARE(textObject->text(), standard.at(i));
+ QVERIFY(textObject->width() > 0);
}
for (int i = 0; i < richText.size(); i++)
@@ -166,6 +171,7 @@ void tst_qmlgraphicstext::text()
QVERIFY(textObject != 0);
QString expected = richText.at(i);
QCOMPARE(textObject->text(), expected.replace("\\\"", "\""));
+ QVERIFY(textObject->width() > 0);
}
}
@@ -176,6 +182,7 @@ void tst_qmlgraphicstext::width()
QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\" }", QUrl("file://"));
QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create());
+ QVERIFY(textObject != 0);
QCOMPARE(textObject->width(), 0.);
}
@@ -189,7 +196,9 @@ void tst_qmlgraphicstext::width()
QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://"));
QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create());
+ QVERIFY(textObject != 0);
QCOMPARE(textObject->width(), qreal(metricWidth));
+ QVERIFY(textObject->textFormat() == QmlGraphicsText::PlainText);
}
for (int i = 0; i < richText.size(); i++)
@@ -204,7 +213,9 @@ void tst_qmlgraphicstext::width()
QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://"));
QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create());
+ QVERIFY(textObject != 0);
QCOMPARE(textObject->width(), qreal(documentWidth));
+ QVERIFY(textObject->textFormat() == QmlGraphicsText::RichText);
}
}
@@ -217,6 +228,8 @@ void tst_qmlgraphicstext::wrap()
QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create());
textHeight = textObject->height();
+ QVERIFY(textObject != 0);
+ QVERIFY(textObject->wrap() == true);
QCOMPARE(textObject->width(), 300.);
}
@@ -226,6 +239,7 @@ void tst_qmlgraphicstext::wrap()
QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://"));
QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create());
+ QVERIFY(textObject != 0);
QCOMPARE(textObject->width(), 30.);
QVERIFY(textObject->height() > textHeight);
}
@@ -236,6 +250,7 @@ void tst_qmlgraphicstext::wrap()
QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://"));
QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create());
+ QVERIFY(textObject != 0);
QCOMPARE(textObject->width(), 30.);
QVERIFY(textObject->height() > textHeight);
}
@@ -246,38 +261,56 @@ void tst_qmlgraphicstext::elide()
{
for (Qt::TextElideMode m = Qt::ElideLeft; m<=Qt::ElideNone; m=Qt::TextElideMode(int(m)+1)) {
const char* elidename[]={"ElideLeft", "ElideRight", "ElideMiddle", "ElideNone"};
- QString elide = "elide: \""+QString(elidename[int(m)])+"\";";
+ QString elide = "elide: Text." + QString(elidename[int(m)]) + ";";
// XXX Poor coverage.
{
- QmlComponent textComponent(&engine, ("import Qt 4.6\nText { text: \"\"; "+elide+" width: 300 }").toLatin1(), QUrl("file://"));
+ QmlComponent textComponent(&engine, ("import Qt 4.6\nText { text: \"\"; "+elide+" width: 100 }").toLatin1(), QUrl("file://"));
QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create());
- QCOMPARE(textObject->width(), 300.);
+ QCOMPARE(textObject->width(), 100.);
}
for (int i = 0; i < standard.size(); i++)
{
- QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + standard.at(i) + "\" }";
+ QString componentStr = "import Qt 4.6\nText { "+elide+" width: 100; text: \"" + standard.at(i) + "\" }";
QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://"));
QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create());
- QCOMPARE(textObject->width(), 300.);
+ QCOMPARE(textObject->width(), 100.);
}
// richtext - does nothing
for (int i = 0; i < richText.size(); i++)
{
- QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + richText.at(i) + "\" }";
+ QString componentStr = "import Qt 4.6\nText { "+elide+" width: 100; text: \"" + richText.at(i) + "\" }";
QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://"));
QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create());
- QCOMPARE(textObject->width(), 300.);
+ QCOMPARE(textObject->width(), 100.);
}
}
}
+void tst_qmlgraphicstext::textFormat()
+{
+ {
+ QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"Hello\"; textFormat: Text.RichText }", QUrl("file://"));
+ QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create());
+
+ QVERIFY(textObject != 0);
+ QVERIFY(textObject->textFormat() == QmlGraphicsText::RichText);
+ }
+ {
+ QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"<b>Hello</b>\"; textFormat: Text.PlainText }", QUrl("file://"));
+ QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create());
+
+ QVERIFY(textObject != 0);
+ QVERIFY(textObject->textFormat() == QmlGraphicsText::PlainText);
+ }
+}
+
//the alignment tests may be trivial o.oa
void tst_qmlgraphicstext::horizontalAlignment()
{
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"
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..ed102a5
--- /dev/null
+++ b/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp
@@ -0,0 +1,211 @@
+/****************************************************************************
+**
+** 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 <QmlMetaType>
+#include <QLocale>
+#include <QPixmap>
+#include <QBitmap>
+#include <QPen>
+#include <QTextLength>
+#include <QMatrix4x4>
+#include <QVector2D>
+#include <QVector3D>
+#include <QVector4D>
+#include <QQuaternion>
+
+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);
+}
+
+QTEST_MAIN(tst_qmlmetatype)
+
+#include "tst_qmlmetatype.moc"
diff --git a/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp b/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp
index a7211bd..9be77e8 100644
--- a/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp
+++ b/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp
@@ -55,6 +55,7 @@ public:
private slots:
void insert();
void operatorInsert();
+ void operatorValue();
void clear();
void changed();
void count();
@@ -66,6 +67,7 @@ void tst_QmlPropertyMap::insert()
map.insert(QLatin1String("key1"),100);
map.insert(QLatin1String("key2"),200);
QVERIFY(map.keys().count() == 2);
+ QVERIFY(map.contains(QLatin1String("key1")));
QCOMPARE(map.value(QLatin1String("key1")), QVariant(100));
QCOMPARE(map.value(QLatin1String("key2")), QVariant(200));
@@ -88,6 +90,20 @@ void tst_QmlPropertyMap::operatorInsert()
QCOMPARE(map.value(QLatin1String("key1")), QVariant("Hello World"));
}
+void tst_QmlPropertyMap::operatorValue()
+{
+ QmlPropertyMap map;
+ map.insert(QLatin1String("key1"),100);
+ map.insert(QLatin1String("key2"),200);
+ QVERIFY(map.keys().count() == 2);
+ QVERIFY(map.contains(QLatin1String("key1")));
+
+ QCOMPARE(map.value(QLatin1String("key1")), QVariant(100));
+ QCOMPARE(map.value(QLatin1String("key2")), QVariant(200));
+ QCOMPARE(map[QLatin1String("key1")], map.value(QLatin1String("key1")));
+ QCOMPARE(map[QLatin1String("key2")], map.value(QLatin1String("key2")));
+}
+
void tst_QmlPropertyMap::clear()
{
QmlPropertyMap map;
@@ -98,6 +114,7 @@ void tst_QmlPropertyMap::clear()
map.clear(QLatin1String("key1"));
QVERIFY(map.keys().count() == 1);
+ QVERIFY(map.contains(QLatin1String("key1")));
QCOMPARE(map.value(QLatin1String("key1")), QVariant());
}
@@ -143,6 +160,7 @@ void tst_QmlPropertyMap::count()
//clearing doesn't remove the key
map.clear(QLatin1String("key3"));
QCOMPARE(map.count(), 3);
+ QCOMPARE(map.size(), map.count());
}
QTEST_MAIN(tst_QmlPropertyMap)