Package com.alibaba.json.bvt

Source Code of com.alibaba.json.bvt.Base64Test2

package com.alibaba.json.bvt;

import junit.framework.TestCase;

import org.junit.Assert;

import com.alibaba.fastjson.util.Base64;

public class Base64Test2 extends TestCase {

    public void test_base64_2() throws Exception {
        new Base64();
        String text = "";
        for (int i = 0; i < 1000; ++i) {
            byte[] bytes = text.getBytes("UTF-8");
            {
                String str = com.alibaba.json.test.Base64.encodeToString(bytes, true);
                Assert.assertEquals(text, new String(Base64.decodeFast(str.toCharArray(), 0, str.length()), "UTF-8"));
                Assert.assertEquals(text, new String(Base64.decodeFast(str), "UTF-8"));
                Assert.assertEquals(text, new String(Base64.decodeFast(str, 0, str.length()), "UTF-8"));
            }
            {
                String str = com.alibaba.json.test.Base64.encodeToString(bytes, false);
                Assert.assertEquals(text, new String(Base64.decodeFast(str.toCharArray(), 0, str.length()), "UTF-8"));
                Assert.assertEquals(text, new String(Base64.decodeFast(str), "UTF-8"));
                Assert.assertEquals(text, new String(Base64.decodeFast(str, 0, str.length()), "UTF-8"));
            }
            text += ((char) i);

        }
    }
   
    public void test_illegal() throws Exception {
        String text = "abc";
        byte[] bytes = text.getBytes("UTF-8");
        String str = "\0" + com.alibaba.json.test.Base64.encodeToString(bytes, false) + "\0";
        Assert.assertEquals(text, new String(Base64.decodeFast(str.toCharArray(), 0, str.length()), "UTF-8"));
        Assert.assertEquals(text, new String(Base64.decodeFast(str), "UTF-8"));
        Assert.assertEquals(text, new String(Base64.decodeFast(str, 0, str.length()), "UTF-8"));
    }
}
TOP

Related Classes of com.alibaba.json.bvt.Base64Test2

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.