summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2009-10-30 05:24:51 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2009-10-30 05:24:51 (GMT)
commit46eec6d54bad7a686b3dd5cd6e4aa8577d38740d (patch)
treee4c828d1d1456b3fafe74a339562263b3f2c156d /tests
parentd85d7addc5084ee7d5de31dec562437f9c31c35d (diff)
parentd788c0127b86d8245aa0a8e2472562f444d98ee9 (diff)
downloadQt-46eec6d54bad7a686b3dd5cd6e4aa8577d38740d.zip
Qt-46eec6d54bad7a686b3dd5cd6e4aa8577d38740d.tar.gz
Qt-46eec6d54bad7a686b3dd5cd6e4aa8577d38740d.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Conflicts: src/declarative/qml/qmlcomponentjs.cpp src/declarative/qml/qmlcomponentjs_p.h src/declarative/qml/qmlcomponentjs_p_p.h
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/listview/data/listview.qml1
-rw-r--r--tests/auto/declarative/qmlecmascript/data/shutdownErrors.qml13
-rw-r--r--tests/auto/declarative/qmlecmascript/testtypes.h1
-rw-r--r--tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp17
-rw-r--r--tests/auto/declarative/qmllanguage/testtypes.h1
-rw-r--r--tests/auto/networkselftest/tst_networkselftest.cpp5
-rw-r--r--tests/auto/qabstractslider/tst_qabstractslider.cpp16
-rw-r--r--tests/auto/qalgorithms/tst_qalgorithms.cpp17
-rw-r--r--tests/auto/qapplication/tst_qapplication.cpp63
-rw-r--r--tests/auto/qcombobox/tst_qcombobox.cpp33
-rw-r--r--tests/auto/qcompleter/tst_qcompleter.cpp2
-rw-r--r--tests/auto/qdatawidgetmapper/tst_qdatawidgetmapper.cpp2
-rw-r--r--tests/auto/qdockwidget/tst_qdockwidget.cpp19
-rw-r--r--tests/auto/qfontmetrics/tst_qfontmetrics.cpp14
-rw-r--r--tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp259
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp177
-rw-r--r--tests/auto/qgraphicsobject/tst_qgraphicsobject.cpp42
-rw-r--r--tests/auto/qgraphicssceneindex/tst_qgraphicssceneindex.cpp58
-rw-r--r--tests/auto/qgraphicsview/tst_qgraphicsview.cpp55
-rw-r--r--tests/auto/qlistview/tst_qlistview.cpp3
-rw-r--r--tests/auto/qlistwidget/tst_qlistwidget.cpp59
-rw-r--r--tests/auto/qmenubar/tst_qmenubar.cpp29
-rw-r--r--tests/auto/qparallelanimationgroup/tst_qparallelanimationgroup.cpp17
-rw-r--r--tests/auto/qpauseanimation/tst_qpauseanimation.cpp53
-rw-r--r--tests/auto/qpixmap/tst_qpixmap.cpp21
-rw-r--r--tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp14
-rw-r--r--tests/auto/qscriptengine/tst_qscriptengine.cpp45
-rw-r--r--tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp85
-rw-r--r--tests/auto/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp13
-rw-r--r--tests/auto/qsoftkeymanager/tst_qsoftkeymanager.cpp25
-rw-r--r--tests/auto/qsound/tst_qsound.cpp2
-rw-r--r--tests/auto/qsplitter/tst_qsplitter.cpp34
-rw-r--r--tests/auto/qsqlquery/tst_qsqlquery.cpp56
-rw-r--r--tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp18
-rw-r--r--tests/auto/qstring/tst_qstring.cpp9
-rw-r--r--tests/auto/qtableview/tst_qtableview.cpp49
-rw-r--r--tests/auto/qtcpsocket/tst_qtcpsocket.cpp14
-rw-r--r--tests/auto/qtextdocument/qtextdocument.pro1
-rw-r--r--tests/auto/qtextdocument/tst_qtextdocument.cpp56
-rw-r--r--tests/auto/qtreeview/tst_qtreeview.cpp69
-rw-r--r--tests/auto/qvariant/tst_qvariant.cpp253
-rw-r--r--tests/auto/qwidget/tst_qwidget.cpp44
42 files changed, 1629 insertions, 135 deletions
diff --git a/tests/auto/declarative/listview/data/listview.qml b/tests/auto/declarative/listview/data/listview.qml
index 5083329..9039b55 100644
--- a/tests/auto/declarative/listview/data/listview.qml
+++ b/tests/auto/declarative/listview/data/listview.qml
@@ -31,6 +31,7 @@ Rectangle {
x: 200
text: wrapper.y
}
+ color: ListView.isCurrentItem ? "lightsteelblue" : "white"
}
}
]
diff --git a/tests/auto/declarative/qmlecmascript/data/shutdownErrors.qml b/tests/auto/declarative/qmlecmascript/data/shutdownErrors.qml
new file mode 100644
index 0000000..398489a
--- /dev/null
+++ b/tests/auto/declarative/qmlecmascript/data/shutdownErrors.qml
@@ -0,0 +1,13 @@
+import Qt 4.6
+
+Item {
+ property int test: myObject.object.a
+
+ Item {
+ id: myObject
+ property Object object;
+ object: Object {
+ property int a: 10
+ }
+ }
+}
diff --git a/tests/auto/declarative/qmlecmascript/testtypes.h b/tests/auto/declarative/qmlecmascript/testtypes.h
index 88616096..d566681 100644
--- a/tests/auto/declarative/qmlecmascript/testtypes.h
+++ b/tests/auto/declarative/qmlecmascript/testtypes.h
@@ -135,6 +135,7 @@ private:
QList<QObject *> m_objectQList;
};
+QML_DECLARE_TYPEINFO(MyQmlObject, QML_HAS_ATTACHED_PROPERTIES)
QML_DECLARE_TYPE(MyQmlObject);
class MyQmlContainer : public QObject
diff --git a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp
index a788109..3e98c69 100644
--- a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp
+++ b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp
@@ -107,6 +107,7 @@ private slots:
void listProperties();
void exceptionClearsOnReeval();
void transientErrors();
+ void shutdownErrors();
private:
QmlEngine engine;
@@ -910,6 +911,22 @@ void tst_qmlecmascript::transientErrors()
QCOMPARE(transientErrorsMsgCount, 0);
}
+// Check that errors during shutdown are minimized
+void tst_qmlecmascript::shutdownErrors()
+{
+ QmlComponent component(&engine, TEST_FILE("shutdownErrors.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ transientErrorsMsgCount = 0;
+ QtMsgHandler old = qInstallMsgHandler(transientErrorsMsgHandler);
+
+ delete object;
+
+ qInstallMsgHandler(old);
+ QCOMPARE(transientErrorsMsgCount, 0);
+}
+
QTEST_MAIN(tst_qmlecmascript)
#include "tst_qmlecmascript.moc"
diff --git a/tests/auto/declarative/qmllanguage/testtypes.h b/tests/auto/declarative/qmllanguage/testtypes.h
index ace86f0..91c6e2e 100644
--- a/tests/auto/declarative/qmllanguage/testtypes.h
+++ b/tests/auto/declarative/qmllanguage/testtypes.h
@@ -151,6 +151,7 @@ private:
MyQmlObject *m_qmlobject;
MyCustomVariantType m_custom;
};
+QML_DECLARE_TYPEINFO(MyQmlObject, QML_HAS_ATTACHED_PROPERTIES)
QML_DECLARE_TYPE(MyQmlObject);
class MyGroupedObject : public QObject
diff --git a/tests/auto/networkselftest/tst_networkselftest.cpp b/tests/auto/networkselftest/tst_networkselftest.cpp
index d58402b..a09d998 100644
--- a/tests/auto/networkselftest/tst_networkselftest.cpp
+++ b/tests/auto/networkselftest/tst_networkselftest.cpp
@@ -333,6 +333,11 @@ QHostAddress tst_NetworkSelfTest::serverIpAddress()
if (cachedIpAddress.protocol() == QAbstractSocket::UnknownNetworkLayerProtocol) {
// need resolving
QHostInfo resolved = QHostInfo::fromName(QtNetworkSettings::serverName());
+ if(resolved.error() != QHostInfo::NoError ||
+ !resolved.addresses().isEmpty()) {
+ qWarning("QHostInfo::fromName failed (%d).", resolved.error());
+ return QHostAddress(QHostAddress::Null);
+ }
cachedIpAddress = resolved.addresses().first();
}
return cachedIpAddress;
diff --git a/tests/auto/qabstractslider/tst_qabstractslider.cpp b/tests/auto/qabstractslider/tst_qabstractslider.cpp
index 5c70bde..d9574df 100644
--- a/tests/auto/qabstractslider/tst_qabstractslider.cpp
+++ b/tests/auto/qabstractslider/tst_qabstractslider.cpp
@@ -714,11 +714,7 @@ void tst_QAbstractSlider::wheelEvent_data()
<< 1 // delta
<< int(Qt::Vertical) // orientation of slider
<< int(Qt::Vertical) // orientation of wheel
-#ifdef Q_WS_MAC
- << 1 // expected position after
-#else
<< 20 // expected position after
-#endif
<< QPoint(0,0);
QTest::newRow("Normal data page") << 0 // initial position
@@ -777,11 +773,7 @@ void tst_QAbstractSlider::wheelEvent_data()
<< 1 // delta
<< int(Qt::Horizontal) // orientation of slider
<< int(Qt::Horizontal) // orientation of wheel
-#ifdef Q_WS_MAC
- << 49 // expected position after
-#else
<< 30 // expected position after
-#endif
<< QPoint(1,1);
QTest::newRow("Past end") << 50 // initial position
@@ -792,11 +784,7 @@ void tst_QAbstractSlider::wheelEvent_data()
<< false // inverted controls
<< 1 // wheel scroll lines
<< false // with modifiers
-#ifdef Q_WS_MAC
- << 60 // delta
-#else
<< 2 // delta
-#endif
<< int(Qt::Horizontal) // orientation of slider
<< int(Qt::Horizontal) // orientation of wheel
<< 100 // expected position after
@@ -810,11 +798,7 @@ void tst_QAbstractSlider::wheelEvent_data()
<< false // inverted controls
<< 1 // wheel scroll lines
<< false // with modifiers
-#ifdef Q_WS_MAC
- << -60 // delta
-#else
<< -2 // delta
-#endif
<< int(Qt::Horizontal) // orientation of slider
<< int(Qt::Horizontal) // orientation of wheel
<< 0 // expected position after
diff --git a/tests/auto/qalgorithms/tst_qalgorithms.cpp b/tests/auto/qalgorithms/tst_qalgorithms.cpp
index 1f1de82..176a451 100644
--- a/tests/auto/qalgorithms/tst_qalgorithms.cpp
+++ b/tests/auto/qalgorithms/tst_qalgorithms.cpp
@@ -602,9 +602,15 @@ void tst_QAlgorithms::test_qUpperBound()
void tst_QAlgorithms::test_qBinaryFind_data()
{
QTest::addColumn<QList<int> >("data");
- QTest::addColumn<int>("resultValue");
+ QTest::addColumn<int>("resultValue"); // -42 means not found
QTest::newRow("sorted-duplicate") << (QList<int>() << 1 << 2 << 2 << 3) << 2;
+ QTest::newRow("sorted-end") << (QList<int>() << -5 << -2 << 0 << 8) << 8;
+ QTest::newRow("sorted-beginning") << (QList<int>() << -5 << -2 << 0 << 8) << -5;
+ QTest::newRow("sorted-duplicate-beginning") << (QList<int>() << -5 << -5 << -2 << 0 << 8) << -5;
+ QTest::newRow("empty") << (QList<int>()) << -42;
+ QTest::newRow("not found 1 ") << (QList<int>() << 1 << 5 << 8 << 65) << -42;
+ QTest::newRow("not found 2 ") << (QList<int>() << -456 << -5 << 8 << 65) << -42;
}
void tst_QAlgorithms::test_qBinaryFind()
@@ -612,6 +618,15 @@ void tst_QAlgorithms::test_qBinaryFind()
QFETCH(QList<int>, data);
QFETCH(int, resultValue);
+ //-42 means not found
+ if (resultValue == -42) {
+ QVERIFY(qBinaryFind(data.constBegin(), data.constEnd(), resultValue) == data.end());
+ QVERIFY(qBinaryFind(data, resultValue) == data.end());
+ QVERIFY(qBinaryFind(data.begin(), data.end(), resultValue) == data.end());
+ QVERIFY(qBinaryFind(data.begin(), data.end(), resultValue, qLess<int>()) == data.end());
+ return;
+ }
+
QCOMPARE(*qBinaryFind(data.constBegin(), data.constEnd(), resultValue), resultValue);
QCOMPARE(*qBinaryFind(data.begin(), data.end(), resultValue), resultValue);
QCOMPARE(*qBinaryFind(data, resultValue), resultValue);
diff --git a/tests/auto/qapplication/tst_qapplication.cpp b/tests/auto/qapplication/tst_qapplication.cpp
index 97aa092..675e559 100644
--- a/tests/auto/qapplication/tst_qapplication.cpp
+++ b/tests/auto/qapplication/tst_qapplication.cpp
@@ -136,6 +136,9 @@ private slots:
void windowsCommandLine();
void touchEventPropagation();
+
+ void symbianNeedForTraps();
+ void symbianLeaveThroughMain();
};
class EventSpy : public QObject
@@ -2011,6 +2014,66 @@ void tst_QApplication::touchEventPropagation()
}
}
+#ifdef Q_OS_SYMBIAN
+class CBaseDummy : public CBase
+{
+public:
+ CBaseDummy(int *numDestroyed) : numDestroyed(numDestroyed)
+ {
+ }
+ ~CBaseDummy()
+ {
+ (*numDestroyed)++;
+ }
+
+private:
+ int *numDestroyed;
+};
+
+static void fakeMain(int *numDestroyed)
+{
+ // Push a few objects, just so that the cleanup stack has something to clean up.
+ CleanupStack::PushL(new (ELeave) CBaseDummy(numDestroyed));
+ int argc = 0;
+ QApplication app(argc, 0);
+ CleanupStack::PushL(new (ELeave) CBaseDummy(numDestroyed));
+
+ User::Leave(KErrGeneral); // Fake error
+}
+#endif
+
+void tst_QApplication::symbianNeedForTraps()
+{
+#ifndef Q_OS_SYMBIAN
+ QSKIP("This is a Symbian-only test", SkipAll);
+#else
+ int argc = 0;
+ QApplication app(argc, 0);
+ int numDestroyed = 0;
+
+ // This next part should not require a trap. If it does, the test will crash.
+ CleanupStack::PushL(new (ELeave) CBaseDummy(&numDestroyed));
+ CleanupStack::PopAndDestroy();
+
+ QCOMPARE(numDestroyed, 1);
+
+ // No other failure condition. The program will crash if it does not pass.
+#endif
+}
+
+void tst_QApplication::symbianLeaveThroughMain()
+{
+#ifndef Q_OS_SYMBIAN
+ QSKIP("This is a Symbian-only test", SkipAll);
+#else
+ int numDestroyed = 0;
+ TInt err;
+ TRAP(err, fakeMain(&numDestroyed));
+
+ QCOMPARE(numDestroyed, 2);
+#endif
+}
+
//QTEST_APPLESS_MAIN(tst_QApplication)
int main(int argc, char *argv[])
{
diff --git a/tests/auto/qcombobox/tst_qcombobox.cpp b/tests/auto/qcombobox/tst_qcombobox.cpp
index 0d3469d..8acae7a 100644
--- a/tests/auto/qcombobox/tst_qcombobox.cpp
+++ b/tests/auto/qcombobox/tst_qcombobox.cpp
@@ -152,6 +152,7 @@ private slots:
void subControlRectsWithOffset();
void task260974_menuItemRectangleForComboBoxPopup();
void removeItem();
+ void resetModel();
protected slots:
void onEditTextChanged( const QString &newString );
@@ -2416,5 +2417,37 @@ void tst_QComboBox::removeItem()
QCOMPARE(cb.count(), 0);
}
+void tst_QComboBox::resetModel()
+{
+ class StringListModel : public QStringListModel
+ {
+ public:
+ StringListModel(const QStringList &list) : QStringListModel(list)
+ {
+ }
+
+ void reset()
+ {
+ QStringListModel::reset();
+ }
+ };
+ QComboBox cb;
+ StringListModel model( QStringList() << "1" << "2");
+ QSignalSpy spy(&cb, SIGNAL(currentIndexChanged(int)));
+ QCOMPARE(spy.count(), 0);
+ QCOMPARE(cb.currentIndex(), -1); //no selection
+
+ cb.setModel(&model);
+
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(cb.currentIndex(), 0); //first item selected
+
+ model.reset();
+ QCOMPARE(spy.count(), 2);
+ QCOMPARE(cb.currentIndex(), -1); //no selection
+
+}
+
+
QTEST_MAIN(tst_QComboBox)
#include "tst_qcombobox.moc"
diff --git a/tests/auto/qcompleter/tst_qcompleter.cpp b/tests/auto/qcompleter/tst_qcompleter.cpp
index 43205e1..2a17984 100644
--- a/tests/auto/qcompleter/tst_qcompleter.cpp
+++ b/tests/auto/qcompleter/tst_qcompleter.cpp
@@ -267,7 +267,7 @@ void tst_QCompleter::filter()
//QModelIndex si = completer->currentIndex();
//QCOMPARE(completer->model()->data(si).toString(), completion);
- QCOMPARE(completer->currentCompletion(), completionText);
+ QVERIFY(0 == QString::compare(completer->currentCompletion(), completionText, completer->caseSensitivity()));
}
// Testing get/set functions
diff --git a/tests/auto/qdatawidgetmapper/tst_qdatawidgetmapper.cpp b/tests/auto/qdatawidgetmapper/tst_qdatawidgetmapper.cpp
index 002aeb7..dedc0cb 100644
--- a/tests/auto/qdatawidgetmapper/tst_qdatawidgetmapper.cpp
+++ b/tests/auto/qdatawidgetmapper/tst_qdatawidgetmapper.cpp
@@ -379,7 +379,7 @@ void tst_QDataWidgetMapper::comboBox()
model->setData(model->index(0, 1), QString("read write item z"), Qt::EditRole);
QCOMPARE(readOnlyBox.currentIndex(), 2);
- QEXPECT_FAIL("", "See tasks 125493 and 147153", Abort);
+ QEXPECT_FAIL("", "See task 125493 and QTBUG-428", Abort);
QCOMPARE(readWriteBox.currentText(), QString("read write item z"));
}
diff --git a/tests/auto/qdockwidget/tst_qdockwidget.cpp b/tests/auto/qdockwidget/tst_qdockwidget.cpp
index dc67f36..e62ba8c 100644
--- a/tests/auto/qdockwidget/tst_qdockwidget.cpp
+++ b/tests/auto/qdockwidget/tst_qdockwidget.cpp
@@ -86,6 +86,7 @@ private slots:
void visibilityChanged();
void dockLocationChanged();
void setTitleBarWidget();
+ void titleBarDoubleClick();
// task specific tests:
void task165177_deleteFocusWidget();
void task169808_setFloating();
@@ -694,6 +695,24 @@ void tst_QDockWidget::setTitleBarWidget()
QCOMPARE(w2.isVisible(), false);
}
+void tst_QDockWidget::titleBarDoubleClick()
+{
+ QMainWindow win;
+ QDockWidget dock(&win);
+ win.show();
+ dock.setFloating(true);
+
+ QEvent e(QEvent::NonClientAreaMouseButtonDblClick);
+ QApplication::sendEvent(&dock, &e);
+ QVERIFY(dock.isFloating());
+ QCOMPARE(win.dockWidgetArea(&dock), Qt::NoDockWidgetArea);
+
+ win.addDockWidget(Qt::TopDockWidgetArea, &dock);
+ dock.setFloating(true);
+ QApplication::sendEvent(&dock, &e);
+ QVERIFY(!dock.isFloating());
+ QCOMPARE(win.dockWidgetArea(&dock), Qt::TopDockWidgetArea);
+}
void tst_QDockWidget::task165177_deleteFocusWidget()
{
diff --git a/tests/auto/qfontmetrics/tst_qfontmetrics.cpp b/tests/auto/qfontmetrics/tst_qfontmetrics.cpp
index 6b2f0fe..e80f8e0 100644
--- a/tests/auto/qfontmetrics/tst_qfontmetrics.cpp
+++ b/tests/auto/qfontmetrics/tst_qfontmetrics.cpp
@@ -100,6 +100,20 @@ void tst_QFontMetrics::same()
QFontMetrics fm(font);
const QString text = QLatin1String("Some stupid STRING");
QCOMPARE(fm.size(0, text), fm.size(0, text)) ;
+
+ {
+ QImage image;
+ QFontMetrics fm2(font, &image);
+ QString text2 = QLatin1String("Foo Foo");
+ QCOMPARE(fm2.size(0, text2), fm2.size(0, text2)); //used to crash
+ }
+
+ {
+ QImage image;
+ QFontMetricsF fm3(font, &image);
+ QString text2 = QLatin1String("Foo Foo");
+ QCOMPARE(fm3.size(0, text2), fm3.size(0, text2)); //used to crash
+ }
}
diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
index 7b87969..c8a9fac 100644
--- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
+++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
@@ -45,6 +45,7 @@
#include <QtGui/qgraphicswidget.h>
#include <QtGui/qgraphicsproxywidget.h>
#include <QtGui/qgraphicsview.h>
+#include <QtGui/qwindowsstyle.h>
class tst_QGraphicsAnchorLayout : public QObject {
Q_OBJECT;
@@ -72,6 +73,7 @@ private slots:
void proportionalPreferred();
void example();
void setSpacing();
+ void styleDefaults();
void hardComplexS60();
void stability();
void delete_anchor();
@@ -82,6 +84,8 @@ private slots:
void expandingParallel();
void floatConflict();
void infiniteMaxSizes();
+ void simplifiableUnfeasible();
+ void simplificationVsOrder();
};
class RectWidget : public QGraphicsWidget
@@ -1102,6 +1106,166 @@ void tst_QGraphicsAnchorLayout::setSpacing()
delete view;
}
+class CustomLayoutStyle : public QWindowsStyle
+{
+ Q_OBJECT
+public:
+ CustomLayoutStyle() : QWindowsStyle()
+ {
+ hspacing = 5;
+ vspacing = 10;
+ }
+
+ virtual int pixelMetric(PixelMetric metric, const QStyleOption * option = 0,
+ const QWidget * widget = 0 ) const;
+
+ int hspacing;
+ int vspacing;
+
+protected slots:
+ int layoutSpacingImplementation(QSizePolicy::ControlType control1,
+ QSizePolicy::ControlType control2,
+ Qt::Orientation orientation,
+ const QStyleOption *option = 0,
+ const QWidget *widget = 0) const;
+
+};
+
+#define CT1(c) CT2(c, c)
+#define CT2(c1, c2) ((uint)c1 << 16) | (uint)c2
+
+int CustomLayoutStyle::layoutSpacingImplementation(QSizePolicy::ControlType control1,
+ QSizePolicy::ControlType control2,
+ Qt::Orientation orientation,
+ const QStyleOption * /*option = 0*/,
+ const QWidget * /*widget = 0*/) const
+{
+ if (orientation == Qt::Horizontal) {
+ switch (CT2(control1, control2)) {
+ case CT1(QSizePolicy::PushButton):
+ return 2;
+ break;
+ }
+ return 5;
+ } else {
+ switch (CT2(control1, control2)) {
+ case CT1(QSizePolicy::RadioButton):
+ return 2;
+ break;
+
+ }
+ return 10;
+ }
+}
+
+int CustomLayoutStyle::pixelMetric(PixelMetric metric, const QStyleOption * option /*= 0*/,
+ const QWidget * widget /*= 0*/ ) const
+{
+ switch (metric) {
+ case PM_LayoutLeftMargin:
+ return 0;
+ break;
+ case PM_LayoutTopMargin:
+ return 3;
+ break;
+ case PM_LayoutRightMargin:
+ return 6;
+ break;
+ case PM_LayoutBottomMargin:
+ return 9;
+ break;
+ case PM_LayoutHorizontalSpacing:
+ return hspacing;
+ case PM_LayoutVerticalSpacing:
+ return vspacing;
+ break;
+ default:
+ break;
+ }
+ return QWindowsStyle::pixelMetric(metric, option, widget);
+}
+
+void tst_QGraphicsAnchorLayout::styleDefaults()
+{
+ QSizeF min (10, 10);
+ QSizeF pref(20, 20);
+ QSizeF max (50, 50);
+
+ /*
+ create this layout, where a,b have controlType QSizePolicy::RadioButton
+ c,d have controlType QSizePolicy::PushButton:
+ +-------+
+ |a |
+ | b |
+ | c |
+ | d|
+ +-------+
+ */
+ QGraphicsScene scene;
+ QGraphicsWidget *a = createItem(min, pref, max);
+ QSizePolicy spRadioButton = a->sizePolicy();
+ spRadioButton.setControlType(QSizePolicy::RadioButton);
+ a->setSizePolicy(spRadioButton);
+
+ QGraphicsWidget *b = createItem(min, pref, max);
+ b->setSizePolicy(spRadioButton);
+
+ QGraphicsWidget *c = createItem(min, pref, max);
+ QSizePolicy spPushButton = c->sizePolicy();
+ spPushButton.setControlType(QSizePolicy::PushButton);
+ c->setSizePolicy(spPushButton);
+
+ QGraphicsWidget *d = createItem(min, pref, max);
+ d->setSizePolicy(spPushButton);
+
+ QGraphicsWidget *window = new QGraphicsWidget(0, Qt::Window);
+
+ // Test layoutSpacingImplementation
+ CustomLayoutStyle *style = new CustomLayoutStyle;
+ style->hspacing = -1;
+ style->vspacing = -1;
+ window->setStyle(style);
+ QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
+
+ l->addCornerAnchors(l, Qt::TopLeftCorner, a, Qt::TopLeftCorner);
+ l->addCornerAnchors(a, Qt::BottomRightCorner, b, Qt::TopLeftCorner);
+ l->addCornerAnchors(b, Qt::BottomRightCorner, c, Qt::TopLeftCorner);
+ l->addCornerAnchors(c, Qt::BottomRightCorner, d, Qt::TopLeftCorner);
+ l->addCornerAnchors(d, Qt::BottomRightCorner, l, Qt::BottomRightCorner);
+
+ window->setLayout(l);
+
+ scene.addItem(window);
+
+ window->show();
+ QGraphicsView *view = new QGraphicsView(&scene);
+ view->resize(200, 200);
+ view->show();
+
+ window->adjustSize();
+ QCOMPARE(a->geometry(), QRectF(0, 3, 20, 20)); //radio
+ QCOMPARE(b->geometry(), QRectF(25, 25, 20, 20)); //radio
+ QCOMPARE(c->geometry(), QRectF(50, 55, 20, 20)); //push
+ QCOMPARE(d->geometry(), QRectF(72, 85, 20, 20)); //push
+ QCOMPARE(l->geometry(), QRectF(0, 0, 98, 114));
+
+
+ // Test pixelMetric(PM_Layout{Horizontal|Vertical}Spacing
+ window->setStyle(0);
+
+ style->hspacing = 1;
+ style->vspacing = 2;
+
+ window->setStyle(style);
+ window->adjustSize();
+ QCOMPARE(a->geometry(), QRectF(0, 3, 20, 20));
+ QCOMPARE(b->geometry(), QRectF(21, 25, 20, 20));
+ QCOMPARE(c->geometry(), QRectF(42, 47, 20, 20));
+ QCOMPARE(d->geometry(), QRectF(63, 69, 20, 20));
+ QCOMPARE(l->geometry(), QRectF(0, 0, 89, 98));
+}
+
+
/*!
Taken from "hard" complex case, found at
https://cwiki.nokia.com/S60QTUI/AnchorLayoutComplexCases
@@ -1755,5 +1919,100 @@ void tst_QGraphicsAnchorLayout::infiniteMaxSizes()
QCOMPARE(d->geometry(), QRectF(QWIDGETSIZE_MAX - 50, 0, 50, 10));
}
+void tst_QGraphicsAnchorLayout::simplifiableUnfeasible()
+{
+ QGraphicsWidget *a = createItem(QSizeF(70.0, 100.0),
+ QSizeF(100.0, 100.0),
+ QSizeF(100.0, 100.0), "A");
+
+ QGraphicsWidget *b = createItem(QSizeF(110.0, 100.0),
+ QSizeF(150.0, 100.0),
+ QSizeF(190.0, 100.0), "B");
+
+ QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
+ l->setContentsMargins(0, 0, 0, 0);
+ l->setSpacing(0);
+
+ l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop);
+ l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop);
+ l->addAnchor(b, Qt::AnchorBottom, l, Qt::AnchorBottom);
+
+ l->addAnchors(l, a, Qt::Horizontal);
+ l->addAnchor(l, Qt::AnchorLeft, b, Qt::AnchorLeft);
+ l->addAnchor(b, Qt::AnchorRight, a, Qt::AnchorRight);
+
+ QCOMPARE(l->count(), 2);
+
+ QGraphicsWidget p;
+ p.setLayout(l);
+
+ l->invalidate();
+ QVERIFY(layoutHasConflict(l));
+ if (hasSimplification)
+ QVERIFY(!usedSimplex(l, Qt::Horizontal));
+
+ // Now we make it valid again
+ b->setMinimumWidth(100);
+
+ l->invalidate();
+ QVERIFY(!layoutHasConflict(l));
+ if (hasSimplification)
+ QVERIFY(!usedSimplex(l, Qt::Horizontal));
+
+ // And make it invalid again
+ a->setPreferredWidth(70);
+ a->setMaximumWidth(70);
+
+ l->invalidate();
+ QVERIFY(layoutHasConflict(l));
+ if (hasSimplification)
+ QVERIFY(!usedSimplex(l, Qt::Horizontal));
+}
+
+/*
+ Test whether the anchor direction can prevent it from
+ being simplificated
+*/
+void tst_QGraphicsAnchorLayout::simplificationVsOrder()
+{
+ QSizeF min(10, 10);
+ QSizeF pref(20, 10);
+ QSizeF max(50, 10);
+
+ QGraphicsWidget *a = createItem(min, pref, max);
+ QGraphicsWidget *b = createItem(min, pref, max);
+ QGraphicsWidget *c = createItem(min, pref, max);
+
+ QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
+
+ // Bulk anchors
+ l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft);
+ l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft);
+ l->addAnchor(b, Qt::AnchorLeft, c, Qt::AnchorLeft);
+ l->addAnchor(c, Qt::AnchorRight, l, Qt::AnchorRight);
+
+ // Problematic anchor, direction b->c
+ QGraphicsAnchor *anchor = l->addAnchor(b, Qt::AnchorRight, c, Qt::AnchorRight);
+ anchor->setSpacing(5);
+
+ l->effectiveSizeHint(Qt::MinimumSize);
+ if (hasSimplification) {
+ QCOMPARE(usedSimplex(l, Qt::Horizontal), false);
+ QCOMPARE(usedSimplex(l, Qt::Vertical), false);
+ }
+
+ // Problematic anchor, direction c->b
+ delete anchor;
+ anchor = l->addAnchor(c, Qt::AnchorRight, b, Qt::AnchorRight);
+ anchor->setSpacing(5);
+
+ l->effectiveSizeHint(Qt::MinimumSize);
+ if (hasSimplification) {
+ QEXPECT_FAIL("", "Sequential anchors cannot handle children of opposite directions", Continue);
+ QCOMPARE(usedSimplex(l, Qt::Horizontal), false);
+ QCOMPARE(usedSimplex(l, Qt::Vertical), false);
+ }
+}
+
QTEST_MAIN(tst_QGraphicsAnchorLayout)
#include "tst_qgraphicsanchorlayout.moc"
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
index dcad8e1..2c948cc 100644
--- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -372,6 +372,7 @@ private slots:
void itemUsesExtendedStyleOption();
void itemSendsGeometryChanges();
void moveItem();
+ void moveLineItem();
void sorting_data();
void sorting();
void itemHasNoContents();
@@ -390,6 +391,7 @@ private slots:
void moveWhileDeleting();
void ensureDirtySceneTransform();
void focusScope();
+ void focusScope2();
void stackBefore();
void sceneModality();
void panelModality();
@@ -7438,6 +7440,39 @@ void tst_QGraphicsItem::moveItem()
COMPARE_REGIONS(view.paintedRegion, expectedParentRegion);
}
+void tst_QGraphicsItem::moveLineItem()
+{
+ QGraphicsScene scene;
+ scene.setSceneRect(0, 0, 200, 200);
+ QGraphicsLineItem *item = new QGraphicsLineItem(0, 0, 100, 0);
+ item->setPos(50, 50);
+ scene.addItem(item);
+
+ MyGraphicsView view(&scene);
+ view.show();
+#ifdef Q_WS_X11
+ qt_x11_wait_for_window_manager(&view);
+#endif
+ QTest::qWait(200);
+ view.reset();
+
+ const QRect itemDeviceBoundingRect = item->deviceTransform(view.viewportTransform())
+ .mapRect(item->boundingRect()).toRect();
+ QRegion expectedRegion = itemDeviceBoundingRect.adjusted(-2, -2, 2, 2); // antialiasing
+
+ // Make sure the calculated region is correct.
+ item->update();
+ QTest::qWait(10);
+ QCOMPARE(view.paintedRegion, expectedRegion);
+ view.reset();
+
+ // Old position: (50, 50)
+ item->setPos(50, 100);
+ expectedRegion += expectedRegion.translated(0, 50);
+ QTest::qWait(10);
+ QCOMPARE(view.paintedRegion, expectedRegion);
+}
+
void tst_QGraphicsItem::sorting_data()
{
QTest::addColumn<int>("index");
@@ -8431,7 +8466,7 @@ void tst_QGraphicsItem::focusScope()
QVERIFY(!scope2->focusScopeItem());
scope3->setParentItem(scope2);
QCOMPARE(scope2->focusScopeItem(), (QGraphicsItem *)scope3);
- QCOMPARE(scope2->focusItem(), (QGraphicsItem *)scope2);
+ QCOMPARE(scope2->focusItem(), (QGraphicsItem *)scope3);
QGraphicsRectItem *scope1 = new QGraphicsRectItem;
scope1->setData(0, "scope1");
@@ -8440,9 +8475,9 @@ void tst_QGraphicsItem::focusScope()
QVERIFY(!scope1->focusScopeItem());
scope2->setParentItem(scope1);
- QCOMPARE(scope1->focusItem(), (QGraphicsItem *)scope1);
- QCOMPARE(scope2->focusItem(), (QGraphicsItem *)0);
- QCOMPARE(scope3->focusItem(), (QGraphicsItem *)0);
+ QCOMPARE(scope1->focusItem(), (QGraphicsItem *)scope3);
+ QCOMPARE(scope2->focusItem(), (QGraphicsItem *)scope3);
+ QCOMPARE(scope3->focusItem(), (QGraphicsItem *)scope3);
QCOMPARE(scope1->focusScopeItem(), (QGraphicsItem *)scope2);
QCOMPARE(scope2->focusScopeItem(), (QGraphicsItem *)scope3);
QCOMPARE(scope3->focusScopeItem(), (QGraphicsItem *)0);
@@ -8493,11 +8528,13 @@ void tst_QGraphicsItem::focusScope()
rect5->setFocus();
rect5->setParentItem(rect4);
QCOMPARE(scope3->focusScopeItem(), (QGraphicsItem *)rect5);
- QVERIFY(!rect5->hasFocus());
+ QVERIFY(rect5->hasFocus());
rect4->setParentItem(0);
+ QVERIFY(rect5->hasFocus());
QCOMPARE(scope3->focusScopeItem(), (QGraphicsItem *)0);
- QVERIFY(scope3->hasFocus());
+ QCOMPARE(scope3->focusItem(), (QGraphicsItem *)0);
+ QVERIFY(!scope3->hasFocus());
QGraphicsRectItem *rectA = new QGraphicsRectItem;
QGraphicsRectItem *scopeA = new QGraphicsRectItem(rectA);
@@ -8508,7 +8545,7 @@ void tst_QGraphicsItem::focusScope()
scopeB->setFocus();
scene.addItem(rectA);
- QVERIFY(!rect5->hasFocus());
+ QVERIFY(rect5->hasFocus());
QVERIFY(!scopeB->hasFocus());
scopeA->setFocus();
@@ -8516,6 +8553,76 @@ void tst_QGraphicsItem::focusScope()
QCOMPARE(scopeB->focusItem(), (QGraphicsItem *)scopeB);
}
+void tst_QGraphicsItem::focusScope2()
+{
+ QGraphicsRectItem *child1 = new QGraphicsRectItem;
+ child1->setFlags(QGraphicsItem::ItemIsFocusable);
+ child1->setFocus();
+ QCOMPARE(child1->focusItem(), (QGraphicsItem *)child1);
+
+ QGraphicsRectItem *child2 = new QGraphicsRectItem;
+ child2->setFlags(QGraphicsItem::ItemIsFocusable);
+
+ QGraphicsRectItem *rootFocusScope = new QGraphicsRectItem;
+ rootFocusScope->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope);
+ rootFocusScope->setFocus();
+ QCOMPARE(rootFocusScope->focusItem(), (QGraphicsItem *)rootFocusScope);
+
+ child1->setParentItem(rootFocusScope);
+ child2->setParentItem(rootFocusScope);
+
+ QCOMPARE(rootFocusScope->focusScopeItem(), (QGraphicsItem *)child1);
+ QCOMPARE(rootFocusScope->focusItem(), (QGraphicsItem *)child1);
+
+ QGraphicsRectItem *siblingChild1 = new QGraphicsRectItem;
+ siblingChild1->setFlags(QGraphicsItem::ItemIsFocusable);
+ siblingChild1->setFocus();
+
+ QGraphicsRectItem *siblingChild2 = new QGraphicsRectItem;
+ siblingChild2->setFlags(QGraphicsItem::ItemIsFocusable);
+
+ QGraphicsRectItem *siblingFocusScope = new QGraphicsRectItem;
+ siblingFocusScope->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope);
+
+ siblingChild1->setParentItem(siblingFocusScope);
+ siblingChild2->setParentItem(siblingFocusScope);
+
+ QCOMPARE(siblingFocusScope->focusScopeItem(), (QGraphicsItem *)siblingChild1);
+ QCOMPARE(siblingFocusScope->focusItem(), (QGraphicsItem *)0);
+
+ QGraphicsItem *root = new QGraphicsRectItem;
+ rootFocusScope->setParentItem(root);
+ siblingFocusScope->setParentItem(root);
+
+ QCOMPARE(root->focusItem(), (QGraphicsItem *)child1);
+
+ QGraphicsScene scene;
+ scene.addItem(root);
+
+ QEvent activate(QEvent::WindowActivate);
+ qApp->sendEvent(&scene, &activate);
+ scene.setFocus();
+
+ QCOMPARE(scene.focusItem(), (QGraphicsItem *)child1);
+
+ // You cannot set focus on a descendant of a focus scope directly;
+ // this will only change the scope's focus scope item pointer. If
+ // you want to give true input focus, you must set it directly on
+ // the scope itself
+ siblingChild2->setFocus();
+ QVERIFY(!siblingChild2->hasFocus());
+ QVERIFY(!siblingChild2->focusItem());
+ QCOMPARE(siblingFocusScope->focusScopeItem(), (QGraphicsItem *)siblingChild2);
+ QCOMPARE(siblingFocusScope->focusItem(), (QGraphicsItem *)0);
+
+ // Set focus on the scope; focus is forwarded to the focus scope item.
+ siblingFocusScope->setFocus();
+ QVERIFY(siblingChild2->hasFocus());
+ QVERIFY(siblingChild2->focusItem());
+ QCOMPARE(siblingFocusScope->focusScopeItem(), (QGraphicsItem *)siblingChild2);
+ QCOMPARE(siblingFocusScope->focusItem(), (QGraphicsItem *)siblingChild2);
+}
+
void tst_QGraphicsItem::stackBefore()
{
QGraphicsRectItem parent;
@@ -8535,24 +8642,24 @@ void tst_QGraphicsItem::stackBefore()
QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child1 << child3 << child4 << child2));
// Move child2 before child1
- child2->stackBefore(child1);
+ child2->stackBefore(child1); // 2134
QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4));
- child2->stackBefore(child2);
+ child2->stackBefore(child2); // 2134
QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4));
- child1->setZValue(1);
+ child1->setZValue(1); // 2341
QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child3 << child4 << child1));
- child1->stackBefore(child2); // no effect
+ child1->stackBefore(child2); // 2341
QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child3 << child4 << child1));
- child1->setZValue(0);
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4));
- child4->stackBefore(child1);
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child4 << child1 << child3));
- child4->setZValue(1);
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4));
- child3->stackBefore(child1);
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child3 << child1 << child4));
- child4->setZValue(0);
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child4 << child3 << child1));
+ child1->setZValue(0); // 1234
+ QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4));
+ child4->stackBefore(child1); // 4123
+ QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child4 << child1 << child2 << child3));
+ child4->setZValue(1); // 1234 (4123)
+ QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4));
+ child3->stackBefore(child1); // 3124 (4312)
+ QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child3 << child1 << child2 << child4));
+ child4->setZValue(0); // 4312
+ QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child4 << child3 << child1 << child2));
// Make them all toplevels
child1->setParentItem(0);
@@ -8574,24 +8681,24 @@ void tst_QGraphicsItem::stackBefore()
QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child1 << child3 << child4 << child2));
// Move child2 before child1
- child2->stackBefore(child1);
+ child2->stackBefore(child1); // 2134
QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4));
- child2->stackBefore(child2);
+ child2->stackBefore(child2); // 2134
QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4));
- child1->setZValue(1);
+ child1->setZValue(1); // 2341
QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child3 << child4 << child1));
- child1->stackBefore(child2); // no effect
+ child1->stackBefore(child2); // 2341
QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child3 << child4 << child1));
- child1->setZValue(0);
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4));
- child4->stackBefore(child1);
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child4 << child1 << child3));
- child4->setZValue(1);
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4));
- child3->stackBefore(child1);
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child3 << child1 << child4));
- child4->setZValue(0);
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child4 << child3 << child1));
+ child1->setZValue(0); // 1234
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4));
+ child4->stackBefore(child1); // 4123
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child4 << child1 << child2 << child3));
+ child4->setZValue(1); // 1234 (4123)
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4));
+ child3->stackBefore(child1); // 3124 (4312)
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child3 << child1 << child2 << child4));
+ child4->setZValue(0); // 4312
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child4 << child3 << child1 << child2));
}
void tst_QGraphicsItem::QTBUG_4233_updateCachedWithSceneRect()
diff --git a/tests/auto/qgraphicsobject/tst_qgraphicsobject.cpp b/tests/auto/qgraphicsobject/tst_qgraphicsobject.cpp
index a9fd55a..194665d 100644
--- a/tests/auto/qgraphicsobject/tst_qgraphicsobject.cpp
+++ b/tests/auto/qgraphicsobject/tst_qgraphicsobject.cpp
@@ -46,6 +46,7 @@
#include <qgraphicssceneevent.h>
#include <qgraphicsview.h>
#include <qstyleoption.h>
+#include <private/qobject_p.h>
#include "../../shared/util.h"
class tst_QGraphicsObject : public QObject {
@@ -65,6 +66,7 @@ private slots:
void opacity();
void enabled();
void visible();
+ void deleted();
};
@@ -249,6 +251,46 @@ void tst_QGraphicsObject::visible()
QVERIFY(object.property("visible") == true);
}
+class DeleteTester : public QGraphicsObject
+{
+public:
+ DeleteTester(bool *w, bool *pw, QGraphicsItem *parent = 0)
+ : QGraphicsObject(parent), wasDeleted(w), parentWasDeleted(pw)
+ { }
+
+ ~DeleteTester()
+ {
+ *wasDeleted = QObjectPrivate::get(this)->wasDeleted;
+ if (QGraphicsItem *p = parentItem()) {
+ if (QGraphicsObject *o = p->toGraphicsObject())
+ *parentWasDeleted = QObjectPrivate::get(o)->wasDeleted;
+ }
+ }
+
+ void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0)
+ { }
+ QRectF boundingRect() const
+ { return QRectF(); }
+
+ bool *wasDeleted;
+ bool *parentWasDeleted;
+};
+
+void tst_QGraphicsObject::deleted()
+{
+ bool item1_parentWasDeleted = false;
+ bool item1_wasDeleted = false;
+ bool item2_parentWasDeleted = false;
+ bool item2_wasDeleted = false;
+ DeleteTester *item1 = new DeleteTester(&item1_wasDeleted, &item1_parentWasDeleted);
+ DeleteTester *item2 = new DeleteTester(&item2_wasDeleted, &item2_parentWasDeleted, item1);
+ delete item1;
+
+ QVERIFY(!item1_wasDeleted); // destructor not called yet
+ QVERIFY(!item1_parentWasDeleted); // no parent
+ QVERIFY(!item2_wasDeleted); // destructor not called yet
+ QVERIFY(item2_parentWasDeleted);
+}
QTEST_MAIN(tst_QGraphicsObject)
#include "tst_qgraphicsobject.moc"
diff --git a/tests/auto/qgraphicssceneindex/tst_qgraphicssceneindex.cpp b/tests/auto/qgraphicssceneindex/tst_qgraphicssceneindex.cpp
index 1109e5e..9dfd486 100644
--- a/tests/auto/qgraphicssceneindex/tst_qgraphicssceneindex.cpp
+++ b/tests/auto/qgraphicssceneindex/tst_qgraphicssceneindex.cpp
@@ -66,6 +66,7 @@ private slots:
void movingItems();
void connectedToSceneRectChanged();
void items();
+ void removeItems();
void clear();
private:
@@ -268,6 +269,63 @@ void tst_QGraphicsSceneIndex::items()
QCOMPARE(scene.items().size(), 3);
}
+class RectWidget : public QGraphicsWidget
+{
+ Q_OBJECT
+public:
+ RectWidget(QGraphicsItem *parent = 0) : QGraphicsWidget(parent)
+ {
+ }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+ {
+ painter->setBrush(brush);
+ painter->drawRect(boundingRect());
+ }
+public:
+ QBrush brush;
+};
+
+void tst_QGraphicsSceneIndex::removeItems()
+{
+ QGraphicsScene scene;
+
+ RectWidget *parent = new RectWidget;
+ parent->brush = QBrush(QColor(Qt::magenta));
+ parent->setGeometry(250, 250, 400, 400);
+
+ RectWidget *widget = new RectWidget(parent);
+ widget->brush = QBrush(QColor(Qt::blue));
+ widget->setGeometry(10, 10, 200, 200);
+
+ RectWidget *widgetChild1 = new RectWidget(widget);
+ widgetChild1->brush = QBrush(QColor(Qt::green));
+ widgetChild1->setGeometry(20, 20, 100, 100);
+
+ RectWidget *widgetChild2 = new RectWidget(widgetChild1);
+ widgetChild2->brush = QBrush(QColor(Qt::yellow));
+ widgetChild2->setGeometry(25, 25, 50, 50);
+
+ scene.addItem(parent);
+
+ QGraphicsView view(&scene);
+ view.resize(600, 600);
+ view.show();
+ QApplication::setActiveWindow(&view);
+ QTest::qWaitForWindowShown(&view);
+
+ QApplication::processEvents();
+
+ scene.removeItem(widgetChild1);
+
+ delete widgetChild1;
+
+ //We move the parent
+ scene.items(295, 295, 50, 50);
+
+ //This should not crash
+}
+
void tst_QGraphicsSceneIndex::clear()
{
class MyItem : public QGraphicsItem
diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
index dc08d0e..f07453c 100644
--- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
+++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
@@ -194,6 +194,8 @@ private slots:
void acceptDrops();
void optimizationFlags();
void optimizationFlags_dontSavePainterState();
+ void optimizationFlags_dontSavePainterState2_data();
+ void optimizationFlags_dontSavePainterState2();
void levelOfDetail_data();
void levelOfDetail();
void scrollBarRanges_data();
@@ -2455,6 +2457,57 @@ void tst_QGraphicsView::optimizationFlags_dontSavePainterState()
QTest::qWaitForWindowShown(&painter2);
}
+void tst_QGraphicsView::optimizationFlags_dontSavePainterState2_data()
+{
+ QTest::addColumn<bool>("savePainter");
+ QTest::newRow("With painter state protection") << true;
+ QTest::newRow("Without painter state protection") << false;
+}
+
+void tst_QGraphicsView::optimizationFlags_dontSavePainterState2()
+{
+ QFETCH(bool, savePainter);
+
+ class MyScene : public QGraphicsScene
+ {
+ public:
+ void drawBackground(QPainter *p, const QRectF &)
+ { transformInDrawBackground = p->worldTransform(); }
+
+ void drawForeground(QPainter *p, const QRectF &)
+ { transformInDrawForeground = p->worldTransform(); }
+
+ QTransform transformInDrawBackground;
+ QTransform transformInDrawForeground;
+ };
+
+ MyScene scene;
+ // Add transformed dummy items to make sure the painter's worldTransform() is changed in drawItems.
+ scene.addRect(0, 0, 20, 20)->setTransform(QTransform::fromScale(2, 2));
+ scene.addRect(50, 50, 20, 20)->setTransform(QTransform::fromTranslate(200, 200));
+
+ CustomView view(&scene);
+ if (!savePainter)
+ view.setOptimizationFlag(QGraphicsView::DontSavePainterState);
+ view.rotate(45);
+ view.scale(1.5, 1.5);
+ view.show();
+#ifdef Q_WS_X11
+ qt_x11_wait_for_window_manager(&view);
+#endif
+
+ // Make sure the view is repainted; otherwise the tests below will fail.
+ view.viewport()->repaint();
+ QTest::qWait(200);
+ QVERIFY(view.painted);
+
+ // Make sure the painter's world transform is preserved after drawItems.
+ const QTransform expectedTransform = view.viewportTransform();
+ QVERIFY(!expectedTransform.isIdentity());
+ QCOMPARE(scene.transformInDrawForeground, expectedTransform);
+ QCOMPARE(scene.transformInDrawBackground, expectedTransform);
+}
+
class LodItem : public QGraphicsRectItem
{
public:
@@ -3735,7 +3788,7 @@ void tst_QGraphicsView::task259503_scrollingArtifacts()
{
// qDebug() << event->region();
// qDebug() << updateRegion;
- QEXPECT_FAIL("", "The event region doesn't include the original item position region. See task #259503.", Continue);
+ QEXPECT_FAIL("", "The event region doesn't include the original item position region. See QTBUG-4416", Continue);
QCOMPARE(event->region(), updateRegion);
}
}
diff --git a/tests/auto/qlistview/tst_qlistview.cpp b/tests/auto/qlistview/tst_qlistview.cpp
index 6e211ae..65ab12d 100644
--- a/tests/auto/qlistview/tst_qlistview.cpp
+++ b/tests/auto/qlistview/tst_qlistview.cpp
@@ -1132,6 +1132,7 @@ void tst_QListView::selection()
#endif
v.show();
+ QTest::qWaitForWindowShown(&v);
QApplication::processEvents();
v.setSelection(selectionRect, QItemSelectionModel::ClearAndSelect);
@@ -1184,6 +1185,7 @@ void tst_QListView::scrollTo()
lv.setModel(&model);
lv.setFixedSize(100, 200);
lv.show();
+ QTest::qWaitForWindowShown(&lv);
//by default, the list view scrolls per item and has no wrapping
QModelIndex index = model.index(6,0);
@@ -1782,6 +1784,7 @@ void tst_QListView::task262152_setModelColumnNavigate()
view.setModelColumn(1);
view.show();
+ QTest::qWaitForWindowShown(&view);
QTest::qWait(100);
QTest::keyClick(&view, Qt::Key_Down);
QTest::qWait(100);
diff --git a/tests/auto/qlistwidget/tst_qlistwidget.cpp b/tests/auto/qlistwidget/tst_qlistwidget.cpp
index e825c8f..5c6ed54 100644
--- a/tests/auto/qlistwidget/tst_qlistwidget.cpp
+++ b/tests/auto/qlistwidget/tst_qlistwidget.cpp
@@ -46,6 +46,7 @@
#include <qlist.h>
#include <qlistwidget.h>
+#include <private/qlistwidget_p.h>
//TESTED_CLASS=
//TESTED_FILES=
@@ -95,6 +96,8 @@ private slots:
void insertItem();
void insertItems_data();
void insertItems();
+ void moveItemsPriv_data();
+ void moveItemsPriv();
void itemAssignment();
void item_data();
@@ -849,6 +852,62 @@ void tst_QListWidget::removeItems()
}
+void tst_QListWidget::moveItemsPriv_data()
+{
+ QTest::addColumn<int>("rowCount");
+ QTest::addColumn<int>("srcRow");
+ QTest::addColumn<int>("dstRow");
+ QTest::addColumn<bool>("shouldHaveSignaled");
+
+ QTest::newRow("Empty") << 0 << 0 << 0 << false;
+ QTest::newRow("Overflow src") << 5 << 5 << 2 << false;
+ QTest::newRow("Underflow src") << 5 << -1 << 2 << false;
+ QTest::newRow("Overflow dst") << 5 << 2 << 5 << false;
+ QTest::newRow("Underflow dst") << 5 << 2 << -1 << false;
+ QTest::newRow("Same place") << 5 << 2 << 2 << false;
+ QTest::newRow("Up") << 5 << 4 << 2 << true;
+ QTest::newRow("Down") << 5 << 2 << 4 << true;
+}
+
+void tst_QListWidget::moveItemsPriv()
+{
+ QFETCH(int, rowCount);
+ QFETCH(int, srcRow);
+ QFETCH(int, dstRow);
+ QFETCH(bool, shouldHaveSignaled);
+
+ for (int r = 0; r < rowCount; ++r)
+ new QListWidgetItem(QString::number(r), testWidget);
+
+ QListModel *model = dynamic_cast<QListModel *>(testWidget->model());
+ QVERIFY(model);
+ QSignalSpy beginMoveSpy(model, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
+ QSignalSpy movedSpy(model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)));
+ model->move(srcRow, dstRow);
+
+ if (shouldHaveSignaled) {
+ if (srcRow < dstRow)
+ QCOMPARE(testWidget->item(dstRow - 1)->text(), QString::number(srcRow));
+ else
+ QCOMPARE(testWidget->item(dstRow)->text(), QString::number(srcRow));
+
+ QCOMPARE(beginMoveSpy.count(), 1);
+ const QList<QVariant> &beginMoveArgs = beginMoveSpy.takeFirst();
+ QCOMPARE(beginMoveArgs.at(1).toInt(), srcRow);
+ QCOMPARE(beginMoveArgs.at(2).toInt(), srcRow);
+ QCOMPARE(beginMoveArgs.at(4).toInt(), dstRow);
+
+ QCOMPARE(movedSpy.count(), 1);
+ const QList<QVariant> &movedArgs = movedSpy.takeFirst();
+ QCOMPARE(movedArgs.at(1).toInt(), srcRow);
+ QCOMPARE(movedArgs.at(2).toInt(), srcRow);
+ QCOMPARE(movedArgs.at(4).toInt(), dstRow);
+ } else {
+ QCOMPARE(beginMoveSpy.count(), 0);
+ QCOMPARE(movedSpy.count(), 0);
+ }
+}
+
void tst_QListWidget::itemStreaming_data()
{
QTest::addColumn<QString>("text");
diff --git a/tests/auto/qmenubar/tst_qmenubar.cpp b/tests/auto/qmenubar/tst_qmenubar.cpp
index 07aa9f4..4291c3e 100644
--- a/tests/auto/qmenubar/tst_qmenubar.cpp
+++ b/tests/auto/qmenubar/tst_qmenubar.cpp
@@ -86,6 +86,18 @@ private:
uint sel_count;
};
+class Menu : public QMenu
+{
+ Q_OBJECT
+ public slots:
+ void addActions()
+ {
+ //this will change the geometry of the menu
+ addAction("action1");
+ addAction("action2");
+ }
+};
+
class tst_QMenuBar : public QObject
{
Q_OBJECT
@@ -1442,7 +1454,7 @@ void tst_QMenuBar::check_menuPosition()
#ifdef Q_OS_WINCE_WM
QSKIP("Qt/CE uses native menubar", SkipAll);
#endif
- QMenu menu;
+ Menu menu;
#ifdef QT3_SUPPORT
initComplexMenubar();
#else
@@ -1496,6 +1508,21 @@ void tst_QMenuBar::check_menuPosition()
menu.close();
}
+ //in RTL, the menu should be stuck at the right of the action geometry
+ {
+ Qt::LayoutDirection dir = qApp->layoutDirection();
+ qApp->setLayoutDirection(Qt::RightToLeft);
+ menu.clear();
+ QObject::connect(&menu, SIGNAL(aboutToShow()), &menu, SLOT(addActions()));
+ QRect mbItemRect = mw->menuBar()->actionGeometry(menu_action);
+ mbItemRect.moveTo(mw->menuBar()->mapToGlobal(mbItemRect.topLeft()));
+ QTest::keyClick(mw, Qt::Key_M, Qt::AltModifier );
+ QVERIFY(menu.isActiveWindow());
+ QCOMPARE(menu.geometry().right(), mbItemRect.right());
+ menu.close();
+ qApp->setLayoutDirection(dir);
+ }
+
}
void tst_QMenuBar::task223138_triggered()
diff --git a/tests/auto/qparallelanimationgroup/tst_qparallelanimationgroup.cpp b/tests/auto/qparallelanimationgroup/tst_qparallelanimationgroup.cpp
index 8578d36..8d937e9 100644
--- a/tests/auto/qparallelanimationgroup/tst_qparallelanimationgroup.cpp
+++ b/tests/auto/qparallelanimationgroup/tst_qparallelanimationgroup.cpp
@@ -56,8 +56,7 @@ public:
virtual ~tst_QParallelAnimationGroup();
public Q_SLOTS:
- void init();
- void cleanup();
+ void initTestCase();
private slots:
void construction();
@@ -86,13 +85,13 @@ tst_QParallelAnimationGroup::~tst_QParallelAnimationGroup()
{
}
-void tst_QParallelAnimationGroup::init()
+void tst_QParallelAnimationGroup::initTestCase()
{
qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State");
-}
-
-void tst_QParallelAnimationGroup::cleanup()
-{
+#if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAC) || defined(Q_WS_WINCE)
+ // give the Symbian and mac app start event queue time to clear
+ QTest::qWait(1000);
+#endif
}
void tst_QParallelAnimationGroup::construction()
@@ -486,10 +485,6 @@ void tst_QParallelAnimationGroup::updateChildrenWithRunningGroup()
void tst_QParallelAnimationGroup::deleteChildrenWithRunningGroup()
{
-#if defined(Q_OS_SYMBIAN)
- // give the Symbian app start event queue time to clear
- QTest::qWait(1000);
-#endif
// test if children can be activated when their group is stopped
QParallelAnimationGroup group;
diff --git a/tests/auto/qpauseanimation/tst_qpauseanimation.cpp b/tests/auto/qpauseanimation/tst_qpauseanimation.cpp
index b11efa0..4d0a7a7 100644
--- a/tests/auto/qpauseanimation/tst_qpauseanimation.cpp
+++ b/tests/auto/qpauseanimation/tst_qpauseanimation.cpp
@@ -93,8 +93,7 @@ public:
virtual ~tst_QPauseAnimation();
public Q_SLOTS:
- void init();
- void cleanup();
+ void initTestCase();
private slots:
void changeDirectionWhileRunning();
@@ -117,20 +116,15 @@ tst_QPauseAnimation::~tst_QPauseAnimation()
{
}
-void tst_QPauseAnimation::init()
+void tst_QPauseAnimation::initTestCase()
{
qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State");
qRegisterMetaType<QAbstractAnimation::DeletionPolicy>("QAbstractAnimation::DeletionPolicy");
}
-void tst_QPauseAnimation::cleanup()
-{
-}
-
void tst_QPauseAnimation::changeDirectionWhileRunning()
{
- QUnifiedTimer *timer = QUnifiedTimer::instance();
- timer->setConsistentTiming(true);
+ EnableConsistentTiming enabled;
TestablePauseAnimation animation;
animation.setDuration(400);
@@ -140,8 +134,6 @@ void tst_QPauseAnimation::changeDirectionWhileRunning()
animation.setDirection(QAbstractAnimation::Backward);
QTest::qWait(animation.totalDuration() + 50);
QVERIFY(animation.state() == QAbstractAnimation::Stopped);
-
- timer->setConsistentTiming(false);
}
void tst_QPauseAnimation::noTimerUpdates_data()
@@ -157,8 +149,7 @@ void tst_QPauseAnimation::noTimerUpdates_data()
void tst_QPauseAnimation::noTimerUpdates()
{
- QUnifiedTimer *timer = QUnifiedTimer::instance();
- timer->setConsistentTiming(true);
+ EnableConsistentTiming enabled;
QFETCH(int, duration);
QFETCH(int, loopCount);
@@ -168,16 +159,19 @@ void tst_QPauseAnimation::noTimerUpdates()
animation.setLoopCount(loopCount);
animation.start();
QTest::qWait(animation.totalDuration() + 100);
+
+#ifdef Q_OS_WIN
+ if (animation.state() != QAbstractAnimation::Stopped)
+ QEXPECT_FAIL("", "On windows, consistent timing is not working properly due to bad timer resolution", Abort);
+#endif
+
QVERIFY(animation.state() == QAbstractAnimation::Stopped);
QCOMPARE(animation.m_updateCurrentTimeCount, 1 + loopCount);
-
- timer->setConsistentTiming(false);
}
void tst_QPauseAnimation::mulitplePauseAnimations()
{
- QUnifiedTimer *timer = QUnifiedTimer::instance();
- timer->setConsistentTiming(true);
+ EnableConsistentTiming enabled;
TestablePauseAnimation animation;
animation.setDuration(200);
@@ -188,16 +182,26 @@ void tst_QPauseAnimation::mulitplePauseAnimations()
animation.start();
animation2.start();
QTest::qWait(animation.totalDuration() + 100);
+
+#ifdef Q_OS_WIN
+ if (animation.state() != QAbstractAnimation::Stopped)
+ QEXPECT_FAIL("", "On windows, consistent timing is not working properly due to bad timer resolution", Abort);
+#endif
+
QVERIFY(animation.state() == QAbstractAnimation::Stopped);
QVERIFY(animation2.state() == QAbstractAnimation::Running);
QCOMPARE(animation.m_updateCurrentTimeCount, 2);
QCOMPARE(animation2.m_updateCurrentTimeCount, 2);
QTest::qWait(550);
+
+#ifdef Q_OS_WIN
+ if (animation2.state() != QAbstractAnimation::Stopped)
+ QEXPECT_FAIL("", "On windows, consistent timing is not working properly due to bad timer resolution", Abort);
+#endif
+
QVERIFY(animation2.state() == QAbstractAnimation::Stopped);
QCOMPARE(animation2.m_updateCurrentTimeCount, 3);
-
- timer->setConsistentTiming(false);
}
void tst_QPauseAnimation::pauseAndPropertyAnimations()
@@ -243,7 +247,7 @@ void tst_QPauseAnimation::pauseResume()
animation.pause();
QVERIFY(animation.state() == QAbstractAnimation::Paused);
animation.start();
- QTest::qWait(250);
+ QTest::qWait(300);
QVERIFY(animation.state() == QAbstractAnimation::Stopped);
QCOMPARE(animation.m_updateCurrentTimeCount, 3);
}
@@ -260,6 +264,9 @@ void tst_QPauseAnimation::sequentialPauseGroup()
animation3.setDuration(200);
group.start();
+ QCOMPARE(animation1.m_updateCurrentTimeCount, 1);
+ QCOMPARE(animation2.m_updateCurrentTimeCount, 0);
+ QCOMPARE(animation3.m_updateCurrentTimeCount, 0);
QVERIFY(group.state() == QAbstractAnimation::Running);
QVERIFY(animation1.state() == QAbstractAnimation::Running);
@@ -267,6 +274,9 @@ void tst_QPauseAnimation::sequentialPauseGroup()
QVERIFY(animation3.state() == QAbstractAnimation::Stopped);
group.setCurrentTime(250);
+ QCOMPARE(animation1.m_updateCurrentTimeCount, 2);
+ QCOMPARE(animation2.m_updateCurrentTimeCount, 1);
+ QCOMPARE(animation3.m_updateCurrentTimeCount, 0);
QVERIFY(group.state() == QAbstractAnimation::Running);
QVERIFY(animation1.state() == QAbstractAnimation::Stopped);
@@ -275,6 +285,9 @@ void tst_QPauseAnimation::sequentialPauseGroup()
QVERIFY(animation3.state() == QAbstractAnimation::Stopped);
group.setCurrentTime(500);
+ QCOMPARE(animation1.m_updateCurrentTimeCount, 2);
+ QCOMPARE(animation2.m_updateCurrentTimeCount, 2);
+ QCOMPARE(animation3.m_updateCurrentTimeCount, 1);
QVERIFY(group.state() == QAbstractAnimation::Running);
QVERIFY(animation1.state() == QAbstractAnimation::Stopped);
diff --git a/tests/auto/qpixmap/tst_qpixmap.cpp b/tests/auto/qpixmap/tst_qpixmap.cpp
index 9f5aee2..53b6230 100644
--- a/tests/auto/qpixmap/tst_qpixmap.cpp
+++ b/tests/auto/qpixmap/tst_qpixmap.cpp
@@ -166,6 +166,7 @@ private slots:
void fromImage_crash();
void fromData();
+ void loadFromDataNullValues();
void preserveDepth();
};
@@ -1436,6 +1437,26 @@ void tst_QPixmap::fromData()
QCOMPARE(img.pixel(0, 1), QRgb(0xff000000));
}
+void tst_QPixmap::loadFromDataNullValues()
+{
+ {
+ QPixmap pixmap;
+ pixmap.loadFromData(QByteArray());
+ QVERIFY(pixmap.isNull());
+ }
+ {
+ QPixmap pixmap;
+ pixmap.loadFromData(0, 123);
+ QVERIFY(pixmap.isNull());
+ }
+ {
+ QPixmap pixmap;
+ const uchar bla[] = "bla";
+ pixmap.loadFromData(bla, 0);
+ QVERIFY(pixmap.isNull());
+ }
+}
+
void tst_QPixmap::task_246446()
{
// This crashed without the bugfix in 246446
diff --git a/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp b/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp
index 7dd17e5..56c1ced 100644
--- a/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp
+++ b/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp
@@ -495,7 +495,7 @@ void tst_QPropertyAnimation::startWhenAnotherIsRunning()
anim->setEndValue(100);
QSignalSpy runningSpy(anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
anim->start(QVariantAnimation::DeleteWhenStopped);
- QTest::qWait(anim->duration() + 50);
+ QTest::qWait(anim->duration() + 100);
QCOMPARE(runningSpy.count(), 2); //started and then stopped
QVERIFY(!anim);
}
@@ -659,7 +659,7 @@ void tst_QPropertyAnimation::playForwardBackward()
anim.setStartValue(0);
anim.setEndValue(100);
anim.start();
- QTest::qWait(anim.duration() + 50);
+ QTest::qWait(anim.duration() + 100);
QCOMPARE(anim.state(), QAbstractAnimation::Stopped);
QCOMPARE(anim.currentTime(), anim.duration());
@@ -667,7 +667,7 @@ void tst_QPropertyAnimation::playForwardBackward()
anim.setDirection(QVariantAnimation::Backward);
anim.start();
QCOMPARE(anim.state(), QAbstractAnimation::Running);
- QTest::qWait(anim.duration() + 50);
+ QTest::qWait(anim.duration() + 100);
QCOMPARE(anim.state(), QAbstractAnimation::Stopped);
QCOMPARE(anim.currentTime(), 0);
@@ -676,7 +676,7 @@ void tst_QPropertyAnimation::playForwardBackward()
anim.start();
QCOMPARE(anim.state(), QAbstractAnimation::Running);
QCOMPARE(anim.currentTime(), anim.duration());
- QTest::qWait(anim.duration() + 50);
+ QTest::qWait(anim.duration() + 100);
QCOMPARE(anim.state(), QAbstractAnimation::Stopped);
QCOMPARE(anim.currentTime(), 0);
}
@@ -1093,7 +1093,7 @@ void tst_QPropertyAnimation::valueChanged()
QSignalSpy spy(&anim, SIGNAL(valueChanged(QVariant)));
anim.start();
- QTest::qWait(anim.duration() + 50);
+ QTest::qWait(anim.duration() + 100);
QCOMPARE(anim.state(), QAbstractAnimation::Stopped);
QCOMPARE(anim.currentTime(), anim.duration());
@@ -1144,7 +1144,7 @@ void tst_QPropertyAnimation::twoAnimations()
o1.anim.start();
o2.anim.start();
- QTest::qWait(o1.anim.duration() + 50);
+ QTest::qWait(o1.anim.duration() + 100);
QCOMPARE(o1.anim.state(), QAbstractAnimation::Stopped);
QCOMPARE(o2.anim.state(), QAbstractAnimation::Stopped);
@@ -1194,7 +1194,7 @@ void tst_QPropertyAnimation::deletedInUpdateCurrentTime()
MyComposedAnimation composedAnimation(&o, "value", "realValue");
composedAnimation.start();
QCOMPARE(composedAnimation.state(), QAbstractAnimation::Running);
- QTest::qWait(composedAnimation.duration() + 50);
+ QTest::qWait(composedAnimation.duration() + 100);
QCOMPARE(composedAnimation.state(), QAbstractAnimation::Stopped);
QCOMPARE(o.value(), 1000);
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp
index 062cbfa..804534f 100644
--- a/tests/auto/qscriptengine/tst_qscriptengine.cpp
+++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp
@@ -53,6 +53,7 @@
Q_DECLARE_METATYPE(QList<int>)
Q_DECLARE_METATYPE(QObjectList)
+Q_DECLARE_METATYPE(QScriptProgram)
//TESTED_CLASS=
//TESTED_FILES=
@@ -4291,6 +4292,13 @@ void tst_QScriptEngine::nativeFunctionScopes()
}
}
+static QScriptValue createProgram(QScriptContext *ctx, QScriptEngine *eng)
+{
+ QString code = ctx->argument(0).toString();
+ QScriptProgram result(code);
+ return qScriptValueFromValue(eng, result);
+}
+
void tst_QScriptEngine::evaluateProgram()
{
QScriptEngine eng;
@@ -4303,13 +4311,27 @@ void tst_QScriptEngine::evaluateProgram()
QVERIFY(!program.isNull());
QCOMPARE(program.sourceCode(), code);
QCOMPARE(program.fileName(), fileName);
- QCOMPARE(program.lineNumber(), lineNumber);
+ QCOMPARE(program.firstLineNumber(), lineNumber);
QScriptValue expected = eng.evaluate(code);
for (int x = 0; x < 10; ++x) {
QScriptValue ret = eng.evaluate(program);
QVERIFY(ret.equals(expected));
}
+
+ // operator=
+ QScriptProgram sameProgram = program;
+ QVERIFY(sameProgram == program);
+ QVERIFY(eng.evaluate(sameProgram).equals(expected));
+
+ // copy constructor
+ QScriptProgram sameProgram2(program);
+ QVERIFY(sameProgram2 == program);
+ QVERIFY(eng.evaluate(sameProgram2).equals(expected));
+
+ QScriptProgram differentProgram("2 + 3");
+ QVERIFY(differentProgram != program);
+ QVERIFY(!eng.evaluate(differentProgram).equals(expected));
}
// Program that accesses variable in the scope
@@ -4371,6 +4393,27 @@ void tst_QScriptEngine::evaluateProgram()
}
}
+ // Program created in a function call, then executed later
+ {
+ QScriptValue fun = eng.newFunction(createProgram);
+ QScriptProgram program = qscriptvalue_cast<QScriptProgram>(
+ fun.call(QScriptValue(), QScriptValueList() << "a + 1"));
+ QVERIFY(!program.isNull());
+ eng.globalObject().setProperty("a", QScriptValue());
+ {
+ QScriptValue ret = eng.evaluate(program);
+ QVERIFY(ret.isError());
+ QCOMPARE(ret.toString(), QString::fromLatin1("ReferenceError: Can't find variable: a"));
+ }
+ eng.globalObject().setProperty("a", 122);
+ {
+ QScriptValue ret = eng.evaluate(program);
+ QVERIFY(!ret.isError());
+ QVERIFY(ret.isNumber());
+ QCOMPARE(ret.toInt32(), 123);
+ }
+ }
+
// Same program run in different engines
{
QString code("1 + 2");
diff --git a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp
index 81f0ee5..a761aac 100644
--- a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp
+++ b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp
@@ -110,10 +110,10 @@ private slots:
void extension_invoctaion();
void extension();
void isEvaluatingInExtension();
+ void hasUncaughtException();
void evaluateProgram();
void evaluateProgram_SyntaxError();
void evaluateNullProgram();
- void hasUncaughtException();
private:
double m_testProperty;
@@ -2306,5 +2306,88 @@ void tst_QScriptEngineAgent::hasUncaughtException()
QVERIFY2(spy->isPass(), "At least one of a functionExit event should set hasUncaughtException flag.");
}
+void tst_QScriptEngineAgent::evaluateProgram()
+{
+ QScriptEngine eng;
+ QScriptProgram program("1 + 2", "foo.js", 123);
+ ScriptEngineSpy *spy = new ScriptEngineSpy(&eng);
+ qint64 scriptId = -1;
+ for (int x = 0; x < 10; ++x) {
+ spy->clear();
+ (void)eng.evaluate(program);
+ QCOMPARE(spy->count(), (x == 0) ? 4 : 3);
+
+ if (x == 0) {
+ // script is only loaded on first execution
+ QCOMPARE(spy->at(0).type, ScriptEngineEvent::ScriptLoad);
+ scriptId = spy->at(0).scriptId;
+ QVERIFY(scriptId != -1);
+ QCOMPARE(spy->at(0).script, program.sourceCode());
+ QCOMPARE(spy->at(0).fileName, program.fileName());
+ QCOMPARE(spy->at(0).lineNumber, program.firstLineNumber());
+ spy->removeFirst();
+ }
+
+ QCOMPARE(spy->at(0).type, ScriptEngineEvent::FunctionEntry); // evaluate()
+ QCOMPARE(spy->at(0).scriptId, scriptId);
+
+ QCOMPARE(spy->at(1).type, ScriptEngineEvent::PositionChange);
+ QCOMPARE(spy->at(1).scriptId, scriptId);
+ QCOMPARE(spy->at(1).lineNumber, program.firstLineNumber());
+
+ QCOMPARE(spy->at(2).type, ScriptEngineEvent::FunctionExit); // evaluate()
+ QCOMPARE(spy->at(2).scriptId, scriptId);
+ QVERIFY(spy->at(2).value.isNumber());
+ QCOMPARE(spy->at(2).value.toNumber(), qsreal(3));
+ }
+}
+
+void tst_QScriptEngineAgent::evaluateProgram_SyntaxError()
+{
+ QScriptEngine eng;
+ QScriptProgram program("this is not valid syntax", "foo.js", 123);
+ ScriptEngineSpy *spy = new ScriptEngineSpy(&eng);
+ qint64 scriptId = -1;
+ for (int x = 0; x < 10; ++x) {
+ spy->clear();
+ (void)eng.evaluate(program);
+ QCOMPARE(spy->count(), (x == 0) ? 8 : 7);
+
+ if (x == 0) {
+ // script is only loaded on first execution
+ QCOMPARE(spy->at(0).type, ScriptEngineEvent::ScriptLoad);
+ scriptId = spy->at(0).scriptId;
+ QVERIFY(scriptId != -1);
+ QCOMPARE(spy->at(0).script, program.sourceCode());
+ QCOMPARE(spy->at(0).fileName, program.fileName());
+ QCOMPARE(spy->at(0).lineNumber, program.firstLineNumber());
+ spy->removeFirst();
+ }
+
+ QCOMPARE(spy->at(0).type, ScriptEngineEvent::FunctionEntry); // evaluate()
+ QCOMPARE(spy->at(0).scriptId, scriptId);
+
+ QCOMPARE(spy->at(1).type, ScriptEngineEvent::ContextPush); // SyntaxError constructor
+ QCOMPARE(spy->at(2).type, ScriptEngineEvent::FunctionEntry); // SyntaxError constructor
+ QCOMPARE(spy->at(3).type, ScriptEngineEvent::FunctionExit); // SyntaxError constructor
+ QCOMPARE(spy->at(4).type, ScriptEngineEvent::ContextPop); // SyntaxError constructor
+
+ QCOMPARE(spy->at(5).type, ScriptEngineEvent::ExceptionThrow);
+ QVERIFY(spy->at(5).value.isError());
+ QCOMPARE(spy->at(5).value.toString(), QString::fromLatin1("SyntaxError: Parse error"));
+
+ QCOMPARE(spy->at(6).type, ScriptEngineEvent::FunctionExit); // evaluate()
+ QCOMPARE(spy->at(6).scriptId, scriptId);
+ }
+}
+
+void tst_QScriptEngineAgent::evaluateNullProgram()
+{
+ QScriptEngine eng;
+ ScriptEngineSpy *spy = new ScriptEngineSpy(&eng);
+ (void)eng.evaluate(QScriptProgram());
+ QCOMPARE(spy->count(), 0);
+}
+
QTEST_MAIN(tst_QScriptEngineAgent)
#include "tst_qscriptengineagent.moc"
diff --git a/tests/auto/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp b/tests/auto/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp
index aa6801a..f6afc5b 100644
--- a/tests/auto/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp
+++ b/tests/auto/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp
@@ -929,16 +929,13 @@ void tst_QSequentialAnimationGroup::startDelay()
group.addPause(125);
QCOMPARE(group.totalDuration(), 375);
- QEventLoop loop;
- QObject::connect(&group, SIGNAL(finished()), &loop, SLOT(quit()));
-
- QTime time;
- time.start();
group.start();
- loop.exec();
+ QCOMPARE(group.state(), QAnimationGroup::Running);
- QVERIFY(time.elapsed() >= 375);
- QVERIFY(time.elapsed() < 1000);
+ QTest::qWait(500);
+
+ QVERIFY(group.currentTime() == 375);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
}
void tst_QSequentialAnimationGroup::clearGroup()
diff --git a/tests/auto/qsoftkeymanager/tst_qsoftkeymanager.cpp b/tests/auto/qsoftkeymanager/tst_qsoftkeymanager.cpp
index 6efa85b..87e0533 100644
--- a/tests/auto/qsoftkeymanager/tst_qsoftkeymanager.cpp
+++ b/tests/auto/qsoftkeymanager/tst_qsoftkeymanager.cpp
@@ -47,6 +47,10 @@
#include "qdialogbuttonbox.h"
#include "private/qsoftkeymanager_p.h"
+#ifdef Q_OS_SYMBIAN
+#include "qsymbianevent.h"
+#endif
+
#ifdef Q_WS_S60
static const int s60CommandStart = 6000;
#endif
@@ -69,6 +73,13 @@ private slots:
void updateSoftKeysCompressed();
void handleCommand();
void checkSoftkeyEnableStates();
+
+private: // utils
+ inline void simulateSymbianCommand(int command)
+ {
+ QSymbianEvent event1(QSymbianEvent::CommandEvent, command);
+ qApp->symbianProcessEvent(&event1);
+ };
};
class EventListener : public QObject
@@ -167,8 +178,8 @@ void tst_QSoftKeyManager::handleCommand()
// QTest::keyPress(&w, Qt::Key_Context1);
// QTest::keyPress(&w, Qt::Key_Context2);
- qApp->symbianHandleCommand(6000);
- qApp->symbianHandleCommand(6001);
+ simulateSymbianCommand(6000);
+ simulateSymbianCommand(6001);
QApplication::processEvents();
@@ -200,9 +211,9 @@ void tst_QSoftKeyManager::checkSoftkeyEnableStates()
//disabled button gets none.
for (int i = 0; i < 10; i++) {
//simulate "Restore Defaults" softkey press
- qApp->symbianHandleCommand(s60CommandStart);
+ simulateSymbianCommand(s60CommandStart);
//simulate "help" softkey press
- qApp->symbianHandleCommand(s60CommandStart + 1);
+ simulateSymbianCommand(s60CommandStart + 1);
}
QApplication::processEvents();
QCOMPARE(spy0.count(), 10);
@@ -212,16 +223,16 @@ void tst_QSoftKeyManager::checkSoftkeyEnableStates()
for (int i = 0; i < 10; i++) {
//simulate "Restore Defaults" softkey press
- qApp->symbianHandleCommand(s60CommandStart);
+ simulateSymbianCommand(s60CommandStart);
//simulate "help" softkey press
- qApp->symbianHandleCommand(s60CommandStart + 1);
+ simulateSymbianCommand(s60CommandStart + 1);
//switch enabled button to disabled and vice versa
pBHelp->setEnabled(!pBHelp->isEnabled());
pBDefaults->setEnabled(!pBDefaults->isEnabled());
}
QApplication::processEvents();
QCOMPARE(spy0.count(), 5);
- QCOMPARE(spy1.count(), 5);
+ QCOMPARE(spy1.count(), 5);
}
QTEST_MAIN(tst_QSoftKeyManager)
diff --git a/tests/auto/qsound/tst_qsound.cpp b/tests/auto/qsound/tst_qsound.cpp
index fdbf6a2..56a330b 100644
--- a/tests/auto/qsound/tst_qsound.cpp
+++ b/tests/auto/qsound/tst_qsound.cpp
@@ -66,7 +66,7 @@ void tst_QSound::checkFinished()
QTest::qWait(5000);
#if defined(Q_WS_QWS)
- QEXPECT_FAIL("", "QSound buggy on embedded (task 122221)", Abort);
+ QEXPECT_FAIL("", "QSound buggy on embedded (task QTBUG-157)", Abort);
#endif
QVERIFY(sound.isFinished() );
}
diff --git a/tests/auto/qsplitter/tst_qsplitter.cpp b/tests/auto/qsplitter/tst_qsplitter.cpp
index cf16421..b832f3a 100644
--- a/tests/auto/qsplitter/tst_qsplitter.cpp
+++ b/tests/auto/qsplitter/tst_qsplitter.cpp
@@ -102,6 +102,8 @@ private slots:
void task187373_addAbstractScrollAreas();
void task187373_addAbstractScrollAreas_data();
void task169702_sizes();
+ void taskQTBUG_4101_ensureOneNonCollapsedWidget_data();
+ void taskQTBUG_4101_ensureOneNonCollapsedWidget();
private:
void removeThirdWidget();
@@ -1281,6 +1283,8 @@ class MyFriendlySplitter : public QSplitter
public:
MyFriendlySplitter(QWidget *parent = 0) : QSplitter(parent) {}
void setRubberBand(int pos) { QSplitter::setRubberBand(pos); }
+
+ friend class tst_QSplitter;
};
void tst_QSplitter::rubberBandNotInSplitter()
@@ -1403,5 +1407,35 @@ void tst_QSplitter::task169702_sizes()
QCOMPARE(testW->size().height(), testW->minimumSizeHint().height());
}
+void tst_QSplitter::taskQTBUG_4101_ensureOneNonCollapsedWidget_data()
+{
+ QTest::addColumn<bool>("testingHide");
+
+ QTest::newRow("last non collapsed hidden") << true;
+ QTest::newRow("last non collapsed deleted") << false;
+}
+
+void tst_QSplitter::taskQTBUG_4101_ensureOneNonCollapsedWidget()
+{
+ QFETCH(bool, testingHide);
+
+ MyFriendlySplitter s;
+ QLabel *l;
+ for (int i = 0; i < 5; ++i) {
+ l = new QLabel(QString("Label ") + QChar('A' + i));
+ l->setAlignment(Qt::AlignCenter);
+ s.addWidget(l);
+ s.moveSplitter(0, i); // Collapse all the labels except the last one.
+ }
+
+ s.show();
+ if (testingHide)
+ l->hide();
+ else
+ delete l;
+ QTest::qWait(100);
+ QVERIFY(s.sizes().at(0) > 0);
+}
+
QTEST_MAIN(tst_QSplitter)
#include "tst_qsplitter.moc"
diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp
index 8fe6f2e..4d9e50f 100644
--- a/tests/auto/qsqlquery/tst_qsqlquery.cpp
+++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp
@@ -193,6 +193,8 @@ private slots:
void sqlServerReturn0_data() { generic_data(); }
void sqlServerReturn0();
+ void QTBUG_551_data() { generic_data("QOCI"); }
+ void QTBUG_551();
private:
// returns all database connections
@@ -322,6 +324,11 @@ void tst_QSqlQuery::dropTestTables( QSqlDatabase db )
tablenames << qTableName("test141895");
tst_Databases::safeDropTables( db, tablenames );
+
+ if ( db.driverName().startsWith( "QOCI" ) ) {
+ QSqlQuery q( db );
+ q.exec( "DROP PACKAGE " + qTableName("pkg") );
+ }
}
void tst_QSqlQuery::createTestTables( QSqlDatabase db )
@@ -396,7 +403,7 @@ void tst_QSqlQuery::char1SelectUnicode()
QSKIP("Needs someone with more Unicode knowledge than I have to fix", SkipSingle);
if ( db.driver()->hasFeature( QSqlDriver::Unicode ) ) {
- QString uniStr( QChar( 'का' ) );
+ QString uniStr( QChar(0x0915) ); // DEVANAGARI LETTER KA
QSqlQuery q( db );
if ( db.driverName().startsWith( "QMYSQL" ) && tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 0 ).toInt()<5 )
@@ -2847,5 +2854,52 @@ void tst_QSqlQuery::sqlServerReturn0()
QVERIFY_SQL(q, next());
}
+void tst_QSqlQuery::QTBUG_551()
+{
+ QFETCH( QString, dbName );
+ QSqlDatabase db = QSqlDatabase::database( dbName );
+ CHECK_DATABASE( db );
+ QSqlQuery q(db);
+ QString pkgname=qTableName("pkg");
+ QVERIFY_SQL(q, exec("CREATE OR REPLACE PACKAGE "+pkgname+" IS \n\
+ \n\
+ TYPE IntType IS TABLE OF INTEGER INDEX BY BINARY_INTEGER;\n\
+ TYPE VCType IS TABLE OF VARCHAR2(60) INDEX BY BINARY_INTEGER;\n\
+ PROCEDURE P (Inp IN IntType, Outp OUT VCType);\n\
+ END "+pkgname+";"));
+
+ QVERIFY_SQL(q, exec("CREATE OR REPLACE PACKAGE BODY "+pkgname+" IS\n\
+ PROCEDURE P (Inp IN IntType, Outp OUT VCType)\n\
+ IS\n\
+ BEGIN\n\
+ Outp(1) := '1. Value is ' ||TO_CHAR(Inp(1));\n\
+ Outp(2) := '2. Value is ' ||TO_CHAR(Inp(2));\n\
+ Outp(3) := '3. Value is ' ||TO_CHAR(Inp(3));\n\
+ END p;\n\
+ END "+pkgname+";"));
+
+ QVariantList inLst, outLst, res_outLst;
+
+ q.prepare("begin "+pkgname+".p(:inp, :outp); end;");
+
+ QString StVal;
+ StVal.reserve(60);
+
+ // loading arrays
+ for (int Cnt=0; Cnt < 3; Cnt++) {
+ inLst << Cnt;
+ outLst << StVal;
+ }
+
+ q.bindValue(":inp", inLst);
+ q.bindValue(":outp", outLst, QSql::Out);
+
+ QVERIFY_SQL(q, execBatch(QSqlQuery::ValuesAsColumns) );
+ res_outLst = qVariantValue<QVariantList>(q.boundValues()[":outp"]);
+ QCOMPARE(res_outLst[0].toString(), QLatin1String("1. Value is 0"));
+ QCOMPARE(res_outLst[1].toString(), QLatin1String("2. Value is 1"));
+ QCOMPARE(res_outLst[2].toString(), QLatin1String("3. Value is 2"));
+}
+
QTEST_MAIN( tst_QSqlQuery )
#include "tst_qsqlquery.moc"
diff --git a/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp b/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp
index 3131f35..02b48fa 100644
--- a/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp
+++ b/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp
@@ -96,6 +96,7 @@ private slots:
void task_180617();
void task_180617_data() { generic_data(); }
+ void task_QTBUG_4963_setHeaderDataWithProxyModel();
private:
void generic_data(const QString &engine=QString());
@@ -428,6 +429,8 @@ void tst_QSqlQueryModel::setHeaderData()
QVERIFY(!model.setHeaderData(5, Qt::Vertical, "foo"));
QVERIFY(model.headerData(5, Qt::Vertical).isValid());
+ model.setQuery(QSqlQuery("select * from " + qTableName("test"), db));
+
qRegisterMetaType<Qt::Orientation>("Qt::Orientation");
QSignalSpy spy(&model, SIGNAL(headerDataChanged(Qt::Orientation, int, int)));
QVERIFY(model.setHeaderData(2, Qt::Horizontal, "bar"));
@@ -437,10 +440,8 @@ void tst_QSqlQueryModel::setHeaderData()
QCOMPARE(spy.value(0).value(1).toInt(), 2);
QCOMPARE(spy.value(0).value(2).toInt(), 2);
- QVERIFY(model.setHeaderData(7, Qt::Horizontal, "foo", Qt::ToolTipRole));
- QVERIFY(model.headerData(7, Qt::Horizontal, Qt::ToolTipRole).isValid());
-
- model.setQuery(QSqlQuery("select * from " + qTableName("test"), db));
+ QVERIFY(!model.setHeaderData(7, Qt::Horizontal, "foo", Qt::ToolTipRole));
+ QVERIFY(!model.headerData(7, Qt::Horizontal, Qt::ToolTipRole).isValid());
bool isToUpper = db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2");
QCOMPARE(model.headerData(0, Qt::Horizontal).toString(), isToUpper ? QString("ID") : QString("id"));
@@ -603,5 +604,14 @@ void tst_QSqlQueryModel::task_180617()
QCOMPARE(view.rowAt(0), -1);
}
+void tst_QSqlQueryModel::task_QTBUG_4963_setHeaderDataWithProxyModel()
+{
+ QSqlQueryModel plainModel;
+ QSortFilterProxyModel proxyModel;
+ proxyModel.setSourceModel(&plainModel);
+ QVERIFY(!plainModel.setHeaderData(0, Qt::Horizontal, QObject::tr("ID")));
+ // And it should not crash.
+}
+
QTEST_MAIN(tst_QSqlQueryModel)
#include "tst_qsqlquerymodel.moc"
diff --git a/tests/auto/qstring/tst_qstring.cpp b/tests/auto/qstring/tst_qstring.cpp
index 5dc1da7..2eb3152 100644
--- a/tests/auto/qstring/tst_qstring.cpp
+++ b/tests/auto/qstring/tst_qstring.cpp
@@ -201,6 +201,7 @@ private slots:
void repeatedSignature() const;
void repeated() const;
void repeated_data() const;
+ void task262677remove();
};
typedef QList<int> IntList;
@@ -4669,6 +4670,14 @@ void tst_QString::repeated_data() const
<< 4;
}
+void tst_QString::task262677remove()
+{
+ QString driveName = QLatin1String("V:\\blahblah\\more_blahblah\\");
+ driveName.remove(2, INT_MAX); // should be "V:" - instead, it's "V::\\blahblah\\more_blahblah\\"
+ QVERIFY(driveName == QLatin1String("V:"));
+}
+
+
QTEST_APPLESS_MAIN(tst_QString)
#include "tst_qstring.moc"
diff --git a/tests/auto/qtableview/tst_qtableview.cpp b/tests/auto/qtableview/tst_qtableview.cpp
index d8110e1..fe2794f 100644
--- a/tests/auto/qtableview/tst_qtableview.cpp
+++ b/tests/auto/qtableview/tst_qtableview.cpp
@@ -41,6 +41,7 @@
#include <QtGui/QtGui>
+#include <private/qtablewidget_p.h>
#include <QtTest/QtTest>
#include "../../shared/util.h"
#include "private/qapplication_p.h"
@@ -58,6 +59,13 @@
} \
} while(0)
+#ifdef QT_BUILD_INTERNAL
+#define VERIFY_SPANS_CONSISTENCY(TEST_VIEW_) \
+ QVERIFY(static_cast<QTableViewPrivate*>(QObjectPrivate::get(TEST_VIEW_))->spans.checkConsistency())
+#else
+#define VERIFY_SPANS_CONSISTENCY(TEST_VIEW_) (void)false
+#endif
+
typedef QList<int> IntList;
Q_DECLARE_METATYPE(IntList)
@@ -188,6 +196,7 @@ private slots:
void task248688_autoScrollNavigation();
void task259308_scrollVerticalHeaderSwappedSections();
void task191545_dragSelectRows();
+ void taskQTBUG_5062_spansInconsistency();
void mouseWheel_data();
void mouseWheel();
@@ -2017,8 +2026,9 @@ void tst_QTableView::resizeRowsToContents()
view.resizeRowsToContents();
QCOMPARE(resizedSpy.count(), model.rowCount());
- for (int r = 0; r < model.rowCount(); ++r)
+ for (int r = 0; r < model.rowCount(); ++r) {
QCOMPARE(view.rowHeight(r), rowHeight);
+ }
}
void tst_QTableView::resizeColumnsToContents_data()
@@ -2898,6 +2908,8 @@ void tst_QTableView::span()
view.clearSpans();
QCOMPARE(view.rowSpan(row, column), 1);
QCOMPARE(view.columnSpan(row, column), 1);
+
+ VERIFY_SPANS_CONSISTENCY(&view);
}
typedef QVector<QRect> SpanList;
@@ -3033,6 +3045,8 @@ void tst_QTableView::spans()
QCOMPARE(view.columnSpan(pos.x(), pos.y()), expectedColumnSpan);
QCOMPARE(view.rowSpan(pos.x(), pos.y()), expectedRowSpan);
+
+ VERIFY_SPANS_CONSISTENCY(&view);
}
void tst_QTableView::spansAfterRowInsertion()
@@ -3067,6 +3081,8 @@ void tst_QTableView::spansAfterRowInsertion()
view.model()->insertRows(12, 2);
QCOMPARE(view.rowSpan(7, 3), 5);
QCOMPARE(view.columnSpan(7, 3), 3);
+
+ VERIFY_SPANS_CONSISTENCY(&view);
}
void tst_QTableView::spansAfterColumnInsertion()
@@ -3101,6 +3117,8 @@ void tst_QTableView::spansAfterColumnInsertion()
view.model()->insertColumns(12, 2);
QCOMPARE(view.rowSpan(3, 7), 3);
QCOMPARE(view.columnSpan(3, 7), 5);
+
+ VERIFY_SPANS_CONSISTENCY(&view);
}
void tst_QTableView::spansAfterRowRemoval()
@@ -3138,6 +3156,8 @@ void tst_QTableView::spansAfterRowRemoval()
QCOMPARE(view.columnSpan(span.top(), span.left()), span.width());
QCOMPARE(view.rowSpan(span.top(), span.left()), span.height());
}
+
+ VERIFY_SPANS_CONSISTENCY(&view);
}
void tst_QTableView::spansAfterColumnRemoval()
@@ -3176,6 +3196,8 @@ void tst_QTableView::spansAfterColumnRemoval()
QCOMPARE(view.columnSpan(span.left(), span.top()), span.height());
QCOMPARE(view.rowSpan(span.left(), span.top()), span.width());
}
+
+ VERIFY_SPANS_CONSISTENCY(&view);
}
class Model : public QAbstractTableModel {
@@ -3267,12 +3289,12 @@ void tst_QTableView::resizeToContents()
//now let's check the row/col sizes
for(int i = 0;i<table.columnCount();i++) {
- QVERIFY( table.columnWidth(i) == table2.columnWidth(i));
- QVERIFY( table2.columnWidth(i) == table3.columnWidth(i));
+ QCOMPARE( table.columnWidth(i), table2.columnWidth(i));
+ QCOMPARE( table2.columnWidth(i), table3.columnWidth(i));
}
for(int i = 0;i<table.rowCount();i++) {
- QVERIFY( table.rowHeight(i) == table2.rowHeight(i));
- QVERIFY( table2.rowHeight(i) == table3.rowHeight(i));
+ QCOMPARE( table.rowHeight(i), table2.rowHeight(i));
+ QCOMPARE( table2.rowHeight(i), table3.rowHeight(i));
}
}
@@ -3844,5 +3866,22 @@ void tst_QTableView::task234926_setHeaderSorting()
QCOMPARE(model.stringList() , sortedDataD);
}
+void tst_QTableView::taskQTBUG_5062_spansInconsistency()
+{
+ const int nRows = 5;
+ const int nColumns = 5;
+
+ QtTestTableModel model(nRows, nColumns);
+ QtTestTableView view;
+ view.setModel(&model);
+
+ for (int i = 0; i < nRows; ++i)
+ view.setSpan(i, 0, 1, nColumns);
+ view.setSpan(2, 0, 1, 1);
+ view.setSpan(3, 0, 1, 1);
+
+ VERIFY_SPANS_CONSISTENCY(&view);
+}
+
QTEST_MAIN(tst_QTableView)
#include "tst_qtableview.moc"
diff --git a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
index 8ea137e..5577903 100644
--- a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
+++ b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
@@ -2096,7 +2096,7 @@ void tst_QTcpSocket::connectToMultiIP()
stopWatch.restart();
socket->connectToHost("multi.dev.troll.no", 81);
- QVERIFY(!socket->waitForConnected(1000));
+ QVERIFY(!socket->waitForConnected(2000));
QVERIFY(stopWatch.elapsed() < 2000);
QCOMPARE(socket->error(), QAbstractSocket::SocketTimeoutError);
@@ -2116,7 +2116,7 @@ void tst_QTcpSocket::moveToThread0()
QTcpSocket *socket = newSocket();;
socket->connectToHost(QtNetworkSettings::serverName(), 143);
socket->moveToThread(0);
- QVERIFY(socket->waitForConnected(1000));
+ QVERIFY(socket->waitForConnected(2000));
socket->write("XXX LOGOUT\r\n");
QVERIFY(socket->waitForBytesWritten(5000));
QVERIFY(socket->waitForDisconnected());
@@ -2127,7 +2127,7 @@ void tst_QTcpSocket::moveToThread0()
QTcpSocket *socket = newSocket();
socket->moveToThread(0);
socket->connectToHost(QtNetworkSettings::serverName(), 143);
- QVERIFY(socket->waitForConnected(1000));
+ QVERIFY(socket->waitForConnected(2000));
socket->write("XXX LOGOUT\r\n");
QVERIFY(socket->waitForBytesWritten(5000));
QVERIFY(socket->waitForDisconnected());
@@ -2137,7 +2137,7 @@ void tst_QTcpSocket::moveToThread0()
// Case 3: Moved after writing, while waiting for bytes to be written.
QTcpSocket *socket = newSocket();
socket->connectToHost(QtNetworkSettings::serverName(), 143);
- QVERIFY(socket->waitForConnected(1000));
+ QVERIFY(socket->waitForConnected(2000));
socket->write("XXX LOGOUT\r\n");
socket->moveToThread(0);
QVERIFY(socket->waitForBytesWritten(5000));
@@ -2148,7 +2148,7 @@ void tst_QTcpSocket::moveToThread0()
// Case 4: Moved after writing, while waiting for response.
QTcpSocket *socket = newSocket();
socket->connectToHost(QtNetworkSettings::serverName(), 143);
- QVERIFY(socket->waitForConnected(1000));
+ QVERIFY(socket->waitForConnected(2000));
socket->write("XXX LOGOUT\r\n");
QVERIFY(socket->waitForBytesWritten(5000));
socket->moveToThread(0);
@@ -2263,7 +2263,7 @@ void tst_QTcpSocket::invalidProxy()
QCOMPARE(socket->state(), QAbstractSocket::UnconnectedState);
} else {
QCOMPARE(socket->state(), QAbstractSocket::ConnectingState);
- QVERIFY(!socket->waitForConnected(1000));
+ QVERIFY(!socket->waitForConnected(2000));
}
QVERIFY(!socket->errorString().isEmpty());
@@ -2382,7 +2382,7 @@ void tst_QTcpSocket::proxyFactory()
QCOMPARE(socket->state(), QAbstractSocket::UnconnectedState);
} else {
QCOMPARE(socket->state(), QAbstractSocket::ConnectingState);
- QVERIFY(socket->waitForConnected(10000));
+ QVERIFY(socket->waitForConnected(2000));
QCOMPARE(proxyAuthCalled, 1);
}
QVERIFY(!socket->errorString().isEmpty());
diff --git a/tests/auto/qtextdocument/qtextdocument.pro b/tests/auto/qtextdocument/qtextdocument.pro
index d3ec45d..1e44a9c 100644
--- a/tests/auto/qtextdocument/qtextdocument.pro
+++ b/tests/auto/qtextdocument/qtextdocument.pro
@@ -1,4 +1,5 @@
load(qttest_p4)
+QT += xml
HEADERS += common.h
SOURCES += tst_qtextdocument.cpp
diff --git a/tests/auto/qtextdocument/tst_qtextdocument.cpp b/tests/auto/qtextdocument/tst_qtextdocument.cpp
index f393393..5237438 100644
--- a/tests/auto/qtextdocument/tst_qtextdocument.cpp
+++ b/tests/auto/qtextdocument/tst_qtextdocument.cpp
@@ -59,6 +59,7 @@
#include <qfontmetrics.h>
#include <qimage.h>
#include <qtextlayout.h>
+#include <QDomDocument>
#include "common.h"
@@ -175,6 +176,8 @@ private slots:
void testUndoBlocks();
void receiveCursorPositionChangedAfterContentsChange();
+ void escape_data();
+ void escape();
private:
void backgroundImage_checkExpectedHtml(const QTextDocument &doc);
@@ -576,7 +579,7 @@ void tst_QTextDocument::task240325()
}
void tst_QTextDocument::stylesheetFont_data()
-{
+{
QTest::addColumn<QString>("stylesheet");
QTest::addColumn<QFont>("font");
@@ -732,7 +735,7 @@ void tst_QTextDocument::toHtml_data()
cursor.insertText("Blah", fmt);
QTest::newRow("font-family-with-quotes1") << QTextDocumentFragment(&doc)
- << QString("<p DEFAULTBLOCKSTYLE><span style=\" font-family:\"Foo's Family\";\">Blah</span></p>");
+ << QString("<p DEFAULTBLOCKSTYLE><span style=\" font-family:&quot;Foo's Family&quot;;\">Blah</span></p>");
}
{
@@ -743,7 +746,7 @@ void tst_QTextDocument::toHtml_data()
cursor.insertText("Blah", fmt);
QTest::newRow("font-family-with-quotes2") << QTextDocumentFragment(&doc)
- << QString("<p DEFAULTBLOCKSTYLE><span style=\" font-family:'Foo\"s Family';\">Blah</span></p>");
+ << QString("<p DEFAULTBLOCKSTYLE><span style=\" font-family:'Foo&quot;s Family';\">Blah</span></p>");
}
{
@@ -974,6 +977,30 @@ void tst_QTextDocument::toHtml_data()
{
CREATE_DOC_AND_CURSOR();
+ QTextCharFormat fmt;
+ fmt.setAnchor(true);
+ fmt.setAnchorHref("http://www.kde.org/?a=1&b=2");
+ cursor.insertText("Blah", fmt);
+
+ QTest::newRow("href anchor with &") << QTextDocumentFragment(&doc)
+ << QString("<p DEFAULTBLOCKSTYLE><a href=\"http://www.kde.org/?a=1&amp;b=2\">Blah</a></p>");
+ }
+
+ {
+ CREATE_DOC_AND_CURSOR();
+
+ QTextCharFormat fmt;
+ fmt.setAnchor(true);
+ fmt.setAnchorHref("http://www.kde.org/?a='&b=\"");
+ cursor.insertText("Blah", fmt);
+
+ QTest::newRow("href anchor with ' and \"") << QTextDocumentFragment(&doc)
+ << QString("<p DEFAULTBLOCKSTYLE><a href=\"http://www.kde.org/?a='&amp;b=&quot;\">Blah</a></p>");
+ }
+
+ {
+ CREATE_DOC_AND_CURSOR();
+
cursor.insertTable(2, 2);
QTest::newRow("simpletable") << QTextDocumentFragment(&doc)
@@ -1541,6 +1568,9 @@ void tst_QTextDocument::toHtml()
QString output = doc->toHtml();
QCOMPARE(output, expectedOutput);
+
+ QDomDocument document;
+ QVERIFY2(document.setContent(output), "Output was not valid XML");
}
void tst_QTextDocument::toHtml2()
@@ -2652,5 +2682,25 @@ void tst_QTextDocument::receiveCursorPositionChangedAfterContentsChange()
QCOMPARE(rec.first, QString("contentsChanged"));
}
+void tst_QTextDocument::escape_data()
+{
+ QTest::addColumn<QString>("original");
+ QTest::addColumn<QString>("expected");
+
+ QTest::newRow("1") << "Hello World\n" << "Hello World\n";
+ QTest::newRow("2") << "#include <QtCore>" << "#include &lt;QtCore&gt;";
+ QTest::newRow("3") << "<p class=\"cool\"><a href=\"http://example.com/?foo=bar&amp;bar=foo\">plop --&gt; </a></p>"
+ << "&lt;p class=&quot;cool&quot;&gt;&lt;a href=&quot;http://example.com/?foo=bar&amp;amp;bar=foo&quot;&gt;plop --&amp;gt; &lt;/a&gt;&lt;/p&gt;";
+ QTest::newRow("4") << QString::fromUtf8("<\320\222\321\201>") << QString::fromUtf8("&lt;\320\222\321\201&gt;");
+}
+
+void tst_QTextDocument::escape()
+{
+ QFETCH(QString, original);
+ QFETCH(QString, expected);
+
+ QCOMPARE(Qt::escape(original), expected);
+}
+
QTEST_MAIN(tst_QTextDocument)
#include "tst_qtextdocument.moc"
diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp
index da58725..1429771 100644
--- a/tests/auto/qtreeview/tst_qtreeview.cpp
+++ b/tests/auto/qtreeview/tst_qtreeview.cpp
@@ -235,6 +235,7 @@ private slots:
void task254234_proxySort();
void task248022_changeSelection();
void task245654_changeModelAndExpandAll();
+ void doubleClickedWithSpans();
};
class QtTestModel: public QAbstractItemModel
@@ -2891,7 +2892,8 @@ void tst_QTreeView::styleOptionViewItem()
QVERIFY(!opt.text.isEmpty());
QCOMPARE(opt.index, index);
- QCOMPARE(!(opt.features & QStyleOptionViewItemV2::Alternate), !(index.row() % 2));
+ if (allCollapsed)
+ QCOMPARE(!(opt.features & QStyleOptionViewItemV2::Alternate), !(index.row() % 2));
QCOMPARE(!(opt.features & QStyleOptionViewItemV2::HasCheckIndicator), !opt.text.contains("Checkable"));
if (opt.text.contains("Beginning"))
@@ -2911,12 +2913,16 @@ void tst_QTreeView::styleOptionViewItem()
else
QCOMPARE(opt.checkState, Qt::Unchecked);
+ QCOMPARE(!(opt.state & QStyle::State_Children) , !opt.text.contains("HasChildren"));
+ QCOMPARE(!!(opt.state & QStyle::State_Sibling) , !opt.text.contains("Last"));
+
QVERIFY(!opt.text.contains("Assert"));
QStyledItemDelegate::paint(painter, option, index);
count++;
}
mutable int count;
+ bool allCollapsed;
};
QTreeView view;
@@ -2926,8 +2932,9 @@ void tst_QTreeView::styleOptionViewItem()
view.setItemDelegate(&delegate);
model.appendRow(QList<QStandardItem*>()
<< new QStandardItem("Beginning") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") );
+ QStandardItem *par1 = new QStandardItem("Beginning HasChildren");
model.appendRow(QList<QStandardItem*>()
- << new QStandardItem("Beginning") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") );
+ << par1 << new QStandardItem("Middle HasChildren") << new QStandardItem("Middle HasChildren") << new QStandardItem("End HasChildren") );
model.appendRow(QList<QStandardItem*>()
<< new QStandardItem("OnlyOne") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Assert") );
QStandardItem *checkable = new QStandardItem("Checkable");
@@ -2937,13 +2944,44 @@ void tst_QTreeView::styleOptionViewItem()
checked->setCheckState(Qt::Checked);
model.appendRow(QList<QStandardItem*>()
<< new QStandardItem("Beginning") << checkable << checked << new QStandardItem("End") );
+ model.appendRow(QList<QStandardItem*>()
+ << new QStandardItem("Beginning Last") << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") );
+
+ par1->appendRow(QList<QStandardItem*>()
+ << new QStandardItem("Beginning") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") );
+ QStandardItem *par2 = new QStandardItem("Beginning HasChildren");
+ par1->appendRow(QList<QStandardItem*>()
+ << par2 << new QStandardItem("Middle HasChildren") << new QStandardItem("Middle HasChildren") << new QStandardItem("End HasChildren") );
+ par2->appendRow(QList<QStandardItem*>()
+ << new QStandardItem("Beginning Last") << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") );
+
+ QStandardItem *par3 = new QStandardItem("Beginning Last");
+ par1->appendRow(QList<QStandardItem*>()
+ << par3 << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") );
+ par3->appendRow(QList<QStandardItem*>()
+ << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Asser") );
+ view.setRowHidden(0, par3->index(), true);
+ par1->appendRow(QList<QStandardItem*>()
+ << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Asser") );
+ view.setRowHidden(3, par1->index(), true);
+
view.setFirstColumnSpanned(2, QModelIndex(), true);
view.setAlternatingRowColors(true);
delegate.count = 0;
+ delegate.allCollapsed = true;
view.showMaximized();
+ QApplication::processEvents();
+ QTRY_VERIFY(delegate.count >= 13);
+ delegate.count = 0;
+ delegate.allCollapsed = false;
+ view.expandAll();
+ QApplication::processEvents();
QTRY_VERIFY(delegate.count >= 13);
+ view.collapse(par2->index());
+ QApplication::processEvents();
+ QTRY_VERIFY(delegate.count >= 4);
}
class task174627_TreeView : public QTreeView
@@ -3507,7 +3545,34 @@ void tst_QTreeView::task245654_changeModelAndExpandAll()
}
+void tst_QTreeView::doubleClickedWithSpans()
+{
+ QTreeView view;
+ QStandardItemModel model(1, 2);
+ view.setModel(&model);
+ view.setFirstColumnSpanned(0, QModelIndex(), true);
+ view.show();
+
+ QPoint p(10, 10);
+ QCOMPARE(view.indexAt(p), model.index(0, 0));
+ QSignalSpy spy(&view, SIGNAL(doubleClicked(QModelIndex)));
+ QTest::mousePress(view.viewport(), Qt::LeftButton, 0, p);
+ QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, p);
+ QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, p);
+ QCOMPARE(spy.count(), 1);
+
+ //let's click on the 2nd column
+ p.setX(p.x() + view.header()->sectionSize(0));
+ QCOMPARE(view.indexAt(p), model.index(0, 0));
+ //end the previous edition
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p);
+ QTest::qWait(100);
+ QTest::mousePress(view.viewport(), Qt::LeftButton, 0, p);
+ QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, p);
+ QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, p);
+ QCOMPARE(spy.count(), 2);
+}
QTEST_MAIN(tst_QTreeView)
#include "tst_qtreeview.moc"
diff --git a/tests/auto/qvariant/tst_qvariant.cpp b/tests/auto/qvariant/tst_qvariant.cpp
index 9295897..61e9a4f 100644
--- a/tests/auto/qvariant/tst_qvariant.cpp
+++ b/tests/auto/qvariant/tst_qvariant.cpp
@@ -270,6 +270,8 @@ private slots:
void task256984_setValue();
void numericalConvert();
+ void moreCustomTypes();
+ void variantInVariant();
};
Q_DECLARE_METATYPE(QDate)
@@ -318,6 +320,14 @@ void tst_QVariant::constructor()
QVariant var6(qlonglong(0));
QCOMPARE(var6.type(), QVariant::LongLong);
QCOMPARE(var6.typeName(), "qlonglong");
+
+ QVariant var7 = 5;
+ QVERIFY(var7.isValid());
+ QVERIFY(!var7.isNull());
+ QVariant var8;
+ var8.setValue<int>(5);
+ QVERIFY(var8.isValid());
+ QVERIFY(!var8.isNull());
}
void tst_QVariant::copy_constructor()
@@ -3127,7 +3137,250 @@ void tst_QVariant::numericalConvert()
}
+template<class T> void playWithVariant(const T &orig, bool isNull, const QString &toString, double toDouble, bool toBool)
+{
+ QVariant v = QVariant::fromValue(orig);
+ QVERIFY(v.isValid());
+ QCOMPARE(v.isNull(), isNull);
+ QCOMPARE(v.toString(), toString);
+ QCOMPARE(v.toDouble(), toDouble);
+ QCOMPARE(v.toBool(), toBool);
+ QCOMPARE(qvariant_cast<T>(v), orig);
+
+ {
+ QVariant v2 = v;
+ QCOMPARE(v2, v);
+ QVERIFY(v2.isValid());
+ QCOMPARE(v2.isNull(), isNull);
+ QCOMPARE(v2.toString(), toString);
+ QCOMPARE(v2.toDouble(), toDouble);
+ QCOMPARE(v2.toBool(), toBool);
+ QCOMPARE(qvariant_cast<T>(v2), orig);
+
+ QVariant v3;
+ v = QVariant();
+ QCOMPARE(v3, v);
+ v = v2;
+ QCOMPARE(v, v2);
+ QCOMPARE(qvariant_cast<T>(v2), qvariant_cast<T>(v));
+ QCOMPARE(v2.toString(), toString);
+ v3 = qVariantFromValue(orig);
+
+ QVERIFY(v3.isValid());
+ QCOMPARE(v3.isNull(), isNull);
+ QCOMPARE(v3.toString(), toString);
+ QCOMPARE(v3.toDouble(), toDouble);
+ QCOMPARE(v3.toBool(), toBool);
+ QCOMPARE(qvariant_cast<T>(v3), qvariant_cast<T>(v));
+ }
+
+ QVERIFY(v.isValid());
+ QCOMPARE(v.isNull(), isNull);
+ QCOMPARE(v.toString(), toString);
+ QCOMPARE(v.toDouble(), toDouble);
+ QCOMPARE(v.toBool(), toBool);
+ QCOMPARE(qvariant_cast<T>(v), orig);
+
+ if (qMetaTypeId<T>() != qMetaTypeId<QVariant>()) {
+ QCOMPARE(v.userType(), qMetaTypeId<T>());
+ QCOMPARE(QVariant::typeToName(QVariant::Type(v.userType())), QMetaType::typeName(qMetaTypeId<T>()));
+ }
+}
+
+
+struct MyPrimitive
+{
+ char x, y;
+ bool operator==(const MyPrimitive &o) const
+ {
+ return x == o.x && y == o.y;
+ }
+};
+Q_DECLARE_TYPEINFO(MyPrimitive, Q_PRIMITIVE_TYPE);
+
+struct MyData
+{
+ void *ptr;
+ MyData() : ptr(this) {}
+ ~MyData() { Q_ASSERT(ptr == this); }
+ MyData(const MyData& o) : ptr(this) { Q_ASSERT(o.ptr == &o); }
+ MyData &operator=(const MyData &o)
+ {
+ Q_ASSERT(ptr == this);
+ Q_ASSERT(o.ptr == &o);
+ return *this;
+ }
+ bool operator==(const MyData &o) const
+ {
+ Q_ASSERT(ptr == this);
+ Q_ASSERT(o.ptr == &o);
+ return true;
+ }
+};
+
+struct MyMovable
+{
+ static int count;
+ int v;
+ MyMovable() { v = count++; }
+ ~MyMovable() { count--; }
+ MyMovable(const MyMovable &o) : v(o.v) { count++; }
+
+ bool operator==(const MyMovable &o) const
+ {
+ return v == o.v;
+ }
+};
+
+int MyMovable::count = 0;
+
+
+Q_DECLARE_TYPEINFO(MyMovable, Q_MOVABLE_TYPE);
+
+Q_DECLARE_METATYPE(QList<QSize>)
+Q_DECLARE_METATYPE(MyPrimitive)
+Q_DECLARE_METATYPE(MyData)
+Q_DECLARE_METATYPE(MyMovable)
+Q_DECLARE_METATYPE(QList<MyPrimitive>)
+Q_DECLARE_METATYPE(QList<MyData>)
+Q_DECLARE_METATYPE(QList<MyMovable>)
+Q_DECLARE_METATYPE(MyPrimitive *)
+Q_DECLARE_METATYPE(MyData *)
+Q_DECLARE_METATYPE(MyMovable *)
+void tst_QVariant::moreCustomTypes()
+{
+ {
+ QList<QSize> listSize;
+ playWithVariant(listSize, false, QString(), 0, false);
+ listSize << QSize(4,5) << QSize(89,23) << QSize(5,6);
+ playWithVariant(listSize, false, QString(), 0, false);
+ }
+
+ {
+ QString str;
+ playWithVariant(str, true, QString(), 0, false);
+ str = QString::fromLatin1("123456789.123");
+ playWithVariant(str, false, str, 123456789.123, true);
+ }
+
+ {
+ QSize size;
+ playWithVariant(size, false, QString(), 0, false);
+ playWithVariant(QSize(45,78), false, QString(), 0, false);
+ }
+
+ {
+ MyData d;
+ playWithVariant(d, false, QString(), 0, false);
+ playWithVariant(&d, false, QString(), 0, false);
+ QList<MyData> l;
+ playWithVariant(l, false, QString(), 0, false);
+ l << MyData() << MyData();
+ playWithVariant(l, false, QString(), 0, false);
+ }
+
+ {
+ MyPrimitive d = { 4, 5 };
+ playWithVariant(d, false, QString(), 0, false);
+ playWithVariant(&d, false, QString(), 0, false);
+ QList<MyPrimitive> l;
+ playWithVariant(l, false, QString(), 0, false);
+ l << d;
+ playWithVariant(l, false, QString(), 0, false);
+ }
+
+ {
+ MyMovable d;
+ playWithVariant(d, false, QString(), 0, false);
+ playWithVariant(&d, false, QString(), 0, false);
+ QList<MyMovable> l;
+ playWithVariant(l, false, QString(), 0, false);
+ l << MyMovable() << d;
+ playWithVariant(l, false, QString(), 0, false);
+ }
+ QCOMPARE(MyMovable::count, 0);
+
+ {
+ playWithVariant(12.12, false, "12.12", 12.12, true);
+ playWithVariant(12.12f, false, "12.12", 12.12f, true);
+ playWithVariant('a', false, "a", 'a', true);
+ playWithVariant((unsigned char)('a'), false, "a", 'a', true);
+ playWithVariant( quint8(12), false, "\xc", 12, true);
+ playWithVariant( qint8(13), false, "\xd", 13, true);
+ playWithVariant(quint16(14), false, "14", 14, true);
+ playWithVariant( qint16(15), false, "15", 15, true);
+ playWithVariant(quint32(16), false, "16", 16, true);
+ playWithVariant( qint32(17), false, "17", 17, true);
+ playWithVariant(quint64(18), false, "18", 18, true);
+ playWithVariant( qint64(19), false, "19", 19, true);
+ playWithVariant( qint8(-12), false, "\xf4", -12, true);
+ playWithVariant( qint16(-13), false, "-13", -13, true);
+ playWithVariant( qint32(-14), false, "-14", -14, true);
+ playWithVariant( qint64(-15), false, "-15", -15, true);
+ playWithVariant(quint64(0), false, "0", 0, false);
+ playWithVariant( true, false, "true", 1, true);
+ playWithVariant( false, false, "false", 0, false);
+
+ playWithVariant(QString("hello\n"), false, "hello\n", 0, true);
+ }
+
+ {
+ int i = 5;
+ playWithVariant((void *)(&i), false, QString(), 0, false);
+ playWithVariant((void *)(0), false, QString(), 0, false);
+ }
+
+ {
+ QVariant v1 = QVariant::fromValue(5);
+ QVariant v2 = QVariant::fromValue(5.0);
+ QVariant v3 = QVariant::fromValue(quint16(5));
+ QVariant v4 = 5;
+ QVariant v5 = QVariant::fromValue(MyPrimitive());
+ QVariant v6 = QVariant::fromValue(MyMovable());
+ QVariant v7 = QVariant::fromValue(MyData());
+ playWithVariant(v1, false, "5", 5, true);
+ playWithVariant(v2, false, "5", 5, true);
+ playWithVariant(v3, false, "5", 5, true);
+ playWithVariant(v4, false, "5", 5, true);
+
+ playWithVariant(v5, false, QString(), 0, false);
+ }
+}
+
+
+void tst_QVariant::variantInVariant()
+{
+ QVariant var1 = 5;
+ QCOMPARE(var1.type(), QVariant::Int);
+ QVariant var2 = var1;
+ QCOMPARE(var2, var1);
+ QCOMPARE(var2.type(), QVariant::Int);
+ QVariant var3 = QVariant::fromValue(var1);
+ QCOMPARE(var3, var1);
+ QCOMPARE(var3.type(), QVariant::Int);
+ QVariant var4 = qvariant_cast<QVariant>(var1);
+ QCOMPARE(var4, var1);
+ QCOMPARE(var4.type(), QVariant::Int);
+ QVariant var5;
+ var5 = var1;
+ QCOMPARE(var5, var1);
+ QCOMPARE(var5.type(), QVariant::Int);
+ QVariant var6;
+ var6.setValue(var1);
+ QCOMPARE(var6, var1);
+ QCOMPARE(var6.type(), QVariant::Int);
+
+ QCOMPARE(QVariant::fromValue(var1), QVariant::fromValue(var2));
+ QCOMPARE(qvariant_cast<QVariant>(var3), QVariant::fromValue(var4));
+ QCOMPARE(qvariant_cast<QVariant>(var5), qvariant_cast<QVariant>(var6));
+
+ QString str("hello");
+ QVariant var8 = qvariant_cast<QVariant>(QVariant::fromValue(QVariant::fromValue(str)));
+ QCOMPARE((int)var8.type(), (int)QVariant::String);
+ QCOMPARE(qvariant_cast<QString>(QVariant(qvariant_cast<QVariant>(var8))), str);
+}
+
QTEST_MAIN(tst_QVariant)
#include "tst_qvariant.moc"
diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp
index 050d1c5..bc8cece 100644
--- a/tests/auto/qwidget/tst_qwidget.cpp
+++ b/tests/auto/qwidget/tst_qwidget.cpp
@@ -332,6 +332,7 @@ private slots:
void doubleRepaint();
#ifndef Q_WS_MAC
void resizeInPaintEvent();
+ void opaqueChildren();
#endif
void setMaskInResizeEvent();
@@ -2982,7 +2983,7 @@ void tst_QWidget::stackUnder()
qApp->processEvents();
#endif
#ifndef Q_WS_MAC
- QEXPECT_FAIL(0, "Task 153869", Continue);
+ QEXPECT_FAIL(0, "See QTBUG-493", Continue);
#endif
QCOMPARE(child->numPaintEvents, 0);
} else {
@@ -8272,6 +8273,47 @@ void tst_QWidget::resizeInPaintEvent()
// Make sure the resize triggers another update.
QTRY_COMPARE(widget.numPaintEvents, 1);
}
+
+void tst_QWidget::opaqueChildren()
+{
+ QWidget widget;
+ widget.resize(200, 200);
+
+ QWidget child(&widget);
+ child.setGeometry(-700, -700, 200, 200);
+
+ QWidget grandChild(&child);
+ grandChild.resize(200, 200);
+
+ QWidget greatGrandChild(&grandChild);
+ greatGrandChild.setGeometry(50, 50, 200, 200);
+ greatGrandChild.setPalette(Qt::red);
+ greatGrandChild.setAutoFillBackground(true); // Opaque child widget.
+
+ widget.show();
+#ifdef Q_WS_X11
+ qt_x11_wait_for_window_manager(&widget);
+#endif
+ QTest::qWait(100);
+
+ // Child, grandChild and greatGrandChild are outside the ancestor clip.
+ QRegion expectedOpaqueRegion(50, 50, 150, 150);
+ QCOMPARE(qt_widget_private(&grandChild)->getOpaqueChildren(), expectedOpaqueRegion);
+
+ // Now they are all inside the ancestor clip.
+ child.setGeometry(50, 50, 150, 150);
+ QCOMPARE(qt_widget_private(&grandChild)->getOpaqueChildren(), expectedOpaqueRegion);
+
+ // Set mask on greatGrandChild.
+ const QRegion mask(10, 10, 50, 50);
+ greatGrandChild.setMask(mask);
+ expectedOpaqueRegion &= mask.translated(50, 50);
+ QCOMPARE(qt_widget_private(&grandChild)->getOpaqueChildren(), expectedOpaqueRegion);
+
+ // Make greatGrandChild "transparent".
+ greatGrandChild.setAutoFillBackground(false);
+ QCOMPARE(qt_widget_private(&grandChild)->getOpaqueChildren(), QRegion());
+}
#endif