From 45848c3f611b88015c8227be197baac07a284b3d Mon Sep 17 00:00:00 2001 From: Andrew Meyer Date: Fri, 8 May 2020 23:48:03 -0400 Subject: Implement 'Save Database Backup' option Add an option in the 'Database' menu to save a backup of the current database. Add unit test for saving database copy * Open a test database, mark it as modified, and save a copy * Fail if the copy is not a valid database * Fail if the original database is saved * Fail if the original database is no longer marked as modified --- tests/gui/TestGui.cpp | 29 +++++++++++++++++++++++++++++ tests/gui/TestGui.h | 1 + 2 files changed, 30 insertions(+) (limited to 'tests') diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index e167b9a30..5ca7ccdbe 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -1212,6 +1212,35 @@ void TestGui::testSaveAs() tmpFile.remove(); } +void TestGui::testSaveBackup() +{ + m_db->metadata()->setName("testSaveBackup"); + + QFileInfo fileInfo(m_dbFilePath); + QDateTime lastModified = fileInfo.lastModified(); + + // open temporary file so it creates a filename + TemporaryFile tmpFile; + QVERIFY(tmpFile.open()); + QString tmpFileName = tmpFile.fileName(); + tmpFile.remove(); + + // wait for modified timer + QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("testSaveBackup*")); + + fileDialog()->setNextFileName(tmpFileName); + + triggerAction("actionDatabaseSaveBackup"); + + QCOMPARE(m_tabWidget->tabName(m_tabWidget->currentIndex()), QString("testSaveBackup*")); + + checkDatabase(tmpFileName); + + fileInfo.refresh(); + QCOMPARE(fileInfo.lastModified(), lastModified); + tmpFile.remove(); +} + void TestGui::testSave() { m_db->metadata()->setName("testSave"); diff --git a/tests/gui/TestGui.h b/tests/gui/TestGui.h index cd329dd06..8d82e021e 100644 --- a/tests/gui/TestGui.h +++ b/tests/gui/TestGui.h @@ -61,6 +61,7 @@ private slots: void testDragAndDropEntry(); void testDragAndDropGroup(); void testSaveAs(); + void testSaveBackup(); void testSave(); void testDatabaseSettings(); void testKeePass1Import(); -- cgit v1.2.3