From 6f52892206b155451e7b24cdbb1b4ab6569153e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Tue, 20 Oct 2009 15:39:06 +0200 Subject: Get file position when attaching an open file descriptor to QFile This was already being done when attaching to FILE* streams. Doing the same here makes the API consistent and more usable. Namely, one can use QFile::pos() to obtain the file position. Test case verifies this doesn't break support for sequential files. More thorough test case included in large file support test. Reviewed-by: Thiago Macieira --- tests/auto/qfile/tst_qfile.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp index 19fbecd239..bbb62805b0 100644 --- a/tests/auto/qfile/tst_qfile.cpp +++ b/tests/auto/qfile/tst_qfile.cpp @@ -187,6 +187,8 @@ private slots: void mapOpenMode_data(); void mapOpenMode(); + void openStandardStreams(); + // --- Task related tests below this line void task167217(); @@ -2634,5 +2636,58 @@ void tst_QFile::openDirectory() QVERIFY(!f1.open(QIODevice::ReadOnly|QIODevice::Unbuffered)); } +void tst_QFile::openStandardStreams() +{ + // Using file descriptors + { + QFile in; + in.open(STDIN_FILENO, QIODevice::ReadOnly); + QCOMPARE( in.pos(), (qint64)0 ); + QCOMPARE( in.size(), (qint64)0 ); + QVERIFY( in.isSequential() ); + } + + { + QFile out; + out.open(STDOUT_FILENO, QIODevice::WriteOnly); + QCOMPARE( out.pos(), (qint64)0 ); + QCOMPARE( out.size(), (qint64)0 ); + QVERIFY( out.isSequential() ); + } + + { + QFile err; + err.open(STDERR_FILENO, QIODevice::WriteOnly); + QCOMPARE( err.pos(), (qint64)0 ); + QCOMPARE( err.size(), (qint64)0 ); + QVERIFY( err.isSequential() ); + } + + // Using streams + { + QFile in; + in.open(stdin, QIODevice::ReadOnly); + QCOMPARE( in.pos(), (qint64)0 ); + QCOMPARE( in.size(), (qint64)0 ); + QVERIFY( in.isSequential() ); + } + + { + QFile out; + out.open(stdout, QIODevice::WriteOnly); + QCOMPARE( out.pos(), (qint64)0 ); + QCOMPARE( out.size(), (qint64)0 ); + QVERIFY( out.isSequential() ); + } + + { + QFile err; + err.open(stderr, QIODevice::WriteOnly); + QCOMPARE( err.pos(), (qint64)0 ); + QCOMPARE( err.size(), (qint64)0 ); + QVERIFY( err.isSequential() ); + } +} + QTEST_MAIN(tst_QFile) #include "tst_qfile.moc" -- cgit v1.2.3 From c6651f91b8f31d94ef37aa41cc2fd76d97e990e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Tue, 20 Oct 2009 16:28:22 +0200 Subject: Adding a test case for large file support The test case creates a (tentatively sparse) very large file with scattered data and uses it to test various aspects of large file support in QFile. Reviewed-by: Thiago Macieira --- tests/auto/qfile/largefile/largefile.pro | 4 + tests/auto/qfile/largefile/tst_largefile.cpp | 492 +++++++++++++++++++++++++++ tests/auto/qfile/qfile.pro | 2 +- 3 files changed, 497 insertions(+), 1 deletion(-) create mode 100644 tests/auto/qfile/largefile/largefile.pro create mode 100644 tests/auto/qfile/largefile/tst_largefile.cpp (limited to 'tests/auto') diff --git a/tests/auto/qfile/largefile/largefile.pro b/tests/auto/qfile/largefile/largefile.pro new file mode 100644 index 0000000000..0f968659a1 --- /dev/null +++ b/tests/auto/qfile/largefile/largefile.pro @@ -0,0 +1,4 @@ +load(qttest_p4) + +QT = core +SOURCES += tst_largefile.cpp diff --git a/tests/auto/qfile/largefile/tst_largefile.cpp b/tests/auto/qfile/largefile/tst_largefile.cpp new file mode 100644 index 0000000000..398ca3f34d --- /dev/null +++ b/tests/auto/qfile/largefile/tst_largefile.cpp @@ -0,0 +1,492 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include + +#include +#include + +#ifdef Q_OS_WIN + +#include +#include + +#ifndef FSCTL_SET_SPARSE +// MinGW doesn't define this. +#define FSCTL_SET_SPARSE (0x900C4) +#endif + +#endif // Q_OS_WIN + +class tst_LargeFile + : public QObject +{ + Q_OBJECT + +public: + tst_LargeFile() + : blockSize(1 << 12) + , maxSizeBits() + , largeFile("qt_largefile.tmp") + , fd_(-1) + , stream_(0) + { + #if defined(QT_LARGEFILE_SUPPORT) && !defined(Q_OS_MAC) + maxSizeBits = 36; // 64 GiB + #elif defined(Q_OS_MAC) + // HFS+ does not support sparse files, so we limit file size for the test + // on Mac OS. + maxSizeBits = 32; // 4 GiB + #else + maxSizeBits = 24; // 16 MiB + #endif + } + +private: + void sparseFileData(); + QByteArray const &getDataBlock(int index, qint64 position); + +private slots: + // The LargeFile test case was designed to be run in order as a single unit + + void initTestCase(); + void cleanupTestCase(); + + void init(); + void cleanup(); + + // Create and fill large file + void createSparseFile(); + void fillFileSparsely(); + void closeSparseFile(); + + // Verify file was created + void fileCreated(); + + // Positioning in large files + void filePositioning(); + void fdPositioning(); + void streamPositioning(); + + // Read data from file + void openFileForReading(); + void readFile(); + + // Map/unmap large file + void mapFile(); + void mapOffsetOverflow(); + + void closeFile() { largeFile.close(); } + + // Test data + void fillFileSparsely_data() { sparseFileData(); } + void filePositioning_data() { sparseFileData(); } + void fdPositioning_data() { sparseFileData(); } + void streamPositioning_data() { sparseFileData(); } + void readFile_data() { sparseFileData(); } + void mapFile_data() { sparseFileData(); } + +private: + const int blockSize; + int maxSizeBits; + + QFile largeFile; + + QVector generatedBlocks; + + int fd_; + FILE *stream_; +}; + +/* + Convenience function to hide reinterpret_cast when copying a POD directly + into a QByteArray. + */ +template +static inline void appendRaw(QByteArray &array, T data) +{ + array.append(reinterpret_cast(&data), sizeof(T)); +} + +/* + Pad array with filler up to size. On return, array.size() returns size. + */ +static inline void topUpWith(QByteArray &array, QByteArray filler, int size) +{ + Q_ASSERT(filler.size() > 0); + + for (int i = (size - array.size()) / filler.size(); i > 0; --i) + array.append(filler); + + if (array.size() < size) { + Q_ASSERT(size - array.size() < filler.size()); + array.append(filler.left(size - array.size())); + } +} + +/* + Generate a unique data block containing identifiable data. Unaligned, + overlapping and partial blocks should not compare equal. + */ +static inline QByteArray generateDataBlock(int blockSize, QString text, qint64 userBits = -1) +{ + QByteArray block; + block.reserve(blockSize); + + // Use of counter and randomBits means content of block will be dependent + // on the generation order. For (file-)systems that do not support sparse + // files, these can be removed so the test file can be reused and doesn't + // have to be generated for every run. + + static qint64 counter = 0; + + qint64 randomBits = ((qint64)qrand() << 32) + | ((qint64)qrand() & 0x00000000ffffffff); + + appendRaw(block, randomBits); + appendRaw(block, userBits); + appendRaw(block, counter); + appendRaw(block, (qint32)0xdeadbeef); + appendRaw(block, blockSize); + + QByteArray userContent = text.toUtf8(); + appendRaw(block, userContent.size()); + block.append(userContent); + appendRaw(block, (qint64)0); + + // size, so far + appendRaw(block, block.size()); + + QByteArray filler("0123456789"); + block.append(filler.right(10 - block.size() % 10)); + topUpWith(block, filler, blockSize - 2 * sizeof(qint64)); + + appendRaw(block, counter); + appendRaw(block, userBits); + appendRaw(block, randomBits); + + Q_ASSERT( block.size() >= blockSize ); + block.resize(blockSize); + + ++counter; + return block; +} + +/* + Generates data blocks the first time they are requested. Keeps copies for reuse. + */ +QByteArray const &tst_LargeFile::getDataBlock(int index, qint64 position) +{ + if (index >= generatedBlocks.size()) + generatedBlocks.resize(index + 1); + + if (generatedBlocks[index].isNull()) { + QString text = QString("Current %1-byte block (index = %2) " + "starts %3 bytes into the file '%4'.") + .arg(blockSize) + .arg(index) + .arg(position) + .arg(largeFile.fileName()); + + generatedBlocks[index] = generateDataBlock(blockSize, text, (qint64)1 << index); + } + + return generatedBlocks[index]; +} + +void tst_LargeFile::initTestCase() +{ + QVERIFY( !largeFile.exists() || largeFile.remove() ); +} + +void tst_LargeFile::cleanupTestCase() +{ + largeFile.close(); + QVERIFY( !largeFile.exists() || largeFile.remove() ); +} + +void tst_LargeFile::init() +{ + fd_ = -1; + stream_ = 0; +} + +void tst_LargeFile::cleanup() +{ + if (-1 != fd_) + QT_CLOSE(fd_); + if (stream_) + ::fclose(stream_); +} + +void tst_LargeFile::sparseFileData() +{ + QTest::addColumn("index"); + QTest::addColumn("position"); + QTest::addColumn("block"); + + QTest::newRow(QString("block[%1] @%2)") + .arg(0).arg(0) + .toLocal8Bit().constData()) + << 0 << (qint64)0 << getDataBlock(0, 0); + + // While on Linux sparse files scale well, on Windows, testing at every + // power of 2 leads to very large files. i += 4 gives us a good coverage + // without taxing too much on resources. + for (int index = 12; index <= maxSizeBits; index += 4) { + qint64 position = (qint64)1 << index; + QByteArray block = getDataBlock(index, position); + + QTest::newRow( + QString("block[%1] @%2)") + .arg(index).arg(position) + .toLocal8Bit().constData()) + << index << position << block; + } +} + +void tst_LargeFile::createSparseFile() +{ +#if defined(Q_OS_WIN) + // On Windows platforms, we must explicitly set the file to be sparse, + // so disk space is not allocated for the full file when writing to it. + HANDLE handle = ::CreateFileA(largeFile.fileName().toLocal8Bit().constData(), + GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0); + QVERIFY( INVALID_HANDLE_VALUE != handle ); + + DWORD bytes; + if (!::DeviceIoControl(handle, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, + &bytes, NULL)) { + QWARN("Unable to set test file as sparse. " + "Limiting test file to 16MiB."); + maxSizeBits = 24; + } + + int fd = ::_open_osfhandle((intptr_t)handle, 0); + QVERIFY( -1 != fd ); + QVERIFY( largeFile.open(fd, QIODevice::WriteOnly) ); +#else // !Q_OS_WIN + QVERIFY( largeFile.open(QIODevice::WriteOnly) ); +#endif +} + +void tst_LargeFile::closeSparseFile() +{ +#if defined(Q_OS_WIN) + int fd = largeFile.handle(); +#endif + + largeFile.close(); + +#if defined(Q_OS_WIN) + if (-1 != fd) + ::_close(fd); +#endif +} + +void tst_LargeFile::fillFileSparsely() +{ + QFETCH( qint64, position ); + QFETCH( QByteArray, block ); + QCOMPARE( block.size(), blockSize ); + + QVERIFY( largeFile.seek(position) ); + QCOMPARE( largeFile.pos(), position ); + + QCOMPARE( largeFile.write(block), (qint64)blockSize ); + QCOMPARE( largeFile.pos(), position + blockSize ); + QVERIFY( largeFile.flush() ); +} + +void tst_LargeFile::fileCreated() +{ + QFileInfo info(largeFile); + + QVERIFY( info.exists() ); + QVERIFY( info.isFile() ); + QVERIFY( info.size() >= ((qint64)1 << maxSizeBits) + blockSize ); +} + +void tst_LargeFile::filePositioning() +{ + QFETCH( qint64, position ); + + QFile file(largeFile.fileName()); + QVERIFY( file.open(QIODevice::ReadOnly) ); + + QVERIFY( file.seek(position) ); + QCOMPARE( file.pos(), position ); +} + +void tst_LargeFile::fdPositioning() +{ + QFETCH( qint64, position ); + + fd_ = QT_OPEN(largeFile.fileName().toLocal8Bit().constData(), + QT_OPEN_RDONLY | QT_OPEN_LARGEFILE); + QVERIFY( -1 != fd_ ); + + QFile file; + QVERIFY( file.open(fd_, QIODevice::ReadOnly) ); + QCOMPARE( file.pos(), (qint64)0 ); + QVERIFY( file.seek(position) ); + QCOMPARE( file.pos(), position ); + + file.close(); + + QCOMPARE( QT_LSEEK(fd_, QT_OFF_T(0), SEEK_SET), QT_OFF_T(0) ); + QCOMPARE( QT_LSEEK(fd_, QT_OFF_T(position), SEEK_SET), QT_OFF_T(position) ); + + QVERIFY( file.open(fd_, QIODevice::ReadOnly) ); + QCOMPARE( QT_LSEEK(fd_, QT_OFF_T(0), SEEK_CUR), QT_OFF_T(position) ); + QCOMPARE( file.pos(), position ); + QVERIFY( file.seek(0) ); + QCOMPARE( file.pos(), (qint64)0 ); + + file.close(); + + QVERIFY( !QT_CLOSE(fd_) ); + fd_ = -1; +} + +void tst_LargeFile::streamPositioning() +{ + QFETCH( qint64, position ); + + stream_ = QT_FOPEN(largeFile.fileName().toLocal8Bit().constData(), "rb"); + QVERIFY( 0 != stream_ ); + + QFile file; + QVERIFY( file.open(stream_, QIODevice::ReadOnly) ); + QCOMPARE( file.pos(), (qint64)0 ); + QVERIFY( file.seek(position) ); + QCOMPARE( file.pos(), position ); + + file.close(); + + QVERIFY( !QT_FSEEK(stream_, QT_OFF_T(0), SEEK_SET) ); + QCOMPARE( QT_FTELL(stream_), QT_OFF_T(0) ); + QVERIFY( !QT_FSEEK(stream_, QT_OFF_T(position), SEEK_SET) ); + QCOMPARE( QT_FTELL(stream_), QT_OFF_T(position) ); + + QVERIFY( file.open(stream_, QIODevice::ReadOnly) ); + QCOMPARE( QT_FTELL(stream_), QT_OFF_T(position) ); + QCOMPARE( file.pos(), position ); + QVERIFY( file.seek(0) ); + QCOMPARE( file.pos(), (qint64)0 ); + + file.close(); + + QVERIFY( !::fclose(stream_) ); + stream_ = 0; +} + +void tst_LargeFile::openFileForReading() +{ + QVERIFY( largeFile.open(QIODevice::ReadOnly) ); +} + +void tst_LargeFile::readFile() +{ + QFETCH( qint64, position ); + QFETCH( QByteArray, block ); + QCOMPARE( block.size(), blockSize ); + + QVERIFY( largeFile.size() >= position + blockSize ); + + QVERIFY( largeFile.seek(position) ); + QCOMPARE( largeFile.pos(), position ); + + QCOMPARE( largeFile.read(blockSize), block ); + QCOMPARE( largeFile.pos(), position + blockSize ); +} + +void tst_LargeFile::mapFile() +{ + QFETCH( qint64, position ); + QFETCH( QByteArray, block ); + QCOMPARE( block.size(), blockSize ); + + // Keep full block mapped to facilitate OS and/or internal reuse by Qt. + uchar *baseAddress = largeFile.map(position, blockSize); + QVERIFY( baseAddress ); + QVERIFY( qEqual(block.begin(), block.end(), reinterpret_cast(baseAddress)) ); + + for (int offset = 1; offset < blockSize; ++offset) { + uchar *address = largeFile.map(position + offset, blockSize - offset); + + QVERIFY( address ); + if ( !qEqual(block.begin() + offset, block.end(), reinterpret_cast(address)) ) { + qDebug() << "Expected:" << block.toHex(); + qDebug() << "Actual :" << QByteArray(reinterpret_cast(address), blockSize).toHex(); + QVERIFY(false); + } + + QVERIFY( largeFile.unmap( address ) ); + } + + QVERIFY( largeFile.unmap( baseAddress ) ); +} + +void tst_LargeFile::mapOffsetOverflow() +{ + // Out-of-range mappings should fail, and not silently clip the offset + for (int i = 50; i < 63; ++i) { + uchar *address = 0; + + address = largeFile.map(((qint64)1 << i), blockSize); + QVERIFY( !address ); + + address = largeFile.map(((qint64)1 << i) + blockSize, blockSize); + QVERIFY( !address ); + } +} + +QTEST_APPLESS_MAIN(tst_LargeFile) +#include "tst_largefile.moc" + diff --git a/tests/auto/qfile/qfile.pro b/tests/auto/qfile/qfile.pro index eebfcdafe9..f70f75025b 100644 --- a/tests/auto/qfile/qfile.pro +++ b/tests/auto/qfile/qfile.pro @@ -5,5 +5,5 @@ wince*:{ SUBDIRS = test stdinprocess } - +SUBDIRS += largefile -- cgit v1.2.3 From d0fa7d4b30fa34fe2a684c331213528c193da85f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Thu, 22 Oct 2009 20:18:21 +0200 Subject: Windows doesn't #define STD{IN,OUT,ERR}_FILENO Reviewed-by: Markus Goetz --- tests/auto/qfile/tst_qfile.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp index bbb62805b0..4971762631 100644 --- a/tests/auto/qfile/tst_qfile.cpp +++ b/tests/auto/qfile/tst_qfile.cpp @@ -79,6 +79,18 @@ # define SRCDIR "" #endif +#ifndef STDIN_FILENO +#define STDIN_FILENO 0 +#endif + +#ifndef STDOUT_FILENO +#define STDOUT_FILENO 1 +#endif + +#ifndef STDERR_FILENO +#define STDERR_FILENO 2 +#endif + Q_DECLARE_METATYPE(QFile::FileError) //TESTED_CLASS= -- cgit v1.2.3 From b402b8c4216ebb2d7db1e7e6cd33a45d1af422e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Fri, 23 Oct 2009 11:48:51 +0200 Subject: Fix the LargeFile test for Windows The test assumed fileName was stable, but it is documented behaviour that this can be reset when a file descriptor or FILE* stream is associated with a QFile. This was the case on Windows. --- tests/auto/qfile/largefile/tst_largefile.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/qfile/largefile/tst_largefile.cpp b/tests/auto/qfile/largefile/tst_largefile.cpp index 398ca3f34d..d2bbffe082 100644 --- a/tests/auto/qfile/largefile/tst_largefile.cpp +++ b/tests/auto/qfile/largefile/tst_largefile.cpp @@ -72,7 +72,6 @@ public: tst_LargeFile() : blockSize(1 << 12) , maxSizeBits() - , largeFile("qt_largefile.tmp") , fd_(-1) , stream_(0) { @@ -231,7 +230,7 @@ QByteArray const &tst_LargeFile::getDataBlock(int index, qint64 position) .arg(blockSize) .arg(index) .arg(position) - .arg(largeFile.fileName()); + .arg("qt_largefile.tmp"); generatedBlocks[index] = generateDataBlock(blockSize, text, (qint64)1 << index); } @@ -241,13 +240,17 @@ QByteArray const &tst_LargeFile::getDataBlock(int index, qint64 position) void tst_LargeFile::initTestCase() { - QVERIFY( !largeFile.exists() || largeFile.remove() ); + QFile file("qt_largefile.tmp"); + QVERIFY( !file.exists() || file.remove() ); } void tst_LargeFile::cleanupTestCase() { - largeFile.close(); - QVERIFY( !largeFile.exists() || largeFile.remove() ); + if (largeFile.isOpen()) + largeFile.close(); + + QFile file("qt_largefile.tmp"); + QVERIFY( !file.exists() || file.remove() ); } void tst_LargeFile::init() @@ -295,7 +298,7 @@ void tst_LargeFile::createSparseFile() #if defined(Q_OS_WIN) // On Windows platforms, we must explicitly set the file to be sparse, // so disk space is not allocated for the full file when writing to it. - HANDLE handle = ::CreateFileA(largeFile.fileName().toLocal8Bit().constData(), + HANDLE handle = ::CreateFileA("qt_largefile.tmp", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0); QVERIFY( INVALID_HANDLE_VALUE != handle ); @@ -311,6 +314,7 @@ void tst_LargeFile::createSparseFile() QVERIFY( -1 != fd ); QVERIFY( largeFile.open(fd, QIODevice::WriteOnly) ); #else // !Q_OS_WIN + largeFile.setFileName("qt_largefile.tmp"); QVERIFY( largeFile.open(QIODevice::WriteOnly) ); #endif } @@ -345,7 +349,7 @@ void tst_LargeFile::fillFileSparsely() void tst_LargeFile::fileCreated() { - QFileInfo info(largeFile); + QFileInfo info("qt_largefile.tmp"); QVERIFY( info.exists() ); QVERIFY( info.isFile() ); @@ -356,7 +360,7 @@ void tst_LargeFile::filePositioning() { QFETCH( qint64, position ); - QFile file(largeFile.fileName()); + QFile file("qt_largefile.tmp"); QVERIFY( file.open(QIODevice::ReadOnly) ); QVERIFY( file.seek(position) ); @@ -367,7 +371,7 @@ void tst_LargeFile::fdPositioning() { QFETCH( qint64, position ); - fd_ = QT_OPEN(largeFile.fileName().toLocal8Bit().constData(), + fd_ = QT_OPEN("qt_largefile.tmp", QT_OPEN_RDONLY | QT_OPEN_LARGEFILE); QVERIFY( -1 != fd_ ); @@ -398,7 +402,7 @@ void tst_LargeFile::streamPositioning() { QFETCH( qint64, position ); - stream_ = QT_FOPEN(largeFile.fileName().toLocal8Bit().constData(), "rb"); + stream_ = QT_FOPEN("qt_largefile.tmp", "rb"); QVERIFY( 0 != stream_ ); QFile file; @@ -428,6 +432,7 @@ void tst_LargeFile::streamPositioning() void tst_LargeFile::openFileForReading() { + largeFile.setFileName("qt_largefile.tmp"); QVERIFY( largeFile.open(QIODevice::ReadOnly) ); } -- cgit v1.2.3 From 45a09e31ebb25d3ad4f63ae02f0a0b464577761e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Fri, 23 Oct 2009 15:02:05 +0200 Subject: Extending QFile::size test to cover files opened with fd and FILE* Also changed tested type from int to qint64, so we'll be able to see clipping issues, although there are no large files in this test, yet. Reviewed-by: Markus Goetz --- tests/auto/qfile/tst_qfile.cpp | 51 +++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 8 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp index 4971762631..55cc286848 100644 --- a/tests/auto/qfile/tst_qfile.cpp +++ b/tests/auto/qfile/tst_qfile.cpp @@ -117,6 +117,7 @@ private slots: void openUnbuffered(); void size_data(); void size(); + void sizeNoExist(); void seek(); void setSize(); void setSizeSeek(); @@ -452,23 +453,57 @@ void tst_QFile::openUnbuffered() void tst_QFile::size_data() { QTest::addColumn("filename"); - QTest::addColumn("size"); + QTest::addColumn("size"); - QTest::newRow( "exist01" ) << QString(SRCDIR "testfile.txt") << 245; - QTest::newRow( "nonexist01" ) << QString("foo.txt") << 0; + QTest::newRow( "exist01" ) << QString(SRCDIR "testfile.txt") << (qint64)245; #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) // Only test UNC on Windows./ - QTest::newRow("unc") << "//" + QString(QtNetworkSettings::winServerName() + "/testsharewritable/test.pri") << 34; + QTest::newRow("unc") << "//" + QString(QtNetworkSettings::winServerName() + "/testsharewritable/test.pri") << (qint64)34; #endif } void tst_QFile::size() { QFETCH( QString, filename ); - QFile f( filename ); - QTEST( (int)f.size(), "size" ); - if (f.open(QFile::ReadOnly)) - QTEST( (int)f.size(), "size" ); + QFETCH( qint64, size ); + + { + QFile f( filename ); + QCOMPARE( f.size(), size ); + + QVERIFY( f.open(QIODevice::ReadOnly) ); + QCOMPARE( f.size(), size ); + } + + { + QFile f; + int fd = QT_OPEN(filename.toLocal8Bit().constData(), QT_OPEN_RDONLY); + QVERIFY( fd != -1 ); + QVERIFY( f.open(fd, QIODevice::ReadOnly) ); + QCOMPARE( f.size(), size ); + + f.close(); + QT_CLOSE(fd); + } + + { + QFile f; + FILE* stream = QT_FOPEN(filename.toLocal8Bit().constData(), "rb"); + QVERIFY( stream ); + QVERIFY( f.open(stream, QIODevice::ReadOnly) ); + QCOMPARE( f.size(), size ); + + f.close(); + fclose(stream); + } +} + +void tst_QFile::sizeNoExist() +{ + QFile file("nonexist01"); + QVERIFY( !file.exists() ); + QCOMPARE( file.size(), (qint64)0 ); + QVERIFY( !file.open(QIODevice::ReadOnly) ); } void tst_QFile::seek() -- cgit v1.2.3 From 764d195bfa252775702bffc93989a35d0c19f035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Thu, 29 Oct 2009 15:32:03 +0100 Subject: Turns out 64-bit fseek/ftell are not available on VS 2003/2002... Not when linking dynamically to the CRT (/MT). So we can't rely on them. The declarations for those are also not on the standard headers. Reverts "(MSVC 2002/2003) Use 64-bit versions of ftell and fseek", fixes return type of QT_FTELL and skips known failures on large-file test case. --- tests/auto/qfile/largefile/tst_largefile.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/qfile/largefile/tst_largefile.cpp b/tests/auto/qfile/largefile/tst_largefile.cpp index d2bbffe082..53dbc127a8 100644 --- a/tests/auto/qfile/largefile/tst_largefile.cpp +++ b/tests/auto/qfile/largefile/tst_largefile.cpp @@ -402,6 +402,11 @@ void tst_LargeFile::streamPositioning() { QFETCH( qint64, position ); +#if defined(QT_LARGEFILE_SUPPORT) && defined(Q_CC_MSVC) && _MSC_VER < 1400 + if (position >= (qint64)1 << 31) + QSKIP("MSVC 2003 doesn't have 64 bit versions of fseek/ftell.", SkipSingle); +#endif + stream_ = QT_FOPEN("qt_largefile.tmp", "rb"); QVERIFY( 0 != stream_ ); -- cgit v1.2.3 From 052a34bef9cf682e3ea0e2183223b0dcab3c05b7 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Wed, 4 Nov 2009 13:37:01 +0100 Subject: Fix new failure in compatibilityChildInsertedEvents The new QEvent::WinIdChange event is sent when QWidget::show() creates the native window id, so we need to expect that event as well. Reviewed-by: TrustMe --- tests/auto/qwidget/tst_qwidget.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index 5630370fc5..3595b84d15 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -6319,6 +6319,7 @@ void tst_QWidget::compatibilityChildInsertedEvents() widget.show(); expected = EventRecorder::EventList() + << qMakePair(&widget, QEvent::WinIdChange) << qMakePair(&widget, QEvent::Polish) << qMakePair(&widget, QEvent::Move) << qMakePair(&widget, QEvent::Resize) @@ -6404,6 +6405,7 @@ void tst_QWidget::compatibilityChildInsertedEvents() widget.show(); expected = EventRecorder::EventList() + << qMakePair(&widget, QEvent::WinIdChange) << qMakePair(&widget, QEvent::Polish) #ifdef QT_HAS_QT3SUPPORT << qMakePair(&widget, QEvent::ChildInserted) @@ -6501,6 +6503,7 @@ void tst_QWidget::compatibilityChildInsertedEvents() widget.show(); expected = EventRecorder::EventList() + << qMakePair(&widget, QEvent::WinIdChange) << qMakePair(&widget, QEvent::Polish) #ifdef QT_HAS_QT3SUPPORT << qMakePair(&widget, QEvent::ChildInserted) -- cgit v1.2.3 From eda773316824cbb1aa7bdba402e568340b79b4f3 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Wed, 4 Nov 2009 18:42:33 +0000 Subject: tst_qwidget widgetAt now does not leave widget lowered if test fails Task-number: QTBUG-5396 Reviewed-by: axis --- tests/auto/qwidget/tst_qwidget.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index 3d801cced9..e027dd1bf4 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -3328,9 +3328,10 @@ void tst_QWidget::widgetAt() w2->lower(); qApp->processEvents(); QTRY_VERIFY((wr = QApplication::widgetAt(100, 100))); - QCOMPARE(wr->objectName(), QString("w1")); - + const bool match = (wr->objectName() == QString("w1")); w2->raise(); + QVERIFY(match); + qApp->processEvents(); QTRY_VERIFY((wr = QApplication::widgetAt(100, 100))); QCOMPARE(wr->objectName(), QString("w2")); -- cgit v1.2.3 From f1a56f4db2f6d6c395ac6e7023b6e9184140d571 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Thu, 5 Nov 2009 11:40:27 +0200 Subject: Fixed symbian-abld build problems with xmlpatternsxqts Qmake generators for symbian can't handle .depends for SUBDIRS values, instead relying on the order of subdirs. Reordered the subdirs as a hot fix to get test case to build before qmake can be properly fixed. Also removed duplicate inclusion of xmlpatterns.pri, which was causing compile time warnings due to duplicate MACRO statements in mmps. Reviewed-by: Janne Koskinen --- tests/auto/xmlpatternsxqts/test/test.pro | 2 -- tests/auto/xmlpatternsxqts/xmlpatternsxqts.pro | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/xmlpatternsxqts/test/test.pro b/tests/auto/xmlpatternsxqts/test/test.pro index 603ae65b26..a69838af5e 100644 --- a/tests/auto/xmlpatternsxqts/test/test.pro +++ b/tests/auto/xmlpatternsxqts/test/test.pro @@ -24,5 +24,3 @@ win32 { else: DESTDIR = ../release } TARGET = tst_xmlpatternsxqts - -include (../../xmlpatterns.pri) diff --git a/tests/auto/xmlpatternsxqts/xmlpatternsxqts.pro b/tests/auto/xmlpatternsxqts/xmlpatternsxqts.pro index a3b13da9c4..39267c8de6 100644 --- a/tests/auto/xmlpatternsxqts/xmlpatternsxqts.pro +++ b/tests/auto/xmlpatternsxqts/xmlpatternsxqts.pro @@ -1,10 +1,10 @@ TEMPLATE = subdirs -SUBDIRS = test contains(QT_CONFIG,xmlpatterns) { SUBDIRS += lib !wince*:lib.file = lib/lib.pro test.depends = lib } +SUBDIRS += test # Needed on the win32-g++ setup and on the test machine arsia. INCLUDEPATH += $$QT_BUILD_TREE/include/QtXmlPatterns/private \ -- cgit v1.2.3 From ec13cf30f10dabce37af3ce9d6763066e8cf4cc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trond=20Kjern=C3=A5sen?= Date: Thu, 5 Nov 2009 11:21:31 +0100 Subject: Removed the FBO stacking behaviour and the test attached to it. Having this behaviour in QGLFrameBufferObject complicates alot of things and isn't really necessary. Reviewed-by: Tom Cooksey --- tests/auto/qgl/tst_qgl.cpp | 105 --------------------------------------------- 1 file changed, 105 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/qgl/tst_qgl.cpp b/tests/auto/qgl/tst_qgl.cpp index e9f0476e0b..c680decc01 100644 --- a/tests/auto/qgl/tst_qgl.cpp +++ b/tests/auto/qgl/tst_qgl.cpp @@ -82,7 +82,6 @@ private slots: void glPBufferRendering(); void glWidgetReparent(); void glWidgetRenderPixmap(); - void stackedFBOs(); void colormap(); void fboFormat(); void testDontCrashOnDanglingResources(); @@ -1226,110 +1225,6 @@ void tst_QGL::glWidgetRenderPixmap() QCOMPARE(fb, reference); } - -// When using multiple FBOs at the same time, unbinding one FBO should re-bind the -// previous. I.e. It should be possible to have a stack of FBOs where pop'ing there -// top re-binds the one underneeth. -void tst_QGL::stackedFBOs() -{ - if (!QGLFramebufferObject::hasOpenGLFramebufferObjects()) - QSKIP("QGLFramebufferObject not supported on this platform", SkipSingle); - - QGLWidget glw; - glw.show(); - -#ifdef Q_WS_X11 - qt_x11_wait_for_window_manager(&glw); -#endif - QTest::qWait(200); - - glw.makeCurrent(); - - // No multisample with combined depth/stencil attachment: - QGLFramebufferObjectFormat fboFormat; - fboFormat.setAttachment(QGLFramebufferObject::CombinedDepthStencil); - - // Don't complicate things by using NPOT: - QGLFramebufferObject *fbo1 = new QGLFramebufferObject(128, 128, fboFormat); - QGLFramebufferObject *fbo2 = new QGLFramebufferObject(128, 128, fboFormat); - QGLFramebufferObject *fbo3 = new QGLFramebufferObject(128, 128, fboFormat); - - glClearColor(1.0, 0.0, 1.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT); - - fbo1->bind(); - glClearColor(1.0, 0.0, 0.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT); - - fbo2->bind(); - glClearColor(0.0, 1.0, 0.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT); - - fbo3->bind(); - glClearColor(0.0, 0.0, 1.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT); - glScissor(32, 32, 64, 64); - glEnable(GL_SCISSOR_TEST); - glClearColor(0.0, 1.0, 1.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT); - fbo3->release(); - - // Scissor rect & test should be left untouched by the fbo release... - glClearColor(0.0, 0.0, 0.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT); - fbo2->release(); - - glClearColor(1.0, 1.0, 1.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT); - fbo1->release(); - - glClearColor(1.0, 1.0, 0.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT); - - glw.swapBuffers(); - - QImage widgetFB = glw.grabFrameBuffer(false).convertToFormat(QImage::Format_RGB32); - QImage fb1 = fbo1->toImage().convertToFormat(QImage::Format_RGB32); - QImage fb2 = fbo2->toImage().convertToFormat(QImage::Format_RGB32); - QImage fb3 = fbo3->toImage().convertToFormat(QImage::Format_RGB32); - - delete fbo1; - delete fbo2; - delete fbo3; - - QImage widgetReference(widgetFB.size(), widgetFB.format()); - QImage fb1Reference(fb1.size(), fb1.format()); - QImage fb2Reference(fb2.size(), fb2.format()); - QImage fb3Reference(fb3.size(), fb3.format()); - - QPainter widgetReferencePainter(&widgetReference); - QPainter fb1ReferencePainter(&fb1Reference); - QPainter fb2ReferencePainter(&fb2Reference); - QPainter fb3ReferencePainter(&fb3Reference); - - widgetReferencePainter.fillRect(0, 0, widgetReference.width(), widgetReference.height(), Qt::magenta); - fb1ReferencePainter.fillRect(0, 0, fb1Reference.width(), fb1Reference.height(), Qt::red); - fb2ReferencePainter.fillRect(0, 0, fb2Reference.width(), fb2Reference.height(), Qt::green); - fb3ReferencePainter.fillRect(0, 0, fb3Reference.width(), fb3Reference.height(), Qt::blue); - - // Flip y-coords to match GL for the widget (which can be any size) - widgetReferencePainter.fillRect(32, glw.height() - 96, 64, 64, Qt::yellow); - fb1ReferencePainter.fillRect(32, 32, 64, 64, Qt::white); - fb2ReferencePainter.fillRect(32, 32, 64, 64, Qt::black); - fb3ReferencePainter.fillRect(32, 32, 64, 64, Qt::cyan); - - widgetReferencePainter.end(); - fb1ReferencePainter.end(); - fb2ReferencePainter.end(); - fb3ReferencePainter.end(); - - QCOMPARE(widgetFB, widgetReference); - QCOMPARE(fb1, fb1Reference); - QCOMPARE(fb2, fb2Reference); - QCOMPARE(fb3, fb3Reference); -} - - class ColormapExtended : public QGLColormap { public: -- cgit v1.2.3 From d456ac11027f7573aa32745a8bc972d2b83926f4 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 5 Nov 2009 14:17:56 +0100 Subject: Add test for QEventTransition when filtering on a QApplication instance Test for 8ec037effce7f515fffed6b05c011e385fb52593. Reviewed-by: Gunnar --- tests/auto/qstatemachine/tst_qstatemachine.cpp | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 9a2b2edf1a..fd39515a98 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -208,6 +208,7 @@ private slots: void task260403_clonedSignals(); void postEventFromOtherThread(); + void eventFilterForApplication(); }; tst_QStateMachine::tst_QStateMachine() @@ -4276,5 +4277,35 @@ void tst_QStateMachine::postEventFromOtherThread() QTRY_COMPARE(finishedSpy.count(), 1); } +void tst_QStateMachine::eventFilterForApplication() +{ + QStateMachine machine; + + QState *s1 = new QState(&machine); + { + machine.setInitialState(s1); + } + + QState *s2 = new QState(&machine); + + QEventTransition *transition = new QEventTransition(QCoreApplication::instance(), + QEvent::ApplicationActivate); + transition->setTargetState(s2); + s1->addTransition(transition); + + machine.start(); + QCoreApplication::processEvents(); + + QCOMPARE(machine.configuration().size(), 1); + QVERIFY(machine.configuration().contains(s1)); + + QCoreApplication::postEvent(QCoreApplication::instance(), + new QEvent(QEvent::ApplicationActivate)); + QCoreApplication::processEvents(); + + QCOMPARE(machine.configuration().size(), 1); + QVERIFY(machine.configuration().contains(s2)); +} + QTEST_MAIN(tst_QStateMachine) #include "tst_qstatemachine.moc" -- cgit v1.2.3 From 24675593113167bfffcb4791e9c3e0865a0c3244 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Thu, 5 Nov 2009 14:38:35 +0100 Subject: Improve the reliability of tst_QGridLayout::minMaxSize() As indicated by the comments, if the test fails, the timeouts may need to be increased. Since this is failing on the test cluster, where CPU time is limited, doubling the timeouts seems to do the trick. Reviewed-by: Richard Moe Gustavsen --- tests/auto/qgridlayout/tst_qgridlayout.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/qgridlayout/tst_qgridlayout.cpp b/tests/auto/qgridlayout/tst_qgridlayout.cpp index 7c320be2ef..46e2a03c32 100644 --- a/tests/auto/qgridlayout/tst_qgridlayout.cpp +++ b/tests/auto/qgridlayout/tst_qgridlayout.cpp @@ -920,9 +920,9 @@ void tst_QGridLayout::minMaxSize() #if defined(Q_WS_X11) qt_x11_wait_for_window_manager(m_toplevel); // wait for the show #endif - QTest::qWait(20); + QTest::qWait(40); m_toplevel->adjustSize(); - QTest::qWait(120); // wait for the implicit adjustSize + QTest::qWait(240); // wait for the implicit adjustSize // If the following fails we might have to wait longer. // If that does not help there is likely a problem with the implicit adjustSize in show() if (!fixedSize.isValid()) { -- cgit v1.2.3 From c4d8d7fd35c8ac7fd2c14208e5e7ca0a35c101e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Thu, 5 Nov 2009 16:15:26 +0100 Subject: Switch large file test to using Unbuffered mode ... so we test the file engine directly and detect file-system errors earlier. --- tests/auto/qfile/largefile/tst_largefile.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/qfile/largefile/tst_largefile.cpp b/tests/auto/qfile/largefile/tst_largefile.cpp index 53dbc127a8..8ab3275c0c 100644 --- a/tests/auto/qfile/largefile/tst_largefile.cpp +++ b/tests/auto/qfile/largefile/tst_largefile.cpp @@ -312,10 +312,10 @@ void tst_LargeFile::createSparseFile() int fd = ::_open_osfhandle((intptr_t)handle, 0); QVERIFY( -1 != fd ); - QVERIFY( largeFile.open(fd, QIODevice::WriteOnly) ); + QVERIFY( largeFile.open(fd, QIODevice::WriteOnly | QIODevice::Unbuffered) ); #else // !Q_OS_WIN largeFile.setFileName("qt_largefile.tmp"); - QVERIFY( largeFile.open(QIODevice::WriteOnly) ); + QVERIFY( largeFile.open(QIODevice::WriteOnly | QIODevice::Unbuffered) ); #endif } -- cgit v1.2.3 From 3c0b6de86ce044ce6f3f4a445d1de90b4e7bb1d9 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Fri, 6 Nov 2009 10:10:46 +0100 Subject: Updated testcase since soft-light algorithm rewrite. The SVG standard changed the algorithm which implies some changes to the results as well. Reviewed-by: Kim --- tests/auto/qpainter/tst_qpainter.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp index 8ed83cb851..bcdbe56671 100644 --- a/tests/auto/qpainter/tst_qpainter.cpp +++ b/tests/auto/qpainter/tst_qpainter.cpp @@ -4193,9 +4193,9 @@ void tst_QPainter::extendedBlendModes() QVERIFY(testCompositionMode(255, 255, 255, QPainter::CompositionMode_SoftLight)); QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_SoftLight)); - QVERIFY(testCompositionMode(127, 127, 127, QPainter::CompositionMode_SoftLight)); - QVERIFY(testCompositionMode( 63, 63, 86, QPainter::CompositionMode_SoftLight)); - QVERIFY(testCompositionMode(127, 63, 63, QPainter::CompositionMode_SoftLight)); + QVERIFY(testCompositionMode(127, 127, 126, QPainter::CompositionMode_SoftLight)); + QVERIFY(testCompositionMode( 63, 63, 39, QPainter::CompositionMode_SoftLight)); + QVERIFY(testCompositionMode(127, 63, 62, QPainter::CompositionMode_SoftLight)); QVERIFY(testCompositionMode(255, 255, 0, QPainter::CompositionMode_Difference)); QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_Difference)); -- cgit v1.2.3 From 9b500e9a09907f05002bd0e57869c5312ae101db Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 6 Nov 2009 12:59:35 +0100 Subject: Fix QPainter::setPen(pen with color but no style) on non-extended. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It was working with a QImage but not with a QPixmap, which is obviously a bug. In addition, it broke WebCore::GraphicsContext::setPlatformStrokeColor which does exactly what I put in the unittest: get pen, set color, set pen. This commit fixes the wrong color in the underline of the links in http://www.davidfaure.fr/kde/link_underline_color.html in QtWebkit. Merge-request: 1995 Reviewed-by: Samuel Rødal --- tests/auto/qpainter/tst_qpainter.cpp | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp index bcdbe56671..4d2c6266ba 100644 --- a/tests/auto/qpainter/tst_qpainter.cpp +++ b/tests/auto/qpainter/tst_qpainter.cpp @@ -239,9 +239,12 @@ private slots: void taskQT4444_dontOverflowDashOffset(); void painterBegin(); + void setPenColorOnImage(); + void setPenColorOnPixmap(); private: void fillData(); + void setPenColor(QPainter& p); QColor baseColor( int k, int intensity=255 ); QImage getResImage( const QString &dir, const QString &addition, const QString &extension ); QBitmap getBitmap( const QString &dir, const QString &filename, bool mask ); @@ -4352,5 +4355,41 @@ void tst_QPainter::painterBegin() QVERIFY(!p.end()); } +void tst_QPainter::setPenColor(QPainter& p) +{ + p.setPen(Qt::NoPen); + + // Setting color, then style + // Should work even though the pen is "NoPen with color", temporarily. + QPen newPen(p.pen()); + newPen.setColor(Qt::red); + QCOMPARE(p.pen().style(), newPen.style()); + QCOMPARE(p.pen().style(), Qt::NoPen); + p.setPen(newPen); + + QCOMPARE(p.pen().color().name(), QString("#ff0000")); + + QPen newPen2(p.pen()); + newPen2.setStyle(Qt::SolidLine); + p.setPen(newPen2); + + QCOMPARE(p.pen().color().name(), QString("#ff0000")); +} + +void tst_QPainter::setPenColorOnImage() +{ + QImage img(QSize(10, 10), QImage::Format_ARGB32_Premultiplied); + QPainter p(&img); + setPenColor(p); +} + +void tst_QPainter::setPenColorOnPixmap() +{ + QPixmap pix(10, 10); + QPainter p(&pix); + setPenColor(p); +} + QTEST_MAIN(tst_QPainter) + #include "tst_qpainter.moc" -- cgit v1.2.3 From 4ad6343be52b757fd354cd92874bca944d2ede49 Mon Sep 17 00:00:00 2001 From: Harald Fernengel Date: Fri, 6 Nov 2009 15:15:05 +0100 Subject: Add preliminary QAccessibleImage interface As requested by the Maemo team. --- tests/auto/qaccessibility/tst_qaccessibility.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/qaccessibility/tst_qaccessibility.cpp b/tests/auto/qaccessibility/tst_qaccessibility.cpp index 9f2e4e7afb..25c2649e43 100644 --- a/tests/auto/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/qaccessibility/tst_qaccessibility.cpp @@ -4034,6 +4034,27 @@ void tst_QAccessibility::labelTest() delete acc_label; delete label; QTestAccessibility::clearEvents(); + + QPixmap testPixmap(50, 50); + testPixmap.fill(); + + QLabel imageLabel; + imageLabel.setPixmap(testPixmap); + imageLabel.setToolTip("Test Description"); + + acc_label = QAccessible::queryAccessibleInterface(&imageLabel); + QVERIFY(acc_label); + + QAccessibleImageInterface *imageInterface = acc_label->imageInterface(); + QVERIFY(imageInterface); + + QCOMPARE(imageInterface->imageSize(), testPixmap.size()); + QCOMPARE(imageInterface->imageDescription(), QString::fromLatin1("Test Description")); + QCOMPARE(imageInterface->imagePosition(QAccessible2::RelativeToParent), imageLabel.geometry()); + + delete acc_label; + + QTestAccessibility::clearEvents(); #else QSKIP("Test needs accessibility support.", SkipAll); #endif -- cgit v1.2.3