summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2015-06-20 12:20:41 (GMT)
committerKevin Smith <kevin.smith@isode.com>2015-07-08 07:08:40 (GMT)
commit5c55a79de95c11cecc0c98b57dfa1ff81ec7fb95 (patch)
tree1d8e52cd829f3b622b54734e17366d7e72d8bdba
parent67fef39ed463533157e66a72c17f31f9d078d5a2 (diff)
downloadswift-5c55a79de95c11cecc0c98b57dfa1ff81ec7fb95.zip
swift-5c55a79de95c11cecc0c98b57dfa1ff81ec7fb95.tar.bz2
Show canceled file-transfer by other party as canceled and not failed
Test-Information: Added unit test that checks for the expected behavior. Change-Id: I4079bdc1182af466eedd2496b9837e024f14acb2
-rw-r--r--Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp6
-rw-r--r--Swiften/FileTransfer/UnitTest/OutgoingJingleFileTransferTest.cpp32
2 files changed, 35 insertions, 3 deletions
diff --git a/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp b/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp
index 5c18b13..f9441cd 100644
--- a/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp
+++ b/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp
@@ -133,15 +133,18 @@ void OutgoingJingleFileTransfer::handleSessionTerminateReceived(boost::optional<
if (state == WaitForTermination) {
waitForRemoteTermination->stop();
}
if (reason && reason->type == JinglePayload::Reason::Cancel) {
setFinishedState(FileTransfer::State::Canceled, FileTransferError(FileTransferError::PeerError));
}
+ else if (reason && reason->type == JinglePayload::Reason::Decline) {
+ setFinishedState(FileTransfer::State::Canceled, boost::optional<FileTransferError>());
+ }
else if (reason && reason->type == JinglePayload::Reason::Success) {
setFinishedState(FileTransfer::State::Finished, boost::optional<FileTransferError>());
- }
+ }
else {
setFinishedState(FileTransfer::State::Failed, FileTransferError(FileTransferError::PeerError));
}
}
void OutgoingJingleFileTransfer::handleTransportAcceptReceived(const JingleContentID&, JingleTransportPayload::ref transport) {
@@ -187,12 +190,13 @@ void OutgoingJingleFileTransfer::handleLocalTransportCandidatesGenerated(
JingleS5BTransportPayload::ref transport = boost::make_shared<JingleS5BTransportPayload>();
transport->setSessionID(s5bSessionID);
transport->setMode(JingleS5BTransportPayload::TCPMode);
transport->setDstAddr(dstAddr);
foreach(JingleS5BTransportPayload::Candidate candidate, candidates) {
transport->addCandidate(candidate);
+ SWIFT_LOG(debug) << "\t" << "S5B candidate: " << candidate.hostPort.toString() << std::endl;
}
setState(WaitingForAccept);
session->sendInitiate(contentID, description, transport);
}
void OutgoingJingleFileTransfer::fallback() {
diff --git a/Swiften/FileTransfer/UnitTest/OutgoingJingleFileTransferTest.cpp b/Swiften/FileTransfer/UnitTest/OutgoingJingleFileTransferTest.cpp
index 40e7233..4b2fb50 100644
--- a/Swiften/FileTransfer/UnitTest/OutgoingJingleFileTransferTest.cpp
+++ b/Swiften/FileTransfer/UnitTest/OutgoingJingleFileTransferTest.cpp
@@ -53,23 +53,35 @@ using namespace Swift;
class OutgoingJingleFileTransferTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(OutgoingJingleFileTransferTest);
CPPUNIT_TEST(test_SendSessionInitiateOnStart);
CPPUNIT_TEST(test_FallbackToIBBAfterFailingS5B);
CPPUNIT_TEST(test_ReceiveSessionTerminateAfterSessionInitiate);
+ CPPUNIT_TEST(test_DeclineEmitsFinishedStateCanceled);
CPPUNIT_TEST_SUITE_END();
class FTStatusHelper {
public:
- bool finishedCalled;
- FileTransferError::Type error;
+ FTStatusHelper() : finishedCalled(false), error(FileTransferError::UnknownError) {
+ }
+
void handleFileTransferFinished(boost::optional<FileTransferError> error) {
finishedCalled = true;
if (error.is_initialized()) this->error = error.get().getType();
}
+
+ void handleFileTransferStatusChanged(FileTransfer::State fileTransferSTate) {
+ state = fileTransferSTate;
+ }
+
+ public:
+ bool finishedCalled;
+ FileTransferError::Type error;
+ boost::optional<FileTransfer::State> state;
};
+
public:
boost::shared_ptr<OutgoingJingleFileTransfer> createTestling() {
JID to("test@foo.com/bla");
JingleFileTransferFileInfo fileInfo;
fileInfo.setDescription("some file");
@@ -190,12 +202,28 @@ public:
transfer->onFinished.connect(bind(&FTStatusHelper::handleFileTransferFinished, &helper, _1));
fakeJingleSession->handleSessionTerminateReceived(JinglePayload::Reason(JinglePayload::Reason::Busy));
CPPUNIT_ASSERT_EQUAL(true, helper.finishedCalled);
CPPUNIT_ASSERT(FileTransferError::PeerError == helper.error);
}
+ void test_DeclineEmitsFinishedStateCanceled() {
+ boost::shared_ptr<OutgoingJingleFileTransfer> transfer = createTestling();
+ transfer->start();
+
+ getCall<FakeJingleSession::InitiateCall>(0);
+
+ FTStatusHelper helper;
+ helper.finishedCalled = false;
+ transfer->onFinished.connect(bind(&FTStatusHelper::handleFileTransferFinished, &helper, _1));
+ transfer->onStateChanged.connect(bind(&FTStatusHelper::handleFileTransferStatusChanged, &helper, _1));
+ fakeJingleSession->handleSessionTerminateReceived(JinglePayload::Reason(JinglePayload::Reason::Decline));
+ CPPUNIT_ASSERT_EQUAL(true, helper.finishedCalled);
+ CPPUNIT_ASSERT(FileTransferError::UnknownError == helper.error);
+ CPPUNIT_ASSERT_EQUAL(true, helper.state.is_initialized());
+ CPPUNIT_ASSERT(FileTransfer::State::Canceled == helper.state.get().type);
+ }
//TODO: some more testcases
private:
void addFileTransferDescription() {
boost::shared_ptr<JingleFileTransferDescription> desc = boost::make_shared<JingleFileTransferDescription>();