Skip to content

Commit

Permalink
test: add test for maximum history in database settings (keepassxrebo…
Browse files Browse the repository at this point in the history
…ot#9176)

This commit adds a test to the TestGui::testDatabaseSettings function for the history maximum items and maximum size settings.
The test opens the database settings dialog, disables the history items and size settings, saves the changes, reopens the dialog, and then cancels without making any changes to load the default values. The test ensures that the default values are loaded correctly.

Co-authored-by: jNullj <jNullj@users.noreply.github.com>
  • Loading branch information
2 people authored and pull[bot] committed Jul 4, 2023
1 parent 5b6905c commit 6f6c648
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/gui/TestGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,7 @@ void TestGui::testDatabaseSettings()
auto* dbSettingsStackedWidget = dbSettingsDialog->findChild<QStackedWidget*>("stackedWidget");
auto* transformRoundsSpinBox = dbSettingsDialog->findChild<QSpinBox*>("transformRoundsSpinBox");
auto advancedToggle = dbSettingsDialog->findChild<QCheckBox*>("advancedSettingsToggle");
auto* dbSettingsButtonBox = dbSettingsDialog->findChild<QDialogButtonBox*>("buttonBox");

advancedToggle->setChecked(true);
QApplication::processEvents();
Expand All @@ -1481,6 +1482,27 @@ void TestGui::testDatabaseSettings()
QTest::keyClick(transformRoundsSpinBox, Qt::Key_Enter);
QTRY_COMPARE(m_db->kdf()->rounds(), 123456);

// test disable and default values for maximum history items and size
triggerAction("actionDatabaseSettings");
auto* historyMaxItemsCheckBox = dbSettingsDialog->findChild<QCheckBox*>("historyMaxItemsCheckBox");
auto* historyMaxItemsSpinBox = dbSettingsDialog->findChild<QSpinBox*>("historyMaxItemsSpinBox");
auto* historyMaxSizeCheckBox = dbSettingsDialog->findChild<QCheckBox*>("historyMaxSizeCheckBox");
auto* historyMaxSizeSpinBox = dbSettingsDialog->findChild<QSpinBox*>("historyMaxSizeSpinBox");
// test defaults
QCOMPARE(historyMaxItemsSpinBox->value(), Metadata::DefaultHistoryMaxItems);
QCOMPARE(historyMaxSizeSpinBox->value(), qRound(Metadata::DefaultHistoryMaxSize / qreal(1024 * 1024)));
// disable and test setting as well
historyMaxItemsCheckBox->setChecked(false);
historyMaxSizeCheckBox->setChecked(false);
QTest::mouseClick(dbSettingsButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
QTRY_COMPARE(m_db->metadata()->historyMaxItems(), -1);
QTRY_COMPARE(m_db->metadata()->historyMaxSize(), -1);
// then open to check the saved disabled state in gui
triggerAction("actionDatabaseSettings");
QCOMPARE(historyMaxItemsCheckBox->isChecked(), false);
QCOMPARE(historyMaxSizeCheckBox->isChecked(), false);
QTest::mouseClick(dbSettingsButtonBox->button(QDialogButtonBox::Cancel), Qt::LeftButton);

checkSaveDatabase();
}

Expand Down

0 comments on commit 6f6c648

Please sign in to comment.