summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoão Abecasis <joao@abecasis.name>2009-05-13 15:13:48 (GMT)
committerJoão Abecasis <joao@abecasis.name>2009-05-22 12:33:40 (GMT)
commitfd7cb7faa765835de6e7beb24f018c417d9ad7d8 (patch)
tree80d7c22e8369aac8cb94210fddc7b309cfebf975 /tests
parentf1e9c0f3d22d611bfaa14c30a34e6042500a0cb8 (diff)
downloadQt-fd7cb7faa765835de6e7beb24f018c417d9ad7d8.zip
Qt-fd7cb7faa765835de6e7beb24f018c417d9ad7d8.tar.gz
Qt-fd7cb7faa765835de6e7beb24f018c417d9ad7d8.tar.bz2
QFile::copy: close source file when using fallback mechanism
Also added check in test case for rename fallback. Task-number: 165920 Reviewed-by: Thiago
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qfile/copy-fallback.qrc5
-rw-r--r--tests/auto/qfile/test/test.pro2
-rw-r--r--tests/auto/qfile/tst_qfile.cpp30
3 files changed, 36 insertions, 1 deletions
diff --git a/tests/auto/qfile/copy-fallback.qrc b/tests/auto/qfile/copy-fallback.qrc
new file mode 100644
index 0000000..864491f
--- /dev/null
+++ b/tests/auto/qfile/copy-fallback.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>copy-fallback.qrc</file>
+</qresource>
+</RCC>
diff --git a/tests/auto/qfile/test/test.pro b/tests/auto/qfile/test/test.pro
index 68f4c05..8d26f5e 100644
--- a/tests/auto/qfile/test/test.pro
+++ b/tests/auto/qfile/test/test.pro
@@ -17,7 +17,7 @@ QT = core network
DEFINES += SRCDIR=\\\"$$PWD/../\\\"
}
-RESOURCES += ../qfile.qrc ../rename-fallback.qrc
+RESOURCES += ../qfile.qrc ../rename-fallback.qrc ../copy-fallback.qrc
TARGET = ../tst_qfile
diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp
index 98e1859..7e28d12 100644
--- a/tests/auto/qfile/tst_qfile.cpp
+++ b/tests/auto/qfile/tst_qfile.cpp
@@ -125,6 +125,7 @@ private slots:
void copy();
void copyRemovesTemporaryFile() const;
void copyShouldntOverwrite();
+ void copyFallback();
void link();
void linkToDir();
void absolutePathLinkToRelativePath();
@@ -213,6 +214,9 @@ void tst_QFile::cleanup()
// TODO: Add cleanup code here.
// This will be executed immediately after each test is run.
+ // for copyFallback()
+ QFile::remove("file-copy-destination.txt");
+
// for renameFallback()
QFile::remove("file-rename-destination.txt");
@@ -907,6 +911,31 @@ void tst_QFile::copyShouldntOverwrite()
QFile::remove("tst_qfile.cpy");
}
+void tst_QFile::copyFallback()
+{
+ // Using a resource file to trigger QFile::copy's fallback handling
+ QFile file(":/copy-fallback.qrc");
+ QFile::remove("file-copy-destination.txt");
+
+ QVERIFY2(file.exists(), "test precondition");
+ QVERIFY2(!QFile::exists("file-copy-destination.txt"), "test precondition");
+
+ // Fallback copy of closed file.
+ QVERIFY(file.copy("file-copy-destination.txt"));
+ QVERIFY(QFile::exists("file-copy-destination.txt"));
+ QVERIFY(!file.isOpen());
+
+ QVERIFY(QFile::remove("file-copy-destination.txt"));
+
+ // Fallback copy of open file.
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ QVERIFY(file.copy("file-copy-destination.txt"));
+ QVERIFY(QFile::exists("file-copy-destination.txt"));
+ QVERIFY(!file.isOpen());
+
+ QFile::remove("file-copy-destination.txt");
+}
+
#ifdef Q_OS_WIN
#include <objbase.h>
#include <shlobj.h>
@@ -2081,6 +2110,7 @@ void tst_QFile::renameFallback()
QVERIFY(!file.rename("file-rename-destination.txt"));
QVERIFY(!QFile::exists("file-rename-destination.txt"));
+ QVERIFY(!file.isOpen());
}
void tst_QFile::renameMultiple()