diff options
author | Kevin Smith <git@kismith.co.uk> | 2011-07-01 09:19:49 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2011-07-01 09:19:49 (GMT) |
commit | 2da71a8a85486a494343f1662d64fb5ae5a2a44e (patch) | |
tree | 23992f9f2a00bac23b345e5c2cc9c1194efc25be /test/com/isode/stroke/compress | |
download | stroke-2da71a8a85486a494343f1662d64fb5ae5a2a44e.zip stroke-2da71a8a85486a494343f1662d64fb5ae5a2a44e.tar.bz2 |
Initial import
Diffstat (limited to 'test/com/isode/stroke/compress')
-rw-r--r-- | test/com/isode/stroke/compress/ZLibCompressorTest.java | 48 | ||||
-rw-r--r-- | test/com/isode/stroke/compress/ZLibDecompressorTest.java | 72 |
2 files changed, 120 insertions, 0 deletions
diff --git a/test/com/isode/stroke/compress/ZLibCompressorTest.java b/test/com/isode/stroke/compress/ZLibCompressorTest.java new file mode 100644 index 0000000..3f9593b --- /dev/null +++ b/test/com/isode/stroke/compress/ZLibCompressorTest.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2010 Remko Tron¨on + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ +/* + * Copyright (c) 2010-2011, Isode Limited, London, England. + * All rights reserved. + */ +package com.isode.stroke.compress; + +import com.isode.stroke.base.ByteArray; +import com.isode.stroke.stringcodecs.Hexify; +import javax.xml.bind.annotation.adapters.HexBinaryAdapter; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author Kev + */ +public class ZLibCompressorTest { + + @Test + public void testProcess() throws Exception { + ZLibCompressor testling = new ZLibCompressor(); + ByteArray result = testling.process(new ByteArray("foo")); + + assertEquals("78da4acbcf07000000ffff", Hexify.hexify(result)); + } + + @Test + public void testProcess_Twice() throws ZLibException { + ZLibCompressor testling = new ZLibCompressor(); + testling.process(new ByteArray("foo")); + ByteArray result = testling.process(new ByteArray("bar")); + + assertEquals("4a4a2c02000000ffff", Hexify.hexify(result)); + } + + public static ByteArray unhex(String string) { + HexBinaryAdapter adaptor = new HexBinaryAdapter(); + return new ByteArray(adaptor.unmarshal(string)); + } +} diff --git a/test/com/isode/stroke/compress/ZLibDecompressorTest.java b/test/com/isode/stroke/compress/ZLibDecompressorTest.java new file mode 100644 index 0000000..838a324 --- /dev/null +++ b/test/com/isode/stroke/compress/ZLibDecompressorTest.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2010 Remko Tron¨on + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ +/* + * Copyright (c) 2010-2011, Isode Limited, London, England. + * All rights reserved. + */ +package com.isode.stroke.compress; + +import com.isode.stroke.base.ByteArray; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author Kev + */ +public class ZLibDecompressorTest { + + @Test + public void testProcess() throws ZLibException { + ZLibDecompressor testling = new ZLibDecompressor(); + ByteArray result = testling.process(ZLibCompressorTest.unhex("78da4acbcf07000000ffff")); + + assertEquals(new ByteArray("foo"), result); + } + + @Test + public void testProcess_Twice() throws ZLibException { + ZLibDecompressor testling = new ZLibDecompressor(); + testling.process(ZLibCompressorTest.unhex("78da4acbcf07000000ffff")); + ByteArray result = testling.process(ZLibCompressorTest.unhex("4a4a2c02000000ffff")); + + assertEquals(new ByteArray("bar"), result); + } + + @Test(expected = ZLibException.class) + public void testProcess_Invalid() throws ZLibException { + ZLibDecompressor testling = new ZLibDecompressor(); + testling.process(new ByteArray("invalid")); + } + + @Test + public void testProcess_Huge() throws ZLibException { + ByteArray data = new ByteArray(); + for (int i = 0; i < 2048; ++i) { + data.append((byte) i); + } + ByteArray original = new ByteArray(data); + ByteArray compressed = new ZLibCompressor().process(original); + ByteArray decompressed = new ZLibDecompressor().process(compressed); + + assertEquals(original, decompressed); + } + + @Test + public void testProcess_ChunkSize() throws ZLibException { + ByteArray data = new ByteArray(); + for (int i = 0; i < 1024; ++i) { + data.append((byte) i); + } + ByteArray original = new ByteArray(data); + ByteArray compressed = new ZLibCompressor().process(original); + ByteArray decompressed = new ZLibDecompressor().process(compressed); + + assertEquals(original, decompressed); + } +} |