From f690e1de6f97305c89cf90afb4305487a9c6fc2e Mon Sep 17 00:00:00 2001
From: Tobias Markmann <tm@ayena.de>
Date: Thu, 14 Jan 2016 11:05:25 +0100
Subject: Free file-transfer objects before removing files in QA tool

FileTransferTest would attempt to remove files while the
file-transfer objects still have a file handle open to them
in form of FileReadBytestream and FileWriteBytestream
references.

Test-Information:

./scons test=system Swiften/QA/FileTransferTest passed
successfully on Windows 8.

Change-Id: Iba45fa5df7e6f55667dd76fee4624733bb363fe5

diff --git a/Swiften/QA/FileTransferTest/FileTransferTest.cpp b/Swiften/QA/FileTransferTest/FileTransferTest.cpp
index 2dcaeb8..13b6eff 100644
--- a/Swiften/QA/FileTransferTest/FileTransferTest.cpp
+++ b/Swiften/QA/FileTransferTest/FileTransferTest.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2015 Isode Limited.
+ * Copyright (c) 2014-2016 Isode Limited.
  * All rights reserved.
  * See the COPYING file for more information.
  */
@@ -75,8 +75,8 @@ class FileTransferTest {
 			timeOut_->onTick.connect(boost::bind(&FileTransferTest::handleTimeOut, this));
 
 			// Create randomly sized data to exchange.
-			sendFilePath_ = boost::filesystem::unique_path();
-			receiveFilePath_ = boost::filesystem::unique_path();
+			sendFilePath_ = boost::filesystem::unique_path("ft_send_%%%%%%%%%%%%%%%%.bin");
+			receiveFilePath_ = boost::filesystem::unique_path("ft_receive_%%%%%%%%%%%%%%%%.bin");
 
 			size_t size = 1024 + boost::numeric_cast<size_t>(randGen.generateRandomInteger(1024 * 10));
 			sendData_.resize(size);
@@ -95,6 +95,10 @@ class FileTransferTest {
 			delete senderTracer_;
 			delete receiverTracer_;
 
+			// Free file-transfer objects so file handles are closed and files can be removed afterwards.
+			incomingFileTransfers_.clear();
+			outgoingFileTransfer_.reset();
+
 			if(boost::filesystem::exists(sendFilePath_)) {
 				boost::filesystem::remove(sendFilePath_);
 			}
-- 
cgit v0.10.2-6-g49f6