diff options
author | Bradley T. Hughes <bradley.hughes@nokia.com> | 2009-06-05 08:09:00 (GMT) |
---|---|---|
committer | Bradley T. Hughes <bradley.hughes@nokia.com> | 2009-06-05 08:09:00 (GMT) |
commit | bb587db95d7c20344c0bf06a1f080c0a2e4a9250 (patch) | |
tree | 50c4615c0c5908bb5a26c1a3ee121dd1f7f070be /tests | |
parent | f26f5b230e614faecce33cf52af0a0d62dcaddaa (diff) | |
parent | 555018baf3115cb2587d2217bf1a5b8f49564ad2 (diff) | |
download | Qt-bb587db95d7c20344c0bf06a1f080c0a2e4a9250.zip Qt-bb587db95d7c20344c0bf06a1f080c0a2e4a9250.tar.gz Qt-bb587db95d7c20344c0bf06a1f080c0a2e4a9250.tar.bz2 |
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt
Diffstat (limited to 'tests')
29 files changed, 612 insertions, 43 deletions
diff --git a/tests/auto/_networkselftest/tst_networkselftest.cpp b/tests/auto/_networkselftest/tst_networkselftest.cpp index dab4433..0fa001a 100644 --- a/tests/auto/_networkselftest/tst_networkselftest.cpp +++ b/tests/auto/_networkselftest/tst_networkselftest.cpp @@ -463,7 +463,7 @@ void tst_NetworkSelfTest::httpsServer() << Chat::expect("200 ") << Chat::DiscardUntilDisconnect); #else - QSKIP("SSL not enabled, cannot test"); + QSKIP("SSL not enabled, cannot test", SkipAll); #endif } diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 27e3c74..a65c172 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -349,7 +349,6 @@ SUBDIRS += _networkselftest \ qtranslator \ qtransform \ qtransformedscreen \ - qtransition \ qtreeview \ qtreewidget \ qtreewidgetitemiterator \ diff --git a/tests/auto/headers/tst_headers.cpp b/tests/auto/headers/tst_headers.cpp index 607d655..7e32deb 100644 --- a/tests/auto/headers/tst_headers.cpp +++ b/tests/auto/headers/tst_headers.cpp @@ -135,6 +135,9 @@ void tst_Headers::licenseCheck() QByteArray data = f.readAll(); QStringList content = QString::fromLocal8Bit(data.replace('\r',"")).split("\n"); + if (content.first().contains("generated")) + content.takeFirst(); + QVERIFY(licensePattern.exactMatch(content.at(7)) || licensePattern.exactMatch(content.at(4))); QString licenseType = licensePattern.cap(1); diff --git a/tests/auto/qcssparser/tst_cssparser.cpp b/tests/auto/qcssparser/tst_cssparser.cpp index 7c4fac1..b41a745 100644 --- a/tests/auto/qcssparser/tst_cssparser.cpp +++ b/tests/auto/qcssparser/tst_cssparser.cpp @@ -1475,7 +1475,7 @@ void tst_CssParser::extractFontFamily_data() QTest::newRow("unquoted-family-name2") << "font-family: Times New Roman" << QString("Times New Roman"); QTest::newRow("multiple") << "font-family: Times New Roman , foobar, 'baz'" << QString("Times New Roman"); QTest::newRow("multiple2") << "font-family: invalid, Times New Roman " << QString("Times New Roman"); - QTest::newRow("invalid") << "font-family: invalid" << QFont().family(); + QTest::newRow("invalid") << "font-family: invalid" << QFontInfo(QFont("invalid font")).family(); QTest::newRow("shorthand") << "font: 12pt Times New Roman" << QString("Times New Roman"); QTest::newRow("shorthand multiple quote") << "font: 12pt invalid, \"Times New Roman\" " << QString("Times New Roman"); QTest::newRow("shorthand multiple") << "font: 12pt invalid, Times New Roman " << QString("Times New Roman"); diff --git a/tests/auto/qdatastream/tst_qdatastream.cpp b/tests/auto/qdatastream/tst_qdatastream.cpp index d7ca7bc..6a69fcc 100644 --- a/tests/auto/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/qdatastream/tst_qdatastream.cpp @@ -462,7 +462,7 @@ void tst_QDataStream::writeQString(QDataStream* s) { QString test(QStringData(dataIndex(QTest::currentDataTag()))); *s << test; - *s << QString("Faen her spyr man"); + *s << QString("Her er det noe tekst"); *s << test; *s << QString(); *s << test; @@ -480,7 +480,7 @@ void tst_QDataStream::readQString(QDataStream *s) *s >> S; QCOMPARE(S, test); *s >> S; - QCOMPARE(S, QString("Faen her spyr man")); + QCOMPARE(S, QString("Her er det noe tekst")); *s >> S; QCOMPARE(S, test); *s >> S; @@ -533,7 +533,7 @@ void tst_QDataStream::writeQRegExp(QDataStream* s) { QRegExp test(QRegExpData(dataIndex(QTest::currentDataTag()))); *s << test; - *s << QString("Faen her spyr man"); + *s << QString("Her er det noe tekst"); *s << test; *s << QString("nonempty"); *s << test; @@ -550,7 +550,7 @@ void tst_QDataStream::readQRegExp(QDataStream *s) *s >> R; QCOMPARE(R, test); *s >> S; - QCOMPARE(S, QString("Faen her spyr man")); + QCOMPARE(S, QString("Her er det noe tekst")); *s >> R; QCOMPARE(R, test); *s >> S; diff --git a/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp b/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp index ad1a1b8..58bfabc 100644 --- a/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp +++ b/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp @@ -84,6 +84,8 @@ private slots: void sendArgument_data(); void sendArgument(); + void sendErrors(); + private: QProcess proc; }; @@ -782,5 +784,28 @@ void tst_QDBusMarshall::sendArgument() QCOMPARE(extracted, value); } +void tst_QDBusMarshall::sendErrors() +{ + QDBusConnection con = QDBusConnection::sessionBus(); + + QVERIFY(con.isConnected()); + QDBusMessage msg = QDBusMessage::createSignal("/foo", "local.interfaceName", + "signalName"); + msg << qVariantFromValue(QDBusObjectPath()); + + QTest::ignoreMessage(QtWarningMsg, "QDBusConnection: error: could not send signal path \"/foo\" interface \"local.interfaceName\" member \"signalName\""); + QVERIFY(!con.send(msg)); + + msg.setArguments(QVariantList()); + QDBusObjectPath path; + + QTest::ignoreMessage(QtWarningMsg, "QDBusObjectPath: invalid path \"abc\""); + path.setPath("abc"); + msg << qVariantFromValue(path); + + QTest::ignoreMessage(QtWarningMsg, "QDBusConnection: error: could not send signal path \"/foo\" interface \"local.interfaceName\" member \"signalName\""); + QVERIFY(!con.send(msg)); +} + QTEST_MAIN(tst_QDBusMarshall) #include "tst_qdbusmarshall.moc" diff --git a/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp index 59d57ce..b109d4b 100644 --- a/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -43,6 +43,7 @@ #include <QtTest/QtTest> #include "../../../src/gui/dialogs/qfilesystemmodel_p.h" #include <QFileIconProvider> +#include <QTreeView> #include "../../shared/util.h" #include <QTime> #include <QStyle> @@ -102,6 +103,7 @@ private slots: void setData_data(); void setData(); + void sort_data(); void sort(); void mkdir(); @@ -452,8 +454,12 @@ void tst_QFileSystemModel::rowsInserted() } else { QCOMPARE(model->index(model->rowCount(root) - 1, 0, root).data().toString(), QString("b")); } - if (spy0.count() > 0) - if (count == 0) QCOMPARE(spy0.count(), 0); else QVERIFY(spy0.count() >= 1); + if (spy0.count() > 0) { + if (count == 0) + QCOMPARE(spy0.count(), 0); + else + QVERIFY(spy0.count() >= 1); + } if (count == 0) QCOMPARE(spy1.count(), 0); else QVERIFY(spy1.count() >= 1); QVERIFY(createFiles(tmp, QStringList(".hidden_file"), 5 + count)); @@ -722,6 +728,19 @@ void tst_QFileSystemModel::setData() QTRY_COMPARE(model->rowCount(root), files.count()); } +class MyFriendFileSystemModel : public QFileSystemModel +{ + friend class tst_QFileSystemModel; + Q_DECLARE_PRIVATE(QFileSystemModel) +}; + +void tst_QFileSystemModel::sort_data() +{ + QTest::addColumn<bool>("fileDialogMode"); + QTest::newRow("standard usage") << false; + QTest::newRow("QFileDialog usage") << true; +} + void tst_QFileSystemModel::sort() { QTemporaryFile file; @@ -733,8 +752,48 @@ void tst_QFileSystemModel::sort() model->sort(0, Qt::AscendingOrder); model->sort(0, Qt::DescendingOrder); QVERIFY(idx.column() != 0); -} + QFETCH(bool, fileDialogMode); + + MyFriendFileSystemModel *myModel = new MyFriendFileSystemModel(); + QTreeView *tree = new QTreeView(); + + if (fileDialogMode) + myModel->d_func()->disableRecursiveSort = true; + + const QString dirPath = QString("%1/sortTemp").arg(QDir::tempPath()); + QDir dir(dirPath); + dir.mkpath(dirPath); + QVERIFY(dir.exists()); + dir.mkdir("a"); + dir.mkdir("b"); + dir.mkdir("c"); + dir.mkdir("d"); + dir.mkdir("e"); + dir.mkdir("f"); + dir.mkdir("g"); + QTemporaryFile tempFile(dirPath + "/rXXXXXX"); + tempFile.open(); + myModel->setRootPath(QDir::rootPath()); + tree->setModel(myModel); + tree->show(); + QTest::qWait(500); + tree->expand(myModel->index(dir.absolutePath(), 0)); + while (dir.cdUp()) + { + tree->expand(myModel->index(dir.absolutePath(), 0)); + } + QTest::qWait(250); + //File dialog Mode means sub trees are not sorted, only the current root + if (fileDialogMode) + QVERIFY(myModel->index(0, 1, myModel->index(dirPath, 0)).data(QFileSystemModel::FilePathRole).toString() != dirPath + QLatin1String("/a")); + else + QCOMPARE(myModel->index(0, 1, myModel->index(dirPath, 0)).data(QFileSystemModel::FilePathRole).toString(), dirPath + QLatin1String("/a")); + + delete tree; + delete myModel; + +} void tst_QFileSystemModel::mkdir() { diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp index a23ada9..56d42c3 100644 --- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp @@ -51,6 +51,7 @@ #include <qlineedit.h> #include <qboxlayout.h> #include <qaction.h> +#include <qwidgetaction.h> #include "../../shared/util.h" @@ -153,6 +154,7 @@ private slots: void popupMouseGrabber(); void windowFlags_data(); void windowFlags(); + void shortcutsDeletion(); // Task fixes void task236127_bspTreeIndexFails(); @@ -2266,6 +2268,20 @@ void tst_QGraphicsWidget::windowFlags() QCOMPARE(widget5->windowFlags(), Qt::WindowFlags(outputFlags)); } +void tst_QGraphicsWidget::shortcutsDeletion() +{ + QGraphicsWidget *widget = new QGraphicsWidget; + QGraphicsWidget *widget2 = new QGraphicsWidget; + widget->setMinimumSize(40, 40); + QWidgetAction *del = new QWidgetAction(widget); + del->setIcon(QIcon("edit-delete")); + del->setShortcut(Qt::Key_Delete); + del->setShortcutContext(Qt::WidgetShortcut); + widget2->addAction(del); + widget2->addAction(del); + delete widget; +} + class ProxyStyle : public QCommonStyle { public: diff --git a/tests/auto/qicon/tst_qicon.cpp b/tests/auto/qicon/tst_qicon.cpp index 4e9a880..1dd223f 100644 --- a/tests/auto/qicon/tst_qicon.cpp +++ b/tests/auto/qicon/tst_qicon.cpp @@ -72,6 +72,8 @@ private slots: void svg(); void addFile(); void availableSizes(); + void streamAvailableSizes_data(); + void streamAvailableSizes(); void task184901_badCache(); void task223279_inconsistentAddFile(); @@ -540,6 +542,47 @@ void tst_QIcon::availableSizes() } } +void tst_QIcon::streamAvailableSizes_data() +{ + QTest::addColumn<QIcon>("icon"); + + QIcon icon; + icon.addFile(":/image.png", QSize(32,32)); + QTest::newRow( "32x32" ) << icon; + icon.addFile(":/image.png", QSize(64,64)); + QTest::newRow( "64x64" ) << icon; + icon.addFile(":/image.png", QSize(128,128)); + QTest::newRow( "128x128" ) << icon; + icon.addFile(":/image.png", QSize(256,256)); + QTest::newRow( "256x256" ) << icon; +} + +void tst_QIcon::streamAvailableSizes() +{ + QFETCH(QIcon, icon); + + QByteArray ba; + // write to QByteArray + { + QBuffer buffer(&ba); + buffer.open(QIODevice::WriteOnly); + QDataStream stream(&buffer); + stream << icon; + } + + // read from QByteArray + { + QBuffer buffer(&ba); + buffer.open(QIODevice::ReadOnly); + QDataStream stream(&buffer); + QIcon i; + stream >> i; + QCOMPARE(i.isNull(), icon.isNull()); + QCOMPARE(i.availableSizes(), icon.availableSizes()); + } +} + + static inline bool operator<(const QSize &lhs, const QSize &rhs) { if (lhs.width() < rhs.width()) diff --git a/tests/auto/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/qlocalsocket/tst_qlocalsocket.cpp index 785eab0..ac26075 100644 --- a/tests/auto/qlocalsocket/tst_qlocalsocket.cpp +++ b/tests/auto/qlocalsocket/tst_qlocalsocket.cpp @@ -115,8 +115,6 @@ tst_QLocalSocket::tst_QLocalSocket() #endif )) qWarning() << "lackey executable doesn't exists!"; - - QLocalServer::removeServer("tst_localsocket"); } tst_QLocalSocket::~tst_QLocalSocket() @@ -141,7 +139,13 @@ public: LocalServer() : QLocalServer() { connect(this, SIGNAL(newConnection()), this, SLOT(slotNewConnection())); - }; + } + + bool listen(const QString &name) + { + removeServer(name); + return QLocalServer::listen(name); + } QList<int> hits; @@ -530,7 +534,7 @@ void tst_QLocalSocket::sendData() // QLocalSocket/Server can take a name or path, check that it works as expected void tst_QLocalSocket::fullPath() { - QLocalServer server; + LocalServer server; QString name = "qlocalsocket_pathtest"; #if defined(QT_LOCALSOCKET_TCP) QString path = "QLocalServer"; @@ -824,7 +828,7 @@ void tst_QLocalSocket::removeServer() void tst_QLocalSocket::recycleServer() { - QLocalServer server; + LocalServer server; QLocalSocket client; QVERIFY(server.listen("recycletest1")); diff --git a/tests/auto/qnetworkdiskcache/tst_qnetworkdiskcache.cpp b/tests/auto/qnetworkdiskcache/tst_qnetworkdiskcache.cpp index 2383767..2f6180f 100644 --- a/tests/auto/qnetworkdiskcache/tst_qnetworkdiskcache.cpp +++ b/tests/auto/qnetworkdiskcache/tst_qnetworkdiskcache.cpp @@ -76,7 +76,7 @@ private slots: void oldCacheVersionFile_data(); void oldCacheVersionFile(); - + void sync(); }; @@ -486,7 +486,7 @@ public: void run() { QByteArray longString = "Hello World, this is some long string, well not really that long"; - for (int i = 0; i < 10; ++i) + for (int j = 0; j < 10; ++j) longString += longString; QByteArray longString2 = "Help, I am stuck in an autotest!"; QUrl url(EXAMPLE_URL); diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp index 87f9c13..c0f9935 100644 --- a/tests/auto/qpainter/tst_qpainter.cpp +++ b/tests/auto/qpainter/tst_qpainter.cpp @@ -215,6 +215,7 @@ private slots: void imageCoordinateLimit(); void imageBlending_data(); void imageBlending(); + void imageBlending_clipped(); void paintOnNullPixmap(); void checkCompositionMode(); @@ -226,6 +227,7 @@ private slots: void extendedBlendModes(); void zeroOpacity(); + void clippingBug(); private: void fillData(); @@ -3792,6 +3794,31 @@ void tst_QPainter::imageBlending() } } +void tst_QPainter::imageBlending_clipped() +{ + QImage src(20, 20, QImage::Format_RGB16); + QPainter p(&src); + p.fillRect(src.rect(), Qt::red); + p.end(); + + QImage dst(40, 20, QImage::Format_RGB16); + p.begin(&dst); + p.fillRect(dst.rect(), Qt::white); + p.end(); + + QImage expected = dst; + + p.begin(&dst); + p.setClipRect(QRect(23, 0, 20, 20)); + + // should be completely clipped + p.drawImage(QRectF(3, 0, 20, 20), src); + p.end(); + + // dst should be left unchanged + QCOMPARE(dst, expected); +} + void tst_QPainter::paintOnNullPixmap() { QPixmap pix(16, 16); @@ -4168,5 +4195,28 @@ void tst_QPainter::zeroOpacity() QCOMPARE(target.pixel(0, 0), 0xff000000); } +void tst_QPainter::clippingBug() +{ + QImage img(32, 32, QImage::Format_ARGB32_Premultiplied); + img.fill(0); + + QImage expected = img; + QPainter p(&expected); + p.fillRect(1, 1, 30, 30, Qt::red); + p.end(); + + QPainterPath path; + path.addRect(1, 1, 30, 30); + path.addRect(1, 1, 30, 30); + path.addRect(1, 1, 30, 30); + + p.begin(&img); + p.setClipPath(path); + p.fillRect(0, 0, 32, 32, Qt::red); + p.end(); + + QCOMPARE(img, expected); +} + QTEST_MAIN(tst_QPainter) #include "tst_qpainter.moc" diff --git a/tests/auto/qprogressbar/tst_qprogressbar.cpp b/tests/auto/qprogressbar/tst_qprogressbar.cpp index d6379d3..cb037e0 100644 --- a/tests/auto/qprogressbar/tst_qprogressbar.cpp +++ b/tests/auto/qprogressbar/tst_qprogressbar.cpp @@ -63,6 +63,7 @@ private slots: void setValueRepaint(); void sizeHint(); + void task245201_testChangeStyleAndDelete_data(); void task245201_testChangeStyleAndDelete(); }; @@ -224,15 +225,30 @@ void tst_QProgressBar::sizeHint() QCOMPARE(barSize.height(), size.height()); } +void tst_QProgressBar::task245201_testChangeStyleAndDelete_data() +{ + QTest::addColumn<QString>("style1_str"); + QTest::addColumn<QString>("style2_str"); + + QTest::newRow("plastique-windows") << QString::fromLatin1("plastique") << QString::fromLatin1("windows"); + QTest::newRow("mlotif-windows") << QString::fromLatin1("motif") << QString::fromLatin1("windows"); + QTest::newRow("cleanlooks-cde") << QString::fromLatin1("cleanlooks") << QString::fromLatin1("cde"); + QTest::newRow("gtk-plastique") << QString::fromLatin1("gtk") << QString::fromLatin1("plastique"); +} + void tst_QProgressBar::task245201_testChangeStyleAndDelete() { + QFETCH(QString, style1_str); + QFETCH(QString, style2_str); + QProgressBar *bar = new QProgressBar; - QStyle *style = QStyleFactory::create("plastique"); + QStyle *style = QStyleFactory::create(style1_str); bar->setStyle(style); bar->show(); - QStyle *style2 = QStyleFactory::create("windows"); + QStyle *style2 = QStyleFactory::create(style2_str); bar->setStyle(style2); + QTest::qWait(10); delete bar; QTest::qWait(100); //should not crash diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index 5339fb4..fe60cd0 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -636,9 +636,21 @@ void tst_QScriptEngine::newQObject() QScriptValue val = ret.property("objectName"); QVERIFY(val.isString()); } + // "promote" variant object to QObject + { + QScriptValue obj = eng.newVariant(123); + QVERIFY(obj.isVariant()); + QScriptValue originalProto = obj.prototype(); + QScriptValue ret = eng.newQObject(obj, this); + QVERIFY(ret.isQObject()); + QVERIFY(ret.strictlyEquals(obj)); + QVERIFY(obj.isQObject()); + QCOMPARE(ret.toQObject(), (QObject *)this); + QVERIFY(ret.prototype().strictlyEquals(originalProto)); + } // replace QObject* of existing object { - QScriptValue object = eng.newQObject(this); + QScriptValue object = eng.newVariant(123); QScriptValue originalProto = object.prototype(); QObject otherQObject; QScriptValue ret = eng.newQObject(object, &otherQObject); diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 768a683..66e50ba 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -1768,6 +1768,34 @@ void tst_QStateMachine::signalTransitions() QState *s0 = new QState(machine.rootState()); QFinalState *s1 = new QFinalState(machine.rootState()); SignalEmitter emitter; + QSignalTransition *trans = s0->addTransition(&emitter, "signalWithNoArg()", s1); + QVERIFY(trans != 0); + QCOMPARE(trans->sourceState(), s0); + QCOMPARE(trans->targetState(), (QAbstractState*)s1); + QCOMPARE(trans->senderObject(), (QObject*)&emitter); + QCOMPARE(trans->signal(), QByteArray("signalWithNoArg()")); + + QSignalSpy finishedSpy(&machine, SIGNAL(finished())); + machine.setInitialState(s0); + machine.start(); + QCoreApplication::processEvents(); + + emitter.emitSignalWithNoArg(); + + QTRY_COMPARE(finishedSpy.count(), 1); + + trans->setSignal("signalWithIntArg(int)"); + QCOMPARE(trans->signal(), QByteArray("signalWithIntArg(int)")); + machine.start(); + QCoreApplication::processEvents(); + emitter.emitSignalWithIntArg(123); + QTRY_COMPARE(finishedSpy.count(), 2); + } + { + QStateMachine machine; + QState *s0 = new QState(machine.rootState()); + QFinalState *s1 = new QFinalState(machine.rootState()); + SignalEmitter emitter; TestSignalTransition *trans = new TestSignalTransition(&emitter, SIGNAL(signalWithIntArg(int)), s1); s0->addTransition(trans); diff --git a/tests/auto/qstringbuilder/qstringbuilder.pro b/tests/auto/qstringbuilder/qstringbuilder.pro new file mode 100644 index 0000000..c5a26d3 --- /dev/null +++ b/tests/auto/qstringbuilder/qstringbuilder.pro @@ -0,0 +1,5 @@ + +TEMPLATE = subdirs +SUBDIRS = scenario1.pro scenario2.pro scenario3.pro scenario4.pro + + diff --git a/tests/auto/qstringbuilder/scenario1.cpp b/tests/auto/qstringbuilder/scenario1.cpp new file mode 100644 index 0000000..26b4ed3 --- /dev/null +++ b/tests/auto/qstringbuilder/scenario1.cpp @@ -0,0 +1 @@ +#include "tst_qstringbuilder.cpp" diff --git a/tests/auto/qstringbuilder/scenario1.pro b/tests/auto/qstringbuilder/scenario1.pro new file mode 100644 index 0000000..4ce7156 --- /dev/null +++ b/tests/auto/qstringbuilder/scenario1.pro @@ -0,0 +1,8 @@ +load(qttest_p4) + +QT = core + +SOURCES += scenario1.cpp + +DEFINES += SCENARIO=1 + diff --git a/tests/auto/qstringbuilder/scenario2.cpp b/tests/auto/qstringbuilder/scenario2.cpp new file mode 100644 index 0000000..26b4ed3 --- /dev/null +++ b/tests/auto/qstringbuilder/scenario2.cpp @@ -0,0 +1 @@ +#include "tst_qstringbuilder.cpp" diff --git a/tests/auto/qstringbuilder/scenario2.pro b/tests/auto/qstringbuilder/scenario2.pro new file mode 100644 index 0000000..64c46e2 --- /dev/null +++ b/tests/auto/qstringbuilder/scenario2.pro @@ -0,0 +1,7 @@ +load(qttest_p4) + +QT = core + +SOURCES += scenario2.cpp + +DEFINES += SCENARIO=2 diff --git a/tests/auto/qstringbuilder/scenario3.cpp b/tests/auto/qstringbuilder/scenario3.cpp new file mode 100644 index 0000000..26b4ed3 --- /dev/null +++ b/tests/auto/qstringbuilder/scenario3.cpp @@ -0,0 +1 @@ +#include "tst_qstringbuilder.cpp" diff --git a/tests/auto/qstringbuilder/scenario3.pro b/tests/auto/qstringbuilder/scenario3.pro new file mode 100644 index 0000000..beedffd --- /dev/null +++ b/tests/auto/qstringbuilder/scenario3.pro @@ -0,0 +1,7 @@ +load(qttest_p4) + +QT = core + +SOURCES += scenario3.cpp + +DEFINES += SCENARIO=3 diff --git a/tests/auto/qstringbuilder/scenario4.cpp b/tests/auto/qstringbuilder/scenario4.cpp new file mode 100644 index 0000000..26b4ed3 --- /dev/null +++ b/tests/auto/qstringbuilder/scenario4.cpp @@ -0,0 +1 @@ +#include "tst_qstringbuilder.cpp" diff --git a/tests/auto/qstringbuilder/scenario4.pro b/tests/auto/qstringbuilder/scenario4.pro new file mode 100644 index 0000000..1c45a70 --- /dev/null +++ b/tests/auto/qstringbuilder/scenario4.pro @@ -0,0 +1,7 @@ +load(qttest_p4) + +QT = core + +SOURCES += scenario4.cpp + +DEFINES += SCENARIO=4 diff --git a/tests/auto/qstringbuilder/tst_qstringbuilder.cpp b/tests/auto/qstringbuilder/tst_qstringbuilder.cpp new file mode 100644 index 0000000..f5df79e --- /dev/null +++ b/tests/auto/qstringbuilder/tst_qstringbuilder.cpp @@ -0,0 +1,182 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// This is included in various .cpp files as a compile test for various scenarios +// depending on NO_CAST_* and QT_USE_FAST_OPERATOR_PLUS and QT_USE_FAST_CONCATENATION + +#if SCENARIO == 1 +// this is the "no harm done" version. Only operator% is active, +// with NO_CAST * defined +#define P % +#undef QT_USE_FAST_OPERATOR_PLUS +#undef QT_USE_FAST_CONCATENATION +#define QT_NO_CAST_FROM_ASCII +#define QT_NO_CAST_TO_ASCII +#endif + + +#if SCENARIO == 2 +// this is the "full" version. Operator+ is replaced by a QStringBuilder +// based version +// with NO_CAST * defined +#define P + +#define QT_USE_FAST_OPERATOR_PLUS +#define QT_USE_FAST_CONCATENATION +#define QT_NO_CAST_FROM_ASCII +#define QT_NO_CAST_TO_ASCII +#endif + +#if SCENARIO == 3 +// this is the "no harm done" version. Only operator% is active, +// with NO_CAST * _not_ defined +#define P % +#undef QT_USE_FAST_OPERATOR_PLUS +#undef QT_USE_FAST_CONCATENATION +#undef QT_NO_CAST_FROM_ASCII +#undef QT_NO_CAST_TO_ASCII +#endif + +#if SCENARIO == 4 +// this is the "full" version. Operator+ is replaced by a QStringBuilder +// based version +// with NO_CAST * _not_ defined +#define P + +#define QT_USE_FAST_OPERATOR_PLUS +#define QT_USE_FAST_CONCATENATION +#undef QT_NO_CAST_FROM_ASCII +#undef QT_NO_CAST_TO_ASCII +#endif + + +#include <QtTest/QtTest> + +//TESTED_CLASS=QStringBuilder +//TESTED_FILES=qstringbuilder.cpp + +#include <qtest.h> + +#define LITERAL "some literal" + +#ifndef QT_NO_CAST_FROM_ASCII + +// Plan is to move the QConcatenable specialications below +// to qstringbuilder.h as soon as the QByteArray builder is +// implemented. + +QT_BEGIN_NAMESPACE + +template <int N> struct QConcatenable<char[N]> +{ + typedef char type[N]; + static int size(const char *) { return N - 1; } + static inline void appendTo(const type &a, QChar *&out) + { + memcpy(out, a, N - 1); + out += N - 1; + } +}; + +template <int N> struct QConcatenable<const char[N]> +{ + typedef char type[N]; + static int size(const char *) { return N - 1; } + static inline void appendTo(const type &a, QChar *&out) + { + memcpy(out, a, N - 1); + out += N - 1; + } +}; + +QT_END_NAMESPACE + +#endif + + +class tst_QStringBuilder : public QObject +{ + Q_OBJECT + +public: + tst_QStringBuilder() {} + ~tst_QStringBuilder() {} + +public slots: + void init() {} + void cleanup() {} + + void scenario(); +}; + +void tst_QStringBuilder::scenario() +{ + QLatin1Literal l1literal(LITERAL); + QLatin1String l1string(LITERAL); + QString string(l1string); + QStringRef stringref(&string, 2, 10); + QLatin1Char achar('c'); + QString r2(QLatin1String(LITERAL LITERAL)); + QString r; + + r = l1literal P l1literal; + QCOMPARE(r, r2); + r = string P string; + QCOMPARE(r, r2); + r = stringref P stringref; + QCOMPARE(r, QString(stringref.toString() + stringref.toString())); + r = string P l1literal; + QCOMPARE(r, r2); + r = string P l1string; + QCOMPARE(r, r2); + r = string + achar; + QCOMPARE(r, QString(string P achar)); + r = achar + string; + QCOMPARE(r, QString(achar P string)); +#ifndef QT_NO_CAST_FROM_ASCII + r = string P LITERAL; + QCOMPARE(r, r2); + r = LITERAL P string; + QCOMPARE(r, r2); +#endif +} + +QTEST_APPLESS_MAIN(tst_QStringBuilder) + +#include "tst_qstringbuilder.moc" diff --git a/tests/auto/qtextcodec/tst_qtextcodec.cpp b/tests/auto/qtextcodec/tst_qtextcodec.cpp index 22f9557..97c409b 100644 --- a/tests/auto/qtextcodec/tst_qtextcodec.cpp +++ b/tests/auto/qtextcodec/tst_qtextcodec.cpp @@ -1540,7 +1540,7 @@ void tst_QTextCodec::utfHeaders_data() << QByteArray("\xef\xbb\xbfhello") << (QString(QChar(0xfeff)) + QString::fromLatin1("hello")) << true; - QTest::newRow("utf8 nobom") + QTest::newRow("utf8 nobom ignore header") << QByteArray("UTF-8") << (int)QTextCodec::IgnoreHeader << QByteArray("hello") @@ -1721,14 +1721,23 @@ void tst_QTextCodec::utfHeaders() QFETCH(bool, toUnicode); + QLatin1String ignoreReverseTestOn = (QSysInfo::ByteOrder == QSysInfo::BigEndian) ? QLatin1String(" le") : QLatin1String(" be"); + QString rowName(QTest::currentDataTag()); + for (int i = 0; i < encoded.length(); ++i) qDebug() << hex << " " << (uint)(uchar)encoded.at(i); if (toUnicode) { QString result = codec->toUnicode(encoded.constData(), encoded.length(), &state); - for (int i = 0; i < result.length(); ++i) - qDebug() << hex << " " << (uint)result.at(i).unicode(); + for (int i = 0; i < result.length(); ++i) + qDebug() << hex << " " << (uint)result.at(i).unicode(); QCOMPARE(result.length(), unicode.length()); QCOMPARE(result, unicode); + + if (!rowName.endsWith("nobom") && !rowName.contains(ignoreReverseTestOn)) { + QTextCodec::ConverterState state2(cFlags); + QByteArray reencoded = codec->fromUnicode(unicode.unicode(), unicode.length(), &state2); + QCOMPARE(reencoded, encoded); + } } else { QByteArray result = codec->fromUnicode(unicode.unicode(), unicode.length(), &state); QCOMPARE(result, encoded); diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index 23ead01..3fad366 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -350,6 +350,9 @@ private slots: void updateOnDestroyedSignal(); void toplevelLineEditFocus(); + void focusWidget_task254563(); + void focusWidget_mixed_widget_hierarchy(); + private: bool ensureScreenSize(int width, int height); QWidget *testWidget; @@ -8977,5 +8980,37 @@ void tst_QWidget::toplevelLineEditFocus() QCOMPARE(QApplication::focusWidget(), &w); } +void tst_QWidget::focusWidget_task254563() +{ + //having different visibility for widget is important + QWidget top; + top.show(); + QWidget container(&top); + QWidget *widget = new QWidget(&container); + widget->show(); + + widget->setFocus(); //set focus (will set the focus widget up to the toplevel to be 'widget') + container.setFocus(); + delete widget; // will call clearFocus but that doesn't help + QVERIFY(top.focusWidget() != widget); //dangling pointer +} + +void tst_QWidget::focusWidget_mixed_widget_hierarchy() +{ + QWidget top; + top.show(); + QWidget notvisible(&top); + QWidget *visible = new QWidget(¬visible); + visible->show(); + + visible->setFocus(); + notvisible.setFocus(); + notvisible.show(); + QCOMPARE(top.focusWidget(), visible); + QCOMPARE(notvisible.focusWidget(), visible); + QCOMPARE(visible->focusWidget(), visible); +} + + QTEST_MAIN(tst_QWidget) #include "tst_qwidget.moc" diff --git a/tests/benchmarks/qpixmapcache/tst_qpixmapcache.cpp b/tests/benchmarks/qpixmapcache/tst_qpixmapcache.cpp index f3c1134..9dafff5 100644 --- a/tests/benchmarks/qpixmapcache/tst_qpixmapcache.cpp +++ b/tests/benchmarks/qpixmapcache/tst_qpixmapcache.cpp @@ -156,9 +156,9 @@ struct styleStruct { int height; bool operator==(const styleStruct &str) const { - return str.key == key && str.state == state && str.direction == direction + return str.state == state && str.direction == direction && str.complex == complex && str.palette == palette && str.width == width - && str.height == height; + && str.height == height && str.key == key; } }; diff --git a/tests/benchmarks/qstringbuilder/main.cpp b/tests/benchmarks/qstringbuilder/main.cpp index d4e2fa0..8b769a6 100644 --- a/tests/benchmarks/qstringbuilder/main.cpp +++ b/tests/benchmarks/qstringbuilder/main.cpp @@ -1,6 +1,6 @@ // Select one of the scenarios below -#define SCENARIO 3 +#define SCENARIO 1 #if SCENARIO == 1 // this is the "no harm done" version. Only operator% is active, @@ -17,7 +17,7 @@ // this is the "full" version. Operator+ is replaced by a QStringBuilder // based version // with NO_CAST * defined -#define P % +#define P + #define QT_USE_FAST_OPERATOR_PLUS #define QT_USE_FAST_CONCATENATION #define QT_NO_CAST_FROM_ASCII @@ -38,7 +38,7 @@ // this is the "full" version. Operator+ is replaced by a QStringBuilder // based version // with NO_CAST * _not_ defined -#define P % +#define P + #define QT_USE_FAST_OPERATOR_PLUS #define QT_USE_FAST_CONCATENATION #undef QT_NO_CAST_FROM_ASCII @@ -53,6 +53,8 @@ #include <qtest.h> +#include <string> + #define COMPARE(a, b) QCOMPARE(a, b) //#define COMPARE(a, b) @@ -70,6 +72,7 @@ public: l1string(LITERAL), ba(LITERAL), string(l1string), + stdstring(LITERAL), stringref(&string, 2, 10), achar('c'), r2(QLatin1String(LITERAL LITERAL)), @@ -115,8 +118,9 @@ public: private slots: void separator_0() { - qDebug() << "\nIn each block the QStringBuilder based result appear first, " - "QStringBased second.\n"; + qDebug() << "\nIn each block the QStringBuilder based result appear first " + "(with a 'b_' prefix), QStringBased second ('q_' prefix), std::string " + "last ('s_' prefix)\n"; } void separator_1() { SEP("literal + literal (builder first)"); } @@ -131,7 +135,7 @@ private slots: COMPARE(r, r2); } #endif - void s_2_l1string() { + void q_2_l1string() { QBENCHMARK { r = l1string + l1string; } COMPARE(r, r2); } @@ -143,10 +147,14 @@ private slots: QBENCHMARK { r = string P string; } COMPARE(r, r2); } - void s_2_string() { + void q_2_string() { QBENCHMARK { r = string + string; } COMPARE(r, r2); } + void s_2_string() { + QBENCHMARK { stdr = stdstring + stdstring; } + COMPARE(stdr, stdstring + stdstring); + } void separator_2c() { SEP("2 string refs"); } @@ -155,7 +163,7 @@ private slots: QBENCHMARK { r = stringref % stringref; } COMPARE(r, QString(stringref.toString() + stringref.toString())); } - void s_2_stringref() { + void q_2_stringref() { QBENCHMARK { r = stringref.toString() + stringref.toString(); } COMPARE(r, QString(stringref % stringref)); } @@ -167,10 +175,30 @@ private slots: QBENCHMARK { r = string P string P string; } COMPARE(r, r3); } - void s_3_string() { + void q_3_string() { QBENCHMARK { r = string + string + string; } COMPARE(r, r3); } + void s_3_string() { + QBENCHMARK { stdr = stdstring + stdstring + stdstring; } + COMPARE(stdr, stdstring + stdstring + stdstring); + } + + void separator_2e() { SEP("4 strings"); } + + void b_4_string() { + QBENCHMARK { r = string P string P string P string; } + COMPARE(r, r4); + } + void q_4_string() { + QBENCHMARK { r = string + string + string + string; } + COMPARE(r, r4); + } + void s_4_string() { + QBENCHMARK { stdr = stdstring + stdstring + stdstring + stdstring; } + COMPARE(stdr, stdstring + stdstring + stdstring + stdstring); + } + void separator_2a() { SEP("string + literal (builder first)"); } @@ -193,14 +221,18 @@ private slots: QBENCHMARK { r = string P l1string; } COMPARE(r, r2); } - void s_string_l1literal() { + void q_string_l1literal() { QBENCHMARK { r = string + l1string; } COMPARE(r, r2); } - void s_string_l1string() { + void q_string_l1string() { QBENCHMARK { r = string + l1string; } COMPARE(r, r2); } + void s_LITERAL_string() { + QBENCHMARK { stdr = LITERAL + stdstring; } + COMPARE(stdr, stdstring + stdstring); + } void separator_3() { SEP("3 literals"); } @@ -209,10 +241,14 @@ private slots: QBENCHMARK { r = l1literal P l1literal P l1literal; } COMPARE(r, r3); } - void s_3_l1string() { + void q_3_l1string() { QBENCHMARK { r = l1string + l1string + l1string; } COMPARE(r, r3); } + void s_3_l1string() { + QBENCHMARK { stdr = stdstring + LITERAL + LITERAL; } + COMPARE(stdr, stdstring + stdstring + stdstring); + } void separator_4() { SEP("4 literals"); } @@ -221,7 +257,7 @@ private slots: QBENCHMARK { r = l1literal P l1literal P l1literal P l1literal; } COMPARE(r, r4); } - void s_4_l1string() { + void q_4_l1string() { QBENCHMARK { r = l1string + l1string + l1string + l1string; } COMPARE(r, r4); } @@ -234,7 +270,7 @@ private slots: COMPARE(r, r5); } - void s_5_l1string() { + void q_5_l1string() { QBENCHMARK { r = l1string + l1string + l1string + l1string + l1string; } COMPARE(r, r5); } @@ -247,11 +283,16 @@ private slots: COMPARE(r, QString(string P achar P achar P achar P achar)); } - void s_string_4_char() { + void q_string_4_char() { QBENCHMARK { r = string + achar + achar + achar + achar; } COMPARE(r, QString(string P achar P achar P achar P achar)); } + void s_string_4_char() { + QBENCHMARK { stdr = stdstring + 'c' + 'c' + 'c' + 'c'; } + COMPARE(stdr, stdstring + 'c' + 'c' + 'c' + 'c'); + } + void separator_7() { SEP("char + string + char"); } @@ -260,11 +301,17 @@ private slots: COMPARE(r, QString(achar P string P achar)); } - void s_char_string_char() { + void q_char_string_char() { QBENCHMARK { r = achar + string + achar; } COMPARE(r, QString(achar P string P achar)); } + void s_char_string_char() { + QBENCHMARK { stdr = 'c' + stdstring + 'c'; } + COMPARE(stdr, 'c' + stdstring + 'c'); + } + + void separator_8() { SEP("string.arg"); } void b_string_arg() { @@ -273,13 +320,13 @@ private slots: COMPARE(r, r3); } - void s_string_arg() { + void q_string_arg() { const QString pattern = l1string + QLatin1String("%1") + l1string; QBENCHMARK { r = pattern.arg(string); } COMPARE(r, r3); } - void s_bytearray_arg() { + void q_bytearray_arg() { QByteArray result; QBENCHMARK { result = ba + ba + ba; } } @@ -331,11 +378,14 @@ private: const QLatin1String l1string; const QByteArray ba; const QString string; + const std::string stdstring; const QStringRef stringref; const QLatin1Char achar; const QString r2, r3, r4, r5; + // short cuts for results QString r; + std::string stdr; }; |