From a83bf7eccb24632b603c2eb77b85359a183e51b6 Mon Sep 17 00:00:00 2001 From: jNullj Date: Tue, 28 Feb 2023 01:04:10 +0200 Subject: [PATCH] test: add test for maximum history in database settings 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. --- tests/gui/TestGui.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index 23e59f338e..668a28d38d 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -1470,6 +1470,7 @@ void TestGui::testDatabaseSettings() auto* dbSettingsStackedWidget = dbSettingsDialog->findChild("stackedWidget"); auto* transformRoundsSpinBox = dbSettingsDialog->findChild("transformRoundsSpinBox"); auto advancedToggle = dbSettingsDialog->findChild("advancedSettingsToggle"); + auto* dbSettingsButtonBox = dbSettingsDialog->findChild("buttonBox"); advancedToggle->setChecked(true); QApplication::processEvents(); @@ -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("historyMaxItemsCheckBox"); + auto* historyMaxItemsSpinBox = dbSettingsDialog->findChild("historyMaxItemsSpinBox"); + auto* historyMaxSizeCheckBox = dbSettingsDialog->findChild("historyMaxSizeCheckBox"); + auto* historyMaxSizeSpinBox = dbSettingsDialog->findChild("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(); }