Store the filename instead of a QTemporaryFile in TestGui.

On Windows QTemporaryFile keeps the file handle open
which conflicts with QSaveFile.
This commit is contained in:
Felix Geyer 2012-10-22 17:52:08 +02:00
parent 9eac5f35d8
commit 8b8e55aa17
2 changed files with 9 additions and 6 deletions

View File

@ -17,6 +17,7 @@
#include "TestGui.h" #include "TestGui.h"
#include <QtCore/QTemporaryFile>
#include <QtTest/QTest> #include <QtTest/QTest>
#include <QtGui/QAction> #include <QtGui/QAction>
#include <QtGui/QApplication> #include <QtGui/QApplication>
@ -276,10 +277,12 @@ void TestGui::testSaveAs()
m_db->metadata()->setName("SaveAs"); m_db->metadata()->setName("SaveAs");
QTemporaryFile* tmpFile = new QTemporaryFile();
// open temporary file so it creates a filename // open temporary file so it creates a filename
QVERIFY(m_tmpFile.open()); QVERIFY(tmpFile->open());
m_tmpFile.close(); m_tmpFileName = tmpFile->fileName();
fileDialog()->setNextFileName(m_tmpFile.fileName()); delete tmpFile;
fileDialog()->setNextFileName(m_tmpFileName);
triggerAction("actionDatabaseSaveAs"); triggerAction("actionDatabaseSaveAs");
@ -357,6 +360,7 @@ void TestGui::testDatabaseLocking()
void TestGui::cleanupTestCase() void TestGui::cleanupTestCase()
{ {
delete m_mainWindow; delete m_mainWindow;
QFile::remove(m_tmpFileName);
} }
void TestGui::checkDatabase() void TestGui::checkDatabase()
@ -364,7 +368,7 @@ void TestGui::checkDatabase()
CompositeKey key; CompositeKey key;
key.addKey(PasswordKey("a")); key.addKey(PasswordKey("a"));
KeePass2Reader reader; KeePass2Reader reader;
QScopedPointer<Database> dbSaved(reader.readDatabase(m_tmpFile.fileName(), key)); QScopedPointer<Database> dbSaved(reader.readDatabase(m_tmpFileName, key));
QVERIFY(dbSaved); QVERIFY(dbSaved);
QVERIFY(!reader.hasError()); QVERIFY(!reader.hasError());
QCOMPARE(dbSaved->metadata()->name(), m_db->metadata()->name()); QCOMPARE(dbSaved->metadata()->name(), m_db->metadata()->name());

View File

@ -20,7 +20,6 @@
#include <QtCore/QAbstractItemModel> #include <QtCore/QAbstractItemModel>
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/QTemporaryFile>
class Database; class Database;
class DatabaseTabWidget; class DatabaseTabWidget;
@ -57,7 +56,7 @@ private:
MainWindow* m_mainWindow; MainWindow* m_mainWindow;
DatabaseTabWidget* m_tabWidget; DatabaseTabWidget* m_tabWidget;
DatabaseWidget* m_dbWidget; DatabaseWidget* m_dbWidget;
QTemporaryFile m_tmpFile; QString m_tmpFileName;
Database* m_db; Database* m_db;
}; };