diff --git a/autotests/messageattachmenttest.cpp b/autotests/messageattachmenttest.cpp index 3c65b381..331f6b9e 100644 --- a/autotests/messageattachmenttest.cpp +++ b/autotests/messageattachmenttest.cpp @@ -1,79 +1,79 @@ /* Copyright (c) 2017-2018 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 ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), 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 "messageattachmenttest.h" #include "messageattachment.h" #include #include -QTEST_MAIN(MessageAttachmentTest) +QTEST_GUILESS_MAIN(MessageAttachmentTest) MessageAttachmentTest::MessageAttachmentTest(QObject *parent) : QObject(parent) { } void MessageAttachmentTest::shouldHaveDefaultValue() { MessageAttachment attachment; QVERIFY(attachment.description().isEmpty()); QVERIFY(attachment.title().isEmpty()); QVERIFY(attachment.link().isEmpty()); QVERIFY(attachment.isEmpty()); QVERIFY(attachment.color().isEmpty()); QCOMPARE(attachment.imageHeight(), -1); QCOMPARE(attachment.imageWidth(), -1); } void MessageAttachmentTest::shouldSerializeData() { { MessageAttachment input; input.setColor(QStringLiteral("foo1")); input.setDescription(QStringLiteral("foo2")); input.setTitle(QStringLiteral("foo3")); input.setLink(QStringLiteral("foo4")); input.setImageHeight(53); input.setImageWidth(83); const QJsonObject ba = MessageAttachment::serialize(input); const MessageAttachment output = MessageAttachment::fromJSon(ba); QCOMPARE(input, output); } { MessageAttachment input; input.setDescription(QStringLiteral("foo2")); input.setTitle(QStringLiteral("foo3")); input.setLink(QStringLiteral("foo4")); const QJsonObject ba = MessageAttachment::serialize(input); const MessageAttachment output = MessageAttachment::fromJSon(ba); QCOMPARE(input, output); } { MessageAttachment input; input.setColor(QStringLiteral("foo1")); input.setDescription(QStringLiteral("foo2")); input.setTitle(QStringLiteral("foo3")); input.setLink(QStringLiteral("foo4")); const QJsonObject ba = MessageAttachment::serialize(input); const MessageAttachment output = MessageAttachment::fromJSon(ba); QCOMPARE(input, output); } } diff --git a/autotests/messageurltest.cpp b/autotests/messageurltest.cpp index acbe4ac7..e3d73e7d 100644 --- a/autotests/messageurltest.cpp +++ b/autotests/messageurltest.cpp @@ -1,68 +1,68 @@ /* Copyright (c) 2017-2018 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 ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), 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 "messageurltest.h" #include "messageurl.h" #include #include -QTEST_MAIN(MessageUrlTest) +QTEST_GUILESS_MAIN(MessageUrlTest) MessageUrlTest::MessageUrlTest(QObject *parent) : QObject(parent) { } void MessageUrlTest::shouldHaveDefaultValue() { MessageUrl url; QVERIFY(url.url().isEmpty()); QVERIFY(url.pageTitle().isEmpty()); QVERIFY(url.description().isEmpty()); QVERIFY(url.isEmpty()); } void MessageUrlTest::shouldSerializeData() { { MessageUrl input; input.setUrl(QStringLiteral("foo1")); input.setPageTitle(QStringLiteral("foo2")); input.setDescription(QStringLiteral("foo3")); const QJsonObject ba = MessageUrl::serialize(input); const MessageUrl output = MessageUrl::fromJSon(ba); QCOMPARE(input, output); } { MessageUrl input; input.setPageTitle(QStringLiteral("foo2")); input.setDescription(QStringLiteral("foo3")); const QJsonObject ba = MessageUrl::serialize(input); const MessageUrl output = MessageUrl::fromJSon(ba); QCOMPARE(input, output); } { MessageUrl input; input.setUrl(QStringLiteral("foo1")); input.setDescription(QStringLiteral("foo3")); const QJsonObject ba = MessageUrl::serialize(input); const MessageUrl output = MessageUrl::fromJSon(ba); QCOMPARE(input, output); } } diff --git a/autotests/rocketchataccountsettingstest.cpp b/autotests/rocketchataccountsettingstest.cpp index 2fb98151..05159573 100644 --- a/autotests/rocketchataccountsettingstest.cpp +++ b/autotests/rocketchataccountsettingstest.cpp @@ -1,215 +1,215 @@ /* Copyright (c) 2017-2018 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 ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), 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 "rocketchataccountsettingstest.h" #include "rocketchataccountsettings.h" #include #include #include -QTEST_MAIN(RocketChatAccountSettingsTest) +QTEST_GUILESS_MAIN(RocketChatAccountSettingsTest) RocketChatAccountSettingsTest::RocketChatAccountSettingsTest(QObject *parent) : QObject(parent) { QStandardPaths::setTestModeEnabled(true); } void RocketChatAccountSettingsTest::shouldNotEmitSignalWhenNewServerUrlIsSameAsOld() { RocketChatAccountSettings SampleChatAccount; const QString url = QStringLiteral("some.url.com"); SampleChatAccount.setServerUrl(url); QSignalSpy SpyURL(&SampleChatAccount, &RocketChatAccountSettings::serverURLChanged); SampleChatAccount.setServerUrl(url); QCOMPARE(SpyURL.count(), 0); } void RocketChatAccountSettingsTest::shouldEmitSignalWhenSetServerURLChanged() { RocketChatAccountSettings SampleChatAccount; QSignalSpy SpyURL(&SampleChatAccount, &RocketChatAccountSettings::serverURLChanged); const QString serverUrlDefault = QStringLiteral("bla bla"); SampleChatAccount.setServerUrl(serverUrlDefault); QCOMPARE(SpyURL.count(), 1); //Test same url SampleChatAccount.setServerUrl(serverUrlDefault); QCOMPARE(SpyURL.count(), 1); //Test Empty url QString emptyString; SampleChatAccount.setServerUrl(emptyString); QCOMPARE(SpyURL.count(), 2); SampleChatAccount.setServerUrl(emptyString); QCOMPARE(SpyURL.count(), 2); } void RocketChatAccountSettingsTest::shouldNotEmitSignalWhenNewUsernameIsSameAsOld() { RocketChatAccountSettings SampleChat; const QString username = QStringLiteral("dummyUsername"); SampleChat.setUserName(username); QSignalSpy SpyName(&SampleChat, &RocketChatAccountSettings::userNameChanged); SampleChat.setUserName(username); QCOMPARE(SpyName.count(), 0); } void RocketChatAccountSettingsTest::shouldEmitSignalWhenUserNameChanged() { RocketChatAccountSettings SampleChat; QSignalSpy SpyName(&SampleChat, &RocketChatAccountSettings::userNameChanged); const QString userNameDefault = QStringLiteral("Donald Knuth"); SampleChat.setUserName(userNameDefault); QCOMPARE(SpyName.count(), 1); //Test same name SampleChat.setUserName(userNameDefault); QCOMPARE(SpyName.count(), 1); //Test empty string QString emptyString; SampleChat.setUserName(emptyString); QCOMPARE(SpyName.count(), 2); SampleChat.setUserName(emptyString); QCOMPARE(SpyName.count(), 2); } void RocketChatAccountSettingsTest::shouldEmitSignalWhenUserIDChanged() { RocketChatAccountSettings SampleChat1; QSignalSpy SpyID(&SampleChat1, &RocketChatAccountSettings::userIDChanged); const QString userId = QStringLiteral("RA15"); QVERIFY(userId != SampleChat1.userId()); SampleChat1.setUserId(QStringLiteral("RA15")); QCOMPARE(SpyID.count(), 1); } void RocketChatAccountSettingsTest::shouldEmitSignalWhenLoginStatusChanged() { } void RocketChatAccountSettingsTest::shouldLogout() { RocketChatAccountSettings SampleChat; SampleChat.setAuthToken(QStringLiteral("Token305")); SampleChat.setUserId(QStringLiteral("ECE305")); SampleChat.setPassword(QStringLiteral("masterPassword")); //Make sure that values are not null QVERIFY(!SampleChat.authToken().isEmpty()); QVERIFY(!SampleChat.userId().isEmpty()); QVERIFY(!SampleChat.password().isEmpty()); SampleChat.logout(); QVERIFY(SampleChat.authToken().isEmpty()); QVERIFY(SampleChat.userId().isEmpty()); QVERIFY(SampleChat.password().isEmpty()); } void RocketChatAccountSettingsTest::shouldSetAccountName() { RocketChatAccountSettings sampleChat; QSignalSpy spy(&sampleChat, &RocketChatAccountSettings::accountNameChanged); QString val = QStringLiteral("myAccount#$^56"); sampleChat.setAccountName(val); QCOMPARE(val, sampleChat.accountName()); QCOMPARE(spy.count(), 1); } void RocketChatAccountSettingsTest::shouldsetAuthToken() { RocketChatAccountSettings sampleChat; QString val = QStringLiteral("myAuthToken#$^56"); sampleChat.setAuthToken(val); QCOMPARE(val, sampleChat.authToken()); } void RocketChatAccountSettingsTest::shouldSetPassword() { RocketChatAccountSettings sampleChat; QString val = QStringLiteral("myPass#$^56"); sampleChat.setPassword(val); QCOMPARE(val, sampleChat.password()); } void RocketChatAccountSettingsTest::shouldSetServerUrl() { RocketChatAccountSettings sampleChat; QString val = QStringLiteral("my.fancy.url"); sampleChat.setServerUrl(val); QCOMPARE(val, sampleChat.serverUrl()); } void RocketChatAccountSettingsTest::shouldSetUserID() { RocketChatAccountSettings sampleChat; QString val = QStringLiteral("ECE305"); sampleChat.setUserId(val); QCOMPARE(val, sampleChat.userId()); } void RocketChatAccountSettingsTest::shouldSetUserName() { RocketChatAccountSettings sampleChat; QString val = QStringLiteral("Eric Roberts"); sampleChat.setUserName(val); QCOMPARE(val, sampleChat.userName()); } void RocketChatAccountSettingsTest::shouldHaveDefaultValues() { RocketChatAccountSettings chat; QVERIFY(chat.accountName().isEmpty()); QVERIFY(chat.authToken().isEmpty()); QVERIFY(chat.cacheBasePath().isEmpty()); QVERIFY(chat.userId().isEmpty()); QVERIFY(chat.userName().isEmpty()); QVERIFY(chat.password().isEmpty()); QVERIFY(chat.serverUrl().isEmpty()); chat.loadSettings(); QVERIFY(chat.userId().isEmpty()); QVERIFY(chat.userName().isEmpty()); QVERIFY(chat.authToken().isEmpty()); QCOMPARE(chat.serverUrl(), QStringLiteral("demo.rocket.chat")); } diff --git a/autotests/rocketchatcachetest.cpp b/autotests/rocketchatcachetest.cpp index eb430b00..abd5bb06 100644 --- a/autotests/rocketchatcachetest.cpp +++ b/autotests/rocketchatcachetest.cpp @@ -1,30 +1,30 @@ /* Copyright (c) 2018 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 ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), 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 "rocketchatcachetest.h" - +#include "rocketchatcache.h" #include -QTEST_MAIN(RocketChatCacheTest) +QTEST_GUILESS_MAIN(RocketChatCacheTest) RocketChatCacheTest::RocketChatCacheTest(QObject *parent) : QObject(parent) { } diff --git a/autotests/ruqolaserverconfigtest.cpp b/autotests/ruqolaserverconfigtest.cpp index 91ef995a..edf5f865 100644 --- a/autotests/ruqolaserverconfigtest.cpp +++ b/autotests/ruqolaserverconfigtest.cpp @@ -1,66 +1,66 @@ /* Copyright (c) 2017-2018 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 ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), 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 "ruqolaserverconfigtest.h" #include "ruqolaserverconfig.h" #include -QTEST_MAIN(RuqolaServerConfigTest) +QTEST_GUILESS_MAIN(RuqolaServerConfigTest) RuqolaServerConfigTest::RuqolaServerConfigTest(QObject *parent) : QObject(parent) { } void RuqolaServerConfigTest::shouldHaveDefaultValues() { RuqolaServerConfig config; QVERIFY(config.jitsiMeetPrefix().isEmpty()); QVERIFY(config.jitsiMeetUrl().isEmpty()); QVERIFY(config.uniqueId().isEmpty()); QVERIFY(config.fileUploadStorageType().isEmpty()); QVERIFY(config.allowMessageEditing()); QCOMPARE(config.blockEditingMessageInMinutes(), 5); } void RuqolaServerConfigTest::shouldAssignValues() { const QString jitsimeetprefix = QStringLiteral("test 1"); const QString jitsimeeturl = QStringLiteral("test 2"); const QString uniqueId = QStringLiteral("test 3"); const QString filestoragetype = QStringLiteral("test 4"); const bool allowEditing = false; const int minutes = 12; RuqolaServerConfig config; config.setJitsiMeetPrefix(jitsimeetprefix); config.setJitsiMeetUrl(jitsimeeturl); config.setUniqueId(uniqueId); config.setFileUploadStorageType(filestoragetype); config.setAllowMessageEditing(allowEditing); config.setBlockEditingMessageInMinutes(minutes); QCOMPARE(config.jitsiMeetPrefix(), jitsimeetprefix); QCOMPARE(config.jitsiMeetUrl(), jitsimeeturl); QCOMPARE(config.uniqueId(), uniqueId); QCOMPARE(config.fileUploadStorageType(), filestoragetype); QCOMPARE(config.allowMessageEditing(), allowEditing); QCOMPARE(config.blockEditingMessageInMinutes(), minutes); } diff --git a/autotests/textconvertertest.cpp b/autotests/textconvertertest.cpp index c17651c4..44e6e52d 100644 --- a/autotests/textconvertertest.cpp +++ b/autotests/textconvertertest.cpp @@ -1,44 +1,44 @@ /* Copyright (C) 2018 Montel Laurent 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 of the License, or (at your option) any later version. 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "textconvertertest.h" #include "textconverter.h" #include -QTEST_MAIN(TextConverterTest) +QTEST_GUILESS_MAIN(TextConverterTest) TextConverterTest::TextConverterTest(QObject *parent) : QObject(parent) { } void TextConverterTest::shouldConvertText_data() { QTest::addColumn("input"); QTest::addColumn("output"); QTest::newRow("empty") << QString() << QString(); } void TextConverterTest::shouldConvertText() { QFETCH(QString, input); QFETCH(QString, output); TextConverter w; QCOMPARE(w.convertMessageText(input, {}), output); } diff --git a/autotests/typingnotificationtest.cpp b/autotests/typingnotificationtest.cpp index f99b6aac..ae6d860d 100644 --- a/autotests/typingnotificationtest.cpp +++ b/autotests/typingnotificationtest.cpp @@ -1,107 +1,107 @@ /* Copyright (c) 2017-2018 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 ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), 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 "typingnotificationtest.h" #include "libruqola_private_export.h" #include "typingnotification.h" #include #include -QTEST_MAIN(TypingNotificationTest) +QTEST_GUILESS_MAIN(TypingNotificationTest) extern LIBRUQOLACORE_TESTS_EXPORT int timerTimeOutValueMs; TypingNotificationTest::TypingNotificationTest(QObject *parent) : QObject(parent) { } void TypingNotificationTest::shouldNotEmitSignalByDefault() { timerTimeOutValueMs = 100; //100ms TypingNotification t; QSignalSpy signal(&t, &TypingNotification::informTypingStatus); //Wait 500ms QTest::qSleep(200); QCOMPARE(signal.count(), 0); } void TypingNotificationTest::shouldEmitSignalWhenTyping() { timerTimeOutValueMs = 100; //100ms TypingNotification t; QSignalSpy signal(&t, &TypingNotification::informTypingStatus); t.setText(QStringLiteral("foo"), QStringLiteral("bla")); //Wait 500ms QTest::qWait(50); QCOMPARE(signal.count(), 1); } void TypingNotificationTest::shouldEmitSignalWhenTypingAndEmitTypingFalseAfterTimeout() { timerTimeOutValueMs = 100; //100ms TypingNotification t; QSignalSpy signal(&t, &TypingNotification::informTypingStatus); t.setText(QStringLiteral("foo"), QStringLiteral("bla")); //Wait 50ms QTest::qWait(50); QCOMPARE(signal.count(), 1); QTest::qWait(150); // 150 ms QCOMPARE(signal.count(), 2); } void TypingNotificationTest::shouldDontEmitSignalWhenTypingSeveralTextBeforeTimeOut() { timerTimeOutValueMs = 100; //100ms TypingNotification t; QSignalSpy signal(&t, &TypingNotification::informTypingStatus); t.setText(QStringLiteral("foo"), QStringLiteral("bla")); //Wait 50ms QTest::qWait(50); QCOMPARE(signal.count(), 1); t.setText(QStringLiteral("foo"), QStringLiteral("bla1")); QTest::qWait(50); QCOMPARE(signal.count(), 1); t.setText(QStringLiteral("foo"), QStringLiteral("bla2")); QTest::qWait(50); QCOMPARE(signal.count(), 1); QTest::qWait(150); // 150 ms QCOMPARE(signal.count(), 2); } void TypingNotificationTest::shouldEmitTwoSignalWhenChangeRoom() { timerTimeOutValueMs = 100; //100ms TypingNotification t; QSignalSpy signal(&t, &TypingNotification::informTypingStatus); QString room1 = QStringLiteral("room1"); QString room2 = QStringLiteral("room2"); t.setText(room1, QStringLiteral("bla")); //Wait 50ms QTest::qWait(50); QCOMPARE(signal.count(), 1); t.setText(room2, QStringLiteral("bla")); //Wait 50ms QTest::qWait(50); QCOMPARE(signal.count(), 3); //Two signal send. } diff --git a/autotests/usertest.cpp b/autotests/usertest.cpp index fa8dafae..eb6bef25 100644 --- a/autotests/usertest.cpp +++ b/autotests/usertest.cpp @@ -1,165 +1,165 @@ /* Copyright (c) 2017-2018 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 ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), 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 "usertest.h" #include "user.h" #include #include #include -QTEST_MAIN(UserTest) +QTEST_GUILESS_MAIN(UserTest) UserTest::UserTest(QObject *parent) : QObject(parent) { } void UserTest::shouldHaveDefaultValue() { User u; QVERIFY(u.name().isEmpty()); QVERIFY(u.userId().isEmpty()); QVERIFY(u.status().isEmpty()); QVERIFY(u.listRooms().isEmpty()); } void UserTest::shouldSetAndGetName() { User sampleUser; QSignalSpy spy(&sampleUser, &User::nameChanged); QString name = QStringLiteral("Maxwell"); sampleUser.setName(name); QCOMPARE(sampleUser.name(), name); QCOMPARE(spy.count(), 1); name = QStringLiteral("Maxwell_NEW"); sampleUser.setName(name); QCOMPARE(sampleUser.name(), name); QCOMPARE(spy.count(), 2); name = QStringLiteral("Maxwell_NEW"); sampleUser.setName(name); QCOMPARE(sampleUser.name(), name); QCOMPARE(spy.count(), 2); } void UserTest::shouldSetAndGetUserId() { User sampleUser; QString Id = QStringLiteral("RA1511ECE"); sampleUser.setUserId(Id); QCOMPARE(sampleUser.userId(), Id); Id = QStringLiteral("RA1511ECE_NEW"); sampleUser.setUserId(Id); QCOMPARE(sampleUser.userId(), Id); Id = QStringLiteral("RA1511ECE_NEW"); sampleUser.setUserId(Id); QCOMPARE(sampleUser.userId(), Id); } void UserTest::shouldSetAndGetStatus() { User sampleUser; QString status = QStringLiteral("myStatus"); QSignalSpy spy(&sampleUser, &User::statusChanged); sampleUser.setStatus(status); QCOMPARE(sampleUser.status(), status); QCOMPARE(spy.count(), 1); status = QStringLiteral("myStatus_NEW"); sampleUser.setStatus(status); QCOMPARE(sampleUser.status(), status); QCOMPARE(spy.count(), 2); status = QStringLiteral("myStatus_NEW"); sampleUser.setStatus(status); QCOMPARE(sampleUser.status(), status); QCOMPARE(spy.count(), 2); } void UserTest::shouldSetAndGetListRooms() { User sampleUser; QStringList roomList; QString room1 = QStringLiteral("myRoom1"); QString room2 = QStringLiteral("myRoom2"); QString room3 = QStringLiteral("myRoom3"); roomList.append(room1); roomList.append(room2); roomList.append(room3); QSignalSpy spy(&sampleUser, &User::listRoomsChanged); sampleUser.setListRooms(roomList); QCOMPARE(sampleUser.listRooms(), roomList); QCOMPARE(spy.count(), 1); } void UserTest::shouldParseUser() { User sampleUser; QJsonObject object; QJsonObject fields; const QString name = QStringLiteral("Newton"); const QString status = QStringLiteral("Newton"); fields.insert(QStringLiteral("name"), QJsonValue(name)); fields.insert(QStringLiteral("status"), QJsonValue(status)); object.insert(QStringLiteral("id"), QJsonValue(QLatin1String("RA151100ECE"))); object.insert(QStringLiteral("fields"), fields); QSignalSpy spyN(&sampleUser, &User::nameChanged); QSignalSpy spyS(&sampleUser, &User::statusChanged); sampleUser.parseUser(object); QCOMPARE(sampleUser.name(), name); QCOMPARE(sampleUser.status(), status); QCOMPARE(spyN.count(), 1); QCOMPARE(spyS.count(), 1); //here signal should not be emmited since we are passing same values sampleUser.parseUser(object); QCOMPARE(spyN.count(), 1); QCOMPARE(spyS.count(), 1); } void UserTest::checkEqualsAndUnequalsOperator() { User sampleuser, sampleuserOther; QString Id = QStringLiteral("RA151100ECE"); QString name = QStringLiteral("Robert Segwick"); QString status = QStringLiteral("myStaus"); sampleuser.setUserId(Id); sampleuser.setName(name); sampleuser.setStatus(status); QVERIFY(sampleuser != sampleuserOther); sampleuserOther.setUserId(Id); sampleuserOther.setName(name); sampleuserOther.setStatus(status); QVERIFY(sampleuser == sampleuserOther); sampleuserOther.setName(QStringLiteral("Robert Segwick_NEW")); QVERIFY(sampleuser != sampleuserOther); } diff --git a/autotests/utilstest.cpp b/autotests/utilstest.cpp index 183d5d33..c4ddcf86 100644 --- a/autotests/utilstest.cpp +++ b/autotests/utilstest.cpp @@ -1,152 +1,152 @@ /* Copyright (c) 2017-2018 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 ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), 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 "utilstest.h" #include "utils.h" #include #include #include #include -QTEST_MAIN(UtilsTest) +QTEST_GUILESS_MAIN(UtilsTest) UtilsTest::UtilsTest(QObject *parent) : QObject(parent) { } void UtilsTest::shouldGenerateServerUrl_data() { QTest::addColumn("input"); QTest::addColumn("output"); QTest::newRow("empty") << QString() << QUrl(); QTest::newRow("http") << QStringLiteral("http://foo.kde.org/") << QUrl(QStringLiteral("ws://foo.kde.org//websocket")); QTest::newRow("http2") << QStringLiteral("http://foo.kde.org") << QUrl(QStringLiteral("ws://foo.kde.org/websocket")); QTest::newRow("https") << QStringLiteral("https://foo.kde.org") << QUrl(QStringLiteral("wss://foo.kde.org/websocket")); QTest::newRow("withoutscheme") << QStringLiteral("foo.kde.org") << QUrl(QStringLiteral("wss://foo.kde.org/websocket")); } void UtilsTest::shouldGenerateServerUrl() { QFETCH(QString, input); QFETCH(QUrl, output); QCOMPARE(Utils::generateServerUrl(input), output); } void UtilsTest::shouldMarkdownToRichText_data() { QTest::addColumn("input"); QTest::addColumn("output"); QTest::newRow("empty") << QString() << QString(); QTest::newRow("testurl") << QStringLiteral("http://www.kde.org http://www.kde.org") << QStringLiteral("http://www.kde.org http://www.kde.org"); QTest::newRow("bold") << QStringLiteral("*bla*") << QStringLiteral("bla"); QTest::newRow("multi star") << QStringLiteral("**bla**") << QStringLiteral("bla"); QTest::newRow("multi star2") << QStringLiteral("***bla***") << QStringLiteral("***bla***"); QTest::newRow("multi star3") << QStringLiteral("***bla ******") << QStringLiteral("***bla ******"); QTest::newRow("Remove
") << QStringLiteral("foo
") << QStringLiteral("foo"); } void UtilsTest::shouldMarkdownToRichText() { QFETCH(QString, input); QFETCH(QString, output); QCOMPARE(Utils::markdownToRichText(input), output); } void UtilsTest::shouldExtractRoomUserFromUrl_data() { QTest::addColumn("input"); QTest::addColumn("output"); QTest::newRow("empty") << QString() << QString(); QTest::newRow("extractuser") << QStringLiteral("ruqola:/user/foo") << QStringLiteral("foo"); QTest::newRow("extractroom") << QStringLiteral("ruqola:/room/foo") << QStringLiteral("foo"); QTest::newRow("extractuser") << QStringLiteral("ruqola:/user2/foo") << QStringLiteral("ruqola:/user2/foo"); } void UtilsTest::shouldExtractRoomUserFromUrl() { QFETCH(QString, input); QFETCH(QString, output); QCOMPARE(Utils::extractRoomUserFromUrl(input), output); } void UtilsTest::shouldExtractGenerateRichText_data() { QTest::addColumn("input"); QTest::addColumn("output"); QTest::newRow("empty") << QString() << QString(); QTest::newRow("word@") << QStringLiteral("@foo") << QStringLiteral("@foo"); QTest::newRow("word@-2") << QStringLiteral("@foo.bla") << QStringLiteral("@foo.bla"); QTest::newRow("word@-3") << QStringLiteral("@foo.bla.bli") << QStringLiteral("@foo.bla.bli"); QTest::newRow("word@-4") << QStringLiteral("@foo.bla.bli dd") << QStringLiteral("@foo.bla.bli dd"); QTest::newRow("word@-5") << QStringLiteral("bla bla 21 @foo.bla.bli dd") << QStringLiteral("bla bla 21 @foo.bla.bli dd"); QTest::newRow("word#") << QStringLiteral("#foo") << QStringLiteral("#foo"); QTest::newRow("word#-2") << QStringLiteral("#foo.bla") << QStringLiteral("#foo.bla"); QTest::newRow("word#-3") << QStringLiteral("#foo.bla.bli") << QStringLiteral("#foo.bla.bli"); QTest::newRow("word#-4") << QStringLiteral("#foo.bla.bli dd") << QStringLiteral("#foo.bla.bli dd"); QTest::newRow("word#-5") << QStringLiteral("bla bla 21 #foo.bla.bli dd") << QStringLiteral("bla bla 21 #foo.bla.bli dd"); } void UtilsTest::shouldExtractGenerateRichText() { QFETCH(QString, input); QFETCH(QString, output); QCOMPARE(Utils::generateRichText(input, {}), output); } void UtilsTest::shouldParseNotification_data() { QTest::addColumn("fileName"); QTest::addColumn("title"); QTest::addColumn("message"); QTest::addColumn("sender"); QTest::newRow("notification1") << QStringLiteral("notification") << QStringLiteral("title") << QStringLiteral("pong") << QStringLiteral("tgrk5CZKgYGiSSqXp"); } void UtilsTest::shouldParseNotification() { QFETCH(QString, fileName); QFETCH(QString, title); QFETCH(QString, message); QFETCH(QString, sender); const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QStringLiteral("/json/") + fileName + QStringLiteral(".json"); QFile f(originalJsonFile); QVERIFY(f.open(QIODevice::ReadOnly)); const QByteArray content = f.readAll(); f.close(); const QJsonDocument doc = QJsonDocument::fromJson(content); const QJsonObject fields = doc.object().value(QLatin1String("fields")).toObject(); const QJsonArray contents = fields.value(QLatin1String("args")).toArray(); QString parseTitle; QString parseMessage; QString parseSender; Utils::parseNotification(contents, parseMessage, parseTitle, parseSender); QCOMPARE(parseMessage, message); QCOMPARE(parseTitle, title); QCOMPARE(parseSender, sender); } diff --git a/src/rocketchatcache.h b/src/rocketchatcache.h index a2a38d76..0ebb9807 100644 --- a/src/rocketchatcache.h +++ b/src/rocketchatcache.h @@ -1,60 +1,62 @@ /* Copyright (c) 2018 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 ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), 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 ROCKETCHATCACHE_H #define ROCKETCHATCACHE_H +#include #include +#include #include "libruqola_private_export.h" class RocketChatAccount; class LIBRUQOLACORE_TESTS_EXPORT RocketChatCache : public QObject { Q_OBJECT public: explicit RocketChatCache(RocketChatAccount *account, QObject *parent = nullptr); ~RocketChatCache(); QString recordingVideoPath(const QString &accountName) const; QString recordingImagePath(const QString &accountName) const; QString avatarUrl(const QString &userId); void insertAvatarUrl(const QString &userId, const QString &url); void downloadFileFromServer(const QString &filename); QUrl attachmentUrl(const QString &url); void downloadFile(const QString &url, const QUrl &localFile); QString avatarUrlFromCacheOnly(const QString &userId); Q_SIGNALS: void fileDownloaded(const QString &filePath, const QUrl &cacheImageUrl); private: Q_DISABLE_COPY(RocketChatCache) bool fileInCache(const QUrl &url); QString fileCachePath(const QUrl &url); void downloadAvatarFromServer(const QString &userId); void slotDataDownloaded(const QByteArray &data, const QUrl &url); QUrl generateDownloadFile(const QString &url); void loadAvatarCache(); QHash mUserAvatarUrl; QSet mFileInDownload; RocketChatAccount *mAccount = nullptr; }; #endif // ROCKETCHATCACHE_H