Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan White <support@dmapps.us>2019-10-21 01:23:11 +0300
committerJonathan White <support@dmapps.us>2019-10-21 01:56:41 +0300
commit1e694271a3c6c233736301dcb2f1a7ced081fc3f (patch)
tree1fa647b44bf8427cc6d4cdd50fe38aee82b242dd /tests/util/TemporaryFile.cpp
parent744b4abce801440ff4e143fb2bb416b3d7a91e07 (diff)
Improve Database and CLI tests
Diffstat (limited to 'tests/util/TemporaryFile.cpp')
-rw-r--r--tests/util/TemporaryFile.cpp30
1 files changed, 28 insertions, 2 deletions
diff --git a/tests/util/TemporaryFile.cpp b/tests/util/TemporaryFile.cpp
index 476313b02..19622faed 100644
--- a/tests/util/TemporaryFile.cpp
+++ b/tests/util/TemporaryFile.cpp
@@ -17,7 +17,7 @@
#include "TemporaryFile.h"
-#ifdef Q_OS_WIN
+#include <QTextStream>
TemporaryFile::TemporaryFile()
: TemporaryFile(nullptr)
@@ -47,9 +47,35 @@ TemporaryFile::TemporaryFile(const QString& templateName, QObject* parent)
tmp.close();
}
+TemporaryFile::~TemporaryFile()
+{
+ remove();
+}
+
bool TemporaryFile::open()
{
return QFile::open(QIODevice::ReadWrite);
}
-#endif
+bool TemporaryFile::copyFromFile(const QString& otherFileName)
+{
+ close();
+ if (!open(QFile::WriteOnly | QFile::Truncate)) {
+ return false;
+ }
+
+ QFile otherFile(otherFileName);
+ if (!otherFile.open(QFile::ReadOnly)) {
+ close();
+ return false;
+ }
+
+ QByteArray data;
+ while(!(data = otherFile.read(1024)).isEmpty()) {
+ write(data);
+ }
+
+ otherFile.close();
+ close();
+ return true;
+}