mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-07-28 17:24:17 -04:00
Use temporary settings file for gui test.
This commit is contained in:
parent
056447fad9
commit
a720903083
4 changed files with 41 additions and 5 deletions
|
@ -90,6 +90,7 @@ set(keepassx_SOURCES
|
||||||
)
|
)
|
||||||
|
|
||||||
set(keepassx_MOC
|
set(keepassx_MOC
|
||||||
|
core/Config.h
|
||||||
core/Database.h
|
core/Database.h
|
||||||
core/Entry.h
|
core/Entry.h
|
||||||
core/EntryAttachments.h
|
core/EntryAttachments.h
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
#include <QtCore/QDir>
|
#include <QtCore/QDir>
|
||||||
#include <QtCore/QSettings>
|
#include <QtCore/QSettings>
|
||||||
|
#include <QtCore/QTemporaryFile>
|
||||||
|
#include <QtGui/QApplication>
|
||||||
#include <QtGui/QDesktopServices>
|
#include <QtGui/QDesktopServices>
|
||||||
|
|
||||||
Config* Config::m_instance(0);
|
Config* Config::m_instance(0);
|
||||||
|
@ -38,7 +40,14 @@ void Config::set(const QString& key, const QVariant& value)
|
||||||
m_settings->setValue(key, 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 userPath;
|
||||||
QString homePath = QDir::homePath();
|
QString homePath = QDir::homePath();
|
||||||
|
@ -67,7 +76,17 @@ Config::Config()
|
||||||
|
|
||||||
userPath += "keepassx2.ini";
|
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("RememberLastDatabases", true);
|
||||||
m_defaults.insert("ModifiedOnExpandedStateChanges", true);
|
m_defaults.insert("ModifiedOnExpandedStateChanges", true);
|
||||||
|
@ -80,8 +99,16 @@ Config::Config()
|
||||||
Config* Config::instance()
|
Config* Config::instance()
|
||||||
{
|
{
|
||||||
if (!m_instance) {
|
if (!m_instance) {
|
||||||
m_instance = new Config();
|
m_instance = new Config(qApp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_instance;
|
return m_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Config::createTempFileInstance()
|
||||||
|
{
|
||||||
|
Q_ASSERT(!m_instance);
|
||||||
|
QTemporaryFile* tmpFile = new QTemporaryFile(qApp);
|
||||||
|
tmpFile->open();
|
||||||
|
m_instance = new Config(tmpFile->fileName(), tmpFile);
|
||||||
|
}
|
||||||
|
|
|
@ -23,17 +23,23 @@
|
||||||
|
|
||||||
class QSettings;
|
class QSettings;
|
||||||
|
|
||||||
class Config
|
class Config : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
~Config();
|
||||||
QVariant get(const QString& key);
|
QVariant get(const QString& key);
|
||||||
QVariant get(const QString& key, const QVariant& defaultValue);
|
QVariant get(const QString& key, const QVariant& defaultValue);
|
||||||
void set(const QString& key, const QVariant& value);
|
void set(const QString& key, const QVariant& value);
|
||||||
|
|
||||||
static Config* instance();
|
static Config* instance();
|
||||||
|
static void createTempFileInstance();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Config();
|
Config(const QString& fileName, QObject* parent);
|
||||||
|
Config(QObject* parent);
|
||||||
|
void init(const QString& fileName);
|
||||||
|
|
||||||
static Config* m_instance;
|
static Config* m_instance;
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include "config-keepassx-tests.h"
|
#include "config-keepassx-tests.h"
|
||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
#include "crypto/Crypto.h"
|
#include "crypto/Crypto.h"
|
||||||
|
#include "core/Config.h"
|
||||||
#include "core/Entry.h"
|
#include "core/Entry.h"
|
||||||
#include "gui/DatabaseTabWidget.h"
|
#include "gui/DatabaseTabWidget.h"
|
||||||
#include "gui/DatabaseWidget.h"
|
#include "gui/DatabaseWidget.h"
|
||||||
|
@ -40,6 +41,7 @@
|
||||||
void TestGui::initTestCase()
|
void TestGui::initTestCase()
|
||||||
{
|
{
|
||||||
Crypto::init();
|
Crypto::init();
|
||||||
|
Config::createTempFileInstance();
|
||||||
m_mainWindow = new MainWindow();
|
m_mainWindow = new MainWindow();
|
||||||
m_mainWindow->show();
|
m_mainWindow->show();
|
||||||
QTest::qWaitForWindowShown(m_mainWindow);
|
QTest::qWaitForWindowShown(m_mainWindow);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue