diff options
| author | Tobias Markmann <tm@ayena.de> | 2015-06-20 12:20:41 (GMT) |
|---|---|---|
| committer | Kevin Smith <kevin.smith@isode.com> | 2015-07-08 07:08:40 (GMT) |
| commit | 5c55a79de95c11cecc0c98b57dfa1ff81ec7fb95 (patch) | |
| tree | 1d8e52cd829f3b622b54734e17366d7e72d8bdba | |
| parent | 67fef39ed463533157e66a72c17f31f9d078d5a2 (diff) | |
| download | swift-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.cpp | 6 | ||||
| -rw-r--r-- | Swiften/FileTransfer/UnitTest/OutgoingJingleFileTransferTest.cpp | 32 |
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 | |||
| @@ -134,13 +134,16 @@ void OutgoingJingleFileTransfer::handleSessionTerminateReceived(boost::optional< | |||
| 134 | waitForRemoteTermination->stop(); | 134 | waitForRemoteTermination->stop(); |
| 135 | } | 135 | } |
| 136 | if (reason && reason->type == JinglePayload::Reason::Cancel) { | 136 | if (reason && reason->type == JinglePayload::Reason::Cancel) { |
| 137 | setFinishedState(FileTransfer::State::Canceled, FileTransferError(FileTransferError::PeerError)); | 137 | setFinishedState(FileTransfer::State::Canceled, FileTransferError(FileTransferError::PeerError)); |
| 138 | } | 138 | } |
| 139 | else if (reason && reason->type == JinglePayload::Reason::Decline) { | ||
| 140 | setFinishedState(FileTransfer::State::Canceled, boost::optional<FileTransferError>()); | ||
| 141 | } | ||
| 139 | else if (reason && reason->type == JinglePayload::Reason::Success) { | 142 | else if (reason && reason->type == JinglePayload::Reason::Success) { |
| 140 | setFinishedState(FileTransfer::State::Finished, boost::optional<FileTransferError>()); | 143 | setFinishedState(FileTransfer::State::Finished, boost::optional<FileTransferError>()); |
| 141 | } | 144 | } |
| 142 | else { | 145 | else { |
| 143 | setFinishedState(FileTransfer::State::Failed, FileTransferError(FileTransferError::PeerError)); | 146 | setFinishedState(FileTransfer::State::Failed, FileTransferError(FileTransferError::PeerError)); |
| 144 | } | 147 | } |
| 145 | } | 148 | } |
| 146 | 149 | ||
| @@ -188,10 +191,11 @@ void OutgoingJingleFileTransfer::handleLocalTransportCandidatesGenerated( | |||
| 188 | transport->setSessionID(s5bSessionID); | 191 | transport->setSessionID(s5bSessionID); |
| 189 | transport->setMode(JingleS5BTransportPayload::TCPMode); | 192 | transport->setMode(JingleS5BTransportPayload::TCPMode); |
| 190 | transport->setDstAddr(dstAddr); | 193 | transport->setDstAddr(dstAddr); |
| 191 | foreach(JingleS5BTransportPayload::Candidate candidate, candidates) { | 194 | foreach(JingleS5BTransportPayload::Candidate candidate, candidates) { |
| 192 | transport->addCandidate(candidate); | 195 | transport->addCandidate(candidate); |
| 196 | SWIFT_LOG(debug) << "\t" << "S5B candidate: " << candidate.hostPort.toString() << std::endl; | ||
| 193 | } | 197 | } |
| 194 | setState(WaitingForAccept); | 198 | setState(WaitingForAccept); |
| 195 | session->sendInitiate(contentID, description, transport); | 199 | session->sendInitiate(contentID, description, transport); |
| 196 | } | 200 | } |
| 197 | 201 | ||
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 | |||
| @@ -54,21 +54,33 @@ using namespace Swift; | |||
| 54 | class OutgoingJingleFileTransferTest : public CppUnit::TestFixture { | 54 | class OutgoingJingleFileTransferTest : public CppUnit::TestFixture { |
| 55 | CPPUNIT_TEST_SUITE(OutgoingJingleFileTransferTest); | 55 | CPPUNIT_TEST_SUITE(OutgoingJingleFileTransferTest); |
| 56 | CPPUNIT_TEST(test_SendSessionInitiateOnStart); | 56 | CPPUNIT_TEST(test_SendSessionInitiateOnStart); |
| 57 | CPPUNIT_TEST(test_FallbackToIBBAfterFailingS5B); | 57 | CPPUNIT_TEST(test_FallbackToIBBAfterFailingS5B); |
| 58 | CPPUNIT_TEST(test_ReceiveSessionTerminateAfterSessionInitiate); | 58 | CPPUNIT_TEST(test_ReceiveSessionTerminateAfterSessionInitiate); |
| 59 | CPPUNIT_TEST(test_DeclineEmitsFinishedStateCanceled); | ||
| 59 | CPPUNIT_TEST_SUITE_END(); | 60 | CPPUNIT_TEST_SUITE_END(); |
| 60 | 61 | ||
| 61 | class FTStatusHelper { | 62 | class FTStatusHelper { |
| 62 | public: | 63 | public: |
| 63 | bool finishedCalled; | 64 | FTStatusHelper() : finishedCalled(false), error(FileTransferError::UnknownError) { |
| 64 | FileTransferError::Type error; | 65 | } |
| 66 | |||
| 65 | void handleFileTransferFinished(boost::optional<FileTransferError> error) { | 67 | void handleFileTransferFinished(boost::optional<FileTransferError> error) { |
| 66 | finishedCalled = true; | 68 | finishedCalled = true; |
| 67 | if (error.is_initialized()) this->error = error.get().getType(); | 69 | if (error.is_initialized()) this->error = error.get().getType(); |
| 68 | } | 70 | } |
| 71 | |||
| 72 | void handleFileTransferStatusChanged(FileTransfer::State fileTransferSTate) { | ||
| 73 | state = fileTransferSTate; | ||
| 74 | } | ||
| 75 | |||
| 76 | public: | ||
| 77 | bool finishedCalled; | ||
| 78 | FileTransferError::Type error; | ||
| 79 | boost::optional<FileTransfer::State> state; | ||
| 69 | }; | 80 | }; |
| 81 | |||
| 70 | public: | 82 | public: |
| 71 | 83 | ||
| 72 | boost::shared_ptr<OutgoingJingleFileTransfer> createTestling() { | 84 | boost::shared_ptr<OutgoingJingleFileTransfer> createTestling() { |
| 73 | JID to("test@foo.com/bla"); | 85 | JID to("test@foo.com/bla"); |
| 74 | JingleFileTransferFileInfo fileInfo; | 86 | JingleFileTransferFileInfo fileInfo; |
| @@ -191,10 +203,26 @@ public: | |||
| 191 | fakeJingleSession->handleSessionTerminateReceived(JinglePayload::Reason(JinglePayload::Reason::Busy)); | 203 | fakeJingleSession->handleSessionTerminateReceived(JinglePayload::Reason(JinglePayload::Reason::Busy)); |
| 192 | CPPUNIT_ASSERT_EQUAL(true, helper.finishedCalled); | 204 | CPPUNIT_ASSERT_EQUAL(true, helper.finishedCalled); |
| 193 | CPPUNIT_ASSERT(FileTransferError::PeerError == helper.error); | 205 | CPPUNIT_ASSERT(FileTransferError::PeerError == helper.error); |
| 194 | } | 206 | } |
| 195 | 207 | ||
| 208 | void test_DeclineEmitsFinishedStateCanceled() { | ||
| 209 | boost::shared_ptr<OutgoingJingleFileTransfer> transfer = createTestling(); | ||
| 210 | transfer->start(); | ||
| 211 | |||
| 212 | getCall<FakeJingleSession::InitiateCall>(0); | ||
| 213 | |||
| 214 | FTStatusHelper helper; | ||
| 215 | helper.finishedCalled = false; | ||
| 216 | transfer->onFinished.connect(bind(&FTStatusHelper::handleFileTransferFinished, &helper, _1)); | ||
| 217 | transfer->onStateChanged.connect(bind(&FTStatusHelper::handleFileTransferStatusChanged, &helper, _1)); | ||
| 218 | fakeJingleSession->handleSessionTerminateReceived(JinglePayload::Reason(JinglePayload::Reason::Decline)); | ||
| 219 | CPPUNIT_ASSERT_EQUAL(true, helper.finishedCalled); | ||
| 220 | CPPUNIT_ASSERT(FileTransferError::UnknownError == helper.error); | ||
| 221 | CPPUNIT_ASSERT_EQUAL(true, helper.state.is_initialized()); | ||
| 222 | CPPUNIT_ASSERT(FileTransfer::State::Canceled == helper.state.get().type); | ||
| 223 | } | ||
| 196 | 224 | ||
| 197 | //TODO: some more testcases | 225 | //TODO: some more testcases |
| 198 | 226 | ||
| 199 | private: | 227 | private: |
| 200 | void addFileTransferDescription() { | 228 | void addFileTransferDescription() { |
Swift