Implemented major autoreload functionality
* Ignore autoreload on save / save-as * Consolidated db save code * Corrected bug (crash) in merge entry code due to not cloning the entry * Enhanced known modified status of database * Implemented test cases for autoreload
This commit is contained in:
@@ -65,20 +65,20 @@ void TestGui::initTestCase()
|
||||
QByteArray tmpData;
|
||||
QFile sourceDbFile(QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabase.kdbx"));
|
||||
QVERIFY(sourceDbFile.open(QIODevice::ReadOnly));
|
||||
QVERIFY(Tools::readAllFromDevice(&sourceDbFile, tmpData));
|
||||
QVERIFY(Tools::readAllFromDevice(&sourceDbFile, m_dbData));
|
||||
sourceDbFile.close();
|
||||
|
||||
// Write the temp storage to a temp database file for use in our tests
|
||||
QVERIFY(m_dbFile.open());
|
||||
QCOMPARE(m_dbFile.write(tmpData), static_cast<qint64>((tmpData.size())));
|
||||
m_dbFile.close();
|
||||
|
||||
m_dbFileName = QFileInfo(m_dbFile).fileName();
|
||||
}
|
||||
|
||||
// Every test starts with opening the temp database
|
||||
void TestGui::init()
|
||||
{
|
||||
// Write the temp storage to a temp database file for use in our tests
|
||||
QVERIFY(m_dbFile.open());
|
||||
QCOMPARE(m_dbFile.write(m_dbData), static_cast<qint64>((m_dbData.size())));
|
||||
m_dbFile.close();
|
||||
|
||||
m_dbFileName = QFileInfo(m_dbFile).fileName();
|
||||
|
||||
fileDialog()->setNextFileName(m_dbFile.fileName());
|
||||
triggerAction("actionDatabaseOpen");
|
||||
|
||||
@@ -110,8 +110,8 @@ void TestGui::cleanup()
|
||||
|
||||
void TestGui::testMergeDatabase()
|
||||
{
|
||||
// this triggers a warning. Perhaps similar to https://bugreports.qt.io/browse/QTBUG-49623 ?
|
||||
QSignalSpy dbMergeSpy(m_tabWidget->currentWidget(), SIGNAL(databaseMerged(Database*)));
|
||||
// It is safe to ignore the warning this line produces
|
||||
QSignalSpy dbMergeSpy(m_dbWidget, SIGNAL(databaseMerged(Database*)));
|
||||
|
||||
// set file to merge from
|
||||
fileDialog()->setNextFileName(QString(KEEPASSX_TEST_DATA_DIR).append("/MergeDatabase.kdbx"));
|
||||
@@ -139,6 +139,74 @@ void TestGui::testMergeDatabase()
|
||||
QCOMPARE(m_db->rootGroup()->findChildByName("General")->entries().size(), 1);
|
||||
}
|
||||
|
||||
void TestGui::testAutoreloadDatabase()
|
||||
{
|
||||
config()->set("AutoReloadOnChange", false);
|
||||
|
||||
// Load the MergeDatabase.kdbx file into temporary storage
|
||||
QByteArray tmpData;
|
||||
QFile mergeDbFile(QString(KEEPASSX_TEST_DATA_DIR).append("/MergeDatabase.kdbx"));
|
||||
QVERIFY(mergeDbFile.open(QIODevice::ReadOnly));
|
||||
QVERIFY(Tools::readAllFromDevice(&mergeDbFile, tmpData));
|
||||
mergeDbFile.close();
|
||||
|
||||
// Test accepting new file in autoreload
|
||||
MessageBox::setNextAnswer(QMessageBox::Yes);
|
||||
// Overwrite the current database with the temp data
|
||||
QVERIFY(m_dbFile.open());
|
||||
QVERIFY(m_dbFile.write(tmpData, static_cast<qint64>(tmpData.size())));
|
||||
m_dbFile.close();
|
||||
Tools::wait(1500);
|
||||
|
||||
m_db = m_dbWidget->database();
|
||||
|
||||
// the General group contains one entry from the new db data
|
||||
QCOMPARE(m_db->rootGroup()->findChildByName("General")->entries().size(), 1);
|
||||
QVERIFY(! m_tabWidget->tabText(m_tabWidget->currentIndex()).endsWith("*"));
|
||||
|
||||
// Reset the state
|
||||
cleanup();
|
||||
init();
|
||||
|
||||
// Test rejecting new file in autoreload
|
||||
MessageBox::setNextAnswer(QMessageBox::No);
|
||||
// Overwrite the current temp database with a new file
|
||||
m_dbFile.open();
|
||||
QVERIFY(m_dbFile.write(tmpData, static_cast<qint64>(tmpData.size())));
|
||||
m_dbFile.close();
|
||||
Tools::wait(1500);
|
||||
|
||||
m_db = m_dbWidget->database();
|
||||
|
||||
// Ensure the merge did not take place
|
||||
QCOMPARE(m_db->rootGroup()->findChildByName("General")->entries().size(), 0);
|
||||
QVERIFY(m_tabWidget->tabText(m_tabWidget->currentIndex()).endsWith("*"));
|
||||
|
||||
// Reset the state
|
||||
cleanup();
|
||||
init();
|
||||
|
||||
// Test accepting a merge of edits into autoreload
|
||||
// Turn on autoload so we only get one messagebox (for the merge)
|
||||
config()->set("AutoReloadOnChange", true);
|
||||
|
||||
// Modify some entries
|
||||
testEditEntry();
|
||||
|
||||
// This is saying yes to merging the entries
|
||||
MessageBox::setNextAnswer(QMessageBox::Yes);
|
||||
// Overwrite the current database with the temp data
|
||||
QVERIFY(m_dbFile.open());
|
||||
QVERIFY(m_dbFile.write(tmpData, static_cast<qint64>(tmpData.size())));
|
||||
m_dbFile.close();
|
||||
Tools::wait(1500);
|
||||
|
||||
m_db = m_dbWidget->database();
|
||||
|
||||
QCOMPARE(m_db->rootGroup()->findChildByName("General")->entries().size(), 1);
|
||||
QVERIFY(m_tabWidget->tabText(m_tabWidget->currentIndex()).endsWith("*"));
|
||||
}
|
||||
|
||||
void TestGui::testTabs()
|
||||
{
|
||||
QCOMPARE(m_tabWidget->count(), 1);
|
||||
|
||||
Reference in New Issue
Block a user