1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-11 18:19:38 +02:00

Create smack.util.stringencoder for Base64, Base32,…

Use Android's Base64 implementation when on Android, otherwise, when on
Java7, use the existing one.
This commit is contained in:
Florian Schmaus 2014-09-04 11:04:51 +02:00
parent 90c0064394
commit 5d4aa76d19
32 changed files with 491 additions and 231 deletions

View file

@ -136,51 +136,6 @@ public class StringUtilsTest {
new String(output.getBytes()));
}
/**
* This method tests 2 StringUtil methods - encodeBase64(String) and encodeBase64(byte[]).
*/
@Test
public void testEncodeBase64() {
String input = "";
String output = "";
assertEquals(StringUtils.encodeBase64(input), output);
input = "foo bar 123";
output = "Zm9vIGJhciAxMjM=";
assertEquals(StringUtils.encodeBase64(input), output);
input = "=";
output = "PQ==";
assertEquals(StringUtils.encodeBase64(input), output);
input = "abcdefghijklmnopqrstuvwxyz0123456789\n\t\"?!.@{}[]();',./<>#$%^&*";
output = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU2Nzg5CgkiPyEuQHt9W10oKTsnLC4vPD4jJCVeJio=";
assertEquals(StringUtils.encodeBase64(input), output);
}
/***
* This method tests 2 StringUtil methods - decodeBase64(String) and decodeBase64(byte[]).
*/
/*
public void testDecodeBase64() {
String input = "";
String output = "";
assertEquals(StringUtils.decodeBase64(input), output);
input = "Zm9vIGJhciAxMjM=";
output = "foo bar 123";
assertEquals(StringUtils.decodeBase64(input), output);
input = "PQ==";
output = "=";
assertEquals(StringUtils.decodeBase64(input), output);
input = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU2Nzg5CgkiPyEuQHt9W10oKTsnLC4vPD4jJCVeJio=";
output = "abcdefghijklmnopqrstuvwxyz0123456789\n\t\"?!.@{}[]();',./<>#$%^&*";
assertEquals(StringUtils.decodeBase64(input), output);
}
*/
@Test
public void testRandomString() {
// Boundary test

View file

@ -0,0 +1,65 @@
/**
*
* Copyright © 2014 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smack.util.stringencoder;
import static org.junit.Assert.assertEquals;
// TODO those tests should be run with the Java7 and Android impl
public class Base64Test {
/**
* This method tests 2 StringUtil methods - encodeBase64(String) and encodeBase64(byte[]).
*/
public void testEncodeBase64() {
String input = "";
String output = "";
assertEquals(Base64.encode(input), output);
input = "foo bar 123";
output = "Zm9vIGJhciAxMjM=";
assertEquals(Base64.encode(input), output);
input = "=";
output = "PQ==";
assertEquals(Base64.encode(input), output);
input = "abcdefghijklmnopqrstuvwxyz0123456789\n\t\"?!.@{}[]();',./<>#$%^&*";
output = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU2Nzg5CgkiPyEuQHt9W10oKTsnLC4vPD4jJCVeJio=";
assertEquals(Base64.encode(input), output);
}
/***
* This method tests 2 StringUtil methods - decodeBase64(String) and decodeBase64(byte[]).
*/
public void testDecodeBase64() {
String input = "";
String output = "";
assertEquals(Base64.decodeToString(input), output);
input = "Zm9vIGJhciAxMjM=";
output = "foo bar 123";
assertEquals(Base64.decodeToString(input), output);
input = "PQ==";
output = "=";
assertEquals(Base64.decodeToString(input), output);
input = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU2Nzg5CgkiPyEuQHt9W10oKTsnLC4vPD4jJCVeJio=";
output = "abcdefghijklmnopqrstuvwxyz0123456789\n\t\"?!.@{}[]();',./<>#$%^&*";
assertEquals(Base64.decodeToString(input), output);
}
}