You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2015/09/11 02:56:17 UTC
svn commit: r1702356 [2/2] - in /poi/trunk: ./
src/scratchpad/src/org/apache/poi/hslf/extractor/
src/scratchpad/testcases/org/apache/poi/hslf/extractor/
src/scratchpad/testcases/org/apache/poi/hwpf/
src/scratchpad/testcases/org/apache/poi/hwpf/converte...
Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java?rev=1702356&r1=1702355&r2=1702356&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java Fri Sep 11 00:56:16 2015
@@ -17,35 +17,34 @@
package org.apache.poi.ss.usermodel;
+import static org.junit.Assert.assertEquals;
+
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
-import junit.framework.TestCase;
-
import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.DataFormatter;
-import org.apache.poi.ss.usermodel.FormulaEvaluator;
-import org.apache.poi.ss.usermodel.FractionFormat;
-import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
/**
* Tests for the Fraction Formatting part of DataFormatter.
* Largely taken from bug #54686
*/
-public final class TestFractionFormat extends TestCase {
- public void testSingle() throws Exception {
+public final class TestFractionFormat {
+ @Test
+ public void testSingle() throws Exception {
FractionFormat f = new FractionFormat("", "##");
double val = 321.321;
String ret = f.format(val);
assertEquals("26027/81", ret);
}
+ @Test
public void testTruthFile() throws Exception {
File truthFile = HSSFTestDataSamples.getSampleFile("54686_fraction_formats.txt");
- BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(truthFile)));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(truthFile), LocaleUtil.CHARSET_1252));
Workbook wb = HSSFTestDataSamples.openSampleWorkbook("54686_fraction_formats.xls");
Sheet sheet = wb.getSheetAt(0);
DataFormatter formatter = new DataFormatter();
@@ -73,6 +72,7 @@ public final class TestFractionFormat ex
}
truthLine = reader.readLine();
}
+ wb.close();
reader.close();
}
Modified: poi/trunk/src/testcases/org/apache/poi/util/TestHexDump.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/util/TestHexDump.java?rev=1702356&r1=1702355&r2=1702356&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/util/TestHexDump.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/util/TestHexDump.java Fri Sep 11 00:56:16 2015
@@ -28,20 +28,15 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.io.PrintStream;
import java.lang.reflect.Constructor;
import org.junit.Test;
-public final class TestHexDump {
+public class TestHexDump {
@Test
public void testDump() throws IOException {
- byte[] testArray = new byte[ 256 ];
-
- for (int j = 0; j < 256; j++) {
- testArray[ j ] = ( byte ) j;
- }
+ byte[] testArray = testArray();
ByteArrayOutputStream streamAct = new ByteArrayOutputStream();
HexDump.dump(testArray, 0, streamAct, 0);
byte bytesAct[] = streamAct.toByteArray();
@@ -55,7 +50,7 @@ public final class TestHexDump {
HexDump.dump(testArray, 0x10000000L, streamAct, 0);
bytesAct = streamAct.toByteArray();
bytesExp = toHexDump(0x10000000L,0);
-
+
assertEquals("array size mismatch", bytesExp.length, bytesAct.length);
assertArrayEquals("array mismatch", bytesExp, bytesAct);
@@ -108,15 +103,15 @@ public final class TestHexDump {
// verify proper behaviour with empty byte array
streamAct.reset();
HexDump.dump( new byte[0], 0, streamAct, 0 );
- assertEquals( "No Data" + System.getProperty( "line.separator"), streamAct.toString() );
+ assertEquals( "No Data" + System.getProperty( "line.separator"), streamAct.toString(LocaleUtil.CHARSET_1252.name()) );
}
-
+
private byte[] toHexDump(long offset, int index) {
StringBuilder strExp = new StringBuilder(), chrs = new StringBuilder();
Object obj[] = new Object[33];
StringBuilder format = new StringBuilder();
-
+
for (int j = 0; j < 16 && (index + j*16) < 256; j++) {
obj[0] = offset+index+j*16;
chrs.setLength(0);
@@ -133,7 +128,7 @@ public final class TestHexDump {
}
obj[17] = chrs.toString();
format.append("%18$s"+HexDump.EOL);
-
+
String str = String.format(LocaleUtil.getUserLocale(), format.toString(), obj);
strExp.append(str);
}
@@ -144,11 +139,11 @@ public final class TestHexDump {
@Test
public void testToHex() {
assertEquals("000A", HexDump.toHex((short)0xA));
-
+
assertEquals("[]", HexDump.toHex(new short[] { }));
assertEquals("[000A]", HexDump.toHex(new short[] { 0xA }));
assertEquals("[000A, 000B]", HexDump.toHex(new short[] { 0xA, 0xB }));
-
+
assertEquals("0A", HexDump.toHex((byte)0xA));
assertEquals("0000000A", HexDump.toHex(0xA));
@@ -163,9 +158,9 @@ public final class TestHexDump {
assertEquals("0: 0A, 0B\n2: 0C, 0D\n4: 0E, 0F", HexDump.toHex(new byte[] { 0xA, 0xB, 0xC, 0xD, 0xE, 0xF }, 2));
assertEquals("FFFF", HexDump.toHex((short)0xFFFF));
-
+
assertEquals("00000000000004D2", HexDump.toHex(1234l));
-
+
assertEquals("0xFE", HexDump.byteToHex(-2));
assertEquals("0x25", HexDump.byteToHex(37));
assertEquals("0xFFFE", HexDump.shortToHex(-2));
@@ -178,20 +173,15 @@ public final class TestHexDump {
@Test
public void testDumpToString() throws Exception {
- byte[] testArray = new byte[ 256 ];
-
- for (int j = 0; j < 256; j++)
- {
- testArray[ j ] = ( byte ) j;
- }
+ byte[] testArray = testArray();
String dump = HexDump.dump(testArray, 0, 0);
//System.out.println("Hex: \n" + dump);
- assertTrue("Had: \n" + dump,
+ assertTrue("Had: \n" + dump,
dump.contains("0123456789:;<=>?"));
dump = HexDump.dump(testArray, 2, 1);
//System.out.println("Hex: \n" + dump);
- assertTrue("Had: \n" + dump,
+ assertTrue("Had: \n" + dump,
dump.contains("123456789:;<=>?@"));
}
@@ -208,88 +198,48 @@ public final class TestHexDump {
public void testDumpToStringOutOfIndex3() throws Exception {
HexDump.dump(new byte[ 1 ], 0, 1);
}
-
-
- @Test
- public void testDumpToPrintStream() throws IOException {
- byte[] testArray = new byte[ 256 ];
-
- for (int j = 0; j < 256; j++)
- {
- testArray[ j ] = ( byte ) j;
- }
- InputStream in = new ByteArrayInputStream(testArray);
- try {
- ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
- PrintStream out = new PrintStream(byteOut);
- try {
- HexDump.dump(in, out, 0, 256);
- } finally {
- out.close();
- }
-
- String str = new String(byteOut.toByteArray());
- assertTrue("Had: \n" + str,
- str.contains("0123456789:;<=>?"));
- } finally {
- in.close();
- }
-
- in = new ByteArrayInputStream(testArray);
- try {
- ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
- PrintStream out = new PrintStream(byteOut);
- try {
- // test with more than we have
- HexDump.dump(in, out, 0, 1000);
- } finally {
- out.close();
- }
-
- String str = new String(byteOut.toByteArray());
- assertTrue("Had: \n" + str,
- str.contains("0123456789:;<=>?"));
- } finally {
- in.close();
- }
- in = new ByteArrayInputStream(testArray);
- try {
- ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
- PrintStream out = new PrintStream(byteOut);
- try {
- // test with -1
- HexDump.dump(in, out, 0, -1);
- } finally {
- out.close();
- }
-
- String str = new String(byteOut.toByteArray());
- assertTrue("Had: \n" + str,
- str.contains("0123456789:;<=>?"));
- } finally {
- in.close();
- }
-
- in = new ByteArrayInputStream(testArray);
- try {
- ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
- PrintStream out = new PrintStream(byteOut);
- try {
- HexDump.dump(in, out, 1, 235);
- } finally {
- out.close();
- }
-
- String str = new String(byteOut.toByteArray());
- assertTrue("Line contents should be moved by one now, but Had: \n" + str,
+ @Test
+ public void testDumpToPrintStream() throws IOException {
+ byte[] testArray = testArray();
+ ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+ PrintStream out = new PrintStream(byteOut,true,LocaleUtil.CHARSET_1252.name());
+ ByteArrayInputStream byteIn = new ByteArrayInputStream(testArray);
+ byteIn.mark(256);
+ String str;
+
+ byteIn.reset();
+ byteOut.reset();
+ HexDump.dump(byteIn, out, 0, 256);
+ str = new String(byteOut.toByteArray(), LocaleUtil.CHARSET_1252);
+ assertTrue("Had: \n" + str, str.contains("0123456789:;<=>?"));
+
+ // test with more than we have
+ byteIn.reset();
+ byteOut.reset();
+ HexDump.dump(byteIn, out, 0, 1000);
+ str = new String(byteOut.toByteArray(), LocaleUtil.CHARSET_1252);
+ assertTrue("Had: \n" + str, str.contains("0123456789:;<=>?"));
+
+ // test with -1
+ byteIn.reset();
+ byteOut.reset();
+ HexDump.dump(byteIn, out, 0, -1);
+ str = new String(byteOut.toByteArray(), LocaleUtil.CHARSET_1252);
+ assertTrue("Had: \n" + str, str.contains("0123456789:;<=>?"));
+
+ byteIn.reset();
+ byteOut.reset();
+ HexDump.dump(byteIn, out, 1, 235);
+ str = new String(byteOut.toByteArray(), LocaleUtil.CHARSET_1252);
+ assertTrue("Line contents should be moved by one now, but Had: \n" + str,
str.contains("123456789:;<=>?@"));
- } finally {
- in.close();
- }
+
+ byteIn.close();
+ byteOut.close();
}
-
+
@Test
public void testConstruct() throws Exception {
// to cover private constructor
@@ -300,25 +250,35 @@ public final class TestHexDump {
c.setAccessible(true);
// call it
- assertNotNull(c.newInstance((Object[]) null));
+ assertNotNull(c.newInstance((Object[]) null));
}
-
+
@Test
public void testMain() throws Exception {
File file = TempFile.createTempFile("HexDump", ".dat");
try {
FileOutputStream out = new FileOutputStream(file);
try {
- IOUtils.copy(new ByteArrayInputStream("teststring".getBytes()), out);
+ IOUtils.copy(new ByteArrayInputStream("teststring".getBytes(LocaleUtil.CHARSET_1252)), out);
} finally {
out.close();
}
assertTrue(file.exists());
assertTrue(file.length() > 0);
-
+
HexDump.main(new String[] { file.getAbsolutePath() });
} finally {
assertTrue(file.exists() && file.delete());
}
}
+
+ private static byte[] testArray() {
+ byte[] testArray = new byte[ 256 ];
+
+ for (int j = 0; j < 256; j++) {
+ testArray[ j ] = ( byte ) j;
+ }
+
+ return testArray;
+ }
}
Modified: poi/trunk/src/testcases/org/apache/poi/util/TestTempFile.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/util/TestTempFile.java?rev=1702356&r1=1702355&r2=1702356&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/util/TestTempFile.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/util/TestTempFile.java Fri Sep 11 00:56:16 2015
@@ -16,36 +16,42 @@
==================================================================== */
package org.apache.poi.util;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
+import org.junit.Test;
+
/**
* @author Glen Stampoultzis
*/
-public class TestTempFile extends TestCase {
- TempFile tempFile;
-
+public class TestTempFile {
+ @Test
public void testCreateTempFile()
throws Exception
{
File tempFile = TempFile.createTempFile("test", ".txt");
- FileWriter w = new FileWriter(tempFile);
- w.write("testing");
- w.close();
+ FileOutputStream fos = new FileOutputStream(tempFile);
+ fos.write(1);
+ fos.close();
assertTrue(tempFile.exists());
assertEquals("poifiles", tempFile.getParentFile().getName());
// Can't think of a good way to check whether a file is actually deleted since it would require the VM to stop.
}
+ @Test
public void testConstructor() {
// can currently be constructed...
new TempFile();
}
+ @Test(expected=IllegalArgumentException.class)
public void testSetTempFileCreationStrategy() throws IOException {
TempFile.setTempFileCreationStrategy(new TempFile.DefaultTempFileCreationStrategy());
@@ -57,11 +63,6 @@ public class TestTempFile extends TestCa
assertNotNull(file1);
assertTrue(file1.delete());
- try {
- TempFile.setTempFileCreationStrategy(null);
- fail("Expecting an exception here");
- } catch (IllegalArgumentException e) {
- // expecting an exception here...
- }
+ TempFile.setTempFileCreationStrategy(null);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org