Commit 3ae633ad authored by Laurent Montel's avatar Laurent Montel 😁

Add autotest

parent 490fed4b
......@@ -3,3 +3,9 @@ ecm_add_test(kactionmenuchangecasetest.cpp
NAME_PREFIX pimcommon-widget
LINK_LIBRARIES Qt5::Test Qt5::Gui KF5::WidgetsAddons KF5::I18n KF5::XmlGui KF5::PimCommon
)
ecm_add_test(lineeditpasswordtest.cpp
TEST_NAME lineeditpasswordtest
NAME_PREFIX pimcommon-widget
LINK_LIBRARIES Qt5::Test Qt5::Gui KF5::WidgetsAddons KF5::I18n KF5::PimCommon
)
/*
Copyright (c) 2017 Montel Laurent <montel@kde.org>
based on lineedit in kpassworddialog.cpp
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "lineeditpasswordtest.h"
#include "../lineeditpassword.h"
#include <QHBoxLayout>
#include <QLineEdit>
#include <QTest>
#include <QAction>
LineEditPasswordTest::LineEditPasswordTest(QObject *parent)
: QObject(parent)
{
}
void LineEditPasswordTest::shouldHaveDefaultValue()
{
PimCommon::LineEditPassword lineEdit;
QVERIFY(lineEdit.password().isEmpty());
QHBoxLayout *mainLayout = lineEdit.findChild<QHBoxLayout *>(QStringLiteral("mainlayout"));
QVERIFY(mainLayout);
QCOMPARE(mainLayout->margin(), 0);
QLineEdit *edit = lineEdit.findChild<QLineEdit *>(QStringLiteral("passwordlineedit"));
QVERIFY(edit);
QVERIFY(edit->text().isEmpty());
QCOMPARE(edit->echoMode(), QLineEdit::Password);
QVERIFY(lineEdit.toggleEchoModeAction());
QVERIFY(!lineEdit.toggleEchoModeAction()->isVisible());
}
void LineEditPasswordTest::shouldShowTogglePassword()
{
PimCommon::LineEditPassword lineEdit;
lineEdit.show();
QTest::qWaitForWindowExposed(&lineEdit);
QLineEdit *edit = lineEdit.findChild<QLineEdit *>(QStringLiteral("passwordlineedit"));
edit->setText(QStringLiteral("FOO"));
QVERIFY(lineEdit.toggleEchoModeAction()->isVisible());
edit->clear();
QVERIFY(!lineEdit.toggleEchoModeAction()->isVisible());
}
void LineEditPasswordTest::shouldNotShowToggleWhenSetPassword()
{
PimCommon::LineEditPassword lineEdit;
lineEdit.show();
QTest::qWaitForWindowExposed(&lineEdit);
lineEdit.setPassword(QStringLiteral("foo"));
QVERIFY(!lineEdit.toggleEchoModeAction()->isVisible());
}
QTEST_MAIN(LineEditPasswordTest)
/*
Copyright (c) 2017 Montel Laurent <montel@kde.org>
based on lineedit in kpassworddialog.cpp
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef LINEEDITPASSWORDTEST_H
#define LINEEDITPASSWORDTEST_H
#include <QObject>
class LineEditPasswordTest : public QObject
{
Q_OBJECT
public:
explicit LineEditPasswordTest(QObject *parent = nullptr);
~LineEditPasswordTest() = default;
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldShowTogglePassword();
void shouldNotShowToggleWhenSetPassword();
};
#endif // LINEEDITPASSWORDTEST_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment