summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2009-08-31 17:34:10 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2009-08-31 17:34:10 (GMT)
commit0d411622521a89c04a416e2aaf3da44b6015b183 (patch)
tree51e61cea6b56b40d359a8914f59bf3297a5e0d3e
parent3b65bb32fda7e34373b64f416ea92a3fa6eb266c (diff)
parent20cc50a21eb5841b3a3e8546877e805f5a4df528 (diff)
downloadQt-0d411622521a89c04a416e2aaf3da44b6015b183.zip
Qt-0d411622521a89c04a416e2aaf3da44b6015b183.tar.gz
Qt-0d411622521a89c04a416e2aaf3da44b6015b183.tar.bz2
Merge branch '4.5' into 4.6
-rw-r--r--src/corelib/io/qtemporaryfile.cpp38
-rw-r--r--src/gui/image/qimage.cpp6
-rw-r--r--tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp8
-rw-r--r--tests/auto/qnetworkreply/tst_qnetworkreply.cpp6
-rw-r--r--tests/auto/qpixmap/tst_qpixmap.cpp29
-rw-r--r--tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp82
6 files changed, 157 insertions, 12 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index 48f34d6..fa3ed09 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -292,14 +292,20 @@ class QTemporaryFileEngine : public QFSFileEngine
Q_DECLARE_PRIVATE(QFSFileEngine)
public:
QTemporaryFileEngine(const QString &file, bool fileIsTemplate = true)
- : QFSFileEngine(file), filePathIsTemplate(fileIsTemplate)
+ : QFSFileEngine(), filePathIsTemplate(fileIsTemplate)
{
+ Q_D(QFSFileEngine);
+ d->filePath = file;
+
+ if (!filePathIsTemplate)
+ QFSFileEngine::setFileName(file);
}
~QTemporaryFileEngine();
bool isReallyOpen();
void setFileName(const QString &file);
+ void setFileTemplate(const QString &fileTemplate);
bool open(QIODevice::OpenMode flags);
bool remove();
@@ -336,6 +342,13 @@ void QTemporaryFileEngine::setFileName(const QString &file)
QFSFileEngine::setFileName(file);
}
+void QTemporaryFileEngine::setFileTemplate(const QString &fileTemplate)
+{
+ Q_D(QFSFileEngine);
+ if (filePathIsTemplate)
+ d->filePath = fileTemplate;
+}
+
bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
{
Q_D(QFSFileEngine);
@@ -382,12 +395,19 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
return false;
}
+ QString template_ = d->filePath;
d->filePath = QString::fromLocal8Bit(filename);
- filePathIsTemplate = false;
d->nativeInitFileName();
- d->closeFileHandle = true;
delete [] filename;
- return QFSFileEngine::open(openMode);
+
+ if (QFSFileEngine::open(openMode)) {
+ filePathIsTemplate = false;
+ return true;
+ }
+
+ d->filePath = template_;
+ d->nativeFilePath.clear();
+ return false;
#endif
}
@@ -533,7 +553,8 @@ QTemporaryFile::QTemporaryFile()
QTemporaryFile::QTemporaryFile(const QString &templateName)
: QFile(*new QTemporaryFilePrivate, 0)
{
- setFileTemplate(templateName);
+ Q_D(QTemporaryFile);
+ d->templateName = templateName;
}
/*!
@@ -567,7 +588,8 @@ QTemporaryFile::QTemporaryFile(QObject *parent)
QTemporaryFile::QTemporaryFile(const QString &templateName, QObject *parent)
: QFile(*new QTemporaryFilePrivate, parent)
{
- setFileTemplate(templateName);
+ Q_D(QTemporaryFile);
+ d->templateName = templateName;
}
#endif
@@ -671,10 +693,10 @@ QString QTemporaryFile::fileTemplate() const
*/
void QTemporaryFile::setFileTemplate(const QString &name)
{
- Q_ASSERT(!isOpen());
Q_D(QTemporaryFile);
- fileEngine()->setFileName(name);
d->templateName = name;
+ if (d->fileEngine)
+ static_cast<QTemporaryFileEngine*>(d->fileEngine)->setFileTemplate(name);
}
/*!
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index 2b82f49..89af452 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -2892,6 +2892,12 @@ static void convert_Indexed8_to_X32(QImageData *dest, const QImageData *src, Qt:
Q_ASSERT(src->height == dest->height);
QVector<QRgb> colorTable = fix_color_table(src->colortable, dest->format);
+ if (colorTable.size() == 0) {
+ colorTable.resize(256);
+ for (int i=0; i<256; ++i)
+ colorTable[i] = qRgb(i, i, i);
+
+ }
int w = src->width;
const uchar *src_data = src->data;
diff --git a/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp b/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp
index 6549be8..419eb71 100644
--- a/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp
+++ b/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp
@@ -189,7 +189,9 @@ void tst_QHttpNetworkConnection::head()
QCOMPARE(reply->statusCode(), statusCode);
QCOMPARE(reply->reasonPhrase(), statusString);
- QCOMPARE(reply->contentLength(), qint64(contentLength));
+ // only check it if it is set
+ if (reply->contentLength() != -1)
+ QCOMPARE(reply->contentLength(), qint64(contentLength));
QVERIFY(reply->isFinished());
@@ -249,7 +251,9 @@ void tst_QHttpNetworkConnection::get()
QCOMPARE(reply->statusCode(), statusCode);
QCOMPARE(reply->reasonPhrase(), statusString);
- QCOMPARE(reply->contentLength(), qint64(contentLength));
+ // only check it if it is set
+ if (reply->contentLength() != -1)
+ QCOMPARE(reply->contentLength(), qint64(contentLength));
stopWatch.start();
QByteArray ba;
diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
index 52e967f..a223d1c 100644
--- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
@@ -1366,8 +1366,10 @@ void tst_QNetworkReply::getFromHttp()
QCOMPARE(reply->url(), request.url());
QCOMPARE(reply->error(), QNetworkReply::NoError);
QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200);
-
- QCOMPARE(reply->header(QNetworkRequest::ContentLengthHeader).toLongLong(), reference.size());
+ QCOMPARE(reply->size(), reference.size());
+ // only compare when the header is set.
+ if (reply->header(QNetworkRequest::ContentLengthHeader).isValid())
+ QCOMPARE(reply->header(QNetworkRequest::ContentLengthHeader).toLongLong(), reference.size());
QCOMPARE(reply->readAll(), reference.readAll());
}
diff --git a/tests/auto/qpixmap/tst_qpixmap.cpp b/tests/auto/qpixmap/tst_qpixmap.cpp
index 02ab1cc..7752a4f 100644
--- a/tests/auto/qpixmap/tst_qpixmap.cpp
+++ b/tests/auto/qpixmap/tst_qpixmap.cpp
@@ -95,6 +95,9 @@ private slots:
void fromImage_data();
void fromImage();
+ void fromUninitializedImage_data();
+ void fromUninitializedImage();
+
void convertFromImage_data();
void convertFromImage();
@@ -318,6 +321,32 @@ void tst_QPixmap::fromImage()
QCOMPARE(result, image);
}
+
+void tst_QPixmap::fromUninitializedImage_data()
+{
+ QTest::addColumn<QImage::Format>("format");
+
+ QTest::newRow("Format_Mono") << QImage::Format_Mono;
+ QTest::newRow("Format_MonoLSB") << QImage::Format_MonoLSB;
+ QTest::newRow("Format_Indexed8") << QImage::Format_Indexed8;
+ QTest::newRow("Format_RGB32") << QImage::Format_RGB32;
+ QTest::newRow("Format_ARGB32") << QImage::Format_ARGB32;
+ QTest::newRow("Format_ARGB32_Premultiplied") << QImage::Format_ARGB32_Premultiplied;
+ QTest::newRow("Format_RGB16") << QImage::Format_RGB16;
+}
+
+void tst_QPixmap::fromUninitializedImage()
+{
+ QFETCH(QImage::Format, format);
+
+ QImage image(100, 100, format);
+ QPixmap pix = QPixmap::fromImage(image);
+
+ // it simply shouldn't crash...
+ QVERIFY(true);
+
+}
+
void tst_QPixmap::convertFromImage_data()
{
QTest::addColumn<QImage>("img1");
diff --git a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
index b797c39..5a84cc1 100644
--- a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
+++ b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
@@ -93,6 +93,8 @@ private slots:
void renameFdLeak();
void reOpenThroughQFile();
void keepOpenMode();
+ void resetTemplateAfterError();
+ void setTemplateAfterOpen();
public:
};
@@ -476,5 +478,85 @@ void tst_QTemporaryFile::keepOpenMode()
}
}
+void tst_QTemporaryFile::resetTemplateAfterError()
+{
+ // calling setFileTemplate on a failed open
+
+ QString tempPath = QDir::tempPath();
+
+ QString const fileTemplate("destination/qt_temp_file_test.XXXXXX");
+ QString const fileTemplate2(tempPath + "/qt_temp_file_test.XXXXXX");
+
+ QVERIFY2( QDir(tempPath).exists() || QDir().mkpath(tempPath), "Test precondition" );
+ QVERIFY2( !QFile::exists("destination"), "Test precondition" );
+ QVERIFY2( !QFile::exists(fileTemplate2) || QFile::remove(fileTemplate2), "Test precondition" );
+
+ QFile file(fileTemplate2);
+ QByteArray fileContent("This file is intentionally NOT left empty.");
+
+ QVERIFY( file.open(QIODevice::ReadWrite | QIODevice::Truncate) );
+ QCOMPARE( file.write(fileContent), (qint64)fileContent.size() );
+ QVERIFY( file.flush() );
+
+ QString fileName;
+ {
+ QTemporaryFile temp;
+
+ QVERIFY( temp.fileName().isEmpty() );
+ QVERIFY( !temp.fileTemplate().isEmpty() );
+
+ temp.setFileTemplate( fileTemplate );
+
+ QVERIFY( temp.fileName().isEmpty() );
+ QCOMPARE( temp.fileTemplate(), fileTemplate );
+
+ QVERIFY( !temp.open() );
+
+ QVERIFY( temp.fileName().isEmpty() );
+ QCOMPARE( temp.fileTemplate(), fileTemplate );
+
+ temp.setFileTemplate( fileTemplate2 );
+ QVERIFY( temp.open() );
+
+ fileName = temp.fileName();
+ QVERIFY( QFile::exists(fileName) );
+ QVERIFY( !fileName.isEmpty() );
+ QVERIFY2( fileName != fileTemplate2,
+ ("Generated name shouldn't be same as template: " + fileTemplate2).toLocal8Bit().constData() );
+ }
+
+ QVERIFY( !QFile::exists(fileName) );
+
+ file.seek(0);
+ QCOMPARE( QString(file.readAll()), QString(fileContent) );
+ QVERIFY( file.remove() );
+}
+
+void tst_QTemporaryFile::setTemplateAfterOpen()
+{
+ QTemporaryFile temp;
+
+ QVERIFY( temp.fileName().isEmpty() );
+ QVERIFY( !temp.fileTemplate().isEmpty() );
+
+ QVERIFY( temp.open() );
+
+ QString const fileName = temp.fileName();
+ QString const newTemplate("funny-path/funny-name-XXXXXX.tmp");
+
+ QVERIFY( !fileName.isEmpty() );
+ QVERIFY( QFile::exists(fileName) );
+ QVERIFY( !temp.fileTemplate().isEmpty() );
+ QVERIFY( temp.fileTemplate() != newTemplate );
+
+ temp.close(); // QTemporaryFile::setFileTemplate will assert on isOpen() up to 4.5.2
+ temp.setFileTemplate(newTemplate);
+ QCOMPARE( temp.fileTemplate(), newTemplate );
+
+ QVERIFY( temp.open() );
+ QCOMPARE( temp.fileName(), fileName );
+ QCOMPARE( temp.fileTemplate(), newTemplate );
+}
+
QTEST_MAIN(tst_QTemporaryFile)
#include "tst_qtemporaryfile.moc"