More forbidden apis fixes (added main-tests to the check)
and a few junit4 upgrades ... hopefully this doesn't crash the build again ... :| to simulate the tests on jenkins on the local developer box, uncomment the UTC lines in the build.xml git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1702356 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c21b7bc4d1
commit
fec6b40606
@ -1025,6 +1025,7 @@ under the License.
|
|||||||
<syspropertyset refid="junit.properties"/>
|
<syspropertyset refid="junit.properties"/>
|
||||||
<jvmarg value="-ea"/>
|
<jvmarg value="-ea"/>
|
||||||
<jvmarg value="-Xmx256m"/>
|
<jvmarg value="-Xmx256m"/>
|
||||||
|
<!-- jvmarg value="-Duser.timezone=UTC"/ -->
|
||||||
<formatter type="plain"/>
|
<formatter type="plain"/>
|
||||||
<formatter type="xml"/>
|
<formatter type="xml"/>
|
||||||
<batchtest todir="${main.reports.test}">
|
<batchtest todir="${main.reports.test}">
|
||||||
@ -1065,6 +1066,7 @@ under the License.
|
|||||||
<classpath refid="test.scratchpad.classpath"/>
|
<classpath refid="test.scratchpad.classpath"/>
|
||||||
<syspropertyset refid="junit.properties"/>
|
<syspropertyset refid="junit.properties"/>
|
||||||
<jvmarg value="-ea"/>
|
<jvmarg value="-ea"/>
|
||||||
|
<!-- jvmarg value="-Duser.timezone=UTC"/ -->
|
||||||
<!--
|
<!--
|
||||||
YK: ensure that JUnit has enough memory to run tests.
|
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
|
Without the line below tests fail on Mac OS X with jdk-1.6.26
|
||||||
@ -1107,6 +1109,7 @@ under the License.
|
|||||||
<syspropertyset refid="junit.properties"/>
|
<syspropertyset refid="junit.properties"/>
|
||||||
<jvmarg value="-Xmx768M"/>
|
<jvmarg value="-Xmx768M"/>
|
||||||
<jvmarg value="-ea"/>
|
<jvmarg value="-ea"/>
|
||||||
|
<!-- jvmarg value="-Duser.timezone=UTC"/ -->
|
||||||
<formatter type="plain"/>
|
<formatter type="plain"/>
|
||||||
<formatter type="xml"/>
|
<formatter type="xml"/>
|
||||||
<batchtest todir="${ooxml.reports.test}">
|
<batchtest todir="${ooxml.reports.test}">
|
||||||
@ -1747,8 +1750,8 @@ under the License.
|
|||||||
<fileset dir="${main.output.dir}"/>
|
<fileset dir="${main.output.dir}"/>
|
||||||
<fileset dir="${scratchpad.output.dir}"/>
|
<fileset dir="${scratchpad.output.dir}"/>
|
||||||
<fileset dir="${ooxml.output.dir}"/>
|
<fileset dir="${ooxml.output.dir}"/>
|
||||||
<!--
|
|
||||||
<fileset dir="${main.output.test.dir}"/>
|
<fileset dir="${main.output.test.dir}"/>
|
||||||
|
<!--
|
||||||
<fileset dir="${scratchpad.output.test.dir}"/>
|
<fileset dir="${scratchpad.output.test.dir}"/>
|
||||||
<fileset dir="${ooxml.output.test.dir}"/>
|
<fileset dir="${ooxml.output.test.dir}"/>
|
||||||
-->
|
-->
|
||||||
|
@ -124,7 +124,7 @@ public final class PowerPointExtractor extends POIOLE2TextExtractor {
|
|||||||
public PowerPointExtractor(DirectoryNode dir, POIFSFileSystem fs) throws IOException {
|
public PowerPointExtractor(DirectoryNode dir, POIFSFileSystem fs) throws IOException {
|
||||||
this(new HSLFSlideShowImpl(dir, fs));
|
this(new HSLFSlideShowImpl(dir, fs));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a PowerPointExtractor, from a HSLFSlideShow
|
* Creates a PowerPointExtractor, from a HSLFSlideShow
|
||||||
*
|
*
|
||||||
|
@ -17,13 +17,18 @@
|
|||||||
|
|
||||||
package org.apache.poi.hslf.extractor;
|
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.ByteArrayOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.POITestCase;
|
|
||||||
import org.apache.poi.hslf.model.OLEShape;
|
import org.apache.poi.hslf.model.OLEShape;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
|
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
|
||||||
@ -33,11 +38,14 @@ import org.apache.poi.poifs.filesystem.DirectoryNode;
|
|||||||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
import org.apache.poi.util.IOUtils;
|
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
|
* 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 */
|
/** Extractor primed on the 2 page basic test data */
|
||||||
private PowerPointExtractor ppe;
|
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 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";
|
||||||
@ -47,15 +55,21 @@ public final class TestExtractor extends POITestCase {
|
|||||||
private static final String expectText2 = "Hello, World!!!\nI am just a poor boy\nThis is Times New Roman\nPlain Text \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 */
|
/** Where our embeded files live */
|
||||||
//private String pdirname;
|
|
||||||
private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
||||||
//private String pdirname;
|
|
||||||
|
|
||||||
protected void setUp() throws Exception {
|
@Before
|
||||||
ppe = new PowerPointExtractor(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
|
public void setUp() throws Exception {
|
||||||
ppe2 = new PowerPointExtractor(slTests.openResourceAsStream("with_textbox.ppt"));
|
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() {
|
public void testReadSheetText() {
|
||||||
// Basic 2 page example
|
// Basic 2 page example
|
||||||
String sheetText = ppe.getText();
|
String sheetText = ppe.getText();
|
||||||
@ -69,20 +83,22 @@ public final class TestExtractor extends POITestCase {
|
|||||||
ensureTwoStringsTheSame(expectText2, sheetText);
|
ensureTwoStringsTheSame(expectText2, sheetText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testReadNoteText() {
|
public void testReadNoteText() {
|
||||||
// Basic 2 page example
|
// Basic 2 page example
|
||||||
String notesText = ppe.getNotes();
|
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
|
// Other one doesn't have notes
|
||||||
notesText = ppe2.getNotes();
|
notesText = ppe2.getNotes();
|
||||||
expectText = "";
|
expText = "";
|
||||||
|
|
||||||
ensureTwoStringsTheSame(expectText, notesText);
|
ensureTwoStringsTheSame(expText, notesText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testReadBoth() {
|
public void testReadBoth() {
|
||||||
String[] slText = new String[] {
|
String[] slText = new String[] {
|
||||||
"This is a test title\nThis is a test subtitle\nThis is on page 1\n",
|
"This is a test title\nThis is a test subtitle\nThis is on page 1\n",
|
||||||
@ -111,6 +127,7 @@ public final class TestExtractor extends POITestCase {
|
|||||||
* core record, we can still get the rest of the text out
|
* core record, we can still get the rest of the text out
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testMissingCoreRecords() throws Exception {
|
public void testMissingCoreRecords() throws Exception {
|
||||||
ppe = new PowerPointExtractor(slTests.openResourceAsStream("missing_core_records.ppt"));
|
ppe = new PowerPointExtractor(slTests.openResourceAsStream("missing_core_records.ppt"));
|
||||||
|
|
||||||
@ -137,6 +154,7 @@ public final class TestExtractor extends POITestCase {
|
|||||||
assertEquals(exp,act);
|
assertEquals(exp,act);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testExtractFromEmbeded() throws Exception {
|
public void testExtractFromEmbeded() throws Exception {
|
||||||
POIFSFileSystem fs = new POIFSFileSystem(
|
POIFSFileSystem fs = new POIFSFileSystem(
|
||||||
POIDataSamples.getSpreadSheetInstance().openResourceAsStream("excel_with_embeded.xls")
|
POIDataSamples.getSpreadSheetInstance().openResourceAsStream("excel_with_embeded.xls")
|
||||||
@ -164,12 +182,14 @@ public final class TestExtractor extends POITestCase {
|
|||||||
assertEquals("Sample PowerPoint file\nThis is the 2nd file\nNot much too it either\n",
|
assertEquals("Sample PowerPoint file\nThis is the 2nd file\nNot much too it either\n",
|
||||||
ppe.getText(true, false)
|
ppe.getText(true, false)
|
||||||
);
|
);
|
||||||
|
fs.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A powerpoint file with embeded powerpoint files
|
* A powerpoint file with embeded powerpoint files
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
@Test
|
||||||
public void testExtractFromOwnEmbeded() throws Exception {
|
public void testExtractFromOwnEmbeded() throws Exception {
|
||||||
String path = "ppt_with_embeded.ppt";
|
String path = "ppt_with_embeded.ppt";
|
||||||
ppe = new PowerPointExtractor(POIDataSamples.getSlideShowInstance().openResourceAsStream(path));
|
ppe = new PowerPointExtractor(POIDataSamples.getSlideShowInstance().openResourceAsStream(path));
|
||||||
@ -182,6 +202,7 @@ public final class TestExtractor extends POITestCase {
|
|||||||
if ("Worksheet".equals(name)) {
|
if ("Worksheet".equals(name)) {
|
||||||
HSSFWorkbook wb = new HSSFWorkbook(data);
|
HSSFWorkbook wb = new HSSFWorkbook(data);
|
||||||
num_xls++;
|
num_xls++;
|
||||||
|
wb.close();
|
||||||
} else if ("Document".equals(name)) {
|
} else if ("Document".equals(name)) {
|
||||||
HWPFDocument doc = new HWPFDocument(data);
|
HWPFDocument doc = new HWPFDocument(data);
|
||||||
num_doc++;
|
num_doc++;
|
||||||
@ -189,6 +210,7 @@ public final class TestExtractor extends POITestCase {
|
|||||||
num_ppt++;
|
num_ppt++;
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(data);
|
HSLFSlideShow ppt = new HSLFSlideShow(data);
|
||||||
}
|
}
|
||||||
|
data.close();
|
||||||
}
|
}
|
||||||
assertEquals("Expected 2 embedded Word Documents", 2, num_doc);
|
assertEquals("Expected 2 embedded Word Documents", 2, num_doc);
|
||||||
assertEquals("Expected 2 embedded Excel Spreadsheets", 2, num_xls);
|
assertEquals("Expected 2 embedded Excel Spreadsheets", 2, num_xls);
|
||||||
@ -198,6 +220,7 @@ public final class TestExtractor extends POITestCase {
|
|||||||
/**
|
/**
|
||||||
* A powerpoint file with embeded powerpoint files
|
* A powerpoint file with embeded powerpoint files
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void test52991() throws Exception {
|
public void test52991() throws Exception {
|
||||||
String path = "badzip.ppt";
|
String path = "badzip.ppt";
|
||||||
ppe = new PowerPointExtractor(POIDataSamples.getSlideShowInstance().openResourceAsStream(path));
|
ppe = new PowerPointExtractor(POIDataSamples.getSlideShowInstance().openResourceAsStream(path));
|
||||||
@ -211,6 +234,7 @@ public final class TestExtractor extends POITestCase {
|
|||||||
/**
|
/**
|
||||||
* From bug #45543
|
* From bug #45543
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testWithComments() throws Exception {
|
public void testWithComments() throws Exception {
|
||||||
ppe = new PowerPointExtractor(slTests.openResourceAsStream("WithComments.ppt"));
|
ppe = new PowerPointExtractor(slTests.openResourceAsStream("WithComments.ppt"));
|
||||||
|
|
||||||
@ -238,6 +262,7 @@ public final class TestExtractor extends POITestCase {
|
|||||||
/**
|
/**
|
||||||
* From bug #45537
|
* From bug #45537
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testHeaderFooter() throws Exception {
|
public void testHeaderFooter() throws Exception {
|
||||||
String text;
|
String text;
|
||||||
|
|
||||||
@ -278,6 +303,7 @@ public final class TestExtractor extends POITestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
@Test
|
||||||
public void testSlideMasterText() throws Exception {
|
public void testSlideMasterText() throws Exception {
|
||||||
String masterTitleText = "This is the Master Title";
|
String masterTitleText = "This is the Master Title";
|
||||||
String masterRandomText = "This text comes from the Master Slide";
|
String masterRandomText = "This text comes from the Master Slide";
|
||||||
@ -292,7 +318,8 @@ public final class TestExtractor extends POITestCase {
|
|||||||
assertContains(text, masterFooterText);
|
assertContains(text, masterFooterText);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMasterText() throws Exception {
|
@Test
|
||||||
|
public void testMasterText() throws Exception {
|
||||||
ppe = new PowerPointExtractor(slTests.openResourceAsStream("master_text.ppt"));
|
ppe = new PowerPointExtractor(slTests.openResourceAsStream("master_text.ppt"));
|
||||||
|
|
||||||
// Initially not there
|
// Initially not there
|
||||||
@ -322,6 +349,7 @@ public final class TestExtractor extends POITestCase {
|
|||||||
/**
|
/**
|
||||||
* Bug #54880 Chinese text not extracted properly
|
* Bug #54880 Chinese text not extracted properly
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testChineseText() throws Exception {
|
public void testChineseText() throws Exception {
|
||||||
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(slTests.openResourceAsStream("54880_chinese.ppt"));
|
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(slTests.openResourceAsStream("54880_chinese.ppt"));
|
||||||
ppe = new PowerPointExtractor(hslf);
|
ppe = new PowerPointExtractor(hslf);
|
||||||
@ -346,6 +374,7 @@ public final class TestExtractor extends POITestCase {
|
|||||||
* and {@link NPOIFSFileSystem}
|
* and {@link NPOIFSFileSystem}
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
|
@Test
|
||||||
public void testDifferentPOIFS() throws Exception {
|
public void testDifferentPOIFS() throws Exception {
|
||||||
// Open the two filesystems
|
// Open the two filesystems
|
||||||
DirectoryNode[] files = new DirectoryNode[2];
|
DirectoryNode[] files = new DirectoryNode[2];
|
||||||
@ -369,6 +398,7 @@ public final class TestExtractor extends POITestCase {
|
|||||||
npoifsFileSystem.close();
|
npoifsFileSystem.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTable() throws Exception{
|
public void testTable() throws Exception{
|
||||||
// ppe = new PowerPointExtractor(slTests.openResourceAsStream("54111.ppt"));
|
// ppe = new PowerPointExtractor(slTests.openResourceAsStream("54111.ppt"));
|
||||||
// String text = ppe.getText();
|
// String text = ppe.getText();
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
|
|
||||||
package org.apache.poi.hwpf;
|
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.AbstractWordUtilsTest;
|
||||||
import org.apache.poi.hwpf.converter.TestWordToFoConverter;
|
import org.apache.poi.hwpf.converter.TestWordToFoConverter;
|
||||||
import org.apache.poi.hwpf.converter.TestWordToHtmlConverter;
|
import org.apache.poi.hwpf.converter.TestWordToHtmlConverter;
|
||||||
@ -58,69 +56,65 @@ import org.apache.poi.hwpf.usermodel.TestRangeReplacement;
|
|||||||
import org.apache.poi.hwpf.usermodel.TestRangeSymbols;
|
import org.apache.poi.hwpf.usermodel.TestRangeSymbols;
|
||||||
import org.apache.poi.hwpf.usermodel.TestShapes;
|
import org.apache.poi.hwpf.usermodel.TestShapes;
|
||||||
import org.apache.poi.hwpf.usermodel.TestTableRow;
|
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()
|
// org.apache.poi.hwpf.converter
|
||||||
{
|
// TestWordToConverterSuite.class,
|
||||||
TestSuite suite = new TestSuite( AllHWPFTests.class.getName() );
|
AbstractWordUtilsTest.class,
|
||||||
|
TestWordToFoConverter.class,
|
||||||
|
TestWordToHtmlConverter.class,
|
||||||
|
|
||||||
// org.apache.poi.hwpf
|
// org.apache.poi.hwpf.extractor
|
||||||
suite.addTestSuite( TestFieldsTables.class );
|
TestDifferentRoutes.class,
|
||||||
suite.addTestSuite( TestHWPFPictures.class );
|
TestWordExtractor.class,
|
||||||
suite.addTestSuite( TestHWPFRangeParts.class );
|
TestWordExtractorBugs.class,
|
||||||
|
|
||||||
// org.apache.poi.hwpf.converter
|
// org.apache.poi.hwpf.model
|
||||||
// suite.addTestSuite( TestWordToConverterSuite.class );
|
TestBookmarksTables.class,
|
||||||
suite.addTestSuite( AbstractWordUtilsTest.class );
|
TestCHPBinTable.class,
|
||||||
suite.addTestSuite( TestWordToFoConverter.class );
|
TestDocumentProperties.class,
|
||||||
suite.addTestSuite( TestWordToHtmlConverter.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
|
// org.apache.poi.hwpf.sprm
|
||||||
suite.addTestSuite( TestDifferentRoutes.class );
|
TestSprms.class,
|
||||||
suite.addTestSuite( TestWordExtractor.class );
|
|
||||||
suite.addTestSuite( TestWordExtractorBugs.class );
|
|
||||||
|
|
||||||
// org.apache.poi.hwpf.model
|
// org.apache.poi.hwpf.usermodel
|
||||||
suite.addTestSuite( TestBookmarksTables.class );
|
TestBorderCode.class,
|
||||||
suite.addTestSuite( TestCHPBinTable.class );
|
TestBug46610.class,
|
||||||
suite.addTestSuite( TestDocumentProperties.class );
|
TestBug49820.class,
|
||||||
suite.addTestSuite( TestFileInformationBlock.class );
|
TestBug50075.class,
|
||||||
suite.addTestSuite( TestFontTable.class );
|
TestBugs.class,
|
||||||
suite.addTestSuite( TestListTables.class );
|
TestHeaderStories.class,
|
||||||
suite.addTestSuite( TestNotesTables.class );
|
TestHWPFOldDocument.class,
|
||||||
suite.addTestSuite( TestPAPBinTable.class );
|
TestLists.class,
|
||||||
suite.addTestSuite( TestPlexOfCps.class );
|
TestPictures.class,
|
||||||
suite.addTestSuite( TestRevisionMarkAuthorTable.class );
|
TestProblems.class,
|
||||||
suite.addTestSuite( TestSavedByTable.class );
|
TestRange.class,
|
||||||
suite.addTestSuite( TestSectionTable.class );
|
TestRangeDelete.class,
|
||||||
suite.addTestSuite( TestStyleSheet.class );
|
TestRangeInsertion.class,
|
||||||
suite.addTestSuite( TestTextPieceTable.class );
|
TestRangeProperties.class,
|
||||||
|
TestRangeReplacement.class,
|
||||||
// org.apache.poi.hwpf.sprm
|
TestRangeSymbols.class,
|
||||||
suite.addTestSuite( TestSprms.class );
|
TestShapes.class,
|
||||||
|
TestTableRow.class
|
||||||
// org.apache.poi.hwpf.usermodel
|
})
|
||||||
suite.addTestSuite( TestBorderCode.class );
|
public final class AllHWPFTests {
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.poi.hwpf.converter;
|
package org.apache.poi.hwpf.converter;
|
||||||
|
|
||||||
|
import static org.apache.poi.POITestCase.assertContains;
|
||||||
|
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
|
||||||
import javax.xml.transform.OutputKeys;
|
import javax.xml.transform.OutputKeys;
|
||||||
@ -27,14 +29,14 @@ import javax.xml.transform.dom.DOMSource;
|
|||||||
import javax.xml.transform.stream.StreamResult;
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.POITestCase;
|
|
||||||
import org.apache.poi.hwpf.HWPFDocument;
|
import org.apache.poi.hwpf.HWPFDocument;
|
||||||
import org.apache.poi.util.XMLHelper;
|
import org.apache.poi.util.XMLHelper;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test cases for {@link WordToFoConverter}
|
* Test cases for {@link WordToFoConverter}
|
||||||
*/
|
*/
|
||||||
public class TestWordToFoConverter extends POITestCase
|
public class TestWordToFoConverter
|
||||||
{
|
{
|
||||||
private static String getFoText( final String sampleFileName )
|
private static String getFoText( final String sampleFileName )
|
||||||
throws Exception
|
throws Exception
|
||||||
@ -59,6 +61,7 @@ public class TestWordToFoConverter extends POITestCase
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDocumentProperties() throws Exception
|
public void testDocumentProperties() throws Exception
|
||||||
{
|
{
|
||||||
String result = getFoText( "documentProperties.doc" );
|
String result = getFoText( "documentProperties.doc" );
|
||||||
@ -71,6 +74,7 @@ public class TestWordToFoConverter extends POITestCase
|
|||||||
"<pdf:Keywords xmlns:pdf=\"http://ns.adobe.com/pdf/1.3/\">This is document keywords</pdf:Keywords>" );
|
"<pdf:Keywords xmlns:pdf=\"http://ns.adobe.com/pdf/1.3/\">This is document keywords</pdf:Keywords>" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEndnote() throws Exception
|
public void testEndnote() throws Exception
|
||||||
{
|
{
|
||||||
String result = getFoText( "endingnote.doc" );
|
String result = getFoText( "endingnote.doc" );
|
||||||
@ -86,6 +90,7 @@ public class TestWordToFoConverter extends POITestCase
|
|||||||
assertContains( result, "Ending note text" );
|
assertContains( result, "Ending note text" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEquation() throws Exception
|
public void testEquation() throws Exception
|
||||||
{
|
{
|
||||||
final String sampleFileName = "equation.doc";
|
final String sampleFileName = "equation.doc";
|
||||||
@ -94,6 +99,7 @@ public class TestWordToFoConverter extends POITestCase
|
|||||||
assertContains( result, "<!--Image link to '0.emf' can be here-->" );
|
assertContains( result, "<!--Image link to '0.emf' can be here-->" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testHyperlink() throws Exception
|
public void testHyperlink() throws Exception
|
||||||
{
|
{
|
||||||
final String sampleFileName = "hyperlink.doc";
|
final String sampleFileName = "hyperlink.doc";
|
||||||
@ -104,6 +110,7 @@ public class TestWordToFoConverter extends POITestCase
|
|||||||
assertContains( result, "Hyperlink text" );
|
assertContains( result, "Hyperlink text" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testInnerTable() throws Exception
|
public void testInnerTable() throws Exception
|
||||||
{
|
{
|
||||||
final String sampleFileName = "innertable.doc";
|
final String sampleFileName = "innertable.doc";
|
||||||
@ -113,6 +120,7 @@ public class TestWordToFoConverter extends POITestCase
|
|||||||
"padding-end=\"0.0in\" padding-start=\"0.0in\" width=\"1.0770833in\"" );
|
"padding-end=\"0.0in\" padding-start=\"0.0in\" width=\"1.0770833in\"" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPageBreak() throws Exception
|
public void testPageBreak() throws Exception
|
||||||
{
|
{
|
||||||
final String sampleFileName = "page-break.doc";
|
final String sampleFileName = "page-break.doc";
|
||||||
@ -121,6 +129,7 @@ public class TestWordToFoConverter extends POITestCase
|
|||||||
assertContains( result, "<fo:block break-before=\"page\"" );
|
assertContains( result, "<fo:block break-before=\"page\"" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPageBreakBefore() throws Exception
|
public void testPageBreakBefore() throws Exception
|
||||||
{
|
{
|
||||||
final String sampleFileName = "page-break-before.doc";
|
final String sampleFileName = "page-break-before.doc";
|
||||||
@ -129,6 +138,7 @@ public class TestWordToFoConverter extends POITestCase
|
|||||||
assertContains( result, "<fo:block break-before=\"page\"" );
|
assertContains( result, "<fo:block break-before=\"page\"" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPageref() throws Exception
|
public void testPageref() throws Exception
|
||||||
{
|
{
|
||||||
final String sampleFileName = "pageref.doc";
|
final String sampleFileName = "pageref.doc";
|
||||||
|
@ -16,6 +16,9 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.hwpf.converter;
|
package org.apache.poi.hwpf.converter;
|
||||||
|
|
||||||
|
import static org.apache.poi.POITestCase.assertContains;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
|
||||||
import javax.xml.transform.OutputKeys;
|
import javax.xml.transform.OutputKeys;
|
||||||
@ -25,16 +28,16 @@ import javax.xml.transform.dom.DOMSource;
|
|||||||
import javax.xml.transform.stream.StreamResult;
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.POITestCase;
|
|
||||||
import org.apache.poi.hwpf.HWPFDocument;
|
import org.apache.poi.hwpf.HWPFDocument;
|
||||||
import org.apache.poi.hwpf.usermodel.PictureType;
|
import org.apache.poi.hwpf.usermodel.PictureType;
|
||||||
import org.apache.poi.util.XMLHelper;
|
import org.apache.poi.util.XMLHelper;
|
||||||
|
import org.junit.Test;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test cases for {@link WordToHtmlConverter}
|
* Test cases for {@link WordToHtmlConverter}
|
||||||
*/
|
*/
|
||||||
public class TestWordToHtmlConverter extends POITestCase
|
public class TestWordToHtmlConverter
|
||||||
{
|
{
|
||||||
private static String getHtmlText( final String sampleFileName )
|
private static String getHtmlText( final String sampleFileName )
|
||||||
throws Exception
|
throws Exception
|
||||||
@ -82,12 +85,14 @@ public class TestWordToHtmlConverter extends POITestCase
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAIOOBTap() throws Exception
|
public void testAIOOBTap() throws Exception
|
||||||
{
|
{
|
||||||
String result = getHtmlText( "AIOOB-Tap.doc");
|
String result = getHtmlText( "AIOOB-Tap.doc");
|
||||||
assertContains(result.substring( 0, 6000 ), "<table class=\"t1\">");
|
assertContains(result.substring( 0, 6000 ), "<table class=\"t1\">");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBug33519() throws Exception
|
public void testBug33519() throws Exception
|
||||||
{
|
{
|
||||||
String result = getHtmlText( "Bug33519.doc");
|
String result = getHtmlText( "Bug33519.doc");
|
||||||
@ -98,6 +103,7 @@ public class TestWordToHtmlConverter extends POITestCase
|
|||||||
"\u042F\u0432\u043E\u0440 \u0410\u0441\u0435\u043D\u043E\u0432");
|
"\u042F\u0432\u043E\u0440 \u0410\u0441\u0435\u043D\u043E\u0432");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBug46610_2() throws Exception
|
public void testBug46610_2() throws Exception
|
||||||
{
|
{
|
||||||
String result = getHtmlText( "Bug46610_2.doc");
|
String result = getHtmlText( "Bug46610_2.doc");
|
||||||
@ -106,6 +112,7 @@ public class TestWordToHtmlConverter extends POITestCase
|
|||||||
"012345678911234567892123456789312345678941234567890123456789112345678921234567893123456789412345678");
|
"012345678911234567892123456789312345678941234567890123456789112345678921234567893123456789412345678");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBug46817() throws Exception
|
public void testBug46817() throws Exception
|
||||||
{
|
{
|
||||||
String result = getHtmlText( "Bug46817.doc");
|
String result = getHtmlText( "Bug46817.doc");
|
||||||
@ -113,6 +120,7 @@ public class TestWordToHtmlConverter extends POITestCase
|
|||||||
assertContains(result, substring);
|
assertContains(result, substring);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBug47286() throws Exception
|
public void testBug47286() throws Exception
|
||||||
{
|
{
|
||||||
String result = getHtmlText( "Bug47286.doc");
|
String result = getHtmlText( "Bug47286.doc");
|
||||||
@ -124,11 +132,13 @@ public class TestWordToHtmlConverter extends POITestCase
|
|||||||
assertContains(result, "mfa.gov.cy");
|
assertContains(result, "mfa.gov.cy");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBug48075() throws Exception
|
public void testBug48075() throws Exception
|
||||||
{
|
{
|
||||||
getHtmlText( "Bug48075.doc");
|
getHtmlText( "Bug48075.doc");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBug52583() throws Exception
|
public void testBug52583() throws Exception
|
||||||
{
|
{
|
||||||
String result = getHtmlText( "Bug52583.doc");
|
String result = getHtmlText( "Bug52583.doc");
|
||||||
@ -137,12 +147,14 @@ public class TestWordToHtmlConverter extends POITestCase
|
|||||||
"<select><option selected>riri</option><option>fifi</option><option>loulou</option></select>");
|
"<select><option selected>riri</option><option>fifi</option><option>loulou</option></select>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBug53182() throws Exception
|
public void testBug53182() throws Exception
|
||||||
{
|
{
|
||||||
String result = getHtmlText( "Bug53182.doc");
|
String result = getHtmlText( "Bug53182.doc");
|
||||||
assertFalse(result.contains( "italic" ));
|
assertFalse(result.contains( "italic" ));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDocumentProperties() throws Exception
|
public void testDocumentProperties() throws Exception
|
||||||
{
|
{
|
||||||
String result = getHtmlText( "documentProperties.doc");
|
String result = getHtmlText( "documentProperties.doc");
|
||||||
@ -152,6 +164,7 @@ public class TestWordToHtmlConverter extends POITestCase
|
|||||||
"<meta content=\"This is document keywords\" name=\"keywords\">");
|
"<meta content=\"This is document keywords\" name=\"keywords\">");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEmailhyperlink() throws Exception
|
public void testEmailhyperlink() throws Exception
|
||||||
{
|
{
|
||||||
String result = getHtmlText( "Bug47286.doc");
|
String result = getHtmlText( "Bug47286.doc");
|
||||||
@ -159,6 +172,7 @@ public class TestWordToHtmlConverter extends POITestCase
|
|||||||
assertContains(result, substring);
|
assertContains(result, substring);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEndnote() throws Exception
|
public void testEndnote() throws Exception
|
||||||
{
|
{
|
||||||
String result = getHtmlText( "endingnote.doc");
|
String result = getHtmlText( "endingnote.doc");
|
||||||
@ -172,6 +186,7 @@ public class TestWordToHtmlConverter extends POITestCase
|
|||||||
assertContains(result, "Ending note text");
|
assertContains(result, "Ending note text");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEquation() throws Exception
|
public void testEquation() throws Exception
|
||||||
{
|
{
|
||||||
String result = getHtmlText( "equation.doc");
|
String result = getHtmlText( "equation.doc");
|
||||||
@ -179,6 +194,7 @@ public class TestWordToHtmlConverter extends POITestCase
|
|||||||
assertContains(result, "<!--Image link to '0.emf' can be here-->");
|
assertContains(result, "<!--Image link to '0.emf' can be here-->");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testHyperlink() throws Exception
|
public void testHyperlink() throws Exception
|
||||||
{
|
{
|
||||||
String result = getHtmlText( "hyperlink.doc");
|
String result = getHtmlText( "hyperlink.doc");
|
||||||
@ -189,11 +205,13 @@ public class TestWordToHtmlConverter extends POITestCase
|
|||||||
assertContains(result, "</a><span>; after text</span>");
|
assertContains(result, "</a><span>; after text</span>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testInnerTable() throws Exception
|
public void testInnerTable() throws Exception
|
||||||
{
|
{
|
||||||
getHtmlText( "innertable.doc");
|
getHtmlText( "innertable.doc");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testListsMargins() throws Exception
|
public void testListsMargins() throws Exception
|
||||||
{
|
{
|
||||||
String result = getHtmlText( "lists-margins.doc");
|
String result = getHtmlText( "lists-margins.doc");
|
||||||
@ -210,11 +228,13 @@ public class TestWordToHtmlConverter extends POITestCase
|
|||||||
".p4{text-indent:-0.59652776in;margin-left:-0.70069444in;");
|
".p4{text-indent:-0.59652776in;margin-left:-0.70069444in;");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testO_kurs_doc() throws Exception
|
public void testO_kurs_doc() throws Exception
|
||||||
{
|
{
|
||||||
getHtmlText( "o_kurs.doc");
|
getHtmlText( "o_kurs.doc");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPageref() throws Exception
|
public void testPageref() throws Exception
|
||||||
{
|
{
|
||||||
String result = getHtmlText( "pageref.doc");
|
String result = getHtmlText( "pageref.doc");
|
||||||
@ -224,6 +244,7 @@ public class TestWordToHtmlConverter extends POITestCase
|
|||||||
assertContains(result, "1");
|
assertContains(result, "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPicture() throws Exception
|
public void testPicture() throws Exception
|
||||||
{
|
{
|
||||||
String result = getHtmlText( "picture.doc", true);
|
String result = getHtmlText( "picture.doc", true);
|
||||||
@ -238,6 +259,7 @@ public class TestWordToHtmlConverter extends POITestCase
|
|||||||
assertContains(result, "width:3.4125in;height:2.325in;");
|
assertContains(result, "width:3.4125in;height:2.325in;");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPicturesEscher() throws Exception
|
public void testPicturesEscher() throws Exception
|
||||||
{
|
{
|
||||||
String result = getHtmlText( "pictures_escher.doc", true);
|
String result = getHtmlText( "pictures_escher.doc", true);
|
||||||
@ -245,6 +267,7 @@ public class TestWordToHtmlConverter extends POITestCase
|
|||||||
assertContains(result, "<img src=\"s808.PNG\">");
|
assertContains(result, "<img src=\"s808.PNG\">");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTableMerges() throws Exception
|
public void testTableMerges() throws Exception
|
||||||
{
|
{
|
||||||
String result = getHtmlText( "table-merges.doc");
|
String result = getHtmlText( "table-merges.doc");
|
||||||
@ -253,6 +276,7 @@ public class TestWordToHtmlConverter extends POITestCase
|
|||||||
assertContains(result, "<td class=\"td2\" colspan=\"2\">");
|
assertContains(result, "<td class=\"td2\" colspan=\"2\">");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBug52420() throws Exception {
|
public void testBug52420() throws Exception {
|
||||||
String result = getHtmlText( "52420.doc");
|
String result = getHtmlText( "52420.doc");
|
||||||
|
|
||||||
|
@ -17,16 +17,17 @@
|
|||||||
|
|
||||||
package org.apache.poi;
|
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 java.util.Collection;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parent class for POI JUnit TestCases, which provide additional
|
* Parent class for POI JUnit TestCases, which provide additional
|
||||||
* features
|
* features
|
||||||
*/
|
*/
|
||||||
public class POITestCase extends TestCase {
|
public class POITestCase {
|
||||||
public static void assertContains(String haystack, String needle) {
|
public static void assertContains(String haystack, String needle) {
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"Unable to find expected text '" + needle + "' in text:\n" + haystack,
|
"Unable to find expected text '" + needle + "' in text:\n" + haystack,
|
||||||
@ -40,21 +41,6 @@ public class POITestCase extends TestCase {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
public static <T> void assertContains(T needle, T[] haystack)
|
||||||
{
|
{
|
||||||
// Check
|
// Check
|
||||||
|
@ -23,12 +23,15 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.util.IOUtils;
|
import org.apache.poi.util.IOUtils;
|
||||||
|
import org.apache.poi.util.LocaleUtil;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@SuppressWarnings("resource")
|
||||||
public class TestEscherDump {
|
public class TestEscherDump {
|
||||||
@Test
|
@Test
|
||||||
public void testSimple() throws Exception {
|
public void testSimple() throws Exception {
|
||||||
@ -64,8 +67,8 @@ public class TestEscherDump {
|
|||||||
* to redirect stdout to avoid spamming the console with output
|
* to redirect stdout to avoid spamming the console with output
|
||||||
*/
|
*/
|
||||||
private static class NullPrinterStream extends PrintStream {
|
private static class NullPrinterStream extends PrintStream {
|
||||||
private NullPrinterStream() {
|
private NullPrinterStream() throws UnsupportedEncodingException {
|
||||||
super(new NullOutputStream());
|
super(new NullOutputStream(),true,LocaleUtil.CHARSET_1252.name());
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Implementation of an OutputStream which does nothing, used
|
* Implementation of an OutputStream which does nothing, used
|
||||||
|
@ -17,6 +17,11 @@
|
|||||||
|
|
||||||
package org.apache.poi.hpsf.basic;
|
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.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@ -25,8 +30,6 @@ import java.io.InputStream;
|
|||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.hpsf.DocumentSummaryInformation;
|
import org.apache.poi.hpsf.DocumentSummaryInformation;
|
||||||
import org.apache.poi.hpsf.HPSFException;
|
import org.apache.poi.hpsf.HPSFException;
|
||||||
@ -37,13 +40,15 @@ import org.apache.poi.hpsf.PropertySetFactory;
|
|||||||
import org.apache.poi.hpsf.Section;
|
import org.apache.poi.hpsf.Section;
|
||||||
import org.apache.poi.hpsf.SummaryInformation;
|
import org.apache.poi.hpsf.SummaryInformation;
|
||||||
import org.apache.poi.hpsf.wellknown.SectionIDMap;
|
import org.apache.poi.hpsf.wellknown.SectionIDMap;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Tests the basic HPSF functionality.</p>
|
* <p>Tests the basic HPSF functionality.</p>
|
||||||
*
|
*
|
||||||
* @author Rainer Klute (klute@rainer-klute.de)
|
* @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_FS = "TestGermanWord90.doc";
|
||||||
private static final String[] POI_FILES = new String[]
|
private static final String[] POI_FILES = new String[]
|
||||||
@ -80,6 +85,7 @@ public final class TestBasic extends TestCase {
|
|||||||
* @exception FileNotFoundException if the file to be read does not exist.
|
* @exception FileNotFoundException if the file to be read does not exist.
|
||||||
* @exception IOException if any other I/O exception occurs.
|
* @exception IOException if any other I/O exception occurs.
|
||||||
*/
|
*/
|
||||||
|
@Before
|
||||||
public void setUp() throws IOException
|
public void setUp() throws IOException
|
||||||
{
|
{
|
||||||
POIDataSamples samples = POIDataSamples.getHPSFInstance();
|
POIDataSamples samples = POIDataSamples.getHPSFInstance();
|
||||||
@ -91,6 +97,7 @@ public final class TestBasic extends TestCase {
|
|||||||
* <p>Checks the names of the files in the POI filesystem. They
|
* <p>Checks the names of the files in the POI filesystem. They
|
||||||
* are expected to be in a certain order.</p>
|
* are expected to be in a certain order.</p>
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testReadFiles()
|
public void testReadFiles()
|
||||||
{
|
{
|
||||||
String[] expected = POI_FILES;
|
String[] expected = POI_FILES;
|
||||||
@ -112,6 +119,7 @@ public final class TestBasic extends TestCase {
|
|||||||
* @exception UnsupportedEncodingException if a character encoding is not
|
* @exception UnsupportedEncodingException if a character encoding is not
|
||||||
* supported.
|
* supported.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testCreatePropertySets()
|
public void testCreatePropertySets()
|
||||||
throws UnsupportedEncodingException, IOException
|
throws UnsupportedEncodingException, IOException
|
||||||
{
|
{
|
||||||
@ -152,24 +160,21 @@ public final class TestBasic extends TestCase {
|
|||||||
* @exception IOException if an I/O exception occurs
|
* @exception IOException if an I/O exception occurs
|
||||||
* @exception HPSFException if any HPSF exception occurs
|
* @exception HPSFException if any HPSF exception occurs
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testPropertySetMethods() throws IOException, HPSFException
|
public void testPropertySetMethods() throws IOException, HPSFException
|
||||||
{
|
{
|
||||||
/* Loop over the two property sets. */
|
/* Loop over the two property sets. */
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
byte[] b = poiFiles[i].getBytes();
|
byte[] b = poiFiles[i].getBytes();
|
||||||
PropertySet ps =
|
PropertySet ps = PropertySetFactory.create(new ByteArrayInputStream(b));
|
||||||
PropertySetFactory.create(new ByteArrayInputStream(b));
|
assertEquals(BYTE_ORDER, ps.getByteOrder());
|
||||||
assertEquals(ps.getByteOrder(), BYTE_ORDER);
|
assertEquals(FORMAT, ps.getFormat());
|
||||||
assertEquals(ps.getFormat(), FORMAT);
|
assertEquals(OS_VERSION, ps.getOSVersion());
|
||||||
assertEquals(ps.getOSVersion(), OS_VERSION);
|
assertArrayEquals(CLASS_ID, ps.getClassID().getBytes());
|
||||||
assertEquals(new String(ps.getClassID().getBytes()),
|
assertEquals(SECTION_COUNT[i], ps.getSectionCount());
|
||||||
new String(CLASS_ID));
|
assertEquals(IS_SUMMARY_INFORMATION[i], ps.isSummaryInformation());
|
||||||
assertEquals(ps.getSectionCount(), SECTION_COUNT[i]);
|
assertEquals(IS_DOCUMENT_SUMMARY_INFORMATION[i], ps.isDocumentSummaryInformation());
|
||||||
assertEquals(ps.isSummaryInformation(),
|
|
||||||
IS_SUMMARY_INFORMATION[i]);
|
|
||||||
assertEquals(ps.isDocumentSummaryInformation(),
|
|
||||||
IS_DOCUMENT_SUMMARY_INFORMATION[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,6 +186,7 @@ public final class TestBasic extends TestCase {
|
|||||||
* @exception IOException if an I/O exception occurs
|
* @exception IOException if an I/O exception occurs
|
||||||
* @exception HPSFException if any HPSF exception occurs
|
* @exception HPSFException if any HPSF exception occurs
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSectionMethods() throws IOException, HPSFException
|
public void testSectionMethods() throws IOException, HPSFException
|
||||||
{
|
{
|
||||||
final SummaryInformation si = (SummaryInformation)
|
final SummaryInformation si = (SummaryInformation)
|
||||||
|
@ -19,9 +19,11 @@ package org.apache.poi.hssf.dev;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
||||||
|
import org.apache.poi.util.LocaleUtil;
|
||||||
|
|
||||||
public class TestBiffViewer extends BaseXLSIteratingTest {
|
public class TestBiffViewer extends BaseXLSIteratingTest {
|
||||||
static {
|
static {
|
||||||
@ -44,12 +46,13 @@ public class TestBiffViewer extends BaseXLSIteratingTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void runOneFile(File file) throws IOException {
|
void runOneFile(File fileIn) throws IOException {
|
||||||
NPOIFSFileSystem fs = new NPOIFSFileSystem(file, true);
|
NPOIFSFileSystem fs = new NPOIFSFileSystem(fileIn, true);
|
||||||
InputStream is = BiffViewer.getPOIFSInputStream(fs);
|
InputStream is = BiffViewer.getPOIFSInputStream(fs);
|
||||||
try {
|
try {
|
||||||
// use a NullOutputStream to not write the bytes anywhere for best runtime
|
// use a NullOutputStream to not write the bytes anywhere for best runtime
|
||||||
BiffViewer.runBiffViewer(new PrintWriter(NULL_OUTPUT_STREAM), is, true, true, true, false);
|
PrintWriter dummy = new PrintWriter(new OutputStreamWriter(NULL_OUTPUT_STREAM, LocaleUtil.CHARSET_1252));
|
||||||
|
BiffViewer.runBiffViewer(dummy, is, true, true, true, false);
|
||||||
} finally {
|
} finally {
|
||||||
is.close();
|
is.close();
|
||||||
fs.close();
|
fs.close();
|
||||||
|
@ -20,6 +20,8 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
|
||||||
|
import org.apache.poi.util.LocaleUtil;
|
||||||
|
|
||||||
public class TestEFBiffViewer extends BaseXLSIteratingTest {
|
public class TestEFBiffViewer extends BaseXLSIteratingTest {
|
||||||
static {
|
static {
|
||||||
// these are likely ok to fail
|
// these are likely ok to fail
|
||||||
@ -39,13 +41,13 @@ public class TestEFBiffViewer extends BaseXLSIteratingTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void runOneFile(File file) throws IOException {
|
void runOneFile(File fileIn) throws IOException {
|
||||||
PrintStream save = System.out;
|
PrintStream save = System.out;
|
||||||
try {
|
try {
|
||||||
// redirect standard out during the test to avoid spamming the console with output
|
// 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 {
|
} finally {
|
||||||
System.setOut(save);
|
System.setOut(save);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ package org.apache.poi.hssf.dev;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
|
||||||
|
import org.apache.poi.util.LocaleUtil;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -39,15 +40,15 @@ public class TestFormulaViewer extends BaseXLSIteratingTest {
|
|||||||
public void testMain() throws Exception {
|
public void testMain() throws Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void runOneFile(File file) throws Exception {
|
void runOneFile(File fileIn) throws Exception {
|
||||||
PrintStream save = System.out;
|
PrintStream save = System.out;
|
||||||
try {
|
try {
|
||||||
// redirect standard out during the test to avoid spamming the console with output
|
// 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();
|
FormulaViewer viewer = new FormulaViewer();
|
||||||
viewer.setFile(file.getAbsolutePath());
|
viewer.setFile(fileIn.getAbsolutePath());
|
||||||
viewer.setList(true);
|
viewer.setList(true);
|
||||||
viewer.run();
|
viewer.run();
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -24,6 +24,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
|
import org.apache.poi.util.LocaleUtil;
|
||||||
|
|
||||||
public class TestReSave extends BaseXLSIteratingTest {
|
public class TestReSave extends BaseXLSIteratingTest {
|
||||||
static {
|
static {
|
||||||
@ -36,20 +37,20 @@ public class TestReSave extends BaseXLSIteratingTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void runOneFile(File file) throws Exception {
|
void runOneFile(File fileIn) throws Exception {
|
||||||
// avoid running on files leftover from previous failed runs
|
// avoid running on files leftover from previous failed runs
|
||||||
if(file.getName().endsWith("-saved.xls")) {
|
if(fileIn.getName().endsWith("-saved.xls")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintStream save = System.out;
|
PrintStream save = System.out;
|
||||||
try {
|
try {
|
||||||
// redirect standard out during the test to avoid spamming the console with output
|
// 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 {
|
try {
|
||||||
ReSave.main(new String[] { file.getAbsolutePath() });
|
ReSave.main(new String[] { fileIn.getAbsolutePath() });
|
||||||
|
|
||||||
// also try BiffViewer on the saved file
|
// also try BiffViewer on the saved file
|
||||||
new TestBiffViewer().runOneFile(reSavedFile);
|
new TestBiffViewer().runOneFile(reSavedFile);
|
||||||
@ -59,7 +60,7 @@ public class TestReSave extends BaseXLSIteratingTest {
|
|||||||
ReSave.main(new String[] { reSavedFile.getAbsolutePath() });
|
ReSave.main(new String[] { reSavedFile.getAbsolutePath() });
|
||||||
} finally {
|
} finally {
|
||||||
// clean up the re-re-saved file
|
// 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 {
|
} finally {
|
||||||
// clean up the re-saved file
|
// clean up the re-saved file
|
||||||
|
@ -20,6 +20,8 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
|
||||||
|
import org.apache.poi.util.LocaleUtil;
|
||||||
|
|
||||||
public class TestRecordLister extends BaseXLSIteratingTest {
|
public class TestRecordLister extends BaseXLSIteratingTest {
|
||||||
static {
|
static {
|
||||||
// these are likely ok to fail
|
// these are likely ok to fail
|
||||||
@ -31,14 +33,14 @@ public class TestRecordLister extends BaseXLSIteratingTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void runOneFile(File file) throws IOException {
|
void runOneFile(File fileIn) throws IOException {
|
||||||
PrintStream save = System.out;
|
PrintStream save = System.out;
|
||||||
try {
|
try {
|
||||||
// redirect standard out during the test to avoid spamming the console with output
|
// 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();
|
RecordLister viewer = new RecordLister();
|
||||||
viewer.setFile(file.getAbsolutePath());
|
viewer.setFile(fileIn.getAbsolutePath());
|
||||||
viewer.run();
|
viewer.run();
|
||||||
} finally {
|
} finally {
|
||||||
System.setOut(save);
|
System.setOut(save);
|
||||||
|
@ -17,27 +17,32 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.extractor;
|
package org.apache.poi.hssf.extractor;
|
||||||
|
|
||||||
import java.io.File;
|
import static org.apache.poi.POITestCase.assertContains;
|
||||||
import java.io.InputStream;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import org.apache.poi.POITestCase;
|
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the Excel 5/95 and Excel 4 (and older) text
|
* Unit tests for the Excel 5/95 and Excel 4 (and older) text
|
||||||
* extractor
|
* extractor
|
||||||
*/
|
*/
|
||||||
public final class TestOldExcelExtractor extends POITestCase {
|
public final class TestOldExcelExtractor {
|
||||||
private static OldExcelExtractor createExtractor(String sampleFileName) {
|
private static OldExcelExtractor createExtractor(String sampleFileName) {
|
||||||
InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName);
|
File file = HSSFTestDataSamples.getSampleFile(sampleFileName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new OldExcelExtractor(is);
|
return new OldExcelExtractor(file);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSimpleExcel3() {
|
public void testSimpleExcel3() {
|
||||||
OldExcelExtractor extractor = createExtractor("testEXCEL_3.xls");
|
OldExcelExtractor extractor = createExtractor("testEXCEL_3.xls");
|
||||||
|
|
||||||
@ -59,6 +64,8 @@ public final class TestOldExcelExtractor extends POITestCase {
|
|||||||
assertEquals(3, extractor.getBiffVersion());
|
assertEquals(3, extractor.getBiffVersion());
|
||||||
assertEquals(0x10, extractor.getFileType());
|
assertEquals(0x10, extractor.getFileType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSimpleExcel4() {
|
public void testSimpleExcel4() {
|
||||||
OldExcelExtractor extractor = createExtractor("testEXCEL_4.xls");
|
OldExcelExtractor extractor = createExtractor("testEXCEL_4.xls");
|
||||||
|
|
||||||
@ -77,6 +84,8 @@ public final class TestOldExcelExtractor extends POITestCase {
|
|||||||
assertEquals(4, extractor.getBiffVersion());
|
assertEquals(4, extractor.getBiffVersion());
|
||||||
assertEquals(0x10, extractor.getFileType());
|
assertEquals(0x10, extractor.getFileType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSimpleExcel5() {
|
public void testSimpleExcel5() {
|
||||||
for (String ver : new String[] {"5", "95"}) {
|
for (String ver : new String[] {"5", "95"}) {
|
||||||
OldExcelExtractor extractor = createExtractor("testEXCEL_"+ver+".xls");
|
OldExcelExtractor extractor = createExtractor("testEXCEL_"+ver+".xls");
|
||||||
@ -101,6 +110,7 @@ public final class TestOldExcelExtractor extends POITestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testStrings() {
|
public void testStrings() {
|
||||||
OldExcelExtractor extractor = createExtractor("testEXCEL_4.xls");
|
OldExcelExtractor extractor = createExtractor("testEXCEL_4.xls");
|
||||||
String text = extractor.getText();
|
String text = extractor.getText();
|
||||||
@ -119,6 +129,7 @@ public final class TestOldExcelExtractor extends POITestCase {
|
|||||||
// TODO Find some then test
|
// TODO Find some then test
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testFormattedNumbersExcel4() {
|
public void testFormattedNumbersExcel4() {
|
||||||
OldExcelExtractor extractor = createExtractor("testEXCEL_4.xls");
|
OldExcelExtractor extractor = createExtractor("testEXCEL_4.xls");
|
||||||
String text = extractor.getText();
|
String text = extractor.getText();
|
||||||
@ -136,6 +147,8 @@ public final class TestOldExcelExtractor extends POITestCase {
|
|||||||
// assertContains(text, "55,624");
|
// assertContains(text, "55,624");
|
||||||
// assertContains(text, "11,743,477");
|
// assertContains(text, "11,743,477");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testFormattedNumbersExcel5() {
|
public void testFormattedNumbersExcel5() {
|
||||||
for (String ver : new String[] {"5", "95"}) {
|
for (String ver : new String[] {"5", "95"}) {
|
||||||
OldExcelExtractor extractor = createExtractor("testEXCEL_"+ver+".xls");
|
OldExcelExtractor extractor = createExtractor("testEXCEL_"+ver+".xls");
|
||||||
@ -160,6 +173,7 @@ public final class TestOldExcelExtractor extends POITestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testFromFile() throws Exception {
|
public void testFromFile() throws Exception {
|
||||||
for (String ver : new String[] {"4", "5", "95"}) {
|
for (String ver : new String[] {"4", "5", "95"}) {
|
||||||
String filename = "testEXCEL_"+ver+".xls";
|
String filename = "testEXCEL_"+ver+".xls";
|
||||||
|
@ -17,30 +17,26 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.model;
|
package org.apache.poi.hssf.model;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import org.junit.runner.RunWith;
|
||||||
import junit.framework.TestSuite;
|
import org.junit.runners.Suite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collects all tests for <tt>org.apache.poi.hssf.model</tt>.
|
* 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 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,12 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.model;
|
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 java.util.Arrays;
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.NumberRecord;
|
import org.apache.poi.hssf.record.NumberRecord;
|
||||||
import org.apache.poi.hssf.record.Record;
|
import org.apache.poi.hssf.record.Record;
|
||||||
@ -28,27 +30,30 @@ import org.apache.poi.hssf.record.RowRecord;
|
|||||||
import org.apache.poi.hssf.record.UnknownRecord;
|
import org.apache.poi.hssf.record.UnknownRecord;
|
||||||
import org.apache.poi.hssf.record.WindowTwoRecord;
|
import org.apache.poi.hssf.record.WindowTwoRecord;
|
||||||
import org.apache.poi.hssf.record.pivottable.ViewDefinitionRecord;
|
import org.apache.poi.hssf.record.pivottable.ViewDefinitionRecord;
|
||||||
|
import org.apache.poi.util.LocaleUtil;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link RowBlocksReader}
|
* Tests for {@link RowBlocksReader}
|
||||||
*
|
*
|
||||||
* @author Josh Micich
|
* @author Josh Micich
|
||||||
*/
|
*/
|
||||||
public final class TestRowBlocksReader extends TestCase {
|
public final class TestRowBlocksReader {
|
||||||
|
@Test
|
||||||
public void testAbnormalPivotTableRecords_bug46280() {
|
public void testAbnormalPivotTableRecords_bug46280() {
|
||||||
int SXVIEW_SID = ViewDefinitionRecord.sid;
|
int SXVIEW_SID = ViewDefinitionRecord.sid;
|
||||||
Record[] inRecs = {
|
Record[] inRecs = {
|
||||||
new RowRecord(0),
|
new RowRecord(0),
|
||||||
new NumberRecord(),
|
new NumberRecord(),
|
||||||
// normally MSODRAWING(0x00EC) would come here before SXVIEW
|
// 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(),
|
new WindowTwoRecord(),
|
||||||
};
|
};
|
||||||
RecordStream rs = new RecordStream(Arrays.asList(inRecs), 0);
|
RecordStream rs = new RecordStream(Arrays.asList(inRecs), 0);
|
||||||
RowBlocksReader rbr = new RowBlocksReader(rs);
|
RowBlocksReader rbr = new RowBlocksReader(rs);
|
||||||
if (rs.peekNextClass() == WindowTwoRecord.class) {
|
if (rs.peekNextClass() == WindowTwoRecord.class) {
|
||||||
// Should have stopped at the SXVIEW record
|
// Should have stopped at the SXVIEW record
|
||||||
throw new AssertionFailedError("Identified bug 46280b");
|
fail("Identified bug 46280b");
|
||||||
}
|
}
|
||||||
RecordStream rbStream = rbr.getPlainRecordStream();
|
RecordStream rbStream = rbr.getPlainRecordStream();
|
||||||
assertEquals(inRecs[0], rbStream.getNext());
|
assertEquals(inRecs[0], rbStream.getNext());
|
||||||
|
@ -18,6 +18,9 @@
|
|||||||
package org.apache.poi.hssf.record;
|
package org.apache.poi.hssf.record;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
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.BufferedReader;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
@ -28,21 +31,22 @@ import java.io.InputStreamReader;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.hssf.record.common.UnicodeString;
|
import org.apache.poi.hssf.record.common.UnicodeString;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
import org.apache.poi.util.HexRead;
|
import org.apache.poi.util.HexRead;
|
||||||
import org.apache.poi.util.LittleEndian;
|
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 Marc Johnson (mjohnson at apache dot org)
|
||||||
* @author Glen Stampoultzis (glens at apache.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
|
* decodes hexdump files and concatenates the results
|
||||||
@ -55,7 +59,7 @@ public final class TestSSTRecord extends TestCase {
|
|||||||
for (int i = 0; i < nFiles; i++) {
|
for (int i = 0; i < nFiles; i++) {
|
||||||
String sampleFileName = hexDumpFileNames[i];
|
String sampleFileName = hexDumpFileNames[i];
|
||||||
InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName);
|
InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName);
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
BufferedReader br = new BufferedReader(new InputStreamReader(is, LocaleUtil.CHARSET_1252));
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
String line = br.readLine();
|
String line = br.readLine();
|
||||||
@ -86,6 +90,7 @@ public final class TestSSTRecord extends TestCase {
|
|||||||
* SST is often split over several {@link ContinueRecord}s
|
* SST is often split over several {@link ContinueRecord}s
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testContinuedRecord() throws IOException {
|
public void testContinuedRecord() throws IOException {
|
||||||
byte[] origData;
|
byte[] origData;
|
||||||
SSTRecord record;
|
SSTRecord record;
|
||||||
@ -109,20 +114,20 @@ public final class TestSSTRecord extends TestCase {
|
|||||||
assertEquals( 5249, record.getNumUniqueStrings() );
|
assertEquals( 5249, record.getNumUniqueStrings() );
|
||||||
assertEquals( 5249, record.countStrings() );
|
assertEquals( 5249, record.countStrings() );
|
||||||
ser_output = record.serialize();
|
ser_output = record.serialize();
|
||||||
if (false) { // set true to observe make sure areSameSSTs() is working
|
// if (false) { // set true to observe make sure areSameSSTs() is working
|
||||||
ser_output[11000] = 'X';
|
// ser_output[11000] = 'X';
|
||||||
}
|
// }
|
||||||
|
|
||||||
SSTRecord rec2 = createSSTFromRawData(ser_output);
|
SSTRecord rec2 = createSSTFromRawData(ser_output);
|
||||||
if (!areSameSSTs(record, rec2)) {
|
if (!areSameSSTs(record, rec2)) {
|
||||||
throw new AssertionFailedError("large SST re-serialized incorrectly");
|
throw new AssertionFailedError("large SST re-serialized incorrectly");
|
||||||
}
|
}
|
||||||
if (false) {
|
// if (false) {
|
||||||
// TODO - trivial differences in ContinueRecord break locations
|
// // TODO - trivial differences in ContinueRecord break locations
|
||||||
// Sample data should be checked against what most recent Excel version produces.
|
// // Sample data should be checked against what most recent Excel version produces.
|
||||||
// maybe tweaks are required in ContinuableRecordOutput
|
// // maybe tweaks are required in ContinuableRecordOutput
|
||||||
assertArrayEquals(origData, ser_output);
|
// assertArrayEquals(origData, ser_output);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean areSameSSTs(SSTRecord a, SSTRecord b) {
|
private boolean areSameSSTs(SSTRecord a, SSTRecord b) {
|
||||||
@ -147,7 +152,7 @@ public final class TestSSTRecord extends TestCase {
|
|||||||
*
|
*
|
||||||
* @exception IOException
|
* @exception IOException
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testHugeStrings() {
|
public void testHugeStrings() {
|
||||||
SSTRecord record = new SSTRecord();
|
SSTRecord record = new SSTRecord();
|
||||||
byte[][] bstrings =
|
byte[][] bstrings =
|
||||||
@ -161,7 +166,7 @@ public final class TestSSTRecord extends TestCase {
|
|||||||
for ( int k = 0; k < bstrings.length; k++ )
|
for ( int k = 0; k < bstrings.length; k++ )
|
||||||
{
|
{
|
||||||
Arrays.fill( bstrings[k], (byte) ( 'a' + 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] );
|
record.addString( strings[k] );
|
||||||
total_length += 3 + bstrings[k].length;
|
total_length += 3 + bstrings[k].length;
|
||||||
}
|
}
|
||||||
@ -198,7 +203,7 @@ public final class TestSSTRecord extends TestCase {
|
|||||||
if ( ( bstrings[k].length % 2 ) == 1 )
|
if ( ( bstrings[k].length % 2 ) == 1 )
|
||||||
{
|
{
|
||||||
Arrays.fill( bstrings[k], (byte) ( 'a' + 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) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -230,6 +235,7 @@ public final class TestSSTRecord extends TestCase {
|
|||||||
/**
|
/**
|
||||||
* test SSTRecord boundary conditions
|
* test SSTRecord boundary conditions
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSSTRecordBug() {
|
public void testSSTRecordBug() {
|
||||||
// create an SSTRecord and write a certain pattern of strings
|
// create an SSTRecord and write a certain pattern of strings
|
||||||
// to it ... then serialize it and verify the content
|
// to it ... then serialize it and verify the content
|
||||||
@ -265,6 +271,7 @@ public final class TestSSTRecord extends TestCase {
|
|||||||
/**
|
/**
|
||||||
* test simple addString
|
* test simple addString
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSimpleAddString() {
|
public void testSimpleAddString() {
|
||||||
SSTRecord record = new SSTRecord();
|
SSTRecord record = new SSTRecord();
|
||||||
UnicodeString s1 = new UnicodeString("Hello world");
|
UnicodeString s1 = new UnicodeString("Hello world");
|
||||||
@ -310,6 +317,7 @@ public final class TestSSTRecord extends TestCase {
|
|||||||
/**
|
/**
|
||||||
* test simple constructor
|
* test simple constructor
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSimpleConstructor() {
|
public void testSimpleConstructor() {
|
||||||
SSTRecord record = new SSTRecord();
|
SSTRecord record = new SSTRecord();
|
||||||
|
|
||||||
@ -334,13 +342,16 @@ public final class TestSSTRecord extends TestCase {
|
|||||||
/**
|
/**
|
||||||
* Tests that workbooks with rich text that duplicates a non rich text cell can be read and written.
|
* 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");
|
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("duprich1.xls");
|
||||||
HSSFSheet sheet = wb.getSheetAt( 1 );
|
HSSFSheet sheet = wb.getSheetAt( 1 );
|
||||||
assertEquals( "01/05 (Wed)", sheet.getRow( 0 ).getCell(8 ).getStringCellValue() );
|
assertEquals( "01/05 (Wed)", sheet.getRow( 0 ).getCell(8 ).getStringCellValue() );
|
||||||
assertEquals( "01/05 (Wed)", sheet.getRow( 1 ).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.
|
// test the second file.
|
||||||
wb = HSSFTestDataSamples.openSampleWorkbook("duprich2.xls");
|
wb = HSSFTestDataSamples.openSampleWorkbook("duprich2.xls");
|
||||||
@ -353,7 +364,9 @@ public final class TestSSTRecord extends TestCase {
|
|||||||
assertEquals( "Testing", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() );
|
assertEquals( "Testing", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() );
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1447,7 +1460,7 @@ public final class TestSSTRecord extends TestCase {
|
|||||||
/**
|
/**
|
||||||
* deep comparison of two SST records
|
* 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 strings", expected.getNumStrings(), actual.getNumStrings());
|
||||||
assertEquals("number of unique strings", expected.getNumUniqueStrings(), actual.getNumUniqueStrings());
|
assertEquals("number of unique strings", expected.getNumUniqueStrings(), actual.getNumUniqueStrings());
|
||||||
assertEquals("count of strings", expected.countStrings(), actual.countStrings());
|
assertEquals("count of strings", expected.countStrings(), actual.countStrings());
|
||||||
@ -1458,8 +1471,8 @@ public final class TestSSTRecord extends TestCase {
|
|||||||
assertTrue("String at idx=" + k, us1.equals(us2));
|
assertTrue("String at idx=" + k, us1.equals(us2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void test50779_1(){
|
public void test50779_1(){
|
||||||
byte[] bytes = HexRead.readFromString(data_50779_1);
|
byte[] bytes = HexRead.readFromString(data_50779_1);
|
||||||
|
|
||||||
@ -1475,9 +1488,10 @@ public final class TestSSTRecord extends TestCase {
|
|||||||
SSTRecord dst = new SSTRecord(in);
|
SSTRecord dst = new SSTRecord(in);
|
||||||
assertEquals(81, dst.getNumStrings());
|
assertEquals(81, dst.getNumStrings());
|
||||||
|
|
||||||
assertEquals(src, dst);
|
assertRecordEquals(src, dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void test50779_2() {
|
public void test50779_2() {
|
||||||
byte[] bytes = HexRead.readFromString(data_50779_2);
|
byte[] bytes = HexRead.readFromString(data_50779_2);
|
||||||
|
|
||||||
@ -1493,9 +1507,10 @@ public final class TestSSTRecord extends TestCase {
|
|||||||
SSTRecord dst = new SSTRecord(in);
|
SSTRecord dst = new SSTRecord(in);
|
||||||
assertEquals(81, dst.getNumStrings());
|
assertEquals(81, dst.getNumStrings());
|
||||||
|
|
||||||
assertEquals(src, dst);
|
assertRecordEquals(src, dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void test57456() {
|
public void test57456() {
|
||||||
byte[] bytes = HexRead.readFromString("FC, 00, 08, 00, 00, 00, 00, 00, E1, 06, 00, 00");
|
byte[] bytes = HexRead.readFromString("FC, 00, 08, 00, 00, 00, 00, 00, E1, 06, 00, 00");
|
||||||
RecordInputStream in = TestcaseRecordInputStream.create(bytes);
|
RecordInputStream in = TestcaseRecordInputStream.create(bytes);
|
||||||
|
@ -17,26 +17,21 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.aggregates;
|
package org.apache.poi.hssf.record.aggregates;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import org.junit.runner.RunWith;
|
||||||
import junit.framework.TestSuite;
|
import org.junit.runners.Suite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collects all tests for package <tt>org.apache.poi.hssf.record.aggregates</tt>.
|
* 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 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,14 +17,12 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.aggregates;
|
package org.apache.poi.hssf.record.aggregates;
|
||||||
|
|
||||||
import java.io.File;
|
import static org.junit.Assert.assertEquals;
|
||||||
import java.io.FileOutputStream;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import java.io.IOException;
|
import static org.junit.Assert.assertTrue;
|
||||||
import java.io.OutputStream;
|
import static org.junit.Assert.fail;
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
import java.util.Arrays;
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.hssf.model.RecordStream;
|
import org.apache.poi.hssf.model.RecordStream;
|
||||||
@ -42,12 +40,15 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|||||||
import org.apache.poi.hssf.usermodel.RecordInspector;
|
import org.apache.poi.hssf.usermodel.RecordInspector;
|
||||||
import org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector;
|
import org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector;
|
||||||
import org.apache.poi.hssf.util.CellRangeAddress8Bit;
|
import org.apache.poi.hssf.util.CellRangeAddress8Bit;
|
||||||
|
import org.apache.poi.util.LocaleUtil;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link RowRecordsAggregate}
|
* Tests for {@link RowRecordsAggregate}
|
||||||
*/
|
*/
|
||||||
public final class TestRowRecordsAggregate extends TestCase {
|
public final class TestRowRecordsAggregate {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testRowGet() {
|
public void testRowGet() {
|
||||||
RowRecordsAggregate rra = new RowRecordsAggregate();
|
RowRecordsAggregate rra = new RowRecordsAggregate();
|
||||||
RowRecord rr = new RowRecord(4);
|
RowRecord rr = new RowRecord(4);
|
||||||
@ -67,7 +68,8 @@ public final class TestRowRecordsAggregate extends TestCase {
|
|||||||
* {@link SharedFormulaRecord}s, these records should appear immediately after the first
|
* {@link SharedFormulaRecord}s, these records should appear immediately after the first
|
||||||
* {@link FormulaRecord}s that they apply to (and only once).<br/>
|
* {@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");
|
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("testArraysAndTables.xls");
|
||||||
Record[] sheetRecs = RecordInspector.getRecords(wb.getSheetAt(0), 0);
|
Record[] sheetRecs = RecordInspector.getRecords(wb.getSheetAt(0), 0);
|
||||||
|
|
||||||
@ -82,20 +84,22 @@ public final class TestRowRecordsAggregate extends TestCase {
|
|||||||
assertEquals(0, countSharedFormulas);
|
assertEquals(0, countSharedFormulas);
|
||||||
|
|
||||||
|
|
||||||
if (false) { // set true to observe re-serialized file
|
// if (false) { // set true to observe re-serialized file
|
||||||
File f = new File(System.getProperty("java.io.tmpdir") + "/testArraysAndTables-out.xls");
|
// File f = new File(System.getProperty("java.io.tmpdir") + "/testArraysAndTables-out.xls");
|
||||||
try {
|
// try {
|
||||||
OutputStream os = new FileOutputStream(f);
|
// OutputStream os = new FileOutputStream(f);
|
||||||
wb.write(os);
|
// wb.write(os);
|
||||||
os.close();
|
// os.close();
|
||||||
} catch (IOException e) {
|
// } catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
}
|
// }
|
||||||
System.out.println("Output file to " + f.getAbsolutePath());
|
// 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;
|
int result =0;
|
||||||
for(int i=0; i<recs.length; i++) {
|
for(int i=0; i<recs.length; i++) {
|
||||||
@ -104,7 +108,7 @@ public final class TestRowRecordsAggregate extends TestCase {
|
|||||||
result++;
|
result++;
|
||||||
Record prevRec = recs[i-1];
|
Record prevRec = recs[i-1];
|
||||||
if (!(prevRec instanceof FormulaRecord)) {
|
if (!(prevRec instanceof FormulaRecord)) {
|
||||||
throw new AssertionFailedError("Bad record order at index "
|
fail("Bad record order at index "
|
||||||
+ i + ": Formula record expected but got ("
|
+ i + ": Formula record expected but got ("
|
||||||
+ prevRec.getClass().getName() + ")");
|
+ prevRec.getClass().getName() + ")");
|
||||||
}
|
}
|
||||||
@ -130,12 +134,13 @@ public final class TestRowRecordsAggregate extends TestCase {
|
|||||||
* This fix in {@link RowRecordsAggregate} was implemented anyway since any {@link
|
* This fix in {@link RowRecordsAggregate} was implemented anyway since any {@link
|
||||||
* UnknownRecord} has the potential of being 'continued'.
|
* UnknownRecord} has the potential of being 'continued'.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testUnknownContinue_bug46280() {
|
public void testUnknownContinue_bug46280() {
|
||||||
Record[] inRecs = {
|
Record[] inRecs = {
|
||||||
new RowRecord(0),
|
new RowRecord(0),
|
||||||
new NumberRecord(),
|
new NumberRecord(),
|
||||||
new UnknownRecord(0x5555, "dummydata".getBytes()),
|
new UnknownRecord(0x5555, "dummydata".getBytes(LocaleUtil.CHARSET_1252)),
|
||||||
new ContinueRecord("moredummydata".getBytes()),
|
new ContinueRecord("moredummydata".getBytes(LocaleUtil.CHARSET_1252)),
|
||||||
};
|
};
|
||||||
RecordStream rs = new RecordStream(Arrays.asList(inRecs), 0);
|
RecordStream rs = new RecordStream(Arrays.asList(inRecs), 0);
|
||||||
RowRecordsAggregate rra;
|
RowRecordsAggregate rra;
|
||||||
@ -143,7 +148,7 @@ public final class TestRowRecordsAggregate extends TestCase {
|
|||||||
rra = new RowRecordsAggregate(rs, SharedValueManager.createEmpty());
|
rra = new RowRecordsAggregate(rs, SharedValueManager.createEmpty());
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
if (e.getMessage().startsWith("Unexpected record type")) {
|
if (e.getMessage().startsWith("Unexpected record type")) {
|
||||||
throw new AssertionFailedError("Identified bug 46280a");
|
fail("Identified bug 46280a");
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
@ -18,16 +18,14 @@
|
|||||||
package org.apache.poi.hssf.usermodel;
|
package org.apache.poi.hssf.usermodel;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||||
@ -35,52 +33,59 @@ import org.apache.poi.poifs.filesystem.Ole10Native;
|
|||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
import org.apache.poi.ss.usermodel.ClientAnchor;
|
import org.apache.poi.ss.usermodel.ClientAnchor;
|
||||||
import org.apache.poi.ss.usermodel.CreationHelper;
|
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
|
// This used to break, until bug #43116 was fixed
|
||||||
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ole2-embedding.xls");
|
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ole2-embedding.xls");
|
||||||
|
|
||||||
// Check we can get at the Escher layer still
|
// Check we can get at the Escher layer still
|
||||||
workbook.getAllPictures();
|
workbook.getAllPictures();
|
||||||
|
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEmbeddedObjects() throws Exception {
|
public void testEmbeddedObjects() throws Exception {
|
||||||
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ole2-embedding.xls");
|
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ole2-embedding.xls");
|
||||||
|
|
||||||
List<HSSFObjectData> objects = workbook.getAllEmbeddedObjects();
|
List<HSSFObjectData> objects = workbook.getAllEmbeddedObjects();
|
||||||
assertEquals("Wrong number of objects", 2, objects.size());
|
assertEquals("Wrong number of objects", 2, objects.size());
|
||||||
assertEquals("Wrong name for first object", "MBD06CAB431",
|
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",
|
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 {
|
public void testReallyEmbedSomething() throws Exception {
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb1 = new HSSFWorkbook();
|
||||||
HSSFSheet sheet = wb.createSheet();
|
HSSFSheet sheet = wb1.createSheet();
|
||||||
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
|
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
|
||||||
|
|
||||||
byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("logoKarmokar4.png");
|
byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("logoKarmokar4.png");
|
||||||
byte[] picturePPT = POIDataSamples.getSlideShowInstance().readFile("clock.jpg");
|
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();
|
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();
|
POIFSFileSystem xlsPoifs = getSampleXLS();
|
||||||
int imgPPT = wb.addPicture(picturePPT, HSSFWorkbook.PICTURE_TYPE_JPEG);
|
int imgPPT = wb1.addPicture(picturePPT, HSSFWorkbook.PICTURE_TYPE_JPEG);
|
||||||
int xlsIdx = wb.addOlePackage(xlsPoifs, "Sample-XLS", "sample.xls", "sample.xls");
|
int xlsIdx = wb1.addOlePackage(xlsPoifs, "Sample-XLS", "sample.xls", "sample.xls");
|
||||||
int txtIdx = wb.addOlePackage(getSampleTXT(), "Sample-TXT", "sample.txt", "sample.txt");
|
int txtIdx = wb1.addOlePackage(getSampleTXT(), "Sample-TXT", "sample.txt", "sample.txt");
|
||||||
|
|
||||||
int rowoffset = 5;
|
int rowoffset = 5;
|
||||||
int coloffset = 5;
|
int coloffset = 5;
|
||||||
|
|
||||||
CreationHelper ch = wb.getCreationHelper();
|
CreationHelper ch = wb1.getCreationHelper();
|
||||||
HSSFClientAnchor anchor = (HSSFClientAnchor)ch.createClientAnchor();
|
HSSFClientAnchor anchor = (HSSFClientAnchor)ch.createClientAnchor();
|
||||||
anchor.setAnchor((short)(2+coloffset), 1+rowoffset, 0, 0, (short)(3+coloffset), 5+rowoffset, 0, 0);
|
anchor.setAnchor((short)(2+coloffset), 1+rowoffset, 0, 0, (short)(3+coloffset), 5+rowoffset, 0, 0);
|
||||||
anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE);
|
anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE);
|
||||||
@ -107,31 +112,35 @@ public final class TestOLE2Embeding extends TestCase {
|
|||||||
circle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_OVAL);
|
circle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_OVAL);
|
||||||
circle.setNoFill(true);
|
circle.setNoFill(true);
|
||||||
|
|
||||||
if (false) {
|
// if (false) {
|
||||||
FileOutputStream fos = new FileOutputStream("embed.xls");
|
// FileOutputStream fos = new FileOutputStream("embed.xls");
|
||||||
wb.write(fos);
|
// wb.write(fos);
|
||||||
fos.close();
|
// fos.close();
|
||||||
}
|
// }
|
||||||
|
|
||||||
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
|
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
|
||||||
|
wb1.close();
|
||||||
|
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
HSSFObjectData od = wb.getAllEmbeddedObjects().get(0);
|
HSSFObjectData od = wb2.getAllEmbeddedObjects().get(0);
|
||||||
Ole10Native ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode)od.getDirectory());
|
Ole10Native ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode)od.getDirectory());
|
||||||
bos.reset();
|
bos.reset();
|
||||||
pptPoifs.writeFilesystem(bos);
|
pptPoifs.writeFilesystem(bos);
|
||||||
assertArrayEquals(ole10.getDataBuffer(), bos.toByteArray());
|
assertArrayEquals(ole10.getDataBuffer(), bos.toByteArray());
|
||||||
|
|
||||||
od = wb.getAllEmbeddedObjects().get(1);
|
od = wb2.getAllEmbeddedObjects().get(1);
|
||||||
ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode)od.getDirectory());
|
ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode)od.getDirectory());
|
||||||
bos.reset();
|
bos.reset();
|
||||||
xlsPoifs.writeFilesystem(bos);
|
xlsPoifs.writeFilesystem(bos);
|
||||||
assertArrayEquals(ole10.getDataBuffer(), bos.toByteArray());
|
assertArrayEquals(ole10.getDataBuffer(), bos.toByteArray());
|
||||||
|
|
||||||
od = wb.getAllEmbeddedObjects().get(2);
|
od = wb2.getAllEmbeddedObjects().get(2);
|
||||||
ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode)od.getDirectory());
|
ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode)od.getDirectory());
|
||||||
assertArrayEquals(ole10.getDataBuffer(), getSampleTXT());
|
assertArrayEquals(ole10.getDataBuffer(), getSampleTXT());
|
||||||
|
|
||||||
|
xlsPoifs.close();
|
||||||
|
pptPoifs.close();
|
||||||
|
wb2.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
static POIFSFileSystem getSamplePPT() throws IOException {
|
static POIFSFileSystem getSamplePPT() throws IOException {
|
||||||
@ -150,12 +159,13 @@ public final class TestOLE2Embeding extends TestCase {
|
|||||||
|
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
wb.write(bos);
|
wb.write(bos);
|
||||||
|
wb.close();
|
||||||
POIFSFileSystem poifs = new POIFSFileSystem(new ByteArrayInputStream(bos.toByteArray()));
|
POIFSFileSystem poifs = new POIFSFileSystem(new ByteArrayInputStream(bos.toByteArray()));
|
||||||
|
|
||||||
return poifs;
|
return poifs;
|
||||||
}
|
}
|
||||||
|
|
||||||
static byte[] getSampleTXT() {
|
static byte[] getSampleTXT() {
|
||||||
return "All your base are belong to us".getBytes();
|
return "All your base are belong to us".getBytes(LocaleUtil.CHARSET_1252);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,25 +17,30 @@
|
|||||||
|
|
||||||
package org.apache.poi.poifs.filesystem;
|
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.io.ByteArrayInputStream;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.POITestCase;
|
|
||||||
import org.apache.poi.poifs.common.POIFSConstants;
|
import org.apache.poi.poifs.common.POIFSConstants;
|
||||||
import org.apache.poi.util.IOUtils;
|
import org.apache.poi.util.IOUtils;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for the Mini Store in the NIO POIFS
|
* 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();
|
private static final POIDataSamples _inst = POIDataSamples.getPOIFSInstance();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check that for a given mini block, we can correctly figure
|
* Check that for a given mini block, we can correctly figure
|
||||||
* out what the next one is
|
* out what the next one is
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testNextBlock() throws Exception {
|
public void testNextBlock() throws Exception {
|
||||||
// It's the same on 512 byte and 4096 byte block files!
|
// It's the same on 512 byte and 4096 byte block files!
|
||||||
NPOIFSFileSystem fsA = new NPOIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
|
NPOIFSFileSystem fsA = new NPOIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
|
||||||
@ -103,14 +108,17 @@ public final class TestNPOIFSMiniStore extends POITestCase {
|
|||||||
for(int i=181; i<fs.getBigBlockSizeDetails().getBATEntriesPerBlock(); i++) {
|
for(int i=181; i<fs.getBigBlockSizeDetails().getBATEntriesPerBlock(); i++) {
|
||||||
assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(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
|
* Check we get the right data back for each block
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testGetBlock() throws Exception {
|
public void testGetBlock() throws Exception {
|
||||||
// It's the same on 512 byte and 4096 byte block files!
|
// It's the same on 512 byte and 4096 byte block files!
|
||||||
NPOIFSFileSystem fsA = new NPOIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
|
NPOIFSFileSystem fsA = new NPOIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
|
||||||
@ -170,15 +178,18 @@ public final class TestNPOIFSMiniStore extends POITestCase {
|
|||||||
assertEquals((byte)0, b.get());
|
assertEquals((byte)0, b.get());
|
||||||
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
|
* Ask for free blocks where there are some already
|
||||||
* to be had from the SFAT
|
* to be had from the SFAT
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testGetFreeBlockWithSpare() throws Exception {
|
public void testGetFreeBlockWithSpare() throws Exception {
|
||||||
NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
|
NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
|
||||||
NPOIFSMiniStore ministore = fs.getMiniStore();
|
NPOIFSMiniStore ministore = fs.getMiniStore();
|
||||||
@ -210,6 +221,7 @@ public final class TestNPOIFSMiniStore extends POITestCase {
|
|||||||
* Ask for free blocks where no free ones exist, and so the
|
* Ask for free blocks where no free ones exist, and so the
|
||||||
* stream needs to be extended and another SBAT added
|
* stream needs to be extended and another SBAT added
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testGetFreeBlockWithNoneSpare() throws Exception {
|
public void testGetFreeBlockWithNoneSpare() throws Exception {
|
||||||
NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
|
NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
|
||||||
NPOIFSMiniStore ministore = fs.getMiniStore();
|
NPOIFSMiniStore ministore = fs.getMiniStore();
|
||||||
@ -254,6 +266,7 @@ public final class TestNPOIFSMiniStore extends POITestCase {
|
|||||||
* Test that we will extend the underlying chain of
|
* Test that we will extend the underlying chain of
|
||||||
* big blocks that make up the ministream as needed
|
* big blocks that make up the ministream as needed
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testCreateBlockIfNeeded() throws Exception {
|
public void testCreateBlockIfNeeded() throws Exception {
|
||||||
NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
|
NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
|
||||||
NPOIFSMiniStore ministore = fs.getMiniStore();
|
NPOIFSMiniStore ministore = fs.getMiniStore();
|
||||||
@ -334,6 +347,7 @@ public final class TestNPOIFSMiniStore extends POITestCase {
|
|||||||
fs.close();
|
fs.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCreateMiniStoreFirst() throws Exception {
|
public void testCreateMiniStoreFirst() throws Exception {
|
||||||
NPOIFSFileSystem fs = new NPOIFSFileSystem();
|
NPOIFSFileSystem fs = new NPOIFSFileSystem();
|
||||||
NPOIFSMiniStore ministore = fs.getMiniStore();
|
NPOIFSMiniStore ministore = fs.getMiniStore();
|
||||||
@ -385,7 +399,7 @@ public final class TestNPOIFSMiniStore extends POITestCase {
|
|||||||
byte[] rdata = new byte[data.length];
|
byte[] rdata = new byte[data.length];
|
||||||
dis = new DocumentInputStream(entry);
|
dis = new DocumentInputStream(entry);
|
||||||
IOUtils.readFully(dis, rdata);
|
IOUtils.readFully(dis, rdata);
|
||||||
assertEquals(data, rdata);
|
assertArrayEquals(data, rdata);
|
||||||
dis.close();
|
dis.close();
|
||||||
|
|
||||||
entry = (DocumentEntry)fs.getRoot().getEntry("mini2");
|
entry = (DocumentEntry)fs.getRoot().getEntry("mini2");
|
||||||
@ -393,13 +407,14 @@ public final class TestNPOIFSMiniStore extends POITestCase {
|
|||||||
rdata = new byte[data.length];
|
rdata = new byte[data.length];
|
||||||
dis = new DocumentInputStream(entry);
|
dis = new DocumentInputStream(entry);
|
||||||
IOUtils.readFully(dis, rdata);
|
IOUtils.readFully(dis, rdata);
|
||||||
assertEquals(data, rdata);
|
assertArrayEquals(data, rdata);
|
||||||
dis.close();
|
dis.close();
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
fs.close();
|
fs.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMultiBlockStream() throws Exception {
|
public void testMultiBlockStream() throws Exception {
|
||||||
byte[] data1B = new byte[63];
|
byte[] data1B = new byte[63];
|
||||||
byte[] data2B = new byte[64+14];
|
byte[] data2B = new byte[64+14];
|
||||||
@ -451,12 +466,13 @@ public final class TestNPOIFSMiniStore extends POITestCase {
|
|||||||
DocumentInputStream dis = fs.createDocumentInputStream("mini1");
|
DocumentInputStream dis = fs.createDocumentInputStream("mini1");
|
||||||
IOUtils.readFully(dis, r1);
|
IOUtils.readFully(dis, r1);
|
||||||
dis.close();
|
dis.close();
|
||||||
assertEquals(data1B, r1);
|
assertArrayEquals(data1B, r1);
|
||||||
|
|
||||||
byte[] r2 = new byte[data2B.length];
|
byte[] r2 = new byte[data2B.length];
|
||||||
dis = fs.createDocumentInputStream("mini2");
|
dis = fs.createDocumentInputStream("mini2");
|
||||||
IOUtils.readFully(dis, r2);
|
IOUtils.readFully(dis, r2);
|
||||||
dis.close();
|
dis.close();
|
||||||
assertEquals(data2B, r2);
|
assertArrayEquals(data2B, r2);
|
||||||
|
fs.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,23 +17,19 @@
|
|||||||
|
|
||||||
package org.apache.poi.poifs.property;
|
package org.apache.poi.poifs.property;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import org.junit.runner.RunWith;
|
||||||
import junit.framework.TestSuite;
|
import org.junit.runners.Suite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for org.apache.poi.poifs.property<br/>
|
* 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 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,10 @@
|
|||||||
|
|
||||||
package org.apache.poi.poifs.property;
|
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.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -25,21 +29,20 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.poifs.storage.RawDataUtil;
|
import org.apache.poi.poifs.storage.RawDataUtil;
|
||||||
|
import org.apache.poi.util.LocaleUtil;
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to test DirectoryProperty functionality
|
* Class to test DirectoryProperty functionality
|
||||||
*
|
|
||||||
* @author Marc Johnson
|
|
||||||
*/
|
*/
|
||||||
public final class TestDirectoryProperty extends TestCase {
|
public final class TestDirectoryProperty {
|
||||||
private DirectoryProperty _property;
|
private DirectoryProperty _property;
|
||||||
private byte[] _testblock;
|
private byte[] _testblock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test constructing DirectoryProperty
|
* Test constructing DirectoryProperty
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testConstructor() throws IOException {
|
public void testConstructor() throws IOException {
|
||||||
createBasicDirectoryProperty();
|
createBasicDirectoryProperty();
|
||||||
verifyProperty();
|
verifyProperty();
|
||||||
@ -48,6 +51,7 @@ public final class TestDirectoryProperty extends TestCase {
|
|||||||
/**
|
/**
|
||||||
* Test pre-write functionality
|
* Test pre-write functionality
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testPreWrite() throws IOException {
|
public void testPreWrite() throws IOException {
|
||||||
createBasicDirectoryProperty();
|
createBasicDirectoryProperty();
|
||||||
_property.preWrite();
|
_property.preWrite();
|
||||||
@ -97,8 +101,8 @@ public final class TestDirectoryProperty extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void verifyChildren(int count) {
|
private void verifyChildren(int count) {
|
||||||
Iterator iter = _property.getChildren();
|
Iterator<Property> iter = _property.getChildren();
|
||||||
List children = new ArrayList();
|
List<Property> children = new ArrayList<Property>();
|
||||||
|
|
||||||
while (iter.hasNext())
|
while (iter.hasNext())
|
||||||
{
|
{
|
||||||
@ -116,7 +120,7 @@ public final class TestDirectoryProperty extends TestCase {
|
|||||||
iter = children.iterator();
|
iter = children.iterator();
|
||||||
while (iter.hasNext())
|
while (iter.hasNext())
|
||||||
{
|
{
|
||||||
Property child = ( Property ) iter.next();
|
Property child = iter.next();
|
||||||
Child next = child.getNextChild();
|
Child next = child.getNextChild();
|
||||||
|
|
||||||
if (next != null)
|
if (next != null)
|
||||||
@ -175,7 +179,7 @@ public final class TestDirectoryProperty extends TestCase {
|
|||||||
{
|
{
|
||||||
_testblock[ index ] = ( byte ) 0;
|
_testblock[ index ] = ( byte ) 0;
|
||||||
}
|
}
|
||||||
byte[] name_bytes = name.getBytes();
|
byte[] name_bytes = name.getBytes(LocaleUtil.CHARSET_1252);
|
||||||
|
|
||||||
for (index = 0; index < limit; index++)
|
for (index = 0; index < limit; index++)
|
||||||
{
|
{
|
||||||
@ -197,6 +201,7 @@ public final class TestDirectoryProperty extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAddChild() throws IOException {
|
public void testAddChild() throws IOException {
|
||||||
createBasicDirectoryProperty();
|
createBasicDirectoryProperty();
|
||||||
_property.addChild(new LocalProperty(1));
|
_property.addChild(new LocalProperty(1));
|
||||||
@ -224,6 +229,7 @@ public final class TestDirectoryProperty extends TestCase {
|
|||||||
_property.addChild(new LocalProperty(3));
|
_property.addChild(new LocalProperty(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDeleteChild() throws IOException {
|
public void testDeleteChild() throws IOException {
|
||||||
createBasicDirectoryProperty();
|
createBasicDirectoryProperty();
|
||||||
Property p1 = new LocalProperty(1);
|
Property p1 = new LocalProperty(1);
|
||||||
@ -244,6 +250,7 @@ public final class TestDirectoryProperty extends TestCase {
|
|||||||
_property.addChild(new LocalProperty(1));
|
_property.addChild(new LocalProperty(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testChangeName() throws IOException {
|
public void testChangeName() throws IOException {
|
||||||
createBasicDirectoryProperty();
|
createBasicDirectoryProperty();
|
||||||
Property p1 = new LocalProperty(1);
|
Property p1 = new LocalProperty(1);
|
||||||
@ -262,6 +269,7 @@ public final class TestDirectoryProperty extends TestCase {
|
|||||||
assertTrue(_property.changeName(p1, originalName));
|
assertTrue(_property.changeName(p1, originalName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testReadingConstructor() {
|
public void testReadingConstructor() {
|
||||||
String[] input = {
|
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",
|
"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",
|
||||||
|
@ -21,6 +21,7 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.poi.poifs.storage.RawDataUtil;
|
import org.apache.poi.poifs.storage.RawDataUtil;
|
||||||
|
import org.apache.poi.util.LocaleUtil;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
@ -137,7 +138,7 @@ public final class TestDocumentProperty extends TestCase {
|
|||||||
{
|
{
|
||||||
testblock[ index ] = ( byte ) 0x0;
|
testblock[ index ] = ( byte ) 0x0;
|
||||||
}
|
}
|
||||||
byte[] name_bytes = name.getBytes();
|
byte[] name_bytes = name.getBytes(LocaleUtil.CHARSET_1252);
|
||||||
|
|
||||||
for (index = 0; index < limit; index++)
|
for (index = 0; index < limit; index++)
|
||||||
{
|
{
|
||||||
|
@ -17,23 +17,27 @@
|
|||||||
|
|
||||||
package org.apache.poi.poifs.property;
|
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.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.poifs.common.POIFSConstants;
|
import org.apache.poi.poifs.common.POIFSConstants;
|
||||||
import org.apache.poi.poifs.storage.RawDataUtil;
|
import org.apache.poi.poifs.storage.RawDataUtil;
|
||||||
|
import org.apache.poi.util.LocaleUtil;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to test RootProperty functionality
|
* Class to test RootProperty functionality
|
||||||
*
|
*
|
||||||
* @author Marc Johnson
|
* @author Marc Johnson
|
||||||
*/
|
*/
|
||||||
public final class TestRootProperty extends TestCase {
|
public final class TestRootProperty {
|
||||||
private RootProperty _property;
|
private RootProperty _property;
|
||||||
private byte[] _testblock;
|
private byte[] _testblock;
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testConstructor() throws IOException {
|
public void testConstructor() throws IOException {
|
||||||
createBasicRootProperty();
|
createBasicRootProperty();
|
||||||
verifyProperty();
|
verifyProperty();
|
||||||
@ -67,7 +71,7 @@ public final class TestRootProperty extends TestCase {
|
|||||||
for (; index < 0x80; index++) {
|
for (; index < 0x80; index++) {
|
||||||
_testblock[index] = (byte) 0;
|
_testblock[index] = (byte) 0;
|
||||||
}
|
}
|
||||||
byte[] name_bytes = name.getBytes();
|
byte[] name_bytes = name.getBytes(LocaleUtil.CHARSET_1252);
|
||||||
|
|
||||||
for (index = 0; index < limit; index++) {
|
for (index = 0; index < limit; index++) {
|
||||||
_testblock[index * 2] = name_bytes[index];
|
_testblock[index * 2] = name_bytes[index];
|
||||||
@ -86,6 +90,7 @@ public final class TestRootProperty extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSetSize() {
|
public void testSetSize() {
|
||||||
for (int j = 0; j < 10; j++) {
|
for (int j = 0; j < 10; j++) {
|
||||||
createBasicRootProperty();
|
createBasicRootProperty();
|
||||||
@ -94,6 +99,7 @@ public final class TestRootProperty extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testReadingConstructor() {
|
public void testReadingConstructor() {
|
||||||
String[] input = {
|
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",
|
"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",
|
||||||
|
@ -17,35 +17,34 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.usermodel;
|
package org.apache.poi.ss.usermodel;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.util.LocaleUtil;
|
||||||
import org.apache.poi.ss.usermodel.DataFormatter;
|
import org.junit.Test;
|
||||||
import org.apache.poi.ss.usermodel.FormulaEvaluator;
|
|
||||||
import org.apache.poi.ss.usermodel.FractionFormat;
|
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for the Fraction Formatting part of DataFormatter.
|
* Tests for the Fraction Formatting part of DataFormatter.
|
||||||
* Largely taken from bug #54686
|
* Largely taken from bug #54686
|
||||||
*/
|
*/
|
||||||
public final class TestFractionFormat extends TestCase {
|
public final class TestFractionFormat {
|
||||||
public void testSingle() throws Exception {
|
@Test
|
||||||
|
public void testSingle() throws Exception {
|
||||||
FractionFormat f = new FractionFormat("", "##");
|
FractionFormat f = new FractionFormat("", "##");
|
||||||
double val = 321.321;
|
double val = 321.321;
|
||||||
String ret = f.format(val);
|
String ret = f.format(val);
|
||||||
assertEquals("26027/81", ret);
|
assertEquals("26027/81", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTruthFile() throws Exception {
|
public void testTruthFile() throws Exception {
|
||||||
File truthFile = HSSFTestDataSamples.getSampleFile("54686_fraction_formats.txt");
|
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");
|
Workbook wb = HSSFTestDataSamples.openSampleWorkbook("54686_fraction_formats.xls");
|
||||||
Sheet sheet = wb.getSheetAt(0);
|
Sheet sheet = wb.getSheetAt(0);
|
||||||
DataFormatter formatter = new DataFormatter();
|
DataFormatter formatter = new DataFormatter();
|
||||||
@ -73,6 +72,7 @@ public final class TestFractionFormat extends TestCase {
|
|||||||
}
|
}
|
||||||
truthLine = reader.readLine();
|
truthLine = reader.readLine();
|
||||||
}
|
}
|
||||||
|
wb.close();
|
||||||
reader.close();
|
reader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,20 +28,15 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public final class TestHexDump {
|
public class TestHexDump {
|
||||||
@Test
|
@Test
|
||||||
public void testDump() throws IOException {
|
public void testDump() throws IOException {
|
||||||
byte[] testArray = new byte[ 256 ];
|
byte[] testArray = testArray();
|
||||||
|
|
||||||
for (int j = 0; j < 256; j++) {
|
|
||||||
testArray[ j ] = ( byte ) j;
|
|
||||||
}
|
|
||||||
ByteArrayOutputStream streamAct = new ByteArrayOutputStream();
|
ByteArrayOutputStream streamAct = new ByteArrayOutputStream();
|
||||||
HexDump.dump(testArray, 0, streamAct, 0);
|
HexDump.dump(testArray, 0, streamAct, 0);
|
||||||
byte bytesAct[] = streamAct.toByteArray();
|
byte bytesAct[] = streamAct.toByteArray();
|
||||||
@ -55,7 +50,7 @@ public final class TestHexDump {
|
|||||||
HexDump.dump(testArray, 0x10000000L, streamAct, 0);
|
HexDump.dump(testArray, 0x10000000L, streamAct, 0);
|
||||||
bytesAct = streamAct.toByteArray();
|
bytesAct = streamAct.toByteArray();
|
||||||
bytesExp = toHexDump(0x10000000L,0);
|
bytesExp = toHexDump(0x10000000L,0);
|
||||||
|
|
||||||
assertEquals("array size mismatch", bytesExp.length, bytesAct.length);
|
assertEquals("array size mismatch", bytesExp.length, bytesAct.length);
|
||||||
assertArrayEquals("array mismatch", bytesExp, bytesAct);
|
assertArrayEquals("array mismatch", bytesExp, bytesAct);
|
||||||
|
|
||||||
@ -108,15 +103,15 @@ public final class TestHexDump {
|
|||||||
// verify proper behaviour with empty byte array
|
// verify proper behaviour with empty byte array
|
||||||
streamAct.reset();
|
streamAct.reset();
|
||||||
HexDump.dump( new byte[0], 0, streamAct, 0 );
|
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) {
|
private byte[] toHexDump(long offset, int index) {
|
||||||
StringBuilder strExp = new StringBuilder(), chrs = new StringBuilder();
|
StringBuilder strExp = new StringBuilder(), chrs = new StringBuilder();
|
||||||
Object obj[] = new Object[33];
|
Object obj[] = new Object[33];
|
||||||
StringBuilder format = new StringBuilder();
|
StringBuilder format = new StringBuilder();
|
||||||
|
|
||||||
for (int j = 0; j < 16 && (index + j*16) < 256; j++) {
|
for (int j = 0; j < 16 && (index + j*16) < 256; j++) {
|
||||||
obj[0] = offset+index+j*16;
|
obj[0] = offset+index+j*16;
|
||||||
chrs.setLength(0);
|
chrs.setLength(0);
|
||||||
@ -133,7 +128,7 @@ public final class TestHexDump {
|
|||||||
}
|
}
|
||||||
obj[17] = chrs.toString();
|
obj[17] = chrs.toString();
|
||||||
format.append("%18$s"+HexDump.EOL);
|
format.append("%18$s"+HexDump.EOL);
|
||||||
|
|
||||||
String str = String.format(LocaleUtil.getUserLocale(), format.toString(), obj);
|
String str = String.format(LocaleUtil.getUserLocale(), format.toString(), obj);
|
||||||
strExp.append(str);
|
strExp.append(str);
|
||||||
}
|
}
|
||||||
@ -144,11 +139,11 @@ public final class TestHexDump {
|
|||||||
@Test
|
@Test
|
||||||
public void testToHex() {
|
public void testToHex() {
|
||||||
assertEquals("000A", HexDump.toHex((short)0xA));
|
assertEquals("000A", HexDump.toHex((short)0xA));
|
||||||
|
|
||||||
assertEquals("[]", HexDump.toHex(new short[] { }));
|
assertEquals("[]", HexDump.toHex(new short[] { }));
|
||||||
assertEquals("[000A]", HexDump.toHex(new short[] { 0xA }));
|
assertEquals("[000A]", HexDump.toHex(new short[] { 0xA }));
|
||||||
assertEquals("[000A, 000B]", HexDump.toHex(new short[] { 0xA, 0xB }));
|
assertEquals("[000A, 000B]", HexDump.toHex(new short[] { 0xA, 0xB }));
|
||||||
|
|
||||||
assertEquals("0A", HexDump.toHex((byte)0xA));
|
assertEquals("0A", HexDump.toHex((byte)0xA));
|
||||||
assertEquals("0000000A", HexDump.toHex(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("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("FFFF", HexDump.toHex((short)0xFFFF));
|
||||||
|
|
||||||
assertEquals("00000000000004D2", HexDump.toHex(1234l));
|
assertEquals("00000000000004D2", HexDump.toHex(1234l));
|
||||||
|
|
||||||
assertEquals("0xFE", HexDump.byteToHex(-2));
|
assertEquals("0xFE", HexDump.byteToHex(-2));
|
||||||
assertEquals("0x25", HexDump.byteToHex(37));
|
assertEquals("0x25", HexDump.byteToHex(37));
|
||||||
assertEquals("0xFFFE", HexDump.shortToHex(-2));
|
assertEquals("0xFFFE", HexDump.shortToHex(-2));
|
||||||
@ -178,20 +173,15 @@ public final class TestHexDump {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDumpToString() throws Exception {
|
public void testDumpToString() throws Exception {
|
||||||
byte[] testArray = new byte[ 256 ];
|
byte[] testArray = testArray();
|
||||||
|
|
||||||
for (int j = 0; j < 256; j++)
|
|
||||||
{
|
|
||||||
testArray[ j ] = ( byte ) j;
|
|
||||||
}
|
|
||||||
String dump = HexDump.dump(testArray, 0, 0);
|
String dump = HexDump.dump(testArray, 0, 0);
|
||||||
//System.out.println("Hex: \n" + dump);
|
//System.out.println("Hex: \n" + dump);
|
||||||
assertTrue("Had: \n" + dump,
|
assertTrue("Had: \n" + dump,
|
||||||
dump.contains("0123456789:;<=>?"));
|
dump.contains("0123456789:;<=>?"));
|
||||||
|
|
||||||
dump = HexDump.dump(testArray, 2, 1);
|
dump = HexDump.dump(testArray, 2, 1);
|
||||||
//System.out.println("Hex: \n" + dump);
|
//System.out.println("Hex: \n" + dump);
|
||||||
assertTrue("Had: \n" + dump,
|
assertTrue("Had: \n" + dump,
|
||||||
dump.contains("123456789:;<=>?@"));
|
dump.contains("123456789:;<=>?@"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,88 +198,48 @@ public final class TestHexDump {
|
|||||||
public void testDumpToStringOutOfIndex3() throws Exception {
|
public void testDumpToStringOutOfIndex3() throws Exception {
|
||||||
HexDump.dump(new byte[ 1 ], 0, 1);
|
HexDump.dump(new byte[ 1 ], 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDumpToPrintStream() throws IOException {
|
public void testDumpToPrintStream() throws IOException {
|
||||||
byte[] testArray = new byte[ 256 ];
|
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;
|
||||||
|
|
||||||
for (int j = 0; j < 256; j++)
|
byteIn.reset();
|
||||||
{
|
byteOut.reset();
|
||||||
testArray[ j ] = ( byte ) j;
|
HexDump.dump(byteIn, out, 0, 256);
|
||||||
}
|
str = new String(byteOut.toByteArray(), LocaleUtil.CHARSET_1252);
|
||||||
|
assertTrue("Had: \n" + str, str.contains("0123456789:;<=>?"));
|
||||||
|
|
||||||
InputStream in = new ByteArrayInputStream(testArray);
|
// test with more than we have
|
||||||
try {
|
byteIn.reset();
|
||||||
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
|
byteOut.reset();
|
||||||
PrintStream out = new PrintStream(byteOut);
|
HexDump.dump(byteIn, out, 0, 1000);
|
||||||
try {
|
str = new String(byteOut.toByteArray(), LocaleUtil.CHARSET_1252);
|
||||||
HexDump.dump(in, out, 0, 256);
|
assertTrue("Had: \n" + str, str.contains("0123456789:;<=>?"));
|
||||||
} 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);
|
// test with -1
|
||||||
try {
|
byteIn.reset();
|
||||||
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
|
byteOut.reset();
|
||||||
PrintStream out = new PrintStream(byteOut);
|
HexDump.dump(byteIn, out, 0, -1);
|
||||||
try {
|
str = new String(byteOut.toByteArray(), LocaleUtil.CHARSET_1252);
|
||||||
// test with -1
|
assertTrue("Had: \n" + str, str.contains("0123456789:;<=>?"));
|
||||||
HexDump.dump(in, out, 0, -1);
|
|
||||||
} finally {
|
byteIn.reset();
|
||||||
out.close();
|
byteOut.reset();
|
||||||
}
|
HexDump.dump(byteIn, out, 1, 235);
|
||||||
|
str = new String(byteOut.toByteArray(), LocaleUtil.CHARSET_1252);
|
||||||
String str = new String(byteOut.toByteArray());
|
assertTrue("Line contents should be moved by one now, but Had: \n" + str,
|
||||||
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,
|
|
||||||
str.contains("123456789:;<=>?@"));
|
str.contains("123456789:;<=>?@"));
|
||||||
} finally {
|
|
||||||
in.close();
|
byteIn.close();
|
||||||
}
|
byteOut.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstruct() throws Exception {
|
public void testConstruct() throws Exception {
|
||||||
// to cover private constructor
|
// to cover private constructor
|
||||||
@ -300,25 +250,35 @@ public final class TestHexDump {
|
|||||||
c.setAccessible(true);
|
c.setAccessible(true);
|
||||||
|
|
||||||
// call it
|
// call it
|
||||||
assertNotNull(c.newInstance((Object[]) null));
|
assertNotNull(c.newInstance((Object[]) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMain() throws Exception {
|
public void testMain() throws Exception {
|
||||||
File file = TempFile.createTempFile("HexDump", ".dat");
|
File file = TempFile.createTempFile("HexDump", ".dat");
|
||||||
try {
|
try {
|
||||||
FileOutputStream out = new FileOutputStream(file);
|
FileOutputStream out = new FileOutputStream(file);
|
||||||
try {
|
try {
|
||||||
IOUtils.copy(new ByteArrayInputStream("teststring".getBytes()), out);
|
IOUtils.copy(new ByteArrayInputStream("teststring".getBytes(LocaleUtil.CHARSET_1252)), out);
|
||||||
} finally {
|
} finally {
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
assertTrue(file.exists());
|
assertTrue(file.exists());
|
||||||
assertTrue(file.length() > 0);
|
assertTrue(file.length() > 0);
|
||||||
|
|
||||||
HexDump.main(new String[] { file.getAbsolutePath() });
|
HexDump.main(new String[] { file.getAbsolutePath() });
|
||||||
} finally {
|
} finally {
|
||||||
assertTrue(file.exists() && file.delete());
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,36 +16,42 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.util;
|
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.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Glen Stampoultzis
|
* @author Glen Stampoultzis
|
||||||
*/
|
*/
|
||||||
public class TestTempFile extends TestCase {
|
public class TestTempFile {
|
||||||
TempFile tempFile;
|
@Test
|
||||||
|
|
||||||
public void testCreateTempFile()
|
public void testCreateTempFile()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
File tempFile = TempFile.createTempFile("test", ".txt");
|
File tempFile = TempFile.createTempFile("test", ".txt");
|
||||||
FileWriter w = new FileWriter(tempFile);
|
FileOutputStream fos = new FileOutputStream(tempFile);
|
||||||
w.write("testing");
|
fos.write(1);
|
||||||
w.close();
|
fos.close();
|
||||||
assertTrue(tempFile.exists());
|
assertTrue(tempFile.exists());
|
||||||
assertEquals("poifiles", tempFile.getParentFile().getName());
|
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.
|
// 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() {
|
public void testConstructor() {
|
||||||
// can currently be constructed...
|
// can currently be constructed...
|
||||||
new TempFile();
|
new TempFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void testSetTempFileCreationStrategy() throws IOException {
|
public void testSetTempFileCreationStrategy() throws IOException {
|
||||||
TempFile.setTempFileCreationStrategy(new TempFile.DefaultTempFileCreationStrategy());
|
TempFile.setTempFileCreationStrategy(new TempFile.DefaultTempFileCreationStrategy());
|
||||||
|
|
||||||
@ -57,11 +63,6 @@ public class TestTempFile extends TestCase {
|
|||||||
assertNotNull(file1);
|
assertNotNull(file1);
|
||||||
assertTrue(file1.delete());
|
assertTrue(file1.delete());
|
||||||
|
|
||||||
try {
|
TempFile.setTempFileCreationStrategy(null);
|
||||||
TempFile.setTempFileCreationStrategy(null);
|
|
||||||
fail("Expecting an exception here");
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
// expecting an exception here...
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user