SVN_SILENT made messages (after extraction)
[kdepim.git] / sieveeditor / autotests / serversievesettingstest.cpp
blob74c3fcd03a9e82b28732e1f880fc1890348b6cd3
1 /*
2 Copyright (c) 2014-2015 Montel Laurent <montel@kde.org>
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
21 #include "serversievesettingstest.h"
22 #include "../serversievesettings.h"
23 #include <qtest.h>
24 #include <QSignalSpy>
25 ServerSieveSettingsTest::ServerSieveSettingsTest(QObject *parent)
26 : QObject(parent)
31 ServerSieveSettingsTest::~ServerSieveSettingsTest()
36 void ServerSieveSettingsTest::shouldHaveDefaultValue()
38 ServerSieveSettings widget;
39 QVERIFY(widget.serverName().isEmpty());
40 QVERIFY(widget.userName().isEmpty());
41 QVERIFY(widget.password().isEmpty());
44 void ServerSieveSettingsTest::shouldSetValue()
46 const QString password = QStringLiteral("password");
47 const QString username = QStringLiteral("username");
48 const QString servername = QStringLiteral("servername");
49 ServerSieveSettings widget;
50 widget.setServerName(servername);
51 widget.setUserName(username);
52 widget.setPassword(password);
53 QCOMPARE(widget.serverName(), servername);
54 QCOMPARE(widget.userName(), username);
55 QCOMPARE(widget.password(), password);
58 void ServerSieveSettingsTest::shouldEmitEnableOkButtonSignal()
60 ServerSieveSettings widget;
61 widget.show();
62 QTest::qWaitForWindowExposed(&widget);
63 QSignalSpy spy(&widget, SIGNAL(enableOkButton(bool)));
64 widget.setPassword(QStringLiteral("foo"));
65 QCOMPARE(spy.count(), 0);
67 int numberEmitSignal = 1;
68 widget.setServerName(QStringLiteral("foo"));
69 QCOMPARE(spy.count(), numberEmitSignal);
70 ++numberEmitSignal;
71 widget.setUserName(QStringLiteral("foo"));
72 QCOMPARE(spy.count(), numberEmitSignal);
73 ++numberEmitSignal;
74 widget.setUserName(QStringLiteral(""));
75 QCOMPARE(spy.count(), numberEmitSignal);
76 ++numberEmitSignal;
77 widget.setServerName(QStringLiteral(""));
78 QCOMPARE(spy.count(), numberEmitSignal);
81 void ServerSieveSettingsTest::shouldEmitSignalWithValueTrue()
83 ServerSieveSettings widget;
84 widget.show();
85 QTest::qWaitForWindowExposed(&widget);
86 QSignalSpy spy(&widget, SIGNAL(enableOkButton(bool)));
87 widget.setServerName(QStringLiteral("foo"));
88 QCOMPARE(spy.count(), 1);
89 //We need servername!=empty and username != empty
90 QCOMPARE(spy.at(0).at(0).toBool(), false);
92 widget.setUserName(QStringLiteral("foo"));
93 QCOMPARE(spy.count(), 2);
94 QCOMPARE(spy.at(1).at(0).toBool(), true);
96 //We don't want empty string
97 widget.setUserName(QStringLiteral(" "));
98 QCOMPARE(spy.count(), 3);
99 QCOMPARE(spy.at(2).at(0).toBool(), false);
101 //We don't want empty string
102 widget.setServerName(QStringLiteral(" "));
103 QCOMPARE(spy.count(), 4);
104 QCOMPARE(spy.at(3).at(0).toBool(), false);
108 QTEST_MAIN(ServerSieveSettingsTest)