diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2009-12-26 19:49:55 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-12-26 19:49:55 (GMT) |
commit | 24270550463fbc81c7725595719e6e21eade2819 (patch) | |
tree | 4e7c118ed3c4b42e43403960365a2672441ea05e /tests | |
parent | 4376f8871b4422830e9ffb7f3acbc29766d8d218 (diff) | |
parent | 444fb94e02308bedc7b37a702adb95b740168a94 (diff) | |
download | Qt-24270550463fbc81c7725595719e6e21eade2819.zip Qt-24270550463fbc81c7725595719e6e21eade2819.tar.gz Qt-24270550463fbc81c7725595719e6e21eade2819.tar.bz2 |
Merge branch '4.6'
Conflicts:
examples/webkit/fancybrowser/main.cpp
src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
tools/assistant/tools/assistant/bookmarkmanager.cpp
Diffstat (limited to 'tests')
36 files changed, 1128 insertions, 250 deletions
diff --git a/tests/auto/headers/tst_headers.cpp b/tests/auto/headers/tst_headers.cpp index 36d25fe..329143d 100644 --- a/tests/auto/headers/tst_headers.cpp +++ b/tests/auto/headers/tst_headers.cpp @@ -217,8 +217,8 @@ void tst_Headers::licenseCheck() QCOMPARE(content.at(i++), QString("/****************************************************************************")); if (licenseType != "3RDPARTY") { QCOMPARE(content.at(i++), QString("**")); - if (sourceFile.endsWith("/tests/auto/qabstractitemmodel/dynamictreemodel.cpp") - || sourceFile.endsWith("/tests/auto/qabstractitemmodel/dynamictreemodel.h") + if (sourceFile.endsWith("/tests/auto/modeltest/dynamictreemodel.cpp") + || sourceFile.endsWith("/tests/auto/modeltest/dynamictreemodel.h") || sourceFile.endsWith("/src/network/kernel/qnetworkproxy_p.h")) { // These files are not copyrighted by Nokia. diff --git a/tests/auto/moc/tst_moc.cpp b/tests/auto/moc/tst_moc.cpp index 2316ba2..1ca2b3a 100644 --- a/tests/auto/moc/tst_moc.cpp +++ b/tests/auto/moc/tst_moc.cpp @@ -489,6 +489,7 @@ private slots: void constructors(); void typenameWithUnsigned(); void warnOnVirtualSignal(); + void QTBUG5590_dummyProperty(); signals: void sigWithUnsignedArg(unsigned foo); void sigWithSignedArg(signed foo); @@ -1216,6 +1217,40 @@ void tst_Moc::warnOnVirtualSignal() #endif } + +class QTBUG5590_DummyObject: public QObject +{ + Q_OBJECT + Q_PROPERTY(bool dummy) +}; + +class QTBUG5590_PropertyObject: public QTBUG5590_DummyObject +{ + Q_OBJECT + Q_PROPERTY(int value READ value WRITE setValue) + Q_PROPERTY(int value2 READ value2 WRITE setValue2) + + public: + QTBUG5590_PropertyObject() : m_value(85), m_value2(40) { } + int value() const { return m_value; } + void setValue(int value) { m_value = value; } + int value2() const { return m_value2; } + void setValue2(int value) { m_value2 = value; } + private: + int m_value, m_value2; +}; + +void tst_Moc::QTBUG5590_dummyProperty() +{ + QTBUG5590_PropertyObject o; + QCOMPARE(o.property("value").toInt(), 85); + QCOMPARE(o.property("value2").toInt(), 40); + o.setProperty("value", 32); + QCOMPARE(o.value(), 32); + o.setProperty("value2", 82); + QCOMPARE(o.value2(), 82); +} + QTEST_APPLESS_MAIN(tst_Moc) #include "tst_moc.moc" diff --git a/tests/auto/qabstractitemmodel/dynamictreemodel.cpp b/tests/auto/modeltest/dynamictreemodel.cpp index 24d3ab3..24d3ab3 100644 --- a/tests/auto/qabstractitemmodel/dynamictreemodel.cpp +++ b/tests/auto/modeltest/dynamictreemodel.cpp diff --git a/tests/auto/qabstractitemmodel/dynamictreemodel.h b/tests/auto/modeltest/dynamictreemodel.h index 3f0d90d..3f0d90d 100644 --- a/tests/auto/qabstractitemmodel/dynamictreemodel.h +++ b/tests/auto/modeltest/dynamictreemodel.h diff --git a/tests/auto/modeltest/modeltest.cpp b/tests/auto/modeltest/modeltest.cpp index 39d00f6..0ca9e14 100644 --- a/tests/auto/modeltest/modeltest.cpp +++ b/tests/auto/modeltest/modeltest.cpp @@ -475,8 +475,8 @@ void ModelTest::data() void ModelTest::rowsAboutToBeInserted ( const QModelIndex &parent, int start, int end ) { // Q_UNUSED(end); - qDebug() << "rowsAboutToBeInserted" << "start=" << start << "end=" << end << "parent=" << model->data ( parent ).toString() - << "current count of parent=" << model->rowCount ( parent ); // << "display of last=" << model->data( model->index(start-1, 0, parent) ); +// qDebug() << "rowsAboutToBeInserted" << "start=" << start << "end=" << end << "parent=" << model->data ( parent ).toString() +// << "current count of parent=" << model->rowCount ( parent ); // << "display of last=" << model->data( model->index(start-1, 0, parent) ); // qDebug() << model->index(start-1, 0, parent) << model->data( model->index(start-1, 0, parent) ); Changing c; c.parent = parent; @@ -495,14 +495,14 @@ void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int end ) { Changing c = insert.pop(); Q_ASSERT ( c.parent == parent ); - qDebug() << "rowsInserted" << "start=" << start << "end=" << end << "oldsize=" << c.oldSize - << "parent=" << model->data ( parent ).toString() << "current rowcount of parent=" << model->rowCount ( parent ); - - for (int ii=start; ii <= end; ii++) - { - qDebug() << "itemWasInserted:" << ii << model->data ( model->index ( ii, 0, parent )); - } - qDebug(); +// qDebug() << "rowsInserted" << "start=" << start << "end=" << end << "oldsize=" << c.oldSize +// << "parent=" << model->data ( parent ).toString() << "current rowcount of parent=" << model->rowCount ( parent ); + +// for (int ii=start; ii <= end; ii++) +// { +// qDebug() << "itemWasInserted:" << ii << model->data ( model->index ( ii, 0, parent )); +// } +// qDebug(); Q_ASSERT ( c.oldSize + ( end - start + 1 ) == model->rowCount ( parent ) ); Q_ASSERT ( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) ); diff --git a/tests/auto/modeltest/modeltest.pro b/tests/auto/modeltest/modeltest.pro index 6655d85..f157da0 100644 --- a/tests/auto/modeltest/modeltest.pro +++ b/tests/auto/modeltest/modeltest.pro @@ -1,6 +1,6 @@ load(qttest_p4) -SOURCES += tst_modeltest.cpp modeltest.cpp -HEADERS += modeltest.h +SOURCES += tst_modeltest.cpp modeltest.cpp dynamictreemodel.cpp +HEADERS += modeltest.h dynamictreemodel.h diff --git a/tests/auto/modeltest/tst_modeltest.cpp b/tests/auto/modeltest/tst_modeltest.cpp index a719168..262b966 100644 --- a/tests/auto/modeltest/tst_modeltest.cpp +++ b/tests/auto/modeltest/tst_modeltest.cpp @@ -44,6 +44,7 @@ #include <QtGui/QtGui> #include "modeltest.h" +#include "dynamictreemodel.h" class tst_ModelTest : public QObject @@ -64,6 +65,8 @@ private slots: void stringListModel(); void treeWidgetModel(); void standardItemModel(); + void testInsertThroughProxy(); + void moveSourceItems(); }; @@ -92,15 +95,15 @@ void tst_ModelTest::stringListModel() { QStringListModel model; QSortFilterProxyModel proxy; - + ModelTest t1(&model); ModelTest t2(&proxy); - + proxy.setSourceModel(&model); - + model.setStringList(QStringList() << "2" << "3" << "1"); model.setStringList(QStringList() << "a" << "e" << "plop" << "b" << "c" ); - + proxy.setDynamicSortFilter(true); proxy.setFilterRegExp(QRegExp("[^b]")); } @@ -110,7 +113,7 @@ void tst_ModelTest::treeWidgetModel() QTreeWidget widget; ModelTest t1(widget.model()); - + QTreeWidgetItem *root = new QTreeWidgetItem(&widget, QStringList("root")); for (int i = 0; i < 20; ++i) { new QTreeWidgetItem(root, QStringList(QString::number(i))); @@ -120,7 +123,7 @@ void tst_ModelTest::treeWidgetModel() QTreeWidgetItem *parent = new QTreeWidgetItem(&widget, QStringList("parent")); new QTreeWidgetItem(parent, QStringList("child")); widget.setItemHidden(parent, true); - + widget.sortByColumn(0); } @@ -128,23 +131,153 @@ void tst_ModelTest::standardItemModel() { QStandardItemModel model(10,10); QSortFilterProxyModel proxy; - - + + ModelTest t1(&model); ModelTest t2(&proxy); - + proxy.setSourceModel(&model); - + model.insertRows(2, 5); model.removeRows(4, 5); model.insertColumns(2, 5); model.removeColumns(4, 5); - + model.insertRows(0,5, model.index(1,1)); model.insertColumns(0,5, model.index(1,3)); - } +void tst_ModelTest::testInsertThroughProxy() +{ + DynamicTreeModel *model = new DynamicTreeModel(this); + + QSortFilterProxyModel *proxy = new QSortFilterProxyModel(this); + proxy->setSourceModel(model); + + new ModelTest(proxy, this); + + ModelInsertCommand *insertCommand = new ModelInsertCommand(model, this); + insertCommand->setNumCols(4); + insertCommand->setStartRow(0); + insertCommand->setEndRow(9); + // Parent is QModelIndex() + insertCommand->doCommand(); + + insertCommand = new ModelInsertCommand(model, this); + insertCommand->setNumCols(4); + insertCommand->setAncestorRowNumbers(QList<int>() << 5); + insertCommand->setStartRow(0); + insertCommand->setEndRow(9); + insertCommand->doCommand(); + + ModelMoveCommand *moveCommand = new ModelMoveCommand(model, this); + moveCommand->setNumCols(4); + moveCommand->setStartRow(0); + moveCommand->setEndRow(0); + moveCommand->setDestRow(9); + moveCommand->setDestAncestors(QList<int>() << 5); + moveCommand->doCommand(); +} + +/** + Makes the persistent index list publicly accessible +*/ +class AccessibleProxyModel : public QSortFilterProxyModel +{ + Q_OBJECT +public: + AccessibleProxyModel(QObject *parent = 0) : QSortFilterProxyModel(parent) {} + + QModelIndexList persistent() + { + return persistentIndexList(); + } +}; + +class ObservingObject : public QObject +{ + Q_OBJECT +public: + ObservingObject(AccessibleProxyModel *proxy, QObject *parent = 0) + : QObject(parent), + m_proxy(proxy) + { + connect(m_proxy, SIGNAL(layoutAboutToBeChanged()), SLOT(storePersistent())); + connect(m_proxy, SIGNAL(layoutChanged()), SLOT(checkPersistent())); + } + +public slots: + + void storePersistent(const QModelIndex &parent) + { + for (int row = 0; row < m_proxy->rowCount(parent); ++row) { + QModelIndex proxyIndex = m_proxy->index(row, 0, parent); + QModelIndex sourceIndex = m_proxy->mapToSource(proxyIndex); + Q_ASSERT(proxyIndex.isValid()); + Q_ASSERT(sourceIndex.isValid()); + m_persistentSourceIndexes.append(sourceIndex); + m_persistentProxyIndexes.append(proxyIndex); + if (m_proxy->hasChildren(proxyIndex)) + storePersistent(proxyIndex); + } + } + + void storePersistent() + { + m_persistentSourceIndexes.clear(); + m_persistentProxyIndexes.clear(); + Q_ASSERT(m_proxy->persistent().isEmpty()); + storePersistent(QModelIndex()); + Q_ASSERT(!m_proxy->persistent().isEmpty()); + } + + void checkPersistent() + { + for (int row = 0; row < m_persistentProxyIndexes.size(); ++row) { + QModelIndex updatedProxy = m_persistentProxyIndexes.at(row); + QModelIndex updatedSource = m_persistentSourceIndexes.at(row); + } + for (int row = 0; row < m_persistentProxyIndexes.size(); ++row) { + QModelIndex updatedProxy = m_persistentProxyIndexes.at(row); + QModelIndex updatedSource = m_persistentSourceIndexes.at(row); + QCOMPARE(m_proxy->mapToSource(updatedProxy), updatedSource); + } + } + +private: + AccessibleProxyModel *m_proxy; + QList<QPersistentModelIndex> m_persistentSourceIndexes; + QList<QPersistentModelIndex> m_persistentProxyIndexes; +}; + +void tst_ModelTest::moveSourceItems() +{ + DynamicTreeModel *model = new DynamicTreeModel(this); + AccessibleProxyModel *proxy = new AccessibleProxyModel(this); + proxy->setSourceModel(model); + + ModelInsertCommand *insertCommand = new ModelInsertCommand(model, this); + insertCommand->setStartRow(0); + insertCommand->setEndRow(2); + insertCommand->doCommand(); + + insertCommand = new ModelInsertCommand(model, this); + insertCommand->setAncestorRowNumbers(QList<int>() << 1); + insertCommand->setStartRow(0); + insertCommand->setEndRow(2); + insertCommand->doCommand(); + + ObservingObject observer(proxy); + + ModelMoveCommand *moveCommand = new ModelMoveCommand(model, this); + moveCommand->setStartRow(0); + moveCommand->setEndRow(0); + moveCommand->setDestAncestors(QList<int>() << 1); + moveCommand->setDestRow(0); + moveCommand->doCommand(); +} + + QTEST_MAIN(tst_ModelTest) #include "tst_modeltest.moc" diff --git a/tests/auto/qabstractitemmodel/qabstractitemmodel.pro b/tests/auto/qabstractitemmodel/qabstractitemmodel.pro index a31868b..52c4e96 100644 --- a/tests/auto/qabstractitemmodel/qabstractitemmodel.pro +++ b/tests/auto/qabstractitemmodel/qabstractitemmodel.pro @@ -1,6 +1,9 @@ load(qttest_p4) -SOURCES += tst_qabstractitemmodel.cpp dynamictreemodel.cpp -HEADERS += dynamictreemodel.h + +INCLUDEPATH += $$PWD/../modeltest + +SOURCES += tst_qabstractitemmodel.cpp ../modeltest/dynamictreemodel.cpp ../modeltest/modeltest.cpp +HEADERS += ../modeltest/dynamictreemodel.h ../modeltest/modeltest.h diff --git a/tests/auto/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/qabstractitemview/tst_qabstractitemview.cpp index 6479829..bf3af63 100644 --- a/tests/auto/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/qabstractitemview/tst_qabstractitemview.cpp @@ -48,6 +48,7 @@ #include <qlistview.h> #include <qlistwidget.h> #include <qtableview.h> +#include <qtablewidget.h> #include <qtreeview.h> #include <qtreewidget.h> #include <qheaderview.h> @@ -226,6 +227,7 @@ private slots: void shiftSelectionAfterRubberbandSelection(); void ctrlRubberbandSelection(); void QTBUG6407_extendedSelection(); + void QTBUG6753_selectOnSelection(); }; class MyAbstractItemDelegate : public QAbstractItemDelegate @@ -1475,5 +1477,26 @@ void tst_QAbstractItemView::QTBUG6407_extendedSelection() } +void tst_QAbstractItemView::QTBUG6753_selectOnSelection() +{ + QTableWidget table(5, 5); + for (int i = 0; i < table.rowCount(); ++i) + for (int j = 0; j < table.columnCount(); ++j) + table.setItem(i, j, new QTableWidgetItem("choo-be-doo-wah")); + + table.show(); + table.setSelectionMode(QAbstractItemView::ExtendedSelection); + table.selectAll(); + QTest::qWaitForWindowShown(&table); + QModelIndex item = table.model()->index(1,1); + QRect itemRect = table.visualRect(item); + QTest::mouseMove(table.viewport(), itemRect.center()); + QTest::mouseClick(table.viewport(), Qt::LeftButton, Qt::NoModifier, itemRect.center()); + QTest::qWait(20); + + QCOMPARE(table.selectedItems().count(), 1); + QCOMPARE(table.selectedItems().first(), table.item(item.row(), item.column())); +} + QTEST_MAIN(tst_QAbstractItemView) #include "tst_qabstractitemview.moc" diff --git a/tests/auto/qdbuspendingreply/tst_qdbuspendingreply.cpp b/tests/auto/qdbuspendingreply/tst_qdbuspendingreply.cpp index 6398d9c..82e6389 100644 --- a/tests/auto/qdbuspendingreply/tst_qdbuspendingreply.cpp +++ b/tests/auto/qdbuspendingreply/tst_qdbuspendingreply.cpp @@ -93,6 +93,7 @@ private slots: } void init(); + void unconnected(); void simpleTypes(); void complexTypes(); void wrongTypes(); @@ -252,6 +253,30 @@ void tst_QDBusPendingReply::init() QVERIFY(iface->isValid()); } +void tst_QDBusPendingReply::unconnected() +{ + QDBusConnection con("invalid stored connection"); + QVERIFY(!con.isConnected()); + QDBusInterface iface("doesnt.matter", "/", "doesnt.matter", con); + QVERIFY(!iface.isValid()); + + QDBusPendingReply<> rvoid = iface.asyncCall("ReloadConfig"); + QVERIFY(rvoid.isFinished()); + QVERIFY(!rvoid.isValid()); + QVERIFY(rvoid.isError()); + rvoid.waitForFinished(); + QVERIFY(!rvoid.isValid()); + QVERIFY(rvoid.isError()); + + QDBusPendingReply<QString> rstring = iface.asyncCall("GetId"); + QVERIFY(rstring.isFinished()); + QVERIFY(!rstring.isValid()); + QVERIFY(rstring.isError()); + rstring.waitForFinished(); + QVERIFY(!rstring.isValid()); + QVERIFY(rstring.isError()); +} + void tst_QDBusPendingReply::simpleTypes() { QDBusPendingReply<> rvoid = iface->asyncCall("retrieveVoid"); diff --git a/tests/auto/qdbusreply/tst_qdbusreply.cpp b/tests/auto/qdbusreply/tst_qdbusreply.cpp index 9866302..e36d288 100644 --- a/tests/auto/qdbusreply/tst_qdbusreply.cpp +++ b/tests/auto/qdbusreply/tst_qdbusreply.cpp @@ -93,6 +93,7 @@ private slots: } void init(); + void unconnected(); void simpleTypes(); void complexTypes(); void wrongTypes(); @@ -236,6 +237,21 @@ void tst_QDBusReply::init() QVERIFY(iface->isValid()); } +void tst_QDBusReply::unconnected() +{ + QDBusConnection con("invalid stored connection"); + QVERIFY(!con.isConnected()); + QDBusInterface iface("doesnt.matter", "/", "doesnt.matter", con); + QVERIFY(!iface.isValid()); + + QDBusReply<void> rvoid = iface.asyncCall("ReloadConfig"); + QVERIFY(!rvoid.isValid()); + + QDBusReply<QString> rstring = iface.asyncCall("GetId"); + QVERIFY(!rstring.isValid()); + QVERIFY(rstring.value().isEmpty()); +} + void tst_QDBusReply::simpleTypes() { QDBusReply<bool> rbool = iface->call(QDBus::BlockWithGui, "retrieveBool"); diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp index 7ee5665..2b2f431 100644 --- a/tests/auto/qfile/tst_qfile.cpp +++ b/tests/auto/qfile/tst_qfile.cpp @@ -220,6 +220,9 @@ public: private: enum FileType { OpenQFile, OpenFd, OpenStream }; + void openStandardStreamsFileDescriptors(); + void openStandardStreamsBufferedStreams(); + bool openFd(QFile &file, QIODevice::OpenMode mode) { int fdMode = QT_OPEN_LARGEFILE | QT_OPEN_BINARY; @@ -554,6 +557,10 @@ void tst_QFile::size() QFETCH( QString, filename ); QFETCH( qint64, size ); +#ifdef Q_WS_WINCE + filename = QFileInfo(filename).absoluteFilePath(); +#endif + { QFile f( filename ); QCOMPARE( f.size(), size ); @@ -564,24 +571,29 @@ void tst_QFile::size() { QFile f; - int fd = QT_OPEN(filename.toLocal8Bit().constData(), QT_OPEN_RDONLY); - QVERIFY( fd != -1 ); - QVERIFY( f.open(fd, QIODevice::ReadOnly) ); + FILE* stream = QT_FOPEN(filename.toLocal8Bit().constData(), "rb"); + QVERIFY( stream ); + QVERIFY( f.open(stream, QIODevice::ReadOnly) ); QCOMPARE( f.size(), size ); f.close(); - QT_CLOSE(fd); + fclose(stream); } { +#ifdef Q_WS_WINCE + QSKIP("Currently low level file I/O not well supported on Windows CE", SkipSingle); +#endif QFile f; - FILE* stream = QT_FOPEN(filename.toLocal8Bit().constData(), "rb"); - QVERIFY( stream ); - QVERIFY( f.open(stream, QIODevice::ReadOnly) ); + + int fd = QT_OPEN(filename.toLocal8Bit().constData(), QT_OPEN_RDONLY); + + QVERIFY( fd != -1 ); + QVERIFY( f.open(fd, QIODevice::ReadOnly) ); QCOMPARE( f.size(), size ); f.close(); - fclose(stream); + QT_CLOSE(fd); } } @@ -603,6 +615,7 @@ void tst_QFile::seek() QVERIFY(file.seek(10)); QCOMPARE(file.pos(), qint64(10)); QCOMPARE(file.size(), qint64(0)); + file.close(); QFile::remove("newfile.txt"); } @@ -1128,9 +1141,15 @@ void tst_QFile::copyFallback() QVERIFY(QFile::exists("file-copy-destination.txt")); QVERIFY(!file.isOpen()); +#ifdef Q_WS_WINCE // Need to reset permissions on Windows to be able to delete QVERIFY(QFile::setPermissions("file-copy-destination.txt", - QFile::ReadOwner | QFile::WriteOwner)); + QFile::WriteOther)); +#else + // Need to reset permissions on Windows to be able to delete + QVERIFY(QFile::setPermissions("file-copy-destination.txt", + QFile::ReadOwner | QFile::WriteOwner)); +#endif QVERIFY(QFile::remove("file-copy-destination.txt")); // Fallback copy of open file. @@ -1139,6 +1158,7 @@ void tst_QFile::copyFallback() QVERIFY(QFile::exists("file-copy-destination.txt")); QVERIFY(!file.isOpen()); + file.close(); QFile::remove("file-copy-destination.txt"); } @@ -2239,6 +2259,7 @@ void tst_QFile::rename() QFile file(source); QCOMPARE(file.rename(destination), result); + if (result) QCOMPARE(file.error(), QFile::NoError); else @@ -2367,6 +2388,7 @@ void tst_QFile::appendAndRead() QCOMPARE(readFile.read(1 << j).size(), 1 << j); } + readFile.close(); QFile::remove(QLatin1String("appendfile.txt")); } @@ -2608,10 +2630,15 @@ void tst_QFile::map() QFETCH(QFile::FileError, error); QString fileName = QDir::currentPath() + '/' + "qfile_map_testfile"; + +#ifdef Q_WS_WINCE + fileName = QFileInfo(fileName).absoluteFilePath(); +#endif + if (QFile::exists(fileName)) { QVERIFY(QFile::setPermissions(fileName, QFile::WriteOwner | QFile::ReadOwner | QFile::WriteUser | QFile::ReadUser)); - QFile::remove(fileName); + QFile::remove(fileName); } QFile file(fileName); @@ -2650,8 +2677,13 @@ void tst_QFile::map() QCOMPARE(file.error(), QFile::NoError); // hpux wont let you map multiple times. -#if !defined(Q_OS_HPUX) && !defined(Q_USE_DEPRECATED_MAP_API) +#if !defined(Q_OS_HPUX) && !defined(Q_USE_DEPRECATED_MAP_API) && !defined(Q_OS_WINCE) // exotic test to make sure that multiple maps work + + // note: windows ce does not reference count mutliple maps + // it's essentially just the same reference but it + // cause a resource lock on the file which prevents it + // from being removed uchar *memory1 = file.map(0, file.size()); uchar *memory1 = file.map(0, file.size()); QCOMPARE(file.error(), QFile::NoError); uchar *memory2 = file.map(0, file.size()); @@ -2687,7 +2719,6 @@ void tst_QFile::map() QVERIFY(!memory); QVERIFY(file.setPermissions(originalPermissions)); } - QVERIFY(file.remove()); } @@ -2800,8 +2831,14 @@ void tst_QFile::openDirectory() f1.close(); } -void tst_QFile::openStandardStreams() +void tst_QFile::openStandardStreamsFileDescriptors() { +#ifdef Q_WS_WINCE + //allthough Windows CE (not mobile!) has functions that allow redirecting + //the standard file descriptors to a file (see SetStdioPathW/GetStdioPathW) + //it does not have functions to simply open them like below . + QSKIP("Opening standard streams on Windows CE via descriptor not implemented", SkipAll); +#endif // Using file descriptors { QFile in; @@ -2826,7 +2863,13 @@ void tst_QFile::openStandardStreams() QCOMPARE( err.size(), (qint64)0 ); QVERIFY( err.isSequential() ); } +} +void tst_QFile::openStandardStreamsBufferedStreams() +{ +#if defined (Q_OS_WIN) || defined(Q_OS_SYMBIAN) + QSKIP("Unix only test.", SkipAll); +#endif // Using streams { QFile in; @@ -2853,6 +2896,12 @@ void tst_QFile::openStandardStreams() } } +void tst_QFile::openStandardStreams() +{ + openStandardStreamsFileDescriptors(); + openStandardStreamsBufferedStreams(); +} + void tst_QFile::writeNothing() { for (int i = 0; i < 3; ++i) { diff --git a/tests/auto/qgl/tst_qgl.cpp b/tests/auto/qgl/tst_qgl.cpp index 5dc072d..532e550 100644 --- a/tests/auto/qgl/tst_qgl.cpp +++ b/tests/auto/qgl/tst_qgl.cpp @@ -75,6 +75,7 @@ private slots: void graphicsViewClipping(); void partialGLWidgetUpdates_data(); void partialGLWidgetUpdates(); + void glWidgetWithAlpha(); void glWidgetRendering(); void glFBOSimpleRendering(); void glFBORendering(); @@ -251,15 +252,10 @@ void tst_QGL::getSetCheck() // bool QGLFormat::sampleBuffers() // void QGLFormat::setSampleBuffers(bool) -#if !defined(QT_OPENGL_ES_2) QCOMPARE(false, obj1.sampleBuffers()); QVERIFY(!obj1.testOption(QGL::SampleBuffers)); QVERIFY(obj1.testOption(QGL::NoSampleBuffers)); -#else - QCOMPARE(true, obj1.sampleBuffers()); - QVERIFY(obj1.testOption(QGL::SampleBuffers)); - QVERIFY(!obj1.testOption(QGL::NoSampleBuffers)); -#endif + obj1.setSampleBuffers(false); QCOMPARE(false, obj1.sampleBuffers()); QVERIFY(obj1.testOption(QGL::NoSampleBuffers)); @@ -927,6 +923,17 @@ void tst_QGL::glPBufferRendering() QFUZZY_COMPARE_IMAGES(fb, reference); } +void tst_QGL::glWidgetWithAlpha() +{ + QGLWidget* w = new QGLWidget(QGLFormat(QGL::AlphaChannel)); + w->show(); +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(w); +#endif + + delete w; +} + class GLWidget : public QGLWidget { public: diff --git a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp index 259df4d..69fc118 100644 --- a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp +++ b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp @@ -69,6 +69,7 @@ private slots: void opacity(); void grayscale(); void colorize(); + void drawPixmapItem(); }; void tst_QGraphicsEffect::initTestCase() @@ -465,6 +466,54 @@ void tst_QGraphicsEffect::colorize() QCOMPARE(image.pixel(10, 10), qRgb(122, 193, 66)); } +class PixmapItemEffect : public QGraphicsEffect +{ +public: + PixmapItemEffect(const QPixmap &source) + : QGraphicsEffect() + , pixmap(source) + , repaints(0) + {} + + QRectF boundingRectFor(const QRectF &rect) const + { return rect; } + + void draw(QPainter *painter) + { + QVERIFY(sourcePixmap(Qt::LogicalCoordinates).pixmapData() == pixmap.pixmapData()); + QVERIFY((painter->worldTransform().type() <= QTransform::TxTranslate) == (sourcePixmap(Qt::DeviceCoordinates).pixmapData() == pixmap.pixmapData())); + + ++repaints; + } + QPixmap pixmap; + int repaints; +}; + +void tst_QGraphicsEffect::drawPixmapItem() +{ + QImage image(32, 32, QImage::Format_RGB32); + QPainter p(&image); + p.fillRect(0, 0, 32, 16, Qt::blue); + p.fillRect(0, 16, 32, 16, Qt::red); + p.end(); + + QGraphicsScene scene; + QGraphicsPixmapItem *item = new QGraphicsPixmapItem(QPixmap::fromImage(image)); + scene.addItem(item); + + PixmapItemEffect *effect = new PixmapItemEffect(item->pixmap()); + item->setGraphicsEffect(effect); + + QGraphicsView view(&scene); + view.show(); + QTest::qWaitForWindowShown(&view); + + item->rotate(180); + QTest::qWait(50); + + QTRY_VERIFY(effect->repaints >= 2); +} + QTEST_MAIN(tst_QGraphicsEffect) #include "tst_qgraphicseffect.moc" diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp index 797e1fb..9e4321b 100644 --- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp @@ -211,6 +211,7 @@ private slots: void centerOnDirtyItem(); void mouseTracking(); void mouseTracking2(); + void mouseTracking3(); void render(); void exposeRegion(); void update_data(); @@ -3403,6 +3404,102 @@ void tst_QGraphicsView::mouseTracking2() QCOMPARE(spy.count(), 1); } +void tst_QGraphicsView::mouseTracking3() +{ + // Mouse tracking should be automatically enabled if AnchorUnderMouse is used for + // view transform or resize. We never disable mouse tracking if it is already enabled. + + { // Make sure we enable mouse tracking when using AnchorUnderMouse for view transformation. + QGraphicsScene scene(-10000, -10000, 20000, 20000); + QGraphicsView view(&scene); + QVERIFY(!view.viewport()->hasMouseTracking()); + + view.setTransformationAnchor(QGraphicsView::AnchorUnderMouse); + QVERIFY(view.viewport()->hasMouseTracking()); + } + + { // Make sure we enable mouse tracking when using AnchorUnderMouse for view resizing. + QGraphicsScene scene(-10000, -10000, 20000, 20000); + QGraphicsView view(&scene); + QVERIFY(!view.viewport()->hasMouseTracking()); + + view.setResizeAnchor(QGraphicsView::AnchorUnderMouse); + QVERIFY(view.viewport()->hasMouseTracking()); + } + + { // Make sure we don't disable mouse tracking in setViewport/setScene (transformation anchor). + QGraphicsView view; + view.setTransformationAnchor(QGraphicsView::AnchorUnderMouse); + QVERIFY(view.viewport()->hasMouseTracking()); + + QWidget *viewport = new QWidget; + view.setViewport(viewport); + QVERIFY(viewport->hasMouseTracking()); + + QGraphicsScene scene(-10000, -10000, 20000, 20000); + view.setScene(&scene); + QVERIFY(viewport->hasMouseTracking()); + } + + { // Make sure we don't disable mouse tracking in setViewport/setScene (resize anchor). + QGraphicsView view; + view.setResizeAnchor(QGraphicsView::AnchorUnderMouse); + QVERIFY(view.viewport()->hasMouseTracking()); + + QWidget *viewport = new QWidget; + view.setViewport(viewport); + QVERIFY(viewport->hasMouseTracking()); + + QGraphicsScene scene(-10000, -10000, 20000, 20000); + view.setScene(&scene); + QVERIFY(viewport->hasMouseTracking()); + } + + // Make sure we don't disable mouse tracking when adding an item (transformation anchor). + { // Adding an item to the scene before the scene is set on the view. + QGraphicsScene scene(-10000, -10000, 20000, 20000); + QGraphicsRectItem *item = new QGraphicsRectItem(10, 10, 10, 10); + scene.addItem(item); + + QGraphicsView view; + view.setTransformationAnchor(QGraphicsView::AnchorUnderMouse); + view.setScene(&scene); + QVERIFY(view.viewport()->hasMouseTracking()); + } + + { // Adding an item to the scene after the scene is set on the view. + QGraphicsScene scene(-10000, -10000, 20000, 20000); + QGraphicsView view(&scene); + view.setTransformationAnchor(QGraphicsView::AnchorUnderMouse); + + QGraphicsRectItem *item = new QGraphicsRectItem(10, 10, 10, 10); + scene.addItem(item); + QVERIFY(view.viewport()->hasMouseTracking()); + } + + // Make sure we don't disable mouse tracking when adding an item (resize anchor). + { // Adding an item to the scene before the scene is set on the view. + QGraphicsScene scene(-10000, -10000, 20000, 20000); + QGraphicsRectItem *item = new QGraphicsRectItem(10, 10, 10, 10); + scene.addItem(item); + + QGraphicsView view; + view.setResizeAnchor(QGraphicsView::AnchorUnderMouse); + view.setScene(&scene); + QVERIFY(view.viewport()->hasMouseTracking()); + } + + { // Adding an item to the scene after the scene is set on the view. + QGraphicsScene scene(-10000, -10000, 20000, 20000); + QGraphicsView view(&scene); + view.setResizeAnchor(QGraphicsView::AnchorUnderMouse); + + QGraphicsRectItem *item = new QGraphicsRectItem(10, 10, 10, 10); + scene.addItem(item); + QVERIFY(view.viewport()->hasMouseTracking()); + } +} + class RenderTester : public QGraphicsRectItem { public: @@ -3601,7 +3698,7 @@ void tst_QGraphicsView::inputMethodSensitivity() item->setFlag(QGraphicsItem::ItemIsFocusable); scene.addItem(item); scene.setFocusItem(item); - QCOMPARE(scene.focusItem(), item); + QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); item->setFlag(QGraphicsItem::ItemAcceptsInputMethod, false); @@ -3616,35 +3713,35 @@ void tst_QGraphicsView::inputMethodSensitivity() scene.addItem(item2); scene.setFocusItem(item2); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); - QCOMPARE(scene.focusItem(), item2); + QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item2)); scene.setFocusItem(item); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); - QCOMPARE(scene.focusItem(), item); + QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); view.setScene(0); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); - QCOMPARE(scene.focusItem(), item); + QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); view.setScene(&scene); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); - QCOMPARE(scene.focusItem(), item); + QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); scene.setFocusItem(item2); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); - QCOMPARE(scene.focusItem(), item2); + QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item2)); view.setScene(0); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); - QCOMPARE(scene.focusItem(), item2); + QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item2)); scene.setFocusItem(item); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); - QCOMPARE(scene.focusItem(), item); + QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); view.setScene(&scene); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); - QCOMPARE(scene.focusItem(), item); + QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); } class InputContextTester : public QInputContext @@ -3878,7 +3975,7 @@ void tst_QGraphicsView::QTBUG_5859_exposedRect() { lastBackgroundExposedRect = rect; } QRectF lastBackgroundExposedRect; }; - + class CustomRectItem : public QGraphicsRectItem { public: diff --git a/tests/auto/qhostinfo/tst_qhostinfo.cpp b/tests/auto/qhostinfo/tst_qhostinfo.cpp index 4d63e10..348c41b 100644 --- a/tests/auto/qhostinfo/tst_qhostinfo.cpp +++ b/tests/auto/qhostinfo/tst_qhostinfo.cpp @@ -88,6 +88,7 @@ #endif #include "../network-settings.h" +#include "../../shared/util.h" //TESTED_CLASS= //TESTED_FILES= @@ -124,6 +125,9 @@ private slots: void raceCondition(); void threadSafety(); + void multipleSameLookups(); + void multipleDifferentLookups(); + protected slots: void resultsReady(const QHostInfo &); @@ -131,6 +135,7 @@ private: bool ipv6LookupsAvailable; bool ipv6Available; bool lookupDone; + int lookupsDoneCounter; QHostInfo lookupResults; }; @@ -411,11 +416,53 @@ void tst_QHostInfo::threadSafety() } } +// this test is for the multi-threaded QHostInfo rewrite. It is about getting results at all, +// not about getting correct IPs +void tst_QHostInfo::multipleSameLookups() +{ + const int COUNT = 10; + lookupsDoneCounter = 0; + + for (int i = 0; i < COUNT; i++) + QHostInfo::lookupHost("localhost", this, SLOT(resultsReady(const QHostInfo))); + + QTRY_VERIFY(lookupsDoneCounter == COUNT); + + // spin two seconds more to see if it is not more :) + QTestEventLoop::instance().enterLoop(2); + QTRY_VERIFY(lookupsDoneCounter == COUNT); +} + +// this test is for the multi-threaded QHostInfo rewrite. It is about getting results at all, +// not about getting correct IPs +void tst_QHostInfo::multipleDifferentLookups() +{ + QStringList hostnameList; + hostnameList << "www.ovi.com" << "www.nokia.com" << "qt.nokia.com" << "www.trolltech.com" << "troll.no" + << "www.qtcentre.org" << "forum.nokia.com" << "www.forum.nokia.com" << "wiki.forum.nokia.com" + << "www.nokia.no" << "nokia.de" << "127.0.0.1" << "----"; + + const int COUNT = hostnameList.size(); + lookupsDoneCounter = 0; + + for (int i = 0; i < hostnameList.size(); i++) + QHostInfo::lookupHost(hostnameList.at(i), this, SLOT(resultsReady(const QHostInfo))); + + // give some time + QTestEventLoop::instance().enterLoop(5); + // try_verify gives some more time + QTRY_VERIFY(lookupsDoneCounter == COUNT); + + // spin two seconds more to see if it is not more than expected + QTestEventLoop::instance().enterLoop(2); + QTRY_VERIFY(lookupsDoneCounter == COUNT); +} + void tst_QHostInfo::resultsReady(const QHostInfo &hi) { lookupDone = true; lookupResults = hi; - + lookupsDoneCounter++; QTestEventLoop::instance().exitLoop(); } diff --git a/tests/auto/qimagereader/tst_qimagereader.cpp b/tests/auto/qimagereader/tst_qimagereader.cpp index 15b1c1c..630cc03 100644 --- a/tests/auto/qimagereader/tst_qimagereader.cpp +++ b/tests/auto/qimagereader/tst_qimagereader.cpp @@ -322,7 +322,15 @@ void tst_QImageReader::setScaledSize_data() QTest::newRow("PPM: test") << "test.ppm" << QSize(10, 10) << QByteArray("ppm"); QTest::newRow("XBM: gnus") << "gnus" << QSize(200, 200) << QByteArray("xbm"); #ifdef QTEST_HAVE_JPEG - QTest::newRow("JPEG: beavis") << "beavis" << QSize(200, 200) << QByteArray("jpeg"); + QTest::newRow("JPEG: beavis A") << "beavis" << QSize(200, 200) << QByteArray("jpeg"); + QTest::newRow("JPEG: beavis B") << "beavis" << QSize(175, 175) << QByteArray("jpeg"); + QTest::newRow("JPEG: beavis C") << "beavis" << QSize(100, 100) << QByteArray("jpeg"); + QTest::newRow("JPEG: beavis D") << "beavis" << QSize(100, 200) << QByteArray("jpeg"); + QTest::newRow("JPEG: beavis E") << "beavis" << QSize(200, 100) << QByteArray("jpeg"); + QTest::newRow("JPEG: beavis F") << "beavis" << QSize(87, 87) << QByteArray("jpeg"); + QTest::newRow("JPEG: beavis G") << "beavis" << QSize(50, 45) << QByteArray("jpeg"); + QTest::newRow("JPEG: beavis H") << "beavis" << QSize(43, 43) << QByteArray("jpeg"); + QTest::newRow("JPEG: beavis I") << "beavis" << QSize(25, 25) << QByteArray("jpeg"); #endif // QTEST_HAVE_JPEG #ifdef QTEST_HAVE_GIF QTest::newRow("GIF: earth") << "earth" << QSize(200, 200) << QByteArray("gif"); diff --git a/tests/auto/qobject/tst_qobject.cpp b/tests/auto/qobject/tst_qobject.cpp index c534cce..b74a61f 100644 --- a/tests/auto/qobject/tst_qobject.cpp +++ b/tests/auto/qobject/tst_qobject.cpp @@ -126,6 +126,7 @@ private slots: void deleteQObjectWhenDeletingEvent(); void overloads(); void isSignalConnected(); + void qMetaObjectConnect(); protected: }; @@ -3297,5 +3298,148 @@ void tst_QObject::isSignalConnected() QCOMPARE(o.rec, 2); } +void tst_QObject::qMetaObjectConnect() +{ + SenderObject *s = new SenderObject; + ReceiverObject *r1 = new ReceiverObject; + ReceiverObject *r2 = new ReceiverObject; + r1->reset(); + r2->reset(); + ReceiverObject::sequence = 0; + + int signal1Index = s->metaObject()->indexOfSignal("signal1()"); + int signal3Index = s->metaObject()->indexOfSignal("signal3()"); + int slot1Index = r1->metaObject()->indexOfSlot("slot1()"); + int slot2Index = r1->metaObject()->indexOfSlot("slot2()"); + int slot3Index = r1->metaObject()->indexOfSlot("slot3()"); + + QVERIFY(slot1Index > 0); + QVERIFY(slot2Index > 0); + QVERIFY(slot3Index > 0); + + QVERIFY( QMetaObject::connect( s, signal1Index, r1, slot1Index) ); + QVERIFY( QMetaObject::connect( s, signal3Index, r2, slot3Index) ); + QVERIFY( QMetaObject::connect( s, -1, r2, slot2Index) ); + + QCOMPARE( r1->count_slot1, 0 ); + QCOMPARE( r1->count_slot2, 0 ); + QCOMPARE( r1->count_slot3, 0 ); + QCOMPARE( r2->count_slot1, 0 ); + QCOMPARE( r2->count_slot2, 0 ); + QCOMPARE( r2->count_slot3, 0 ); + + s->emitSignal1(); + + QCOMPARE( r1->count_slot1, 1 ); + QCOMPARE( r1->count_slot2, 0 ); + QCOMPARE( r1->count_slot3, 0 ); + QCOMPARE( r2->count_slot1, 0 ); + QCOMPARE( r2->count_slot2, 1 ); + QCOMPARE( r2->count_slot3, 0 ); + + s->emitSignal2(); + s->emitSignal3(); + s->emitSignal4(); + + QCOMPARE( r1->count_slot1, 1 ); + QCOMPARE( r1->count_slot2, 0 ); + QCOMPARE( r1->count_slot3, 0 ); + QCOMPARE( r2->count_slot1, 0 ); + QCOMPARE( r2->count_slot2, 4 ); + QCOMPARE( r2->count_slot3, 1 ); + + QVERIFY( QMetaObject::disconnect( s, signal1Index, r1, slot1Index) ); + QVERIFY( QMetaObject::disconnect( s, signal3Index, r2, slot3Index) ); + QVERIFY( QMetaObject::disconnect( s, -1, r2, slot2Index) ); + + s->emitSignal1(); + s->emitSignal2(); + s->emitSignal3(); + s->emitSignal4(); + + QCOMPARE( r1->count_slot1, 1 ); + QCOMPARE( r1->count_slot2, 0 ); + QCOMPARE( r1->count_slot3, 0 ); + QCOMPARE( r2->count_slot1, 0 ); + QCOMPARE( r2->count_slot2, 4 ); + QCOMPARE( r2->count_slot3, 1 ); + + //some "dynamic" signal + QVERIFY( QMetaObject::connect( s, s->metaObject()->methodOffset() + 20, r1, slot3Index) ); + QVERIFY( QMetaObject::connect( s, s->metaObject()->methodOffset() + 35, r2, slot1Index) ); + QVERIFY( QMetaObject::connect( s, -1, r1, slot2Index) ); + + r1->reset(); + r2->reset(); + + void *args[] = { 0 , 0 }; + QMetaObject::activate(s, s->metaObject()->methodOffset() + 20, args); + QMetaObject::activate(s, s->metaObject()->methodOffset() + 48, args); + QCOMPARE( r1->count_slot1, 0 ); + QCOMPARE( r1->count_slot2, 2 ); + QCOMPARE( r1->count_slot3, 1 ); + QCOMPARE( r2->count_slot1, 0 ); + QCOMPARE( r2->count_slot2, 0 ); + QCOMPARE( r2->count_slot3, 0 ); + + QMetaObject::activate(s, s->metaObject()->methodOffset() + 35, args); + s->emitSignal1(); + s->emitSignal2(); + + QCOMPARE( r1->count_slot1, 0 ); + QCOMPARE( r1->count_slot2, 5 ); + QCOMPARE( r1->count_slot3, 1 ); + QCOMPARE( r2->count_slot1, 1 ); + QCOMPARE( r2->count_slot2, 0 ); + QCOMPARE( r2->count_slot3, 0 ); + + delete s; + r1->reset(); + r2->reset(); + +#define SIGNAL_INDEX(S) obj1.metaObject()->indexOfSignal(QMetaObject::normalizedSignature(#S)) + OverloadObject obj1; + QObject obj2, obj3; + + QMetaObject::connect(&obj1, SIGNAL_INDEX(sig(int)) , r1, slot1Index); + QMetaObject::connect(&obj1, SIGNAL_INDEX(sig(QObject *, QObject *, QObject *)) , r2, slot1Index); + + QMetaObject::connect(&obj1, SIGNAL_INDEX(sig(QObject *, QObject *, QObject *, QObject *)) , r1, slot2Index); + QMetaObject::connect(&obj1, SIGNAL_INDEX(sig(QObject *)) , r2, slot2Index); + QMetaObject::connect(&obj1, SIGNAL_INDEX(sig(int, int)) , r1, slot3Index); + + emit obj1.sig(0.5); //connected to nothing + emit obj1.sig(1, 'a'); //connected to nothing + QCOMPARE( r1->count_slot1, 0 ); + QCOMPARE( r1->count_slot2, 0 ); + QCOMPARE( r1->count_slot3, 0 ); + QCOMPARE( r2->count_slot1, 0 ); + QCOMPARE( r2->count_slot2, 0 ); + QCOMPARE( r2->count_slot3, 0 ); + + emit obj1.sig(1); //this signal is connected + emit obj1.sig(&obj2); + + QCOMPARE( r1->count_slot1, 1 ); + QCOMPARE( r1->count_slot2, 0 ); + QCOMPARE( r1->count_slot3, 1 ); + QCOMPARE( r2->count_slot1, 0 ); + QCOMPARE( r2->count_slot2, 1 ); + QCOMPARE( r2->count_slot3, 0 ); + + emit obj1.sig(&obj2, &obj3); //this signal is connected + + QCOMPARE( r1->count_slot1, 1 ); + QCOMPARE( r1->count_slot2, 1 ); + QCOMPARE( r1->count_slot3, 1 ); + QCOMPARE( r2->count_slot1, 1 ); + QCOMPARE( r2->count_slot2, 1 ); + QCOMPARE( r2->count_slot3, 0 ); + + delete r1; + delete r2; + +} + QTEST_MAIN(tst_QObject) #include "tst_qobject.moc" diff --git a/tests/auto/qpixmap/tst_qpixmap.cpp b/tests/auto/qpixmap/tst_qpixmap.cpp index 0512499..c7fb930 100644 --- a/tests/auto/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/qpixmap/tst_qpixmap.cpp @@ -1308,6 +1308,12 @@ void tst_QPixmap::copy() QPixmap expected(10, 10); expected.fill(Qt::blue); QVERIFY(lenientCompare(dest, expected)); + + QPixmap trans; + trans.fill(Qt::transparent); + + QPixmap transCopy = trans.copy(); + QVERIFY(pixmapsAreEqual(&trans, &transCopy)); } #ifdef QT3_SUPPORT diff --git a/tests/auto/qresourceengine/tst_qresourceengine.cpp b/tests/auto/qresourceengine/tst_qresourceengine.cpp index cc6eda3..ed7de23 100644 --- a/tests/auto/qresourceengine/tst_qresourceengine.cpp +++ b/tests/auto/qresourceengine/tst_qresourceengine.cpp @@ -62,6 +62,7 @@ private slots: void searchPath_data(); void searchPath(); void doubleSlashInRoot(); + void setLocale(); private: QString builddir; @@ -460,6 +461,27 @@ void tst_QResourceEngine::doubleSlashInRoot() QVERIFY(QFile::exists("://secondary_root/runtime_resource/search_file.txt")); } +void tst_QResourceEngine::setLocale() +{ + QLocale::setDefault(QLocale::c()); + + // default constructed QResource gets the default locale + QResource resource; + resource.setFileName("aliasdir/aliasdir.txt"); + QVERIFY(!resource.isCompressed()); + + // change the default locale and make sure it doesn't affect the resource + QLocale::setDefault(QLocale("de_CH")); + QVERIFY(!resource.isCompressed()); + + // then explicitly set the locale on qresource + resource.setLocale(QLocale("de_CH")); + QVERIFY(resource.isCompressed()); + + // the reset the default locale back + QLocale::setDefault(QLocale::system()); +} + QTEST_MAIN(tst_QResourceEngine) #include "tst_qresourceengine.moc" diff --git a/tests/auto/qsqldatabase/tst_qsqldatabase.cpp b/tests/auto/qsqldatabase/tst_qsqldatabase.cpp index cb4e103..1d39c67 100644 --- a/tests/auto/qsqldatabase/tst_qsqldatabase.cpp +++ b/tests/auto/qsqldatabase/tst_qsqldatabase.cpp @@ -768,9 +768,7 @@ void tst_QSqlDatabase::checkValues(const FieldDef fieldDefs[], QSqlDatabase db) rec->setValue(fieldDefs[ i ].fieldName(), fieldDefs[ i ].val); // qDebug(QString("inserting %1 into %2").arg(fieldDefs[ i ].val.toString()).arg(fieldDefs[ i ].fieldName())); } - if (!cur.insert()) { - QFAIL(QString("Couldn't insert record: %1 %2").arg(cur.lastError().databaseText()).arg(cur.lastError().driverText())); - } + QVERIFY_SQL(cur, insert()); cur.setForwardOnly(true); QVERIFY_SQL(cur, select("id = " + QString::number(pkey - 1))); QVERIFY_SQL(cur, next()); @@ -833,9 +831,7 @@ void tst_QSqlDatabase::checkNullValues(const FieldDef fieldDefs[], QSqlDatabase else rec->setValue(fieldDefs[ i ].fieldName(), fieldDefs[ i ].val); } - if (!cur.insert()) { - QFAIL(QString("Couldn't insert record: %1 %2").arg(cur.lastError().databaseText()).arg(cur.lastError().driverText())); - } + QVERIFY_SQL(cur, insert()); cur.setForwardOnly(true); QVERIFY_SQL(cur, select("id = " + QString::number(pkey - 1))); QVERIFY_SQL(cur, next()); @@ -907,12 +903,8 @@ void tst_QSqlDatabase::recordOCI() CHECK_DATABASE(db); // runtime check for Oracle version since V8 doesn't support TIMESTAMPs - if (tst_Databases::getOraVersion(db) >= 9) { - qDebug("Detected Oracle >= 9, TIMESTAMP test enabled"); - hasTimeStamp = true; - } else { - qDebug("Detected Oracle < 9, TIMESTAMP test disabled"); - } + if (tst_Databases::getOraVersion(db) >= 9) + hasTimeStamp = true; FieldDef tsdef; FieldDef tstzdef; @@ -923,11 +915,11 @@ void tst_QSqlDatabase::recordOCI() static const QDateTime dt(QDate::currentDate(), QTime(1, 2, 3, 0)); if (hasTimeStamp) { - tsdef = FieldDef("timestamp", QVariant::DateTime, dt); - tstzdef = FieldDef("timestamp with time zone", QVariant::DateTime, dt); - tsltzdef = FieldDef("timestamp with local time zone", QVariant::DateTime, dt); - intytm = FieldDef("interval year to month", QVariant::String, QString("+01-01")); - intdts = FieldDef("interval day to second", QVariant::String, QString("+01 00:00:01.000000")); + tsdef = FieldDef("timestamp", QVariant::DateTime, dt); + tstzdef = FieldDef("timestamp with time zone", QVariant::DateTime, dt); + tsltzdef = FieldDef("timestamp with local time zone", QVariant::DateTime, dt); + intytm = FieldDef("interval year to month", QVariant::String, QString("+01-01")); + intdts = FieldDef("interval day to second", QVariant::String, QString("+01 00:00:01.000000")); } const FieldDef fieldDefs[] = { @@ -937,21 +929,19 @@ void tst_QSqlDatabase::recordOCI() FieldDef("nvarchar2(20)", QVariant::String, QString("blah4")), FieldDef("number(10,5)", QVariant::Double, 1.1234567), FieldDef("date", QVariant::DateTime, dt), -#ifdef QT3_SUPPORT -//X? FieldDef("long raw", QVariant::ByteArray, QByteArray(Q3CString("blah5"))), - FieldDef("raw(2000)", QVariant::ByteArray, QByteArray(Q3CString("blah6")), false), - FieldDef("blob", QVariant::ByteArray, QByteArray(Q3CString("blah7"))), -#endif -//FIXME FieldDef("clob", QVariant::CString, Q3CString("blah8")), -//FIXME FieldDef("nclob", QVariant::CString, Q3CString("blah9")), -//X FieldDef("bfile", QVariant::ByteArray, QByteArray(Q3CString("blah10"))), - - intytm, - intdts, - tsdef, - tstzdef, - tsltzdef, - FieldDef() + FieldDef("long raw", QVariant::ByteArray, QByteArray("blah5")), + FieldDef("raw(2000)", QVariant::ByteArray, QByteArray("blah6"), false), + FieldDef("blob", QVariant::ByteArray, QByteArray("blah7")), + FieldDef("clob", QVariant::String, QString("blah8")), + FieldDef("nclob", QVariant::String, QString("blah9")), +// FieldDef("bfile", QVariant::ByteArray, QByteArray("blah10")), + + intytm, + intdts, + tsdef, + tstzdef, + tsltzdef, + FieldDef() }; const int fieldCount = createFieldTable(fieldDefs, db); @@ -959,9 +949,8 @@ void tst_QSqlDatabase::recordOCI() commonFieldTest(fieldDefs, db, fieldCount); checkNullValues(fieldDefs, db); - for (int i = 0; i < ITERATION_COUNT; ++i) { - checkValues(fieldDefs, db); - } + for (int i = 0; i < ITERATION_COUNT; ++i) + checkValues(fieldDefs, db); // some additional tests QSqlRecord rec = db.record(qTableName("qtestfields")); diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp index a8908fd..2a55c32 100644 --- a/tests/auto/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp @@ -201,6 +201,8 @@ private slots: void QTBUG_5251(); void QTBUG_6421_data() { generic_data("QOCI"); } void QTBUG_6421(); + void QTBUG_6618_data() { generic_data("QODBC"); } + void QTBUG_6618(); private: // returns all database connections @@ -2961,5 +2963,27 @@ void tst_QSqlQuery::QTBUG_6421() QCOMPARE(q.value(0).toString(), QLatin1String("\"COL3\"")); } +void tst_QSqlQuery::QTBUG_6618() +{ + QFETCH( QString, dbName ); + QSqlDatabase db = QSqlDatabase::database( dbName ); + CHECK_DATABASE( db ); + if (!tst_Databases::isSqlServer( db )) + QSKIP("SQL Server specific test", SkipSingle); + + QSqlQuery q(db); + q.exec( "drop procedure " + qTableName( "tst_raiseError" ) ); //non-fatal + QString errorString; + for (int i=0;i<110;i++) + errorString+="reallylong"; + errorString+=" error"; + QVERIFY_SQL( q, exec("create procedure " + qTableName( "tst_raiseError" ) + " as\n" + "begin\n" + " raiserror('" + errorString + "', 16, 1)\n" + "end\n" )); + q.exec( "{call " + qTableName( "tst_raiseError" ) + "}" ); + QVERIFY(q.lastError().text().contains(errorString)); +} + QTEST_MAIN( tst_QSqlQuery ) #include "tst_qsqlquery.moc" diff --git a/tests/auto/selftests/tst_selftests.cpp b/tests/auto/selftests/tst_selftests.cpp index 579f4eb..ed3b08e 100644 --- a/tests/auto/selftests/tst_selftests.cpp +++ b/tests/auto/selftests/tst_selftests.cpp @@ -182,12 +182,12 @@ void tst_Selftests::runSubTest_data() #endif QTest::newRow("benchlibeventcounter") << "benchlibeventcounter" << QStringList("-eventcounter"); QTest::newRow("benchliboptions") << "benchliboptions" << QStringList("-eventcounter"); - QTest::newRow("benchlibwalltime") << "benchlibwalltime" << QStringList(); - //### This test is affected by the speed of the CPU and whether the tick counter is - //### monotonically increasing. It won't work on some machines so leave it off by default. + //### These tests are affected by timing and whether the CPU tick counter is + //### monotonically increasing. They won't work on some machines so leave them off by default. //### Feel free to uncomment for your own testing. #if 0 + QTest::newRow("benchlibwalltime") << "benchlibwalltime" << QStringList(); QTest::newRow("benchlibtickcounter") << "benchlibtickcounter" << QStringList("-tickcounter"); #endif diff --git a/tests/benchmarks/benchmarks.pro b/tests/benchmarks/benchmarks.pro index bffa009..bb20dcf 100644 --- a/tests/benchmarks/benchmarks.pro +++ b/tests/benchmarks/benchmarks.pro @@ -36,7 +36,8 @@ SUBDIRS = containers-associative \ qstringbuilder \ qstylesheetstyle \ qsvgrenderer \ - qtableview + qtableview \ + qthreadstorage diff --git a/tests/benchmarks/containers-sequential/main.cpp b/tests/benchmarks/containers-sequential/main.cpp index 76643ca..885db3e 100644 --- a/tests/benchmarks/containers-sequential/main.cpp +++ b/tests/benchmarks/containers-sequential/main.cpp @@ -59,7 +59,7 @@ public: }; template <typename T> -static T * f(T *ts) // dummy function to prevent code from being optimized away by the compiler +T * f(T *ts) // dummy function to prevent code from being optimized away by the compiler { return ts; } @@ -81,7 +81,7 @@ class UseCases_QVector : public UseCases<T> void lookup(int size) { QVector<T> v; - + T t; for (int i = 0; i < size; ++i) v.append(t); @@ -113,7 +113,7 @@ class UseCases_stdvector : public UseCases<T> void lookup(int size) { std::vector<T> v; - + T t; for (int i = 0; i < size; ++i) v.push_back(t); @@ -132,6 +132,13 @@ struct Large { // A "large" item type int x[1000]; }; +// Symbian devices typically have limited memory +#ifdef Q_OS_SYMBIAN +# define LARGE_MAX_SIZE 2000 +#else +# define LARGE_MAX_SIZE 20000 +#endif + class tst_vector_vs_std : public QObject { Q_OBJECT @@ -190,7 +197,7 @@ void tst_vector_vs_std::insert_Large_data() QTest::addColumn<bool>("useStd"); QTest::addColumn<int>("size"); - for (int size = 10; size < 20000; size += 100) { + for (int size = 10; size < LARGE_MAX_SIZE; size += 100) { const QByteArray sizeString = QByteArray::number(size); QTest::newRow(("std::vector-Large--" + sizeString).constData()) << true << size; QTest::newRow(("QVector-Large--" + sizeString).constData()) << false << size; @@ -236,7 +243,7 @@ void tst_vector_vs_std::lookup_Large_data() QTest::addColumn<bool>("useStd"); QTest::addColumn<int>("size"); - for (int size = 10; size < 20000; size += 100) { + for (int size = 10; size < LARGE_MAX_SIZE; size += 100) { const QByteArray sizeString = QByteArray::number(size); QTest::newRow(("std::vector-Large--" + sizeString).constData()) << true << size; QTest::newRow(("QVector-Large--" + sizeString).constData()) << false << size; diff --git a/tests/benchmarks/events/main.cpp b/tests/benchmarks/events/main.cpp index 7c9de8f..09d6c53 100644 --- a/tests/benchmarks/events/main.cpp +++ b/tests/benchmarks/events/main.cpp @@ -47,6 +47,7 @@ class PingPong : public QObject { public: void setPeer(QObject *peer); + void resetCounter() {m_counter = 100;} protected: bool event(QEvent *e); @@ -69,7 +70,7 @@ bool PingPong::event(QEvent *) QEvent *e = new QEvent(QEvent::User); QCoreApplication::postEvent(m_peer, e); } else { - QCoreApplication::quit(); + QTestEventLoop::instance().exitLoop(); } return true; } @@ -149,6 +150,10 @@ void EventsBench::sendEvent() void EventsBench::postEvent_data() { QTest::addColumn<bool>("filterEvents"); + // The first time an eventloop is executed, the case runs radically slower at least + // on some platforms, so test the "no eventfilter" case to get a comparable results + // with the "eventfilter" case. + QTest::newRow("first time, no eventfilter") << false; QTest::newRow("no eventfilter") << false; QTest::newRow("eventfilter") << true; } @@ -164,8 +169,14 @@ void EventsBench::postEvent() ping.installEventFilter(this); pong.installEventFilter(this); } - QEvent *e = new QEvent(QEvent::User); + QBENCHMARK { + // In case multiple iterations are done, event needs to be created inside the QBENCHMARK, + // or it gets deleted once first iteration exits and can cause a crash. Similarly, + // ping and pong need their counters reset. + QEvent *e = new QEvent(QEvent::User); + ping.resetCounter(); + pong.resetCounter(); QCoreApplication::postEvent(&ping, e); QTestEventLoop::instance().enterLoop( 61 ); } diff --git a/tests/benchmarks/qbytearray/main.cpp b/tests/benchmarks/qbytearray/main.cpp index 6a481f1..78c5b16 100644 --- a/tests/benchmarks/qbytearray/main.cpp +++ b/tests/benchmarks/qbytearray/main.cpp @@ -73,6 +73,11 @@ void tst_qbytearray::append() { QFETCH(int, size); +#ifdef Q_OS_SYMBIAN + if (size > 1000000) + QSKIP("Skipped due to limited memory in many Symbian devices.", SkipSingle); +#endif + QByteArray ba; QBENCHMARK { QByteArray ba2(size, 'x'); diff --git a/tests/benchmarks/qdiriterator/main.cpp b/tests/benchmarks/qdiriterator/main.cpp index 2a400e3..9e4e53e 100644 --- a/tests/benchmarks/qdiriterator/main.cpp +++ b/tests/benchmarks/qdiriterator/main.cpp @@ -73,7 +73,7 @@ private slots: void tst_qdiriterator::data() { -#ifdef Q_OS_WINCE +#if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN) QByteArray qtdir = qPrintable(QCoreApplication::applicationDirPath()); qtdir += "/depot"; #else @@ -148,9 +148,9 @@ static int posix_helper(const char *dirpath) int count = 0; while ((entry = ::readdir(dir))) { - if (qstrcmp(entry->d_name, ".") == 0) + if (qstrcmp(entry->d_name, ".") == 0) continue; - if (qstrcmp(entry->d_name, "..") == 0) + if (qstrcmp(entry->d_name, "..") == 0) continue; ++count; QByteArray ba = dirpath; @@ -198,7 +198,7 @@ void tst_qdiriterator::diriterator() //QDir::AllEntries | QDir::Hidden, QDir::Files, QDirIterator::Subdirectories); - + while (dir.hasNext()) { dir.next(); //printf("%s\n", qPrintable(dir.fileName())); @@ -231,7 +231,7 @@ void tst_qdiriterator::fsiterator() //QDir::Files | QDir::NoDotAndDotDot, QDir::Files, QFileSystemIterator::Subdirectories); - + for (; !dir.atEnd(); dir.next()) { dump && printf("%d %s\n", dir.fileInfo().isDir(), diff --git a/tests/benchmarks/qdiriterator/qdiriterator.pro b/tests/benchmarks/qdiriterator/qdiriterator.pro index fb4b753..e06d746 100755 --- a/tests/benchmarks/qdiriterator/qdiriterator.pro +++ b/tests/benchmarks/qdiriterator/qdiriterator.pro @@ -15,7 +15,7 @@ SOURCES += main.cpp SOURCES += qfilesystemiterator.cpp HEADERS += qfilesystemiterator.h -wince*: { +wince*|symbian: { corelibdir.sources = $$QT_SOURCE_TREE/src/corelib corelibdir.path = ./depot/src DEPLOYMENT += corelibdir diff --git a/tests/benchmarks/qfile/main.cpp b/tests/benchmarks/qfile/main.cpp index d3f6ab5..4217077 100644 --- a/tests/benchmarks/qfile/main.cpp +++ b/tests/benchmarks/qfile/main.cpp @@ -128,12 +128,18 @@ private: QString tmpDirName; }; +Q_DECLARE_METATYPE(tst_qfile::BenchmarkType) +Q_DECLARE_METATYPE(QIODevice::OpenMode) +Q_DECLARE_METATYPE(QIODevice::OpenModeFlag) + void tst_qfile::createFile() { + removeFile(); // Cleanup in case previous test case aborted before cleaning up + QTemporaryFile tmpFile; tmpFile.setAutoRemove(false); if (!tmpFile.open()) - ::_exit(1); + ::exit(1); filename = tmpFile.fileName(); tmpFile.close(); } @@ -217,7 +223,6 @@ void tst_qfile::readBigFile_data(BenchmarkType type, QIODevice::OpenModeFlag t, for (int i=0; i<bs_entries; ++i) QTest::newRow((QString("BS: %1, Flags: %2" )).arg(bs[i]).arg(flagstring).toLatin1().constData()) << type << bs[i] << t << b; - } void tst_qfile::readBigFile() @@ -227,8 +232,12 @@ void tst_qfile::readBigFile() QFETCH(QFile::OpenModeFlag, textMode); QFETCH(QFile::OpenModeFlag, bufferedMode); - char buffer[BUFSIZE]; // we can't allocate buffers nice and dynamically in c++ - removeFile(); +#ifndef Q_OS_WIN + if (testType == Win32Benchmark) + QSKIP("This is Windows only benchmark.", SkipSingle); +#endif + + char *buffer = new char[BUFSIZE]; createFile(); fillFile(); @@ -297,6 +306,9 @@ void tst_qfile::readBigFile() } break; } + + removeFile(); + delete[] buffer; } void tst_qfile::seek_data() @@ -374,6 +386,8 @@ void tst_qfile::seek() } break; } + + removeFile(); } void tst_qfile::open_data() @@ -392,7 +406,6 @@ void tst_qfile::open() { QFETCH(tst_qfile::BenchmarkType, testType); - removeFile(); createFile(); switch (testType) { @@ -435,6 +448,7 @@ void tst_qfile::open() file.open(cfile, QIODevice::ReadOnly); file.close(); } + ::fclose(cfile); } break; case(Win32Benchmark): { @@ -456,6 +470,7 @@ void tst_qfile::open() break; } + removeFile(); } @@ -515,15 +530,20 @@ void tst_qfile::readSmallFiles_data(BenchmarkType type, QIODevice::OpenModeFlag void tst_qfile::createSmallFiles() { QDir dir = QDir::temp(); - Q_ASSERT(dir.mkdir("tst")); + dir.mkdir("tst"); dir.cd("tst"); tmpDirName = dir.absolutePath(); +#ifdef Q_OS_SYMBIAN + for (int i = 0; i < 100; ++i) +#else for (int i = 0; i < 1000; ++i) +#endif { QFile f(tmpDirName+"/"+QString::number(i)); f.open(QIODevice::WriteOnly); - f.seek(512); + f.seek(511); + f.putChar('\n'); f.close(); } } @@ -544,17 +564,22 @@ void tst_qfile::readSmallFiles() QFETCH(QFile::OpenModeFlag, textMode); QFETCH(QFile::OpenModeFlag, bufferedMode); - removeSmallFiles(); +#ifndef Q_OS_WIN + if (testType == Win32Benchmark) + QSKIP("This is Windows only benchmark.", SkipSingle); +#endif + createSmallFiles(); + QDir dir(tmpDirName); - const QStringList files = dir.entryList(QDir::NoDotAndDotDot|QDir::NoSymLinks); - char buffer[BUFSIZE]; // we can't allocate buffers nice and dynamically in c++ + const QStringList files = dir.entryList(QDir::NoDotAndDotDot|QDir::NoSymLinks|QDir::Files); + char *buffer = new char[BUFSIZE]; switch (testType) { case(QFileBenchmark): { QList<QFile*> fileList; Q_FOREACH(QString file, files) { - QFile *f = new QFile(file); + QFile *f = new QFile(tmpDirName+ "/" + file); f->open(QIODevice::ReadOnly|textMode|bufferedMode); fileList.append(f); } @@ -576,7 +601,7 @@ void tst_qfile::readSmallFiles() case(QFSFileEngineBenchmark): { QList<QFSFileEngine*> fileList; Q_FOREACH(QString file, files) { - QFSFileEngine *fse = new QFSFileEngine(file); + QFSFileEngine *fse = new QFSFileEngine(tmpDirName+ "/" + file); fse->open(QIODevice::ReadOnly|textMode|bufferedMode); fileList.append(fse); } @@ -596,7 +621,7 @@ void tst_qfile::readSmallFiles() case(PosixBenchmark): { QList<FILE*> fileList; Q_FOREACH(QString file, files) { - fileList.append(::fopen(QFile::encodeName(file).constData(), "rb")); + fileList.append(::fopen(QFile::encodeName(tmpDirName+ "/" + file).constData(), "rb")); } QBENCHMARK { @@ -640,11 +665,10 @@ void tst_qfile::readSmallFiles() } break; } -} -Q_DECLARE_METATYPE(tst_qfile::BenchmarkType) -Q_DECLARE_METATYPE(QIODevice::OpenMode) -Q_DECLARE_METATYPE(QIODevice::OpenModeFlag) + removeSmallFiles(); + delete[] buffer; +} QTEST_MAIN(tst_qfile) diff --git a/tests/benchmarks/qgraphicsview/qgraphicsview.pro b/tests/benchmarks/qgraphicsview/qgraphicsview.pro index d9db8c9..927d731 100644 --- a/tests/benchmarks/qgraphicsview/qgraphicsview.pro +++ b/tests/benchmarks/qgraphicsview/qgraphicsview.pro @@ -6,3 +6,11 @@ SOURCES += tst_qgraphicsview.cpp RESOURCES += qgraphicsview.qrc include(chiptester/chiptester.pri) + +symbian { + qt_not_deployed { + plugins.sources = qjpeg.dll + plugins.path = imageformats + DEPLOYMENT += plugins + } +} diff --git a/tests/benchmarks/qgraphicsview/tst_qgraphicsview.cpp b/tests/benchmarks/qgraphicsview/tst_qgraphicsview.cpp index aadd56c..cf65e5d 100644 --- a/tests/benchmarks/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/benchmarks/qgraphicsview/tst_qgraphicsview.cpp @@ -62,25 +62,25 @@ class QEventWaiter : public QEventLoop { public: QEventWaiter(QObject *receiver, QEvent::Type type) - : waiting(false), t(type) + : waiting(false), t(type) { - receiver->installEventFilter(this); + receiver->installEventFilter(this); } void wait() { - waiting = true; - exec(); + waiting = true; + exec(); } bool eventFilter(QObject *receiver, QEvent *event) { - Q_UNUSED(receiver); - if (waiting && event->type() == t) { - waiting = false; - exit(); - } - return false; + Q_UNUSED(receiver); + if (waiting && event->type() == t) { + waiting = false; + exit(); + } + return false; } private: @@ -166,20 +166,26 @@ void tst_QGraphicsView::paintSingleItem() QImage image(100, 100, QImage::Format_ARGB32_Premultiplied); QPainter painter(&image); QBENCHMARK { - view.viewport()->render(&painter); + view.viewport()->render(&painter); } } +#ifdef Q_OS_SYMBIAN +# define DEEP_STACKING_COUNT 200 +#else +# define DEEP_STACKING_COUNT 1000 +#endif + void tst_QGraphicsView::paintDeepStackingItems() { QGraphicsScene scene(0, 0, 100, 100); QGraphicsRectItem *item = scene.addRect(0, 0, 10, 10); QGraphicsRectItem *lastRect = item; - for (int i = 0; i < 1000; ++i) { - QGraphicsRectItem *rect = scene.addRect(0, 0, 10, 10); - rect->setPos(1, 1); - rect->setParentItem(lastRect); - lastRect = rect; + for (int i = 0; i < DEEP_STACKING_COUNT; ++i) { + QGraphicsRectItem *rect = scene.addRect(0, 0, 10, 10); + rect->setPos(1, 1); + rect->setParentItem(lastRect); + lastRect = rect; } QGraphicsView view(&scene); @@ -192,7 +198,7 @@ void tst_QGraphicsView::paintDeepStackingItems() QImage image(100, 100, QImage::Format_ARGB32_Premultiplied); QPainter painter(&image); QBENCHMARK { - view.viewport()->render(&painter); + view.viewport()->render(&painter); } } @@ -202,11 +208,11 @@ void tst_QGraphicsView::paintDeepStackingItems_clipped() QGraphicsRectItem *item = scene.addRect(0, 0, 10, 10); item->setFlag(QGraphicsItem::ItemClipsChildrenToShape); QGraphicsRectItem *lastRect = item; - for (int i = 0; i < 1000; ++i) { - QGraphicsRectItem *rect = scene.addRect(0, 0, 10, 10); - rect->setPos(1, 1); - rect->setParentItem(lastRect); - lastRect = rect; + for (int i = 0; i < DEEP_STACKING_COUNT; ++i) { + QGraphicsRectItem *rect = scene.addRect(0, 0, 10, 10); + rect->setPos(1, 1); + rect->setParentItem(lastRect); + lastRect = rect; } QGraphicsView view(&scene); @@ -219,7 +225,7 @@ void tst_QGraphicsView::paintDeepStackingItems_clipped() QImage image(100, 100, QImage::Format_ARGB32_Premultiplied); QPainter painter(&image); QBENCHMARK { - view.viewport()->render(&painter); + view.viewport()->render(&painter); } } @@ -239,8 +245,8 @@ void tst_QGraphicsView::moveSingleItem() int n = 1; QBENCHMARK { item->setPos(25 * n, 25 * n); - waiter.wait(); - n = n ? 0 : 1; + waiter.wait(); + n = n ? 0 : 1; } } @@ -382,18 +388,18 @@ void tst_QGraphicsView::chipTester() tester.setOpenGL(opengl); tester.setOperation(ChipTester::Operation(operation)); QBENCHMARK { - tester.runBenchmark(); + tester.runBenchmark(); } } static void addChildHelper(QGraphicsItem *parent, int n, bool rotate) { if (!n) - return; + return; QGraphicsRectItem *item = new QGraphicsRectItem(QRectF(0, 0, 50, 50), parent); item->setPos(10, 10); if (rotate) - item->rotate(10); + item->rotate(10); addChildHelper(item, n - 1, rotate); } @@ -421,12 +427,12 @@ void tst_QGraphicsView::deepNesting() QGraphicsScene scene; for (int y = 0; y < 15; ++y) { - for (int x = 0; x < 15; ++x) { - QGraphicsItem *item1 = scene.addRect(QRectF(0, 0, 50, 50)); - if (rotate) item1->rotate(10); - item1->setPos(x * 25, y * 25); - addChildHelper(item1, 30, rotate); - } + for (int x = 0; x < 15; ++x) { + QGraphicsItem *item1 = scene.addRect(QRectF(0, 0, 50, 50)); + if (rotate) item1->rotate(10); + item1->setPos(x * 25, y * 25); + addChildHelper(item1, 30, rotate); + } } scene.setItemIndexMethod(bsp ? QGraphicsScene::BspTreeIndex : QGraphicsScene::NoIndex); scene.setSortCacheEnabled(sortCache); @@ -441,11 +447,11 @@ void tst_QGraphicsView::deepNesting() QBENCHMARK { #ifdef CALLGRIND_DEBUG - CALLGRIND_START_INSTRUMENTATION + CALLGRIND_START_INSTRUMENTATION #endif - view.viewport()->repaint(); + view.viewport()->repaint(); #ifdef CALLGRIND_DEBUG - CALLGRIND_STOP_INSTRUMENTATION + CALLGRIND_STOP_INSTRUMENTATION #endif } } @@ -456,36 +462,36 @@ public: AnimatedPixmapItem(int x, int y, bool rot, bool scal, QGraphicsItem *parent = 0) : QGraphicsPixmapItem(parent), rotateFactor(0), scaleFactor(0) { - rotate = rot; - scale = scal; - xspeed = x; - yspeed = y; + rotate = rot; + scale = scal; + xspeed = x; + yspeed = y; } protected: void advance(int i) - { - if (!i) - return; - int x = int(pos().x()) + pixmap().width(); - x += xspeed; - x = (x % (300 + pixmap().width() * 2)) - pixmap().width(); - int y = int(pos().y()) + pixmap().width(); - y += yspeed; - y = (y % (300 + pixmap().width() * 2)) - pixmap().width(); - setPos(x, y); - - int rot = rotateFactor; - int sca = scaleFactor; + { + if (!i) + return; + int x = int(pos().x()) + pixmap().width(); + x += xspeed; + x = (x % (300 + pixmap().width() * 2)) - pixmap().width(); + int y = int(pos().y()) + pixmap().width(); + y += yspeed; + y = (y % (300 + pixmap().width() * 2)) - pixmap().width(); + setPos(x, y); + + int rot = rotateFactor; + int sca = scaleFactor; if (rotate) - rotateFactor = 1 + (rot + xspeed) % 360; + rotateFactor = 1 + (rot + xspeed) % 360; if (scale) - scaleFactor = 1 + (sca + yspeed) % 50; + scaleFactor = 1 + (sca + yspeed) % 50; - if (rotate || scale) { - qreal s = 0.5 + scaleFactor / 50.0; - setTransform(QTransform().rotate(rotateFactor).scale(s, s)); - } + if (rotate || scale) { + qreal s = 0.5 + scaleFactor / 50.0; + setTransform(QTransform().rotate(rotateFactor).scale(s, s)); + } } private: @@ -543,38 +549,38 @@ void tst_QGraphicsView::imageRiver() view.show(); QPixmap pix(":/images/designer.png"); - QVERIFY(!pix.isNull()); + QVERIFY(!pix.isNull()); QList<QGraphicsItem *> items; QFile file(":/random.data"); QVERIFY(file.open(QIODevice::ReadOnly)); QDataStream str(&file); for (int i = 0; i < 100; ++i) { - AnimatedPixmapItem *item; - if (direction == 0) item = new AnimatedPixmapItem((i % 4) + 1, 0, rotation, scale); - if (direction == 1) item = new AnimatedPixmapItem(0, (i % 4) + 1, rotation, scale); - if (direction == 2) item = new AnimatedPixmapItem((i % 4) + 1, (i % 4) + 1, rotation, scale); - item->setPixmap(pix); + AnimatedPixmapItem *item; + if (direction == 0) item = new AnimatedPixmapItem((i % 4) + 1, 0, rotation, scale); + if (direction == 1) item = new AnimatedPixmapItem(0, (i % 4) + 1, rotation, scale); + if (direction == 2) item = new AnimatedPixmapItem((i % 4) + 1, (i % 4) + 1, rotation, scale); + item->setPixmap(pix); int rnd1, rnd2; str >> rnd1 >> rnd2; - item->setPos(-pix.width() + rnd1 % (view.width() + pix.width()), - -pix.height() + rnd2 % (view.height() + pix.height())); - scene.addItem(item); + item->setPos(-pix.width() + rnd1 % (view.width() + pix.width()), + -pix.height() + rnd2 % (view.height() + pix.height())); + scene.addItem(item); } view.count = 0; QBENCHMARK { #ifdef CALLGRIND_DEBUG - CALLGRIND_START_INSTRUMENTATION + CALLGRIND_START_INSTRUMENTATION #endif - for (int i = 0; i < 100; ++i) { - scene.advance(); - while (view.count < (i+1)) - qApp->processEvents(); - } + for (int i = 0; i < 100; ++i) { + scene.advance(); + while (view.count < (i+1)) + qApp->processEvents(); + } #ifdef CALLGRIND_DEBUG - CALLGRIND_STOP_INSTRUMENTATION + CALLGRIND_STOP_INSTRUMENTATION #endif } } @@ -585,38 +591,38 @@ public: AnimatedTextItem(int x, int y, bool rot, bool scal, QGraphicsItem *parent = 0) : QGraphicsSimpleTextItem(parent), rotateFactor(0), scaleFactor(25) { - setText("River of text"); - rotate = rot; - scale = scal; - xspeed = x; - yspeed = y; + setText("River of text"); + rotate = rot; + scale = scal; + xspeed = x; + yspeed = y; } protected: void advance(int i) - { - if (!i) - return; - QRect r = boundingRect().toRect(); - int x = int(pos().x()) + r.width(); - x += xspeed; - x = (x % (300 + r.width() * 2)) - r.width(); - int y = int(pos().y()) + r.width(); - y += yspeed; - y = (y % (300 + r.width() * 2)) - r.width(); - setPos(x, y); - - int rot = rotateFactor; - int sca = scaleFactor; + { + if (!i) + return; + QRect r = boundingRect().toRect(); + int x = int(pos().x()) + r.width(); + x += xspeed; + x = (x % (300 + r.width() * 2)) - r.width(); + int y = int(pos().y()) + r.width(); + y += yspeed; + y = (y % (300 + r.width() * 2)) - r.width(); + setPos(x, y); + + int rot = rotateFactor; + int sca = scaleFactor; if (rotate) - rotateFactor = 1 + (rot + xspeed) % 360; + rotateFactor = 1 + (rot + xspeed) % 360; if (scale) - scaleFactor = 1 + (sca + yspeed) % 50; + scaleFactor = 1 + (sca + yspeed) % 50; - if (rotate || scale) { - qreal s = 0.5 + scaleFactor / 50.0; - setTransform(QTransform().rotate(rotateFactor).scale(s, s)); - } + if (rotate || scale) { + qreal s = 0.5 + scaleFactor / 50.0; + setTransform(QTransform().rotate(rotateFactor).scale(s, s)); + } } private: @@ -657,37 +663,37 @@ void tst_QGraphicsView::textRiver() view.show(); QPixmap pix(":/images/designer.png"); - QVERIFY(!pix.isNull()); + QVERIFY(!pix.isNull()); QList<QGraphicsItem *> items; QFile file(":/random.data"); QVERIFY(file.open(QIODevice::ReadOnly)); QDataStream str(&file); for (int i = 0; i < 100; ++i) { - AnimatedTextItem *item; - if (direction == 0) item = new AnimatedTextItem((i % 4) + 1, 0, rotation, scale); - if (direction == 1) item = new AnimatedTextItem(0, (i % 4) + 1, rotation, scale); - if (direction == 2) item = new AnimatedTextItem((i % 4) + 1, (i % 4) + 1, rotation, scale); + AnimatedTextItem *item; + if (direction == 0) item = new AnimatedTextItem((i % 4) + 1, 0, rotation, scale); + if (direction == 1) item = new AnimatedTextItem(0, (i % 4) + 1, rotation, scale); + if (direction == 2) item = new AnimatedTextItem((i % 4) + 1, (i % 4) + 1, rotation, scale); int rnd1, rnd2; str >> rnd1 >> rnd2; - item->setPos(-pix.width() + rnd1 % (view.width() + pix.width()), - -pix.height() + rnd2 % (view.height() + pix.height())); - scene.addItem(item); + item->setPos(-pix.width() + rnd1 % (view.width() + pix.width()), + -pix.height() + rnd2 % (view.height() + pix.height())); + scene.addItem(item); } view.count = 0; QBENCHMARK { #ifdef CALLGRIND_DEBUG - CALLGRIND_START_INSTRUMENTATION + CALLGRIND_START_INSTRUMENTATION #endif - for (int i = 0; i < 100; ++i) { - scene.advance(); - while (view.count < (i+1)) - qApp->processEvents(); - } + for (int i = 0; i < 100; ++i) { + scene.advance(); + while (view.count < (i+1)) + qApp->processEvents(); + } #ifdef CALLGRIND_DEBUG - CALLGRIND_STOP_INSTRUMENTATION + CALLGRIND_STOP_INSTRUMENTATION #endif } } diff --git a/tests/benchmarks/qstringlist/qstringlist.pro b/tests/benchmarks/qstringlist/qstringlist.pro index 86c1508..5c64b34 100644 --- a/tests/benchmarks/qstringlist/qstringlist.pro +++ b/tests/benchmarks/qstringlist/qstringlist.pro @@ -4,3 +4,5 @@ CONFIG -= debug CONFIG += release QT -= gui SOURCES += main.cpp + +symbian: LIBS += -llibpthread diff --git a/tests/benchmarks/qstylesheetstyle/main.cpp b/tests/benchmarks/qstylesheetstyle/main.cpp index 19efcab..d6fa48c 100644 --- a/tests/benchmarks/qstylesheetstyle/main.cpp +++ b/tests/benchmarks/qstylesheetstyle/main.cpp @@ -49,16 +49,16 @@ class tst_qstylesheetstyle : public QObject private slots: void empty(); void empty_events(); - + void simple(); void simple_events(); - + void grid_data(); void grid(); - + private: QWidget *buildSimpleWidgets(); - + }; @@ -103,7 +103,7 @@ void tst_qstylesheetstyle::empty_events() delete w; } -static const char *simple_css = +static const char *simple_css = " QLineEdit { background: red; } QPushButton { border: 1px solid yellow; color: pink; } \n" " QCheckBox { margin: 3px 5px; background-color:red; } QAbstractButton { background-color: #456; } \n" " QFrame { padding: 3px; } QLabel { color: black } QSpinBox:hover { background-color:blue; } "; @@ -138,7 +138,7 @@ void tst_qstylesheetstyle::grid_data() QTest::addColumn<bool>("events"); QTest::addColumn<bool>("show"); QTest::addColumn<int>("N"); - for (int n = 5; n <= 25; n += 5) { + for (int n = 5; n <= 25; n += 5) { const QByteArray nString = QByteArray::number(n*n); QTest::newRow(("simple--" + nString).constData()) << false << false << n; QTest::newRow(("events--" + nString).constData()) << true << false << n; @@ -153,6 +153,13 @@ void tst_qstylesheetstyle::grid() QFETCH(bool, show); QFETCH(int, N); +#ifdef Q_OS_SYMBIAN + // Symbian has limited stack (max 80k), which will run out when N >= 20 due to + // QWidget::show() using recursion among grid labels somewhere down the line. + if (show && N >= 20) + QSKIP("Grid too big for device to show", SkipSingle); +#endif + QWidget *w = new QWidget(); QGridLayout *layout = new QGridLayout(w); w->setLayout(layout); diff --git a/tests/benchmarks/qthreadstorage/qthreadstorage.pro b/tests/benchmarks/qthreadstorage/qthreadstorage.pro new file mode 100644 index 0000000..f9c1978 --- /dev/null +++ b/tests/benchmarks/qthreadstorage/qthreadstorage.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_qthreadstorage + +SOURCES += tst_qthreadstorage.cpp + diff --git a/tests/benchmarks/qthreadstorage/tst_qthreadstorage.cpp b/tests/benchmarks/qthreadstorage/tst_qthreadstorage.cpp new file mode 100644 index 0000000..c00bf5a --- /dev/null +++ b/tests/benchmarks/qthreadstorage/tst_qthreadstorage.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qtest.h> +#include <QtCore> + +//TESTED_FILES= + +QThreadStorage<int *> dummy[8]; + +QThreadStorage<QString *> tls1; + +class tst_QThreadStorage : public QObject +{ + Q_OBJECT + +public: + tst_QThreadStorage(); + virtual ~tst_QThreadStorage(); + +public slots: + void init(); + void cleanup(); + +private slots: + void construct(); + void get(); + void set(); +}; + +tst_QThreadStorage::tst_QThreadStorage() +{ +} + +tst_QThreadStorage::~tst_QThreadStorage() +{ +} + +void tst_QThreadStorage::init() +{ + dummy[1].setLocalData(new int(5)); + dummy[2].setLocalData(new int(4)); + dummy[3].setLocalData(new int(3)); + tls1.setLocalData(new QString()); +} + +void tst_QThreadStorage::cleanup() +{ +} + +void tst_QThreadStorage::construct() +{ + QBENCHMARK { + QThreadStorage<int *> ts; + } +} + + +void tst_QThreadStorage::get() +{ + QThreadStorage<int *> ts; + ts.setLocalData(new int(45)); + + int count = 0; + QBENCHMARK { + int *i = ts.localData(); + count += *i; + } + ts.setLocalData(0); +} + +void tst_QThreadStorage::set() +{ + QThreadStorage<int *> ts; + + int count = 0; + QBENCHMARK { + ts.setLocalData(new int(count)); + count++; + } + ts.setLocalData(0); +} + + +QTEST_MAIN(tst_QThreadStorage) +#include "tst_qthreadstorage.moc" |