keepassxc/tests/gui/TestGui.cpp

70 lines
2.2 KiB
C++
Raw Normal View History

2011-12-26 13:18:21 -05:00
/*
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TestGui.h"
#include <QtTest/QTest>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QDialogButtonBox>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include "config-keepassx-tests.h"
#include "tests.h"
2011-12-26 13:18:21 -05:00
#include "crypto/Crypto.h"
#include "gui/FileDialog.h"
#include "gui/MainWindow.h"
void TestGui::initTestCase()
{
Crypto::init();
2011-12-29 14:10:19 -05:00
m_mainWindow = new MainWindow();
2011-12-26 13:18:21 -05:00
}
void TestGui::testOpenDatabase()
{
2011-12-29 14:10:19 -05:00
m_mainWindow->show();
QAction* actionDatabaseOpen = m_mainWindow->findChild<QAction*>("actionDatabaseOpen");
2011-12-26 13:18:21 -05:00
fileDialog()->setNextFileName(QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabase.kdbx"));
actionDatabaseOpen->trigger();
QWidget* keyDialog = m_mainWindow->findChild<QWidget*>("DatabaseOpenDialog");
2011-12-29 14:10:19 -05:00
QVERIFY(keyDialog);
QTest::qWaitForWindowShown(keyDialog);
2011-12-26 13:18:21 -05:00
2011-12-29 14:10:19 -05:00
QLineEdit* editPassword = keyDialog->findChild<QLineEdit*>("editPassword");
2011-12-26 13:18:21 -05:00
QVERIFY(editPassword);
QTest::keyClicks(editPassword, "a");
2011-12-29 14:10:19 -05:00
QDialogButtonBox* buttonBox = keyDialog->findChild<QDialogButtonBox*>("buttonBox");
2011-12-26 13:18:21 -05:00
QTest::mouseClick(buttonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
2011-12-29 14:10:19 -05:00
}
2011-12-26 13:18:21 -05:00
2011-12-29 14:10:19 -05:00
void TestGui::testTabs()
{
QTabWidget* tabWidget = m_mainWindow->findChild<QTabWidget*>("tabWidget");
2011-12-26 13:18:21 -05:00
QCOMPARE(tabWidget->count(), 1);
QCOMPARE(tabWidget->tabText(tabWidget->currentIndex()), QString("NewDatabase.kdbx"));
}
2011-12-29 14:10:19 -05:00
void TestGui::cleanupTestCase()
{
delete m_mainWindow;
}
KEEPASSX_QTEST_GUI_MAIN(TestGui)