diff options
Diffstat (limited to 'tests')
61 files changed, 2990 insertions, 212 deletions
diff --git a/tests/arthur/lance/widgets.h b/tests/arthur/lance/widgets.h index 88e0726..f7d3268 100644 --- a/tests/arthur/lance/widgets.h +++ b/tests/arthur/lance/widgets.h @@ -236,7 +236,12 @@ public: } if (m_render_view.isNull()) { - m_render_view = T::window()->windowSurface()->grabWidget(this); + + if (T::window()->windowSurface()) + m_render_view = T::window()->windowSurface()->grabWidget(this); + else + m_render_view = QPixmap::grabWidget(this); + m_render_view.save("renderView.png"); } } diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 3198a65..1abf9b7 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -462,7 +462,7 @@ SUBDIRS += \ rcc \ windowsmobile -contains(QT_CONFIG,opengl):SUBDIRS += qgl +contains(QT_CONFIG,opengl):SUBDIRS += qgl qglbuffer contains(QT_CONFIG,qt3support):!wince*:SUBDIRS += $$Q3SUBDIRS diff --git a/tests/auto/linguist/lupdate/testdata/good/respfile/lupdatecmd b/tests/auto/linguist/lupdate/testdata/good/respfile/lupdatecmd new file mode 100644 index 0000000..6f198ab --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/respfile/lupdatecmd @@ -0,0 +1,2 @@ +# Add the command that lupdate should run here. If it can't find anything it will default to +lupdate -silent @sources.lst -ts @tsfiles.lst diff --git a/tests/auto/linguist/lupdate/testdata/good/respfile/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/respfile/project.ts.result new file mode 100644 index 0000000..3a864a2 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/respfile/project.ts.result @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.0"> +<context> + <name>Dialog2</name> + <message> + <location filename="source1.cpp" line="47"/> + <source>func1</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="source2.cpp" line="47"/> + <source>func2</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/tests/auto/linguist/lupdate/testdata/good/respfile/source1.cpp b/tests/auto/linguist/lupdate/testdata/good/respfile/source1.cpp new file mode 100644 index 0000000..33642c4 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/respfile/source1.cpp @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// IMPORTANT!!!! If you want to add testdata to this file, +// always add it to the end in order to not change the linenumbers of translations!!! + +void Dialog2::func3() +{ + tr("func1"); +} + diff --git a/tests/auto/linguist/lupdate/testdata/good/respfile/source2.cpp b/tests/auto/linguist/lupdate/testdata/good/respfile/source2.cpp new file mode 100644 index 0000000..f284a61 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/respfile/source2.cpp @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +// IMPORTANT!!!! If you want to add testdata to this file, +// always add it to the end in order to not change the linenumbers of translations!!! + +void Dialog2::func3() +{ + tr("func2"); +} + diff --git a/tests/auto/linguist/lupdate/testdata/good/respfile/sources.lst b/tests/auto/linguist/lupdate/testdata/good/respfile/sources.lst new file mode 100644 index 0000000..430937e --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/respfile/sources.lst @@ -0,0 +1,2 @@ +source1.cpp +source2.cpp diff --git a/tests/auto/linguist/lupdate/testdata/good/respfile/tsfiles.lst b/tests/auto/linguist/lupdate/testdata/good/respfile/tsfiles.lst new file mode 100644 index 0000000..f3eb71f --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/respfile/tsfiles.lst @@ -0,0 +1 @@ +project.ts diff --git a/tests/auto/modeltest/dynamictreemodel.cpp b/tests/auto/modeltest/dynamictreemodel.cpp index 24d3ab3..b572eb1 100644 --- a/tests/auto/modeltest/dynamictreemodel.cpp +++ b/tests/auto/modeltest/dynamictreemodel.cpp @@ -160,10 +160,11 @@ QVariant DynamicTreeModel::data(const QModelIndex &index, int role) const void DynamicTreeModel::clear() { + beginResetModel(); m_items.clear(); m_childItems.clear(); nextId = 1; - reset(); + endResetModel(); } diff --git a/tests/auto/modeltest/tst_modeltest.cpp b/tests/auto/modeltest/tst_modeltest.cpp index 95326d4..da5cd6a 100644 --- a/tests/auto/modeltest/tst_modeltest.cpp +++ b/tests/auto/modeltest/tst_modeltest.cpp @@ -67,6 +67,7 @@ private slots: void standardItemModel(); void testInsertThroughProxy(); void moveSourceItems(); + void testResetThroughProxy(); }; @@ -225,8 +226,9 @@ public slots: void storePersistent() { - m_persistentSourceIndexes.clear(); - m_persistentProxyIndexes.clear(); + foreach(const QModelIndex &idx, m_persistentProxyIndexes) + Q_ASSERT(idx.isValid()); // This is called from layoutAboutToBeChanged. Persistent indexes should be valid + Q_ASSERT(m_proxy->persistent().isEmpty()); storePersistent(QModelIndex()); Q_ASSERT(!m_proxy->persistent().isEmpty()); @@ -243,6 +245,8 @@ public slots: QModelIndex updatedSource = m_persistentSourceIndexes.at(row); QCOMPARE(m_proxy->mapToSource(updatedProxy), updatedSource); } + m_persistentSourceIndexes.clear(); + m_persistentProxyIndexes.clear(); } private: @@ -278,6 +282,28 @@ void tst_ModelTest::moveSourceItems() moveCommand->doCommand(); } +void tst_ModelTest::testResetThroughProxy() +{ + DynamicTreeModel *model = new DynamicTreeModel(this); + + ModelInsertCommand *insertCommand = new ModelInsertCommand(model, this); + insertCommand->setStartRow(0); + insertCommand->setEndRow(2); + insertCommand->doCommand(); + + QPersistentModelIndex persistent = model->index(0, 0); + + AccessibleProxyModel *proxy = new AccessibleProxyModel(this); + proxy->setSourceModel(model); + + ObservingObject observer(proxy); + observer.storePersistent(); + + ModelResetCommand *resetCommand = new ModelResetCommand(model, this); + resetCommand->setNumCols(0); + resetCommand->doCommand(); +} + QTEST_MAIN(tst_ModelTest) #include "tst_modeltest.moc" diff --git a/tests/auto/qbrush/tst_qbrush.cpp b/tests/auto/qbrush/tst_qbrush.cpp index bc2bc60..628e859 100644 --- a/tests/auto/qbrush/tst_qbrush.cpp +++ b/tests/auto/qbrush/tst_qbrush.cpp @@ -108,6 +108,15 @@ void tst_QBrush::operator_eq_eq_data() << false; QTest::newRow("rad vs con") << QBrush(QRadialGradient(0, 0, 0, 0, 0)) << QBrush(QConicalGradient(0, 0, 0)) << false; + + QBrush b1(lg); + QBrush b2(lg); + b1.setTransform(QTransform().scale(2, 2)); + QTest::newRow("lg with transform vs same lg") << b1 << b2 << false; + + b2.setTransform(QTransform().scale(2, 2)); + QTest::newRow("lg w/transform vs same lg w/same transform") << b1 << b2 << true; + } void tst_QBrush::operator_eq_eq() diff --git a/tests/auto/qcombobox/tst_qcombobox.cpp b/tests/auto/qcombobox/tst_qcombobox.cpp index fbaa824..1fcea9e 100644 --- a/tests/auto/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/qcombobox/tst_qcombobox.cpp @@ -156,6 +156,7 @@ private slots: void resetModel(); void keyBoardNavigationWithMouse(); void task_QTBUG_1071_changingFocusEmitsActivated(); + void maxVisibleItems(); protected slots: void onEditTextChanged( const QString &newString ); @@ -2529,5 +2530,34 @@ void tst_QComboBox::task_QTBUG_1071_changingFocusEmitsActivated() QTRY_COMPARE(spy.count(), 1); } +void tst_QComboBox::maxVisibleItems() +{ + QComboBox comboBox; + QCOMPARE(comboBox.maxVisibleItems(), 10); //default value. + + QStringList content; + for(int i = 1; i < 50; i++) + content += QString::number(i); + + comboBox.addItems(content); + comboBox.show(); + comboBox.resize(200, comboBox.height()); + QTRY_VERIFY(comboBox.isVisible()); + + comboBox.setMaxVisibleItems(5); + QCOMPARE(comboBox.maxVisibleItems(), 5); + + comboBox.showPopup(); + QTRY_VERIFY(comboBox.view()); + QTRY_VERIFY(comboBox.view()->isVisible()); + + QAbstractItemView *v = comboBox.view(); + int itemHeight = v->visualRect(v->model()->index(0,0)).height(); + if (v->style()->styleHint(QStyle::SH_ComboBox_Popup)) + QCOMPARE(v->viewport()->height(), itemHeight * comboBox.maxVisibleItems()); + // QCombobox without a popup does not work, see QTBUG-760 +} + + QTEST_MAIN(tst_QComboBox) #include "tst_qcombobox.moc" diff --git a/tests/auto/qdir/tst_qdir.cpp b/tests/auto/qdir/tst_qdir.cpp index c7f9b6b..ba18bbb 100644 --- a/tests/auto/qdir/tst_qdir.cpp +++ b/tests/auto/qdir/tst_qdir.cpp @@ -49,6 +49,7 @@ #include <qregexp.h> #include <qstringlist.h> #include "../network-settings.h" +#include "../../shared/filesystem.h" #if defined(Q_OS_SYMBIAN) # define STRINGIFY(x) #x @@ -164,6 +165,8 @@ private slots: void longFileName_data(); void longFileName(); + + void updateFileLists(); }; // Testing get/set functions @@ -982,6 +985,13 @@ tst_QDir::cleanPath_data() QTest::newRow("data7") << ".//file1.txt" << "file1.txt"; QTest::newRow("data8") << "/foo/bar/..//file1.txt" << "/foo/file1.txt"; QTest::newRow("data9") << "//" << "/"; +#if !defined(Q_OS_WINCE) +#if defined Q_OS_WIN + QTest::newRow("data10") << "c:\\" << "c:/"; +#else + QTest::newRow("data10") << "/:/" << "/:"; +#endif +#endif } @@ -1435,6 +1445,95 @@ void tst_QDir::longFileName() QFile::remove(fileName); } +void tst_QDir::updateFileLists() +{ + // Test setup + + FileSystem fs; + + QVERIFY( fs.createDirectory("update-file-lists") ); + QVERIFY( fs.createFile("update-file-lists/file1.txt") ); + QVERIFY( fs.createFile("update-file-lists/file2.doc") ); + + QVERIFY( fs.createDirectory("update-file-lists/sub-dir1") ); + QVERIFY( fs.createFile("update-file-lists/sub-dir1/file3.txt") ); + QVERIFY( fs.createFile("update-file-lists/sub-dir1/file4.doc") ); + QVERIFY( fs.createFile("update-file-lists/sub-dir1/file5.txt") ); + + QVERIFY( fs.createDirectory("update-file-lists/sub-dir2") ); + QVERIFY( fs.createFile("update-file-lists/sub-dir2/file6.txt") ); + QVERIFY( fs.createFile("update-file-lists/sub-dir2/file7.txt") ); + QVERIFY( fs.createFile("update-file-lists/sub-dir2/file8.doc") ); + QVERIFY( fs.createFile("update-file-lists/sub-dir2/file9.doc") ); + + // Actual test + + QDir dir("update-file-lists"); + + QCOMPARE(dir.count(), uint(6)); + QCOMPARE(dir.entryList().size(), 6); + QCOMPARE(dir.entryInfoList().size(), 6); + + dir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot); + + QCOMPARE(dir.entryList().size(), 4); + QCOMPARE(dir.count(), uint(4)); + QCOMPARE(dir.entryInfoList().size(), 4); + + dir.setPath("update-file-lists/sub-dir1"); + + QCOMPARE(dir.entryInfoList().size(), 3); + QCOMPARE(dir.count(), uint(3)); + QCOMPARE(dir.entryList().size(), 3); + + dir.setNameFilters(QStringList("*.txt")); + + QCOMPARE(dir.entryInfoList().size(), 2); + QCOMPARE(dir.entryList().size(), 2); + QCOMPARE(dir.count(), uint(2)); + + dir.setPath("update-file-lists"); + dir = QDir(dir.path(), + "*.txt", + QDir::Name | QDir::DirsLast, + QDir::AllEntries | QDir::AllDirs | QDir::NoDotAndDotDot); + + QCOMPARE(dir.count(), uint(3)); + QCOMPARE(dir.entryList().size(), 3); + QCOMPARE(dir.entryInfoList().size(), 3); + QCOMPARE(dir.entryList(), QStringList() << "file1.txt" << "sub-dir1" << "sub-dir2"); + + dir.setSorting(QDir::Name | QDir::DirsFirst); + + QCOMPARE(dir.count(), uint(3)); + QCOMPARE(dir.entryList().size(), 3); + QCOMPARE(dir.entryInfoList().size(), 3); + QCOMPARE(dir.entryList(), QStringList() << "sub-dir1" << "sub-dir2" << "file1.txt"); + + { + QVERIFY( fs.createFile("update-file-lists/extra-file.txt") ); + + QDir dir2(dir); + + QCOMPARE(dir2.count(), uint(3)); + QCOMPARE(dir2.entryList().size(), 3); + QCOMPARE(dir2.entryInfoList().size(), 3); + QCOMPARE(dir2.entryList(), QStringList() << "sub-dir1" << "sub-dir2" << "file1.txt"); + + dir2.refresh(); + + QCOMPARE(dir2.count(), uint(4)); + QCOMPARE(dir2.entryList().size(), 4); + QCOMPARE(dir2.entryInfoList().size(), 4); + QCOMPARE(dir2.entryList(), QStringList() << "sub-dir1" << "sub-dir2" << "extra-file.txt" << "file1.txt"); + } + + QCOMPARE(dir.count(), uint(3)); + QCOMPARE(dir.entryList().size(), 3); + QCOMPARE(dir.entryInfoList().size(), 3); + QCOMPARE(dir.entryList(), QStringList() << "sub-dir1" << "sub-dir2" << "file1.txt"); +} + QTEST_MAIN(tst_QDir) #include "tst_qdir.moc" diff --git a/tests/auto/qdiriterator/foo/bar/readme.txt b/tests/auto/qdiriterator/foo/bar/readme.txt deleted file mode 100644 index e69de29..0000000 --- a/tests/auto/qdiriterator/foo/bar/readme.txt +++ /dev/null diff --git a/tests/auto/qdiriterator/recursiveDirs/dir1/aPage.html b/tests/auto/qdiriterator/recursiveDirs/dir1/aPage.html deleted file mode 100644 index 51a2261..0000000 --- a/tests/auto/qdiriterator/recursiveDirs/dir1/aPage.html +++ /dev/null @@ -1,8 +0,0 @@ -<html xmlns="http://www.w3.org/1999/xhtml/"> - <head> - <title>A title</title> - </head> - <body> - <p>Some text</p> - </body> -</html> diff --git a/tests/auto/qdiriterator/recursiveDirs/dir1/textFileB.txt b/tests/auto/qdiriterator/recursiveDirs/dir1/textFileB.txt deleted file mode 100644 index 5b1dd02..0000000 --- a/tests/auto/qdiriterator/recursiveDirs/dir1/textFileB.txt +++ /dev/null @@ -1 +0,0 @@ -Some Text diff --git a/tests/auto/qdiriterator/recursiveDirs/textFileA.txt b/tests/auto/qdiriterator/recursiveDirs/textFileA.txt deleted file mode 100644 index 5b1dd02..0000000 --- a/tests/auto/qdiriterator/recursiveDirs/textFileA.txt +++ /dev/null @@ -1 +0,0 @@ -Some Text diff --git a/tests/auto/qdiriterator/tst_qdiriterator.cpp b/tests/auto/qdiriterator/tst_qdiriterator.cpp index 6cdd1f7..f6fce32 100644 --- a/tests/auto/qdiriterator/tst_qdiriterator.cpp +++ b/tests/auto/qdiriterator/tst_qdiriterator.cpp @@ -71,6 +71,39 @@ public: tst_QDirIterator(); virtual ~tst_QDirIterator(); +private: // convenience functions + QStringList createdDirectories; + QStringList createdFiles; + + QDir currentDir; + bool createDirectory(const QString &dirName) + { + if (currentDir.mkdir(dirName)) { + createdDirectories.prepend(dirName); + return true; + } + return false; + } + + bool createFile(const QString &fileName) + { + QFile file(fileName); + if (file.open(QIODevice::WriteOnly)) { + createdFiles << fileName; + return true; + } + return false; + } + + bool createLink(const QString &destination, const QString &linkName) + { + if (QFile::link(destination, linkName)) { + createdFiles << linkName; + return true; + } + return false; + } + private slots: void iterateRelativeDirectory_data(); void iterateRelativeDirectory(); @@ -96,41 +129,47 @@ tst_QDirIterator::tst_QDirIterator() QFile::remove("entrylist/directory/entrylist3.lnk"); QFile::remove("entrylist/directory/entrylist4.lnk"); + createDirectory("entrylist"); + createDirectory("entrylist/directory"); + createFile("entrylist/file"); + createFile("entrylist/writable"); + createFile("entrylist/directory/dummy"); + + createDirectory("recursiveDirs"); + createDirectory("recursiveDirs/dir1"); + createFile("recursiveDirs/textFileA.txt"); + createFile("recursiveDirs/dir1/aPage.html"); + createFile("recursiveDirs/dir1/textFileB.txt"); + + createDirectory("foo"); + createDirectory("foo/bar"); + createFile("foo/bar/readme.txt"); + #ifndef Q_NO_SYMLINKS # if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) // ### Sadly, this is a platform difference right now. - QFile::link("entrylist/file", "entrylist/linktofile.lnk"); + createLink("entrylist/file", "entrylist/linktofile.lnk"); # ifndef Q_NO_SYMLINKS_TO_DIRS - QFile::link("entrylist/directory", "entrylist/linktodirectory.lnk"); + createLink("entrylist/directory", "entrylist/linktodirectory.lnk"); # endif - QFile::link("entrylist/nothing", "entrylist/brokenlink.lnk"); + createLink("entrylist/nothing", "entrylist/brokenlink.lnk"); # else - QFile::link("file", "entrylist/linktofile.lnk"); + createLink("file", "entrylist/linktofile.lnk"); # ifndef Q_NO_SYMLINKS_TO_DIRS - QFile::link("directory", "entrylist/linktodirectory.lnk"); + createLink("directory", "entrylist/linktodirectory.lnk"); # endif - QFile::link("nothing", "entrylist/brokenlink.lnk"); + createLink("nothing", "entrylist/brokenlink.lnk"); # endif #endif - QFile("entrylist/writable").open(QIODevice::ReadWrite); } tst_QDirIterator::~tst_QDirIterator() { - QFile::remove("entrylist/directory"); - QFile::remove("entrylist/linktofile.lnk"); - QFile::remove("entrylist/linktodirectory.lnk"); - QFile::remove("entrylist/brokenlink.lnk"); - QFile::remove("entrylist/brokenlink"); - QFile::remove("entrylist/writable"); - QFile::remove("entrylist/entrylist1.lnk"); - QFile::remove("entrylist/entrylist2.lnk"); - QFile::remove("entrylist/entrylist3.lnk"); - QFile::remove("entrylist/entrylist4.lnk"); - QFile::remove("entrylist/directory/entrylist1.lnk"); - QFile::remove("entrylist/directory/entrylist2.lnk"); - QFile::remove("entrylist/directory/entrylist3.lnk"); - QFile::remove("entrylist/directory/entrylist4.lnk"); + Q_FOREACH(QString fileName, createdFiles) + QFile::remove(fileName); + + Q_FOREACH(QString dirName, createdDirectories) + currentDir.rmdir(dirName); } void tst_QDirIterator::iterateRelativeDirectory_data() @@ -298,23 +337,23 @@ void tst_QDirIterator::stopLinkLoop() { #ifdef Q_OS_WIN // ### Sadly, this is a platform difference right now. - QFile::link(QDir::currentPath() + QLatin1String("/entrylist"), "entrylist/entrylist1.lnk"); - QFile::link("entrylist/.", "entrylist/entrylist2.lnk"); - QFile::link("entrylist/../entrylist/.", "entrylist/entrylist3.lnk"); - QFile::link("entrylist/..", "entrylist/entrylist4.lnk"); - QFile::link(QDir::currentPath() + QLatin1String("/entrylist"), "entrylist/directory/entrylist1.lnk"); - QFile::link("entrylist/.", "entrylist/directory/entrylist2.lnk"); - QFile::link("entrylist/../directory/.", "entrylist/directory/entrylist3.lnk"); - QFile::link("entrylist/..", "entrylist/directory/entrylist4.lnk"); + createLink(QDir::currentPath() + QLatin1String("/entrylist"), "entrylist/entrylist1.lnk"); + createLink("entrylist/.", "entrylist/entrylist2.lnk"); + createLink("entrylist/../entrylist/.", "entrylist/entrylist3.lnk"); + createLink("entrylist/..", "entrylist/entrylist4.lnk"); + createLink(QDir::currentPath() + QLatin1String("/entrylist"), "entrylist/directory/entrylist1.lnk"); + createLink("entrylist/.", "entrylist/directory/entrylist2.lnk"); + createLink("entrylist/../directory/.", "entrylist/directory/entrylist3.lnk"); + createLink("entrylist/..", "entrylist/directory/entrylist4.lnk"); #else - QFile::link(QDir::currentPath() + QLatin1String("/entrylist"), "entrylist/entrylist1.lnk"); - QFile::link(".", "entrylist/entrylist2.lnk"); - QFile::link("../entrylist/.", "entrylist/entrylist3.lnk"); - QFile::link("..", "entrylist/entrylist4.lnk"); - QFile::link(QDir::currentPath() + QLatin1String("/entrylist"), "entrylist/directory/entrylist1.lnk"); - QFile::link(".", "entrylist/directory/entrylist2.lnk"); - QFile::link("../directory/.", "entrylist/directory/entrylist3.lnk"); - QFile::link("..", "entrylist/directory/entrylist4.lnk"); + createLink(QDir::currentPath() + QLatin1String("/entrylist"), "entrylist/entrylist1.lnk"); + createLink(".", "entrylist/entrylist2.lnk"); + createLink("../entrylist/.", "entrylist/entrylist3.lnk"); + createLink("..", "entrylist/entrylist4.lnk"); + createLink(QDir::currentPath() + QLatin1String("/entrylist"), "entrylist/directory/entrylist1.lnk"); + createLink(".", "entrylist/directory/entrylist2.lnk"); + createLink("../directory/.", "entrylist/directory/entrylist3.lnk"); + createLink("..", "entrylist/directory/entrylist4.lnk"); #endif QDirIterator it(QLatin1String("entrylist"), QDirIterator::Subdirectories | QDirIterator::FollowSymlinks); @@ -325,22 +364,6 @@ void tst_QDirIterator::stopLinkLoop() QVERIFY(max); // The goal of this test is only to ensure that the test above don't malfunction - -#ifdef Q_OS_WIN - // ### Sadly, this is a platform difference right now. - QFile::link(QDir::currentPath() + QLatin1String("/entrylist"), "entrylist/entrylist1.lnk"); - QFile::link("../../entrylist/.", "entrylist/entrylist2.lnk"); - QFile::link("entrylist/..", "entrylist/entrylist3.lnk"); -#else - QFile::remove("entrylist/entrylist1.lnk"); - QFile::remove("entrylist/entrylist2.lnk"); - QFile::remove("entrylist/entrylist3.lnk"); - QFile::remove("entrylist/entrylist4.lnk"); - QFile::remove("entrylist/directory/entrylist1.lnk"); - QFile::remove("entrylist/directory/entrylist2.lnk"); - QFile::remove("entrylist/directory/entrylist3.lnk"); - QFile::remove("entrylist/directory/entrylist4.lnk"); -#endif } class EngineWithNoIterator : public QFSFileEngine diff --git a/tests/auto/qdom/tst_qdom.cpp b/tests/auto/qdom/tst_qdom.cpp index d1b2ea5..76903e5 100644 --- a/tests/auto/qdom/tst_qdom.cpp +++ b/tests/auto/qdom/tst_qdom.cpp @@ -476,10 +476,6 @@ void tst_QDom::save() void tst_QDom::initTestCase() { -#ifdef Q_CC_MINGW - QSKIP("Our current test machine, arsia, is too slow for this auto test.", SkipAll); -#endif - QFile file(SRCDIR "testdata/excludedCodecs.txt"); QVERIFY(file.open(QIODevice::ReadOnly|QIODevice::Text)); @@ -1676,7 +1672,7 @@ void tst_QDom::appendDocumentNode() const doc.appendChild(elem); - Q_ASSERT(!xml.isNull()); + QVERIFY(!xml.isNull()); const QString expected(QLatin1String("<document>\n<test_elem name=\"value\"/>\n</document>\n")); elem.appendChild(xml); diff --git a/tests/auto/qeasingcurve/tst_qeasingcurve.cpp b/tests/auto/qeasingcurve/tst_qeasingcurve.cpp index 0122d43..12ddff1 100644 --- a/tests/auto/qeasingcurve/tst_qeasingcurve.cpp +++ b/tests/auto/qeasingcurve/tst_qeasingcurve.cpp @@ -193,186 +193,208 @@ void tst_QEasingCurve::valueForProgress_data() // integer values and avoid fp inaccuracies QTest::newRow("Linear") << int(QEasingCurve::Linear) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.1 << 0.2 << 0.3 << 0.4 << 0.5 << 0.6 << 0.7 << 0.8 << 0.9 << 1); + << (RealList() << 0.0000 << 0.1000 << 0.2000 << 0.3000 << 0.4000 << 0.5000 << 0.6000 << 0.7000 << 0.8000 << 0.9000 << 1.0000); QTest::newRow("InQuad") << int(QEasingCurve::InQuad) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.01 << 0.04 << 0.09 << 0.16 << 0.25 << 0.36 << 0.49 << 0.64 << 0.81 << 1); + << (RealList() << 0.0000 << 0.0100 << 0.0400 << 0.0900 << 0.1600 << 0.2500 << 0.3600 << 0.4900 << 0.6400 << 0.8100 << 1.0000); QTest::newRow("OutQuad") << int(QEasingCurve::OutQuad) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.19 << 0.36 << 0.51 << 0.64 << 0.75 << 0.84 << 0.91 << 0.96 << 0.99 << 1); + << (RealList() << 0.0000 << 0.1900 << 0.3600 << 0.5100 << 0.6400 << 0.7500 << 0.8400 << 0.9100 << 0.9600 << 0.9900 << 1.0000); QTest::newRow("InOutQuad") << int(QEasingCurve::InOutQuad) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.02 << 0.08 << 0.18 << 0.32 << 0.5 << 0.68 << 0.82 << 0.92 << 0.98 << 1); + << (RealList() << 0.0000 << 0.0200 << 0.0800 << 0.1800 << 0.3200 << 0.5000 << 0.6800 << 0.8200 << 0.9200 << 0.9800 << 1.0000); QTest::newRow("OutInQuad") << int(QEasingCurve::OutInQuad) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.18 << 0.32 << 0.42 << 0.48 << 0.5 << 0.52 << 0.58 << 0.68 << 0.82 << 1); + << (RealList() << 0.0000 << 0.1800 << 0.3200 << 0.4200 << 0.4800 << 0.5000 << 0.5200 << 0.5800 << 0.6800 << 0.8200 << 1.0000); QTest::newRow("InCubic") << int(QEasingCurve::InCubic) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.001 << 0.008 << 0.027 << 0.064 << 0.125 << 0.216 << 0.343 << 0.512 << 0.729 << 1); + << (RealList() << 0.0000 << 0.0010 << 0.0080 << 0.0270 << 0.0640 << 0.1250 << 0.2160 << 0.3430 << 0.5120 << 0.7290 << 1.0000); QTest::newRow("OutCubic") << int(QEasingCurve::OutCubic) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.271 << 0.488 << 0.657 << 0.784 << 0.875 << 0.936 << 0.973 << 0.992 << 0.999 << 1); + << (RealList() << 0.0000 << 0.2710 << 0.4880 << 0.6570 << 0.7840 << 0.8750 << 0.9360 << 0.9730 << 0.9920 << 0.9990 << 1.0000); QTest::newRow("InOutCubic") << int(QEasingCurve::InOutCubic) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.004 << 0.032 << 0.108 << 0.256 << 0.5 << 0.744 << 0.892 << 0.968 << 0.996 << 1); + << (RealList() << 0.0000 << 0.0040 << 0.0320 << 0.1080 << 0.2560 << 0.5000 << 0.7440 << 0.8920 << 0.9680 << 0.9960 << 1.0000); QTest::newRow("OutInCubic") << int(QEasingCurve::OutInCubic) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.244 << 0.392 << 0.468 << 0.496 << 0.5 << 0.504 << 0.532 << 0.608 << 0.756 << 1); + << (RealList() << 0.0000 << 0.2440 << 0.3920 << 0.4680 << 0.4960 << 0.5000 << 0.5040 << 0.5320 << 0.6080 << 0.7560 << 1.0000); QTest::newRow("InQuart") << int(QEasingCurve::InQuart) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.0001 << 0.0016 << 0.0081 << 0.0256 << 0.0625 << 0.1296 << 0.2401 << 0.4096 << 0.6561 << 1); + << (RealList() << 0.0000 << 0.0001 << 0.0016 << 0.0081 << 0.0256 << 0.0625 << 0.1296 << 0.2401 << 0.4096 << 0.6561 << 1.0000); QTest::newRow("OutQuart") << int(QEasingCurve::OutQuart) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.3439 << 0.5904 << 0.7599 << 0.8704 << 0.9375 << 0.9744 << 0.9919 << 0.9984 << 0.9999 << 1); + << (RealList() << 0.0000 << 0.3439 << 0.5904 << 0.7599 << 0.8704 << 0.9375 << 0.9744 << 0.9919 << 0.9984 << 0.9999 << 1.0000); QTest::newRow("InOutQuart") << int(QEasingCurve::InOutQuart) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.0008 << 0.0128 << 0.0648 << 0.2048 << 0.5 << 0.7952 << 0.9352 << 0.9872 << 0.9992 << 1); + << (RealList() << 0.0000 << 0.0008 << 0.0128 << 0.0648 << 0.2048 << 0.5000 << 0.7952 << 0.9352 << 0.9872 << 0.9992 << 1.0000); QTest::newRow("OutInQuart") << int(QEasingCurve::OutInQuart) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.2952 << 0.4352 << 0.4872 << 0.4992 << 0.5 << 0.5008 << 0.5128 << 0.5648 << 0.7048 << 1); + << (RealList() << 0.0000 << 0.2952 << 0.4352 << 0.4872 << 0.4992 << 0.5000 << 0.5008 << 0.5128 << 0.5648 << 0.7048 << 1.0000); QTest::newRow("InQuint") << int(QEasingCurve::InQuint) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 1e-05 << 0.00032 << 0.00243 << 0.01024 << 0.03125 << 0.07776 << 0.1681 << 0.3277 << 0.5905 << 1); + << (RealList() << 0.0000 << 0.0000 << 0.0003 << 0.0024 << 0.0102 << 0.0313 << 0.0778 << 0.1681 << 0.3277 << 0.5905 << 1.0000); QTest::newRow("OutQuint") << int(QEasingCurve::OutQuint) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.4095 << 0.6723 << 0.8319 << 0.9222 << 0.9688 << 0.9898 << 0.9976 << 0.9997 << 1 << 1); + << (RealList() << 0.0000 << 0.4095 << 0.6723 << 0.8319 << 0.9222 << 0.9688 << 0.9898 << 0.9976 << 0.9997 << 1.0000 << 1.0000); QTest::newRow("InOutQuint") << int(QEasingCurve::InOutQuint) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.00016 << 0.00512 << 0.03888 << 0.1638 << 0.5 << 0.8362 << 0.9611 << 0.9949 << 0.9998 << 1); + << (RealList() << 0.0000 << 0.0002 << 0.0051 << 0.0389 << 0.1638 << 0.5000 << 0.8362 << 0.9611 << 0.9949 << 0.9998 << 1.0000); QTest::newRow("OutInQuint") << int(QEasingCurve::OutInQuint) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.3362 << 0.4611 << 0.4949 << 0.4998 << 0.5 << 0.5002 << 0.5051 << 0.5389 << 0.6638 << 1); + << (RealList() << 0.0000 << 0.3362 << 0.4611 << 0.4949 << 0.4998 << 0.5000 << 0.5002 << 0.5051 << 0.5389 << 0.6638 << 1.0000); QTest::newRow("InSine") << int(QEasingCurve::InSine) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.01231 << 0.04894 << 0.109 << 0.191 << 0.2929 << 0.4122 << 0.546 << 0.691 << 0.8436 << 1); + << (RealList() << 0.0000 << 0.0123 << 0.0489 << 0.1090 << 0.1910 << 0.2929 << 0.4122 << 0.5460 << 0.6910 << 0.8436 << 1.0000); QTest::newRow("OutSine") << int(QEasingCurve::OutSine) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.1564 << 0.309 << 0.454 << 0.5878 << 0.7071 << 0.809 << 0.891 << 0.9511 << 0.9877 << 1); + << (RealList() << 0.0000 << 0.1564 << 0.3090 << 0.4540 << 0.5878 << 0.7071 << 0.8090 << 0.8910 << 0.9511 << 0.9877 << 1.0000); QTest::newRow("InOutSine") << int(QEasingCurve::InOutSine) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.02447 << 0.09549 << 0.2061 << 0.3455 << 0.5 << 0.6545 << 0.7939 << 0.9045 << 0.9755 << 1); + << (RealList() << 0.0000 << 0.0245 << 0.0955 << 0.2061 << 0.3455 << 0.5000 << 0.6545 << 0.7939 << 0.9045 << 0.9755 << 1.0000); QTest::newRow("OutInSine") << int(QEasingCurve::OutInSine) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.1545 << 0.2939 << 0.4045 << 0.4755 << 0.5 << 0.5245 << 0.5955 << 0.7061 << 0.8455 << 1); + << (RealList() << 0.0000 << 0.1545 << 0.2939 << 0.4045 << 0.4755 << 0.5000 << 0.5245 << 0.5955 << 0.7061 << 0.8455 << 1.0000); QTest::newRow("InExpo") << int(QEasingCurve::InExpo) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.0009531 << 0.002906 << 0.006812 << 0.01462 << 0.03025 << 0.0615 << 0.124 << 0.249 << 0.499 << 1); + << (RealList() << 0.0000 << 0.0010 << 0.0029 << 0.0068 << 0.0146 << 0.0303 << 0.0615 << 0.1240 << 0.2490 << 0.4990 << 1.0000); QTest::newRow("OutExpo") << int(QEasingCurve::OutExpo) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.5005 << 0.7507 << 0.8759 << 0.9384 << 0.9697 << 0.9854 << 0.9932 << 0.9971 << 0.999 << 1); + << (RealList() << 0.0000 << 0.5005 << 0.7507 << 0.8759 << 0.9384 << 0.9697 << 0.9854 << 0.9932 << 0.9971 << 0.9990 << 1.0000); QTest::newRow("InOutExpo") << int(QEasingCurve::InOutExpo) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.001453 << 0.007312 << 0.03075 << 0.1245 << 0.5002 << 0.8754 << 0.9692 << 0.9927 << 0.9985 << 1); + << (RealList() << 0.0000 << 0.0015 << 0.0073 << 0.0308 << 0.1245 << 0.5003 << 0.8754 << 0.9692 << 0.9927 << 0.9985 << 1.0000); QTest::newRow("OutInExpo") << int(QEasingCurve::OutInExpo) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.3754 << 0.4692 << 0.4927 << 0.4985 << 0.5 << 0.5015 << 0.5073 << 0.5308 << 0.6245 << 1); + << (RealList() << 0.0000 << 0.3754 << 0.4692 << 0.4927 << 0.4985 << 0.5000 << 0.5015 << 0.5073 << 0.5308 << 0.6245 << 1.0000); QTest::newRow("InCirc") << int(QEasingCurve::InCirc) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.005013 << 0.0202 << 0.04606 << 0.08348 << 0.134 << 0.2 << 0.2859 << 0.4 << 0.5641 << 1); + << (RealList() << 0.0000 << 0.0050 << 0.0202 << 0.0461 << 0.0835 << 0.1340 << 0.2000 << 0.2859 << 0.4000 << 0.5641 << 1.0000); QTest::newRow("OutCirc") << int(QEasingCurve::OutCirc) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.4359 << 0.6 << 0.7141 << 0.8 << 0.866 << 0.9165 << 0.9539 << 0.9798 << 0.995 << 1); + << (RealList() << 0.0000 << 0.4359 << 0.6000 << 0.7141 << 0.8000 << 0.8660 << 0.9165 << 0.9539 << 0.9798 << 0.9950 << 1.0000); QTest::newRow("InOutCirc") << int(QEasingCurve::InOutCirc) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.0101 << 0.04174 << 0.1 << 0.2 << 0.5 << 0.8 << 0.9 << 0.9583 << 0.9899 << 1); + << (RealList() << 0.0000 << 0.0101 << 0.0417 << 0.1000 << 0.2000 << 0.5000 << 0.8000 << 0.9000 << 0.9583 << 0.9899 << 1.0000); QTest::newRow("OutInCirc") << int(QEasingCurve::OutInCirc) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.3 << 0.4 << 0.4583 << 0.4899 << 0.5 << 0.5101 << 0.5417 << 0.6 << 0.7 << 1); + << (RealList() << 0.0000 << 0.3000 << 0.4000 << 0.4583 << 0.4899 << 0.5000 << 0.5101 << 0.5417 << 0.6000 << 0.7000 << 1.0000); QTest::newRow("InElastic") << int(QEasingCurve::InElastic) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.001953 << -0.001953 << -0.003906 << 0.01562 << -0.01562 << -0.03125 << 0.125 << -0.125 << -0.25 << 1); + << (RealList() << 0.0000 << 0.0020 << -0.0020 << -0.0039 << 0.0156 << -0.0156 << -0.0313 << 0.1250 << -0.1250 << -0.2500 << 1.0000); QTest::newRow("OutElastic") << int(QEasingCurve::OutElastic) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 1.25 << 1.125 << 0.875 << 1.031 << 1.016 << 0.9844 << 1.004 << 1.002 << 0.998 << 1); + << (RealList() << 0.0000 << 1.2500 << 1.1250 << 0.8750 << 1.0313 << 1.0156 << 0.9844 << 1.0039 << 1.0020 << 0.9980 << 1.0000); QTest::newRow("InOutElastic") << int(QEasingCurve::InOutElastic) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << -0.0009766 << 0.007812 << -0.01563 << -0.0625 << 0.5 << 1.062 << 1.016 << 0.9922 << 1.001 << 1); + << (RealList() << 0.0000 << -0.0010 << 0.0078 << -0.0156 << -0.0625 << 0.5000 << 1.0625 << 1.0156 << 0.9922 << 1.0010 << 1.0000); QTest::newRow("OutInElastic") << int(QEasingCurve::OutInElastic) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.375 << 0.5625 << 0.4922 << 0.498 << 0.5 << 0.4961 << 0.5078 << 0.5313 << 0.25 << 1); + << (RealList() << 0.0000 << 0.3750 << 0.5625 << 0.4922 << 0.4980 << 0.5000 << 0.4961 << 0.5078 << 0.5313 << 0.2500 << 1.0000); QTest::newRow("InBack") << int(QEasingCurve::InBack) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << -0.01431 << -0.04645 << -0.0802 << -0.09935 << -0.0877 << -0.02903 << 0.09287 << 0.2942 << 0.5912 << 1); + << (RealList() << 0.0000 << -0.0143 << -0.0465 << -0.0802 << -0.0994 << -0.0877 << -0.0290 << 0.0929 << 0.2942 << 0.5912 << 1.0000); QTest::newRow("OutBack") << int(QEasingCurve::OutBack) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.4088 << 0.7058 << 0.9071 << 1.029 << 1.088 << 1.099 << 1.08 << 1.046 << 1.014 << 1); + << (RealList() << 0.0000 << 0.4088 << 0.7058 << 0.9071 << 1.0290 << 1.0877 << 1.0994 << 1.0802 << 1.0465 << 1.0143 << 1.0000); QTest::newRow("InOutBack") << int(QEasingCurve::InOutBack) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << -0.03752 << -0.09256 << -0.07883 << 0.08993 << 0.5 << 0.9101 << 1.079 << 1.093 << 1.038 << 1); + << (RealList() << 0.0000 << -0.0375 << -0.0926 << -0.0788 << 0.0899 << 0.5000 << 0.9101 << 1.0788 << 1.0926 << 1.0375 << 1.0000); QTest::newRow("OutInBack") << int(QEasingCurve::OutInBack) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.3529 << 0.5145 << 0.5497 << 0.5232 << 0.5 << 0.4768 << 0.4503 << 0.4855 << 0.6471 << 1); + << (RealList() << 0.0000 << 0.3529 << 0.5145 << 0.5497 << 0.5232 << 0.5000 << 0.4768 << 0.4503 << 0.4855 << 0.6471 << 1.0000); QTest::newRow("InBounce") << int(QEasingCurve::InBounce) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.01188 << 0.06 << 0.06937 << 0.2275 << 0.2344 << 0.09 << 0.3194 << 0.6975 << 0.9244 << 1); + << (RealList() << 0.0000 << 0.0119 << 0.0600 << 0.0694 << 0.2275 << 0.2344 << 0.0900 << 0.3194 << 0.6975 << 0.9244 << 1.0000); QTest::newRow("OutBounce") << int(QEasingCurve::OutBounce) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.07563 << 0.3025 << 0.6806 << 0.91 << 0.7656 << 0.7725 << 0.9306 << 0.94 << 0.9881 << 1); + << (RealList() << 0.0000 << 0.0756 << 0.3025 << 0.6806 << 0.9100 << 0.7656 << 0.7725 << 0.9306 << 0.9400 << 0.9881 << 1.0000); QTest::newRow("InOutBounce") << int(QEasingCurve::InOutBounce) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.03 << 0.1138 << 0.045 << 0.3488 << 0.5 << 0.6512 << 0.955 << 0.8862 << 0.97 << 1); + << (RealList() << 0.0000 << 0.0300 << 0.1138 << 0.0450 << 0.3488 << 0.5000 << 0.6512 << 0.9550 << 0.8863 << 0.9700 << 1.0000); QTest::newRow("OutInBounce") << int(QEasingCurve::OutInBounce) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.1513 << 0.41 << 0.2725 << 0.44 << 0.5 << 0.56 << 0.7275 << 0.59 << 0.8488 << 1); + << (RealList() << 0.0000 << 0.1513 << 0.4100 << 0.2725 << 0.4400 << 0.5000 << 0.5600 << 0.7275 << 0.5900 << 0.8488 << 1.0000); QTest::newRow("InCurve") << int(QEasingCurve::InCurve) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.02447 << 0.1059 << 0.2343 << 0.3727 << 0.5 << 0.6055 << 0.7 << 0.8 << 0.9 << 1); + << (RealList() << 0.0000 << 0.0245 << 0.1059 << 0.2343 << 0.3727 << 0.5000 << 0.6055 << 0.7000 << 0.8000 << 0.9000 << 1.0000); QTest::newRow("OutCurve") << int(QEasingCurve::OutCurve) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.1 << 0.2 << 0.3 << 0.3945 << 0.5 << 0.6273 << 0.7657 << 0.8941 << 0.9755 << 1); + << (RealList() << 0.0000 << 0.1000 << 0.2000 << 0.3000 << 0.3945 << 0.5000 << 0.6273 << 0.7657 << 0.8941 << 0.9755 << 1.0000); QTest::newRow("SineCurve") << int(QEasingCurve::SineCurve) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0 << 0.09549 << 0.3455 << 0.6545 << 0.9045 << 1 << 0.9045 << 0.6545 << 0.3455 << 0.09549 << 0); + << (RealList() << 0.0000 << 0.0955 << 0.3455 << 0.6545 << 0.9045 << 1.0000 << 0.9045 << 0.6545 << 0.3455 << 0.0955 << 0.0000); QTest::newRow("CosineCurve") << int(QEasingCurve::CosineCurve) << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100) - << (RealList() << 0.5 << 0.7939 << 0.9755 << 0.9755 << 0.7939 << 0.5 << 0.2061 << 0.02447 << 0.02447 << 0.2061 << 0.5); + << (RealList() << 0.5000 << 0.7939 << 0.9755 << 0.9755 << 0.7939 << 0.5000 << 0.2061 << 0.0245 << 0.0245 << 0.2061 << 0.5000); } +/* + "fixedpoint" number that is scaled up by 10000. + This is to work around two bugs (precision and rounding error) in QString::setNum(). + It does not trim off trailing zeros. This is good, just to emphasize the precision. +*/ +QString fixedToString(int value) +{ + QString str; + if (value < 0) { + str+= QLatin1Char('-'); + value = -value; + } + + QString digitArg(QLatin1String("%1.")); + for (int i = 10000; i >= 1; i/=10) { + int digit = value/i; + value -= digit*i; + str.append(digitArg.arg(digit)); + digitArg = QLatin1String("%1"); + } + return str; +} void tst_QEasingCurve::valueForProgress() { @@ -390,7 +412,7 @@ void tst_QEasingCurve::valueForProgress() for (int t = 0; t <= 100; t+= 10) { qreal ease = curve.valueForProgress(t/qreal(100)); strInputs += QString::fromAscii(" << %1").arg(t); - strOutputs += " << " + QString().setNum(ease, 'g', 4); + strOutputs += " << " + fixedToString(qRound(ease*10000)); } QString str = QString::fromAscii(" QTest::newRow(\"%1\") << int(QEasingCurve::%2)\n" " << (IntList() %3)\n" @@ -409,26 +431,13 @@ void tst_QEasingCurve::valueForProgress() QFETCH(RealList, expected); QEasingCurve curve((QEasingCurve::Type)type); + // in theory the baseline should't have an error of more than 0.00005 due to how its rounded, + // but due to FP imprecision, we have to adjust the error a bit more. + const qreal errorBound = 0.00006; for (int i = 0; i < at.count(); ++i) { - qreal ease = curve.valueForProgress(at.at(i)/qreal(100)); - // converting ease to 4 precision qreal to match the generated samples - qreal easeConv = qreal(QString().setNum(ease, 'g', 4).toDouble()); - qreal ex = expected.at(i); - - // the least significant digit it is still subject to rounding errors - qreal error = easeConv - ex; - qreal errorbound = 0.00001; -#if defined( Q_OS_WINCE ) || defined( Q_OS_SYMBIAN ) - // exception values for WINCE(this test should be rewritten, as it only freezes the status quo of QEasingCurve - // The failing (2) values are explicitly excepted here: - // The source values for the comparison table should remain untruncated double and the - // error bound checking function dynamic. Also the source values should come from a "trusted" source and not - // from QEasingCurve itself. - if ((type == int(QEasingCurve::InOutBounce) && (i == 8 || i == 6) ) || (type == int(QEasingCurve::OutExpo) && i == 2)) - errorbound = 0.0002; -#endif - // accept the potential rounding error in the least significant digit - QVERIFY(error <= errorbound ); + const qreal ex = expected.at(i); + const qreal error = qAbs(ex - curve.valueForProgress(at.at(i)/qreal(100))); + QVERIFY(error <= errorBound); } #endif } diff --git a/tests/auto/qfileinfo/tst_qfileinfo.cpp b/tests/auto/qfileinfo/tst_qfileinfo.cpp index fdc629a..42e7250 100644 --- a/tests/auto/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/qfileinfo/tst_qfileinfo.cpp @@ -828,6 +828,17 @@ void tst_QFileInfo::compare_data() QTest::addColumn<QString>("file2"); QTest::addColumn<bool>("same"); +#if defined(Q_OS_MAC) + // Since 10.6 we use realpath() in qfsfileengine, and it properly handles + // file system case sensitivity. However here in the autotest we don't + // check if the file system is case sensitive, so to make it pass in the + // default OS X installation we assume we are running on a case insensitive + // file system if on 10.6 and on a case sensitive file system if on 10.5 + bool caseSensitiveOnMac = true; + if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6) + caseSensitiveOnMac = false; +#endif + QTest::newRow("data0") << QString::fromLatin1(SRCDIR "tst_qfileinfo.cpp") << QString::fromLatin1(SRCDIR "tst_qfileinfo.cpp") @@ -845,6 +856,8 @@ void tst_QFileInfo::compare_data() << QString::fromLatin1(SRCDIR "tst_qfileinfo.cpp") #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) << true; +#elif defined(Q_OS_MAC) + << !caseSensitiveOnMac; #else << false; #endif @@ -856,7 +869,7 @@ void tst_QFileInfo::compare() QFETCH(QString, file2); QFETCH(bool, same); QFileInfo fi1(file1), fi2(file2); - QCOMPARE(same, fi1 == fi2); + QCOMPARE(fi1 == fi2, same); } void tst_QFileInfo::consistent_data() diff --git a/tests/auto/qgl/tst_qgl.cpp b/tests/auto/qgl/tst_qgl.cpp index cf4616e..972a0ae 100644 --- a/tests/auto/qgl/tst_qgl.cpp +++ b/tests/auto/qgl/tst_qgl.cpp @@ -425,6 +425,26 @@ void tst_QGL::getSetCheck() obj1.setPlane(TEST_INT_MAX); QCOMPARE(TEST_INT_MAX, obj1.plane()); + // int QGLFormat::major/minorVersion() + // void QGLFormat::setVersion(int, int) + QCOMPARE(obj1.majorVersion(), 1); + QCOMPARE(obj1.minorVersion(), 0); + obj1.setVersion(3, 2); + QCOMPARE(obj1.majorVersion(), 3); + QCOMPARE(obj1.minorVersion(), 2); + QTest::ignoreMessage(QtWarningMsg, "QGLFormat::setVersion: Cannot set zero or negative version number 0.1"); + obj1.setVersion(0, 1); + QCOMPARE(obj1.majorVersion(), 3); + QCOMPARE(obj1.minorVersion(), 2); + QTest::ignoreMessage(QtWarningMsg, "QGLFormat::setVersion: Cannot set zero or negative version number 3.-1"); + obj1.setVersion(3, -1); + QCOMPARE(obj1.majorVersion(), 3); + QCOMPARE(obj1.minorVersion(), 2); + obj1.setVersion(TEST_INT_MAX, TEST_INT_MAX - 1); + QCOMPARE(obj1.majorVersion(), TEST_INT_MAX); + QCOMPARE(obj1.minorVersion(), TEST_INT_MAX - 1); + + // operator== and operator!= for QGLFormat QGLFormat format1; QGLFormat format2; @@ -508,6 +528,27 @@ void tst_QGL::getSetCheck() QVERIFY(format1 == format2); QVERIFY(!(format1 != format2)); + format1.setVersion(3, 2); + QVERIFY(!(format1 == format2)); + QVERIFY(format1 != format2); + format2.setVersion(3, 2); + QVERIFY(format1 == format2); + QVERIFY(!(format1 != format2)); + + format1.setProfile(QGLFormat::CoreProfile); + QVERIFY(!(format1 == format2)); + QVERIFY(format1 != format2); + format2.setProfile(QGLFormat::CoreProfile); + QVERIFY(format1 == format2); + QVERIFY(!(format1 != format2)); + + format1.setOption(QGL::NoDeprecatedFunctions); + QVERIFY(!(format1 == format2)); + QVERIFY(format1 != format2); + format2.setOption(QGL::NoDeprecatedFunctions); + QVERIFY(format1 == format2); + QVERIFY(!(format1 != format2)); + // Copy constructor and assignment for QGLFormat. QGLFormat format3(format1); QGLFormat format4; @@ -698,8 +739,6 @@ void tst_QGL::openGLVersionCheck() #if defined(QT_OPENGL_ES_1) QVERIFY(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_ES_Common_Version_1_0); -#elif defined(QT_OPENGL_ES_1_CL) - QVERIFY(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_ES_CommonLite_Version_1_0); #elif defined(QT_OPENGL_ES_2) QVERIFY(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_ES_Version_2_0); #else diff --git a/tests/auto/qglbuffer/qglbuffer.pro b/tests/auto/qglbuffer/qglbuffer.pro new file mode 100644 index 0000000..07d05bb --- /dev/null +++ b/tests/auto/qglbuffer/qglbuffer.pro @@ -0,0 +1,9 @@ +############################################################ +# Project file for autotest for file qglbuffer.h +############################################################ + +load(qttest_p4) +requires(contains(QT_CONFIG,opengl)) +QT += opengl + +SOURCES += tst_qglbuffer.cpp diff --git a/tests/auto/qglbuffer/tst_qglbuffer.cpp b/tests/auto/qglbuffer/tst_qglbuffer.cpp new file mode 100644 index 0000000..b7d5821 --- /dev/null +++ b/tests/auto/qglbuffer/tst_qglbuffer.cpp @@ -0,0 +1,261 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtOpenGL module 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 <QtTest/QtTest> +#include <QtOpenGL/qgl.h> +#include <QtOpenGL/qglbuffer.h> + +class tst_QGLBuffer : public QObject +{ + Q_OBJECT +public: + tst_QGLBuffer() {} + ~tst_QGLBuffer() {} + +private slots: + void vertexBuffer_data(); + void vertexBuffer(); + void indexBuffer_data(); + void indexBuffer(); + void bufferSharing(); + +private: + void testBuffer(QGLBuffer::Type type); +}; + +void tst_QGLBuffer::vertexBuffer_data() +{ + QTest::addColumn<int>("usagePattern"); + + QTest::newRow("StreamDraw") << int(QGLBuffer::StreamDraw); + QTest::newRow("StaticDraw") << int(QGLBuffer::StaticDraw); + QTest::newRow("DynamicDraw") << int(QGLBuffer::DynamicDraw); +} + +void tst_QGLBuffer::vertexBuffer() +{ + testBuffer(QGLBuffer::VertexBuffer); +} + +void tst_QGLBuffer::indexBuffer_data() +{ + vertexBuffer_data(); +} + +void tst_QGLBuffer::indexBuffer() +{ + testBuffer(QGLBuffer::IndexBuffer); +} + +void tst_QGLBuffer::testBuffer(QGLBuffer::Type type) +{ + QFETCH(int, usagePattern); + + QGLWidget w; + w.makeCurrent(); + + // Create the local object, but not the buffer in the server. + QGLBuffer buffer(type); + QVERIFY(buffer.usagePattern() == QGLBuffer::StaticDraw); + buffer.setUsagePattern(QGLBuffer::UsagePattern(usagePattern)); + + // Check the initial state. + QVERIFY(buffer.type() == type); + QVERIFY(!buffer.isCreated()); + QVERIFY(buffer.bufferId() == 0); + QVERIFY(buffer.usagePattern() == QGLBuffer::UsagePattern(usagePattern)); + QCOMPARE(buffer.size(), -1); + + // Should not be able to bind it yet because it isn't created. + QVERIFY(!buffer.bind()); + + // Create the buffer - if this fails, then assume that the + // GL implementation does not support buffers at all. + if (!buffer.create()) + QSKIP("Buffers are not supported on this platform", SkipAll); + + // Should now have a buffer id. + QVERIFY(buffer.bufferId() != 0); + + // Bind the buffer and upload some data. + QVERIFY(buffer.bind()); + static GLfloat const data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + buffer.allocate(data, sizeof(data)); + + // Check the buffer size. + QCOMPARE(buffer.size(), int(sizeof(data))); + + // Map the buffer and read back its contents. + bool haveMap = false; + GLfloat *mapped = reinterpret_cast<GLfloat *> + (buffer.map(QGLBuffer::ReadOnly)); + if (mapped) { + for (int index = 0; index < 9; ++index) + QCOMPARE(mapped[index], data[index]); + buffer.unmap(); + haveMap = true; + } else { + qWarning("QGLBuffer::map() is not supported on this platform"); + } + + // Read back the buffer contents using read(). + bool haveRead = false; + GLfloat readdata[9]; + if (buffer.read(0, readdata, sizeof(readdata))) { + for (int index = 0; index < 9; ++index) + QCOMPARE(readdata[index], data[index]); + haveRead = true; + } else { + qWarning("QGLBuffer::read() is not supported on this platform"); + } + + // Write some different data to a specific location and check it. + static GLfloat const diffdata[] = {11, 12, 13}; + buffer.write(sizeof(GLfloat) * 3, diffdata, sizeof(diffdata)); + if (haveMap) { + mapped = reinterpret_cast<GLfloat *>(buffer.map(QGLBuffer::ReadOnly)); + QVERIFY(mapped != 0); + for (int index = 0; index < 9; ++index) { + if (index >= 3 && index <= 5) + QCOMPARE(mapped[index], diffdata[index - 3]); + else + QCOMPARE(mapped[index], data[index]); + } + buffer.unmap(); + } + if (haveRead) { + QVERIFY(buffer.read(0, readdata, sizeof(readdata))); + for (int index = 0; index < 9; ++index) { + if (index >= 3 && index <= 5) + QCOMPARE(readdata[index], diffdata[index - 3]); + else + QCOMPARE(readdata[index], data[index]); + } + } + + // Write to the buffer using the return value from map. + if (haveMap) { + mapped = reinterpret_cast<GLfloat *>(buffer.map(QGLBuffer::WriteOnly)); + QVERIFY(mapped != 0); + mapped[6] = 14; + buffer.unmap(); + + mapped = reinterpret_cast<GLfloat *>(buffer.map(QGLBuffer::ReadOnly)); + QVERIFY(mapped != 0); + static GLfloat const diff2data[] = {11, 12, 13, 14}; + for (int index = 0; index < 9; ++index) { + if (index >= 3 && index <= 6) + QCOMPARE(mapped[index], diff2data[index - 3]); + else + QCOMPARE(mapped[index], data[index]); + } + buffer.unmap(); + } + + // Resize the buffer. + buffer.allocate(sizeof(GLfloat) * 20); + QCOMPARE(buffer.size(), int(sizeof(GLfloat) * 20)); + buffer.allocate(0, sizeof(GLfloat) * 32); + QCOMPARE(buffer.size(), int(sizeof(GLfloat) * 32)); + + // Release the buffer. + buffer.release(); +} + +void tst_QGLBuffer::bufferSharing() +{ + QGLWidget *w1 = new QGLWidget(); + w1->makeCurrent(); + + QGLWidget *w2 = new QGLWidget(0, w1); + if (!w2->isSharing()) { + delete w2; + delete w1; + QSKIP("Context sharing is not supported on this platform", SkipSingle); + } + + // Bind the buffer in the first context and write some data to it. + QGLBuffer buffer(QGLBuffer::VertexBuffer); + if (!buffer.create()) + QSKIP("Buffers are not supported on this platform", SkipSingle); + QVERIFY(buffer.isCreated()); + QVERIFY(buffer.bind()); + static GLfloat const data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + buffer.allocate(data, sizeof(data)); + QCOMPARE(buffer.size(), int(sizeof(data))); + buffer.release(); + + // Bind the buffer in the second context and read back the data. + w2->makeCurrent(); + QVERIFY(buffer.bind()); + QCOMPARE(buffer.size(), int(sizeof(data))); + GLfloat readdata[9]; + if (buffer.read(0, readdata, sizeof(readdata))) { + for (int index = 0; index < 9; ++index) + QCOMPARE(readdata[index], data[index]); + } + buffer.release(); + + // Delete the first context. + delete w1; + + // Make the second context current again because deleting the first + // one will call doneCurrent() even though it wasn't current! + w2->makeCurrent(); + + // The buffer should still be valid in the second context. + QVERIFY(buffer.bufferId() != 0); + QVERIFY(buffer.isCreated()); + QVERIFY(buffer.bind()); + QCOMPARE(buffer.size(), int(sizeof(data))); + buffer.release(); + + // Delete the second context. + delete w2; + + // The buffer should now be invalid. + QVERIFY(buffer.bufferId() == 0); + QVERIFY(!buffer.isCreated()); +} + +QTEST_MAIN(tst_QGLBuffer) + +#include "tst_qglbuffer.moc" diff --git a/tests/auto/qgraphicsitem/nestedClipping_reference.png b/tests/auto/qgraphicsitem/nestedClipping_reference.png Binary files differdeleted file mode 100644 index 3bd4fe7..0000000 --- a/tests/auto/qgraphicsitem/nestedClipping_reference.png +++ /dev/null diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp index d3132fe..79ce68e 100644 --- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp @@ -163,6 +163,7 @@ private slots: void addChildInpolishEvent(); void polishEvent(); void polishEvent2(); + void autoFillBackground(); void initialShow(); // Task fixes @@ -2857,6 +2858,32 @@ void tst_QGraphicsWidget::polishEvent2() QVERIFY(widget->events.contains(QEvent::Polish)); } +void tst_QGraphicsWidget::autoFillBackground() +{ + QGraphicsWidget *widget = new QGraphicsWidget; + QCOMPARE(widget->autoFillBackground(), false); + widget->setAutoFillBackground(true); + QCOMPARE(widget->autoFillBackground(), true); + + const QColor color(Qt::red); + const QRect rect(0, 0, 1, 1); + + QGraphicsScene scene; + scene.addItem(widget); + widget->setGeometry(rect); + + QPalette palette = widget->palette(); + palette.setColor(QPalette::Window, color); + widget->setPalette(palette); + + QImage image(rect.size(), QImage::Format_RGB32); + QPainter painter; + painter.begin(&image); + scene.render(&painter, rect, rect); + painter.end(); + QCOMPARE(image.pixel(0, 0), color.rgb()); +} + void tst_QGraphicsWidget::initialShow() { class MyGraphicsWidget : public QGraphicsWidget diff --git a/tests/auto/qhttp/tst_qhttp.cpp b/tests/auto/qhttp/tst_qhttp.cpp index 59bfb15..320225d 100644 --- a/tests/auto/qhttp/tst_qhttp.cpp +++ b/tests/auto/qhttp/tst_qhttp.cpp @@ -114,9 +114,6 @@ private slots: void abortInReadyRead(); void abortInResponseHeaderReceived(); void nestedEventLoop(); - - - // manual tests void connectionClose(); protected slots: @@ -175,6 +172,23 @@ private: bool proxyAuthCalled; }; +class ClosingServer: public QTcpServer +{ + Q_OBJECT +public: + ClosingServer() + { + connect(this, SIGNAL(newConnection()), SLOT(handleConnection())); + listen(); + } + +public slots: + void handleConnection() + { + delete nextPendingConnection(); + } +}; + //#define DUMP_SIGNALS const int bytesTotal_init = -10; @@ -1491,20 +1505,14 @@ void tst_QHttp::abortInResponseHeaderReceived() void tst_QHttp::connectionClose() { - // This test tries to connect to a client's server, so it is disabled. - // Every now and then, someone please run it to make sure it's not broken. - // Note: the servers might change too... - // // This was added in response to bug 176822 -#ifndef Q_OS_SYMBIAN - QSKIP("This test is manual - read comments in the source code", SkipAll); -#endif QFETCH_GLOBAL(bool, setProxy); if (setProxy) return; QHttp http; - http.setHost("www.fon.com", QHttp::ConnectionModeHttps); + ClosingServer server; + http.setHost("localhost", QHttp::ConnectionModeHttps, server.serverPort()); http.get("/login/gateway/processLogin"); // another possibility: diff --git a/tests/auto/qintvalidator/tst_qintvalidator.cpp b/tests/auto/qintvalidator/tst_qintvalidator.cpp index 72e7f7a..46ad0dd 100644 --- a/tests/auto/qintvalidator/tst_qintvalidator.cpp +++ b/tests/auto/qintvalidator/tst_qintvalidator.cpp @@ -50,6 +50,7 @@ private slots: void validate_data(); void validate(); void validateArabic(); + void validateFrench(); }; Q_DECLARE_METATYPE(QValidator::State); @@ -182,6 +183,30 @@ void tst_QIntValidator::validateArabic() } + +void tst_QIntValidator::validateFrench() +{ + QIntValidator validator(-2000, 2000, 0); + validator.setLocale(QLocale::French); + int i; + + QString s = QLatin1String("1 "); + QCOMPARE(validator.validate(s, i), QValidator::Acceptable); + validator.fixup(s); + QCOMPARE(s, s); + + s = QLatin1String("1 000"); + QCOMPARE(validator.validate(s, i), QValidator::Acceptable); + validator.fixup(s); + QCOMPARE(s, s); + + + s = QLatin1String("1 0 00"); + QCOMPARE(validator.validate(s, i), QValidator::Intermediate); + validator.fixup(s); + QCOMPARE(s, validator.locale().toString(1000)); +} + void tst_QIntValidator::validate() { QFETCH(int, minimum); @@ -190,6 +215,7 @@ void tst_QIntValidator::validate() QFETCH(QValidator::State, state); QIntValidator iv(minimum, maximum, 0); + iv.setLocale(QLocale::C); int dummy; QCOMPARE((int)iv.validate(value, dummy), (int)state); } diff --git a/tests/auto/qkeysequence/tst_qkeysequence.cpp b/tests/auto/qkeysequence/tst_qkeysequence.cpp index 3e3f202..b1ef223 100644 --- a/tests/auto/qkeysequence/tst_qkeysequence.cpp +++ b/tests/auto/qkeysequence/tst_qkeysequence.cpp @@ -119,6 +119,7 @@ private slots: void symetricConstructors_data(); void symetricConstructors(); void checkMultipleNames(); + void checkMultipleCodes(); void mnemonic_data(); void mnemonic(); void toString_data(); @@ -265,6 +266,18 @@ void tst_QKeySequence::checkMultipleNames() QVERIFY( oldK == newK ); } +//TODO: could test third constructor, or test fromString on all constructor-data +void tst_QKeySequence::checkMultipleCodes() +{ + QKeySequence seq1("Alt+d, l"); + QKeySequence seq2 = QKeySequence::fromString("Alt+d, l"); + QVERIFY( seq1 == seq2 ); + + QKeySequence seq3("Alt+d,l"); + QKeySequence seq4 = QKeySequence::fromString("Alt+d,l"); + QVERIFY( seq3 == seq4 ); +} + /* * We must ensure that the keyBindings data is allways sorted * so that we can safely perform binary searches. diff --git a/tests/auto/qlabel/tst_qlabel.cpp b/tests/auto/qlabel/tst_qlabel.cpp index c3af495..7099917 100644 --- a/tests/auto/qlabel/tst_qlabel.cpp +++ b/tests/auto/qlabel/tst_qlabel.cpp @@ -119,6 +119,7 @@ private slots: void mnemonic_data(); void mnemonic(); + void selection(); private: QLabel *testWidget; @@ -559,6 +560,27 @@ void tst_QLabel::mnemonic() QCOMPARE(d->shortcutCursor.selectedText(), expectedShortcutCursor); } +void tst_QLabel::selection() +{ + QLabel label; + label.setText("Hello world"); + + label.setTextInteractionFlags(Qt::TextSelectableByMouse); + + QVERIFY(!label.hasSelectedText()); + QCOMPARE(label.selectedText(), QString()); + QCOMPARE(label.selectionStart(), -1); + + label.setSelection(0, 4); + QVERIFY(label.hasSelectedText()); + QCOMPARE(label.selectedText(), QString::fromLatin1("Hell")); + QCOMPARE(label.selectionStart(), 0); + + label.setSelection(6, 5); + QVERIFY(label.hasSelectedText()); + QCOMPARE(label.selectedText(), QString::fromLatin1("world")); + QCOMPARE(label.selectionStart(), 6); +} QTEST_MAIN(tst_QLabel) #include "tst_qlabel.moc" diff --git a/tests/auto/qmetaobject/tst_qmetaobject.cpp b/tests/auto/qmetaobject/tst_qmetaobject.cpp index 286e793..15b6204 100644 --- a/tests/auto/qmetaobject/tst_qmetaobject.cpp +++ b/tests/auto/qmetaobject/tst_qmetaobject.cpp @@ -664,7 +664,7 @@ void tst_QMetaObject::normalizedSignature_data() QTest::newRow("const rettype") << "const QString *foo()" << "const QString*foo()"; QTest::newRow("const ref") << "const QString &foo()" << "const QString&foo()"; QTest::newRow("reference") << "QString &foo()" << "QString&foo()"; - QTest::newRow("const2") << "void foo(QString const *)" << "void foo(const QString*)"; + QTest::newRow("const1") << "void foo(QString const *)" << "void foo(const QString*)"; QTest::newRow("const2") << "void foo(QString * const)" << "void foo(QString*const)"; QTest::newRow("const3") << "void foo(QString const &)" << "void foo(QString)"; QTest::newRow("const4") << "void foo(const int)" << "void foo(int)"; @@ -672,7 +672,7 @@ void tst_QMetaObject::normalizedSignature_data() << "void foo(int,int,int,int)"; QTest::newRow("const6") << "void foo(QList<const int>)" << "void foo(QList<const int>)"; QTest::newRow("const7") << "void foo(QList<const int*>)" << "void foo(QList<const int*>)"; - QTest::newRow("const7") << "void foo(QList<int const*>)" << "void foo(QList<const int*>)"; + QTest::newRow("const8") << "void foo(QList<int const*>)" << "void foo(QList<const int*>)"; } void tst_QMetaObject::normalizedSignature() diff --git a/tests/auto/qobject/moc_oldnormalizeobject.cpp b/tests/auto/qobject/moc_oldnormalizeobject.cpp new file mode 100644 index 0000000..bde9c39 --- /dev/null +++ b/tests/auto/qobject/moc_oldnormalizeobject.cpp @@ -0,0 +1,113 @@ +/**************************************************************************** +** Meta object code from reading C++ file 'oldnormalizeobject.h' +** +** Created: Wed Nov 18 11:43:05 2009 +** by: The Qt Meta Object Compiler version 62 (Qt 4.6.0) +** +*****************************************************************************/ + +// Yhis file was generated from moc version 4.6 to test binary compatibility +// It should *not* be generated by the current moc + +#include "oldnormalizeobject.h" + +QT_BEGIN_MOC_NAMESPACE +static const uint qt_meta_data_OldNormalizeObject[] = { + + // content: + 4, // revision + 0, // classname + 0, 0, // classinfo + 6, 14, // methods + 0, 0, // properties + 0, 0, // enums/sets + 0, 0, // constructors + 0, // flags + 3, // signalCount + + // signals: signature, parameters, type, tag, flags + 24, 20, 19, 19, 0x05, + 57, 20, 19, 19, 0x05, + 100, 20, 19, 19, 0x05, + + // slots: signature, parameters, type, tag, flags + 149, 20, 19, 19, 0x0a, + 180, 20, 19, 19, 0x0a, + 221, 20, 19, 19, 0x0a, + + 0 // eod +}; + +static const char qt_meta_stringdata_OldNormalizeObject[] = { + "OldNormalizeObject\0\0ref\0" + "typeRefSignal(Template<Class&>&)\0" + "constTypeRefSignal(Template<const Class&>)\0" + "typeConstRefSignal(Template<const Class&>const&)\0" + "typeRefSlot(Template<Class&>&)\0" + "constTypeRefSlot(Template<const Class&>)\0" + "typeConstRefSlot(Template<const Class&>const&)\0" +}; + +const QMetaObject OldNormalizeObject::staticMetaObject = { + { &QObject::staticMetaObject, qt_meta_stringdata_OldNormalizeObject, + qt_meta_data_OldNormalizeObject, 0 } +}; + +#ifdef Q_NO_DATA_RELOCATION +const QMetaObject &OldNormalizeObject::getStaticMetaObject() { return staticMetaObject; } +#endif //Q_NO_DATA_RELOCATION + +const QMetaObject *OldNormalizeObject::metaObject() const +{ + return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; +} + +void *OldNormalizeObject::qt_metacast(const char *_clname) +{ + if (!_clname) return 0; + if (!strcmp(_clname, qt_meta_stringdata_OldNormalizeObject)) + return static_cast<void*>(const_cast< OldNormalizeObject*>(this)); + return QObject::qt_metacast(_clname); +} + +int OldNormalizeObject::qt_metacall(QMetaObject::Call _c, int _id, void **_a) +{ + _id = QObject::qt_metacall(_c, _id, _a); + if (_id < 0) + return _id; + if (_c == QMetaObject::InvokeMetaMethod) { + switch (_id) { + case 0: typeRefSignal((*reinterpret_cast< Template<Class&>(*)>(_a[1]))); break; + case 1: constTypeRefSignal((*reinterpret_cast< const Template<const Class&>(*)>(_a[1]))); break; + case 2: typeConstRefSignal((*reinterpret_cast< Template<const Class&>const(*)>(_a[1]))); break; + case 3: typeRefSlot((*reinterpret_cast< Template<Class&>(*)>(_a[1]))); break; + case 4: constTypeRefSlot((*reinterpret_cast< const Template<const Class&>(*)>(_a[1]))); break; + case 5: typeConstRefSlot((*reinterpret_cast< Template<const Class&>const(*)>(_a[1]))); break; + default: ; + } + _id -= 6; + } + return _id; +} + +// SIGNAL 0 +void OldNormalizeObject::typeRefSignal(Template<Class&> & _t1) +{ + void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) }; + QMetaObject::activate(this, &staticMetaObject, 0, _a); +} + +// SIGNAL 1 +void OldNormalizeObject::constTypeRefSignal(const Template<const Class&> & _t1) +{ + void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) }; + QMetaObject::activate(this, &staticMetaObject, 1, _a); +} + +// SIGNAL 2 +void OldNormalizeObject::typeConstRefSignal(Template<Class const&> const & _t1) +{ + void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) }; + QMetaObject::activate(this, &staticMetaObject, 2, _a); +} +QT_END_MOC_NAMESPACE diff --git a/tests/auto/qobject/oldnormalizeobject.h b/tests/auto/qobject/oldnormalizeobject.h new file mode 100644 index 0000000..3adf04d --- /dev/null +++ b/tests/auto/qobject/oldnormalizeobject.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtTest module 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$ +** +****************************************************************************/ + +#ifndef OLDNORMALIZEOBJECT_H +#define OLDNORMALIZEOBJECT_H + +#include <QObject> + +struct Struct; +class Class; +template <typename T> class Template; + +// An object with old moc output that incorrectly normalizes 'T<C> const &' in the function +// signatures +class OldNormalizeObject : public QObject +{ + /* tmake ignore Q_OBJECT */ + Q_OBJECT + +signals: + void typeRefSignal(Template<Class &> &ref); + void constTypeRefSignal(const Template<const Class &> &ref); + void typeConstRefSignal(Template<Class const &> const &ref); + +public slots: + void typeRefSlot(Template<Class &> &) {} + void constTypeRefSlot(const Template<const Class &> &) {} + void typeConstRefSlot(Template<Class const &> const &) {} +}; + +#endif // OLDNORMALIZEOBJECT_H diff --git a/tests/auto/qobject/tst_qobject.cpp b/tests/auto/qobject/tst_qobject.cpp index 4fa6aaa..3896d70 100644 --- a/tests/auto/qobject/tst_qobject.cpp +++ b/tests/auto/qobject/tst_qobject.cpp @@ -2024,6 +2024,7 @@ enum Enum { }; struct Struct { }; class Class { }; +template <typename T> class Template { }; class NormalizeObject : public QObject { @@ -2061,6 +2062,12 @@ signals: void unsignedshortSignal(unsigned short); void unsignedcharSignal(unsigned char); + void typeRefSignal(Template<Class &> &ref); + void constTypeRefSignal(const Template<Class const &> &ref); + void typeConstRefSignal(Template<Class const &> const &ref); + + void typePointerConstRefSignal(Class * const &); + public slots: void uintPointerSlot(uint *) { } void ulongPointerSlot(ulong *) { } @@ -2092,8 +2099,15 @@ public slots: void unsignedshortSlot(unsigned short) {}; void unsignedcharSlot(unsigned char) {}; + void typeRefSlot(Template<Class &> &) {} + void constTypeRefSlot(const Template<const Class &> &) {} + void typeConstRefSlot(Template<Class const &> const &) {} + + void typePointerConstRefSlot(Class * const &) {} }; +#include "oldnormalizeobject.h" + void tst_QObject::normalize() { NormalizeObject object; @@ -2333,7 +2347,165 @@ void tst_QObject::normalize() SIGNAL(unsignedcharSignal(unsigned char)), SLOT(unsignedcharSlot(unsigned char)))); + // connect when original template signature and mixed usage of 'T<C const &> const &', + // 'const T<const C &> &', and 'T<const C &>' + + QVERIFY(object.connect(&object, + SIGNAL(typeRefSignal(Template<Class &> &)), + SLOT(typeRefSlot(Template<Class &> &)))); + + QVERIFY(object.connect(&object, + SIGNAL(constTypeRefSignal(const Template<const Class &> &)), + SLOT(constTypeRefSlot(const Template<const Class &> &)))); + QVERIFY(object.connect(&object, + SIGNAL(constTypeRefSignal(const Template<const Class &> &)), + SLOT(constTypeRefSlot(const Template<Class const &> &)))); + QVERIFY(object.connect(&object, + SIGNAL(constTypeRefSignal(const Template<const Class &> &)), + SLOT(constTypeRefSlot(Template<Class const &> const &)))); + QVERIFY(object.connect(&object, + SIGNAL(constTypeRefSignal(Template<const Class &> const &)), + SLOT(constTypeRefSlot(Template<Class const &> const &)))); + QVERIFY(object.connect(&object, + SIGNAL(constTypeRefSignal(Template<Class const &> const &)), + SLOT(constTypeRefSlot(Template<Class const &> const &)))); + QVERIFY(object.connect(&object, + SIGNAL(constTypeRefSignal(const Template<const Class &> &)), + SLOT(typeConstRefSlot(const Template<const Class &> &)))); + QVERIFY(object.connect(&object, + SIGNAL(constTypeRefSignal(const Template<const Class &> &)), + SLOT(typeConstRefSlot(const Template<Class const &> &)))); + QVERIFY(object.connect(&object, + SIGNAL(constTypeRefSignal(const Template<const Class &> &)), + SLOT(typeConstRefSlot(Template<Class const &> const &)))); + QVERIFY(object.connect(&object, + SIGNAL(constTypeRefSignal(Template<const Class &> const &)), + SLOT(typeConstRefSlot(Template<Class const &> const &)))); + QVERIFY(object.connect(&object, + SIGNAL(constTypeRefSignal(Template<Class const &> const &)), + SLOT(typeConstRefSlot(Template<Class const &> const &)))); + + QVERIFY(object.connect(&object, + SIGNAL(typeConstRefSignal(const Template<const Class &> &)), + SLOT(constTypeRefSlot(const Template<const Class &> &)))); + QVERIFY(object.connect(&object, + SIGNAL(typeConstRefSignal(const Template<const Class &> &)), + SLOT(constTypeRefSlot(const Template<Class const &> &)))); + QVERIFY(object.connect(&object, + SIGNAL(typeConstRefSignal(const Template<const Class &> &)), + SLOT(constTypeRefSlot(Template<Class const &> const &)))); + QVERIFY(object.connect(&object, + SIGNAL(typeConstRefSignal(Template<const Class &> const &)), + SLOT(constTypeRefSlot(Template<Class const &> const &)))); + QVERIFY(object.connect(&object, + SIGNAL(typeConstRefSignal(Template<Class const &> const &)), + SLOT(constTypeRefSlot(Template<Class const &> const &)))); + + QVERIFY(object.connect(&object, + SIGNAL(typeConstRefSignal(const Template<const Class &> &)), + SLOT(typeConstRefSlot(const Template<const Class &> &)))); + QVERIFY(object.connect(&object, + SIGNAL(typeConstRefSignal(const Template<const Class &> &)), + SLOT(typeConstRefSlot(const Template<Class const &> &)))); + QVERIFY(object.connect(&object, + SIGNAL(typeConstRefSignal(const Template<const Class &> &)), + SLOT(typeConstRefSlot(Template<Class const &> const &)))); + QVERIFY(object.connect(&object, + SIGNAL(typeConstRefSignal(Template<const Class &> const &)), + SLOT(typeConstRefSlot(Template<Class const &> const &)))); + QVERIFY(object.connect(&object, + SIGNAL(typeConstRefSignal(Template<Class const &> const &)), + SLOT(typeConstRefSlot(Template<Class const &> const &)))); + + // same test again, this time with an object compiled with old moc output... we know that + // it is not possible to connect everything, whic is the purpose for this test + OldNormalizeObject oldobject; + + QVERIFY(oldobject.connect(&oldobject, + SIGNAL(constTypeRefSignal(const Template<const Class &> &)), + SLOT(constTypeRefSlot(const Template<const Class &> &)))); + QVERIFY(oldobject.connect(&oldobject, + SIGNAL(constTypeRefSignal(const Template<const Class &> &)), + SLOT(constTypeRefSlot(const Template<Class const &> &)))); + // this fails in older versions, but passes now due to proper normalizing + QVERIFY(oldobject.connect(&oldobject, + SIGNAL(constTypeRefSignal(const Template<const Class &> &)), + SLOT(constTypeRefSlot(Template<Class const &> const &)))); + // this fails in older versions, but passes now due to proper normalizing + QVERIFY(oldobject.connect(&oldobject, + SIGNAL(constTypeRefSignal(Template<const Class &> const &)), + SLOT(constTypeRefSlot(Template<Class const &> const &)))); + // this fails in older versions, but passes now due to proper normalizing + QVERIFY(oldobject.connect(&oldobject, + SIGNAL(constTypeRefSignal(Template<Class const &> const &)), + SLOT(constTypeRefSlot(Template<Class const &> const &)))); + + // these fail in older Qt versions, but pass now due to proper normalizing + QVERIFY(oldobject.connect(&oldobject, + SIGNAL(constTypeRefSignal(const Template<const Class &> &)), + SLOT(typeConstRefSlot(const Template<const Class &> &)))); + QVERIFY(oldobject.connect(&oldobject, + SIGNAL(constTypeRefSignal(const Template<const Class &> &)), + SLOT(typeConstRefSlot(const Template<Class const &> &)))); + QVERIFY(oldobject.connect(&oldobject, + SIGNAL(constTypeRefSignal(const Template<const Class &> &)), + SLOT(typeConstRefSlot(Template<Class const &> const &)))); + QVERIFY(oldobject.connect(&oldobject, + SIGNAL(constTypeRefSignal(Template<const Class &> const &)), + SLOT(typeConstRefSlot(Template<Class const &> const &)))); + QVERIFY(oldobject.connect(&oldobject, + SIGNAL(constTypeRefSignal(Template<Class const &> const &)), + SLOT(typeConstRefSlot(Template<Class const &> const &)))); + + // these also fail in older Qt versions, but pass now due to proper normalizing + QVERIFY(oldobject.connect(&oldobject, + SIGNAL(typeConstRefSignal(const Template<const Class &> &)), + SLOT(constTypeRefSlot(const Template<const Class &> &)))); + QVERIFY(oldobject.connect(&oldobject, + SIGNAL(typeConstRefSignal(const Template<const Class &> &)), + SLOT(constTypeRefSlot(const Template<Class const &> &)))); + QVERIFY(oldobject.connect(&oldobject, + SIGNAL(typeConstRefSignal(const Template<const Class &> &)), + SLOT(constTypeRefSlot(Template<Class const &> const &)))); + QVERIFY(oldobject.connect(&oldobject, + SIGNAL(typeConstRefSignal(Template<const Class &> const &)), + SLOT(constTypeRefSlot(Template<Class const &> const &)))); + QVERIFY(oldobject.connect(&oldobject, + SIGNAL(typeConstRefSignal(Template<Class const &> const &)), + SLOT(constTypeRefSlot(Template<Class const &> const &)))); + + // this fails in older versions, but passes now due to proper normalizing + QVERIFY(oldobject.connect(&oldobject, + SIGNAL(typeConstRefSignal(const Template<const Class &> &)), + SLOT(typeConstRefSlot(const Template<const Class &> &)))); + // this fails in older versions, but passes now due to proper normalizing + QVERIFY(oldobject.connect(&oldobject, + SIGNAL(typeConstRefSignal(const Template<const Class &> &)), + SLOT(typeConstRefSlot(const Template<Class const &> &)))); + // this fails in older versions, but passes now due to proper normalizing + QVERIFY(oldobject.connect(&oldobject, + SIGNAL(typeConstRefSignal(const Template<const Class &> &)), + SLOT(typeConstRefSlot(Template<Class const &> const &)))); + QVERIFY(oldobject.connect(&oldobject, + SIGNAL(typeConstRefSignal(Template<const Class &> const &)), + SLOT(typeConstRefSlot(Template<Class const &> const &)))); + QVERIFY(oldobject.connect(&oldobject, + SIGNAL(typeConstRefSignal(Template<Class const &> const &)), + SLOT(typeConstRefSlot(Template<Class const &> const &)))); + + QVERIFY(object.connect(&object, + SIGNAL(typePointerConstRefSignal(Class*const&)), + SLOT(typePointerConstRefSlot(Class*const&)))); + QVERIFY(object.connect(&object, + SIGNAL(typePointerConstRefSignal(Class*const&)), + SLOT(typePointerConstRefSlot(Class*)))); + QVERIFY(object.connect(&object, + SIGNAL(typePointerConstRefSignal(Class*)), + SLOT(typePointerConstRefSlot(Class*const&)))); + QVERIFY(object.connect(&object, + SIGNAL(typePointerConstRefSignal(Class*)), + SLOT(typePointerConstRefSlot(Class*)))); } class SiblingDeleter : public QObject diff --git a/tests/auto/qobject/tst_qobject.pro b/tests/auto/qobject/tst_qobject.pro index 003ee98..0200f3e 100644 --- a/tests/auto/qobject/tst_qobject.pro +++ b/tests/auto/qobject/tst_qobject.pro @@ -1,16 +1,20 @@ load(qttest_p4) -SOURCES += tst_qobject.cpp +SOURCES += tst_qobject.cpp -QT = core network gui -contains(QT_CONFIG, qt3support):DEFINES+=QT_HAS_QT3SUPPORT +# this is here for a reason, moc_oldnormalizedobject.cpp is not auto-generated, it was generated by +# moc from Qt 4.6, and should *not* be generated by the current moc +SOURCES += moc_oldnormalizeobject.cpp -wince*: { - addFiles.sources = signalbug.exe - addFiles.path = . - DEPLOYMENT += addFiles +QT = core \ + network \ + gui +contains(QT_CONFIG, qt3support):DEFINES += QT_HAS_QT3SUPPORT +wince*: { + addFiles.sources = signalbug.exe + addFiles.path = . + DEPLOYMENT += addFiles } - -symbian: { +symbian: { addFiles.sources = signalbug.exe addFiles.path = \sys\bin DEPLOYMENT += addFiles diff --git a/tests/auto/qpixmap/tst_qpixmap.cpp b/tests/auto/qpixmap/tst_qpixmap.cpp index d7c6ad3..49b1e52 100644 --- a/tests/auto/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/qpixmap/tst_qpixmap.cpp @@ -47,6 +47,7 @@ #include <qmatrix.h> #include <qdesktopwidget.h> #include <qpaintengine.h> +#include <qtreewidget.h> #include <qsplashscreen.h> #include <private/qpixmapdata_p.h> @@ -797,14 +798,32 @@ void tst_QPixmap::drawBitmap() void tst_QPixmap::grabWidget() { QWidget widget; - widget.setPalette(Qt::green); - widget.resize(128, 128); + QImage image(128, 128, QImage::Format_ARGB32_Premultiplied); + for (int row = 0; row < image.height(); ++row) { + QRgb *line = reinterpret_cast<QRgb *>(image.scanLine(row)); + for (int col = 0; col < image.width(); ++col) + line[col] = qRgb(rand() & 255, row, col); + } - QPixmap expected(64, 64); - expected.fill(Qt::green); + QPalette pal = widget.palette(); + pal.setBrush(QPalette::Window, QBrush(image)); + widget.setPalette(pal); + widget.resize(128, 128); + QPixmap expected = QPixmap::fromImage(QImage(image.scanLine(64) + 64 * 4, 64, 64, image.bytesPerLine(), image.format())); QPixmap actual = QPixmap::grabWidget(&widget, QRect(64, 64, 64, 64)); QVERIFY(lenientCompare(actual, expected)); + + actual = QPixmap::grabWidget(&widget, 64, 64); + QVERIFY(lenientCompare(actual, expected)); + + // Make sure a widget that is not yet shown is grabbed correctly. + QTreeWidget widget2; + actual = QPixmap::grabWidget(&widget2); + widget2.show(); + expected = QPixmap::grabWidget(&widget2); + + QVERIFY(lenientCompare(actual, expected)); } void tst_QPixmap::grabWindow() diff --git a/tests/auto/qsharedpointer/externaltests.cpp b/tests/auto/qsharedpointer/externaltests.cpp index eb2f27d..7eae3c1 100644 --- a/tests/auto/qsharedpointer/externaltests.cpp +++ b/tests/auto/qsharedpointer/externaltests.cpp @@ -671,14 +671,9 @@ namespace QTest { make.setProcessChannelMode(channelMode); -#if defined(Q_OS_WIN) && !defined(Q_CC_MINGW) - make.start(QLatin1String("nmake.exe"), args); - make.waitForStarted(); -#else static const char makes[] = -# ifdef Q_CC_MINGW - "mingw32-make.exe\0" -# endif + "nmake.exe\0" //for visual c++ + "mingw32-make.exe\0" //for mingw "gmake\0" "make\0"; for (const char *p = makes; *p; p += strlen(p) + 1) { @@ -686,7 +681,6 @@ namespace QTest { if (make.waitForStarted()) break; } -#endif if (make.state() != QProcess::Running) { exitCode = 255; diff --git a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index 8abf3c0..5b2b0cf 100644 --- a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -136,6 +136,7 @@ private slots: void task252507_mapFromToSource(); void task255652_removeRowsRecursive(); void taskQTBUG_6205_doubleProxySelectionSetSourceModel(); + void taskQTBUG_7537_appearsAndSort(); protected: void buildHierarchy(const QStringList &data, QAbstractItemModel *model); @@ -2852,5 +2853,73 @@ void tst_QSortFilterProxyModel::taskQTBUG_6205_doubleProxySelectionSetSourceMode QVERIFY(ism.selection().isEmpty()); } +void tst_QSortFilterProxyModel::taskQTBUG_7537_appearsAndSort() +{ + class PModel : public QSortFilterProxyModel + { + public: + PModel() : mVisible(false) {}; + protected: + bool filterAcceptsRow(int, const QModelIndex &) const + { + return mVisible; + } + + public: + void updateXX() + { + mVisible = true; + invalidate(); + } + private: + bool mVisible; + } proxyModel; + + + QStringListModel sourceModel; + QStringList list; + list << "b" << "a" << "c"; + sourceModel.setStringList(list); + + proxyModel.setSourceModel(&sourceModel); + proxyModel.setDynamicSortFilter(true); + proxyModel.sort(0, Qt::AscendingOrder); + + QApplication::processEvents(); + QCOMPARE(sourceModel.rowCount(), 3); + QCOMPARE(proxyModel.rowCount(), 0); //all rows are hidden at first; + + QSignalSpy spyAbout1(&proxyModel, SIGNAL(layoutAboutToBeChanged())); + QSignalSpy spyChanged1(&proxyModel, SIGNAL(layoutChanged())); + + //introducing secondProxyModel to test the layoutChange when many items appears at once + QSortFilterProxyModel secondProxyModel; + secondProxyModel.setSourceModel(&proxyModel); + secondProxyModel.setDynamicSortFilter(true); + secondProxyModel.sort(0, Qt::DescendingOrder); + QCOMPARE(secondProxyModel.rowCount(), 0); //all rows are hidden at first; + QSignalSpy spyAbout2(&secondProxyModel, SIGNAL(layoutAboutToBeChanged())); + QSignalSpy spyChanged2(&secondProxyModel, SIGNAL(layoutChanged())); + + proxyModel.updateXX(); + QApplication::processEvents(); + //now rows should be visible, and sorted + QCOMPARE(proxyModel.rowCount(), 3); + QCOMPARE(proxyModel.data(proxyModel.index(0,0), Qt::DisplayRole).toString(), QString::fromLatin1("a")); + QCOMPARE(proxyModel.data(proxyModel.index(1,0), Qt::DisplayRole).toString(), QString::fromLatin1("b")); + QCOMPARE(proxyModel.data(proxyModel.index(2,0), Qt::DisplayRole).toString(), QString::fromLatin1("c")); + + //now rows should be visible, and sorted + QCOMPARE(secondProxyModel.rowCount(), 3); + QCOMPARE(secondProxyModel.data(secondProxyModel.index(0,0), Qt::DisplayRole).toString(), QString::fromLatin1("c")); + QCOMPARE(secondProxyModel.data(secondProxyModel.index(1,0), Qt::DisplayRole).toString(), QString::fromLatin1("b")); + QCOMPARE(secondProxyModel.data(secondProxyModel.index(2,0), Qt::DisplayRole).toString(), QString::fromLatin1("a")); + + QCOMPARE(spyAbout1.count(), 1); + QCOMPARE(spyChanged1.count(), 1); + QCOMPARE(spyAbout2.count(), 1); + QCOMPARE(spyChanged2.count(), 1); +} + QTEST_MAIN(tst_QSortFilterProxyModel) #include "tst_qsortfilterproxymodel.moc" diff --git a/tests/auto/qtabbar/tst_qtabbar.cpp b/tests/auto/qtabbar/tst_qtabbar.cpp index d980efa..72f9dd3 100644 --- a/tests/auto/qtabbar/tst_qtabbar.cpp +++ b/tests/auto/qtabbar/tst_qtabbar.cpp @@ -273,6 +273,9 @@ void tst_QTabBar::setElideMode() if (tabElideMode != -128) tabBar.setElideMode(Qt::TextElideMode(tabElideMode)); QTEST(int(tabBar.elideMode()), "expectedMode"); + // Make sure style sheet does not override user set mode + tabBar.setStyleSheet("QWidget { background-color: #ABA8A6;}"); + QTEST(int(tabBar.elideMode()), "expectedMode"); } void tst_QTabBar::setUsesScrollButtons_data() diff --git a/tests/auto/qtoolbar/tst_qtoolbar.cpp b/tests/auto/qtoolbar/tst_qtoolbar.cpp index e00597d..07e81c1 100644 --- a/tests/auto/qtoolbar/tst_qtoolbar.cpp +++ b/tests/auto/qtoolbar/tst_qtoolbar.cpp @@ -102,6 +102,7 @@ private slots: void orientationChanged(); void iconSizeChanged(); void toolButtonStyleChanged(); + void visibilityChanged(); void actionOwnership(); void widgetAction(); void accel(); @@ -998,6 +999,36 @@ void tst_QToolBar::iconSizeChanged() void tst_QToolBar::toolButtonStyleChanged() { DEPENDS_ON("toolButtonStyle()"); } +void tst_QToolBar::visibilityChanged() +{ + QMainWindow mw; + QToolBar tb; + QSignalSpy spy(&tb, SIGNAL(visibilityChanged(bool))); + + mw.addToolBar(&tb); + mw.show(); + + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.at(0).at(0).toBool(), true); + spy.clear(); + + tb.hide(); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.at(0).at(0).toBool(), false); + spy.clear(); + + tb.hide(); + QCOMPARE(spy.count(), 0); + + tb.show(); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.at(0).at(0).toBool(), true); + spy.clear(); + + tb.show(); + QCOMPARE(spy.count(), 0); +} + void tst_QToolBar::actionOwnership() { { diff --git a/tests/auto/qxmlsimplereader/tst_qxmlsimplereader.cpp b/tests/auto/qxmlsimplereader/tst_qxmlsimplereader.cpp index e38a2bc..0e57306 100644 --- a/tests/auto/qxmlsimplereader/tst_qxmlsimplereader.cpp +++ b/tests/auto/qxmlsimplereader/tst_qxmlsimplereader.cpp @@ -580,7 +580,7 @@ void tst_QXmlSimpleReader::inputFromSocket() QSKIP("Symbian: Skipped due to problems in Open C and QtNetwork", SkipAll); #endif -#if defined(Q_OS_WIN32) && (defined(Q_CC_INTEL) || defined(Q_CC_MINGW) || defined(Q_CC_MSVC_NET)) +#if defined(Q_OS_WIN32) && (defined(Q_CC_INTEL) || defined(Q_CC_MSVC_NET)) QSKIP("Regression caused by QHOstInfo change 294548, see task 202231.", SkipAll); #endif QTcpSocket sock; diff --git a/tests/auto/selftests/expected_benchlibcallgrind.txt b/tests/auto/selftests/expected_benchlibcallgrind.txt index caf2424..f172711 100644 --- a/tests/auto/selftests/expected_benchlibcallgrind.txt +++ b/tests/auto/selftests/expected_benchlibcallgrind.txt @@ -2,7 +2,7 @@ Config: Using QTest library 4.5.0, Qt 4.5.0 PASS : tst_BenchlibCallgrind::initTestCase() RESULT : tst_BenchlibCallgrind::twoHundredMillionInstructions(): - 200,000,000 instr. loads per iteration (total: 200000000, iterations: 1) + 200,000,000 instruction reads per iteration (total: 200000000, iterations: 1) PASS : tst_BenchlibCallgrind::twoHundredMillionInstructions() PASS : tst_BenchlibCallgrind::cleanupTestCase() Totals: 3 passed, 0 failed, 0 skipped diff --git a/tests/auto/selftests/expected_cmptest.txt b/tests/auto/selftests/expected_cmptest.txt index 1b65adf..e9f94c9 100644 --- a/tests/auto/selftests/expected_cmptest.txt +++ b/tests/auto/selftests/expected_cmptest.txt @@ -1,5 +1,5 @@ ********* Start testing of tst_Cmptest ********* -Config: Using QTest library 4.6.2, Qt 4.6.2 +Config: Using QTest library 4.7.0, Qt 4.7.0 PASS : tst_Cmptest::initTestCase() PASS : tst_Cmptest::compare_boolfuncs() PASS : tst_Cmptest::compare_pointerfuncs() diff --git a/tests/auto/selftests/expected_crashes_3.txt b/tests/auto/selftests/expected_crashes_3.txt index aabe83d..3aced25 100644 --- a/tests/auto/selftests/expected_crashes_3.txt +++ b/tests/auto/selftests/expected_crashes_3.txt @@ -1,5 +1,5 @@ ********* Start testing of tst_Crashes ********* -Config: Using QTest library 4.6.2, Qt 4.6.2 +Config: Using QTest library 4.7.0, Qt 4.7.0 PASS : tst_Crashes::initTestCase() QFATAL : tst_Crashes::crash() Received signal 11 FAIL! : tst_Crashes::crash() Received a fatal error. diff --git a/tests/auto/selftests/expected_longstring.txt b/tests/auto/selftests/expected_longstring.txt index 3fe237a..a6ad5d0 100644 --- a/tests/auto/selftests/expected_longstring.txt +++ b/tests/auto/selftests/expected_longstring.txt @@ -1,5 +1,5 @@ ********* Start testing of tst_LongString ********* -Config: Using QTest library 4.6.2, Qt 4.6.2 +Config: Using QTest library 4.7.0, Qt 4.7.0 PASS : tst_LongString::initTestCase() FAIL! : tst_LongString::failWithLongString() Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. diff --git a/tests/auto/selftests/expected_maxwarnings.txt b/tests/auto/selftests/expected_maxwarnings.txt index 8bafeff..908bd5d 100644 --- a/tests/auto/selftests/expected_maxwarnings.txt +++ b/tests/auto/selftests/expected_maxwarnings.txt @@ -1,5 +1,5 @@ ********* Start testing of MaxWarnings ********* -Config: Using QTest library 4.6.2, Qt 4.6.2 +Config: Using QTest library 4.7.0, Qt 4.7.0 PASS : MaxWarnings::initTestCase() QWARN : MaxWarnings::warn() 0 QWARN : MaxWarnings::warn() 1 diff --git a/tests/auto/selftests/expected_skip.txt b/tests/auto/selftests/expected_skip.txt index c4ef92d..4345a6c 100644 --- a/tests/auto/selftests/expected_skip.txt +++ b/tests/auto/selftests/expected_skip.txt @@ -1,5 +1,5 @@ ********* Start testing of tst_Skip ********* -Config: Using QTest library 4.6.2, Qt 4.6.2 +Config: Using QTest library 4.7.0, Qt 4.7.0 PASS : tst_Skip::initTestCase() SKIP : tst_Skip::test() skipping all Loc: [/home/rmcgover/depot/qt-git/mainline/tests/auto/selftests/skip/tst_skip.cpp(68)] diff --git a/tests/auto/selftests/tst_selftests.cpp b/tests/auto/selftests/tst_selftests.cpp index 0b9cee0..3d58c15 100644 --- a/tests/auto/selftests/tst_selftests.cpp +++ b/tests/auto/selftests/tst_selftests.cpp @@ -97,7 +97,7 @@ inline bool qCompare if (r1.unit == "msec") { variance = 0.1; } - else if (r1.unit == "instr. loads") { + else if (r1.unit == "instruction reads") { variance = 0.001; } else if (r1.unit == "ticks") { @@ -434,7 +434,7 @@ BenchmarkResult BenchmarkResult::parse(QString const& line, QString* error) /* This code avoids using a QRegExp because QRegExp might be broken. */ - /* Sample format: 4,000 msec per iteration (total: 4000, iterations: 1) */ + /* Sample format: 4,000 msec per iteration (total: 4,000, iterations: 1) */ QString sFirstNumber; while (!remaining.isEmpty() && !remaining.at(0).isSpace()) { @@ -468,7 +468,7 @@ BenchmarkResult BenchmarkResult::parse(QString const& line, QString* error) remaining = remaining.mid(sizeof(periterbit)-1); - /* Remaining: 4000, iterations: 1) */ + /* Remaining: 4,000, iterations: 1) */ static const char itersbit[] = ", iterations: "; QString sTotal; while (!remaining.startsWith(itersbit) && !remaining.isEmpty()) { @@ -482,9 +482,12 @@ BenchmarkResult BenchmarkResult::parse(QString const& line, QString* error) remaining = remaining.mid(sizeof(itersbit)-1); - qint64 total = sTotal.toLongLong(&ok); + /* 4,000 -> 4000 */ + sTotal.remove(','); + + double total = sTotal.toDouble(&ok); if (!ok) { - if (error) *error = sTotal + " (total) is not a valid integer"; + if (error) *error = sTotal + " (total) is not a valid number"; return out; } diff --git a/tests/auto/selftests/xunit/tst_xunit b/tests/auto/selftests/xunit/tst_xunit Binary files differdeleted file mode 100755 index 31d03a8..0000000 --- a/tests/auto/selftests/xunit/tst_xunit +++ /dev/null diff --git a/tests/auto/symbols/tst_symbols.cpp b/tests/auto/symbols/tst_symbols.cpp index e30481a..70abc43 100644 --- a/tests/auto/symbols/tst_symbols.cpp +++ b/tests/auto/symbols/tst_symbols.cpp @@ -100,7 +100,6 @@ void tst_Symbols::globalObjects() #ifndef Q_OS_LINUX QSKIP("Linux-specific test", SkipAll); #endif - QSKIP("Test disabled, we're not fixing these issues in this Qt version", SkipAll); // these are regexps for global objects that are allowed in Qt QStringList whitelist = QStringList() diff --git a/tests/auto/uiloader/baseline/css_buttons_background.ui b/tests/auto/uiloader/baseline/css_buttons_background.ui index f1fa0bc..3d80aeb 100644 --- a/tests/auto/uiloader/baseline/css_buttons_background.ui +++ b/tests/auto/uiloader/baseline/css_buttons_background.ui @@ -89,6 +89,19 @@ color: yellow; </property> </widget> </item> + <item row="5" column="0"> + <widget class="QPushButton" name="pushButton_4"> + <property name="text"> + <string>Checked</string> + </property> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> </layout> </widget> </item> @@ -149,6 +162,19 @@ color: yellow; </property> </widget> </item> + <item row="5" column="0"> + <widget class="QPushButton" name="pushButton_5"> + <property name="text"> + <string>Checked</string> + </property> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> </layout> </widget> </item> @@ -209,6 +235,19 @@ color: yellow; </property> </widget> </item> + <item row="5" column="0"> + <widget class="QPushButton" name="pushButton_6"> + <property name="text"> + <string>Checked</string> + </property> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> </layout> </widget> </item> diff --git a/tests/auto/uiloader/baseline/css_qtbug6855.ui b/tests/auto/uiloader/baseline/css_qtbug6855.ui new file mode 100644 index 0000000..0727f6b --- /dev/null +++ b/tests/auto/uiloader/baseline/css_qtbug6855.ui @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Form</class> + <widget class="QWidget" name="Form"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>212</width> + <height>108</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <property name="styleSheet"> + <string notr="true">QPushButton { padding: 20px; }</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QPushButton" name="pushButton"> + <property name="text"> + <string>Text not cropped</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>258</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="1" column="0"> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>218</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/tests/benchmarks/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/benchmarks/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp index faacec4..01285d1 100644 --- a/tests/benchmarks/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp +++ b/tests/benchmarks/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the documentation of the Qt Toolkit. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/tests/benchmarks/qmetaobject/main.cpp b/tests/benchmarks/qmetaobject/main.cpp index c375a16..eef6020 100644 --- a/tests/benchmarks/qmetaobject/main.cpp +++ b/tests/benchmarks/qmetaobject/main.cpp @@ -42,6 +42,84 @@ #include <QtGui> #include <qtest.h> +class LotsOfSignals : public QObject +{ + Q_OBJECT +public: + LotsOfSignals() {} + +signals: + void extraSignal1(); + void extraSignal2(); + void extraSignal3(); + void extraSignal4(); + void extraSignal5(); + void extraSignal6(); + void extraSignal7(); + void extraSignal8(); + void extraSignal9(); + void extraSignal10(); + void extraSignal12(); + void extraSignal13(); + void extraSignal14(); + void extraSignal15(); + void extraSignal16(); + void extraSignal17(); + void extraSignal18(); + void extraSignal19(); + void extraSignal20(); + void extraSignal21(); + void extraSignal22(); + void extraSignal23(); + void extraSignal24(); + void extraSignal25(); + void extraSignal26(); + void extraSignal27(); + void extraSignal28(); + void extraSignal29(); + void extraSignal30(); + void extraSignal31(); + void extraSignal32(); + void extraSignal33(); + void extraSignal34(); + void extraSignal35(); + void extraSignal36(); + void extraSignal37(); + void extraSignal38(); + void extraSignal39(); + void extraSignal40(); + void extraSignal41(); + void extraSignal42(); + void extraSignal43(); + void extraSignal44(); + void extraSignal45(); + void extraSignal46(); + void extraSignal47(); + void extraSignal48(); + void extraSignal49(); + void extraSignal50(); + void extraSignal51(); + void extraSignal52(); + void extraSignal53(); + void extraSignal54(); + void extraSignal55(); + void extraSignal56(); + void extraSignal57(); + void extraSignal58(); + void extraSignal59(); + void extraSignal60(); + void extraSignal61(); + void extraSignal62(); + void extraSignal63(); + void extraSignal64(); + void extraSignal65(); + void extraSignal66(); + void extraSignal67(); + void extraSignal68(); + void extraSignal69(); + void extraSignal70(); +}; + class tst_qmetaobject: public QObject { Q_OBJECT @@ -57,6 +135,9 @@ private slots: void indexOfSignal(); void indexOfSlot_data(); void indexOfSlot(); + + void unconnected_data(); + void unconnected(); }; void tst_qmetaobject::initTestCase() @@ -154,6 +235,30 @@ void tst_qmetaobject::indexOfSlot() } } +void tst_qmetaobject::unconnected_data() +{ + QTest::addColumn<int>("signal_index"); + QTest::newRow("signal--9") << 9; + QTest::newRow("signal--32") << 32; + QTest::newRow("signal--33") << 33; + QTest::newRow("signal--64") << 64; + QTest::newRow("signal--65") << 65; + QTest::newRow("signal--70") << 70; +} + +void tst_qmetaobject::unconnected() +{ + LotsOfSignals *obj = new LotsOfSignals; + QFETCH(int, signal_index); + QVERIFY(obj->metaObject()->methodCount() == 73); + void *v; + QBENCHMARK { + //+1 because QObject has one slot + QMetaObject::metacall(obj, QMetaObject::InvokeMetaMethod, signal_index+1, &v); + } + delete obj; +} + QTEST_MAIN(tst_qmetaobject) #include "main.moc" diff --git a/tests/benchmarks/qstringlist/main.cpp b/tests/benchmarks/qstringlist/main.cpp index 3fac598..1717b88 100644 --- a/tests/benchmarks/qstringlist/main.cpp +++ b/tests/benchmarks/qstringlist/main.cpp @@ -54,17 +54,21 @@ private slots: void join() const; void join_data() const; - void split() const; + void split_qlist_qbytearray() const; + void split_qlist_qbytearray_data() const { return split_data(); } + void split_data() const; + void split_qlist_qstring() const; + void split_qlist_qstring_data() const { return split_data(); } - void split_std() const; - void split_std_data() const { return split_data(); } + void split_stdvector_stdstring() const; + void split_stdvector_stdstring_data() const { return split_data(); } - void split_stdw() const; - void split_stdw_data() const { return split_data(); } + void split_stdvector_stdwstring() const; + void split_stdvector_stdwstring_data() const { return split_data(); } - void split_ba() const; - void split_ba_data() const { return split_data(); } + void split_stdlist_stdstring() const; + void split_stdlist_stdstring_data() const { return split_data(); } private: static QStringList populateList(const int count, const QString &unit); @@ -125,27 +129,39 @@ void tst_QStringList::join_data() const << QString(); } -void tst_QStringList::split() const +void tst_QStringList::split_data() const +{ + QTest::addColumn<QString>("input"); + QString unit = QLatin1String("unit") + QString(100, QLatin1Char('s')); + //QTest::newRow("") << populateString(10, unit); + QTest::newRow("") << populateString(100, unit); + //QTest::newRow("") << populateString(100, unit); + //QTest::newRow("") << populateString(1000, unit); + //QTest::newRow("") << populateString(10000, unit); +} + +void tst_QStringList::split_qlist_qbytearray() const { QFETCH(QString, input); - const QChar splitChar = ':'; + const char splitChar = ':'; + QByteArray ba = input.toLatin1(); QBENCHMARK { - input.split(splitChar); + ba.split(splitChar); } } -void tst_QStringList::split_data() const +void tst_QStringList::split_qlist_qstring() const { - QTest::addColumn<QString>("input"); - QString unit = QLatin1String("unit"); - QTest::newRow("") << populateString(10, unit); - QTest::newRow("") << populateString(100, unit); - QTest::newRow("") << populateString(1000, unit); - QTest::newRow("") << populateString(10000, unit); + QFETCH(QString, input); + const QChar splitChar = ':'; + + QBENCHMARK { + input.split(splitChar); + } } -void tst_QStringList::split_std() const +void tst_QStringList::split_stdvector_stdstring() const { QFETCH(QString, input); const char split_char = ':'; @@ -161,7 +177,7 @@ void tst_QStringList::split_std() const } } -void tst_QStringList::split_stdw() const +void tst_QStringList::split_stdvector_stdwstring() const { QFETCH(QString, input); const wchar_t split_char = ':'; @@ -177,14 +193,19 @@ void tst_QStringList::split_stdw() const } } -void tst_QStringList::split_ba() const +void tst_QStringList::split_stdlist_stdstring() const { QFETCH(QString, input); - const char splitChar = ':'; - QByteArray ba = input.toLatin1(); + const char split_char = ':'; + std::string stdinput = input.toStdString(); QBENCHMARK { - ba.split(splitChar); + std::istringstream split(stdinput); + std::list<std::string> token; + for (std::string each; + std::getline(split, each, split_char); + token.push_back(each)) + ; } } diff --git a/tests/benchmarks/qstringlist/qstringlist.pro b/tests/benchmarks/qstringlist/qstringlist.pro index 11cceb0..5c64b34 100644 --- a/tests/benchmarks/qstringlist/qstringlist.pro +++ b/tests/benchmarks/qstringlist/qstringlist.pro @@ -1,5 +1,7 @@ load(qttest_p4) TARGET = tst_qstringlist +CONFIG -= debug +CONFIG += release QT -= gui SOURCES += main.cpp diff --git a/tests/benchmarks/qvector/main.cpp b/tests/benchmarks/qvector/main.cpp new file mode 100644 index 0000000..65e7609 --- /dev/null +++ b/tests/benchmarks/qvector/main.cpp @@ -0,0 +1,426 @@ +/**************************************************************************** +** +** 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 <QVector> +#include <QDebug> +#include <QtTest> + +#include "qrawvector.h" + +#include <vector> + +/* + +Code generated by g++ 4.3.3. The lines marked with '!' are the ones that get +executed inside the loop. Using the external 's' causes some load making the +loop resembling a 'simple inner loop' in 'real' applications. + + +qvector_mutable_read_access: + +.L166: +! movl -16(%ebp), %edx +! movl (%edx), %eax +! subl $1, %eax +! je .L165 + movl 4(%edx), %eax + movl %eax, 8(%esp) + movl 8(%edx), %eax + movl %esi, (%esp) + movl %eax, 4(%esp) + call _ZN4myns7QVectorIdE7reallocEii +.L165: +! movl -16(%ebp), %eax +! fldl s +! faddl 16(%eax,%ebx,8) +! addl $1, %ebx +! cmpl $10000, %ebx +! fstpl s +! jne .L166 + + +qvector_const_read_access: + + movl -16(%ebp), %edx + xorl %eax, %eax +.L183: +! fldl s +! faddl 16(%edx,%eax,8) +! addl $1, %eax +! cmpl $10000, %eax +! fstpl s +! jne .L183 + + +stdvector_const_read_access and stdvector_mutable_read_access and +qrawvector_const_read_access and qrawvector_mutable_read_access: + + xorl %eax, %eax +.L64: +! fldl s +! faddl (%ebx,%eax,8) +! addl $1, %eax +! cmpl $10000, %eax +! fstpl s +! jne .L64 + + + +Behaviour varies with small modifications, but total is more or +less stable: + +qrawvector_mutable_read_access, using size() instead of N: + +.L145: +! faddl (%edx,%eax,8) +! addl $1, %eax +! cmpl %ecx, %eax +! fstl s +! jne .L145 +! fstp %st(0) + + +qrawvector_mutable_read_access, counting backward: + +.L145: +! faddl (%edx,%eax,8) +! subl $1, %eax +! cmpl $-1, %eax +! fstl s +! jne .L145 + + +qrawvector_mutable_read_access, counting backward, using size(): + +.L146: +! faddl (%edx) +! addl $1, %eax +! subl $8, %edx +! cmpl %ecx, %eax +! fstl s +! jne .L146 + + + +*/ + + +/* + +//////////////////////////////////////////////////////////////////// + +time ./tst_vector qvector_const_read_access +real 0m12.912s +user 0m12.401s +sys 0m0.016s + +time ./tst_vector qvector_mutable_read_access +real 0m38.566s +user 0m36.754s +sys 0m0.008s + + +time ./tst_vector stdvector_mutable_read_access +real 0m12.736s +user 0m12.665s +sys 0m0.004s + + +//////////////////////////////////////////////////////////////////// + +time ./tst_vector qvector_fill_and_return +real 0m28.778s +user 0m28.522s +sys 0m0.012s + +time ./tst_vector stdvector_fill_and_return +real 0m26.675s +user 0m26.558s +sys 0m0.012s + +time ./tst_vector qrawvector_fill_and_return +real 0m23.370s +user 0m23.269s +sys 0m0.008s + + + +*/ + + + +#define TEST_RETURN 1 + +// For some reason, both 'plain' and '-callgrind' create strange results +// (like varying instruction count for the same assembly code) +// So replace it by a plain loop and measure wall clock time. +//#undef QBENCHMARK +//#define QBENCHMARK for (int j = 0; j != 10000; ++j) + +class tst_QVector: public QObject +{ + Q_OBJECT + +private slots: + void calibration(); + + // Pure Qt solution + void qvector_separator() { qWarning() << "QVector results: "; } + void qvector_const_read_access(); + void qvector_mutable_read_access(); + #ifdef TEST_RETURN + void qvector_fill_and_return(); + void qvector_fill_and_return2(); + #endif + + // Purre Standard solution + void stdvector() { qWarning() << "std::vector results: "; } + void stdvector_const_read_access(); + void stdvector_mutable_read_access(); + #ifdef TEST_RETURN + void stdvector_fill_and_return(); + void stdvector_fill_and_return2(); + #endif + + // Build using std, pass as QVector + void mixedvector() { qWarning() << "mixed results: "; } + #ifdef TEST_RETURN + void mixedvector_fill_and_return(); + void mixedvector_fill_and_return2(); + #endif + + // Alternative implementation + void qrawvector_separator() { qWarning() << "QRawVector results: "; } + void qrawvector_const_read_access(); + void qrawvector_mutable_read_access(); + #ifdef TEST_RETURN + void qrawvector_fill_and_return(); + void qrawvector_fill_and_return2(); + #endif +}; + +const int N = 1000000; +extern double s; + +void tst_QVector::calibration() +{ + QVector<double> v(N); + for (int i = 0; i != N; ++i) + v[i] = i; + QBENCHMARK { + for (int i = 0; i != N; ++i) + s += i; + } +} + +///////////////////// QVector ///////////////////// + +void tst_QVector::qvector_const_read_access() +{ + QVector<double> v(N); + for (int i = 0; i != N; ++i) + v[i] = i; + + const QVector<double> &vc = v; + QBENCHMARK { + for (int i = 0; i != N; ++i) + s += vc[i]; + } +} + +void tst_QVector::qvector_mutable_read_access() +{ + QVector<double> v(N); + for (int i = 0; i != N; ++i) + v[i] = i; + + QBENCHMARK { + for (int i = 0; i != N; ++i) + s += v[i]; + } +} + +#ifdef TEST_RETURN +extern QVector<double> qvector_fill_and_return_helper(); +extern QVector<double> qvector_fill_and_return_helper2(); + +void tst_QVector::qvector_fill_and_return() +{ + QBENCHMARK { + QVector<double> v = qvector_fill_and_return_helper(); + s += v[1]; + } +} + +void tst_QVector::qvector_fill_and_return2() +{ + QBENCHMARK { + QVector<double> v = qvector_fill_and_return_helper2(); + s += v[1]; + } +} +#endif + + +///////////////////// QRawVector ///////////////////// + +void tst_QVector::qrawvector_const_read_access() +{ + QRawVector<double> v(N); + for (int i = 0; i != N; ++i) + v[i] = i; + + const QRawVector<double> &vc = v; + QBENCHMARK { + for (int i = vc.size(); --i >= 0;) + s += vc[i]; + } +} + +void tst_QVector::qrawvector_mutable_read_access() +{ + QRawVector<double> v(N); + for (int i = 0; i != N; ++i) + v[i] = i; + + QBENCHMARK { + for (int i = 0; i != N; ++i) + s += v[i]; + } +} + +#ifdef TEST_RETURN +extern QVector<double> qrawvector_fill_and_return_helper(); +extern QVector<double> qrawvector_fill_and_return_helper2(); + +void tst_QVector::qrawvector_fill_and_return() +{ + QBENCHMARK { + QVector<double> v = qrawvector_fill_and_return_helper(); + s += v[1]; + } +} + +void tst_QVector::qrawvector_fill_and_return2() +{ + QBENCHMARK { + QVector<double> v = qrawvector_fill_and_return_helper(); + s += v[1]; + } +} +#endif + + +///////////////////// std::vector ///////////////////// + +void tst_QVector::stdvector_const_read_access() +{ + std::vector<double> v(N); + for (int i = 0; i != N; ++i) + v[i] = i; + + const std::vector<double> &vc = v; + QBENCHMARK { + for (int i = 0; i != N; ++i) + s += vc[i]; + } +} + +void tst_QVector::stdvector_mutable_read_access() +{ + std::vector<double> v(N); + for (int i = 0; i != N; ++i) + v[i] = i; + + QBENCHMARK { + for (int i = 0; i != N; ++i) + s += v[i]; + } +} + +#ifdef TEST_RETURN +extern std::vector<double> stdvector_fill_and_return_helper(); +extern std::vector<double> stdvector_fill_and_return_helper2(); + +void tst_QVector::stdvector_fill_and_return() +{ + QBENCHMARK { + std::vector<double> v = stdvector_fill_and_return_helper(); + s += v[1]; + } +} + +void tst_QVector::stdvector_fill_and_return2() +{ + QBENCHMARK { + std::vector<double> v = stdvector_fill_and_return_helper2(); + s += v[1]; + } +} +#endif + +///////////////////// mixed vector ///////////////////// + + +#ifdef TEST_RETURN +extern QVector<double> mixedvector_fill_and_return_helper(); +extern QVector<double> mixedvector_fill_and_return_helper2(); + +void tst_QVector::mixedvector_fill_and_return() +{ + QBENCHMARK { + std::vector<double> v = stdvector_fill_and_return_helper(); + s += v[1]; + } +} + +void tst_QVector::mixedvector_fill_and_return2() +{ + QBENCHMARK { + std::vector<double> v = stdvector_fill_and_return_helper2(); + s += v[1]; + } +} +#endif + +QTEST_MAIN(tst_QVector) + +#include "main.moc" diff --git a/tests/benchmarks/qvector/outofline.cpp b/tests/benchmarks/qvector/outofline.cpp new file mode 100644 index 0000000..e8d036e --- /dev/null +++ b/tests/benchmarks/qvector/outofline.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtTest module 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 <QVector> +#include <vector> +#include "qrawvector.h" + +const int N = 1000000; +double s = 0; + +QVector<double> qvector_fill_and_return_helper() +{ + QVector<double> v(N); + for (int i = 0; i != N; ++i) + v[i] = i; + return v; +} + +QVector<double> qrawvector_fill_and_return_helper() +{ + QRawVector<double> v(N); + for (int i = 0; i != N; ++i) + v[i] = i; + return v.mutateToVector(); +} + +QVector<double> mixedvector_fill_and_return_helper() +{ + std::vector<double> v(N); + for (int i = 0; i != N; ++i) + v[i] = i; + return QVector<double>::fromStdVector(v); +} + + +std::vector<double> stdvector_fill_and_return_helper() +{ + std::vector<double> v(N); + for (int i = 0; i != N; ++i) + v[i] = i; + return v; +} + diff --git a/tests/benchmarks/qvector/qrawvector.h b/tests/benchmarks/qvector/qrawvector.h new file mode 100644 index 0000000..15421eb --- /dev/null +++ b/tests/benchmarks/qvector/qrawvector.h @@ -0,0 +1,742 @@ +/**************************************************************************** +** +** 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 QtCore module 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$ +** +****************************************************************************/ + +#ifndef QRAWVECTOR_H +#define QRAWVECTOR_H + +#include <QtCore/qiterator.h> +#include <QtCore/qdebug.h> +#include <QtCore/qatomic.h> +#include <QtCore/qalgorithms.h> +#include <QtCore/qlist.h> + +#ifndef QT_NO_STL +#include <iterator> +#include <vector> +#endif +#include <stddef.h> +#include <stdlib.h> +#include <string.h> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Core) + + + +template <typename T> +class QRawVector +{ + struct Data : QVectorData { T array[1]; }; + + T *m_begin; + int m_size; + int m_alloc; + +public: + //static Data dummy; + //int headerOffset() { return (char*)&dummy.array - (char*)&dummy; } + inline int headerOffset() const { + // gcc complains about: return offsetof(Data, array); and also + // does not like '0' in the expression below. + return (char *)&(((Data *)(1))->array) - (char *)1; + } + inline Data *toBase(T *begin) const + { return (Data*)((char*)begin - headerOffset()); } + inline T *fromBase(void *d) const + { return (T*)((char*)d + headerOffset()); } + inline QRawVector() + { m_begin = fromBase(0); m_alloc = m_size = 0; realloc(m_size, m_alloc, true); } + explicit QRawVector(int size); + QRawVector(int size, const T &t); + inline QRawVector(const QRawVector<T> &v) + { m_begin = v.m_begin; m_alloc = v.m_alloc; m_size = v.m_size; realloc(m_size, m_alloc, true); } + inline ~QRawVector() { free(m_begin, m_size); } + QRawVector<T> &operator=(const QRawVector<T> &v); + bool operator==(const QRawVector<T> &v) const; + inline bool operator!=(const QRawVector<T> &v) const { return !(*this == v); } + + inline int size() const { return m_size; } + + inline bool isEmpty() const { return m_size == 0; } + + void resize(int size); + + inline int capacity() const { return m_alloc; } + void reserve(int size); + inline void squeeze() { realloc(m_size, m_size, false); } + + inline T *data() { return m_begin; } + inline const T *data() const { return m_begin; } + inline const T *constData() const { return m_begin; } + void clear(); + + const T &at(int i) const; + T &operator[](int i); + const T &operator[](int i) const; + void append(const T &t); + void prepend(const T &t); + void insert(int i, const T &t); + void insert(int i, int n, const T &t); + void replace(int i, const T &t); + void remove(int i); + void remove(int i, int n); + + QRawVector<T> &fill(const T &t, int size = -1); + + int indexOf(const T &t, int from = 0) const; + int lastIndexOf(const T &t, int from = -1) const; + bool contains(const T &t) const; + int count(const T &t) const; + +#ifdef QT_STRICT_ITERATORS + class iterator { + public: + T *i; + typedef std::random_access_iterator_tag iterator_category; + typedef ptrdiff_t difference_type; + typedef T value_type; + typedef T *pointer; + typedef T &reference; + + inline iterator() : i(0) {} + inline iterator(T *n) : i(n) {} + inline iterator(const iterator &o): i(o.i){} + inline T &operator*() const { return *i; } + inline T *operator->() const { return i; } + inline T &operator[](int j) const { return *(i + j); } + inline bool operator==(const iterator &o) const { return i == o.i; } + inline bool operator!=(const iterator &o) const { return i != o.i; } + inline bool operator<(const iterator& other) const { return i < other.i; } + inline bool operator<=(const iterator& other) const { return i <= other.i; } + inline bool operator>(const iterator& other) const { return i > other.i; } + inline bool operator>=(const iterator& other) const { return i >= other.i; } + inline iterator &operator++() { ++i; return *this; } + inline iterator operator++(int) { T *n = i; ++i; return n; } + inline iterator &operator--() { i--; return *this; } + inline iterator operator--(int) { T *n = i; i--; return n; } + inline iterator &operator+=(int j) { i+=j; return *this; } + inline iterator &operator-=(int j) { i-=j; return *this; } + inline iterator operator+(int j) const { return iterator(i+j); } + inline iterator operator-(int j) const { return iterator(i-j); } + inline int operator-(iterator j) const { return i - j.i; } + }; + friend class iterator; + + class const_iterator { + public: + T *i; + typedef std::random_access_iterator_tag iterator_category; + typedef ptrdiff_t difference_type; + typedef T value_type; + typedef const T *pointer; + typedef const T &reference; + + inline const_iterator() : i(0) {} + inline const_iterator(T *n) : i(n) {} + inline const_iterator(const const_iterator &o): i(o.i) {} + inline explicit const_iterator(const iterator &o): i(o.i) {} + inline const T &operator*() const { return *i; } + inline const T *operator->() const { return i; } + inline const T &operator[](int j) const { return *(i + j); } + inline bool operator==(const const_iterator &o) const { return i == o.i; } + inline bool operator!=(const const_iterator &o) const { return i != o.i; } + inline bool operator<(const const_iterator& other) const { return i < other.i; } + inline bool operator<=(const const_iterator& other) const { return i <= other.i; } + inline bool operator>(const const_iterator& other) const { return i > other.i; } + inline bool operator>=(const const_iterator& other) const { return i >= other.i; } + inline const_iterator &operator++() { ++i; return *this; } + inline const_iterator operator++(int) { T *n = i; ++i; return n; } + inline const_iterator &operator--() { i--; return *this; } + inline const_iterator operator--(int) { T *n = i; i--; return n; } + inline const_iterator &operator+=(int j) { i+=j; return *this; } + inline const_iterator &operator-=(int j) { i+=j; return *this; } + inline const_iterator operator+(int j) const { return const_iterator(i+j); } + inline const_iterator operator-(int j) const { return const_iterator(i-j); } + inline int operator-(const_iterator j) const { return i - j.i; } + }; + friend class const_iterator; +#else + // STL-style + typedef T *iterator; + typedef const T *const_iterator; +#endif + inline iterator begin() { return m_begin; } + inline const_iterator begin() const { return m_begin; } + inline const_iterator constBegin() const { return m_begin; } + inline iterator end() { return m_begin + m_size; } + inline const_iterator end() const { return m_begin + m_size; } + inline const_iterator constEnd() const { return m_begin + m_size; } + iterator insert(iterator before, int n, const T &x); + inline iterator insert(iterator before, const T &x) { return insert(before, 1, x); } + iterator erase(iterator begin, iterator end); + inline iterator erase(iterator pos) { return erase(pos, pos+1); } + + // more Qt + inline int count() const { return m_size; } + inline T& first() { Q_ASSERT(!isEmpty()); return *begin(); } + inline const T &first() const { Q_ASSERT(!isEmpty()); return *begin(); } + inline T& last() { Q_ASSERT(!isEmpty()); return *(end()-1); } + inline const T &last() const { Q_ASSERT(!isEmpty()); return *(end()-1); } + inline bool startsWith(const T &t) const { return !isEmpty() && first() == t; } + inline bool endsWith(const T &t) const { return !isEmpty() && last() == t; } + QRawVector<T> mid(int pos, int length = -1) const; + + T value(int i) const; + T value(int i, const T &defaultValue) const; + + // STL compatibility + typedef T value_type; + typedef value_type *pointer; + typedef const value_type *const_pointer; + typedef value_type &reference; + typedef const value_type &const_reference; + typedef ptrdiff_t difference_type; + typedef iterator Iterator; + typedef const_iterator ConstIterator; + typedef int size_type; + inline void push_back(const T &t) { append(t); } + inline void push_front(const T &t) { prepend(t); } + void pop_back() { Q_ASSERT(!isEmpty()); erase(end()-1); } + void pop_front() { Q_ASSERT(!isEmpty()); erase(begin()); } + inline bool empty() const { return m_size == 0; } + inline T &front() { return first(); } + inline const_reference front() const { return first(); } + inline reference back() { return last(); } + inline const_reference back() const { return last(); } + + // comfort + QRawVector<T> &operator+=(const QRawVector<T> &l); + inline QRawVector<T> operator+(const QRawVector<T> &l) const + { QRawVector n = *this; n += l; return n; } + inline QRawVector<T> &operator+=(const T &t) + { append(t); return *this; } + inline QRawVector<T> &operator<< (const T &t) + { append(t); return *this; } + inline QRawVector<T> &operator<<(const QRawVector<T> &l) + { *this += l; return *this; } + + QList<T> toList() const; + + //static QRawVector<T> fromList(const QList<T> &list); + +#ifndef QT_NO_STL + static inline QRawVector<T> fromStdVector(const std::vector<T> &vector) + { QRawVector<T> tmp; qCopy(vector.begin(), vector.end(), std::back_inserter(tmp)); return tmp; } + inline std::vector<T> toStdVector() const + { std::vector<T> tmp; qCopy(constBegin(), constEnd(), std::back_inserter(tmp)); return tmp; } +#endif + +private: + T *allocate(int alloc); + void realloc(int size, int alloc, bool ref); + void free(T *begin, int size); + int sizeOfTypedData() { + // this is more or less the same as sizeof(Data), except that it doesn't + // count the padding at the end + return reinterpret_cast<const char *>(&(reinterpret_cast<const Data *>(this))->array[1]) - reinterpret_cast<const char *>(this); + } + static inline int alignOfTypedData() + { +#ifdef Q_ALIGNOF + return qMax<int>(sizeof(void*), Q_ALIGNOF(Data)); +#else + return 0; +#endif + } + +public: + QVector<T> mutateToVector() + { + Data *d = toBase(m_begin); + d->ref = 1; + d->alloc = m_alloc; + d->size = m_size; + d->sharable = 0; + d->capacity = 0; + + QVector<T> v; + *reinterpret_cast<QVectorData **>(&v) = d; + m_begin = fromBase(0); + m_size = m_alloc = 0; + return v; + } +}; + + +template <typename T> +void QRawVector<T>::reserve(int asize) +{ if (asize > m_alloc) realloc(m_size, asize, false); } +template <typename T> +void QRawVector<T>::resize(int asize) +{ realloc(asize, (asize > m_alloc || (asize < m_size && asize < (m_alloc >> 1))) + ? QVectorData::grow(sizeOfTypedData(), asize, sizeof(T), QTypeInfo<T>::isStatic) + : m_alloc, false); } +template <typename T> +inline void QRawVector<T>::clear() +{ *this = QRawVector<T>(); } +template <typename T> +inline const T &QRawVector<T>::at(int i) const +{ Q_ASSERT_X(i >= 0 && i < m_size, "QRawVector<T>::at", "index out of range"); + return m_begin[i]; } +template <typename T> +inline const T &QRawVector<T>::operator[](int i) const +{ Q_ASSERT_X(i >= 0 && i < m_size, "QRawVector<T>::operator[]", "index out of range"); + return m_begin[i]; } +template <typename T> +inline T &QRawVector<T>::operator[](int i) +{ Q_ASSERT_X(i >= 0 && i < m_size, "QRawVector<T>::operator[]", "index out of range"); + return data()[i]; } +template <typename T> +inline void QRawVector<T>::insert(int i, const T &t) +{ Q_ASSERT_X(i >= 0 && i <= m_size, "QRawVector<T>::insert", "index out of range"); + insert(begin() + i, 1, t); } +template <typename T> +inline void QRawVector<T>::insert(int i, int n, const T &t) +{ Q_ASSERT_X(i >= 0 && i <= m_size, "QRawVector<T>::insert", "index out of range"); + insert(begin() + i, n, t); } +template <typename T> +inline void QRawVector<T>::remove(int i, int n) +{ Q_ASSERT_X(i >= 0 && n >= 0 && i + n <= m_size, "QRawVector<T>::remove", "index out of range"); + erase(begin() + i, begin() + i + n); } +template <typename T> +inline void QRawVector<T>::remove(int i) +{ Q_ASSERT_X(i >= 0 && i < m_size, "QRawVector<T>::remove", "index out of range"); + erase(begin() + i, begin() + i + 1); } +template <typename T> +inline void QRawVector<T>::prepend(const T &t) +{ insert(begin(), 1, t); } + +template <typename T> +inline void QRawVector<T>::replace(int i, const T &t) +{ + Q_ASSERT_X(i >= 0 && i < m_size, "QRawVector<T>::replace", "index out of range"); + const T copy(t); + data()[i] = copy; +} + +template <typename T> +QRawVector<T> &QRawVector<T>::operator=(const QRawVector<T> &v) +{ + if (this != &v) { + free(m_begin, m_size); + m_alloc = v.m_alloc; + m_size = v.m_size; + m_begin = v.m_begin; + realloc(m_size, m_alloc, true); + } + return *this; +} + +template <typename T> +inline T *QRawVector<T>::allocate(int aalloc) +{ + QVectorData *d = QVectorData::allocate(sizeOfTypedData() + (aalloc - 1) * sizeof(T), alignOfTypedData()); + Q_CHECK_PTR(d); + return fromBase(d); +} + +template <typename T> +QRawVector<T>::QRawVector(int asize) +{ + m_size = m_alloc = asize; + m_begin = allocate(asize); + if (QTypeInfo<T>::isComplex) { + T *b = m_begin; + T *i = m_begin + m_size; + while (i != b) + new (--i) T; + } else { + qMemSet(m_begin, 0, asize * sizeof(T)); + } +} + +template <typename T> +QRawVector<T>::QRawVector(int asize, const T &t) +{ + m_size = m_alloc = asize; + m_begin = allocate(asize); + T *i = m_begin + m_size; + while (i != m_begin) + new (--i) T(t); +} + +template <typename T> +void QRawVector<T>::free(T *begin, int size) +{ + if (QTypeInfo<T>::isComplex) { + T *i = begin + size; + while (i-- != begin) + i->~T(); + } + Data *x = toBase(begin); + x->free(x, alignOfTypedData()); +} + +template <typename T> +void QRawVector<T>::realloc(int asize, int aalloc, bool ref) +{ + if (QTypeInfo<T>::isComplex && asize < m_size && !ref) { + // call the destructor on all objects that need to be + // destroyed when shrinking + T *pOld = m_begin + m_size; + while (asize < m_size) { + (--pOld)->~T(); + --m_size; + } + } + + int xalloc = m_alloc; + int xsize = m_size; + bool changed = false; + T *xbegin = m_begin; + if (aalloc != xalloc || ref) { + // (re)allocate memory + if (QTypeInfo<T>::isStatic) { + xbegin = allocate(aalloc); + xsize = 0; + changed = true; + } else if (ref) { + xbegin = allocate(aalloc); + if (QTypeInfo<T>::isComplex) { + xsize = 0; + } else { + ::memcpy(xbegin, m_begin, qMin(aalloc, xalloc) * sizeof(T)); + xsize = m_size; + } + changed = true; + } else { + QT_TRY { + QVectorData *mem = QVectorData::reallocate( + toBase(m_begin), sizeOfTypedData() + (aalloc - 1) * sizeof(T), + sizeOfTypedData() ++ (xalloc - 1) * sizeof(T), alignOfTypedData()); + Q_CHECK_PTR(mem); + xbegin = fromBase(mem); + xsize = m_size; + } QT_CATCH (const std::bad_alloc &) { + if (aalloc > xalloc) // ignore the error in case we are just shrinking. + QT_RETHROW; + } + } + xalloc = aalloc; + } + + if (QTypeInfo<T>::isComplex) { + QT_TRY { + T *pOld = m_begin + xsize; + T *pNew = xbegin + xsize; + // copy objects from the old array into the new array + while (xsize < qMin(asize, m_size)) { + new (pNew++) T(*pOld++); + ++xsize; + } + // construct all new objects when growing + while (xsize < asize) { + new (pNew++) T; + ++xsize; + } + } QT_CATCH (...) { + free(xbegin, xsize); + QT_RETHROW; + } + + } else if (asize > xsize) { + // initialize newly allocated memory to 0 + qMemSet(xbegin + xsize, 0, (asize - xsize) * sizeof(T)); + } + xsize = asize; + + if (changed) { + if (!ref) + free(m_begin, m_size); + } + m_alloc = xalloc; + m_size = xsize; + m_begin = xbegin; +} + +template<typename T> +Q_OUTOFLINE_TEMPLATE T QRawVector<T>::value(int i) const +{ + return (i < 0 || i >= m_size) ? T() : m_begin[i]; +} +template<typename T> +Q_OUTOFLINE_TEMPLATE T QRawVector<T>::value(int i, const T &defaultValue) const +{ + return (i < 0 || i >= m_size) ? defaultValue : m_begin[i]; +} + +template <typename T> +void QRawVector<T>::append(const T &t) +{ + if (m_size + 1 > m_alloc) { + const T copy(t); + realloc(m_size, QVectorData::grow(sizeOfTypedData(), m_size + 1, sizeof(T), + QTypeInfo<T>::isStatic), false); + if (QTypeInfo<T>::isComplex) + new (m_begin + m_size) T(copy); + else + m_begin[m_size] = copy; + } else { + if (QTypeInfo<T>::isComplex) + new (m_begin + m_size) T(t); + else + m_begin[m_size] = t; + } + ++m_size; +} + +template <typename T> +Q_TYPENAME QRawVector<T>::iterator QRawVector<T>::insert(iterator before, size_type n, const T &t) +{ + int offset = int(before - m_begin); + if (n != 0) { + const T copy(t); + if (m_size + n > m_alloc) + realloc(m_size, QVectorData::grow(sizeOfTypedData(), m_size + n, sizeof(T), + QTypeInfo<T>::isStatic), false); + if (QTypeInfo<T>::isStatic) { + T *b = m_begin + m_size; + T *i = m_begin + m_size + n; + while (i != b) + new (--i) T; + i = m_begin + m_size; + T *j = i + n; + b = m_begin + offset; + while (i != b) + *--j = *--i; + i = b+n; + while (i != b) + *--i = copy; + } else { + T *b = m_begin + offset; + T *i = b + n; + memmove(i, b, (m_size - offset) * sizeof(T)); + while (i != b) + new (--i) T(copy); + } + m_size += n; + } + return m_begin + offset; +} + +template <typename T> +Q_TYPENAME QRawVector<T>::iterator QRawVector<T>::erase(iterator abegin, iterator aend) +{ + int f = int(abegin - m_begin); + int l = int(aend - m_begin); + int n = l - f; + if (QTypeInfo<T>::isComplex) { + qCopy(m_begin + l, m_begin + m_size, m_begin + f); + T *i = m_begin + m_size; + T *b = m_begin + m_size - n; + while (i != b) { + --i; + i->~T(); + } + } else { + memmove(m_begin + f, m_begin + l, (m_size - l) * sizeof(T)); + } + m_size -= n; + return m_begin + f; +} + +template <typename T> +bool QRawVector<T>::operator==(const QRawVector<T> &v) const +{ + if (m_size != v.m_size) + return false; + T* b = m_begin; + T* i = b + m_size; + T* j = v.m_begin + m_size; + while (i != b) + if (!(*--i == *--j)) + return false; + return true; +} + +template <typename T> +QRawVector<T> &QRawVector<T>::fill(const T &from, int asize) +{ + const T copy(from); + resize(asize < 0 ? m_size : asize); + if (m_size) { + T *i = m_begin + m_size; + T *b = m_begin; + while (i != b) + *--i = copy; + } + return *this; +} + +template <typename T> +QRawVector<T> &QRawVector<T>::operator+=(const QRawVector &l) +{ + int newSize = m_size + l.m_size; + realloc(m_size, newSize, false); + + T *w = m_begin + newSize; + T *i = l.m_begin + l.m_size; + T *b = l.m_begin; + while (i != b) { + if (QTypeInfo<T>::isComplex) + new (--w) T(*--i); + else + *--w = *--i; + } + m_size = newSize; + return *this; +} + +template <typename T> +int QRawVector<T>::indexOf(const T &t, int from) const +{ + if (from < 0) + from = qMax(from + m_size, 0); + if (from < m_size) { + T* n = m_begin + from - 1; + T* e = m_begin + m_size; + while (++n != e) + if (*n == t) + return n - m_begin; + } + return -1; +} + +template <typename T> +int QRawVector<T>::lastIndexOf(const T &t, int from) const +{ + if (from < 0) + from += m_size; + else if (from >= m_size) + from = m_size-1; + if (from >= 0) { + T* b = m_begin; + T* n = m_begin + from + 1; + while (n != b) { + if (*--n == t) + return n - b; + } + } + return -1; +} + +template <typename T> +bool QRawVector<T>::contains(const T &t) const +{ + T* b = m_begin; + T* i = m_begin + m_size; + while (i != b) + if (*--i == t) + return true; + return false; +} + +template <typename T> +int QRawVector<T>::count(const T &t) const +{ + int c = 0; + T* b = m_begin; + T* i = m_begin + m_size; + while (i != b) + if (*--i == t) + ++c; + return c; +} + +template <typename T> +Q_OUTOFLINE_TEMPLATE QRawVector<T> QRawVector<T>::mid(int pos, int length) const +{ + if (length < 0) + length = size() - pos; + if (pos == 0 && length == size()) + return *this; + QRawVector<T> copy; + if (pos + length > size()) + length = size() - pos; + for (int i = pos; i < pos + length; ++i) + copy += at(i); + return copy; +} + +template <typename T> +Q_OUTOFLINE_TEMPLATE QList<T> QRawVector<T>::toList() const +{ + QList<T> result; + for (int i = 0; i < size(); ++i) + result.append(at(i)); + return result; +} + + +/*template <typename T> +Q_OUTOFLINE_TEMPLATE QRawVector<T> QList<T>::toVector() const +{ + QRawVector<T> result(size()); + for (int i = 0; i < size(); ++i) + result[i] = at(i); + return result; +} + +template <typename T> +QRawVector<T> QRawVector<T>::fromList(const QList<T> &list) +{ + return list.toVector(); +} + +template <typename T> +QList<T> QList<T>::fromVector(const QRawVector<T> &vector) +{ + return vector.toList(); +} +*/ + +Q_DECLARE_SEQUENTIAL_ITERATOR(RawVector) +Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(RawVector) + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QRAWVECTOR_H diff --git a/tests/benchmarks/qvector/qvector.pro b/tests/benchmarks/qvector/qvector.pro new file mode 100644 index 0000000..adb30c9 --- /dev/null +++ b/tests/benchmarks/qvector/qvector.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +TARGET = tst_vector +QT = core +INCLUDEPATH += . +SOURCES += main.cpp outofline.cpp outofline2.cpp +CONFIG += release diff --git a/tests/shared/filesystem.h b/tests/shared/filesystem.h new file mode 100644 index 0000000..2d46c0d --- /dev/null +++ b/tests/shared/filesystem.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +// Helper functions for creating file-system hierarchies and cleaning up. + +#ifndef QT_TESTS_SHARED_FILESYSTEM_H_INCLUDED +#define QT_TESTS_SHARED_FILESYSTEM_H_INCLUDED + +#include <QString> +#include <QStringList> +#include <QDir> +#include <QFile> + +struct FileSystem +{ + ~FileSystem() + { + Q_FOREACH(QString fileName, createdFiles) + QFile::remove(fileName); + + Q_FOREACH(QString dirName, createdDirectories) + currentDir.rmdir(dirName); + } + + bool createDirectory(const QString &dirName) + { + if (currentDir.mkdir(dirName)) { + createdDirectories.prepend(dirName); + return true; + } + return false; + } + + bool createFile(const QString &fileName) + { + QFile file(fileName); + if (file.open(QIODevice::WriteOnly)) { + createdFiles << fileName; + return true; + } + return false; + } + + bool createLink(const QString &destination, const QString &linkName) + { + if (QFile::link(destination, linkName)) { + createdFiles << linkName; + return true; + } + return false; + } + +private: + QDir currentDir; + + QStringList createdDirectories; + QStringList createdFiles; +}; + +#endif // include guard |