diff options
author | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-07-26 08:19:02 (GMT) |
---|---|---|
committer | Kevin Smith <kevin.smith@isode.com> | 2015-08-17 15:06:09 (GMT) |
commit | afac50e2a7bfaf70d53a8265194b5a5ca13034f8 (patch) | |
tree | 255a9b20fd99995eb6c68c46f13a26221ccae46a /test/com/isode/stroke/stringcodecs/Base64Test.java | |
parent | f56f245c1f7e768caf356a0e7b57f428cf8cc6da (diff) | |
download | stroke-afac50e2a7bfaf70d53a8265194b5a5ca13034f8.zip stroke-afac50e2a7bfaf70d53a8265194b5a5ca13034f8.tar.bz2 |
Remove unnecessary Crypto functions from StringCodecs.
Remove SHA1 and HMACSHA1 from StringCodecs as they are already provided by CryptoProvider,
and is equivalent to Swiften.
License:
This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Test-Information:
Add tests for Base64 and PBKDF2, which passes.
Change-Id: Ife05f185a10a79c9d69a12235f1b0397d022d992
Diffstat (limited to 'test/com/isode/stroke/stringcodecs/Base64Test.java')
-rw-r--r-- | test/com/isode/stroke/stringcodecs/Base64Test.java | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/test/com/isode/stroke/stringcodecs/Base64Test.java b/test/com/isode/stroke/stringcodecs/Base64Test.java new file mode 100644 index 0000000..7365955 --- /dev/null +++ b/test/com/isode/stroke/stringcodecs/Base64Test.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.stringcodecs; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import org.junit.Before; +import com.isode.stroke.base.ByteArray; +import com.isode.stroke.stringcodecs.Base64; + +public class Base64Test { + + @Test + public void testEncodeDecodeAllChars() { + ByteArray input = new ByteArray(); + for (int i = 0; i < 255; ++i) { + char c = (char)i; + input.append((byte)c); + } + String result = Base64.encode(input); + + assertEquals(("AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+"), result); + assertEquals(input, Base64.decode(result)); + } + + @Test + public void testEncodeDecodeOneBytePadding() { + ByteArray input = new ByteArray("ABCDE"); + + String result = Base64.encode(input); + + assertEquals(("QUJDREU="), result); + assertEquals(input, Base64.decode(result)); + } + + @Test + public void testEncodeDecodeTwoBytesPadding() { + ByteArray input = new ByteArray("ABCD"); + + String result = Base64.encode(input); + + assertEquals(("QUJDRA=="), result); + assertEquals(input, Base64.decode(result)); + } + + @Test + public void testEncode_NoData() { + String result = (Base64.encode(new ByteArray())); + assertEquals((""), result); + } + + @Test + public void testDecode_NoData() { + ByteArray result = (Base64.decode("")); + assertEquals(new ByteArray(), result); + } +}
\ No newline at end of file |