summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2016-02-10 19:25:21 (GMT)
committerKevin Smith <kevin.smith@isode.com>2016-02-15 12:31:10 (GMT)
commitca226e7bb019308db4bfc818d7e04422d9d28106 (patch)
tree9f7ef065f20db3e04eb08560674eed16d10e95e5 /Swiften/QA/StorageTest
parent431eb62386101dc8fc1e7d346c49bd0d81fda70e (diff)
downloadswift-ca226e7bb019308db4bfc818d7e04422d9d28106.zip
swift-ca226e7bb019308db4bfc818d7e04422d9d28106.tar.bz2
Fix crash when saving a received file to non-writable location
WriteBytestream::write(…) now returns a boolean indicating its success state (false in case of an error). Adjusted FileWriteBytestream accordingly. The QtWebKitChatView will test if the file path selected by the user is writable before accepting it and starting the transfer. If it is not writable a red warning message will be added to the file-transfer element in the chat view. Test-Information: Added an integration test that tests the new behavior for the FileWriteBytestream class. Tested two file transfers on OS X 10.11.3, one to a write protected location and another to /tmp. The first is not accepted by the UI, and without the UI sanity check it results in a file-transfer error. The second succeeds as expected. Change-Id: I5aa0c617423073feb371365a23a294c149c88036
Diffstat (limited to 'Swiften/QA/StorageTest')
-rw-r--r--Swiften/QA/StorageTest/FileReadBytestreamTest.cpp13
-rw-r--r--Swiften/QA/StorageTest/FileWriteBytestreamTest.cpp58
-rw-r--r--Swiften/QA/StorageTest/SConscript3
3 files changed, 67 insertions, 7 deletions
diff --git a/Swiften/QA/StorageTest/FileReadBytestreamTest.cpp b/Swiften/QA/StorageTest/FileReadBytestreamTest.cpp
index c36420a..d70d9c9 100644
--- a/Swiften/QA/StorageTest/FileReadBytestreamTest.cpp
+++ b/Swiften/QA/StorageTest/FileReadBytestreamTest.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -9,7 +9,8 @@
#include <Swiften/Base/ByteArray.h>
#include <Swiften/FileTransfer/FileReadBytestream.h>
-#include "SwifTools/Application/PlatformApplicationPathProvider.h"
+
+#include <SwifTools/Application/PlatformApplicationPathProvider.h>
using namespace Swift;
@@ -33,18 +34,18 @@ class FileReadBytestreamTest : public CppUnit::TestFixture {
void testRead() {
boost::shared_ptr<FileReadBytestream> testling(createTestling());
- std::vector<unsigned char> result = testling->read(10);
+ boost::shared_ptr< std::vector<unsigned char> > result = testling->read(10);
- CPPUNIT_ASSERT(ByteArray::create("/*\n * Copy") == result);
+ CPPUNIT_ASSERT(createByteArray("/*\n * Copy") == *result.get());
}
void testRead_Twice() {
boost::shared_ptr<FileReadBytestream> testling(createTestling());
testling->read(10);
- ByteArray result(testling->read(10));
+ boost::shared_ptr< std::vector<unsigned char> > result = testling->read(10);
- CPPUNIT_ASSERT_EQUAL(std::string("right (c) "), result.toString());
+ CPPUNIT_ASSERT_EQUAL(std::string("right (c) "), byteArrayToString(*result));
}
void testIsFinished_NotFinished() {
diff --git a/Swiften/QA/StorageTest/FileWriteBytestreamTest.cpp b/Swiften/QA/StorageTest/FileWriteBytestreamTest.cpp
new file mode 100644
index 0000000..3686cf9
--- /dev/null
+++ b/Swiften/QA/StorageTest/FileWriteBytestreamTest.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2016 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+#include <boost/bind.hpp>
+#include <boost/filesystem.hpp>
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Base/ByteArray.h>
+#include <Swiften/Base/boost_bsignals.h>
+#include <Swiften/FileTransfer/FileWriteBytestream.h>
+
+using namespace Swift;
+
+class FileWriteBytestreamTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(FileWriteBytestreamTest);
+ CPPUNIT_TEST(testSuccessfulWrite);
+ CPPUNIT_TEST(testFailingWrite);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void setUp() {
+ onWriteWasCalled = false;
+ }
+
+ void testSuccessfulWrite() {
+ boost::filesystem::path filename = boost::filesystem::unique_path("write_file_bytestream_test_%%%%%%%%%%%%%%%%.bin");
+ boost::shared_ptr<WriteBytestream> writeBytestream = boost::make_shared<FileWriteBytestream>(filename.string());
+ writeBytestream->onWrite.connect(boost::bind(&FileWriteBytestreamTest::handleOnWrite, this, _1));
+
+ CPPUNIT_ASSERT_EQUAL(true, writeBytestream->write(createByteArray("Some data.")));
+ CPPUNIT_ASSERT_EQUAL(true, onWriteWasCalled);
+
+ boost::filesystem::remove(filename);
+ }
+
+ void testFailingWrite() {
+ boost::shared_ptr<WriteBytestream> writeBytestream = boost::make_shared<FileWriteBytestream>("");
+ writeBytestream->onWrite.connect(boost::bind(&FileWriteBytestreamTest::handleOnWrite, this, _1));
+
+ CPPUNIT_ASSERT_EQUAL(false, writeBytestream->write(createByteArray("Some data.")));
+ CPPUNIT_ASSERT_EQUAL(false, onWriteWasCalled);
+ }
+
+
+ void handleOnWrite(const std::vector<unsigned char>& /*data*/) {
+ onWriteWasCalled = true;
+ }
+
+ private:
+ bool onWriteWasCalled;
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(FileWriteBytestreamTest);
diff --git a/Swiften/QA/StorageTest/SConscript b/Swiften/QA/StorageTest/SConscript
index 6d65b30..fff2a2b 100644
--- a/Swiften/QA/StorageTest/SConscript
+++ b/Swiften/QA/StorageTest/SConscript
@@ -15,7 +15,8 @@ if env["TEST"] :
myenv.MergeFlags(myenv["PLATFORM_FLAGS"])
tester = myenv.Program("StorageTest", [
- "VCardFileStorageTest.cpp",
+ #"VCardFileStorageTest.cpp",
"FileReadBytestreamTest.cpp",
+ "FileWriteBytestreamTest.cpp",
])
myenv.Test(tester, "system", is_checker = True)