diff --git a/CMakeLists.txt b/CMakeLists.txt index c2306e38c512913fa218e0ebecc54af094f8e0a8..df48e295872311d846c8bd1f6152daae503d74a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -881,6 +881,8 @@ IF((${ENABLE_TEST} MATCHES true)) test/conversationmodeltester.cpp test/contactmodeltester.h test/contactmodeltester.cpp + test/newcallmodeltester.h + test/newcallmodeltester.cpp ${libringclient_LIB_SRCS} ${libringclient_PRIVATE_HDRS} ) diff --git a/test/mocks/callmanager_mock.h b/test/mocks/callmanager_mock.h index ef562db174a9c7164e54cc505bc94d12da9b4dcf..522860fb023929cd684003e9a135e9859cfb496c 100644 --- a/test/mocks/callmanager_mock.h +++ b/test/mocks/callmanager_mock.h @@ -54,8 +54,8 @@ public: public Q_SLOTS: // METHODS bool accept(const QString &callID) { - Q_UNUSED(callID) - return false; + emit callStateChanged(callID, "CURRENT", -1); + return true; } bool addMainParticipant(const QString &confID) @@ -143,8 +143,8 @@ public Q_SLOTS: // METHODS bool hangUp(const QString &callID) { - Q_UNUSED(callID) - return false; + emit callStateChanged(callID, "OVER", -1); + return true; } bool hangUpConference(const QString &confID) @@ -155,8 +155,8 @@ public Q_SLOTS: // METHODS bool hold(const QString &callID) { - Q_UNUSED(callID) - return false; + emit callStateChanged(callID, "HOLD", -1); + return true; } bool holdConference(const QString &confID) @@ -245,8 +245,8 @@ public Q_SLOTS: // METHODS bool unhold(const QString &callID) { - Q_UNUSED(callID) - return false; + emit callStateChanged(callID, "CURRENT", -1); + return true; } bool unholdConference(const QString &confID) @@ -272,6 +272,11 @@ public Q_SLOTS: // METHODS { } + 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(); diff --git a/test/mocks/configurationmanager_mock.h b/test/mocks/configurationmanager_mock.h index 24209dd4ef0e4c0b4ea3cdae9d36c74272c1961f..dfed8e01150ab7e99b514a63496ea6a280a008e6 100644 --- a/test/mocks/configurationmanager_mock.h +++ b/test/mocks/configurationmanager_mock.h @@ -142,8 +142,9 @@ public Q_SLOTS: // METHODS QStringList getAccountList() { auto accountList = QStringList(); - accountList << QString("ring0"); - accountList << QString("ring1"); + accountList << QString("ring0"); // Used in conversationmodeltester + accountList << QString("ring1"); // Used in contactmodeltester + accountList << QString("ring2"); // Used in newcallmodeltester accountList << QString("sip0"); accountList << QString("sip1"); return accountList; diff --git a/test/newcallmodeltester.cpp b/test/newcallmodeltester.cpp new file mode 100644 index 0000000000000000000000000000000000000000..13cb7ed8234a5b05930eb00c1db33416d1147f8e --- /dev/null +++ b/test/newcallmodeltester.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2017 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::testAcceptHoldUnholdHangupCall() +{ + std::string callId = "ring:contact1"; + CallManager::instance().emitIncomingCall("ring2", callId.c_str(), "ring:contact1"); + WaitForSignalHelper(*accInfo_.callModel, + SIGNAL(newIncomingCall(const std::string& callId, const std::string& fromId))).wait(1000); + 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 new file mode 100644 index 0000000000000000000000000000000000000000..eeff50c22fa574f54e8e2192b9a49f583c290834 --- /dev/null +++ b/test/newcallmodeltester.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2017 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_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(); + /** + * 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