jdk/test/java/util/Base64/TestBase64Golden.java
changeset 26039 a6d9e5b030b1
parent 23010 6dadb192ad81
equal deleted inserted replaced
26038:ddbc61761999 26039:a6d9e5b030b1
    37 import java.util.Base64;
    37 import java.util.Base64;
    38 import java.util.Base64.Decoder;
    38 import java.util.Base64.Decoder;
    39 import java.util.Base64.Encoder;
    39 import java.util.Base64.Encoder;
    40 import java.util.Objects;
    40 import java.util.Objects;
    41 import java.util.Random;
    41 import java.util.Random;
    42 
       
    43 import sun.misc.BASE64Decoder;
       
    44 import sun.misc.BASE64Encoder;
       
    45 
    42 
    46 public class TestBase64Golden {
    43 public class TestBase64Golden {
    47 
    44 
    48     public static void main(String[] args) throws Exception {
    45     public static void main(String[] args) throws Exception {
    49         test0(Base64Type.BASIC, Base64.getEncoder(), Base64.getDecoder(),
    46         test0(Base64Type.BASIC, Base64.getEncoder(), Base64.getDecoder(),
   136 
   133 
   137             // test byte[] decode(String)
   134             // test byte[] decode(String)
   138             resArr = decoder.decode(encodedStr);
   135             resArr = decoder.decode(encodedStr);
   139             assertEqual(resArr, srcArr);
   136             assertEqual(resArr, srcArr);
   140 
   137 
   141             // test compatible with sun.misc.Base64Encoder
       
   142             if (type == Base64Type.MIME) {
       
   143                 sun.misc.BASE64Encoder miscEncoder = new BASE64Encoder();
       
   144                 sun.misc.BASE64Decoder miscDecoder = new BASE64Decoder();
       
   145                 resArr = decoder.decode(miscEncoder.encode(srcArr));
       
   146                 assertEqual(resArr, srcArr);
       
   147 
       
   148                 resArr = encoder.encode(miscDecoder.decodeBuffer(encodedStr));
       
   149                 assertEqual(new String(resArr, DEF_CHARSET), encodedStr);
       
   150             }
       
   151         }
   138         }
   152     }
   139     }
   153 
   140 
   154     private static void test1() throws Exception {
   141     private static void test1() throws Exception {
   155         byte[] src = new byte[] {
   142         byte[] src = new byte[] {