From 9d32ee95acf65452b3c6a295bba26082e07c1e6b Mon Sep 17 00:00:00 2001 From: kkostiuk <kateryna.kostiuk@savoirfairelinux.com> Date: Tue, 16 Mar 2021 09:29:11 -0400 Subject: [PATCH] misc: remove test Change-Id: I79e67aba4a97d7f81c743ca1664936f98ef1e9b4 --- CMakeLists.txt | 53 -- test/contactmodeltester.cpp | 371 ---------- test/contactmodeltester.h | 141 ---- test/conversationmodeltester.cpp | 928 ------------------------- test/conversationmodeltester.h | 196 ------ test/databasetester.cpp | 232 ------- test/databasetester.h | 99 --- test/datatransfertester.cpp | 157 ----- test/datatransfertester.h | 83 --- test/mocks/callmanager_mock.h | 326 --------- test/mocks/configurationmanager_mock.h | 855 ----------------------- test/mocks/instancemanager_mock.h | 75 -- test/mocks/presencemanager_mock.h | 108 --- test/mocks/videomanager_mock.h | 226 ------ test/newaccountmodeltester.cpp | 54 -- test/newaccountmodeltester.h | 63 -- test/newcallmodeltester.cpp | 109 --- test/newcallmodeltester.h | 82 --- test/newdevicemodeltester.cpp | 197 ------ test/newdevicemodeltester.h | 103 --- test/test_runner.cpp | 41 -- test/utils/waitforsignalhelper.cpp | 121 ---- test/utils/waitforsignalhelper.h | 67 -- 23 files changed, 4687 deletions(-) delete mode 100644 test/contactmodeltester.cpp delete mode 100644 test/contactmodeltester.h delete mode 100644 test/conversationmodeltester.cpp delete mode 100644 test/conversationmodeltester.h delete mode 100644 test/databasetester.cpp delete mode 100644 test/databasetester.h delete mode 100644 test/datatransfertester.cpp delete mode 100644 test/datatransfertester.h delete mode 100644 test/mocks/callmanager_mock.h delete mode 100644 test/mocks/configurationmanager_mock.h delete mode 100644 test/mocks/instancemanager_mock.h delete mode 100644 test/mocks/presencemanager_mock.h delete mode 100644 test/mocks/videomanager_mock.h delete mode 100644 test/newaccountmodeltester.cpp delete mode 100644 test/newaccountmodeltester.h delete mode 100644 test/newcallmodeltester.cpp delete mode 100644 test/newcallmodeltester.h delete mode 100644 test/newdevicemodeltester.cpp delete mode 100644 test/newdevicemodeltester.h delete mode 100644 test/test_runner.cpp delete mode 100644 test/utils/waitforsignalhelper.cpp delete mode 100644 test/utils/waitforsignalhelper.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e690f90..2aabcff7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -746,59 +746,6 @@ ADD_CUSTOM_TARGET(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) -IF((${ENABLE_TEST} MATCHES true)) - ADD_DEFINITIONS(-DENABLE_LIBWRAP=true) # Avoid dbus models - ADD_DEFINITIONS(-DENABLE_TEST=true) # Use mocks - INCLUDE_DIRECTORIES(SYSTEM ${Qt5Core_INCLUDE_DIRS} ) - INCLUDE_DIRECTORIES(SYSTEM ${Qt5Gui_INCLUDE_DIRS} ) - FIND_PACKAGE(Cppunit REQUIRED) - FIND_PACKAGE(Qt5Widgets) - MESSAGE(STATUS "Is cppunit present? " ${CPPUNIT_FOUND}) - # unit testing - IF (CPPUNIT_FOUND) - add_executable(LRCTester - test/mocks/callmanager_mock.h - test/mocks/configurationmanager_mock.h - test/mocks/instancemanager_mock.h - test/mocks/presencemanager_mock.h - test/mocks/videomanager_mock.h - test/test_runner.cpp - test/databasetester.h - test/databasetester.cpp - test/utils/waitforsignalhelper.h - test/utils/waitforsignalhelper.cpp - test/conversationmodeltester.h - test/conversationmodeltester.cpp - test/contactmodeltester.h - test/contactmodeltester.cpp - test/datatransfertester.h - test/datatransfertester.cpp - test/newcallmodeltester.h - test/newcallmodeltester.cpp - test/newaccountmodeltester.h - test/newaccountmodeltester.cpp - ${libringclient_LIB_SRCS} - ${LIB_HEADER_MOC} - ${libringclient_PRIVATE_HDRS} - ) - TARGET_LINK_LIBRARIES(LRCTester - -lcppunit - -lpthread - ${QT_QTCORE_LIBRARY} - Qt5::Gui - Qt5::Sql - ) - - IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - TARGET_LINK_LIBRARIES( LRCTester - -lrt - ) - ENDIF() - enable_testing() - add_test(TEST LRCTester) - ENDIF() -ENDIF() - if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") add_definitions(-DUNICODE -D_UNICODE) remove_definitions(-D_MBCS) diff --git a/test/contactmodeltester.cpp b/test/contactmodeltester.cpp deleted file mode 100644 index eb2d5494..00000000 --- a/test/contactmodeltester.cpp +++ /dev/null @@ -1,371 +0,0 @@ -/* - * Copyright (C) 2017-2020 Savoir-faire Linux Inc. - * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> - * - * 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 3 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#include "contactmodeltester.h" -#include "utils/waitforsignalhelper.h" - -// std -#include <algorithm> - -// Qt -#include <QString> -#include <QMetaType> - -// Lrc -#include <api/newaccountmodel.h> -#include <api/contact.h> -#include <api/contactmodel.h> -#include <api/conversationmodel.h> -#include <dbus/configurationmanager.h> -#include <dbus/presencemanager.h> - -namespace ring -{ -namespace test -{ - -CPPUNIT_TEST_SUITE_REGISTRATION(ContactModelTester); - -ContactModelTester::ContactModelTester() -: lrc_(new lrc::api::Lrc()) -, accInfo_(lrc_->getAccountModel().getAccountInfo("ring1")) -{ -} - -void -ContactModelTester::setUp() -{ -} - -void -ContactModelTester::testBanUnbanContact() -{ - // "bigbadjohn" should not be in "ring1" contacts. - CPPUNIT_ASSERT_THROW(accInfo_.contactModel->getContact("bigbadjohn"), std::out_of_range); - - // Search and add the temporaryContact - auto searchContactSigsCaught = WaitForSignalHelper([&]() { - accInfo_.contactModel->searchContact("bigbadjohn"); - }) - .addSignal("modelUpdated", *accInfo_.contactModel, SIGNAL(modelUpdated(const std::string&, bool))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(searchContactSigsCaught["modelUpdated"], 1); - auto temporaryContact = accInfo_.contactModel->getContact(""); - std::string uri = std::string("bigbadjohn"); - CPPUNIT_ASSERT_EQUAL(temporaryContact.profileInfo.uri, uri); - - auto addContactSigsCaught = WaitForSignalHelper([&]() { - accInfo_.contactModel->addContact(temporaryContact); - }) - .addSignal("contactAdded", *accInfo_.contactModel, SIGNAL(contactAdded(const std::string&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(addContactSigsCaught["contactAdded"], 1); - - // Ban contact - auto banContactSigsCaught = WaitForSignalHelper([&]() { - accInfo_.contactModel->removeContact(uri, true); - }) - .addSignal("filterChanged", *accInfo_.conversationModel, SIGNAL(filterChanged())) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(banContactSigsCaught["filterChanged"], 1); - - auto contactInfo = accInfo_.contactModel->getContact(uri); - CPPUNIT_ASSERT_EQUAL(contactInfo.isBanned, true); - - // Re-ban contact, make sure it isn't a problem - auto reBanContactSigsCaught = WaitForSignalHelper([&]() { - accInfo_.contactModel->removeContact(uri, true); - }) - .addSignal("filterChanged", *accInfo_.conversationModel, SIGNAL(filterChanged())) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(reBanContactSigsCaught["filterChanged"], 1); - - contactInfo = accInfo_.contactModel->getContact(uri); - CPPUNIT_ASSERT_EQUAL(contactInfo.isBanned, true); - - // Unban contact, make sure it worked - auto unbanContactSigsCaught = WaitForSignalHelper([&]() { - contactInfo = accInfo_.contactModel->getContact(uri); - accInfo_.contactModel->addContact(contactInfo); - }) - .addSignal("filterChanged", *accInfo_.conversationModel, SIGNAL(filterChanged())) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(unbanContactSigsCaught["filterChanged"], 1); - - contactInfo = accInfo_.contactModel->getContact(uri); - CPPUNIT_ASSERT_EQUAL(contactInfo.isBanned, false); -} - -void -ContactModelTester::testGetAllContactsForRINGAccount() -{ - auto contacts = accInfo_.contactModel->getAllContacts(); - auto contactsFromDaemon = ConfigurationManager::instance().getContacts("ring1"); - // getAllContacts must return all daemon contacts - int lrcContactsNumber = contacts.size(); - int daemonContactsNumber = contactsFromDaemon.size(); - CPPUNIT_ASSERT_EQUAL(lrcContactsNumber, daemonContactsNumber); - for (const auto& contactUri: contactsFromDaemon) - CPPUNIT_ASSERT(contacts.find(contactUri["id"].toStdString()) != contacts.end()); -} - -void -ContactModelTester::testReceivesPendingRequest() -{ - CPPUNIT_ASSERT_EQUAL(accInfo_.contactModel->hasPendingRequests(), false); - QByteArray payload = "FN:pending0\nPHOTO;ENCODING=BASE64;TYPE=PNG:"; - auto incomingTrustRequestSigsCaught = WaitForSignalHelper([&]() { - ConfigurationManager::instance().emitIncomingTrustRequest("ring1", "pending0", payload, 0); - }) - .addSignal("contactAdded", *accInfo_.contactModel, SIGNAL(contactAdded(const std::string&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(incomingTrustRequestSigsCaught["contactAdded"], 1); - CPPUNIT_ASSERT(accInfo_.contactModel->hasPendingRequests()); - auto contactsFromDaemon = ConfigurationManager::instance().getContacts("ring1"); - auto contacts = accInfo_.contactModel->getAllContacts(); - int lrcContactsNumber = contacts.size(); - int daemonContactsNumber = contactsFromDaemon.size(); - CPPUNIT_ASSERT_EQUAL(lrcContactsNumber, daemonContactsNumber + 1); -} - -void -ContactModelTester::testAddNewRingContact() -{ - // "dummy" should not be in "ring1" contacts. - CPPUNIT_ASSERT_THROW(accInfo_.contactModel->getContact("dummy"), std::out_of_range); - // Search and add the temporaryContact - auto searchContactSigsCaught = WaitForSignalHelper([&]() { - accInfo_.contactModel->searchContact("dummy"); - }) - .addSignal("modelUpdated", *accInfo_.contactModel, SIGNAL(modelUpdated(const std::string&, bool))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(searchContactSigsCaught["modelUpdated"], 1); - auto temporaryContact = accInfo_.contactModel->getContact(""); - CPPUNIT_ASSERT_EQUAL(std::string("dummy"), temporaryContact.profileInfo.uri); - auto addContactSigsCaught = WaitForSignalHelper([&]() { - accInfo_.contactModel->addContact(temporaryContact); - }) - .addSignal("contactAdded", *accInfo_.contactModel, SIGNAL(contactAdded(const std::string&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(addContactSigsCaught["contactAdded"], 1); - CPPUNIT_ASSERT_NO_THROW(accInfo_.contactModel->getContact("dummy")); -} - -void -ContactModelTester::testAddRingURI() -{ - CPPUNIT_ASSERT_THROW(accInfo_.contactModel->getContact("f5a46751671918fe7210a3c31b9a9e4ce081429b"), std::out_of_range); - auto nbContacts = accInfo_.contactModel->getAllContacts().size(); - // Search and add the temporaryContact - auto searchContactSigsCaught = WaitForSignalHelper([&]() { - accInfo_.contactModel->searchContact("ring:f5a46751671918fe7210a3c31b9a9e4ce081429b"); - }) - .addSignal("modelUpdated", *accInfo_.contactModel, SIGNAL(modelUpdated(const std::string&, bool))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(searchContactSigsCaught["modelUpdated"], 1); - auto temporaryContact = accInfo_.contactModel->getContact(""); - CPPUNIT_ASSERT_EQUAL(temporaryContact.profileInfo.uri, std::string("f5a46751671918fe7210a3c31b9a9e4ce081429b")); - auto addContactSigsCaught = WaitForSignalHelper([&]() { - accInfo_.contactModel->addContact(temporaryContact); - }) - .addSignal("contactAdded", *accInfo_.contactModel, SIGNAL(contactAdded(const std::string&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(addContactSigsCaught["contactAdded"], 1); - // "f5a46751671918fe7210a3c31b9a9e4ce081429b" should be in "ring1" contacts. - CPPUNIT_ASSERT_NO_THROW(accInfo_.contactModel->getContact("f5a46751671918fe7210a3c31b9a9e4ce081429b")); - // We should only have added one contact. - CPPUNIT_ASSERT_EQUAL((nbContacts + 1), accInfo_.contactModel->getAllContacts().size()); -} - -void -ContactModelTester::testAddNewSIPContact() -{ - // TODO: fix me - // mock is broken for SIP account (contacts are stored in the database, not in the daemon) - - /*auto& accInfoSip = lrc_->getAccountModel().getAccountInfo("sip0"); - // "sipcontact0" should not be in "ring1" contacts. - CPPUNIT_ASSERT_THROW(accInfoSip.contactModel->getContact("sipcontact0"), std::out_of_range); - // Search and add the temporaryContact - auto searchContactSigsCaught = WaitForSignalHelper([&]() { - accInfoSip.contactModel->searchContact("sipcontact0"); - }) - .addSignal("modelUpdated", *accInfo_.contactModel, SIGNAL(modelUpdated(const std::string&, bool))) - .wait(1000); - //CPPUNIT_ASSERT_EQUAL(searchContactSigsCaught["modelUpdated"] > 0, true); - auto temporaryContact = accInfoSip.contactModel->getContact(""); - CPPUNIT_ASSERT_EQUAL(temporaryContact.profileInfo.uri, std::string("sipcontact0")); - auto addContactSigsCaught = WaitForSignalHelper([&]() { - accInfoSip.contactModel->addContact(temporaryContact); - }) - .addSignal("contactAdded", *accInfo_.contactModel, SIGNAL(contactAdded(const std::string&))) - .wait(1000); - //CPPUNIT_ASSERT_EQUAL(addContactSigsCaught["contactAdded"] > 0, true); - // "sipcontact0" should be "ring1" contacts. - CPPUNIT_ASSERT_NO_THROW(accInfoSip.contactModel->getContact("sipcontact0"));*/ -} - -void -ContactModelTester::testAddAlreadyAddedContact() -{ - auto nbContactsAtBegin = accInfo_.contactModel->getAllContacts().size(); - // "contact1" should be in "ring1" contacts. - CPPUNIT_ASSERT_NO_THROW(accInfo_.contactModel->getContact("contact1")); - auto contact1 = accInfo_.contactModel->getContact("contact1"); - accInfo_.contactModel->addContact(contact1); - // "contact1" should be in "ring1" contacts. - CPPUNIT_ASSERT_NO_THROW(accInfo_.contactModel->getContact("contact1")); - auto nbContactsAtEnd = accInfo_.contactModel->getAllContacts().size(); - CPPUNIT_ASSERT_EQUAL(nbContactsAtBegin, nbContactsAtEnd); -} - -void -ContactModelTester::testReceivesContactPresenceUpdate() -{ - CPPUNIT_ASSERT_NO_THROW(accInfo_.contactModel->getContact("contact1")); - CPPUNIT_ASSERT_EQUAL(accInfo_.contactModel->getContact("contact1").isPresent, false); - auto newBuddyNotificationSigsCaught = WaitForSignalHelper([&]() { - PresenceManager::instance().emitNewBuddyNotification(QString::fromStdString(accInfo_.id), "contact1", true, QString()); - }) - .addSignal("modelUpdated", *accInfo_.contactModel, SIGNAL(modelUpdated(const std::string&, bool))) - .addSignal("modelSorted", *accInfo_.conversationModel, SIGNAL(modelSorted())) - .addSignal("conversationUpdated", *accInfo_.conversationModel, SIGNAL(conversationUpdated(const std::string&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(newBuddyNotificationSigsCaught["modelUpdated"], 1); - CPPUNIT_ASSERT_EQUAL(newBuddyNotificationSigsCaught["modelSorted"], 0); - CPPUNIT_ASSERT_EQUAL(newBuddyNotificationSigsCaught["conversationUpdated"], 1); - CPPUNIT_ASSERT_EQUAL(accInfo_.contactModel->getContact("contact1").isPresent, true); -} - -void -ContactModelTester::testRmRingContact() -{ - int nbContactsAtBegin = accInfo_.contactModel->getAllContacts().size(); - // "contact2" should be in "ring1" contacts. - CPPUNIT_ASSERT_NO_THROW(accInfo_.contactModel->getContact("contact2")); - auto removeContactSigsCaught = WaitForSignalHelper([&]() { - accInfo_.contactModel->removeContact("contact2"); - }) - .addSignal("contactRemoved", *accInfo_.contactModel, SIGNAL(contactRemoved(const std::string&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(removeContactSigsCaught["contactRemoved"], 1); - int nbContactsAtEnd = accInfo_.contactModel->getAllContacts().size(); - CPPUNIT_ASSERT_EQUAL(nbContactsAtEnd, nbContactsAtBegin - 1); - CPPUNIT_ASSERT_THROW(accInfo_.contactModel->getContact("contact2"), std::out_of_range); -} - -void -ContactModelTester::testRmPendingContact() -{ - int nbContactsAtBegin = accInfo_.contactModel->getAllContacts().size(); - CPPUNIT_ASSERT_NO_THROW(accInfo_.contactModel->getContact("pending0")); - auto removeContactSigsCaught = WaitForSignalHelper([&]() { - accInfo_.contactModel->removeContact("pending0"); - }) - .addSignal("contactRemoved", *accInfo_.contactModel, SIGNAL(contactRemoved(const std::string&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(removeContactSigsCaught["contactRemoved"], 1); - int nbContactsAtEnd = accInfo_.contactModel->getAllContacts().size(); - CPPUNIT_ASSERT_EQUAL(nbContactsAtEnd, nbContactsAtBegin - 1); - CPPUNIT_ASSERT_THROW(accInfo_.contactModel->getContact("pending0"), std::out_of_range); -} - -void -ContactModelTester::testRmSIPContact() -{ - // TODO: fix me - // mock is broken for SIP account (contacts are stored in the database, not in the daemon) - - /*auto& accInfoSip = lrc_->getAccountModel().getAccountInfo("sip0"); - // Search and add the temporaryContact - auto searchContactSigsCaught = WaitForSignalHelper([&]() { - accInfoSip.contactModel->searchContact("sipcontact1"); - }) - .addSignal("modelUpdated", *accInfo_.contactModel, SIGNAL(modelUpdated(const std::string&, bool))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(searchContactSigsCaught["modelUpdated"] > 0, true); - auto temporaryContact = accInfoSip.contactModel->getContact(""); - CPPUNIT_ASSERT_EQUAL(temporaryContact.profileInfo.uri, std::string("sipcontact1")); - auto addContactSigsCaught = WaitForSignalHelper([&]() { - accInfoSip.contactModel->addContact(temporaryContact); - }) - .addSignal("contactAdded", *accInfo_.contactModel, SIGNAL(contactAdded(const std::string&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(addContactSigsCaught["contactAdded"] > 0, true); - // "sipcontact1" should be in "ring1" contacts. - CPPUNIT_ASSERT_NO_THROW(accInfoSip.contactModel->getContact("sipcontact1")); - int nbContactsAtBegin = accInfoSip.contactModel->getAllContacts().size(); - // "sipcontact1" should be in "ring1" contacts. - CPPUNIT_ASSERT_NO_THROW(accInfoSip.contactModel->getContact("sipcontact1")); - auto removeContactSigsCaught = WaitForSignalHelper([&]() { - accInfoSip.contactModel->removeContact("sipcontact1"); - }) - .addSignal("contactRemoved", *accInfo_.contactModel, SIGNAL(contactRemoved(const std::string&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(removeContactSigsCaught["contactRemoved"] > 0, true); - int nbContactsAtEnd = accInfoSip.contactModel->getAllContacts().size(); - CPPUNIT_ASSERT_EQUAL(nbContactsAtEnd, nbContactsAtBegin - 1); - // "sipcontact1" should not be in "ring1" contacts. - CPPUNIT_ASSERT_THROW(accInfoSip.contactModel->getContact("sipcontact1"), std::out_of_range);*/ -} - -void -ContactModelTester::testRmTemporaryContact() -{ - int nbContactsAtBegin = accInfo_.contactModel->getAllContacts().size(); - accInfo_.contactModel->removeContact(""); - int nbContactsAtEnd = accInfo_.contactModel->getAllContacts().size(); - CPPUNIT_ASSERT_EQUAL(nbContactsAtEnd, nbContactsAtBegin); -} - -void -ContactModelTester::testCountPendingRequests() -{ - CPPUNIT_ASSERT_NO_THROW(accInfo_.contactModel->getContact("pending0")); - accInfo_.contactModel->removeContact("pending0"); - CPPUNIT_ASSERT_EQUAL(accInfo_.contactModel->hasPendingRequests(), false); - QByteArray payload = "FN:pending0\nPHOTO;ENCODING=BASE64;TYPE=PNG:"; - auto incomingTrustRequestSigsCaught = WaitForSignalHelper([&]() { - ConfigurationManager::instance().emitIncomingTrustRequest("ring1", "pending0", payload, 0); - }) - .addSignal("contactAdded", *accInfo_.contactModel, SIGNAL(contactAdded(const std::string&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(incomingTrustRequestSigsCaught["contactAdded"], 1); - CPPUNIT_ASSERT(accInfo_.contactModel->hasPendingRequests()); - CPPUNIT_ASSERT_EQUAL(accInfo_.contactModel->pendingRequestCount(), 1); -} - -void -ContactModelTester::testCountPendingRequestsWithBlockedContact() -{ - CPPUNIT_ASSERT(accInfo_.contactModel->hasPendingRequests()); - CPPUNIT_ASSERT_EQUAL(accInfo_.contactModel->pendingRequestCount(), 1); - CPPUNIT_ASSERT_NO_THROW(accInfo_.contactModel->getContact("pending0")); - accInfo_.contactModel->removeContact("pending0", true); - CPPUNIT_ASSERT(!accInfo_.contactModel->hasPendingRequests()); - CPPUNIT_ASSERT_EQUAL(accInfo_.contactModel->pendingRequestCount(), 0); -} - -void -ContactModelTester::tearDown() -{ - -} - -} // namespace test -} // namespace ring diff --git a/test/contactmodeltester.h b/test/contactmodeltester.h deleted file mode 100644 index 99d6ae57..00000000 --- a/test/contactmodeltester.h +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (C) 2017-2020 Savoir-faire Linux Inc. - * - * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> - * - * 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 3 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#pragma once - -// cppunit -#include <cppunit/TestFixture.h> -#include <cppunit/extensions/HelperMacros.h> - -// std -#include <memory> - -// Qt -#include <QObject> - -// lrc -#include "api/lrc.h" -#include "api/account.h" - -namespace ring -{ -namespace test -{ - -class ContactModelTester : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(ContactModelTester); - CPPUNIT_TEST(testGetAllContactsForRINGAccount); - CPPUNIT_TEST(testReceivesPendingRequest); - CPPUNIT_TEST(testAddNewRingContact); - CPPUNIT_TEST(testAddRingURI); - CPPUNIT_TEST(testAddNewSIPContact); - CPPUNIT_TEST(testAddAlreadyAddedContact); - CPPUNIT_TEST(testReceivesContactPresenceUpdate); - CPPUNIT_TEST(testRmRingContact); - CPPUNIT_TEST(testRmPendingContact); - CPPUNIT_TEST(testRmSIPContact); - CPPUNIT_TEST(testRmTemporaryContact); - CPPUNIT_TEST(testCountPendingRequests); - CPPUNIT_TEST(testBanUnbanContact); - CPPUNIT_TEST_SUITE_END(); - -public: - ContactModelTester(); - /** - * Method automatically called before each test by CppUnit - */ - void setUp(); - /** - * Get all contacts for account "ring1". - * Contacts are defined in configurationmanager_mock.h - */ - void testGetAllContactsForRINGAccount(); - /** - * Generate a pending request from "pending0" for account "ring1". - * The pending contact should be added. - */ - void testReceivesPendingRequest(); - /** - * Add "dummy" to "ring1" contacts. - * A new ring contact should be added. - */ - void testAddNewRingContact(); - /** - * Test if someone try to add ring:xxxxxxxx works correctly and don't create 2 contacts - */ - void testAddRingURI(); - /** - * Add "sipcontact0" to "sip0" contacts. - * A new sip contact should be added. - */ - void testAddNewSIPContact(); - /** - * re-add "contact1" to "ring1" contacts. - * No new contact should appears. - */ - void testAddAlreadyAddedContact(); - /** - * receive a presence update. - * modelSorted should not be emitted, but conversationUpdated should. - */ - void testReceivesContactPresenceUpdate(); - /** - * Remove "dummy" from "ring1" contacts. - * The contact should be removed. - */ - void testRmRingContact(); - /** - * remove "pending0" from "ring1" contacts. - * The contact should be removed. - */ - void testRmPendingContact(); - /** - * Add and remove "sipcontact1" form "sip0" contacts. - * The contact should be removed. - */ - void testRmSIPContact(); - /** - * Search "dummy" and try to remove it. Should not change anything - */ - void testRmTemporaryContact(); - /** - * Count contact requests - */ - void testCountPendingRequests(); - /** - * Count contact requests when banned contacts exists - */ - void testCountPendingRequestsWithBlockedContact(); - /** - * Try to ban and unban contacts - */ - void testBanUnbanContact(); - /** - * Method automatically called after each test by CppUnit - */ - void tearDown(); - -protected: - std::unique_ptr<lrc::api::Lrc> lrc_; - const lrc::api::account::Info& accInfo_; -}; - -} // namespace test -} // namespace ring diff --git a/test/conversationmodeltester.cpp b/test/conversationmodeltester.cpp deleted file mode 100644 index 59d4938a..00000000 --- a/test/conversationmodeltester.cpp +++ /dev/null @@ -1,928 +0,0 @@ -/* - * Copyright (C) 2017-2020 Savoir-faire Linux Inc. - * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> - * Author: Hugo Lefeuvre <hugo.lefeuvre@savoirfairelinux.com> - * - * 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 3 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#include "conversationmodeltester.h" - -// Qt -#include <QString> -#include "utils/waitforsignalhelper.h" - -// Lrc -#include <api/newaccountmodel.h> -#include <api/conversationmodel.h> -#include <api/contact.h> -#include <api/contactmodel.h> -#include <api/newcallmodel.h> -#include <dbus/configurationmanager.h> -#include <dbus/callmanager.h> -#include <namedirectory.h> - -namespace ring -{ -namespace test -{ - -CPPUNIT_TEST_SUITE_REGISTRATION(ConversationModelTester); - -ConversationModelTester::ConversationModelTester() -: lrc_(new lrc::api::Lrc()) -, accInfo_(lrc_->getAccountModel().getAccountInfo("ring0")) -{ - accInfo_.conversationModel->setFilter(lrc::api::profile::Type::RING); -} - -void -ConversationModelTester::setUp() -{ - -} - -void -ConversationModelTester::testAddValidConversation() -{ - // Dummy should not be in contacts - CPPUNIT_ASSERT(!isAContact("dummy")); - - auto newContactUri = addToContacts("dummy"); - - // Dummy should be in contacts - CPPUNIT_ASSERT(isAContact("dummy")); - - // So, a conversation should exists. - CPPUNIT_ASSERT(hasConversationWithContact("dummy")); -} - -void -ConversationModelTester::testPlaceCallWithBannedContact() -{ - // badguy0 should not be in contacts - CPPUNIT_ASSERT(!isAContact("badguy0")); - - // so, add him to contacts - auto uri = addToContacts("badguy0"); - CPPUNIT_ASSERT(isAContact("badguy0")); - - // and ban him - banContact(uri); - auto contactInfo = accInfo_.contactModel->getContact(uri); - CPPUNIT_ASSERT_EQUAL(contactInfo.isBanned, true); - - // find conversation - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - auto conversation = std::find_if(conversations.begin(), conversations.end(), - [&contactInfo](const lrc::api::conversation::Info& conversation) { - return std::find(conversation.participants.begin(), - conversation.participants.end(), - contactInfo.profileInfo.uri) != conversation.participants.end(); - }); - - CPPUNIT_ASSERT(conversation != conversations.end()); - - // now that badguy0 is banned, calling him should be forbidden - auto baseInteractionsSize = conversation->interactions.size(); - accInfo_.conversationModel->placeCall(conversation->uid); - - // make sure call didn't succeed - CPPUNIT_ASSERT(conversation->callId.empty()); - - // unban badguy0 - unbanContact(uri); - contactInfo = accInfo_.contactModel->getContact(uri); - CPPUNIT_ASSERT_EQUAL(contactInfo.isBanned, false); - - // call again, should succeed - accInfo_.conversationModel->placeCall(conversation->uid); - - // make sure call succeeded - conversations = accInfo_.conversationModel->allFilteredConversations(); - conversation = std::find_if(conversations.begin(), conversations.end(), - [&contactInfo](const lrc::api::conversation::Info& conversation) { - return std::find(conversation.participants.begin(), - conversation.participants.end(), - contactInfo.profileInfo.uri) != conversation.participants.end(); - }); - - CPPUNIT_ASSERT(conversation != conversations.end()); - CPPUNIT_ASSERT(!conversation->callId.empty()); -} - -void -ConversationModelTester::testFilterBannedContact() -{ - // bannedContact should not be in contacts - CPPUNIT_ASSERT(!isAContact("bannedContact")); - CPPUNIT_ASSERT(!isAContact("bannedContacte")); - CPPUNIT_ASSERT(!isAContact("bannedContac")); - - auto uri = addToContacts("bannedContact"); - - // bannedContact now should be in contacts - CPPUNIT_ASSERT(isAContact("bannedContact")); - - // ban bannedContact - banContact(uri); - auto contactInfo = accInfo_.contactModel->getContact(uri); - CPPUNIT_ASSERT_EQUAL(contactInfo.isBanned, true); - - // Make sure bannedContact doesn't appear is non-perfect-match filter searches - // We expect 1 (temporary item) - auto setFilter1SigsCaught = WaitForSignalHelper([&]() { - accInfo_.conversationModel->setFilter("bannedContac"); - }) - .addSignal("modelUpdated", *accInfo_.contactModel, SIGNAL(modelUpdated(const std::string&, bool))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(setFilter1SigsCaught["modelUpdated"], 1); - CPPUNIT_ASSERT_EQUAL(1, (int)accInfo_.conversationModel->allFilteredConversations().size()); - auto isTemporary = accInfo_.conversationModel->filteredConversation(0).participants.front() == ""; - CPPUNIT_ASSERT(isTemporary); - auto setFilter2SigsCaught = WaitForSignalHelper([&]() { - accInfo_.conversationModel->setFilter("bannedContacte"); - }) - .addSignal("modelUpdated", *accInfo_.contactModel, SIGNAL(modelUpdated(const std::string&, bool))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(setFilter2SigsCaught["modelUpdated"], 1); - CPPUNIT_ASSERT_EQUAL(1, (int)accInfo_.conversationModel->allFilteredConversations().size()); - isTemporary = accInfo_.conversationModel->filteredConversation(0).participants.front() == ""; - CPPUNIT_ASSERT(isTemporary); - - // Make sure bannedContact appears in perfect-match filter searches - // We expect 1 (bannedContact) - auto setFilter3SigsCaught = WaitForSignalHelper([&]() { - accInfo_.conversationModel->setFilter("bannedContact"); - }) - .addSignal("modelUpdated", *accInfo_.contactModel, SIGNAL(modelUpdated(const std::string&, bool))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(setFilter3SigsCaught["modelUpdated"], 1); - CPPUNIT_ASSERT_EQUAL(1, (int)accInfo_.conversationModel->allFilteredConversations().size()); - isTemporary = accInfo_.conversationModel->filteredConversation(0).participants.front() == ""; - CPPUNIT_ASSERT(!isTemporary); - - // Unban bannedContact - unbanContact(uri); - contactInfo = accInfo_.contactModel->getContact(uri); - CPPUNIT_ASSERT_EQUAL(contactInfo.isBanned, false); - - // Make sure bannedContact appears is non-perfect-match filter searches - // We expect 2 (temporary item + bannedContact) - auto setFilter4SigsCaught = WaitForSignalHelper([&]() { - accInfo_.conversationModel->setFilter("bannedContac"); - }) - .addSignal("modelUpdated", *accInfo_.contactModel, SIGNAL(modelUpdated(const std::string&, bool))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(setFilter4SigsCaught["modelUpdated"], 1); - CPPUNIT_ASSERT_EQUAL(2, (int)accInfo_.conversationModel->allFilteredConversations().size()); - - // Here we expect 1 (temporary item) - auto setFilter5SigsCaught = WaitForSignalHelper([&]() { - accInfo_.conversationModel->setFilter("bannedContacte"); - }) - .addSignal("modelUpdated", *accInfo_.contactModel, SIGNAL(modelUpdated(const std::string&, bool))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(setFilter5SigsCaught["modelUpdated"], 1); - CPPUNIT_ASSERT_EQUAL(1, (int)accInfo_.conversationModel->allFilteredConversations().size()); - - // Make sure bannedContact appears in perfect-match filter searches - // We expect 1 (bannedContact) - auto setFilter6SigsCaught = WaitForSignalHelper([&]() { - accInfo_.conversationModel->setFilter("bannedContact"); - }) - .addSignal("modelUpdated", *accInfo_.contactModel, SIGNAL(modelUpdated(const std::string&, bool))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(setFilter6SigsCaught["modelUpdated"], 1); - CPPUNIT_ASSERT_EQUAL(1, (int)accInfo_.conversationModel->allFilteredConversations().size()); - - isTemporary = accInfo_.conversationModel->filteredConversation(0).participants.front() == ""; - CPPUNIT_ASSERT(!isTemporary); -} - -void -ConversationModelTester::testSendMessageToBannedContact() -{ - // badguy1 should not be in contacts - CPPUNIT_ASSERT(!isAContact("badguy1")); - - auto uri = addToContacts("badguy1"); - - // badguy1 should now be in contacts - CPPUNIT_ASSERT(isAContact("badguy1")); - - // Ban badguy1 - banContact(uri); - auto contactInfo = accInfo_.contactModel->getContact(uri); - CPPUNIT_ASSERT_EQUAL(contactInfo.isBanned, true); - - // So, now that badguy is banned, sending a message should be forbidden - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - auto conversation = std::find_if(conversations.begin(), conversations.end(), - [&contactInfo](const lrc::api::conversation::Info& conversation) { - return std::find(conversation.participants.begin(), - conversation.participants.end(), - contactInfo.profileInfo.uri) != conversation.participants.end(); - }); - - CPPUNIT_ASSERT(conversation != conversations.end()); - - // Try to send message to banned contact - auto baseInteractionsSize = conversation->interactions.size(); - accInfo_.conversationModel->sendMessage(conversation->uid, "Hello banned !"); - // Make sure message didn't arrive (but contact added is already here) - CPPUNIT_ASSERT_EQUAL((int)baseInteractionsSize, (int)conversation->interactions.size()); - - // Unban badguy1 - unbanContact(uri); - contactInfo = accInfo_.contactModel->getContact(uri); - CPPUNIT_ASSERT_EQUAL(contactInfo.isBanned, false); - - // Now send message again, should succeed - accInfo_.conversationModel->sendMessage(conversation->uid, "Hello unbanned !"); - - // Make sure message arrived - conversations = accInfo_.conversationModel->allFilteredConversations(); - conversation = std::find_if(conversations.begin(), conversations.end(), - [&contactInfo](const lrc::api::conversation::Info& conversation) { - return std::find(conversation.participants.begin(), - conversation.participants.end(), - contactInfo.profileInfo.uri) != conversation.participants.end(); - }); - - CPPUNIT_ASSERT(conversation != conversations.end()); - - CPPUNIT_ASSERT_EQUAL((int)baseInteractionsSize + 1, (int)conversation->interactions.size()); -} - -void -ConversationModelTester::testAddInvalidConversation() -{ - // notAContact should not be in contacts - CPPUNIT_ASSERT(!isAContact("notAContact")); - - // Search contact - auto setFilterSigsCaught = WaitForSignalHelper([&]() { - accInfo_.conversationModel->setFilter("notAContact"); - }) - .addSignal("modelUpdated", *accInfo_.contactModel, SIGNAL(modelUpdated(const std::string&, bool))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(setFilterSigsCaught["modelUpdated"], 1); - - // Temporary item should contain "Searching...notAContact" - // makePermanent should not do anything - auto makePermanentSigsCaught = WaitForSignalHelper([&]() { - accInfo_.conversationModel->makePermanent(""); - }) - .addSignal("contactAdded", ConfigurationManager::instance(), SIGNAL(contactAdded(const QString&, const QString&, bool))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(makePermanentSigsCaught["contactAdded"], 1); - - CPPUNIT_ASSERT(!isAContact("notAContact")); -} - -void -ConversationModelTester::testRmConversation() -{ - // Dummy is already in conversations (added by testAddValidConversation) - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - auto i = std::find_if(conversations.begin(), conversations.end(), - [](const lrc::api::conversation::Info& conversation) { - return std::find(conversation.participants.begin(), - conversation.participants.end(), - "contact0") != conversation.participants.end(); - }); - CPPUNIT_ASSERT(i != conversations.end()); - auto removeConversationSigsCaught = WaitForSignalHelper([&]() { - accInfo_.conversationModel->removeConversation((*i).uid); - }) - .addSignal("conversationRemoved", *accInfo_.conversationModel, SIGNAL(conversationRemoved(const std::string&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(removeConversationSigsCaught["conversationRemoved"], 1); - CPPUNIT_ASSERT(!hasConversationWithContact("contact0")); -} - -void -ConversationModelTester::testFilterAndGetConversations() -{ - // If filter gives nothing, the allFilteredConversations should return a list with size == 1 (temporary item) - auto setFilter1SigsCaught = WaitForSignalHelper([&]() { - accInfo_.conversationModel->setFilter("YouShouldNotPass"); - }) - .addSignal("modelUpdated", *accInfo_.contactModel, SIGNAL(modelUpdated(const std::string&, bool))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(setFilter1SigsCaught["modelUpdated"], 1); - - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT_EQUAL((int)conversations.size(), 1); - - // Count when filter exact name - auto contacts = accInfo_.contactModel->getAllContacts(); - CPPUNIT_ASSERT(contacts.size() != 0); // the daemon should return some contacts - auto contactUri = (*contacts.rbegin()).first; - auto setFilter2SigsCaught = WaitForSignalHelper([&]() { - accInfo_.conversationModel->setFilter(contactUri); - }) - .addSignal("modelUpdated", *accInfo_.contactModel, SIGNAL(modelUpdated(const std::string&, bool))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(setFilter2SigsCaught["modelUpdated"], 1); - conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT_EQUAL((int)conversations.size(), 1); // We should see the contact - auto firstConversation = accInfo_.conversationModel->filteredConversation(0); - CPPUNIT_ASSERT_EQUAL(firstConversation.participants.front(), contactUri); - - // Count all contacts - auto nbContact = 0; - for (const auto& contact: contacts) { - if (contact.first.find("contact") != std::string::npos) { - ++ nbContact; - } - } - - auto setFilter3SigsCaught = WaitForSignalHelper([&]() { - accInfo_.conversationModel->setFilter("contact"); - }) - .addSignal("modelUpdated", *accInfo_.contactModel, SIGNAL(modelUpdated(const std::string&, bool))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(setFilter3SigsCaught["modelUpdated"], 1); - - conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT_EQUAL((int)conversations.size() - 1, nbContact); -} - -void -ConversationModelTester::testSendMessageAndClearHistory() -{ - accInfo_.conversationModel->setFilter(""); - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - auto firstConversation = accInfo_.conversationModel->filteredConversation(0).uid; - - auto sendMessageSigsCaught = WaitForSignalHelper([&]() { - accInfo_.conversationModel->sendMessage(firstConversation, "Hello World!"); - }) - .addSignal("newInteraction", *accInfo_.conversationModel, SIGNAL(newInteraction(const std::string&, uint64_t, const interaction::Info&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(sendMessageSigsCaught["newInteraction"], 1); - - conversations = accInfo_.conversationModel->allFilteredConversations(); - auto conversationExists = false; - for (const auto& conversation: conversations) { - if (conversation.uid == firstConversation) { - conversationExists = true; - // Should contains "Contact Added" + "Hello World!" - CPPUNIT_ASSERT_EQUAL((int)conversation.interactions.size(), 2); - CPPUNIT_ASSERT_EQUAL((*conversation.interactions.rbegin()).second.body, std::string("Hello World!")); - break; - } - } - CPPUNIT_ASSERT(conversationExists); - - // Then test clearHistory - accInfo_.conversationModel->clearHistory(firstConversation); - conversations = accInfo_.conversationModel->allFilteredConversations(); - conversationExists = false; - for (const auto& conversation: conversations) { - if (conversation.uid == firstConversation) { - conversationExists = true; - CPPUNIT_ASSERT_EQUAL((int)conversation.interactions.size(), 0); - break; - } - } - CPPUNIT_ASSERT(conversationExists); -} - -void -ConversationModelTester::testSendMessagesAndClearInteraction() -{ - accInfo_.conversationModel->setFilter(""); - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - auto firstConversation = accInfo_.conversationModel->filteredConversation(0); - auto firstConversationUid = firstConversation.uid; - - // HACK reinit the conversation here (without these line, Hello World! will not be in interactions) - // FIXME - accInfo_.conversationModel->clearHistory(firstConversationUid); - firstConversation = accInfo_.conversationModel->filteredConversation(0); - - // Send 3 messages (will be added to conversation.interactions) - int baseInteractionsSize = firstConversation.interactions.size(); - accInfo_.conversationModel->sendMessage(firstConversationUid, "Hello World!"); - accInfo_.conversationModel->sendMessage(firstConversationUid, "It's been a long time"); - accInfo_.conversationModel->sendMessage(firstConversationUid, "How have you been?"); - - conversations = accInfo_.conversationModel->allFilteredConversations(); - auto conversationExists = false; - uint64_t secondInterId = {}; - for (const auto& conversation: conversations) { - if (conversation.uid == firstConversationUid) { - conversationExists = true; - CPPUNIT_ASSERT_EQUAL((int)conversation.interactions.size(), baseInteractionsSize + 3); - auto it = conversation.interactions.begin(); - it++; - secondInterId = it->first; - break; - } - } - CPPUNIT_ASSERT(conversationExists); - - auto clearInteractionFromConversationSigsCaught = WaitForSignalHelper([&]() { - accInfo_.conversationModel->clearInteractionFromConversation(firstConversationUid, secondInterId); - }) - .addSignal("interactionRemoved", *accInfo_.conversationModel, SIGNAL(interactionRemoved(const std::string&, uint64_t))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(clearInteractionFromConversationSigsCaught["interactionRemoved"], 1); - - conversations = accInfo_.conversationModel->allFilteredConversations(); - conversationExists = false; - for (const auto& conversation: conversations) { - if (conversation.uid == firstConversationUid) { - conversationExists = true; - // Second interaction should be removed - CPPUNIT_ASSERT_EQUAL((int)conversation.interactions.size(), baseInteractionsSize + 2); - for (const auto& interaction: conversation.interactions) - CPPUNIT_ASSERT(interaction.first != secondInterId); - break; - } - } - CPPUNIT_ASSERT(conversationExists); -} - -void -ConversationModelTester::testSendMessagesAndClearLastInteraction() -{ - accInfo_.conversationModel->setFilter(""); - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - auto firstConversation = accInfo_.conversationModel->filteredConversation(0); - auto firstConversationUid = firstConversation.uid; - - // HACK reinit the conversation here (without these line, Hello World! will not be in interactions) - // FIXME - accInfo_.conversationModel->clearHistory(firstConversationUid); - firstConversation = accInfo_.conversationModel->filteredConversation(0); - - // Send 3 messages (will be added to conversation.interactions) - int baseInteractionsSize = firstConversation.interactions.size(); - accInfo_.conversationModel->sendMessage(firstConversationUid, "Hello World!"); - accInfo_.conversationModel->sendMessage(firstConversationUid, "It's been a long time"); - accInfo_.conversationModel->sendMessage(firstConversationUid, "How have you been?"); - - conversations = accInfo_.conversationModel->allFilteredConversations(); - auto conversationExists = false; - uint64_t lastInteractionId = {}; - uint64_t secondInterId = {}; - for (const auto& conversation : conversations) { - if (conversation.uid == firstConversationUid) { - conversationExists = true; - CPPUNIT_ASSERT_EQUAL((int)conversation.interactions.size(), baseInteractionsSize + 3); - auto it = conversation.interactions.rbegin(); - lastInteractionId = it->first; - it++; - secondInterId = it->first; - break; - } - } - CPPUNIT_ASSERT(conversationExists); - - auto clearInteractionFromConversationSigsCaught = WaitForSignalHelper([&]() { - accInfo_.conversationModel->clearInteractionFromConversation(firstConversationUid, lastInteractionId); - }) - .addSignal("interactionRemoved", *accInfo_.conversationModel, SIGNAL(interactionRemoved(const std::string&, uint64_t))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(clearInteractionFromConversationSigsCaught["interactionRemoved"], 1); - - conversations = accInfo_.conversationModel->allFilteredConversations(); - conversationExists = false; - for (const auto& conversation : conversations) { - if (conversation.uid == firstConversationUid) { - conversationExists = true; - // lastMessageUid should be equals to the new last interaction's id. - CPPUNIT_ASSERT_EQUAL(conversation.lastMessageUid, secondInterId); - break; - } - } - CPPUNIT_ASSERT(conversationExists); -} - -void -ConversationModelTester::testRetryToSendTextInteraction() -{ - accInfo_.conversationModel->setFilter(""); - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - auto firstConversation = accInfo_.conversationModel->filteredConversation(0).uid; - accInfo_.conversationModel->sendMessage(firstConversation, "Hello World!"); - accInfo_.conversationModel->sendMessage(firstConversation, "It's been a long time"); - accInfo_.conversationModel->sendMessage(firstConversation, "How have you been?"); - auto conversation = accInfo_.conversationModel->filteredConversation(0); - const auto& interactions = conversation.interactions; - auto it = interactions.begin(); - it++; - auto secondId = it->first; - - // set failure on one interaction - ConfigurationManager::instance().emitAccountMessageStatusChanged( - "ring0", secondId, - conversation.participants.front().c_str(), - static_cast<int>(DRing::Account::MessageStates::FAILURE)); - // retry sending - accInfo_.conversationModel->retryInteraction(conversation.uid, secondId); - // no more failure, no more secondId, and second message should be the last - conversation = accInfo_.conversationModel->filteredConversation(0); - bool hasFailedInteraction = false; - bool hasOldSecondInteraction = false; - bool secondBodyPresent = false; conversation.interactions.begin()->second.body == "It's been a long time"; - for (const auto& interaction : conversation.interactions) { - if (interaction.second.status == lrc::api::interaction::Status::FAILED) - hasFailedInteraction = true; - if (interaction.second.body == "It's been a long time") - secondBodyPresent = true; - if (interaction.first == secondId) - hasOldSecondInteraction = true; - } - CPPUNIT_ASSERT(!hasFailedInteraction); - CPPUNIT_ASSERT(!hasOldSecondInteraction); - CPPUNIT_ASSERT(secondBodyPresent); -} - -void -ConversationModelTester::testRetryToSendFileInteraction() -{ - accInfo_.conversationModel->setFilter(""); - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - auto firstConversation = accInfo_.conversationModel->filteredConversation(0).uid; - // send file - -} - -void -ConversationModelTester::testRetryInvalidInteraction() -{ - accInfo_.conversationModel->setFilter(""); - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - auto firstConversation = accInfo_.conversationModel->filteredConversation(0).uid; - accInfo_.conversationModel->sendMessage(firstConversation, "Hello World!"); - accInfo_.conversationModel->sendMessage(firstConversation, "It's been a long time"); - accInfo_.conversationModel->sendMessage(firstConversation, "How have you been?"); - auto conversation = accInfo_.conversationModel->filteredConversation(0); - const auto& interactions = conversation.interactions; - auto it = interactions.begin(); - it++; - auto secondId = it->first; - - // set failure on one interaction - ConfigurationManager::instance().emitAccountMessageStatusChanged( - "ring0", secondId, - conversation.participants.front().c_str(), - static_cast<int>(DRing::Account::MessageStates::FAILURE)); - auto firstConv = accInfo_.conversationModel->filteredConversation(0); - // retry sending (should do nothing) - accInfo_.conversationModel->retryInteraction(conversation.uid, 1412); - - conversation = accInfo_.conversationModel->filteredConversation(0); - auto bIt = firstConv.interactions.begin(); - auto nIt = conversation.interactions.begin(); - for (size_t i = 0 ; i < firstConv.interactions.size(); ++i) { - CPPUNIT_ASSERT(bIt->second.body == nIt->second.body); - CPPUNIT_ASSERT(bIt->second.status == nIt->second.status); - CPPUNIT_ASSERT(bIt->second.type == nIt->second.type); - bIt++; - nIt++; - } -} - -void -ConversationModelTester::testRetryIncomingInteraction() -{ - // Add a new message for the first conversation - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - auto firstConversation = accInfo_.conversationModel->filteredConversation(0); - QMap<QString, QString> payloads; - payloads["text/plain"] = "You're a monster"; - - auto incomingAccountMessageSigsCaught = WaitForSignalHelper([&]() { - ConfigurationManager::instance().emitIncomingAccountMessage(accInfo_.id.c_str(), firstConversation.participants.front().c_str(), payloads); - }) - .addSignal("newInteraction", *accInfo_.conversationModel, SIGNAL(newInteraction(const std::string&, uint64_t, const interaction::Info&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(incomingAccountMessageSigsCaught["newInteraction"], 1); - - // Retry incoming message - conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - firstConversation = accInfo_.conversationModel->filteredConversation(0); - auto lastInteraction = *firstConversation.interactions.rbegin(); - accInfo_.conversationModel->retryInteraction(firstConversation.uid, lastInteraction.first); - // Should do nothing - firstConversation = accInfo_.conversationModel->filteredConversation(0); - auto newLastInteraction = *firstConversation.interactions.rbegin(); - CPPUNIT_ASSERT(newLastInteraction.second.status == lrc::api::interaction::Status::UNREAD); -} - -void -ConversationModelTester::testRetryContactInteraction() -{ - // Add a new message for the first conversation. The first message will be "contact added" - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - auto firstConversation = accInfo_.conversationModel->filteredConversation(0); - QMap<QString, QString> payloads; - payloads["text/plain"] = "You're a monster"; - - auto incomingAccountMessageSigsCaught = WaitForSignalHelper([&]() { - ConfigurationManager::instance().emitIncomingAccountMessage(accInfo_.id.c_str(), firstConversation.participants.front().c_str(), payloads); - }) - .addSignal("newInteraction", *accInfo_.conversationModel, SIGNAL(newInteraction(const std::string&, uint64_t, const interaction::Info&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(incomingAccountMessageSigsCaught["newInteraction"], 1); - - // The first message is "Contact added" - conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - firstConversation = accInfo_.conversationModel->filteredConversation(0); - auto firstInteraction = *firstConversation.interactions.begin(); - CPPUNIT_ASSERT(firstInteraction.second.type == lrc::api::interaction::Type::CONTACT); - - // Retry contact - accInfo_.conversationModel->retryInteraction(firstConversation.uid, firstInteraction.first); - // Should do nothings - firstConversation = accInfo_.conversationModel->filteredConversation(0); - auto newLastInteraction = *firstConversation.interactions.begin(); - CPPUNIT_ASSERT(newLastInteraction.second.type == lrc::api::interaction::Type::CONTACT); -} - -void -ConversationModelTester::testRetryCallInteraction() -{ - // Place call - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - auto firstConversation = accInfo_.conversationModel->filteredConversation(0); - accInfo_.conversationModel->placeCall(firstConversation.uid); - - auto callStateChangedSigsCaught = WaitForSignalHelper([&]() { - CallManager::instance().emitCallStateChanged(accInfo_.conversationModel->filteredConversation(0).callId.c_str(), "CURRENT", 0); - }) - .addSignal("modelSorted", *accInfo_.conversationModel, SIGNAL(modelSorted())) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(callStateChangedSigsCaught["modelSorted"], 1); - - // Last interaction is a CALL - conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - firstConversation = accInfo_.conversationModel->filteredConversation(0); - auto lastInteraction = *firstConversation.interactions.rbegin(); - CPPUNIT_ASSERT(lastInteraction.second.type == lrc::api::interaction::Type::CALL); - // Retry, should do nothing - accInfo_.conversationModel->retryInteraction(firstConversation.uid, lastInteraction.first); - - // Should do nothing - firstConversation = accInfo_.conversationModel->filteredConversation(0); - auto newLastInteraction = *firstConversation.interactions.rbegin(); - CPPUNIT_ASSERT(newLastInteraction.second.type == lrc::api::interaction::Type::CALL); -} - - -void -ConversationModelTester::testReceiveMessageAndSetRead() -{ - // Add a new message for the first conversation - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - auto firstConversation = accInfo_.conversationModel->filteredConversation(0); - QMap<QString, QString> payloads; - payloads["text/plain"] = "This is not a message"; - - auto incomingAccountMessageSigsCaught = WaitForSignalHelper([&]() { - ConfigurationManager::instance().emitIncomingAccountMessage(accInfo_.id.c_str(), firstConversation.participants.front().c_str(), payloads); - }) - .addSignal("newInteraction", *accInfo_.conversationModel, SIGNAL(newInteraction(const std::string&, uint64_t, const interaction::Info&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(incomingAccountMessageSigsCaught["newInteraction"], 1); - - // This message should be unread - conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - firstConversation = accInfo_.conversationModel->filteredConversation(0); - auto lastInteraction = *firstConversation.interactions.rbegin(); - CPPUNIT_ASSERT(lastInteraction.second.status == lrc::api::interaction::Status::UNREAD); - accInfo_.conversationModel->setInteractionRead(firstConversation.uid, lastInteraction.first); - - // Now, the interaction should be READ - conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - firstConversation = accInfo_.conversationModel->filteredConversation(0); - CPPUNIT_ASSERT((*firstConversation.interactions.rbegin()).second.status == lrc::api::interaction::Status::READ); -} - -void -ConversationModelTester::testPlaceCall() -{ - // Get first conversation and make sure it is empty - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - auto firstConversation = accInfo_.conversationModel->filteredConversation(0); - CPPUNIT_ASSERT(firstConversation.callId.empty()); - - // Place a call - accInfo_.conversationModel->placeCall(firstConversation.uid); - - // Get first conversation again and make sure it isn't empty anymore (call succeeded) - conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - auto newConv = accInfo_.conversationModel->filteredConversation(0); - CPPUNIT_ASSERT_EQUAL(newConv.uid, firstConversation.uid); - CPPUNIT_ASSERT(!newConv.callId.empty()); -} - -void -ConversationModelTester::testPlaceAudioOnlyCall() -{ - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - auto firstConversation = accInfo_.conversationModel->filteredConversation(0); - CPPUNIT_ASSERT(firstConversation.callId.empty()); - accInfo_.conversationModel->placeAudioOnlyCall(firstConversation.uid); - conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - auto newConv = accInfo_.conversationModel->filteredConversation(0); - CPPUNIT_ASSERT_EQUAL(newConv.uid, firstConversation.uid); - CPPUNIT_ASSERT(!newConv.callId.empty()); -} - -void -ConversationModelTester::testCreateConference() -{ - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() > 1); - auto firstConversation = accInfo_.conversationModel->filteredConversation(0); - CPPUNIT_ASSERT(firstConversation.callId.empty()); - accInfo_.conversationModel->placeCall(firstConversation.uid); - auto secondConversation = accInfo_.conversationModel->filteredConversation(1); - CPPUNIT_ASSERT(secondConversation.callId.empty()); - accInfo_.conversationModel->placeCall(secondConversation.uid); - - // Calls should be dialogs - conversations = accInfo_.conversationModel->allFilteredConversations(); - firstConversation = accInfo_.conversationModel->filteredConversation(0); - auto firstCall = accInfo_.callModel->getCall(firstConversation.callId); - CPPUNIT_ASSERT(firstCall.type == lrc::api::call::Type::DIALOG); - secondConversation = accInfo_.conversationModel->filteredConversation(1); - auto secondCall = accInfo_.callModel->getCall(secondConversation.callId); - CPPUNIT_ASSERT(secondCall.type == lrc::api::call::Type::DIALOG); - - // Create conference - auto joinConversationsSigsCaught = WaitForSignalHelper([&]() { - accInfo_.conversationModel->joinConversations(firstConversation.uid, secondConversation.uid); - }) - .addSignal("callAddedToConference", *accInfo_.callModel, SIGNAL(callAddedToConference(const std::string&, const std::string&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(joinConversationsSigsCaught["callAddedToConference"], 1); - - conversations = accInfo_.conversationModel->allFilteredConversations(); - firstConversation = accInfo_.conversationModel->filteredConversation(0); - firstCall = accInfo_.callModel->getCall(firstConversation.confId); - CPPUNIT_ASSERT(firstCall.type == lrc::api::call::Type::CONFERENCE); - secondConversation = accInfo_.conversationModel->filteredConversation(1); - secondCall = accInfo_.callModel->getCall(secondConversation.confId); - CPPUNIT_ASSERT(secondCall.type == lrc::api::call::Type::CONFERENCE); - CPPUNIT_ASSERT(secondConversation.confId == firstConversation.confId); - -} - -void -ConversationModelTester::testClearUnreadInteractions() -{ - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - auto firstConversation = accInfo_.conversationModel->filteredConversation(0); - auto sender = firstConversation.participants.front().c_str(); - - QMap<QString, QString> payloads; - - // Send a first message - payloads["text/plain"] = "This is not a message"; - auto incomingAccountMessageSigsCaught = WaitForSignalHelper([&]() { - ConfigurationManager::instance().emitIncomingAccountMessage(accInfo_.id.c_str(), sender, payloads); - }) - .addSignal("newInteraction", *accInfo_.conversationModel, SIGNAL(newInteraction(const std::string&, uint64_t, const interaction::Info&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(incomingAccountMessageSigsCaught["newInteraction"], 1); - - // Send a second message - auto incomingAccountMessage2SigsCaught = WaitForSignalHelper([&]() { - ConfigurationManager::instance().emitIncomingAccountMessage(accInfo_.id.c_str(), sender, payloads); - }) - .addSignal("newInteraction", *accInfo_.conversationModel, SIGNAL(newInteraction(const std::string&, uint64_t, const interaction::Info&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(incomingAccountMessage2SigsCaught["newInteraction"], 1); - - // Make sure both messages are unread - firstConversation = accInfo_.conversationModel->filteredConversation(0); - auto interactions = firstConversation.interactions.rbegin(); - CPPUNIT_ASSERT(interactions->second.status == lrc::api::interaction::Status::UNREAD); - CPPUNIT_ASSERT((++interactions)->second.status == lrc::api::interaction::Status::UNREAD); - - // Clear conversation of unread interactions - auto clearUnreadInteractionsSigsCaught = WaitForSignalHelper([&]() { - accInfo_.conversationModel->clearUnreadInteractions(firstConversation.uid); - }) - .addSignal("conversationUpdated", *accInfo_.conversationModel, SIGNAL(conversationUpdated(const std::string&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(clearUnreadInteractionsSigsCaught["conversationUpdated"], 1); - - // Now make sure both messages are read - firstConversation = accInfo_.conversationModel->filteredConversation(0); - interactions = firstConversation.interactions.rbegin(); - CPPUNIT_ASSERT(interactions->second.status == lrc::api::interaction::Status::READ); - CPPUNIT_ASSERT((++interactions)->second.status == lrc::api::interaction::Status::READ); -} - -void -ConversationModelTester::tearDown() -{ -} - -bool -ConversationModelTester::hasConversationWithContact(const std::string& uri) -{ - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - auto i = std::find_if(conversations.begin(), conversations.end(), - [&uri](const lrc::api::conversation::Info& conversation) { - return std::find(conversation.participants.begin(), - conversation.participants.end(), - uri) != conversation.participants.end(); - }); - return i != conversations.end(); -} - -void -ConversationModelTester::banContact(const std::string& uri) -{ - auto banContactSigsCaught = WaitForSignalHelper([&]() { - accInfo_.contactModel->removeContact(uri, true); - }) - .addSignal("filterChanged", *accInfo_.conversationModel, SIGNAL(filterChanged())) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(banContactSigsCaught["filterChanged"], 1); -} - -void -ConversationModelTester::unbanContact(const std::string& uri) -{ - auto contactInfo = accInfo_.contactModel->getContact(uri); - auto unbanContactSigsCaught = WaitForSignalHelper([&]() { - accInfo_.contactModel->addContact(contactInfo); - }) - .addSignal("filterChanged", *accInfo_.conversationModel, SIGNAL(filterChanged())) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(unbanContactSigsCaught["filterChanged"], 1); -} - -bool -ConversationModelTester::isAContact(const std::string& uri) -{ - return !accInfo_.contactModel->getContactProfileId(uri).empty(); -} - -std::string -ConversationModelTester::addToContacts(const std::string& username) -{ - // Search contact - auto setFilterSigsCaught = WaitForSignalHelper([&]() { - accInfo_.conversationModel->setFilter(username); - }) - .addSignal("modelUpdated", *accInfo_.contactModel, SIGNAL(modelUpdated(const std::string&, bool))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(setFilterSigsCaught["modelUpdated"], 1); - - // Add to contacts - auto uri = accInfo_.conversationModel->owner.contactModel->getContact("").profileInfo.uri; - auto makePermanentSigsCaught = WaitForSignalHelper([&]() { - accInfo_.conversationModel->makePermanent(uri); - }) - .addSignal("contactAdded", ConfigurationManager::instance(), SIGNAL(contactAdded(const QString&, const QString&, bool))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(makePermanentSigsCaught["contactAdded"], 1); - - return uri; -} - -} // namespace test -} // namespace ring diff --git a/test/conversationmodeltester.h b/test/conversationmodeltester.h deleted file mode 100644 index 9506942a..00000000 --- a/test/conversationmodeltester.h +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright (C) 2017-2020 Savoir-faire Linux Inc. - * - * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> - * - * 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 3 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#pragma once - -// cppunit -#include <cppunit/TestFixture.h> -#include <cppunit/extensions/HelperMacros.h> - -// std -#include <memory> - -// Qt -#include <QObject> - -// lrc -#include "api/lrc.h" -#include "api/account.h" - -namespace ring -{ -namespace test -{ - -class ConversationModelTester : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(ConversationModelTester); - CPPUNIT_TEST(testAddValidConversation); - CPPUNIT_TEST(testAddInvalidConversation); - CPPUNIT_TEST(testRmConversation); - CPPUNIT_TEST(testFilterAndGetConversations); - CPPUNIT_TEST(testSendMessageAndClearHistory); - CPPUNIT_TEST(testSendMessagesAndClearInteraction); - CPPUNIT_TEST(testSendMessagesAndClearLastInteraction); - CPPUNIT_TEST(testRetryToSendTextInteraction); - CPPUNIT_TEST(testRetryToSendFileInteraction); - CPPUNIT_TEST(testRetryInvalidInteraction); - CPPUNIT_TEST(testRetryIncomingInteraction); - CPPUNIT_TEST(testRetryContactInteraction); - CPPUNIT_TEST(testRetryCallInteraction); - CPPUNIT_TEST(testReceiveMessageAndSetRead); - CPPUNIT_TEST(testPlaceCall); - CPPUNIT_TEST(testCreateConference); - CPPUNIT_TEST(testPlaceAudioOnlyCall); - CPPUNIT_TEST(testClearUnreadInteractions); - CPPUNIT_TEST(testSendMessageToBannedContact); - CPPUNIT_TEST(testFilterBannedContact); - CPPUNIT_TEST(testPlaceCallWithBannedContact); - CPPUNIT_TEST_SUITE_END(); - -public: - ConversationModelTester(); - /** - * Method automatically called before each test by CppUnit - */ - void setUp(); - /** - * Add a new conversation between account "ring0" and "dummy" - */ - void testAddValidConversation(); - /** - * Try to add a new conversation between account "ring0" and "notAContact" - * but "notAContact" is not a ringId of another user, so we can't create a - * new conversation with "notAContact". - */ - void testAddInvalidConversation(); - /** - * Remove the conversation between account "ring0" and "contact0" - * NOTE: "contact0" is already a contact for "ring0", - * cf. mock/configurationmanager_mock - */ - void testRmConversation(); - /** - * Test the behavior of setFilter(query) with different queries. - */ - void testFilterAndGetConversations(); - /** - * Send "Hello World!" to the first conversation and clear the history - */ - void testSendMessageAndClearHistory(); - /** - * Make sure it is not possible to send a message to a banned contact - */ - void testSendMessageToBannedContact(); - /** - * Make sure banned contacts only appear in perfect-match filter searches. - */ - void testFilterBannedContact(); - /** - * Send multiple messages to the first conversation and clear one interaction - */ - void testSendMessagesAndClearInteraction(); - /** - * Send multiple messages to the first conversation and clear the last interaction - * lastMessageUid should be updated - */ - void testSendMessagesAndClearLastInteraction(); - /** - * Send an old failed outgoing text interaction - */ - void testRetryToSendTextInteraction(); - /** - * Send an old failed outgoing file interaction - */ - void testRetryToSendFileInteraction(); - /** - * Retry an unexistant interaction - */ - void testRetryInvalidInteraction(); - /** - * Retry an incoming interaction - */ - void testRetryIncomingInteraction(); - /** - * Retry a contact interaction - */ - void testRetryContactInteraction(); - /** - * Retry a call interaction - */ - void testRetryCallInteraction(); - /** - * Receives a message from a conversation and set this message READ - */ - void testReceiveMessageAndSetRead(); - /** - * Call the first conversation - */ - void testPlaceCall(); - /** - * Make sure it is not possible to call a banned contact - */ - void testPlaceCallWithBannedContact(); - /** - * Start and audio-only call with the first conversation - */ - void testPlaceAudioOnlyCall(); - /** - * Create a conference with the two first conversations - */ - void testCreateConference(); - /** - * Clear any unread text messages from a conversation - */ - void testClearUnreadInteractions(); - /** - * Method automatically called after each test by CppUnit - */ - void tearDown(); - -protected: - std::unique_ptr<lrc::api::Lrc> lrc_; - const lrc::api::account::Info& accInfo_; - - // Helpers - - /** - * Ban contact with passed uri - */ - void banContact(const std::string& uri); - /** - * Unban contact with passed uri - */ - void unbanContact(const std::string& uri); - /** - * Return whether passed uri already maps to a contact or not - */ - bool isAContact(const std::string& uri); - /** - * Add passed usename to contacts and return its uri - */ - std::string addToContacts(const std::string& username); - /** - * Return whether a converation with passed contact uri exists or not - */ - bool hasConversationWithContact(const std::string& uri); -}; - -} // namespace test -} // namespace ring diff --git a/test/databasetester.cpp b/test/databasetester.cpp deleted file mode 100644 index 935d7040..00000000 --- a/test/databasetester.cpp +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright (C) 2017-2020 Savoir-faire Linux Inc. - * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> - * - * 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 3 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#include "databasetester.h" - -// std -#include <cstdio> -#include <map> - -// Qt -#include <QString> - -// Lrc -#include "dbus/configurationmanager.h" - -namespace lrc -{ -namespace test -{ - -CPPUNIT_TEST_SUITE_REGISTRATION(DatabaseTester); - -void -DatabaseTester::setUp() -{ - // Remove ring.db - dbPath_ = "./ring.db"; - std::remove(dbPath_.c_str()); - // Init database - database_ = std::unique_ptr<lrc::Database>(new lrc::Database()); -} - -void -DatabaseTester::tearDown() -{ - // Remove ring.db - std::remove(dbPath_.c_str()); -} - -void -DatabaseTester::testInsertAndSelectCorrectValue() -{ - // Insert a new profile - auto table = "profiles"; - auto bindsCol = std::map<std::string, std::string>(); - bindsCol.emplace(":uri", "uri"); - bindsCol.emplace(":alias", "alias"); - bindsCol.emplace(":photo", "photo"); - bindsCol.emplace(":type", "type"); - bindsCol.emplace(":status", "status"); - auto bindsSet = std::map<std::string, std::string>(); - bindsSet.emplace(":uri", "glados"); - bindsSet.emplace(":alias", "GLaDOs"); - bindsSet.emplace(":photo", ""); - bindsSet.emplace(":type", "0"); - bindsSet.emplace(":status", "0"); - auto result = database_->insertInto(table, bindsCol, bindsSet); - // The query should succeed - CPPUNIT_ASSERT(result != -1); - - auto col = "alias"; - auto whereCond = "uri=:uri"; - auto bindsWhere = std::map<std::string, std::string>(); - bindsWhere.emplace(":uri", "glados"); - auto selectResult = database_->select(col, table, whereCond, bindsWhere); - CPPUNIT_ASSERT(selectResult.nbrOfCols == 1); - CPPUNIT_ASSERT(selectResult.payloads[0] == "GLaDOs"); -} - -void -DatabaseTester::testInsertIncorrectFail() -{ - // Insert a new profile - try { - auto table = "profiles"; - auto bindsCol = std::map<std::string, std::string>(); - bindsCol.emplace(":NOTACOL", "NotACol"); - bindsCol.emplace(":alias", "alias"); - bindsCol.emplace(":photo", "photo"); - bindsCol.emplace(":type", "type"); - bindsCol.emplace(":status", "status"); - auto bindsSet = std::map<std::string, std::string>(); - bindsSet.emplace(":uri", "0000"); - bindsSet.emplace(":alias", "ALIAS"); - bindsSet.emplace(":photo", "0000"); - bindsSet.emplace(":type", "0"); - bindsSet.emplace(":status", "0"); - database_->insertInto(table, bindsCol, bindsSet); - CPPUNIT_ASSERT_EQUAL(0, 1); - } catch (lrc::Database::QueryInsertError& e) { - CPPUNIT_ASSERT(e.details().size() > 0); - } -} - -void -DatabaseTester::testSelectInexistantValue() -{ - // Insert a new profile - auto table = "profiles"; - auto col = "alias"; - auto whereCond = "uri=:uri"; - auto bindsWhere = std::map<std::string, std::string>(); - bindsWhere.emplace(":uri", "schrödinger"); - auto selectResult = database_->select(col, table, whereCond, bindsWhere); - CPPUNIT_ASSERT(selectResult.nbrOfCols == 1); - CPPUNIT_ASSERT(selectResult.payloads.size() == 0); -} - -void -DatabaseTester::testUpdateCorrectValue() -{ - // Insert a new profile - auto table = "profiles"; - auto bindsCol = std::map<std::string, std::string>(); - bindsCol.emplace(":uri", "uri"); - bindsCol.emplace(":alias", "alias"); - bindsCol.emplace(":photo", "photo"); - bindsCol.emplace(":type", "type"); - bindsCol.emplace(":status", "status"); - auto bindsSet = std::map<std::string, std::string>(); - bindsSet.emplace(":uri", "weasley"); - bindsSet.emplace(":alias", "good core"); - bindsSet.emplace(":photo", ""); - bindsSet.emplace(":type", "0"); - bindsSet.emplace(":status", "0"); - auto result = database_->insertInto(table, bindsCol, bindsSet); - // The query should succeed - CPPUNIT_ASSERT(result != -1); - - // Update value - auto col = "alias=:alias"; - bindsCol = std::map<std::string, std::string>(); - bindsCol.emplace(":alias", "bad core"); - auto whereCond = "uri=:uri"; - auto bindsWhere = std::map<std::string, std::string>(); - bindsWhere.emplace(":uri", "weasley"); - database_->update(table, col, bindsCol, whereCond, bindsWhere); - - // And select it - col = "alias"; - auto selectResult = database_->select(col, table, whereCond, bindsWhere); - CPPUNIT_ASSERT(selectResult.nbrOfCols == 1); - CPPUNIT_ASSERT(selectResult.payloads[0] == "bad core"); -} - -void -DatabaseTester::testUpdateInexistantValue() -{ - // Update an incorrect profile - auto table = "profiles"; - auto bindsCol = std::map<std::string, std::string>(); - bindsCol.emplace(":alias", "schrödinger"); - auto whereCond = "uri=:uri"; - auto bindsWhere = std::map<std::string, std::string>(); - bindsWhere.emplace(":uri", "schrödinger"); - database_->update(table, "alias=:alias", bindsCol, whereCond, bindsWhere); - // And try to find this profile - auto selectResult = database_->select("alias", table, whereCond, bindsWhere); - CPPUNIT_ASSERT(selectResult.nbrOfCols == 1); - CPPUNIT_ASSERT(selectResult.payloads.size() == 0); -} - -void -DatabaseTester::testDeleteCorrectValue() -{ - // Insert a new profile - auto table = "profiles"; - auto bindsCol = std::map<std::string, std::string>(); - bindsCol.emplace(":uri", "uri"); - bindsCol.emplace(":alias", "alias"); - bindsCol.emplace(":photo", "photo"); - bindsCol.emplace(":type", "type"); - bindsCol.emplace(":status", "status"); - auto bindsSet = std::map<std::string, std::string>(); - bindsSet.emplace(":uri", "pbody"); - bindsSet.emplace(":alias", "P-Body"); - bindsSet.emplace(":photo", ""); - bindsSet.emplace(":type", "0"); - bindsSet.emplace(":status", "0"); - auto result = database_->insertInto(table, bindsCol, bindsSet); - // The query should succeed - CPPUNIT_ASSERT(result != -1); - - // Delete the profile - auto whereCond = "uri=:uri"; - auto bindsWhere = std::map<std::string, std::string>(); - bindsWhere.emplace(":uri", "pbody"); - database_->deleteFrom(table, whereCond, bindsWhere); - - // And try to find this profile - auto col = "alias"; - auto selectResult = database_->select(col, table, whereCond, bindsWhere); - CPPUNIT_ASSERT(selectResult.nbrOfCols == 1); - CPPUNIT_ASSERT(selectResult.payloads.size() == 0); -} - -void -DatabaseTester::testDeleteInexistantValue() -{ - auto table = "profiles"; - auto whereCond = "uri=:uri"; - auto bindsWhere = std::map<std::string, std::string>(); - bindsWhere.emplace(":uri", "schrödinger"); - database_->deleteFrom(table, whereCond, bindsWhere); - // Should not throw anything if fails -} - -void -DatabaseTester::testCountUnreadMessages() -{ - auto table = "profiles"; - auto count = database_->count("uri", table, "status=:status", {{":status", "0"}}); - CPPUNIT_ASSERT(count == 1); -} - -} // namespace test -} // namespace ring diff --git a/test/databasetester.h b/test/databasetester.h deleted file mode 100644 index 3ebce4e3..00000000 --- a/test/databasetester.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2017-2020 Savoir-faire Linux Inc. - * - * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> - * - * 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 3 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#pragma once - -// cppunit -#include <cppunit/TestFixture.h> -#include <cppunit/extensions/HelperMacros.h> - -// std -#include <memory> - -// lrc -#include "database.h" - -namespace lrc -{ -namespace test -{ - -class DatabaseTester : public CppUnit::TestFixture { - - CPPUNIT_TEST_SUITE(DatabaseTester); - CPPUNIT_TEST(testInsertAndSelectCorrectValue); - CPPUNIT_TEST(testCountUnreadMessages); - CPPUNIT_TEST(testInsertIncorrectFail); - CPPUNIT_TEST(testSelectInexistantValue); - CPPUNIT_TEST(testUpdateCorrectValue); - CPPUNIT_TEST(testUpdateInexistantValue); - CPPUNIT_TEST(testDeleteCorrectValue); - CPPUNIT_TEST(testDeleteInexistantValue); - CPPUNIT_TEST_SUITE_END(); - -public: - /** - * Method automatically called before each test by CppUnit - */ - void setUp(); - /** - * Method automatically called after each test CppUnit - */ - void tearDown(); - /** - * Insert a correct value and try to retrieve it - */ - void testInsertAndSelectCorrectValue(); - /** - * Insert incorrect value - */ - void testInsertIncorrectFail(); - /** - * Select inexistant value - */ - void testSelectInexistantValue(); - /** - * Update value - */ - void testUpdateCorrectValue(); - /** - * Update inexistant value - */ - void testUpdateInexistantValue(); - /** - * Delete value from the database - */ - void testDeleteCorrectValue(); - /** - * Delete inexistant value in the database - */ - void testDeleteInexistantValue(); - /** - * Count the number of unread messages. - */ - void testCountUnreadMessages(); - -protected: - std::unique_ptr<lrc::Database> database_; - std::string dbPath_; -}; - -} // namespace test -} // namespace lrc diff --git a/test/datatransfertester.cpp b/test/datatransfertester.cpp deleted file mode 100644 index 35e42c8e..00000000 --- a/test/datatransfertester.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (C) 2017-2020 Savoir-faire Linux Inc. - * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> - * - * 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 3 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#include "datatransfertester.h" - -// std -#include <algorithm> - -// Qt -#include <QString> -#include "utils/waitforsignalhelper.h" - -// Lrc -#include <api/newaccountmodel.h> -#include <api/contact.h> -#include <api/conversationmodel.h> -#include <dbus/configurationmanager.h> -#include <api/datatransfer.h> -#include <api/datatransfermodel.h> -#include <datatransfer_interface.h> - -namespace ring -{ -namespace test -{ - -CPPUNIT_TEST_SUITE_REGISTRATION(DataTransferTester); - -DataTransferTester::DataTransferTester() -: lrc_(new lrc::api::Lrc()) -, accInfo_(lrc_->getAccountModel().getAccountInfo("ring0")) -{ - -} - -void -DataTransferTester::setUp() -{ - -} - -void -DataTransferTester::testReceivesMusic() -{ - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - auto firstConversation = accInfo_.conversationModel->filteredConversation(0); - auto intBaseSize = accInfo_.conversationModel->filteredConversation(0).interactions.size(); - - lrc::api::datatransfer::Info info { - "1", lrc::api::datatransfer::Status::on_connection, 0, 10 * 1024 * 1024, 0, - "./", "glados.mp3", "ring0", firstConversation.participants[0] - }; - ConfigurationManager::instance().setDataTransferInfo(1, info); - ConfigurationManager::instance().emitDataTransferEvent(1, DRing::DataTransferEventCode::created); - auto intFinalSize = accInfo_.conversationModel->filteredConversation(0).interactions.size(); - CPPUNIT_ASSERT_EQUAL(intFinalSize, intBaseSize + 1); - // base conversation + file transfer -} - -void -DataTransferTester::testReceivesImage5MbNoPref() -{ - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - auto firstConversation = accInfo_.conversationModel->filteredConversation(0); - lrc::api::datatransfer::Info info { - "1", lrc::api::datatransfer::Status::on_connection, 0, 5 * 1024 * 1024, 0, - "./", "glados.jpg", "ring0", firstConversation.participants[0] - }; - ConfigurationManager::instance().setDataTransferInfo(2, info); - - auto dataTransferEventSigsCaught = WaitForSignalHelper([&]() { - ConfigurationManager::instance().emitDataTransferEvent(2, DRing::DataTransferEventCode::created); - ConfigurationManager::instance().emitDataTransferEvent(2, DRing::DataTransferEventCode::wait_host_acceptance); - }) - .addSignal("interactionStatusUpdated", *accInfo_.conversationModel, SIGNAL(interactionStatusUpdated(const std::string&, uint64_t, const api::interaction::Info&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(dataTransferEventSigsCaught["interactionStatusUpdated"], 1); - - auto lastIt = accInfo_.conversationModel->filteredConversation(0).interactions.rbegin()->second; - CPPUNIT_ASSERT(lastIt.status == lrc::api::interaction::Status::TRANSFER_AWAITING_HOST); -} - -void -DataTransferTester::testReceivesImage5Mb() -{ - lrc_->getDataTransferModel().downloadDirectory = "/"; - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - auto firstConversation = accInfo_.conversationModel->filteredConversation(0); - lrc::api::datatransfer::Info info { - "1", lrc::api::datatransfer::Status::on_connection, 0, 5 * 1024 * 1024, 0, - "./", "glados.jpg", "ring0", firstConversation.participants[0] - }; - ConfigurationManager::instance().setDataTransferInfo(3, info); - - auto dataTransferEventSigsCaught = WaitForSignalHelper([&]() { - ConfigurationManager::instance().emitDataTransferEvent(3, DRing::DataTransferEventCode::created); - ConfigurationManager::instance().emitDataTransferEvent(3, DRing::DataTransferEventCode::wait_host_acceptance); - }) - .addSignal("interactionStatusUpdated", *accInfo_.conversationModel, SIGNAL(interactionStatusUpdated(const std::string&, uint64_t, const api::interaction::Info&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(dataTransferEventSigsCaught["interactionStatusUpdated"], 1); - - auto lastIt = accInfo_.conversationModel->filteredConversation(0).interactions.rbegin()->second; - CPPUNIT_ASSERT(lastIt.status == lrc::api::interaction::Status::TRANSFER_ACCEPTED); -} - -void -DataTransferTester::testReceivesImage50Mb() -{ - lrc_->getDataTransferModel().downloadDirectory = "/"; - auto conversations = accInfo_.conversationModel->allFilteredConversations(); - CPPUNIT_ASSERT(conversations.size() != 0); - auto firstConversation = accInfo_.conversationModel->filteredConversation(0); - lrc::api::datatransfer::Info info { - "1", lrc::api::datatransfer::Status::on_connection, 0, 50 * 1024 * 1024, 0, - "./", "glados.jpg", "ring0", firstConversation.participants[0] - }; - ConfigurationManager::instance().setDataTransferInfo(3, info); - - auto dataTransferEventSigsCaught = WaitForSignalHelper([&]() { - ConfigurationManager::instance().emitDataTransferEvent(3, DRing::DataTransferEventCode::created); - ConfigurationManager::instance().emitDataTransferEvent(3, DRing::DataTransferEventCode::wait_host_acceptance); - }) - .addSignal("interactionStatusUpdated", *accInfo_.conversationModel, SIGNAL(interactionStatusUpdated(const std::string&, uint64_t, const api::interaction::Info&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(dataTransferEventSigsCaught["interactionStatusUpdated"], 1); - - auto lastIt = accInfo_.conversationModel->filteredConversation(0).interactions.rbegin()->second; - CPPUNIT_ASSERT(lastIt.status == lrc::api::interaction::Status::TRANSFER_CREATED); -} - -void -DataTransferTester::tearDown() -{ - -} - -} // namespace test -} // namespace ring diff --git a/test/datatransfertester.h b/test/datatransfertester.h deleted file mode 100644 index 13778d50..00000000 --- a/test/datatransfertester.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2017-2020 Savoir-faire Linux Inc. - * - * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> - * - * 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 3 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#pragma once - -// cppunit -#include <cppunit/TestFixture.h> -#include <cppunit/extensions/HelperMacros.h> - -// std -#include <memory> - -// Qt -#include <QObject> - -// lrc -#include "api/lrc.h" -#include "api/account.h" - -namespace ring -{ -namespace test -{ - -class DataTransferTester : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(DataTransferTester); - CPPUNIT_TEST(testReceivesMusic); - CPPUNIT_TEST(testReceivesImage5MbNoPref); - CPPUNIT_TEST(testReceivesImage5Mb); - CPPUNIT_TEST(testReceivesImage50Mb); - CPPUNIT_TEST_SUITE_END(); - -public: - DataTransferTester(); - /** - * Method automatically called before each test by CppUnit - */ - void setUp(); - /** - * Receives a new file, should be in conversations - */ - void testReceivesMusic(); - /** - * Receives a new image without any prefedred dir, should be awaiting peer - */ - void testReceivesImage5MbNoPref(); - /** - * Receives a new image with a prefedred dir, should accept transfer - */ - void testReceivesImage5Mb(); - /** - * Receives a new image with a prefedred dir but too big, awaiting peer - */ - void testReceivesImage50Mb(); - /** - * Method automatically called after each test by CppUnit - */ - void tearDown(); - -protected: - std::unique_ptr<lrc::api::Lrc> lrc_; - const lrc::api::account::Info& accInfo_; -}; - -} // namespace test -} // namespace ring diff --git a/test/mocks/callmanager_mock.h b/test/mocks/callmanager_mock.h deleted file mode 100644 index 2c4c0957..00000000 --- a/test/mocks/callmanager_mock.h +++ /dev/null @@ -1,326 +0,0 @@ -/* - * Copyright (C) 2017-2020 Savoir-faire Linux Inc. - * - * Authors: Sébastien Blin <sebastien.blin@savoirfairelinux.com> - * Nicolas Jager <nicolas.jager@savoirfairelinux.com> - * - * 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 3 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#pragma once - -#include <QtCore/QObject> -#include <QtCore/QByteArray> -#include <QtCore/QList> -#include <QtCore/QMap> -#include <QtCore/QString> -#include <QtCore/QStringList> -#include <QtCore/QVariant> -#include <QtCore/QTimer> - -#include <callmanager_interface.h> -#include "typedefs.h" -#include "qtwrapper/conversions_wrap.hpp" - -/* - * Proxy class for interface cx.ring.Ring.CallManager - */ -class CallManagerInterface: public QObject -{ - Q_OBJECT - -public: - - std::map<std::string, std::shared_ptr<DRing::CallbackWrapperBase>> callHandlers; - - CallManagerInterface() - { - - } - - ~CallManagerInterface() {} - - bool isValid() { return true; } - - void emitCallStateChanged(const QString &callID, const QString &state, int code) { - emit callStateChanged(callID, state, code); - } - -public Q_SLOTS: // METHODS - bool accept(const QString &callID) - { - emit callStateChanged(callID, "CURRENT", -1); - return true; - } - - bool addMainParticipant(const QString &confID) - { - Q_UNUSED(confID) - return false; - } - - bool addParticipant(const QString &callID, const QString &confID) - { - Q_UNUSED(callID) - Q_UNUSED(confID) - return false; - } - - bool attendedTransfer(const QString &transferID, const QString &targetID) - { - Q_UNUSED(transferID) - Q_UNUSED(targetID) - return false; - } - - void createConfFromParticipantList(const QStringList &participants) - { - Q_UNUSED(participants) - - } - - bool detachParticipant(const QString &callID) - { - Q_UNUSED(callID) - return false; - } - - MapStringString getCallDetails(const QString &callID) - { - Q_UNUSED(callID) - return MapStringString(); - } - - QStringList getCallList() - { - QStringList temp; - return temp; - } - - MapStringString getConferenceDetails(const QString &callID) - { - Q_UNUSED(callID) - MapStringString temp; - return temp; - } - - QString getConferenceId(const QString &callID) - { - Q_UNUSED(callID) - QString temp; - return temp; - } - - QStringList getConferenceList() - { - QStringList temp; - return temp; - } - - QStringList getDisplayNames(const QString &confID) - { - Q_UNUSED(confID) - QStringList temp; - return temp; - } - - bool getIsRecording(const QString &callID) - { - Q_UNUSED(callID) - //TODO: match API - return false; - } - - QStringList getParticipantList(const QString &confID) - { - return confID.split(","); - } - - bool hangUp(const QString &callID) - { - emit callStateChanged(callID, "OVER", -1); - return true; - } - - bool hangUpConference(const QString &confID) - { - Q_UNUSED(confID) - return false; - } - - bool hold(const QString &callID) - { - emit callStateChanged(callID, "HOLD", -1); - return true; - } - - bool holdConference(const QString &confID) - { - Q_UNUSED(confID) - return false; - } - - bool isConferenceParticipant(const QString &callID) - { - Q_UNUSED(callID) - return false; - } - - bool joinConference(const QString &sel_confID, const QString &drag_confID) - { - Q_UNUSED(sel_confID) - Q_UNUSED(drag_confID) - return false; - } - - bool joinParticipant(const QString &sel_callID, const QString &drag_callID) - { - emit conferenceCreated(sel_callID + "," + drag_callID); - return true; - } - - QString placeCall(const QString &accountID, const QString &to) - { - Q_UNUSED(accountID, to) - return to; - } - -#ifdef ENABLE_LIBWRAP - QString placeCall(const QString &accountID, const QString &to, const std::map<std::string, std::string>& VolatileCallDetails) - { - Q_UNUSED(accountID, to, VolatileCallDetails) - return to; - } -#else // dbus - QString placeCallWithDetails(const QString &accountID, const QString &to, const std::map<std::string, std::string>& VolatileCallDetails) - { - emit newCallCreated(accountID, to, to); - return to; - } -#endif // ENABLE_LIBWRAP - - void playDTMF(const QString &key) - { - Q_UNUSED(key) - } - - void recordPlaybackSeek(double value) - { - Q_UNUSED(value) - } - - bool refuse(const QString &callID) - { - Q_UNUSED(callID) - return false; - } - - void sendTextMessage(const QString &callID, const QMap<QString,QString> &message, bool isMixed) - { - Q_UNUSED(callID) - Q_UNUSED(message) - Q_UNUSED(isMixed) - } - - bool startRecordedFilePlayback(const QString &filepath) - { - Q_UNUSED(filepath) - return false; - } - - void startTone(int start, int type) - { - Q_UNUSED(start) - Q_UNUSED(type) - } - - void stopRecordedFilePlayback() - { } - - bool toggleRecording(const QString &callID) - { - Q_UNUSED(callID) - return false; - } - - bool transfer(const QString &callID, const QString &to) - { - Q_UNUSED(callID) - Q_UNUSED(to) - return false; - } - - bool unhold(const QString &callID) - { - emit callStateChanged(callID, "CURRENT", -1); - return true; - } - - bool unholdConference(const QString &confID) - { - Q_UNUSED(confID) - return false; - } - - bool muteLocalMedia(const QString& callid, const QString& mediaType, bool mute) - { - Q_UNUSED(callid) - Q_UNUSED(mediaType) - Q_UNUSED(mute) - return false; - } - - void startSmartInfo(int refresh) - { - Q_UNUSED(refresh) - } - - void stopSmartInfo() - { - } - - void emitIncomingCall(const QString &accountID, const QString &callID, const QString &from) - { - emit incomingCall(accountID, callID, from); - } - -Q_SIGNALS: // SIGNALS - void callStateChanged(const QString &callID, const QString &state, int code); - void transferFailed(); - void transferSucceeded(); - void recordPlaybackStopped(const QString &filepath); - void voiceMailNotify(const QString &accountId, int newCount, int oldCount, int urgentCount); - void incomingMessage(const QString &callID, const QString &from, const MapStringString &message); - void incomingCall(const QString &accountID, const QString &callID, const QString &from); - void recordPlaybackFilepath(const QString &callID, const QString &filepath); - void conferenceCreated(const QString &confID); - void conferenceChanged(const QString &confID, const QString &state); - void updatePlaybackScale(const QString &filepath, int position, int size); - void conferenceRemoved(const QString &confID); - void recordingStateChanged(const QString &callID, bool recordingState); - void onRtcpReportReceived(const QString &callID, MapStringInt report); - void audioMuted(const QString &callID, bool state); - void videoMuted(const QString &callID, bool state); - void peerHold(const QString &callID, bool state); - void smartInfo(const MapStringString& info); -}; - -namespace org { - namespace ring { - namespace Ring { - typedef ::CallManagerInterface CallManager; - } - } -} diff --git a/test/mocks/configurationmanager_mock.h b/test/mocks/configurationmanager_mock.h deleted file mode 100644 index 796afd5f..00000000 --- a/test/mocks/configurationmanager_mock.h +++ /dev/null @@ -1,855 +0,0 @@ -/* - * Copyright (C) 2017-2020 Savoir-faire Linux Inc. - * - * Authors: Sébastien Blin <sebastien.blin@savoirfairelinux.com> - * Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> - * Anthony Léonard <anthony.leonard@savoirfairelinux.com> - * Hugo Lefeuvre <hugo.lefeuvre@savoirfairelinux.com> - * - * 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 3 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#pragma once - -#include <QtCore/QObject> -#include <QtCore/QByteArray> -#include <QtCore/QList> -#include <QtCore/QMap> -#include <QtCore/QTimer> -#include <QtCore/QString> -#include <QtCore/QStringList> -#include <QtCore/QVariant> - -#include <future> - -#include <configurationmanager_interface.h> -#include <account_const.h> - -#include "typedefs.h" -#include "qtwrapper/conversions_wrap.hpp" - -#include <api/datatransfer.h> -#include <datatransfer_interface.h> - -/* - * Proxy class for interface org.ring.Ring.ConfigurationManager - */ -class ConfigurationManagerInterface: public QObject -{ - Q_OBJECT - -private: - QMap<QString, VectorMapStringString> accountToContactsMap; - QStringList availableContacts_; - std::mutex contactsMtx_; - QMap<QString, QMap<QString, QString>> devices; - -public: - - std::map<std::string, std::shared_ptr<DRing::CallbackWrapperBase>> confHandlers; - - ConfigurationManagerInterface() - { - setObjectName("ConfigurationManagerInterface"); - availableContacts_ << "contact0"; - availableContacts_ << "contact1"; - availableContacts_ << "contact2"; - availableContacts_ << "badguy0"; - availableContacts_ << "badguy1"; - availableContacts_ << "bannedContact"; - availableContacts_ << "dummy"; - for (auto& account: getAccountList()) { - auto contacts = VectorMapStringString(); - if (account.indexOf("ring") != -1) { - for (auto& contactUri: availableContacts_) { - if (contactUri == "dummy") break; - if (contactUri == "bannedContact") break; - if (contactUri == "badguy0") break; - if (contactUri == "badguy1") break; - auto contact = QMap<QString, QString>(); - contact.insert("id", contactUri); - contact.insert("added", "true"); - contact.insert("removed", "false"); - contact.insert("confirmed", "true"); - contact.insert("banned", "false"); - contacts.push_back(contact); - } - } - accountToContactsMap.insert(account, contacts); - // Init devices - MapStringString devicesForAccount; - devicesForAccount["device0"] = "pc"; - if (account.toStdString() == "ring3") - devicesForAccount["device1"] = "tel"; - devices[account] = devicesForAccount; - } - } - - ~ConfigurationManagerInterface() {} - - void addNewDevice(const QString& accountId, const QString& deviceId, const QString& name) { - devices[accountId][deviceId] = name; - emit knownDevicesChanged(accountId, devices[accountId]); - } - - void emitIncomingAccountMessage(const QString& accountId, const QString& from, const QMap<QString,QString>& payloads) - { - emit incomingAccountMessage(accountId, from, payloads); - } - - void emitAccountMessageStatusChanged(const QString& accountId, const uint64_t id, const QString& to, int status) - { - emit accountMessageStatusChanged(accountId, id, to, status); - } - - std::map<long long, lrc::api::datatransfer::Info> transferInfos_; - std::map<long long, uint32_t> transferInfosEvent_; - void setDataTransferInfo(long long ringId, lrc::api::datatransfer::Info lrc_info) { - transferInfos_.emplace(std::make_pair(ringId, lrc_info)); - } - - void emitDataTransferEvent(uint64_t transfer_id, DRing::DataTransferEventCode eventCode) { - auto code = static_cast<uint32_t>(eventCode); - auto it = transferInfosEvent_.find('c'); - if (it != transferInfosEvent_.end()) - it->second = code; - else - transferInfosEvent_.emplace(std::make_pair(transfer_id, code)); - emit dataTransferEvent(transfer_id, code); - } - -public Q_SLOTS: // METHODS - QString addAccount(MapStringString details) - { - Q_UNUSED(details) - QString temp; - return temp; - } - - bool exportOnRing(const QString& accountId, const QString& password) - { - Q_UNUSED(accountId) - Q_UNUSED(password) - return false; - } - - bool exportToFile(const QString& accountId, const QString& destinationPath, const QString& password = {}) - { - Q_UNUSED(accountId) - Q_UNUSED(destinationPath) - Q_UNUSED(password) - return false; - } - - MapStringString getKnownRingDevices(const QString& accountId) - { - return devices[accountId]; - } - - bool lookupName(const QString& accountId, const QString& nameServiceURL, const QString& name) - { - Q_UNUSED(nameServiceURL) - if (getAccountList().indexOf(accountId) == -1) return false; - if (name == "notAContact") return false; - emit registeredNameFound(accountId, 00, name, name); - return availableContacts_.indexOf(name) != -1; - } - - bool lookupAddress(const QString& accountId, const QString& nameServiceURL, const QString& address) - { - Q_UNUSED(nameServiceURL) - if (getAccountList().indexOf(accountId) == -1) return false; - return availableContacts_.indexOf(address) != -1; - } - - bool registerName(const QString& accountId, const QString& password, const QString& name) - { - Q_UNUSED(accountId) - Q_UNUSED(password) - Q_UNUSED(name) - return false; - } - - MapStringString getAccountDetails(const QString& accountId) - { - auto result = MapStringString(); - if (accountId.indexOf("ring") != -1) { - result.insert("Account.type", "RING"); - } else { - result.insert("Account.type", "SIP"); - } - result.insert("Account.deviceID", "device0"); - return result; - } - - QStringList getAccountList() - { - auto accountList = QStringList(); - accountList << QString("ring0"); // Used in conversationmodeltester - accountList << QString("ring1"); // Used in contactmodeltester - accountList << QString("ring2"); // Used in newcallmodeltester - accountList << QString("ring3"); // Used in newdevicemodeltester - accountList << QString("sip0"); - accountList << QString("sip1"); - return accountList; - } - - MapStringString getAccountTemplate(const QString& accountType) - { - Q_UNUSED(accountType) - return MapStringString(); - } - - VectorUInt getActiveCodecList(const QString& accountId) - { - Q_UNUSED(accountId) - return QVector<unsigned int>(); - } - - QString getAddrFromInterfaceName(const QString& interface) - { - Q_UNUSED(interface) - return QString(); - } - - QStringList getAllIpInterface() - { - return QStringList(); - } - - QStringList getAllIpInterfaceByName() - { - return QStringList(); - } - - MapStringString getCodecDetails(const QString& accountId, int payload) - { - Q_UNUSED(accountId) - Q_UNUSED(payload) - return MapStringString(); - } - - VectorUInt getCodecList() - { - return QVector<unsigned int>(); - } - - VectorMapStringString getContacts(const QString &accountId) - { - if (accountToContactsMap.find(accountId) == accountToContactsMap.end()) { - return VectorMapStringString(); - } - return accountToContactsMap[accountId]; - } - - int getAudioInputDeviceIndex(const QString& devname) - { - Q_UNUSED(devname) - return 0; - } - - QStringList getAudioInputDeviceList() - { - return QStringList(); - } - - QString getAudioManager() - { - return QString(); - } - - int getAudioOutputDeviceIndex(const QString& devname) - { - Q_UNUSED(devname) - return 0; - } - - QStringList getAudioOutputDeviceList() - { - return QStringList(); - } - - QStringList getAudioPluginList() - { - return QStringList(); - } - - VectorMapStringString getCredentials(const QString& accountId) - { - Q_UNUSED(accountId) - return VectorMapStringString(); - } - - QStringList getCurrentAudioDevicesIndex() - { - return QStringList(); - } - - QString getCurrentAudioOutputPlugin() - { - return QString(); - } - - int getHistoryLimit() - { - return 0; - } - - bool getIsAlwaysRecording() - { - return false; - } - - bool getNoiseSuppressState() - { - return false; - } - - QString getRecordPath() - { - return QString(); - } - - QStringList getSupportedAudioManagers() - { - QStringList temp; - return temp; - } - - MapStringString getShortcuts() - { - return MapStringString(); - } - - QStringList getSupportedTlsMethod() - { - return QStringList(); - } - - MapStringString validateCertificate(const QString& unused, const QString& certificate) - { - Q_UNUSED(unused) - Q_UNUSED(certificate) - return MapStringString(); - } - - MapStringString validateCertificatePath(const QString& unused, const QString& certificate, const QString& privateKey, const QString& privateKeyPass, const QString& caListPath) - { - Q_UNUSED(unused) - Q_UNUSED(certificate) - Q_UNUSED(privateKey) - Q_UNUSED(privateKeyPass) - Q_UNUSED(caListPath) - return MapStringString(); - } - - MapStringString getCertificateDetails(const QString& certificate) - { - Q_UNUSED(certificate) - return MapStringString(); - } - - MapStringString getCertificateDetailsPath(const QString& certificate, const QString& privateKey, const QString& privateKeyPass) - { - Q_UNUSED(certificate) - Q_UNUSED(privateKey) - Q_UNUSED(privateKeyPass) - return MapStringString(); - } - - QStringList getSupportedCiphers(const QString& accountId) - { - Q_UNUSED(accountId) - return QStringList(); - } - - MapStringString getTlsDefaultSettings() - { - return MapStringString(); - } - - double getVolume(const QString& device) - { - Q_UNUSED(device) - return 0; - } - - bool isAgcEnabled() - { - return false; - } - - bool isCaptureMuted() - { - return false; - } - - bool isDtmfMuted() - { - return false; - } - - bool isPlaybackMuted() - { - return false; - } - - void muteCapture(bool mute) - { - Q_UNUSED(mute) - } - - void muteDtmf(bool mute) - { - Q_UNUSED(mute) - } - - void mutePlayback(bool mute) - { - Q_UNUSED(mute) - } - - void registerAllAccounts() - { - } - - void removeAccount(const QString& accountId) - { - Q_UNUSED(accountId) - } - - int exportAccounts(const QStringList& accountIds, const QString& filePath, const QString& password) - { - Q_UNUSED(accountIds) - Q_UNUSED(filePath) - Q_UNUSED(password) - return 0; - } - - int importAccounts(const QString& filePath, const QString& password) - { - Q_UNUSED(filePath) - Q_UNUSED(password) - return 0; - } - - bool changeAccountPassword(const QString& id, const QString& currentPassword, const QString& newPassword) - { - Q_UNUSED(id) - Q_UNUSED(currentPassword) - Q_UNUSED(newPassword) - return false; - } - - void sendRegister(const QString& accountId, bool enable) - { - Q_UNUSED(accountId) - Q_UNUSED(enable) - } - - void setAccountDetails(const QString& accountId, MapStringString details) - { - if (accountId.toStdString() == "ring3") { - // testSetCurrentDeviceName - if (details.contains(DRing::Account::ConfProperties::RING_DEVICE_NAME)) { - devices["ring3"]["device0"] = details[DRing::Account::ConfProperties::RING_DEVICE_NAME]; - emit knownDevicesChanged(accountId, devices[accountId]); - } - } - } - - void setAccountsOrder(const QString& order) - { - Q_UNUSED(order) - } - - void setActiveCodecList(const QString& accountId, VectorUInt &list) - { - Q_UNUSED(accountId) - Q_UNUSED(list) - } - - void setAgcState(bool enabled) - { - Q_UNUSED(enabled) - } - - void setAudioInputDevice(int index) - { - Q_UNUSED(index) - } - - bool setAudioManager(const QString& api) - { - Q_UNUSED(api) - return false; - } - - void setAudioOutputDevice(int index) - { - Q_UNUSED(index) - } - - void setAudioPlugin(const QString& audioPlugin) - { - Q_UNUSED(audioPlugin) - } - - void setAudioRingtoneDevice(int index) - { - Q_UNUSED(index) - } - - void setCredentials(const QString& accountId, VectorMapStringString credentialInformation) - { - Q_UNUSED(accountId) - Q_UNUSED(credentialInformation) - } - - void setHistoryLimit(int days) - { - Q_UNUSED(days) - } - - void setIsAlwaysRecording(bool enabled) - { - Q_UNUSED(enabled) - } - - void setNoiseSuppressState(bool state) - { - Q_UNUSED(state) - } - - void setRecordPath(const QString& rec) - { - Q_UNUSED(rec) - } - - void setShortcuts(MapStringString shortcutsMap) - { - Q_UNUSED(shortcutsMap) - } - - void setVolume(const QString& device, double value) - { - Q_UNUSED(device) - Q_UNUSED(value) - } - - MapStringString getVolatileAccountDetails(const QString& accountId) - { - Q_UNUSED(accountId) - return MapStringString(); - } - - QStringList getPinnedCertificates() - { - return QStringList(); - } - - QStringList pinCertificate(const QByteArray& content, bool local) - { - Q_UNUSED(content) - Q_UNUSED(local) - return QStringList(); - } - - bool unpinCertificate(const QString& certId) - { - Q_UNUSED(certId) - return false; - } - - void pinCertificatePath(const QString& certPath) - { - Q_UNUSED(certPath) - } - - uint unpinCertificatePath(const QString& certPath) - { - Q_UNUSED(certPath) - return 0; - } - - bool pinRemoteCertificate(const QString& accountId, const QString& certPath) - { - Q_UNUSED(accountId) - Q_UNUSED(certPath) - return false; - } - - bool setCertificateStatus(const QString& accountId, const QString& certPath, const QString& status) - { - Q_UNUSED(accountId) - Q_UNUSED(certPath) - Q_UNUSED(status) - return false; - } - - QStringList getCertificatesByStatus(const QString& accountId, const QString& status) - { - Q_UNUSED(accountId) - Q_UNUSED(status) - return QStringList(); - } - - VectorMapStringString getTrustRequests(const QString& accountId) - { - Q_UNUSED(accountId) - return VectorMapStringString(); - } - - bool acceptTrustRequest(const QString& accountId, const QString& from) - { - Q_UNUSED(accountId) - Q_UNUSED(from) - return false; - } - - bool discardTrustRequest(const QString& accountId, const QString& from) - { - Q_UNUSED(accountId) - Q_UNUSED(from) - return false; - } - - void sendTrustRequest(const QString& accountId, const QString& from, const QByteArray& payload) - { - Q_UNUSED(accountId) - Q_UNUSED(from) - Q_UNUSED(payload) - } - - QVector<Message> getLastMessages(const std::string& accountID, const uint64_t& base_timestamp) - { - Q_UNUSED(accountID) - Q_UNUSED(base_timestamp) - return {}; - } - - void removeContact(const QString &accountId, const QString &uri, bool ban) - { - if (getAccountList().indexOf(accountId) == -1) return; - auto contacts = accountToContactsMap[accountId]; - - { - std::lock_guard<std::mutex> lk(contactsMtx_); - auto i = std::find_if( - contacts.begin(), contacts.end(), - [&uri](auto contact) { - return contact["id"] == uri; - }); - - if (i == contacts.end()) { - return; - } - - if (ban) { - i->insert("removed", "true"); - i->insert("banned", "true"); - } else { - contacts.erase(i); - } - } - - emit contactRemoved(accountId, uri, ban); - } - - void revokeDevice(const QString &accountId, const QString &password, const QString &deviceId) { - if (password == "") { - if (devices[accountId].contains(deviceId)) { - devices[accountId].remove(deviceId); - emit deviceRevocationEnded(accountId, deviceId, 0); - } else { - emit deviceRevocationEnded(accountId, deviceId, 2); - } - } else { - emit deviceRevocationEnded(accountId, deviceId, 1); - } - } - - void addContact(const QString &accountId, const QString &uri) - { - if (getAccountList().indexOf(accountId) == -1) return; - auto& cm = accountToContactsMap[accountId]; - - { - std::lock_guard<std::mutex> lk(contactsMtx_); - auto i = std::find_if( - cm.begin(), cm.end(), - [&uri](auto contact) { - return contact["id"] == uri; - }); - - if (i != cm.end()) { - // Contact is already there, erase it before adding it back. - // This is important to reset the banned/removed flags. - cm.erase(i); - } - - auto contact = QMap<QString, QString>(); - contact.insert("id", uri); - contact.insert("added", "true"); - contact.insert("removed", "false"); - contact.insert("confirmed", "true"); - contact.insert("banned", "false"); - cm.push_back(contact); - } - - emit contactAdded(accountId, uri, true); - } - - uint64_t sendTextMessage(const QString& accountId, const QString& to, const QMap<QString,QString>& payloads) - { - // NOTE used in ContactModel::sendMessage and ConversationModel::sendMessage - Q_UNUSED(accountId) - Q_UNUSED(to) - Q_UNUSED(payloads) - return 0; - } - - bool setCodecDetails(const QString& accountId, unsigned int codecId, const MapStringString& details) - { - Q_UNUSED(accountId) - Q_UNUSED(codecId) - Q_UNUSED(details) - return false; - } - - int getMessageStatus(uint64_t id) - { - Q_UNUSED(id) - return 0; - } - - void connectivityChanged() - { - } - - MapStringString getContactDetails(const QString &accountId, const QString &uri) - { - Q_UNUSED(accountId) - Q_UNUSED(uri) - return MapStringString(); - } - - void - emitIncomingTrustRequest(const QString& accountId, const QString& from, const QByteArray& payload, qulonglong timestamp) - { - emit incomingTrustRequest(accountId, from, payload, timestamp); - } - - VectorULongLong dataTransferList() { - return {}; - } - - uint32_t sendFile(const DataTransferInfo& lrc_info, qulonglong& id) { - (void)lrc_info; - (void)id; - return 0; - } - - uint32_t dataTransferInfo(uint64_t transfer_id, DataTransferInfo& lrc_info) { - auto dring_info = transferInfos_.find(transfer_id)->second; - lrc_info.accountId = QString::fromStdString(dring_info.accountId); - lrc_info.lastEvent = quint32(transferInfosEvent_.find(transfer_id)->second); - lrc_info.flags = {}; - lrc_info.totalSize = dring_info.totalSize; - lrc_info.bytesProgress = dring_info.progress; - lrc_info.peer = QString::fromStdString(dring_info.peerUri); - lrc_info.displayName = QString::fromStdString(dring_info.displayName); - lrc_info.path = QString::fromStdString(dring_info.path); - lrc_info.mimetype = QString::fromStdString(std::string("")); - return 0; - } - - uint64_t dataTransferBytesProgress(uint64_t transfer_id, qlonglong& total, qlonglong& progress) { - (void)transfer_id; - (void)total; - (void)progress; - return 0; - } - - uint32_t acceptFileTransfer(uint64_t transfer_id, const QString& file_path, uint64_t offset) { - (void)transfer_id; - (void)file_path; - (void)offset; - return 0; - } - - uint32_t cancelDataTransfer(uint64_t transfer_id) { - (void)transfer_id; - return 0; - } - - void enableProxyClient(const std::string& /*accountID*/, bool /*enable*/) - { } - - void setPushNotificationToken(const std::string& /*token*/) - { } - - void pushNotificationReceived(const std::string& /*from*/, - const std::map<std::string, std::string>& /*data*/) - { } - - void startProxyClient(const std::string& /*accountID*/, const std::string& /*address*/, - const std::string& /*deviceKey*/) { } - - void stopProxyClient(const std::string& /*accountID*/) { } - - bool isAudioMeterActive(const std::string& /*id*/) { return false; } - - void setAudioMeterState(const std::string& /*id*/, bool /*state*/) { } - -Q_SIGNALS: // SIGNALS - void volumeChanged(const QString& device, double value); - void accountsChanged(); - void accountDetailsChanged(const QString& accountId, const MapStringString& details); - void historyChanged(); - void stunStatusFailure(const QString& reason); - void registrationStateChanged(const QString& accountId, const QString& registration_state, unsigned detail_code, const QString& detail_str); - void stunStatusSuccess(const QString& message); - void errorAlert(int code); - void volatileAccountDetailsChanged(const QString& accountId, MapStringString details); - void certificatePinned(const QString& certId); - void certificatePathPinned(const QString& path, const QStringList& certIds); - void certificateExpired(const QString& certId); - void certificateStateChanged(const QString& accountId, const QString& certId, const QString& status); - void incomingTrustRequest(const QString& accountId, const QString& from, const QByteArray& payload, qulonglong timeStamp); - void knownDevicesChanged(const QString& accountId, const MapStringString& devices); - void exportOnRingEnded(const QString& accountId, int status, const QString& pin); - void incomingAccountMessage(const QString& accountId, const QString& from, const MapStringString& payloads); - void mediaParametersChanged(const QString& accountId); - void audioDeviceEvent(); - void audioMeter(const QString& id, float level); - void accountMessageStatusChanged(const QString& accountId, const uint64_t id, const QString& to, int status); - void nameRegistrationEnded(const QString& accountId, int status, const QString& name); - void registeredNameFound(const QString& accountId, int status, const QString& address, const QString& name); // used by conversationModel - void migrationEnded(const QString &accountId, const QString &result); - void contactAdded(const QString &accountId, const QString &uri, bool banned); - void contactRemoved(const QString &accountId, const QString &uri, bool banned); - void dataTransferEvent(uint64_t transfer_id, uint32_t code); - void deviceRevocationEnded(const QString& accountId, const QString& deviceId, int status); - void avatarReceived(const QString& accountId, const QString& userPhoto); - void debugMessageReceived(const std::string& message); -}; - -namespace org { - namespace ring { - namespace Ring { - typedef ::ConfigurationManagerInterface ConfigurationManager; - } - } -} diff --git a/test/mocks/instancemanager_mock.h b/test/mocks/instancemanager_mock.h deleted file mode 100644 index 16527acc..00000000 --- a/test/mocks/instancemanager_mock.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2017-2020 Savoir-faire Linux Inc. - * - * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> - * - * 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 3 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#pragma once - -#include <QObject> -#include <QByteArray> -#include <QList> -#include <QMap> -#include <QString> -#include <QStringList> -#include <QVariant> -#include <QTimer> - -#include "dring.h" -#include "typedefs.h" -#include "qtwrapper/conversions_wrap.hpp" - -/** - * Proxy class for interface org.ring.Ring.Instance - */ -class InstanceManagerInterface: public QObject -{ - Q_OBJECT -public: - InstanceManagerInterface() {} - ~InstanceManagerInterface() {} - -// TODO: These are not present in dring.h - -public Q_SLOTS: // METHODS - void Register(int pid, const QString &name) - { - Q_UNUSED(pid ) //When directly linked, the PID is always the current process PID - Q_UNUSED(name) - } - - void Unregister(int pid) - { - Q_UNUSED(pid) //When directly linked, the PID is always the current process PID - } - - bool isConnected() {return false;} - - void pollEvents() {} - -private: - -Q_SIGNALS: // SIGNALS - void started(); -}; - -namespace cx { - namespace Ring { - namespace Ring { - typedef ::InstanceManagerInterface Instance; - } - } -} diff --git a/test/mocks/presencemanager_mock.h b/test/mocks/presencemanager_mock.h deleted file mode 100644 index 2d81a89e..00000000 --- a/test/mocks/presencemanager_mock.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (C) 2017-2020 Savoir-faire Linux Inc. - * - * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> - * - * 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 3 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#pragma once - -#include <QtCore/QObject> -#include <QtCore/QByteArray> -#include <QtCore/QList> -#include <QtCore/QMap> -#include <QtCore/QString> -#include <QtCore/QStringList> -#include <QtCore/QVariant> -#include <QtCore/QTimer> - -#include "typedefs.h" -#include <presencemanager_interface.h> -#include "qtwrapper/conversions_wrap.hpp" - - -/* - * Proxy class for interface org.ring.Ring.PresenceManager - */ -class PresenceManagerInterface: public QObject -{ - Q_OBJECT -public: - - - PresenceManagerInterface() - { - } - - ~PresenceManagerInterface() {} - - void emitNewBuddyNotification(const QString &accountID, const QString &buddyUri, bool status, const QString &lineStatus) - { - emit newBuddyNotification(accountID, buddyUri, status, lineStatus); - } - void emitNearbyPeerNotification(const QString &accountID, const QString &buddyUri, int status, const QString &displayname) - { - emit nearbyPeerNotification(accountID, buddyUri, status, displayname); - } - -public Q_SLOTS: // METHODS - void answerServerRequest(const QString &uri, bool flag) - { - Q_UNUSED(uri) - Q_UNUSED(flag) - } - - VectorMapStringString getSubscriptions(const QString &accountID) - { - Q_UNUSED(accountID) - VectorMapStringString temp; - return temp; - } - - void publish(const QString &accountID, bool status, const QString ¬e) - { - Q_UNUSED(accountID) - Q_UNUSED(status) - Q_UNUSED(note) - } - - void setSubscriptions(const QString &accountID, const QStringList &uriList) - { - Q_UNUSED(accountID) - Q_UNUSED(uriList) - } - - void subscribeBuddy(const QString &accountID, const QString &uri, bool flag) - { - Q_UNUSED(accountID) - Q_UNUSED(uri) - Q_UNUSED(flag) - } - -Q_SIGNALS: // SIGNALS - void newServerSubscriptionRequest(const QString &buddyUri); - void serverError(const QString &accountID, const QString &error, const QString &msg); - void newBuddyNotification(const QString &accountID, const QString &buddyUri, bool status, const QString &lineStatus); - void nearbyPeerNotification(const QString &accountID, const QString &buddyUri, int status, const QString &displayname); - void subscriptionStateChanged(const QString &accountID, const QString &buddyUri, bool state); -}; - -namespace org { - namespace ring { - namespace Ring { - typedef ::PresenceManagerInterface PresenceManager; - } - } -} diff --git a/test/mocks/videomanager_mock.h b/test/mocks/videomanager_mock.h deleted file mode 100644 index c8fff1b0..00000000 --- a/test/mocks/videomanager_mock.h +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright (C) 2017-2020 Savoir-faire Linux Inc. - * - * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> - * - * 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 3 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#pragma once - -// libstdc++ -#include <functional> - -// Qt -#include <QtCore/QObject> -#include <QtCore/QCoreApplication> -#include <QtCore/QByteArray> -#include <QtCore/QThread> -#include <QtCore/QList> -#include <QtCore/QMap> -#include <QtCore/QString> -#include <QtCore/QStringList> -#include <QtCore/QVariant> -#include <QtCore/QTimer> - -// Ring -#include <videomanager_interface.h> - -#include "typedefs.h" -#include "qtwrapper/conversions_wrap.hpp" - -class VideoManagerInterface; - -class VideoManagerSignalProxy : public QObject -{ - Q_OBJECT -public: - VideoManagerSignalProxy(VideoManagerInterface* parent) { - Q_UNUSED(parent) - } - -public Q_SLOTS: - void slotDeviceEvent() {} - void slotStartedDecoding(const QString &id, const QString &shmPath, int width, int height, bool isMixer) { - Q_UNUSED(id) - Q_UNUSED(shmPath) - Q_UNUSED(width) - Q_UNUSED(height) - Q_UNUSED(isMixer) - - } - - void slotStoppedDecoding(const QString &id, const QString &shmPath, bool isMixer) { - Q_UNUSED(id) - Q_UNUSED(shmPath) - Q_UNUSED(isMixer) - - } - -private: - VideoManagerInterface* m_pParent; -}; - -class VideoManagerProxySender : public QObject -{ - Q_OBJECT - friend class VideoManagerInterface; -public: - -Q_SIGNALS: - void deviceEvent(); - void startedDecoding(const QString &id, const QString &shmPath, int width, int height, bool isMixer); - void stoppedDecoding(const QString &id, const QString &shmPath, bool isMixer); -}; - - - -/* - * Proxy class for interface org.ring.Ring.VideoManager - */ -class VideoManagerInterface: public QObject -{ - Q_OBJECT - -friend class VideoManagerSignalProxy; - -public: - - VideoManagerInterface() {} - ~VideoManagerInterface() {} - -private: - VideoManagerSignalProxy* proxy; - VideoManagerProxySender* sender; - -public Q_SLOTS: // METHODS - void applySettings(const QString &name, MapStringString settings) - { - Q_UNUSED(name) - Q_UNUSED(settings) - - } - - MapStringMapStringVectorString getCapabilities(const QString &name) - { - Q_UNUSED(name) - MapStringMapStringVectorString ret; - return ret; - } - - QString getDefaultDevice() - { - return QString(); - } - - QStringList getDeviceList() - { - QStringList temp; - return temp; - } - - MapStringString getSettings(const QString &device) - { - Q_UNUSED(device) - MapStringString temp; - return temp; - } - - bool hasCameraStarted() - { - return false; - } - - void setDefaultDevice(const QString &name) - { - Q_UNUSED(name) - } - - void startCamera() - { - } - - void stopCamera() - { - } - - void startAudioDevice() - { - } - - void stopAudioDevice() - { - } - - bool switchInput(const QString &resource) - { - Q_UNUSED(resource) - return false; - } - - void registerSinkTarget(const QString &sinkID, - const DRing::SinkTarget& target) - { - Q_UNUSED(sinkID) - Q_UNUSED(target) - } - - bool getDecodingAccelerated() - { - return false; - } - - void setDecodingAccelerated(bool state) - { - Q_UNUSED(state) - } - - bool getEncodingAccelerated() - { - return false; - } - - void setEncodingAccelerated(bool state) - { - Q_UNUSED(state) - } - - void stopLocalRecorder(const QString& path) - { - Q_UNUSED(path) - } - - QString startLocalRecorder(bool audioOnly, const QString& path) - { - Q_UNUSED(audioOnly) - Q_UNUSED(path) - return "/tmp/foobar"; - } - - MapStringString getRenderer(const QString& id) - { - Q_UNUSED(id) - return {}; - } - - -Q_SIGNALS: // SIGNALS - void deviceEvent(); - void startedDecoding(const QString &id, const QString &shmPath, int width, int height, bool isMixer); - void stoppedDecoding(const QString &id, const QString &shmPath, bool isMixer); -}; - -namespace org { namespace ring { namespace Ring { - typedef ::VideoManagerInterface VideoManager; -}}} // namesapce org::ring::Ring diff --git a/test/newaccountmodeltester.cpp b/test/newaccountmodeltester.cpp deleted file mode 100644 index 432e9083..00000000 --- a/test/newaccountmodeltester.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2017-2020 Savoir-faire Linux Inc. * - * Author: Nicolas Jäger <nicolas.jager@savoirfairelinux.com> * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation; either * - * version 2.1 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 * - * Lesser 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 "newaccountmodeltester.h" - -// Qt -#include <QString> -#include "utils/waitforsignalhelper.h" - -// lrc -#include "api/lrc.h" - -namespace ring -{ -namespace test -{ - -CPPUNIT_TEST_SUITE_REGISTRATION(NewAccountModelTester); - -NewAccountModelTester::NewAccountModelTester() -: lrc_(new lrc::api::Lrc()) -{ - -} - -void -NewAccountModelTester::setUp() -{ - -} - - -void -NewAccountModelTester::tearDown() -{ - -} - -} // namespace test -} // namespace ring diff --git a/test/newaccountmodeltester.h b/test/newaccountmodeltester.h deleted file mode 100644 index 89a1ac5f..00000000 --- a/test/newaccountmodeltester.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2017-2020 Savoir-faire Linux Inc. * - * Author: Nicolas Jäger <nicolas.jager@savoirfairelinux.com> * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation; either * - * version 2.1 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 * - * Lesser 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/>. * - ***************************************************************************/ -#pragma once - -// cppunit -#include <cppunit/TestFixture.h> -#include <cppunit/extensions/HelperMacros.h> - -// std -#include <memory> - -// Qt -#include <QObject> - -namespace lrc -{ -namespace api -{ -class Lrc; -} -} - -namespace ring -{ -namespace test -{ - -class NewAccountModelTester : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(NewAccountModelTester); - CPPUNIT_TEST_SUITE_END(); - -public: - NewAccountModelTester(); - /** - * Method automatically called before each test by CppUnit - */ - void setUp(); - /** - * Method automatically called after each test CppUnit - */ - void tearDown(); - -protected: - std::unique_ptr<lrc::api::Lrc> lrc_; -}; - -} // namespace test -} // namespace ring diff --git a/test/newcallmodeltester.cpp b/test/newcallmodeltester.cpp deleted file mode 100644 index b52ae7cc..00000000 --- a/test/newcallmodeltester.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (C) 2017-2020 Savoir-faire Linux Inc. - * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> - * - * 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 3 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#include "newcallmodeltester.h" - -// Qt -#include <QString> -#include "utils/waitforsignalhelper.h" - -// Lrc -#include <api/newaccountmodel.h> -#include <api/newcallmodel.h> -#include <api/conversationmodel.h> -#include <api/call.h> -#include <dbus/callmanager.h> - -namespace ring -{ -namespace test -{ - -CPPUNIT_TEST_SUITE_REGISTRATION(NewCallModelTester); - -NewCallModelTester::NewCallModelTester() -: lrc_(new lrc::api::Lrc()) -, accInfo_(lrc_->getAccountModel().getAccountInfo("ring2")) -{ - -} - -void -NewCallModelTester::setUp() -{ - -} - -void -NewCallModelTester::testCreateAndGetCall() -{ - auto callId = accInfo_.callModel->createCall("ring:contact0"); - CPPUNIT_ASSERT(!callId.empty()); - CPPUNIT_ASSERT(accInfo_.callModel->hasCall(callId)); - auto& call = accInfo_.callModel->getCallFromURI("ring:contact0"); - auto& callFromId = accInfo_.callModel->getCall(call.id); - CPPUNIT_ASSERT_EQUAL(callFromId.peer, std::string("ring:contact0")); -} - -void -NewCallModelTester::testCreateAndGetAudioOnlyCall() -{ - auto callId = accInfo_.callModel->createCall("ring:contact0", true); - CPPUNIT_ASSERT(!callId.empty()); - CPPUNIT_ASSERT(accInfo_.callModel->hasCall(callId)); - auto& call = accInfo_.callModel->getCallFromURI("ring:contact0"); - auto& callFromId = accInfo_.callModel->getCall(call.id); - CPPUNIT_ASSERT_EQUAL(callFromId.peer, std::string("ring:contact0")); -} - -void -NewCallModelTester::testAcceptHoldUnholdHangupCall() -{ - std::string callId = "ring:contact1"; - - auto incomingCallSigsCaught = WaitForSignalHelper([&]() { - CallManager::instance().emitIncomingCall("ring2", callId.c_str(), "ring:contact1"); - }) - .addSignal("newIncomingCall", *accInfo_.callModel, SIGNAL(newIncomingCall(const std::string&, const std::string&))) - .wait(1000); - CPPUNIT_ASSERT_EQUAL(incomingCallSigsCaught["newIncomingCall"], 1); - - CPPUNIT_ASSERT(accInfo_.callModel->hasCall(callId)); - accInfo_.callModel->accept(callId); - auto& call = accInfo_.callModel->getCallFromURI("ring:contact1"); - CPPUNIT_ASSERT_EQUAL((int)call.status, (int)lrc::api::call::Status::IN_PROGRESS); - accInfo_.callModel->togglePause(callId); - auto& callHold = accInfo_.callModel->getCallFromURI("ring:contact1"); - CPPUNIT_ASSERT_EQUAL((int)callHold.status, (int)lrc::api::call::Status::PAUSED); - accInfo_.callModel->togglePause(callId); - auto& callUnhold = accInfo_.callModel->getCallFromURI("ring:contact1"); - CPPUNIT_ASSERT_EQUAL((int)callUnhold.status, (int)lrc::api::call::Status::IN_PROGRESS); - accInfo_.callModel->hangUp(callId); - auto& callOver = accInfo_.callModel->getCallFromURI("ring:contact1"); - CPPUNIT_ASSERT_EQUAL((int)callOver.status, (int)lrc::api::call::Status::ENDED); -} - - -void -NewCallModelTester::tearDown() -{ - -} - -} // namespace test -} // namespace ring diff --git a/test/newcallmodeltester.h b/test/newcallmodeltester.h deleted file mode 100644 index 24fad4ee..00000000 --- a/test/newcallmodeltester.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2017-2020 Savoir-faire Linux Inc. - * - * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> - * - * 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 3 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#pragma once - -// cppunit -#include <cppunit/TestFixture.h> -#include <cppunit/extensions/HelperMacros.h> - -// std -#include <memory> - -// Qt -#include <QObject> - -// lrc -#include "api/lrc.h" -#include "api/account.h" - -namespace ring -{ -namespace test -{ - -class NewCallModelTester : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(NewCallModelTester); - CPPUNIT_TEST(testCreateAndGetCall); - CPPUNIT_TEST(testAcceptHoldUnholdHangupCall); - CPPUNIT_TEST(testCreateAndGetAudioOnlyCall); - CPPUNIT_TEST_SUITE_END(); - -public: - NewCallModelTester(); - /** - * Method automatically called before each test by CppUnit - */ - void setUp(); - /** - * Create a call between "ring2" and "contact0" and retrieve it. - */ - void testCreateAndGetCall(); - /** - * Create a audio-only call between "ring2" and "contact0" and retrieve it. - */ - void testCreateAndGetAudioOnlyCall(); - /** - * Simulate an incoming call from "contact1" for "ring2" - * Accept the call, call status should be IN_PROGRESS - * Hold the call, call status should be HOLD - * Unhold the call, call status should be IN_PROGRESS - * then hangUp. - */ - void testAcceptHoldUnholdHangupCall(); - /** - * Method automatically called after each test by CppUnit - */ - void tearDown(); - -protected: - std::unique_ptr<lrc::api::Lrc> lrc_; - const lrc::api::account::Info& accInfo_; -}; - -} // namespace test -} // namespace ring diff --git a/test/newdevicemodeltester.cpp b/test/newdevicemodeltester.cpp deleted file mode 100644 index fcee91f5..00000000 --- a/test/newdevicemodeltester.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (C) 2017-2020 Savoir-faire Linux Inc. - * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> - * - * 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 3 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#include "newdevicemodeltester.h" - -// std -#include <string> - -// Qt -#include "utils/waitforsignalhelper.h" - -// Lrc -#include <api/newaccountmodel.h> -#include <api/newdevicemodel.h> -#include <dbus/configurationmanager.h> - - -namespace ring -{ -namespace test -{ - -CPPUNIT_TEST_SUITE_REGISTRATION(NewDeviceModelTester); - -NewDeviceModelTester::NewDeviceModelTester() -: lrc_(new lrc::api::Lrc()) -, accInfo_(lrc_->getAccountModel().getAccountInfo("ring3")) -{ - -} - -void -NewDeviceModelTester::setUp() -{ - -} - -void -NewDeviceModelTester::testGetAllDevices() -{ - // See mocked ConfigurationManager::getKnownRingDevices() and getAccountDetails() - auto devices = accInfo_.deviceModel->getAllDevices(); - // Here, we should have 2 devices (device0 pc) and (device1 tel) - CPPUNIT_ASSERT_EQUAL(static_cast<int>(devices.size()), 2); - auto device0 = devices.front(); - CPPUNIT_ASSERT_EQUAL(device0.isCurrent, true); - CPPUNIT_ASSERT_EQUAL(device0.id, std::string("device0")); - CPPUNIT_ASSERT_EQUAL(device0.name, std::string("pc")); - auto device1 = devices.back(); - CPPUNIT_ASSERT_EQUAL(device1.isCurrent, false); - CPPUNIT_ASSERT_EQUAL(device1.id, std::string("device1")); - CPPUNIT_ASSERT_EQUAL(device1.name, std::string("tel")); -} - -void -NewDeviceModelTester::testGetValidDevice() -{ - // device0 defined in mocked ConfigurationManager - auto device0 = accInfo_.deviceModel->getDevice("device0"); - CPPUNIT_ASSERT_EQUAL(device0.isCurrent, true); - CPPUNIT_ASSERT_EQUAL(device0.id, std::string("device0")); - CPPUNIT_ASSERT_EQUAL(device0.name, std::string("pc")); -} - -void -NewDeviceModelTester::testGetInvalidDevice() -{ - // notADevice not defined in mocked ConfigurationManager - auto device0 = accInfo_.deviceModel->getDevice("notADevice"); - CPPUNIT_ASSERT_EQUAL(device0.id, std::string("")); -} - -void -NewDeviceModelTester::testNewDeviceAdded() -{ - // this will add a new device for ring3 (see mock) - ConfigurationManager::instance().addNewDevice("ring3", "device2", "tv"); - // Wait for deviceAdded - WaitForSignalHelper(*accInfo_.deviceModel, - SIGNAL(deviceAdded(const std::string& id))).wait(1000); - auto device0 = accInfo_.deviceModel->getDevice("device2"); - CPPUNIT_ASSERT_EQUAL(device0.isCurrent, false); - CPPUNIT_ASSERT_EQUAL(device0.id, std::string("device2")); - CPPUNIT_ASSERT_EQUAL(device0.name, std::string("tv")); - // Revoke device for other tests - // NOTE: should be removed when test will not depends from each others - // See mock - ConfigurationManager::instance().revokeDevice("ring3", "", "device2"); -} - -void -NewDeviceModelTester::testRevokeDevice() -{ - // this will add a new device for ring3 (see mock) - ConfigurationManager::instance().addNewDevice("ring3", "device2", "tv"); - // Wait for deviceAdded - WaitForSignalHelper(*accInfo_.deviceModel, - SIGNAL(deviceAdded(const std::string& id))).wait(1000); - // Then revoke device - accInfo_.deviceModel->revokeDevice("device2", ""); // empty password = correct - // Wait for deviceAdded - WaitForSignalHelper(*accInfo_.deviceModel, - SIGNAL(deviceRevoked(const std::string& id, - const lrc::api::NewDeviceModel::Status status))) - .wait(1000); - // Should not exists anymore - auto device2 = accInfo_.deviceModel->getDevice("device2"); - CPPUNIT_ASSERT_EQUAL(device2.id, std::string("")); -} - -void -NewDeviceModelTester::testRevokeDeviceInvalidDevice() -{ - // this will add a new device for ring3 (see mock) - ConfigurationManager::instance().addNewDevice("ring3", "device2", "tv"); - // Wait for deviceAdded - WaitForSignalHelper(*accInfo_.deviceModel, - SIGNAL(deviceAdded(const std::string& id))).wait(1000); - // Then revoke device - accInfo_.deviceModel->revokeDevice("device3", ""); // empty password = correct - // Wait for deviceAdded - WaitForSignalHelper(*accInfo_.deviceModel, - SIGNAL(deviceRevoked(const std::string& id, - const lrc::api::NewDeviceModel::Status status))) - .wait(1000); - // device2 still exists - auto device0 = accInfo_.deviceModel->getDevice("device2"); - CPPUNIT_ASSERT_EQUAL(device0.id, std::string("device2")); - // Revoke device for other tests - // NOTE: should be removed when test will not depends from each others - // See mock - ConfigurationManager::instance().revokeDevice("ring3", "", "device2"); -} - -void -NewDeviceModelTester::testRevokeDeviceInvalidPassword() -{ - // this will add a new device for ring3 (see mock) - ConfigurationManager::instance().addNewDevice("ring3", "device2", "tv"); - // Wait for deviceAdded - WaitForSignalHelper(*accInfo_.deviceModel, - SIGNAL(deviceAdded(const std::string& id))).wait(1000); - // Then revoke device - accInfo_.deviceModel->revokeDevice("device2", "notAPass"); // !empty password = incorrect - // Wait for deviceAdded - WaitForSignalHelper(*accInfo_.deviceModel, - SIGNAL(deviceRevoked(const std::string& id, - const lrc::api::NewDeviceModel::Status status))) - .wait(1000); - // device2 still exists - auto device0 = accInfo_.deviceModel->getDevice("device2"); - CPPUNIT_ASSERT_EQUAL(device0.id, std::string("device2")); - // Revoke device for other tests - // NOTE: should be removed when test will not depends from each others - // See mock - ConfigurationManager::instance().revokeDevice("ring3", "", "device2"); -} - -void -NewDeviceModelTester::testSetCurrentDeviceName() -{ - // Will change the name of device0 - accInfo_.deviceModel->setCurrentDeviceName("NewDeviceName"); - // Will call mocked ConfigurationManager::setAccountDetails() - // Because known devices changed, NewDeviceModel::deviceUpdated will be emitted - WaitForSignalHelper(*accInfo_.deviceModel, - SIGNAL(deviceUpdated(const std::string& id))).wait(1000); - // device0 should have a new name now. - auto device0 = accInfo_.deviceModel->getDevice("device0"); - CPPUNIT_ASSERT_EQUAL(device0.isCurrent, true); - CPPUNIT_ASSERT_EQUAL(device0.id, std::string("device0")); - CPPUNIT_ASSERT_EQUAL(device0.name, std::string("NewDeviceName")); -} - -void -NewDeviceModelTester::tearDown() -{ - accInfo_.deviceModel->setCurrentDeviceName("pc"); -} - -} // namespace test -} // namespace ring diff --git a/test/newdevicemodeltester.h b/test/newdevicemodeltester.h deleted file mode 100644 index 508f84dd..00000000 --- a/test/newdevicemodeltester.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) 2017-2020 Savoir-faire Linux Inc. - * - * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> - * - * 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 3 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#pragma once - -// cppunit -#include <cppunit/TestFixture.h> -#include <cppunit/extensions/HelperMacros.h> - -// std -#include <memory> - -// Qt -#include <QObject> - -// lrc -#include "api/lrc.h" -#include "api/account.h" - -namespace ring -{ -namespace test -{ - -class NewDeviceModelTester : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(NewDeviceModelTester); - CPPUNIT_TEST(testGetAllDevices); - CPPUNIT_TEST(testGetValidDevice); - CPPUNIT_TEST(testGetInvalidDevice); - CPPUNIT_TEST(testNewDeviceAdded); - CPPUNIT_TEST(testRevokeDevice); - CPPUNIT_TEST(testRevokeDeviceInvalidDevice); - CPPUNIT_TEST(testRevokeDeviceInvalidPassword); - CPPUNIT_TEST(testSetCurrentDeviceName); - CPPUNIT_TEST_SUITE_END(); - -public: - NewDeviceModelTester(); - /** - * Method automatically called before each test by CppUnit - */ - void setUp(); - /** - * Retrieve all devices of an account - */ - void testGetAllDevices(); - /** - * Test getting an existing device - */ - void testGetValidDevice(); - /** - * Test getting a non existing device - */ - void testGetInvalidDevice(); - /** - * Test new device added - */ - void testNewDeviceAdded(); - /** - * Test to remove a device (valid device, valid password) - */ - void testRevokeDevice(); - /** - * Test to remove a device (invalid device, valid password) - */ - void testRevokeDeviceInvalidDevice(); - /** - * Test to remove a device (valid device, invalid password) - */ - void testRevokeDeviceInvalidPassword(); - /** - * Test to change the current device name - */ - void testSetCurrentDeviceName(); - /** - * Method automatically called after each test by CppUnit - */ - void tearDown(); - -protected: - std::unique_ptr<lrc::api::Lrc> lrc_; - const lrc::api::account::Info& accInfo_; -}; - -} // namespace test -} // namespace ring diff --git a/test/test_runner.cpp b/test/test_runner.cpp deleted file mode 100644 index 14782fff..00000000 --- a/test/test_runner.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2017-2020 Savoir-faire Linux Inc. - * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> - * - * 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 3 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#include <cppunit/extensions/TestFactoryRegistry.h> -#include <cppunit/ui/text/TestRunner.h> -#include <cppunit/CompilerOutputter.h> -#include <iostream> - -#include <QCoreApplication> - -int main(int argc, char** argv) -{ - QCoreApplication app(argc, argv); - std::remove("/tmp/ring.db"); - CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry(); - CppUnit::Test *suite = registry.makeTest(); - if (suite->countTestCases() == 0) { - std::cout << "No test cases specified for suite" << std::endl; - return 1; - } - CppUnit::TextUi::TestRunner runner; - runner.addTest(suite); - auto result = runner.run() ? 0 : 1; - std::remove("/tmp/ring.db"); - return result; -} diff --git a/test/utils/waitforsignalhelper.cpp b/test/utils/waitforsignalhelper.cpp deleted file mode 100644 index 86a0606d..00000000 --- a/test/utils/waitforsignalhelper.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2017-2020 Savoir-faire Linux Inc. - * - * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> - * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> - * - * 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 3 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "waitforsignalhelper.h" -#include "api/interaction.h" -#include "../mocks/configurationmanager_mock.h" - -#include <QTimer> -#include <QSignalMapper> -#include <QMetaType> -#include <QString> -#include <QMap> - -#include <iostream> - -WaitForSignalHelper::WaitForSignalHelper(std::function<void()> f) -: f_(f) -{ - qRegisterMetaType<std::string>("std::string"); - qRegisterMetaType<uint32_t>("uint32_t"); - qRegisterMetaType<uint64_t>("uint64_t"); - qRegisterMetaType<lrc::api::interaction::Info>("interaction::Info"); - qRegisterMetaType<lrc::api::interaction::Info>("api::interaction::Info"); - qRegisterMetaType<MapStringString>("MapStringString"); -} - -WaitForSignalHelper& -WaitForSignalHelper::addSignal(const std::string& id, QObject& object, const char* signal) -{ - results_.insert({id , 0}); - QSignalMapper* signalMapper = new QSignalMapper(this); - auto connection = connect(&object, signal, signalMapper, SLOT(map()), Qt::QueuedConnection); - connections_.emplace_back(connection); - signalMapper->setMapping(&object, QString::fromStdString(id)); - connection = connect(signalMapper, - SIGNAL(mapped(const QString&)), - this, - SLOT(signalSlot(const QString&)), Qt::QueuedConnection); - connections_.emplace_back(connection); - return *this; -} - -void -WaitForSignalHelper::signalSlot(const QString & id) -{ - std::string signalId = id.toStdString(); - std::cout << "Signal caught: " << signalId.c_str() << "\n"; - auto resultsSize = results_.size(); - unsigned signalsCaught = 0; - // loop through results map till we find the id and increment the value, - // meanwhile testing the total caught signals and exiting the wait loop - // if all the signals have come through at least once - for (auto it = results_.begin(); it != results_.end(); it++) { - if ((*it).first.compare(signalId) == 0) { - (*it).second = 1; - } - signalsCaught = signalsCaught + static_cast<unsigned>((*it).second > 0); - if (signalsCaught == resultsSize) { - std::cout << "All signals caught\n"; - eventLoop_.quit(); - break; - } - } -} - -void -WaitForSignalHelper::timeout() -{ - std::cout << "Timed out! signal(s) missed\n"; - eventLoop_.quit(); -} - -std::map<std::string, int> -WaitForSignalHelper::wait(int timeoutMs) -{ - if (timeoutMs <= 0) { - throw std::invalid_argument("Invalid time out value"); - } - // wait till ready or timeout - std::thread readyThread([this, timeoutMs] () { - std::unique_lock<std::mutex> lk(mutex_); - cv_.wait_for(lk, std::chrono::milliseconds(timeoutMs), [this, timeoutMs] { - auto start = std::chrono::high_resolution_clock::now(); - while (!eventLoop_.isRunning() && std::chrono::high_resolution_clock::now() - start < std::chrono::milliseconds(timeoutMs)) {} - return true; - }); - // execute function expected to produce awaited signal(s) - f_(); - }); - // connect timer to A::timeout() here… or use chrono and busy loop, cv, etc. - QTimer timeoutHelper; - timeoutHelper.setInterval(timeoutMs); - timeoutHelper.start(); - connect(&timeoutHelper, SIGNAL(timeout()), this, SLOT(timeout()), Qt::QueuedConnection); - cv_.notify_all(); - // wait for results… if they come, else time out - eventLoop_.exec(); - for (auto& connection: connections_) { - QObject::disconnect(connection); - } - readyThread.join(); - return results_; -} diff --git a/test/utils/waitforsignalhelper.h b/test/utils/waitforsignalhelper.h deleted file mode 100644 index 5f4f698c..00000000 --- a/test/utils/waitforsignalhelper.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2017-2020 Savoir-faire Linux Inc. - * - * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> - * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> - * - * 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 3 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#pragma once - -// std -#include <mutex> -#include <string> -#include <thread> -#include <map> -#include <functional> -#include <condition_variable> - -// Qt -#include <QEventLoop> - -/** - * Class used to wait a Qt signal - * @param function object to execute that is expected to trigger signal emission - */ -class WaitForSignalHelper: public QObject -{ - Q_OBJECT -public: - WaitForSignalHelper(std::function<void()> f); - - WaitForSignalHelper& addSignal(const std::string& id, QObject& object, const char* signal); - std::map<std::string, int> wait(int timeoutMs); - -public Q_SLOTS: - /** - * Is activated if wait is finished - */ - void timeout(); - /** - * called when a signal is received - */ - void signalSlot(const QString & id); - -private: - std::function<void()> f_; - std::map<std::string, int> results_; - - std::mutex mutex_; - std::condition_variable cv_; - QEventLoop eventLoop_; - - std::vector<QMetaObject::Connection> connections_; -}; -- GitLab