mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-23 21:21:08 -05:00
Add Save and SaveAs gui tests.
This commit is contained in:
parent
b579eb954e
commit
2e38b01d80
@ -244,6 +244,11 @@ EntryView* DatabaseWidget::entryView()
|
|||||||
return m_entryView;
|
return m_entryView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Database* DatabaseWidget::database()
|
||||||
|
{
|
||||||
|
return m_db;
|
||||||
|
}
|
||||||
|
|
||||||
void DatabaseWidget::createEntry()
|
void DatabaseWidget::createEntry()
|
||||||
{
|
{
|
||||||
if (!m_groupView->currentGroup()) {
|
if (!m_groupView->currentGroup()) {
|
||||||
|
@ -69,6 +69,7 @@ public:
|
|||||||
~DatabaseWidget();
|
~DatabaseWidget();
|
||||||
GroupView* groupView();
|
GroupView* groupView();
|
||||||
EntryView* entryView();
|
EntryView* entryView();
|
||||||
|
Database* database();
|
||||||
bool dbHasKey();
|
bool dbHasKey();
|
||||||
bool canDeleteCurrentGoup();
|
bool canDeleteCurrentGoup();
|
||||||
int addWidget(QWidget* w);
|
int addWidget(QWidget* w);
|
||||||
|
@ -28,21 +28,26 @@
|
|||||||
|
|
||||||
#include "config-keepassx-tests.h"
|
#include "config-keepassx-tests.h"
|
||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
#include "crypto/Crypto.h"
|
|
||||||
#include "core/Config.h"
|
#include "core/Config.h"
|
||||||
|
#include "core/Database.h"
|
||||||
#include "core/Entry.h"
|
#include "core/Entry.h"
|
||||||
|
#include "core/Metadata.h"
|
||||||
|
#include "crypto/Crypto.h"
|
||||||
|
#include "format/KeePass2Reader.h"
|
||||||
#include "gui/DatabaseTabWidget.h"
|
#include "gui/DatabaseTabWidget.h"
|
||||||
#include "gui/DatabaseWidget.h"
|
#include "gui/DatabaseWidget.h"
|
||||||
#include "gui/FileDialog.h"
|
#include "gui/FileDialog.h"
|
||||||
#include "gui/MainWindow.h"
|
#include "gui/MainWindow.h"
|
||||||
#include "gui/entry/EditEntryWidget.h"
|
#include "gui/entry/EditEntryWidget.h"
|
||||||
#include "gui/entry/EntryView.h"
|
#include "gui/entry/EntryView.h"
|
||||||
|
#include "keys/PasswordKey.h"
|
||||||
|
|
||||||
void TestGui::initTestCase()
|
void TestGui::initTestCase()
|
||||||
{
|
{
|
||||||
Crypto::init();
|
Crypto::init();
|
||||||
Config::createTempFileInstance();
|
Config::createTempFileInstance();
|
||||||
m_mainWindow = new MainWindow();
|
m_mainWindow = new MainWindow();
|
||||||
|
m_tabWidget = m_mainWindow->findChild<DatabaseTabWidget*>("tabWidget");
|
||||||
m_mainWindow->show();
|
m_mainWindow->show();
|
||||||
QTest::qWaitForWindowShown(m_mainWindow);
|
QTest::qWaitForWindowShown(m_mainWindow);
|
||||||
}
|
}
|
||||||
@ -66,15 +71,13 @@ void TestGui::testOpenDatabase()
|
|||||||
|
|
||||||
void TestGui::testTabs()
|
void TestGui::testTabs()
|
||||||
{
|
{
|
||||||
QTabWidget* tabWidget = m_mainWindow->findChild<QTabWidget*>("tabWidget");
|
QCOMPARE(m_tabWidget->count(), 1);
|
||||||
QCOMPARE(tabWidget->count(), 1);
|
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("NewDatabase.kdbx"));
|
||||||
QCOMPARE(tabWidget->tabText(tabWidget->currentIndex()), QString("NewDatabase.kdbx"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestGui::testEditEntry()
|
void TestGui::testEditEntry()
|
||||||
{
|
{
|
||||||
DatabaseTabWidget* tabWidget = m_mainWindow->findChild<DatabaseTabWidget*>("tabWidget");
|
DatabaseWidget* dbWidget = m_tabWidget->currentDatabaseWidget();
|
||||||
DatabaseWidget* dbWidget = tabWidget->currentDatabaseWidget();
|
|
||||||
EntryView* entryView = dbWidget->findChild<EntryView*>("entryView");
|
EntryView* entryView = dbWidget->findChild<EntryView*>("entryView");
|
||||||
QModelIndex item = entryView->model()->index(0, 1);
|
QModelIndex item = entryView->model()->index(0, 1);
|
||||||
QRect itemRect = entryView->visualRect(item);
|
QRect itemRect = entryView->visualRect(item);
|
||||||
@ -97,13 +100,12 @@ void TestGui::testEditEntry()
|
|||||||
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
||||||
QTest::qWait(20);
|
QTest::qWait(20);
|
||||||
// make sure the database isn't marked as modified
|
// make sure the database isn't marked as modified
|
||||||
QCOMPARE(tabWidget->tabText(tabWidget->currentIndex()), QString("NewDatabase.kdbx"));
|
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("NewDatabase.kdbx"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestGui::testAddEntry()
|
void TestGui::testAddEntry()
|
||||||
{
|
{
|
||||||
DatabaseTabWidget* tabWidget = m_mainWindow->findChild<DatabaseTabWidget*>("tabWidget");
|
DatabaseWidget* dbWidget = m_tabWidget->currentDatabaseWidget();
|
||||||
DatabaseWidget* dbWidget = tabWidget->currentDatabaseWidget();
|
|
||||||
|
|
||||||
EntryView* entryView = dbWidget->findChild<EntryView*>("entryView");
|
EntryView* entryView = dbWidget->findChild<EntryView*>("entryView");
|
||||||
QAction* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew");
|
QAction* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew");
|
||||||
@ -134,7 +136,7 @@ void TestGui::testAddEntry()
|
|||||||
QCOMPARE(entry->title(), QString("test"));
|
QCOMPARE(entry->title(), QString("test"));
|
||||||
QCOMPARE(entry->historyItems().size(), 0);
|
QCOMPARE(entry->historyItems().size(), 0);
|
||||||
QTest::qWait(200);
|
QTest::qWait(200);
|
||||||
QCOMPARE(tabWidget->tabText(tabWidget->currentIndex()), QString("NewDatabase.kdbx*"));
|
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("NewDatabase.kdbx*"));
|
||||||
|
|
||||||
QAction* entryEditAction = m_mainWindow->findChild<QAction*>("actionEntryEdit");
|
QAction* entryEditAction = m_mainWindow->findChild<QAction*>("actionEntryEdit");
|
||||||
QVERIFY(entryEditAction->isEnabled());
|
QVERIFY(entryEditAction->isEnabled());
|
||||||
@ -155,8 +157,7 @@ void TestGui::testAddEntry()
|
|||||||
|
|
||||||
void TestGui::testSearch()
|
void TestGui::testSearch()
|
||||||
{
|
{
|
||||||
DatabaseTabWidget* tabWidget = m_mainWindow->findChild<DatabaseTabWidget*>("tabWidget");
|
DatabaseWidget* dbWidget = m_tabWidget->currentDatabaseWidget();
|
||||||
DatabaseWidget* dbWidget = tabWidget->currentDatabaseWidget();
|
|
||||||
|
|
||||||
QAction* searchAction = m_mainWindow->findChild<QAction*>("actionSearch");
|
QAction* searchAction = m_mainWindow->findChild<QAction*>("actionSearch");
|
||||||
QVERIFY(searchAction->isEnabled());
|
QVERIFY(searchAction->isEnabled());
|
||||||
@ -217,6 +218,56 @@ void TestGui::testSearch()
|
|||||||
QCOMPARE(entryView->model()->rowCount(), 1);
|
QCOMPARE(entryView->model()->rowCount(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestGui::testSaveAs()
|
||||||
|
{
|
||||||
|
QFileInfo fileInfo(QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabase.kdbx"));
|
||||||
|
QDateTime lastModified = fileInfo.lastModified();
|
||||||
|
|
||||||
|
Database* db = m_tabWidget->currentDatabaseWidget()->database();
|
||||||
|
db->metadata()->setName("SaveAs");
|
||||||
|
|
||||||
|
// open temporary file so it creates a filename
|
||||||
|
QVERIFY(tmpFile.open());
|
||||||
|
tmpFile.close();
|
||||||
|
fileDialog()->setNextFileName(tmpFile.fileName());
|
||||||
|
|
||||||
|
QAction* actionDatabaseSaveAs = m_mainWindow->findChild<QAction*>("actionDatabaseSaveAs");
|
||||||
|
actionDatabaseSaveAs->trigger();
|
||||||
|
|
||||||
|
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("SaveAs"));
|
||||||
|
|
||||||
|
CompositeKey key;
|
||||||
|
key.addKey(PasswordKey("a"));
|
||||||
|
KeePass2Reader reader;
|
||||||
|
QScopedPointer<Database> dbSaved(reader.readDatabase(tmpFile.fileName(), key));
|
||||||
|
QVERIFY(dbSaved);
|
||||||
|
QVERIFY(!reader.hasError());
|
||||||
|
QCOMPARE(dbSaved->metadata()->name(), db->metadata()->name());
|
||||||
|
|
||||||
|
fileInfo.refresh();
|
||||||
|
QCOMPARE(fileInfo.lastModified(), lastModified);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestGui::testSave()
|
||||||
|
{
|
||||||
|
Database* db = m_tabWidget->currentDatabaseWidget()->database();
|
||||||
|
db->metadata()->setName("Save");
|
||||||
|
QTest::qWait(200);
|
||||||
|
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("Save*"));
|
||||||
|
|
||||||
|
QAction* actionDatabaseSave = m_mainWindow->findChild<QAction*>("actionDatabaseSave");
|
||||||
|
actionDatabaseSave->trigger();
|
||||||
|
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("Save"));
|
||||||
|
|
||||||
|
CompositeKey key;
|
||||||
|
key.addKey(PasswordKey("a"));
|
||||||
|
KeePass2Reader reader;
|
||||||
|
QScopedPointer<Database> dbSaved(reader.readDatabase(tmpFile.fileName(), key));
|
||||||
|
QVERIFY(dbSaved);
|
||||||
|
QVERIFY(!reader.hasError());
|
||||||
|
QCOMPARE(dbSaved->metadata()->name(), db->metadata()->name());
|
||||||
|
}
|
||||||
|
|
||||||
void TestGui::testKeePass1Import()
|
void TestGui::testKeePass1Import()
|
||||||
{
|
{
|
||||||
QAction* actionImportKeePass1 = m_mainWindow->findChild<QAction*>("actionImportKeePass1");
|
QAction* actionImportKeePass1 = m_mainWindow->findChild<QAction*>("actionImportKeePass1");
|
||||||
@ -232,9 +283,8 @@ void TestGui::testKeePass1Import()
|
|||||||
QTest::keyClick(editPassword, Qt::Key_Enter);
|
QTest::keyClick(editPassword, Qt::Key_Enter);
|
||||||
QTest::qWait(20);
|
QTest::qWait(20);
|
||||||
|
|
||||||
QTabWidget* tabWidget = m_mainWindow->findChild<QTabWidget*>("tabWidget");
|
QCOMPARE(m_tabWidget->count(), 2);
|
||||||
QCOMPARE(tabWidget->count(), 2);
|
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("basic [New database]*"));
|
||||||
QCOMPARE(tabWidget->tabText(tabWidget->currentIndex()), QString("basic [New database]*"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestGui::cleanupTestCase()
|
void TestGui::cleanupTestCase()
|
||||||
|
@ -19,7 +19,9 @@
|
|||||||
#define KEEPASSX_TESTGUI_H
|
#define KEEPASSX_TESTGUI_H
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
|
#include <QtCore/QTemporaryFile>
|
||||||
|
|
||||||
|
class DatabaseTabWidget;
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
|
|
||||||
class TestGui : public QObject
|
class TestGui : public QObject
|
||||||
@ -33,11 +35,15 @@ private Q_SLOTS:
|
|||||||
void testEditEntry();
|
void testEditEntry();
|
||||||
void testAddEntry();
|
void testAddEntry();
|
||||||
void testSearch();
|
void testSearch();
|
||||||
|
void testSaveAs();
|
||||||
|
void testSave();
|
||||||
void testKeePass1Import();
|
void testKeePass1Import();
|
||||||
void cleanupTestCase();
|
void cleanupTestCase();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MainWindow* m_mainWindow;
|
MainWindow* m_mainWindow;
|
||||||
|
DatabaseTabWidget* m_tabWidget;
|
||||||
|
QTemporaryFile tmpFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEEPASSX_TESTGUI_H
|
#endif // KEEPASSX_TESTGUI_H
|
||||||
|
Loading…
Reference in New Issue
Block a user