<syspropertyset refid="junit.properties"/>
<jvmarg value="-ea"/>
<jvmarg value="-Xmx256m"/>
+ <!-- jvmarg value="-Duser.timezone=UTC"/ -->
<formatter type="plain"/>
<formatter type="xml"/>
<batchtest todir="${main.reports.test}">
<classpath refid="test.scratchpad.classpath"/>
<syspropertyset refid="junit.properties"/>
<jvmarg value="-ea"/>
+ <!-- jvmarg value="-Duser.timezone=UTC"/ -->
<!--
YK: ensure that JUnit has enough memory to run tests.
Without the line below tests fail on Mac OS X with jdk-1.6.26
<syspropertyset refid="junit.properties"/>
<jvmarg value="-Xmx768M"/>
<jvmarg value="-ea"/>
+ <!-- jvmarg value="-Duser.timezone=UTC"/ -->
<formatter type="plain"/>
<formatter type="xml"/>
<batchtest todir="${ooxml.reports.test}">
<fileset dir="${main.output.dir}"/>
<fileset dir="${scratchpad.output.dir}"/>
<fileset dir="${ooxml.output.dir}"/>
- <!--
<fileset dir="${main.output.test.dir}"/>
+ <!--
<fileset dir="${scratchpad.output.test.dir}"/>
<fileset dir="${ooxml.output.test.dir}"/>
-->
public PowerPointExtractor(DirectoryNode dir, POIFSFileSystem fs) throws IOException {
this(new HSLFSlideShowImpl(dir, fs));
}
-
+
/**
* Creates a PowerPointExtractor, from a HSLFSlideShow
*
package org.apache.poi.hslf.extractor;
+import static org.apache.poi.POITestCase.assertContains;
+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.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.List;
import java.util.Locale;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.POITestCase;
import org.apache.poi.hslf.model.OLEShape;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.IOUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests that the extractor correctly gets the text out of our sample file
*/
-public final class TestExtractor extends POITestCase {
+public final class TestExtractor {
/** Extractor primed on the 2 page basic test data */
private PowerPointExtractor ppe;
private static final String expectText = "This is a test title\nThis is a test subtitle\nThis is on page 1\nThis is the title on page 2\nThis is page two\nIt has several blocks of text\nNone of them have formatting\n";
private static final String expectText2 = "Hello, World!!!\nI am just a poor boy\nThis is Times New Roman\nPlain Text \n";
/** Where our embeded files live */
- //private String pdirname;
private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
- //private String pdirname;
- protected void setUp() throws Exception {
- ppe = new PowerPointExtractor(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
- ppe2 = new PowerPointExtractor(slTests.openResourceAsStream("with_textbox.ppt"));
+ @Before
+ public void setUp() throws Exception {
+ ppe = new PowerPointExtractor(slTests.getFile("basic_test_ppt_file.ppt").getCanonicalPath());
+ ppe2 = new PowerPointExtractor(slTests.getFile("with_textbox.ppt").getCanonicalPath());
}
+ @After
+ public void closeResources() throws Exception {
+ ppe2.close();
+ ppe.close();
+ }
+
+ @Test
public void testReadSheetText() {
// Basic 2 page example
String sheetText = ppe.getText();
ensureTwoStringsTheSame(expectText2, sheetText);
}
+ @Test
public void testReadNoteText() {
// Basic 2 page example
String notesText = ppe.getNotes();
- String expectText = "These are the notes for page 1\nThese are the notes on page two, again lacking formatting\n";
+ String expText = "These are the notes for page 1\nThese are the notes on page two, again lacking formatting\n";
- ensureTwoStringsTheSame(expectText, notesText);
+ ensureTwoStringsTheSame(expText, notesText);
// Other one doesn't have notes
notesText = ppe2.getNotes();
- expectText = "";
+ expText = "";
- ensureTwoStringsTheSame(expectText, notesText);
+ ensureTwoStringsTheSame(expText, notesText);
}
+ @Test
public void testReadBoth() {
String[] slText = new String[] {
"This is a test title\nThis is a test subtitle\nThis is on page 1\n",
* core record, we can still get the rest of the text out
* @throws Exception
*/
+ @Test
public void testMissingCoreRecords() throws Exception {
ppe = new PowerPointExtractor(slTests.openResourceAsStream("missing_core_records.ppt"));
assertEquals(exp,act);
}
+ @Test
public void testExtractFromEmbeded() throws Exception {
POIFSFileSystem fs = new POIFSFileSystem(
POIDataSamples.getSpreadSheetInstance().openResourceAsStream("excel_with_embeded.xls")
assertEquals("Sample PowerPoint file\nThis is the 2nd file\nNot much too it either\n",
ppe.getText(true, false)
);
+ fs.close();
}
/**
* A powerpoint file with embeded powerpoint files
*/
@SuppressWarnings("unused")
+ @Test
public void testExtractFromOwnEmbeded() throws Exception {
String path = "ppt_with_embeded.ppt";
ppe = new PowerPointExtractor(POIDataSamples.getSlideShowInstance().openResourceAsStream(path));
if ("Worksheet".equals(name)) {
HSSFWorkbook wb = new HSSFWorkbook(data);
num_xls++;
+ wb.close();
} else if ("Document".equals(name)) {
HWPFDocument doc = new HWPFDocument(data);
num_doc++;
num_ppt++;
HSLFSlideShow ppt = new HSLFSlideShow(data);
}
+ data.close();
}
assertEquals("Expected 2 embedded Word Documents", 2, num_doc);
assertEquals("Expected 2 embedded Excel Spreadsheets", 2, num_xls);
/**
* A powerpoint file with embeded powerpoint files
*/
+ @Test
public void test52991() throws Exception {
String path = "badzip.ppt";
ppe = new PowerPointExtractor(POIDataSamples.getSlideShowInstance().openResourceAsStream(path));
/**
* From bug #45543
*/
+ @Test
public void testWithComments() throws Exception {
ppe = new PowerPointExtractor(slTests.openResourceAsStream("WithComments.ppt"));
/**
* From bug #45537
*/
+ @Test
public void testHeaderFooter() throws Exception {
String text;
}
@SuppressWarnings("unused")
+ @Test
public void testSlideMasterText() throws Exception {
String masterTitleText = "This is the Master Title";
String masterRandomText = "This text comes from the Master Slide";
assertContains(text, masterFooterText);
}
- public void testMasterText() throws Exception {
+ @Test
+ public void testMasterText() throws Exception {
ppe = new PowerPointExtractor(slTests.openResourceAsStream("master_text.ppt"));
// Initially not there
/**
* Bug #54880 Chinese text not extracted properly
*/
+ @Test
public void testChineseText() throws Exception {
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(slTests.openResourceAsStream("54880_chinese.ppt"));
ppe = new PowerPointExtractor(hslf);
* and {@link NPOIFSFileSystem}
*/
@SuppressWarnings("resource")
+ @Test
public void testDifferentPOIFS() throws Exception {
// Open the two filesystems
DirectoryNode[] files = new DirectoryNode[2];
npoifsFileSystem.close();
}
+ @Test
public void testTable() throws Exception{
// ppe = new PowerPointExtractor(slTests.openResourceAsStream("54111.ppt"));
// String text = ppe.getText();
package org.apache.poi.hwpf;
-import junit.framework.Test;
-import junit.framework.TestSuite;
import org.apache.poi.hwpf.converter.AbstractWordUtilsTest;
import org.apache.poi.hwpf.converter.TestWordToFoConverter;
import org.apache.poi.hwpf.converter.TestWordToHtmlConverter;
import org.apache.poi.hwpf.usermodel.TestRangeSymbols;
import org.apache.poi.hwpf.usermodel.TestShapes;
import org.apache.poi.hwpf.usermodel.TestTableRow;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
-public final class AllHWPFTests
-{
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ // org.apache.poi.hwpf
+ TestFieldsTables.class,
+ TestHWPFPictures.class,
+ TestHWPFRangeParts.class,
- public static Test suite()
- {
- TestSuite suite = new TestSuite( AllHWPFTests.class.getName() );
+ // org.apache.poi.hwpf.converter
+ // TestWordToConverterSuite.class,
+ AbstractWordUtilsTest.class,
+ TestWordToFoConverter.class,
+ TestWordToHtmlConverter.class,
- // org.apache.poi.hwpf
- suite.addTestSuite( TestFieldsTables.class );
- suite.addTestSuite( TestHWPFPictures.class );
- suite.addTestSuite( TestHWPFRangeParts.class );
+ // org.apache.poi.hwpf.extractor
+ TestDifferentRoutes.class,
+ TestWordExtractor.class,
+ TestWordExtractorBugs.class,
- // org.apache.poi.hwpf.converter
- // suite.addTestSuite( TestWordToConverterSuite.class );
- suite.addTestSuite( AbstractWordUtilsTest.class );
- suite.addTestSuite( TestWordToFoConverter.class );
- suite.addTestSuite( TestWordToHtmlConverter.class );
+ // org.apache.poi.hwpf.model
+ TestBookmarksTables.class,
+ TestCHPBinTable.class,
+ TestDocumentProperties.class,
+ TestFileInformationBlock.class,
+ TestFontTable.class,
+ TestListTables.class,
+ TestNotesTables.class,
+ TestPAPBinTable.class,
+ TestPlexOfCps.class,
+ TestRevisionMarkAuthorTable.class,
+ TestSavedByTable.class,
+ TestSectionTable.class,
+ TestStyleSheet.class,
+ TestTextPieceTable.class,
- // org.apache.poi.hwpf.extractor
- suite.addTestSuite( TestDifferentRoutes.class );
- suite.addTestSuite( TestWordExtractor.class );
- suite.addTestSuite( TestWordExtractorBugs.class );
+ // org.apache.poi.hwpf.sprm
+ TestSprms.class,
- // org.apache.poi.hwpf.model
- suite.addTestSuite( TestBookmarksTables.class );
- suite.addTestSuite( TestCHPBinTable.class );
- suite.addTestSuite( TestDocumentProperties.class );
- suite.addTestSuite( TestFileInformationBlock.class );
- suite.addTestSuite( TestFontTable.class );
- suite.addTestSuite( TestListTables.class );
- suite.addTestSuite( TestNotesTables.class );
- suite.addTestSuite( TestPAPBinTable.class );
- suite.addTestSuite( TestPlexOfCps.class );
- suite.addTestSuite( TestRevisionMarkAuthorTable.class );
- suite.addTestSuite( TestSavedByTable.class );
- suite.addTestSuite( TestSectionTable.class );
- suite.addTestSuite( TestStyleSheet.class );
- suite.addTestSuite( TestTextPieceTable.class );
-
- // org.apache.poi.hwpf.sprm
- suite.addTestSuite( TestSprms.class );
-
- // org.apache.poi.hwpf.usermodel
- suite.addTestSuite( TestBorderCode.class );
- suite.addTestSuite( TestBug46610.class );
- suite.addTestSuite( TestBug49820.class );
- suite.addTestSuite( TestBug50075.class );
- suite.addTestSuite( TestBugs.class );
- suite.addTestSuite( TestHeaderStories.class );
- suite.addTestSuite( TestHWPFOldDocument.class );
- suite.addTestSuite( TestLists.class );
- suite.addTestSuite( TestPictures.class );
- suite.addTestSuite( TestProblems.class );
- suite.addTestSuite( TestRange.class );
- suite.addTestSuite( TestRangeDelete.class );
- suite.addTestSuite( TestRangeInsertion.class );
- suite.addTestSuite( TestRangeProperties.class );
- suite.addTestSuite( TestRangeReplacement.class );
- suite.addTestSuite( TestRangeSymbols.class );
- suite.addTestSuite( TestShapes.class );
- suite.addTestSuite( TestTableRow.class );
-
- return suite;
- }
+ // org.apache.poi.hwpf.usermodel
+ TestBorderCode.class,
+ TestBug46610.class,
+ TestBug49820.class,
+ TestBug50075.class,
+ TestBugs.class,
+ TestHeaderStories.class,
+ TestHWPFOldDocument.class,
+ TestLists.class,
+ TestPictures.class,
+ TestProblems.class,
+ TestRange.class,
+ TestRangeDelete.class,
+ TestRangeInsertion.class,
+ TestRangeProperties.class,
+ TestRangeReplacement.class,
+ TestRangeSymbols.class,
+ TestShapes.class,
+ TestTableRow.class
+})
+public final class AllHWPFTests {
}
*/
package org.apache.poi.hwpf.converter;
+import static org.apache.poi.POITestCase.assertContains;
+
import java.io.StringWriter;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.stream.StreamResult;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.POITestCase;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.util.XMLHelper;
+import org.junit.Test;
/**
* Test cases for {@link WordToFoConverter}
*/
-public class TestWordToFoConverter extends POITestCase
+public class TestWordToFoConverter
{
private static String getFoText( final String sampleFileName )
throws Exception
return result;
}
+ @Test
public void testDocumentProperties() throws Exception
{
String result = getFoText( "documentProperties.doc" );
"<pdf:Keywords xmlns:pdf=\"http://ns.adobe.com/pdf/1.3/\">This is document keywords</pdf:Keywords>" );
}
+ @Test
public void testEndnote() throws Exception
{
String result = getFoText( "endingnote.doc" );
assertContains( result, "Ending note text" );
}
+ @Test
public void testEquation() throws Exception
{
final String sampleFileName = "equation.doc";
assertContains( result, "<!--Image link to '0.emf' can be here-->" );
}
+ @Test
public void testHyperlink() throws Exception
{
final String sampleFileName = "hyperlink.doc";
assertContains( result, "Hyperlink text" );
}
+ @Test
public void testInnerTable() throws Exception
{
final String sampleFileName = "innertable.doc";
"padding-end=\"0.0in\" padding-start=\"0.0in\" width=\"1.0770833in\"" );
}
+ @Test
public void testPageBreak() throws Exception
{
final String sampleFileName = "page-break.doc";
assertContains( result, "<fo:block break-before=\"page\"" );
}
+ @Test
public void testPageBreakBefore() throws Exception
{
final String sampleFileName = "page-break-before.doc";
assertContains( result, "<fo:block break-before=\"page\"" );
}
+ @Test
public void testPageref() throws Exception
{
final String sampleFileName = "pageref.doc";
==================================================================== */
package org.apache.poi.hwpf.converter;
+import static org.apache.poi.POITestCase.assertContains;
+import static org.junit.Assert.assertFalse;
+
import java.io.StringWriter;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.stream.StreamResult;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.POITestCase;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.PictureType;
import org.apache.poi.util.XMLHelper;
+import org.junit.Test;
import org.w3c.dom.Document;
/**
* Test cases for {@link WordToHtmlConverter}
*/
-public class TestWordToHtmlConverter extends POITestCase
+public class TestWordToHtmlConverter
{
private static String getHtmlText( final String sampleFileName )
throws Exception
return result;
}
+ @Test
public void testAIOOBTap() throws Exception
{
String result = getHtmlText( "AIOOB-Tap.doc");
assertContains(result.substring( 0, 6000 ), "<table class=\"t1\">");
}
+ @Test
public void testBug33519() throws Exception
{
String result = getHtmlText( "Bug33519.doc");
"\u042F\u0432\u043E\u0440 \u0410\u0441\u0435\u043D\u043E\u0432");
}
+ @Test
public void testBug46610_2() throws Exception
{
String result = getHtmlText( "Bug46610_2.doc");
"012345678911234567892123456789312345678941234567890123456789112345678921234567893123456789412345678");
}
+ @Test
public void testBug46817() throws Exception
{
String result = getHtmlText( "Bug46817.doc");
assertContains(result, substring);
}
+ @Test
public void testBug47286() throws Exception
{
String result = getHtmlText( "Bug47286.doc");
assertContains(result, "mfa.gov.cy");
}
+ @Test
public void testBug48075() throws Exception
{
getHtmlText( "Bug48075.doc");
}
+ @Test
public void testBug52583() throws Exception
{
String result = getHtmlText( "Bug52583.doc");
"<select><option selected>riri</option><option>fifi</option><option>loulou</option></select>");
}
+ @Test
public void testBug53182() throws Exception
{
String result = getHtmlText( "Bug53182.doc");
assertFalse(result.contains( "italic" ));
}
+ @Test
public void testDocumentProperties() throws Exception
{
String result = getHtmlText( "documentProperties.doc");
"<meta content=\"This is document keywords\" name=\"keywords\">");
}
+ @Test
public void testEmailhyperlink() throws Exception
{
String result = getHtmlText( "Bug47286.doc");
assertContains(result, substring);
}
+ @Test
public void testEndnote() throws Exception
{
String result = getHtmlText( "endingnote.doc");
assertContains(result, "Ending note text");
}
+ @Test
public void testEquation() throws Exception
{
String result = getHtmlText( "equation.doc");
assertContains(result, "<!--Image link to '0.emf' can be here-->");
}
+ @Test
public void testHyperlink() throws Exception
{
String result = getHtmlText( "hyperlink.doc");
assertContains(result, "</a><span>; after text</span>");
}
+ @Test
public void testInnerTable() throws Exception
{
getHtmlText( "innertable.doc");
}
+ @Test
public void testListsMargins() throws Exception
{
String result = getHtmlText( "lists-margins.doc");
".p4{text-indent:-0.59652776in;margin-left:-0.70069444in;");
}
+ @Test
public void testO_kurs_doc() throws Exception
{
getHtmlText( "o_kurs.doc");
}
+ @Test
public void testPageref() throws Exception
{
String result = getHtmlText( "pageref.doc");
assertContains(result, "1");
}
+ @Test
public void testPicture() throws Exception
{
String result = getHtmlText( "picture.doc", true);
assertContains(result, "width:3.4125in;height:2.325in;");
}
+ @Test
public void testPicturesEscher() throws Exception
{
String result = getHtmlText( "pictures_escher.doc", true);
assertContains(result, "<img src=\"s808.PNG\">");
}
+ @Test
public void testTableMerges() throws Exception
{
String result = getHtmlText( "table-merges.doc");
assertContains(result, "<td class=\"td2\" colspan=\"2\">");
}
+ @Test
public void testBug52420() throws Exception {
String result = getHtmlText( "52420.doc");
package org.apache.poi;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.util.Collection;
-import junit.framework.TestCase;
-
/**
* Parent class for POI JUnit TestCases, which provide additional
* features
*/
-public class POITestCase extends TestCase {
+public class POITestCase {
public static void assertContains(String haystack, String needle) {
assertTrue(
"Unable to find expected text '" + needle + "' in text:\n" + haystack,
);
}
- public static <T> void assertEquals(T[] expected, T[] actual)
- {
- assertEquals("Non-matching lengths", expected.length, actual.length);
- for (int i=0; i<expected.length; i++) {
- assertEquals("Mis-match at offset " + i, expected[i], actual[i]);
- }
- }
- public static void assertEquals(byte[] expected, byte[] actual)
- {
- assertEquals("Non-matching lengths", expected.length, actual.length);
- for (int i=0; i<expected.length; i++) {
- assertEquals("Mis-match at offset " + i, expected[i], actual[i]);
- }
- }
-
public static <T> void assertContains(T needle, T[] haystack)
{
// Check
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.util.IOUtils;
+import org.apache.poi.util.LocaleUtil;
import org.junit.Test;
+@SuppressWarnings("resource")
public class TestEscherDump {
@Test
public void testSimple() throws Exception {
* to redirect stdout to avoid spamming the console with output
*/
private static class NullPrinterStream extends PrintStream {
- private NullPrinterStream() {
- super(new NullOutputStream());
+ private NullPrinterStream() throws UnsupportedEncodingException {
+ super(new NullOutputStream(),true,LocaleUtil.CHARSET_1252.name());
}
/**
* Implementation of an OutputStream which does nothing, used
package org.apache.poi.hpsf.basic;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.util.List;
-import junit.framework.TestCase;
-
import org.apache.poi.POIDataSamples;
import org.apache.poi.hpsf.DocumentSummaryInformation;
import org.apache.poi.hpsf.HPSFException;
import org.apache.poi.hpsf.Section;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hpsf.wellknown.SectionIDMap;
+import org.junit.Before;
+import org.junit.Test;
/**
* <p>Tests the basic HPSF functionality.</p>
*
* @author Rainer Klute (klute@rainer-klute.de)
*/
-public final class TestBasic extends TestCase {
+public final class TestBasic {
private static final String POI_FS = "TestGermanWord90.doc";
private static final String[] POI_FILES = new String[]
* @exception FileNotFoundException if the file to be read does not exist.
* @exception IOException if any other I/O exception occurs.
*/
+ @Before
public void setUp() throws IOException
{
POIDataSamples samples = POIDataSamples.getHPSFInstance();
* <p>Checks the names of the files in the POI filesystem. They
* are expected to be in a certain order.</p>
*/
+ @Test
public void testReadFiles()
{
String[] expected = POI_FILES;
* @exception UnsupportedEncodingException if a character encoding is not
* supported.
*/
+ @Test
public void testCreatePropertySets()
throws UnsupportedEncodingException, IOException
{
* @exception IOException if an I/O exception occurs
* @exception HPSFException if any HPSF exception occurs
*/
+ @Test
public void testPropertySetMethods() throws IOException, HPSFException
{
/* Loop over the two property sets. */
for (int i = 0; i < 2; i++)
{
byte[] b = poiFiles[i].getBytes();
- PropertySet ps =
- PropertySetFactory.create(new ByteArrayInputStream(b));
- assertEquals(ps.getByteOrder(), BYTE_ORDER);
- assertEquals(ps.getFormat(), FORMAT);
- assertEquals(ps.getOSVersion(), OS_VERSION);
- assertEquals(new String(ps.getClassID().getBytes()),
- new String(CLASS_ID));
- assertEquals(ps.getSectionCount(), SECTION_COUNT[i]);
- assertEquals(ps.isSummaryInformation(),
- IS_SUMMARY_INFORMATION[i]);
- assertEquals(ps.isDocumentSummaryInformation(),
- IS_DOCUMENT_SUMMARY_INFORMATION[i]);
+ PropertySet ps = PropertySetFactory.create(new ByteArrayInputStream(b));
+ assertEquals(BYTE_ORDER, ps.getByteOrder());
+ assertEquals(FORMAT, ps.getFormat());
+ assertEquals(OS_VERSION, ps.getOSVersion());
+ assertArrayEquals(CLASS_ID, ps.getClassID().getBytes());
+ assertEquals(SECTION_COUNT[i], ps.getSectionCount());
+ assertEquals(IS_SUMMARY_INFORMATION[i], ps.isSummaryInformation());
+ assertEquals(IS_DOCUMENT_SUMMARY_INFORMATION[i], ps.isDocumentSummaryInformation());
}
}
* @exception IOException if an I/O exception occurs
* @exception HPSFException if any HPSF exception occurs
*/
+ @Test
public void testSectionMethods() throws IOException, HPSFException
{
final SummaryInformation si = (SummaryInformation)
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
+import org.apache.poi.util.LocaleUtil;
public class TestBiffViewer extends BaseXLSIteratingTest {
static {
}
@Override
- void runOneFile(File file) throws IOException {
- NPOIFSFileSystem fs = new NPOIFSFileSystem(file, true);
+ void runOneFile(File fileIn) throws IOException {
+ NPOIFSFileSystem fs = new NPOIFSFileSystem(fileIn, true);
InputStream is = BiffViewer.getPOIFSInputStream(fs);
try {
- // use a NullOutputStream to not write the bytes anywhere for best runtime
- BiffViewer.runBiffViewer(new PrintWriter(NULL_OUTPUT_STREAM), is, true, true, true, false);
+ // use a NullOutputStream to not write the bytes anywhere for best runtime
+ PrintWriter dummy = new PrintWriter(new OutputStreamWriter(NULL_OUTPUT_STREAM, LocaleUtil.CHARSET_1252));
+ BiffViewer.runBiffViewer(dummy, is, true, true, true, false);
} finally {
is.close();
fs.close();
import java.io.IOException;
import java.io.PrintStream;
+import org.apache.poi.util.LocaleUtil;
+
public class TestEFBiffViewer extends BaseXLSIteratingTest {
static {
// these are likely ok to fail
}
@Override
- void runOneFile(File file) throws IOException {
+ void runOneFile(File fileIn) throws IOException {
PrintStream save = System.out;
try {
// redirect standard out during the test to avoid spamming the console with output
- System.setOut(new PrintStream(NULL_OUTPUT_STREAM));
+ System.setOut(new PrintStream(NULL_OUTPUT_STREAM,true,LocaleUtil.CHARSET_1252.name()));
- EFBiffViewer.main(new String[] { file.getAbsolutePath() });
+ EFBiffViewer.main(new String[] { fileIn.getAbsolutePath() });
} finally {
System.setOut(save);
}
import java.io.File;
import java.io.PrintStream;
+import org.apache.poi.util.LocaleUtil;
import org.junit.Ignore;
import org.junit.Test;
public void testMain() throws Exception {
}
- @Override
- void runOneFile(File file) throws Exception {
+ @Override
+ void runOneFile(File fileIn) throws Exception {
PrintStream save = System.out;
try {
// redirect standard out during the test to avoid spamming the console with output
- System.setOut(new PrintStream(NULL_OUTPUT_STREAM));
+ System.setOut(new PrintStream(NULL_OUTPUT_STREAM,true,LocaleUtil.CHARSET_1252.name()));
FormulaViewer viewer = new FormulaViewer();
- viewer.setFile(file.getAbsolutePath());
+ viewer.setFile(fileIn.getAbsolutePath());
viewer.setList(true);
viewer.run();
} finally {
import java.util.List;
import org.apache.poi.POIDataSamples;
+import org.apache.poi.util.LocaleUtil;
public class TestReSave extends BaseXLSIteratingTest {
static {
}
@Override
- void runOneFile(File file) throws Exception {
+ void runOneFile(File fileIn) throws Exception {
// avoid running on files leftover from previous failed runs
- if(file.getName().endsWith("-saved.xls")) {
+ if(fileIn.getName().endsWith("-saved.xls")) {
return;
}
PrintStream save = System.out;
try {
// redirect standard out during the test to avoid spamming the console with output
- System.setOut(new PrintStream(NULL_OUTPUT_STREAM));
+ System.setOut(new PrintStream(NULL_OUTPUT_STREAM,true,LocaleUtil.CHARSET_1252.name()));
- File reSavedFile = new File(file.getParentFile(), file.getName().replace(".xls", "-saved.xls"));
+ File reSavedFile = new File(fileIn.getParentFile(), fileIn.getName().replace(".xls", "-saved.xls"));
try {
- ReSave.main(new String[] { file.getAbsolutePath() });
+ ReSave.main(new String[] { fileIn.getAbsolutePath() });
// also try BiffViewer on the saved file
new TestBiffViewer().runOneFile(reSavedFile);
ReSave.main(new String[] { reSavedFile.getAbsolutePath() });
} finally {
// clean up the re-re-saved file
- new File(file.getParentFile(), reSavedFile.getName().replace(".xls", "-saved.xls")).delete();
+ new File(fileIn.getParentFile(), reSavedFile.getName().replace(".xls", "-saved.xls")).delete();
}
} finally {
// clean up the re-saved file
import java.io.IOException;
import java.io.PrintStream;
+import org.apache.poi.util.LocaleUtil;
+
public class TestRecordLister extends BaseXLSIteratingTest {
static {
// these are likely ok to fail
}
@Override
- void runOneFile(File file) throws IOException {
+ void runOneFile(File fileIn) throws IOException {
PrintStream save = System.out;
try {
// redirect standard out during the test to avoid spamming the console with output
- System.setOut(new PrintStream(NULL_OUTPUT_STREAM));
+ System.setOut(new PrintStream(NULL_OUTPUT_STREAM,true,LocaleUtil.CHARSET_1252.name()));
RecordLister viewer = new RecordLister();
- viewer.setFile(file.getAbsolutePath());
+ viewer.setFile(fileIn.getAbsolutePath());
viewer.run();
} finally {
System.setOut(save);
package org.apache.poi.hssf.extractor;
+import static org.apache.poi.POITestCase.assertContains;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import java.io.File;
-import java.io.InputStream;
-import org.apache.poi.POITestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.junit.Test;
/**
* Unit tests for the Excel 5/95 and Excel 4 (and older) text
* extractor
*/
-public final class TestOldExcelExtractor extends POITestCase {
+public final class TestOldExcelExtractor {
private static OldExcelExtractor createExtractor(String sampleFileName) {
- InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName);
+ File file = HSSFTestDataSamples.getSampleFile(sampleFileName);
try {
- return new OldExcelExtractor(is);
+ return new OldExcelExtractor(file);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
+ @Test
public void testSimpleExcel3() {
OldExcelExtractor extractor = createExtractor("testEXCEL_3.xls");
assertEquals(3, extractor.getBiffVersion());
assertEquals(0x10, extractor.getFileType());
}
+
+ @Test
public void testSimpleExcel4() {
OldExcelExtractor extractor = createExtractor("testEXCEL_4.xls");
assertEquals(4, extractor.getBiffVersion());
assertEquals(0x10, extractor.getFileType());
}
+
+ @Test
public void testSimpleExcel5() {
for (String ver : new String[] {"5", "95"}) {
OldExcelExtractor extractor = createExtractor("testEXCEL_"+ver+".xls");
}
}
+ @Test
public void testStrings() {
OldExcelExtractor extractor = createExtractor("testEXCEL_4.xls");
String text = extractor.getText();
// TODO Find some then test
}
+ @Test
public void testFormattedNumbersExcel4() {
OldExcelExtractor extractor = createExtractor("testEXCEL_4.xls");
String text = extractor.getText();
// assertContains(text, "55,624");
// assertContains(text, "11,743,477");
}
+
+ @Test
public void testFormattedNumbersExcel5() {
for (String ver : new String[] {"5", "95"}) {
OldExcelExtractor extractor = createExtractor("testEXCEL_"+ver+".xls");
}
}
+ @Test
public void testFromFile() throws Exception {
for (String ver : new String[] {"4", "5", "95"}) {
String filename = "testEXCEL_"+ver+".xls";
package org.apache.poi.hssf.model;
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
/**
* Collects all tests for <tt>org.apache.poi.hssf.model</tt>.
- *
- * @author Josh Micich
*/
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ TestDrawingManager.class,
+ TestDrawingManager2.class,
+ TestFormulaParser.class,
+ TestFormulaParserEval.class,
+ TestFormulaParserIf.class,
+ TestLinkTable.class,
+ TestOperandClassTransformer.class,
+ TestRowBlocksReader.class,
+ TestRVA.class,
+ TestSheet.class,
+ TestSheetAdditional.class,
+ TestWorkbook.class
+})
public final class AllModelTests {
-
- public static Test suite() {
- TestSuite result = new TestSuite(AllModelTests.class.getName());
- result.addTestSuite(TestDrawingManager.class);
- result.addTestSuite(TestDrawingManager2.class);
- result.addTestSuite(TestFormulaParser.class);
- result.addTestSuite(TestFormulaParserEval.class);
- result.addTestSuite(TestFormulaParserIf.class);
- result.addTestSuite(TestLinkTable.class);
- result.addTestSuite(TestOperandClassTransformer.class);
- result.addTestSuite(TestRowBlocksReader.class);
- result.addTestSuite(TestRVA.class);
- result.addTestSuite(TestSheet.class);
- result.addTestSuite(TestSheetAdditional.class);
- result.addTestSuite(TestWorkbook.class);
- return result;
- }
}
package org.apache.poi.hssf.model;
-import java.util.Arrays;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
+import java.util.Arrays;
import org.apache.poi.hssf.record.NumberRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.UnknownRecord;
import org.apache.poi.hssf.record.WindowTwoRecord;
import org.apache.poi.hssf.record.pivottable.ViewDefinitionRecord;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
/**
* Tests for {@link RowBlocksReader}
*
* @author Josh Micich
*/
-public final class TestRowBlocksReader extends TestCase {
+public final class TestRowBlocksReader {
+ @Test
public void testAbnormalPivotTableRecords_bug46280() {
int SXVIEW_SID = ViewDefinitionRecord.sid;
Record[] inRecs = {
new RowRecord(0),
new NumberRecord(),
// normally MSODRAWING(0x00EC) would come here before SXVIEW
- new UnknownRecord(SXVIEW_SID, "dummydata (SXVIEW: View Definition)".getBytes()),
+ new UnknownRecord(SXVIEW_SID, "dummydata (SXVIEW: View Definition)".getBytes(LocaleUtil.CHARSET_1252)),
new WindowTwoRecord(),
};
RecordStream rs = new RecordStream(Arrays.asList(inRecs), 0);
RowBlocksReader rbr = new RowBlocksReader(rs);
if (rs.peekNextClass() == WindowTwoRecord.class) {
// Should have stopped at the SXVIEW record
- throw new AssertionFailedError("Identified bug 46280b");
+ fail("Identified bug 46280b");
}
RecordStream rbStream = rbr.getPlainRecordStream();
assertEquals(inRecs[0], rbStream.getNext());
package org.apache.poi.hssf.record;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.util.Arrays;
import java.util.Iterator;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.common.UnicodeString;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.util.HexRead;
import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
+
+import junit.framework.AssertionFailedError;
/**
* @author Marc Johnson (mjohnson at apache dot org)
* @author Glen Stampoultzis (glens at apache.org)
*/
-public final class TestSSTRecord extends TestCase {
+public final class TestSSTRecord {
/**
* decodes hexdump files and concatenates the results
for (int i = 0; i < nFiles; i++) {
String sampleFileName = hexDumpFileNames[i];
InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName);
- BufferedReader br = new BufferedReader(new InputStreamReader(is));
+ BufferedReader br = new BufferedReader(new InputStreamReader(is, LocaleUtil.CHARSET_1252));
while (true) {
String line = br.readLine();
* SST is often split over several {@link ContinueRecord}s
* @throws IOException
*/
+ @Test
public void testContinuedRecord() throws IOException {
byte[] origData;
SSTRecord record;
assertEquals( 5249, record.getNumUniqueStrings() );
assertEquals( 5249, record.countStrings() );
ser_output = record.serialize();
- if (false) { // set true to observe make sure areSameSSTs() is working
- ser_output[11000] = 'X';
- }
+// if (false) { // set true to observe make sure areSameSSTs() is working
+// ser_output[11000] = 'X';
+// }
SSTRecord rec2 = createSSTFromRawData(ser_output);
if (!areSameSSTs(record, rec2)) {
throw new AssertionFailedError("large SST re-serialized incorrectly");
}
- if (false) {
- // TODO - trivial differences in ContinueRecord break locations
- // Sample data should be checked against what most recent Excel version produces.
- // maybe tweaks are required in ContinuableRecordOutput
- assertArrayEquals(origData, ser_output);
- }
+// if (false) {
+// // TODO - trivial differences in ContinueRecord break locations
+// // Sample data should be checked against what most recent Excel version produces.
+// // maybe tweaks are required in ContinuableRecordOutput
+// assertArrayEquals(origData, ser_output);
+// }
}
private boolean areSameSSTs(SSTRecord a, SSTRecord b) {
*
* @exception IOException
*/
-
+ @Test
public void testHugeStrings() {
SSTRecord record = new SSTRecord();
byte[][] bstrings =
for ( int k = 0; k < bstrings.length; k++ )
{
Arrays.fill( bstrings[k], (byte) ( 'a' + k ) );
- strings[k] = new UnicodeString( new String(bstrings[k]) );
+ strings[k] = new UnicodeString( new String(bstrings[k], LocaleUtil.CHARSET_1252) );
record.addString( strings[k] );
total_length += 3 + bstrings[k].length;
}
if ( ( bstrings[k].length % 2 ) == 1 )
{
Arrays.fill( bstrings[k], (byte) ( 'a' + k ) );
- strings[k] = new UnicodeString( new String(bstrings[k]) );
+ strings[k] = new UnicodeString( new String(bstrings[k], LocaleUtil.CHARSET_1252) );
}
else
{
/**
* test SSTRecord boundary conditions
*/
+ @Test
public void testSSTRecordBug() {
// create an SSTRecord and write a certain pattern of strings
// to it ... then serialize it and verify the content
/**
* test simple addString
*/
+ @Test
public void testSimpleAddString() {
SSTRecord record = new SSTRecord();
UnicodeString s1 = new UnicodeString("Hello world");
/**
* test simple constructor
*/
+ @Test
public void testSimpleConstructor() {
SSTRecord record = new SSTRecord();
/**
* Tests that workbooks with rich text that duplicates a non rich text cell can be read and written.
*/
- public void testReadWriteDuplicatedRichText1() {
+ @Test
+ public void testReadWriteDuplicatedRichText1() throws Exception {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("duprich1.xls");
HSSFSheet sheet = wb.getSheetAt( 1 );
assertEquals( "01/05 (Wed)", sheet.getRow( 0 ).getCell(8 ).getStringCellValue() );
assertEquals( "01/05 (Wed)", sheet.getRow( 1 ).getCell(8 ).getStringCellValue() );
- HSSFTestDataSamples.writeOutAndReadBack(wb);
+ HSSFTestDataSamples.writeOutAndReadBack(wb).close();
+
+ wb.close();
// test the second file.
wb = HSSFTestDataSamples.openSampleWorkbook("duprich2.xls");
assertEquals( "Testing", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() );
assertEquals( "Testing", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() );
- HSSFTestDataSamples.writeOutAndReadBack(wb);
+ HSSFTestDataSamples.writeOutAndReadBack(wb).close();
+
+ wb.close();
}
/**
/**
* deep comparison of two SST records
*/
- public static void assertEquals(SSTRecord expected, SSTRecord actual){
+ private static void assertRecordEquals(SSTRecord expected, SSTRecord actual){
assertEquals("number of strings", expected.getNumStrings(), actual.getNumStrings());
assertEquals("number of unique strings", expected.getNumUniqueStrings(), actual.getNumUniqueStrings());
assertEquals("count of strings", expected.countStrings(), actual.countStrings());
assertTrue("String at idx=" + k, us1.equals(us2));
}
}
-
-
+
+ @Test
public void test50779_1(){
byte[] bytes = HexRead.readFromString(data_50779_1);
SSTRecord dst = new SSTRecord(in);
assertEquals(81, dst.getNumStrings());
- assertEquals(src, dst);
+ assertRecordEquals(src, dst);
}
+ @Test
public void test50779_2() {
byte[] bytes = HexRead.readFromString(data_50779_2);
SSTRecord dst = new SSTRecord(in);
assertEquals(81, dst.getNumStrings());
- assertEquals(src, dst);
+ assertRecordEquals(src, dst);
}
+ @Test
public void test57456() {
byte[] bytes = HexRead.readFromString("FC, 00, 08, 00, 00, 00, 00, 00, E1, 06, 00, 00");
RecordInputStream in = TestcaseRecordInputStream.create(bytes);
package org.apache.poi.hssf.record.aggregates;
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
/**
* Collects all tests for package <tt>org.apache.poi.hssf.record.aggregates</tt>.
- *
- * @author Josh Micich
*/
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ TestCFRecordsAggregate.class,
+ TestColumnInfoRecordsAggregate.class,
+ TestFormulaRecordAggregate.class,
+ TestRowRecordsAggregate.class,
+ TestSharedValueManager.class,
+ TestValueRecordsAggregate.class,
+ TestPageSettingsBlock.class
+})
public final class AllRecordAggregateTests {
-
- public static Test suite() {
- TestSuite result = new TestSuite(AllRecordAggregateTests.class.getName());
-
- result.addTestSuite(TestCFRecordsAggregate.class);
- result.addTestSuite(TestColumnInfoRecordsAggregate.class);
- result.addTestSuite(TestFormulaRecordAggregate.class);
- result.addTestSuite(TestRowRecordsAggregate.class);
- result.addTestSuite(TestSharedValueManager.class);
- result.addTestSuite(TestValueRecordsAggregate.class);
- result.addTestSuite(TestPageSettingsBlock.class);
- return result;
- }
}
package org.apache.poi.hssf.record.aggregates;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.Arrays;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
+import java.util.Arrays;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.model.RecordStream;
import org.apache.poi.hssf.usermodel.RecordInspector;
import org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector;
import org.apache.poi.hssf.util.CellRangeAddress8Bit;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
/**
* Tests for {@link RowRecordsAggregate}
*/
-public final class TestRowRecordsAggregate extends TestCase {
+public final class TestRowRecordsAggregate {
+ @Test
public void testRowGet() {
RowRecordsAggregate rra = new RowRecordsAggregate();
RowRecord rr = new RowRecord(4);
* {@link SharedFormulaRecord}s, these records should appear immediately after the first
* {@link FormulaRecord}s that they apply to (and only once).<br/>
*/
- public void testArraysAndTables() {
+ @Test
+ public void testArraysAndTables() throws Exception {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("testArraysAndTables.xls");
Record[] sheetRecs = RecordInspector.getRecords(wb.getSheetAt(0), 0);
assertEquals(0, countSharedFormulas);
- if (false) { // set true to observe re-serialized file
- File f = new File(System.getProperty("java.io.tmpdir") + "/testArraysAndTables-out.xls");
- try {
- OutputStream os = new FileOutputStream(f);
- wb.write(os);
- os.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- System.out.println("Output file to " + f.getAbsolutePath());
- }
+// if (false) { // set true to observe re-serialized file
+// File f = new File(System.getProperty("java.io.tmpdir") + "/testArraysAndTables-out.xls");
+// try {
+// OutputStream os = new FileOutputStream(f);
+// wb.write(os);
+// os.close();
+// } catch (IOException e) {
+// throw new RuntimeException(e);
+// }
+// System.out.println("Output file to " + f.getAbsolutePath());
+// }
+
+ wb.close();
}
- private static int verifySharedValues(Record[] recs, Class shfClass) {
+ private static int verifySharedValues(Record[] recs, Class<? extends SharedValueRecordBase> shfClass) {
int result =0;
for(int i=0; i<recs.length; i++) {
result++;
Record prevRec = recs[i-1];
if (!(prevRec instanceof FormulaRecord)) {
- throw new AssertionFailedError("Bad record order at index "
+ fail("Bad record order at index "
+ i + ": Formula record expected but got ("
+ prevRec.getClass().getName() + ")");
}
* This fix in {@link RowRecordsAggregate} was implemented anyway since any {@link
* UnknownRecord} has the potential of being 'continued'.
*/
+ @Test
public void testUnknownContinue_bug46280() {
Record[] inRecs = {
new RowRecord(0),
new NumberRecord(),
- new UnknownRecord(0x5555, "dummydata".getBytes()),
- new ContinueRecord("moredummydata".getBytes()),
+ new UnknownRecord(0x5555, "dummydata".getBytes(LocaleUtil.CHARSET_1252)),
+ new ContinueRecord("moredummydata".getBytes(LocaleUtil.CHARSET_1252)),
};
RecordStream rs = new RecordStream(Arrays.asList(inRecs), 0);
RowRecordsAggregate rra;
rra = new RowRecordsAggregate(rs, SharedValueManager.createEmpty());
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Unexpected record type")) {
- throw new AssertionFailedError("Identified bug 46280a");
+ fail("Identified bug 46280a");
}
throw e;
}
package org.apache.poi.hssf.usermodel;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
-import junit.framework.TestCase;
-
import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.CreationHelper;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
/**
*
*/
-public final class TestOLE2Embeding extends TestCase {
+public final class TestOLE2Embeding {
- public void testEmbeding() {
+ @Test
+ public void testEmbeding() throws Exception {
// This used to break, until bug #43116 was fixed
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ole2-embedding.xls");
// Check we can get at the Escher layer still
workbook.getAllPictures();
+
+ workbook.close();
}
+ @Test
public void testEmbeddedObjects() throws Exception {
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ole2-embedding.xls");
List<HSSFObjectData> objects = workbook.getAllEmbeddedObjects();
assertEquals("Wrong number of objects", 2, objects.size());
assertEquals("Wrong name for first object", "MBD06CAB431",
- ((HSSFObjectData)
- objects.get(0)).getDirectory().getName());
+ objects.get(0).getDirectory().getName());
assertEquals("Wrong name for second object", "MBD06CAC85A",
- ((HSSFObjectData)
- objects.get(1)).getDirectory().getName());
+ objects.get(1).getDirectory().getName());
+
+ workbook.close();
}
+ @Test
public void testReallyEmbedSomething() throws Exception {
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet sheet = wb.createSheet();
+ HSSFWorkbook wb1 = new HSSFWorkbook();
+ HSSFSheet sheet = wb1.createSheet();
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("logoKarmokar4.png");
byte[] picturePPT = POIDataSamples.getSlideShowInstance().readFile("clock.jpg");
- int imgIdx = wb.addPicture(pictureData, HSSFWorkbook.PICTURE_TYPE_PNG);
+ int imgIdx = wb1.addPicture(pictureData, HSSFWorkbook.PICTURE_TYPE_PNG);
POIFSFileSystem pptPoifs = getSamplePPT();
- int pptIdx = wb.addOlePackage(pptPoifs, "Sample-PPT", "sample.ppt", "sample.ppt");
+ int pptIdx = wb1.addOlePackage(pptPoifs, "Sample-PPT", "sample.ppt", "sample.ppt");
POIFSFileSystem xlsPoifs = getSampleXLS();
- int imgPPT = wb.addPicture(picturePPT, HSSFWorkbook.PICTURE_TYPE_JPEG);
- int xlsIdx = wb.addOlePackage(xlsPoifs, "Sample-XLS", "sample.xls", "sample.xls");
- int txtIdx = wb.addOlePackage(getSampleTXT(), "Sample-TXT", "sample.txt", "sample.txt");
+ int imgPPT = wb1.addPicture(picturePPT, HSSFWorkbook.PICTURE_TYPE_JPEG);
+ int xlsIdx = wb1.addOlePackage(xlsPoifs, "Sample-XLS", "sample.xls", "sample.xls");
+ int txtIdx = wb1.addOlePackage(getSampleTXT(), "Sample-TXT", "sample.txt", "sample.txt");
int rowoffset = 5;
int coloffset = 5;
- CreationHelper ch = wb.getCreationHelper();
+ CreationHelper ch = wb1.getCreationHelper();
HSSFClientAnchor anchor = (HSSFClientAnchor)ch.createClientAnchor();
anchor.setAnchor((short)(2+coloffset), 1+rowoffset, 0, 0, (short)(3+coloffset), 5+rowoffset, 0, 0);
anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE);
circle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_OVAL);
circle.setNoFill(true);
- if (false) {
- FileOutputStream fos = new FileOutputStream("embed.xls");
- wb.write(fos);
- fos.close();
- }
+// if (false) {
+// FileOutputStream fos = new FileOutputStream("embed.xls");
+// wb.write(fos);
+// fos.close();
+// }
- wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
+ HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
+ wb1.close();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- HSSFObjectData od = wb.getAllEmbeddedObjects().get(0);
+ HSSFObjectData od = wb2.getAllEmbeddedObjects().get(0);
Ole10Native ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode)od.getDirectory());
bos.reset();
pptPoifs.writeFilesystem(bos);
assertArrayEquals(ole10.getDataBuffer(), bos.toByteArray());
- od = wb.getAllEmbeddedObjects().get(1);
+ od = wb2.getAllEmbeddedObjects().get(1);
ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode)od.getDirectory());
bos.reset();
xlsPoifs.writeFilesystem(bos);
assertArrayEquals(ole10.getDataBuffer(), bos.toByteArray());
- od = wb.getAllEmbeddedObjects().get(2);
+ od = wb2.getAllEmbeddedObjects().get(2);
ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode)od.getDirectory());
assertArrayEquals(ole10.getDataBuffer(), getSampleTXT());
+ xlsPoifs.close();
+ pptPoifs.close();
+ wb2.close();
}
static POIFSFileSystem getSamplePPT() throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
wb.write(bos);
+ wb.close();
POIFSFileSystem poifs = new POIFSFileSystem(new ByteArrayInputStream(bos.toByteArray()));
return poifs;
}
static byte[] getSampleTXT() {
- return "All your base are belong to us".getBytes();
+ return "All your base are belong to us".getBytes(LocaleUtil.CHARSET_1252);
}
}
\ No newline at end of file
package org.apache.poi.poifs.filesystem;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
import java.io.ByteArrayInputStream;
import java.nio.ByteBuffer;
import java.util.Iterator;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.POITestCase;
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.util.IOUtils;
+import org.junit.Test;
/**
* Tests for the Mini Store in the NIO POIFS
*/
-public final class TestNPOIFSMiniStore extends POITestCase {
+public final class TestNPOIFSMiniStore {
private static final POIDataSamples _inst = POIDataSamples.getPOIFSInstance();
/**
* Check that for a given mini block, we can correctly figure
* out what the next one is
*/
+ @Test
public void testNextBlock() throws Exception {
// It's the same on 512 byte and 4096 byte block files!
NPOIFSFileSystem fsA = new NPOIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
for(int i=181; i<fs.getBigBlockSizeDetails().getBATEntriesPerBlock(); i++) {
assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(i));
}
-
- fs.close();
}
+ fsD.close();
+ fsC.close();
+ fsB.close();
+ fsA.close();
}
/**
* Check we get the right data back for each block
*/
+ @Test
public void testGetBlock() throws Exception {
// It's the same on 512 byte and 4096 byte block files!
NPOIFSFileSystem fsA = new NPOIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
assertEquals((byte)0, b.get());
assertEquals((byte)0, b.get());
}
-
- fs.close();
}
+ fsD.close();
+ fsC.close();
+ fsB.close();
+ fsA.close();
}
/**
* Ask for free blocks where there are some already
* to be had from the SFAT
*/
+ @Test
public void testGetFreeBlockWithSpare() throws Exception {
NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
NPOIFSMiniStore ministore = fs.getMiniStore();
* Ask for free blocks where no free ones exist, and so the
* stream needs to be extended and another SBAT added
*/
+ @Test
public void testGetFreeBlockWithNoneSpare() throws Exception {
NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
NPOIFSMiniStore ministore = fs.getMiniStore();
* Test that we will extend the underlying chain of
* big blocks that make up the ministream as needed
*/
+ @Test
public void testCreateBlockIfNeeded() throws Exception {
NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
NPOIFSMiniStore ministore = fs.getMiniStore();
fs.close();
}
+ @Test
public void testCreateMiniStoreFirst() throws Exception {
NPOIFSFileSystem fs = new NPOIFSFileSystem();
NPOIFSMiniStore ministore = fs.getMiniStore();
byte[] rdata = new byte[data.length];
dis = new DocumentInputStream(entry);
IOUtils.readFully(dis, rdata);
- assertEquals(data, rdata);
+ assertArrayEquals(data, rdata);
dis.close();
entry = (DocumentEntry)fs.getRoot().getEntry("mini2");
rdata = new byte[data.length];
dis = new DocumentInputStream(entry);
IOUtils.readFully(dis, rdata);
- assertEquals(data, rdata);
+ assertArrayEquals(data, rdata);
dis.close();
// Done
fs.close();
}
+ @Test
public void testMultiBlockStream() throws Exception {
byte[] data1B = new byte[63];
byte[] data2B = new byte[64+14];
DocumentInputStream dis = fs.createDocumentInputStream("mini1");
IOUtils.readFully(dis, r1);
dis.close();
- assertEquals(data1B, r1);
+ assertArrayEquals(data1B, r1);
byte[] r2 = new byte[data2B.length];
dis = fs.createDocumentInputStream("mini2");
IOUtils.readFully(dis, r2);
dis.close();
- assertEquals(data2B, r2);
+ assertArrayEquals(data2B, r2);
+ fs.close();
}
}
package org.apache.poi.poifs.property;
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
/**
* Tests for org.apache.poi.poifs.property<br/>
- *
- * @author Josh Micich
*/
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ TestDirectoryProperty.class,
+ TestDocumentProperty.class,
+ TestPropertyFactory.class,
+ TestPropertyTable.class,
+ TestRootProperty.class
+})
public final class AllPOIFSPropertyTests {
-
- public static Test suite() {
- TestSuite result = new TestSuite(AllPOIFSPropertyTests.class.getName());
- result.addTestSuite(TestDirectoryProperty.class);
- result.addTestSuite(TestDocumentProperty.class);
- result.addTestSuite(TestPropertyFactory.class);
- result.addTestSuite(TestPropertyTable.class);
- result.addTestSuite(TestRootProperty.class);
- return result;
- }
}
package org.apache.poi.poifs.property;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.poifs.storage.RawDataUtil;
-
-import junit.framework.TestCase;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
/**
* Class to test DirectoryProperty functionality
- *
- * @author Marc Johnson
*/
-public final class TestDirectoryProperty extends TestCase {
+public final class TestDirectoryProperty {
private DirectoryProperty _property;
private byte[] _testblock;
/**
* Test constructing DirectoryProperty
*/
+ @Test
public void testConstructor() throws IOException {
createBasicDirectoryProperty();
verifyProperty();
/**
* Test pre-write functionality
*/
+ @Test
public void testPreWrite() throws IOException {
createBasicDirectoryProperty();
_property.preWrite();
}
private void verifyChildren(int count) {
- Iterator iter = _property.getChildren();
- List children = new ArrayList();
+ Iterator<Property> iter = _property.getChildren();
+ List<Property> children = new ArrayList<Property>();
while (iter.hasNext())
{
iter = children.iterator();
while (iter.hasNext())
{
- Property child = ( Property ) iter.next();
+ Property child = iter.next();
Child next = child.getNextChild();
if (next != null)
{
_testblock[ index ] = ( byte ) 0;
}
- byte[] name_bytes = name.getBytes();
+ byte[] name_bytes = name.getBytes(LocaleUtil.CHARSET_1252);
for (index = 0; index < limit; index++)
{
}
}
+ @Test
public void testAddChild() throws IOException {
createBasicDirectoryProperty();
_property.addChild(new LocalProperty(1));
_property.addChild(new LocalProperty(3));
}
+ @Test
public void testDeleteChild() throws IOException {
createBasicDirectoryProperty();
Property p1 = new LocalProperty(1);
_property.addChild(new LocalProperty(1));
}
+ @Test
public void testChangeName() throws IOException {
createBasicDirectoryProperty();
Property p1 = new LocalProperty(1);
assertTrue(_property.changeName(p1, originalName));
}
+ @Test
public void testReadingConstructor() {
String[] input = {
"42 00 6F 00 6F 00 74 00 20 00 45 00 6E 00 74 00 72 00 79 00 00 00 00 00 00 00 00 00 00 00 00 00",
import java.io.IOException;
import org.apache.poi.poifs.storage.RawDataUtil;
+import org.apache.poi.util.LocaleUtil;
import junit.framework.TestCase;
{
testblock[ index ] = ( byte ) 0x0;
}
- byte[] name_bytes = name.getBytes();
+ byte[] name_bytes = name.getBytes(LocaleUtil.CHARSET_1252);
for (index = 0; index < limit; index++)
{
package org.apache.poi.poifs.property;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import junit.framework.TestCase;
-
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.poifs.storage.RawDataUtil;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
/**
* Class to test RootProperty functionality
*
* @author Marc Johnson
*/
-public final class TestRootProperty extends TestCase {
+public final class TestRootProperty {
private RootProperty _property;
private byte[] _testblock;
+ @Test
public void testConstructor() throws IOException {
createBasicRootProperty();
verifyProperty();
for (; index < 0x80; index++) {
_testblock[index] = (byte) 0;
}
- byte[] name_bytes = name.getBytes();
+ byte[] name_bytes = name.getBytes(LocaleUtil.CHARSET_1252);
for (index = 0; index < limit; index++) {
_testblock[index * 2] = name_bytes[index];
}
}
+ @Test
public void testSetSize() {
for (int j = 0; j < 10; j++) {
createBasicRootProperty();
}
}
+ @Test
public void testReadingConstructor() {
String[] input = {
"52 00 6F 00 6F 00 74 00 20 00 45 00 6E 00 74 00 72 00 79 00 00 00 00 00 00 00 00 00 00 00 00 00",
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();
}
truthLine = reader.readLine();
}
+ wb.close();
reader.close();
}
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();
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);
// 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);
}
obj[17] = chrs.toString();
format.append("%18$s"+HexDump.EOL);
-
+
String str = String.format(LocaleUtil.getUserLocale(), format.toString(), obj);
strExp.append(str);
}
@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));
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));
@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:;<=>?@"));
}
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
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;
+ }
}
==================================================================== */
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());
assertNotNull(file1);
assertTrue(file1.delete());
- try {
- TempFile.setTempFileCreationStrategy(null);
- fail("Expecting an exception here");
- } catch (IllegalArgumentException e) {
- // expecting an exception here...
- }
+ TempFile.setTempFileCreationStrategy(null);
}
}