/**
* Test Open Packaging Convention package model compliance.
- *
+ *
* M1.11 : A package implementer shall neither create nor recognize a part with
* a part name derived from another part name by appending segments to it.
- *
+ *
* @author Julien Chable
*/
public class TestOPCCompliancePackageModel extends TestCase {
- public TestOPCCompliancePackageModel(String name) {
- super(name);
- }
-
/**
* A package implementer shall neither create nor recognize a part with a
* part name derived from another part name by appending segments to it.
/**
* Try to add a relationship to a relationship part.
- *
+ *
* Check rule M1.25: The Relationships part shall not have relationships to
* any other part. Package implementers shall enforce this requirement upon
* the attempt to create such a relationship and shall treat any such
*/
public final class TestOPCCompliancePartName extends TestCase {
- public TestOPCCompliancePartName(String name) {
- super(name);
- }
-
/**
* Test some common invalid names.
*
import org.apache.poi.openxml4j.opc.OPCPackage;
/**
- * Tests for XSSFReader
+ * Tests for {@link XSSFReader}
*/
-public class TestXSSFReader extends TestCase {
+public final class TestXSSFReader extends TestCase {
private String dirName;
-
- public TestXSSFReader(String name) {
- super(name);
-
+
+ @Override
+ protected void setUp() {
+
dirName = System.getProperty("HSSF.testdata.path");
assertNotNull(dirName);
assertTrue( (new File(dirName)).exists() );
-
+
// Use system out logger
- System.setProperty(
- "org.apache.poi.util.POILogger",
- "org.apache.poi.util.SystemOutLogger"
- );
+ System.setProperty(
+ "org.apache.poi.util.POILogger",
+ "org.apache.poi.util.SystemOutLogger"
+ );
+ }
+
+ public void testGetBits() throws Exception {
+ File f = new File(dirName, "SampleSS.xlsx");
+ OPCPackage pkg = OPCPackage.open(f.toString());
+
+ XSSFReader r = new XSSFReader(pkg);
+
+ assertNotNull(r.getWorkbookData());
+ assertNotNull(r.getSharedStringsData());
+ assertNotNull(r.getStylesData());
+
+ assertNotNull(r.getSharedStringsTable());
+ assertNotNull(r.getStylesTable());
+ }
+
+ public void testStyles() throws Exception {
+ File f = new File(dirName, "SampleSS.xlsx");
+ OPCPackage pkg = OPCPackage.open(f.toString());
+
+ XSSFReader r = new XSSFReader(pkg);
+
+ assertEquals(3, r.getStylesTable().getFonts().size());
+ assertEquals(0, r.getStylesTable()._getNumberFormatSize());
+ }
+
+ public void testStrings() throws Exception {
+ File f = new File(dirName, "SampleSS.xlsx");
+ OPCPackage pkg = OPCPackage.open(f.toString());
+
+ XSSFReader r = new XSSFReader(pkg);
+
+ assertEquals(11, r.getSharedStringsTable().getItems().size());
+ assertEquals("Test spreadsheet", new XSSFRichTextString(r.getSharedStringsTable().getEntryAt(0)).toString());
+ }
+
+ public void testSheets() throws Exception {
+ File f = new File(dirName, "SampleSS.xlsx");
+ OPCPackage pkg = OPCPackage.open(f.toString());
+
+ XSSFReader r = new XSSFReader(pkg);
+ byte[] data = new byte[4096];
+
+ // By r:id
+ assertNotNull(r.getSheet("rId2"));
+ int read = IOUtils.readFully(r.getSheet("rId2"), data);
+ assertEquals(974, read);
+
+ // All
+ Iterator<InputStream> it = r.getSheetsData();
+
+ int count = 0;
+ while(it.hasNext()) {
+ count++;
+ InputStream inp = it.next();
+ assertNotNull(inp);
+ read = IOUtils.readFully(inp, data);
+ inp.close();
+
+ assertTrue(read > 400);
+ assertTrue(read < 1500);
+ }
+ assertEquals(3, count);
+ }
+
+ /**
+ * Check that the sheet iterator returns sheets in the logical order
+ * (as they are defined in the workbook.xml)
+ */
+ public void testOrderOfSheets() throws Exception {
+ File f = new File(dirName, "reordered_sheets.xlsx");
+ OPCPackage pkg = OPCPackage.open(f.toString());
+
+ XSSFReader r = new XSSFReader(pkg);
+
+ String[] sheetNames = {"Sheet4", "Sheet2", "Sheet3", "Sheet1"};
+ XSSFReader.SheetIterator it = (XSSFReader.SheetIterator)r.getSheetsData();
+
+ int count = 0;
+ while(it.hasNext()) {
+ InputStream inp = it.next();
+ assertNotNull(inp);
+ inp.close();
+
+ assertEquals(sheetNames[count], it.getSheetName());
+ count++;
+ }
+ assertEquals(4, count);
}
-
- public void testGetBits() throws Exception {
- File f = new File(dirName, "SampleSS.xlsx");
- OPCPackage pkg = OPCPackage.open(f.toString());
-
- XSSFReader r = new XSSFReader(pkg);
-
- assertNotNull(r.getWorkbookData());
- assertNotNull(r.getSharedStringsData());
- assertNotNull(r.getStylesData());
-
- assertNotNull(r.getSharedStringsTable());
- assertNotNull(r.getStylesTable());
- }
-
- public void testStyles() throws Exception {
- File f = new File(dirName, "SampleSS.xlsx");
- OPCPackage pkg = OPCPackage.open(f.toString());
-
- XSSFReader r = new XSSFReader(pkg);
-
- assertEquals(3, r.getStylesTable().getFonts().size());
- assertEquals(0, r.getStylesTable()._getNumberFormatSize());
- }
-
- public void testStrings() throws Exception {
- File f = new File(dirName, "SampleSS.xlsx");
- OPCPackage pkg = OPCPackage.open(f.toString());
-
- XSSFReader r = new XSSFReader(pkg);
-
- assertEquals(11, r.getSharedStringsTable().getItems().size());
- assertEquals("Test spreadsheet", new XSSFRichTextString(r.getSharedStringsTable().getEntryAt(0)).toString());
- }
-
- public void testSheets() throws Exception {
- File f = new File(dirName, "SampleSS.xlsx");
- OPCPackage pkg = OPCPackage.open(f.toString());
-
- XSSFReader r = new XSSFReader(pkg);
- byte[] data = new byte[4096];
-
- // By r:id
- assertNotNull(r.getSheet("rId2"));
- int read = IOUtils.readFully(r.getSheet("rId2"), data);
- assertEquals(974, read);
-
- // All
- Iterator<InputStream> it = r.getSheetsData();
-
- int count = 0;
- while(it.hasNext()) {
- count++;
- InputStream inp = it.next();
- assertNotNull(inp);
- read = IOUtils.readFully(inp, data);
- inp.close();
-
- assertTrue(read > 400);
- assertTrue(read < 1500);
- }
- assertEquals(3, count);
- }
-
- /**
- * Check that the sheet iterator returns sheets in the logical order
- * (as they are defined in the workbook.xml)
- */
- public void testOrderOfSheets() throws Exception {
- File f = new File(dirName, "reordered_sheets.xlsx");
- OPCPackage pkg = OPCPackage.open(f.toString());
-
- XSSFReader r = new XSSFReader(pkg);
-
- String[] sheetNames = {"Sheet4", "Sheet2", "Sheet3", "Sheet1"};
- XSSFReader.SheetIterator it = (XSSFReader.SheetIterator)r.getSheetsData();
-
- int count = 0;
- while(it.hasNext()) {
- InputStream inp = it.next();
- assertNotNull(inp);
- inp.close();
-
- assertEquals(sheetNames[count], it.getSheetName());
- count++;
- }
- assertEquals(4, count);
-
- }
}
import org.apache.poi.xssf.XSSFTestDataSamples;
public final class TestXSSFFormulaEvaluation extends TestCase {
- public TestXSSFFormulaEvaluation(String name) {
- super(name);
-
+ @Override
+ protected void setUp() {
// Use system out logger
System.setProperty(
"org.apache.poi.util.POILogger",
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.XSSFTestDataSamples;
-public class TestXSSFHyperlink extends TestCase {
- public TestXSSFHyperlink(String name) {
- super(name);
-
+public final class TestXSSFHyperlink extends TestCase {
+ @Override
+ protected void setUp() {
// Use system out logger
- System.setProperty(
- "org.apache.poi.util.POILogger",
- "org.apache.poi.util.SystemOutLogger"
- );
+ System.setProperty(
+ "org.apache.poi.util.POILogger",
+ "org.apache.poi.util.SystemOutLogger"
+ );
}
-
- public void testAddNew() throws Exception {
-
- }
- public void testLoadExisting() throws Exception {
+ public void testLoadExisting() throws Exception {
File xml = new File(
System.getProperty("HSSF.testdata.path") +
File.separator + "WithMoreVariousData.xlsx"
);
assertTrue(xml.exists());
-
+
XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
assertEquals(3, workbook.getNumberOfSheets());
-
+
XSSFSheet sheet = (XSSFSheet)workbook.getSheetAt(0);
// Check the hyperlinks
doTestHyperlinkContents(sheet);
}
- public void testLoadSave() throws Exception {
+ public void testLoadSave() throws Exception {
File xml = new File(
System.getProperty("HSSF.testdata.path") +
File.separator + "WithMoreVariousData.xlsx"
);
assertTrue(xml.exists());
-
+
XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
CreationHelper createHelper = workbook.getCreationHelper();
assertEquals(3, workbook.getNumberOfSheets());
// Check hyperlinks
assertEquals(4, sheet.getNumHyperlinks());
doTestHyperlinkContents(sheet);
-
-
+
+
// Write out, and check
// Load up again, check all links still there
assertNotNull(wb2.getSheetAt(0));
assertNotNull(wb2.getSheetAt(1));
assertNotNull(wb2.getSheetAt(2));
-
+
sheet = (XSSFSheet)wb2.getSheetAt(0);
-
+
// Check hyperlinks again
assertEquals(4, sheet.getNumHyperlinks());
doTestHyperlinkContents(sheet);
-
-
+
+
// Add one more, and re-check
Row r17 = sheet.createRow(17);
Cell r17c = r17.createCell(2);
-
+
Hyperlink hyperlink = createHelper.createHyperlink(Hyperlink.LINK_URL);
hyperlink.setAddress("http://poi.apache.org/spreadsheet/");
hyperlink.setLabel("POI SS Link");
r17c.setHyperlink(hyperlink);
-
+
assertEquals(5, sheet.getNumHyperlinks());
doTestHyperlinkContents(sheet);
-
- assertEquals(Hyperlink.LINK_URL,
+
+ assertEquals(Hyperlink.LINK_URL,
sheet.getRow(17).getCell(2).getHyperlink().getType());
- assertEquals("POI SS Link",
+ assertEquals("POI SS Link",
sheet.getRow(17).getCell(2).getHyperlink().getLabel());
- assertEquals("http://poi.apache.org/spreadsheet/",
+ assertEquals("http://poi.apache.org/spreadsheet/",
sheet.getRow(17).getCell(2).getHyperlink().getAddress());
-
-
+
+
// Save and re-load once more
- XSSFWorkbook wb3 = XSSFTestDataSamples.writeOutAndReadBack(wb2);
+ XSSFWorkbook wb3 = XSSFTestDataSamples.writeOutAndReadBack(wb2);
assertEquals(3, wb3.getNumberOfSheets());
assertNotNull(wb3.getSheetAt(0));
assertNotNull(wb3.getSheetAt(1));
assertNotNull(wb3.getSheetAt(2));
-
+
sheet = wb3.getSheetAt(0);
-
+
assertEquals(5, sheet.getNumHyperlinks());
doTestHyperlinkContents(sheet);
-
- assertEquals(Hyperlink.LINK_URL,
+
+ assertEquals(Hyperlink.LINK_URL,
sheet.getRow(17).getCell(2).getHyperlink().getType());
- assertEquals("POI SS Link",
+ assertEquals("POI SS Link",
sheet.getRow(17).getCell(2).getHyperlink().getLabel());
- assertEquals("http://poi.apache.org/spreadsheet/",
+ assertEquals("http://poi.apache.org/spreadsheet/",
sheet.getRow(17).getCell(2).getHyperlink().getAddress());
- }
+ }
- /**
- * Only for WithMoreVariousData.xlsx !
- */
- private void doTestHyperlinkContents(XSSFSheet sheet) {
+ /**
+ * Only for WithMoreVariousData.xlsx !
+ */
+ private void doTestHyperlinkContents(XSSFSheet sheet) {
assertNotNull(sheet.getRow(3).getCell(2).getHyperlink());
assertNotNull(sheet.getRow(14).getCell(2).getHyperlink());
assertNotNull(sheet.getRow(15).getCell(2).getHyperlink());
assertNotNull(sheet.getRow(16).getCell(2).getHyperlink());
-
+
// First is a link to poi
- assertEquals(Hyperlink.LINK_URL,
+ assertEquals(Hyperlink.LINK_URL,
sheet.getRow(3).getCell(2).getHyperlink().getType());
- assertEquals(null,
+ assertEquals(null,
sheet.getRow(3).getCell(2).getHyperlink().getLabel());
- assertEquals("http://poi.apache.org/",
+ assertEquals("http://poi.apache.org/",
sheet.getRow(3).getCell(2).getHyperlink().getAddress());
-
+
// Next is an internal doc link
- assertEquals(Hyperlink.LINK_DOCUMENT,
+ assertEquals(Hyperlink.LINK_DOCUMENT,
sheet.getRow(14).getCell(2).getHyperlink().getType());
- assertEquals("Internal hyperlink to A2",
+ assertEquals("Internal hyperlink to A2",
sheet.getRow(14).getCell(2).getHyperlink().getLabel());
- assertEquals("Sheet1!A2",
+ assertEquals("Sheet1!A2",
sheet.getRow(14).getCell(2).getHyperlink().getAddress());
-
+
// Next is a file
- assertEquals(Hyperlink.LINK_FILE,
+ assertEquals(Hyperlink.LINK_FILE,
sheet.getRow(15).getCell(2).getHyperlink().getType());
- assertEquals(null,
+ assertEquals(null,
sheet.getRow(15).getCell(2).getHyperlink().getLabel());
- assertEquals("WithVariousData.xlsx",
+ assertEquals("WithVariousData.xlsx",
sheet.getRow(15).getCell(2).getHyperlink().getAddress());
-
+
// Last is a mailto
- assertEquals(Hyperlink.LINK_EMAIL,
+ assertEquals(Hyperlink.LINK_EMAIL,
sheet.getRow(16).getCell(2).getHyperlink().getType());
- assertEquals(null,
+ assertEquals(null,
sheet.getRow(16).getCell(2).getHyperlink().getLabel());
- assertEquals("mailto:dev@poi.apache.org?subject=XSSF%20Hyperlinks",
+ assertEquals("mailto:dev@poi.apache.org?subject=XSSF%20Hyperlinks",
sheet.getRow(16).getCell(2).getHyperlink().getAddress());
- }
+ }
}
package org.apache.poi.hdf.model;
-
-import junit.framework.TestCase;
-
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
+import junit.framework.TestCase;
/**
- * Class to test HDFDocument functionality
+ * Class to test {@link HDFDocument} functionality
*
* @author Bob Otterberg
*/
-public final class TestHDFDocument
- extends TestCase
-{
-
- public TestHDFDocument( String name )
- {
- super( name );
+public final class TestHDFDocument extends TestCase {
+ public void testStopJUnitComplainintAboutNoTests() {
+ // TODO - fix these junits
}
- public void testStopJUnitComplainintAboutNoTests()
- throws Exception
- {
-
+ private static InputStream openSample(String sampleFileName) {
+ String fullPathName = System.getProperty("HDF.testdata.path") + "/" + sampleFileName;
+ try {
+ return new FileInputStream(System.getProperty("HDF.testdata.path"));
+ } catch (FileNotFoundException e) {
+ throw new RuntimeException("Sample HDF file '" + fullPathName + "' was not found.");
+ }
}
/**
- * TEST NAME: Test Read Empty <P>
* OBJECTIVE: Test that HDF can read an empty document (empty.doc).<P>
* SUCCESS: HDF reads the document. Matches values in their particular positions.<P>
* FAILURE: HDF does not read the document or excepts. HDF cannot identify values
* in the document in their known positions.<P>
- *
*/
- public void fixme_testEmpty()
- throws IOException
- {
-
- String filename = System.getProperty( "HDF.testdata.path" );
-
-
- filename = filename + "/empty.doc";
-
- FileInputStream stream = new FileInputStream( filename );
-
- HDFDocument empty = new HDFDocument( stream );
-
- stream.close();
-
+ public void fixme_testEmpty() throws IOException {
+ InputStream stream = openSample("empty.doc");
+ new HDFDocument(stream);
}
-
/**
- * TEST NAME: Test Simple <P>
* OBJECTIVE: Test that HDF can read an _very_ simple document (simple.doc).<P>
* SUCCESS: HDF reads the document. Matches values in their particular positions.<P>
* FAILURE: HDF does not read the document or excepts. HDF cannot identify values
* in the document in their known positions.<P>
- *
*/
- public void fixme_testSimple()
- throws IOException
- {
- String filename = System.getProperty( "HDF.testdata.path" );
- filename = filename + "/simple.doc";
- FileInputStream stream = new FileInputStream( filename );
- HDFDocument empty = new HDFDocument( stream );
- stream.close();
+ public void fixme_testSimple() throws IOException {
+ InputStream stream = openSample("simple.doc");
+ new HDFDocument(stream);
}
/**
- * TEST NAME: Test Read Simple List <P>
* OBJECTIVE: Test that HDF can read a document containing a simple list (simple-list.doc).<P>
* SUCCESS: HDF reads the document. Matches values in their particular positions.<P>
* FAILURE: HDF does not read the document or excepts. HDF cannot identify values
* in the document in their known positions.<P>
*
*/
- public void fixme_testSimpleList()
- throws IOException
- {
- String filename = System.getProperty( "HDF.testdata.path" );
-
- filename = filename + "/simple-list.doc";
- FileInputStream stream = new FileInputStream( filename );
- HDFDocument empty = new HDFDocument( stream );
- stream.close();
+ public void fixme_testSimpleList() throws IOException {
+ InputStream stream = openSample("simple-list.doc");
+ new HDFDocument(stream);
}
/**
- * TEST NAME: Test Read Simple Table <P>
* OBJECTIVE: Test that HDF can read a document containing a simple table (simple-table.doc).<P>
* SUCCESS: HDF reads the document. Matches values in their particular positions.<P>
* FAILURE: HDF does not read the document or excepts. HDF cannot identify values
* in the document in their known positions.<P>
- *
*/
- public void fixme_testSimpleTable()
- throws IOException
- {
- String filename = System.getProperty( "HDF.testdata.path" );
-
- filename = filename + "/simple-table.doc";
- FileInputStream stream = new FileInputStream( filename );
- HDFDocument empty = new HDFDocument( stream );
- stream.close();
- }
-
- public static void main( String[] ignored_args )
- {
- String path = System.getProperty( "HDF.testdata.path" );
-
- // assume this is relative to basedir
- if ( path == null )
- {
- System.setProperty(
- "HDF.testdata.path",
- "src/scratchpad/testcases/org/apache/poi/hdf/data" );
- }
- System.out.println( "Testing org.apache.poi.hdf.model.HDFDocument" );
-
- junit.textui.TestRunner.run( TestHDFDocument.class );
+ public void fixme_testSimpleTable() throws IOException {
+ InputStream stream = openSample("simple-table.doc");
+ new HDFDocument(stream);
}
}
-
-
private TextPieceTable fakeTPT = new TextPieceTable();
- public TestCHPBinTable(String name)
- {
- super(name);
- }
-
public void testReadWrite()
throws Exception
{
private DocumentProperties _documentProperties = null;
private HWPFDocFixture _hWPFDocFixture;
- public TestDocumentProperties(String name)
- {
- super(name);
- }
-
-
public void testReadWrite()
throws Exception
{
private FileInformationBlock _fileInformationBlock = null;
private HWPFDocFixture _hWPFDocFixture;
- public TestFileInformationBlock(String name)
- {
- super(name);
- }
-
public void testReadWrite()
throws Exception
{
private FontTable _fontTable = null;
private HWPFDocFixture _hWPFDocFixture;
- public TestFontTable(String name)
- {
- super(name);
- }
-
public void testReadWrite()
throws Exception
{
private TextPieceTable fakeTPT = new TextPieceTable();
- public TestPAPBinTable(String name)
- {
- super(name);
- }
-
public void testReadWrite()
throws Exception
{
private PlexOfCps _plexOfCps = null;
private HWPFDocFixture _hWPFDocFixture;
- public TestPlexOfCps(String name)
- {
- super(name);
- }
- public void testWriteRead()
- throws Exception
- {
+ public void testWriteRead() {
_plexOfCps = new PlexOfCps(4);
int last = 0;
{
private HWPFDocFixture _hWPFDocFixture;
- public TestSectionTable(String name)
- {
- super(name);
- }
-
public void testReadWrite()
throws Exception
{
private StyleSheet _styleSheet = null;
private HWPFDocFixture _hWPFDocFixture;
-
- public TestStyleSheet(String name)
- {
- super(name);
- }
-
public void testReadWrite()
throws Exception
{
private HWPFDocFixture _hWPFDocFixture;
private String dirname;
- public TestTextPieceTable(String name)
- {
- super(name);
- }
-
public void testReadWrite()
throws Exception
{
*
* @author Rainer Klute (klute@rainer-klute.de)
*/
-public class TestBasic extends TestCase
-{
+public final class TestBasic extends TestCase {
- static final String POI_FS = "TestGermanWord90.doc";
- static final String[] POI_FILES = new String[]
+ private static final String POI_FS = "TestGermanWord90.doc";
+ private static final String[] POI_FILES = new String[]
{
"\005SummaryInformation",
"\005DocumentSummaryInformation",
"\001CompObj",
"1Table"
};
- static final int BYTE_ORDER = 0xfffe;
- static final int FORMAT = 0x0000;
- static final int OS_VERSION = 0x00020A04;
- static final byte[] CLASS_ID =
+ private static final int BYTE_ORDER = 0xfffe;
+ private static final int FORMAT = 0x0000;
+ private static final int OS_VERSION = 0x00020A04;
+ private static final byte[] CLASS_ID =
{
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
};
- static final int[] SECTION_COUNT =
+ private static final int[] SECTION_COUNT =
{1, 2};
- static final boolean[] IS_SUMMARY_INFORMATION =
+ private static final boolean[] IS_SUMMARY_INFORMATION =
{true, false};
- static final boolean[] IS_DOCUMENT_SUMMARY_INFORMATION =
- {false, true};
-
- POIFile[] poiFiles;
-
-
-
- /**
- * <p>Test case constructor.</p>
- *
- * @param name The test case's name.
- */
- public TestBasic(final String name)
- {
- super(name);
- }
+ private static final boolean[] IS_DOCUMENT_SUMMARY_INFORMATION =
+ {false, true};
+ private POIFile[] poiFiles;
/**
* <p>Read a the test file from the "data" directory.</p>
- *
+ *
* @exception FileNotFoundException if the file to be read does not exist.
* @exception IOException if any other I/O exception occurs.
*/
poiFiles = Util.readPOIFiles(data);
}
-
-
/**
* <p>Checks the names of the files in the POI filesystem. They
* are expected to be in a certain order.</p>
Assert.assertEquals(poiFiles[i].getName(), expected[i]);
}
-
-
/**
* <p>Tests whether property sets can be created from the POI
* files in the POI file system. This test case expects the first
* property sets. In the latter cases a {@link
* NoPropertySetStreamException} will be thrown when trying to
* create a {@link PropertySet}.</p>
- *
+ *
* @exception IOException if an I/O exception occurs.
- *
+ *
* @exception UnsupportedEncodingException if a character encoding is not
* supported.
*/
}
}
-
-
/**
* <p>Tests the {@link PropertySet} methods. The test file has two
* property sets: the first one is a {@link SummaryInformation},
* the second one is a {@link DocumentSummaryInformation}.</p>
- *
+ *
* @exception IOException if an I/O exception occurs
* @exception HPSFException if any HPSF exception occurs
*/
}
}
-
-
/**
* <p>Tests the {@link Section} methods. The test file has two
* property sets: the first one is a {@link SummaryInformation},
* the second one is a {@link DocumentSummaryInformation}.</p>
- *
+ *
* @exception IOException if an I/O exception occurs
* @exception HPSFException if any HPSF exception occurs
*/
Assert.assertEquals("Titel", s.getProperty(2));
Assert.assertEquals(1748, s.getSize());
}
-
-
-
- /**
- * <p>Runs the test cases stand-alone.</p>
- *
- * @param args Command-line arguments (ignored)
- *
- * @exception Throwable if any sort of exception or error occurs
- */
- public static void main(final String[] args) throws Throwable
- {
- System.setProperty("HPSF.testdata.path",
- "./src/testcases/org/apache/poi/hpsf/data");
- junit.textui.TestRunner.run(TestBasic.class);
- }
-
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hpsf.basic;
*
* @author Michael Zalewski (zalewski@optonline.net)
*/
-public class TestClassID extends TestCase
-{
- /**
- * <p>Constructor</p>
- *
- * @param name the test case's name
- */
- public TestClassID(final String name)
- {
- super(name);
- }
+public final class TestClassID extends TestCase {
/**
* Various tests of overridden .equals()
"{04030201-0605-0807-090A-0B0C0D0E0F10}"
);
}
-
-
-
- /**
- * <p>Runs the test cases stand-alone.</p>
- *
- * @param args Command-line parameters (ignored)
- */
- public static void main(final String[] args)
- {
- System.setProperty("HPSF.testdata.path",
- "./src/testcases/org/apache/poi/hpsf/data");
- junit.textui.TestRunner.run(TestClassID.class);
- }
-
}
* @author Rainer Klute <a
* href="mailto:klute@rainer-klute.de"><klute@rainer-klute.de></a>
*/
-public class TestEmptyProperties extends TestCase
-{
+public final class TestEmptyProperties extends TestCase {
/**
* <p>This test file's summary information stream contains some empty
* properties.</p>
*/
- static final String POI_FS = "TestCorel.shw";
+ private static final String POI_FS = "TestCorel.shw";
- static final String[] POI_FILES = new String[]
+ private static final String[] POI_FILES = new String[]
{
"PerfectOffice_MAIN",
"\005SummaryInformation",
"Main"
};
- POIFile[] poiFiles;
-
-
-
- /**
- * <p>Constructor</p>
- *
- * @param name The name of the test case
- */
- public TestEmptyProperties(final String name)
- {
- super(name);
- }
-
-
+ private POIFile[] poiFiles;
/**
* <p>Read a the test file from the "data" directory.</p>
poiFiles = Util.readPOIFiles(data);
}
-
-
/**
* <p>Checks the names of the files in the POI filesystem. They
* are expected to be in a certain order.</p>
Assert.assertEquals(poiFiles[i].getName(), expected[i]);
}
-
-
/**
* <p>Tests whether property sets can be created from the POI
* files in the POI file system. This test case expects the first
* property sets. In the latter cases a {@link
* NoPropertySetStreamException} will be thrown when trying to
* create a {@link PropertySet}.</p>
- *
+ *
* @exception IOException if an I/O exception occurs.
- *
+ *
* @exception UnsupportedEncodingException if a character encoding is not
* supported.
*/
public void testCreatePropertySets()
throws UnsupportedEncodingException, IOException
- {
+ {
Class[] expected = new Class[]
{
NoPropertySetStreamException.class,
}
}
-
-
/**
* <p>Tests the {@link PropertySet} methods. The test file has two
* property sets: the first one is a {@link SummaryInformation},
* the second one is a {@link DocumentSummaryInformation}.</p>
- *
+ *
* @exception IOException if an I/O exception occurs
* @exception HPSFException if an HPSF operation fails
*/
assertNull(s.getThumbnail());
assertNull(s.getApplicationName());
}
-
-
-
- /**
- * <p>Runs the test cases stand-alone.</p>
- *
- * @param args the command-line arguments (unused)
- *
- * @exception Throwable if any exception or error occurs
- */
- public static void main(final String[] args) throws Throwable
- {
- System.setProperty("HPSF.testdata.path",
- "./src/testcases/org/apache/poi/hpsf/data");
- junit.textui.TestRunner.run(TestBasic.class);
- }
-
}
import junit.framework.TestCase;
/**
- * Tests the ModelFactory.
- *
+ * Tests the ModelFactory.
+ *
* @author Andrew C. Oliver acoliver@apache.org
*/
-public class TestModelFactory extends TestCase
-{
+public class TestModelFactory extends TestCase {
private ModelFactory factory;
private HSSFWorkbook book;
private InputStream in;
private List models;
- /**
- * Tests that the listeners collection is created
- * @param arg0
- */
- public TestModelFactory(String arg0)
+ protected void setUp() throws Exception
{
- super(arg0);
ModelFactory mf = new ModelFactory();
assertTrue("listeners member cannot be null", mf.listeners != null);
- assertTrue("listeners member must be a List", mf.listeners instanceof List);
- }
-
- public static void main(String[] args)
- {
- junit.textui.TestRunner.run(TestModelFactory.class);
- }
-
- protected void setUp() throws Exception
- {
- super.setUp();
+ assertTrue("listeners member must be a List", mf.listeners instanceof List);
models = new ArrayList(3);
factory = new ModelFactory();
book = new HSSFWorkbook();
- ByteArrayOutputStream stream = (ByteArrayOutputStream)setupRunFile(book);
+ ByteArrayOutputStream stream = (ByteArrayOutputStream)setupRunFile(book);
POIFSFileSystem fs = new POIFSFileSystem(
new ByteArrayInputStream(stream.toByteArray())
);
public void testRegisterListener()
{
if (factory.listeners.size() != 0) {
- factory = new ModelFactory();
+ factory = new ModelFactory();
}
-
+
factory.registerListener(new MFListener(null));
factory.registerListener(new MFListener(null));
assertTrue("Factory listeners should be two, was="+
{
Model temp = null;
Iterator mi = null;
-
+
if (factory.listeners.size() != 0) {
- factory = new ModelFactory();
+ factory = new ModelFactory();
}
-
+
factory.registerListener(new MFListener(models));
factory.run(in);
-
+
assertTrue("Models size must be 2 was = "+models.size(),
models.size() == 2);
- mi = models.iterator();
+ mi = models.iterator();
temp = (Model)mi.next();
-
+
assertTrue("First model is Workbook was " + temp.getClass().getName(),
temp instanceof Workbook);
-
+
temp = (Model)mi.next();
-
+
assertTrue("Second model is Sheet was " + temp.getClass().getName(),
temp instanceof Sheet);
-
+
}
-
+
/**
* Sets up a test file
*/
class MFListener implements ModelFactoryListener {
private List mlist;
public MFListener(List mlist) {
- this.mlist = mlist;
+ this.mlist = mlist;
}
-
+
public boolean process(Model model)
{
- mlist.add(model);
+ mlist.add(model);
return true;
}
-
+
public Iterator models() {
- return mlist.iterator();
+ return mlist.iterator();
}
-
-}
\ No newline at end of file
+}
import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.hssf.record.formula.RefNPtg;
import org.apache.poi.hssf.record.formula.RefPtg;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.util.LittleEndian;
-import org.apache.poi.ss.formula.Formula;
/**
* Tests the serialization and deserialization of the TestCFRuleRecord
* class works correctly.
*
- * @author Dmitriy Kumshayev
+ * @author Dmitriy Kumshayev
*/
-public final class TestCFRuleRecord extends TestCase
-{
- public void testConstructors ()
- {
+public final class TestCFRuleRecord extends TestCase {
+ public void testConstructors () {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
assertSame(Ptg.EMPTY_PTG_ARRAY, rule3.getParsedExpression2());
}
- public void testCreateCFRuleRecord ()
- {
+ public void testCreateCFRuleRecord() {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
CFRuleRecord record = CFRuleRecord.create(sheet, "7");
}
}
- private void testCFRuleRecord(CFRuleRecord record)
- {
+ private void testCFRuleRecord(CFRuleRecord record) {
FontFormatting fontFormatting = new FontFormatting();
testFontFormattingAccessors(fontFormatting);
assertFalse(record.containsFontFormattingBlock());
assertTrue(record.isPatternStyleModified());
}
- private void testPatternFormattingAccessors(PatternFormatting patternFormatting)
- {
+ private void testPatternFormattingAccessors(PatternFormatting patternFormatting) {
patternFormatting.setFillBackgroundColor(HSSFColor.GREEN.index);
assertEquals(HSSFColor.GREEN.index,patternFormatting.getFillBackgroundColor());
assertEquals(PatternFormatting.DIAMONDS,patternFormatting.getFillPattern());
}
- private void testBorderFormattingAccessors(BorderFormatting borderFormatting)
- {
+ private void testBorderFormattingAccessors(BorderFormatting borderFormatting) {
borderFormatting.setBackwardDiagonalOn(false);
assertFalse(borderFormatting.isBackwardDiagonalOn());
borderFormatting.setBackwardDiagonalOn(true);
}
- private void testFontFormattingAccessors(FontFormatting fontFormatting)
- {
+ private void testFontFormattingAccessors(FontFormatting fontFormatting) {
// Check for defaults
assertFalse(fontFormatting.isEscapementTypeModified());
assertFalse(fontFormatting.isFontCancellationModified());
assertTrue(refNPtg.isRowRelative());
byte[] data = rr.serialize();
-
- if (!compareArrays(DATA_REFN, 0, data, 4, DATA_REFN.length)) {
- fail("Did not re-serialize correctly");
- }
- }
-
- private static boolean compareArrays(byte[] arrayA, int offsetA, byte[] arrayB, int offsetB, int length) {
-
- if (offsetA + length > arrayA.length) {
- return false;
- }
- if (offsetB + length > arrayB.length) {
- return false;
- }
- for (int i = 0; i < length; i++) {
- if (arrayA[i+offsetA] != arrayB[i+offsetB]) {
- return false;
- }
- }
- return true;
- }
-
- public static void main(String[] ignored_args)
- {
- System.out.println("Testing org.apache.poi.hssf.record.CFRuleRecord");
- junit.textui.TestRunner.run(TestCFRuleRecord.class);
+ TestcaseRecordInputStream.confirmRecordEncoding(CFRuleRecord.sid, DATA_REFN, data);
}
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hssf.record;
import java.util.Iterator;
*
* @author Brian Sanders (bsanders at risklabs dot com)
*/
-public class TestPaletteRecord extends TestCase
-{
- public TestPaletteRecord(String name)
- {
- super(name);
- }
-
+public final class TestPaletteRecord extends TestCase {
+
/**
* Tests that the default palette matches the constants of HSSFColor
*/
- public void testDefaultPalette()
- {
+ public void testDefaultPalette() {
PaletteRecord palette = new PaletteRecord();
-
+
//make sure all the HSSFColor constants match
Map colors = HSSFColor.getIndexHash();
Iterator indexes = colors.keySet().iterator();
* @author Andrew C. Oliver(acoliver at apache.org)
*/
public final class TestAxisOptionsRecord extends TestCase {
- byte[] data = new byte[] {
+ private static final byte[] data = {
(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x01,
(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x01,(byte)0x00,
(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
for (int i = 0; i < data.length; i++)
assertEquals("At offset " + i, data[i], recordBytes[i+4]);
}
-
- /**
- * The main program for the TestAxisOptionsRecord class
- *
- *@param args The command line arguments
- */
- public static void main(String[] args) {
- System.out.println("Testing org.apache.poi.hssf.record.AxisOptionsRecord");
- junit.textui.TestRunner.run(TestAxisOptionsRecord.class);
- }
}
* class works correctly. Test data taken directly from a real
* Excel file.
*
-
* @author Andrew C. Oliver(acoliver at apache.org)
*/
public final class TestTickRecord extends TestCase {
- byte[] data = new byte[] {
- (byte)0x02, (byte)0x00, (byte)0x03, (byte)0x01,
+ private static final byte[] data = {
+ (byte)0x02, (byte)0x00, (byte)0x03, (byte)0x01,
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x23, (byte)0x00,
- (byte)0x4D, (byte)0x00, (byte)0x00, (byte)0x00
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+ (byte)0x00, (byte)0x00, (byte)0x00,
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x23, (byte)0x00,
+ (byte)0x4D, (byte)0x00, (byte)0x00, (byte)0x00
};
public void testLoad() {
assertEquals( 34, record.getRecordSize() );
}
- public void testStore()
- {
+ public void testStore() {
TickRecord record = new TickRecord();
record.setMajorTickType( (byte)2 );
record.setMinorTickType( (byte)0 );
for (int i = 0; i < data.length; i++)
assertEquals("At offset " + i, data[i], recordBytes[i+4]);
}
-
-
- /**
- * The main program for the TestTickRecord class
- *
- *@param args The command line arguments
- */
- public static void main(String[] args) {
- System.out.println("Testing org.apache.poi.hssf.record.TickRecord");
- junit.textui.TestRunner.run(TestTickRecord.class);
- }
-
}
Sheet newSheet = workbook.getSheetAt(0).getSheet();
List records = newSheet.getRecords();
- //System.out.println("BOF Assertion");
assertTrue(records.get(0) instanceof BOFRecord);
- //System.out.println("EOF Assertion");
assertTrue(records.get(records.size() - 1) instanceof EOFRecord);
}
-
- public static void main(String [] args) {
- junit.textui.TestRunner.run(TestReadWriteChart.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.eventfilesystem;
-import junit.framework.*;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
-import java.util.*;
+import junit.framework.TestCase;
import org.apache.poi.poifs.filesystem.POIFSDocumentPath;
*
* @author Marc Johnson
*/
-
-public class TestPOIFSReaderRegistry
- extends TestCase
-{
+public final class TestPOIFSReaderRegistry extends TestCase {
private POIFSReaderListener[] listeners =
{
new Listener(), new Listener(), new Listener(), new Listener()
"a0", "a1", "a2", "a3"
};
- /**
- * Constructor TestPOIFSReaderRegistry
- *
- * @param name
- */
-
- public TestPOIFSReaderRegistry(String name)
- {
- super(name);
- }
-
/**
* Test empty registry
*/
-
- public void testEmptyRegistry()
- {
+ public void testEmptyRegistry() {
POIFSReaderRegistry registry = new POIFSReaderRegistry();
for (int j = 0; j < paths.length; j++)
/**
* Test mixed registration operations
*/
-
- public void testMixedRegistrationOperations()
- {
+ public void testMixedRegistrationOperations() {
POIFSReaderRegistry registry = new POIFSReaderRegistry();
for (int j = 0; j < listeners.length; j++)
}
}
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out.println(
- "Testing org.apache.poi.poifs.eventfilesystem.POIFSReaderRegistry");
- junit.textui.TestRunner.run(TestPOIFSReaderRegistry.class);
- }
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.filesystem;
*
* @author Marc Johnson
*/
-
-public class TestDirectoryNode
- extends TestCase
-{
-
- /**
- * Constructor TestDirectoryNode
- *
- * @param name
- */
-
- public TestDirectoryNode(String name)
- {
- super(name);
- }
+public final class TestDirectoryNode extends TestCase {
/**
* test trivial constructor (a DirectoryNode with no children)
- *
- * @exception IOException
*/
-
- public void testEmptyConstructor()
- throws IOException
- {
+ public void testEmptyConstructor() {
POIFSFileSystem fs = new POIFSFileSystem();
DirectoryProperty property1 = new DirectoryProperty("parent");
DirectoryProperty property2 = new DirectoryProperty("child");
/**
* test non-trivial constructor (a DirectoryNode with children)
- *
- * @exception IOException
*/
-
- public void testNonEmptyConstructor()
- throws IOException
- {
+ public void testNonEmptyConstructor() throws IOException {
DirectoryProperty property1 = new DirectoryProperty("parent");
DirectoryProperty property2 = new DirectoryProperty("child1");
/**
* test deletion methods
- *
- * @exception IOException
*/
-
- public void testDeletion()
- throws IOException
- {
+ public void testDeletion() throws IOException {
POIFSFileSystem fs = new POIFSFileSystem();
DirectoryEntry root = fs.getRoot();
/**
* test change name methods
- *
- * @exception IOException
*/
-
- public void testRename()
- throws IOException
- {
+ public void testRename() throws IOException {
POIFSFileSystem fs = new POIFSFileSystem();
DirectoryEntry root = fs.getRoot();
assertTrue(dir2.renameTo("foo"));
assertEquals("foo", dir2.getName());
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out
- .println("Testing org.apache.poi.poifs.filesystem.DirectoryNode");
- junit.textui.TestRunner.run(TestDirectoryNode.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.filesystem;
-import java.io.*;
-
-import java.util.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
-import junit.framework.*;
+import junit.framework.TestCase;
-import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.poifs.property.DocumentProperty;
import org.apache.poi.poifs.storage.RawDataBlock;
import org.apache.poi.poifs.storage.SmallDocumentBlock;
*
* @author Marc Johnson
*/
-
-public class TestDocument
- extends TestCase
-{
-
- /**
- * Constructor TestDocument
- *
- * @param name
- */
-
- public TestDocument(String name)
- {
- super(name);
- }
+public final class TestDocument extends TestCase {
/**
* Integration test -- really about all we can do
- *
- * @exception IOException
*/
-
- public void testPOIFSDocument()
- throws IOException
- {
+ public void testPOIFSDocument() throws IOException {
// verify correct number of blocks get created for document
// that is exact multituple of block size
}
}
- private POIFSDocument makeCopy(POIFSDocument document, byte [] input,
- byte [] data)
- throws IOException
- {
+ private static POIFSDocument makeCopy(POIFSDocument document, byte[] input, byte[] data)
+ throws IOException {
POIFSDocument copy = null;
if (input.length >= 4096)
return copy;
}
- private void checkDocument(final POIFSDocument document,
- final byte [] input)
- throws IOException
- {
+ private static void checkDocument(final POIFSDocument document, final byte[] input)
+ throws IOException {
int big_blocks = 0;
int small_blocks = 0;
int total_output = 0;
input)), input);
}
- private byte [] checkValues(int big_blocks, int small_blocks,
- int total_output, POIFSDocument document,
- byte [] input)
- throws IOException
- {
+ private static byte[] checkValues(int big_blocks, int small_blocks, int total_output,
+ POIFSDocument document, byte[] input) throws IOException {
assertEquals(document, document.getDocumentProperty().getDocument());
int increment = ( int ) Math.sqrt(input.length);
}
return output;
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out
- .println("Testing org.apache.poi.poifs.filesystem.POIFSDocument");
- junit.textui.TestRunner.run(TestDocument.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.filesystem;
-import junit.framework.*;
+import junit.framework.TestCase;
/**
* Class to test DocumentDescriptor functionality
*
* @author Marc Johnson
*/
-
-public class TestDocumentDescriptor
- extends TestCase
-{
-
- /**
- * Constructor TestDocumentDescriptor
- *
- * @param name
- */
-
- public TestDocumentDescriptor(String name)
- {
- super(name);
- }
+public final class TestDocumentDescriptor extends TestCase {
/**
* test equality
*/
-
- public void testEquality()
- {
- String[] names =
- {
- "c1", "c2", "c3", "c4", "c5"
- };
+ public void testEquality() {
+ String[] names = { "c1", "c2", "c3", "c4", "c5" };
POIFSDocumentPath a1 = new POIFSDocumentPath();
POIFSDocumentPath a2 = new POIFSDocumentPath(null);
POIFSDocumentPath a3 = new POIFSDocumentPath(new String[ 0 ]);
POIFSDocumentPath a4 = new POIFSDocumentPath(a1, null);
POIFSDocumentPath a5 = new POIFSDocumentPath(a1,
new String[ 0 ]);
- POIFSDocumentPath[] paths =
- {
- a1, a2, a3, a4, a5
- };
+ POIFSDocumentPath[] paths = { a1, a2, a3, a4, a5 };
for (int j = 0; j < paths.length; j++)
{
}
}
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out.println(
- "Testing org.apache.poi.poifs.eventfilesystem.DocumentDescriptor");
- junit.textui.TestRunner.run(TestDocumentDescriptor.class);
- }
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.filesystem;
*
* @author Marc Johnson
*/
-
-public class TestDocumentNode
- extends TestCase
-{
-
- /**
- * Constructor TestDocumentNode
- *
- * @param name
- */
-
- public TestDocumentNode(String name)
- {
- super(name);
- }
+public final class TestDocumentNode extends TestCase {
/**
* test constructor
- *
- * @exception IOException
*/
-
- public void testConstructor()
- throws IOException
- {
+ public void testConstructor() throws IOException {
DirectoryProperty property1 = new DirectoryProperty("directory");
RawDataBlock[] rawBlocks = new RawDataBlock[ 4 ];
ByteArrayInputStream stream =
// verify getParent behaves correctly
assertEquals(parent, node.getParent());
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out
- .println("Testing org.apache.poi.poifs.filesystem.DocumentNode");
- junit.textui.TestRunner.run(TestDocumentNode.class);
- }
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.filesystem;
-import java.io.*;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
-import java.util.*;
-
-import junit.framework.*;
-
-import org.apache.poi.poifs.property.DirectoryProperty;
-import org.apache.poi.poifs.property.DocumentProperty;
-import org.apache.poi.poifs.storage.RawDataBlock;
+import junit.framework.TestCase;
/**
* Class to test DocumentOutputStream functionality
*
* @author Marc Johnson
*/
-
-public class TestDocumentOutputStream
- extends TestCase
-{
-
- /**
- * Constructor TestDocumentOutputStream
- *
- * @param name
- *
- * @exception IOException
- */
-
- public TestDocumentOutputStream(String name)
- throws IOException
- {
- super(name);
- }
+public final class TestDocumentOutputStream extends TestCase {
/**
* test write(int) behavior
- *
- * @exception IOException
*/
-
- public void testWrite1()
- throws IOException
- {
+ public void testWrite1() throws IOException {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
DocumentOutputStream dstream = new DocumentOutputStream(stream, 25);
/**
* test write(byte[]) behavior
- *
- * @exception IOException
*/
-
- public void testWrite2()
- throws IOException
- {
+ public void testWrite2() throws IOException {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
DocumentOutputStream dstream = new DocumentOutputStream(stream, 25);
/**
* test write(byte[], int, int) behavior
- *
- * @exception IOException
*/
-
- public void testWrite3()
- throws IOException
- {
+ public void testWrite3() throws IOException {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
DocumentOutputStream dstream = new DocumentOutputStream(stream, 25);
byte[] array = new byte[ 50 ];
/**
* test writeFiller()
- *
- * @exception IOException
*/
-
- public void testWriteFiller()
- throws IOException
- {
+ public void testWriteFiller() throws IOException {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
DocumentOutputStream dstream = new DocumentOutputStream(stream, 25);
}
stream.close();
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out.println(
- "Testing org.apache.poi.poifs.filesystem.DocumentOutputStream");
- junit.textui.TestRunner.run(TestDocumentOutputStream.class);
- }
}
import org.apache.poi.poifs.filesystem.POIFSWriterListener;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
-public class TestEmptyDocument extends TestCase {
-
- public static void main(String[] args) {
- TestEmptyDocument driver = new TestEmptyDocument();
-
- System.out.println();
- System.out.println("As only file...");
- System.out.println();
-
- System.out.print("Trying using createDocument(String,InputStream): ");
- try {
- driver.testSingleEmptyDocument();
- System.out.println("Worked!");
- } catch (IOException exception) {
- System.out.println("failed! ");
- System.out.println(exception.toString());
- }
- System.out.println();
-
- System.out.print
- ("Trying using createDocument(String,int,POIFSWriterListener): ");
- try {
- driver.testSingleEmptyDocumentEvent();
- System.out.println("Worked!");
- } catch (IOException exception) {
- System.out.println("failed!");
- System.out.println(exception.toString());
- }
- System.out.println();
-
- System.out.println();
- System.out.println("After another file...");
- System.out.println();
-
- System.out.print("Trying using createDocument(String,InputStream): ");
- try {
- driver.testEmptyDocumentWithFriend();
- System.out.println("Worked!");
- } catch (IOException exception) {
- System.out.println("failed! ");
- System.out.println(exception.toString());
- }
- System.out.println();
-
- System.out.print
- ("Trying using createDocument(String,int,POIFSWriterListener): ");
- try {
- driver.testEmptyDocumentWithFriend();
- System.out.println("Worked!");
- } catch (IOException exception) {
- System.out.println("failed!");
- System.out.println(exception.toString());
- }
- System.out.println();
- }
-
- public void testSingleEmptyDocument() throws IOException {
- POIFSFileSystem fs = new POIFSFileSystem();
- DirectoryEntry dir = fs.getRoot();
- dir.createDocument("Foo", new ByteArrayInputStream(new byte[] { }));
-
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- fs.writeFilesystem(out);
- new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
- }
-
- public void testSingleEmptyDocumentEvent() throws IOException {
- POIFSFileSystem fs = new POIFSFileSystem();
- DirectoryEntry dir = fs.getRoot();
- dir.createDocument("Foo", 0, new POIFSWriterListener() {
- public void processPOIFSWriterEvent(POIFSWriterEvent event) {
- System.out.println("written");
- }
- });
-
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- fs.writeFilesystem(out);
- new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
- }
-
- public void testEmptyDocumentWithFriend() throws IOException {
- POIFSFileSystem fs = new POIFSFileSystem();
- DirectoryEntry dir = fs.getRoot();
- dir.createDocument("Bar", new ByteArrayInputStream(new byte[] { 0 }));
- dir.createDocument("Foo", new ByteArrayInputStream(new byte[] { }));
-
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- fs.writeFilesystem(out);
- new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
- }
-
- public void testEmptyDocumentEventWithFriend() throws IOException {
- POIFSFileSystem fs = new POIFSFileSystem();
- DirectoryEntry dir = fs.getRoot();
- dir.createDocument("Bar", 1, new POIFSWriterListener() {
- public void processPOIFSWriterEvent(POIFSWriterEvent event) {
- try {
- event.getStream().write(0);
- } catch (IOException exception) {
- throw new RuntimeException("exception on write: " + exception);
- }
- }
- });
- dir.createDocument("Foo", 0, new POIFSWriterListener() {
- public void processPOIFSWriterEvent(POIFSWriterEvent event) {
- }
- });
-
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- fs.writeFilesystem(out);
- new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
- }
-
- public void testEmptyDocumentBug11744() throws Exception {
- byte[] testData = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
-
- POIFSFileSystem fs = new POIFSFileSystem();
- fs.createDocument(new ByteArrayInputStream(new byte[0]), "Empty");
- fs.createDocument(new ByteArrayInputStream(testData), "NotEmpty");
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- fs.writeFilesystem(out);
- out.toByteArray();
-
- // This line caused the error.
- fs = new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
-
- DocumentEntry entry = (DocumentEntry) fs.getRoot().getEntry("Empty");
- assertEquals("Expected zero size", 0, entry.getSize());
- byte[] actualReadbackData;
- actualReadbackData = IOUtils.toByteArray(new DocumentInputStream(entry));
- assertEquals("Expected zero read from stream", 0,
- actualReadbackData.length);
-
- entry = (DocumentEntry) fs.getRoot().getEntry("NotEmpty");
- actualReadbackData = IOUtils.toByteArray(new DocumentInputStream(entry));
- assertEquals("Expected size was wrong", testData.length, entry.getSize());
- assertTrue("Expected different data read from stream",
- Arrays.equals(testData, actualReadbackData));
- }
+public final class TestEmptyDocument extends TestCase {
+
+ public void testSingleEmptyDocument() throws IOException {
+ POIFSFileSystem fs = new POIFSFileSystem();
+ DirectoryEntry dir = fs.getRoot();
+ dir.createDocument("Foo", new ByteArrayInputStream(new byte[] {}));
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ fs.writeFilesystem(out);
+ new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
+ }
+
+ public void testSingleEmptyDocumentEvent() throws IOException {
+ POIFSFileSystem fs = new POIFSFileSystem();
+ DirectoryEntry dir = fs.getRoot();
+ dir.createDocument("Foo", 0, new POIFSWriterListener() {
+ public void processPOIFSWriterEvent(POIFSWriterEvent event) {
+ System.out.println("written");
+ }
+ });
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ fs.writeFilesystem(out);
+ new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
+ }
+
+ public void testEmptyDocumentWithFriend() throws IOException {
+ POIFSFileSystem fs = new POIFSFileSystem();
+ DirectoryEntry dir = fs.getRoot();
+ dir.createDocument("Bar", new ByteArrayInputStream(new byte[] { 0 }));
+ dir.createDocument("Foo", new ByteArrayInputStream(new byte[] {}));
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ fs.writeFilesystem(out);
+ new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
+ }
+
+ public void testEmptyDocumentEventWithFriend() throws IOException {
+ POIFSFileSystem fs = new POIFSFileSystem();
+ DirectoryEntry dir = fs.getRoot();
+ dir.createDocument("Bar", 1, new POIFSWriterListener() {
+ public void processPOIFSWriterEvent(POIFSWriterEvent event) {
+ try {
+ event.getStream().write(0);
+ } catch (IOException exception) {
+ throw new RuntimeException("exception on write: " + exception);
+ }
+ }
+ });
+ dir.createDocument("Foo", 0, new POIFSWriterListener() {
+ public void processPOIFSWriterEvent(POIFSWriterEvent event) {
+ }
+ });
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ fs.writeFilesystem(out);
+ new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
+ }
+
+ public void testEmptyDocumentBug11744() throws Exception {
+ byte[] testData = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+
+ POIFSFileSystem fs = new POIFSFileSystem();
+ fs.createDocument(new ByteArrayInputStream(new byte[0]), "Empty");
+ fs.createDocument(new ByteArrayInputStream(testData), "NotEmpty");
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ fs.writeFilesystem(out);
+ out.toByteArray();
+
+ // This line caused the error.
+ fs = new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
+
+ DocumentEntry entry = (DocumentEntry) fs.getRoot().getEntry("Empty");
+ assertEquals("Expected zero size", 0, entry.getSize());
+ byte[] actualReadbackData;
+ actualReadbackData = IOUtils.toByteArray(new DocumentInputStream(entry));
+ assertEquals("Expected zero read from stream", 0, actualReadbackData.length);
+
+ entry = (DocumentEntry) fs.getRoot().getEntry("NotEmpty");
+ actualReadbackData = IOUtils.toByteArray(new DocumentInputStream(entry));
+ assertEquals("Expected size was wrong", testData.length, entry.getSize());
+ assertTrue("Expected different data read from stream", Arrays.equals(testData,
+ actualReadbackData));
+ }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.filesystem;
-import junit.framework.*;
+import junit.framework.TestCase;
/**
* Class to test POIFSDocumentPath functionality
*
* @author Marc Johnson
*/
+public final class TestPOIFSDocumentPath extends TestCase {
-public class TestPOIFSDocumentPath
- extends TestCase
-{
-
- /**
- * Constructor TestPOIFSDocumentPath
- *
- * @param name
- */
-
- public TestPOIFSDocumentPath(String name)
- {
- super(name);
- }
/**
* Test default constructor
*/
-
- public void testDefaultConstructor()
- {
+ public void testDefaultConstructor() {
POIFSDocumentPath path = new POIFSDocumentPath();
assertEquals(0, path.length());
/**
* Test full path constructor
*/
-
- public void testFullPathConstructor()
- {
+ public void testFullPathConstructor() {
String[] components =
{
"foo", "bar", "foobar", "fubar"
/**
* Test relative path constructor
*/
-
- public void testRelativePathConstructor()
- {
+ public void testRelativePathConstructor() {
String[] initialComponents =
{
"a", "b", "c"
/**
* test equality
*/
-
- public void testEquality()
- {
+ public void testEquality() {
POIFSDocumentPath a1 = new POIFSDocumentPath();
POIFSDocumentPath a2 = new POIFSDocumentPath(null);
POIFSDocumentPath a3 = new POIFSDocumentPath(new String[ 0 ]);
}
}
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out.println(
- "Testing org.apache.poi.poifs.eventfilesystem.POIFSDocumentPath");
- junit.textui.TestRunner.run(TestPOIFSDocumentPath.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.property;
-import java.io.*;
-
-import java.util.*;
-
-import junit.framework.*;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
-import org.apache.poi.poifs.common.POIFSConstants;
+import junit.framework.TestCase;
/**
* Class to test DirectoryProperty functionality
*
* @author Marc Johnson
*/
-
-public class TestDirectoryProperty
- extends TestCase
-{
+public final class TestDirectoryProperty extends TestCase {
private DirectoryProperty _property;
private byte[] _testblock;
- /**
- * Constructor TestDirectoryProperty
- *
- * @param name
- */
-
- public TestDirectoryProperty(String name)
- {
- super(name);
- }
-
/**
* Test constructing DirectoryProperty
- *
- * @exception IOException
*/
-
- public void testConstructor()
- throws IOException
- {
+ public void testConstructor() throws IOException {
createBasicDirectoryProperty();
verifyProperty();
}
/**
* Test pre-write functionality
- *
- * @exception IOException
*/
-
- public void testPreWrite()
- throws IOException
- {
+ public void testPreWrite() throws IOException {
createBasicDirectoryProperty();
_property.preWrite();
}
}
- private void verifyChildren(int count)
- throws IOException
- {
+ private void verifyChildren(int count) {
Iterator iter = _property.getChildren();
List children = new ArrayList();
}
}
- private void createBasicDirectoryProperty()
- {
+ private void createBasicDirectoryProperty() {
String name = "MyDirectory";
_property = new DirectoryProperty(name);
}
}
- private void verifyProperty()
- throws IOException
- {
+ private void verifyProperty() throws IOException {
ByteArrayOutputStream stream = new ByteArrayOutputStream(512);
_property.writeData(stream);
}
}
- /**
- * Test addChild
- *
- * @exception IOException
- */
-
- public void testAddChild()
- throws IOException
- {
+ public void testAddChild() throws IOException {
createBasicDirectoryProperty();
_property.addChild(new LocalProperty(1));
_property.addChild(new LocalProperty(2));
_property.addChild(new LocalProperty(3));
}
- /**
- * Test deleteChild
- *
- * @exception IOException
- */
-
- public void testDeleteChild()
- throws IOException
- {
+ public void testDeleteChild() throws IOException {
createBasicDirectoryProperty();
Property p1 = new LocalProperty(1);
_property.addChild(new LocalProperty(1));
}
- /**
- * Test changeName
- *
- * @exception IOException
- */
-
- public void testChangeName()
- throws IOException
- {
+ public void testChangeName() throws IOException {
createBasicDirectoryProperty();
Property p1 = new LocalProperty(1);
String originalName = p1.getName();
assertTrue(_property.changeName(p1, originalName));
}
- /**
- * Test reading constructor
- *
- * @exception IOException
- */
-
- public void testReadingConstructor()
- throws IOException
- {
+ public void testReadingConstructor() throws IOException {
byte[] input =
{
( byte ) 0x42, ( byte ) 0x00, ( byte ) 0x6F, ( byte ) 0x00,
verifyReadingProperty(0, input, 0, "Boot Entry");
}
- private void verifyReadingProperty(int index, byte [] input, int offset,
+ private static void verifyReadingProperty(int index, byte [] input, int offset,
String name)
throws IOException
{
assertEquals(name, property.getName());
assertTrue(!property.getChildren().hasNext());
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out.println(
- "Testing org.apache.poi.poifs.property.DirectoryProperty");
- junit.textui.TestRunner.run(TestDirectoryProperty.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.property;
-import java.io.*;
-
-import java.util.*;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
-import junit.framework.*;
-
-import org.apache.poi.poifs.property.DocumentProperty;
+import junit.framework.TestCase;
/**
* Class to test DocumentProperty functionality
*
* @author Marc Johnson
*/
+public final class TestDocumentProperty extends TestCase {
-public class TestDocumentProperty
- extends TestCase
-{
-
- /**
- * Constructor TestDocumentProperty
- *
- * @param name
- */
-
- public TestDocumentProperty(String name)
- {
- super(name);
- }
-
- /**
- * Test constructing DocumentPropertys
- *
- * @exception IOException
- */
-
- public void testConstructor()
- throws IOException
- {
-
+ public void testConstructor() throws IOException {
// test with short name, small file
verifyProperty("foo", 1234);
verifyProperty("A.really.long.long.long.name123", 4096);
}
- /**
- * Test reading constructor
- *
- * @exception IOException
- */
-
- public void testReadingConstructor()
- throws IOException
- {
+ public void testReadingConstructor() throws IOException {
byte[] input =
{
( byte ) 0x52, ( byte ) 0x00, ( byte ) 0x6F, ( byte ) 0x00,
verifyReadingProperty(1, input, 128, "Workbook");
verifyReadingProperty(2, input, 256, "\005SummaryInformation");
- verifyReadingProperty(3, input, 384,
- "\005DocumentSummaryInformation");
+ verifyReadingProperty(3, input, 384, "\005DocumentSummaryInformation");
}
- private void verifyReadingProperty(int index, byte [] input, int offset,
- String name)
- throws IOException
- {
+ private void verifyReadingProperty(int index, byte[] input, int offset, String name)
+ throws IOException {
DocumentProperty property = new DocumentProperty(index, input,
offset);
ByteArrayOutputStream stream = new ByteArrayOutputStream(128);
assertEquals(name, property.getName());
}
- private void verifyProperty(String name, int size)
- throws IOException
- {
+ private void verifyProperty(String name, int size) throws IOException {
DocumentProperty property = new DocumentProperty(name, size);
if (size >= 4096)
output[ j ]);
}
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out.println(
- "Testing org.apache.poi.poifs.property.DocumentProperty");
- junit.textui.TestRunner.run(TestDocumentProperty.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.property;
-import java.io.*;
-
-import java.util.*;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.List;
-import junit.framework.*;
+import junit.framework.TestCase;
import org.apache.poi.poifs.storage.RawDataBlock;
*
* @author Marc Johnson
*/
+public final class TestPropertyFactory extends TestCase {
-public class TestPropertyFactory
- extends TestCase
-{
-
- /**
- * Constructor TestPropertyFactory
- *
- * @param name
- */
-
- public TestPropertyFactory(String name)
- {
- super(name);
- }
-
- /**
- * Test executing convertToProperties
- *
- * @exception IOException
- */
-
- public void testConvertToProperties()
- throws IOException
- {
+ public void testConvertToProperties() throws IOException {
// real data from a real file!
byte[] testdata =
}
}
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out
- .println("Testing org.apache.poi.poifs.property.PropertyFactory");
- junit.textui.TestRunner.run(TestPropertyFactory.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.property;
-import java.io.*;
-
-import java.util.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Iterator;
-import junit.framework.*;
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.poifs.storage.BlockAllocationTableReader;
*
* @author Marc Johnson
*/
-
-public class TestPropertyTable
- extends TestCase
-{
-
- /**
- * Constructor TestPropertyTable
- *
- * @param name
- */
-
- public TestPropertyTable(String name)
- {
- super(name);
- }
+public final class TestPropertyTable extends TestCase {
/**
* Test PropertyTable
* the output (including the preWrite phase first), and comparing
* it against a real property table extracted from a file known to
* be acceptable to Excel.
- *
- * @exception IOException
*/
-
- public void testWriterPropertyTable()
- throws IOException
- {
+ public void testWriterPropertyTable() throws IOException {
// create the PropertyTable
PropertyTable table = new PropertyTable();
ByteArrayOutputStream stream = new ByteArrayOutputStream(512);
byte[] testblock =
{
+ // TODO - put this raw data in a better format
( byte ) 0x52, ( byte ) 0x00, ( byte ) 0x6f, ( byte ) 0x00,
( byte ) 0x6f, ( byte ) 0x00, ( byte ) 0x74, ( byte ) 0x00,
( byte ) 0x20, ( byte ) 0x00, ( byte ) 0x45, ( byte ) 0x00,
child = ( Property ) iter.next();
++count;
}
+ if (child == null) {
+ throw new AssertionFailedError("no children found");
+ }
assertEquals(1, count);
assertTrue(child.isDirectory());
iter = (( DirectoryProperty ) child).getChildren();
}
assertEquals(35, count);
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out
- .println("Testing org.apache.poi.poifs.property.PropertyTable");
- junit.textui.TestRunner.run(TestPropertyTable.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.property;
-import java.io.*;
-
-import java.util.*;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
-import junit.framework.*;
+import junit.framework.TestCase;
import org.apache.poi.poifs.common.POIFSConstants;
*
* @author Marc Johnson
*/
-
-public class TestRootProperty
- extends TestCase
-{
+public final class TestRootProperty extends TestCase {
private RootProperty _property;
private byte[] _testblock;
- /**
- * Constructor TestRootProperty
- *
- * @param name
- */
- public TestRootProperty(String name)
- {
- super(name);
- }
-
- /**
- * Test constructing RootProperty
- *
- * @exception IOException
- */
-
- public void testConstructor()
- throws IOException
- {
+ public void testConstructor() throws IOException {
createBasicRootProperty();
verifyProperty();
}
}
}
- private void verifyProperty()
- throws IOException
- {
+ private void verifyProperty() throws IOException {
ByteArrayOutputStream stream = new ByteArrayOutputStream(512);
_property.writeData(stream);
}
}
- /**
- * test setSize
- */
-
- public void testSetSize()
- {
+ public void testSetSize() {
for (int j = 0; j < 10; j++)
{
createBasicRootProperty();
}
}
- /**
- * Test reading constructor
- *
- * @exception IOException
- */
-
- public void testReadingConstructor()
- throws IOException
- {
+ public void testReadingConstructor() throws IOException {
byte[] input =
{
( byte ) 0x52, ( byte ) 0x00, ( byte ) 0x6F, ( byte ) 0x00,
verifyReadingProperty(0, input, 0, "Root Entry", "{00020820-0000-0000-C000-000000000046}");
}
- private void verifyReadingProperty(int index, byte [] input, int offset,
- String name, String sClsId)
- throws IOException
- {
+ private void verifyReadingProperty(int index, byte[] input, int offset, String name,
+ String sClsId) throws IOException {
RootProperty property = new RootProperty(index, input,
offset);
ByteArrayOutputStream stream = new ByteArrayOutputStream(128);
assertTrue(!property.getChildren().hasNext());
assertEquals(property.getStorageClsid().toString(), sClsId);
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out
- .println("Testing org.apache.poi.poifs.property.RootProperty");
- junit.textui.TestRunner.run(TestRootProperty.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.storage;
-import java.io.*;
-
-import java.util.*;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
-import junit.framework.*;
+import junit.framework.TestCase;
/**
* Class to test BATBlock functionality
*
* @author Marc Johnson
*/
-
-public class TestBATBlock
- extends TestCase
-{
-
- /**
- * Constructor TestBATBlock
- *
- * @param name
- */
-
- public TestBATBlock(String name)
- {
- super(name);
- }
+public final class TestBATBlock extends TestCase {
/**
* Test the createBATBlocks method. The test involves setting up
* various arrays of int's and ensuring that the correct number of
* BATBlocks is created for each array, and that the data from
* each array is correctly written to the BATBlocks.
- *
- * @exception IOException
*/
-
- public void testCreateBATBlocks()
- throws IOException
- {
+ public void testCreateBATBlocks() throws IOException {
// test 0 length array (basic sanity)
BATBlock[] rvalue = BATBlock.createBATBlocks(createTestArray(0));
verifyContents(rvalue, 129);
}
- private int [] createTestArray(int count)
- {
+ private static int[] createTestArray(int count) {
int[] rvalue = new int[ count ];
for (int j = 0; j < count; j++)
return rvalue;
}
- private void verifyContents(BATBlock [] blocks, int entries)
- throws IOException
- {
+ private static void verifyContents(BATBlock[] blocks, int entries) throws IOException {
byte[] expected = new byte[ 512 * blocks.length ];
Arrays.fill(expected, ( byte ) 0xFF);
}
}
- /**
- * test createXBATBlocks
- *
- * @exception IOException
- */
-
- public void testCreateXBATBlocks()
- throws IOException
- {
-
+ public void testCreateXBATBlocks() throws IOException {
// test 0 length array (basic sanity)
BATBlock[] rvalue = BATBlock.createXBATBlocks(createTestArray(0), 1);
verifyXBATContents(rvalue, 255, 1);
}
- private void verifyXBATContents(BATBlock [] blocks, int entries,
- int start_block)
- throws IOException
- {
+ private static void verifyXBATContents(BATBlock[] blocks, int entries, int start_block)
+ throws IOException {
byte[] expected = new byte[ 512 * blocks.length ];
Arrays.fill(expected, ( byte ) 0xFF);
}
}
- /**
- * test calculateXBATStorageRequirements
- */
-
- public void testCalculateXBATStorageRequirements()
- {
- int[] blockCounts =
- {
- 0, 1, 127, 128
- };
- int[] requirements =
- {
- 0, 1, 1, 2
- };
+ public void testCalculateXBATStorageRequirements() {
+ int[] blockCounts = { 0, 1, 127, 128 };
+ int[] requirements = { 0, 1, 1, 2 };
for (int j = 0; j < blockCounts.length; j++)
{
}
}
- /**
- * test entriesPerBlock
- */
-
- public void testEntriesPerBlock()
- {
+ public void testEntriesPerBlock() {
assertEquals(128, BATBlock.entriesPerBlock());
}
-
- /**
- * test entriesPerXBATBlock
- */
-
- public void testEntriesPerXBATBlock()
- {
+ public void testEntriesPerXBATBlock() {
assertEquals(127, BATBlock.entriesPerXBATBlock());
}
-
- /**
- * test getXBATChainOffset
- */
-
- public void testGetXBATChainOffset()
- {
+ public void testGetXBATChainOffset() {
assertEquals(508, BATBlock.getXBATChainOffset());
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out.println("Testing org.apache.poi.poifs.storage.BATBlock");
- junit.textui.TestRunner.run(TestBATBlock.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.storage;
-import java.io.*;
-
-import java.util.*;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
-import junit.framework.*;
+import junit.framework.TestCase;
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.util.LittleEndian;
*
* @author Marc Johnson
*/
-
-public class TestBlockAllocationTableReader
- extends TestCase
-{
-
- /**
- * Constructor TestBlockAllocationTableReader
- *
- * @param name
- */
-
- public TestBlockAllocationTableReader(String name)
- {
- super(name);
- }
+public final class TestBlockAllocationTableReader extends TestCase {
/**
* Test small block allocation table constructor
- *
- * @exception IOException
*/
-
- public void testSmallBATConstructor()
- throws IOException
- {
+ public void testSmallBATConstructor() throws IOException {
// need to create an array of raw blocks containing the SBAT,
// and a small document block list
byte[] sbat_data =
{
+ // TODO - put this raw data in a better format
( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF,
( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF,
( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF,
}
}
- /**
- * Test reading constructor
- *
- * @exception IOException
- */
-
- public void testReadingConstructor()
- throws IOException
- {
+ public void testReadingConstructor() throws IOException {
// create a document, minus the header block, and use that to
// create a RawDataBlockList. The document will exist entire
// of BATBlocks and XBATBlocks
- //
+ //
// we will create two XBAT blocks, which will encompass 128
// BAT blocks between them, and two extra BAT blocks which
// will be in the block array passed to the constructor. This
// makes a total of 130 BAT blocks, which will encompass
// 16,640 blocks, for a file size of some 8.5 megabytes.
- //
+ //
// Naturally, we'll fake that out ...
- //
+ //
// map of blocks:
// block 0: xbat block 0
// block 1: xbat block 1
}
}
- /**
- * Test fetchBlocks
- *
- * @exception IOException
- */
-
- public void testFetchBlocks()
- throws IOException
- {
+ public void testFetchBlocks() throws IOException {
// strategy:
- //
+ //
// 1. set up a single BAT block from which to construct a
// BAT. create nonsense blocks in the raw data block list
// corresponding to the indices in the BAT block.
}
}
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out.println(
- "Testing org.apache.poi.poifs.storage.BlockAllocationTableReader");
- junit.textui.TestRunner.run(TestBlockAllocationTableReader.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.storage;
-import java.io.*;
-
-import java.util.*;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
-import junit.framework.*;
+import junit.framework.TestCase;
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.util.LittleEndian;
*
* @author Marc Johnson
*/
+public final class TestBlockAllocationTableWriter extends TestCase {
-public class TestBlockAllocationTableWriter
- extends TestCase
-{
-
- /**
- * Constructor TestBlockAllocationTableWriter
- *
- * @param name
- */
-
- public TestBlockAllocationTableWriter(String name)
- {
- super(name);
- }
-
- /**
- * Test the allocateSpace method.
- */
-
- public void testAllocateSpace()
- {
+ public void testAllocateSpace() {
BlockAllocationTableWriter table =
new BlockAllocationTableWriter();
int[] blockSizes =
}
}
- /**
- * Test the createBlocks method
- *
- * @exception IOException
- */
-
- public void testCreateBlocks()
- throws IOException
- {
+ public void testCreateBlocks() {
BlockAllocationTableWriter table = new BlockAllocationTableWriter();
table.allocateSpace(127);
/**
* Test content produced by BlockAllocationTableWriter
- *
- * @exception IOException
*/
-
- public void testProduct()
- throws IOException
- {
+ public void testProduct() throws IOException {
BlockAllocationTableWriter table = new BlockAllocationTableWriter();
for (int k = 1; k <= 22; k++)
}
}
- private void verifyBlocksCreated(BlockAllocationTableWriter table,
- int count)
- throws IOException
- {
+ private static void verifyBlocksCreated(BlockAllocationTableWriter table, int count){
ByteArrayOutputStream stream = new ByteArrayOutputStream();
- table.writeBlocks(stream);
+ try {
+ table.writeBlocks(stream);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
byte[] output = stream.toByteArray();
assertEquals(count * 512, output.length);
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out.println(
- "Testing org.apache.poi.poifs.storage.BlockAllocationTableWriter");
- junit.textui.TestRunner.run(TestBlockAllocationTableWriter.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.storage;
-import java.io.*;
-
-import java.util.*;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
-import junit.framework.*;
+import junit.framework.TestCase;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianConsts;
*
* @author Marc Johnson
*/
+public final class TestBlockListImpl extends TestCase {
-public class TestBlockListImpl
- extends TestCase
-{
-
- /**
- * Constructor TestBlockListImpl
- *
- * @param name
- */
-
- public TestBlockListImpl(String name)
- {
- super(name);
- }
-
- /**
- * test zap method
- *
- * @exception IOException
- */
-
- public void testZap()
- throws IOException
- {
+ public void testZap() throws IOException {
BlockListImpl list = new BlockListImpl();
// verify that you can zap anything
}
}
- /**
- * test remove method
- *
- * @exception IOException
- */
-
- public void testRemove()
- throws IOException
- {
+ public void testRemove() throws IOException {
BlockListImpl list = new BlockListImpl();
RawDataBlock[] blocks = new RawDataBlock[ 5 ];
byte[] data = new byte[ 512 * 5 ];
}
}
- /**
- * test setBAT
- *
- * @exception IOException
- */
-
- public void testSetBAT()
- throws IOException
- {
+ public void testSetBAT() throws IOException {
BlockListImpl list = new BlockListImpl();
list.setBAT(null);
}
}
- /**
- * Test fetchBlocks
- *
- * @exception IOException
- */
-
- public void testFetchBlocks()
- throws IOException
- {
+ public void testFetchBlocks() throws IOException {
// strategy:
- //
+ //
// 1. set up a single BAT block from which to construct a
// BAT. create nonsense blocks in the raw data block list
// corresponding to the indices in the BAT block.
}
}
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out
- .println("Testing org.apache.poi.poifs.storage.BlockListImpl");
- junit.textui.TestRunner.run(TestBlockListImpl.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.storage;
-import java.io.*;
-
-import java.util.*;
-
-import junit.framework.*;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
-import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.LittleEndianConsts;
+import junit.framework.TestCase;
/**
* Class to test HeaderBlockReader functionality
*
* @author Marc Johnson
*/
+public final class TestHeaderBlockReader extends TestCase {
-public class TestHeaderBlockReader
- extends TestCase
-{
-
- /**
- * Constructor TestHeaderBlockReader
- *
- * @param name
- */
-
- public TestHeaderBlockReader(String name)
- {
- super(name);
- }
-
- /**
- * Test creating a HeaderBlockReader
- *
- * @exception IOException
- */
-
- public void testConstructors()
- throws IOException
- {
+ public void testConstructors() throws IOException {
byte[] content =
{
( byte ) 0xD0, ( byte ) 0xCF, ( byte ) 0x11, ( byte ) 0xE0,
content[ index ] = ( byte ) (content[ index ] + 1);
}
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out.println(
- "Testing org.apache.poi.poifs.storage.HeaderBlockReader");
- junit.textui.TestRunner.run(TestHeaderBlockReader.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.storage;
-import java.io.*;
-
-import java.util.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
-import junit.framework.*;
+import junit.framework.TestCase;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianConsts;
*
* @author Marc Johnson
*/
-
-public class TestHeaderBlockWriter
- extends TestCase
-{
-
- /**
- * Constructor TestHeaderBlockWriter
- *
- * @param name
- */
-
- public TestHeaderBlockWriter(String name)
- {
- super(name);
- }
+public final class TestHeaderBlockWriter extends TestCase {
/**
* Test creating a HeaderBlockWriter
- *
- * @exception IOException
*/
-
- public void testConstructors()
- throws IOException
- {
+ public void testConstructors() throws IOException {
HeaderBlockWriter block = new HeaderBlockWriter();
ByteArrayOutputStream output = new ByteArrayOutputStream(512);
block.writeBlocks(output);
byte[] copy = output.toByteArray();
byte[] expected =
- {
+ { // TODO - put this raw data in a better format
( byte ) 0xD0, ( byte ) 0xCF, ( byte ) 0x11, ( byte ) 0xE0,
( byte ) 0xA1, ( byte ) 0xB1, ( byte ) 0x1A, ( byte ) 0xE1,
( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00,
/**
* Test setting the SBAT start block
- *
- * @exception IOException
*/
-
- public void testSetSBATStart()
- throws IOException
- {
+ public void testSetSBATStart() throws IOException {
HeaderBlockWriter block = new HeaderBlockWriter();
block.setSBATStart(0x01234567);
/**
* test setPropertyStart and getPropertyStart
- *
- * @exception IOException
*/
-
- public void testSetPropertyStart()
- throws IOException
- {
+ public void testSetPropertyStart() throws IOException {
HeaderBlockWriter block = new HeaderBlockWriter();
block.setPropertyStart(0x01234567);
/**
* test setting the BAT blocks; also tests getBATCount,
* getBATArray, getXBATCount
- *
- * @exception IOException
*/
-
- public void testSetBATBlocks()
- throws IOException
- {
+ public void testSetBATBlocks() throws IOException {
// first, a small set of blocks
HeaderBlockWriter block = new HeaderBlockWriter();
assertEquals("XBAT End of chain", -2,
LittleEndian.getInt(copy, offset));
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out.println(
- "Testing org.apache.poi.poifs.storage.HeaderBlockWriter");
- junit.textui.TestRunner.run(TestHeaderBlockWriter.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.storage;
-import java.io.*;
-
-import java.util.*;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
-import junit.framework.*;
-
-import org.apache.poi.poifs.property.Property;
+import junit.framework.TestCase;
/**
* Class to test PropertyBlock functionality
*
* @author Marc Johnson
*/
+public final class TestPropertyBlock extends TestCase {
-public class TestPropertyBlock
- extends TestCase
-{
-
- /**
- * Constructor TestPropertyBlock
- *
- * @param name
- */
-
- public TestPropertyBlock(String name)
- {
- super(name);
- }
-
- /**
- * Test constructing PropertyBlocks
- *
- * @exception IOException
- */
-
- public void testCreatePropertyBlocks()
- throws IOException
- {
+ public void testCreatePropertyBlocks() {
// test with 0 properties
List properties = new ArrayList();
verifyCorrect(blocks, testblock);
}
- private void setDefaultBlock(byte [] testblock, int j)
+ private static void setDefaultBlock(byte [] testblock, int j)
{
int base = j * 128;
int index = 0;
}
}
- private void verifyCorrect(BlockWritable [] blocks, byte [] testblock)
- throws IOException
- {
+ private static void verifyCorrect(BlockWritable[] blocks, byte[] testblock) {
ByteArrayOutputStream stream = new ByteArrayOutputStream(512
* blocks.length);
- for (int j = 0; j < blocks.length; j++)
- {
- blocks[ j ].writeBlocks(stream);
+ for (int j = 0; j < blocks.length; j++) {
+ try {
+ blocks[ j ].writeBlocks(stream);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
}
byte[] output = stream.toByteArray();
output[ j ]);
}
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out
- .println("Testing org.apache.poi.poifs.storage.PropertyBlock");
- junit.textui.TestRunner.run(TestPropertyBlock.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.storage;
-import java.io.*;
-import java.util.Random;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.lang.reflect.Field;
+import java.util.Random;
-import org.apache.poi.util.DummyPOILogger;
+import junit.framework.TestCase;
-import junit.framework.*;
+import org.apache.poi.util.DummyPOILogger;
/**
* Class to test RawDataBlock functionality
*
* @author Marc Johnson
*/
-
-public class TestRawDataBlock
- extends TestCase
-{
+public final class TestRawDataBlock extends TestCase {
static {
- // We always want to use our own
- // logger
- System.setProperty(
- "org.apache.poi.util.POILogger",
- "org.apache.poi.util.DummyPOILogger"
- );
+ // We always want to use our own
+ // logger
+ System.setProperty(
+ "org.apache.poi.util.POILogger",
+ "org.apache.poi.util.DummyPOILogger"
+ );
+ }
+
+ /**
+ * Test creating a normal RawDataBlock
+ */
+ public void testNormalConstructor() throws IOException {
+ byte[] data = new byte[ 512 ];
+
+ for (int j = 0; j < 512; j++)
+ {
+ data[ j ] = ( byte ) j;
+ }
+ RawDataBlock block = new RawDataBlock(new ByteArrayInputStream(data));
+
+ assertTrue("Should not be at EOF", !block.eof());
+ byte[] out_data = block.getData();
+
+ assertEquals("Should be same length", data.length, out_data.length);
+ for (int j = 0; j < 512; j++)
+ {
+ assertEquals("Should be same value at offset " + j, data[ j ],
+ out_data[ j ]);
+ }
+ }
+
+ /**
+ * Test creating an empty RawDataBlock
+ */
+ public void testEmptyConstructor() throws IOException {
+ byte[] data = new byte[ 0 ];
+ RawDataBlock block = new RawDataBlock(new ByteArrayInputStream(data));
+
+ assertTrue("Should be at EOF", block.eof());
+ try
+ {
+ block.getData();
+ }
+ catch (IOException ignored)
+ {
+
+ // as expected
+ }
+ }
+
+ /**
+ * Test creating a short RawDataBlock
+ * Will trigger a warning, but no longer an IOException,
+ * as people seem to have "valid" truncated files
+ */
+ public void testShortConstructor() throws Exception {
+ // Get the logger to be used
+ DummyPOILogger logger = new DummyPOILogger();
+ Field fld = RawDataBlock.class.getDeclaredField("log");
+ fld.setAccessible(true);
+ fld.set(null, logger);
+ assertEquals(0, logger.logged.size());
+
+ // Test for various data sizes
+ for (int k = 1; k <= 512; k++)
+ {
+ byte[] data = new byte[ k ];
+
+ for (int j = 0; j < k; j++)
+ {
+ data[ j ] = ( byte ) j;
+ }
+ RawDataBlock block = null;
+
+ logger.reset();
+ assertEquals(0, logger.logged.size());
+
+ // Have it created
+ block = new RawDataBlock(new ByteArrayInputStream(data));
+ assertNotNull(block);
+
+ // Check for the warning is there for <512
+ if(k < 512) {
+ assertEquals(
+ "Warning on " + k + " byte short block",
+ 1, logger.logged.size()
+ );
+
+ // Build the expected warning message, and check
+ String bts = k + " byte";
+ if(k > 1) {
+ bts += "s";
+ }
+
+ assertEquals(
+ "7 - Unable to read entire block; "+bts+" read before EOF; expected 512 bytes. Your document was either written by software that ignores the spec, or has been truncated!",
+ (String)(logger.logged.get(0))
+ );
+ } else {
+ assertEquals(0, logger.logged.size());
+ }
+ }
+ }
+
+ /**
+ * Tests that when using a slow input stream, which
+ * won't return a full block at a time, we don't
+ * incorrectly think that there's not enough data
+ */
+ public void testSlowInputStream() throws Exception {
+ // Get the logger to be used
+ DummyPOILogger logger = new DummyPOILogger();
+ Field fld = RawDataBlock.class.getDeclaredField("log");
+ fld.setAccessible(true);
+ fld.set(null, logger);
+ assertEquals(0, logger.logged.size());
+
+ // Test for various ok data sizes
+ for (int k = 1; k < 512; k++) {
+ byte[] data = new byte[ 512 ];
+ for (int j = 0; j < data.length; j++) {
+ data[j] = (byte) j;
+ }
+
+ // Shouldn't complain, as there is enough data,
+ // even if it dribbles through
+ RawDataBlock block =
+ new RawDataBlock(new SlowInputStream(data, k));
+ assertFalse(block.eof());
+ }
+
+ // But if there wasn't enough data available, will
+ // complain
+ for (int k = 1; k < 512; k++) {
+ byte[] data = new byte[ 511 ];
+ for (int j = 0; j < data.length; j++) {
+ data[j] = (byte) j;
+ }
+
+ logger.reset();
+ assertEquals(0, logger.logged.size());
+
+ // Should complain, as there isn't enough data
+ RawDataBlock block =
+ new RawDataBlock(new SlowInputStream(data, k));
+ assertNotNull(block);
+ assertEquals(
+ "Warning on " + k + " byte short block",
+ 1, logger.logged.size()
+ );
+ }
}
- /**
- * Constructor TestRawDataBlock
- *
- * @param name
- */
- public TestRawDataBlock(String name)
- {
- super(name);
- }
-
- /**
- * Test creating a normal RawDataBlock
- *
- * @exception IOException
- */
-
- public void testNormalConstructor()
- throws IOException
- {
- byte[] data = new byte[ 512 ];
-
- for (int j = 0; j < 512; j++)
- {
- data[ j ] = ( byte ) j;
- }
- RawDataBlock block = new RawDataBlock(new ByteArrayInputStream(data));
-
- assertTrue("Should not be at EOF", !block.eof());
- byte[] out_data = block.getData();
-
- assertEquals("Should be same length", data.length, out_data.length);
- for (int j = 0; j < 512; j++)
- {
- assertEquals("Should be same value at offset " + j, data[ j ],
- out_data[ j ]);
- }
- }
-
- /**
- * Test creating an empty RawDataBlock
- *
- * @exception IOException
- */
-
- public void testEmptyConstructor()
- throws IOException
- {
- byte[] data = new byte[ 0 ];
- RawDataBlock block = new RawDataBlock(new ByteArrayInputStream(data));
-
- assertTrue("Should be at EOF", block.eof());
- try
- {
- block.getData();
- }
- catch (IOException ignored)
- {
-
- // as expected
- }
- }
-
- /**
- * Test creating a short RawDataBlock
- * Will trigger a warning, but no longer an IOException,
- * as people seem to have "valid" truncated files
- */
- public void testShortConstructor() throws Exception
- {
- // Get the logger to be used
- DummyPOILogger logger = new DummyPOILogger();
- Field fld = RawDataBlock.class.getDeclaredField("log");
- fld.setAccessible(true);
- fld.set(null, logger);
- assertEquals(0, logger.logged.size());
-
- // Test for various data sizes
- for (int k = 1; k <= 512; k++)
- {
- byte[] data = new byte[ k ];
-
- for (int j = 0; j < k; j++)
- {
- data[ j ] = ( byte ) j;
- }
- RawDataBlock block = null;
-
- logger.reset();
- assertEquals(0, logger.logged.size());
-
- // Have it created
- block = new RawDataBlock(new ByteArrayInputStream(data));
- assertNotNull(block);
-
- // Check for the warning is there for <512
- if(k < 512) {
- assertEquals(
- "Warning on " + k + " byte short block",
- 1, logger.logged.size()
- );
-
- // Build the expected warning message, and check
- String bts = k + " byte";
- if(k > 1) {
- bts += "s";
- }
-
- assertEquals(
- "7 - Unable to read entire block; "+bts+" read before EOF; expected 512 bytes. Your document was either written by software that ignores the spec, or has been truncated!",
- (String)(logger.logged.get(0))
- );
- } else {
- assertEquals(0, logger.logged.size());
- }
- }
- }
-
- /**
- * Tests that when using a slow input stream, which
- * won't return a full block at a time, we don't
- * incorrectly think that there's not enough data
- */
- public void testSlowInputStream() throws Exception {
- // Get the logger to be used
- DummyPOILogger logger = new DummyPOILogger();
- Field fld = RawDataBlock.class.getDeclaredField("log");
- fld.setAccessible(true);
- fld.set(null, logger);
- assertEquals(0, logger.logged.size());
-
- // Test for various ok data sizes
- for (int k = 1; k < 512; k++) {
- byte[] data = new byte[ 512 ];
- for (int j = 0; j < data.length; j++) {
- data[j] = (byte) j;
- }
-
- // Shouldn't complain, as there is enough data,
- // even if it dribbles through
- RawDataBlock block =
- new RawDataBlock(new SlowInputStream(data, k));
- assertFalse(block.eof());
- }
-
- // But if there wasn't enough data available, will
- // complain
- for (int k = 1; k < 512; k++) {
- byte[] data = new byte[ 511 ];
- for (int j = 0; j < data.length; j++) {
- data[j] = (byte) j;
- }
-
- logger.reset();
- assertEquals(0, logger.logged.size());
-
- // Should complain, as there isn't enough data
- RawDataBlock block =
- new RawDataBlock(new SlowInputStream(data, k));
- assertNotNull(block);
- assertEquals(
- "Warning on " + k + " byte short block",
- 1, logger.logged.size()
- );
- }
- }
-
- /**
- * An input stream which will return a maximum of
- * a given number of bytes to read, and often claims
- * not to have any data
- */
- public static class SlowInputStream extends InputStream {
- private Random rnd = new Random();
- private byte[] data;
- private int chunkSize;
- private int pos = 0;
-
- public SlowInputStream(byte[] data, int chunkSize) {
- this.chunkSize = chunkSize;
- this.data = data;
- }
-
- /**
- * 75% of the time, claim there's no data available
- */
- private boolean claimNoData() {
- if(rnd.nextFloat() < 0.25f) {
- return false;
- }
- return true;
- }
-
- public int read() throws IOException {
+ /**
+ * An input stream which will return a maximum of
+ * a given number of bytes to read, and often claims
+ * not to have any data
+ */
+ public static class SlowInputStream extends InputStream {
+ private Random rnd = new Random();
+ private byte[] data;
+ private int chunkSize;
+ private int pos = 0;
+
+ public SlowInputStream(byte[] data, int chunkSize) {
+ this.chunkSize = chunkSize;
+ this.data = data;
+ }
+
+ /**
+ * 75% of the time, claim there's no data available
+ */
+ private boolean claimNoData() {
+ if(rnd.nextFloat() < 0.25f) {
+ return false;
+ }
+ return true;
+ }
+
+ public int read() {
if(pos >= data.length) {
return -1;
}
int ret = data[pos];
pos++;
-
+
if(ret < 0) ret += 256;
return ret;
}
* size, whichever is lower.
* Quite often will simply claim to have no data
*/
- public int read(byte[] b, int off, int len) throws IOException {
+ public int read(byte[] b, int off, int len) {
// Keep the length within the chunk size
if(len > chunkSize) {
len = chunkSize;
// Don't read off the end of the data
if(pos + len > data.length) {
len = data.length - pos;
-
+
// Spot when we're out of data
if(len == 0) {
return -1;
}
}
-
+
// 75% of the time, claim there's no data
if(claimNoData()) {
return 0;
}
-
+
// Copy, and return what we read
System.arraycopy(data, pos, b, off, len);
pos += len;
return len;
}
- public int read(byte[] b) throws IOException {
+ public int read(byte[] b) {
return read(b, 0, b.length);
}
-
- }
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out
- .println("Testing org.apache.poi.poifs.storage.RawDataBlock");
- junit.textui.TestRunner.run(TestRawDataBlock.class);
- }
+ }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.storage;
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.lang.reflect.Field;
+import junit.framework.TestCase;
+
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.util.DummyPOILogger;
-import junit.framework.*;
-
/**
* Class to test RawDataBlockList functionality
*
* @author Marc Johnson
*/
-
-public class TestRawDataBlockList
- extends TestCase
-{
+public final class TestRawDataBlockList extends TestCase {
static {
// We always want to use our own
// logger
);
}
- /**
- * Constructor TestRawDataBlockList
- *
- * @param name
- */
- public TestRawDataBlockList(String name)
- {
- super(name);
- }
-
/**
* Test creating a normal RawDataBlockList
- *
- * @exception IOException
*/
- public void testNormalConstructor()
- throws IOException
- {
+ public void testNormalConstructor() throws IOException {
byte[] data = new byte[ 2560 ];
for (int j = 0; j < 2560; j++)
/**
* Test creating an empty RawDataBlockList
- *
- * @exception IOException
*/
-
- public void testEmptyConstructor()
- throws IOException
- {
+ public void testEmptyConstructor() throws IOException {
new RawDataBlockList(new ByteArrayInputStream(new byte[ 0 ]), POIFSConstants.BIG_BLOCK_SIZE);
}
/**
* Test creating a short RawDataBlockList
*/
-
- public void testShortConstructor() throws Exception
- {
+ public void testShortConstructor() throws Exception {
// Get the logger to be used
DummyPOILogger logger = new DummyPOILogger();
Field fld = RawDataBlock.class.getDeclaredField("log");
fld.setAccessible(true);
fld.set(null, logger);
assertEquals(0, logger.logged.size());
-
+
// Test for various short sizes
for (int k = 2049; k < 2560; k++)
{
assertEquals(1, logger.logged.size());
}
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out
- .println("Testing org.apache.poi.poifs.storage.RawDataBlockList");
- junit.textui.TestRunner.run(TestRawDataBlockList.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.storage;
-import java.io.*;
-
-import java.util.*;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
-import junit.framework.*;
+import junit.framework.TestCase;
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.poifs.property.PropertyTable;
*
* @author Marc Johnson
*/
+public final class TestSmallBlockTableReader extends TestCase {
-public class TestSmallBlockTableReader
- extends TestCase
-{
-
- /**
- * Constructor TestSmallBlockTableReader
- *
- * @param name
- */
-
- public TestSmallBlockTableReader(String name)
- {
- super(name);
- }
-
- /**
- * test reading constructor
- *
- * @exception IOException
- */
-
- public void testReadingConstructor()
- throws IOException
- {
+ public void testReadingConstructor() throws IOException {
// first, we need the raw data blocks
byte[] raw_data_array =
- {
+ { // TODO - put this raw data in a better format
( byte ) 0x52, ( byte ) 0x00, ( byte ) 0x6F, ( byte ) 0x00,
( byte ) 0x6F, ( byte ) 0x00, ( byte ) 0x74, ( byte ) 0x00,
( byte ) 0x20, ( byte ) 0x00, ( byte ) 0x45, ( byte ) 0x00,
SmallBlockTableReader.getSmallDocumentBlocks(data_blocks, root,
14);
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out.println(
- "Testing org.apache.poi.poifs.storage.SmallBlockTableReader");
- junit.textui.TestRunner.run(TestSmallBlockTableReader.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.storage;
-import java.io.*;
-
-import java.util.*;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
-import junit.framework.*;
+import junit.framework.TestCase;
import org.apache.poi.poifs.filesystem.POIFSDocument;
import org.apache.poi.poifs.property.PropertyTable;
*
* @author Marc Johnson
*/
+public final class TestSmallBlockTableWriter extends TestCase {
-public class TestSmallBlockTableWriter
- extends TestCase
-{
-
- /**
- * Constructor TestSmallBlockTableWriter
- *
- * @param name
- */
-
- public TestSmallBlockTableWriter(String name)
- {
- super(name);
- }
-
- /**
- * test writing constructor
- *
- * @exception IOException
- */
-
- public void testWritingConstructor()
- throws IOException
- {
- List documents = new ArrayList();
+ public void testWritingConstructor() throws IOException {
+ List<POIFSDocument> documents = new ArrayList<POIFSDocument>();
documents.add(
new POIFSDocument(
sbtw.setStartBlock(start_block);
assertEquals(start_block, root.getStartBlock());
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out.println(
- "Testing org.apache.poi.poifs.storage.SmallBlockTableWriter");
- junit.textui.TestRunner.run(TestSmallBlockTableWriter.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.storage;
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
-import junit.framework.*;
+import junit.framework.TestCase;
/**
* Class to test SmallDocumentBlockList functionality
*
* @author Marc Johnson
*/
+public final class TestSmallDocumentBlockList extends TestCase {
-public class TestSmallDocumentBlockList
- extends TestCase
-{
-
- /**
- * Constructor TestSmallDocumentBlockList
- *
- * @param name
- */
-
- public TestSmallDocumentBlockList(String name)
- {
- super(name);
- }
-
- /**
- * Test creating a SmallDocumentBlockList
- *
- * @exception IOException
- */
-
- public void testConstructor()
- throws IOException
- {
+ public void testConstructor() throws IOException {
byte[] data = new byte[ 2560 ];
for (int j = 0; j < 2560; j++)
// it better have thrown one!!
}
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out.println(
- "Testing org.apache.poi.poifs.storage.SmallDocumentBlockList");
- junit.textui.TestRunner.run(TestSmallDocumentBlockList.class);
- }
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.util;
*
* @author Marc Johnson (mjohnson at apache dot org)
*/
+public final class TestBinaryTree extends TestCase {
-public class TestBinaryTree
- extends TestCase
-{
-
- /**
- * constructor
- *
- * @param name
- */
-
- public TestBinaryTree(final String name)
- {
- super(name);
- }
-
- /**
- * test size() method
- */
-
- public void testSize()
- {
+ public void testSize() {
Map m = new BinaryTree();
assertEquals(0, m.size());
}
}
- /**
- * test IsEmpty() method
- */
-
- public void testIsEmpty()
- {
+ public void testIsEmpty() {
Map m = new BinaryTree();
assertTrue(m.isEmpty());
}
}
- /**
- * test containsKey() method
- */
-
- public void testContainsKey()
- {
+ public void testContainsKey() {
Map m = new BinaryTree();
try
}
}
- /**
- * test containsValue() method
- */
-
- public void testContainsValue()
- {
+ public void testContainsValue() {
Map m = new BinaryTree();
LocalTestNode nodes[] = makeLocalNodes();
}
}
- /**
- * test get() method
- */
-
- public void testGet()
- {
+ public void testGet() {
Map m = new BinaryTree();
try
}
}
- /**
- * test put() method
- */
-
- public void testPut()
- {
+ public void testPut() {
Map m = new BinaryTree();
try
}
}
- /**
- * test remove() method
- */
-
- public void testRemove()
- {
+ public void testRemove() {
BinaryTree m = new BinaryTree();
LocalTestNode nodes[] = makeLocalNodes();
assertTrue(m.isEmpty());
}
- /**
- * Method testPutAll
- */
-
- public void testPutAll()
- {
+ public void testPutAll() {
Map m = new BinaryTree();
LocalTestNode nodes[] = makeLocalNodes();
}
}
- /**
- * test clear() method
- */
-
- public void testClear()
- {
+ public void testClear() {
Map m = new BinaryTree();
LocalTestNode nodes[] = makeLocalNodes();
}
}
- /**
- * test keySet() method
- */
-
- public void testKeySet()
- {
+ public void testKeySet() {
testKeySet(new BinaryTree());
Map m = new BinaryTree();
LocalTestNode nodes[] = makeLocalNodes();
assertTrue(m.size() == 0);
}
- /**
- * test values() method
- */
-
- public void testValues()
- {
+ public void testValues() {
testValues(new BinaryTree());
Map m = new BinaryTree();
LocalTestNode nodes[] = makeLocalNodes();
assertEquals(0, m.size());
}
- /**
- * test entrySet() method
- */
-
- public void testEntrySet()
- {
+ public void testEntrySet() {
testEntrySet(new BinaryTree());
Map m = new BinaryTree();
LocalTestNode nodes[] = makeLocalNodes();
}
}
- /**
- * Method testEquals
- */
-
- public void testEquals()
- {
+ public void testEquals() {
Map m = new BinaryTree();
LocalTestNode nodes[] = makeLocalNodes();
assertEquals(m, m1);
}
- /**
- * test hashCode() method
- */
-
- public void testHashCode()
- {
+ public void testHashCode() {
Map m = new BinaryTree();
LocalTestNode nodes[] = makeLocalNodes();
assertTrue(m.hashCode() == m1.hashCode());
}
- /**
- * test constructors
- */
-
- public void testConstructors()
- {
+ public void testConstructors() {
BinaryTree m = new BinaryTree();
assertTrue(m.isEmpty());
}
}
- /**
- * test getKeyForValue() method
- */
-
- public void testGetKeyForValue()
- {
+ public void testGetKeyForValue() {
BinaryTree m = new BinaryTree();
try
}
}
- /**
- * test removeValue() method
- */
-
- public void testRemoveValue()
- {
+ public void testRemoveValue() {
BinaryTree m = new BinaryTree();
LocalTestNode nodes[] = makeLocalNodes();
assertTrue(m.isEmpty());
}
- /**
- * test entrySetByValue() method
- */
-
- public void testEntrySetByValue()
- {
+ public void testEntrySetByValue() {
testEntrySetByValue(new BinaryTree());
BinaryTree m = new BinaryTree();
LocalTestNode nodes[] = makeLocalNodes();
}
}
- /**
- * test keySetByValue() method
- */
-
- public void testKeySetByValue()
- {
+ public void testKeySetByValue() {
testKeySetByValue(new BinaryTree());
BinaryTree m = new BinaryTree();
LocalTestNode nodes[] = makeLocalNodes();
assertTrue(m.size() == 0);
}
- /**
- * test valuesByValue() method
- */
-
- public void testValuesByValue()
- {
+ public void testValuesByValue() {
testValuesByValue(new BinaryTree());
BinaryTree m = new BinaryTree();
LocalTestNode nodes[] = makeLocalNodes();
}
/* ********** START helper methods ********** */
- private void testKeySet(final Map m)
- {
+ private static void testKeySet(final Map m) {
Set s = m.keySet();
assertEquals(m.size(), s.size());
assertTrue(s.hashCode() == hs.hashCode());
}
- private void testKeySetByValue(final BinaryTree m)
- {
+ private static void testKeySetByValue(final BinaryTree m) {
Set s = m.keySetByValue();
assertEquals(m.size(), s.size());
assertTrue(s.hashCode() == hs.hashCode());
}
- private void testValues(Map m)
- {
+ private static void testValues(Map m) {
Collection s = m.values();
assertEquals(m.size(), s.size());
assertTrue(!hs.equals(s));
}
- private void testValuesByValue(BinaryTree m)
- {
+ private static void testValuesByValue(BinaryTree m) {
Collection s = m.valuesByValue();
assertEquals(m.size(), s.size());
assertTrue(!hs.equals(s));
}
- private void testEntrySet(Map m)
- {
+ private static void testEntrySet(Map m) {
Set s = m.entrySet();
assertEquals(m.size(), s.size());
assertTrue(s.hashCode() == hs.hashCode());
}
- private void testEntrySetByValue(BinaryTree m)
- {
+ private static void testEntrySetByValue(BinaryTree m) {
Set s = m.entrySetByValue();
assertEquals(m.size(), s.size());
}
return nodes;
}
-
- /* ********** END helper methods ********** */
-
- /**
- * Method main
- *
- * @param unused_args
- */
-
- public static void main(final String unused_args[])
- {
- junit.textui.TestRunner.run(TestBinaryTree.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.util;
* @author Marc Johnson
* @author Glen Stampoultzis (gstamp@iprimus.com.au)
*/
-
-public class TestBitField
- extends TestCase
-{
+public final class TestBitField extends TestCase {
private static BitField bf_multi = BitFieldFactory.getInstance(0x3F80);
private static BitField bf_single = BitFieldFactory.getInstance(0x4000);
- /**
- * Constructor TestBitField
- *
- * @param name
- */
-
- public TestBitField(String name)
- {
- super(name);
- }
-
- /**
- * test the getValue() method
- */
-
- public void testGetValue()
- {
+ public void testGetValue() {
assertEquals(bf_multi.getValue(-1), 127);
assertEquals(bf_multi.getValue(0), 0);
assertEquals(bf_single.getValue(-1), 1);
assertEquals(bf_single.getValue(0), 0);
}
- /**
- * test the getShortValue() method
- */
-
- public void testGetShortValue()
- {
+ public void testGetShortValue() {
assertEquals(bf_multi.getShortValue(( short ) -1), ( short ) 127);
assertEquals(bf_multi.getShortValue(( short ) 0), ( short ) 0);
assertEquals(bf_single.getShortValue(( short ) -1), ( short ) 1);
assertEquals(bf_single.getShortValue(( short ) 0), ( short ) 0);
}
- /**
- * test the getRawValue() method
- */
-
- public void testGetRawValue()
- {
+ public void testGetRawValue() {
assertEquals(bf_multi.getRawValue(-1), 0x3F80);
assertEquals(bf_multi.getRawValue(0), 0);
assertEquals(bf_single.getRawValue(-1), 0x4000);
assertEquals(bf_single.getRawValue(0), 0);
}
- /**
- * test the getShortRawValue() method
- */
-
- public void testGetShortRawValue()
- {
+ public void testGetShortRawValue() {
assertEquals(bf_multi.getShortRawValue(( short ) -1),
( short ) 0x3F80);
assertEquals(bf_multi.getShortRawValue(( short ) 0), ( short ) 0);
assertEquals(bf_single.getShortRawValue(( short ) 0), ( short ) 0);
}
- /**
- * test the isSet() method
- */
-
- public void testIsSet()
- {
+ public void testIsSet() {
assertTrue(!bf_multi.isSet(0));
for (int j = 0x80; j <= 0x3F80; j += 0x80)
{
assertTrue(bf_single.isSet(0x4000));
}
- /**
- * test the isAllSet() method
- */
-
- public void testIsAllSet()
- {
+ public void testIsAllSet() {
for (int j = 0; j < 0x3F80; j += 0x80)
{
assertTrue(!bf_multi.isAllSet(j));
assertTrue(bf_single.isAllSet(0x4000));
}
- /**
- * test the setValue() method
- */
-
- public void testSetValue()
- {
+ public void testSetValue() {
for (int j = 0; j < 128; j++)
{
assertEquals(bf_multi.getValue(bf_multi.setValue(0, j)), j);
assertEquals(bf_single.setValue(0x4000, 2), 0);
}
- /**
- * test the setShortValue() method
- */
-
- public void testSetShortValue()
- {
+ public void testSetShortValue() {
for (int j = 0; j < 128; j++)
{
assertEquals(bf_multi
( short ) 0);
}
- public void testByte()
- {
+ public void testByte() {
assertEquals(1, BitFieldFactory.getInstance(1).setByteBoolean(( byte ) 0, true));
assertEquals(2, BitFieldFactory.getInstance(2).setByteBoolean(( byte ) 0, true));
assertEquals(4, BitFieldFactory.getInstance(4).setByteBoolean(( byte ) 0, true));
assertEquals(false, BitFieldFactory.getInstance(0x40).isSet(clearedBit));
}
- /**
- * test the clear() method
- */
-
- public void testClear()
- {
+ public void testClear() {
assertEquals(bf_multi.clear(-1), 0xFFFFC07F);
assertEquals(bf_single.clear(-1), 0xFFFFBFFF);
}
- /**
- * test the clearShort() method
- */
-
- public void testClearShort()
- {
+ public void testClearShort() {
assertEquals(bf_multi.clearShort(( short ) -1), ( short ) 0xC07F);
assertEquals(bf_single.clearShort(( short ) -1), ( short ) 0xBFFF);
}
- /**
- * test the set() method
- */
-
- public void testSet()
- {
+ public void testSet() {
assertEquals(bf_multi.set(0), 0x3F80);
assertEquals(bf_single.set(0), 0x4000);
}
- /**
- * test the setShort() method
- */
-
- public void testSetShort()
- {
+ public void testSetShort() {
assertEquals(bf_multi.setShort(( short ) 0), ( short ) 0x3F80);
assertEquals(bf_single.setShort(( short ) 0), ( short ) 0x4000);
}
- /**
- * test the setBoolean() method
- */
-
- public void testSetBoolean()
- {
+ public void testSetBoolean() {
assertEquals(bf_multi.set(0), bf_multi.setBoolean(0, true));
assertEquals(bf_single.set(0), bf_single.setBoolean(0, true));
assertEquals(bf_multi.clear(-1), bf_multi.setBoolean(-1, false));
assertEquals(bf_single.clear(-1), bf_single.setBoolean(-1, false));
}
- /**
- * test the setShortBoolean() method
- */
-
- public void testSetShortBoolean()
- {
+ public void testSetShortBoolean() {
assertEquals(bf_multi.setShort(( short ) 0),
bf_multi.setShortBoolean(( short ) 0, true));
assertEquals(bf_single.setShort(( short ) 0),
assertEquals(bf_single.clearShort(( short ) -1),
bf_single.setShortBoolean(( short ) -1, false));
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out.println("Testing util.BitField functionality");
- junit.textui.TestRunner.run(TestBitField.class);
- }
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.util;
-import junit.framework.*;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
-import java.io.*;
+import junit.framework.TestCase;
/**
* Title: Unit test for ByteField class
* Description: Unit test for ByteField class
* @author Marc Johnson (mjohnson at apache dot org)
*/
+public final class TestByteField extends TestCase {
-public class TestByteField
- extends TestCase
-{
-
- /**
- * Constructor
- *
- * @param name
- */
-
- public TestByteField(String name)
- {
- super(name);
- }
-
- static private final byte[] _test_array =
+ private static final byte[] _test_array =
{
Byte.MIN_VALUE, ( byte ) -1, ( byte ) 0, ( byte ) 1, Byte.MAX_VALUE
};
- /**
- * Test constructors.
- */
-
- public void testConstructors()
- {
+ public void testConstructors() {
try
{
new ByteField(-1);
}
}
- /**
- * Test set() methods
- */
-
- public void testSet()
- {
+ public void testSet() {
ByteField field = new ByteField(0);
byte[] array = new byte[ 1 ];
}
}
- /**
- * Test readFromBytes
- */
-
- public void testReadFromBytes()
- {
+ public void testReadFromBytes() {
ByteField field = new ByteField(1);
byte[] array = new byte[ 1 ];
}
}
- /**
- * Test readFromStream
- *
- * @exception IOException
- */
-
- public void testReadFromStream()
- throws IOException
- {
+ public void testReadFromStream() throws IOException {
ByteField field = new ByteField(0);
byte[] buffer = new byte[ _test_array.length ];
}
}
- /**
- * test writeToBytes
- */
-
- public void testWriteToBytes()
- {
+ public void testWriteToBytes() {
ByteField field = new ByteField(0);
byte[] array = new byte[ 1 ];
assertEquals("testing ", _test_array[ j ], array[ 0 ]);
}
}
-
- /**
- * Main
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out.println("Testing util.ByteField functionality");
- junit.textui.TestRunner.run(TestByteField.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.util;
-import junit.framework.*;
+import junit.framework.TestCase;
/**
* Class to test IntList
*
* @author Marc Johnson
*/
+public final class TestIntList extends TestCase {
-public class TestIntList
- extends TestCase
-{
-
- /**
- * Constructor TestIntList
- *
- * @param name
- */
-
- public TestIntList(String name)
- {
- super(name);
- }
-
- /**
- * test the various IntListconstructors
- */
-
- public void testConstructors()
- {
+ public void testConstructors() {
IntList list = new IntList();
assertTrue(list.isEmpty());
assertTrue(list3.isEmpty());
}
- /**
- * test the add method
- */
-
- public void testAdd()
- {
+ public void testAdd() {
IntList list = new IntList();
int[] testArray =
{
}
}
- /**
- * test the addAll method
- */
-
- public void testAddAll()
- {
+ public void testAddAll() {
IntList list = new IntList();
for (int j = 0; j < 5; j++)
assertEquals(list.get(4), empty.get(14));
}
- /**
- * test the clear method
- */
-
- public void testClear()
- {
+ public void testClear() {
IntList list = new IntList();
for (int j = 0; j < 500; j++)
}
}
- /**
- * test the contains method
- */
-
- public void testContains()
- {
+ public void testContains() {
IntList list = new IntList();
for (int j = 0; j < 1000; j += 2)
}
}
- /**
- * test the containsAll method
- */
-
- public void testContainsAll()
- {
+ public void testContainsAll() {
IntList list = new IntList();
assertTrue(list.containsAll(list));
assertTrue(!list.containsAll(list2));
}
- /**
- * test the equals method
- */
-
- public void testEquals()
- {
+ public void testEquals() {
IntList list = new IntList();
assertEquals(list, list);
assertTrue(!list2.equals(list));
}
- /**
- * test the get method
- */
-
- public void testGet()
- {
+ public void testGet() {
IntList list = new IntList();
for (int j = 0; j < 1000; j++)
}
}
- /**
- * test the indexOf method
- */
-
- public void testIndexOf()
- {
+ public void testIndexOf() {
IntList list = new IntList();
for (int j = 0; j < 1000; j++)
}
}
- /**
- * test the isEmpty method
- */
-
- public void testIsEmpty()
- {
+ public void testIsEmpty() {
IntList list1 = new IntList();
IntList list2 = new IntList(1000);
IntList list3 = new IntList(list1);
assertTrue(list3.isEmpty());
}
- /**
- * test the lastIndexOf method
- */
-
- public void testLastIndexOf()
- {
+ public void testLastIndexOf() {
IntList list = new IntList();
for (int j = 0; j < 1000; j++)
}
}
- /**
- * test the remove method
- */
-
- public void testRemove()
- {
+ public void testRemove() {
IntList list = new IntList();
for (int j = 0; j < 1000; j++)
}
}
- /**
- * test the removeValue method
- */
-
- public void testRemoveValue()
- {
+ public void testRemoveValue() {
IntList list = new IntList();
for (int j = 0; j < 1000; j++)
}
}
- /**
- * test the removeAll method
- */
-
- public void testRemoveAll()
- {
+ public void testRemoveAll() {
IntList list = new IntList();
for (int j = 0; j < 1000; j++)
assertTrue(listCopy.isEmpty());
}
- /**
- * test the retainAll method
- */
-
- public void testRetainAll()
- {
+ public void testRetainAll() {
IntList list = new IntList();
for (int j = 0; j < 1000; j++)
assertTrue(listCopy.isEmpty());
}
- /**
- * test the set method
- */
-
- public void testSet()
- {
+ public void testSet() {
IntList list = new IntList();
for (int j = 0; j < 1000; j++)
}
}
- /**
- * test the size method
- */
-
- public void testSize()
- {
+ public void testSize() {
IntList list = new IntList();
for (int j = 0; j < 1000; j++)
}
}
- /**
- * test the toArray method
- */
-
- public void testToArray()
- {
+ public void testToArray() {
IntList list = new IntList();
for (int j = 0; j < 1000; j++)
assertEquals(a5[ j ], list.get(j));
}
}
-
- /**
- * main method to run the unit tests
- *
- * @param unused_args
- */
-
- public static void main(String [] unused_args)
- {
- System.out.println("Testing util.IntList functionality");
- junit.textui.TestRunner.run(TestIntList.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.util;
-import junit.framework.*;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
-import java.io.*;
+import junit.framework.TestCase;
/**
* Test IntegerField code
*
* @author Marc Johnson (mjohnson at apache dot org)
*/
+public final class TestIntegerField extends TestCase {
-public class TestIntegerField
- extends TestCase
-{
-
- /**
- * Constructor
- *
- * @param name
- */
-
- public TestIntegerField(String name)
- {
- super(name);
- }
-
- static private final int[] _test_array =
+ private static final int[] _test_array =
{
Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE
};
- /**
- * Test constructors.
- */
-
- public void testConstructors()
- {
+ public void testConstructors() {
try
{
new IntegerField(-1);
}
}
- /**
- * Test set() methods
- */
-
- public void testSet()
- {
+ public void testSet() {
IntegerField field = new IntegerField(0);
byte[] array = new byte[ 4 ];
}
}
- /**
- * Test readFromBytes
- */
-
- public void testReadFromBytes()
- {
+ public void testReadFromBytes() {
IntegerField field = new IntegerField(1);
byte[] array = new byte[ 4 ];
}
}
- /**
- * Test readFromStream
- *
- * @exception IOException
- */
-
- public void testReadFromStream()
- throws IOException
- {
+ public void testReadFromStream() throws IOException {
IntegerField field = new IntegerField(0);
byte[] buffer = new byte[ _test_array.length * 4 ];
}
}
- /**
- * test writeToBytes
- */
-
- public void testWriteToBytes()
- {
+ public void testWriteToBytes() {
IntegerField field = new IntegerField(0);
byte[] array = new byte[ 4 ];
assertEquals("testing ", _test_array[ j ], val);
}
}
-
- /**
- * Main
- *
- * @param args
- */
-
- public static void main(String [] args)
- {
- System.out.println("Testing util.IntegerField functionality");
- junit.textui.TestRunner.run(TestIntegerField.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.util;
import junit.framework.TestCase;
-import java.io.IOException;
-
/**
* @author Marc Johnson (mjohnson at apache dot org)
* @author Glen Stampoultzis (glens at apache.org)
* @author Nicola Ken Barozzi (nicolaken at apache.org)
*/
+public final class TestPOILogFactory extends TestCase {
-public class TestPOILogFactory
- extends TestCase
-{
- /**
- * Creates new TestPOILogFactory
- *
- * @param name
- */
-
- public TestPOILogFactory( String name )
- {
- super( name );
- }
/**
* test log creation
- *
- * @exception IOException
*/
-
- public void testLog()
- throws IOException
- {
+ public void testLog() {
//NKB Testing only that logging classes use gives no exception
// Since logging can be disabled, no checking of logging
// output is done.
l2.log( POILogger.DEBUG, "testing cat org.apache.poi.hdf.*:DEBUG" );
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main( String[] ignored_args )
- {
- System.out.println( "Testing basic util.POILogFactory functionality" );
- junit.textui.TestRunner.run( TestPOILogFactory.class );
- }
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.util;
* @author Marc Johnson (mjohnson at apache dot org)
* @author Nicola Ken Barozzi (nicolaken at apache.org)
*/
-
-public class TestPOILogger
- extends TestCase
-{
- /**
- * Constructor TestPOILogger
- *
- *
- * @param s
- *
- */
-
- public TestPOILogger( String s )
- {
- super( s );
- }
+public final class TestPOILogger extends TestCase {
/**
* Test different types of log output.
- *
- * @exception Exception
*/
- public void testVariousLogTypes()
- throws Exception
- {
+ public void testVariousLogTypes() {
//NKB Testing only that logging classes use gives no exception
// Since logging can be disabled, no checking of logging
// output is done.
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.util;
*
* @author Marc Johnson (mjohnson at apache dot org)
*/
+public final class TestShortField extends TestCase {
-public class TestShortField
- extends TestCase
-{
-
- /**
- * Constructor
- *
- * @param name
- */
-
- public TestShortField(String name)
- {
- super(name);
- }
-
- static private final short[] _test_array =
+ private static final short[] _test_array =
{
Short.MIN_VALUE, ( short ) -1, ( short ) 0, ( short ) 1,
Short.MAX_VALUE
};
- /**
- * Test constructors.
- */
-
- public void testConstructors()
- {
+ public void testConstructors() {
try
{
new ShortField(-1);
}
}
- /**
- * Test set() methods
- */
-
- public void testSet()
- {
+ public void testSet() {
ShortField field = new ShortField(0);
byte[] array = new byte[ 2 ];
}
}
- /**
- * Test readFromBytes
- */
-
- public void testReadFromBytes()
- {
+ public void testReadFromBytes() {
ShortField field = new ShortField(1);
byte[] array = new byte[ 2 ];
}
}
- /**
- * Test readFromStream
- *
- * @exception IOException
- */
-
- public void testReadFromStream()
- throws IOException
- {
+ public void testReadFromStream() throws IOException {
ShortField field = new ShortField(0);
byte[] buffer = new byte[ _test_array.length * 2 ];
}
}
- /**
- * test writeToBytes
- */
-
- public void testWriteToBytes()
- {
+ public void testWriteToBytes() {
ShortField field = new ShortField(0);
byte[] array = new byte[ 2 ];
assertEquals("testing ", _test_array[ j ], val);
}
}
-
- /**
- * Main
- *
- * @param args
- */
-
- public static void main(String [] args)
- {
- System.out.println("Testing util.ShortField functionality");
- junit.textui.TestRunner.run(TestShortField.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.util;
-import junit.framework.*;
+import junit.framework.TestCase;
/**
* Class to test ShortList
*
* @author Marc Johnson
*/
+public final class TestShortList extends TestCase {
-public class TestShortList
- extends TestCase
-{
-
- /**
- * Constructor TestShortList
- *
- * @param name
- */
-
- public TestShortList(String name)
- {
- super(name);
- }
-
- /**
- * test the various ShortListconstructors
- */
-
- public void testConstructors()
- {
+ public void testConstructors() {
ShortList list = new ShortList();
assertTrue(list.isEmpty());
assertTrue(list3.isEmpty());
}
- /**
- * test the add method
- */
-
- public void testAdd()
- {
+ public void testAdd() {
ShortList list = new ShortList();
short[] testArray =
{
}
}
- /**
- * test the addAll method
- */
-
- public void testAddAll()
- {
+ public void testAddAll() {
ShortList list = new ShortList();
for (short j = 0; j < 5; j++)
assertEquals(list.get(4), empty.get(14));
}
- /**
- * test the clear method
- */
-
- public void testClear()
- {
+ public void testClear() {
ShortList list = new ShortList();
for (short j = 0; j < 500; j++)
}
}
- /**
- * test the contains method
- */
-
- public void testContains()
- {
+ public void testContains() {
ShortList list = new ShortList();
for (short j = 0; j < 1000; j += 2)
}
}
- /**
- * test the containsAll method
- */
-
- public void testContainsAll()
- {
+ public void testContainsAll() {
ShortList list = new ShortList();
assertTrue(list.containsAll(list));
assertTrue(!list.containsAll(list2));
}
- /**
- * test the equals method
- */
-
- public void testEquals()
- {
+ public void testEquals() {
ShortList list = new ShortList();
assertEquals(list, list);
assertTrue(!list2.equals(list));
}
- /**
- * test the get method
- */
-
- public void testGet()
- {
+ public void testGet() {
ShortList list = new ShortList();
for (short j = 0; j < 1000; j++)
}
}
- /**
- * test the indexOf method
- */
-
- public void testIndexOf()
- {
+ public void testIndexOf() {
ShortList list = new ShortList();
for (short j = 0; j < 1000; j++)
}
}
- /**
- * test the isEmpty method
- */
-
- public void testIsEmpty()
- {
+ public void testIsEmpty() {
ShortList list1 = new ShortList();
ShortList list2 = new ShortList(1000);
ShortList list3 = new ShortList(list1);
assertTrue(list3.isEmpty());
}
- /**
- * test the lastIndexOf method
- */
-
- public void testLastIndexOf()
- {
+ public void testLastIndexOf() {
ShortList list = new ShortList();
for (short j = 0; j < 1000; j++)
}
}
- /**
- * test the remove method
- */
-
- public void testRemove()
- {
+ public void testRemove() {
ShortList list = new ShortList();
for (short j = 0; j < 1000; j++)
}
}
- /**
- * test the removeValue method
- */
-
- public void testRemoveValue()
- {
+ public void testRemoveValue() {
ShortList list = new ShortList();
for (short j = 0; j < 1000; j++)
}
}
- /**
- * test the removeAll method
- */
-
- public void testRemoveAll()
- {
+ public void testRemoveAll() {
ShortList list = new ShortList();
for (short j = 0; j < 1000; j++)
assertTrue(listCopy.isEmpty());
}
- /**
- * test the retainAll method
- */
-
- public void testRetainAll()
- {
+ public void testRetainAll() {
ShortList list = new ShortList();
for (short j = 0; j < 1000; j++)
assertTrue(listCopy.isEmpty());
}
- /**
- * test the set method
- */
-
- public void testSet()
- {
+ public void testSet() {
ShortList list = new ShortList();
for (short j = 0; j < 1000; j++)
}
}
- /**
- * test the size method
- */
-
- public void testSize()
- {
+ public void testSize() {
ShortList list = new ShortList();
for (short j = 0; j < 1000; j++)
}
}
- /**
- * test the toArray method
- */
-
- public void testToArray()
- {
+ public void testToArray() {
ShortList list = new ShortList();
for (short j = 0; j < 1000; j++)
assertEquals(a5[ j ], list.get(j));
}
}
-
- /**
- * main method to run the unit tests
- *
- * @param unused_args
- */
-
- public static void main(String [] unused_args)
- {
- System.out.println("Testing util.ShortList functionality");
- junit.textui.TestRunner.run(TestShortList.class);
- }
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-package org.apache.poi.util;
-import junit.framework.*;
+package org.apache.poi.util;
+import java.io.UnsupportedEncodingException;
import java.text.NumberFormat;
+import junit.framework.TestCase;
+
/**
* Unit test for StringUtil
*
* @author Glen Stampoultzis (glens at apache.org)
* @author Sergei Kozello (sergeikozello at mail.ru)
*/
-public class TestStringUtil
- extends TestCase
-{
- /**
- * Creates new TestStringUtil
- *
- * @param name
- */
- public TestStringUtil( String name )
- {
- super( name );
- }
-
-
+public final class TestStringUtil extends TestCase {
/**
* test getFromUnicodeHigh for symbols with code below and more 127
*/
- public void testGetFromUnicodeHighSymbolsWithCodesMoreThan127()
- {
+ public void testGetFromUnicodeHighSymbolsWithCodesMoreThan127() {
byte[] test_data = new byte[]{0x22, 0x04,
0x35, 0x04,
0x41, 0x04,
StringUtil.getFromUnicodeLE( test_data ) );
}
-
-
- /**
- * Test putCompressedUnicode
- */
- public void testPutCompressedUnicode() throws Exception
- {
+ public void testPutCompressedUnicode() {
byte[] output = new byte[100];
byte[] expected_output =
{
(byte) 'o', (byte) ' ', (byte) 'W', (byte) 'o',
(byte) 'r', (byte) 'l', (byte) 'd', (byte) 0xAE
};
- String input = new String( expected_output, StringUtil.getPreferredEncoding() );
+ String input;
+ try {
+ input = new String( expected_output, StringUtil.getPreferredEncoding() );
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
StringUtil.putCompressedUnicode( input, output, 0 );
for ( int j = 0; j < expected_output.length; j++ )
}
}
- /**
- * Test putUncompressedUnicode
- */
- public void testPutUncompressedUnicode()
- {
+ public void testPutUncompressedUnicode() {
byte[] output = new byte[100];
String input = "Hello World";
byte[] expected_output =
}
}
-
- public void testFormat()
- throws Exception
- {
+ public void testFormat() {
assertEquals( "This is a test " + fmt( 1.2345, 2, 2 ),
StringUtil.format( "This is a test %2.2", new Object[]
{
}
- private String fmt( double num, int minIntDigits, int maxFracDigitis )
- {
+ private static String fmt(double num, int minIntDigits, int maxFracDigitis) {
NumberFormat nf = NumberFormat.getInstance();
if ( minIntDigits != -1 )
return nf.format( num );
}
-
-
- /**
- * main
- *
- * @param ignored_args
- */
- public static void main( String[] ignored_args )
- {
- System.out.println( "Testing util.StringUtil functionality" );
- junit.textui.TestRunner.run( TestStringUtil.class );
- }
-
- /**
- * @see junit.framework.TestCase#setUp()
- */
- protected void setUp() throws Exception
- {
- super.setUp();
-
- // System.setProperty()
- }
-
}