393947 additional tests

This commit is contained in:
Greg Wilkins 2012-11-11 10:25:10 +11:00
parent 75aedbbf45
commit 0f60eb751d
2 changed files with 161 additions and 0 deletions

View File

@ -0,0 +1,85 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.util;
import junit.framework.Assert;
import org.junit.Test;
public class B64CodeTest
{
String text = "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.";
@Test
public void testRFC1421() throws Exception
{
String b64 = B64Code.encode(text,StringUtil.__ISO_8859_1);
Assert.assertEquals("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz"+
"IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg"+
"dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu"+
"dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo"+
"ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=",b64);
char[] chars = B64Code.encode(text.getBytes(StringUtil.__ISO_8859_1),false);
b64 = new String(chars,0,chars.length);
Assert.assertEquals("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz"+
"IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg"+
"dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu"+
"dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo"+
"ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=",b64);
}
@Test
public void testRFC2045() throws Exception
{
char[] chars = B64Code.encode(text.getBytes(StringUtil.__ISO_8859_1),true);
String b64 = new String(chars,0,chars.length);
Assert.assertEquals("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz\r\n"+
"IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg\r\n"+
"dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu\r\n"+
"dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo\r\n"+
"ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=\r\n",b64);
}
@Test
public void testInteger() throws Exception
{
byte[] bytes = text.getBytes(StringUtil.__ISO_8859_1);
int value=(bytes[0]<<24)+(bytes[1]<<16)+(bytes[2]<<8)+(bytes[3]);
StringBuilder b = new StringBuilder();
B64Code.encode(value,b);
Assert.assertEquals("TWFuIA=",b.toString());
}
@Test
public void testLong() throws Exception
{
byte[] bytes = text.getBytes(StringUtil.__ISO_8859_1);
long value=((0xffL&bytes[0])<<56)+((0xffL&bytes[1])<<48)+((0xffL&bytes[2])<<40)+((0xffL&bytes[3])<<32)+
((0xffL&bytes[4])<<24)+((0xffL&bytes[5])<<16)+((0xffL&bytes[6])<<8)+(0xffL&bytes[7]);
StringBuilder b = new StringBuilder();
B64Code.encode(value,b);
Assert.assertEquals("TWFuIGlzIGQ",b.toString());
}
}

View File

@ -0,0 +1,76 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.util;
import junit.framework.Assert;
import org.junit.Test;
public class TypeUtilTest
{
@Test
public void testToHexInt() throws Exception
{
StringBuilder b = new StringBuilder();
b.setLength(0);
TypeUtil.toHex((int)0,b);
Assert.assertEquals("00000000",b.toString());
b.setLength(0);
TypeUtil.toHex(Integer.MAX_VALUE,b);
Assert.assertEquals("7FFFFFFF",b.toString());
b.setLength(0);
TypeUtil.toHex(Integer.MIN_VALUE,b);
Assert.assertEquals("80000000",b.toString());
b.setLength(0);
TypeUtil.toHex(0x12345678,b);
Assert.assertEquals("12345678",b.toString());
b.setLength(0);
TypeUtil.toHex(0x9abcdef0,b);
Assert.assertEquals("9ABCDEF0",b.toString());
}
@Test
public void testToHexLong() throws Exception
{
StringBuilder b = new StringBuilder();
b.setLength(0);
TypeUtil.toHex((long)0,b);
Assert.assertEquals("0000000000000000",b.toString());
b.setLength(0);
TypeUtil.toHex(Long.MAX_VALUE,b);
Assert.assertEquals("7FFFFFFFFFFFFFFF",b.toString());
b.setLength(0);
TypeUtil.toHex(Long.MIN_VALUE,b);
Assert.assertEquals("8000000000000000",b.toString());
b.setLength(0);
TypeUtil.toHex(0x123456789abcdef0L,b);
Assert.assertEquals("123456789ABCDEF0",b.toString());
}
}