diff options
Diffstat (limited to 'tests')
27 files changed, 1029 insertions, 665 deletions
diff --git a/tests/arthur/common/paintcommands.cpp b/tests/arthur/common/paintcommands.cpp index 44deb0e..feabaed 100644 --- a/tests/arthur/common/paintcommands.cpp +++ b/tests/arthur/common/paintcommands.cpp @@ -587,10 +587,10 @@ void PaintCommands::staticInit() "^image_setColor\\s+([\\w.:\\/]*)\\s+([0-9]*)\\s+#([0-9]*)$", "image_setColor <imageName> <index> <color>", "image_setColor myImage 0 black"); - DECL_PAINTCOMMAND("image_setNumColors", command_image_setNumColors, - "^image_setNumColors\\s+([\\w.:\\/]*)\\s+([0-9]*)$", - "image_setNumColors <imageName> <nbColors>", - "image_setNumColors myImage 128"); + DECL_PAINTCOMMAND("image_setColorCount", command_image_setColorCount, + "^image_setColorCount\\s+([\\w.:\\/]*)\\s+([0-9]*)$", + "image_setColorCount <imageName> <nbColors>", + "image_setColorCount myImage 128"); DECL_PAINTCOMMANDSECTION("transformations"); DECL_PAINTCOMMAND("resetMatrix", command_resetMatrix, @@ -2245,7 +2245,7 @@ void PaintCommands::command_image_load(QRegExp re) } /***************************************************************************************************/ -void PaintCommands::command_image_setNumColors(QRegExp re) +void PaintCommands::command_image_setColorCount(QRegExp re) { QStringList caps = re.capturedTexts(); @@ -2253,10 +2253,10 @@ void PaintCommands::command_image_setNumColors(QRegExp re) int count = convertToInt(caps.at(2)); if (m_verboseMode) - printf(" -(lance) image_setNumColors(%s), %d -> %d\n", - qPrintable(name), m_imageMap[name].numColors(), count); + printf(" -(lance) image_setColorCount(%s), %d -> %d\n", + qPrintable(name), m_imageMap[name].colorCount(), count); - m_imageMap[name].setNumColors(count); + m_imageMap[name].setColorCount(count); } /***************************************************************************************************/ diff --git a/tests/arthur/common/paintcommands.h b/tests/arthur/common/paintcommands.h index ba91a92..e2c4d67 100644 --- a/tests/arthur/common/paintcommands.h +++ b/tests/arthur/common/paintcommands.h @@ -239,7 +239,7 @@ private: void command_image_convertToFormat(QRegExp re); void command_image_load(QRegExp re); void command_image_setColor(QRegExp re); - void command_image_setNumColors(QRegExp re); + void command_image_setColorCount(QRegExp re); // commands: transformation void command_resetMatrix(QRegExp re); diff --git a/tests/auto/qaudiodeviceinfo/tst_qaudiodeviceinfo.cpp b/tests/auto/qaudiodeviceinfo/tst_qaudiodeviceinfo.cpp index 7b9a422..715f219 100644 --- a/tests/auto/qaudiodeviceinfo/tst_qaudiodeviceinfo.cpp +++ b/tests/auto/qaudiodeviceinfo/tst_qaudiodeviceinfo.cpp @@ -77,7 +77,7 @@ private: void tst_QAudioDeviceInfo::initTestCase() { // Only perform tests if audio output device exists! - QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::deviceList(QAudio::AudioOutput); + QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput); if(devices.size() > 0) available = true; else { @@ -90,7 +90,7 @@ void tst_QAudioDeviceInfo::checkAvailableDefaultInput() { // Only perform tests if audio input device exists! bool storeAvailable = available; - QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::deviceList(QAudio::AudioInput); + QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput); if(devices.size() > 0) available = true; else { @@ -111,7 +111,7 @@ void tst_QAudioDeviceInfo::checkAvailableDefaultOutput() void tst_QAudioDeviceInfo::outputList() { if(available) { - QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::deviceList(QAudio::AudioOutput); + QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput); QVERIFY(devices.size() > 0); device = new QAudioDeviceInfo(devices.at(0)); } diff --git a/tests/auto/qaudioformat/tst_qaudioformat.cpp b/tests/auto/qaudioformat/tst_qaudioformat.cpp index 286e63f..0778a8e 100644 --- a/tests/auto/qaudioformat/tst_qaudioformat.cpp +++ b/tests/auto/qaudioformat/tst_qaudioformat.cpp @@ -69,17 +69,20 @@ private slots: void tst_QAudioFormat::checkNull() { - // Default constructed QAudioFormat is null. + // Default constructed QAudioFormat is invalid. QAudioFormat audioFormat0; - QVERIFY(audioFormat0.isNull()); + QVERIFY(!audioFormat0.isValid()); - // Null is transferred + // validity is transferred QAudioFormat audioFormat1(audioFormat0); - QVERIFY(audioFormat1.isNull()); + QVERIFY(!audioFormat1.isValid()); - // Null is voided on activity audioFormat0.setFrequency(44100); - QVERIFY(!audioFormat0.isNull()); + audioFormat0.setChannels(2); + audioFormat0.setSampleSize(16); + audioFormat0.setCodec("audio/pcm"); + audioFormat0.setSampleType(QAudioFormat::SignedInt); + QVERIFY(audioFormat0.isValid()); } void tst_QAudioFormat::checkFrequency() diff --git a/tests/auto/qaudioinput/tst_qaudioinput.cpp b/tests/auto/qaudioinput/tst_qaudioinput.cpp index 3efc346..744ce38 100644 --- a/tests/auto/qaudioinput/tst_qaudioinput.cpp +++ b/tests/auto/qaudioinput/tst_qaudioinput.cpp @@ -76,7 +76,7 @@ void tst_QAudioInput::initTestCase() format.setSampleType(QAudioFormat::UnSignedInt); // Only perform tests if audio input device exists! - QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::deviceList(QAudio::AudioInput); + QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput); if(devices.size() > 0) available = true; else { @@ -137,16 +137,16 @@ void tst_QAudioInput::pullFile() QSignalSpy stateSignal(audio, SIGNAL(stateChanged(QAudio::State))); // Always have default states, before start - QVERIFY(audio->state() == QAudio::StopState); + QVERIFY(audio->state() == QAudio::StoppedState); QVERIFY(audio->error() == QAudio::NoError); - QVERIFY(audio->clock() == 0); + QVERIFY(audio->elapsedUSecs() == 0); audio->start(&filename); QTest::qWait(20); // Check state and periodSize() are valid non-zero values. QVERIFY(audio->state() == QAudio::ActiveState); QVERIFY(audio->error() == QAudio::NoError); - QVERIFY(audio->clock() > 10000 && audio->clock() < 800000); + QVERIFY(audio->elapsedUSecs() > 10000 && audio->elapsedUSecs() < 800000); QVERIFY(audio->periodSize() > 0); QVERIFY(stateSignal.count() == 1); // State changed to QAudio::ActiveState @@ -154,12 +154,12 @@ void tst_QAudioInput::pullFile() QTest::qWait(5000); QVERIFY(readSignal.count() > 0); - QVERIFY(audio->totalTime() > 0); + QVERIFY(audio->processedUSecs() > 0); audio->stop(); QTest::qWait(20); - QVERIFY(audio->state() == QAudio::StopState); - QVERIFY(audio->clock() == 0); + QVERIFY(audio->state() == QAudio::StoppedState); + QVERIFY(audio->elapsedUSecs() == 0); // Can only check to make sure we got at least 1 more signal, but can be more. QVERIFY(stateSignal.count() > 1); diff --git a/tests/auto/qaudiooutput/tst_qaudiooutput.cpp b/tests/auto/qaudiooutput/tst_qaudiooutput.cpp index b001af1..26694cc 100644 --- a/tests/auto/qaudiooutput/tst_qaudiooutput.cpp +++ b/tests/auto/qaudiooutput/tst_qaudiooutput.cpp @@ -79,7 +79,7 @@ void tst_QAudioOutput::initTestCase() format.setSampleType(QAudioFormat::UnSignedInt); // Only perform tests if audio output device exists! - QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::deviceList(QAudio::AudioOutput); + QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput); if(devices.size() > 0) available = true; else { @@ -140,9 +140,9 @@ void tst_QAudioOutput::pullFile() audio->setNotifyInterval(100); // Always have default states, before start - QVERIFY(audio->state() == QAudio::StopState); + QVERIFY(audio->state() == QAudio::StoppedState); QVERIFY(audio->error() == QAudio::NoError); - QVERIFY(audio->clock() == 0); + QVERIFY(audio->elapsedUSecs() == 0); audio->start(&file); QTest::qWait(20); // wait 20ms @@ -150,12 +150,12 @@ void tst_QAudioOutput::pullFile() QVERIFY(audio->state() == QAudio::ActiveState); QVERIFY(audio->error() == QAudio::NoError); QVERIFY(audio->periodSize() > 0); - QVERIFY(audio->clock() > 10000 && audio->clock() < 800000); + QVERIFY(audio->elapsedUSecs() > 10000 && audio->elapsedUSecs() < 800000); QVERIFY(stateSignal.count() == 1); // State changed to QAudio::ActiveState // Wait until finished... QTestEventLoop::instance().enterLoop(1); - QCOMPARE(audio->totalTime(), qint64(692250)); + QCOMPARE(audio->processedUSecs(), qint64(692250)); #ifdef Q_OS_WINCE // 4.wav is a little less than 700ms, so notify should fire 4 times on Wince! @@ -166,8 +166,8 @@ void tst_QAudioOutput::pullFile() #endif audio->stop(); QTest::qWait(20); // wait 20ms - QVERIFY(audio->state() == QAudio::StopState); - QVERIFY(audio->clock() == 0); + QVERIFY(audio->state() == QAudio::StoppedState); + QVERIFY(audio->elapsedUSecs() == 0); // Can only check to make sure we got at least 1 more signal, but can be more. QVERIFY(stateSignal.count() > 1); @@ -184,7 +184,7 @@ void tst_QAudioOutput::pushFile() const qint64 fileSize = file.size(); - QIODevice* feed = audio->start(0); + QIODevice* feed = audio->start(); char* buffer = new char[fileSize]; file.read(buffer, fileSize); @@ -199,7 +199,7 @@ void tst_QAudioOutput::pushFile() QTestEventLoop::instance().enterLoop(1); QVERIFY(written == fileSize); - QVERIFY(audio->totalTime() == 692250); + QVERIFY(audio->processedUSecs() == 692250); audio->stop(); file.close(); diff --git a/tests/auto/qdatastream/tst_qdatastream.cpp b/tests/auto/qdatastream/tst_qdatastream.cpp index 56fc53a..7535645 100644 --- a/tests/auto/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/qdatastream/tst_qdatastream.cpp @@ -1461,7 +1461,7 @@ void tst_QDataStream::readQImage(QDataStream *s) QVERIFY(d12.width() == ref.width()); QVERIFY(d12.height() == ref.height()); QVERIFY(d12.depth() == ref.depth()); - QVERIFY(d12.numColors() == ref.numColors()); + QVERIFY(d12.colorCount() == ref.colorCount()); #ifdef QT3_SUPPORT QVERIFY(d12.hasAlphaBuffer() == ref.hasAlphaBuffer()); #else diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp index 55cc286..b3d6fd9 100644 --- a/tests/auto/qfile/tst_qfile.cpp +++ b/tests/auto/qfile/tst_qfile.cpp @@ -91,6 +91,10 @@ #define STDERR_FILENO 2 #endif +#ifndef QT_OPEN_BINARY +#define QT_OPEN_BINARY 0 +#endif + Q_DECLARE_METATYPE(QFile::FileError) //TESTED_CLASS= @@ -211,6 +215,81 @@ public: // disabled this test for the moment... it hangs void invalidFile_data(); void invalidFile(); + +private: + enum FileType { OpenQFile, OpenFd, OpenStream }; + + bool openFd(QFile &file, QIODevice::OpenMode mode) + { + int fdMode = QT_OPEN_LARGEFILE | QT_OPEN_BINARY; + + // File will be truncated if in Write mode. + if (mode & QIODevice::WriteOnly) + fdMode |= QT_OPEN_WRONLY | QT_OPEN_TRUNC; + if (mode & QIODevice::ReadOnly) + fdMode |= QT_OPEN_RDONLY; + + fd_ = QT_OPEN(qPrintable(file.fileName()), fdMode); + + return (-1 != fd_) && file.open(fd_, mode); + } + + bool openStream(QFile &file, QIODevice::OpenMode mode) + { + char const *streamMode = ""; + + // File will be truncated if in Write mode. + if (mode & QIODevice::WriteOnly) + streamMode = "wb+"; + else if (mode & QIODevice::ReadOnly) + streamMode = "rb"; + + stream_ = QT_FOPEN(qPrintable(file.fileName()), streamMode); + + return stream_ && file.open(stream_, mode); + } + + bool openFile(QFile &file, QIODevice::OpenMode mode, FileType type = OpenQFile) + { + if (mode & QIODevice::WriteOnly && !file.exists()) + { + // Make sure the file exists + QFile createFile(file.fileName()); + if (!createFile.open(QIODevice::ReadWrite)) + return false; + } + + // Note: openFd and openStream will truncate the file if write mode. + switch (type) + { + case OpenQFile: + return file.open(mode); + + case OpenFd: + return openFd(file, mode); + + case OpenStream: + return openStream(file, mode); + } + + return false; + } + + void closeFile(QFile &file) + { + file.close(); + + if (-1 != fd_) + QT_CLOSE(fd_); + if (stream_) + ::fclose(stream_); + + fd_ = -1; + stream_ = 0; + } + + int fd_; + FILE *stream_; }; tst_QFile::tst_QFile() @@ -226,6 +305,8 @@ void tst_QFile::init() { // TODO: Add initialization code here. // This will be executed immediately before each test is run. + fd_ = -1; + stream_ = 0; } void tst_QFile::cleanup() @@ -254,6 +335,11 @@ void tst_QFile::cleanup() QFile::remove("existing-file.txt"); QFile::remove("file-renamed-once.txt"); QFile::remove("file-renamed-twice.txt"); + + if (-1 != fd_) + QT_CLOSE(fd_); + if (stream_) + ::fclose(stream_); } void tst_QFile::initTestCase() @@ -1958,53 +2044,71 @@ void tst_QFile::fullDisk() void tst_QFile::writeLargeDataBlock_data() { QTest::addColumn<QString>("fileName"); + QTest::addColumn<int>("type"); + + QTest::newRow("localfile-QFile") << "./largeblockfile.txt" << (int)OpenQFile; + QTest::newRow("localfile-Fd") << "./largeblockfile.txt" << (int)OpenFd; + QTest::newRow("localfile-Stream") << "./largeblockfile.txt" << (int)OpenStream; - QTest::newRow("localfile") << QString("./largeblockfile.txt"); #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) // Some semi-randomness to avoid collisions. QTest::newRow("unc file") << QString("//" + QtNetworkSettings::winServerName() + "/TESTSHAREWRITABLE/largefile-%1-%2.txt") .arg(QHostInfo::localHostName()) - .arg(QTime::currentTime().msec()); + .arg(QTime::currentTime().msec()) << (int)OpenQFile; #endif } -void tst_QFile::writeLargeDataBlock() +static QByteArray getLargeDataBlock() { - QFETCH(QString, fileName); + static QByteArray array; - // Generate a 64MB array with well defined contents. - QByteArray array; + if (array.isNull()) + { #if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN) - int resizeSize = 1024 * 1024; // WinCE and Symbian do not have much space + int resizeSize = 1024 * 1024; // WinCE and Symbian do not have much space #else - int resizeSize = 64 * 1024 * 1024; + int resizeSize = 64 * 1024 * 1024; #endif - array.resize(resizeSize); - for (int i = 0; i < array.size(); ++i) - array[i] = uchar(i); + array.resize(resizeSize); + for (int i = 0; i < array.size(); ++i) + array[i] = uchar(i); + } - // Remove and open the target file - QFile file(fileName); - file.remove(); - if (file.open(QFile::WriteOnly)) { - QCOMPARE(file.write(array), qint64(array.size())); - file.close(); - QVERIFY(file.open(QFile::ReadOnly)); - array.clear(); - array = file.readAll(); - file.remove(); - } else { - QFAIL(qPrintable(QString("Couldn't open file for writing: [%1]").arg(fileName))); - } - // Check that we got the right content - QCOMPARE(array.size(), resizeSize); - for (int i = 0; i < array.size(); ++i) { - if (array[i] != char(i)) { - QFAIL(qPrintable(QString("Wrong contents! Char at %1 = %2, expected %3") - .arg(i).arg(int(uchar(array[i]))).arg(int(uchar(i))))); - } + return array; +} + +void tst_QFile::writeLargeDataBlock() +{ + QFETCH(QString, fileName); + QFETCH( int, type ); + + QByteArray const originalData = getLargeDataBlock(); + + { + QFile file(fileName); + + QVERIFY2( openFile(file, QIODevice::WriteOnly, (FileType)type), + qPrintable(QString("Couldn't open file for writing: [%1]").arg(fileName)) ); + QCOMPARE( file.write(originalData), (qint64)originalData.size() ); + QVERIFY( file.flush() ); + + closeFile(file); + } + + QByteArray readData; + + { + QFile file(fileName); + + QVERIFY2( openFile(file, QIODevice::ReadOnly, (FileType)type), + qPrintable(QString("Couldn't open file for reading: [%1]").arg(fileName)) ); + readData = file.readAll(); + closeFile(file); } + + QCOMPARE( readData, originalData ); + QVERIFY( QFile::remove(fileName) ); } void tst_QFile::readFromWriteOnlyFile() diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp index cc96edb..c7ed309 100644 --- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp +++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp @@ -83,6 +83,8 @@ private slots: void infiniteMaxSizes(); void simplifiableUnfeasible(); void simplificationVsOrder(); + void parallelSimplificationOfCenter(); + void simplificationVsRedundance(); }; class RectWidget : public QGraphicsWidget @@ -1801,5 +1803,68 @@ void tst_QGraphicsAnchorLayout::simplificationVsOrder() } } +void tst_QGraphicsAnchorLayout::parallelSimplificationOfCenter() +{ + QSizeF min(10, 10); + QSizeF pref(20, 10); + QSizeF max(50, 10); + + QGraphicsWidget *a = createItem(min, pref, max, "A"); + QGraphicsWidget *b = createItem(min, pref, max, "B"); + + QGraphicsWidget parent; + QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout(&parent); + l->setContentsMargins(0, 0, 0, 0); + + l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); + l->addAnchor(l, Qt::AnchorRight, a, Qt::AnchorRight); + + l->addAnchor(a, Qt::AnchorHorizontalCenter, b, Qt::AnchorLeft); + l->addAnchor(b, Qt::AnchorRight, a, Qt::AnchorRight); + + parent.resize(l->effectiveSizeHint(Qt::PreferredSize)); + + QCOMPARE(a->geometry(), QRectF(0, 0, 40, 10)); + QCOMPARE(b->geometry(), QRectF(20, 0, 20, 10)); +} + +/* + Test whether redundance of anchors (in this case by using addCornerAnchors), will + prevent simplification to take place when it should. +*/ +void tst_QGraphicsAnchorLayout::simplificationVsRedundance() +{ + QSizeF min(10, 10); + QSizeF pref(20, 10); + QSizeF max(50, 30); + + QGraphicsWidget *a = createItem(min, pref, max, "A"); + QGraphicsWidget *b = createItem(min, pref, max, "B"); + QGraphicsWidget *c = createItem(min, pref, max, "C"); + + QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; + + l->addCornerAnchors(a, Qt::TopLeftCorner, l, Qt::TopLeftCorner); + l->addCornerAnchors(a, Qt::BottomLeftCorner, l, Qt::BottomLeftCorner); + + l->addCornerAnchors(b, Qt::TopLeftCorner, a, Qt::TopRightCorner); + l->addCornerAnchors(b, Qt::TopRightCorner, l, Qt::TopRightCorner); + + l->addCornerAnchors(c, Qt::TopLeftCorner, b, Qt::BottomLeftCorner); + l->addCornerAnchors(c, Qt::BottomLeftCorner, a, Qt::BottomRightCorner); + l->addCornerAnchors(c, Qt::TopRightCorner, b, Qt::BottomRightCorner); + l->addCornerAnchors(c, Qt::BottomRightCorner, l, Qt::BottomRightCorner); + + l->effectiveSizeHint(Qt::MinimumSize); + + QCOMPARE(layoutHasConflict(l), false); + + if (!hasSimplification) + QEXPECT_FAIL("", "Test depends on simplification.", Abort); + + QCOMPARE(usedSimplex(l, Qt::Horizontal), false); + QCOMPARE(usedSimplex(l, Qt::Vertical), false); +} + QTEST_MAIN(tst_QGraphicsAnchorLayout) #include "tst_qgraphicsanchorlayout.moc" diff --git a/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp b/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp index 4f8a478..0fbd069 100644 --- a/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp +++ b/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp @@ -423,7 +423,6 @@ void tst_QGraphicsAnchorLayout1::testAddAndRemoveAnchor() layout->setAnchor(layout, Qt::AnchorLeft, widget5, Qt::AnchorTop, 10); QCOMPARE( layout->count(), 4 ); - // ###: NOT SUPPORTED // anchor two edges of a widget (to define width / height) QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor the item to itself"); layout->setAnchor(widget5, Qt::AnchorLeft, widget5, Qt::AnchorRight, 10); @@ -520,8 +519,6 @@ void tst_QGraphicsAnchorLayout1::testIsValid() widget->setLayout(layout); widget->setGeometry(QRectF(0,0,100,100)); - // ###: this shall change once isValid() is ready - // QCOMPARE(layout->isValid(), false); QCOMPARE(layout->isValid(), true); delete widget; } @@ -698,9 +695,8 @@ void tst_QGraphicsAnchorLayout1::testSpecialCases() layout2->setAnchor(widget1, Qt::AnchorRight, layout2, Qt::AnchorRight, 1); layout2->setAnchor(widget1, Qt::AnchorBottom, layout2, Qt::AnchorBottom, 1); - // ###: uncomment when simplification bug is solved - //widget->setGeometry(QRectF(0,0,100,100)); - //QCOMPARE(widget1->geometry(), QRectF(51,2,47,96)); + widget->setGeometry(QRectF(0,0,100,100)); + QCOMPARE(widget1->geometry(), QRectF(51,2,47,96)); delete widget; } @@ -900,9 +896,6 @@ void tst_QGraphicsAnchorLayout1::testBasicLayout_data() << BasicData(-1, Qt::AnchorLeft, 1, Qt::AnchorRight, 20) ; - // ### SIMPLIFICATION BUG FOR ITEM 1 - // ### remove this when bug is solved - theResult << BasicResult(0, QRectF(10, 10, 180, 80) ) << BasicResult(1, QRectF(10, 80, 10, 10) ) @@ -1743,7 +1736,10 @@ void tst_QGraphicsAnchorLayout1::testBasicLayout() if (mirroredRect.isValid()){ mirroredRect.moveLeft(size.width()-item.rect.width()-item.rect.left()); } - QCOMPARE(widgets[item.index]->geometry(), mirroredRect); + QRectF expected = truncate(mirroredRect); + QRectF actual = truncate(widgets[item.index]->geometry()); + + QCOMPARE(expected, actual); delete widgets[item.index]; } @@ -2445,6 +2441,8 @@ void tst_QGraphicsAnchorLayout1::testDoubleSizePolicy_data() QTest::newRow("double size policy: expanding-preferred") << sizePolicy1 << sizePolicy2 << width1 << width2; } + // QGAL handling of ignored flag is different + if (0) { QSizePolicy sizePolicy1( QSizePolicy::Ignored, QSizePolicy::Ignored ); QSizePolicy sizePolicy2( QSizePolicy::Preferred, QSizePolicy::Preferred ); @@ -2512,9 +2510,6 @@ void tst_QGraphicsAnchorLayout1::testDoubleSizePolicy_data() void tst_QGraphicsAnchorLayout1::testDoubleSizePolicy() { - // ### Size policy is not yet supported - return; - QFETCH(QSizePolicy, policy1); QFETCH(QSizePolicy, policy2); QFETCH(qreal, width1); diff --git a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp index b40cf43..d216924 100644 --- a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp +++ b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp @@ -49,6 +49,7 @@ #include <QtGui/qstyleoption.h> #include "../../shared/util.h" +#include <private/qgraphicseffect_p.h> //TESTED_CLASS= //TESTED_FILES= @@ -131,16 +132,16 @@ public: int margin() const { return m_margin; } - void draw(QPainter *painter, QGraphicsEffectSource *source) + void draw(QPainter *painter) { ++numRepaints; if (doNothingInDraw) return; - m_source = source; + m_source = source(); m_painter = painter; - m_styleOption = source->styleOption(); + m_styleOption = source()->styleOption(); m_opacity = painter->opacity(); - source->draw(painter); + drawSource(painter); } void sourceChanged(QGraphicsEffect::ChangeFlags flags) diff --git a/tests/auto/qimage/tst_qimage.cpp b/tests/auto/qimage/tst_qimage.cpp index e15ae8a..da4e85d 100644 --- a/tests/auto/qimage/tst_qimage.cpp +++ b/tests/auto/qimage/tst_qimage.cpp @@ -104,7 +104,7 @@ private slots: void setPixel_data(); void setPixel(); - void setNumColors(); + void setColorCount(); void setColor(); void rasterClipping(); @@ -155,7 +155,7 @@ void tst_QImage::create() #endif //QImage image(7000000, 7000000, 8, 256, QImage::IgnoreEndian); QImage image(7000000, 7000000, QImage::Format_Indexed8); - image.setNumColors(256); + image.setColorCount(256); cr = !image.isNull(); #if !defined(Q_WS_QWS) && !defined(Q_OS_WINCE) } catch (...) { @@ -242,7 +242,7 @@ void tst_QImage::convertBitOrder() QSKIP("Qt compiled without Qt3Support", SkipAll); #else QImage i(9,5,1,2,QImage::LittleEndian); - qMemSet(i.bits(), 0, i.numBytes()); + qMemSet(i.bits(), 0, i.byteCount()); i.setDotsPerMeterX(9); i.setDotsPerMeterY(5); @@ -258,7 +258,7 @@ void tst_QImage::convertBitOrder() QVERIFY(i.dotsPerMeterY() == ni.dotsPerMeterY()); QVERIFY(i.depth() == ni.depth()); QVERIFY(i.size() == ni.size()); - QVERIFY(i.numColors() == ni.numColors()); + QVERIFY(i.colorCount() == ni.colorCount()); #endif } @@ -365,7 +365,7 @@ void tst_QImage::setAlphaChannel() QImage alphaChannel; if (gray) { alphaChannel = QImage(width, height, QImage::Format_Indexed8); - alphaChannel.setNumColors(256); + alphaChannel.setColorCount(256); for (int i=0; i<256; ++i) alphaChannel.setColor(i, qRgb(i, i, i)); alphaChannel.fill(alpha); @@ -927,7 +927,7 @@ void tst_QImage::rotate() original.fill(qRgb(255,255,255)); if (format == QImage::Format_Indexed8) { - original.setNumColors(256); + original.setColorCount(256); for (int i = 0; i < 255; ++i) original.setColor(i, qRgb(0, i, i)); } @@ -1196,23 +1196,23 @@ void tst_QImage::convertToFormatPreserveText() } #endif // QT_NO_IMAGE_TEXT -void tst_QImage::setNumColors() +void tst_QImage::setColorCount() { QImage img(0, 0, QImage::Format_Indexed8); - QTest::ignoreMessage(QtWarningMsg, "QImage::setNumColors: null image"); - img.setNumColors(256); - QCOMPARE(img.numColors(), 0); + QTest::ignoreMessage(QtWarningMsg, "QImage::setColorCount: null image"); + img.setColorCount(256); + QCOMPARE(img.colorCount(), 0); } void tst_QImage::setColor() { QImage img(0, 0, QImage::Format_Indexed8); img.setColor(0, qRgba(18, 219, 108, 128)); - QCOMPARE(img.numColors(), 0); + QCOMPARE(img.colorCount(), 0); QImage img2(1, 1, QImage::Format_Indexed8); img2.setColor(0, qRgba(18, 219, 108, 128)); - QCOMPARE(img2.numColors(), 1); + QCOMPARE(img2.colorCount(), 1); } /* Just some sanity checking that we don't draw outside the buffer of diff --git a/tests/auto/qimagewriter/tst_qimagewriter.cpp b/tests/auto/qimagewriter/tst_qimagewriter.cpp index 584a060..ab5572d 100644 --- a/tests/auto/qimagewriter/tst_qimagewriter.cpp +++ b/tests/auto/qimagewriter/tst_qimagewriter.cpp @@ -546,7 +546,7 @@ void tst_QImageWriter::saveWithNoFormat() QFETCH(QImageWriter::ImageWriterError, error); QImage niceImage(64, 64, QImage::Format_ARGB32); - qMemSet(niceImage.bits(), 0, niceImage.numBytes()); + qMemSet(niceImage.bits(), 0, niceImage.byteCount()); QImageWriter writer(fileName /* , 0 - no format! */); if (error != 0) { diff --git a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp index 426887d..a2770d4 100644 --- a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp +++ b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp @@ -877,7 +877,7 @@ void tst_QItemDelegate::decoration() } case QVariant::Image: { QImage img(size, QImage::Format_Mono); - qMemSet(img.bits(), 0, img.numBytes()); + qMemSet(img.bits(), 0, img.byteCount()); value = img; break; } diff --git a/tests/auto/qlcdnumber/tst_qlcdnumber.cpp b/tests/auto/qlcdnumber/tst_qlcdnumber.cpp index c18ce24..3f52c70 100644 --- a/tests/auto/qlcdnumber/tst_qlcdnumber.cpp +++ b/tests/auto/qlcdnumber/tst_qlcdnumber.cpp @@ -74,14 +74,14 @@ tst_QLCDNumber::~tst_QLCDNumber() void tst_QLCDNumber::getSetCheck() { QLCDNumber obj1; - // int QLCDNumber::numDigits() - // void QLCDNumber::setNumDigits(int) - obj1.setNumDigits(0); - QCOMPARE(0, obj1.numDigits()); - obj1.setNumDigits(INT_MIN); - QCOMPARE(0, obj1.numDigits()); // Range<0, 99> - obj1.setNumDigits(INT_MAX); - QCOMPARE(99, obj1.numDigits()); // Range<0, 99> + // int QLCDNumber::digitCount() + // void QLCDNumber::setDigitCount(int) + obj1.setDigitCount(0); + QCOMPARE(0, obj1.digitCount()); + obj1.setDigitCount(INT_MIN); + QCOMPARE(0, obj1.digitCount()); // Range<0, 99> + obj1.setDigitCount(INT_MAX); + QCOMPARE(99, obj1.digitCount()); // Range<0, 99> } QTEST_MAIN(tst_QLCDNumber) diff --git a/tests/auto/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/qlocalsocket/tst_qlocalsocket.cpp index ab7b0ac..5ead049 100644 --- a/tests/auto/qlocalsocket/tst_qlocalsocket.cpp +++ b/tests/auto/qlocalsocket/tst_qlocalsocket.cpp @@ -587,14 +587,16 @@ void tst_QLocalSocket::readBufferOverflow() char buffer[dataBufferSize]; memset(buffer, 0, dataBufferSize); serverSocket->write(buffer, dataBufferSize); - serverSocket->flush(); + serverSocket->waitForBytesWritten(); + // wait until the first 128 bytes are ready to read QVERIFY(client.waitForReadyRead()); QCOMPARE(client.read(buffer, readBufferSize), qint64(readBufferSize)); -#if defined(QT_LOCALSOCKET_TCP) || defined(Q_OS_SYMBIAN) - QTest::qWait(250); -#endif + // wait until the second 128 bytes are ready to read + QVERIFY(client.waitForReadyRead()); QCOMPARE(client.read(buffer, readBufferSize), qint64(readBufferSize)); + // no more bytes available + QVERIFY(client.bytesAvailable() == 0); } // QLocalSocket/Server can take a name or path, check that it works as expected diff --git a/tests/auto/qnetworkcookie/tst_qnetworkcookie.cpp b/tests/auto/qnetworkcookie/tst_qnetworkcookie.cpp index 3c4ddd4..94857d7 100644 --- a/tests/auto/qnetworkcookie/tst_qnetworkcookie.cpp +++ b/tests/auto/qnetworkcookie/tst_qnetworkcookie.cpp @@ -234,7 +234,7 @@ void tst_QNetworkCookie::parseSingleCookie_data() QTest::newRow("path-with-utf8-2") << "a=b;path=/R%C3%A9sum%C3%A9" << cookie; cookie.setPath(QString()); - cookie.setDomain(".qt.nokia.com"); + cookie.setDomain("qt.nokia.com"); QTest::newRow("plain-domain1") << "a=b;domain=qt.nokia.com" << cookie; QTest::newRow("plain-domain2") << "a=b; domain=qt.nokia.com " << cookie; QTest::newRow("plain-domain3") << "a=b;domain=QT.NOKIA.COM" << cookie; @@ -247,32 +247,25 @@ void tst_QNetworkCookie::parseSingleCookie_data() QTest::newRow("dot-domain4") << "a=b; Domain = .QT.NOKIA.COM" << cookie; cookie.setDomain(QString::fromUtf8(".d\303\270gn\303\245pent.troll.no")); - QTest::newRow("idn-domain1") << "a=b;domain=xn--dgnpent-gxa2o.troll.no" << cookie; - QTest::newRow("idn-domain2") << "a=b;domain=d\303\270gn\303\245pent.troll.no" << cookie; - QTest::newRow("idn-domain3") << "a=b;domain=XN--DGNPENT-GXA2O.TROLL.NO" << cookie; - QTest::newRow("idn-domain4") << "a=b;domain=D\303\230GN\303\205PENT.troll.NO" << cookie; - QTest::newRow("idn-domain5") << "a=b;domain = D\303\230GN\303\205PENT.troll.NO" << cookie; - - cookie.setDomain(QString::fromUtf8(".d\303\270gn\303\245pent.troll.no")); - QTest::newRow("dot-idn-domain1") << "a=b;domain=.xn--dgnpent-gxa2o.troll.no" << cookie; - QTest::newRow("dot-idn-domain2") << "a=b;domain=.d\303\270gn\303\245pent.troll.no" << cookie; - QTest::newRow("dot-idn-domain3") << "a=b;domain=.XN--DGNPENT-GXA2O.TROLL.NO" << cookie; - QTest::newRow("dot-idn-domain4") << "a=b;domain=.D\303\230GN\303\205PENT.troll.NO" << cookie; + QTest::newRow("idn-domain1") << "a=b;domain=.xn--dgnpent-gxa2o.troll.no" << cookie; + QTest::newRow("idn-domain2") << "a=b;domain=.d\303\270gn\303\245pent.troll.no" << cookie; + QTest::newRow("idn-domain3") << "a=b;domain=.XN--DGNPENT-GXA2O.TROLL.NO" << cookie; + QTest::newRow("idn-domain4") << "a=b;domain=.D\303\230GN\303\205PENT.troll.NO" << cookie; cookie.setDomain(".qt.nokia.com"); cookie.setPath("/"); - QTest::newRow("two-fields") << "a=b;domain=qt.nokia.com;path=/" << cookie; - QTest::newRow("two-fields2") << "a=b; domain=qt.nokia.com; path=/" << cookie; - QTest::newRow("two-fields3") << "a=b; domain=qt.nokia.com ; path=/ " << cookie; - QTest::newRow("two-fields4") << "a=b;path=/; domain=qt.nokia.com" << cookie; - QTest::newRow("two-fields5") << "a=b; path=/ ; domain=qt.nokia.com" << cookie; - QTest::newRow("two-fields6") << "a=b; path= / ; domain =qt.nokia.com" << cookie; + QTest::newRow("two-fields") << "a=b;domain=.qt.nokia.com;path=/" << cookie; + QTest::newRow("two-fields2") << "a=b; domain=.qt.nokia.com; path=/" << cookie; + QTest::newRow("two-fields3") << "a=b; domain=.qt.nokia.com ; path=/ " << cookie; + QTest::newRow("two-fields4") << "a=b;path=/; domain=.qt.nokia.com" << cookie; + QTest::newRow("two-fields5") << "a=b; path=/ ; domain=.qt.nokia.com" << cookie; + QTest::newRow("two-fields6") << "a=b; path= / ; domain =.qt.nokia.com" << cookie; cookie.setSecure(true); - QTest::newRow("three-fields") << "a=b;domain=qt.nokia.com;path=/;secure" << cookie; - QTest::newRow("three-fields2") << "a=b;secure;path=/;domain=qt.nokia.com" << cookie; - QTest::newRow("three-fields3") << "a=b;secure;domain=qt.nokia.com; path=/" << cookie; - QTest::newRow("three-fields4") << "a = b;secure;domain=qt.nokia.com; path=/" << cookie; + QTest::newRow("three-fields") << "a=b;domain=.qt.nokia.com;path=/;secure" << cookie; + QTest::newRow("three-fields2") << "a=b;secure;path=/;domain=.qt.nokia.com" << cookie; + QTest::newRow("three-fields3") << "a=b;secure;domain=.qt.nokia.com; path=/" << cookie; + QTest::newRow("three-fields4") << "a = b;secure;domain=.qt.nokia.com; path=/" << cookie; cookie = QNetworkCookie(); cookie.setName("a"); @@ -664,7 +657,7 @@ void tst_QNetworkCookie::parseMultipleCookies_data() cookie.setName("baz"); cookie.setDomain(".qt.nokia.com"); list.prepend(cookie); - QTest::newRow("complex-2") << "baz=bar; path=/; domain=qt.nokia.com, c=d,a=,foo=bar; path=/" << list; + QTest::newRow("complex-2") << "baz=bar; path=/; domain=.qt.nokia.com, c=d,a=,foo=bar; path=/" << list; // cookies obtained from the network: cookie = QNetworkCookie("id", "51706646077999719"); diff --git a/tests/auto/qnetworkcookiejar/tst_qnetworkcookiejar.cpp b/tests/auto/qnetworkcookiejar/tst_qnetworkcookiejar.cpp index 9b9c56a..ff7e78e 100644 --- a/tests/auto/qnetworkcookiejar/tst_qnetworkcookiejar.cpp +++ b/tests/auto/qnetworkcookiejar/tst_qnetworkcookiejar.cpp @@ -120,7 +120,7 @@ void tst_QNetworkCookieJar::setCookiesFromUrl_data() cookie.setName("a"); cookie.setPath("/"); - cookie.setDomain("www.foo.tld"); + cookie.setDomain(".foo.tld"); result += cookie; QTest::newRow("just-add") << preset << cookie << "http://www.foo.tld" << result << true; @@ -148,6 +148,20 @@ void tst_QNetworkCookieJar::setCookiesFromUrl_data() cookie.setPath("/"); QTest::newRow("diff-path-order") << preset << cookie << "http://www.foo.tld" << result << true; + preset.clear(); + result.clear(); + QNetworkCookie finalCookie = cookie; + cookie.setDomain("foo.tld"); + finalCookie.setDomain(".foo.tld"); + result += finalCookie; + QTest::newRow("should-add-dot-prefix") << preset << cookie << "http://www.foo.tld" << result << true; + + result.clear(); + cookie.setDomain(""); + finalCookie.setDomain("www.foo.tld"); + result += finalCookie; + QTest::newRow("should-set-default-domain") << preset << cookie << "http://www.foo.tld" << result << true; + // security test: result.clear(); preset.clear(); @@ -159,7 +173,7 @@ void tst_QNetworkCookieJar::setCookiesFromUrl_data() QTest::newRow("security-path-1") << preset << cookie << "http://www.foo.tld" << result << false; // setting the defaults: - QNetworkCookie finalCookie = cookie; + finalCookie = cookie; finalCookie.setPath("/something/"); cookie.setPath(""); cookie.setDomain(""); diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index 7adb67f..0b61dcd 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -227,12 +227,6 @@ private Q_SLOTS: void rateControl_data(); void rateControl(); - void downloadPerformance(); - void uploadPerformance(); - void performanceControlRate(); - void httpUploadPerformance(); - void httpDownloadPerformance_data(); - void httpDownloadPerformance(); void downloadProgress_data(); void downloadProgress(); @@ -413,93 +407,6 @@ public slots: } }; -class FixedSizeDataGenerator : public QIODevice -{ - Q_OBJECT - enum { Idle, Started, Stopped } state; -public: - FixedSizeDataGenerator(qint64 size) : state(Idle) - { open(ReadOnly | Unbuffered); - toBeGeneratedTotalCount = toBeGeneratedCount = size; - } - - virtual qint64 bytesAvailable() const - { - return state == Started ? toBeGeneratedCount + QIODevice::bytesAvailable() : 0; - } - - virtual bool isSequential() const{ - return false; - } - - virtual bool reset() const{ - return false; - } - - qint64 size() const { - return toBeGeneratedTotalCount; - } - -public slots: - void start() { state = Started; emit readyRead(); } - -protected: - virtual qint64 readData(char *data, qint64 maxlen) - { - memset(data, '@', maxlen); - - if (toBeGeneratedCount <= 0) { - return -1; - } - - qint64 n = qMin(maxlen, toBeGeneratedCount); - toBeGeneratedCount -= n; - - if (toBeGeneratedCount <= 0) { - // make sure this is a queued connection! - emit readChannelFinished(); - } - - return n; - } - virtual qint64 writeData(const char *, qint64) - { return -1; } - - qint64 toBeGeneratedCount; - qint64 toBeGeneratedTotalCount; -}; - - -class DataGenerator: public QIODevice -{ - Q_OBJECT - enum { Idle, Started, Stopped } state; -public: - DataGenerator() : state(Idle) - { open(ReadOnly); } - - virtual bool isSequential() const { return true; } - virtual qint64 bytesAvailable() const { return state == Started ? 1024*1024 : 0; } - -public slots: - void start() { state = Started; emit readyRead(); } - void stop() { state = Stopped; emit readyRead(); } - -protected: - virtual qint64 readData(char *data, qint64 maxlen) - { - if (state == Stopped) - return -1; // EOF - - // return as many bytes as are wanted - memset(data, '@', maxlen); - return maxlen; - } - virtual qint64 writeData(const char *, qint64) - { return -1; } -}; - - class SocketPair: public QObject { @@ -692,255 +599,6 @@ protected: } }; -class TimedSender: public QThread -{ - Q_OBJECT - qint64 totalBytes; - QSemaphore ready; - QByteArray dataToSend; - QTcpSocket *client; - int timeout; - int port; -public: - int transferRate; - TimedSender(int ms) - : totalBytes(0), timeout(ms), port(-1), transferRate(-1) - { - dataToSend = QByteArray(16*1024, '@'); - start(); - ready.acquire(); - } - - inline int serverPort() const { return port; } - -private slots: - void writeMore() - { - while (client->bytesToWrite() < 128 * 1024) { - writePacket(dataToSend); - } - } - -protected: - void run() - { - QTcpServer server; - server.listen(); - port = server.serverPort(); - ready.release(); - - server.waitForNewConnection(-1); - client = server.nextPendingConnection(); - - writeMore(); - connect(client, SIGNAL(bytesWritten(qint64)), SLOT(writeMore()), Qt::DirectConnection); - - QEventLoop eventLoop; - QTimer::singleShot(timeout, &eventLoop, SLOT(quit())); - - QTime timer; - timer.start(); - eventLoop.exec(); - disconnect(client, SIGNAL(bytesWritten(qint64)), this, 0); - - // wait for the connection to shut down - client->disconnectFromHost(); - if (!client->waitForDisconnected(10000)) - return; - - transferRate = totalBytes * 1000 / timer.elapsed(); - qDebug() << "TimedSender::run" << "receive rate:" << (transferRate / 1024) << "kB/s in" - << timer.elapsed() << "ms"; - } - - void writePacket(const QByteArray &array) - { - client->write(array); - totalBytes += array.size(); - } -}; - -class ThreadedDataReader: public QThread -{ - Q_OBJECT - // used to make the constructor only return after the tcp server started listening - QSemaphore ready; - QTcpSocket *client; - int timeout; - int port; -public: - qint64 transferRate; - ThreadedDataReader() - : port(-1), transferRate(-1) - { - start(); - ready.acquire(); - } - - inline int serverPort() const { return port; } - -protected: - void run() - { - QTcpServer server; - server.listen(); - port = server.serverPort(); - ready.release(); - - server.waitForNewConnection(-1); - client = server.nextPendingConnection(); - - QEventLoop eventLoop; - DataReader reader(client, false); - QObject::connect(client, SIGNAL(disconnected()), &eventLoop, SLOT(quit())); - - QTime timer; - timer.start(); - eventLoop.exec(); - qint64 elapsed = timer.elapsed(); - - transferRate = reader.totalBytes * 1000 / elapsed; - qDebug() << "ThreadedDataReader::run" << "send rate:" << (transferRate / 1024) << "kB/s in" << elapsed << "msec"; - } -}; - -class ThreadedDataReaderHttpServer: public QThread -{ - Q_OBJECT - // used to make the constructor only return after the tcp server started listening - QSemaphore ready; - QTcpSocket *client; - int timeout; - int port; -public: - qint64 transferRate; - ThreadedDataReaderHttpServer() - : port(-1), transferRate(-1) - { - start(); - ready.acquire(); - } - - inline int serverPort() const { return port; } - -protected: - void run() - { - QTcpServer server; - server.listen(); - port = server.serverPort(); - ready.release(); - - server.waitForNewConnection(-1); - client = server.nextPendingConnection(); - client->write("HTTP/1.0 200 OK\r\n"); - client->write("Content-length: 0\r\n"); - client->write("\r\n"); - client->flush(); - - QCoreApplication::processEvents(); - - QEventLoop eventLoop; - DataReader reader(client, false); - QObject::connect(client, SIGNAL(disconnected()), &eventLoop, SLOT(quit())); - - QTime timer; - timer.start(); - eventLoop.exec(); - qint64 elapsed = timer.elapsed(); - - transferRate = reader.totalBytes * 1000 / elapsed; - qDebug() << "ThreadedDataReaderHttpServer::run" << "send rate:" << (transferRate / 1024) << "kB/s in" << elapsed << "msec"; - } -}; - -class HttpDownloadPerformanceClient : QObject { - Q_OBJECT; - QIODevice *device; - public: - HttpDownloadPerformanceClient (QIODevice *dev) : device(dev){ - connect(dev, SIGNAL(readyRead()), this, SLOT(readyReadSlot())); - } - - public slots: - void readyReadSlot() { - device->readAll(); - } - -}; - -class HttpDownloadPerformanceServer : QObject { - Q_OBJECT; - qint64 dataSize; - qint64 dataSent; - QTcpServer server; - QTcpSocket *client; - bool serverSendsContentLength; - bool chunkedEncoding; - -public: - HttpDownloadPerformanceServer (qint64 ds, bool sscl, bool ce) : dataSize(ds), dataSent(0), - client(0), serverSendsContentLength(sscl), chunkedEncoding(ce) { - server.listen(); - connect(&server, SIGNAL(newConnection()), this, SLOT(newConnectionSlot())); - } - - int serverPort() { - return server.serverPort(); - } - -public slots: - - void newConnectionSlot() { - client = server.nextPendingConnection(); - client->setParent(this); - connect(client, SIGNAL(readyRead()), this, SLOT(readyReadSlot())); - connect(client, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWrittenSlot(qint64))); - } - - void readyReadSlot() { - client->readAll(); - client->write("HTTP/1.0 200 OK\n"); - if (serverSendsContentLength) - client->write(QString("Content-Length: " + QString::number(dataSize) + "\n").toAscii()); - if (chunkedEncoding) - client->write(QString("Transfer-Encoding: chunked\n").toAscii()); - client->write("Connection: close\n\n"); - } - - void bytesWrittenSlot(qint64 amount) { - Q_UNUSED(amount); - if (dataSent == dataSize && client) { - // close eventually - - // chunked encoding: we have to send a last "empty" chunk - if (chunkedEncoding) - client->write(QString("0\r\n\r\n").toAscii()); - - client->disconnectFromHost(); - server.close(); - client = 0; - return; - } - - // send data - if (client && client->bytesToWrite() < 100*1024 && dataSent < dataSize) { - qint64 amount = qMin(qint64(16*1024), dataSize - dataSent); - QByteArray data(amount, '@'); - - if (chunkedEncoding) { - client->write(QString(QString("%1").arg(amount,0,16).toUpper() + "\r\n").toAscii()); - client->write(data.constData(), amount); - client->write(QString("\r\n").toAscii()); - } else { - client->write(data.constData(), amount); - } - - dataSent += amount; - } - } -}; - tst_QNetworkReply::tst_QNetworkReply() { @@ -3311,7 +2969,6 @@ void tst_QNetworkReply::ioPostToHttpEmtpyUploadProgress() server.close(); } - void tst_QNetworkReply::rateControl_data() { QTest::addColumn<int>("rate"); @@ -3365,142 +3022,6 @@ void tst_QNetworkReply::rateControl() QVERIFY(sender.transferRate <= maxRate); } -void tst_QNetworkReply::downloadPerformance() -{ - // unlike the above function, this one tries to send as fast as possible - // and measures how fast it was. - TimedSender sender(5000); - QNetworkRequest request("debugpipe://127.0.0.1:" + QString::number(sender.serverPort()) + "/?bare=1"); - QNetworkReplyPtr reply = manager.get(request); - DataReader reader(reply, false); - - QTime loopTime; - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - loopTime.start(); - QTestEventLoop::instance().enterLoop(40); - int elapsedTime = loopTime.elapsed(); - sender.wait(); - - qint64 receivedBytes = reader.totalBytes; - qDebug() << "tst_QNetworkReply::downloadPerformance" << "receive rate:" << (receivedBytes * 1000 / elapsedTime / 1024) << "kB/s and" - << elapsedTime << "ms"; -} - -void tst_QNetworkReply::uploadPerformance() -{ - ThreadedDataReader reader; - DataGenerator generator; - - - QNetworkRequest request("debugpipe://127.0.0.1:" + QString::number(reader.serverPort()) + "/?bare=1"); - QNetworkReplyPtr reply = manager.put(request, &generator); - generator.start(); - connect(&reader, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTimer::singleShot(5000, &generator, SLOT(stop())); - - QTestEventLoop::instance().enterLoop(30); - QCOMPARE(reply->error(), QNetworkReply::NoError); - QVERIFY(!QTestEventLoop::instance().timeout()); -} - -void tst_QNetworkReply::httpUploadPerformance() -{ -#ifdef Q_OS_SYMBIAN - // SHow some mercy for non-desktop platform/s - enum {UploadSize = 4*1024*1024}; // 4 MB -#else - enum {UploadSize = 128*1024*1024}; // 128 MB -#endif - ThreadedDataReaderHttpServer reader; - FixedSizeDataGenerator generator(UploadSize); - - QNetworkRequest request(QUrl("http://127.0.0.1:" + QString::number(reader.serverPort()) + "/?bare=1")); - request.setHeader(QNetworkRequest::ContentLengthHeader,UploadSize); - - QNetworkReplyPtr reply = manager.put(request, &generator); - - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - - QTime time; - generator.start(); - time.start(); - QTestEventLoop::instance().enterLoop(40); - QCOMPARE(reply->error(), QNetworkReply::NoError); - QVERIFY(!QTestEventLoop::instance().timeout()); - - qint64 elapsed = time.elapsed(); - qDebug() << "tst_QNetworkReply::httpUploadPerformance" << elapsed << "msec, " - << ((UploadSize/1024.0)/(elapsed/1000.0)) << " kB/sec"; - - reader.exit(); - reader.wait(); -} - - -void tst_QNetworkReply::performanceControlRate() -{ - // this is a control comparison for the other two above - // it does the same thing, but instead bypasses the QNetworkAccess system - qDebug() << "The following are the maximum transfer rates that we can get in this system" - " (bypassing QNetworkAccess)"; - - TimedSender sender(5000); - QTcpSocket sink; - sink.connectToHost("127.0.0.1", sender.serverPort()); - DataReader reader(&sink, false); - - QTime loopTime; - connect(&sink, SIGNAL(disconnected()), &QTestEventLoop::instance(), SLOT(exitLoop())); - loopTime.start(); - QTestEventLoop::instance().enterLoop(40); - int elapsedTime = loopTime.elapsed(); - sender.wait(); - - qint64 receivedBytes = reader.totalBytes; - qDebug() << "tst_QNetworkReply::performanceControlRate" << "receive rate:" << (receivedBytes * 1000 / elapsedTime / 1024) << "kB/s and" - << elapsedTime << "ms"; -} - -void tst_QNetworkReply::httpDownloadPerformance_data() -{ - QTest::addColumn<bool>("serverSendsContentLength"); - QTest::addColumn<bool>("chunkedEncoding"); - - QTest::newRow("Server sends no Content-Length") << false << false; - QTest::newRow("Server sends Content-Length") << true << false; - QTest::newRow("Server uses chunked encoding") << false << true; - -} - -void tst_QNetworkReply::httpDownloadPerformance() -{ - QFETCH(bool, serverSendsContentLength); - QFETCH(bool, chunkedEncoding); -#ifdef Q_OS_SYMBIAN - // Show some mercy to non-desktop platform/s - enum {UploadSize = 4*1024*1024}; // 4 MB -#else - enum {UploadSize = 128*1024*1024}; // 128 MB -#endif - HttpDownloadPerformanceServer server(UploadSize, serverSendsContentLength, chunkedEncoding); - - QNetworkRequest request(QUrl("http://127.0.0.1:" + QString::number(server.serverPort()) + "/?bare=1")); - QNetworkReplyPtr reply = manager.get(request); - - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection); - HttpDownloadPerformanceClient client(reply); - - QTime time; - time.start(); - QTestEventLoop::instance().enterLoop(40); - QCOMPARE(reply->error(), QNetworkReply::NoError); - QVERIFY(!QTestEventLoop::instance().timeout()); - - qint64 elapsed = time.elapsed(); - qDebug() << "tst_QNetworkReply::httpDownloadPerformance" << elapsed << "msec, " - << ((UploadSize/1024.0)/(elapsed/1000.0)) << " kB/sec"; -} - void tst_QNetworkReply::downloadProgress_data() { QTest::addColumn<int>("loopCount"); diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp index 4d2c626..8b71349 100644 --- a/tests/auto/qpainter/tst_qpainter.cpp +++ b/tests/auto/qpainter/tst_qpainter.cpp @@ -101,6 +101,8 @@ private slots: void saveAndRestore_data(); void saveAndRestore(); + void drawBorderPixmap(); + void drawLine_data(); void drawLine(); void drawLine_clipped(); @@ -973,6 +975,18 @@ void tst_QPainter::initFrom() delete widget; } +void tst_QPainter::drawBorderPixmap() +{ + QPixmap src(79,79); + src.fill(Qt::transparent); + + QImage pm(200,200,QImage::Format_RGB32); + QPainter p(&pm); + p.setTransform(QTransform(-1,0,0,-1,173.5,153.5)); + qDrawBorderPixmap(&p, QRect(0,0,75,105), QMargins(39,39,39,39), src, QRect(0,0,79,79), QMargins(39,39,39,39), + QTileRules(Qt::StretchTile,Qt::StretchTile), 0); +} + void tst_QPainter::drawLine_data() { QTest::addColumn<QLine>("line"); @@ -2918,7 +2932,7 @@ void tst_QPainter::monoImages() QImage img(2, 2, format); - if (img.numColors() > 0) { + if (img.colorCount() > 0) { img.setColor(0, QColor(colorPairs[j][0]).rgba()); img.setColor(1, QColor(colorPairs[j][1]).rgba()); } @@ -2940,7 +2954,7 @@ void tst_QPainter::monoImages() // should not change the image QCOMPARE(original, img); - if (img.numColors() == 0) + if (img.colorCount() == 0) continue; for (int k = 0; k < 2; ++k) { diff --git a/tests/auto/qpixmap/tst_qpixmap.cpp b/tests/auto/qpixmap/tst_qpixmap.cpp index 8e02c74..d7f042e 100644 --- a/tests/auto/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/qpixmap/tst_qpixmap.cpp @@ -293,7 +293,7 @@ void tst_QPixmap::setAlphaChannel() QRgb expected = alpha == 0 ? 0 : qRgba(red, green, blue, alpha); for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { - if (result.numColors() > 0) { + if (result.colorCount() > 0) { ok &= result.pixelIndex(x, y) == expected; } else { ok &= result.pixel(x, y) == expected; @@ -330,7 +330,7 @@ void tst_QPixmap::fromImage() QImage image(37, 16, format); - if (image.numColors() == 2) { + if (image.colorCount() == 2) { image.setColor(0, QColor(Qt::color0).rgba()); image.setColor(1, QColor(Qt::color1).rgba()); } @@ -731,7 +731,7 @@ void tst_QPixmap::testMetrics() void tst_QPixmap::createMaskFromColor() { QImage image(3, 3, QImage::Format_Indexed8); - image.setNumColors(10); + image.setColorCount(10); image.setColor(0, 0xffffffff); image.setColor(1, 0xff000000); image.setColor(2, 0xffff0000); diff --git a/tests/auto/qregexp/tst_qregexp.cpp b/tests/auto/qregexp/tst_qregexp.cpp index 86d831e..e305386 100644 --- a/tests/auto/qregexp/tst_qregexp.cpp +++ b/tests/auto/qregexp/tst_qregexp.cpp @@ -628,7 +628,7 @@ void tst_QRegExp::capturedTexts() QRegExp rx7("([A-Za-z_])([A-Za-z_0-9]*)"); rx7.setCaseSensitivity(Qt::CaseSensitive); rx7.setPatternSyntax(QRegExp::RegExp); - QCOMPARE(rx7.numCaptures(), 2); + QCOMPARE(rx7.captureCount(), 2); int pos = rx7.indexIn("(10 + delta4) * 32"); QCOMPARE(pos, 6); @@ -1177,36 +1177,36 @@ void tst_QRegExp::prepareEngineOptimization() QCOMPARE(rx1.capturedTexts(), QStringList() << "" << "" << "" << ""); QCOMPARE(rx1.matchedLength(), -1); QCOMPARE(rx1.matchedLength(), -1); - QCOMPARE(rx1.numCaptures(), 3); + QCOMPARE(rx1.captureCount(), 3); QCOMPARE(rx1.exactMatch("foo"), true); QCOMPARE(rx1.matchedLength(), 3); QCOMPARE(rx1.capturedTexts(), QStringList() << "foo" << "f" << "o" << "o"); - QCOMPARE(rx1.numCaptures(), 3); + QCOMPARE(rx1.captureCount(), 3); QCOMPARE(rx1.matchedLength(), 3); QCOMPARE(rx1.capturedTexts(), QStringList() << "foo" << "f" << "o" << "o"); QCOMPARE(rx1.pos(3), 2); QCOMPARE(rx1.exactMatch("foo"), true); - QCOMPARE(rx1.numCaptures(), 3); + QCOMPARE(rx1.captureCount(), 3); QCOMPARE(rx1.matchedLength(), 3); QCOMPARE(rx1.capturedTexts(), QStringList() << "foo" << "f" << "o" << "o"); QCOMPARE(rx1.pos(3), 2); QRegExp rx2 = rx1; - QCOMPARE(rx1.numCaptures(), 3); + QCOMPARE(rx1.captureCount(), 3); QCOMPARE(rx1.matchedLength(), 3); QCOMPARE(rx1.capturedTexts(), QStringList() << "foo" << "f" << "o" << "o"); QCOMPARE(rx1.pos(3), 2); - QCOMPARE(rx2.numCaptures(), 3); + QCOMPARE(rx2.captureCount(), 3); QCOMPARE(rx2.matchedLength(), 3); QCOMPARE(rx2.capturedTexts(), QStringList() << "foo" << "f" << "o" << "o"); QCOMPARE(rx2.pos(3), 2); QCOMPARE(rx1.exactMatch("fo"), true); - QCOMPARE(rx1.numCaptures(), 3); + QCOMPARE(rx1.captureCount(), 3); QCOMPARE(rx1.matchedLength(), 2); QCOMPARE(rx1.capturedTexts(), QStringList() << "fo" << "f" << "o" << ""); QCOMPARE(rx1.pos(2), 1); @@ -1245,25 +1245,25 @@ void tst_QRegExp::prepareEngineOptimization() rx11.setPatternSyntax(QRegExp::Wildcard); QVERIFY(!rx11.isValid()); - QCOMPARE(rx11.numCaptures(), 0); + QCOMPARE(rx11.captureCount(), 0); QCOMPARE(rx11.matchedLength(), -1); rx11.setPatternSyntax(QRegExp::RegExp); QVERIFY(!rx11.isValid()); - QCOMPARE(rx11.numCaptures(), 0); + QCOMPARE(rx11.captureCount(), 0); QCOMPARE(rx11.matchedLength(), -1); rx11.setPattern("(foo)"); QVERIFY(rx11.isValid()); - QCOMPARE(rx11.numCaptures(), 1); + QCOMPARE(rx11.captureCount(), 1); QCOMPARE(rx11.matchedLength(), -1); QCOMPARE(rx11.indexIn("ofoo"), 1); - QCOMPARE(rx11.numCaptures(), 1); + QCOMPARE(rx11.captureCount(), 1); QCOMPARE(rx11.matchedLength(), 3); rx11.setPatternSyntax(QRegExp::RegExp); - QCOMPARE(rx11.numCaptures(), 1); + QCOMPARE(rx11.captureCount(), 1); QCOMPARE(rx11.matchedLength(), 3); /* @@ -1278,11 +1278,11 @@ void tst_QRegExp::prepareEngineOptimization() QCOMPARE(rx11.matchedLength(), 3); rx11.setPatternSyntax(QRegExp::Wildcard); - QCOMPARE(rx11.numCaptures(), 0); + QCOMPARE(rx11.captureCount(), 0); QCOMPARE(rx11.matchedLength(), -1); rx11.setPatternSyntax(QRegExp::RegExp); - QCOMPARE(rx11.numCaptures(), 1); + QCOMPARE(rx11.captureCount(), 1); QCOMPARE(rx11.matchedLength(), -1); } diff --git a/tests/auto/qregion/tst_qregion.cpp b/tests/auto/qregion/tst_qregion.cpp index e5a3151..582b5e8 100644 --- a/tests/auto/qregion/tst_qregion.cpp +++ b/tests/auto/qregion/tst_qregion.cpp @@ -88,8 +88,8 @@ private slots: void operator_xor_data(); void operator_xor(); - void numRects_data(); - void numRects(); + void rectCount_data(); + void rectCount(); void isEmpty_data(); void isEmpty(); @@ -554,7 +554,7 @@ void tst_QRegion::operator_plus() qDebug() << "expected" << expected; } QCOMPARE(r1 + r2, expected); - if (r2.numRects() == 1) { + if (r2.rectCount() == 1) { if (r1 + r2.boundingRect() != expected) { qDebug() << "r1 + QRect(r2)" << (r1 + r2.boundingRect()); qDebug() << "expected" << expected; @@ -567,7 +567,7 @@ void tst_QRegion::operator_plus() qDebug() << "expected" << expected; } QCOMPARE(r2 + r1, expected); - if (r1.numRects() == 1) { + if (r1.rectCount() == 1) { if (r1 + r2.boundingRect() != expected) { qDebug() << "r2 + QRect(r1)" << (r2 + r1.boundingRect()); qDebug() << "expected" << expected; @@ -582,7 +582,7 @@ void tst_QRegion::operator_plus() qDebug() << "expected" << expected; } QCOMPARE(result1, expected); - if (r2.numRects() == 1) { + if (r2.rectCount() == 1) { result1 = r1; result1 += r2.boundingRect(); if (result1 != expected) { @@ -599,7 +599,7 @@ void tst_QRegion::operator_plus() qDebug() << "expected" << expected; } QCOMPARE(result2, expected); - if (r1.numRects() == 1) { + if (r1.rectCount() == 1) { result2 = r2; result2 += r1.boundingRect(); if (result2 != expected) { @@ -802,7 +802,7 @@ void tst_QRegion::operator_xor() QCOMPARE(dest, expected); } -void tst_QRegion::numRects_data() +void tst_QRegion::rectCount_data() { QTest::addColumn<QRegion>("region"); QTest::addColumn<int>("expected"); @@ -818,12 +818,12 @@ void tst_QRegion::numRects_data() QTest::newRow("2 rects") << dest << rects.size(); } -void tst_QRegion::numRects() +void tst_QRegion::rectCount() { QFETCH(QRegion, region); QFETCH(int, expected); - QCOMPARE(region.numRects(), expected); + QCOMPARE(region.rectCount(), expected); } void tst_QRegion::isEmpty_data() @@ -850,7 +850,7 @@ void tst_QRegion::isEmpty() QVERIFY(region.isEmpty()); QCOMPARE(region, QRegion()); - QCOMPARE(region.numRects(), 0); + QCOMPARE(region.rectCount(), 0); QCOMPARE(region.boundingRect(), QRect()); QVERIFY(region.rects().isEmpty()); } diff --git a/tests/auto/qscopedpointer/tst_qscopedpointer.cpp b/tests/auto/qscopedpointer/tst_qscopedpointer.cpp index aeead15..f319891 100644 --- a/tests/auto/qscopedpointer/tst_qscopedpointer.cpp +++ b/tests/auto/qscopedpointer/tst_qscopedpointer.cpp @@ -313,30 +313,152 @@ void tst_QScopedPointer::objectSize() QCOMPARE(sizeof(QScopedPointer<int>), sizeof(void *)); } -void tst_QScopedPointer::comparison() +struct RefCounted { - int *a = new int(42); - int *b = new int(43); + RefCounted() + : ref(0) + { + instanceCount.ref(); + } + + RefCounted(RefCounted const &other) + : ref(0) + { + instanceCount.ref(); + } + + ~RefCounted() + { + QVERIFY( ref == 0 ); + instanceCount.deref(); + } + + RefCounted &operator=(RefCounted const &) + { + } + + QAtomicInt ref; + + static QAtomicInt instanceCount; +}; - QScopedPointer<int> pa(a); - QScopedPointer<int> pa2(a); - QScopedPointer<int> pb(b); +QAtomicInt RefCounted::instanceCount = 0; +template <class A1, class A2, class B> +void scopedPointerComparisonTest(const A1 &a1, const A2 &a2, const B &b) +{ // test equality on equal pointers - QVERIFY(pa == pa2); - QVERIFY(pa2 == pa); + QVERIFY(a1 == a2); + QVERIFY(a2 == a1); + + // test inequality on equal pointers + QVERIFY(!(a1 != a2)); + QVERIFY(!(a2 != a1)); + + // test equality on unequal pointers + QVERIFY(!(a1 == b)); + QVERIFY(!(a2 == b)); + QVERIFY(!(b == a1)); + QVERIFY(!(b == a2)); + + // test inequality on unequal pointers + QVERIFY(b != a1); + QVERIFY(b != a2); + QVERIFY(a1 != b); + QVERIFY(a2 != b); +} + +void tst_QScopedPointer::comparison() +{ + QCOMPARE( int(RefCounted::instanceCount), 0 ); + + { + RefCounted *a = new RefCounted; + RefCounted *b = new RefCounted; + + QCOMPARE( int(RefCounted::instanceCount), 2 ); + + QScopedPointer<RefCounted> pa1(a); + QScopedPointer<RefCounted> pa2(a); + QScopedPointer<RefCounted> pb(b); + + scopedPointerComparisonTest(pa1, pa1, pb); + scopedPointerComparisonTest(pa2, pa2, pb); + scopedPointerComparisonTest(pa1, pa2, pb); + + pa2.take(); + + QCOMPARE( int(RefCounted::instanceCount), 2 ); + } - // test unequality on equal pointers - QVERIFY(!(pa != pa2)); - QVERIFY(!(pa2 != pa)); + QCOMPARE( int(RefCounted::instanceCount), 0 ); - // test on unequal pointers - QVERIFY(!(pa == pb)); - QVERIFY(!(pb == pa)); - QVERIFY(pb != pa); - QVERIFY(pa != pb); + { + RefCounted *a = new RefCounted[42]; + RefCounted *b = new RefCounted[43]; + + QCOMPARE( int(RefCounted::instanceCount), 85 ); + + QScopedArrayPointer<RefCounted> pa1(a); + QScopedArrayPointer<RefCounted> pa2(a); + QScopedArrayPointer<RefCounted> pb(b); + + scopedPointerComparisonTest(pa1, pa2, pb); + + pa2.take(); + + QCOMPARE( int(RefCounted::instanceCount), 85 ); + } + + QCOMPARE( int(RefCounted::instanceCount), 0 ); + + { + // QCustomScopedPointer is an internal helper class -- it is unsupported! + + RefCounted *a = new RefCounted; + RefCounted *b = new RefCounted; + + QCOMPARE( int(RefCounted::instanceCount), 2 ); + + QCustomScopedPointer<RefCounted> pa1(a); + QCustomScopedPointer<RefCounted> pa2(a); + QCustomScopedPointer<RefCounted> pb(b); + + scopedPointerComparisonTest(pa1, pa2, pb); + + pa2.take(); + + QCOMPARE( int(RefCounted::instanceCount), 2 ); + } + + QCOMPARE( int(RefCounted::instanceCount), 0 ); + + { + // QScopedSharedPointer is an internal helper class -- it is unsupported! + + RefCounted *a = new RefCounted; + RefCounted *b = new RefCounted; + + QCOMPARE( int(RefCounted::instanceCount), 2 ); + + a->ref.ref(); + QScopedSharedPointer<RefCounted> pa1(a); + a->ref.ref(); + QScopedSharedPointer<RefCounted> pa2(a); + b->ref.ref(); + QScopedSharedPointer<RefCounted> pb(b); + + + QCOMPARE( int(a->ref), 2 ); + QCOMPARE( int(b->ref), 1 ); + QCOMPARE( int(RefCounted::instanceCount), 2 ); + + scopedPointerComparisonTest(pa1, pa2, pb); + + QCOMPARE( int(RefCounted::instanceCount), 2 ); + } - pa2.take(); + QCOMPARE( int(RefCounted::instanceCount), 0 ); } QTEST_MAIN(tst_QScopedPointer) diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index 804534f..8eaad78 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -4485,7 +4485,7 @@ void tst_QScriptEngine::qRegExpInport() QScriptValue result = func.call(QScriptValue(), QScriptValueList() << string << rexp); rx.indexIn(string); - for (int i = 0; i <= rx.numCaptures(); i++) { + for (int i = 0; i <= rx.captureCount(); i++) { QCOMPARE(result.property(i).toString(), rx.cap(i)); } } diff --git a/tests/auto/qtextdocument/tst_qtextdocument.cpp b/tests/auto/qtextdocument/tst_qtextdocument.cpp index 5237438..1d54409 100644 --- a/tests/auto/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/qtextdocument/tst_qtextdocument.cpp @@ -1721,21 +1721,21 @@ void tst_QTextDocument::capitalizationHtmlInExport() const QString smallcaps = doc->toHtml(); QVERIFY(re.exactMatch(doc->toHtml())); - QCOMPARE(re.numCaptures(), 1); + QCOMPARE(re.captureCount(), 1); QCOMPARE(re.cap(1).trimmed(), QString("font-variant:small-caps;")); cf.setFontCapitalization(QFont::AllUppercase); cursor.mergeCharFormat(cf); const QString uppercase = doc->toHtml(); QVERIFY(re.exactMatch(doc->toHtml())); - QCOMPARE(re.numCaptures(), 1); + QCOMPARE(re.captureCount(), 1); QCOMPARE(re.cap(1).trimmed(), QString("text-transform:uppercase;")); cf.setFontCapitalization(QFont::AllLowercase); cursor.mergeCharFormat(cf); const QString lowercase = doc->toHtml(); QVERIFY(re.exactMatch(doc->toHtml())); - QCOMPARE(re.numCaptures(), 1); + QCOMPARE(re.captureCount(), 1); QCOMPARE(re.cap(1).trimmed(), QString("text-transform:lowercase;")); doc->setHtml(smallcaps); @@ -1761,14 +1761,14 @@ void tst_QTextDocument::wordspacingHtmlExport() cursor.mergeCharFormat(cf); QVERIFY(re.exactMatch(doc->toHtml())); - QCOMPARE(re.numCaptures(), 1); + QCOMPARE(re.captureCount(), 1); QCOMPARE(re.cap(1).trimmed(), QString("word-spacing:4px;")); cf.setFontWordSpacing(-8.5); cursor.mergeCharFormat(cf); QVERIFY(re.exactMatch(doc->toHtml())); - QCOMPARE(re.numCaptures(), 1); + QCOMPARE(re.captureCount(), 1); QCOMPARE(re.cap(1).trimmed(), QString("word-spacing:-8.5px;")); } diff --git a/tests/benchmarks/qnetworkreply/tst_qnetworkreply.cpp b/tests/benchmarks/qnetworkreply/tst_qnetworkreply.cpp index 993db52..1d50013 100644 --- a/tests/benchmarks/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/benchmarks/qnetworkreply/tst_qnetworkreply.cpp @@ -46,11 +46,397 @@ #include <QtNetwork/qnetworkreply.h> #include <QtNetwork/qnetworkrequest.h> #include <QtNetwork/qnetworkaccessmanager.h> +#include <QtNetwork/qtcpsocket.h> +#include <QtNetwork/qtcpserver.h> #include "../../auto/network-settings.h" + +class TimedSender: public QThread +{ + Q_OBJECT + qint64 totalBytes; + QSemaphore ready; + QByteArray dataToSend; + QTcpSocket *client; + int timeout; + int port; +public: + int transferRate; + TimedSender(int ms) + : totalBytes(0), timeout(ms), port(-1), transferRate(-1) + { + dataToSend = QByteArray(16*1024, '@'); + start(); + ready.acquire(); + } + + inline int serverPort() const { return port; } + +private slots: + void writeMore() + { + while (client->bytesToWrite() < 128 * 1024) { + writePacket(dataToSend); + } + } + +protected: + void run() + { + QTcpServer server; + server.listen(); + port = server.serverPort(); + ready.release(); + + server.waitForNewConnection(-1); + client = server.nextPendingConnection(); + + writeMore(); + connect(client, SIGNAL(bytesWritten(qint64)), SLOT(writeMore()), Qt::DirectConnection); + + QEventLoop eventLoop; + QTimer::singleShot(timeout, &eventLoop, SLOT(quit())); + + QTime timer; + timer.start(); + eventLoop.exec(); + disconnect(client, SIGNAL(bytesWritten(qint64)), this, 0); + + // wait for the connection to shut down + client->disconnectFromHost(); + if (!client->waitForDisconnected(10000)) + return; + + transferRate = totalBytes * 1000 / timer.elapsed(); + qDebug() << "TimedSender::run" << "receive rate:" << (transferRate / 1024) << "kB/s in" + << timer.elapsed() << "ms"; + } + + void writePacket(const QByteArray &array) + { + client->write(array); + totalBytes += array.size(); + } +}; + + +class QNetworkReplyPtr: public QSharedPointer<QNetworkReply> +{ +public: + inline QNetworkReplyPtr(QNetworkReply *ptr = 0) + : QSharedPointer<QNetworkReply>(ptr) + { } + + inline operator QNetworkReply *() const { return data(); } +}; + + +class DataReader: public QObject +{ + Q_OBJECT +public: + qint64 totalBytes; + QByteArray data; + QIODevice *device; + bool accumulate; + DataReader(QIODevice *dev, bool acc = true) : totalBytes(0), device(dev), accumulate(acc) + { + connect(device, SIGNAL(readyRead()), SLOT(doRead())); + } + +public slots: + void doRead() + { + QByteArray buffer; + buffer.resize(device->bytesAvailable()); + qint64 bytesRead = device->read(buffer.data(), device->bytesAvailable()); + if (bytesRead == -1) { + QTestEventLoop::instance().exitLoop(); + return; + } + buffer.truncate(bytesRead); + totalBytes += bytesRead; + + if (accumulate) + data += buffer; + } +}; + +class ThreadedDataReader: public QThread +{ + Q_OBJECT + // used to make the constructor only return after the tcp server started listening + QSemaphore ready; + QTcpSocket *client; + int timeout; + int port; +public: + qint64 transferRate; + ThreadedDataReader() + : port(-1), transferRate(-1) + { + start(); + ready.acquire(); + } + + inline int serverPort() const { return port; } + +protected: + void run() + { + QTcpServer server; + server.listen(); + port = server.serverPort(); + ready.release(); + + server.waitForNewConnection(-1); + client = server.nextPendingConnection(); + + QEventLoop eventLoop; + DataReader reader(client, false); + QObject::connect(client, SIGNAL(disconnected()), &eventLoop, SLOT(quit())); + + QTime timer; + timer.start(); + eventLoop.exec(); + qint64 elapsed = timer.elapsed(); + + transferRate = reader.totalBytes * 1000 / elapsed; + qDebug() << "ThreadedDataReader::run" << "send rate:" << (transferRate / 1024) << "kB/s in" << elapsed << "msec"; + } +}; + +class DataGenerator: public QIODevice +{ + Q_OBJECT + enum { Idle, Started, Stopped } state; +public: + DataGenerator() : state(Idle) + { open(ReadOnly); } + + virtual bool isSequential() const { return true; } + virtual qint64 bytesAvailable() const { return state == Started ? 1024*1024 : 0; } + +public slots: + void start() { state = Started; emit readyRead(); } + void stop() { state = Stopped; emit readyRead(); } + +protected: + virtual qint64 readData(char *data, qint64 maxlen) + { + if (state == Stopped) + return -1; // EOF + + // return as many bytes as are wanted + memset(data, '@', maxlen); + return maxlen; + } + virtual qint64 writeData(const char *, qint64) + { return -1; } +}; + +class ThreadedDataReaderHttpServer: public QThread +{ + Q_OBJECT + // used to make the constructor only return after the tcp server started listening + QSemaphore ready; + QTcpSocket *client; + int timeout; + int port; +public: + qint64 transferRate; + ThreadedDataReaderHttpServer() + : port(-1), transferRate(-1) + { + start(); + ready.acquire(); + } + + inline int serverPort() const { return port; } + +protected: + void run() + { + QTcpServer server; + server.listen(); + port = server.serverPort(); + ready.release(); + + server.waitForNewConnection(-1); + client = server.nextPendingConnection(); + client->write("HTTP/1.0 200 OK\r\n"); + client->write("Content-length: 0\r\n"); + client->write("\r\n"); + client->flush(); + + QCoreApplication::processEvents(); + + QEventLoop eventLoop; + DataReader reader(client, false); + QObject::connect(client, SIGNAL(disconnected()), &eventLoop, SLOT(quit())); + + QTime timer; + timer.start(); + eventLoop.exec(); + qint64 elapsed = timer.elapsed(); + + transferRate = reader.totalBytes * 1000 / elapsed; + qDebug() << "ThreadedDataReaderHttpServer::run" << "send rate:" << (transferRate / 1024) << "kB/s in" << elapsed << "msec"; + } +}; + + +class FixedSizeDataGenerator : public QIODevice +{ + Q_OBJECT + enum { Idle, Started, Stopped } state; +public: + FixedSizeDataGenerator(qint64 size) : state(Idle) + { open(ReadOnly | Unbuffered); + toBeGeneratedTotalCount = toBeGeneratedCount = size; + } + + virtual qint64 bytesAvailable() const + { + return state == Started ? toBeGeneratedCount + QIODevice::bytesAvailable() : 0; + } + + virtual bool isSequential() const{ + return false; + } + + virtual bool reset() const{ + return false; + } + + qint64 size() const { + return toBeGeneratedTotalCount; + } + +public slots: + void start() { state = Started; emit readyRead(); } + +protected: + virtual qint64 readData(char *data, qint64 maxlen) + { + memset(data, '@', maxlen); + + if (toBeGeneratedCount <= 0) { + return -1; + } + + qint64 n = qMin(maxlen, toBeGeneratedCount); + toBeGeneratedCount -= n; + + if (toBeGeneratedCount <= 0) { + // make sure this is a queued connection! + emit readChannelFinished(); + } + + return n; + } + virtual qint64 writeData(const char *, qint64) + { return -1; } + + qint64 toBeGeneratedCount; + qint64 toBeGeneratedTotalCount; +}; + +class HttpDownloadPerformanceServer : QObject { + Q_OBJECT; + qint64 dataSize; + qint64 dataSent; + QTcpServer server; + QTcpSocket *client; + bool serverSendsContentLength; + bool chunkedEncoding; + +public: + HttpDownloadPerformanceServer (qint64 ds, bool sscl, bool ce) : dataSize(ds), dataSent(0), + client(0), serverSendsContentLength(sscl), chunkedEncoding(ce) { + server.listen(); + connect(&server, SIGNAL(newConnection()), this, SLOT(newConnectionSlot())); + } + + int serverPort() { + return server.serverPort(); + } + +public slots: + + void newConnectionSlot() { + client = server.nextPendingConnection(); + client->setParent(this); + connect(client, SIGNAL(readyRead()), this, SLOT(readyReadSlot())); + connect(client, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWrittenSlot(qint64))); + } + + void readyReadSlot() { + client->readAll(); + client->write("HTTP/1.0 200 OK\n"); + if (serverSendsContentLength) + client->write(QString("Content-Length: " + QString::number(dataSize) + "\n").toAscii()); + if (chunkedEncoding) + client->write(QString("Transfer-Encoding: chunked\n").toAscii()); + client->write("Connection: close\n\n"); + } + + void bytesWrittenSlot(qint64 amount) { + Q_UNUSED(amount); + if (dataSent == dataSize && client) { + // close eventually + + // chunked encoding: we have to send a last "empty" chunk + if (chunkedEncoding) + client->write(QString("0\r\n\r\n").toAscii()); + + client->disconnectFromHost(); + server.close(); + client = 0; + return; + } + + // send data + if (client && client->bytesToWrite() < 100*1024 && dataSent < dataSize) { + qint64 amount = qMin(qint64(16*1024), dataSize - dataSent); + QByteArray data(amount, '@'); + + if (chunkedEncoding) { + client->write(QString(QString("%1").arg(amount,0,16).toUpper() + "\r\n").toAscii()); + client->write(data.constData(), amount); + client->write(QString("\r\n").toAscii()); + } else { + client->write(data.constData(), amount); + } + + dataSent += amount; + } + } +}; + +class HttpDownloadPerformanceClient : QObject { + Q_OBJECT; + QIODevice *device; + public: + HttpDownloadPerformanceClient (QIODevice *dev) : device(dev){ + connect(dev, SIGNAL(readyRead()), this, SLOT(readyReadSlot())); + } + + public slots: + void readyReadSlot() { + device->readAll(); + } + +}; + + + + class tst_qnetworkreply : public QObject { Q_OBJECT + + QNetworkAccessManager manager; private slots: void httpLatency(); @@ -58,6 +444,14 @@ private slots: void echoPerformance_data(); void echoPerformance(); #endif + + void downloadPerformance(); + void uploadPerformance(); + void performanceControlRate(); + void httpUploadPerformance(); + void httpDownloadPerformance_data(); + void httpDownloadPerformance(); + }; void tst_qnetworkreply::httpLatency() @@ -107,6 +501,142 @@ void tst_qnetworkreply::echoPerformance() } #endif +void tst_qnetworkreply::downloadPerformance() +{ + // unlike the above function, this one tries to send as fast as possible + // and measures how fast it was. + TimedSender sender(5000); + QNetworkRequest request("debugpipe://127.0.0.1:" + QString::number(sender.serverPort()) + "/?bare=1"); + QNetworkReplyPtr reply = manager.get(request); + DataReader reader(reply, false); + + QTime loopTime; + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + loopTime.start(); + QTestEventLoop::instance().enterLoop(40); + int elapsedTime = loopTime.elapsed(); + sender.wait(); + + qint64 receivedBytes = reader.totalBytes; + qDebug() << "tst_QNetworkReply::downloadPerformance" << "receive rate:" << (receivedBytes * 1000 / elapsedTime / 1024) << "kB/s and" + << elapsedTime << "ms"; +} + +void tst_qnetworkreply::uploadPerformance() +{ + ThreadedDataReader reader; + DataGenerator generator; + + + QNetworkRequest request("debugpipe://127.0.0.1:" + QString::number(reader.serverPort()) + "/?bare=1"); + QNetworkReplyPtr reply = manager.put(request, &generator); + generator.start(); + connect(&reader, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + QTimer::singleShot(5000, &generator, SLOT(stop())); + + QTestEventLoop::instance().enterLoop(30); + QCOMPARE(reply->error(), QNetworkReply::NoError); + QVERIFY(!QTestEventLoop::instance().timeout()); +} + +void tst_qnetworkreply::httpUploadPerformance() +{ +#ifdef Q_OS_SYMBIAN + // SHow some mercy for non-desktop platform/s + enum {UploadSize = 4*1024*1024}; // 4 MB +#else + enum {UploadSize = 128*1024*1024}; // 128 MB +#endif + ThreadedDataReaderHttpServer reader; + FixedSizeDataGenerator generator(UploadSize); + + QNetworkRequest request(QUrl("http://127.0.0.1:" + QString::number(reader.serverPort()) + "/?bare=1")); + request.setHeader(QNetworkRequest::ContentLengthHeader,UploadSize); + + QNetworkReplyPtr reply = manager.put(request, &generator); + + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + + QTime time; + generator.start(); + time.start(); + QTestEventLoop::instance().enterLoop(40); + QCOMPARE(reply->error(), QNetworkReply::NoError); + QVERIFY(!QTestEventLoop::instance().timeout()); + + qint64 elapsed = time.elapsed(); + qDebug() << "tst_QNetworkReply::httpUploadPerformance" << elapsed << "msec, " + << ((UploadSize/1024.0)/(elapsed/1000.0)) << " kB/sec"; + + reader.exit(); + reader.wait(); +} + + +void tst_qnetworkreply::performanceControlRate() +{ + // this is a control comparison for the other two above + // it does the same thing, but instead bypasses the QNetworkAccess system + qDebug() << "The following are the maximum transfer rates that we can get in this system" + " (bypassing QNetworkAccess)"; + + TimedSender sender(5000); + QTcpSocket sink; + sink.connectToHost("127.0.0.1", sender.serverPort()); + DataReader reader(&sink, false); + + QTime loopTime; + connect(&sink, SIGNAL(disconnected()), &QTestEventLoop::instance(), SLOT(exitLoop())); + loopTime.start(); + QTestEventLoop::instance().enterLoop(40); + int elapsedTime = loopTime.elapsed(); + sender.wait(); + + qint64 receivedBytes = reader.totalBytes; + qDebug() << "tst_QNetworkReply::performanceControlRate" << "receive rate:" << (receivedBytes * 1000 / elapsedTime / 1024) << "kB/s and" + << elapsedTime << "ms"; +} + +void tst_qnetworkreply::httpDownloadPerformance_data() +{ + QTest::addColumn<bool>("serverSendsContentLength"); + QTest::addColumn<bool>("chunkedEncoding"); + + QTest::newRow("Server sends no Content-Length") << false << false; + QTest::newRow("Server sends Content-Length") << true << false; + QTest::newRow("Server uses chunked encoding") << false << true; + +} + +void tst_qnetworkreply::httpDownloadPerformance() +{ + QFETCH(bool, serverSendsContentLength); + QFETCH(bool, chunkedEncoding); +#ifdef Q_OS_SYMBIAN + // Show some mercy to non-desktop platform/s + enum {UploadSize = 4*1024*1024}; // 4 MB +#else + enum {UploadSize = 128*1024*1024}; // 128 MB +#endif + HttpDownloadPerformanceServer server(UploadSize, serverSendsContentLength, chunkedEncoding); + + QNetworkRequest request(QUrl("http://127.0.0.1:" + QString::number(server.serverPort()) + "/?bare=1")); + QNetworkReplyPtr reply = manager.get(request); + + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection); + HttpDownloadPerformanceClient client(reply); + + QTime time; + time.start(); + QTestEventLoop::instance().enterLoop(40); + QCOMPARE(reply->error(), QNetworkReply::NoError); + QVERIFY(!QTestEventLoop::instance().timeout()); + + qint64 elapsed = time.elapsed(); + qDebug() << "tst_QNetworkReply::httpDownloadPerformance" << elapsed << "msec, " + << ((UploadSize/1024.0)/(elapsed/1000.0)) << " kB/sec"; +} + QTEST_MAIN(tst_qnetworkreply) #include "tst_qnetworkreply.moc" |