Use temporary settings file for gui test.

This commit is contained in:
Florian Geyer 2012-06-14 22:55:25 +02:00
parent 056447fad9
commit a720903083
4 changed files with 41 additions and 5 deletions

View File

@ -90,6 +90,7 @@ set(keepassx_SOURCES
)
set(keepassx_MOC
core/Config.h
core/Database.h
core/Entry.h
core/EntryAttachments.h

View File

@ -19,6 +19,8 @@
#include <QtCore/QDir>
#include <QtCore/QSettings>
#include <QtCore/QTemporaryFile>
#include <QtGui/QApplication>
#include <QtGui/QDesktopServices>
Config* Config::m_instance(0);
@ -38,7 +40,14 @@ void Config::set(const QString& key, const QVariant& value)
m_settings->setValue(key, value);
}
Config::Config()
Config::Config(const QString& fileName, QObject* parent)
: QObject(parent)
{
init(fileName);
}
Config::Config(QObject* parent)
: QObject(parent)
{
QString userPath;
QString homePath = QDir::homePath();
@ -67,7 +76,17 @@ Config::Config()
userPath += "keepassx2.ini";
m_settings.reset(new QSettings(userPath, QSettings::IniFormat));
init(userPath);
}
Config::~Config()
{
;
}
void Config::init(const QString& fileName)
{
m_settings.reset(new QSettings(fileName, QSettings::IniFormat));
m_defaults.insert("RememberLastDatabases", true);
m_defaults.insert("ModifiedOnExpandedStateChanges", true);
@ -80,8 +99,16 @@ Config::Config()
Config* Config::instance()
{
if (!m_instance) {
m_instance = new Config();
m_instance = new Config(qApp);
}
return m_instance;
}
void Config::createTempFileInstance()
{
Q_ASSERT(!m_instance);
QTemporaryFile* tmpFile = new QTemporaryFile(qApp);
tmpFile->open();
m_instance = new Config(tmpFile->fileName(), tmpFile);
}

View File

@ -23,17 +23,23 @@
class QSettings;
class Config
class Config : public QObject
{
Q_OBJECT
public:
~Config();
QVariant get(const QString& key);
QVariant get(const QString& key, const QVariant& defaultValue);
void set(const QString& key, const QVariant& value);
static Config* instance();
static void createTempFileInstance();
private:
Config();
Config(const QString& fileName, QObject* parent);
Config(QObject* parent);
void init(const QString& fileName);
static Config* m_instance;

View File

@ -29,6 +29,7 @@
#include "config-keepassx-tests.h"
#include "tests.h"
#include "crypto/Crypto.h"
#include "core/Config.h"
#include "core/Entry.h"
#include "gui/DatabaseTabWidget.h"
#include "gui/DatabaseWidget.h"
@ -40,6 +41,7 @@
void TestGui::initTestCase()
{
Crypto::init();
Config::createTempFileInstance();
m_mainWindow = new MainWindow();
m_mainWindow->show();
QTest::qWaitForWindowShown(m_mainWindow);