diff options
author | Alex Clayton <alex.clayton@isode.com> | 2016-03-16 13:48:37 (GMT) |
---|---|---|
committer | Alex Clayton <alex.clayton@isode.com> | 2016-03-16 14:05:38 (GMT) |
commit | 8b9891afc85d114ff1e9c9a0291a4aaee8baeb09 (patch) | |
tree | 5027dc69d6ca785e0ed94aebc7232b3790b51464 /test/com/isode | |
parent | 892af8539f2b46e840d7344489529259d1df03b9 (diff) | |
download | stroke-8b9891afc85d114ff1e9c9a0291a4aaee8baeb09.zip stroke-8b9891afc85d114ff1e9c9a0291a4aaee8baeb09.tar.bz2 |
Add FileWriteBytestream class and test.
Adds a FileWriteBytestream class plus a test for it. These had been
missed out previously. Also as per patch 'Fix crash when saving a
received file to non-writable location' changed
WriteBytestream.write() method to return a boolean indicating success
or failure.
Test-information: Tests pass ok.
Change-Id: I0c3676db8b67573142e8628f439cecf54f3f8f1a
Diffstat (limited to 'test/com/isode')
-rw-r--r-- | test/com/isode/stroke/filetransfer/FileWriteBytestreamTest.java | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/test/com/isode/stroke/filetransfer/FileWriteBytestreamTest.java b/test/com/isode/stroke/filetransfer/FileWriteBytestreamTest.java new file mode 100644 index 0000000..3e06646 --- /dev/null +++ b/test/com/isode/stroke/filetransfer/FileWriteBytestreamTest.java @@ -0,0 +1,83 @@ +/* Copyright (c) 2016, Isode Limited, London, England. + * All rights reserved. + * + * Acquisition and use of this software and related materials for any + * purpose requires a written license agreement from Isode Limited, + * or a written license from an organisation licensed by Isode Limited + * to grant such a license. + * + */ +package com.isode.stroke.filetransfer; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + +import com.isode.stroke.base.ByteArray; +import com.isode.stroke.signals.Slot1; + +/** + * Tests for {@link FileWriteBytestream} + * + */ +public class FileWriteBytestreamTest { + + private boolean onWriteWasCalled = false; + + @Test + public void testSuccessfulWrite() { + File tempfile = null; + String filename = null; + try { + try { + tempfile = File.createTempFile("write_file_bytestream_test_", ".tmp"); + filename = tempfile.getAbsolutePath(); + } catch (IOException e) { + // Unable to create file exit test + return; + } + WriteBytestream writeBytestream = new FileWriteBytestream(filename); + writeBytestream.onWrite.connect(new Slot1<ByteArray>() { + + @Override + public void call(ByteArray data) { + handleOnWrite(data); + } + + }); + + assertTrue(writeBytestream.write(new ByteArray("Some data."))); + assertTrue(onWriteWasCalled); + } + finally { + if (tempfile != null && tempfile.exists()) { + tempfile.delete(); + } + } + } + + @Test + public void testFailingWrite() { + WriteBytestream writeBytestream = new FileWriteBytestream(""); + writeBytestream.onWrite.connect(new Slot1<ByteArray>() { + + @Override + public void call(ByteArray data) { + handleOnWrite(data); + } + + }); + + assertFalse(writeBytestream.write(new ByteArray("Some data."))); + assertFalse(onWriteWasCalled); + } + + private void handleOnWrite(ByteArray data) { + onWriteWasCalled = true; + } + +} |