diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qbuffer/tst_qbuffer.cpp | 50 | ||||
-rw-r--r-- | tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 58 | ||||
-rw-r--r-- | tests/auto/qsocketnotifier/tst_qsocketnotifier.cpp | 18 | ||||
-rw-r--r-- | tests/benchmarks/corelib/tools/qstring/main.cpp | 100 |
4 files changed, 211 insertions, 15 deletions
diff --git a/tests/auto/qbuffer/tst_qbuffer.cpp b/tests/auto/qbuffer/tst_qbuffer.cpp index 776935d..bf4842f 100644 --- a/tests/auto/qbuffer/tst_qbuffer.cpp +++ b/tests/auto/qbuffer/tst_qbuffer.cpp @@ -56,6 +56,7 @@ public: tst_QBuffer(); private slots: + void open(); void getSetCheck(); void readBlock(); void readBlockPastEnd(); @@ -104,6 +105,55 @@ tst_QBuffer::tst_QBuffer() { } +void tst_QBuffer::open() +{ + QByteArray data(10, 'f'); + + QBuffer b; + + QTest::ignoreMessage(QtWarningMsg, "QBuffer::open: Buffer access not specified"); + QVERIFY(!b.open(QIODevice::NotOpen)); + QVERIFY(!b.isOpen()); + b.close(); + + QTest::ignoreMessage(QtWarningMsg, "QBuffer::open: Buffer access not specified"); + QVERIFY(!b.open(QIODevice::Text)); + QVERIFY(!b.isOpen()); + b.close(); + + QTest::ignoreMessage(QtWarningMsg, "QBuffer::open: Buffer access not specified"); + QVERIFY(!b.open(QIODevice::Unbuffered)); + QVERIFY(!b.isOpen()); + b.close(); + + QVERIFY(b.open(QIODevice::ReadOnly)); + QVERIFY(b.isReadable()); + b.close(); + + QVERIFY(b.open(QIODevice::WriteOnly)); + QVERIFY(b.isWritable()); + b.close(); + + b.setData(data); + QVERIFY(b.open(QIODevice::Append)); + QVERIFY(b.isWritable()); + QCOMPARE(b.size(), qint64(10)); + QCOMPARE(b.pos(), b.size()); + b.close(); + + b.setData(data); + QVERIFY(b.open(QIODevice::Truncate)); + QVERIFY(b.isWritable()); + QCOMPARE(b.size(), qint64(0)); + QCOMPARE(b.pos(), qint64(0)); + b.close(); + + QVERIFY(b.open(QIODevice::ReadWrite)); + QVERIFY(b.isReadable()); + QVERIFY(b.isWritable()); + b.close(); +} + // some status() tests, too void tst_QBuffer::readBlock() { diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index 25925bd..45f501c 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -6195,16 +6195,62 @@ void tst_QNetworkReply::synchronousRequestSslFailure() } #endif -void tst_QNetworkReply::httpAbort() +class HttpAbortHelper : public QObject { - // FIXME: Implement a test that aborts a big HTTP reply - // a) after the first readyRead() - // b) immediatly after the get() - // c) after the finished() - // The goal is no crash and no irrelevant signals after the abort + Q_OBJECT +public: + HttpAbortHelper(QNetworkReply *parent) + : QObject(parent) + { + mReply = parent; + connect(parent, SIGNAL(readyRead()), this, SLOT(readyRead())); + } + + ~HttpAbortHelper() + { + } + +public slots: + void readyRead() + { + mReply->abort(); + QMetaObject::invokeMethod(&QTestEventLoop::instance(), "exitLoop", Qt::QueuedConnection); + } + +private: + QNetworkReply *mReply; +}; +void tst_QNetworkReply::httpAbort() +{ // FIXME Also implement one where we do a big upload and then abort(). // It must not crash either. + + // Abort after the first readyRead() + QNetworkRequest request("http://" + QtNetworkSettings::serverName() + "/qtest/bigfile"); + QNetworkReplyPtr reply; + reply = manager.get(request); + HttpAbortHelper replyHolder(reply); + QTestEventLoop::instance().enterLoop(10); + QVERIFY(!QTestEventLoop::instance().timeout()); + QCOMPARE(reply->error(), QNetworkReply::OperationCanceledError); + QVERIFY(reply->isFinished()); + + // Abort immediatly after the get() + QNetworkReplyPtr reply2 = manager.get(request); + connect(reply2, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + reply2->abort(); + QCOMPARE(reply2->error(), QNetworkReply::OperationCanceledError); + QVERIFY(reply2->isFinished()); + + // Abort after the finished() + QNetworkRequest request3("http://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt"); + QNetworkReplyPtr reply3 = manager.get(request3); + connect(reply3, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + QTestEventLoop::instance().enterLoop(10); + QVERIFY(reply3->isFinished()); + reply3->abort(); + QCOMPARE(reply3->error(), QNetworkReply::NoError); } void tst_QNetworkReply::dontInsertPartialContentIntoTheCache() diff --git a/tests/auto/qsocketnotifier/tst_qsocketnotifier.cpp b/tests/auto/qsocketnotifier/tst_qsocketnotifier.cpp index 550cef9..eb9a260 100644 --- a/tests/auto/qsocketnotifier/tst_qsocketnotifier.cpp +++ b/tests/auto/qsocketnotifier/tst_qsocketnotifier.cpp @@ -57,7 +57,7 @@ #include <private/qnet_unix_p.h> #endif #include <limits> -#include <select.h> +#include <sys/select.h> class tst_QSocketNotifier : public QObject { @@ -180,7 +180,7 @@ void tst_QSocketNotifier::unexpectedDisconnection() // we have to wait until sequence value changes // as any event can make us jump out processing QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents); - QVERIFY(timer.isActive); //escape if test would hang + QVERIFY(timer.isActive()); //escape if test would hang } while(tester.sequence <= 0); QVERIFY(readEnd1.state() == QAbstractSocket::ConnectedState); @@ -294,7 +294,7 @@ void tst_QSocketNotifier::posixSockets() QTestEventLoop::instance().enterLoop(3); QCOMPARE(readSpy.count(), 1); - QCOMPARE(writeSpy.count(), 0); + writeSpy.clear(); //depending on OS, write notifier triggers on creation or not. QCOMPARE(errorSpy.count(), 0); char buffer[100]; @@ -315,18 +315,17 @@ void tst_QSocketNotifier::posixSockets() void tst_QSocketNotifier::bogusFds() { -#ifndef Q_OS_WIN +#ifndef Q_OS_SYMBIAN + //behaviour of QSocketNotifier with an invalid fd is totally different across OS + //main point of this test was to check symbian backend doesn't crash + QSKIP("test only for symbian", SkipAll); +#else QTest::ignoreMessage(QtWarningMsg, "QSocketNotifier: Internal error"); -#endif QSocketNotifier max(std::numeric_limits<int>::max(), QSocketNotifier::Read); QTest::ignoreMessage(QtWarningMsg, "QSocketNotifier: Invalid socket specified"); -#ifndef Q_OS_WIN QTest::ignoreMessage(QtWarningMsg, "QSocketNotifier: Internal error"); -#endif QSocketNotifier min(std::numeric_limits<int>::min(), QSocketNotifier::Write); -#ifndef Q_OS_WIN QTest::ignoreMessage(QtWarningMsg, "QSocketNotifier: Internal error"); -#endif //bogus magic number is the first pseudo socket descriptor from symbian socket engine. QSocketNotifier bogus(0x40000000, QSocketNotifier::Exception); QSocketNotifier largestlegal(FD_SETSIZE - 1, QSocketNotifier::Read); @@ -350,6 +349,7 @@ void tst_QSocketNotifier::bogusFds() QCOMPARE(minspy.count(), 0); QCOMPARE(bogspy.count(), 0); QCOMPARE(llspy.count(), 0); +#endif } QTEST_MAIN(tst_QSocketNotifier) diff --git a/tests/benchmarks/corelib/tools/qstring/main.cpp b/tests/benchmarks/corelib/tools/qstring/main.cpp index 87322a5..5b5f0f7 100644 --- a/tests/benchmarks/corelib/tools/qstring/main.cpp +++ b/tests/benchmarks/corelib/tools/qstring/main.cpp @@ -48,7 +48,12 @@ #define SRCDIR "" #endif +#if !defined(QWS) && defined(Q_OS_MAC) +#include "private/qcore_mac_p.h" +#endif + #ifdef Q_OS_UNIX +#include <sys/ipc.h> #include <sys/mman.h> #include <unistd.h> #endif @@ -76,6 +81,18 @@ private slots: void fromLatin1Alternatives() const; void fromUtf8Alternatives_data() const; void fromUtf8Alternatives() const; + +#if !defined(QWS) && defined(Q_OS_MAC) + void QCFString_data() const; + void QCFString_toCFStringRef_data() const; + void QCFString_toCFStringRef() const; + void QCFString_operatorCFStringRef_data() const; + void QCFString_operatorCFStringRef() const; + void QCFString_toQString_data() const; + void QCFString_toQString() const; + void QCFString_operatorQString_data() const; + void QCFString_operatorQString() const; +#endif // !defined(QWS) && defined(Q_OS_MAC) }; void tst_QString::equals() const @@ -2596,6 +2613,89 @@ void tst_QString::fromUtf8Alternatives() const } } +#if !defined(QWS) && defined(Q_OS_MAC) +void tst_QString::QCFString_data() const +{ + QTest::addColumn<QString>("string"); + + QString base(QLatin1String("I'm some cool string")); + QTest::newRow("base") << base; + + base = base.repeated(25); + QTest::newRow("25 bases") << base; + + QTest::newRow("raw 25 bases") << QString::fromRawData(base.constData(), base.size()); +} + +void tst_QString::QCFString_toCFStringRef_data() const +{ + QCFString_data(); +} + +void tst_QString::QCFString_toCFStringRef() const +{ + QFETCH(QString, string); + + QBENCHMARK { + CFStringRef cfstr = QCFString::toCFStringRef(string); + CFRelease(cfstr); + } +} + +void tst_QString::QCFString_operatorCFStringRef_data() const +{ + QCFString_data(); +} + +void tst_QString::QCFString_operatorCFStringRef() const +{ + QFETCH(QString, string); + + CFStringRef cfstr; + QBENCHMARK { + QCFString qcfstr(string); + cfstr = qcfstr; + } +} + +void tst_QString::QCFString_toQString_data() const +{ + QCFString_data(); +} + +void tst_QString::QCFString_toQString() const +{ + QFETCH(QString, string); + + QCFString qcfstr(string); + + QString qstr; + QBENCHMARK { + qstr = QCFString::toQString(qcfstr); + } + QVERIFY(qstr == string); +} + +void tst_QString::QCFString_operatorQString_data() const +{ + QCFString_data(); +} + +void tst_QString::QCFString_operatorQString() const +{ + QFETCH(QString, string); + + QCFString qcfstr_base(string); + + QString qstr; + QBENCHMARK { + QCFString qcfstr(qcfstr_base); + qstr = qcfstr; + } + QVERIFY(qstr == string); +} +#endif // !defined(QWS) && defined(Q_OS_MAC) + QTEST_MAIN(tst_QString) #include "main.moc" |