8055262: Update jdk/test/java/util/Base64 tests to remove use of sun.misc.BASE64Encoder/Decoder
Reviewed-by: mchung, sherman
This commit is contained in:
parent
81d2d33d87
commit
f9c8748b48
jdk/test/java/util/Base64
@ -114,8 +114,6 @@ public class TestBase64 {
|
||||
testDecodeIgnoredAfterPadding();
|
||||
}
|
||||
|
||||
private static sun.misc.BASE64Encoder sunmisc = new sun.misc.BASE64Encoder();
|
||||
|
||||
private static void test(Base64.Encoder enc, Base64.Decoder dec,
|
||||
int numRuns, int numBytes) throws Throwable {
|
||||
Random rnd = new java.util.Random();
|
||||
@ -143,21 +141,6 @@ public class TestBase64 {
|
||||
throw new RuntimeException(
|
||||
"Base64 enc.encode().withoutPadding() has padding!");
|
||||
}
|
||||
// compare to sun.misc.BASE64Encoder
|
||||
|
||||
byte[] encoded2 = sunmisc.encode(orig).getBytes("ASCII");
|
||||
if (!withoutPadding) { // don't test for withoutPadding()
|
||||
checkEqual(normalize(encoded), normalize(encoded2),
|
||||
"Base64 enc.encode() does not match sun.misc.base64!");
|
||||
}
|
||||
// remove padding '=' to test non-padding decoding case
|
||||
if (encoded[encoded.length -2] == '=')
|
||||
encoded2 = Arrays.copyOf(encoded, encoded.length -2);
|
||||
else if (encoded[encoded.length -1] == '=')
|
||||
encoded2 = Arrays.copyOf(encoded, encoded.length -1);
|
||||
else
|
||||
encoded2 = null;
|
||||
|
||||
// --------testing encodetoString(byte[])/decode(String)--------
|
||||
String str = enc.encodeToString(orig);
|
||||
if (!Arrays.equals(str.getBytes("ASCII"), encoded)) {
|
||||
@ -167,11 +150,6 @@ public class TestBase64 {
|
||||
byte[] buf = dec.decode(new String(encoded, "ASCII"));
|
||||
checkEqual(buf, orig, "Base64 decoding(String) failed!");
|
||||
|
||||
if (encoded2 != null) {
|
||||
buf = dec.decode(new String(encoded2, "ASCII"));
|
||||
checkEqual(buf, orig, "Base64 decoding(String) failed!");
|
||||
}
|
||||
|
||||
//-------- testing encode/decode(Buffer)--------
|
||||
testEncode(enc, ByteBuffer.wrap(orig), encoded);
|
||||
ByteBuffer bin = ByteBuffer.allocateDirect(orig.length);
|
||||
@ -183,9 +161,6 @@ public class TestBase64 {
|
||||
bin.put(encoded).flip();
|
||||
testDecode(dec, bin, orig);
|
||||
|
||||
if (encoded2 != null)
|
||||
testDecode(dec, ByteBuffer.wrap(encoded2), orig);
|
||||
|
||||
// --------testing decode.wrap(input stream)--------
|
||||
// 1) random buf length
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(encoded);
|
||||
|
@ -40,9 +40,6 @@ import java.util.Base64.Encoder;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
import sun.misc.BASE64Decoder;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
public class TestBase64Golden {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
@ -138,16 +135,6 @@ public class TestBase64Golden {
|
||||
resArr = decoder.decode(encodedStr);
|
||||
assertEqual(resArr, srcArr);
|
||||
|
||||
// test compatible with sun.misc.Base64Encoder
|
||||
if (type == Base64Type.MIME) {
|
||||
sun.misc.BASE64Encoder miscEncoder = new BASE64Encoder();
|
||||
sun.misc.BASE64Decoder miscDecoder = new BASE64Decoder();
|
||||
resArr = decoder.decode(miscEncoder.encode(srcArr));
|
||||
assertEqual(resArr, srcArr);
|
||||
|
||||
resArr = encoder.encode(miscDecoder.decodeBuffer(encodedStr));
|
||||
assertEqual(new String(resArr, DEF_CHARSET), encodedStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user