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

View File

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