summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro1
-rw-r--r--tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.qrc5
-rw-r--r--tests/auto/corelib/io/qtemporaryfile/resources/test.txt1
-rw-r--r--tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp38
4 files changed, 44 insertions, 1 deletions
diff --git a/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro b/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro
index 64331daef9..8a91340e5f 100644
--- a/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro
+++ b/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro
@@ -5,3 +5,4 @@ QT = core testlib
SOURCES = tst_qtemporaryfile.cpp
TESTDATA += tst_qtemporaryfile.cpp
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
+RESOURCES += qtemporaryfile.qrc \ No newline at end of file
diff --git a/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.qrc b/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.qrc
new file mode 100644
index 0000000000..efadde8b4d
--- /dev/null
+++ b/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>resources/test.txt</file>
+</qresource>
+</RCC> \ No newline at end of file
diff --git a/tests/auto/corelib/io/qtemporaryfile/resources/test.txt b/tests/auto/corelib/io/qtemporaryfile/resources/test.txt
new file mode 100644
index 0000000000..793aa682b0
--- /dev/null
+++ b/tests/auto/corelib/io/qtemporaryfile/resources/test.txt
@@ -0,0 +1 @@
+This is a test \ No newline at end of file
diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
index e68594ebaf..6d7a6e76ef 100644
--- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
+++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
@@ -88,7 +88,8 @@ private slots:
void resetTemplateAfterError();
void setTemplateAfterOpen();
void autoRemoveAfterFailedRename();
-
+ void createNativeFile_data();
+ void createNativeFile();
void QTBUG_4796_data();
void QTBUG_4796();
};
@@ -633,6 +634,41 @@ void tst_QTemporaryFile::autoRemoveAfterFailedRename()
cleaner.reset();
}
+void tst_QTemporaryFile::createNativeFile_data()
+{
+ QTest::addColumn<QString>("filePath");
+ QTest::addColumn<qint64>("currentPos");
+ QTest::addColumn<bool>("valid");
+ QTest::addColumn<QByteArray>("content");
+
+ QTest::newRow("nativeFile") << QFINDTESTDATA("resources/test.txt") << (qint64)-1 << false << QByteArray();
+ QTest::newRow("nativeFileWithPos") << QFINDTESTDATA("resources/test.txt") << (qint64)5 << false << QByteArray();
+ QTest::newRow("resourceFile") << ":/resources/test.txt" << (qint64)-1 << true << QByteArray("This is a test");
+ QTest::newRow("resourceFileWithPos") << ":/resources/test.txt" << (qint64)5 << true << QByteArray("This is a test");
+}
+
+void tst_QTemporaryFile::createNativeFile()
+{
+ QFETCH(QString, filePath);
+ QFETCH(qint64, currentPos);
+ QFETCH(bool, valid);
+ QFETCH(QByteArray, content);
+
+ QFile f(filePath);
+ if (currentPos != -1) {
+ f.open(QIODevice::ReadOnly);
+ f.seek(currentPos);
+ }
+ QTemporaryFile *tempFile = QTemporaryFile::createNativeFile(f);
+ QVERIFY(valid == (bool)tempFile);
+ if (currentPos != -1)
+ QCOMPARE(currentPos, f.pos());
+ if (valid) {
+ QCOMPARE(content, tempFile->readAll());
+ delete tempFile;
+ }
+}
+
void tst_QTemporaryFile::QTBUG_4796_data()
{
QTest::addColumn<QString>("prefix");