Nothing to see here
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352915 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c875478b07
commit
74619707cd
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
* The Apache Software License, Version 1.1
|
* The Apache Software License, Version 1.1
|
||||||
*
|
*
|
||||||
@ -52,7 +51,6 @@
|
|||||||
* information on the Apache Software Foundation, please see
|
* information on the Apache Software Foundation, please see
|
||||||
* <http://www.apache.org/>.
|
* <http://www.apache.org/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.poi.util;
|
package org.apache.poi.util;
|
||||||
|
|
||||||
import junit.framework.*;
|
import junit.framework.*;
|
||||||
@ -66,138 +64,131 @@ import java.text.NumberFormat;
|
|||||||
* @author Glen Stampoultzis (glens at apache.org)
|
* @author Glen Stampoultzis (glens at apache.org)
|
||||||
* @author Sergei Kozello (sergeikozello at mail.ru)
|
* @author Sergei Kozello (sergeikozello at mail.ru)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class TestStringUtil
|
public class TestStringUtil
|
||||||
extends TestCase
|
extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new TestStringUtil
|
* Creates new TestStringUtil
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
*/
|
*/
|
||||||
|
public TestStringUtil( String name )
|
||||||
public TestStringUtil(String name)
|
|
||||||
{
|
{
|
||||||
super(name);
|
super( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test simple form of getFromUnicode
|
* test simple form of getFromUnicode
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void testSimpleGetFromUnicode()
|
public void testSimpleGetFromUnicode()
|
||||||
{
|
{
|
||||||
byte[] test_data = new byte[ 32 ];
|
byte[] test_data = new byte[32];
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
for (int k = 0; k < 16; k++)
|
for ( int k = 0; k < 16; k++ )
|
||||||
{
|
{
|
||||||
test_data[ index++ ] = ( byte ) 0;
|
test_data[index++] = (byte) 0;
|
||||||
test_data[ index++ ] = ( byte ) ('a' + k);
|
test_data[index++] = (byte) ( 'a' + k );
|
||||||
}
|
}
|
||||||
assertEquals("abcdefghijklmnop",
|
|
||||||
StringUtil.getFromUnicode(test_data));
|
assertEquals( "abcdefghijklmnop",
|
||||||
|
StringUtil.getFromUnicode( test_data ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test simple form of getFromUnicode with symbols with code below and more 127
|
* test simple form of getFromUnicode with symbols with code below and more 127
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void testGetFromUnicodeSymbolsWithCodesMoreThan127()
|
public void testGetFromUnicodeSymbolsWithCodesMoreThan127()
|
||||||
{
|
{
|
||||||
byte[] test_data = new byte[] { 0x04, 0x22,
|
byte[] test_data = new byte[]{0x04, 0x22,
|
||||||
0x04, 0x35,
|
0x04, 0x35,
|
||||||
0x04, 0x41,
|
0x04, 0x41,
|
||||||
0x04, 0x42,
|
0x04, 0x42,
|
||||||
0x00, 0x20,
|
0x00, 0x20,
|
||||||
0x00, 0x74,
|
0x00, 0x74,
|
||||||
0x00, 0x65,
|
0x00, 0x65,
|
||||||
0x00, 0x73,
|
0x00, 0x73,
|
||||||
0x00, 0x74,
|
0x00, 0x74,
|
||||||
};
|
};
|
||||||
|
|
||||||
assertEquals("\u0422\u0435\u0441\u0442 test",
|
assertEquals( "\u0422\u0435\u0441\u0442 test",
|
||||||
StringUtil.getFromUnicode(test_data));
|
StringUtil.getFromUnicode( test_data ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test getFromUnicodeHigh for symbols with code below and more 127
|
* test getFromUnicodeHigh for symbols with code below and more 127
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void testGetFromUnicodeHighSymbolsWithCodesMoreThan127()
|
public void testGetFromUnicodeHighSymbolsWithCodesMoreThan127()
|
||||||
{
|
{
|
||||||
byte[] test_data = new byte[] { 0x22, 0x04,
|
byte[] test_data = new byte[]{0x22, 0x04,
|
||||||
0x35, 0x04,
|
0x35, 0x04,
|
||||||
0x41, 0x04,
|
0x41, 0x04,
|
||||||
0x42, 0x04,
|
0x42, 0x04,
|
||||||
0x20, 0x00,
|
0x20, 0x00,
|
||||||
0x74, 0x00,
|
0x74, 0x00,
|
||||||
0x65, 0x00,
|
0x65, 0x00,
|
||||||
0x73, 0x00,
|
0x73, 0x00,
|
||||||
0x74, 0x00,
|
0x74, 0x00,
|
||||||
};
|
};
|
||||||
|
|
||||||
assertEquals("\u0422\u0435\u0441\u0442 test",
|
|
||||||
StringUtil.getFromUnicodeHigh( test_data ) );
|
assertEquals( "\u0422\u0435\u0441\u0442 test",
|
||||||
|
StringUtil.getFromUnicodeHigh( test_data ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test more complex form of getFromUnicode
|
* Test more complex form of getFromUnicode
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void testComplexGetFromUnicode()
|
public void testComplexGetFromUnicode()
|
||||||
{
|
{
|
||||||
byte[] test_data = new byte[ 32 ];
|
byte[] test_data = new byte[32];
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
for ( int k = 0; k < 16; k++ )
|
||||||
for (int k = 0; k < 16; k++)
|
|
||||||
{
|
{
|
||||||
test_data[ index++ ] = ( byte ) 0;
|
test_data[index++] = (byte) 0;
|
||||||
test_data[ index++ ] = ( byte ) ('a' + k);
|
test_data[index++] = (byte) ( 'a' + k );
|
||||||
}
|
}
|
||||||
assertEquals("abcdefghijklmno",
|
assertEquals( "abcdefghijklmno",
|
||||||
StringUtil.getFromUnicode(test_data, 0, 15));
|
StringUtil.getFromUnicode( test_data, 0, 15 ) );
|
||||||
assertEquals("bcdefghijklmnop",
|
assertEquals( "bcdefghijklmnop",
|
||||||
StringUtil.getFromUnicode(test_data, 2, 15));
|
StringUtil.getFromUnicode( test_data, 2, 15 ) );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
StringUtil.getFromUnicode(test_data, -1, 16);
|
StringUtil.getFromUnicode( test_data, -1, 16 );
|
||||||
fail("Should have caught ArrayIndexOutOfBoundsException");
|
fail( "Should have caught ArrayIndexOutOfBoundsException" );
|
||||||
}
|
}
|
||||||
catch (ArrayIndexOutOfBoundsException ignored)
|
catch ( ArrayIndexOutOfBoundsException ignored )
|
||||||
{
|
{
|
||||||
|
|
||||||
// as expected
|
// as expected
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
StringUtil.getFromUnicode(test_data, 32, 16);
|
StringUtil.getFromUnicode( test_data, 32, 16 );
|
||||||
fail("Should have caught ArrayIndexOutOfBoundsException");
|
fail( "Should have caught ArrayIndexOutOfBoundsException" );
|
||||||
}
|
}
|
||||||
catch (ArrayIndexOutOfBoundsException ignored)
|
catch ( ArrayIndexOutOfBoundsException ignored )
|
||||||
{
|
{
|
||||||
|
|
||||||
// as expected
|
// as expected
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
StringUtil.getFromUnicode(test_data, 1, 16);
|
StringUtil.getFromUnicode( test_data, 1, 16 );
|
||||||
fail("Should have caught IllegalArgumentException");
|
fail( "Should have caught IllegalArgumentException" );
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException ignored)
|
catch ( IllegalArgumentException ignored )
|
||||||
{
|
{
|
||||||
|
|
||||||
// as expected
|
// as expected
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
StringUtil.getFromUnicode(test_data, 1, -1);
|
StringUtil.getFromUnicode( test_data, 1, -1 );
|
||||||
fail("Should have caught IllegalArgumentException");
|
fail( "Should have caught IllegalArgumentException" );
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException ignored)
|
catch ( IllegalArgumentException ignored )
|
||||||
{
|
{
|
||||||
|
|
||||||
// as expected
|
// as expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -205,40 +196,38 @@ public class TestStringUtil
|
|||||||
/**
|
/**
|
||||||
* Test putCompressedUnicode
|
* Test putCompressedUnicode
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void testPutCompressedUnicode() throws Exception
|
public void testPutCompressedUnicode() throws Exception
|
||||||
{
|
{
|
||||||
byte[] output = new byte[ 100 ];
|
byte[] output = new byte[100];
|
||||||
byte[] expected_output =
|
byte[] expected_output =
|
||||||
{
|
{
|
||||||
( byte ) 'H', ( byte ) 'e', ( byte ) 'l', ( byte ) 'l',
|
(byte) 'H', (byte) 'e', (byte) 'l', (byte) 'l',
|
||||||
( byte ) 'o', ( byte ) ' ', ( byte ) 'W', ( byte ) 'o',
|
(byte) 'o', (byte) ' ', (byte) 'W', (byte) 'o',
|
||||||
( byte ) 'r', ( byte ) 'l', ( byte ) 'd', ( byte ) 0xAE
|
(byte) 'r', (byte) 'l', (byte) 'd', (byte) 0xAE
|
||||||
};
|
};
|
||||||
String input = new String(expected_output,StringUtil.getPreferredEncoding());
|
String input = new String( expected_output, StringUtil.getPreferredEncoding() );
|
||||||
|
|
||||||
StringUtil.putCompressedUnicode(input, output, 0);
|
StringUtil.putCompressedUnicode( input, output, 0 );
|
||||||
for (int j = 0; j < expected_output.length; j++)
|
for ( int j = 0; j < expected_output.length; j++ )
|
||||||
{
|
{
|
||||||
assertEquals("testing offset " + j, expected_output[ j ],
|
assertEquals( "testing offset " + j, expected_output[j],
|
||||||
output[ j ]);
|
output[j] );
|
||||||
}
|
}
|
||||||
StringUtil.putCompressedUnicode(input, output,
|
StringUtil.putCompressedUnicode( input, output,
|
||||||
100 - expected_output.length);
|
100 - expected_output.length );
|
||||||
for (int j = 0; j < expected_output.length; j++)
|
for ( int j = 0; j < expected_output.length; j++ )
|
||||||
{
|
{
|
||||||
assertEquals("testing offset " + j, expected_output[ j ],
|
assertEquals( "testing offset " + j, expected_output[j],
|
||||||
output[ 100 + j - expected_output.length ]);
|
output[100 + j - expected_output.length] );
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
StringUtil.putCompressedUnicode(input, output,
|
StringUtil.putCompressedUnicode( input, output,
|
||||||
101 - expected_output.length);
|
101 - expected_output.length );
|
||||||
fail("Should have caught ArrayIndexOutOfBoundsException");
|
fail( "Should have caught ArrayIndexOutOfBoundsException" );
|
||||||
}
|
}
|
||||||
catch (ArrayIndexOutOfBoundsException ignored)
|
catch ( ArrayIndexOutOfBoundsException ignored )
|
||||||
{
|
{
|
||||||
|
|
||||||
// as expected
|
// as expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -246,121 +235,126 @@ public class TestStringUtil
|
|||||||
/**
|
/**
|
||||||
* Test putUncompressedUnicode
|
* Test putUncompressedUnicode
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void testPutUncompressedUnicode()
|
public void testPutUncompressedUnicode()
|
||||||
{
|
{
|
||||||
byte[] output = new byte[ 100 ];
|
byte[] output = new byte[100];
|
||||||
String input = "Hello World";
|
String input = "Hello World";
|
||||||
byte[] expected_output =
|
byte[] expected_output =
|
||||||
{
|
{
|
||||||
( byte ) 'H', ( byte ) 0, ( byte ) 'e', ( byte ) 0, ( byte ) 'l',
|
(byte) 'H', (byte) 0, (byte) 'e', (byte) 0, (byte) 'l',
|
||||||
( byte ) 0, ( byte ) 'l', ( byte ) 0, ( byte ) 'o', ( byte ) 0,
|
(byte) 0, (byte) 'l', (byte) 0, (byte) 'o', (byte) 0,
|
||||||
( byte ) ' ', ( byte ) 0, ( byte ) 'W', ( byte ) 0, ( byte ) 'o',
|
(byte) ' ', (byte) 0, (byte) 'W', (byte) 0, (byte) 'o',
|
||||||
( byte ) 0, ( byte ) 'r', ( byte ) 0, ( byte ) 'l', ( byte ) 0,
|
(byte) 0, (byte) 'r', (byte) 0, (byte) 'l', (byte) 0,
|
||||||
( byte ) 'd', ( byte ) 0
|
(byte) 'd', (byte) 0
|
||||||
};
|
};
|
||||||
|
|
||||||
StringUtil.putUncompressedUnicode(input, output, 0);
|
StringUtil.putUncompressedUnicode( input, output, 0 );
|
||||||
for (int j = 0; j < expected_output.length; j++)
|
for ( int j = 0; j < expected_output.length; j++ )
|
||||||
{
|
{
|
||||||
assertEquals("testing offset " + j, expected_output[ j ],
|
assertEquals( "testing offset " + j, expected_output[j],
|
||||||
output[ j ]);
|
output[j] );
|
||||||
}
|
}
|
||||||
StringUtil.putUncompressedUnicode(input, output,
|
StringUtil.putUncompressedUnicode( input, output,
|
||||||
100 - expected_output.length);
|
100 - expected_output.length );
|
||||||
for (int j = 0; j < expected_output.length; j++)
|
for ( int j = 0; j < expected_output.length; j++ )
|
||||||
{
|
{
|
||||||
assertEquals("testing offset " + j, expected_output[ j ],
|
assertEquals( "testing offset " + j, expected_output[j],
|
||||||
output[ 100 + j - expected_output.length ]);
|
output[100 + j - expected_output.length] );
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
StringUtil.putUncompressedUnicode(input, output,
|
StringUtil.putUncompressedUnicode( input, output,
|
||||||
101 - expected_output.length);
|
101 - expected_output.length );
|
||||||
fail("Should have caught ArrayIndexOutOfBoundsException");
|
fail( "Should have caught ArrayIndexOutOfBoundsException" );
|
||||||
}
|
}
|
||||||
catch (ArrayIndexOutOfBoundsException ignored)
|
catch ( ArrayIndexOutOfBoundsException ignored )
|
||||||
{
|
{
|
||||||
|
|
||||||
// as expected
|
// as expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testFormat()
|
public void testFormat()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
assertEquals("This is a test " + fmt(1.2345, 2, 2),
|
assertEquals( "This is a test " + fmt( 1.2345, 2, 2 ),
|
||||||
StringUtil.format("This is a test %2.2", new Object[]
|
StringUtil.format( "This is a test %2.2", new Object[]
|
||||||
{
|
{
|
||||||
new Double(1.2345)
|
new Double( 1.2345 )
|
||||||
}));
|
} ) );
|
||||||
assertEquals("This is a test " + fmt(1.2345, -1, 3),
|
assertEquals( "This is a test " + fmt( 1.2345, -1, 3 ),
|
||||||
StringUtil.format("This is a test %.3", new Object[]
|
StringUtil.format( "This is a test %.3", new Object[]
|
||||||
{
|
{
|
||||||
new Double(1.2345)
|
new Double( 1.2345 )
|
||||||
}));
|
} ) );
|
||||||
assertEquals("This is a great test " + fmt(1.2345, -1, 3),
|
assertEquals( "This is a great test " + fmt( 1.2345, -1, 3 ),
|
||||||
StringUtil.format("This is a % test %.3", new Object[]
|
StringUtil.format( "This is a % test %.3", new Object[]
|
||||||
{
|
{
|
||||||
"great", new Double(1.2345)
|
"great", new Double( 1.2345 )
|
||||||
}));
|
} ) );
|
||||||
assertEquals("This is a test 1",
|
assertEquals( "This is a test 1",
|
||||||
StringUtil.format("This is a test %", new Object[]
|
StringUtil.format( "This is a test %", new Object[]
|
||||||
{
|
{
|
||||||
new Integer(1)
|
new Integer( 1 )
|
||||||
}));
|
} ) );
|
||||||
assertEquals("This is a test 1",
|
assertEquals( "This is a test 1",
|
||||||
StringUtil.format("This is a test %", new Object[]
|
StringUtil.format( "This is a test %", new Object[]
|
||||||
{
|
{
|
||||||
new Integer(1), new Integer(1)
|
new Integer( 1 ), new Integer( 1 )
|
||||||
}));
|
} ) );
|
||||||
assertEquals("This is a test 1.x",
|
assertEquals( "This is a test 1.x",
|
||||||
StringUtil.format("This is a test %1.x", new Object[]
|
StringUtil.format( "This is a test %1.x", new Object[]
|
||||||
{
|
{
|
||||||
new Integer(1)
|
new Integer( 1 )
|
||||||
}));
|
} ) );
|
||||||
assertEquals("This is a test ?missing data?1.x",
|
assertEquals( "This is a test ?missing data?1.x",
|
||||||
StringUtil.format("This is a test %1.x", new Object[]
|
StringUtil.format( "This is a test %1.x", new Object[]
|
||||||
{
|
{
|
||||||
}));
|
} ) );
|
||||||
assertEquals("This is a test %1.x",
|
assertEquals( "This is a test %1.x",
|
||||||
StringUtil.format("This is a test \\%1.x", new Object[]
|
StringUtil.format( "This is a test \\%1.x", new Object[]
|
||||||
{
|
{
|
||||||
}));
|
} ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
private String fmt(double num, int minIntDigits, int maxFracDigitis)
|
|
||||||
|
private String fmt( double num, int minIntDigits, int maxFracDigitis )
|
||||||
{
|
{
|
||||||
NumberFormat nf = NumberFormat.getInstance();
|
NumberFormat nf = NumberFormat.getInstance();
|
||||||
|
|
||||||
if (minIntDigits != -1)
|
if ( minIntDigits != -1 )
|
||||||
{
|
{
|
||||||
nf.setMinimumIntegerDigits(minIntDigits);
|
nf.setMinimumIntegerDigits( minIntDigits );
|
||||||
}
|
}
|
||||||
if (maxFracDigitis != -1)
|
if ( maxFracDigitis != -1 )
|
||||||
{
|
{
|
||||||
nf.setMaximumFractionDigits(maxFracDigitis);
|
nf.setMaximumFractionDigits( maxFracDigitis );
|
||||||
}
|
}
|
||||||
return nf.format(num);
|
|
||||||
|
return nf.format( num );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* main
|
* main
|
||||||
*
|
*
|
||||||
* @param ignored_args
|
* @param ignored_args
|
||||||
*/
|
*/
|
||||||
|
public static void main( String[] ignored_args )
|
||||||
public static void main(String [] ignored_args)
|
|
||||||
{
|
{
|
||||||
System.out.println("Testing util.StringUtil functionality");
|
System.out.println( "Testing util.StringUtil functionality" );
|
||||||
junit.textui.TestRunner.run(TestStringUtil.class);
|
junit.textui.TestRunner.run( TestStringUtil.class );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see junit.framework.TestCase#setUp()
|
* @see junit.framework.TestCase#setUp()
|
||||||
*/
|
*/
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception
|
||||||
|
{
|
||||||
super.setUp();
|
super.setUp();
|
||||||
// System.setProperty()
|
|
||||||
|
// System.setProperty()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user