From d142a19c1b2e36943b4c831cef17fac0c0e184ed Mon Sep 17 00:00:00 2001 From: Montel Laurent Date: Fri, 28 Nov 2014 23:45:01 +0100 Subject: [PATCH] Fix enable/disable ok button . Add unittest here --- sieveeditor/CMakeLists.txt | 2 + sieveeditor/autotests/CMakeLists.txt | 9 +++ .../autotests/serversievesettingstest.cpp | 57 +++++++++++++++++++ .../autotests/serversievesettingstest.h | 40 +++++++++++++ sieveeditor/serversievesettings.cpp | 2 +- 5 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 sieveeditor/autotests/CMakeLists.txt create mode 100644 sieveeditor/autotests/serversievesettingstest.cpp create mode 100644 sieveeditor/autotests/serversievesettingstest.h diff --git a/sieveeditor/CMakeLists.txt b/sieveeditor/CMakeLists.txt index 793c19f441..7fd8dd1cfe 100644 --- a/sieveeditor/CMakeLists.txt +++ b/sieveeditor/CMakeLists.txt @@ -58,3 +58,5 @@ install(FILES DESTINATION ${DATA_INSTALL_DIR}/sieveeditor) install(PROGRAMS sieveeditor.desktop DESTINATION ${XDG_APPS_INSTALL_DIR}) + +add_subdirectory(autotests) diff --git a/sieveeditor/autotests/CMakeLists.txt b/sieveeditor/autotests/CMakeLists.txt new file mode 100644 index 0000000000..52a2139049 --- /dev/null +++ b/sieveeditor/autotests/CMakeLists.txt @@ -0,0 +1,9 @@ + +set( sieveedit_serversievesettings_source serversievesettingstest.cpp ../serversievesettings.cpp) +kde4_add_ui_files(sieveedit_serversievesettings_source + ../ui/serversievesettings.ui +) + +kde4_add_unit_test( serversievesettingstest ${sieveedit_serversievesettings_source}) +target_link_libraries( serversievesettingstest ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS}) + diff --git a/sieveeditor/autotests/serversievesettingstest.cpp b/sieveeditor/autotests/serversievesettingstest.cpp new file mode 100644 index 0000000000..bd51011dd5 --- /dev/null +++ b/sieveeditor/autotests/serversievesettingstest.cpp @@ -0,0 +1,57 @@ +/* + Copyright (c) 2014 Montel Laurent + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library 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 Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + +*/ + +#include "serversievesettingstest.h" +#include "../serversievesettings.h" +#include +ServerSieveSettingsTest::ServerSieveSettingsTest(QObject *parent) + : QObject(parent) +{ + +} + +ServerSieveSettingsTest::~ServerSieveSettingsTest() +{ + +} + +void ServerSieveSettingsTest::shouldHaveDefaultValue() +{ + ServerSieveSettings widget; + QVERIFY(widget.serverName().isEmpty()); + QVERIFY(widget.userName().isEmpty()); + QVERIFY(widget.password().isEmpty()); +} + +void ServerSieveSettingsTest::shouldSetValue() +{ + const QString password = QLatin1String("password"); + const QString username = QLatin1String("username"); + const QString servername = QLatin1String("servername"); + ServerSieveSettings widget; + widget.setServerName(servername); + widget.setUserName(username); + widget.setPassword(password); + QCOMPARE(widget.serverName(), servername); + QCOMPARE(widget.userName(), username); + QCOMPARE(widget.password(), password); +} + +QTEST_KDEMAIN(ServerSieveSettingsTest, GUI) diff --git a/sieveeditor/autotests/serversievesettingstest.h b/sieveeditor/autotests/serversievesettingstest.h new file mode 100644 index 0000000000..c884588fc8 --- /dev/null +++ b/sieveeditor/autotests/serversievesettingstest.h @@ -0,0 +1,40 @@ +/* + Copyright (c) 2014 Montel Laurent + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library 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 Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + +*/ + +#ifndef SERVERSIEVESETTINGSTEST_H +#define SERVERSIEVESETTINGSTEST_H + +#include + +class ServerSieveSettingsTest : public QObject +{ + Q_OBJECT +public: + explicit ServerSieveSettingsTest(QObject *parent = 0); + ~ServerSieveSettingsTest(); + +private Q_SLOTS: + void shouldHaveDefaultValue(); + void shouldSetValue(); + + +}; + +#endif // SERVERSIEVESETTINGSTEST_H diff --git a/sieveeditor/serversievesettings.cpp b/sieveeditor/serversievesettings.cpp index 8253bcb19b..3b577757b2 100644 --- a/sieveeditor/serversievesettings.cpp +++ b/sieveeditor/serversievesettings.cpp @@ -107,7 +107,7 @@ void ServerSieveSettings::populateDefaultAuthenticationOptions() void ServerSieveSettings::slotUserServerNameChanged() { - Q_EMIT enableOkButton(!ui->userName->text().isEmpty() && !ui->serverName->text().isEmpty()); + Q_EMIT enableOkButton(!ui->userName->text().trimmed().isEmpty() && !ui->serverName->text().trimmed().isEmpty()); } QString ServerSieveSettings::serverName() const -- GitLab