summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qtemporaryfile
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@digia.com>2012-09-25 13:14:52 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-02 10:43:48 +0200
commitef3a544436beaecb4d26349ce115be39b680ef6a (patch)
tree540c4d2f4485794165d6d780b04296da8910db14 /tests/auto/corelib/io/qtemporaryfile
parentf20266f9f43ab3956de271f696c769db02992e87 (diff)
Rename createLocalFile to createNativeFile & deprecate createLocalFile
As it was confusing to use the term local file when referring to a file that was accessible using native APIs and not just a file that was on a hard disk somewhere already the function name has been changed. By renaming it to createNativeFile we keep it consistant with QFileInfo which has an isNativeFile() function too. Test also added. Task-number: QTBUG-3169 Change-Id: I410e7ed28133d68fd312c6c0faf3f7191460d7ce Reviewed-by: João Abecasis <joao@abecasis.name> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/io/qtemporaryfile')
-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");