Skip to content

Commit

Permalink
Prevent leaks in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
droidmonkey committed Nov 1, 2020
1 parent 88e6a12 commit 4088de8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/gui/PasswordEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ PasswordEdit::PasswordEdit(QWidget* parent)
m_toggleVisibleAction = new QAction(
icons()->icon("password-show-off"),
tr("Toggle Password (%1)").arg(QKeySequence(modifier + Qt::Key_H).toString(QKeySequence::NativeText)),
nullptr);
this);
m_toggleVisibleAction->setCheckable(true);
m_toggleVisibleAction->setShortcut(modifier + Qt::Key_H);
m_toggleVisibleAction->setShortcutContext(Qt::WidgetShortcut);
Expand All @@ -70,7 +70,7 @@ PasswordEdit::PasswordEdit(QWidget* parent)
m_passwordGeneratorAction = new QAction(
icons()->icon("password-generator"),
tr("Generate Password (%1)").arg(QKeySequence(modifier + Qt::Key_G).toString(QKeySequence::NativeText)),
nullptr);
this);
m_passwordGeneratorAction->setShortcut(modifier + Qt::Key_G);
m_passwordGeneratorAction->setShortcutContext(Qt::WidgetShortcut);
addAction(m_passwordGeneratorAction, QLineEdit::TrailingPosition);
Expand All @@ -79,7 +79,7 @@ PasswordEdit::PasswordEdit(QWidget* parent)
m_capslockAction =
new QAction(icons()->icon("dialog-warning", true, StateColorPalette().color(StateColorPalette::Error)),
tr("Warning: Caps Lock enabled!"),
nullptr);
this);
addAction(m_capslockAction, QLineEdit::LeadingPosition);
m_capslockAction->setVisible(false);
}
Expand Down
13 changes: 9 additions & 4 deletions tests/TestCli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ void TestCli::initTestCase()
Config::createTempFileInstance();
Bootstrap::bootstrap();

auto fd = new QFile();
m_devNull.reset(new QFile());
#ifdef Q_OS_WIN
fd->open(fopen("nul", "w"), QIODevice::WriteOnly);
m_devNull->open(fopen("nul", "w"), QIODevice::WriteOnly);
#else
fd->open(fopen("/dev/null", "w"), QIODevice::WriteOnly);
m_devNull->open(fopen("/dev/null", "w"), QIODevice::WriteOnly);
#endif
Utils::DEVNULL.setDevice(fd);
Utils::DEVNULL.setDevice(m_devNull.data());
}

void TestCli::init()
Expand Down Expand Up @@ -131,6 +131,11 @@ void TestCli::cleanup()
Utils::STDIN.setDevice(nullptr);
}

void TestCli::cleanupTestCase()
{
m_devNull.reset();
}

QSharedPointer<Database> TestCli::readDatabase(const QString& filename, const QString& pw, const QString& keyfile)
{
auto db = QSharedPointer<Database>::create();
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCli.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ private slots:
void initTestCase();
void init();
void cleanup();
void cleanupTestCase();

void testBatchCommands();
void testAdd();
Expand Down Expand Up @@ -81,6 +82,7 @@ private slots:
void testYubiKeyOption();

private:
QScopedPointer<QFile> m_devNull;
QScopedPointer<TemporaryFile> m_dbFile;
QScopedPointer<TemporaryFile> m_dbFile2;
QScopedPointer<TemporaryFile> m_dbFileMulti;
Expand Down

0 comments on commit 4088de8

Please sign in to comment.