diff --git a/src/excelant/testcases/org/apache/poi/ss/examples/formula/TestExcelAntUserDefinedFunction.java b/src/excelant/testcases/org/apache/poi/ss/examples/formula/TestExcelAntUserDefinedFunction.java index ad9851ae8f..0606a8bd89 100644 --- a/src/excelant/testcases/org/apache/poi/ss/examples/formula/TestExcelAntUserDefinedFunction.java +++ b/src/excelant/testcases/org/apache/poi/ss/examples/formula/TestExcelAntUserDefinedFunction.java @@ -16,36 +16,42 @@ ==================================================================== */ package org.apache.poi.ss.examples.formula; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class TestExcelAntUserDefinedFunction { -public class TestExcelAntUserDefinedFunction extends TestCase { - private ExcelAntUserDefinedFunctionTestHelper fixture ; - - @Override + + @Before public void setUp() { fixture = new ExcelAntUserDefinedFunctionTestHelper() ; } - + + @Test public void testSetClassName() { String className = "simple.class.name" ; - + fixture.setClassName( className ) ; String value = fixture.getClassName() ; - + assertNotNull( value ) ; assertEquals( className, value ) ; } - + + @Test public void testSetFunction() { String functionAlias = "alias" ; - + fixture.setFunctionAlias( functionAlias ) ; - + String alias = fixture.getFunctionAlias() ; - + assertNotNull( alias ) ; assertEquals( functionAlias, alias ) ; } - + } diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/BuildFileTest.java b/src/excelant/testcases/org/apache/poi/ss/excelant/BuildFileTest.java deleted file mode 100644 index a582a45ab3..0000000000 --- a/src/excelant/testcases/org/apache/poi/ss/excelant/BuildFileTest.java +++ /dev/null @@ -1,593 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.poi.ss.excelant; - -import static org.apache.poi.POITestCase.assertContains; -import static org.apache.poi.POITestCase.assertNotContained; - -import java.io.File; -import java.io.PrintStream; -import java.net.URL; - -import junit.framework.TestCase; - -import org.apache.poi.POIDataSamples; -import org.apache.tools.ant.BuildEvent; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.BuildListener; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.ProjectHelper; - -/** - * A BuildFileTest is a TestCase which executes targets from an Ant buildfile - * for testing. - *

- * This class provides a number of utility methods for particular build file - * tests which extend this class. - * - * @see - * http://svn.apache.org/repos/asf/ant/core/trunk/src/tests/junit/org/apache/tools/ant/BuildFileTest.java - */ -public abstract class BuildFileTest extends TestCase { - - protected Project project; - - private StringBuilder logBuffer; - private StringBuilder fullLogBuffer; - private StringBuilder outBuffer; - private StringBuilder errBuffer; - private BuildException buildException; - - /** - * Default constructor for the BuildFileTest object. - */ - public BuildFileTest() { - super(); - } - - /** - * Constructor for the BuildFileTest object. - * - * @param name string to pass up to TestCase constructor - */ - public BuildFileTest(String name) { - super(name); - } - - /** - * Automatically calls the target called "tearDown" - * from the build file tested if it exits. - *

- * This allows to use Ant tasks directly in the build file - * to clean up after each test. Note that no "setUp" target - * is automatically called, since it's trivial to have a - * test target depend on it. - */ - @Override - protected void tearDown() throws Exception { - if (project == null) { - /* - * Maybe the BuildFileTest was subclassed and there is - * no initialized project. So we could avoid getting a - * NPE. - * If there is an initialized project getTargets() does - * not return null as it is initialized by an empty - * HashSet. - */ - return; - } - final String tearDown = "tearDown"; - if (project.getTargets().containsKey(tearDown)) { - project.executeTarget(tearDown); - } - } - - /** - * run a target, expect for any build exception - * - * @param target target to run - * @param cause information string to reader of report - */ - public void expectBuildException(String target, String cause) { - expectSpecificBuildException(target, cause, null); - } - - /** - * Assert that only the given message has been logged with a - * priority <= INFO when running the given target. - */ - public void expectLog(String target, String log) { - executeTarget(target); - String realLog = getLog(); - assertEquals(log, realLog); - } - - /** - * Assert that the given substring is in the log messages. - */ - public void assertLogContaining(String substring) { - assertContains(getLog(), substring); - } - - /** - * Assert that the given substring is not in the log messages. - */ - public void assertLogNotContaining(String substring) { - assertNotContained(getLog(), substring); - } - - /** - * Assert that the given substring is in the output messages. - * - * @since Ant1.7 - */ - public void assertOutputContaining(String substring) { - assertOutputContaining(null, substring); - } - - /** - * Assert that the given substring is in the output messages. - * - * @param message Print this message if the test fails. Defaults to - * a meaningful text if null is passed. - * @since Ant1.7 - */ - public void assertOutputContaining(String message, String substring) { - assertContains("output: " + message, getOutput(), substring); - } - - /** - * Assert that the given substring is not in the output messages. - * - * @param message Print this message if the test fails. Defaults to - * a meaningful text if null is passed. - * @since Ant1.7 - */ - public void assertOutputNotContaining(String message, String substring) { - assertNotContained(getOutput(), substring); - } - - /** - * Assert that the given message has been logged with a priority <= INFO when running the - * given target. - */ - public void expectLogContaining(String target, String log) { - executeTarget(target); - assertLogContaining(log); - } - - /** - * Assert that the given message has not been logged with a - * priority <= INFO when running the given target. - */ - public void expectLogNotContaining(String target, String log) { - executeTarget(target); - assertLogNotContaining(log); - } - - /** - * Gets the log the BuildFileTest object. - * Only valid if configureProject() has been called. - * - * @return The log value - * @pre logBuffer!=null - */ - public String getLog() { - return logBuffer.toString(); - } - - /** - * Assert that the given message has been logged with a priority - * >= VERBOSE when running the given target. - */ - public void expectDebuglog(String target, String log) { - executeTarget(target); - String realLog = getFullLog(); - assertEquals(log, realLog); - } - - /** - * Assert that the given substring is in the log messages. - */ - public void assertDebuglogContaining(String substring) { - String realLog = getFullLog(); - assertContains("expecting debug log to contain \"" + substring - + "\" log was \"" - + realLog + "\"", - realLog, substring); - } - - /** - * Gets the log the BuildFileTest object. - *

- * Only valid if configureProject() has been called. - * - * @return The log value - * @pre fullLogBuffer!=null - */ - public String getFullLog() { - return fullLogBuffer.toString(); - } - - /** - * execute the target, verify output matches expectations - * - * @param target target to execute - * @param output output to look for - */ - public void expectOutput(String target, String output) { - executeTarget(target); - String realOutput = getOutput(); - assertEquals(output, realOutput.trim()); - } - - /** - * Executes the target, verify output matches expectations - * and that we got the named error at the end - * - * @param target target to execute - * @param output output to look for - * @param error Description of Parameter - */ - public void expectOutputAndError(String target, String output, String error) { - executeTarget(target); - String realOutput = getOutput(); - assertEquals(output, realOutput); - String realError = getError(); - assertEquals(error, realError); - } - - public String getOutput() { - return cleanBuffer(outBuffer); - } - - public String getError() { - return cleanBuffer(errBuffer); - } - - public BuildException getBuildException() { - return buildException; - } - - private String cleanBuffer(StringBuilder buffer) { - StringBuilder cleanedBuffer = new StringBuilder(); - for (int i = 0; i < buffer.length(); i++) { - char ch = buffer.charAt(i); - if (ch != '\r') { - cleanedBuffer.append(ch); - } - } - return cleanedBuffer.toString(); - } - - /** - * Sets up to run the named project - * - * @param filename name of project file to run - */ - public void configureProject(String filename) throws BuildException { - configureProject(filename, Project.MSG_DEBUG); - } - - /** - * Sets up to run the named project - * - * @param filename name of project file to run - */ - public void configureProject(String filename, int logLevel) - throws BuildException { - logBuffer = new StringBuilder(); - fullLogBuffer = new StringBuilder(); - project = new Project(); - project.init(); - project.setNewProperty("data.dir.name", getDataDir()); - File antFile = new File(System.getProperty("root"), filename); - project.setUserProperty("ant.file", antFile.getAbsolutePath()); - project.addBuildListener(new AntTestListener(logLevel)); - ProjectHelper.configureProject(project, antFile); - } - - /** - * Executes a target we have set up - * - * @param targetName target to run - * @pre configureProject has been called - */ - public void executeTarget(String targetName) { - PrintStream sysOut = System.out; - PrintStream sysErr = System.err; - try { - sysOut.flush(); - sysErr.flush(); - outBuffer = new StringBuilder(); - PrintStream out = new PrintStream(new AntOutputStream(outBuffer)); - System.setOut(out); - errBuffer = new StringBuilder(); - PrintStream err = new PrintStream(new AntOutputStream(errBuffer)); - System.setErr(err); - logBuffer = new StringBuilder(); - fullLogBuffer = new StringBuilder(); - buildException = null; - project.executeTarget(targetName); - } finally { - System.setOut(sysOut); - System.setErr(sysErr); - } - - } - - /** - * Get the project which has been configured for a test. - * - * @return the Project instance for this test. - */ - public Project getProject() { - return project; - } - - /** - * Gets the directory of the project. - * - * @return the base dir of the project - */ - public File getProjectDir() { - return project.getBaseDir(); - } - - /** - * Runs a target, wait for a build exception. - * - * @param target target to run - * @param cause information string to reader of report - * @param msg the message value of the build exception we are waiting - * for set to null for any build exception to be valid - */ - public void expectSpecificBuildException(String target, String cause, String msg) { - try { - executeTarget(target); - } catch (org.apache.tools.ant.BuildException ex) { - buildException = ex; - if ((null != msg) && (!ex.getMessage().equals(msg))) { - fail("Should throw BuildException because '" + cause - + "' with message '" + msg - + "' (actual message '" + ex.getMessage() + "' instead)"); - } - return; - } - fail("Should throw BuildException because: " + cause); - } - - /** - * run a target, expect an exception string - * containing the substring we look for (case sensitive match) - * - * @param target target to run - * @param cause information string to reader of report - * @param contains substring of the build exception to look for - */ - public void expectBuildExceptionContaining(String target, String cause, String contains) { - try { - executeTarget(target); - } catch (org.apache.tools.ant.BuildException ex) { - buildException = ex; - if ((null != contains) && (!ex.getMessage().contains(contains))) { - fail("Should throw BuildException because '" + cause + "' with message containing '" + contains + "' (actual message '" + ex.getMessage() + "' instead)"); - } - return; - } - fail("Should throw BuildException because: " + cause); - } - - /** - * call a target, verify property is as expected - * - * @param target build file target - * @param property property name - * @param value expected value - */ - public void expectPropertySet(String target, String property, String value) { - executeTarget(target); - assertPropertyEquals(property, value); - } - - /** - * assert that a property equals a value; comparison is case sensitive. - * - * @param property property name - * @param value expected value - */ - public void assertPropertyEquals(String property, String value) { - String result = project.getProperty(property); - assertEquals("property " + property, value, result); - } - - /** - * assert that a property equals "true". - * - * @param property property name - */ - public void assertPropertySet(String property) { - assertPropertyEquals(property, "true"); - } - - /** - * assert that a property is null. - * - * @param property property name - */ - public void assertPropertyUnset(String property) { - String result = project.getProperty(property); - if (result != null) { - fail("Expected property " + property - + " to be unset, but it is set to the value: " + result); - } - } - - /** - * call a target, verify named property is "true". - * - * @param target build file target - * @param property property name - */ - public void expectPropertySet(String target, String property) { - expectPropertySet(target, property, "true"); - } - - /** - * Call a target, verify property is null. - * - * @param target build file target - * @param property property name - */ - public void expectPropertyUnset(String target, String property) { - expectPropertySet(target, property, null); - } - - /** - * Retrieve a resource from the caller classloader to avoid - * assuming a vm working directory. The resource path must be - * relative to the package name or absolute from the root path. - * - * @param resource the resource to retrieve its url. - * @throws junit.framework.AssertionFailedError - * if the resource is not found. - */ - public URL getResource(String resource) { - URL url = getClass().getResource(resource); - assertNotNull("Could not find resource :" + resource, url); - return url; - } - - public static String getDataDir() { - String dataDirName = System.getProperty(POIDataSamples.TEST_PROPERTY); - return dataDirName == null ? "test-data" : dataDirName; - } - - /** - * an output stream which saves stuff to our buffer. - */ - protected static class AntOutputStream extends java.io.OutputStream { - private StringBuilder buffer; - - public AntOutputStream(StringBuilder buffer) { - this.buffer = buffer; - } - - @Override - public void write(int b) { - buffer.append((char) b); - } - } - - /** - * Our own personal build listener. - */ - private class AntTestListener implements BuildListener { - private int logLevel; - - /** - * Constructs a test listener which will ignore log events - * above the given level. - */ - public AntTestListener(int logLevel) { - this.logLevel = logLevel; - } - - /** - * Fired before any targets are started. - */ - @Override - public void buildStarted(BuildEvent event) { - } - - /** - * Fired after the last target has finished. This event - * will still be thrown if an error occurred during the build. - * - * @see BuildEvent#getException() - */ - @Override - public void buildFinished(BuildEvent event) { - } - - /** - * Fired when a target is started. - * - * @see BuildEvent#getTarget() - */ - @Override - public void targetStarted(BuildEvent event) { - //System.out.println("targetStarted " + event.getTarget().getName()); - } - - /** - * Fired when a target has finished. This event will - * still be thrown if an error occurred during the build. - * - * @see BuildEvent#getException() - */ - @Override - public void targetFinished(BuildEvent event) { - //System.out.println("targetFinished " + event.getTarget().getName()); - } - - /** - * Fired when a task is started. - * - * @see BuildEvent#getTask() - */ - @Override - public void taskStarted(BuildEvent event) { - //System.out.println("taskStarted " + event.getTask().getTaskName()); - } - - /** - * Fired when a task has finished. This event will still - * be throw if an error occurred during the build. - * - * @see BuildEvent#getException() - */ - @Override - public void taskFinished(BuildEvent event) { - //System.out.println("taskFinished " + event.getTask().getTaskName()); - } - - /** - * Fired whenever a message is logged. - * - * @see BuildEvent#getMessage() - * @see BuildEvent#getPriority() - */ - @Override - public void messageLogged(BuildEvent event) { - if (event.getPriority() > logLevel) { - // ignore event - return; - } - - if (event.getPriority() == Project.MSG_INFO || - event.getPriority() == Project.MSG_WARN || - event.getPriority() == Project.MSG_ERR) { - logBuffer.append(event.getMessage()); - } - fullLogBuffer.append(event.getMessage()); - } - } - -} diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java b/src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java index 7d55c52767..af9e317a42 100644 --- a/src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java +++ b/src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java @@ -15,105 +15,384 @@ * limitations under the License. * */ + package org.apache.poi.ss.excelant; +import static org.apache.poi.POITestCase.assertContains; +import static org.apache.poi.POITestCase.assertNotContained; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.PrintStream; + +import org.apache.poi.POIDataSamples; +import org.apache.tools.ant.BuildEvent; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildListener; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.ProjectHelper; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; /** * JUnit test for the ExcelAnt tasks. * Leverages Ant's test framework. - * - * @see - * http://svn.apache.org/repos/asf/ant/core/trunk/src/tests/junit/org/apache/tools/ant/BuildFileTest.java */ -public class TestBuildFile extends BuildFileTest { +public class TestBuildFile { - @Override + protected Project project; + + private StringBuilder logBuffer; + private StringBuilder fullLogBuffer; + private BuildException buildException; + + + @Before public void setUp() { - configureProject(BuildFileTest.getDataDir() + "/../src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml"); + String filename = TestBuildFile.getDataDir() + "/../src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml"; + int logLevel = Project.MSG_DEBUG; + + logBuffer = new StringBuilder(); + fullLogBuffer = new StringBuilder(); + project = new Project(); + project.init(); + project.setNewProperty("data.dir.name", getDataDir()); + File antFile = new File(System.getProperty("root"), filename); + project.setUserProperty("ant.file", antFile.getAbsolutePath()); + project.addBuildListener(new AntTestListener(logLevel)); + ProjectHelper.configureProject(project, antFile); + } + /** + * Automatically calls the target called "tearDown" + * from the build file tested if it exits. + *

+ * This allows to use Ant tasks directly in the build file + * to clean up after each test. Note that no "setUp" target + * is automatically called, since it's trivial to have a + * test target depend on it. + */ + @After + public void tearDown() { + if (project == null) { + /* + * Maybe the BuildFileTest was subclassed and there is + * no initialized project. So we could avoid getting a + * NPE. + * If there is an initialized project getTargets() does + * not return null as it is initialized by an empty + * HashSet. + */ + return; + } + final String tearDown = "tearDown"; + if (project.getTargets().containsKey(tearDown)) { + project.executeTarget(tearDown); + } + } + + /** + * run a target, expect for any build exception + * + * @param target target to run + * @param cause information string to reader of report + */ + public void expectBuildException(String target, String cause) { + expectSpecificBuildException(target, cause, null); + } + + /** + * Assert that the given substring is in the log messages. + */ + public void assertLogContaining(String substring) { + assertContains(getLog(), substring); + } + + /** + * Assert that the given substring is not in the log messages. + */ + public void assertLogNotContaining(String substring) { + assertNotContained(getLog(), substring); + } + + /** + * Gets the log the BuildFileTest object. + * Only valid if configureProject() has been called. + * + * @return The log value + */ + public String getLog() { + return logBuffer.toString(); + } + + /** + * Executes a target we have set up + * + * @param targetName target to run + */ + public void executeTarget(String targetName) { + PrintStream sysOut = System.out; + PrintStream sysErr = System.err; + try { + sysOut.flush(); + sysErr.flush(); + StringBuilder outBuffer = new StringBuilder(); + PrintStream out = new PrintStream(new AntOutputStream(outBuffer)); + System.setOut(out); + StringBuilder errBuffer = new StringBuilder(); + PrintStream err = new PrintStream(new AntOutputStream(errBuffer)); + System.setErr(err); + logBuffer = new StringBuilder(); + fullLogBuffer = new StringBuilder(); + buildException = null; + project.executeTarget(targetName); + } finally { + System.setOut(sysOut); + System.setErr(sysErr); + } + + } + + /** + * Runs a target, wait for a build exception. + * + * @param target target to run + * @param cause information string to reader of report + * @param msg the message value of the build exception we are waiting + * for set to null for any build exception to be valid + */ + public void expectSpecificBuildException(String target, String cause, String msg) { + try { + executeTarget(target); + } catch (org.apache.tools.ant.BuildException ex) { + buildException = ex; + if ((null != msg) && (!ex.getMessage().equals(msg))) { + fail("Should throw BuildException because '" + cause + + "' with message '" + msg + + "' (actual message '" + ex.getMessage() + "' instead)"); + } + return; + } + fail("Should throw BuildException because: " + cause); + } + + public static String getDataDir() { + String dataDirName = System.getProperty(POIDataSamples.TEST_PROPERTY); + return dataDirName == null ? "test-data" : dataDirName; + } + + /** + * an output stream which saves stuff to our buffer. + */ + protected static class AntOutputStream extends java.io.OutputStream { + private StringBuilder buffer; + + public AntOutputStream(StringBuilder buffer) { + this.buffer = buffer; + } + + @Override + public void write(int b) { + buffer.append((char) b); + } + } + + /** + * Our own personal build listener. + */ + private class AntTestListener implements BuildListener { + private int logLevel; + + /** + * Constructs a test listener which will ignore log events + * above the given level. + */ + public AntTestListener(int logLevel) { + this.logLevel = logLevel; + } + + /** + * Fired before any targets are started. + */ + @Override + public void buildStarted(BuildEvent event) { + } + + /** + * Fired after the last target has finished. This event + * will still be thrown if an error occurred during the build. + * + * @see BuildEvent#getException() + */ + @Override + public void buildFinished(BuildEvent event) { + } + + /** + * Fired when a target is started. + * + * @see BuildEvent#getTarget() + */ + @Override + public void targetStarted(BuildEvent event) { + //System.out.println("targetStarted " + event.getTarget().getName()); + } + + /** + * Fired when a target has finished. This event will + * still be thrown if an error occurred during the build. + * + * @see BuildEvent#getException() + */ + @Override + public void targetFinished(BuildEvent event) { + //System.out.println("targetFinished " + event.getTarget().getName()); + } + + /** + * Fired when a task is started. + * + * @see BuildEvent#getTask() + */ + @Override + public void taskStarted(BuildEvent event) { + //System.out.println("taskStarted " + event.getTask().getTaskName()); + } + + /** + * Fired when a task has finished. This event will still + * be throw if an error occurred during the build. + * + * @see BuildEvent#getException() + */ + @Override + public void taskFinished(BuildEvent event) { + //System.out.println("taskFinished " + event.getTask().getTaskName()); + } + + /** + * Fired whenever a message is logged. + * + * @see BuildEvent#getMessage() + * @see BuildEvent#getPriority() + */ + @Override + public void messageLogged(BuildEvent event) { + if (event.getPriority() > logLevel) { + // ignore event + return; + } + + if (event.getPriority() == Project.MSG_INFO || + event.getPriority() == Project.MSG_WARN || + event.getPriority() == Project.MSG_ERR) { + logBuffer.append(event.getMessage()); + } + fullLogBuffer.append(event.getMessage()); + } + } + + @Test public void testMissingFilename() { expectSpecificBuildException("test-nofile", "required argument not specified", - "fileName attribute must be set!"); - } + "fileName attribute must be set!"); + } + @Test public void testFileNotFound() { expectSpecificBuildException("test-filenotfound", "required argument not specified", - "Cannot load file invalid.xls. Make sure the path and file permissions are correct."); - } + "Cannot load file invalid.xls. Make sure the path and file permissions are correct."); + } + @Test public void testEvaluate() { executeTarget("test-evaluate"); - assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls"); + assertLogContaining("Using input file: " + TestBuildFile.getDataDir() + "/spreadsheet/excelant.xls"); assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4."); } + @Test public void testEvaluateNoDetails() { executeTarget("test-evaluate-nodetails"); - assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls"); + assertLogContaining("Using input file: " + TestBuildFile.getDataDir() + "/spreadsheet/excelant.xls"); assertLogNotContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4."); } + @Test public void testPrecision() { executeTarget("test-precision"); - assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls"); + assertLogContaining("Using input file: " + TestBuildFile.getDataDir() + "/spreadsheet/excelant.xls"); assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4. " + - "It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-4"); + "It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-4"); assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4. " + - "It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-5"); + "It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-5"); assertLogContaining("Failed to evaluate cell 'MortgageCalculator'!$B$4. " + - "It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-10 was expected."); + "It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-10 was expected."); assertLogContaining("2/3 tests passed"); } + @Test public void testPrecisionFail() { expectSpecificBuildException("test-precision-fails", "precision not matched", - "\tFailed to evaluate cell 'MortgageCalculator'!$B$4. It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-10 was expected."); + "\tFailed to evaluate cell 'MortgageCalculator'!$B$4. It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-10 was expected."); } + @Test public void testPassOnError() { executeTarget("test-passonerror"); } + @Test public void testFailOnError() { expectBuildException("test-failonerror", "fail on error"); - assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls"); + assertLogContaining("Using input file: " + TestBuildFile.getDataDir() + "/spreadsheet/excelant.xls"); assertLogNotContaining("failed because 1 of 0 evaluations failed to evaluate correctly. Failed to evaluate cell 'MortageCalculatorFunction'!$D$3"); } + @Test public void testFailOnErrorNoDetails() { expectBuildException("test-failonerror-nodetails", "fail on error"); - assertLogNotContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls"); + assertLogNotContaining("Using input file: " + TestBuildFile.getDataDir() + "/spreadsheet/excelant.xls"); assertLogNotContaining("failed because 1 of 0 evaluations failed to evaluate correctly. Failed to evaluate cell 'MortageCalculatorFunction'!$D$3"); } + @Test public void testUdf() { executeTarget("test-udf"); assertLogContaining("1/1 tests passed"); } - + + @Test public void testSetText() { executeTarget("test-settext"); assertLogContaining("1/1 tests passed"); } - + + @Test public void testAddHandler() { executeTarget("test-addhandler"); - assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls"); + assertLogContaining("Using input file: " + TestBuildFile.getDataDir() + "/spreadsheet/excelant.xls"); assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4."); - + assertNotNull("The workbook should have been passed to the handler", MockExcelAntWorkbookHandler.workbook); assertTrue("The handler should have been executed", MockExcelAntWorkbookHandler.executed); } - + + @Test public void testAddHandlerWrongClass() { executeTarget("test-addhandler-wrongclass"); - assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls"); + assertLogContaining("Using input file: " + TestBuildFile.getDataDir() + "/spreadsheet/excelant.xls"); assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4."); } - + + @Test public void testAddHandlerFails() { expectSpecificBuildException("test-addhandler-fails", "NullPointException", null); } + } diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntPrecision.java b/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntPrecision.java index 0c6f9cbf83..d815bcf161 100644 --- a/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntPrecision.java +++ b/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntPrecision.java @@ -16,32 +16,38 @@ ==================================================================== */ package org.apache.poi.ss.excelant; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class TestExcelAntPrecision { -public class TestExcelAntPrecision extends TestCase { - private ExcelAntPrecision fixture ; - @Override + @Before public void setUp() { fixture = new ExcelAntPrecision() ; } - - @Override + + @After public void tearDown() { fixture = null ; } - + + @Test public void testVerifyPrecision() { - + double value = 1.0E-1 ; - + fixture.setValue( value ) ; - + double result = fixture.getValue() ; - + assertTrue( result > 0 ) ; - + assertEquals( value, result, 0.0 ) ; } diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSet.java b/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSet.java index b59c886ae9..abf3a799ed 100644 --- a/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSet.java +++ b/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSet.java @@ -16,48 +16,54 @@ ==================================================================== */ package org.apache.poi.ss.excelant; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtil; import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtilFactory; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; -public class TestExcelAntSet extends TestCase { +public class TestExcelAntSet { - - // This is abstract in nature, so we'll use a + + // This is abstract in nature, so we'll use a // concrete instance to test the set methods. private ExcelAntSet fixture ; - + private static final String mortgageCalculatorFileName = - BuildFileTest.getDataDir() + "/spreadsheet/mortgage-calculation.xls" ; - - @Override + TestBuildFile.getDataDir() + "/spreadsheet/mortgage-calculation.xls" ; + + @Before public void setUp() { fixture = new ExcelAntSetDoubleCell() ; } - - @Override + + @After public void tearDown() { fixture = null ; } - + + @Test public void testSetter() { String cell = "simpleCellRef!$F$1" ; - + fixture.setCell( cell ) ; - + String cellStr = fixture.getCell() ; - + assertNotNull( cellStr ) ; assertEquals( cell, cellStr ) ; } - + + @Test public void testSetWorkbookUtil() { ExcelAntWorkbookUtil util = ExcelAntWorkbookUtilFactory.getInstance( mortgageCalculatorFileName ) ; - + assertNotNull( util ) ; - + fixture.setWorkbookUtil( util ) ; } } diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSetDoubleCell.java b/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSetDoubleCell.java index 3d5b11ef49..be30f7a64e 100644 --- a/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSetDoubleCell.java +++ b/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSetDoubleCell.java @@ -16,51 +16,55 @@ ==================================================================== */ package org.apache.poi.ss.excelant; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtil; import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtilFactory; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class TestExcelAntSetDoubleCell { -public class TestExcelAntSetDoubleCell extends TestCase { - private ExcelAntSetDoubleCell fixture ; - + private ExcelAntWorkbookUtil util ; private static final String mortgageCalculatorFileName = - BuildFileTest.getDataDir() + "/spreadsheet/mortgage-calculation.xls" ; + TestBuildFile.getDataDir() + "/spreadsheet/mortgage-calculation.xls" ; - @Override + @Before public void setUp() { fixture = new ExcelAntSetDoubleCell() ; - util = ExcelAntWorkbookUtilFactory.getInstance( - mortgageCalculatorFileName ) ; + util = ExcelAntWorkbookUtilFactory.getInstance(mortgageCalculatorFileName ) ; fixture.setWorkbookUtil( util ) ; } - - @Override + + @After public void tearDown() { fixture = null ; } - + + @Test public void testSetDouble() { String cellId = "'Sheet3'!$A$1" ; double testValue = 1.1 ; - + fixture.setCell( cellId ) ; fixture.setValue( testValue ) ; - + double value = fixture.getCellValue() ; - + assertTrue( value > 0 ) ; assertEquals( testValue, value, 0.0 ) ; - + fixture.execute() ; - + double setValue = util.getCellAsDouble( cellId ) ; - + assertEquals( setValue, testValue, 0.0 ) ; } - + } diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java b/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java index 6f25cb3d3b..3771405cb6 100644 --- a/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java +++ b/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java @@ -16,6 +16,13 @@ ==================================================================== */ package org.apache.poi.ss.excelant.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -23,166 +30,178 @@ import java.util.Date; import java.util.List; import org.apache.poi.ss.examples.formula.CalculateMortgageFunction; -import org.apache.poi.ss.excelant.BuildFileTest; +import org.apache.poi.ss.excelant.TestBuildFile; import org.apache.poi.ss.formula.udf.UDFFinder; import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.ss.usermodel.FormulaEvaluator; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.WorkbookFactory; import org.apache.tools.ant.BuildException; +import org.junit.After; +import org.junit.Test; -import junit.framework.TestCase; +public class TestExcelAntWorkbookUtil { -public class TestExcelAntWorkbookUtil extends TestCase { - private static final String mortgageCalculatorFileName = - BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls" ; + TestBuildFile.getDataDir() + "/spreadsheet/excelant.xls" ; private ExcelAntWorkbookUtilTestHelper fixture ; - - - @Override + + + @After public void tearDown() { fixture = null ; } + @Test public void testStringConstructor() { - fixture = new ExcelAntWorkbookUtilTestHelper( - mortgageCalculatorFileName); - + fixture = new ExcelAntWorkbookUtilTestHelper(mortgageCalculatorFileName); + assertNotNull(fixture); } + @Test public void testLoadNotExistingFile() { try { new ExcelAntWorkbookUtilTestHelper("notexistingFile"); fail("Should catch exception here"); } catch (BuildException e) { - assertTrue(e.getMessage().contains("notexistingFile")); + assertTrue(e.getMessage().contains("notexistingFile")); } } - + + @Test public void testWorkbookConstructor() throws IOException { File workbookFile = new File(mortgageCalculatorFileName); FileInputStream fis = new FileInputStream(workbookFile); Workbook workbook = WorkbookFactory.create(fis); fixture = new ExcelAntWorkbookUtilTestHelper(workbook); - + assertNotNull(fixture); } - + + @Test public void testAddFunction() { fixture = new ExcelAntWorkbookUtilTestHelper( mortgageCalculatorFileName); assertNotNull(fixture); - + fixture.addFunction("h2_ZFactor", new CalculateMortgageFunction()); - + UDFFinder functions = fixture.getFunctions(); - + assertNotNull(functions); assertNotNull(functions.findFunction("h2_ZFactor")); } + @Test public void testAddFunctionClassName() throws Exception { fixture = new ExcelAntWorkbookUtilTestHelper( mortgageCalculatorFileName); assertNotNull(fixture); - + fixture.addFunction("h2_ZFactor", CalculateMortgageFunction.class.getName()); - + UDFFinder functions = fixture.getFunctions(); - + assertNotNull(functions); assertNotNull(functions.findFunction("h2_ZFactor")); } + @Test public void testAddFunctionInvalidClassName() throws Exception { fixture = new ExcelAntWorkbookUtilTestHelper( mortgageCalculatorFileName); assertNotNull(fixture); - + fixture.addFunction("h2_ZFactor", String.class.getName()); - + UDFFinder functions = fixture.getFunctions(); - + assertNotNull(functions); assertNull(functions.findFunction("h2_ZFactor")); } + @Test public void testGetWorkbook() { fixture = new ExcelAntWorkbookUtilTestHelper( mortgageCalculatorFileName); - + assertNotNull(fixture); - + Workbook workbook = fixture.getWorkbook(); - + assertNotNull(workbook); } - + + @Test public void testFileName() { fixture = new ExcelAntWorkbookUtilTestHelper( mortgageCalculatorFileName); - + assertNotNull(fixture); String fileName = fixture.getFileName(); - + assertNotNull(fileName); - + assertEquals(mortgageCalculatorFileName, fileName); - + } - + + @Test public void testGetEvaluator() { fixture = new ExcelAntWorkbookUtilTestHelper( mortgageCalculatorFileName); - + FormulaEvaluator evaluator = fixture.getEvaluator( mortgageCalculatorFileName); - + assertNotNull(evaluator); } + @Test public void testGetEvaluatorWithUDF() { fixture = new ExcelAntWorkbookUtilTestHelper( mortgageCalculatorFileName); fixture.addFunction("h2_ZFactor", new CalculateMortgageFunction()); - + FormulaEvaluator evaluator = fixture.getEvaluator( mortgageCalculatorFileName); - + assertNotNull(evaluator); } - + + @Test public void testGetEvaluatorXLSX() { fixture = new ExcelAntWorkbookUtilTestHelper( - BuildFileTest.getDataDir() + "/spreadsheet/sample.xlsx"); - + TestBuildFile.getDataDir() + "/spreadsheet/sample.xlsx"); + FormulaEvaluator evaluator = fixture.getEvaluator( - BuildFileTest.getDataDir() + "/spreadsheet/sample.xlsx"); - + TestBuildFile.getDataDir() + "/spreadsheet/sample.xlsx"); + assertNotNull(evaluator); } + @Test public void testGetEvaluatorXLSXWithFunction() { fixture = new ExcelAntWorkbookUtilTestHelper( - BuildFileTest.getDataDir() + "/spreadsheet/sample.xlsx"); - + TestBuildFile.getDataDir() + "/spreadsheet/sample.xlsx"); + fixture.addFunction("h2_ZFactor", new CalculateMortgageFunction()); - + FormulaEvaluator evaluator = fixture.getEvaluator( - BuildFileTest.getDataDir() + "/spreadsheet/sample.xlsx"); - + TestBuildFile.getDataDir() + "/spreadsheet/sample.xlsx"); + assertNotNull(evaluator); } + @Test public void testEvaluateCell() { String cell = "'MortgageCalculator'!B4" ; double expectedValue = 790.79 ; @@ -191,8 +210,8 @@ public class TestExcelAntWorkbookUtil extends TestCase { fixture = new ExcelAntWorkbookUtilTestHelper( mortgageCalculatorFileName); - ExcelAntEvaluationResult result = fixture.evaluateCell(cell, - expectedValue, + ExcelAntEvaluationResult result = fixture.evaluateCell(cell, + expectedValue, precision); //System.out.println(result); @@ -204,7 +223,8 @@ public class TestExcelAntWorkbookUtil extends TestCase { assertFalse(result.evaluationCompleteWithError()); assertTrue(result.didTestPass()); } - + + @Test public void testEvaluateCellFailedPrecision() { String cell = "'MortgageCalculator'!B4" ; double expectedValue = 790.79 ; @@ -213,8 +233,8 @@ public class TestExcelAntWorkbookUtil extends TestCase { fixture = new ExcelAntWorkbookUtilTestHelper( mortgageCalculatorFileName); - ExcelAntEvaluationResult result = fixture.evaluateCell(cell, - expectedValue, + ExcelAntEvaluationResult result = fixture.evaluateCell(cell, + expectedValue, precision); //System.out.println(result); @@ -226,7 +246,8 @@ public class TestExcelAntWorkbookUtil extends TestCase { assertFalse(result.evaluationCompleteWithError()); assertFalse(result.didTestPass()); } - + + @Test public void testEvaluateCellWithError() { String cell = "'ErrorCell'!A1" ; double expectedValue = 790.79 ; @@ -235,8 +256,8 @@ public class TestExcelAntWorkbookUtil extends TestCase { fixture = new ExcelAntWorkbookUtilTestHelper( mortgageCalculatorFileName); - ExcelAntEvaluationResult result = fixture.evaluateCell(cell, - expectedValue, + ExcelAntEvaluationResult result = fixture.evaluateCell(cell, + expectedValue, precision); System.out.println(result); @@ -248,35 +269,38 @@ public class TestExcelAntWorkbookUtil extends TestCase { assertTrue(result.evaluationCompleteWithError()); assertFalse(result.didTestPass()); } - + + @Test public void testGetSheets() { fixture = new ExcelAntWorkbookUtilTestHelper( mortgageCalculatorFileName); - + List sheets = fixture.getSheets(); - + assertNotNull(sheets); - assertEquals(sheets.size(), 3); + assertEquals(sheets.size(), 3); } - + + @Test public void testSetString() { String cell = "'MortgageCalculator'!C14" ; String cellValue = "testString" ; - + fixture = new ExcelAntWorkbookUtilTestHelper( mortgageCalculatorFileName); - + fixture.setStringValue(cell, cellValue); - + String value = fixture.getCellAsString(cell); - + assertNotNull(value); assertEquals(cellValue, value); } - + + @Test public void testSetNotExistingSheet() { String cell = "'NotexistingSheet'!C14" ; - + fixture = new ExcelAntWorkbookUtilTestHelper( mortgageCalculatorFileName); try { @@ -287,68 +311,72 @@ public class TestExcelAntWorkbookUtil extends TestCase { } } + @Test public void testSetFormula() { String cell = "'MortgageCalculator'!C14" ; String cellValue = "SUM(B14:B18)" ; - + fixture = new ExcelAntWorkbookUtilTestHelper( mortgageCalculatorFileName); - + fixture.setFormulaValue(cell, cellValue); - + double value = fixture.getCellAsDouble(cell); - - assertEquals(0.0, value); + + assertEquals(0.0, value, 0); } - + + @Test public void testSetDoubleValue() { String cell = "'MortgageCalculator'!C14" ; double cellValue = 1.2; - + fixture = new ExcelAntWorkbookUtilTestHelper( mortgageCalculatorFileName); - + fixture.setDoubleValue(cell, cellValue); - - Double value = fixture.getCellAsDouble(cell); - - assertNotNull(value); - assertEquals(cellValue, value); + + double value = fixture.getCellAsDouble(cell); + + assertEquals(cellValue, value, 0); } - + + @Test public void testSetDate() { String cell = "'MortgageCalculator'!C14" ; Date cellValue = new Date(); - + fixture = new ExcelAntWorkbookUtilTestHelper( mortgageCalculatorFileName); - + fixture.setDateValue(cell, cellValue); - + double value = fixture.getCellAsDouble(cell); - - assertEquals(DateUtil.getExcelDate(cellValue, false), value); + + assertEquals(DateUtil.getExcelDate(cellValue, false), value, 0); } + @Test public void testGetNonexistingString() { String cell = "'MortgageCalculator'!C33" ; - + fixture = new ExcelAntWorkbookUtilTestHelper( mortgageCalculatorFileName); - + String value = fixture.getCellAsString(cell); - + assertEquals("", value); } + @Test public void testGetNonexistingDouble() { String cell = "'MortgageCalculator'!C33" ; - + fixture = new ExcelAntWorkbookUtilTestHelper( mortgageCalculatorFileName); - + double value = fixture.getCellAsDouble(cell); - - assertEquals(0.0, value); + + assertEquals(0.0, value, 0); } } diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtilFactory.java b/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtilFactory.java index b69449a5f7..360334cbe1 100644 --- a/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtilFactory.java +++ b/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtilFactory.java @@ -19,23 +19,19 @@ package org.apache.poi.ss.excelant.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import org.apache.poi.ss.excelant.BuildFileTest; +import org.apache.poi.ss.excelant.TestBuildFile; import org.junit.Test; /** * Tests for the ExcelAntWorbookUtilFactory. - * - * @author Jon Svede (jon [at] loquatic [dot] com) - * @author Brian Bush (brian [dot] bush [at] nrel [dot] gov) - * */ public class TestExcelAntWorkbookUtilFactory { private static final String mortgageCalculatorWorkbookFile = - BuildFileTest.getDataDir() + "/spreadsheet/mortgage-calculation.xls" ; - - + TestBuildFile.getDataDir() + "/spreadsheet/mortgage-calculation.xls" ; + + /** * Simple test to determine if the factory properly returns an non-null * instance of the ExcelAntWorkbookUtil class. @@ -44,29 +40,29 @@ public class TestExcelAntWorkbookUtilFactory { public void testGetNewWorkbookUtilInstance() { ExcelAntWorkbookUtil util = ExcelAntWorkbookUtilFactory.getInstance( mortgageCalculatorWorkbookFile) ; - + assertNotNull(util) ; } - - + + /** * Test whether or not the factory will properly return the same reference * to an ExcelAnt WorkbookUtil when two different Strings, that point to - * the same resource, are passed in. + * the same resource, are passed in. */ @Test public void testVerifyEquivalence() { - String sameFileName = BuildFileTest.getDataDir() + "/spreadsheet/mortgage-calculation.xls" ; - + String sameFileName = TestBuildFile.getDataDir() + "/spreadsheet/mortgage-calculation.xls" ; + ExcelAntWorkbookUtil util = ExcelAntWorkbookUtilFactory.getInstance( mortgageCalculatorWorkbookFile) ; ExcelAntWorkbookUtil util2 = ExcelAntWorkbookUtilFactory.getInstance( sameFileName) ; - + assertNotNull(util) ; assertNotNull(util2) ; - + assertEquals(util, util2) ; } } diff --git a/src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java b/src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java index 95040905ed..c54b4f0c74 100644 --- a/src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java +++ b/src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java @@ -30,6 +30,7 @@ import org.apache.poi.hssf.record.StringRecord; import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor; import org.apache.poi.ss.formula.FormulaShifter; import org.apache.poi.ss.formula.ptg.Ptg; +import org.apache.poi.util.Removal; /** * @@ -357,6 +358,10 @@ public final class ValueRecordsAggregate implements Iterable - * + * * The maximum column width for an individual cell is 255 characters. * This value represents the number of characters that can be displayed * in a cell that is formatted with the standard font (first font in the workbook).

- * + * * Character width is defined as the maximum digit width * of the numbers 0, 1, 2, ... 9 as rendered * using the default font (first font in the workbook).

- * + * * Unless you are using a very special font, the default character is '0' (zero), * this is true for Arial (default font font in HSSF) and Calibri (default font in XSSF)

- * + * * Please note, that the width set by this method includes 4 pixels of margin padding (two on each side), * plus 1 pixel padding for the gridlines (Section 3.3.1.12 of the OOXML spec). * This results is a slightly less value of visible characters than passed to this method (approx. 1/2 of a character).

- * + * * To compute the actual number of visible characters, * Excel uses the following formula (Section 3.3.1.12 of the OOXML spec):

- * + * * * width = Truncate([{Number of Visible Characters} * * {Maximum Digit Width} + {5 pixel padding}]/{Maximum Digit Width}*256)/256 @@ -561,7 +561,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { return cw/px; } - + /** * get the default column width for the sheet (if the columns do not define their own width) in * characters @@ -730,7 +730,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { // throw IllegalStateException if the argument CellRangeAddress intersects with // a multi-cell array formula defined in this sheet validateArrayFormulas(region); - + // Throw IllegalStateException if the argument CellRangeAddress intersects with // a merged region already in this sheet validateMergedRegions(region); @@ -752,7 +752,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { for (int rowIn = firstRow; rowIn <= lastRow; rowIn++) { HSSFRow row = getRow(rowIn); if (row == null) continue; - + for (int colIn = firstColumn; colIn <= lastColumn; colIn++) { HSSFCell cell = row.getCell(colIn); if (cell == null) continue; @@ -814,11 +814,11 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { /** * Control if Excel should be asked to recalculate all formulas on this sheet * when the workbook is opened.

- * + * * Calculating the formula values with {@link org.apache.poi.ss.usermodel.FormulaEvaluator} is the * recommended solution, but this may be used for certain cases where * evaluation in POI is not possible.

- * + * * It is recommended to force recalcuation of formulas on workbook level using * {@link org.apache.poi.ss.usermodel.Workbook#setForceFormulaRecalculation(boolean)} * to ensure that all cross-worksheet formuals and external dependencies are updated. @@ -909,7 +909,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { public void removeMergedRegion(int index) { _sheet.removeMergedRegion(index); } - + /** * Removes a number of merged regions of cells (hence letting them free) * @@ -981,7 +981,8 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { * * @return Sheet - low level representation of this HSSFSheet. */ - /*package*/ InternalSheet getSheet() { + @Internal + public InternalSheet getSheet() { return _sheet; } @@ -1222,7 +1223,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { public void setPrintGridlines(boolean show) { getSheet().getPrintGridlines().setPrintGridlines(show); } - + /** * Returns whether row and column headings are printed. * @@ -1408,7 +1409,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { sclRecord.setDenominator((short) denominator); getSheet().setSCLRecord(sclRecord); } - + /** * Window zoom magnification for current view representing percent values. * Valid values range from 10 to 400. Horizontal & Vertical scale together. @@ -1464,7 +1465,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { public void showInPane(int topRow, int leftCol) { int maxrow = SpreadsheetVersion.EXCEL97.getLastRowIndex(); if (topRow > maxrow) throw new IllegalArgumentException("Maximum row number is " + maxrow); - + showInPane((short) topRow, (short) leftCol); } /** @@ -1478,10 +1479,10 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { _sheet.setTopRow(toprow); _sheet.setLeftCol(leftcol); } - + /** * Shifts, grows, or shrinks the merged regions due to a row shift - * + * * @param startRow the start-index of the rows to shift, zero-based * @param endRow the end-index of the rows to shift, zero-based * @param n how far to shift, negative to shift up @@ -1497,9 +1498,9 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { * Shifts rows between startRow and endRow n number of rows. * If you use a negative number, it will shift rows up. * Code ensures that rows don't wrap around.

- * + * * Calls {@code shiftRows(startRow, endRow, n, false, false);}

- * + * * Additionally shifts merged regions that are completely defined in these * rows (ie. merged 2 cells on a row to be shifted). * @@ -1516,11 +1517,11 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { * Shifts rows between startRow and endRow n number of rows. * If you use a negative number, it will shift rows up. * Code ensures that rows don't wrap around

- * + * * Additionally shifts merged regions that are completely defined in these * rows (ie. merged 2 cells on a row to be shifted). All merged regions that are * completely overlaid by shifting will be deleted.

- * + * * TODO Might want to add bounds checking here * * @param startRow the row to start shifting @@ -1533,7 +1534,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { public void shiftRows(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight) { shiftRows(startRow, endRow, n, copyRowHeight, resetOriginalRowHeight, true); } - + /** * bound a row number between 0 and last row index (65535) * @@ -1549,10 +1550,10 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { * Shifts rows between startRow and endRow n number of rows. * If you use a negative number, it will shift rows up. * Code ensures that rows don't wrap around

- * + * * Additionally shifts merged regions that are completely defined in these * rows (ie. merged 2 cells on a row to be shifted).

- * + * * TODO Might want to add bounds checking here * * @param startRow the row to start shifting @@ -1578,9 +1579,9 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { // Nothing to do return; } - + final RowShifter rowShifter = new HSSFRowShifter(this); - + // Move comments from the source row to the // destination row. Note that comments can // exist for cells which are null @@ -1594,10 +1595,10 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { // Shift Merged Regions rowShifter.shiftMergedRegions(startRow, endRow, n); - + // Shift Row Breaks _sheet.getPageSettings().shiftRowBreaks(startRow, endRow, n); - + // Delete overwritten hyperlinks deleteOverwrittenHyperlinksForRowShift(startRow, endRow, n); @@ -1747,30 +1748,30 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { } } } - + /** * Shifts columns in range [startColumn, endColumn] for n places to the right. * For n < 0, it will shift columns left. * Additionally adjusts formulas. - * Probably should also process other features (hyperlinks, comments...) in the way analog to shiftRows method + * Probably should also process other features (hyperlinks, comments...) in the way analog to shiftRows method * @param startColumn the column to start shifting * @param endColumn the column to end shifting * @param n the number of columns to shift */ @Beta @Override - public void shiftColumns(int startColumn, int endColumn, int n){ - HSSFColumnShifter columnShifter = new HSSFColumnShifter(this); - columnShifter.shiftColumns(startColumn, endColumn, n); - + public void shiftColumns(int startColumn, int endColumn, int n){ + HSSFColumnShifter columnShifter = new HSSFColumnShifter(this); + columnShifter.shiftColumns(startColumn, endColumn, n); + int sheetIndex = _workbook.getSheetIndex(this); short externSheetIndex = _book.checkExternSheet(sheetIndex); String sheetName = _workbook.getSheetName(sheetIndex); FormulaShifter formulaShifter = FormulaShifter.createForColumnShift( externSheetIndex, sheetName, startColumn, endColumn, n, SpreadsheetVersion.EXCEL97); - updateFormulasForShift(formulaShifter); - // add logic for hyperlinks etc, like in shiftRows() - } + updateFormulasForShift(formulaShifter); + // add logic for hyperlinks etc, like in shiftRows() + } protected void insertChartRecords(List records) { int window2Loc = _sheet.findFirstRecordLocBySid(WindowTwoRecord.sid); @@ -1790,7 +1791,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { /** * Creates a split (freezepane). Any existing freezepane or split pane is overwritten.

- * + * * If both colSplit and rowSplit are zero then the existing freeze pane is removed * * @param colSplit Horizonatal position of split. @@ -1811,7 +1812,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { /** * Creates a split (freezepane). Any existing freezepane or split pane is overwritten.

- * + * * If both colSplit and rowSplit are zero then the existing freeze pane is removed * * @param colSplit Horizonatal position of split. @@ -1914,7 +1915,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { /** * Sets a page break at the indicated row * Breaks occur above the specified row and left of the specified column inclusive.

- * + * * For example, sheet.setColumnBreak(2); breaks the sheet into two parts * with columns A,B,C in the first and D,E,... in the second. Simuilar, sheet.setRowBreak(2); * breaks the sheet into two parts with first three rows (rownum=1...3) in the first part @@ -1966,7 +1967,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { /** * Sets a page break at the indicated column. * Breaks occur above the specified row and left of the specified column inclusive.

- * + * * For example, sheet.setColumnBreak(2); breaks the sheet into two parts * with columns A,B,C in the first and D,E,... in the second. Simuilar, {@code sheet.setRowBreak(2);} * breaks the sheet into two parts with first three rows (rownum=1...3) in the first part @@ -2079,9 +2080,9 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { } /** - * Creates the top-level drawing patriarch. + * Creates the top-level drawing patriarch. *

This may then be used to add graphics or charts.

- *

Note that this will normally have the effect of removing + *

Note that this will normally have the effect of removing * any existing drawings on this sheet.

* * @return The new patriarch. @@ -2189,7 +2190,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { /** * Adjusts the column width to fit the contents.

- * + * * This process can be relatively slow on large sheets, so this should * normally only be called once per column, at the end of your * processing. @@ -2203,11 +2204,11 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { /** * Adjusts the column width to fit the contents.

- * + * * This process can be relatively slow on large sheets, so this should * normally only be called once per column, at the end of your * processing.

- * + * * You can specify whether the content of merged cells should be considered or ignored. * Default is to ignore merged cells. * @@ -2227,7 +2228,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { setColumnWidth(column, (int) (width)); } } - + /** * Returns cell comment for the specified row and column * @@ -2237,7 +2238,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { public HSSFComment getCellComment(CellAddress ref) { return findCellComment(ref.getRow(), ref.getColumn()); } - + /** * Get a Hyperlink in this sheet anchored at row, column * @@ -2257,7 +2258,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { } return null; } - + /** * Get a Hyperlink in this sheet located in a cell specified by {code addr} * @@ -2269,7 +2270,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { public HSSFHyperlink getHyperlink(CellAddress addr) { return getHyperlink(addr.getRow(), addr.getColumn()); } - + /** * Get a list of Hyperlinks in this sheet * @@ -2286,7 +2287,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { } return hyperlinkList; } - + /** * Remove the underlying HyperlinkRecord from this sheet. * If multiple HSSFHyperlinks refer to the same HyperlinkRecord, all HSSFHyperlinks will be removed. @@ -2296,7 +2297,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { protected void removeHyperlink(HSSFHyperlink link) { removeHyperlink(link.record); } - + /** * Remove the underlying HyperlinkRecord from this sheet * @@ -2415,7 +2416,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { } int firstRow = range.getFirstRow(); - + // if row was not given when constructing the range... if(firstRow == -1) { firstRow = 0; @@ -2485,7 +2486,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { if (null == patriarch) { patriarch = createDrawingPatriarch(); } - + Map locations = new TreeMap<>(); findCellCommentLocations(patriarch, locations); return locations; @@ -2663,7 +2664,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { } return _workbook.getNameRecord(recIndex); } - + /** * Returns the column outline level. Increased as you * put it into more groups (outlines), reduced as diff --git a/src/ooxml/testcases/org/apache/poi/TestEmbedded.java b/src/ooxml/testcases/org/apache/poi/TestEmbedded.java index c50c22f38e..26ba8067a3 100644 --- a/src/ooxml/testcases/org/apache/poi/TestEmbedded.java +++ b/src/ooxml/testcases/org/apache/poi/TestEmbedded.java @@ -15,26 +15,28 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import org.apache.poi.ooxml.POIXMLDocument; +import org.apache.poi.openxml4j.opc.OPCPackage; +import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.util.IOUtils; import org.apache.poi.xslf.usermodel.XSLFSlideShow; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xwpf.usermodel.XWPFDocument; -import org.apache.poi.openxml4j.opc.OPCPackage; -import org.apache.poi.openxml4j.opc.PackagePart; - -import junit.framework.TestCase; +import org.junit.Test; /** - * Class to test that we handle embeded bits in - * OOXML files properly + * Class to test that we handle embeded bits in OOXML files properly */ -public class TestEmbedded extends TestCase -{ +public class TestEmbedded { + @Test public void testExcel() throws Exception { POIXMLDocument doc = new XSSFWorkbook( POIDataSamples.getSpreadSheetInstance().openResourceAsStream("ExcelWithAttachments.xlsm") @@ -42,6 +44,7 @@ public class TestEmbedded extends TestCase test(doc, 4); } + @Test public void testWord() throws Exception { POIXMLDocument doc = new XWPFDocument( POIDataSamples.getDocumentInstance().openResourceAsStream("WordWithAttachments.docx") @@ -49,13 +52,14 @@ public class TestEmbedded extends TestCase test(doc, 5); } + @Test public void testPowerPoint() throws Exception { POIXMLDocument doc = new XSLFSlideShow(OPCPackage.open( POIDataSamples.getSlideShowInstance().openResourceAsStream("PPTWithAttachments.pptm")) ); test(doc, 4); } - + private void test(POIXMLDocument doc, int expectedCount) throws Exception { assertNotNull(doc.getAllEmbeddedParts()); assertEquals(expectedCount, doc.getAllEmbeddedParts().size()); @@ -63,7 +67,7 @@ public class TestEmbedded extends TestCase for(int i=0; i 0); } diff --git a/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java b/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java index ce0e3c7565..7186d64e70 100644 --- a/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java +++ b/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java @@ -17,20 +17,23 @@ package org.apache.poi; import static org.apache.poi.POITestCase.assertContains; - -import junit.framework.TestCase; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import org.apache.poi.ooxml.extractor.POIXMLPropertiesTextExtractor; -import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.ooxml.util.PackageHelper; +import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.xslf.usermodel.XSLFSlideShow; import org.apache.poi.xssf.extractor.XSSFExcelExtractor; import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.junit.Test; -public final class TestXMLPropertiesTextExtractor extends TestCase { +public final class TestXMLPropertiesTextExtractor { private static final POIDataSamples _ssSamples = POIDataSamples.getSpreadSheetInstance(); private static final POIDataSamples _slSamples = POIDataSamples.getSlideShowInstance(); + @Test public void testGetFromMainExtractor() throws Exception { OPCPackage pkg = PackageHelper.open(_ssSamples.openResourceAsStream("ExcelWithAttachments.xlsm")); @@ -49,11 +52,12 @@ public final class TestXMLPropertiesTextExtractor extends TestCase { assertContains(text, "LastModifiedBy = Yury Batrakov"); assertContains(cText, "LastModifiedBy = Yury Batrakov"); - + textExt.close(); ext.close(); } + @Test public void testCore() throws Exception { OPCPackage pkg = PackageHelper.open( _ssSamples.openResourceAsStream("ExcelWithAttachments.xlsm") @@ -69,10 +73,11 @@ public final class TestXMLPropertiesTextExtractor extends TestCase { assertContains(text, "LastModifiedBy = Yury Batrakov"); assertContains(cText, "LastModifiedBy = Yury Batrakov"); - + ext.close(); } + @Test public void testExtended() throws Exception { OPCPackage pkg = OPCPackage.open( _ssSamples.openResourceAsStream("ExcelWithAttachments.xlsm") @@ -94,6 +99,7 @@ public final class TestXMLPropertiesTextExtractor extends TestCase { ext.close(); } + @Test public void testCustom() throws Exception { OPCPackage pkg = OPCPackage.open( _ssSamples.openResourceAsStream("ExcelWithAttachments.xlsm") @@ -106,31 +112,32 @@ public final class TestXMLPropertiesTextExtractor extends TestCase { // Now check String text = ext.getText(); String cText = ext.getCustomPropertiesText(); - + assertContains(text, "description = another value"); assertContains(cText, "description = another value"); ext.close(); } - + /** * Bug #49386 - some properties, especially * dates can be null */ + @Test public void testWithSomeNulls() throws Exception { OPCPackage pkg = OPCPackage.open( _slSamples.openResourceAsStream("49386-null_dates.pptx") ); XSLFSlideShow sl = new XSLFSlideShow(pkg); - + POIXMLPropertiesTextExtractor ext = new POIXMLPropertiesTextExtractor(sl); ext.getText(); - + String text = ext.getText(); assertFalse(text.contains("Created =")); // With date is null assertContains(text, "CreatedString = "); // Via string is blank assertContains(text, "LastModifiedBy = IT Client Services"); - + ext.close(); } } diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestListParts.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestListParts.java index f0e9e19997..88d45f75de 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestListParts.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestListParts.java @@ -17,26 +17,29 @@ package org.apache.poi.openxml4j.opc; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import java.io.IOException; import java.io.InputStream; import java.util.TreeMap; -import junit.framework.TestCase; - import org.apache.poi.openxml4j.OpenXML4JTestDataSamples; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; -import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; +import org.junit.Before; +import org.junit.Test; -public final class TestListParts extends TestCase { +public final class TestListParts { private static final POILogger logger = POILogFactory.getLogger(TestListParts.class); private TreeMap expectedValues; private TreeMap values; - @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { values = new TreeMap<>(); // Expected values @@ -81,21 +84,21 @@ public final class TestListParts extends TestCase { /** * List all parts of a package. */ + @Test public void testListParts() throws InvalidFormatException, IOException { - InputStream is = OpenXML4JTestDataSamples.openSampleStream("sample.docx"); + try (InputStream is = OpenXML4JTestDataSamples.openSampleStream("sample.docx"); + OPCPackage p = OPCPackage.open(is)) { - OPCPackage p = OPCPackage.open(is); - for (PackagePart part : p.getParts()) { - values.put(part.getPartName(), part.getContentType()); - logger.log(POILogger.DEBUG, part.getPartName()); + for (PackagePart part : p.getParts()) { + values.put(part.getPartName(), part.getContentType()); + logger.log(POILogger.DEBUG, part.getPartName()); + } + + // Compare expected values with values return by the package + for (PackagePartName partName : expectedValues.keySet()) { + assertNotNull(values.get(partName)); + assertEquals(expectedValues.get(partName), values.get(partName)); + } } - - // Compare expected values with values return by the package - for (PackagePartName partName : expectedValues.keySet()) { - assertNotNull(values.get(partName)); - assertEquals(expectedValues.get(partName), values.get(partName)); - } - - p.close(); } } diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagePartName.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagePartName.java index 65642fcebe..bb900b1e5c 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagePartName.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagePartName.java @@ -17,13 +17,16 @@ package org.apache.poi.openxml4j.opc; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; -public final class TestPackagePartName extends TestCase { +import org.junit.Test; + +public final class TestPackagePartName { /** * Test method getExtension(). */ + @Test public void testGetExtension() throws Exception{ PackagePartName name1 = PackagingURIHelper.createPartName("/doc/props/document.xml"); PackagePartName name2 = PackagingURIHelper.createPartName("/root/document"); diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageThumbnail.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageThumbnail.java index 432bd896c9..e9295970cd 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageThumbnail.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageThumbnail.java @@ -17,22 +17,23 @@ package org.apache.poi.openxml4j.opc; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.File; -import junit.framework.TestCase; - import org.apache.poi.openxml4j.OpenXML4JTestDataSamples; +import org.junit.Test; /** * Test the addition of thumbnail in a package. - * - * @author Julien Chable */ -public final class TestPackageThumbnail extends TestCase { +public final class TestPackageThumbnail { /** * Test package addThumbnail() method. */ + @Test public void testSetProperties() throws Exception { String inputPath = OpenXML4JTestDataSamples.getSampleFileName("TestPackageThumbnail.docx"); @@ -46,7 +47,7 @@ public final class TestPackageThumbnail extends TestCase { p.addThumbnail(imagePath); // Save the package in the output directory p.save(outputFile); - + // Open the newly created file to check core properties saved values. OPCPackage p2 = OPCPackage.open(outputFile.getAbsolutePath(), PackageAccess.READ); try { @@ -59,7 +60,7 @@ public final class TestPackageThumbnail extends TestCase { } } finally { p.revert(); - outputFile.delete(); + assertTrue(outputFile.delete()); } } } diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java index 08081e711b..9969187422 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java @@ -16,18 +16,20 @@ ==================================================================== */ package org.apache.poi.openxml4j.opc; -import java.net.URI; -import java.net.URISyntaxException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; -import junit.framework.TestCase; +import java.net.URI; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; +import org.junit.Test; -public class TestPackagingURIHelper extends TestCase { +public class TestPackagingURIHelper { /** * Test relativizePartName() method. */ + @Test public void testRelativizeURI() throws Exception { URI uri1 = new URI("/word/document.xml"); URI uri2 = new URI("/word/media/image1.gif"); @@ -60,18 +62,23 @@ public class TestPackagingURIHelper extends TestCase { //URI compatible with MS Office and OpenOffice: leading slash is removed uriRes = PackagingURIHelper.relativizeURI(root, uri1, true); + assertNotNull(uriRes); assertEquals("word/document.xml", uriRes.toString()); //preserve URI fragments uriRes = PackagingURIHelper.relativizeURI(uri1, uri3, true); + assertNotNull(uriRes); assertEquals("media/image1.gif#Sheet1!A1", uriRes.toString()); + assertNotNull(uriRes); uriRes = PackagingURIHelper.relativizeURI(root, uri4, true); + assertNotNull(uriRes); assertEquals("#'My%20Sheet1'!A1", uriRes.toString()); } /** * Test createPartName(String, y) */ + @Test public void testCreatePartNameRelativeString() throws InvalidFormatException { PackagePartName partNameToValid = PackagingURIHelper @@ -93,6 +100,7 @@ public class TestPackagingURIHelper extends TestCase { /** * Test createPartName(URI, y) */ + @Test public void testCreatePartNameRelativeURI() throws Exception { PackagePartName partNameToValid = PackagingURIHelper .createPartName("/word/media/image1.gif"); @@ -110,6 +118,7 @@ public class TestPackagingURIHelper extends TestCase { pkg.revert(); } + @Test public void testCreateURIFromString() throws Exception { String[] href = { "..\\\\\\cygwin\\home\\yegor\\.vim\\filetype.vim", @@ -120,15 +129,14 @@ public class TestPackagingURIHelper extends TestCase { "#'性'!B21", "javascript://" }; + for(String s : href){ - try { - URI uri = PackagingURIHelper.toURI(s); - } catch (URISyntaxException e){ - fail("Failed to create URI from " + s); - } + URI uri = PackagingURIHelper.toURI(s); + assertNotNull(uri); } } + @Test public void test53734() throws Exception { URI uri = PackagingURIHelper.toURI("javascript://"); // POI appends a trailing slash tpo avoid "Expected authority at index 13: javascript://" diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java index a9b7d52c12..843c049ca7 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java @@ -17,7 +17,12 @@ package org.apache.poi.openxml4j.opc; +import static org.apache.poi.openxml4j.OpenXML4JTestDataSamples.openSampleStream; import static org.apache.poi.openxml4j.opc.TestContentType.isOldXercesActive; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -25,14 +30,13 @@ import java.io.InputStream; import java.net.URI; import java.util.regex.Pattern; -import junit.framework.TestCase; - import org.apache.poi.openxml4j.OpenXML4JTestDataSamples; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; +import org.junit.Test; -public class TestRelationships extends TestCase { +public class TestRelationships { private static final String HYPERLINK_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"; private static final String COMMENTS_REL_TYPE = @@ -48,8 +52,9 @@ public class TestRelationships extends TestCase { * The code in this case assumes there are no relationships defined, but it should * really look also for not yet loaded parts. */ + @Test public void testLoadRelationships() throws Exception { - InputStream is = OpenXML4JTestDataSamples.openSampleStream("sample.xlsx"); + InputStream is = openSampleStream("sample.xlsx"); try (OPCPackage pkg = OPCPackage.open(is)) { logger.log(POILogger.DEBUG, "1: " + pkg); PackageRelationshipCollection rels = pkg.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT); @@ -65,13 +70,14 @@ public class TestRelationships extends TestCase { } } } - + /** * Checks that we can fetch a collection of relations by * type, then grab from within there by id */ + @Test public void testFetchFromCollection() throws Exception { - InputStream is = OpenXML4JTestDataSamples.openSampleStream("ExcelWithHyperlinks.xlsx"); + InputStream is = openSampleStream("ExcelWithHyperlinks.xlsx"); try (OPCPackage pkg = OPCPackage.open(is)) { PackagePart sheet = pkg.getPart( PackagingURIHelper.createPartName(SHEET_WITH_COMMENTS)); @@ -107,13 +113,14 @@ public class TestRelationships extends TestCase { assertNotNull(sheet.getRelationship("rId6")); } } - + /** - * Excel uses relations on sheets to store the details of + * Excel uses relations on sheets to store the details of * external hyperlinks. Check we can load these ok. */ + @Test public void testLoadExcelHyperlinkRelations() throws Exception { - InputStream is = OpenXML4JTestDataSamples.openSampleStream("ExcelWithHyperlinks.xlsx"); + InputStream is = openSampleStream("ExcelWithHyperlinks.xlsx"); try (OPCPackage pkg = OPCPackage.open(is)) { PackagePart sheet = pkg.getPart( PackagingURIHelper.createPartName(SHEET_WITH_COMMENTS)); @@ -141,21 +148,22 @@ public class TestRelationships extends TestCase { assertEquals("mailto:dev@poi.apache.org?subject=XSSF%20Hyperlinks", mailto.getTargetURI().toString()); } } - + /* - * Excel uses relations on sheets to store the details of - * external hyperlinks. Check we can create these OK, + * Excel uses relations on sheets to store the details of + * external hyperlinks. Check we can create these OK, * then still read them later */ + @Test public void testCreateExcelHyperlinkRelations() throws Exception { String filepath = OpenXML4JTestDataSamples.getSampleFileName("ExcelWithHyperlinks.xlsx"); OPCPackage pkg = OPCPackage.open(filepath, PackageAccess.READ_WRITE); PackagePart sheet = pkg.getPart( PackagingURIHelper.createPartName(SHEET_WITH_COMMENTS)); assertNotNull(sheet); - + assertEquals(3, sheet.getRelationshipsByType(HYPERLINK_REL_TYPE).size()); - + // Add three new ones PackageRelationship openxml4j = sheet.addExternalRelationship("http://www.openxml4j.org/", HYPERLINK_REL_TYPE); @@ -163,53 +171,53 @@ public class TestRelationships extends TestCase { sheet.addExternalRelationship("http://openxml4j.sf.net/", HYPERLINK_REL_TYPE); PackageRelationship file = sheet.addExternalRelationship("MyDocument.docx", HYPERLINK_REL_TYPE); - + // Check they were added properly assertNotNull(openxml4j); assertNotNull(sf); assertNotNull(file); - + assertEquals(6, sheet.getRelationshipsByType(HYPERLINK_REL_TYPE).size()); - + assertEquals("http://www.openxml4j.org/", openxml4j.getTargetURI().toString()); assertEquals("/xl/worksheets/sheet1.xml", openxml4j.getSourceURI().toString()); assertEquals(HYPERLINK_REL_TYPE, openxml4j.getRelationshipType()); - + assertEquals("http://openxml4j.sf.net/", sf.getTargetURI().toString()); assertEquals("/xl/worksheets/sheet1.xml", sf.getSourceURI().toString()); assertEquals(HYPERLINK_REL_TYPE, sf.getRelationshipType()); - + assertEquals("MyDocument.docx", file.getTargetURI().toString()); assertEquals("/xl/worksheets/sheet1.xml", file.getSourceURI().toString()); assertEquals(HYPERLINK_REL_TYPE, file.getRelationshipType()); - + // Will get ids 7, 8 and 9, as we already have 1-6 assertEquals("rId7", openxml4j.getId()); assertEquals("rId8", sf.getId()); assertEquals("rId9", file.getId()); - - + + // Write out and re-load ByteArrayOutputStream baos = new ByteArrayOutputStream(); pkg.save(baos); - + // use revert to not re-write the input file pkg.revert(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); pkg = OPCPackage.open(bais); - + // Check again sheet = pkg.getPart( PackagingURIHelper.createPartName(SHEET_WITH_COMMENTS)); - + assertEquals(6, sheet.getRelationshipsByType(HYPERLINK_REL_TYPE).size()); - + assertEquals("http://poi.apache.org/", sheet.getRelationship("rId1").getTargetURI().toString()); assertEquals("mailto:dev@poi.apache.org?subject=XSSF%20Hyperlinks", sheet.getRelationship("rId3").getTargetURI().toString()); - + assertEquals("http://www.openxml4j.org/", sheet.getRelationship("rId7").getTargetURI().toString()); assertEquals("http://openxml4j.sf.net/", @@ -218,6 +226,7 @@ public class TestRelationships extends TestCase { sheet.getRelationship("rId9").getTargetURI().toString()); } + @Test public void testCreateRelationsFromScratch() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); OPCPackage pkg = OPCPackage.create(baos); @@ -286,6 +295,7 @@ public class TestRelationships extends TestCase { partB.getRelationship("rId3").getTargetURI().toString()); } + @Test public void testTargetWithSpecialChars() throws Exception{ OPCPackage pkg; @@ -305,7 +315,7 @@ public class TestRelationships extends TestCase { assert_50154(pkg); } - public void assert_50154(OPCPackage pkg) throws Exception { + private void assert_50154(OPCPackage pkg) throws Exception { URI drawingURI = new URI("/xl/drawings/drawing1.xml"); PackagePart drawingPart = pkg.getPart(PackagingURIHelper.createPartName(drawingURI)); PackageRelationshipCollection drawingRels = drawingPart.getRelationships(); @@ -347,83 +357,89 @@ public class TestRelationships extends TestCase { assertEquals("'\u0410\u043F\u0430\u0447\u0435 \u041F\u041E\u0418'!A5", rel6.getFragment()); } + @Test public void testSelfRelations_bug51187() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OPCPackage pkg = OPCPackage.create(baos); + PackageRelationship rel1; + try (OPCPackage pkg = OPCPackage.create(baos)) { - PackagePart partA = - pkg.createPart(PackagingURIHelper.createPartName("/partA"), "text/plain"); - assertNotNull(partA); + PackagePart partA = + pkg.createPart(PackagingURIHelper.createPartName("/partA"), "text/plain"); + assertNotNull(partA); - // reference itself - PackageRelationship rel1 = partA.addRelationship(partA.getPartName(), TargetMode.INTERNAL, "partA"); - - - // Save, and re-load - pkg.close(); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - pkg = OPCPackage.open(bais); - - partA = pkg.getPart(PackagingURIHelper.createPartName("/partA")); + // reference itself + rel1 = partA.addRelationship(partA.getPartName(), TargetMode.INTERNAL, "partA"); - // Check the relations - assertEquals(1, partA.getRelationships().size()); - - PackageRelationship rel2 = partA.getRelationships().getRelationship(0); - - assertNotNull(rel2); - assertEquals(rel1.getRelationshipType(), rel2.getRelationshipType()); - assertEquals(rel1.getId(), rel2.getId()); - assertEquals(rel1.getSourceURI(), rel2.getSourceURI()); - assertEquals(rel1.getTargetURI(), rel2.getTargetURI()); - assertEquals(rel1.getTargetMode(), rel2.getTargetMode()); - } - - public void testTrailingSpacesInURI_53282() throws Exception { - InputStream is = OpenXML4JTestDataSamples.openSampleStream("53282.xlsx"); - OPCPackage pkg = OPCPackage.open(is); - is.close(); - - PackageRelationshipCollection sheetRels = pkg.getPartsByName(Pattern.compile("/xl/worksheets/sheet1.xml")).get(0).getRelationships(); - assertEquals(3, sheetRels.size()); - PackageRelationship rId1 = sheetRels.getRelationshipByID("rId1"); - assertEquals(TargetMode.EXTERNAL, rId1.getTargetMode()); - URI targetUri = rId1.getTargetURI(); - assertEquals("mailto:nobody@nowhere.uk%C2%A0", targetUri.toASCIIString()); - assertEquals("nobody@nowhere.uk\u00A0", targetUri.getSchemeSpecificPart()); - - ByteArrayOutputStream out = new ByteArrayOutputStream(); - pkg.save(out); - out.close(); - - pkg = OPCPackage.open(new ByteArrayInputStream(out.toByteArray())); - sheetRels = pkg.getPartsByName(Pattern.compile("/xl/worksheets/sheet1.xml")).get(0).getRelationships(); - assertEquals(3, sheetRels.size()); - rId1 = sheetRels.getRelationshipByID("rId1"); - assertEquals(TargetMode.EXTERNAL, rId1.getTargetMode()); - targetUri = rId1.getTargetURI(); - assertEquals("mailto:nobody@nowhere.uk%C2%A0", targetUri.toASCIIString()); - assertEquals("nobody@nowhere.uk\u00A0", targetUri.getSchemeSpecificPart()); - } - - public void testEntitiesInRels_56164() throws Exception { - InputStream is = OpenXML4JTestDataSamples.openSampleStream("PackageRelsHasEntities.ooxml"); - OPCPackage p = OPCPackage.open(is); - is.close(); - - // Should have 3 root relationships - boolean foundDocRel = false, foundCorePropRel = false, foundExtPropRel = false; - for (PackageRelationship pr : p.getRelationships()) { - if (pr.getRelationshipType().equals(PackageRelationshipTypes.CORE_DOCUMENT)) - foundDocRel = true; - if (pr.getRelationshipType().equals(PackageRelationshipTypes.CORE_PROPERTIES)) - foundCorePropRel = true; - if (pr.getRelationshipType().equals(PackageRelationshipTypes.EXTENDED_PROPERTIES)) - foundExtPropRel = true; + // Save, and re-load + } + + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + try (OPCPackage pkg = OPCPackage.open(bais)) { + PackagePart partA = pkg.getPart(PackagingURIHelper.createPartName("/partA")); + + + // Check the relations + assertEquals(1, partA.getRelationships().size()); + + PackageRelationship rel2 = partA.getRelationships().getRelationship(0); + + assertNotNull(rel2); + assertEquals(rel1.getRelationshipType(), rel2.getRelationshipType()); + assertEquals(rel1.getId(), rel2.getId()); + assertEquals(rel1.getSourceURI(), rel2.getSourceURI()); + assertEquals(rel1.getTargetURI(), rel2.getTargetURI()); + assertEquals(rel1.getTargetMode(), rel2.getTargetMode()); + } + } + + @Test + public void testTrailingSpacesInURI_53282() throws Exception { + try (InputStream is = openSampleStream("53282.xlsx"); + OPCPackage pkg1 = OPCPackage.open(is)) { + + PackageRelationshipCollection sheetRels = pkg1.getPartsByName(Pattern.compile("/xl/worksheets/sheet1.xml")).get(0).getRelationships(); + assertEquals(3, sheetRels.size()); + PackageRelationship rId1 = sheetRels.getRelationshipByID("rId1"); + assertEquals(TargetMode.EXTERNAL, rId1.getTargetMode()); + URI targetUri = rId1.getTargetURI(); + assertEquals("mailto:nobody@nowhere.uk%C2%A0", targetUri.toASCIIString()); + assertEquals("nobody@nowhere.uk\u00A0", targetUri.getSchemeSpecificPart()); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + pkg1.save(out); + out.close(); + + try (OPCPackage pkg2 = OPCPackage.open(new ByteArrayInputStream(out.toByteArray()))) { + sheetRels = pkg2.getPartsByName(Pattern.compile("/xl/worksheets/sheet1.xml")).get(0).getRelationships(); + assertEquals(3, sheetRels.size()); + rId1 = sheetRels.getRelationshipByID("rId1"); + assertEquals(TargetMode.EXTERNAL, rId1.getTargetMode()); + targetUri = rId1.getTargetURI(); + assertEquals("mailto:nobody@nowhere.uk%C2%A0", targetUri.toASCIIString()); + assertEquals("nobody@nowhere.uk\u00A0", targetUri.getSchemeSpecificPart()); + } + } + } + + @Test + public void testEntitiesInRels_56164() throws Exception { + try (InputStream is = openSampleStream("PackageRelsHasEntities.ooxml"); + OPCPackage p = OPCPackage.open(is)) { + + // Should have 3 root relationships + boolean foundDocRel = false, foundCorePropRel = false, foundExtPropRel = false; + for (PackageRelationship pr : p.getRelationships()) { + if (pr.getRelationshipType().equals(PackageRelationshipTypes.CORE_DOCUMENT)) + foundDocRel = true; + if (pr.getRelationshipType().equals(PackageRelationshipTypes.CORE_PROPERTIES)) + foundCorePropRel = true; + if (pr.getRelationshipType().equals(PackageRelationshipTypes.EXTENDED_PROPERTIES)) + foundExtPropRel = true; + } + assertEquals("Core/Doc Relationship not found in " + p.getRelationships(), isOldXercesActive(), foundDocRel); + assertEquals("Core Props Relationship not found in " + p.getRelationships(), isOldXercesActive(), foundCorePropRel); + assertEquals("Ext Props Relationship not found in " + p.getRelationships(), isOldXercesActive(), foundExtPropRel); } - assertEquals("Core/Doc Relationship not found in " + p.getRelationships(), isOldXercesActive(), foundDocRel); - assertEquals("Core Props Relationship not found in " + p.getRelationships(), isOldXercesActive(), foundCorePropRel); - assertEquals("Ext Props Relationship not found in " + p.getRelationships(), isOldXercesActive(), foundExtPropRel); } } diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/ZipFileAssert.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/ZipFileAssert.java index 56f4a9baec..3a17b79851 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/ZipFileAssert.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/ZipFileAssert.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; @@ -43,8 +44,6 @@ import org.xmlunit.diff.Diff; import org.xmlunit.diff.DifferenceEvaluator; import org.xmlunit.diff.ElementSelectors; -import junit.framework.AssertionFailedError; - /** * Compare the contents of 2 zip files. */ @@ -140,7 +139,7 @@ public final class ZipFileAssert { TreeMap file2 = decompress(actual); equals(file1, file2); } catch (IOException e) { - throw new AssertionFailedError(e.toString()); + fail(e.toString()); } } diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java index dc0bff3201..216d577beb 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java @@ -17,6 +17,14 @@ package org.apache.poi.openxml4j.opc.compliance; +import static org.apache.poi.openxml4j.OpenXML4JTestDataSamples.openComplianceSampleStream; +import static org.apache.poi.openxml4j.OpenXML4JTestDataSamples.openSampleStream; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -27,7 +35,6 @@ import java.net.URI; import java.net.URISyntaxException; import org.apache.poi.POIDataSamples; -import org.apache.poi.openxml4j.OpenXML4JTestDataSamples; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidOperationException; import org.apache.poi.openxml4j.opc.ContentTypes; @@ -39,41 +46,35 @@ import org.apache.poi.util.IOUtils; import org.apache.poi.util.TempFile; import org.junit.Test; -import junit.framework.AssertionFailedError; - -import static org.junit.Assert.*; - /** * Test core properties Open Packaging Convention compliance. - * + * * M4.1: The format designer shall specify and the format producer shall create * at most one core properties relationship for a package. A format consumer * shall consider more than one core properties relationship for a package to be * an error. If present, the relationship shall target the Core Properties part. * (POI relaxes this on reading, as Office sometimes breaks this) - * + * * M4.2: The format designer shall not specify and the format producer shall not * create Core Properties that use the Markup Compatibility namespace as defined * in Annex F, "Standard Namespaces and Content Types". A format consumer shall * consider the use of the Markup Compatibility namespace to be an error. - * + * * M4.3: Producers shall not create a document element that contains refinements * to the Dublin Core elements, except for the two specified in the schema: * and Consumers shall consider a document * element that violates this constraint to be an error. - * + * * M4.4: Producers shall not create a document element that contains the * xml:lang attribute. Consumers shall consider a document element that violates * this constraint to be an error. - * + * * M4.5: Producers shall not create a document element that contains the * xsi:type attribute, except for a or * element where the xsi:type attribute shall be present and shall hold the * value dcterms:W3CDTF, where dcterms is the namespace prefix of the Dublin * Core namespace. Consumers shall consider a document element that violates * this constraint to be an error. - * - * @author Julien Chable */ public final class TestOPCComplianceCoreProperties { @@ -81,7 +82,7 @@ public final class TestOPCComplianceCoreProperties { public void testCorePropertiesPart() { OPCPackage pkg; try { - InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx"); + InputStream is = openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx"); pkg = OPCPackage.open(is); } catch (InvalidFormatException | IOException e) { throw new RuntimeException(e); @@ -90,7 +91,7 @@ public final class TestOPCComplianceCoreProperties { } private static String extractInvalidFormatMessage(String sampleNameSuffix) { - InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_" + sampleNameSuffix); + InputStream is = openComplianceSampleStream("OPCCompliance_CoreProperties_" + sampleNameSuffix); OPCPackage pkg; try { pkg = OPCPackage.open(is); @@ -101,25 +102,27 @@ public final class TestOPCComplianceCoreProperties { throw new RuntimeException(e); } pkg.revert(); - throw new AssertionFailedError("expected OPC compliance exception was not thrown"); + fail("expected OPC compliance exception was not thrown"); + return null; } - + /** * Test M4.1 rule. */ @Test public void testOnlyOneCorePropertiesPart() throws Exception { // We have relaxed this check, so we can read the file anyway - try { - extractInvalidFormatMessage("OnlyOneCorePropertiesPartFAIL.docx"); - fail("M4.1 should be being relaxed"); - } catch (AssertionFailedError e) { - // expected here - } - + try (InputStream is = openSampleStream("OPCCompliance_CoreProperties_" + "OnlyOneCorePropertiesPartFAIL.docx"); + OPCPackage pkg = OPCPackage.open(is)) { + assertNotNull(pkg); + } catch (Exception e) { + fail("M4.1 should be being relaxed"); + } + // We will use the first core properties, and ignore the others - InputStream is = OpenXML4JTestDataSamples.openSampleStream("MultipleCoreProperties.docx"); - try (OPCPackage pkg = OPCPackage.open(is)) { + + try (InputStream is = openSampleStream("MultipleCoreProperties.docx"); + OPCPackage pkg = OPCPackage.open(is)) { // We can see 2 by type assertEquals(2, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size()); @@ -132,7 +135,7 @@ public final class TestOPCComplianceCoreProperties { ); } } - + private static URI createURI(String text) { try { return new URI(text); @@ -146,7 +149,7 @@ public final class TestOPCComplianceCoreProperties { */ @Test public void testOnlyOneCorePropertiesPart_AddRelationship() { - InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx"); + InputStream is = openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx"); OPCPackage pkg; try { pkg = OPCPackage.open(is); @@ -233,7 +236,7 @@ public final class TestOPCComplianceCoreProperties { String msg = extractInvalidFormatMessage("LimitedXSITypeAttribute_PresentWithUnauthorizedValueFAIL.docx"); assertEquals("The element 'modified' must have the 'xsi:type' attribute with the value 'dcterms:W3CDTF', but had 'W3CDTF' !", msg); } - + /** * Document with no core properties - testing at the OPC level, * saving into a new stream @@ -263,10 +266,10 @@ public final class TestOPCComplianceCoreProperties { assertNotNull(pkg.getPackageProperties().getLanguageProperty()); assertFalse(pkg.getPackageProperties().getLanguageProperty().isPresent()); pkg.close(); - + // Open a new copy of it pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath()); - + // Save and re-load, without having touched the properties yet baos = new ByteArrayOutputStream(); pkg.save(baos); @@ -274,7 +277,7 @@ public final class TestOPCComplianceCoreProperties { bais = new ByteArrayInputStream(baos.toByteArray()); pkg = OPCPackage.open(bais); - + // Check that this too added empty properties without error assertEquals(1, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size()); assertNotNull(pkg.getPackageProperties()); diff --git a/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java b/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java index 2296b6a4a9..89fdb5247f 100644 --- a/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java +++ b/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java @@ -17,6 +17,9 @@ package org.apache.poi.ss.formula.functions; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.formula.eval.StringEval; @@ -29,13 +32,8 @@ import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator; import org.apache.poi.xssf.usermodel.XSSFWorkbook; - -import junit.framework.AssertionFailedError; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public final class TestProper { private Cell cell11; private FormulaEvaluator evaluator; @@ -70,16 +68,16 @@ public final class TestProper { confirm("PROPER(\"/&%\")", "/&%"); //nothing happens with ascii punctuation that is not upper or lower case confirm("PROPER(\"Apache POI\")", "Apache Poi"); //acronyms are not special confirm("PROPER(\" hello world\")", " Hello World"); //leading whitespace is ignored - + final String scharfes = "\u00df"; //German lowercase eszett, scharfes s, sharp s confirm("PROPER(\"stra"+scharfes+"e\")", "Stra"+scharfes+"e"); assertTrue(Character.isLetter(scharfes.charAt(0))); - + // CURRENTLY FAILS: result: "SSUnd"+scharfes // LibreOffice 5.0.3.2 behavior: "Sund"+scharfes // Excel 2013 behavior: ??? confirm("PROPER(\""+scharfes+"und"+scharfes+"\")", "SSund"+scharfes); - + // also test longer string StringBuilder builder = new StringBuilder("A"); StringBuilder expected = new StringBuilder("A"); @@ -94,9 +92,7 @@ public final class TestProper { cell11.setCellFormula(formulaText); evaluator.clearAllCachedResultValues(); CellValue cv = evaluator.evaluate(cell11); - if (cv.getCellType() != CellType.STRING) { - throw new AssertionFailedError("Wrong result type: " + cv.formatAsString()); - } + assertEquals("Wrong result type", CellType.STRING, cv.getCellType()); String actualValue = cv.getStringValue(); assertEquals(expectedResult, actualValue); } diff --git a/src/ooxml/testcases/org/apache/poi/util/TestIdentifierManager.java b/src/ooxml/testcases/org/apache/poi/util/TestIdentifierManager.java index 20a7b5f1d1..8b7b6dc759 100644 --- a/src/ooxml/testcases/org/apache/poi/util/TestIdentifierManager.java +++ b/src/ooxml/testcases/org/apache/poi/util/TestIdentifierManager.java @@ -16,11 +16,18 @@ ==================================================================== */ package org.apache.poi.util; -import junit.framework.TestCase; -import org.apache.poi.ooxml.util.IdentifierManager; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; -public class TestIdentifierManager extends TestCase -{ +import org.apache.poi.ooxml.util.IdentifierManager; +import org.junit.Test; + +public class TestIdentifierManager { + @Test public void testBasic() { IdentifierManager manager = new IdentifierManager(0L,100L); @@ -31,8 +38,8 @@ public class TestIdentifierManager extends TestCase assertEquals(99L,manager.getRemainingIdentifiers()); } - public void testLongLimits() - { + @Test + public void testLongLimits() { long min = IdentifierManager.MIN_ID; long max = IdentifierManager.MAX_ID; IdentifierManager manager = new IdentifierManager(min,max); @@ -44,53 +51,44 @@ public class TestIdentifierManager extends TestCase manager.release(max); manager.release(min); } - - public void testReserve() - { + + @Test + public void testReserve() { IdentifierManager manager = new IdentifierManager(10L,30L); assertEquals(12L,manager.reserve(12L)); long reserve = manager.reserve(12L); - assertFalse("Same id must be reserved twice!",reserve == 12L); + assertNotEquals("Same id must be reserved twice!", 12L, reserve); assertTrue(manager.release(12L)); assertTrue(manager.release(reserve)); assertFalse(manager.release(12L)); assertFalse(manager.release(reserve)); - + manager = new IdentifierManager(0L,2L); assertEquals(0L,manager.reserve(0L)); assertEquals(1L,manager.reserve(1L)); assertEquals(2L,manager.reserve(2L)); - try - { + try { manager.reserve(0L); fail("Exception expected"); - } - catch(IllegalStateException e) - { + } catch(IllegalStateException e) { // expected } - try - { + try { manager.reserve(1L); fail("Exception expected"); - } - catch(IllegalStateException e) - { + } catch(IllegalStateException e) { // expected } - try - { + try { manager.reserve(2L); fail("Exception expected"); - } - catch(IllegalStateException e) - { + } catch(IllegalStateException e) { // expected } } - public void testReserveNew() - { + @Test + public void testReserveNew() { IdentifierManager manager = new IdentifierManager(10L,12L); assertSame(10L,manager.reserveNew()); assertSame(11L,manager.reserveNew()); @@ -98,13 +96,12 @@ public class TestIdentifierManager extends TestCase try { manager.reserveNew(); fail("IllegalStateException expected"); - } - catch (IllegalStateException e) - { + } catch (IllegalStateException e) { // expected } } - + + @Test public void testRelease() { IdentifierManager manager = new IdentifierManager(10L,20L); assertEquals(10L,manager.reserve(10L)); @@ -112,11 +109,11 @@ public class TestIdentifierManager extends TestCase assertEquals(12L,manager.reserve(12L)); assertEquals(13L,manager.reserve(13L)); assertEquals(14L,manager.reserve(14L)); - + assertTrue(manager.release(10L)); assertEquals(10L,manager.reserve(10L)); assertTrue(manager.release(10L)); - + assertTrue(manager.release(11L)); assertEquals(11L,manager.reserve(11L)); assertTrue(manager.release(11L)); diff --git a/src/ooxml/testcases/org/apache/poi/xddf/usermodel/chart/TestXDDFDataSourcesFactory.java b/src/ooxml/testcases/org/apache/poi/xddf/usermodel/chart/TestXDDFDataSourcesFactory.java index f6c547cb15..8e7ef92687 100644 --- a/src/ooxml/testcases/org/apache/poi/xddf/usermodel/chart/TestXDDFDataSourcesFactory.java +++ b/src/ooxml/testcases/org/apache/poi/xddf/usermodel/chart/TestXDDFDataSourcesFactory.java @@ -16,17 +16,22 @@ ==================================================================== */ package org.apache.poi.xddf.usermodel.chart; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.SheetBuilder; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; - -import junit.framework.TestCase; +import org.junit.Test; /** * Tests for {@link XDDFDataSourcesFactory}. */ -public class TestXDDFDataSourcesFactory extends TestCase { +public class TestXDDFDataSourcesFactory { private static final Object[][] numericCells = { {0.0, 1.0, 2.0, 3.0, 4.0}, @@ -42,6 +47,7 @@ public class TestXDDFDataSourcesFactory extends TestCase { {1.0, "2.0", 3.0, "4.0", 5.0, "6.0"} }; + @Test public void testNumericArrayDataSource() { Double[] doubles = new Double[]{1.0, 2.0, 3.0, 4.0, 5.0}; XDDFDataSource doubleDataSource = XDDFDataSourcesFactory.fromArray(doubles, null); @@ -50,6 +56,7 @@ public class TestXDDFDataSourcesFactory extends TestCase { assertDataSourceIsEqualToArray(doubleDataSource, doubles); } + @Test public void testStringArrayDataSource() { String[] strings = new String[]{"one", "two", "three", "four", "five"}; XDDFDataSource stringDataSource = XDDFDataSourcesFactory.fromArray(strings, null); @@ -58,6 +65,7 @@ public class TestXDDFDataSourcesFactory extends TestCase { assertDataSourceIsEqualToArray(stringDataSource, strings); } + @Test public void testNumericCellDataSource() { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = (XSSFSheet) new SheetBuilder(wb, numericCells).build(); @@ -72,6 +80,7 @@ public class TestXDDFDataSourcesFactory extends TestCase { } } + @Test public void testStringCellDataSource() { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = (XSSFSheet) new SheetBuilder(wb, stringCells).build(); @@ -85,6 +94,7 @@ public class TestXDDFDataSourcesFactory extends TestCase { } } + @Test public void testMixedCellDataSource() { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = (XSSFSheet) new SheetBuilder(wb, mixedCells).build(); @@ -103,6 +113,7 @@ public class TestXDDFDataSourcesFactory extends TestCase { } } + @Test public void testIOBExceptionOnInvalidIndex() { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = (XSSFSheet) new SheetBuilder(wb, numericCells).build(); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java b/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java index be6db36d42..62b9825dd2 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java @@ -19,25 +19,30 @@ package org.apache.poi.xssf.eventusermodel; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + import java.io.IOException; import java.util.List; import java.util.regex.Pattern; -import junit.framework.TestCase; import org.apache.poi.POIDataSamples; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.xssf.model.SharedStringsTable; import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.junit.Test; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst; import org.xml.sax.SAXException; /** * Tests for {@link org.apache.poi.xssf.eventusermodel.XSSFReader} */ -public final class TestReadOnlySharedStringsTable extends TestCase { +@SuppressWarnings("deprecation") +public final class TestReadOnlySharedStringsTable { private static POIDataSamples _ssTests = POIDataSamples.getSpreadSheetInstance(); + @Test public void testParse() throws Exception { try (OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("SampleSS.xlsx"))) { List parts = pkg.getPartsByName(Pattern.compile("/xl/sharedStrings.xml")); @@ -60,6 +65,7 @@ public final class TestReadOnlySharedStringsTable extends TestCase { } //51519 + @Test public void testPhoneticRuns() throws Exception { try (OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("51519.xlsx"))) { List < PackagePart > parts = pkg.getPartsByName(Pattern.compile("/xl/sharedStrings.xml")); @@ -82,13 +88,15 @@ public final class TestReadOnlySharedStringsTable extends TestCase { } } + @Test public void testEmptySSTOnPackageObtainedViaWorkbook() throws Exception { XSSFWorkbook wb = new XSSFWorkbook(_ssTests.openResourceAsStream("noSharedStringTable.xlsx")); OPCPackage pkg = wb.getPackage(); assertEmptySST(pkg); wb.close(); } - + + @Test public void testEmptySSTOnPackageDirect() throws Exception { try (OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("noSharedStringTable.xlsx"))) { assertEmptySST(pkg); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.java b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.java index ed61a060f1..a68d34f9ac 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.java @@ -17,28 +17,30 @@ package org.apache.poi.xssf.extractor; -import static org.apache.poi.POITestCase.assertStartsWith; -import static org.apache.poi.POITestCase.assertEndsWith; import static org.apache.poi.POITestCase.assertContains; +import static org.apache.poi.POITestCase.assertEndsWith; import static org.apache.poi.POITestCase.assertNotContained; +import static org.apache.poi.POITestCase.assertStartsWith; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.io.IOException; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; -import java.util.HashMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; -import junit.framework.TestCase; import org.apache.poi.extractor.POITextExtractor; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.extractor.ExcelExtractor; import org.apache.poi.xssf.XSSFTestDataSamples; +import org.junit.Test; /** * Tests for {@link XSSFExcelExtractor} */ -public class TestXSSFExcelExtractor extends TestCase { +public class TestXSSFExcelExtractor { protected XSSFExcelExtractor getExtractor(String sampleName) { return new XSSFExcelExtractor(XSSFTestDataSamples.openSampleWorkbook(sampleName)); } @@ -46,29 +48,30 @@ public class TestXSSFExcelExtractor extends TestCase { /** * Get text out of the simple file */ + @Test public void testGetSimpleText() throws IOException { // a very simple file XSSFExcelExtractor extractor = getExtractor("sample.xlsx"); - + String text = extractor.getText(); assertTrue(text.length() > 0); - + // Check sheet names assertStartsWith(text, "Sheet1"); assertEndsWith(text, "Sheet3\n"); - + // Now without, will have text extractor.setIncludeSheetNames(false); text = extractor.getText(); String CHUNK1 = - "Lorem\t111\n" + - "ipsum\t222\n" + - "dolor\t333\n" + - "sit\t444\n" + - "amet\t555\n" + - "consectetuer\t666\n" + - "adipiscing\t777\n" + - "elit\t888\n" + + "Lorem\t111\n" + + "ipsum\t222\n" + + "dolor\t333\n" + + "sit\t444\n" + + "amet\t555\n" + + "consectetuer\t666\n" + + "adipiscing\t777\n" + + "elit\t888\n" + "Nunc\t999\n"; String CHUNK2 = "The quick brown fox jumps over the lazy dog\n" + @@ -77,66 +80,68 @@ public class TestXSSFExcelExtractor extends TestCase { "hello, xssf hello, xssf\n" + "hello, xssf hello, xssf\n"; assertEquals( - CHUNK1 + - "at\t4995\n" + + CHUNK1 + + "at\t4995\n" + CHUNK2 , text); - + // Now get formulas not their values extractor.setFormulasNotResults(true); text = extractor.getText(); assertEquals( CHUNK1 + - "at\tSUM(B1:B9)\n" + + "at\tSUM(B1:B9)\n" + CHUNK2, text); - + // With sheet names too extractor.setIncludeSheetNames(true); text = extractor.getText(); assertEquals( "Sheet1\n" + CHUNK1 + - "at\tSUM(B1:B9)\n" + + "at\tSUM(B1:B9)\n" + "rich test\n" + CHUNK2 + "Sheet3\n" , text); - + extractor.close(); } + @Test public void testGetComplexText() throws IOException { // A fairly complex file XSSFExcelExtractor extractor = getExtractor("AverageTaxRates.xlsx"); - + String text = extractor.getText(); assertTrue(text.length() > 0); - + // Might not have all formatting it should do! assertStartsWith(text, "Avgtxfull\n" + "\t(iii) AVERAGE TAX RATES ON ANNUAL" ); - + extractor.close(); } - + /** * Test that we return pretty much the same as * ExcelExtractor does, when we're both passed * the same file, just saved as xls and xlsx */ + @Test public void testComparedToOLE2() throws IOException { // A fairly simple file - ooxml XSSFExcelExtractor ooxmlExtractor = getExtractor("SampleSS.xlsx"); ExcelExtractor ole2Extractor = new ExcelExtractor(HSSFTestDataSamples.openSampleWorkbook("SampleSS.xls")); - + Map extractors = new HashMap<>(); extractors.put("SampleSS.xlsx", ooxmlExtractor); extractors.put("SampleSS.xls", ole2Extractor); - + for (final Entry e : extractors.entrySet()) { String filename = e.getKey(); POITextExtractor extractor = e.getValue(); @@ -150,10 +155,11 @@ public class TestXSSFExcelExtractor extends TestCase { ole2Extractor.close(); ooxmlExtractor.close(); } - + /** * From bug #45540 */ + @Test public void testHeaderFooter() throws IOException { String[] files = new String[] { "45540_classic_Header.xlsx", "45540_form_Header.xlsx", @@ -162,10 +168,10 @@ public class TestXSSFExcelExtractor extends TestCase { for(String sampleName : files) { XSSFExcelExtractor extractor = getExtractor(sampleName); String text = extractor.getText(); - + assertContains(sampleName, text, "testdoc"); assertContains(sampleName, text, "test phrase"); - + extractor.close(); } } @@ -173,6 +179,7 @@ public class TestXSSFExcelExtractor extends TestCase { /** * From bug #45544 */ + @Test public void testComments() throws IOException { XSSFExcelExtractor extractor = getExtractor("45544.xlsx"); String text = extractor.getText(); @@ -186,10 +193,11 @@ public class TestXSSFExcelExtractor extends TestCase { text = extractor.getText(); assertContains(text, "testdoc"); assertContains(text, "test phrase"); - + extractor.close(); } - + + @Test public void testInlineStrings() throws IOException { XSSFExcelExtractor extractor = getExtractor("InlineStrings.xlsx"); extractor.setFormulasNotResults(true); @@ -198,24 +206,26 @@ public class TestXSSFExcelExtractor extends TestCase { // Numbers assertContains(text, "43"); assertContains(text, "22"); - + // Strings assertContains(text, "ABCDE"); assertContains(text, "Long Text"); - + // Inline Strings assertContains(text, "1st Inline String"); assertContains(text, "And More"); - + // Formulas assertContains(text, "A2"); assertContains(text, "A5-A$2"); - + extractor.close(); } + /** * Simple test for text box text */ + @Test public void testTextBoxes() throws IOException { try (XSSFExcelExtractor extractor = getExtractor("WithTextBox.xlsx")) { extractor.setFormulasNotResults(true); @@ -226,6 +236,7 @@ public class TestXSSFExcelExtractor extends TestCase { } } + @Test public void testPhoneticRuns() throws Exception { try (XSSFExcelExtractor extractor = getExtractor("51519.xlsx")) { String text = extractor.getText(); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractorUsingFactory.java b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractorUsingFactory.java index 217fbf5800..fd130ba0ba 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractorUsingFactory.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractorUsingFactory.java @@ -17,8 +17,9 @@ package org.apache.poi.xssf.extractor; -import org.apache.poi.ooxml.extractor.ExtractorFactory; import org.apache.poi.hssf.HSSFTestDataSamples; +import org.apache.poi.ooxml.extractor.ExtractorFactory; +import org.junit.After; /** * Tests for {@link XSSFExcelExtractor} @@ -34,8 +35,8 @@ public final class TestXSSFExcelExtractorUsingFactory extends TestXSSFExcelExtra throw new RuntimeException(e); } } - - @Override + + @After public void tearDown() { // reset setting to not affect other tests ExtractorFactory.setAllThreadsPreferEventExtractors(null); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java b/src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java index dfd4ce5ca6..5e9c2452e1 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java @@ -17,22 +17,25 @@ package org.apache.poi.xssf.io; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import java.util.List; -import junit.framework.TestCase; - +import org.apache.poi.POIDataSamples; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFPictureData; -import org.apache.poi.POIDataSamples; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.junit.Test; -public class TestLoadSaveXSSF extends TestCase { +public class TestLoadSaveXSSF { private static final POIDataSamples _ssSamples = POIDataSamples.getSpreadSheetInstance(); + @Test public void testLoadSample() throws Exception { try (XSSFWorkbook workbook = new XSSFWorkbook(_ssSamples.openResourceAsStream("sample.xlsx"))) { assertEquals(3, workbook.getNumberOfSheets()); @@ -47,6 +50,7 @@ public class TestLoadSaveXSSF extends TestCase { } } + @Test public void testLoadStyles() throws Exception { try (XSSFWorkbook workbook = new XSSFWorkbook(_ssSamples.openResourceAsStream("styles.xlsx"))) { Sheet sheet = workbook.getSheetAt(0); @@ -57,6 +61,7 @@ public class TestLoadSaveXSSF extends TestCase { } } + @Test public void testLoadPictures() throws Exception { try (XSSFWorkbook workbook = new XSSFWorkbook(_ssSamples.openResourceAsStream("picture.xlsx"))) { List pictures = workbook.getAllPictures(); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/model/TestCalculationChain.java b/src/ooxml/testcases/org/apache/poi/xssf/model/TestCalculationChain.java index c4f0f5ef6b..ab74879f07 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/model/TestCalculationChain.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/model/TestCalculationChain.java @@ -17,19 +17,21 @@ package org.apache.poi.xssf.model; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.junit.Test; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcCell; -import junit.framework.TestCase; - -import java.io.IOException; - -public final class TestCalculationChain extends TestCase { +public final class TestCalculationChain { + @Test public void test46535() throws IOException { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("46535.xlsx")) { diff --git a/src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.java b/src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.java index 27645c55af..f78af2f044 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.java @@ -17,35 +17,35 @@ package org.apache.poi.xssf.model; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Collectors; -import org.apache.poi.POIDataSamples; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.usermodel.XSSFFont; import org.apache.poi.xssf.usermodel.XSSFRichTextString; import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.junit.Test; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPhoneticRun; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst; -import junit.framework.TestCase; - /** * Test {@link SharedStringsTable}, the cache of strings in a workbook - * - * @author Yegor Kozlov */ -public final class TestSharedStringsTable extends TestCase { - +public final class TestSharedStringsTable { @SuppressWarnings("deprecation") + @Test public void testCreateNew() { SharedStringsTable sst = new SharedStringsTable(); @@ -117,6 +117,7 @@ public final class TestSharedStringsTable extends TestCase { assertEquals("Second string", new XSSFRichTextString(sst.getEntryAt(2)).toString()); } + @Test public void testCreateUsingRichTextStrings() { SharedStringsTable sst = new SharedStringsTable(); @@ -183,6 +184,7 @@ public final class TestSharedStringsTable extends TestCase { assertEquals("Second string", sst.getItemAt(2).toString()); } + @Test @SuppressWarnings("deprecation") public void testReadWrite() throws IOException { XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("sample.xlsx"); @@ -222,14 +224,21 @@ public final class TestSharedStringsTable extends TestCase { * Test for Bugzilla 48936 * * A specific sequence of strings can result in broken CDATA section in sharedStrings.xml file. - * - * @author Philippe Laflamme */ + @Test public void testBug48936() throws IOException { Workbook w1 = new XSSFWorkbook(); Sheet s = w1.createSheet(); int i = 0; - List lst = readStrings("48936-strings.txt"); + + Path path = XSSFTestDataSamples.getSampleFile("48936-strings.txt").toPath(); + + List lst = Files + .lines(path, StandardCharsets.UTF_8) + .map(String::trim) + .filter(((Predicate)String::isEmpty).negate()) + .collect(Collectors.toList()); + for (String str : lst) { s.createRow(i++).createCell(0).setCellValue(str); } @@ -242,26 +251,10 @@ public final class TestSharedStringsTable extends TestCase { String val = s.getRow(i++).getCell(0).getStringCellValue(); assertEquals(str, val); } - + Workbook w3 = XSSFTestDataSamples.writeOutAndReadBack(w2); w2.close(); assertNotNull(w3); w3.close(); } - - private List readStrings(String filename) throws IOException { - List strs = new ArrayList<>(); - POIDataSamples samples = POIDataSamples.getSpreadSheetInstance(); - BufferedReader br = new BufferedReader( - new InputStreamReader(samples.openResourceAsStream(filename), StandardCharsets.UTF_8)); - String s; - while ((s = br.readLine()) != null) { - if (s.trim().length() > 0) { - strs.add(s.trim()); - } - } - br.close(); - return strs; - } - } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/AllXSSFUsermodelTests.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/AllXSSFUsermodelTests.java index 7ee7546b3d..4ccb70e9d1 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/AllXSSFUsermodelTests.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/AllXSSFUsermodelTests.java @@ -20,7 +20,6 @@ package org.apache.poi.xssf.usermodel; import org.apache.poi.ss.formula.eval.forked.TestForkedEvaluator; import org.apache.poi.xssf.usermodel.extensions.TestXSSFBorder; import org.apache.poi.xssf.usermodel.extensions.TestXSSFCellFill; -import org.apache.poi.xssf.usermodel.extensions.TestXSSFSheetComments; import org.apache.poi.xssf.usermodel.helpers.TestColumnHelper; import org.apache.poi.xssf.usermodel.helpers.TestHeaderFooterHelper; import org.junit.runner.RunWith; @@ -56,7 +55,6 @@ import org.junit.runners.Suite; TestXSSFWorkbook.class, TestXSSFBorder.class, TestXSSFCellFill.class, - TestXSSFSheetComments.class, TestColumnHelper.class, TestHeaderFooterHelper.class, //TestXSSFPivotTable.class, //converted to junit4 diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/BaseTestXSSFPivotTable.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/BaseTestXSSFPivotTable.java index dcb793cf9f..ff16a5358f 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/BaseTestXSSFPivotTable.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/BaseTestXSSFPivotTable.java @@ -16,7 +16,9 @@ ==================================================================== */ package org.apache.poi.xssf.usermodel; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import java.io.IOException; @@ -41,14 +43,13 @@ public abstract class BaseTestXSSFPivotTable { protected XSSFPivotTable pivotTable; protected XSSFPivotTable offsetPivotTable; protected Cell offsetOuterCell; - + /** * required to set up the test pivot tables and cell reference, either by name or reference. - * @see junit.framework.TestCase#setUp() */ @Before public abstract void setUp(); - + @After public void tearDown() throws IOException { if (wb != null) { @@ -67,18 +68,18 @@ public abstract class BaseTestXSSFPivotTable { int columnIndex = 0; assertEquals(0, pivotTable.getRowLabelColumns().size()); - + pivotTable.addRowLabel(columnIndex); CTPivotTableDefinition defintion = pivotTable.getCTPivotTableDefinition(); assertEquals(defintion.getRowFields().getFieldArray(0).getX(), columnIndex); assertEquals(defintion.getRowFields().getCount(), 1); assertEquals(1, pivotTable.getRowLabelColumns().size()); - + columnIndex = 1; pivotTable.addRowLabel(columnIndex); assertEquals(2, pivotTable.getRowLabelColumns().size()); - + assertEquals(0, (int)pivotTable.getRowLabelColumns().get(0)); assertEquals(1, (int)pivotTable.getRowLabelColumns().get(1)); } @@ -120,8 +121,8 @@ public abstract class BaseTestXSSFPivotTable { assertEquals(defintion.getDataFields().getDataFieldList().size(), 3); } - - + + /** * Verify that it's possible to create three column labels with the same DataConsolidateFunction */ @@ -138,7 +139,7 @@ public abstract class BaseTestXSSFPivotTable { assertEquals(defintion.getDataFields().getDataFieldList().size(), 3); } - + /** * Verify that when creating two column labels, a col field is being created and X is set to -2. */ @@ -169,7 +170,7 @@ public abstract class BaseTestXSSFPivotTable { assertEquals(defintion.getDataFields().getDataFieldArray(0).getSubtotal(), STDataConsolidateFunction.Enum.forInt(DataConsolidateFunction.SUM.getValue())); } - + /** * Verify that it's possible to set a custom name when creating a data column */ @@ -178,7 +179,7 @@ public abstract class BaseTestXSSFPivotTable { int columnIndex = 0; String customName = "Custom Name"; - + pivotTable.addColumnLabel(DataConsolidateFunction.SUM, columnIndex, customName); CTPivotTableDefinition defintion = pivotTable.getCTPivotTableDefinition(); @@ -186,7 +187,7 @@ public abstract class BaseTestXSSFPivotTable { assertEquals(defintion.getDataFields().getDataFieldArray(0).getFld(), columnIndex); assertEquals(defintion.getDataFields().getDataFieldArray(0).getName(), customName); } - + /** * Verify that it's possible to set the format to the data column */ @@ -195,7 +196,7 @@ public abstract class BaseTestXSSFPivotTable { int columnIndex = 0; String format = "#,##0.0"; - + pivotTable.addColumnLabel(DataConsolidateFunction.SUM, columnIndex, null, format); CTPivotTableDefinition defintion = pivotTable.getCTPivotTableDefinition(); @@ -256,7 +257,7 @@ public abstract class BaseTestXSSFPivotTable { public void testAddReportFilterOutOfRangeThrowsException() { pivotTable.addReportFilter(5); } - + /** * Verify that the Pivot Table operates only within the referenced area, even when the * first column of the referenced area is not index 0. @@ -265,10 +266,10 @@ public abstract class BaseTestXSSFPivotTable { public void testAddDataColumnWithOffsetData() { offsetPivotTable.addColumnLabel(DataConsolidateFunction.SUM, 1); assertEquals(CellType.NUMERIC, offsetOuterCell.getCellType()); - + offsetPivotTable.addColumnLabel(DataConsolidateFunction.SUM, 0); } - + @Test public void testPivotTableSheetNamesAreCaseInsensitive() { wb.setSheetName(0, "original"); @@ -278,7 +279,7 @@ public abstract class BaseTestXSSFPivotTable { // assume sheets are accessible via case-insensitive name assertNotNull(original); assertNotNull(offset); - + AreaReference source = wb.getCreationHelper().createAreaReference("ORIGinal!A1:C2"); // create a pivot table on the same sheet, case insensitive original.createPivotTable(source, new CellReference("W1")); @@ -296,18 +297,18 @@ public abstract class BaseTestXSSFPivotTable { int columnIndex = 0; assertEquals(0, pivotTable.getColLabelColumns().size()); - + pivotTable.addColLabel(columnIndex); CTPivotTableDefinition defintion = pivotTable.getCTPivotTableDefinition(); assertEquals(defintion.getColFields().getFieldArray(0).getX(), columnIndex); assertEquals(defintion.getColFields().getCount(), 1); assertEquals(1, pivotTable.getColLabelColumns().size()); - + columnIndex = 1; pivotTable.addColLabel(columnIndex); assertEquals(2, pivotTable.getColLabelColumns().size()); - + assertEquals(0, (int)pivotTable.getColLabelColumns().get(0)); assertEquals(1, (int)pivotTable.getColLabelColumns().get(1)); } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMatrixFormulasFromXMLSpreadsheet.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMatrixFormulasFromXMLSpreadsheet.java index b0447871b3..a5b7dcbc2f 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMatrixFormulasFromXMLSpreadsheet.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMatrixFormulasFromXMLSpreadsheet.java @@ -26,8 +26,6 @@ import java.util.Collection; import java.util.List; import java.util.Locale; - -import org.apache.poi.poifs.crypt.TestSignatureInfo; import org.apache.poi.ss.formula.eval.ErrorEval; import org.apache.poi.ss.formula.functions.TestMathX; import org.apache.poi.ss.usermodel.Cell; @@ -47,8 +45,6 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import junit.framework.AssertionFailedError; - @RunWith(Parameterized.class) public final class TestMatrixFormulasFromXMLSpreadsheet { @@ -58,17 +54,17 @@ public final class TestMatrixFormulasFromXMLSpreadsheet { private static Sheet sheet; private static FormulaEvaluator evaluator; private static Locale userLocale; - + /* * Unlike TestFormulaFromSpreadsheet which this class is modified from, there is no * differentiation between operators and functions, if more functionality is implemented with * array formulas then it might be worth it to separate operators from functions - * + * * Also, output matrices are statically 3x3, if larger matrices wanted to be tested * then adding matrix size parameter would be useful and parsing would be based off that. */ - - private static interface Navigator { + + private interface Navigator { /** * Name of the test spreadsheet (found in the standard test data folder) */ @@ -97,21 +93,21 @@ public final class TestMatrixFormulasFromXMLSpreadsheet { * Used to indicate when there are no more operations left */ String END_OF_TESTS = ""; - + } - + /* Parameters for test case */ @Parameter(0) public String targetFunctionName; @Parameter(1) public int formulasRowIdx; - + @AfterClass public static void closeResource() throws Exception { LocaleUtil.setUserLocale(userLocale); workbook.close(); } - + /* generating parameter instances */ @Parameters(name="{0}") public static Collection data() throws Exception { @@ -120,18 +116,18 @@ public final class TestMatrixFormulasFromXMLSpreadsheet { // already set, when we would try to change the locale by then userLocale = LocaleUtil.getUserLocale(); LocaleUtil.setUserLocale(Locale.ROOT); - + workbook = XSSFTestDataSamples.openSampleWorkbook(Navigator.FILENAME); sheet = workbook.getSheetAt(0); evaluator = new XSSFFormulaEvaluator(workbook); - + List data = new ArrayList(); - + processFunctionGroup(data, Navigator.START_OPERATORS_ROW_INDEX, null); - + return data; } - + /** * @param startRowIndex row index in the spreadsheet where the first function/operator is found * @param testFocusFunctionName name of a single function/operator to test alone. @@ -153,7 +149,7 @@ public final class TestMatrixFormulasFromXMLSpreadsheet { } } } - + @Test public void processFunctionRow() { @@ -162,27 +158,27 @@ public final class TestMatrixFormulasFromXMLSpreadsheet { for (int rowNum = formulasRowIdx; rowNum < formulasRowIdx + Navigator.ROW_OFF_NEXT_OP - 1; rowNum++) { for (int colNum = Navigator.START_RESULT_COL_INDEX; colNum < endColNum; colNum++) { Row r = sheet.getRow(rowNum); - + /* mainly to escape row failures on MDETERM which only returns a scalar */ if (r == null) { continue; } - + Cell c = sheet.getRow(rowNum).getCell(colNum); - + if (c == null || c.getCellType() != CellType.FORMULA) { continue; } - + CellValue actValue = evaluator.evaluate(c); Cell expValue = sheet.getRow(rowNum).getCell(colNum + Navigator.COL_OFF_EXPECTED_RESULT); - + String msg = String.format(Locale.ROOT, "Function '%s': Formula: %s @ %d:%d" , targetFunctionName, c.getCellFormula(), rowNum, colNum); - + assertNotNull(msg + " - Bad setup data expected value is null", expValue); assertNotNull(msg + " - actual value was null", actValue); - + final CellType cellType = expValue.getCellType(); switch (cellType) { case BLANK: @@ -212,7 +208,7 @@ public final class TestMatrixFormulasFromXMLSpreadsheet { } } } - + /** * @return null if cell is missing, empty or blank */ @@ -234,13 +230,8 @@ public final class TestMatrixFormulasFromXMLSpreadsheet { return cell.getRichStringCellValue().getString(); } - throw new AssertionFailedError("Bad cell type for 'function name' column: (" + fail("Bad cell type for 'function name' column: (" + cell.getCellType() + ") row (" + (r.getRowNum() +1) + ")"); + return null; } - - - - - - } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFChart.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFChart.java index a81472527f..afea5bc1b6 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFChart.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFChart.java @@ -17,14 +17,17 @@ package org.apache.poi.xssf.usermodel; -import org.apache.poi.xssf.XSSFTestDataSamples; - -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import java.io.IOException; -public final class TestXSSFChart extends TestCase { +import org.apache.poi.xssf.XSSFTestDataSamples; +import org.junit.Test; +public final class TestXSSFChart { + @Test public void testGetAccessors() throws IOException { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("WithThreeCharts.xlsx")) { XSSFSheet s1 = wb.getSheetAt(0); @@ -39,6 +42,7 @@ public final class TestXSSFChart extends TestCase { } } + @Test public void testGetCharts() throws Exception { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("WithThreeCharts.xlsx")) { XSSFSheet s1 = wb.getSheetAt(0); @@ -67,6 +71,7 @@ public final class TestXSSFChart extends TestCase { } } + @Test public void testAddChartsToNewWorkbook() throws Exception { try (XSSFWorkbook wb = new XSSFWorkbook()) { XSSFSheet s1 = wb.createSheet(); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java index 0827b5b24f..db8dc231e8 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java @@ -17,27 +17,34 @@ package org.apache.poi.xssf.usermodel; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.util.TreeMap; + import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.model.StylesTable; +import org.junit.Test; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst; import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXstring; -import java.io.IOException; -import java.util.TreeMap; - /** * Tests functionality of the XSSFRichTextRun object - * - * @author Yegor Kozlov */ -public final class TestXSSFRichTextString extends TestCase { +public final class TestXSSFRichTextString { + @Test public void testCreate() { XSSFRichTextString rt = new XSSFRichTextString("Apache POI"); assertEquals("Apache POI", rt.getString()); @@ -56,6 +63,7 @@ public final class TestXSSFRichTextString extends TestCase { assertFalse(rt.hasFormatting()); } + @Test public void testEmpty() { XSSFRichTextString rt = new XSSFRichTextString(); assertEquals(0, rt.getIndexOfFormattingRun(9999)); @@ -63,6 +71,7 @@ public final class TestXSSFRichTextString extends TestCase { assertNull(rt.getFontAtIndex(9999)); } + @Test public void testApplyFont() { XSSFRichTextString rt = new XSSFRichTextString(); rt.append("123"); @@ -92,43 +101,46 @@ public final class TestXSSFRichTextString extends TestCase { assertEquals(7, rt.getIndexOfFormattingRun(3)); assertEquals(2, rt.getLengthOfFormattingRun(3)); assertEquals("89", rt.getCTRst().getRArray(3).getT()); - - + + assertEquals(-1, rt.getIndexOfFormattingRun(9999)); assertEquals(-1, rt.getLengthOfFormattingRun(9999)); assertNull(rt.getFontAtIndex(9999)); } + @Test public void testApplyFontIndex() { XSSFRichTextString rt = new XSSFRichTextString("Apache POI"); rt.applyFont(0, 10, (short)1); - + rt.applyFont((short)1); - + assertNotNull(rt.getFontAtIndex(0)); } + @Test public void testApplyFontWithStyles() { XSSFRichTextString rt = new XSSFRichTextString("Apache POI"); - + StylesTable tbl = new StylesTable(); rt.setStylesTableReference(tbl); - + try { rt.applyFont(0, 10, (short)1); fail("Fails without styles in the table"); } catch (IndexOutOfBoundsException e) { // expected } - + tbl.putFont(new XSSFFont()); rt.applyFont(0, 10, (short)1); rt.applyFont((short)1); } + @Test public void testApplyFontException() { XSSFRichTextString rt = new XSSFRichTextString("Apache POI"); - + rt.applyFont(0, 0, (short)1); try { @@ -153,6 +165,7 @@ public final class TestXSSFRichTextString extends TestCase { } } + @Test public void testClearFormatting() { XSSFRichTextString rt = new XSSFRichTextString("Apache POI"); @@ -173,14 +186,15 @@ public final class TestXSSFRichTextString extends TestCase { rt.applyFont(7, 10, font); assertEquals(2, rt.numFormattingRuns()); assertTrue(rt.hasFormatting()); - + rt.clearFormatting(); - + assertEquals("Apache POI", rt.getString()); assertEquals(0, rt.numFormattingRuns()); assertFalse(rt.hasFormatting()); } + @Test public void testGetFonts() { XSSFRichTextString rt = new XSSFRichTextString(); @@ -208,6 +222,7 @@ public final class TestXSSFRichTextString extends TestCase { * make sure we insert xml:space="preserve" attribute * if a string has leading or trailing white spaces */ + @Test public void testPreserveSpaces() { XSSFRichTextString rt = new XSSFRichTextString("Apache"); CTRst ct = rt.getCTRst(); @@ -227,6 +242,7 @@ public final class TestXSSFRichTextString extends TestCase { /** * test that unicode representation_ xHHHH_ is properly processed */ + @Test public void testUtfDecode() { CTRst st = CTRst.Factory.newInstance(); st.setT("abc_x000D_2ef_x000D_"); @@ -241,6 +257,7 @@ public final class TestXSSFRichTextString extends TestCase { assertEquals("abc\r2ef\r", rt2.getString()); } + @Test public void testApplyFont_lowlevel(){ CTRst st = CTRst.Factory.newInstance(); String text = "Apache Software Foundation"; @@ -355,6 +372,7 @@ public final class TestXSSFRichTextString extends TestCase { assertSame(fmt5, runs12[4]); } + @Test public void testApplyFont_usermodel(){ String text = "Apache Software Foundation"; XSSFRichTextString str = new XSSFRichTextString(text); @@ -382,6 +400,7 @@ public final class TestXSSFRichTextString extends TestCase { assertEquals(" Software Foundation", str.getCTRst().getRArray(1).getT()); } + @Test public void testLineBreaks_bug48877() { XSSFFont font = new XSSFFont(); @@ -441,6 +460,7 @@ public final class TestXSSFRichTextString extends TestCase { assertEquals("\n\n", t3.xmlText()); } + @Test public void testBug56511() throws IOException { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56511.xlsx")) { for (Sheet sheet : wb) { @@ -471,6 +491,7 @@ public final class TestXSSFRichTextString extends TestCase { } } + @Test public void testBug56511_values() throws IOException { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56511.xlsx")) { Sheet sheet = wb.getSheetAt(0); @@ -510,6 +531,7 @@ public final class TestXSSFRichTextString extends TestCase { } } + @Test public void testToString() { XSSFRichTextString rt = new XSSFRichTextString("Apache POI"); assertNotNull(rt.toString()); @@ -518,6 +540,7 @@ public final class TestXSSFRichTextString extends TestCase { assertEquals("", rt.toString()); } + @Test public void test59008Font() { XSSFFont font = new XSSFFont(CTFont.Factory.newInstance()); @@ -534,6 +557,7 @@ public final class TestXSSFRichTextString extends TestCase { assertEquals("", rts.getFontAtIndex(s3-1).toString()); } + @Test public void test60289UtfDecode() throws IOException { XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("60289.xlsx"); assertEquals("Rich Text\r\nTest", wb.getSheetAt(0).getRow(1).getCell(1).getRichStringCellValue().getString()); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetRowGrouping.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetRowGrouping.java index c2eb54ebe5..bcdfb3d5e8 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetRowGrouping.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetRowGrouping.java @@ -17,23 +17,24 @@ package org.apache.poi.xssf.usermodel; -import java.io.IOException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; -import junit.framework.TestCase; +import java.io.IOException; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.XSSFTestDataSamples; +import org.junit.Test; -public final class TestXSSFSheetRowGrouping extends TestCase { +public final class TestXSSFSheetRowGrouping { private static final int ROWS_NUMBER = 200; private static final int GROUP_SIZE = 5; - //private int o_groupsNumber = 0; - + @Test public void test55640() { //long startTime = System.currentTimeMillis(); Workbook wb = new XSSFWorkbook(); @@ -88,6 +89,7 @@ public final class TestXSSFSheetRowGrouping extends TestCase { assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(p_wb)); } + @Test public void test55640reduce1() { Workbook wb = new XSSFWorkbook(); Sheet sheet = wb.createSheet("sheet123"); @@ -106,7 +108,7 @@ public final class TestXSSFSheetRowGrouping extends TestCase { while (start < end) { // natural order sheet.groupRow(start, end); //o_groupsNumber++; - boolean collapsed = start % 2 == 0 ? false : true; + boolean collapsed = (start % 2) != 0; //System.out.println("Set group " + start + "->" + end + " to " + collapsed); sheet.setRowGroupCollapsed(start, collapsed); start++; // natural order @@ -116,29 +118,29 @@ public final class TestXSSFSheetRowGrouping extends TestCase { writeToFile(wb); } - + @Test public void test55640_VerifyCases() { // NOTE: This is currently based on current behavior of POI, somehow - // what POI returns in the calls to collapsed/hidden is not fully matching + // what POI returns in the calls to collapsed/hidden is not fully matching // the examples in the spec or I did not fully understand how POI stores the data internally... - + // all expanded verifyGroupCollapsed( // level1, level2, level3 - false, false, false, + false, false, false, // collapsed: - new Boolean[] { false, false, false, false, false}, + new Boolean[] { false, false, false, false, false}, // hidden: new boolean[] { false, false, false, false, false}, // outlineLevel new int[] { 1, 2, 3, 3, 3 } ); - - // Level 1 collapsed, others expanded, should only have 4 rows, all hidden: + + // Level 1 collapsed, others expanded, should only have 4 rows, all hidden: verifyGroupCollapsed( // level1, level2, level3 - true, false, false, + true, false, false, // collapsed: new Boolean[] { false, false, false, false, false}, // hidden: @@ -147,10 +149,10 @@ public final class TestXSSFSheetRowGrouping extends TestCase { new int[] { 1, 2, 3, 3, 3 } ); - // Level 1 and 2 collapsed, Level 3 expanded, + // Level 1 and 2 collapsed, Level 3 expanded, verifyGroupCollapsed( // level1, level2, level3 - true, true, false, + true, true, false, // collapsed: new Boolean[] { false, false, false, false, true, false}, // hidden: @@ -159,10 +161,10 @@ public final class TestXSSFSheetRowGrouping extends TestCase { new int[] { 1, 2, 3, 3, 3, 0 } ); - // Level 1 collapsed, Level 2 expanded, Level 3 collapsed + // Level 1 collapsed, Level 2 expanded, Level 3 collapsed verifyGroupCollapsed( // level1, level2, level3 - true, false, true, + true, false, true, // collapsed: new Boolean[] { false, false, false, false, false, true}, // hidden: @@ -174,7 +176,7 @@ public final class TestXSSFSheetRowGrouping extends TestCase { // Level 2 collapsed, others expanded: verifyGroupCollapsed( // level1, level2, level3 - false, true, false, + false, true, false, // collapsed: new Boolean[] { false, false, false, false, false, false}, // hidden: @@ -183,10 +185,10 @@ public final class TestXSSFSheetRowGrouping extends TestCase { new int[] { 1, 2, 3, 3, 3, 0 } ); - // Level 3 collapsed, others expanded + // Level 3 collapsed, others expanded verifyGroupCollapsed( // level1, level2, level3 - false, false, true, + false, false, true, // collapsed: new Boolean[] { false, false, false, false, false, true}, // hidden: @@ -195,10 +197,10 @@ public final class TestXSSFSheetRowGrouping extends TestCase { new int[] { 1, 2, 3, 3, 3, 0 } ); - // All collapsed + // All collapsed verifyGroupCollapsed( // level1, level2, level3 - true, true, true, + true, true, true, // collapsed: new Boolean[] { false, false, false, false, true, true}, // hidden: @@ -207,9 +209,9 @@ public final class TestXSSFSheetRowGrouping extends TestCase { new int[] { 1, 2, 3, 3, 3, 0 } ); } - - - private void verifyGroupCollapsed(boolean level1, boolean level2, boolean level3, + + + private void verifyGroupCollapsed(boolean level1, boolean level2, boolean level3, Boolean[] collapsed, boolean[] hidden, int[] outlineLevel) { Workbook wb = new XSSFWorkbook(); Sheet sheet = wb.createSheet("sheet123"); @@ -217,11 +219,11 @@ public final class TestXSSFSheetRowGrouping extends TestCase { for (int i = 0; i < 4; i++) { sheet.createRow(i); } - + sheet.groupRow(0, 4); sheet.groupRow(1, 4); sheet.groupRow(2, 4); - + sheet.setRowGroupCollapsed(0, level1); sheet.setRowGroupCollapsed(1, level2); sheet.setRowGroupCollapsed(2, level3); @@ -229,27 +231,28 @@ public final class TestXSSFSheetRowGrouping extends TestCase { checkWorkbookGrouping(wb, collapsed, hidden, outlineLevel); } - public void test55640_VerifyCasesSpec() throws IOException { + @Test + public void test55640_VerifyCasesSpec() { // NOTE: This is currently based on current behavior of POI, somehow - // what POI returns in the calls to collapsed/hidden is not fully matching + // what POI returns in the calls to collapsed/hidden is not fully matching // the examples in the spec or I did not fully understand how POI stores the data internally... - + // all expanded verifyGroupCollapsedSpec( // level3, level2, level1 - false, false, false, + false, false, false, // collapsed: - new Boolean[] { false, false, false, false}, + new Boolean[] { false, false, false, false}, // hidden: new boolean[] { false, false, false, false}, // outlineLevel new int[] { 3, 3, 2, 1 } ); - + verifyGroupCollapsedSpec( // level3, level2, level1 - false, false, true, + false, false, true, // collapsed: new Boolean[] { false, false, false, true}, // hidden: @@ -260,7 +263,7 @@ public final class TestXSSFSheetRowGrouping extends TestCase { verifyGroupCollapsedSpec( // level3, level2, level1 - false, true, false, + false, true, false, // collapsed: new Boolean[] { false, false, true, false}, // hidden: @@ -268,10 +271,10 @@ public final class TestXSSFSheetRowGrouping extends TestCase { // outlineLevel new int[] { 3, 3, 2, 1 } ); - + verifyGroupCollapsedSpec( // level3, level2, level1 - false, true, true, + false, true, true, // collapsed: new Boolean[] { false, false, true, true}, // hidden: @@ -281,34 +284,34 @@ public final class TestXSSFSheetRowGrouping extends TestCase { ); } - private void verifyGroupCollapsedSpec(boolean level1, boolean level2, boolean level3, - Boolean[] collapsed, boolean[] hidden, int[] outlineLevel) { + @SuppressWarnings("SameParameterValue") + private void verifyGroupCollapsedSpec(boolean level1, boolean level2, boolean level3, + Boolean[] collapsed, boolean[] hidden, int[] outlineLevel) { Workbook wb = new XSSFWorkbook(); Sheet sheet = wb.createSheet("sheet123"); for (int i = 5; i < 9; i++) { sheet.createRow(i); } - + sheet.groupRow(5, 6); sheet.groupRow(5, 7); sheet.groupRow(5, 8); - + sheet.setRowGroupCollapsed(6, level1); sheet.setRowGroupCollapsed(7, level2); sheet.setRowGroupCollapsed(8, level3); - + checkWorkbookGrouping(wb, collapsed, hidden, outlineLevel); } private void checkWorkbookGrouping(Workbook wb, Boolean[] collapsed, boolean[] hidden, int[] outlineLevel) { - printWorkbook(wb); Sheet sheet = wb.getSheetAt(0); - + assertEquals(collapsed.length, hidden.length); assertEquals(collapsed.length, outlineLevel.length); assertEquals("Expected " + collapsed.length + " rows with collapsed state, but had " + (sheet.getLastRowNum()-sheet.getFirstRowNum()+1) + " rows (" - + sheet.getFirstRowNum() + "-" + sheet.getLastRowNum() + ")", + + sheet.getFirstRowNum() + "-" + sheet.getLastRowNum() + ")", collapsed.length, sheet.getLastRowNum()-sheet.getFirstRowNum()+1); for(int i = sheet.getFirstRowNum(); i < sheet.getLastRowNum();i++) { if(collapsed[i-sheet.getFirstRowNum()] == null) { @@ -317,16 +320,16 @@ public final class TestXSSFSheetRowGrouping extends TestCase { XSSFRow row = (XSSFRow) sheet.getRow(i); assertNotNull("Could not read row " + i, row); assertNotNull("Could not read row " + i, row.getCTRow()); - assertEquals("Row: " + i + ": collapsed", collapsed[i-sheet.getFirstRowNum()].booleanValue(), row.getCTRow().getCollapsed()); + assertEquals("Row: " + i + ": collapsed", collapsed[i - sheet.getFirstRowNum()], row.getCTRow().getCollapsed()); assertEquals("Row: " + i + ": hidden", hidden[i-sheet.getFirstRowNum()], row.getCTRow().getHidden()); - + assertEquals("Row: " + i + ": level", outlineLevel[i-sheet.getFirstRowNum()], row.getCTRow().getOutlineLevel()); } - + writeToFile(wb); } - + @Test public void test55640working() { Workbook wb = new XSSFWorkbook(); Sheet sheet = wb.createSheet("sheet123"); @@ -334,7 +337,7 @@ public final class TestXSSFSheetRowGrouping extends TestCase { sheet.groupRow(1, 4); sheet.groupRow(2, 5); sheet.groupRow(3, 6); - + sheet.setRowGroupCollapsed(1, true); sheet.setRowGroupCollapsed(2, false); sheet.setRowGroupCollapsed(3, false); @@ -342,29 +345,7 @@ public final class TestXSSFSheetRowGrouping extends TestCase { writeToFile(wb); } - // just used for printing out contents of spreadsheets - public void notRuntest55640printSample() { - XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("55640.xlsx"); - printWorkbook(wb); - - wb = XSSFTestDataSamples.openSampleWorkbook("GroupTest.xlsx"); - printWorkbook(wb); - } - - private void printWorkbook(Workbook wb) { - // disable all output for now... -// Sheet sheet = wb.getSheetAt(0); -// -// for(Iterator it = sheet.rowIterator();it.hasNext();) { -// XSSFRow row = (XSSFRow) it.next(); -// boolean collapsed = row.getCTRow().getCollapsed(); -// boolean hidden = row.getCTRow().getHidden(); -// short level = row.getCTRow().getOutlineLevel(); -// -// System.out.println("Row: " + row.getRowNum() + ": Level: " + level + " Collapsed: " + collapsed + " Hidden: " + hidden); -// } - } - + @Test public void testGroupingTest() throws IOException { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("GroupTest.xlsx")) { diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetUpdateArrayFormulas.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetUpdateArrayFormulas.java index 85378ec2b2..99ebd95c0e 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetUpdateArrayFormulas.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetUpdateArrayFormulas.java @@ -19,6 +19,7 @@ package org.apache.poi.xssf.usermodel; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; @@ -33,12 +34,8 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula; import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellFormulaType; -import junit.framework.AssertionFailedError; /** * Test array formulas in XSSF - * - * @author Yegor Kozlov - * @author Josh Micich */ public final class TestXSSFSheetUpdateArrayFormulas extends BaseTestSheetUpdateArrayFormulas { @@ -67,7 +64,7 @@ public final class TestXSSFSheetUpdateArrayFormulas extends BaseTestSheetUpdateA //retrieve the range and check it is the same assertEquals(range.formatAsString(), firstCell.getArrayFormulaRange().formatAsString()); confirmArrayFormulaCell(firstCell, "C3", formula1, "C3"); - + workbook.close(); } @@ -103,9 +100,7 @@ public final class TestXSSFSheetUpdateArrayFormulas extends BaseTestSheetUpdateA confirmArrayFormulaCell(c, cellRef, null, null); } private static void confirmArrayFormulaCell(XSSFCell c, String cellRef, String formulaText, String arrayRangeRef) { - if (c == null) { - throw new AssertionFailedError("Cell should not be null."); - } + assertNotNull("Cell should not be null.", c); CTCell ctCell = c.getCTCell(); assertEquals(cellRef, ctCell.getR()); if (formulaText == null) { diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFCategoryAxis.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFCategoryAxis.java index a7f9098e39..5b55a85b7a 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFCategoryAxis.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFCategoryAxis.java @@ -17,6 +17,8 @@ package org.apache.poi.xssf.usermodel.charts; +import static org.junit.Assert.assertEquals; + import org.apache.poi.xddf.usermodel.chart.AxisCrosses; import org.apache.poi.xddf.usermodel.chart.AxisPosition; import org.apache.poi.xddf.usermodel.chart.XDDFCategoryAxis; @@ -25,24 +27,22 @@ import org.apache.poi.xssf.usermodel.XSSFClientAnchor; import org.apache.poi.xssf.usermodel.XSSFDrawing; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.junit.Test; -import junit.framework.TestCase; - -public final class TestXSSFCategoryAxis extends TestCase { - +public final class TestXSSFCategoryAxis { + @Test public void testAccessMethods() throws Exception { - XSSFWorkbook wb = new XSSFWorkbook(); - XSSFSheet sheet = wb.createSheet(); - XSSFDrawing drawing = sheet.createDrawingPatriarch(); - XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30); - XSSFChart chart = drawing.createChart(anchor); - XDDFCategoryAxis axis = chart.createCategoryAxis(AxisPosition.BOTTOM); + try (XSSFWorkbook wb = new XSSFWorkbook()) { + XSSFSheet sheet = wb.createSheet(); + XSSFDrawing drawing = sheet.createDrawingPatriarch(); + XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30); + XSSFChart chart = drawing.createChart(anchor); + XDDFCategoryAxis axis = chart.createCategoryAxis(AxisPosition.BOTTOM); - axis.setCrosses(AxisCrosses.AUTO_ZERO); - assertEquals(axis.getCrosses(), AxisCrosses.AUTO_ZERO); + axis.setCrosses(AxisCrosses.AUTO_ZERO); + assertEquals(axis.getCrosses(), AxisCrosses.AUTO_ZERO); - assertEquals(chart.getAxes().size(), 1); - - wb.close(); + assertEquals(chart.getAxes().size(), 1); + } } } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartAxis.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartAxis.java index eac0becc4e..a7c912f43c 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartAxis.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartAxis.java @@ -17,6 +17,11 @@ package org.apache.poi.xssf.usermodel.charts; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.List; @@ -29,17 +34,19 @@ import org.apache.poi.xssf.usermodel.XSSFClientAnchor; import org.apache.poi.xssf.usermodel.XSSFDrawing; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; -import junit.framework.TestCase; - -public final class TestXSSFChartAxis extends TestCase { +public final class TestXSSFChartAxis { private static final double EPSILON = 1E-7; - private final XDDFChartAxis axis; + private XSSFWorkbook wb; + private XDDFChartAxis axis; - public TestXSSFChartAxis() { - super(); - XSSFWorkbook wb = new XSSFWorkbook(); + @Before + public void setup() { + wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet(); XSSFDrawing drawing = sheet.createDrawingPatriarch(); XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30); @@ -47,6 +54,14 @@ public final class TestXSSFChartAxis extends TestCase { axis = chart.createValueAxis(AxisPosition.BOTTOM); } + @After + public void teardown() throws IOException { + wb.close(); + wb = null; + axis = null; + } + + @Test public void testLogBaseIllegalArgument() { IllegalArgumentException iae = null; try { @@ -65,17 +80,20 @@ public final class TestXSSFChartAxis extends TestCase { assertNotNull(iae); } + @Test public void testLogBaseLegalArgument() { axis.setLogBase(Math.E); assertTrue(Math.abs(axis.getLogBase() - Math.E) < EPSILON); } + @Test public void testNumberFormat() { final String numberFormat = "General"; axis.setNumberFormat(numberFormat); assertEquals(numberFormat, axis.getNumberFormat()); } + @Test public void testMaxAndMinAccessMethods() { final double newValue = 10.0; @@ -86,6 +104,7 @@ public final class TestXSSFChartAxis extends TestCase { assertTrue(Math.abs(axis.getMaximum() - newValue) < EPSILON); } + @Test public void testVisibleAccessMethods() { axis.setVisible(true); assertTrue(axis.isVisible()); @@ -94,6 +113,7 @@ public final class TestXSSFChartAxis extends TestCase { assertFalse(axis.isVisible()); } + @Test public void testMajorTickMarkAccessMethods() { axis.setMajorTickMark(AxisTickMark.NONE); assertEquals(AxisTickMark.NONE, axis.getMajorTickMark()); @@ -108,6 +128,7 @@ public final class TestXSSFChartAxis extends TestCase { assertEquals(AxisTickMark.CROSS, axis.getMajorTickMark()); } + @Test public void testMinorTickMarkAccessMethods() { axis.setMinorTickMark(AxisTickMark.NONE); assertEquals(AxisTickMark.NONE, axis.getMinorTickMark()); @@ -122,6 +143,7 @@ public final class TestXSSFChartAxis extends TestCase { assertEquals(AxisTickMark.CROSS, axis.getMinorTickMark()); } + @Test public void testGetChartAxisBug57362() throws IOException { //Load existing excel with some chart on it having primary and secondary axis. try (final XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("57362.xlsx")) { diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFDateAxis.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFDateAxis.java index 5664488185..42c59b3dcc 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFDateAxis.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFDateAxis.java @@ -17,6 +17,8 @@ package org.apache.poi.xssf.usermodel.charts; +import static org.junit.Assert.assertEquals; + import org.apache.poi.xddf.usermodel.chart.AxisCrosses; import org.apache.poi.xddf.usermodel.chart.AxisPosition; import org.apache.poi.xddf.usermodel.chart.XDDFDateAxis; @@ -25,24 +27,23 @@ import org.apache.poi.xssf.usermodel.XSSFClientAnchor; import org.apache.poi.xssf.usermodel.XSSFDrawing; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.junit.Test; -import junit.framework.TestCase; - -public final class TestXSSFDateAxis extends TestCase { +public final class TestXSSFDateAxis { + @Test public void testAccessMethods() throws Exception { - XSSFWorkbook wb = new XSSFWorkbook(); - XSSFSheet sheet = wb.createSheet(); - XSSFDrawing drawing = sheet.createDrawingPatriarch(); - XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30); - XSSFChart chart = drawing.createChart(anchor); - XDDFDateAxis axis = chart.createDateAxis(AxisPosition.BOTTOM); + try (XSSFWorkbook wb = new XSSFWorkbook()) { + XSSFSheet sheet = wb.createSheet(); + XSSFDrawing drawing = sheet.createDrawingPatriarch(); + XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30); + XSSFChart chart = drawing.createChart(anchor); + XDDFDateAxis axis = chart.createDateAxis(AxisPosition.BOTTOM); - axis.setCrosses(AxisCrosses.AUTO_ZERO); - assertEquals(axis.getCrosses(), AxisCrosses.AUTO_ZERO); + axis.setCrosses(AxisCrosses.AUTO_ZERO); + assertEquals(axis.getCrosses(), AxisCrosses.AUTO_ZERO); - assertEquals(chart.getAxes().size(), 1); - - wb.close(); + assertEquals(chart.getAxes().size(), 1); + } } } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFValueAxis.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFValueAxis.java index 3f8ef06db4..87866259d5 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFValueAxis.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFValueAxis.java @@ -17,6 +17,8 @@ package org.apache.poi.xssf.usermodel.charts; +import static org.junit.Assert.assertEquals; + import org.apache.poi.xddf.usermodel.chart.AxisCrossBetween; import org.apache.poi.xddf.usermodel.chart.AxisCrosses; import org.apache.poi.xddf.usermodel.chart.AxisPosition; @@ -26,27 +28,26 @@ import org.apache.poi.xssf.usermodel.XSSFClientAnchor; import org.apache.poi.xssf.usermodel.XSSFDrawing; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.junit.Test; -import junit.framework.TestCase; - -public final class TestXSSFValueAxis extends TestCase { +public final class TestXSSFValueAxis { + @Test public void testAccessMethods() throws Exception { - XSSFWorkbook wb = new XSSFWorkbook(); - XSSFSheet sheet = wb.createSheet(); - XSSFDrawing drawing = sheet.createDrawingPatriarch(); - XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30); - XSSFChart chart = drawing.createChart(anchor); - XDDFValueAxis axis = chart.createValueAxis(AxisPosition.BOTTOM); + try (XSSFWorkbook wb = new XSSFWorkbook()) { + XSSFSheet sheet = wb.createSheet(); + XSSFDrawing drawing = sheet.createDrawingPatriarch(); + XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30); + XSSFChart chart = drawing.createChart(anchor); + XDDFValueAxis axis = chart.createValueAxis(AxisPosition.BOTTOM); - axis.setCrossBetween(AxisCrossBetween.MIDPOINT_CATEGORY); - assertEquals(axis.getCrossBetween(), AxisCrossBetween.MIDPOINT_CATEGORY); + axis.setCrossBetween(AxisCrossBetween.MIDPOINT_CATEGORY); + assertEquals(axis.getCrossBetween(), AxisCrossBetween.MIDPOINT_CATEGORY); - axis.setCrosses(AxisCrosses.AUTO_ZERO); - assertEquals(axis.getCrosses(), AxisCrosses.AUTO_ZERO); + axis.setCrosses(AxisCrosses.AUTO_ZERO); + assertEquals(axis.getCrosses(), AxisCrosses.AUTO_ZERO); - assertEquals(chart.getAxes().size(), 1); - - wb.close(); + assertEquals(chart.getAxes().size(), 1); + } } } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFBorder.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFBorder.java index e7233c227e..67442a18d2 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFBorder.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFBorder.java @@ -17,38 +17,40 @@ package org.apache.poi.xssf.usermodel.extensions; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; import org.apache.poi.ss.usermodel.BorderStyle; import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSide; +import org.junit.Test; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorderPr; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTStylesheet; import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle; -public class TestXSSFBorder extends TestCase { - +public class TestXSSFBorder { + + @Test public void testGetBorderStyle() { CTStylesheet stylesheet = CTStylesheet.Factory.newInstance(); CTBorder border = stylesheet.addNewBorders().addNewBorder(); CTBorderPr top = border.addNewTop(); CTBorderPr right = border.addNewRight(); CTBorderPr bottom = border.addNewBottom(); - + top.setStyle(STBorderStyle.DASH_DOT); right.setStyle(STBorderStyle.NONE); bottom.setStyle(STBorderStyle.THIN); - + XSSFCellBorder cellBorderStyle = new XSSFCellBorder(border); assertEquals("DASH_DOT", cellBorderStyle.getBorderStyle(BorderSide.TOP).toString()); - + assertEquals("NONE", cellBorderStyle.getBorderStyle(BorderSide.RIGHT).toString()); assertEquals(BorderStyle.NONE.ordinal(), cellBorderStyle.getBorderStyle(BorderSide.RIGHT).ordinal()); - + assertEquals("THIN", cellBorderStyle.getBorderStyle(BorderSide.BOTTOM).toString()); - + assertEquals(BorderStyle.THIN.ordinal(), cellBorderStyle.getBorderStyle(BorderSide.BOTTOM).ordinal()); } - + } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFSheetComments.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFSheetComments.java deleted file mode 100644 index b58078f063..0000000000 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFSheetComments.java +++ /dev/null @@ -1,26 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.xssf.usermodel.extensions; - -import junit.framework.TestCase; - -public class TestXSSFSheetComments extends TestCase { - // So eclipse doesn't moan - public void testTODO() { - } -} diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestHeaderFooterHelper.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestHeaderFooterHelper.java index d058e36c82..c36e1fd519 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestHeaderFooterHelper.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestHeaderFooterHelper.java @@ -17,27 +17,31 @@ package org.apache.poi.xssf.usermodel.helpers; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; /** * Test the header and footer helper. * As we go through XmlBeans, should always use &, * and not & */ -public class TestHeaderFooterHelper extends TestCase { - +public class TestHeaderFooterHelper { + + @Test public void testGetCenterLeftRightSection() { HeaderFooterHelper helper = new HeaderFooterHelper(); - + String headerFooter = "&CTest the center section"; assertEquals("Test the center section", helper.getCenterSection(headerFooter)); - + headerFooter = "&CTest the center section<he left one&RAnd the right one"; assertEquals("Test the center section", helper.getCenterSection(headerFooter)); assertEquals("The left one", helper.getLeftSection(headerFooter)); assertEquals("And the right one", helper.getRightSection(headerFooter)); } - + + @Test public void testSetCenterLeftRightSection() { HeaderFooterHelper helper = new HeaderFooterHelper(); String headerFooter = ""; @@ -53,10 +57,10 @@ public class TestHeaderFooterHelper extends TestCase { headerFooter = helper.setRightSection(headerFooter, "First right&F"); assertEquals("First right&F", helper.getRightSection(headerFooter)); assertEquals("&CFirst added center section&LFirst left&RFirst right&F", headerFooter); - + headerFooter = helper.setRightSection(headerFooter, "First right&"); assertEquals("First right&", helper.getRightSection(headerFooter)); assertEquals("&CFirst added center section&LFirst left&RFirst right&", headerFooter); } - + } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/util/MemoryUsage.java b/src/ooxml/testcases/org/apache/poi/xssf/util/MemoryUsage.java index b3327ef873..dac40c9ee4 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/util/MemoryUsage.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/util/MemoryUsage.java @@ -27,21 +27,18 @@ import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.CellReference; import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.junit.Test; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetData; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet; import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType; -import junit.framework.TestCase; - /** * Mixed utilities for testing memory usage in XSSF - * - * @author Yegor Kozlov */ @SuppressWarnings("InfiniteLoopStatement") -public class MemoryUsage extends TestCase { +public class MemoryUsage { private static final int NUM_COLUMNS = 255; private static void printMemoryUsage(String msg) { @@ -159,6 +156,7 @@ public class MemoryUsage extends TestCase { * * @see #testXmlAttached() */ + @Test public void testXmlDetached() { System.out.println(); System.out.println("Testing detached"); @@ -187,6 +185,7 @@ public class MemoryUsage extends TestCase { * * @see #testXmlAttached() */ + @Test public void testXmlAttached() { System.out.println(); System.out.println("Testing attached"); @@ -212,18 +211,22 @@ public class MemoryUsage extends TestCase { printMemoryUsage("after"); } + @Test public void testMixedHSSF() { mixedSpreadsheet(new HSSFWorkbook(), NUM_COLUMNS); } + @Test public void testMixedXSSF() { mixedSpreadsheet(new XSSFWorkbook(), NUM_COLUMNS); } + @Test public void testNumberHSSF() { numberSpreadsheet(new HSSFWorkbook(), NUM_COLUMNS); } + @Test public void testNumberXSSF() { numberSpreadsheet(new XSSFWorkbook(), NUM_COLUMNS); } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/util/TestCTColComparator.java b/src/ooxml/testcases/org/apache/poi/xssf/util/TestCTColComparator.java index 9fa8320bba..ec1a679d6d 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/util/TestCTColComparator.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/util/TestCTColComparator.java @@ -17,15 +17,17 @@ package org.apache.poi.xssf.util; +import static org.junit.Assert.assertEquals; + import java.util.Arrays; -import junit.framework.TestCase; - +import org.junit.Test; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol; -public final class TestCTColComparator extends TestCase { +public final class TestCTColComparator { + @Test public void testCompare() { CTCol o1 = CTCol.Factory.newInstance(); o1.setMin(1); @@ -43,6 +45,7 @@ public final class TestCTColComparator extends TestCase { assertEquals(-1, CTColComparator.BY_MIN_MAX.compare(o3, o4)); } + @Test public void testArraysSort() { CTCol o1 = CTCol.Factory.newInstance(); o1.setMin(1); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/util/TestNumericRanges.java b/src/ooxml/testcases/org/apache/poi/xssf/util/TestNumericRanges.java index 90ea9736aa..183098188f 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/util/TestNumericRanges.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/util/TestNumericRanges.java @@ -17,11 +17,14 @@ package org.apache.poi.xssf.util; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; -public class TestNumericRanges extends TestCase { - +public class TestNumericRanges { + + @Test public void testGetOverlappingType() { long[] r1 = {3, 8}; long[] r2 = {6, 11}; @@ -35,7 +38,8 @@ public class TestNumericRanges extends TestCase { assertEquals(NumericRanges.OVERLAPS_1_WRAPS, NumericRanges.getOverlappingType(r1, r5)); assertEquals(NumericRanges.NO_OVERLAPS, NumericRanges.getOverlappingType(r1, r6)); } - + + @Test public void testGetOverlappingRange() { long[] r1 = {3, 8}; long[] r2 = {6, 11}; @@ -54,5 +58,5 @@ public class TestNumericRanges extends TestCase { assertEquals(-1, NumericRanges.getOverlappingRange(r1, r6)[0]); assertEquals(-1, NumericRanges.getOverlappingRange(r1, r6)[1]); } - + } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/TestPackageCorePropertiesGetKeywords.java b/src/ooxml/testcases/org/apache/poi/xwpf/TestPackageCorePropertiesGetKeywords.java index e9ab3f7197..2295e9a5f3 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/TestPackageCorePropertiesGetKeywords.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/TestPackageCorePropertiesGetKeywords.java @@ -17,12 +17,14 @@ package org.apache.poi.xwpf; +import static org.junit.Assert.assertEquals; + import java.io.IOException; -import junit.framework.TestCase; import org.apache.poi.ooxml.POIXMLProperties.CoreProperties; import org.apache.poi.openxml4j.opc.PackageProperties; import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.junit.Test; /** * Tests if the {@link CoreProperties#getKeywords()} method. This test has been @@ -33,10 +35,9 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument; * The author of this has added {@link CoreProperties#getKeywords()} and * {@link CoreProperties#setKeywords(String)} and this test is supposed to test * them. - * - * @author Antoni Mylka */ -public final class TestPackageCorePropertiesGetKeywords extends TestCase { +public final class TestPackageCorePropertiesGetKeywords { + @Test public void testGetSetKeywords() throws IOException { try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestPoiXMLDocumentCorePropertiesGetKeywords.docx")) { String keywords = doc.getProperties().getCoreProperties().getKeywords(); diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestExternalEntities.java b/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestExternalEntities.java index 929d430413..6f74f01ed1 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestExternalEntities.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestExternalEntities.java @@ -17,31 +17,32 @@ package org.apache.poi.xwpf.extractor; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; -import junit.framework.TestCase; import org.apache.poi.xwpf.XWPFTestDataSamples; import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.junit.Test; -public class TestExternalEntities extends TestCase { +public class TestExternalEntities { /** * Get text out of the simple file - * - * @throws IOException */ + @Test public void testFile() throws IOException { - XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("ExternalEntityInText.docx"); - XWPFWordExtractor extractor = new XWPFWordExtractor(doc); + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("ExternalEntityInText.docx"); + XWPFWordExtractor extractor = new XWPFWordExtractor(doc)) { - String text = extractor.getText(); + String text = extractor.getText(); - assertTrue(text.length() > 0); + assertTrue(text.length() > 0); - // Check contents, they should not contain the text from POI web site after colon! - assertEquals("Here should not be the POI web site: \"\"", text.trim()); - - extractor.close(); + // Check contents, they should not contain the text from POI web site after colon! + assertEquals("Here should not be the POI web site: \"\"", text.trim()); + } } } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java b/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java index eae693f0f0..ecab432c10 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java @@ -17,32 +17,36 @@ package org.apache.poi.xwpf.extractor; +import static org.apache.poi.POITestCase.assertContains; +import static org.apache.poi.POITestCase.assertEndsWith; +import static org.apache.poi.POITestCase.assertNotContained; +import static org.apache.poi.POITestCase.assertStartsWith; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; -import junit.framework.TestCase; - import org.apache.poi.util.StringUtil; import org.apache.poi.xwpf.XWPFTestDataSamples; import org.apache.poi.xwpf.usermodel.XWPFDocument; -import static org.apache.poi.POITestCase.assertContains; -import static org.apache.poi.POITestCase.assertEndsWith; -import static org.apache.poi.POITestCase.assertNotContained; -import static org.apache.poi.POITestCase.assertStartsWith; +import org.junit.Test; /** * Tests for HXFWordExtractor */ -public class TestXWPFWordExtractor extends TestCase { +public class TestXWPFWordExtractor { /** * Get text out of the simple file */ + @Test public void testGetSimpleText() throws IOException { - try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx")) { - XWPFWordExtractor extractor = new XWPFWordExtractor(doc); + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx"); + XWPFWordExtractor extractor = new XWPFWordExtractor(doc)) { String text = extractor.getText(); assertTrue(text.length() > 0); @@ -58,23 +62,21 @@ public class TestXWPFWordExtractor extends TestCase { // Check number of paragraphs by counting number of newlines int numberOfParagraphs = StringUtil.countMatches(text, '\n'); assertEquals(3, numberOfParagraphs); - - extractor.close(); } } /** * Tests getting the text out of a complex file */ + @Test public void testGetComplexText() throws IOException { - try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx")) { - XWPFWordExtractor extractor = new XWPFWordExtractor(doc); + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx"); + XWPFWordExtractor extractor = new XWPFWordExtractor(doc)) { String text = extractor.getText(); assertTrue(text.length() > 0); char euro = '\u20ac'; -// System.err.println("'"+text.substring(text.length() - 40) + "'"); // Check contents assertStartsWith(text, @@ -90,14 +92,13 @@ public class TestXWPFWordExtractor extends TestCase { // Check number of paragraphs by counting number of newlines int numberOfParagraphs = StringUtil.countMatches(text, '\n'); assertEquals(134, numberOfParagraphs); - - extractor.close(); } } + @Test public void testGetWithHyperlinks() throws IOException { - try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestDocument.docx")) { - XWPFWordExtractor extractor = new XWPFWordExtractor(doc); + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestDocument.docx"); + XWPFWordExtractor extractor = new XWPFWordExtractor(doc)) { // Now check contents extractor.setFetchHyperlinks(false); @@ -118,126 +119,117 @@ public class TestXWPFWordExtractor extends TestCase { "We have a hyperlink here, and another.\n", extractor.getText() ); - - extractor.close(); } } + @Test public void testHeadersFooters() throws IOException { - try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("ThreeColHeadFoot.docx")) { - XWPFWordExtractor extractor = new XWPFWordExtractor(doc); + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("ThreeColHeadFoot.docx"); + XWPFWordExtractor extractor = new XWPFWordExtractor(doc)) { assertEquals( - "First header column!\tMid header\tRight header!\n" + - "This is a sample word document. It has two pages. It has a three column heading, and a three column footer\n" + - "\n" + - "HEADING TEXT\n" + - "\n" + - "More on page one\n" + - "\n\n" + - "End of page 1\n\n\n" + - "This is page two. It also has a three column heading, and a three column footer.\n" + - "Footer Left\tFooter Middle\tFooter Right\n", - extractor.getText() + "First header column!\tMid header\tRight header!\n" + + "This is a sample word document. It has two pages. It has a three column heading, and a three column footer\n" + + "\n" + + "HEADING TEXT\n" + + "\n" + + "More on page one\n" + + "\n\n" + + "End of page 1\n\n\n" + + "This is page two. It also has a three column heading, and a three column footer.\n" + + "Footer Left\tFooter Middle\tFooter Right\n", + extractor.getText() ); + } - // Now another file, expect multiple headers - // and multiple footers - XWPFDocument doc2 = XWPFTestDataSamples.openSampleDocument("DiffFirstPageHeadFoot.docx"); - extractor.close(); + // Now another file, expect multiple headers + // and multiple footers + try (XWPFDocument doc2 = XWPFTestDataSamples.openSampleDocument("DiffFirstPageHeadFoot.docx")) { - extractor = new XWPFWordExtractor(doc2); - extractor.close(); + new XWPFWordExtractor(doc2).close(); - extractor = - new XWPFWordExtractor(doc2); - extractor.getText(); + try (XWPFWordExtractor extractor = new XWPFWordExtractor(doc2)) { + extractor.getText(); - assertEquals( + assertEquals( "I am the header on the first page, and I" + '\u2019' + "m nice and simple\n" + - "First header column!\tMid header\tRight header!\n" + - "This is a sample word document. It has two pages. It has a simple header and footer, which is different to all the other pages.\n" + - "\n" + - "HEADING TEXT\n" + - "\n" + - "More on page one\n" + - "\n\n" + - "End of page 1\n\n\n" + - "This is page two. It also has a three column heading, and a three column footer.\n" + - "The footer of the first page\n" + - "Footer Left\tFooter Middle\tFooter Right\n", + "First header column!\tMid header\tRight header!\n" + + "This is a sample word document. It has two pages. It has a simple header and footer, which is different to all the other pages.\n" + + "\n" + + "HEADING TEXT\n" + + "\n" + + "More on page one\n" + + "\n\n" + + "End of page 1\n\n\n" + + "This is page two. It also has a three column heading, and a three column footer.\n" + + "The footer of the first page\n" + + "Footer Left\tFooter Middle\tFooter Right\n", extractor.getText() - ); + ); - extractor.close(); + } } } + @Test public void testFootnotes() throws IOException { - try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("footnotes.docx")) { - XWPFWordExtractor extractor = new XWPFWordExtractor(doc); + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("footnotes.docx"); + XWPFWordExtractor extractor = new XWPFWordExtractor(doc)) { String text = extractor.getText(); assertContains(text, "snoska"); assertContains(text, "Eto ochen prostoy[footnoteRef:1] text so snoskoy"); - - extractor.close(); } } + @Test public void testTableFootnotes() throws IOException { - try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("table_footnotes.docx")) { - XWPFWordExtractor extractor = new XWPFWordExtractor(doc); + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("table_footnotes.docx"); + XWPFWordExtractor extractor = new XWPFWordExtractor(doc)) { assertContains(extractor.getText(), "snoska"); - - extractor.close(); } } + @Test public void testFormFootnotes() throws IOException { - try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("form_footnotes.docx")) { - XWPFWordExtractor extractor = new XWPFWordExtractor(doc); + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("form_footnotes.docx"); + XWPFWordExtractor extractor = new XWPFWordExtractor(doc)) { String text = extractor.getText(); assertContains(text, "testdoc"); assertContains(text, "test phrase"); - - extractor.close(); } } + @Test public void testEndnotes() throws IOException { - try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("endnotes.docx")) { - XWPFWordExtractor extractor = new XWPFWordExtractor(doc); + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("endnotes.docx"); + XWPFWordExtractor extractor = new XWPFWordExtractor(doc)) { String text = extractor.getText(); assertContains(text, "XXX"); assertContains(text, "tilaka [endnoteRef:2]or 'tika'"); - - extractor.close(); } } + @Test public void testInsertedDeletedText() throws IOException { - try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("delins.docx")) { - XWPFWordExtractor extractor = new XWPFWordExtractor(doc); + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("delins.docx"); + XWPFWordExtractor extractor = new XWPFWordExtractor(doc)) { assertContains(extractor.getText(), "pendant worn"); assertContains(extractor.getText(), "extremely well"); - - extractor.close(); } } + @Test public void testParagraphHeader() throws IOException { - try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Headers.docx")) { - XWPFWordExtractor extractor = new XWPFWordExtractor(doc); + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Headers.docx"); + XWPFWordExtractor extractor = new XWPFWordExtractor(doc)) { assertContains(extractor.getText(), "Section 1"); assertContains(extractor.getText(), "Section 2"); assertContains(extractor.getText(), "Section 3"); - - extractor.close(); } } @@ -245,15 +237,14 @@ public class TestXWPFWordExtractor extends TestCase { * Test that we can open and process .docm * (macro enabled) docx files (bug #45690) */ + @Test public void testDOCMFiles() throws IOException { - try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("45690.docm")) { - XWPFWordExtractor extractor = new XWPFWordExtractor(doc); + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("45690.docm"); + XWPFWordExtractor extractor = new XWPFWordExtractor(doc)) { assertContains(extractor.getText(), "2004"); assertContains(extractor.getText(), "2008"); assertContains(extractor.getText(), "(120 "); - - extractor.close(); } } @@ -262,9 +253,10 @@ public class TestXWPFWordExtractor extends TestCase { * carriage returns properly in the text that * we're extracting (bug #49189) */ + @Test public void testDocTabs() throws IOException { - try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("WithTabs.docx")) { - XWPFWordExtractor extractor = new XWPFWordExtractor(doc); + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("WithTabs.docx"); + XWPFWordExtractor extractor = new XWPFWordExtractor(doc)) { // Check bits assertContains(extractor.getText(), "a"); @@ -273,8 +265,6 @@ public class TestXWPFWordExtractor extends TestCase { // Now check the first paragraph in total assertContains(extractor.getText(), "a\tb\n"); - - extractor.close(); } } @@ -282,15 +272,14 @@ public class TestXWPFWordExtractor extends TestCase { * The output should not contain field codes, e.g. those specified in the * w:instrText tag (spec sec. 17.16.23) */ + @Test public void testNoFieldCodes() throws IOException { - try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("FieldCodes.docx")) { - XWPFWordExtractor extractor = new XWPFWordExtractor(doc); + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("FieldCodes.docx"); + XWPFWordExtractor extractor = new XWPFWordExtractor(doc)) { String text = extractor.getText(); assertTrue(text.length() > 0); assertFalse(text.contains("AUTHOR")); assertFalse(text.contains("CREATEDATE")); - - extractor.close(); } } @@ -298,14 +287,13 @@ public class TestXWPFWordExtractor extends TestCase { * The output should contain the values of simple fields, those specified * with the fldSimple element (spec sec. 17.16.19) */ + @Test public void testFldSimpleContent() throws IOException { - try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("FldSimple.docx")) { - XWPFWordExtractor extractor = new XWPFWordExtractor(doc); + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("FldSimple.docx"); + XWPFWordExtractor extractor = new XWPFWordExtractor(doc)) { String text = extractor.getText(); assertTrue(text.length() > 0); assertContains(text, "FldSimple.docx"); - - extractor.close(); } } @@ -313,38 +301,38 @@ public class TestXWPFWordExtractor extends TestCase { * Test for parsing document with drawings to prevent * NoClassDefFoundError for CTAnchor in XWPFRun */ + @Test public void testDrawings() throws IOException { - try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("drawing.docx")) { - XWPFWordExtractor extractor = new XWPFWordExtractor(doc); + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("drawing.docx"); + XWPFWordExtractor extractor = new XWPFWordExtractor(doc)) { String text = extractor.getText(); assertTrue(text.length() > 0); - - extractor.close(); } } /** * Test for basic extraction of SDT content */ + @Test public void testSimpleControlContent() throws IOException { - try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54849.docx")) { + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54849.docx"); + XWPFWordExtractor ex = new XWPFWordExtractor(doc)) { String[] targs = new String[]{ - "header_rich_text", - "rich_text", - "rich_text_pre_table\nrich_text_cell1\t\t\t\n\t\t\t\n\t\t\t\n\nrich_text_post_table", - "plain_text_no_newlines", - "plain_text_with_newlines1\nplain_text_with_newlines2\n", - "watermelon\n", - "dirt\n", - "4/16/2013\n", - "rich_text_in_cell", - "abc", - "rich_text_in_paragraph_in_cell", - "footer_rich_text", - "footnote_sdt", - "endnote_sdt" + "header_rich_text", + "rich_text", + "rich_text_pre_table\nrich_text_cell1\t\t\t\n\t\t\t\n\t\t\t\n\nrich_text_post_table", + "plain_text_no_newlines", + "plain_text_with_newlines1\nplain_text_with_newlines2\n", + "watermelon\n", + "dirt\n", + "4/16/2013\n", + "rich_text_in_cell", + "abc", + "rich_text_in_paragraph_in_cell", + "footer_rich_text", + "footnote_sdt", + "endnote_sdt" }; - XWPFWordExtractor ex = new XWPFWordExtractor(doc); String s = ex.getText().toLowerCase(Locale.ROOT); int hits = 0; @@ -357,17 +345,17 @@ public class TestXWPFWordExtractor extends TestCase { assertTrue("controlled content loading-" + targ, hit); } assertEquals("controlled content loading hit count", targs.length, hits); - ex.close(); + } + try (XWPFDocument doc2 = XWPFTestDataSamples.openSampleDocument("Bug54771a.docx"); + XWPFWordExtractor ex = new XWPFWordExtractor(doc2)) { + String s = ex.getText().toLowerCase(Locale.ROOT); - XWPFDocument doc2 = XWPFTestDataSamples.openSampleDocument("Bug54771a.docx"); - targs = new String[]{ - "bb", - "test subtitle\n", - "test user\n", + String[] targs = { + "bb", + "test subtitle\n", + "test user\n", }; - ex = new XWPFWordExtractor(doc2); - s = ex.getText().toLowerCase(Locale.ROOT); //At one point in development there were three copies of the text. //This ensures that there is only one copy. @@ -387,69 +375,71 @@ public class TestXWPFWordExtractor extends TestCase { hit++; } assertEquals("test", 2, hit); - ex.close(); } } /** * No Header or Footer in document */ + @Test public void testBug55733() throws Exception { - try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("55733.docx")) { - XWPFWordExtractor extractor = new XWPFWordExtractor(doc); + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("55733.docx"); + XWPFWordExtractor extractor = new XWPFWordExtractor(doc)) { // Check it gives text without error extractor.getText(); - extractor.close(); } } + @Test public void testCheckboxes() throws IOException { - try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("checkboxes.docx")) { - XWPFWordExtractor extractor = new XWPFWordExtractor(doc); + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("checkboxes.docx"); + XWPFWordExtractor extractor = new XWPFWordExtractor(doc)) { assertEquals("This is a small test for checkboxes \nunchecked: |_| \n" + - "Or checked: |X|\n\n\n\n\n" + - "Test a checkbox within a textbox: |_| -> |X|\n\n\n" + - "In Table:\n|_|\t|X|\n\n\n" + - "In Sequence:\n|X||_||X|\n", extractor.getText()); - extractor.close(); - } - } - - public void testMultipleBodyBug() throws IOException { - try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("MultipleBodyBug.docx")) { - XWPFWordExtractor extractor = new XWPFWordExtractor(doc); - assertEquals("START BODY 1 The quick, brown fox jumps over a lazy dog. END BODY 1.\n" - + "START BODY 2 The quick, brown fox jumps over a lazy dog. END BODY 2.\n" - + "START BODY 3 The quick, brown fox jumps over a lazy dog. END BODY 3.\n", - extractor.getText()); - extractor.close(); + "Or checked: |X|\n\n\n\n\n" + + "Test a checkbox within a textbox: |_| -> |X|\n\n\n" + + "In Table:\n|_|\t|X|\n\n\n" + + "In Sequence:\n|X||_||X|\n", extractor.getText()); } } + @Test + public void testMultipleBodyBug() throws IOException { + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("MultipleBodyBug.docx"); + XWPFWordExtractor extractor = new XWPFWordExtractor(doc)) { + assertEquals("START BODY 1 The quick, brown fox jumps over a lazy dog. END BODY 1.\n" + + "START BODY 2 The quick, brown fox jumps over a lazy dog. END BODY 2.\n" + + "START BODY 3 The quick, brown fox jumps over a lazy dog. END BODY 3.\n", + extractor.getText()); + } + } + + @Test public void testPhonetic() throws IOException { try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("61470.docx")) { - XWPFWordExtractor extractor = new XWPFWordExtractor(doc); - //expect: baseText (phoneticText) - assertEquals("\u6771\u4EAC (\u3068\u3046\u304D\u3087\u3046)", extractor.getText().trim()); - extractor.close(); - extractor = new XWPFWordExtractor(doc); - extractor.setConcatenatePhoneticRuns(false); - assertEquals("\u6771\u4EAC", extractor.getText().trim()); + try (XWPFWordExtractor extractor = new XWPFWordExtractor(doc)) { + //expect: baseText (phoneticText) + assertEquals("\u6771\u4EAC (\u3068\u3046\u304D\u3087\u3046)", extractor.getText().trim()); + } + try (XWPFWordExtractor extractor = new XWPFWordExtractor(doc)) { + extractor.setConcatenatePhoneticRuns(false); + assertEquals("\u6771\u4EAC", extractor.getText().trim()); + } } } + @Test public void testCTPictureBase() throws IOException { //This forces ctpicturebase to be included in the poi-ooxml-schemas jar - try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("61991.docx")) { - XWPFWordExtractor extractor = new XWPFWordExtractor(doc); + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("61991.docx"); + XWPFWordExtractor extractor = new XWPFWordExtractor(doc)) { String txt = extractor.getText(); assertContains(txt, "Sequencing data"); - extractor.close(); } } + @Test public void testGlossary() throws IOException { try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("60316.dotx")) { XWPFWordExtractor extractor = new XWPFWordExtractor(doc); @@ -461,6 +451,7 @@ public class TestXWPFWordExtractor extends TestCase { } } + @Test public void testPartsInTemplate() throws IOException { try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("60316b.dotx")) { XWPFWordExtractor extractor = new XWPFWordExtractor(doc); diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFEndnotes.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFEndnotes.java index 1195a1206e..2fda6ab44d 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFEndnotes.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFEndnotes.java @@ -17,45 +17,46 @@ package org.apache.poi.xwpf.usermodel; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; + import java.io.IOException; import java.math.BigInteger; import org.apache.poi.xwpf.XWPFTestDataSamples; +import org.junit.Test; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STFtnEdn; -import junit.framework.TestCase; +public class TestXWPFEndnotes { -public class TestXWPFEndnotes extends TestCase { - + @Test public void testCreateEndnotes() throws IOException{ - XWPFDocument docOut = new XWPFDocument(); + try (XWPFDocument docOut = new XWPFDocument()) { + XWPFEndnotes footnotes = docOut.createEndnotes(); + assertNotNull(footnotes); - XWPFEndnotes footnotes = docOut.createEndnotes(); - - assertNotNull(footnotes); - - XWPFEndnotes secondFootnotes = docOut.createEndnotes(); - - assertSame(footnotes, secondFootnotes); - - docOut.close(); + XWPFEndnotes secondFootnotes = docOut.createEndnotes(); + assertSame(footnotes, secondFootnotes); + } } + @Test public void testAddEndnotesToDocument() throws IOException { - XWPFDocument docOut = new XWPFDocument(); + try (XWPFDocument docOut = new XWPFDocument()) { + // NOTE: XWPFDocument.createEndnote() delegates directly + // to XWPFFootnotes.createEndnote() so this tests + // both creation of new XWPFFootnotes in document + // and XWPFFootnotes.createEndnote(); + XWPFEndnote endnote = docOut.createEndnote(); + BigInteger noteId = endnote.getId(); - // NOTE: XWPFDocument.createEndnote() delegates directly - // to XWPFFootnotes.createEndnote() so this tests - // both creation of new XWPFFootnotes in document - // and XWPFFootnotes.createEndnote(); - XWPFEndnote endnote = docOut.createEndnote(); - BigInteger noteId = endnote.getId(); + XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut); - XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut); - - XWPFEndnote note = docIn.getEndnoteByID(noteId.intValue()); - assertNotNull(note); - assertEquals(STFtnEdn.NORMAL, note.getCTFtnEdn().getType()); + XWPFEndnote note = docIn.getEndnoteByID(noteId.intValue()); + assertNotNull(note); + assertEquals(STFtnEdn.NORMAL, note.getCTFtnEdn().getType()); + } } } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java index 328eca4919..0f642ae98b 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java @@ -17,16 +17,21 @@ package org.apache.poi.xwpf.usermodel; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.math.BigInteger; -import junit.framework.TestCase; import org.apache.poi.xwpf.XWPFTestDataSamples; +import org.junit.Test; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNum; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNumLvl; -public class TestXWPFNumbering extends TestCase { +public class TestXWPFNumbering { + @Test public void testCompareAbstractNum() throws IOException { try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Numbering.docx")) { XWPFNumbering numbering = doc.getNumbering(); @@ -40,6 +45,7 @@ public class TestXWPFNumbering extends TestCase { } } + @Test public void testAddNumberingToDoc() throws IOException { BigInteger abstractNumId = BigInteger.valueOf(1); BigInteger numId = BigInteger.valueOf(1); @@ -58,6 +64,7 @@ public class TestXWPFNumbering extends TestCase { assertEquals(abstractNumId, compareAbstractNum); } + @Test public void testGetNumIlvl() throws IOException { try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Numbering.docx")) { BigInteger numIlvl = BigInteger.valueOf(0); @@ -67,6 +74,7 @@ public class TestXWPFNumbering extends TestCase { } } + @Test public void testGetNumFmt() throws IOException { try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Numbering.docx")) { assertEquals("bullet", doc.getParagraphs().get(0).getNumFmt()); @@ -79,6 +87,7 @@ public class TestXWPFNumbering extends TestCase { } } + @Test public void testLvlText() throws IOException { try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Numbering.docx")) { @@ -93,6 +102,7 @@ public class TestXWPFNumbering extends TestCase { } } + @Test public void testOverrideList() throws IOException { try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("NumberingWOverrides.docx")) { XWPFParagraph p = doc.getParagraphs().get(4); diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFPictureData.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFPictureData.java index daf4675f9d..570d153d88 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFPictureData.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFPictureData.java @@ -18,21 +18,26 @@ package org.apache.poi.xwpf.usermodel; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.List; -import junit.framework.TestCase; - import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.xssf.usermodel.XSSFRelation; import org.apache.poi.xwpf.XWPFTestDataSamples; import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy; +import org.junit.Assert; +import org.junit.Test; -public class TestXWPFPictureData extends TestCase { +public class TestXWPFPictureData { + @Test public void testRead() throws InvalidFormatException, IOException { try (XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("VariousPictures.docx")) { List pictures = sampleDoc.getAllPictures(); @@ -57,6 +62,7 @@ public class TestXWPFPictureData extends TestCase { } } + @Test public void testPictureInHeader() throws IOException { try (XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("headerPic.docx")) { verifyOneHeaderPicture(sampleDoc); @@ -65,7 +71,8 @@ public class TestXWPFPictureData extends TestCase { verifyOneHeaderPicture(readBack); } } - + + @Test public void testCreateHeaderPicture() throws Exception { try (XWPFDocument doc = new XWPFDocument()) { @@ -104,6 +111,7 @@ public class TestXWPFPictureData extends TestCase { assertEquals(1, pictures.size()); } + @Test public void testNew() throws InvalidFormatException, IOException { try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("EmptyDocumentWithHeaderFooter.docx")) { byte[] jpegData = XWPFTestDataSamples.getImage("nature1.jpg"); @@ -165,22 +173,19 @@ public class TestXWPFPictureData extends TestCase { } } + @Test public void testBug51770() throws IOException { try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug51170.docx")) { XWPFHeaderFooterPolicy policy = doc.getHeaderFooterPolicy(); XWPFHeader header = policy.getDefaultHeader(); - for (XWPFParagraph paragraph : header.getParagraphs()) { - for (XWPFRun run : paragraph.getRuns()) { - for (XWPFPicture picture : run.getEmbeddedPictures()) { - if (paragraph.getDocument() != null) { - XWPFPictureData data = picture.getPictureData(); - if (data != null) { - fail("Should have returned null: " + data.getFileName()); - } - } - } - } - } + + header.getParagraphs().stream() + .map(XWPFParagraph::getRuns) + .flatMap(List::stream) + .map(XWPFRun::getEmbeddedPictures) + .flatMap(List::stream) + .map(XWPFPicture::getPictureData) + .forEach(Assert::assertNull); } } } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSmartTag.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSmartTag.java index c3a0409023..ba9eb30ed4 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSmartTag.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSmartTag.java @@ -16,19 +16,18 @@ ==================================================================== */ package org.apache.poi.xwpf.usermodel; +import static org.apache.poi.POITestCase.assertContains; + import java.io.IOException; -import junit.framework.TestCase; import org.apache.poi.xwpf.XWPFTestDataSamples; -import static org.apache.poi.POITestCase.assertContains; +import org.junit.Test; /** * Tests for reading SmartTags from Word docx. - * - * @author Fabian Lange */ -public final class TestXWPFSmartTag extends TestCase { - +public final class TestXWPFSmartTag { + @Test public void testSmartTags() throws IOException { try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("smarttag-snippet.docx")) { XWPFParagraph p = doc.getParagraphArray(0); diff --git a/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java b/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java index ad3888d19e..e68cace494 100644 --- a/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java +++ b/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java @@ -17,36 +17,41 @@ package org.apache.poi.hdgf; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import org.apache.poi.POIDataSamples; import org.apache.poi.hdgf.extractor.VisioTextExtractor; import org.apache.poi.hdgf.streams.PointerContainingStream; import org.apache.poi.hdgf.streams.TrailerStream; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; -public final class TestHDGFCore extends TestCase { +public final class TestHDGFCore { private static POIDataSamples _dgTests = POIDataSamples.getDiagramInstance(); private POIFSFileSystem fs; private HDGFDiagram hdgf; private VisioTextExtractor textExtractor; - @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { fs = new POIFSFileSystem(_dgTests.openResourceAsStream("Test_Visio-Some_Random_Text.vsd")); } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { if (textExtractor != null) textExtractor.close(); if (hdgf != null) hdgf.close(); } - + @Test public void testCreate() throws Exception { hdgf = new HDGFDiagram(fs); } + @Test public void testTrailer() throws Exception { hdgf = new HDGFDiagram(fs); assertNotNull(hdgf); @@ -74,6 +79,7 @@ public final class TestHDGFCore extends TestCase { * Tests that we can open a problematic file, that used to * break with a negative chunk length */ + @Test public void testNegativeChunkLength() throws Exception { fs = new POIFSFileSystem(_dgTests.openResourceAsStream("NegativeChunkLength.vsd")); @@ -90,8 +96,8 @@ public final class TestHDGFCore extends TestCase { * Tests that we can open a problematic file that triggers * an ArrayIndexOutOfBoundsException when processing the * chunk commands. - * @throws Exception */ + @Test public void DISABLEDtestAIOOB() throws Exception { fs = new POIFSFileSystem(_dgTests.openResourceAsStream("44501.vsd")); @@ -99,6 +105,7 @@ public final class TestHDGFCore extends TestCase { assertNotNull(hdgf); } + @Test public void testV5() throws Exception { fs = new POIFSFileSystem(_dgTests.openResourceAsStream("v5_Connection_Types.vsd")); @@ -111,6 +118,7 @@ public final class TestHDGFCore extends TestCase { assertEquals("Static to Static\nDynamic to Static\nDynamic to Dynamic", text); } + @Test public void testV6NonUtf16LE() throws Exception { fs = new POIFSFileSystem(_dgTests.openResourceAsStream("v6-non-utf16le.vsd")); @@ -123,6 +131,7 @@ public final class TestHDGFCore extends TestCase { assertEquals("Table\n\n\nPropertySheet\n\n\n\nPropertySheetField", text); } + @Test public void testUtf16LE() throws Exception { fs = new POIFSFileSystem(_dgTests.openResourceAsStream("Test_Visio-Some_Random_Text.vsd")); diff --git a/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFLZW.java b/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFLZW.java index 7f89a050fb..5d23c1af5b 100644 --- a/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFLZW.java +++ b/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFLZW.java @@ -17,12 +17,15 @@ package org.apache.poi.hdgf; +import static org.junit.Assert.assertEquals; + import java.io.ByteArrayInputStream; -import junit.framework.TestCase; +import org.junit.Ignore; +import org.junit.Test; -public final class TestHDGFLZW extends TestCase { - public static final byte[] testTrailerComp = new byte[] { +public final class TestHDGFLZW { + public static final byte[] testTrailerComp = { 123, // *mask bit* -60, 2, -21, -16, // 3 @ 4093 @@ -38,7 +41,7 @@ public final class TestHDGFLZW extends TestCase { 21, // *mask bit* 1,3,5 9, -21, -16, // 3 @ 4093 - 103, + 103, -21, -16, // 3 @ 4093 34, -36, -1, // 18 @ 4078 @@ -72,7 +75,7 @@ public final class TestHDGFLZW extends TestCase { 1, 67, 85, 1, 81, -127, 0, -41, 0, 14, 6, 4, 17, 63, -63, 17, 68, 85, -65, 1, 30, -120, 0, 0, 42, 79, 18, 68, 126, -21, -16, -76, 69, 85, 1, 102, -119, 72, 37, 0, 97, 33 }; - public static final byte[] testTrailerDecomp = new byte[] { + public static final byte[] testTrailerDecomp = { -60, 2, 0, 0, 0, 1, 0, 0, -72, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 3, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 9, 0, 0, 0, 103, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -108,6 +111,7 @@ public final class TestHDGFLZW extends TestCase { 0, 0, 42, 1, 0, 0, 84, 0, 0, 0, 0, 0 }; + @Test public void testFromToInt() { byte b255 = -1; assertEquals(255, HDGFLZW.fromByte(b255)); @@ -135,6 +139,7 @@ public final class TestHDGFLZW extends TestCase { assertEquals(-128, HDGFLZW.fromInt( 128 )); } + @Test public void testCounts() throws Exception { assertEquals(339, testTrailerComp.length); assertEquals(632, testTrailerDecomp.length); @@ -155,6 +160,7 @@ public final class TestHDGFLZW extends TestCase { */ } + @Test public void testDecompress() throws Exception { assertEquals(339, testTrailerComp.length); assertEquals(632, testTrailerDecomp.length); @@ -176,6 +182,7 @@ public final class TestHDGFLZW extends TestCase { * Uses a part short enough that we agree with visio * on the best way to compress it */ + @Test public void testCompressMini() throws Exception { // first 11 bytes compressed = 12 bytes uncompressed byte[] sourceComp = new byte[11]; @@ -186,7 +193,7 @@ public final class TestHDGFLZW extends TestCase { // Compress it using our engine HDGFLZW lzw = new HDGFLZW(); byte[] comp = lzw.compress(new ByteArrayInputStream(sourceDecomp)); - + // Now decompress it again byte[] decomp = lzw.decompress(new ByteArrayInputStream(comp)); @@ -206,6 +213,7 @@ public final class TestHDGFLZW extends TestCase { /** * Tests that we can do several mask pages */ + @Test public void testCompressMidi() throws Exception { // First 12 -> 11 // Next 32 -> 13 @@ -217,11 +225,11 @@ public final class TestHDGFLZW extends TestCase { // Compress it using our engine HDGFLZW lzw = new HDGFLZW(); byte[] comp = lzw.compress(new ByteArrayInputStream(sourceDecomp)); - + // We should be 3 characters bigger, as // we split one compressed bit into two assertEquals(27, comp.length); - + // Now decompress it again byte[] decomp = lzw.decompress(new ByteArrayInputStream(comp)); @@ -237,28 +245,30 @@ public final class TestHDGFLZW extends TestCase { * Gets 160 bytes through then starts going wrong... * TODO Fix this */ - public void DISABLEDtestCompressFull() throws Exception { + @Test + @Ignore + public void testCompressFull() throws Exception { assertEquals(339, testTrailerComp.length); assertEquals(632, testTrailerDecomp.length); // Compress it using our engine HDGFLZW lzw = new HDGFLZW(); byte[] comp = lzw.compress(new ByteArrayInputStream(testTrailerDecomp)); - + // Now decompress it again byte[] decomp = lzw.decompress(new ByteArrayInputStream(comp)); // for(int i=0; i foundTextV = te.getTextAsVector(); @@ -76,6 +80,7 @@ public final class TestCruddyExtractor extends TestCase { } } + @Test public void testReadAsString() { // Extract the text as a String String foundText = te.getTextAsString(); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestAnimationInfoAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestAnimationInfoAtom.java index df3150c59e..e6de0b4952 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestAnimationInfoAtom.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestAnimationInfoAtom.java @@ -19,17 +19,18 @@ package org.apache.poi.hslf.record; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayOutputStream; -import junit.framework.TestCase; +import org.junit.Test; /** * Tests that {@link HeadersFootersAtom} works properly - * - * @author Yegor Kozlov */ -public final class TestAnimationInfoAtom extends TestCase { +public final class TestAnimationInfoAtom { // From a real file /* @@ -37,12 +38,13 @@ public final class TestAnimationInfoAtom extends TestCase { 00 00 00 */ - private final byte[] data = new byte[] { + private final byte[] data = { 0x01, 0x00, (byte)0xF1, 0x0F, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x04, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + @Test public void testRead() { AnimationInfoAtom record = new AnimationInfoAtom(data, 0, data.length); assertEquals(RecordTypes.AnimationInfoAtom.typeID, record.getRecordType()); @@ -61,6 +63,7 @@ public final class TestAnimationInfoAtom extends TestCase { assertEquals(0, record.getSlideCount()); } + @Test public void testWrite() throws Exception { AnimationInfoAtom record = new AnimationInfoAtom(data, 0, data.length); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -70,6 +73,7 @@ public final class TestAnimationInfoAtom extends TestCase { assertArrayEquals(data, b); } + @Test public void testNewRecord() throws Exception { AnimationInfoAtom record = new AnimationInfoAtom(); record.setDimColor(0x07000000); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCString.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCString.java index 4289c27710..51f8c2daa3 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCString.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCString.java @@ -18,29 +18,34 @@ package org.apache.poi.hslf.record; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import java.io.ByteArrayOutputStream; +import org.junit.Test; + /** * Tests that CString works properly - * - * @author Nick Burch (nick at torchbox dot com) */ -public final class TestCString extends TestCase { +public final class TestCString { // From a real file - private final byte[] data_a = new byte[] { 0, 0, 0xBA-256, 0x0f, 0x10, 0, 0, 0, - 0x48, 00, 0x6F, 00, 0x67, 00, 0x77, 00, - 0x61, 00, 0x72, 00, 0x74, 00, 0x73, 00 }; + private final byte[] data_a = { 0, 0, 0xBA-256, 0x0f, 0x10, 0, 0, 0, + 0x48, 0, 0x6F, 0, 0x67, 0, 0x77, 0, + 0x61, 0, 0x72, 0, 0x74, 0, 0x73, 0 }; private final byte[] data_b = new byte[] { 0x10, 0, 0xBA-256, 0x0f, 0x10, 0, 0, 0, - 0x43, 00, 0x6F, 00, 0x6D, 00, 0x6D, 00, - 0x65, 00, 0x6E, 00, 0x74, 00, 0x73, 00 }; + 0x43, 0, 0x6F, 0, 0x6D, 0, 0x6D, 0, + 0x65, 0, 0x6E, 0, 0x74, 0, 0x73, 0 }; + @Test public void testRecordType() { CString ca = new CString(data_a, 0, data_a.length); - assertEquals(4026l, ca.getRecordType()); + assertEquals(4026L, ca.getRecordType()); CString cb = new CString(data_b, 0, data_a.length); - assertEquals(4026l, cb.getRecordType()); + assertEquals(4026L, cb.getRecordType()); } + + @Test public void testCount() { CString ca = new CString(data_a, 0, data_a.length); assertEquals(0, ca.getOptions()); @@ -51,6 +56,7 @@ public final class TestCString extends TestCase { assertEquals(28, ca.getOptions()); } + @Test public void testText() { CString ca = new CString(data_a, 0, data_a.length); assertEquals("Hogwarts", ca.getText()); @@ -61,6 +67,7 @@ public final class TestCString extends TestCase { assertEquals("FooBar", ca.getText()); } + @Test public void testWrite() throws Exception { CString ca = new CString(data_a, 0, data_a.length); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -84,6 +91,7 @@ public final class TestCString extends TestCase { } // Turn data_a into data_b + @Test public void testChange() throws Exception { CString ca = new CString(data_a, 0, data_a.length); ca.setText("Comments"); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestColorSchemeAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestColorSchemeAtom.java index 9e0af0d9d5..c4b6f9ab7f 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestColorSchemeAtom.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestColorSchemeAtom.java @@ -18,28 +18,31 @@ package org.apache.poi.hslf.record; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + import java.io.ByteArrayOutputStream; +import org.junit.Test; + /** * Tests that ColorSchemAtom works properly - * - * @author Nick Burch (nick at torchbox dot com) */ -public final class TestColorSchemeAtom extends TestCase { +public final class TestColorSchemeAtom { // From a real file - private final byte[] data_a = new byte[] { 60, 0, 0xF0-256, 0x07, 0x20, 0, 0, 0, - 0xFF-256, 0xFF-256, 0xFF-256, 00, 00, 00, 00, 00, - 0x80-256, 0x80-256, 0x80-256, 00, 00, 00, 00, 00, - 0xBB-256, 0xE0-256, 0xE3-256, 00, 0x33, 0x33, 0x99-256, 00, - 00, 0x99-256, 0x99-256, 00, 0x99-256, 0xCC-256, 00, 00 + private final byte[] data_a = { 60, 0, 0xF0-256, 0x07, 0x20, 0, 0, 0, + 0xFF-256, 0xFF-256, 0xFF-256, 0, 0, 0, 0, 0, + 0x80-256, 0x80-256, 0x80-256, 0, 0, 0, 0, 0, + 0xBB-256, 0xE0-256, 0xE3-256, 0, 0x33, 0x33, 0x99-256, 0, + 0, 0x99-256, 0x99-256, 0, 0x99-256, 0xCC-256, 0, 0 }; + @Test public void testRecordType() { ColorSchemeAtom csa = new ColorSchemeAtom(data_a,0,data_a.length); - assertEquals(2032l, csa.getRecordType()); + assertEquals(2032L, csa.getRecordType()); } + @Test public void testToRGB() { byte[] rgb = ColorSchemeAtom.splitRGB(3669760); @@ -49,6 +52,7 @@ public final class TestColorSchemeAtom extends TestCase { assertEquals(55, rgb[2]); } + @Test public void testFromRGB() { byte[] rgb_a = new byte[] { 0, 255-256, 55 }; byte[] rgb_b = new byte[] { 255-256, 127, 79 }; @@ -60,6 +64,7 @@ public final class TestColorSchemeAtom extends TestCase { assertEquals( 5210111, ColorSchemeAtom.joinRGB( rgb_b[0], rgb_b[1], rgb_b[2] ) ); } + @Test public void testRGBs() { ColorSchemeAtom csa = new ColorSchemeAtom(data_a,0,data_a.length); @@ -73,6 +78,7 @@ public final class TestColorSchemeAtom extends TestCase { assertEquals( 52377 , csa.getAccentAndFollowingHyperlinkColourRGB() ); } + @Test public void testWrite() throws Exception { ColorSchemeAtom csa = new ColorSchemeAtom(data_a,0,data_a.length); ByteArrayOutputStream baos = new ByteArrayOutputStream(); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocument.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocument.java index e9134eea48..fa576ced48 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocument.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocument.java @@ -17,25 +17,28 @@ package org.apache.poi.hslf.record; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; -import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl; -import org.apache.poi.poifs.filesystem.*; import org.apache.poi.POIDataSamples; +import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.junit.Before; +import org.junit.Test; /** * Tests that Document works properly (Also tests Environment while we're at it) - * - * @author Nick Burch (nick at torchbox dot com) */ -public final class TestDocument extends TestCase { - // HSLFSlideShow primed on the test data - private final HSLFSlideShowImpl ss; - // POIFS primed on the test data - private final POIFSFileSystem pfs; +public final class TestDocument { + private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); - public TestDocument() throws Exception { - POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); + // HSLFSlideShow primed on the test data + private HSLFSlideShowImpl ss; + // POIFS primed on the test data + private POIFSFileSystem pfs; + + @Before + public void setup() throws Exception { pfs = new POIFSFileSystem(slTests.openResourceAsStream("basic_test_ppt_file.ppt")); ss = new HSLFSlideShowImpl(pfs); } @@ -50,11 +53,13 @@ public final class TestDocument extends TestCase { throw new IllegalStateException("No Document record found"); } + @Test public void testRecordType() { Document dr = getDocRecord(); assertEquals(1000, dr.getRecordType()); } + @Test public void testChildRecords() { Document dr = getDocRecord(); assertNotNull(dr.getDocumentAtom()); @@ -68,6 +73,7 @@ public final class TestDocument extends TestCase { assertNotNull(dr.getSlideListWithTexts()[2]); } + @Test public void testEnvironment() { Document dr = getDocRecord(); Environment env = dr.getEnvironment(); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentAtom.java index 82ec7bec51..73aea573c0 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentAtom.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentAtom.java @@ -18,46 +18,59 @@ package org.apache.poi.hslf.record; -import junit.framework.TestCase; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.io.ByteArrayOutputStream; +import org.junit.Test; + /** * Tests that DocumentAtom works properly - * - * @author Nick Burch (nick at torchbox dot com) */ -public final class TestDocumentAtom extends TestCase { +public final class TestDocumentAtom { // From a real file - private final byte[] data_a = new byte[] { 1, 0, 0xE9-256, 3, 0x28, 0, 0, 0, + private final byte[] data_a = { 1, 0, 0xE9-256, 3, 0x28, 0, 0, 0, 0x80-256, 0x16, 0, 0, 0xE0-256, 0x10, 0, 0, 0xE0-256, 0x10, 0, 0, 0x80-256, 0x16, 0, 0, 0x05, 0, 0, 0, 0x0A, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 }; + @Test public void testRecordType() { DocumentAtom da = new DocumentAtom(data_a, 0, data_a.length); assertEquals(1001l, da.getRecordType()); } + + @Test public void testSizeAndZoom() { DocumentAtom da = new DocumentAtom(data_a, 0, data_a.length); - assertEquals(5760l, da.getSlideSizeX()); - assertEquals(4320l, da.getSlideSizeY()); - assertEquals(4320l, da.getNotesSizeX()); - assertEquals(5760l, da.getNotesSizeY()); + assertEquals(5760L, da.getSlideSizeX()); + assertEquals(4320L, da.getSlideSizeY()); + assertEquals(4320L, da.getNotesSizeX()); + assertEquals(5760L, da.getNotesSizeY()); - assertEquals(5l, da.getServerZoomFrom()); - assertEquals(10l, da.getServerZoomTo()); + assertEquals(5L, da.getServerZoomFrom()); + assertEquals(10L, da.getServerZoomTo()); } + + @Test public void testMasterPersist() { DocumentAtom da = new DocumentAtom(data_a, 0, data_a.length); - assertEquals(2l, da.getNotesMasterPersist()); - assertEquals(0l, da.getHandoutMasterPersist()); + assertEquals(2L, da.getNotesMasterPersist()); + assertEquals(0L, da.getHandoutMasterPersist()); } + + @Test public void testSlideDetails() { DocumentAtom da = new DocumentAtom(data_a, 0, data_a.length); assertEquals(1, da.getFirstSlideNum()); assertEquals(0, da.getSlideSizeType()); } + + @Test public void testBooleans() { DocumentAtom da = new DocumentAtom(data_a, 0, data_a.length); assertFalse(da.getSaveWithFonts()); @@ -66,15 +79,11 @@ public final class TestDocumentAtom extends TestCase { assertTrue(da.getShowComments()); } + @Test public void testWrite() throws Exception { DocumentAtom da = new DocumentAtom(data_a, 0, data_a.length); ByteArrayOutputStream baos = new ByteArrayOutputStream(); da.writeOut(baos); - byte[] b = baos.toByteArray(); - - assertEquals(data_a.length, b.length); - for(int i=0; i */ - private final byte[] data = new byte[] { + private final byte[] data = { 0x0F, 0x00, (byte)0xEE, 0x0F, (byte)0xDA, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)0xFB, 0x0F, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, (byte)0xC3, 0x0F, 0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, (byte)0x96, 0x13, 0x00, @@ -71,6 +71,7 @@ public final class TestExControl extends TestCase { 0x65, 0x00, 0x63, 0x00, 0x74, 0x00 }; + @Test public void testRead() { ExControl record = new ExControl(data, 0, data.length); assertEquals(RecordTypes.ExControl.typeID, record.getRecordType()); @@ -89,15 +90,15 @@ public final class TestExControl extends TestCase { assertEquals("Shockwave Flash Object", record.getClipboardName()); } + @Test public void testWrite() throws Exception { ExControl record = new ExControl(data, 0, data.length); ByteArrayOutputStream baos = new ByteArrayOutputStream(); record.writeOut(baos); - byte[] b = baos.toByteArray(); - - assertArrayEquals(data, b); + assertArrayEquals(data, baos.toByteArray()); } + @Test public void testNewRecord() throws Exception { ExControl record = new ExControl(); ExControlAtom ctrl = record.getExControlAtom(); @@ -117,9 +118,6 @@ public final class TestExControl extends TestCase { ByteArrayOutputStream baos = new ByteArrayOutputStream(); record.writeOut(baos); - byte[] b = baos.toByteArray(); - - assertEquals(data.length, b.length); - assertArrayEquals(data, b); + assertArrayEquals(data, baos.toByteArray()); } } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlinkAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlinkAtom.java index eba79e05a6..f7ed7acf9e 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlinkAtom.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlinkAtom.java @@ -18,30 +18,34 @@ package org.apache.poi.hslf.record; -import junit.framework.TestCase; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + import java.io.ByteArrayOutputStream; +import org.junit.Test; + /** * Tests that ExHyperlinkAtom works properly. - * - * @author Nick Burch (nick at torchbox dot com) */ -public class TestExHyperlinkAtom extends TestCase { +public class TestExHyperlinkAtom { // From a real file private final byte[] data_a = new byte[] { - 00, 00, 0xD3-256, 0x0F, 04, 00, 00, 00, - 01, 00, 00, 00 + 0, 0, 0xD3-256, 0x0F, 4, 0, 0, 0, + 1, 0, 0, 0 }; private final byte[] data_b = new byte[] { - 00, 00, 0xD3-256, 0x0F, 04, 00, 00, 00, - 04, 00, 00, 00 + 0, 0, 0xD3-256, 0x0F, 4, 0, 0, 0, + 4, 0, 0, 0 }; + @Test public void testRecordType() { ExHyperlinkAtom eha = new ExHyperlinkAtom(data_a, 0, data_a.length); - assertEquals(4051l, eha.getRecordType()); + assertEquals(4051L, eha.getRecordType()); } + @Test public void testGetNumber() { ExHyperlinkAtom eha = new ExHyperlinkAtom(data_a, 0, data_a.length); ExHyperlinkAtom ehb = new ExHyperlinkAtom(data_b, 0, data_b.length); @@ -50,19 +54,16 @@ public class TestExHyperlinkAtom extends TestCase { assertEquals(4, ehb.getNumber()); } + @Test public void testWrite() throws Exception { ExHyperlinkAtom eha = new ExHyperlinkAtom(data_a, 0, data_a.length); ByteArrayOutputStream baos = new ByteArrayOutputStream(); eha.writeOut(baos); - byte[] b = baos.toByteArray(); - - assertEquals(data_a.length, b.length); - for(int i=0; iTestTxMasterStyleAtom record. * Check master style for the empty ppt which is created * by the default constructor of SlideShow - * - * @author Yegor Kozlov */ -public final class TestTxMasterStyleAtom extends TestCase { - protected HSLFSlideShow _ppt; +public final class TestTxMasterStyleAtom { + private HSLFSlideShow _ppt; - @Override + @Before public void setUp() { _ppt = new HSLFSlideShow(); } + @Test public void testDefaultStyles() { TxMasterStyleAtom[] txmaster = getMasterStyles(); for (final TxMasterStyleAtom atom : txmaster) { final int txtype = atom.getTextType(); - switch (TextPlaceholder.fromNativeId(txtype)){ + TextPlaceholder tp = TextPlaceholder.fromNativeId(txtype); + assertNotNull(tp); + switch (tp) { case TITLE: checkTitleType(atom); break; @@ -61,11 +67,8 @@ public final class TestTxMasterStyleAtom extends TestCase { checkOtherType(atom); break; case CENTER_BODY: - break; case CENTER_TITLE: - break; case HALF_BODY: - break; case QUARTER_BODY: break; default: @@ -200,7 +203,7 @@ public final class TestTxMasterStyleAtom extends TestCase { * Collect all TxMasterStyleAtom records contained in the supplied slide show. * There must be a TxMasterStyleAtom per each type of text defined in TextHeaderAtom */ - protected TxMasterStyleAtom[] getMasterStyles(){ + private TxMasterStyleAtom[] getMasterStyles(){ List lst = new ArrayList<>(); Record[] coreRecs = _ppt.getMostRecentCoreRecords(); @@ -221,13 +224,12 @@ public final class TestTxMasterStyleAtom extends TestCase { Record[] rec = doc.getEnvironment().getChildRecords(); for (final Record atom : rec) { if (atom instanceof TxMasterStyleAtom) { - if (txstyle != null) fail("Document.Environment must contain 1 TxMasterStyleAtom"); + assertNull("Document.Environment must contain 1 TxMasterStyleAtom", txstyle); txstyle = (TxMasterStyleAtom)atom; } } - if (txstyle == null) { - throw new AssertionFailedError("TxMasterStyleAtom not found in Document.Environment"); - } + + assertNotNull("TxMasterStyleAtom not found in Document.Environment", txstyle); assertEquals("Document.Environment must contain TxMasterStyleAtom with type=TextHeaderAtom.OTHER_TYPE", TextPlaceholder.OTHER.nativeId, txstyle.getTextType()); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestUserEditAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestUserEditAtom.java index fca70287c0..85fd287b39 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestUserEditAtom.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestUserEditAtom.java @@ -18,25 +18,30 @@ package org.apache.poi.hslf.record; -import junit.framework.TestCase; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + import java.io.ByteArrayOutputStream; +import org.junit.Test; + /** * Tests that UserEditAtom works properly - * - * @author Nick Burch (nick at torchbox dot com) */ -public final class TestUserEditAtom extends TestCase { +public final class TestUserEditAtom { // From a real file private final byte[] data_a = new byte[] { 0, 0, 0xF5-256, 0x0F, 0x1C, 0, 0, 0, - 00, 01, 00, 00, 0xD9-256, 18, 00, 03, - 00, 00, 00, 00, 00, 0x18, 00, 00, 01, 00, 00, 00, - 05, 00, 00, 00, 01, 00, 0xF6-256, 77 }; + 0, 1, 0, 0, 0xD9-256, 18, 0, 3, + 0, 0, 0, 0, 0, 0x18, 0, 0, 1, 0, 0, 0, + 5, 0, 0, 0, 1, 0, 0xF6-256, 77 }; + @Test public void testRecordType() { UserEditAtom uea = new UserEditAtom(data_a, 0, data_a.length); - assertEquals(4085l, uea.getRecordType()); + assertEquals(4085L, uea.getRecordType()); } + + @Test public void testFlags() { UserEditAtom uea = new UserEditAtom(data_a, 0, data_a.length); @@ -49,15 +54,11 @@ public final class TestUserEditAtom extends TestCase { assertEquals((short)1, uea.getLastViewType() ); } + @Test public void testWrite() throws Exception { UserEditAtom uea = new UserEditAtom(data_a, 0, data_a.length); ByteArrayOutputStream baos = new ByteArrayOutputStream(); uea.writeOut(baos); - byte[] b = baos.toByteArray(); - - assertEquals(data_a.length, b.length); - for(int i=0; iHTML автоматически", ascii_cp1251_lcid1049.getHtmlBody()); - + assertEquals("Subject öäü Subject", ascii_utf_8_cp1252_lcid1031.getSubject()); assertEquals("Body öäü Body", ascii_utf_8_cp1252_lcid1031.getTextBody()); assertNull(ascii_utf_8_cp1252_lcid1031.getHtmlBody()); - + assertEquals("Subject öäü Subject", ascii_utf_8_cp1252_lcid1031_html.getSubject()); assertEquals("Body öäü Body", ascii_utf_8_cp1252_lcid1031_html.getTextBody()); assertEquals("HTML öäü", ascii_utf_8_cp1252_lcid1031_html.getHtmlBody()); - + assertEquals("Subject öäü Subject", htmlbodybinary_cp1251.getSubject()); assertNull(htmlbodybinary_cp1251.getTextBody()); assertEquals("HTML автоматически", htmlbodybinary_cp1251.getHtmlBody()); - + assertEquals("Subject öäü Subject", htmlbodybinary_utf_8.getSubject()); assertNull(htmlbodybinary_utf_8.getTextBody()); assertEquals("HTML öäü", htmlbodybinary_utf_8.getHtmlBody()); diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java index 860f1f5e6c..ffeab21c8c 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java @@ -19,34 +19,38 @@ package org.apache.poi.hsmf; import static org.apache.poi.POITestCase.assertContains; import static org.apache.poi.POITestCase.assertStartsWith; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.IOException; -import junit.framework.TestCase; - import org.apache.poi.POIDataSamples; import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; +import org.junit.Before; +import org.junit.Test; /** - * Tests to verify that we can perform basic opperations on + * Tests to verify that we can perform basic opperations on * a range of files */ -public final class TestBasics extends TestCase { - private final MAPIMessage simple; - private final MAPIMessage quick; - private final MAPIMessage outlook30; - private final MAPIMessage attachments; - private final MAPIMessage noRecipientAddress; - private final MAPIMessage unicode; - private final MAPIMessage cyrillic; - private final MAPIMessage chinese; +public final class TestBasics { + private MAPIMessage simple; + private MAPIMessage quick; + private MAPIMessage outlook30; + private MAPIMessage attachments; + private MAPIMessage noRecipientAddress; + private MAPIMessage unicode; + private MAPIMessage cyrillic; + private MAPIMessage chinese; /** * Initialize this test, load up the blank.msg mapi message. - * @throws Exception */ - public TestBasics() throws IOException { + @Before + public void setup() throws IOException { POIDataSamples samples = POIDataSamples.getHSMFInstance(); simple = new MAPIMessage(samples.openResourceAsStream("simple_test_msg.msg")); quick = new MAPIMessage(samples.openResourceAsStream("quick.msg")); @@ -61,18 +65,19 @@ public final class TestBasics extends TestCase { /** * Can we always get the recipient's email? */ + @Test public void testRecipientEmail() throws Exception { assertEquals("travis@overwrittenstack.com", simple.getRecipientEmailAddress()); assertEquals("kevin.roast@alfresco.org", quick.getRecipientEmailAddress()); assertEquals("nicolas1.23456@free.fr", attachments.getRecipientEmailAddress()); - + // This one has lots... assertEquals(18, outlook30.getRecipientEmailAddressList().length); assertEquals("shawn.bohn@pnl.gov; gus.calapristi@pnl.gov; Richard.Carter@pnl.gov; " + "barb.cheney@pnl.gov; nick.cramer@pnl.gov; vern.crow@pnl.gov; Laura.Curtis@pnl.gov; " + "julie.dunkle@pnl.gov; david.gillen@pnl.gov; michelle@pnl.gov; Jereme.Haack@pnl.gov; " + "Michelle.Hart@pnl.gov; ranata.johnson@pnl.gov; grant.nakamura@pnl.gov; " + - "debbie.payne@pnl.gov; stuart.rose@pnl.gov; randall.scarberry@pnl.gov; Leigh.Williams@pnl.gov", + "debbie.payne@pnl.gov; stuart.rose@pnl.gov; randall.scarberry@pnl.gov; Leigh.Williams@pnl.gov", outlook30.getRecipientEmailAddress() ); } @@ -80,6 +85,7 @@ public final class TestBasics extends TestCase { /** * Test subject */ + @Test public void testSubject() throws Exception { assertEquals("test message", simple.getSubject()); assertEquals("Test the content transformer", quick.getSubject()); @@ -90,25 +96,26 @@ public final class TestBasics extends TestCase { /** * Test message headers */ + @Test public void testHeaders() throws Exception { // Simple email first assertEquals(26, simple.getHeaders().length); assertStartsWith(simple.getHeaders()[0], "Return-path:"); assertEquals("Envelope-to: travis@overwrittenstack.com", simple.getHeaders()[1]); assertStartsWith(simple.getHeaders()[25], "X-Antivirus-Scanner: Clean"); - + // Quick doesn't have them try { quick.getHeaders(); fail("expected ChunkNotFoundException"); } catch(ChunkNotFoundException e) {} - + // Attachments doesn't have them try { attachments.getHeaders(); fail("expected ChunkNotFoundException"); } catch(ChunkNotFoundException e) {} - + // Outlook30 has some assertEquals(33, outlook30.getHeaders().length); assertStartsWith(outlook30.getHeaders()[0], "Microsoft Mail Internet Headers"); @@ -116,6 +123,7 @@ public final class TestBasics extends TestCase { assertStartsWith(outlook30.getHeaders()[32], "\t\"Williams"); // May need better parsing in future } + @Test public void testBody() throws Exception { // Messages may have their bodies saved as plain text, html, and/or rtf. assertEquals("This is a test message.", simple.getTextBody()); @@ -123,17 +131,17 @@ public final class TestBasics extends TestCase { assertStartsWith(outlook30.getTextBody(), "I am shutting down the IN-SPIRE servers now for 30ish minutes.\r\n\r\n"); assertStartsWith(attachments.getTextBody(), "contenu\r\n\r\n"); assertStartsWith(unicode.getTextBody(), "..less you are Nick....."); - + // outlook30 has chunks for all 3 body formats // Examine one of the paragraphs is present in all 3 formats, surrounded by markup tags String text = "I am shutting down the IN-SPIRE servers now for 30ish minutes."; assertStartsWith(outlook30.getTextBody(), text + "\r\n\r\n"); assertEquals(850494485, outlook30.getTextBody().hashCode()); - + assertStartsWith(outlook30.getHtmlBody(), "\r\n\r\n"); assertContains(outlook30.getHtmlBody(), "

" + text + "

"); assertEquals(-654938715, outlook30.getHtmlBody().hashCode()); - + assertStartsWith(outlook30.getRtfBody(), "{\\rtf1\\adeflang1025\\ansi\\ansicpg1252\\uc1\\adeff3150"); assertContains(outlook30.getRtfBody(), "{\\rtlch\\fcs1 \\af31507 \\ltrch\\fcs0 \\cf0\\insrsid5003910 " + text + "\r\n\\par \r\n\\par"); assertEquals(891652290, outlook30.getRtfBody().hashCode()); @@ -142,7 +150,8 @@ public final class TestBasics extends TestCase { /** * Test attachments */ - public void testAttachments() throws Exception { + @Test + public void testAttachments() { assertEquals(0, simple.getAttachmentFiles().length); assertEquals(0, quick.getAttachmentFiles().length); assertEquals(0, outlook30.getAttachmentFiles().length); @@ -153,6 +162,7 @@ public final class TestBasics extends TestCase { * Test missing chunks. * Use a file with no HTML body */ + @Test public void testMissingChunks() throws Exception { assertFalse(attachments.isReturnNullOnMissingChunk()); @@ -166,9 +176,9 @@ public final class TestBasics extends TestCase { attachments.setReturnNullOnMissingChunk(true); assertNull(attachments.getHtmlBody()); - + attachments.setReturnNullOnMissingChunk(false); - + try { attachments.getHtmlBody(); fail("expected ChunkNotFoundException"); @@ -181,6 +191,7 @@ public final class TestBasics extends TestCase { * More missing chunk testing, this time for * missing recipient email address */ + @Test public void testMissingAddressChunk() throws Exception { assertFalse(noRecipientAddress.isReturnNullOnMissingChunk()); @@ -196,66 +207,68 @@ public final class TestBasics extends TestCase { } catch(ChunkNotFoundException e) { // Good } - + noRecipientAddress.setReturnNullOnMissingChunk(true); - + noRecipientAddress.getRecipientEmailAddress(); noRecipientAddress.getRecipientEmailAddressList(); assertEquals("", noRecipientAddress.getRecipientEmailAddress()); assertEquals(1, noRecipientAddress.getRecipientEmailAddressList().length); assertNull(noRecipientAddress.getRecipientEmailAddressList()[0]); - + // Check a few other bits too assertEquals("Microsoft Outlook 2003 Team", noRecipientAddress.getDisplayFrom()); assertEquals("New Outlook User", noRecipientAddress.getDisplayTo()); - + noRecipientAddress.setReturnNullOnMissingChunk(false); } /** * Test the 7 bit detection */ - public void test7BitDetection() throws Exception { + @Test + public void test7BitDetection() { assertFalse(unicode.has7BitEncodingStrings()); assertTrue(simple.has7BitEncodingStrings()); assertTrue(chinese.has7BitEncodingStrings()); assertTrue(cyrillic.has7BitEncodingStrings()); } - + /** * We default to CP1252, but can sometimes do better * if needed. * This file is really CP1251, according to the person * who submitted it in bug #49441 */ + @Test public void testEncoding() throws Exception { assertEquals(2, cyrillic.getRecipientDetailsChunks().length); assertEquals("CP1252", cyrillic.getRecipientDetailsChunks()[0].recipientDisplayNameChunk.get7BitEncoding()); assertEquals("CP1252", cyrillic.getRecipientDetailsChunks()[1].recipientDisplayNameChunk.get7BitEncoding()); - + cyrillic.guess7BitEncoding(); - + assertEquals("Cp1251", cyrillic.getRecipientDetailsChunks()[0].recipientDisplayNameChunk.get7BitEncoding()); assertEquals("Cp1251", cyrillic.getRecipientDetailsChunks()[1].recipientDisplayNameChunk.get7BitEncoding()); - + // Override it, check it's taken cyrillic.set7BitEncoding("UTF-8"); assertEquals("UTF-8", cyrillic.getRecipientDetailsChunks()[0].recipientDisplayNameChunk.get7BitEncoding()); assertEquals("UTF-8", cyrillic.getRecipientDetailsChunks()[1].recipientDisplayNameChunk.get7BitEncoding()); - - + + // Check with a file that has no headers try { chinese.getHeaders(); fail("File doesn't have headers!"); } catch(ChunkNotFoundException e) {} - + String html = chinese.getHtmlBody(); assertTrue("Charset not found:\n" + html, html.contains("text/html; charset=big5")); - + // Defaults to CP1251 assertEquals("CP1252", chinese.getRecipientDetailsChunks()[0].recipientDisplayNameChunk.get7BitEncoding()); - + // But after guessing goes to the correct one, cp950 (Windows Traditional Chinese) chinese.guess7BitEncoding(); assertEquals("cp950", chinese.getRecipientDetailsChunks()[0].recipientDisplayNameChunk.get7BitEncoding()); diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestBlankFileRead.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestBlankFileRead.java index 0a9a7af8ed..256ed5ced3 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/TestBlankFileRead.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestBlankFileRead.java @@ -17,104 +17,97 @@ package org.apache.poi.hsmf; +import static org.junit.Assert.assertEquals; + import java.io.IOException; -import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; import org.apache.poi.POIDataSamples; - -import junit.framework.TestCase; +import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; +import org.junit.Before; +import org.junit.Test; /** * Tests to verify that the library can read blank msg files. */ -public final class TestBlankFileRead extends TestCase { - private final MAPIMessage mapiMessage; +public final class TestBlankFileRead { + private MAPIMessage mapiMessage; /** * Initialize this test, load up the blank.msg mapi message. */ - public TestBlankFileRead() throws IOException { + @Before + public void setup() throws IOException { POIDataSamples samples = POIDataSamples.getHSMFInstance(); - this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("blank.msg")); + mapiMessage = new MAPIMessage(samples.openResourceAsStream("blank.msg")); } /** * Check if we can read the body of the blank message, we expect "". */ - public void testReadBody() { - try { - mapiMessage.getTextBody(); - } catch(ChunkNotFoundException exp) { - return; - } - - TestCase.fail("Should have thrown a ChunkNotFoundException but didn't"); + @Test(expected = ChunkNotFoundException.class) + public void testReadBody() throws ChunkNotFoundException { + mapiMessage.getTextBody(); } /** * Test to see if we can read the CC Chunk. */ + @Test public void testReadDisplayCC() throws ChunkNotFoundException { String obtained = mapiMessage.getDisplayCC(); String expected = ""; - TestCase.assertEquals(expected, obtained); + assertEquals(expected, obtained); } /** * Test to see if we can read the CC Chunk. */ + @Test public void testReadDisplayTo() throws ChunkNotFoundException { String obtained = mapiMessage.getDisplayTo(); String expected = ""; - TestCase.assertEquals(expected, obtained); + assertEquals(expected, obtained); } /** * Test to see if we can read the FROM Chunk. */ - public void testReadDisplayFrom() { - try { - mapiMessage.getDisplayFrom(); - } catch(ChunkNotFoundException exp) { - return; - } - - TestCase.fail("Should have thrown a ChunkNotFoundException but didn't"); + @Test(expected = ChunkNotFoundException.class) + public void testReadDisplayFrom() throws ChunkNotFoundException { + mapiMessage.getDisplayFrom(); } /** * Test to see if we can read the CC Chunk. */ + @Test public void testReadDisplayBCC() throws ChunkNotFoundException { String obtained = mapiMessage.getDisplayBCC(); String expected = ""; - TestCase.assertEquals(expected, obtained); + assertEquals(expected, obtained); } /** * Check if we can read the subject line of the blank message, we expect "" */ + @Test public void testReadSubject() throws Exception { String obtained = mapiMessage.getSubject(); - TestCase.assertEquals("", obtained); + assertEquals("", obtained); } /** * Check if we can read the subject line of the blank message, we expect "" */ - public void testReadConversationTopic() { - try { - mapiMessage.getConversationTopic(); - } catch(ChunkNotFoundException exp) { - return; - } - TestCase.fail("We shouldn't have a ConversationTopic node on the blank.msg file."); + @Test(expected = ChunkNotFoundException.class) + public void testReadConversationTopic() throws ChunkNotFoundException { + mapiMessage.getConversationTopic(); } } diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunk.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunk.java index fc218b9125..e82f0b5dd0 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunk.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunk.java @@ -17,41 +17,45 @@ package org.apache.poi.hsmf; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import java.io.IOException; - -import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; -import org.apache.poi.POIDataSamples; - import java.util.Calendar; -import junit.framework.TestCase; +import org.apache.poi.POIDataSamples; +import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; +import org.junit.Before; +import org.junit.Test; -public final class TestMessageSubmissionChunk extends TestCase { - - private final MAPIMessage mapiMessageExtraHyphenSubmissionChunk; - private final MAPIMessage mapiMessageNormalSubmissionChunk; +public final class TestMessageSubmissionChunk { + + private MAPIMessage mapiMessageExtraHyphenSubmissionChunk; + private MAPIMessage mapiMessageNormalSubmissionChunk; /** * Initialise this test, load up the test messages. - * @throws Exception */ - public TestMessageSubmissionChunk() throws IOException { + @Before + public void setup() throws IOException { POIDataSamples samples = POIDataSamples.getHSMFInstance(); this.mapiMessageExtraHyphenSubmissionChunk = new MAPIMessage(samples.openResourceAsStream("message_extra_hyphen_submission_chunk.msg")); this.mapiMessageNormalSubmissionChunk = new MAPIMessage(samples.openResourceAsStream("message_normal_submission_chunk.msg")); } + @Test public void testReadMessageDateExtraHyphenSubmissionChunk() throws ChunkNotFoundException { final Calendar date = mapiMessageExtraHyphenSubmissionChunk.getMessageDate(); - TestCase.assertNotNull(date); + assertNotNull(date); final int year = date.get(Calendar.YEAR); - TestCase.assertEquals(2007, year); + assertEquals(2007, year); } + @Test public void testReadMessageDateNormalSubmissionChunk() throws ChunkNotFoundException { final Calendar date = mapiMessageNormalSubmissionChunk.getMessageDate(); - TestCase.assertNotNull(date); + assertNotNull(date); final int year = date.get(Calendar.YEAR); - TestCase.assertEquals(2007, year); + assertEquals(2007, year); } } diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunkY2KRead.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunkY2KRead.java index 410356b290..bec75504c1 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunkY2KRead.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunkY2KRead.java @@ -17,50 +17,54 @@ package org.apache.poi.hsmf; +import static org.junit.Assert.assertEquals; + import java.io.IOException; - -import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; -import org.apache.poi.POIDataSamples; - import java.util.Calendar; -import junit.framework.TestCase; +import org.apache.poi.POIDataSamples; +import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; +import org.junit.Before; +import org.junit.Test; -public final class TestMessageSubmissionChunkY2KRead extends TestCase { - - private final MAPIMessage mapiMessage1979; - private final MAPIMessage mapiMessage1980; - private final MAPIMessage mapiMessage1981; +public final class TestMessageSubmissionChunkY2KRead { + + private MAPIMessage mapiMessage1979; + private MAPIMessage mapiMessage1980; + private MAPIMessage mapiMessage1981; /** * Initialise this test, load up the three test messages. - * @throws Exception */ - public TestMessageSubmissionChunkY2KRead() throws IOException { + @Before + public void setup() throws IOException { POIDataSamples samples = POIDataSamples.getHSMFInstance(); - this.mapiMessage1979 = new MAPIMessage(samples.openResourceAsStream("message_1979.msg")); - this.mapiMessage1980 = new MAPIMessage(samples.openResourceAsStream("message_1980.msg")); - this.mapiMessage1981 = new MAPIMessage(samples.openResourceAsStream("message_1981.msg")); + mapiMessage1979 = new MAPIMessage(samples.openResourceAsStream("message_1979.msg")); + mapiMessage1980 = new MAPIMessage(samples.openResourceAsStream("message_1980.msg")); + mapiMessage1981 = new MAPIMessage(samples.openResourceAsStream("message_1981.msg")); } // 1979 is one year before our pivot year (so this is an expected "failure") + @Test public void testReadMessageDate1979() throws ChunkNotFoundException { final Calendar date = mapiMessage1979.getMessageDate(); final int year = date.get(Calendar.YEAR); - TestCase.assertEquals(2079, year); + assertEquals(2079, year); } // 1980 is our pivot year (so this is an expected "failure") + @Test public void testReadMessageDate1980() throws ChunkNotFoundException { final Calendar date = mapiMessage1980.getMessageDate(); final int year = date.get(Calendar.YEAR); - TestCase.assertEquals(2080, year); + assertEquals(2080, year); } // 1981 is one year after our pivot year (so this starts working) + @Test public void testReadMessageDate1981() throws ChunkNotFoundException { final Calendar date = mapiMessage1981.getMessageDate(); final int year = date.get(Calendar.YEAR); - TestCase.assertEquals(1981, year); + assertEquals(1981, year); } } diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java index 126a265ab4..ce8527f665 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java @@ -17,45 +17,47 @@ package org.apache.poi.hsmf; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.io.IOException; -import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; import org.apache.poi.POIDataSamples; - -import junit.framework.TestCase; +import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; +import org.junit.Before; +import org.junit.Test; /** * Tests to verify that we can still work on the newer Outlook 3.0 files. */ -public final class TestOutlook30FileRead extends TestCase { - private final MAPIMessage mapiMessage; +public final class TestOutlook30FileRead { + private MAPIMessage mapiMessage; /** * Initialize this test, load up the blank.msg mapi message. - * @throws Exception */ - public TestOutlook30FileRead() throws IOException { + @Before + public void setup() throws IOException { POIDataSamples samples = POIDataSamples.getHSMFInstance(); this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("outlook_30_msg.msg")); } /** * Test to see if we can read the CC Chunk. - * @throws ChunkNotFoundException - * */ + @Test public void testReadDisplayCC() throws ChunkNotFoundException { String obtained = mapiMessage.getDisplayCC(); String expected = ""; - TestCase.assertEquals(obtained, expected); + assertEquals(obtained, expected); } /** * Test to see if we can read the CC Chunk. - * @throws ChunkNotFoundException - * */ + @Test public void testReadDisplayTo() throws ChunkNotFoundException { String obtained = mapiMessage.getDisplayTo(); @@ -64,34 +66,31 @@ public final class TestOutlook30FileRead extends TestCase { /** * Test to see if we can read the From Chunk. - * @throws ChunkNotFoundException - * */ + @Test public void testReadDisplayFrom() throws ChunkNotFoundException { String obtained = mapiMessage.getDisplayFrom(); String expected = "Cramer, Nick"; - TestCase.assertEquals(obtained, expected); + assertEquals(obtained, expected); } /** * Test to see if we can read the CC Chunk. - * @throws ChunkNotFoundException - * */ + @Test public void testReadDisplayBCC() throws ChunkNotFoundException { String obtained = mapiMessage.getDisplayBCC(); String expected = ""; - TestCase.assertEquals(obtained, expected); + assertEquals(obtained, expected); } /** * Check if we can read the body of the blank message, we expect "". - * - * @throws Exception */ + @Test public void testReadBody() throws Exception { String obtained = mapiMessage.getTextBody(); assertTrue(obtained.startsWith("I am shutting down")); @@ -99,39 +98,37 @@ public final class TestOutlook30FileRead extends TestCase { /** * Check if we can read the subject line of the blank message, we expect "" - * - * @throws Exception */ + @Test public void testReadSubject() throws Exception { String obtained = mapiMessage.getSubject(); String expected = "IN-SPIRE servers going down for a bit, back up around 8am"; - TestCase.assertEquals(expected, obtained); + assertEquals(expected, obtained); } /** * Check if we can read the subject line of the blank message, we expect "" - * - * @throws Exception */ + @Test public void testReadConversationTopic() throws Exception { String obtained = mapiMessage.getConversationTopic(); - TestCase.assertEquals("IN-SPIRE servers going down for a bit, back up around 8am", obtained); + assertEquals("IN-SPIRE servers going down for a bit, back up around 8am", obtained); } /** * Check if we can read the subject line of the blank message, we expect "" - * - * @throws Exception */ + @Test public void testReadMessageClass() throws Exception { MAPIMessage.MESSAGE_CLASS obtained = mapiMessage.getMessageClassEnum(); - TestCase.assertEquals(MAPIMessage.MESSAGE_CLASS.NOTE, obtained); + assertEquals(MAPIMessage.MESSAGE_CLASS.NOTE, obtained); } /** * Ensure we can get the HTML and RTF versions */ + @Test public void testReadBodyContents() throws Exception { String html = mapiMessage.getHtmlBody(); String rtf = mapiMessage.getRtfBody(); diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestSimpleFileRead.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestSimpleFileRead.java index a0a1bc731f..314fe14ab4 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/TestSimpleFileRead.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestSimpleFileRead.java @@ -17,15 +17,15 @@ package org.apache.poi.hsmf; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; -import junit.framework.TestCase; import org.apache.poi.POIDataSamples; import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; import org.junit.Test; -import static org.junit.Assert.assertTrue; - /** * Tests to verify that we can read a simple msg file, that is in plain/text * format with no attachments or extra recipents. @@ -50,7 +50,7 @@ public final class TestSimpleFileRead { String obtained = mapiMessage.getDisplayCC(); String expected = ""; - TestCase.assertEquals(obtained, expected); + assertEquals(obtained, expected); } /** @@ -61,7 +61,7 @@ public final class TestSimpleFileRead { String obtained = mapiMessage.getDisplayTo(); String expected = "travis@overwrittenstack.com"; - TestCase.assertEquals(obtained, expected); + assertEquals(obtained, expected); } /** @@ -72,7 +72,7 @@ public final class TestSimpleFileRead { String obtained = mapiMessage.getDisplayFrom(); String expected = "Travis Ferguson"; - TestCase.assertEquals(obtained, expected); + assertEquals(obtained, expected); } /** @@ -83,7 +83,7 @@ public final class TestSimpleFileRead { String obtained = mapiMessage.getDisplayBCC(); String expected = ""; - TestCase.assertEquals(obtained, expected); + assertEquals(obtained, expected); } @@ -95,7 +95,7 @@ public final class TestSimpleFileRead { String obtained = mapiMessage.getTextBody(); String expected = "This is a test message."; - TestCase.assertEquals(obtained, expected); + assertEquals(obtained, expected); } /** @@ -106,7 +106,7 @@ public final class TestSimpleFileRead { String obtained = mapiMessage.getSubject(); String expected = "test message"; - TestCase.assertEquals(expected, obtained); + assertEquals(expected, obtained); } /** @@ -115,7 +115,7 @@ public final class TestSimpleFileRead { @Test public void testReadConversationTopic() throws Exception { String obtained = mapiMessage.getConversationTopic(); - TestCase.assertEquals("test message", obtained); + assertEquals("test message", obtained); } @@ -125,7 +125,7 @@ public final class TestSimpleFileRead { @Test public void testReadMessageClass() throws Exception { MAPIMessage.MESSAGE_CLASS obtained = mapiMessage.getMessageClassEnum(); - TestCase.assertEquals(MAPIMessage.MESSAGE_CLASS.NOTE, obtained); + assertEquals(MAPIMessage.MESSAGE_CLASS.NOTE, obtained); } /** @@ -133,7 +133,7 @@ public final class TestSimpleFileRead { */ @Test public void testReadMessageClass2() throws Exception { - TestCase.assertEquals( + assertEquals( MAPIMessage.MESSAGE_CLASS.NOTE, mapiMessage.getMessageClassEnum()); for (String messageClass : new String[]{ diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java index ea6f8be81b..cf28fa3210 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java @@ -17,19 +17,19 @@ package org.apache.poi.hsmf.datatypes; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; /** * Verifies that the Chunks class is actually setup properly and hasn't been changed in ways * that will break the library. - * - * @author Travis Ferguson - * */ -public final class TestChunkData extends TestCase { +public final class TestChunkData { + @Test public void testChunkCreate() { Chunk chunk; - + chunk = new StringChunk(0x0200, Types.createCustom(0x001E)); assertEquals("__substg1.0_0200001E", chunk.getEntryName()); assertEquals(0x0200, chunk.getChunkId()); @@ -39,12 +39,12 @@ public final class TestChunkData extends TestCase { assertEquals("__substg1.0_0200001E", chunk.getEntryName()); assertEquals(0x0200, chunk.getChunkId()); assertEquals(0x001E, chunk.getType().getId()); - + chunk = new StringChunk("__substg1.0_", 0x0200, Types.getById(0x001E)); assertEquals("__substg1.0_0200001E", chunk.getEntryName()); assertEquals(0x0200, chunk.getChunkId()); assertEquals(0x001E, chunk.getType().getId()); - + /* test the lower and upper limits of the chunk ids */ chunk = new StringChunk(0x0000, Types.createCustom(0x001E)); assertEquals("__substg1.0_0000001E", chunk.getEntryName()); @@ -56,27 +56,32 @@ public final class TestChunkData extends TestCase { assertEquals("__substg1.0_FFFF001F", chunk.getEntryName()); } + @Test public void testTextBodyChunk() { StringChunk chunk = new StringChunk(0x1000, Types.UNICODE_STRING); assertEquals(chunk.getChunkId(), MAPIProperty.BODY.id); } + @Test public void testDisplayToChunk() { StringChunk chunk = new StringChunk(0x0E04, Types.UNICODE_STRING); assertEquals(chunk.getChunkId(), MAPIProperty.DISPLAY_TO.id); } + @Test public void testDisplayCCChunk() { StringChunk chunk = new StringChunk(0x0E03, Types.UNICODE_STRING); assertEquals(chunk.getChunkId(), MAPIProperty.DISPLAY_CC.id); } + @Test public void testDisplayBCCChunk() { StringChunk chunk = new StringChunk(0x0E02, Types.UNICODE_STRING); assertEquals(chunk.getChunkId(), MAPIProperty.DISPLAY_BCC.id); } + @Test public void testSubjectChunk() { Chunk chunk = new StringChunk(0x0037, Types.UNICODE_STRING); assertEquals(chunk.getChunkId(), MAPIProperty.SUBJECT.id); diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestMAPIProperty.java b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestMAPIProperty.java index d44980a960..5229ada289 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestMAPIProperty.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestMAPIProperty.java @@ -17,42 +17,50 @@ package org.apache.poi.hsmf.datatypes; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertTrue; + import java.util.Collection; -import junit.framework.TestCase; +import org.junit.Test; /** * Checks various MAPIProperty related logic */ -public final class TestMAPIProperty extends TestCase { - public void testGet() throws Exception { +public final class TestMAPIProperty { + @Test + public void testGet() { assertEquals(MAPIProperty.DISPLAY_NAME, MAPIProperty.get(MAPIProperty.DISPLAY_NAME.id)); assertEquals(MAPIProperty.DISPLAY_BCC, MAPIProperty.get(MAPIProperty.DISPLAY_BCC.id)); assertNotSame(MAPIProperty.DISPLAY_BCC, MAPIProperty.get(MAPIProperty.DISPLAY_CC.id)); } - - public void testGetAll() throws Exception { + + @Test + public void testGetAll() { Collection all = MAPIProperty.getAll(); assertTrue(all.contains(MAPIProperty.DISPLAY_NAME)); assertTrue(all.contains(MAPIProperty.DISPLAY_CC)); - + // Won't contain custom assertFalse(all.contains(MAPIProperty.createCustom(1, Types.UNSPECIFIED, ""))); - + // Won't contain unknown assertFalse(all.contains(MAPIProperty.UNKNOWN)); } - - public void testCustom() throws Exception { + + @Test + public void testCustom() { MAPIProperty c1 = MAPIProperty.createCustom(1, Types.UNSPECIFIED, ""); MAPIProperty c2a = MAPIProperty.createCustom(2, Types.UNSPECIFIED, "2"); MAPIProperty c2b = MAPIProperty.createCustom(2, Types.UNSPECIFIED, "2"); - + // New object each time assertNotSame(c1, c2a); assertNotSame(c1, c2b); assertNotSame(c2a, c2b); - + // Won't be in all list Collection all = MAPIProperty.getAll(); assertFalse(all.contains(c1)); diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestSorters.java b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestSorters.java index 815fb2d661..d1d2032069 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestSorters.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestSorters.java @@ -17,21 +17,22 @@ package org.apache.poi.hsmf.datatypes; +import static org.junit.Assert.assertEquals; + import java.util.Arrays; import org.apache.poi.hsmf.datatypes.AttachmentChunks.AttachmentChunksSorter; import org.apache.poi.hsmf.datatypes.RecipientChunks.RecipientChunksSorter; - -import junit.framework.TestCase; +import org.junit.Test; /** - * Checks that the sorters on the chunk groups order - * chunks properly. + * Checks that the sorters on the chunk groups order chunks properly. */ -public final class TestSorters extends TestCase { +public final class TestSorters { + @Test public void testAttachmentChunksSorter() { AttachmentChunks[] chunks; - + // Simple chunks = new AttachmentChunks[] { new AttachmentChunks("__attach_version1.0_#00000001"), @@ -40,7 +41,7 @@ public final class TestSorters extends TestCase { Arrays.sort(chunks, new AttachmentChunksSorter()); assertEquals("__attach_version1.0_#00000000", chunks[0].getPOIFSName()); assertEquals("__attach_version1.0_#00000001", chunks[1].getPOIFSName()); - + // Lots, with gaps chunks = new AttachmentChunks[] { new AttachmentChunks("__attach_version1.0_#00000101"), @@ -60,10 +61,11 @@ public final class TestSorters extends TestCase { assertEquals("__attach_version1.0_#000000AB", chunks[5].getPOIFSName()); assertEquals("__attach_version1.0_#00000101", chunks[6].getPOIFSName()); } - + + @Test public void testRecipientChunksSorter() { RecipientChunks[] chunks; - + // Simple chunks = new RecipientChunks[] { new RecipientChunks("__recip_version1.0_#00000001"), @@ -72,7 +74,7 @@ public final class TestSorters extends TestCase { Arrays.sort(chunks, new RecipientChunksSorter()); assertEquals(0, chunks[0].recipientNumber); assertEquals(1, chunks[1].recipientNumber); - + // Lots, with gaps chunks = new RecipientChunks[] { new RecipientChunks("__recip_version1.0_#00020001"), diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestTypes.java b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestTypes.java index 305de74a8d..381584e8ea 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestTypes.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestTypes.java @@ -17,39 +17,44 @@ package org.apache.poi.hsmf.datatypes; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; /** * Verifies that the Types class is behaving properly. * Also check that no changes have been made that will * break the library. */ -public final class TestTypes extends TestCase { +public final class TestTypes { + @Test public void testTypeIds() { assertEquals(0x1e, Types.ASCII_STRING.getId()); assertEquals(0x1f, Types.UNICODE_STRING.getId()); - + assertEquals(0x0102, Types.BINARY.getId()); assertEquals(0x000B, Types.BOOLEAN.getId()); assertEquals(0x0003, Types.LONG.getId()); assertEquals(0x0040, Types.TIME.getId()); - + assertEquals(Types.ASCII_STRING, Types.getById(0x1e)); assertEquals(Types.UNICODE_STRING, Types.getById(0x1f)); - + assertEquals(Types.BINARY, Types.getById(0x0102)); assertEquals(Types.BOOLEAN, Types.getById(0x000B)); assertEquals(Types.LONG, Types.getById(0x0003)); assertEquals(Types.TIME, Types.getById(0x0040)); } - + + @Test public void testTypeFormatting() { assertEquals("0000", Types.asFileEnding(0x0000)); assertEquals("0020", Types.asFileEnding(0x0020)); assertEquals("0102", Types.asFileEnding(0x0102)); assertEquals("FEDC", Types.asFileEnding(0xfedc)); } - + + @Test public void testName() { assertEquals("ASCII String", Types.ASCII_STRING.getName()); assertEquals("Boolean", Types.BOOLEAN.getName()); diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java b/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java index 902dffc956..da84762332 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java @@ -17,6 +17,11 @@ package org.apache.poi.hwpf; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.File; @@ -27,14 +32,13 @@ import javax.imageio.ImageIO; import org.apache.poi.POIDataSamples; import org.apache.poi.hwpf.model.PicturesTable; import org.apache.poi.hwpf.usermodel.Picture; - -import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; /** * Test picture support in HWPF - * @author nick */ -public final class TestHWPFPictures extends TestCase { +public final class TestHWPFPictures { private String docAFile; private String docBFile; private String docCFile; @@ -45,10 +49,8 @@ public final class TestHWPFPictures extends TestCase { private String imgCFile; private String imgDFile; - @Override - protected void setUp() throws Exception { - super.setUp(); - + @Before + public void setUp() { docAFile = "testPictures.doc"; docBFile = "two_images.doc"; docCFile = "vector_image.doc"; @@ -68,6 +70,7 @@ public final class TestHWPFPictures extends TestCase { /** * Test just opening the files */ + @Test public void testOpen() { HWPFTestDataSamples.openSampleFile(docAFile); HWPFTestDataSamples.openSampleFile(docBFile); @@ -76,6 +79,7 @@ public final class TestHWPFPictures extends TestCase { /** * Test that we have the right numbers of images in each file */ + @Test public void testImageCount() { HWPFDocument docA = HWPFTestDataSamples.openSampleFile(docAFile); HWPFDocument docB = HWPFTestDataSamples.openSampleFile(docBFile); @@ -96,6 +100,7 @@ public final class TestHWPFPictures extends TestCase { /** * Test that we have the right images in at least one file */ + @Test public void testImageData() { HWPFDocument docB = HWPFTestDataSamples.openSampleFile(docBFile); PicturesTable picB = docB.getPicturesTable(); @@ -113,16 +118,14 @@ public final class TestHWPFPictures extends TestCase { byte[] pic1B = readFile(imgAFile); byte[] pic2B = readFile(imgBFile); - assertEquals(pic1B.length, pic1.getContent().length); - assertEquals(pic2B.length, pic2.getContent().length); - - assertBytesSame(pic1B, pic1.getContent()); - assertBytesSame(pic2B, pic2.getContent()); + assertArrayEquals(pic1B, pic1.getContent()); + assertArrayEquals(pic2B, pic2.getContent()); } /** * Test that compressed image data is correctly returned. */ + @Test public void testCompressedImageData() { HWPFDocument docC = HWPFTestDataSamples.openSampleFile(docCFile); PicturesTable picC = docC.getPicturesTable(); @@ -135,11 +138,10 @@ public final class TestHWPFPictures extends TestCase { // Check the same byte[] picBytes = readFile(imgCFile); - - assertEquals(picBytes.length, pic.getContent().length); - assertBytesSame(picBytes, pic.getContent()); + assertArrayEquals(picBytes, pic.getContent()); } + @Test public void testMacImages() throws Exception { HWPFDocument docC = HWPFTestDataSamples.openSampleFile("53446.doc"); PicturesTable picturesTable = docC.getPicturesTable(); @@ -168,6 +170,7 @@ public final class TestHWPFPictures extends TestCase { * Pending the missing files being uploaded to * bug #44937 */ + @Test public void testEscherDrawing() { HWPFDocument docD = HWPFTestDataSamples.openSampleFile(docDFile); List allPictures = docD.getPicturesTable().getAllPictures(); @@ -180,14 +183,7 @@ public final class TestHWPFPictures extends TestCase { assertEquals(picD.length, pic.getContent().length); - assertBytesSame(picD, pic.getContent()); - } - - private void assertBytesSame(byte[] a, byte[] b) { - assertEquals(a.length, b.length); - for(int i=0; i= 0) { - boolean keepLooking = true; - while (keepLooking) { - // Reload the range every time - range = daDoc.getRange(); - int offset = range.text().indexOf(searchText); - if (offset >= 0) { + int absOffset = range.getStartOffset() + offset; - int absOffset = range.getStartOffset() + offset; + Range subRange = new Range( + absOffset, (absOffset + searchText.length()), range.getDocument()); - Range subRange = new Range( - absOffset, (absOffset + searchText.length()), range.getDocument()); + assertEquals(searchText, subRange.text()); - assertEquals(searchText, subRange.text()); + subRange.delete(); - subRange.delete(); - - } else { - keepLooking = false; + } else { + keepLooking = false; + } } + + // we need to let the model re-calculate the Range before we use it + range = daDoc.getRange(); + + assertEquals(1, range.numSections()); + section = range.getSection(0); + + assertEquals(5, section.numParagraphs()); + + para = section.getParagraph(0); + text = para.text(); + assertEquals(introText, text); + + para = section.getParagraph(1); + text = para.text(); + assertEquals(expectedText1, text); + + para = section.getParagraph(2); + text = para.text(); + assertEquals(expectedText2, text); + + para = section.getParagraph(3); + text = para.text(); + assertEquals(expectedText3, text); } - - // we need to let the model re-calculate the Range before we use it - range = daDoc.getRange(); - - assertEquals(1, range.numSections()); - section = range.getSection(0); - - assertEquals(5, section.numParagraphs()); - - para = section.getParagraph(0); - text = para.text(); - assertEquals(introText, text); - - para = section.getParagraph(1); - text = para.text(); - assertEquals(expectedText1, text); - - para = section.getParagraph(2); - text = para.text(); - assertEquals(expectedText2, text); - - para = section.getParagraph(3); - text = para.text(); - assertEquals(expectedText3, text); } } diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java index 18ae0e7ac5..9271ef2c64 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java @@ -17,10 +17,13 @@ package org.apache.poi.hwpf.usermodel; -import junit.framework.TestCase; +import static org.apache.poi.hwpf.HWPFTestDataSamples.openSampleFile; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; import org.apache.poi.hwpf.HWPFDocument; -import org.apache.poi.hwpf.HWPFTestDataSamples; +import org.junit.Test; /** * Test to see if Range.insertBefore() works even if the Range contains a @@ -28,63 +31,58 @@ import org.apache.poi.hwpf.HWPFTestDataSamples; * * TODO - re-enable me when unicode paragraph stuff is fixed! */ -public final class TestRangeInsertion extends TestCase { +public final class TestRangeInsertion { // u201c and u201d are "smart-quotes" - private final String originalText = + private static final String originalText = "It is used to confirm that text insertion works even if Unicode characters (such as \u201c\u2014\u201d (U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present.\r"; - private final String textToInsert = "Look at me! I'm cool! "; - private final int insertionPoint = 122; + private static final String textToInsert = "Look at me! I'm cool! "; + private static final int insertionPoint = 122; - private String illustrativeDocFile; - - @Override - protected void setUp() { - illustrativeDocFile = "testRangeInsertion.doc"; - } + private static final String illustrativeDocFile = "testRangeInsertion.doc"; /** * Test just opening the files */ - public void testOpen() { - - HWPFTestDataSamples.openSampleFile(illustrativeDocFile); + @Test + public void testOpen() throws IOException { + openSampleFile(illustrativeDocFile).close(); } /** * Test (more "confirm" than test) that we have the general structure that we expect to have. */ - public void testDocStructure() { + @Test + public void testDocStructure() throws IOException { + try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) { - HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile); + Range range = daDoc.getRange(); - Range range = daDoc.getRange(); + assertEquals(1, range.numSections()); + Section section = range.getSection(0); - assertEquals(1, range.numSections()); - Section section = range.getSection(0); + assertEquals(3, section.numParagraphs()); + Paragraph para = section.getParagraph(2); + assertEquals(originalText, para.text()); - assertEquals(3, section.numParagraphs()); - Paragraph para = section.getParagraph(2); - assertEquals(originalText, para.text()); + assertEquals(3, para.numCharacterRuns()); + String text = + para.getCharacterRun(0).text() + + para.getCharacterRun(1).text() + + para.getCharacterRun(2).text(); - assertEquals(3, para.numCharacterRuns()); - String text = - para.getCharacterRun(0).text() + - para.getCharacterRun(1).text() + - para.getCharacterRun(2).text() - ; + assertEquals(originalText, text); - assertEquals(originalText, text); - - assertEquals(insertionPoint, para.getStartOffset()); + assertEquals(insertionPoint, para.getStartOffset()); + } } /** * Test that we can insert text in our CharacterRun with Unicode text. */ - public void testRangeInsertion() { - - HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile); + @Test + public void testRangeInsertion() throws IOException { + try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) { // if (false) { // TODO - delete or resurrect this code // Range range = daDoc.getRange(); @@ -96,28 +94,26 @@ public final class TestRangeInsertion extends TestCase { // System.out.println(text); // } - Range range = new Range(insertionPoint, (insertionPoint + 2), daDoc); - range.insertBefore(textToInsert); + Range range = new Range(insertionPoint, (insertionPoint + 2), daDoc); + range.insertBefore(textToInsert); - // we need to let the model re-calculate the Range before we evaluate it - range = daDoc.getRange(); + // we need to let the model re-calculate the Range before we evaluate it + range = daDoc.getRange(); - assertEquals(1, range.numSections()); - Section section = range.getSection(0); + assertEquals(1, range.numSections()); + Section section = range.getSection(0); - assertEquals(3, section.numParagraphs()); - Paragraph para = section.getParagraph(2); - assertEquals((textToInsert + originalText), para.text()); + assertEquals(3, section.numParagraphs()); + Paragraph para = section.getParagraph(2); + assertEquals((textToInsert + originalText), para.text()); - assertEquals(3, para.numCharacterRuns()); - String text = - para.getCharacterRun(0).text() + - para.getCharacterRun(1).text() + - para.getCharacterRun(2).text() - ; + assertEquals(3, para.numCharacterRuns()); + String text = + para.getCharacterRun(0).text() + + para.getCharacterRun(1).text() + + para.getCharacterRun(2).text(); - // System.out.println(text); - - assertEquals((textToInsert + originalText), text); + assertEquals((textToInsert + originalText), text); + } } } diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java index 0865189a22..423aa9081c 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java @@ -17,21 +17,25 @@ package org.apache.poi.hwpf.usermodel; -import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; -import junit.framework.TestCase; +import java.util.List; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFTestDataSamples; import org.apache.poi.hwpf.model.PAPX; import org.apache.poi.hwpf.model.StyleSheet; +import org.junit.Before; +import org.junit.Test; /** * Tests to ensure that our ranges end up with * the right text in them, and the right font/styling * properties applied to them. */ -public final class TestRangeProperties extends TestCase { +public final class TestRangeProperties { private static final char page_break = (char)12; private static final String u_page_1 = @@ -64,13 +68,13 @@ public final class TestRangeProperties extends TestCase { private HWPFDocument u; private HWPFDocument a; - @Override - protected void setUp() { + @Before + public void setUp() { u = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc"); a = HWPFTestDataSamples.openSampleFile("SampleDoc.doc"); } - + @Test public void testAsciiTextParagraphs() { Range r = a.getRange(); assertEquals( @@ -126,6 +130,7 @@ public final class TestRangeProperties extends TestCase { assertEquals( p2_parts[2] + "\r", r.getParagraph( 7 ).text() ); } + @Test public void testAsciiStyling() { Range r = a.getRange(); @@ -168,10 +173,10 @@ public final class TestRangeProperties extends TestCase { * Tests the raw definitions of the paragraphs of * a unicode document */ + @Test public void testUnicodeParagraphDefinitions() { Range r = u.getRange(); String[] p1_parts = u_page_1.split("\r"); - String[] p2_parts = u_page_2.split("\r"); assertEquals( u_page_1 + page_break + "\r" + u_page_2, @@ -204,7 +209,7 @@ public final class TestRangeProperties extends TestCase { // Check that the last paragraph ends where it should do assertEquals(531, u.getOverallRange().text().length()); PAPX pLast = pDefs.get(34); - // assertEquals(530, pLast.getEnd()); + assertEquals(530, pLast.getEnd()); // Only care about the first few really though PAPX p0 = pDefs.get(0); @@ -261,6 +266,7 @@ public final class TestRangeProperties extends TestCase { /** * Tests the paragraph text of a unicode document */ + @Test public void testUnicodeTextParagraphs() { Range r = u.getRange(); assertEquals( @@ -296,6 +302,8 @@ public final class TestRangeProperties extends TestCase { assertEquals( "\r", r.getParagraph( 11 ).text() ); assertEquals( p2_parts[0] + "\r", r.getParagraph( 12 ).text() ); } + + @Test public void testUnicodeStyling() { Range r = u.getRange(); String[] p1_parts = u_page_1.split("\r"); diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java index 370c4f3f41..7e4f1584f5 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java @@ -17,10 +17,13 @@ package org.apache.poi.hwpf.usermodel; -import junit.framework.TestCase; +import static org.apache.poi.hwpf.HWPFTestDataSamples.openSampleFile; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; import org.apache.poi.hwpf.HWPFDocument; -import org.apache.poi.hwpf.HWPFTestDataSamples; +import org.junit.Test; /** * Test to see if Range.replaceText() works even if the Range contains a @@ -28,125 +31,126 @@ import org.apache.poi.hwpf.HWPFTestDataSamples; * * TODO - re-enable me when unicode paragraph stuff is fixed! */ -public final class TestRangeReplacement extends TestCase { +public final class TestRangeReplacement { // u201c and u201d are "smart-quotes" - private final String originalText = + private static final String originalText = "It is used to confirm that text replacement works even if Unicode characters (such as \u201c\u2014\u201d (U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present. Everybody should be thankful to the ${organization} and all the POI contributors for their assistance in this matter.\r"; - private final String searchText = "${organization}"; - private final String replacementText = "Apache Software Foundation"; - private final String expectedText2 = + private static final String searchText = "${organization}"; + private static final String replacementText = "Apache Software Foundation"; + private static final String expectedText2 = "It is used to confirm that text replacement works even if Unicode characters (such as \u201c\u2014\u201d (U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present. Everybody should be thankful to the Apache Software Foundation and all the POI contributors for their assistance in this matter.\r"; - private final String expectedText3 = "Thank you, Apache Software Foundation!\r"; + private static final String expectedText3 = "Thank you, Apache Software Foundation!\r"; - private final String illustrativeDocFile = "testRangeReplacement.doc"; + private static final String illustrativeDocFile = "testRangeReplacement.doc"; /** * Test just opening the files */ public void testOpen() { - - HWPFTestDataSamples.openSampleFile(illustrativeDocFile); + openSampleFile(illustrativeDocFile); } /** * Test (more "confirm" than test) that we have the general structure that we expect to have. */ - public void testDocStructure() { + @Test + public void testDocStructure() throws IOException { + try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) { - HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile); + Range range = daDoc.getRange(); + assertEquals(414, range.text().length()); - Range range = daDoc.getRange(); - assertEquals(414, range.text().length()); + assertEquals(1, range.numSections()); + Section section = range.getSection(0); + assertEquals(414, section.text().length()); - assertEquals(1, range.numSections()); - Section section = range.getSection(0); - assertEquals(414, section.text().length()); + assertEquals(5, section.numParagraphs()); + Paragraph para = section.getParagraph(2); - assertEquals(5, section.numParagraphs()); - Paragraph para = section.getParagraph(2); + assertEquals(5, para.numCharacterRuns()); + String text = + para.getCharacterRun(0).text() + + para.getCharacterRun(1).text() + + para.getCharacterRun(2).text() + + para.getCharacterRun(3).text() + + para.getCharacterRun(4).text(); - assertEquals(5, para.numCharacterRuns()); - String text = - para.getCharacterRun(0).text() + - para.getCharacterRun(1).text() + - para.getCharacterRun(2).text() + - para.getCharacterRun(3).text() + - para.getCharacterRun(4).text() - ; - - assertEquals(originalText, text); + assertEquals(originalText, text); + } } /** * Test that we can replace text in our Range with Unicode text. */ - public void testRangeReplacementOne() { + @Test + public void testRangeReplacementOne() throws IOException { + try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) { - HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile); + // Has one section + Range range = daDoc.getRange(); + assertEquals(1, range.numSections()); - // Has one section - Range range = daDoc.getRange(); - assertEquals(1, range.numSections()); + // The first section has 5 paragraphs + Section section = range.getSection(0); + assertEquals(5, section.numParagraphs()); - // The first section has 5 paragraphs - Section section = range.getSection(0); - assertEquals(5, section.numParagraphs()); - - // Change some text - Paragraph para = section.getParagraph(2); + // Change some text + Paragraph para = section.getParagraph(2); - String text = para.text(); - assertEquals(originalText, text); + String text = para.text(); + assertEquals(originalText, text); - int offset = text.indexOf(searchText); - assertEquals(181, offset); + int offset = text.indexOf(searchText); + assertEquals(181, offset); - para.replaceText(searchText, replacementText, offset); + para.replaceText(searchText, replacementText, offset); - // Ensure we still have one section, 5 paragraphs - assertEquals(1, range.numSections()); - section = range.getSection(0); + // Ensure we still have one section, 5 paragraphs + assertEquals(1, range.numSections()); + section = range.getSection(0); - assertEquals(5, section.numParagraphs()); - para = section.getParagraph(2); + assertEquals(5, section.numParagraphs()); + para = section.getParagraph(2); - // Ensure the text is what we should now have - text = para.text(); - assertEquals(expectedText2, text); + // Ensure the text is what we should now have + text = para.text(); + assertEquals(expectedText2, text); + } } /** * Test that we can replace text in our Range with Unicode text. */ - public void testRangeReplacementAll() { + @Test + public void testRangeReplacementAll() throws IOException { + try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) { - HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile); + Range range = daDoc.getRange(); + assertEquals(1, range.numSections()); - Range range = daDoc.getRange(); - assertEquals(1, range.numSections()); + Section section = range.getSection(0); + assertEquals(5, section.numParagraphs()); - Section section = range.getSection(0); - assertEquals(5, section.numParagraphs()); + Paragraph para = section.getParagraph(2); - Paragraph para = section.getParagraph(2); + String text = para.text(); + assertEquals(originalText, text); - String text = para.text(); - assertEquals(originalText, text); + range.replaceText(searchText, replacementText); - range.replaceText(searchText, replacementText); + assertEquals(1, range.numSections()); + section = range.getSection(0); + assertEquals(5, section.numParagraphs()); - assertEquals(1, range.numSections()); - section = range.getSection(0); - assertEquals(5, section.numParagraphs()); + para = section.getParagraph(2); + text = para.text(); + assertEquals(expectedText2, text); - para = section.getParagraph(2); - text = para.text(); - assertEquals(expectedText2, text); - - para = section.getParagraph(3); - text = para.text(); - assertEquals(expectedText3, text); + para = section.getParagraph(3); + text = para.text(); + assertEquals(expectedText3, text); + } } } diff --git a/src/testcases/org/apache/poi/hssf/eventmodel/TestAbortableListener.java b/src/testcases/org/apache/poi/hssf/eventmodel/TestAbortableListener.java index 18384de5d8..f47104c225 100644 --- a/src/testcases/org/apache/poi/hssf/eventmodel/TestAbortableListener.java +++ b/src/testcases/org/apache/poi/hssf/eventmodel/TestAbortableListener.java @@ -17,11 +17,12 @@ package org.apache.poi.hssf.eventmodel; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + import java.io.ByteArrayInputStream; import java.io.IOException; -import junit.framework.TestCase; - import org.apache.poi.hssf.HSSFITestDataProvider; import org.apache.poi.hssf.eventusermodel.AbortableHSSFListener; import org.apache.poi.hssf.eventusermodel.HSSFEventFactory; @@ -30,22 +31,20 @@ import org.apache.poi.hssf.record.BOFRecord; import org.apache.poi.hssf.record.EOFRecord; import org.apache.poi.hssf.record.Record; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.junit.Test; /** * Tests for {@link AbortableHSSFListener} */ -public final class TestAbortableListener extends TestCase { +public final class TestAbortableListener { - private POIFSFileSystem openSample() { + private POIFSFileSystem openSample() throws IOException { ByteArrayInputStream is = new ByteArrayInputStream(HSSFITestDataProvider.instance .getTestDataFileContent("SimpleWithColours.xls")); - try { - return new POIFSFileSystem(is); - } catch (IOException e) { - throw new RuntimeException(e); - } + return new POIFSFileSystem(is); } + @Test public void testAbortingBasics() throws Exception { AbortableCountingListener l = new AbortableCountingListener(1000); @@ -65,7 +64,7 @@ public final class TestAbortableListener extends TestCase { assertEquals(EOFRecord.sid, l.lastRecordSeen.getSid()); } - + @Test public void testAbortStops() throws Exception { AbortableCountingListener l = new AbortableCountingListener(1); @@ -100,7 +99,7 @@ public final class TestAbortableListener extends TestCase { countSeen++; lastRecordSeen = record; - if(countSeen == abortAfterIndex) { + if (countSeen == abortAfterIndex) { return 1234; } return 0; diff --git a/src/testcases/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java b/src/testcases/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java index eacfdd51bb..f579c4097e 100644 --- a/src/testcases/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java +++ b/src/testcases/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java @@ -17,46 +17,59 @@ package org.apache.poi.hssf.eventmodel; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.SequenceInputStream; +import java.util.Iterator; +import java.util.stream.Stream; -import junit.framework.TestCase; - +import org.apache.commons.collections4.IteratorUtils; import org.apache.poi.hssf.record.BOFRecord; import org.apache.poi.hssf.record.ContinueRecord; import org.apache.poi.hssf.record.EOFRecord; import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.RecordFactory; +import org.apache.poi.hssf.record.StandardRecord; import org.apache.poi.hssf.record.TestcaseRecordInputStream; import org.apache.poi.hssf.record.UnknownRecord; import org.apache.poi.util.NotImplemented; +import org.junit.Ignore; +import org.junit.Test; /** * enclosing_type describe the purpose here - * - * @author Andrew C. Oliver acoliver@apache.org - * @author Csaba Nagy (ncsaba at yahoo dot com) */ -public final class TestEventRecordFactory extends TestCase { +public final class TestEventRecordFactory { + private static final byte[][] CONTINUE_DATA = { + // an unknown record with 0 length + {0, -1, 0, 0,}, + // a continuation record with 3 bytes of data + {0x3C, 0, 3, 0, 1, 2, 3,}, + // one more continuation record with 1 byte of data + {0x3C, 0, 1, 0, 4} + }; /** - * tests that the records can be processed and properly return - * values. + * tests that the records can be processed and properly return values. */ - public void testProcessRecords() - { - final boolean[] wascalled = { false, }; // hack to pass boolean by ref into inner class + @Test + public void testProcessRecords() { + final boolean[] wascalled = { false }; // hack to pass boolean by ref into inner class - ERFListener listener = new ERFListener() { - @Override - public boolean processRecord(Record rec) { - wascalled[0] = true; - assertTrue("must be BOFRecord got SID="+rec.getSid(), - (rec.getSid() == BOFRecord.sid)); - return true; - } + ERFListener listener = rec -> { + wascalled[0] = true; + assertEquals("must be BOFRecord got SID=" + rec.getSid(), rec.getSid(), BOFRecord.sid); + return true; }; EventRecordFactory factory = new EventRecordFactory(listener, new short[] {BOFRecord.sid}); - + BOFRecord bof = new BOFRecord(); bof.setBuild((short)0); bof.setBuildYear((short)1999); @@ -64,22 +77,23 @@ public final class TestEventRecordFactory extends TestCase { bof.setType(BOFRecord.TYPE_WORKBOOK); bof.setVersion((short)0x06); bof.setHistoryBitMask(BOFRecord.HISTORY_MASK); - + EOFRecord eof = EOFRecord.instance; byte[] bytes = new byte[bof.getRecordSize() + eof.getRecordSize()]; int offset = 0; offset = bof.serialize(offset,bytes); - offset = eof.serialize(offset,bytes); - - factory.processRecords(new ByteArrayInputStream(bytes)); - assertTrue("The record listener must be called", wascalled[0]); + eof.serialize(offset,bytes); + + factory.processRecords(new ByteArrayInputStream(bytes)); + assertTrue("The record listener must be called", wascalled[0]); } - + /** - * tests that the create record function returns a properly + * tests that the create record function returns a properly * constructed record in the simple case. */ + @Test public void testCreateRecord() { BOFRecord bof = new BOFRecord(); bof.setBuild((short)0); @@ -88,49 +102,30 @@ public final class TestEventRecordFactory extends TestCase { bof.setType(BOFRecord.TYPE_WORKBOOK); bof.setVersion((short)0x06); bof.setHistoryBitMask(BOFRecord.HISTORY_MASK); - + byte[] bytes = bof.serialize(); - + Record[] records = RecordFactory.createRecord(TestcaseRecordInputStream.create(bytes)); assertEquals("record.length must be 1, was =" + records.length, 1, records.length); - assertTrue("record is the same", compareRec(bof,records[0])); - + + byte[] rec1 = bof.serialize(); + byte[] rec2 = records[0].serialize(); + assertArrayEquals(rec1, rec2); } /** - * Compare the serialized bytes of two records are equal - * @param first the first record to compare - * @param second the second record to compare - * @return boolean whether or not the record where equal - */ - private static boolean compareRec(Record first, Record second) { - byte[] rec1 = first.serialize(); - byte[] rec2 = second.serialize(); - - if (rec1.length != rec2.length) { - return false; - } - for (int k=0; k @@ -140,45 +135,35 @@ public final class TestEventRecordFactory extends TestCase { * FAILURE: The wrong records are created or contain the wrong values

* */ - public void testContinuedUnknownRecord() { - final byte[] data = { - 0, -1, 0, 0, // an unknown record with 0 length - 0x3C , 0, 3, 0, 1, 2, 3, // a continuation record with 3 bytes of data - 0x3C , 0, 1, 0, 4 // one more continuation record with 1 byte of data + @Test + public void testContinuedUnknownRecord() throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + for (byte[] b : CONTINUE_DATA) { + bos.write(b); + } + continueHelper(new ByteArrayInputStream(bos.toByteArray())); + } + + @Test + @Ignore("same as testContinuedUnknownRecord but with SequenceInputStream which causes the available() bug 59893") + public void bug59893() { + Iterator iter = Stream.of(CONTINUE_DATA).map(ByteArrayInputStream::new).iterator(); + SequenceInputStream sis = new SequenceInputStream(IteratorUtils.asEnumeration(iter)); + continueHelper(sis); + } + + private void continueHelper(InputStream data) { + Iterator> expectedType = + Stream.of(UnknownRecord.class, ContinueRecord.class, ContinueRecord.class).iterator(); + Iterator expectedData = Stream.of(CONTINUE_DATA).iterator(); + + ERFListener listener = rec -> { + assertEquals(expectedType.next(), rec.getClass()); + assertArrayEquals(expectedData.next(), rec.serialize()); + return true; }; - - final int[] recCnt = { 0 }; - final int[] offset = { 0 }; - ERFListener listener = new ERFListener() { - private final String[] expectedRecordTypes = { - UnknownRecord.class.getName(), - ContinueRecord.class.getName(), - ContinueRecord.class.getName() - }; - @Override - public boolean processRecord(Record rec) - { - // System.out.println(rec.toString()); - assertEquals( - "Record type", - expectedRecordTypes[recCnt[0]], - rec.getClass().getName() - ); - compareData(rec, "Record " + recCnt[0] + ": "); - recCnt[0]++; - return true; - } - private void compareData(Record record, String message) { - byte[] recData = record.serialize(); - for (int i = 0; i < recData.length; i++) { - assertEquals(message + " data byte " + i, data[offset[0]++], recData[i]); - } - } - }; - EventRecordFactory factory = new EventRecordFactory(listener, new short[] {-256, 0x3C}); - - factory.processRecords(new ByteArrayInputStream(data)); - assertEquals("nr. of processed records", 3, recCnt[0]); - assertEquals("nr. of processed bytes", data.length, offset[0]); + EventRecordFactory factory = new EventRecordFactory(listener, new short[] {-256, 0x3C}); + factory.processRecords(data); + assertFalse("left over input data", expectedData.hasNext()); } } diff --git a/src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java b/src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java index 296eff6458..ca45d61501 100644 --- a/src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java +++ b/src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java @@ -17,13 +17,15 @@ package org.apache.poi.hssf.eventusermodel; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; - import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder.SheetRecordCollectingListener; import org.apache.poi.hssf.model.HSSFFormulaParser; @@ -35,41 +37,50 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.formula.ptg.Ref3DPtg; +import org.junit.Before; +import org.junit.Test; + /** * Tests for {@link EventWorkbookBuilder} */ -public final class TestEventWorkbookBuilder extends TestCase { - private MockHSSFListener mockListen; +public final class TestEventWorkbookBuilder { + private final List fRecs = new ArrayList<>(); private SheetRecordCollectingListener listener; - @Override - public void setUp() { + @Before + public void setUp() throws IOException { HSSFRequest req = new HSSFRequest(); - mockListen = new MockHSSFListener(); - listener = new SheetRecordCollectingListener(mockListen); + fRecs.clear(); + listener = new SheetRecordCollectingListener(this::addFormulaRecord); req.addListenerForAllRecords(listener); HSSFEventFactory factory = new HSSFEventFactory(); - try { - InputStream is = HSSFTestDataSamples.openSampleFileStream("3dFormulas.xls"); - POIFSFileSystem fs = new POIFSFileSystem(is); + try (InputStream is = HSSFTestDataSamples.openSampleFileStream("3dFormulas.xls"); + POIFSFileSystem fs = new POIFSFileSystem(is)) { factory.processWorkbookEvents(req, fs); - } catch (IOException e) { - throw new RuntimeException(e); } } + private void addFormulaRecord(Record r) { + if (r instanceof FormulaRecord) { + fRecs.add((FormulaRecord)r); + } + } + + @Test public void testBasics() { assertNotNull(listener.getSSTRecord()); assertNotNull(listener.getBoundSheetRecords()); assertNotNull(listener.getExternSheetRecords()); } + @Test public void testGetStubWorkbooks() { assertNotNull(listener.getStubWorkbook()); assertNotNull(listener.getStubHSSFWorkbook()); } + @Test public void testContents() { assertEquals(2, listener.getSSTRecord().getNumStrings()); assertEquals(3, listener.getBoundSheetRecords().length); @@ -83,12 +94,11 @@ public final class TestEventWorkbookBuilder extends TestCase { assertEquals("S2", ref.findSheetFirstNameFromExternSheet(2)); } + @Test public void testFormulas() { - FormulaRecord[] fRecs = mockListen.getFormulaRecords(); - // Check our formula records - assertEquals(6, fRecs.length); + assertEquals(6, fRecs.size()); InternalWorkbook stubWB = listener.getStubWorkbook(); assertNotNull(stubWB); @@ -110,7 +120,7 @@ public final class TestEventWorkbookBuilder extends TestCase { // Peer into just one formula, and check that // all the ptgs give back the right things - Ptg[] ptgs = fRecs[0].getParsedExpression(); + Ptg[] ptgs = fRecs.get(0).getParsedExpression(); assertEquals(1, ptgs.length); assertTrue(ptgs[0] instanceof Ref3DPtg); @@ -124,19 +134,19 @@ public final class TestEventWorkbookBuilder extends TestCase { FormulaRecord fr; // Sheet 1 A2 is on same sheet - fr = fRecs[0]; + fr = fRecs.get(0); assertEquals(1, fr.getRow()); assertEquals(0, fr.getColumn()); assertEquals("Sheet1!A1", HSSFFormulaParser.toFormulaString(stubHSSF, fr.getParsedExpression())); // Sheet 1 A5 is to another sheet - fr = fRecs[3]; + fr = fRecs.get(3); assertEquals(4, fr.getRow()); assertEquals(0, fr.getColumn()); assertEquals("'S2'!A1", HSSFFormulaParser.toFormulaString(stubHSSF, fr.getParsedExpression())); // Sheet 1 A7 is to another sheet, range - fr = fRecs[5]; + fr = fRecs.get(5); assertEquals(6, fr.getRow()); assertEquals(0, fr.getColumn()); assertEquals("SUM(Sh3!A1:A4)", HSSFFormulaParser.toFormulaString(stubHSSF, fr.getParsedExpression())); @@ -147,23 +157,4 @@ public final class TestEventWorkbookBuilder extends TestCase { assertEquals("Sheet1!A1", wb.getSheetAt(0).getRow(1).getCell(0).getCellFormula()); assertEquals("SUM(Sh3!A1:A4)", wb.getSheetAt(0).getRow(6).getCell(0).getCellFormula()); } - - private static final class MockHSSFListener implements HSSFListener { - public MockHSSFListener() {} - private final List _records = new ArrayList<>(); - private final List _frecs = new ArrayList<>(); - - @Override - public void processRecord(Record record) { - _records.add(record); - if(record instanceof FormulaRecord) { - _frecs.add(record); - } - } - public FormulaRecord[] getFormulaRecords() { - FormulaRecord[] result = new FormulaRecord[_frecs.size()]; - _frecs.toArray(result); - return result; - } - } } diff --git a/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java b/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java index 459cfe90ec..6ad37f618e 100644 --- a/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java +++ b/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java @@ -16,12 +16,17 @@ ==================================================================== */ package org.apache.poi.hssf.eventusermodel; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; - import org.apache.poi.EncryptedDocumentException; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.record.BoundSheetRecord; @@ -36,66 +41,61 @@ import org.apache.poi.hssf.record.SelectionRecord; import org.apache.poi.hssf.record.WindowTwoRecord; import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; import org.apache.poi.poifs.filesystem.POIFSFileSystem; -import org.junit.After; +import org.junit.Test; /** * Testing for {@link HSSFEventFactory} */ -public final class TestHSSFEventFactory extends TestCase { - private static InputStream openSample(String sampleFileName) { - return HSSFTestDataSamples.openSampleFileStream(sampleFileName); +public final class TestHSSFEventFactory { + private final List records = new ArrayList<>(); + + private void openSample(String sampleFileName) throws IOException { + records.clear(); + HSSFRequest req = new HSSFRequest(); + req.addListenerForAllRecords(records::add); + try (InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName); + POIFSFileSystem fs = new POIFSFileSystem(is)) { + HSSFEventFactory factory = new HSSFEventFactory(); + factory.processWorkbookEvents(req, fs); + } } + @Test public void testWithMissingRecords() throws Exception { - HSSFRequest req = new HSSFRequest(); - MockHSSFListener mockListen = new MockHSSFListener(); - req.addListenerForAllRecords(mockListen); + openSample("SimpleWithSkip.xls"); - POIFSFileSystem fs = new POIFSFileSystem(openSample("SimpleWithSkip.xls")); - HSSFEventFactory factory = new HSSFEventFactory(); - factory.processWorkbookEvents(req, fs); + int numRec = records.size(); - Record[] recs = mockListen.getRecords(); // Check we got the records - assertTrue( recs.length > 100 ); + assertTrue( numRec > 100 ); // Check that the last few records are as we expect // (Makes sure we don't accidently skip the end ones) - int numRec = recs.length; - assertEquals(WindowTwoRecord.class, recs[numRec-3].getClass()); - assertEquals(SelectionRecord.class, recs[numRec-2].getClass()); - assertEquals(EOFRecord.class, recs[numRec-1].getClass()); + Class[] exp = { WindowTwoRecord.class, SelectionRecord.class, EOFRecord.class }; + Class[] act = records.subList(numRec - 3, numRec).stream().map(Object::getClass).toArray(Class[]::new); + assertArrayEquals(exp, act); } + @Test public void testWithCrazyContinueRecords() throws Exception { // Some files have crazy ordering of their continue records // Check that we don't break on them (bug #42844) - HSSFRequest req = new HSSFRequest(); - MockHSSFListener mockListen = new MockHSSFListener(); - req.addListenerForAllRecords(mockListen); + openSample("ContinueRecordProblem.xls"); - POIFSFileSystem fs = new POIFSFileSystem(openSample("ContinueRecordProblem.xls")); - HSSFEventFactory factory = new HSSFEventFactory(); - factory.processWorkbookEvents(req, fs); - - Record[] recs = mockListen.getRecords(); + int numRec = records.size(); // Check we got the records - assertTrue( recs.length > 100 ); + assertTrue( numRec > 100 ); // And none of them are continue ones - for (Record rec : recs) { - assertFalse( rec instanceof ContinueRecord ); - } + assertFalse(records.stream().anyMatch(r -> r instanceof ContinueRecord)); // Check that the last few records are as we expect - // (Makes sure we don't accidently skip the end ones) - int numRec = recs.length; - assertEquals(DVALRecord.class, recs[numRec-4].getClass()); - assertEquals(DVRecord.class, recs[numRec-3].getClass()); - assertEquals(FeatHdrRecord.class, recs[numRec-2].getClass()); - assertEquals(EOFRecord.class, recs[numRec-1].getClass()); + // (Makes sure we don't accidentally skip the end ones) + Class[] exp = { DVALRecord.class, DVRecord.class, FeatHdrRecord.class, EOFRecord.class }; + Class[] act = records.subList(numRec-4, numRec).stream().map(Object::getClass).toArray(Class[]::new); + assertArrayEquals(exp, act); } /** @@ -103,77 +103,36 @@ public final class TestHSSFEventFactory extends TestCase { * Check that HSSFEventFactory doesn't break on them. * (the test file was provided in a reopen of bug #42844) */ + @Test public void testUnknownContinueRecords() throws Exception { - - HSSFRequest req = new HSSFRequest(); - MockHSSFListener mockListen = new MockHSSFListener(); - req.addListenerForAllRecords(mockListen); - - POIFSFileSystem fs = new POIFSFileSystem(openSample("42844.xls")); - HSSFEventFactory factory = new HSSFEventFactory(); - factory.processWorkbookEvents(req, fs); - } - - private static class MockHSSFListener implements HSSFListener { - private final List records = new ArrayList<>(); - - public MockHSSFListener() {} - public Record[] getRecords() { - Record[] result = new Record[records.size()]; - records.toArray(result); - return result; - } - - @Override - public void processRecord(Record record) { - records.add(record); - } + openSample("42844.xls"); } + @Test public void testWithDifferentWorkbookName() throws Exception { - HSSFRequest req = new HSSFRequest(); - MockHSSFListener mockListen = new MockHSSFListener(); - req.addListenerForAllRecords(mockListen); - - POIFSFileSystem fs = new POIFSFileSystem(openSample("BOOK_in_capitals.xls")); - HSSFEventFactory factory = new HSSFEventFactory(); - factory.processWorkbookEvents(req, fs); - - fs = new POIFSFileSystem(openSample("WORKBOOK_in_capitals.xls")); - factory = new HSSFEventFactory(); - factory.processWorkbookEvents(req, fs); + openSample("BOOK_in_capitals.xls"); + openSample("WORKBOOK_in_capitals.xls"); } - public void testWithPasswordProtectedWorkbooks() throws Exception { - HSSFRequest req = new HSSFRequest(); - MockHSSFListener mockListen = new MockHSSFListener(); - req.addListenerForAllRecords(mockListen); - + @Test(expected = EncryptedDocumentException.class) + public void testWithPasswordProtectedWorkbooksNoPass() throws Exception { // Without a password, can't be read - POIFSFileSystem fs = new POIFSFileSystem(openSample("xor-encryption-abc.xls")); - - HSSFEventFactory factory = new HSSFEventFactory(); - try { - factory.processWorkbookEvents(req, fs); - fail("Shouldn't be able to process protected workbook without the password"); - } catch (EncryptedDocumentException e) {} - + openSample("xor-encryption-abc.xls"); + } + @Test + public void testWithPasswordProtectedWorkbooks() throws Exception { // With the password, is properly processed Biff8EncryptionKey.setCurrentUserPassword("abc"); try { - req = new HSSFRequest(); - mockListen = new MockHSSFListener(); - req.addListenerForAllRecords(mockListen); - factory.processWorkbookEvents(req, fs); + openSample("xor-encryption-abc.xls"); // Check we got the sheet and the contents - Record[] recs = mockListen.getRecords(); - assertTrue(recs.length > 50); + assertTrue(records.size() > 50); // Has one sheet, with values 1,2,3 in column A rows 1-3 boolean hasSheet = false, hasA1 = false, hasA2 = false, hasA3 = false; - for (Record r : recs) { + for (Record r : records) { if (r instanceof BoundSheetRecord) { BoundSheetRecord bsr = (BoundSheetRecord) r; assertEquals("Sheet1", bsr.getSheetname()); @@ -204,4 +163,4 @@ public final class TestHSSFEventFactory extends TestCase { Biff8EncryptionKey.setCurrentUserPassword(null); } } -} +} diff --git a/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java b/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java index 5387723b81..0b1fff72bf 100644 --- a/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java +++ b/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java @@ -16,343 +16,95 @@ ==================================================================== */ package org.apache.poi.hssf.eventusermodel; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; - -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import java.util.function.Predicate; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord; import org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord; import org.apache.poi.hssf.eventusermodel.dummyrecord.MissingRowDummyRecord; -import org.apache.poi.hssf.record.BOFRecord; import org.apache.poi.hssf.record.BlankRecord; import org.apache.poi.hssf.record.CellValueRecordInterface; import org.apache.poi.hssf.record.DimensionsRecord; -import org.apache.poi.hssf.record.FormulaRecord; import org.apache.poi.hssf.record.LabelSSTRecord; import org.apache.poi.hssf.record.MulBlankRecord; import org.apache.poi.hssf.record.NumberRecord; import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.RowRecord; import org.apache.poi.hssf.record.SharedFormulaRecord; -import org.apache.poi.hssf.record.StringRecord; import org.apache.poi.hssf.record.WindowTwoRecord; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.junit.Test; + /** * Tests for MissingRecordAwareHSSFListener */ -public final class TestMissingRecordAwareHSSFListener extends TestCase { - - private Record[] r; +public final class TestMissingRecordAwareHSSFListener { - private void readRecords(String sampleFileName) { + private final List _records = new ArrayList<>(); + + private void readRecords(String sampleFileName) throws IOException { + _records.clear(); HSSFRequest req = new HSSFRequest(); - MockHSSFListener mockListen = new MockHSSFListener(); - MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener(mockListen); - req.addListenerForAllRecords(listener); - - HSSFEventFactory factory = new HSSFEventFactory(); - try { - InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName); - POIFSFileSystem fs = new POIFSFileSystem(is); - factory.processWorkbookEvents(req, fs); - } catch (IOException e) { - throw new RuntimeException(e); - } - - r = mockListen.getRecords(); - assertTrue(r.length > 100); - } - public void openNormal() { - readRecords("MissingBits.xls"); - } - - public void testMissingRowRecords() { - openNormal(); - - // We have rows 0, 1, 2, 20 and 21 - int row0 = -1; - for(int i=0; i -1); - - // Following row 0, we should have 1, 2, then dummy, then 20+21+22 - assertTrue(r[row0] instanceof RowRecord); - assertTrue(r[row0+1] instanceof RowRecord); - assertTrue(r[row0+2] instanceof RowRecord); - assertTrue(r[row0+3] instanceof MissingRowDummyRecord); - assertTrue(r[row0+4] instanceof MissingRowDummyRecord); - assertTrue(r[row0+5] instanceof MissingRowDummyRecord); - assertTrue(r[row0+6] instanceof MissingRowDummyRecord); - // ... - assertTrue(r[row0+18] instanceof MissingRowDummyRecord); - assertTrue(r[row0+19] instanceof MissingRowDummyRecord); - assertTrue(r[row0+20] instanceof RowRecord); - assertTrue(r[row0+21] instanceof RowRecord); - assertTrue(r[row0+22] instanceof RowRecord); - - // Check things had the right row numbers - RowRecord rr; - rr = (RowRecord)r[row0+2]; - assertEquals(2, rr.getRowNumber()); - rr = (RowRecord)r[row0+20]; - assertEquals(20, rr.getRowNumber()); - rr = (RowRecord)r[row0+21]; - assertEquals(21, rr.getRowNumber()); - - MissingRowDummyRecord mr; - mr = (MissingRowDummyRecord)r[row0+3]; - assertEquals(3, mr.getRowNumber()); - mr = (MissingRowDummyRecord)r[row0+4]; - assertEquals(4, mr.getRowNumber()); - mr = (MissingRowDummyRecord)r[row0+5]; - assertEquals(5, mr.getRowNumber()); - mr = (MissingRowDummyRecord)r[row0+18]; - assertEquals(18, mr.getRowNumber()); - mr = (MissingRowDummyRecord)r[row0+19]; - assertEquals(19, mr.getRowNumber()); - } - - public void testEndOfRowRecords() { - openNormal(); - - // Find the cell at 0,0 - int cell00 = -1; - for(int i=0; i -1); - - // We have rows 0, 1, 2, 20 and 21 - // Row 0 has 1 entry - // Row 1 has 4 entries - // Row 2 has 6 entries - // Row 20 has 5 entries - // Row 21 has 7 entries - // Row 22 has 12 entries + req.addListenerForAllRecords(new MissingRecordAwareHSSFListener(_records::add)); - // Row 0 - assertFalse(r[cell00+0] instanceof LastCellOfRowDummyRecord); - assertTrue(r[cell00+1] instanceof LastCellOfRowDummyRecord); - // Row 1 - assertFalse(r[cell00+2] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+3] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+4] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+5] instanceof LastCellOfRowDummyRecord); - assertTrue(r[cell00+6] instanceof LastCellOfRowDummyRecord); - // Row 2 - assertFalse(r[cell00+7] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+8] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+9] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+10] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+11] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+12] instanceof LastCellOfRowDummyRecord); - assertTrue(r[cell00+13] instanceof LastCellOfRowDummyRecord); - // Row 3 -> 19 - assertTrue(r[cell00+14] instanceof LastCellOfRowDummyRecord); - assertTrue(r[cell00+15] instanceof LastCellOfRowDummyRecord); - assertTrue(r[cell00+16] instanceof LastCellOfRowDummyRecord); - assertTrue(r[cell00+17] instanceof LastCellOfRowDummyRecord); - assertTrue(r[cell00+18] instanceof LastCellOfRowDummyRecord); - assertTrue(r[cell00+19] instanceof LastCellOfRowDummyRecord); - assertTrue(r[cell00+20] instanceof LastCellOfRowDummyRecord); - assertTrue(r[cell00+21] instanceof LastCellOfRowDummyRecord); - assertTrue(r[cell00+22] instanceof LastCellOfRowDummyRecord); - assertTrue(r[cell00+23] instanceof LastCellOfRowDummyRecord); - assertTrue(r[cell00+24] instanceof LastCellOfRowDummyRecord); - assertTrue(r[cell00+25] instanceof LastCellOfRowDummyRecord); - assertTrue(r[cell00+26] instanceof LastCellOfRowDummyRecord); - assertTrue(r[cell00+27] instanceof LastCellOfRowDummyRecord); - assertTrue(r[cell00+28] instanceof LastCellOfRowDummyRecord); - assertTrue(r[cell00+29] instanceof LastCellOfRowDummyRecord); - assertTrue(r[cell00+30] instanceof LastCellOfRowDummyRecord); - // Row 20 - assertFalse(r[cell00+31] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+32] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+33] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+34] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+35] instanceof LastCellOfRowDummyRecord); - assertTrue(r[cell00+36] instanceof LastCellOfRowDummyRecord); - // Row 21 - assertFalse(r[cell00+37] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+38] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+39] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+40] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+41] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+42] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+43] instanceof LastCellOfRowDummyRecord); - assertTrue(r[cell00+44] instanceof LastCellOfRowDummyRecord); - // Row 22 - assertFalse(r[cell00+45] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+46] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+47] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+48] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+49] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+50] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+51] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+52] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+53] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+54] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+55] instanceof LastCellOfRowDummyRecord); - assertFalse(r[cell00+56] instanceof LastCellOfRowDummyRecord); - assertTrue(r[cell00+57] instanceof LastCellOfRowDummyRecord); - - // Check the numbers of the last seen columns - LastCellOfRowDummyRecord[] lrs = new LastCellOfRowDummyRecord[24]; - int lrscount = 0; - for (final Record rec : r) { - if(rec instanceof LastCellOfRowDummyRecord) { - lrs[lrscount] = (LastCellOfRowDummyRecord)rec; - lrscount++; - } + HSSFEventFactory factory = new HSSFEventFactory(); + try (InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName); + POIFSFileSystem fs = new POIFSFileSystem(is)) { + factory.processWorkbookEvents(req, fs); } - - assertEquals(0, lrs[0].getLastColumnNumber()); - assertEquals(0, lrs[0].getRow()); - - assertEquals(3, lrs[1].getLastColumnNumber()); - assertEquals(1, lrs[1].getRow()); - - assertEquals(5, lrs[2].getLastColumnNumber()); - assertEquals(2, lrs[2].getRow()); - - for(int i=3; i<=19; i++) { - assertEquals(-1, lrs[i].getLastColumnNumber()); - assertEquals(i, lrs[i].getRow()); - } - - assertEquals(4, lrs[20].getLastColumnNumber()); - assertEquals(20, lrs[20].getRow()); - - assertEquals(6, lrs[21].getLastColumnNumber()); - assertEquals(21, lrs[21].getRow()); - - assertEquals(11, lrs[22].getLastColumnNumber()); - assertEquals(22, lrs[22].getRow()); + + assertTrue(_records.size() > 100); } - - - public void testMissingCellRecords() { - openNormal(); - - // Find the cell at 0,0 - int cell00 = -1; - for(int i=0; i -1); - + + @Test + public void testMissingRowRecords() throws IOException { + readRecords("MissingBits.xls"); + // We have rows 0, 1, 2, 20 and 21 - // Row 0 has 1 entry, 0 - // Row 1 has 4 entries, 0+3 - // Row 2 has 6 entries, 0+5 - // Row 20 has 5 entries, 0-5 - // Row 21 has 7 entries, 0+1+3+5+6 - // Row 22 has 12 entries, 0+3+4+11 - - // Row 0 - assertFalse(r[cell00+0] instanceof MissingCellDummyRecord); - assertFalse(r[cell00+1] instanceof MissingCellDummyRecord); - - // Row 1 - assertFalse(r[cell00+2] instanceof MissingCellDummyRecord); - assertTrue(r[cell00+3] instanceof MissingCellDummyRecord); - assertTrue(r[cell00+4] instanceof MissingCellDummyRecord); - assertFalse(r[cell00+5] instanceof MissingCellDummyRecord); - assertFalse(r[cell00+6] instanceof MissingCellDummyRecord); - - // Row 2 - assertFalse(r[cell00+7] instanceof MissingCellDummyRecord); - assertTrue(r[cell00+8] instanceof MissingCellDummyRecord); - assertTrue(r[cell00+9] instanceof MissingCellDummyRecord); - assertTrue(r[cell00+10] instanceof MissingCellDummyRecord); - assertTrue(r[cell00+11] instanceof MissingCellDummyRecord); - assertFalse(r[cell00+12] instanceof MissingCellDummyRecord); - assertFalse(r[cell00+13] instanceof MissingCellDummyRecord); - - // Row 3-19 - assertFalse(r[cell00+14] instanceof MissingCellDummyRecord); - assertFalse(r[cell00+15] instanceof MissingCellDummyRecord); - - // Row 20 - assertFalse(r[cell00+31] instanceof MissingCellDummyRecord); - assertFalse(r[cell00+32] instanceof MissingCellDummyRecord); - assertFalse(r[cell00+33] instanceof MissingCellDummyRecord); - assertFalse(r[cell00+34] instanceof MissingCellDummyRecord); - assertFalse(r[cell00+35] instanceof MissingCellDummyRecord); - assertFalse(r[cell00+36] instanceof MissingCellDummyRecord); - - // Row 21 - assertFalse(r[cell00+37] instanceof MissingCellDummyRecord); - assertFalse(r[cell00+38] instanceof MissingCellDummyRecord); - assertTrue(r[cell00+39] instanceof MissingCellDummyRecord); - assertFalse(r[cell00+40] instanceof MissingCellDummyRecord); - assertTrue(r[cell00+41] instanceof MissingCellDummyRecord); - assertFalse(r[cell00+42] instanceof MissingCellDummyRecord); - assertFalse(r[cell00+43] instanceof MissingCellDummyRecord); - assertFalse(r[cell00+44] instanceof MissingCellDummyRecord); - - // Row 22 - assertFalse(r[cell00+45] instanceof MissingCellDummyRecord); - assertTrue(r[cell00+46] instanceof MissingCellDummyRecord); - assertTrue(r[cell00+47] instanceof MissingCellDummyRecord); - assertFalse(r[cell00+48] instanceof MissingCellDummyRecord); - assertFalse(r[cell00+49] instanceof MissingCellDummyRecord); - assertTrue(r[cell00+50] instanceof MissingCellDummyRecord); - assertTrue(r[cell00+51] instanceof MissingCellDummyRecord); - assertTrue(r[cell00+52] instanceof MissingCellDummyRecord); - assertTrue(r[cell00+53] instanceof MissingCellDummyRecord); - assertTrue(r[cell00+54] instanceof MissingCellDummyRecord); - assertTrue(r[cell00+55] instanceof MissingCellDummyRecord); - assertFalse(r[cell00+56] instanceof MissingCellDummyRecord); - assertFalse(r[cell00+57] instanceof MissingCellDummyRecord); - - // Check some numbers - MissingCellDummyRecord mc; - - mc = (MissingCellDummyRecord)r[cell00+3]; - assertEquals(1, mc.getRow()); - assertEquals(1, mc.getColumn()); - mc = (MissingCellDummyRecord)r[cell00+4]; - assertEquals(1, mc.getRow()); - assertEquals(2, mc.getColumn()); - - mc = (MissingCellDummyRecord)r[cell00+8]; - assertEquals(2, mc.getRow()); - assertEquals(1, mc.getColumn()); - mc = (MissingCellDummyRecord)r[cell00+9]; - assertEquals(2, mc.getRow()); - assertEquals(2, mc.getColumn()); - - mc = (MissingCellDummyRecord)r[cell00+55]; - assertEquals(22, mc.getRow()); - assertEquals(10, mc.getColumn()); + int row0 = lastIndexOf(r -> r instanceof RowRecord && ((RowRecord)r).getRowNumber() == 0); + assertTrue(row0 > -1); + + // Records: row 0: column 1, 2), then missing rows, rows 20,21,22 each 1 column + String exp1 = + "0:rr,1:rr,2:rr,3:mr,4:mr,5:mr,6:mr,7:mr,8:mr,9:mr,10:mr,11:mr,12:mr,13:mr,14:mr," + + "15:mr,16:mr,17:mr,18:mr,19:mr,20:rr,21:rr,22:rr"; + String act1 = digest(row0, 22); + assertEquals(exp1, act1); + + + // Find the cell at 0,0 + int cell00 = lastIndexOf(r -> r instanceof LabelSSTRecord && ((LabelSSTRecord)r).getRow() == 0 && ((LabelSSTRecord)r).getColumn() == 0); + + String exp2 = + "0:ls0lc0," + + "1:nr0/11mc1mc2nr3/23lc3," + + "2:nr0/45mc1mc2mc3mc4nr5/22lc5," + + "3:lc,4:lc,5:lc,6:lc,7:lc,8:lc,9:lc,10:lc,11:lc,12:lc,13:lc,14:lc,15:lc,16:lc,17:lc,18:lc,19:lc," + + "20:nr0/50nr1/51nr2/52nr3/53nr4/54lc4," + + "21:ls0ls1mc2nr3/12mc4nr5/23nr6/42lc6," + + "22:ls0mc1mc2ls3ls4mc5mc6mc7mc8mc9mc10ls11lc11"; + String act2 = digest(cell00, 57); + assertEquals(exp2, act2); } - - // Make sure we don't put in any extra new lines - // that aren't already there - public void testNoExtraNewLines() { + + // Make sure we don't put in any extra new lines that aren't already there + @Test + public void testNoExtraNewLines() throws IOException { // Load a different file // This file has has something in lines 1-33 readRecords("MRExtraLines.xls"); - + int rowCount=0; - for (Record rec : r) { - if(rec instanceof LastCellOfRowDummyRecord) { + for (Record rec : _records) { + if (rec instanceof LastCellOfRowDummyRecord) { LastCellOfRowDummyRecord eor = (LastCellOfRowDummyRecord) rec; assertEquals(rowCount, eor.getRow()); rowCount++; @@ -362,534 +114,114 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase { assertEquals(33, rowCount); } - private static final class MockHSSFListener implements HSSFListener { - public MockHSSFListener() {} - private final List _records = new ArrayList<>(); - private final boolean logToStdOut = false; - - @Override - public void processRecord(Record record) { - _records.add(record); - - if(record instanceof MissingRowDummyRecord) { - MissingRowDummyRecord mr = (MissingRowDummyRecord)record; - log("Got dummy row " + mr.getRowNumber()); - } - if(record instanceof MissingCellDummyRecord) { - MissingCellDummyRecord mc = (MissingCellDummyRecord)record; - log("Got dummy cell " + mc.getRow() + " " + mc.getColumn()); - } - if(record instanceof LastCellOfRowDummyRecord) { - LastCellOfRowDummyRecord lc = (LastCellOfRowDummyRecord)record; - log("Got end-of row, row was " + lc.getRow() + ", last column was " + lc.getLastColumnNumber()); - } - - if(record instanceof BOFRecord) { - BOFRecord r = (BOFRecord)record; - if(r.getType() == BOFRecord.TYPE_WORKSHEET) { - log("On new sheet"); - } - } - if(record instanceof RowRecord) { - RowRecord rr = (RowRecord)record; - log("Starting row #" + rr.getRowNumber()); - } - } - private void log(String msg) { - if(logToStdOut) { - System.out.println(msg); - } - } - public Record[] getRecords() { - Record[] result = new Record[_records.size()]; - _records.toArray(result); - return result; - } - } - /** - * Make sure that the presence of shared formulas does not cause extra - * end-of-row records. + * Make sure that the presence of shared formulas does not cause extra end-of-row records. */ - public void testEndOfRow_bug45672() { + @Test + public void testEndOfRow_bug45672() throws IOException { readRecords("ex45672.xls"); - Record[] rr = r; - int eorCount=0; - int sfrCount=0; - for (Record record : rr) { - if (record instanceof SharedFormulaRecord) { - sfrCount++; - } - if (record instanceof LastCellOfRowDummyRecord) { - eorCount++; - } - } - if (eorCount == 2) { - throw new AssertionFailedError("Identified bug 45672"); - } - assertEquals(1, eorCount); - assertEquals(1, sfrCount); - } - - /** - * MulBlank records hold multiple blank cells. Check we - * can handle them correctly. - */ - public void testMulBlankHandling() { - readRecords("45672.xls"); - - // Check that we don't have any MulBlankRecords, but do - // have lots of BlankRecords - Record[] rr = r; - int eorCount=0; - int mbrCount=0; - int brCount=0; - for (Record record : rr) { - if (record instanceof MulBlankRecord) { - mbrCount++; - } - if (record instanceof BlankRecord) { - brCount++; - } - if (record instanceof LastCellOfRowDummyRecord) { - eorCount++; - } - } - if (mbrCount > 0) { - throw new AssertionFailedError("Identified bug 45672"); - } - if (brCount < 20) { - throw new AssertionFailedError("Identified bug 45672"); - } - if (eorCount != 2) { - throw new AssertionFailedError("Identified bug 45672"); - } - assertEquals(2, eorCount); + assertEquals(1, matches(r -> r instanceof SharedFormulaRecord)); + assertEquals(1, matches(r -> r instanceof LastCellOfRowDummyRecord)); } - public void testStringRecordHandling(){ - readRecords("53588.xls"); - Record[] rr = r; - int missingCount=0; - int lastCount=0; - for (Record record : rr) { - if (record instanceof MissingCellDummyRecord) { - missingCount++; - } - if (record instanceof LastCellOfRowDummyRecord) { - lastCount++; - } - } - assertEquals(1, missingCount); - assertEquals(1, lastCount); - } - - public void testFormulasWithStringResultsHandling() { - readRecords("53433.xls"); - - int pos = 95; - - // First three rows are blank - assertEquals(DimensionsRecord.class, r[pos++].getClass()); - - assertEquals(MissingRowDummyRecord.class, r[pos].getClass()); - assertEquals(0, ((MissingRowDummyRecord)r[pos]).getRowNumber()); - pos++; - assertEquals(MissingRowDummyRecord.class, r[pos].getClass()); - assertEquals(1, ((MissingRowDummyRecord)r[pos]).getRowNumber()); - pos++; - assertEquals(MissingRowDummyRecord.class, r[pos].getClass()); - assertEquals(2, ((MissingRowDummyRecord)r[pos]).getRowNumber()); - pos++; - - // Then rows 4-10 are defined - assertEquals(RowRecord.class, r[pos].getClass()); - assertEquals(3, ((RowRecord)r[pos]).getRowNumber()); - pos++; - assertEquals(RowRecord.class, r[pos].getClass()); - assertEquals(4, ((RowRecord)r[pos]).getRowNumber()); - pos++; - assertEquals(RowRecord.class, r[pos].getClass()); - assertEquals(5, ((RowRecord)r[pos]).getRowNumber()); - pos++; - assertEquals(RowRecord.class, r[pos].getClass()); - assertEquals(6, ((RowRecord)r[pos]).getRowNumber()); - pos++; - assertEquals(RowRecord.class, r[pos].getClass()); - assertEquals(7, ((RowRecord)r[pos]).getRowNumber()); - pos++; - assertEquals(RowRecord.class, r[pos].getClass()); - assertEquals(8, ((RowRecord)r[pos]).getRowNumber()); - pos++; - assertEquals(RowRecord.class, r[pos].getClass()); - assertEquals(9, ((RowRecord)r[pos]).getRowNumber()); - pos++; - - // 5 more blank rows - assertEquals(MissingRowDummyRecord.class, r[pos].getClass()); - assertEquals(10, ((MissingRowDummyRecord)r[pos]).getRowNumber()); - pos++; - assertEquals(MissingRowDummyRecord.class, r[pos].getClass()); - assertEquals(11, ((MissingRowDummyRecord)r[pos]).getRowNumber()); - pos++; - assertEquals(MissingRowDummyRecord.class, r[pos].getClass()); - assertEquals(12, ((MissingRowDummyRecord)r[pos]).getRowNumber()); - pos++; - assertEquals(MissingRowDummyRecord.class, r[pos].getClass()); - assertEquals(13, ((MissingRowDummyRecord)r[pos]).getRowNumber()); - pos++; - assertEquals(MissingRowDummyRecord.class, r[pos].getClass()); - assertEquals(14, ((MissingRowDummyRecord)r[pos]).getRowNumber()); - pos++; - - // 2 defined rows - assertEquals(RowRecord.class, r[pos].getClass()); - assertEquals(15, ((RowRecord)r[pos]).getRowNumber()); - pos++; - assertEquals(RowRecord.class, r[pos].getClass()); - assertEquals(16, ((RowRecord)r[pos]).getRowNumber()); - pos++; - - // one blank row - assertEquals(MissingRowDummyRecord.class, r[pos].getClass()); - assertEquals(17, ((MissingRowDummyRecord)r[pos]).getRowNumber()); - pos++; - - // one last real row - assertEquals(RowRecord.class, r[pos].getClass()); - assertEquals(18, ((RowRecord)r[pos]).getRowNumber()); - pos++; - - - - // Now onto the cells - - // Because the 3 first rows are missing, should have last-of-row records first - assertEquals(LastCellOfRowDummyRecord.class, r[pos].getClass()); - assertEquals(0, ((LastCellOfRowDummyRecord)r[pos]).getRow()); - assertEquals(-1, ((LastCellOfRowDummyRecord)r[pos]).getLastColumnNumber()); - pos++; - assertEquals(LastCellOfRowDummyRecord.class, r[pos].getClass()); - assertEquals(1, ((LastCellOfRowDummyRecord)r[pos]).getRow()); - assertEquals(-1, ((LastCellOfRowDummyRecord)r[pos]).getLastColumnNumber()); - pos++; - assertEquals(LastCellOfRowDummyRecord.class, r[pos].getClass()); - assertEquals(2, ((LastCellOfRowDummyRecord)r[pos]).getRow()); - assertEquals(-1, ((LastCellOfRowDummyRecord)r[pos]).getLastColumnNumber()); - pos++; - - - // Onto row 4 (=3) - - // Now we have blank cell A4 - assertEquals(MissingCellDummyRecord.class, r[pos].getClass()); - assertEquals(3, ((MissingCellDummyRecord)r[pos]).getRow()); - assertEquals(0, ((MissingCellDummyRecord)r[pos]).getColumn()); - pos++; - - // Now 4 real cells, all strings - assertEquals(LabelSSTRecord.class, r[pos].getClass()); - assertEquals(3, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(1, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - assertEquals(LabelSSTRecord.class, r[pos].getClass()); - assertEquals(3, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(2, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - assertEquals(LabelSSTRecord.class, r[pos].getClass()); - assertEquals(3, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(3, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - assertEquals(LabelSSTRecord.class, r[pos].getClass()); - assertEquals(3, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(4, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - - // Final dummy cell for the end-of-row - assertEquals(LastCellOfRowDummyRecord.class, r[pos].getClass()); - assertEquals(3, ((LastCellOfRowDummyRecord)r[pos]).getRow()); - assertEquals(4, ((LastCellOfRowDummyRecord)r[pos]).getLastColumnNumber()); - pos++; - - - // Row 5 has string, formula of string, number, formula of string - assertEquals(MissingCellDummyRecord.class, r[pos].getClass()); - assertEquals(4, ((MissingCellDummyRecord)r[pos]).getRow()); - assertEquals(0, ((MissingCellDummyRecord)r[pos]).getColumn()); - pos++; - - assertEquals(LabelSSTRecord.class, r[pos].getClass()); - assertEquals(4, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(1, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - assertEquals(FormulaRecord.class, r[pos].getClass()); - assertEquals(4, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(2, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - assertEquals(StringRecord.class, r[pos].getClass()); - assertEquals("s1", ((StringRecord)r[pos]).getString()); - pos++; - assertEquals(NumberRecord.class, r[pos].getClass()); - assertEquals(4, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(3, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - assertEquals(FormulaRecord.class, r[pos].getClass()); - assertEquals(4, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(4, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - assertEquals(StringRecord.class, r[pos].getClass()); - assertEquals("s3845", ((StringRecord)r[pos]).getString()); - pos++; - - // Final dummy cell for the end-of-row - assertEquals(LastCellOfRowDummyRecord.class, r[pos].getClass()); - assertEquals(4, ((LastCellOfRowDummyRecord)r[pos]).getRow()); - assertEquals(4, ((LastCellOfRowDummyRecord)r[pos]).getLastColumnNumber()); - pos++; - - - // Row 6 is blank / string formula / number / number / string formula - assertEquals(MissingCellDummyRecord.class, r[pos].getClass()); - assertEquals(5, ((MissingCellDummyRecord)r[pos]).getRow()); - assertEquals(0, ((MissingCellDummyRecord)r[pos]).getColumn()); - pos++; - - assertEquals(FormulaRecord.class, r[pos].getClass()); - assertEquals(5, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(1, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - assertEquals(StringRecord.class, r[pos].getClass()); - assertEquals("s4", ((StringRecord)r[pos]).getString()); - pos++; - assertEquals(NumberRecord.class, r[pos].getClass()); - assertEquals(5, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(2, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - assertEquals(NumberRecord.class, r[pos].getClass()); - assertEquals(5, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(3, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - assertEquals(FormulaRecord.class, r[pos].getClass()); - assertEquals(5, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(4, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - assertEquals(StringRecord.class, r[pos].getClass()); - assertEquals("s3845", ((StringRecord)r[pos]).getString()); - pos++; - - assertEquals(LastCellOfRowDummyRecord.class, r[pos].getClass()); - assertEquals(5, ((LastCellOfRowDummyRecord)r[pos]).getRow()); - assertEquals(4, ((LastCellOfRowDummyRecord)r[pos]).getLastColumnNumber()); - pos++; - - - // Row 7 is blank / blank / number / number / number - assertEquals(MissingCellDummyRecord.class, r[pos].getClass()); - assertEquals(6, ((MissingCellDummyRecord)r[pos]).getRow()); - assertEquals(0, ((MissingCellDummyRecord)r[pos]).getColumn()); - pos++; - assertEquals(MissingCellDummyRecord.class, r[pos].getClass()); - assertEquals(6, ((MissingCellDummyRecord)r[pos]).getRow()); - assertEquals(1, ((MissingCellDummyRecord)r[pos]).getColumn()); - pos++; - - assertEquals(NumberRecord.class, r[pos].getClass()); - assertEquals(6, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(2, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - assertEquals(NumberRecord.class, r[pos].getClass()); - assertEquals(6, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(3, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - assertEquals(NumberRecord.class, r[pos].getClass()); - assertEquals(6, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(4, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - - assertEquals(LastCellOfRowDummyRecord.class, r[pos].getClass()); - assertEquals(6, ((LastCellOfRowDummyRecord)r[pos]).getRow()); - assertEquals(4, ((LastCellOfRowDummyRecord)r[pos]).getLastColumnNumber()); - pos++; - - - // Row 8 is blank / string / number formula / string formula / blank - assertEquals(MissingCellDummyRecord.class, r[pos].getClass()); - assertEquals(7, ((MissingCellDummyRecord)r[pos]).getRow()); - assertEquals(0, ((MissingCellDummyRecord)r[pos]).getColumn()); - pos++; - - assertEquals(LabelSSTRecord.class, r[pos].getClass()); - assertEquals(7, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(1, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - assertEquals(FormulaRecord.class, r[pos].getClass()); - assertEquals(7, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(2, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - assertEquals(FormulaRecord.class, r[pos].getClass()); - assertEquals(7, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(3, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - assertEquals(StringRecord.class, r[pos].getClass()); - assertEquals("s4", ((StringRecord)r[pos]).getString()); - pos++; - assertEquals(BlankRecord.class, r[pos].getClass()); - assertEquals(7, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(4, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - - assertEquals(LastCellOfRowDummyRecord.class, r[pos].getClass()); - assertEquals(7, ((LastCellOfRowDummyRecord)r[pos]).getRow()); - assertEquals(4, ((LastCellOfRowDummyRecord)r[pos]).getLastColumnNumber()); - pos++; - - - // Row 9 is empty, but with a blank at E9 - assertEquals(MissingCellDummyRecord.class, r[pos].getClass()); - assertEquals(8, ((MissingCellDummyRecord)r[pos]).getRow()); - assertEquals(0, ((MissingCellDummyRecord)r[pos]).getColumn()); - pos++; - assertEquals(MissingCellDummyRecord.class, r[pos].getClass()); - assertEquals(8, ((MissingCellDummyRecord)r[pos]).getRow()); - assertEquals(1, ((MissingCellDummyRecord)r[pos]).getColumn()); - pos++; - assertEquals(MissingCellDummyRecord.class, r[pos].getClass()); - assertEquals(8, ((MissingCellDummyRecord)r[pos]).getRow()); - assertEquals(2, ((MissingCellDummyRecord)r[pos]).getColumn()); - pos++; - assertEquals(MissingCellDummyRecord.class, r[pos].getClass()); - assertEquals(8, ((MissingCellDummyRecord)r[pos]).getRow()); - assertEquals(3, ((MissingCellDummyRecord)r[pos]).getColumn()); - pos++; - assertEquals(BlankRecord.class, r[pos].getClass()); - assertEquals(8, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(4, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - assertEquals(LastCellOfRowDummyRecord.class, r[pos].getClass()); - assertEquals(8, ((LastCellOfRowDummyRecord)r[pos]).getRow()); - assertEquals(4, ((LastCellOfRowDummyRecord)r[pos]).getLastColumnNumber()); - pos++; - - - // Row 10 has a string in D10 - assertEquals(MissingCellDummyRecord.class, r[pos].getClass()); - assertEquals(9, ((MissingCellDummyRecord)r[pos]).getRow()); - assertEquals(0, ((MissingCellDummyRecord)r[pos]).getColumn()); - pos++; - assertEquals(MissingCellDummyRecord.class, r[pos].getClass()); - assertEquals(9, ((MissingCellDummyRecord)r[pos]).getRow()); - assertEquals(1, ((MissingCellDummyRecord)r[pos]).getColumn()); - pos++; - assertEquals(MissingCellDummyRecord.class, r[pos].getClass()); - assertEquals(9, ((MissingCellDummyRecord)r[pos]).getRow()); - assertEquals(2, ((MissingCellDummyRecord)r[pos]).getColumn()); - pos++; - assertEquals(LabelSSTRecord.class, r[pos].getClass()); - assertEquals(9, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(3, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - assertEquals(LastCellOfRowDummyRecord.class, r[pos].getClass()); - assertEquals(9, ((LastCellOfRowDummyRecord)r[pos]).getRow()); - assertEquals(3, ((LastCellOfRowDummyRecord)r[pos]).getLastColumnNumber()); - pos++; - - - // Now 5 blank rows - assertEquals(LastCellOfRowDummyRecord.class, r[pos].getClass()); - assertEquals(10, ((LastCellOfRowDummyRecord)r[pos]).getRow()); - assertEquals(-1, ((LastCellOfRowDummyRecord)r[pos]).getLastColumnNumber()); - pos++; - assertEquals(LastCellOfRowDummyRecord.class, r[pos].getClass()); - assertEquals(11, ((LastCellOfRowDummyRecord)r[pos]).getRow()); - assertEquals(-1, ((LastCellOfRowDummyRecord)r[pos]).getLastColumnNumber()); - pos++; - assertEquals(LastCellOfRowDummyRecord.class, r[pos].getClass()); - assertEquals(12, ((LastCellOfRowDummyRecord)r[pos]).getRow()); - assertEquals(-1, ((LastCellOfRowDummyRecord)r[pos]).getLastColumnNumber()); - pos++; - assertEquals(LastCellOfRowDummyRecord.class, r[pos].getClass()); - assertEquals(13, ((LastCellOfRowDummyRecord)r[pos]).getRow()); - assertEquals(-1, ((LastCellOfRowDummyRecord)r[pos]).getLastColumnNumber()); - pos++; - assertEquals(LastCellOfRowDummyRecord.class, r[pos].getClass()); - assertEquals(14, ((LastCellOfRowDummyRecord)r[pos]).getRow()); - assertEquals(-1, ((LastCellOfRowDummyRecord)r[pos]).getLastColumnNumber()); - pos++; - - - // Row 16 has a single string in B16 - assertEquals(MissingCellDummyRecord.class, r[pos].getClass()); - assertEquals(15, ((MissingCellDummyRecord)r[pos]).getRow()); - assertEquals(0, ((MissingCellDummyRecord)r[pos]).getColumn()); - pos++; - assertEquals(LabelSSTRecord.class, r[pos].getClass()); - assertEquals(15, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(1, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - assertEquals(LastCellOfRowDummyRecord.class, r[pos].getClass()); - assertEquals(15, ((LastCellOfRowDummyRecord)r[pos]).getRow()); - assertEquals(1, ((LastCellOfRowDummyRecord)r[pos]).getLastColumnNumber()); - pos++; - - - // Row 17 has a single string in D17 - assertEquals(MissingCellDummyRecord.class, r[pos].getClass()); - assertEquals(16, ((MissingCellDummyRecord)r[pos]).getRow()); - assertEquals(0, ((MissingCellDummyRecord)r[pos]).getColumn()); - pos++; - assertEquals(MissingCellDummyRecord.class, r[pos].getClass()); - assertEquals(16, ((MissingCellDummyRecord)r[pos]).getRow()); - assertEquals(1, ((MissingCellDummyRecord)r[pos]).getColumn()); - pos++; - assertEquals(MissingCellDummyRecord.class, r[pos].getClass()); - assertEquals(16, ((MissingCellDummyRecord)r[pos]).getRow()); - assertEquals(2, ((MissingCellDummyRecord)r[pos]).getColumn()); - pos++; - assertEquals(LabelSSTRecord.class, r[pos].getClass()); - assertEquals(16, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(3, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - assertEquals(LastCellOfRowDummyRecord.class, r[pos].getClass()); - assertEquals(16, ((LastCellOfRowDummyRecord)r[pos]).getRow()); - assertEquals(3, ((LastCellOfRowDummyRecord)r[pos]).getLastColumnNumber()); - pos++; - - - // Row 18 is blank - assertEquals(LastCellOfRowDummyRecord.class, r[pos].getClass()); - assertEquals(17, ((LastCellOfRowDummyRecord)r[pos]).getRow()); - assertEquals(-1, ((LastCellOfRowDummyRecord)r[pos]).getLastColumnNumber()); - pos++; - - - // Row 19 has a single string in E19 - assertEquals(MissingCellDummyRecord.class, r[pos].getClass()); - assertEquals(18, ((MissingCellDummyRecord)r[pos]).getRow()); - assertEquals(0, ((MissingCellDummyRecord)r[pos]).getColumn()); - pos++; - assertEquals(MissingCellDummyRecord.class, r[pos].getClass()); - assertEquals(18, ((MissingCellDummyRecord)r[pos]).getRow()); - assertEquals(1, ((MissingCellDummyRecord)r[pos]).getColumn()); - pos++; - assertEquals(MissingCellDummyRecord.class, r[pos].getClass()); - assertEquals(18, ((MissingCellDummyRecord)r[pos]).getRow()); - assertEquals(2, ((MissingCellDummyRecord)r[pos]).getColumn()); - pos++; - assertEquals(MissingCellDummyRecord.class, r[pos].getClass()); - assertEquals(18, ((MissingCellDummyRecord)r[pos]).getRow()); - assertEquals(3, ((MissingCellDummyRecord)r[pos]).getColumn()); - pos++; - assertEquals(LabelSSTRecord.class, r[pos].getClass()); - assertEquals(18, ((CellValueRecordInterface)r[pos]).getRow()); - assertEquals(4, ((CellValueRecordInterface)r[pos]).getColumn()); - pos++; - assertEquals(LastCellOfRowDummyRecord.class, r[pos].getClass()); - assertEquals(18, ((LastCellOfRowDummyRecord)r[pos]).getRow()); - assertEquals(4, ((LastCellOfRowDummyRecord)r[pos]).getLastColumnNumber()); - pos++; - - - // And that's it! - assertEquals(WindowTwoRecord.class, r[pos++].getClass()); - } + /** + * MulBlank records hold multiple blank cells. + * Check that we don't have any MulBlankRecords, but do have lots of BlankRecords + */ + @Test + public void testMulBlankHandling() throws IOException { + readRecords("45672.xls"); + assertEquals(20, matches(r -> r instanceof BlankRecord)); + assertEquals(2, matches(r -> r instanceof LastCellOfRowDummyRecord)); + assertEquals(0, matches(r -> r instanceof MulBlankRecord)); + } + + @Test + public void testStringRecordHandling() throws IOException { + readRecords("53588.xls"); + assertEquals(1, matches(r -> r instanceof MissingCellDummyRecord)); + assertEquals(1, matches(r -> r instanceof LastCellOfRowDummyRecord)); + } + + @Test + public void testFormulasWithStringResultsHandling() throws IOException { + readRecords("53433.xls"); + + String exp = + "dr0:mr,1:mr,2:mr,3:rr,4:rr,5:rr,6:rr,7:rr,8:rr,9:rr,10:mr,11:mr,12:mr,13:mr,14:mr,15:rr,16:rr,17:mr,18:rr," + + "0:lc,1:lc,2:lc,3:mc0ls1ls2ls3ls4lc4,4:mc0ls1cv2urnr3/12cv4urlc4," + + "5:mc0cv1urnr2/23nr3/23cv4urlc4,6:mc0mc1nr2/25nr3/45nr4/32815lc4," + + "7:mc0ls1cv2cv3urcv4lc4,8:mc0mc1mc2mc3cv4lc4,9:mc0mc1mc2ls3lc3," + + "10:lc,11:lc,12:lc,13:lc,14:lc,15:mc0ls1lc1,16:mc0mc1mc2ls3lc3," + + "17:lc,18:mc0mc1mc2mc3ls4lc4wr"; + String act = digest(95, 89); + assertEquals(exp, act); + } + + private int lastIndexOf(Predicate pre) { + int found = -1; + int i = 0; + for (Record r : _records) { + if (pre.test(r)) { + found = i; + } + i++; + } + return found; + } + + private String digest(int start, int len) { + StringBuilder sb = new StringBuilder(len*10); + int lastRow = -1; + for (Record r : _records.subList(start, start+len+1)) { + String dig = null; + int row = -1; + if (r instanceof RowRecord) { + RowRecord rr = (RowRecord)r; + row = rr.getRowNumber(); + dig = "rr"; + } else if (r instanceof MissingRowDummyRecord) { + MissingRowDummyRecord mr = (MissingRowDummyRecord)r; + row = mr.getRowNumber(); + dig = "mr"; + } else if (r instanceof MissingCellDummyRecord) { + MissingCellDummyRecord mc = (MissingCellDummyRecord)r; + row = mc.getRow(); + dig = "mc" + mc.getColumn(); + } else if (r instanceof LastCellOfRowDummyRecord) { + LastCellOfRowDummyRecord lc = (LastCellOfRowDummyRecord)r; + row = lc.getRow(); + dig = "lc" + (lc.getLastColumnNumber() > -1 ? lc.getLastColumnNumber() : ""); + } else if (r instanceof NumberRecord) { + NumberRecord nr = (NumberRecord)r; + row = nr.getRow(); + dig = "nr" + nr.getColumn() + "/" + (int)nr.getValue(); + } else if (r instanceof LabelSSTRecord) { + LabelSSTRecord ls = (LabelSSTRecord) r; + row = ls.getRow(); + dig = "ls" + ls.getColumn(); + } else if (r instanceof WindowTwoRecord) { + dig = "wr"; + } else if (r instanceof DimensionsRecord) { + dig = "dr"; + } else if (r instanceof CellValueRecordInterface) { + CellValueRecordInterface cv = (CellValueRecordInterface) r; + row = cv.getRow(); + dig = "cv" + cv.getColumn(); + } else { + // unhandled record + dig = "ur"; + } + if (lastRow != row && row > -1) { + sb.append((lastRow > -1 ? "," : "") + row + ":"); + lastRow = row; + } + sb.append(dig); + } + return sb.toString(); + } + + private long matches(Predicate r) { + return _records.stream().filter(r).count(); + } } diff --git a/src/testcases/org/apache/poi/hssf/model/TestEscherRecordFactory.java b/src/testcases/org/apache/poi/hssf/model/TestEscherRecordFactory.java index 905641f0a3..c0b00c2c64 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestEscherRecordFactory.java +++ b/src/testcases/org/apache/poi/hssf/model/TestEscherRecordFactory.java @@ -17,7 +17,16 @@ package org.apache.poi.hssf.model; -import junit.framework.TestCase; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.List; +import java.util.Random; + import org.apache.poi.ddf.DefaultEscherRecordFactory; import org.apache.poi.ddf.EscherContainerRecord; import org.apache.poi.ddf.EscherTextboxRecord; @@ -28,19 +37,9 @@ import org.apache.poi.hssf.record.RecordBase; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFTestHelper; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.junit.Test; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.List; -import java.util.Random; - -import static org.junit.Assert.assertArrayEquals; - -/** - * @author Evgeniy Berlog - * @date 18.06.12 - */ -public class TestEscherRecordFactory extends TestCase{ +public class TestEscherRecordFactory { private static byte[] toByteArray(List records) { ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -55,6 +54,7 @@ public class TestEscherRecordFactory extends TestCase{ return out.toByteArray(); } + @Test public void testDetectContainer() { Random rnd = new Random(); assertTrue(DefaultEscherRecordFactory.isContainer((short) 0x0, EscherContainerRecord.DG_CONTAINER)); @@ -79,6 +79,7 @@ public class TestEscherRecordFactory extends TestCase{ assertFalse(DefaultEscherRecordFactory.isContainer((short) 0xCCCC, EscherTextboxRecord.RECORD_ID)); } + @Test public void testDgContainerMustBeRootOfHSSFSheetEscherRecords() throws IOException { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("47251.xls"); HSSFSheet sh = wb.getSheetAt(0); diff --git a/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java b/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java index d7ab7aa48d..aba91ad718 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java +++ b/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java @@ -17,29 +17,29 @@ package org.apache.poi.hssf.model; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; -import org.apache.poi.ss.formula.ptg.AttrPtg; -import org.apache.poi.ss.formula.ptg.NamePtg; -import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; import org.apache.poi.hssf.usermodel.HSSFName; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.ss.formula.FormulaParseException; +import org.apache.poi.ss.formula.ptg.AttrPtg; +import org.apache.poi.ss.formula.ptg.NamePtg; +import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellValue; +import org.junit.Test; /** * Test the low level formula parser functionality, * but using parts which need to use * HSSFFormulaEvaluator. */ -public final class TestFormulaParserEval extends TestCase { +public final class TestFormulaParserEval { + @Test public void testWithNamedRange() { HSSFWorkbook workbook = new HSSFWorkbook(); @@ -75,6 +75,7 @@ public final class TestFormulaParserEval extends TestCase { assertEquals(AttrPtg.class, ptgs[1].getClass()); } + @Test public void testEvaluateFormulaWithRowBeyond32768_Bug44539() { HSSFWorkbook wb = new HSSFWorkbook(); @@ -90,15 +91,8 @@ public final class TestFormulaParserEval extends TestCase { sheet.createRow(32769).createCell(0).setCellValue(11); HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); - CellValue result; - try { - result = fe.evaluate(cell); - } catch (FormulaParseException e) { - if (!e.getMessage().equals("Found reference to named range \"A\", but that named range wasn't defined!")) { - throw new AssertionFailedError("Identifed bug 44539"); - } - throw e; - } + // Check for: Found reference to named range "A", but that named range wasn't defined! + CellValue result= fe.evaluate(cell); assertEquals(CellType.NUMERIC, result.getCellType()); assertEquals(42.0, result.getNumberValue(), 0.0); } diff --git a/src/testcases/org/apache/poi/hssf/model/TestFormulaParserIf.java b/src/testcases/org/apache/poi/hssf/model/TestFormulaParserIf.java index 250263392e..6897ccb88c 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestFormulaParserIf.java +++ b/src/testcases/org/apache/poi/hssf/model/TestFormulaParserIf.java @@ -17,8 +17,8 @@ package org.apache.poi.hssf.model; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import org.apache.poi.ss.formula.ptg.AddPtg; import org.apache.poi.ss.formula.ptg.AttrPtg; @@ -33,11 +33,12 @@ import org.apache.poi.ss.formula.ptg.NotEqualPtg; import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.formula.ptg.RefPtg; import org.apache.poi.ss.formula.ptg.StringPtg; +import org.junit.Test; /** * Tests FormulaParser specifically with respect to IF() functions */ -public final class TestFormulaParserIf extends TestCase { +public final class TestFormulaParserIf { private static Ptg[] parseFormula(String formula) { return TestFormulaParser.parseFormula(formula); } @@ -48,18 +49,15 @@ public final class TestFormulaParserIf extends TestCase { private static void confirmAttrData(Ptg[] ptgs, int i, int expectedData) { Ptg ptg = ptgs[i]; - if (!(ptg instanceof AttrPtg)) { - throw new AssertionFailedError("Token[" + i + "] was not AttrPtg as expected"); - } + assertTrue("Token[" + i + "] was not AttrPtg as expected", ptg instanceof AttrPtg); AttrPtg attrPtg = (AttrPtg) ptg; assertEquals(expectedData, attrPtg.getData()); } + @Test public void testSimpleIf() { - Class[] expClss; - - expClss = new Class[] { + Class[] expClss = { RefPtg.class, AttrPtg.class, // tAttrIf IntPtg.class, @@ -76,11 +74,10 @@ public final class TestFormulaParserIf extends TestCase { confirmAttrData(ptgs, 5, 3); } + @Test public void testSimpleIfNoFalseParam() { - Class[] expClss; - - expClss = new Class[] { + Class[] expClss = { RefPtg.class, AttrPtg.class, // tAttrIf RefPtg.class, @@ -94,11 +91,10 @@ public final class TestFormulaParserIf extends TestCase { confirmAttrData(ptgs, 3, 3); } + @Test public void testIfWithLargeParams() { - Class[] expClss; - - expClss = new Class[] { + Class[] expClss = { RefPtg.class, AttrPtg.class, // tAttrIf @@ -126,12 +122,10 @@ public final class TestFormulaParserIf extends TestCase { confirmAttrData(ptgs, 13, 3); } + @Test public void testNestedIf() { - Class[] expClss; - - expClss = new Class[] { - + Class[] expClss = { RefPtg.class, AttrPtg.class, // A tAttrIf RefPtg.class, @@ -165,6 +159,7 @@ public final class TestFormulaParserIf extends TestCase { confirmAttrData(ptgs, 17, 3); } + @Test public void testEmbeddedIf() { Ptg[] ptgs = parseFormula("IF(3>=1,\"*\",IF(4<>1,\"first\",\"second\"))"); assertEquals(17, ptgs.length); @@ -174,19 +169,22 @@ public final class TestFormulaParserIf extends TestCase { assertEquals("15th Ptg is not the inner IF variable function ptg",FuncVarPtg.class,ptgs[14].getClass()); } - + @Test public void testSimpleLogical() { Ptg[] ptgs = parseFormula("IF(A1 recList = Arrays.asList(recs); WorkbookRecordList wrl = new WorkbookRecordList(); - - LinkTable lt; - try { - lt = new LinkTable(recList, 0, wrl, Collections.emptyMap()); - } catch (RuntimeException e) { - if (e.getMessage().equals("Expected an EXTERNSHEET record but got (org.apache.poi.hssf.record.SSTRecord)")) { - throw new AssertionFailedError("Identified bug 47001b"); - } - - throw e; - } - assertNotNull(lt); - } - /** - * - */ + // Bug 47001b: Expected an EXTERNSHEET record but got (org.apache.poi.hssf.record.SSTRecord) + LinkTable lt = new LinkTable(recList, 0, wrl, Collections.emptyMap()); + assertNotNull(lt); + } + + @Test public void testNameCommentRecordBetweenNameRecords() { final Record[] recs = { @@ -184,9 +156,10 @@ public final class TestLinkTable extends TestCase { assertSame(recs[1], commentRecords.get("name1")); //== is intentionally not .equals()! assertSame(recs[3], commentRecords.get("name2")); //== is intentionally not .equals()! - assertEquals(2, lt.getNumNames()); + assertEquals(2, lt.getNumNames()); } + @Test public void testAddNameX(){ WorkbookRecordList wrl = new WorkbookRecordList(); wrl.add(0, new BOFRecord()); @@ -217,13 +190,17 @@ public final class TestLinkTable extends TestCase { NameXPtg namex1 = tbl.addNameXPtg("ISODD"); // adds two new rercords assertEquals(0, namex1.getSheetRefIndex()); assertEquals(0, namex1.getNameIndex()); - assertEquals(namex1.toString(), tbl.getNameXPtg("ISODD", -1).toString()); - + NameXPtg act = tbl.getNameXPtg("ISODD", -1); + assertNotNull(act); + assertEquals(namex1.toString(), act.toString()); + // Can only find on the right sheet ref, if restricting - assertEquals(namex1.toString(), tbl.getNameXPtg("ISODD", 0).toString()); + act = tbl.getNameXPtg("ISODD", 0); + assertNotNull(act); + assertEquals(namex1.toString(), act.toString()); assertNull(tbl.getNameXPtg("ISODD", 1)); assertNull(tbl.getNameXPtg("ISODD", 2)); - + // assure they are in place: // [BOFRecord] // [CountryRecord] @@ -251,7 +228,9 @@ public final class TestLinkTable extends TestCase { NameXPtg namex2 = tbl.addNameXPtg("ISEVEN"); // adds two new rercords assertEquals(0, namex2.getSheetRefIndex()); assertEquals(1, namex2.getNameIndex()); // name index increased by one - assertEquals(namex2.toString(), tbl.getNameXPtg("ISEVEN", -1).toString()); + act = tbl.getNameXPtg("ISEVEN", -1); + assertNotNull(act); + assertEquals(namex2.toString(), act.toString()); assertEquals(8, wrl.getRecords().size()); // assure they are in place: // [BOFRecord] diff --git a/src/testcases/org/apache/poi/hssf/model/TestOperandClassTransformer.java b/src/testcases/org/apache/poi/hssf/model/TestOperandClassTransformer.java index 5c9a935a0e..ec2158d315 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestOperandClassTransformer.java +++ b/src/testcases/org/apache/poi/hssf/model/TestOperandClassTransformer.java @@ -17,8 +17,10 @@ package org.apache.poi.hssf.model; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; import org.apache.poi.ss.formula.eval.BlankEval; import org.apache.poi.ss.formula.eval.ErrorEval; @@ -29,13 +31,13 @@ import org.apache.poi.ss.formula.functions.MatrixFunction; import org.apache.poi.ss.formula.ptg.AbstractFunctionPtg; import org.apache.poi.ss.formula.ptg.FuncVarPtg; import org.apache.poi.ss.formula.ptg.Ptg; +import org.junit.Ignore; +import org.junit.Test; /** * Tests specific formula examples in OperandClassTransformer. - * - * @author Josh Micich */ -public final class TestOperandClassTransformer extends TestCase { +public final class TestOperandClassTransformer { private static Ptg[] parseFormula(String formula) { Ptg[] result = HSSFFormulaParser.parse(formula, null); @@ -43,6 +45,7 @@ public final class TestOperandClassTransformer extends TestCase { return result; } + @Test public void testMdeterm() { String formula = "MDETERM(ABS(A1))"; Ptg[] ptgs = parseFormula(formula); @@ -52,6 +55,7 @@ public final class TestOperandClassTransformer extends TestCase { confirmFuncClass(ptgs, 2, "MDETERM", Ptg.CLASS_VALUE); } + @Test public void testMdetermReturnsValueInvalidOnABlankCell() { ValueEval matrixRef = EvalFactory.createAreaEval("A1:B2", new ValueEval[]{ @@ -74,7 +78,9 @@ public final class TestOperandClassTransformer extends TestCase { *

* This test has been added but disabled in order to document this issue. */ - public void DISABLED_testIndexPi1() { + @Test + @Ignore + public void testIndexPi1() { String formula = "INDEX(PI(),1)"; Ptg[] ptgs = parseFormula(formula); @@ -86,13 +92,11 @@ public final class TestOperandClassTransformer extends TestCase { * Even though count expects args of type R, because A1 is a direct operand of a * value operator it must get type V */ + @Test public void testDirectOperandOfValueOperator() { String formula = "COUNT(A1*1)"; Ptg[] ptgs = parseFormula(formula); - if (ptgs[0].getPtgClass() == Ptg.CLASS_REF) { - throw new AssertionFailedError("Identified bug 45348"); - } - + assertNotEquals(Ptg.CLASS_REF, ptgs[0].getPtgClass()); confirmTokenClass(ptgs, 0, Ptg.CLASS_VALUE); confirmTokenClass(ptgs, 3, Ptg.CLASS_VALUE); } @@ -100,6 +104,7 @@ public final class TestOperandClassTransformer extends TestCase { /** * A cell ref passed to a function expecting type V should be converted to type V */ + @Test public void testRtoV() { String formula = "lookup(A1, A3:A52, B3:B52)"; @@ -107,6 +112,7 @@ public final class TestOperandClassTransformer extends TestCase { confirmTokenClass(ptgs, 0, Ptg.CLASS_VALUE); } + @Test public void testComplexIRR_bug45041() { String formula = "(1+IRR(SUMIF(A:A,ROW(INDIRECT(MIN(A:A)&\":\"&MAX(A:A))),B:B),0))^365-1"; Ptg[] ptgs = parseFormula(formula); @@ -116,9 +122,8 @@ public final class TestOperandClassTransformer extends TestCase { assertEquals("ROW", rowFunc.getName()); assertEquals("SUMIF", sumifFunc.getName()); - if (rowFunc.getPtgClass() == Ptg.CLASS_VALUE || sumifFunc.getPtgClass() == Ptg.CLASS_VALUE) { - throw new AssertionFailedError("Identified bug 45041"); - } + assertNotEquals(Ptg.CLASS_VALUE, rowFunc.getPtgClass()); + assertNotEquals(Ptg.CLASS_VALUE, sumifFunc.getPtgClass()); confirmTokenClass(ptgs, 1, Ptg.CLASS_REF); confirmTokenClass(ptgs, 2, Ptg.CLASS_REF); confirmFuncClass(ptgs, 3, "MIN", Ptg.CLASS_VALUE); @@ -139,25 +144,7 @@ public final class TestOperandClassTransformer extends TestCase { private void confirmTokenClass(Ptg[] ptgs, int i, byte operandClass) { Ptg ptg = ptgs[i]; - if (ptg.isBaseToken()) { - throw new AssertionFailedError("ptg[" + i + "] is a base token"); - } - if (operandClass != ptg.getPtgClass()) { - throw new AssertionFailedError("Wrong operand class for ptg (" - + ptg + "). Expected " + getOperandClassName(operandClass) - + " but got " + getOperandClassName(ptg.getPtgClass())); - } - } - - private static String getOperandClassName(byte ptgClass) { - switch (ptgClass) { - case Ptg.CLASS_REF: - return "R"; - case Ptg.CLASS_VALUE: - return "V"; - case Ptg.CLASS_ARRAY: - return "A"; - } - throw new RuntimeException("Unknown operand class (" + ptgClass + ")"); + assertFalse("ptg[" + i + "] is a base token", ptg.isBaseToken()); + assertEquals(operandClass, ptg.getPtgClass()); } } diff --git a/src/testcases/org/apache/poi/hssf/model/TestSheet.java b/src/testcases/org/apache/poi/hssf/model/TestSheet.java index 84d5e65015..105cf9cb54 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestSheet.java +++ b/src/testcases/org/apache/poi/hssf/model/TestSheet.java @@ -19,40 +19,19 @@ package org.apache.poi.hssf.model; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Iterator; import java.util.List; import org.apache.poi.ddf.EscherDggRecord; import org.apache.poi.hssf.HSSFTestDataSamples; -import org.apache.poi.hssf.record.BOFRecord; -import org.apache.poi.hssf.record.BlankRecord; -import org.apache.poi.hssf.record.CellValueRecordInterface; -import org.apache.poi.hssf.record.ColumnInfoRecord; -import org.apache.poi.hssf.record.DimensionsRecord; -import org.apache.poi.hssf.record.DrawingRecord; -import org.apache.poi.hssf.record.EOFRecord; -import org.apache.poi.hssf.record.EscherAggregate; -import org.apache.poi.hssf.record.FormulaRecord; -import org.apache.poi.hssf.record.GutsRecord; -import org.apache.poi.hssf.record.IndexRecord; -import org.apache.poi.hssf.record.MergeCellsRecord; -import org.apache.poi.hssf.record.MulBlankRecord; -import org.apache.poi.hssf.record.NoteRecord; -import org.apache.poi.hssf.record.NumberRecord; -import org.apache.poi.hssf.record.ObjRecord; -import org.apache.poi.hssf.record.Record; -import org.apache.poi.hssf.record.RecordBase; -import org.apache.poi.hssf.record.RowRecord; -import org.apache.poi.hssf.record.StringRecord; -import org.apache.poi.hssf.record.TextObjectRecord; -import org.apache.poi.hssf.record.UncalcedRecord; -import org.apache.poi.hssf.record.WindowTwoRecord; +import org.apache.poi.hssf.record.*; import org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable; import org.apache.poi.hssf.record.aggregates.PageSettingsBlock; import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor; @@ -61,15 +40,12 @@ import org.apache.poi.hssf.usermodel.HSSFRichTextString; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector; import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.formula.FormulaShifter; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.util.HexRead; import org.junit.Test; -import junit.framework.AssertionFailedError; - /** * Unit test for the {@link InternalSheet} class. */ @@ -78,12 +54,6 @@ public final class TestSheet { return InternalSheet.createSheet(new RecordStream(inRecs, 0)); } - private static Record[] getSheetRecords(InternalSheet s, int offset) { - RecordCollector rc = new RecordCollector(); - s.visitContainedRecords(rc, offset); - return rc.getRecords(); - } - @Test public void testCreateSheet() { // Check we're adding row and cell aggregates @@ -93,14 +63,16 @@ public final class TestSheet { records.add(createWindow2Record()); records.add(EOFRecord.instance); InternalSheet sheet = createSheet(records); - Record[] outRecs = getSheetRecords(sheet, 0); - int pos = 0; - assertTrue(outRecs[pos++] instanceof BOFRecord ); - assertTrue(outRecs[pos++] instanceof IndexRecord); - assertTrue(outRecs[pos++] instanceof DimensionsRecord); - assertTrue(outRecs[pos++] instanceof WindowTwoRecord ); - assertTrue(outRecs[pos++] instanceof EOFRecord); + List outRecs = new ArrayList<>(); + sheet.visitContainedRecords(outRecs::add, 0); + + Iterator iter = outRecs.iterator(); + assertTrue(iter.next() instanceof BOFRecord ); + assertTrue(iter.next() instanceof IndexRecord); + assertTrue(iter.next() instanceof DimensionsRecord); + assertTrue(iter.next() instanceof WindowTwoRecord ); + assertTrue(iter.next() instanceof EOFRecord); } private static Record createWindow2Record() { @@ -134,7 +106,7 @@ public final class TestSheet { @Test public void testAddMergedRegion() { InternalSheet sheet = InternalSheet.createSheet(); - int regionsToAdd = 4096; + final int regionsToAdd = 4096; //simple test that adds a load of regions for (int n = 0; n < regionsToAdd; n++) @@ -151,8 +123,10 @@ public final class TestSheet { sheet.visitContainedRecords(mcListener, 0); int recordsAdded = mcListener.getCount(); int recordsExpected = regionsToAdd/1027; - if ((regionsToAdd % 1027) != 0) + //noinspection ConstantConditions + if ((regionsToAdd % 1027) != 0) { recordsExpected++; + } assertEquals("The " + regionsToAdd + " merged regions should have been spread out over " + recordsExpected + " records, not " + recordsAdded, recordsAdded, recordsExpected); // Check we can't add one with invalid date @@ -387,11 +361,10 @@ public final class TestSheet { public void testXFIndexForColumn() { final short TEST_IDX = 10; final short DEFAULT_IDX = 0xF; // 15 - short xfindex = Short.MIN_VALUE; InternalSheet sheet = InternalSheet.createSheet(); // without ColumnInfoRecord - xfindex = sheet.getXFIndexForColAt((short) 0); + int xfindex = sheet.getXFIndexForColAt((short) 0); assertEquals(DEFAULT_IDX, xfindex); xfindex = sheet.getXFIndexForColAt((short) 1); assertEquals(DEFAULT_IDX, xfindex); @@ -450,28 +423,6 @@ public final class TestSheet { assertEquals(DEFAULT_IDX, xfindex); } - private static final class SizeCheckingRecordVisitor implements RecordVisitor { - - private int _totalSize; - public SizeCheckingRecordVisitor() { - _totalSize = 0; - } - @Override - public void visitRecord(Record r) { - - int estimatedSize=r.getRecordSize(); - byte[] buf = new byte[estimatedSize]; - int serializedSize = r.serialize(0, buf); - if (estimatedSize != serializedSize) { - throw new AssertionFailedError("serialized size mismatch for record (" - + r.getClass().getName() + ")"); - } - _totalSize += estimatedSize; - } - public int getTotalSize() { - return _totalSize; - } - } /** * Prior to bug 45066, POI would get the estimated sheet size wrong * when an UncalcedRecord was present.

@@ -490,9 +441,16 @@ public final class TestSheet { // The original bug was due to different logic for collecting records for sizing and // serialization. The code has since been refactored into a single method for visiting // all contained records. Now this test is much less interesting - SizeCheckingRecordVisitor scrv = new SizeCheckingRecordVisitor(); - sheet.visitContainedRecords(scrv, 0); - assertEquals(90, scrv.getTotalSize()); + int[] totalSize = { 0 }; + byte[] buf = new byte[100]; + + sheet.visitContainedRecords(r -> { + int estimatedSize = r.getRecordSize(); + int serializedSize = r.serialize(0, buf); + assertEquals("serialized size mismatch for record (" + r.getClass().getName() + ")", estimatedSize, serializedSize); + totalSize[0] += estimatedSize; + }, 0); + assertEquals(90, totalSize[0]); } /** @@ -517,11 +475,9 @@ public final class TestSheet { int dbCellRecordPos = getDbCellRecordPos(sheet); - if (dbCellRecordPos == 252) { - // The overt symptom of the bug - // DBCELL record pos is calculated wrong if VRA comes before RRA - throw new AssertionFailedError("Identified bug 45145"); - } + // The overt symptom of the bug + // DBCELL record pos is calculated wrong if VRA comes before RRA + assertNotEquals (252, dbCellRecordPos); // if (false) { // // make sure that RRA and VRA are in the right place @@ -575,17 +531,10 @@ public final class TestSheet { sheet.addRow(new RowRecord(0)); sheet.addRow(new RowRecord(1)); sheet.groupRowRange( 0, 1, true ); - sheet.toString(); + assertNotNull(sheet.toString()); List recs = sheet.getRecords(); - int count=0; - for(int i=0; i< recs.size(); i++) { - if (recs.get(i) instanceof GutsRecord) { - count++; - } - } - if (count == 2) { - throw new AssertionFailedError("Identified bug 45640"); - } + long count = recs.stream().filter(r -> r instanceof GutsRecord).count(); + assertNotEquals(2, count); assertEquals(1, count); } @@ -600,7 +549,7 @@ public final class TestSheet { fail("Identified bug 45699"); } assertEquals("Informations", cell.getRichStringCellValue().getString()); - + wb.close(); } /** @@ -645,21 +594,12 @@ public final class TestSheet { inRecs.add(nr); inRecs.add(createWindow2Record()); inRecs.add(EOFRecord.instance); - InternalSheet sheet; - try { - sheet = createSheet(inRecs); - } catch (RuntimeException e) { - if ("DimensionsRecord was not found".equals(e.getMessage())) { - throw new AssertionFailedError("Identified bug 46206"); - } - throw e; - } + InternalSheet sheet = createSheet(inRecs); - RecordCollector rv = new RecordCollector(); - sheet.visitContainedRecords(rv, rowIx); - Record[] outRecs = rv.getRecords(); - assertEquals(8, outRecs.length); - DimensionsRecord dims = (DimensionsRecord) outRecs[5]; + List outRecs = new ArrayList<>(); + sheet.visitContainedRecords(outRecs::add, rowIx); + assertEquals(8, outRecs.size()); + DimensionsRecord dims = (DimensionsRecord) outRecs.get(5); assertEquals(rowIx, dims.getFirstRow()); assertEquals(rowIx, dims.getLastRow()); assertEquals(colIx, dims.getFirstCol()); @@ -683,9 +623,7 @@ public final class TestSheet { FormulaShifter shifter = FormulaShifter.createForRowShift(0, "", 0, 0, 1, SpreadsheetVersion.EXCEL97); sheet.updateFormulasAfterCellShift(shifter, 0); - if (sheetRecs.size() == 24 && sheetRecs.get(22) instanceof ConditionalFormattingTable) { - throw new AssertionFailedError("Identified bug 46547a"); - } + assertFalse(sheetRecs.size() == 24 && sheetRecs.get(22) instanceof ConditionalFormattingTable); assertEquals(23, sheetRecs.size()); } /** @@ -698,14 +636,8 @@ public final class TestSheet { InternalSheet sheet = InternalSheet.createSheet(); sheet.getOrCreateDataValidityTable(); - ConditionalFormattingTable cft; // attempt to add conditional formatting - try { - - cft = sheet.getConditionalFormattingTable(); // lazy getter - } catch (ClassCastException e) { - throw new AssertionFailedError("Identified bug 46547b"); - } + ConditionalFormattingTable cft = sheet.getConditionalFormattingTable(); assertNotNull(cft); } @@ -723,20 +655,12 @@ public final class TestSheet { InternalSheet sheet = createSheet(Arrays.asList(recs)); - InternalSheet sheet2; - try { - sheet2 = sheet.cloneSheet(); - } catch (RuntimeException e) { - if (e.getMessage().equals("The class org.apache.poi.hssf.record.MulBlankRecord needs to define a clone method")) { - throw new AssertionFailedError("Identified bug 46776"); - } - throw e; - } + InternalSheet sheet2 = sheet.cloneSheet(); - RecordCollector rc = new RecordCollector(); - sheet2.visitContainedRecords(rc, 0); - Record[] clonedRecs = rc.getRecords(); - assertEquals(recs.length+2, clonedRecs.length); // +2 for INDEX and DBCELL + List clonedRecs = new ArrayList<>(); + sheet2.visitContainedRecords(clonedRecs::add, 0); + // +2 for INDEX and DBCELL + assertEquals(recs.length+2, clonedRecs.size()); } @Test @@ -828,9 +752,10 @@ public final class TestSheet { } @Test - public void testSheetDimensions() throws IOException{ + public void testSheetDimensions() { InternalSheet sheet = InternalSheet.createSheet(); DimensionsRecord dimensions = (DimensionsRecord)sheet.findFirstRecordBySid(DimensionsRecord.sid); + assertNotNull(dimensions); assertEquals(0, dimensions.getFirstCol()); assertEquals(0, dimensions.getFirstRow()); assertEquals(1, dimensions.getLastCol()); // plus pne diff --git a/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java b/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java index 8bd521edc1..d92239bbfe 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java +++ b/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java @@ -17,15 +17,18 @@ package org.apache.poi.hssf.model; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; import org.apache.poi.hssf.record.ColumnInfoRecord; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; -/** - * @author Tony Poppleton - */ -public final class TestSheetAdditional extends TestCase { +public final class TestSheetAdditional { + @Rule + public ExpectedException thrown= ExpectedException.none(); + @Test public void testGetCellWidth() { InternalSheet sheet = InternalSheet.createSheet(); ColumnInfoRecord nci = new ColumnInfoRecord(); @@ -55,14 +58,15 @@ public final class TestSheetAdditional extends TestCase { assertEquals(100,sheet.getColumnWidth(10)); } + @Test public void testMaxColumnWidth() { InternalSheet sheet = InternalSheet.createSheet(); - sheet.setColumnWidth(0, 255*256); //the limit - try { - sheet.setColumnWidth(0, 256*256); //the limit - fail("expected exception"); - } catch (IllegalArgumentException e){ - assertEquals(e.getMessage(), "The maximum column width for an individual cell is 255 characters."); - } + // the limit + sheet.setColumnWidth(0, 255*256); + + // over the limit + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("The maximum column width for an individual cell is 255 characters."); + sheet.setColumnWidth(0, 256*256); } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestArrayRecord.java b/src/testcases/org/apache/poi/hssf/record/TestArrayRecord.java index ff5fe0ad9b..d84b514b08 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestArrayRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestArrayRecord.java @@ -17,7 +17,8 @@ package org.apache.poi.hssf.record; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFSheet; @@ -30,9 +31,11 @@ import org.apache.poi.ss.formula.FormulaType; import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.util.HexDump; import org.apache.poi.util.HexRead; +import org.junit.Test; -public final class TestArrayRecord extends TestCase { +public final class TestArrayRecord { + @Test public void testRead() { String hex = "21 02 25 00 01 00 01 00 01 01 00 00 00 00 00 00 " + @@ -58,6 +61,7 @@ public final class TestArrayRecord extends TestCase { assertEquals(HexDump.toHex(data), HexDump.toHex(ser)); } + @Test public void testBug57231() { HSSFWorkbook wb = HSSFTestDataSamples .openSampleWorkbook("57231_MixedGasReport.xls"); diff --git a/src/testcases/org/apache/poi/hssf/record/TestAutoFilterInfoRecord.java b/src/testcases/org/apache/poi/hssf/record/TestAutoFilterInfoRecord.java index 9bc4dfde22..2baf72b8a4 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestAutoFilterInfoRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestAutoFilterInfoRecord.java @@ -18,19 +18,19 @@ package org.apache.poi.hssf.record; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.junit.Test; /** * Tests the AutoFilterInfoRecord class. - * - * @author Yegor Kozlov */ -public final class TestAutoFilterInfoRecord extends TestCase { +public final class TestAutoFilterInfoRecord { private final byte[] data = new byte[] { 0x05, 0x00 }; + @Test public void testRead() { AutoFilterInfoRecord record = new AutoFilterInfoRecord(TestcaseRecordInputStream.create(AutoFilterInfoRecord.sid, data)); @@ -42,6 +42,7 @@ public final class TestAutoFilterInfoRecord extends TestCase { assertEquals(3, record.getNumEntries()); } + @Test public void testWrite() { AutoFilterInfoRecord record = new AutoFilterInfoRecord(); record.setNumEntries((short)3); @@ -52,6 +53,7 @@ public final class TestAutoFilterInfoRecord extends TestCase { assertEquals(3, record.getNumEntries()); } + @Test public void testClone() { AutoFilterInfoRecord record = new AutoFilterInfoRecord(); diff --git a/src/testcases/org/apache/poi/hssf/record/TestBoolErrRecord.java b/src/testcases/org/apache/poi/hssf/record/TestBoolErrRecord.java index 7f34a1c5dc..ee5d8af5c3 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestBoolErrRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestBoolErrRecord.java @@ -18,16 +18,19 @@ package org.apache.poi.hssf.record; import static org.junit.Assert.assertArrayEquals; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; -import org.apache.poi.hssf.record.RecordInputStream.LeftoverDataException; import org.apache.poi.util.HexRead; +import org.junit.Test; + /** * Tests for {@link BoolErrRecord} */ -public final class TestBoolErrRecord extends TestCase { +public final class TestBoolErrRecord { + @Test public void testError() { byte[] data = HexRead.readFromString( "00 00 00 00 0F 00 " + // row, col, xfIndex @@ -38,18 +41,19 @@ public final class TestBoolErrRecord extends TestCase { BoolErrRecord ber = new BoolErrRecord(in); assertTrue(ber.isError()); assertEquals(7, ber.getErrorValue()); - + TestcaseRecordInputStream.confirmRecordEncoding(BoolErrRecord.sid, data, ber.serialize()); } /** - * Bugzilla 47479 was due to an apparent error in OOO which (as of version 3.0.1) + * Bugzilla 47479 was due to an apparent error in OOO which (as of version 3.0.1) * writes the value field of BOOLERR records as 2 bytes instead of 1.
- * Coincidentally, the extra byte written is zero, which is exactly the value + * Coincidentally, the extra byte written is zero, which is exactly the value * required by the isError field. This probably why Excel seems to have * no problem. OOO does not have the same bug for error values (which wouldn't - * work by the same coincidence). + * work by the same coincidence). */ + @Test public void testOooBadFormat_bug47479() { byte[] data = HexRead.readFromString( "05 02 09 00 " + // sid, size @@ -59,19 +63,11 @@ public final class TestBoolErrRecord extends TestCase { RecordInputStream in = TestcaseRecordInputStream.create(data); BoolErrRecord ber = new BoolErrRecord(in); - boolean hasMore; - try { - hasMore = in.hasNextRecord(); - } catch (LeftoverDataException e) { - if ("Initialisation of record 0x205 left 1 bytes remaining still to be read.".equals(e.getMessage())) { - throw new AssertionFailedError("Identified bug 47479"); - } - throw e; - } + boolean hasMore = in.hasNextRecord(); assertFalse(hasMore); assertTrue(ber.isBoolean()); assertTrue(ber.getBooleanValue()); - + // Check that the record re-serializes correctly byte[] outData = ber.serialize(); byte[] expData = HexRead.readFromString( diff --git a/src/testcases/org/apache/poi/hssf/record/TestBoundSheetRecord.java b/src/testcases/org/apache/poi/hssf/record/TestBoundSheetRecord.java index 6a1dccac28..4f2f32904f 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestBoundSheetRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestBoundSheetRecord.java @@ -18,46 +18,40 @@ package org.apache.poi.hssf.record; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.List; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; - import org.apache.poi.util.HexRead; +import org.junit.Test; /** * Tests BoundSheetRecord. - * - * @see BoundSheetRecord - * - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestBoundSheetRecord extends TestCase { - +public final class TestBoundSheetRecord { + @Test public void testRecordLength() { BoundSheetRecord record = new BoundSheetRecord("Sheet1"); assertEquals(18, record.getRecordSize()); } + @Test public void testWideRecordLength() { BoundSheetRecord record = new BoundSheetRecord("Sheet\u20ac"); assertEquals(24, record.getRecordSize()); } + @Test(expected = IllegalArgumentException.class) public void testName() { BoundSheetRecord record = new BoundSheetRecord("1234567890223456789032345678904"); - - try { - record.setSheetname("s//*s"); - fail("Should have thrown IllegalArgumentException, but didnt"); - } catch (IllegalArgumentException e) { - // expected - } + record.setSheetname("s//*s"); } + @Test public void testDeserializeUnicode() { byte[] data = HexRead.readFromString("" @@ -80,6 +74,7 @@ public final class TestBoundSheetRecord extends TestCase { assertArrayEquals(data, data2); } + @Test public void testOrdering() { BoundSheetRecord bs1 = new BoundSheetRecord("SheetB"); BoundSheetRecord bs2 = new BoundSheetRecord("SheetC"); @@ -100,32 +95,28 @@ public final class TestBoundSheetRecord extends TestCase { assertEquals(bs2, r[2]); } + @Test public void testValidNames() { - confirmValid("Sheet1", true); - confirmValid("O'Brien's sales", true); - confirmValid(" data # ", true); - confirmValid("data $1.00", true); + assertTrue(isValid("Sheet1")); + assertTrue(isValid("O'Brien's sales")); + assertTrue(isValid(" data # ")); + assertTrue(isValid("data $1.00")); - confirmValid("data?", false); - confirmValid("abc/def", false); - confirmValid("data[0]", false); - confirmValid("data*", false); - confirmValid("abc\\def", false); - confirmValid("'data", false); - confirmValid("data'", false); + assertFalse(isValid("data?")); + assertFalse(isValid("abc/def")); + assertFalse(isValid("data[0]")); + assertFalse(isValid("data*")); + assertFalse(isValid("abc\\def")); + assertFalse(isValid("'data")); + assertFalse(isValid("data'")); } - private static void confirmValid(String sheetName, boolean expectedResult) { - + private static boolean isValid(String sheetName) { try { new BoundSheetRecord(sheetName); - if (!expectedResult) { - throw new AssertionFailedError("Expected sheet name '" + sheetName + "' to be invalid"); - } + return true; } catch (IllegalArgumentException e) { - if (expectedResult) { - throw new AssertionFailedError("Expected sheet name '" + sheetName + "' to be valid"); - } + return false; } } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java b/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java index 57ae686b0c..484cfc0b7d 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java @@ -17,16 +17,20 @@ package org.apache.poi.hssf.record; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import org.apache.poi.ss.util.CellRangeAddress; +import org.junit.Test; /** * Tests the serialization and deserialization of the {@link CFHeaderRecord} - * and {@link CFHeader12Record} classes works correctly. + * and {@link CFHeader12Record} classes works correctly. */ -public final class TestCFHeaderRecord extends TestCase { +public final class TestCFHeaderRecord { + @Test public void testCreateCFHeaderRecord () { CFHeaderRecord record = new CFHeaderRecord(); CellRangeAddress[] ranges = { @@ -48,17 +52,18 @@ public final class TestCFHeaderRecord extends TestCase { assertFalse(record.getNeedRecalculation()); assertEquals(0, record.getID()); - + record.setNeedRecalculation(true); assertTrue(record.getNeedRecalculation()); assertEquals(0, record.getID()); - + record.setID(7); record.setNeedRecalculation(false); assertFalse(record.getNeedRecalculation()); assertEquals(7, record.getID()); } - + + @Test public void testCreateCFHeader12Record () { CFHeader12Record record = new CFHeader12Record(); CellRangeAddress[] ranges = { @@ -80,45 +85,46 @@ public final class TestCFHeaderRecord extends TestCase { assertFalse(record.getNeedRecalculation()); assertEquals(0, record.getID()); - + record.setNeedRecalculation(true); assertTrue(record.getNeedRecalculation()); assertEquals(0, record.getID()); - + record.setID(7); record.setNeedRecalculation(false); assertFalse(record.getNeedRecalculation()); assertEquals(7, record.getID()); } - + + @Test public void testSerialization() { - byte[] recordData = + byte[] recordData = { (byte)0x03, (byte)0x00, (byte)0x01, (byte)0x00, - + (byte)0x00, (byte)0x00, (byte)0x03, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x03, (byte)0x00, - + (byte)0x04, (byte)0x00, // nRegions - + (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x00, - + (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x00, (byte)0x02, (byte)0x00, (byte)0x03, (byte)0x00, - + (byte)0x02, (byte)0x00, (byte)0x03, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x00, - + (byte)0x02, (byte)0x00, (byte)0x03, (byte)0x00, (byte)0x02, (byte)0x00, @@ -139,52 +145,40 @@ public final class TestCFHeaderRecord extends TestCase { assertEquals(recordData.length+4, record.getRecordSize()); byte[] output = record.serialize(); - - assertEquals("Output size", recordData.length+4, output.length); //includes sid+recordlength - - for (int i = 0; i < recordData.length; i++) - { - assertEquals("CFHeaderRecord doesn't match", recordData[i], output[i+4]); - } + confirmRecordEncoding(CFHeaderRecord.sid, recordData, output); } - + + @Test public void testExtremeRows() { byte[] recordData = { (byte)0x13, (byte)0x00, // nFormats (byte)0x00, (byte)0x00, - + (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, - + (byte)0x03, (byte)0x00, // nRegions - + (byte)0x40, (byte)0x9C, (byte)0x50, (byte)0xC3, (byte)0x02, (byte)0x00, (byte)0x02, (byte)0x00, - + (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFF, (byte)0x05, (byte)0x00, (byte)0x05, (byte)0x00, - + (byte)0x07, (byte)0x00, (byte)0x07, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, }; - CFHeaderRecord record; - try { - record = new CFHeaderRecord(TestcaseRecordInputStream.create(CFHeaderRecord.sid, recordData)); - } catch (IllegalArgumentException e) { - if(e.getMessage().equals("invalid cell range (-25536, 2, -15536, 2)")) { - throw new AssertionFailedError("Identified bug 44739b"); - } - throw e; - } + // bug 44739b - invalid cell range (-25536, 2, -15536, 2) + CFHeaderRecord record = new CFHeaderRecord(TestcaseRecordInputStream.create(CFHeaderRecord.sid, recordData)); assertEquals("#CFRULES", 19, record.getNumberOfConditionalFormats()); assertFalse(record.getNeedRecalculation()); @@ -196,12 +190,7 @@ public final class TestCFHeaderRecord extends TestCase { confirm(ranges[2], 7, 7, 0, 255); byte[] output = record.serialize(); - - assertEquals("Output size", recordData.length+4, output.length); //includes sid+recordlength - - for (int i = 0; i < recordData.length;i++) { - assertEquals("CFHeaderRecord doesn't match", recordData[i], output[i+4]); - } + confirmRecordEncoding(CFHeaderRecord.sid, recordData, output); } private static void confirm(CellRangeAddress cr, int expFirstRow, int expLastRow, int expFirstCol, int expLastColumn) { diff --git a/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java b/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java index 5b99e8c973..6dab9734d7 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java @@ -17,6 +17,7 @@ package org.apache.poi.hssf.record; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -26,7 +27,6 @@ import static org.junit.Assert.assertTrue; import java.io.IOException; -import junit.framework.AssertionFailedError; import org.apache.poi.hssf.HSSFITestDataProvider; import org.apache.poi.hssf.record.CFRuleBase.ComparisonOperator; import org.apache.poi.hssf.record.cf.BorderFormatting; @@ -50,126 +50,108 @@ import org.junit.Test; public final class TestCFRuleRecord { @Test public void testConstructors () throws IOException { - HSSFWorkbook workbook = new HSSFWorkbook(); - HSSFSheet sheet = workbook.createSheet(); + try (HSSFWorkbook workbook = new HSSFWorkbook()) { + HSSFSheet sheet = workbook.createSheet(); - CFRuleRecord rule1 = CFRuleRecord.create(sheet, "7"); - assertEquals(CFRuleBase.CONDITION_TYPE_FORMULA, rule1.getConditionType()); - assertEquals(ComparisonOperator.NO_COMPARISON, rule1.getComparisonOperation()); - assertNotNull(rule1.getParsedExpression1()); - assertSame(Ptg.EMPTY_PTG_ARRAY, rule1.getParsedExpression2()); + CFRuleRecord rule1 = CFRuleRecord.create(sheet, "7"); + assertEquals(CFRuleBase.CONDITION_TYPE_FORMULA, rule1.getConditionType()); + assertEquals(ComparisonOperator.NO_COMPARISON, rule1.getComparisonOperation()); + assertNotNull(rule1.getParsedExpression1()); + assertSame(Ptg.EMPTY_PTG_ARRAY, rule1.getParsedExpression2()); - CFRuleRecord rule2 = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "2", "5"); - assertEquals(CFRuleBase.CONDITION_TYPE_CELL_VALUE_IS, rule2.getConditionType()); - assertEquals(ComparisonOperator.BETWEEN, rule2.getComparisonOperation()); - assertNotNull(rule2.getParsedExpression1()); - assertNotNull(rule2.getParsedExpression2()); + CFRuleRecord rule2 = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "2", "5"); + assertEquals(CFRuleBase.CONDITION_TYPE_CELL_VALUE_IS, rule2.getConditionType()); + assertEquals(ComparisonOperator.BETWEEN, rule2.getComparisonOperation()); + assertNotNull(rule2.getParsedExpression1()); + assertNotNull(rule2.getParsedExpression2()); - CFRuleRecord rule3 = CFRuleRecord.create(sheet, ComparisonOperator.EQUAL, null, null); - assertEquals(CFRuleBase.CONDITION_TYPE_CELL_VALUE_IS, rule3.getConditionType()); - assertEquals(ComparisonOperator.EQUAL, rule3.getComparisonOperation()); - assertSame(Ptg.EMPTY_PTG_ARRAY, rule3.getParsedExpression2()); - assertSame(Ptg.EMPTY_PTG_ARRAY, rule3.getParsedExpression2()); - workbook.close(); + CFRuleRecord rule3 = CFRuleRecord.create(sheet, ComparisonOperator.EQUAL, null, null); + assertEquals(CFRuleBase.CONDITION_TYPE_CELL_VALUE_IS, rule3.getConditionType()); + assertEquals(ComparisonOperator.EQUAL, rule3.getComparisonOperation()); + assertSame(Ptg.EMPTY_PTG_ARRAY, rule3.getParsedExpression2()); + assertSame(Ptg.EMPTY_PTG_ARRAY, rule3.getParsedExpression2()); + } } @Test public void testCreateCFRuleRecord() throws IOException { - HSSFWorkbook workbook = new HSSFWorkbook(); - HSSFSheet sheet = workbook.createSheet(); - CFRuleRecord record = CFRuleRecord.create(sheet, "7"); - testCFRuleRecord(record); + try (HSSFWorkbook workbook = new HSSFWorkbook()) { + HSSFSheet sheet = workbook.createSheet(); + CFRuleRecord record = CFRuleRecord.create(sheet, "7"); + testCFRuleRecord(record); - // Serialize - byte [] serializedRecord = record.serialize(); + // Serialize + byte[] serializedRecord = record.serialize(); - // Strip header - byte [] recordData = new byte[serializedRecord.length-4]; - System.arraycopy(serializedRecord, 4, recordData, 0, recordData.length); + // Strip header + byte[] recordData = new byte[serializedRecord.length - 4]; + System.arraycopy(serializedRecord, 4, recordData, 0, recordData.length); - // Deserialize - record = new CFRuleRecord(TestcaseRecordInputStream.create(CFRuleRecord.sid, recordData)); + // Deserialize + record = new CFRuleRecord(TestcaseRecordInputStream.create(CFRuleRecord.sid, recordData)); - // Serialize again - byte[] output = record.serialize(); - - // Compare - assertEquals("Output size", recordData.length+4, output.length); //includes sid+recordlength - - for (int i = 0; i < recordData.length;i++) { - assertEquals("CFRuleRecord doesn't match", recordData[i], output[i+4]); + // Serialize again + byte[] output = record.serialize(); + confirmRecordEncoding(CFRuleRecord.sid, recordData, output); } - workbook.close(); } @Test public void testCreateCFRule12Record() throws IOException { - HSSFWorkbook workbook = new HSSFWorkbook(); - HSSFSheet sheet = workbook.createSheet(); - CFRule12Record record = CFRule12Record.create(sheet, "7"); - testCFRule12Record(record); + try (HSSFWorkbook workbook = new HSSFWorkbook()) { + HSSFSheet sheet = workbook.createSheet(); + CFRule12Record record = CFRule12Record.create(sheet, "7"); + testCFRule12Record(record); - // Serialize - byte [] serializedRecord = record.serialize(); + // Serialize + byte[] serializedRecord = record.serialize(); - // Strip header - byte [] recordData = new byte[serializedRecord.length-4]; - System.arraycopy(serializedRecord, 4, recordData, 0, recordData.length); + // Strip header + byte[] recordData = new byte[serializedRecord.length - 4]; + System.arraycopy(serializedRecord, 4, recordData, 0, recordData.length); - // Deserialize - record = new CFRule12Record(TestcaseRecordInputStream.create(CFRule12Record.sid, recordData)); + // Deserialize + record = new CFRule12Record(TestcaseRecordInputStream.create(CFRule12Record.sid, recordData)); - // Serialize again - byte[] output = record.serialize(); - - // Compare - assertEquals("Output size", recordData.length+4, output.length); //includes sid+recordlength - - for (int i = 0; i < recordData.length;i++) { - assertEquals("CFRule12Record doesn't match", recordData[i], output[i+4]); + // Serialize again + byte[] output = record.serialize(); + confirmRecordEncoding(CFRule12Record.sid, recordData, output); } - workbook.close(); } @Test public void testCreateIconCFRule12Record() throws IOException { - HSSFWorkbook workbook = new HSSFWorkbook(); - HSSFSheet sheet = workbook.createSheet(); - CFRule12Record record = CFRule12Record.create(sheet, IconSet.GREY_5_ARROWS); - record.getMultiStateFormatting().getThresholds()[1].setType(RangeType.PERCENT.id); - record.getMultiStateFormatting().getThresholds()[1].setValue(10d); - record.getMultiStateFormatting().getThresholds()[2].setType(RangeType.NUMBER.id); - record.getMultiStateFormatting().getThresholds()[2].setValue(-4d); + try (HSSFWorkbook workbook = new HSSFWorkbook()) { + HSSFSheet sheet = workbook.createSheet(); + CFRule12Record record = CFRule12Record.create(sheet, IconSet.GREY_5_ARROWS); + record.getMultiStateFormatting().getThresholds()[1].setType(RangeType.PERCENT.id); + record.getMultiStateFormatting().getThresholds()[1].setValue(10d); + record.getMultiStateFormatting().getThresholds()[2].setType(RangeType.NUMBER.id); + record.getMultiStateFormatting().getThresholds()[2].setValue(-4d); - // Check it - testCFRule12Record(record); - assertEquals(IconSet.GREY_5_ARROWS, record.getMultiStateFormatting().getIconSet()); - assertEquals(5, record.getMultiStateFormatting().getThresholds().length); + // Check it + testCFRule12Record(record); + assertEquals(IconSet.GREY_5_ARROWS, record.getMultiStateFormatting().getIconSet()); + assertEquals(5, record.getMultiStateFormatting().getThresholds().length); - // Serialize - byte [] serializedRecord = record.serialize(); + // Serialize + byte[] serializedRecord = record.serialize(); - // Strip header - byte [] recordData = new byte[serializedRecord.length-4]; - System.arraycopy(serializedRecord, 4, recordData, 0, recordData.length); + // Strip header + byte[] recordData = new byte[serializedRecord.length - 4]; + System.arraycopy(serializedRecord, 4, recordData, 0, recordData.length); - // Deserialize - record = new CFRule12Record(TestcaseRecordInputStream.create(CFRule12Record.sid, recordData)); + // Deserialize + record = new CFRule12Record(TestcaseRecordInputStream.create(CFRule12Record.sid, recordData)); - // Check it has the icon, and the right number of thresholds - assertEquals(IconSet.GREY_5_ARROWS, record.getMultiStateFormatting().getIconSet()); - assertEquals(5, record.getMultiStateFormatting().getThresholds().length); + // Check it has the icon, and the right number of thresholds + assertEquals(IconSet.GREY_5_ARROWS, record.getMultiStateFormatting().getIconSet()); + assertEquals(5, record.getMultiStateFormatting().getThresholds().length); - // Serialize again - byte[] output = record.serialize(); - - // Compare - assertEquals("Output size", recordData.length+4, output.length); //includes sid+recordlength - - for (int i = 0; i < recordData.length;i++) { - assertEquals("CFRule12Record doesn't match", recordData[i], output[i+4]); + // Serialize again + byte[] output = record.serialize(); + confirmRecordEncoding(CFRule12Record.sid, recordData, output); } - workbook.close(); } private void testCFRuleRecord(CFRuleRecord record) { @@ -391,25 +373,25 @@ public final class TestCFRuleRecord { @Test public void testWrite() throws IOException { - HSSFWorkbook workbook = new HSSFWorkbook(); - HSSFSheet sheet = workbook.createSheet(); - CFRuleRecord rr = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "5", "10"); + try (HSSFWorkbook workbook = new HSSFWorkbook()) { + HSSFSheet sheet = workbook.createSheet(); + CFRuleRecord rr = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "5", "10"); - PatternFormatting patternFormatting = new PatternFormatting(); - patternFormatting.setFillPattern(PatternFormatting.BRICKS); - rr.setPatternFormatting(patternFormatting); + PatternFormatting patternFormatting = new PatternFormatting(); + patternFormatting.setFillPattern(PatternFormatting.BRICKS); + rr.setPatternFormatting(patternFormatting); - byte[] data = rr.serialize(); - assertEquals(26, data.length); - assertEquals(3, LittleEndian.getShort(data, 6)); - assertEquals(3, LittleEndian.getShort(data, 8)); + byte[] data = rr.serialize(); + assertEquals(26, data.length); + assertEquals(3, LittleEndian.getShort(data, 6)); + assertEquals(3, LittleEndian.getShort(data, 8)); - int flags = LittleEndian.getInt(data, 10); - assertEquals("unused flags should be 111", 0x00380000, flags & 0x00380000); - assertEquals("undocumented flags should be 0000", 0, flags & 0x03C00000); // Otherwise Excel gets unhappy - // check all remaining flag bits (some are not well understood yet) - assertEquals(0x203FFFFF, flags); - workbook.close(); + int flags = LittleEndian.getInt(data, 10); + assertEquals("unused flags should be 111", 0x00380000, flags & 0x00380000); + assertEquals("undocumented flags should be 0000", 0, flags & 0x03C00000); // Otherwise Excel gets unhappy + // check all remaining flag bits (some are not well understood yet) + assertEquals(0x203FFFFF, flags); + } } private static final byte[] DATA_REFN = { @@ -433,9 +415,7 @@ public final class TestCFRuleRecord { CFRuleRecord rr = new CFRuleRecord(is); Ptg[] ptgs = rr.getParsedExpression1(); assertEquals(3, ptgs.length); - if (ptgs[0] instanceof RefPtg) { - throw new AssertionFailedError("Identified bug 45234"); - } + assertFalse("Identified bug 45234", ptgs[0] instanceof RefPtg); assertEquals(RefNPtg.class, ptgs[0].getClass()); RefNPtg refNPtg = (RefNPtg) ptgs[0]; assertTrue(refNPtg.isColRelative()); @@ -447,26 +427,26 @@ public final class TestCFRuleRecord { @Test public void testBug53691() throws IOException { - HSSFWorkbook workbook = new HSSFWorkbook(); - HSSFSheet sheet = workbook.createSheet(); + try (HSSFWorkbook workbook = new HSSFWorkbook()) { + HSSFSheet sheet = workbook.createSheet(); - CFRuleRecord record = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "2", "5"); + CFRuleRecord record = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "2", "5"); - CFRuleRecord clone = record.copy(); + CFRuleRecord clone = record.copy(); - byte [] serializedRecord = record.serialize(); - byte [] serializedClone = clone.serialize(); - assertArrayEquals(serializedRecord, serializedClone); - workbook.close(); + byte[] serializedRecord = record.serialize(); + byte[] serializedClone = clone.serialize(); + assertArrayEquals(serializedRecord, serializedClone); + } } @Test public void testBug57231_rewrite() throws IOException { - HSSFWorkbook wb1 = HSSFITestDataProvider.instance.openSampleWorkbook("57231_MixedGasReport.xls"); - assertEquals(7, wb1.getNumberOfSheets()); - HSSFWorkbook wb2 = HSSFITestDataProvider.instance.writeOutAndReadBack(wb1); - assertEquals(7, wb2.getNumberOfSheets()); - wb2.close(); - wb1.close(); + try (HSSFWorkbook wb1 = HSSFITestDataProvider.instance.openSampleWorkbook("57231_MixedGasReport.xls")) { + assertEquals(7, wb1.getNumberOfSheets()); + try (HSSFWorkbook wb2 = HSSFITestDataProvider.instance.writeOutAndReadBack(wb1)) { + assertEquals(7, wb2.getNumberOfSheets()); + } + } } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestColumnInfoRecord.java b/src/testcases/org/apache/poi/hssf/record/TestColumnInfoRecord.java index b2c56686fa..0d57714618 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestColumnInfoRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestColumnInfoRecord.java @@ -18,18 +18,18 @@ package org.apache.poi.hssf.record; import static org.junit.Assert.assertArrayEquals; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import org.apache.poi.util.HexRead; +import org.junit.Test; /** * Tests for {@link ColumnInfoRecord} - * - * @author Josh Micich */ -public final class TestColumnInfoRecord extends TestCase { +public final class TestColumnInfoRecord { + @Test public void testBasic() { byte[] data = HexRead.readFromString("7D 00 0C 00 14 00 9B 00 C7 19 0F 00 01 13 00 00"); @@ -52,21 +52,15 @@ public final class TestColumnInfoRecord extends TestCase { * The attached file was apparently created by "SoftArtisans OfficeWriter for Excel". * Excel reads that file OK and assumes zero for the value of the reserved field. */ + @Test public void testZeroResevedBytes_bug48332() { // Taken from bugzilla attachment 24661 (offset 0x1E73) byte[] inpData = HexRead.readFromString("7D 00 0A 00 00 00 00 00 D5 19 0F 00 02 00"); byte[] outData = HexRead.readFromString("7D 00 0C 00 00 00 00 00 D5 19 0F 00 02 00 00 00"); RecordInputStream in = TestcaseRecordInputStream.create(inpData); - ColumnInfoRecord cir; - try { - cir = new ColumnInfoRecord(in); - } catch (RuntimeException e) { - if (e.getMessage().equals("Unusual record size remaining=(0)")) { - throw new AssertionFailedError("Identified bug 48332"); - } - throw e; - } + // bug 48332 - Unusual record size remaining=(0) + ColumnInfoRecord cir = new ColumnInfoRecord(in); assertEquals(0, in.remaining()); assertArrayEquals(outData, cir.serialize()); } @@ -76,6 +70,7 @@ public final class TestColumnInfoRecord extends TestCase { * OddStyleRecord.xls, NoGutsRecords.xls, WORKBOOK_in_capitals.xls * but this seems to cause no problem to Excel */ + @Test public void testOneReservedByte() { byte[] inpData = HexRead.readFromString("7D 00 0B 00 00 00 00 00 24 02 0F 00 00 00 01"); byte[] outData = HexRead.readFromString("7D 00 0C 00 00 00 00 00 24 02 0F 00 00 00 01 00"); diff --git a/src/testcases/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java b/src/testcases/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java index 5f0ac2e4e9..7c0c4293f1 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java @@ -18,16 +18,19 @@ package org.apache.poi.hssf.record; -import junit.framework.TestCase; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; /** * Tests the serialization and deserialization of the {@link CommonObjectDataSubRecord} * class works correctly. Test data taken directly from a real * Excel file. - * - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestCommonObjectDataSubRecord extends TestCase { +public final class TestCommonObjectDataSubRecord { byte[] data = new byte[] { (byte)0x12,(byte)0x00,(byte)0x01,(byte)0x00, (byte)0x01,(byte)0x00,(byte)0x11,(byte)0x60, @@ -36,6 +39,7 @@ public final class TestCommonObjectDataSubRecord extends TestCase { (byte)0x00,(byte)0x00, }; + @Test public void testLoad() { CommonObjectDataSubRecord record = new CommonObjectDataSubRecord(TestcaseRecordInputStream.createLittleEndian(data), data.length); @@ -52,6 +56,7 @@ public final class TestCommonObjectDataSubRecord extends TestCase { assertEquals(18, record.getDataSize()); } + @Test public void testStore() { CommonObjectDataSubRecord record = new CommonObjectDataSubRecord(); @@ -66,9 +71,7 @@ public final class TestCommonObjectDataSubRecord extends TestCase { record.setReserved2(218103808); record.setReserved3(294); - byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + byte[] recordBytes = record.serialize(); + confirmRecordEncoding(CommonObjectDataSubRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestDConRefRecord.java b/src/testcases/org/apache/poi/hssf/record/TestDConRefRecord.java index 5962e78767..259cd9b2a3 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestDConRefRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestDConRefRecord.java @@ -19,27 +19,27 @@ package org.apache.poi.hssf.record; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; -import junit.framework.TestCase; -import org.apache.poi.util.LittleEndianOutputStream; -import static org.junit.Assert.assertArrayEquals; +import org.apache.poi.util.LittleEndianOutputStream; +import org.junit.Test; /** * Unit tests for DConRefRecord class. - * - * @author Niklas Rehfeld */ -public class TestDConRefRecord extends TestCase -{ +public class TestDConRefRecord { /** * record of a proper single-byte external 'volume'-style path with multiple parts and a sheet * name. */ - final byte[] volumeString = new byte[] - { + final byte[] volumeString = { 0, 0, 0, 0, 0, 0, //ref (6 bytes) not used... 17, 0,//cchFile (2 bytes) 0, //char type @@ -51,8 +51,7 @@ public class TestDConRefRecord extends TestCase * record of a proper single-byte external 'unc-volume'-style path with multiple parts and a * sheet name. */ - final byte[] uncVolumeString = new byte[] - { + final byte[] uncVolumeString = { 0, 0, 0, 0, 0, 0, //ref (6 bytes) not used... 34, 0,//cchFile (2 bytes) 0, //char type @@ -65,8 +64,7 @@ public class TestDConRefRecord extends TestCase /** * record of a proper single-byte external 'simple-file-path-dcon' style path with a sheet name. */ - final byte[] simpleFilePathDconString = new byte[] - { + final byte[] simpleFilePathDconString = { 0, 0, 0, 0, 0, 0, //ref (6 bytes) not used... 16, 0,//cchFile (2 bytes) 0, //char type @@ -77,8 +75,7 @@ public class TestDConRefRecord extends TestCase * record of a proper 'transfer-protocol'-style path. This one has a sheet name at the end, and * another one inside the file path. The spec doesn't seem to care about what they are. */ - final byte[] transferProtocolString = new byte[] - { + final byte[] transferProtocolString = { 0, 0, 0, 0, 0, 0, //ref (6 bytes) not used... 33, 0,//cchFile (2 bytes) 0, //char type @@ -91,8 +88,7 @@ public class TestDConRefRecord extends TestCase /** * startup-type path. */ - final byte[] relVolumeString = new byte[] - { + final byte[] relVolumeString = { 0, 0, 0, 0, 0, 0, //ref (6 bytes) not used... 16, 0,//cchFile (2 bytes) 0, //char type @@ -102,8 +98,7 @@ public class TestDConRefRecord extends TestCase /** * startup-type path. */ - final byte[] startupString = new byte[] - { + final byte[] startupString = { 0, 0, 0, 0, 0, 0, //ref (6 bytes) not used... 16, 0,//cchFile (2 bytes) 0, //char type @@ -113,8 +108,7 @@ public class TestDConRefRecord extends TestCase /** * alt-startup-type path. */ - final byte[] altStartupString = new byte[] - { + final byte[] altStartupString = { 0, 0, 0, 0, 0, 0, //ref (6 bytes) not used... 16, 0,//cchFile (2 bytes) 0, //char type @@ -124,8 +118,7 @@ public class TestDConRefRecord extends TestCase /** * library-style path. */ - final byte[] libraryString = new byte[] - { + final byte[] libraryString = { 0, 0, 0, 0, 0, 0, //ref (6 bytes) not used... 16, 0,//cchFile (2 bytes) 0, //char type @@ -135,8 +128,7 @@ public class TestDConRefRecord extends TestCase /** * record of single-byte string, external, volume path. */ - final byte[] data1 = new byte[] - { + final byte[] data1 = { 0, 0, 0, 0, 0, 0, //ref (6 bytes) not used... 10, 0,//cchFile (2 bytes) 0, //char type @@ -147,8 +139,7 @@ public class TestDConRefRecord extends TestCase /** * record of double-byte string, self-reference. */ - final byte[] data2 = new byte[] - { + final byte[] data2 = { 0, 0, 0, 0, 0, 0, //ref (6 bytes) not used... 9, 0,//cchFile (2 bytes) 1, //char type = unicode @@ -159,8 +150,7 @@ public class TestDConRefRecord extends TestCase /** * record of single-byte string, self-reference. */ - final byte[] data3 = new byte[] - { + final byte[] data3 = { 0, 0, 0, 0, 0, 0, //ref (6 bytes) not used... 9, 0,//cchFile (2 bytes) 0, //char type = ansi @@ -171,8 +161,7 @@ public class TestDConRefRecord extends TestCase /** * double-byte string, external reference, unc-volume. */ - final byte[] data4 = new byte[] - { + final byte[] data4 = { 0, 0, 0, 0, 0, 0, //ref (6 bytes) not used... 16, 0,//cchFile (2 bytes) //stFile starts here: @@ -187,8 +176,8 @@ public class TestDConRefRecord extends TestCase * test read-constructor-then-serialize for a single-byte external reference strings of * various flavours. This uses the RecordInputStream constructor. */ - public void testReadWriteSBExtRef() throws IOException - { + @Test + public void testReadWriteSBExtRef() throws IOException { testReadWrite(data1, "read-write single-byte external reference, volume type path"); testReadWrite(volumeString, "read-write properly formed single-byte external reference, volume type path"); @@ -212,13 +201,12 @@ public class TestDConRefRecord extends TestCase * test read-constructor-then-serialize for a double-byte external reference 'UNC-Volume' style * string */ - public void testReadWriteDBExtRefUncVol() throws IOException - { + @Test + public void testReadWriteDBExtRefUncVol() throws IOException { testReadWrite(data4, "read-write double-byte external reference, UNC volume type path"); } - private void testReadWrite(byte[] data, String message) throws IOException - { + private void testReadWrite(byte[] data, String message) throws IOException { RecordInputStream is = TestcaseRecordInputStream.create(81, data); DConRefRecord d = new DConRefRecord(is); ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length); @@ -232,24 +220,24 @@ public class TestDConRefRecord extends TestCase /** * test read-constructor-then-serialize for a double-byte self-reference style string */ - public void testReadWriteDBSelfRef() throws IOException - { + @Test + public void testReadWriteDBSelfRef() throws IOException { testReadWrite(data2, "read-write double-byte self reference"); } /** * test read-constructor-then-serialize for a single-byte self-reference style string */ - public void testReadWriteSBSelfRef() throws IOException - { + @Test + public void testReadWriteSBSelfRef() throws IOException { testReadWrite(data3, "read-write single byte self reference"); } /** * Test of getDataSize method, of class DConRefRecord. */ - public void testGetDataSize() - { + @Test + public void testGetDataSize() { DConRefRecord instance = new DConRefRecord(TestcaseRecordInputStream.create(81, data1)); int expResult = data1.length; int result = instance.getDataSize(); @@ -266,8 +254,8 @@ public class TestDConRefRecord extends TestCase /** * Test of getSid method, of class DConRefRecord. */ - public void testGetSid() - { + @Test + public void testGetSid() { DConRefRecord instance = new DConRefRecord(TestcaseRecordInputStream.create(81, data1)); short expResult = 81; short result = instance.getSid(); @@ -276,10 +264,10 @@ public class TestDConRefRecord extends TestCase /** * Test of getPath method, of class DConRefRecord. - * @todo different types of paths. */ - public void testGetPath() - { + @Test + public void testGetPath() { + // TODO: different types of paths. DConRefRecord instance = new DConRefRecord(TestcaseRecordInputStream.create(81, data1)); byte[] expResult = Arrays.copyOfRange(data1, 9, data1.length); byte[] result = instance.getPath(); @@ -289,8 +277,8 @@ public class TestDConRefRecord extends TestCase /** * Test of isExternalRef method, of class DConRefRecord. */ - public void testIsExternalRef() - { + @Test + public void testIsExternalRef() { DConRefRecord instance = new DConRefRecord(TestcaseRecordInputStream.create(81, data1)); assertTrue("external reference", instance.isExternalRef()); instance = new DConRefRecord(TestcaseRecordInputStream.create(81, data2)); diff --git a/src/testcases/org/apache/poi/hssf/record/TestDVALRecord.java b/src/testcases/org/apache/poi/hssf/record/TestDVALRecord.java index bcfb76645d..3e8ab9811e 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestDVALRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestDVALRecord.java @@ -17,19 +17,17 @@ package org.apache.poi.hssf.record; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + import java.io.ByteArrayInputStream; import org.apache.poi.util.LittleEndian; +import org.junit.Test; -import junit.framework.TestCase; - -/** - * - * @author Josh Micich - */ -public final class TestDVALRecord extends TestCase { +public final class TestDVALRecord { + @Test public void testRead() { - byte[] data = new byte[22]; LittleEndian.putShort(data, 0, DVALRecord.sid); LittleEndian.putShort(data, 2, (short)18); @@ -38,18 +36,16 @@ public final class TestDVALRecord extends TestCase { LittleEndian.putInt(data, 10, 57); LittleEndian.putInt(data, 14, 58); LittleEndian.putInt(data, 18, 59); - + RecordInputStream in = new RecordInputStream(new ByteArrayInputStream(data)); in.nextRecord(); DVALRecord dv = new DVALRecord(in); - + assertEquals(55, dv.getOptions()); assertEquals(56, dv.getHorizontalPos()); assertEquals(57, dv.getVerticalPos()); assertEquals(58, dv.getObjectID()); - if(dv.getDVRecNo() == 0) { - fail("Identified bug 44510"); - } + assertNotEquals("Identified bug 44510",0, dv.getDVRecNo()); assertEquals(59, dv.getDVRecNo()); } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestDrawingGroupRecord.java b/src/testcases/org/apache/poi/hssf/record/TestDrawingGroupRecord.java index 17d6475e8b..acee4f2727 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestDrawingGroupRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestDrawingGroupRecord.java @@ -17,15 +17,19 @@ package org.apache.poi.hssf.record; -import junit.framework.TestCase; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.cut; +import static org.junit.Assert.assertEquals; + import org.apache.poi.ddf.EscherContainerRecord; import org.apache.poi.ddf.EscherSpRecord; import org.apache.poi.util.HexDump; +import org.junit.Test; -public final class TestDrawingGroupRecord extends TestCase { +public final class TestDrawingGroupRecord { private static final int MAX_RECORD_SIZE = 8228; private static final int MAX_DATA_SIZE = MAX_RECORD_SIZE - 4; + @Test public void testGetRecordSize() { DrawingGroupRecord r = new DrawingGroupRecord(); assertEquals(4, r.getRecordSize()); @@ -62,6 +66,7 @@ public final class TestDrawingGroupRecord extends TestCase { assertEquals( MAX_RECORD_SIZE * 2 + 5, r.getRecordSize() ); } + @Test public void testSerialize() { // Check under max record size DrawingGroupRecord r = new DrawingGroupRecord(); @@ -112,21 +117,8 @@ public final class TestDrawingGroupRecord extends TestCase { assertEquals( 664856, r.getRecordSize() ); } - private static byte[] cut( byte[] data, int fromInclusive, int toExclusive ) - { - int length = toExclusive - fromInclusive; - byte[] result = new byte[length]; - System.arraycopy( data, fromInclusive, result, 0, length); - return result; - } - + @Test public void testGrossSizeFromDataSize() { - for (int i = 0; i < MAX_RECORD_SIZE * 4; i += 11) - { - //System.out.print( "data size = " + i + ", gross size = " + DrawingGroupRecord.grossSizeFromDataSize( i ) ); - //System.out.println( " Diff: " + (DrawingGroupRecord.grossSizeFromDataSize( i ) - i) ); - } - assertEquals( 4, DrawingGroupRecord.grossSizeFromDataSize( 0 ) ); assertEquals( 5, DrawingGroupRecord.grossSizeFromDataSize( 1 ) ); assertEquals( MAX_RECORD_SIZE, DrawingGroupRecord.grossSizeFromDataSize( MAX_DATA_SIZE ) ); diff --git a/src/testcases/org/apache/poi/hssf/record/TestDrawingRecord.java b/src/testcases/org/apache/poi/hssf/record/TestDrawingRecord.java index e6a3167913..10491b080c 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestDrawingRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestDrawingRecord.java @@ -18,6 +18,8 @@ package org.apache.poi.hssf.record; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -25,14 +27,15 @@ import java.io.IOException; import java.util.Arrays; import java.util.List; -import junit.framework.TestCase; +import org.junit.Test; -public final class TestDrawingRecord extends TestCase { +public final class TestDrawingRecord { /** * Check that RecordFactoryInputStream properly handles continued DrawingRecords * See Bugzilla #47548 */ + @Test public void testReadContinued() throws IOException { //simulate a continues drawing record diff --git a/src/testcases/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java b/src/testcases/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java index fc12c98e22..baa3a91db9 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java @@ -17,25 +17,22 @@ package org.apache.poi.hssf.record; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; import org.apache.poi.util.HexRead; -import org.apache.poi.util.RecordFormatException; - -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import org.junit.Test; /** * Tests the serialization and deserialization of the TestEmbeddedObjectRefSubRecord - * class works correctly. Test data taken directly from a real - * Excel file. - * - * @author Yegor Kozlov + * class works correctly. Test data taken directly from a real Excel file. */ -public final class TestEmbeddedObjectRefSubRecord extends TestCase { +public final class TestEmbeddedObjectRefSubRecord { private static final short EORSR_SID = EmbeddedObjectRefSubRecord.sid; + @Test public void testStore() { String data1 = "20 00 05 00 FC 10 76 01 02 24 14 DF 00 03 10 00 " @@ -53,29 +50,15 @@ public final class TestEmbeddedObjectRefSubRecord extends TestCase { RecordInputStream in2 = TestcaseRecordInputStream.create(ser); EmbeddedObjectRefSubRecord record2 = new EmbeddedObjectRefSubRecord(in2, ser.length-4); - - confirmData(src, ser); + confirmRecordEncoding(EmbeddedObjectRefSubRecord.sid, src, ser); assertEquals(record1.getOLEClassName(), record2.getOLEClassName()); byte[] ser2 = record1.serialize(); assertArrayEquals(ser, ser2); } - /** - * @param expectedData does not include sid & size - * @param actualFullRecordData includes sid & size - */ - private static void confirmData(byte[] expectedData, byte[] actualFullRecordData) { - assertEquals(expectedData.length, actualFullRecordData.length-4); - for (int i = 0; i < expectedData.length; i++) { - if(expectedData[i] != actualFullRecordData[i+4]) { - throw new AssertionFailedError("Difference at offset (" + i + ")"); - } - } - } - + @Test public void testCreate() { - EmbeddedObjectRefSubRecord record1 = new EmbeddedObjectRefSubRecord(); byte[] ser = record1.serialize(); @@ -89,8 +72,9 @@ public final class TestEmbeddedObjectRefSubRecord extends TestCase { assertArrayEquals(ser, ser2); } + @Test public void testCameraTool_bug45912() { - /** + /* * taken from ftPictFmla sub-record in attachment 22645 (offset 0x40AB). */ byte[] data45912 = hr( @@ -101,7 +85,7 @@ public final class TestEmbeddedObjectRefSubRecord extends TestCase { EmbeddedObjectRefSubRecord rec = new EmbeddedObjectRefSubRecord(in, data45912.length); byte[] ser2 = rec.serialize(); - confirmData(data45912, ser2); + confirmRecordEncoding(EmbeddedObjectRefSubRecord.sid, data45912, ser2); } private static byte[] hr(String string) { @@ -111,6 +95,7 @@ public final class TestEmbeddedObjectRefSubRecord extends TestCase { /** * tests various examples of OLE controls */ + @Test public void testVarious() { String[] rawData = { "12 00 0B 00 70 95 0B 05 3B 01 00 36 00 40 00 18 00 19 00 18", @@ -143,8 +128,9 @@ public final class TestEmbeddedObjectRefSubRecord extends TestCase { TestcaseRecordInputStream.confirmRecordEncoding("Test record " + i, EORSR_SID, data, ser2); } + @Test public void testVisioDrawing_bug46199() { - /** + /* * taken from ftPictFmla sub-record in attachment 22860 (stream offset 0x768F).
* Note that the since the string length is zero, there is no unicode flag byte */ @@ -157,15 +143,8 @@ public final class TestEmbeddedObjectRefSubRecord extends TestCase { + "0F CB E8 00"); RecordInputStream in = TestcaseRecordInputStream.create(EORSR_SID, data46199); - EmbeddedObjectRefSubRecord rec; - try { - rec = new EmbeddedObjectRefSubRecord(in, data46199.length); - } catch (RecordFormatException e) { - if (e.getMessage().equals("Not enough data (3) to read requested (4) bytes")) { - throw new AssertionFailedError("Identified bug 22860"); - } - throw e; - } + // bug 22860 - Not enough data (3) to read requested (4) bytes + EmbeddedObjectRefSubRecord rec = new EmbeddedObjectRefSubRecord(in, data46199.length); byte[] ser2 = rec.serialize(); TestcaseRecordInputStream.confirmRecordEncoding(EORSR_SID, data46199, ser2); } diff --git a/src/testcases/org/apache/poi/hssf/record/TestEndSubRecord.java b/src/testcases/org/apache/poi/hssf/record/TestEndSubRecord.java index ab4a80120f..fa5d9c7233 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestEndSubRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestEndSubRecord.java @@ -18,30 +18,27 @@ package org.apache.poi.hssf.record; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; /** * Tests the serialization and deserialization of the EndSubRecord - * class works correctly. Test data taken directly from a real - * Excel file. - * - * @author Glen Stampoultzis (glens at apache.org) + * class works correctly. Test data taken directly from a real Excel file. */ -public final class TestEndSubRecord extends TestCase { +public final class TestEndSubRecord { private static final byte[] data = { }; + @Test public void testLoad() { EndSubRecord record = new EndSubRecord(TestcaseRecordInputStream.create(0x00, data), 0); assertEquals(0, record.getDataSize()); } - public void testStore() - { + @Test + public void testStore() { EndSubRecord record = new EndSubRecord(); - byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + assertEquals(0, recordBytes.length - 4); } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestEscherAggregate.java b/src/testcases/org/apache/poi/hssf/record/TestEscherAggregate.java index 0e9a0ba297..32c0750336 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestEscherAggregate.java +++ b/src/testcases/org/apache/poi/hssf/record/TestEscherAggregate.java @@ -17,25 +17,26 @@ package org.apache.poi.hssf.record; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + import org.apache.poi.ddf.EscherClientDataRecord; import org.apache.poi.ddf.EscherContainerRecord; import org.apache.poi.ddf.EscherSpRecord; import org.apache.poi.util.HexDump; import org.apache.poi.util.HexRead; - -import java.util.ArrayList; -import java.util.List; +import org.junit.Test; /** * Tests the EscherAggregate class. - * - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestEscherAggregate extends TestCase { +public final class TestEscherAggregate { /** * Tests that the create aggregate method correctly rejoins escher records together. */ + @Test public void testCreateAggregate() { String msoDrawingRecord1 = "0F 00 02 F0 20 01 00 00 10 00 08 F0 08 00 00 00 \n" + @@ -81,10 +82,9 @@ public final class TestEscherAggregate extends TestCase { assertEquals( 1, aggregate.getEscherRecords().size() ); assertEquals( (short) 0xF002, aggregate.getEscherRecord( 0 ).getRecordId() ); assertEquals( 2, aggregate.getEscherRecord( 0 ).getChildRecords().size() ); - -// System.out.println( "aggregate = " + aggregate ); } + @Test public void testSerialize() { EscherContainerRecord container1 = new EscherContainerRecord(); diff --git a/src/testcases/org/apache/poi/hssf/record/TestExtSSTRecord.java b/src/testcases/org/apache/poi/hssf/record/TestExtSSTRecord.java index 228e728ae8..0d6bf167af 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestExtSSTRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestExtSSTRecord.java @@ -19,822 +19,134 @@ package org.apache.poi.hssf.record; -import junit.framework.TestCase; -import org.apache.poi.hssf.record.common.UnicodeString; -import org.apache.poi.util.HexRead; +import static org.junit.Assert.assertEquals; -/** - * @author Yegor Kozlov - */ -public final class TestExtSSTRecord extends TestCase { +import java.io.IOException; +import org.apache.poi.poifs.storage.RawDataUtil; +import org.junit.Test; - /** - * hex dump from ISBN_UPD_PL_20100104_1525.xls atatched to Bugzilla 50867 - */ - private static final String data_50967 = - // "Offset=0x0008BB19(572185) recno=159 sid=0x00FF size=0x201A(8218)\n" + - " FF 00 1A 20 08 00 1A" + - "09 00 00 0C 00 00 00 6D 09 00 00 5F 00 00 00 B8" + - "09 00 00 AA 00 00 00 BC 0A 00 00 AE 01 00 00 FA" + - "0B 00 00 EC 02 00 00 C6 0D 00 00 B8 04 00 00 2E" + - "0F 00 00 20 06 00 00 5C 11 00 00 4E 08 00 00 B0" + - "12 00 00 A2 09 00 00 A4 13 00 00 96 0A 00 00 92" + - "15 00 00 84 0C 00 00 0A 17 00 00 FC 0D 00 00 32" + - "18 00 00 24 0F 00 00 84 19 00 00 76 10 00 00 9A" + - "1A 00 00 8C 11 00 00 5E 1C 00 00 50 13 00 00 24" + - "1D 00 00 16 14 00 00 56 1E 00 00 48 15 00 00 1C" + - "1F 00 00 0E 16 00 00 DA 1F 00 00 CC 16 00 00 76" + - "21 00 00 68 18 00 00 2E 23 00 00 20 1A 00 00 A0" + - "24 00 00 92 1B 00 00 FA 25 00 00 EC 1C 00 00 BA" + - "27 00 00 AC 1E 00 00 12 29 00 00 04 00 00 00 4E" + - "2A 00 00 40 01 00 00 A0 2B 00 00 92 02 00 00 C8" + - "2C 00 00 BA 03 00 00 62 2E 00 00 54 05 00 00 58" + - "2F 00 00 4A 06 00 00 9A 30 00 00 8C 07 00 00 02" + - "32 00 00 F4 08 00 00 36 33 00 00 28 0A 00 00 30" + - "34 00 00 22 0B 00 00 FC 34 00 00 EE 0B 00 00 FE" + - "35 00 00 F0 0C 00 00 26 37 00 00 18 0E 00 00 C6" + - "38 00 00 B8 0F 00 00 FA 39 00 00 EC 10 00 00 8E" + - "3B 00 00 80 12 00 00 2C 3D 00 00 1E 14 00 00 3C" + - "3E 00 00 2E 15 00 00 80 3F 00 00 72 16 00 00 74" + - "40 00 00 66 17 00 00 8A 41 00 00 7C 18 00 00 64" + - "42 00 00 56 19 00 00 96 43 00 00 88 1A 00 00 82" + - "44 00 00 74 1B 00 00 76 45 00 00 68 1C 00 00 80" + - "46 00 00 72 1D 00 00 88 47 00 00 7A 1E 00 00 80" + - "48 00 00 72 1F 00 00 66 49 00 00 34 00 00 00 76" + - "4A 00 00 44 01 00 00 D0 4B 00 00 9E 02 00 00 F2" + - "4C 00 00 C0 03 00 00 DA 4D 00 00 A8 04 00 00 B4" + - "4F 00 00 82 06 00 00 12 51 00 00 E0 07 00 00 2A" + - "52 00 00 F8 08 00 00 3C 53 00 00 0A 0A 00 00 6E" + - "54 00 00 3C 0B 00 00 BC 55 00 00 8A 0C 00 00 14" + - "57 00 00 E2 0D 00 00 3C 58 00 00 0A 0F 00 00 36" + - "59 00 00 04 10 00 00 4A 5A 00 00 18 11 00 00 4A" + - "5B 00 00 18 12 00 00 AC 5C 00 00 7A 13 00 00 C2" + - "5D 00 00 90 14 00 00 2C 5F 00 00 FA 15 00 00 74" + - "60 00 00 42 17 00 00 56 62 00 00 24 19 00 00 12" + - "64 00 00 E0 1A 00 00 E8 65 00 00 B6 1C 00 00 CA" + - "66 00 00 98 1D 00 00 14 68 00 00 E2 1E 00 00 56" + - "69 00 00 04 00 00 00 EC 6A 00 00 9A 01 00 00 DC" + - "6B 00 00 8A 02 00 00 EE 6C 00 00 9C 03 00 00 66" + - "6E 00 00 14 05 00 00 A6 6F 00 00 54 06 00 00 92" + - "70 00 00 40 07 00 00 E6 71 00 00 94 08 00 00 48" + - "73 00 00 F6 09 00 00 AC 74 00 00 5A 0B 00 00 A2" + - "75 00 00 50 0C 00 00 C4 76 00 00 72 0D 00 00 4E" + - "78 00 00 FC 0E 00 00 14 7A 00 00 C2 10 00 00 0C" + - "7B 00 00 BA 11 00 00 4E 7C 00 00 FC 12 00 00 5A" + - "7D 00 00 08 14 00 00 C4 7E 00 00 72 15 00 00 BA" + - "80 00 00 68 17 00 00 1C 82 00 00 CA 18 00 00 5E" + - "83 00 00 0C 1A 00 00 BA 84 00 00 68 1B 00 00 E6" + - "85 00 00 94 1C 00 00 46 87 00 00 F4 1D 00 00 94" + - "88 00 00 42 1F 00 00 24 8A 00 00 10 01 00 00 80" + - "8B 00 00 6C 02 00 00 8E 8C 00 00 7A 03 00 00 82" + - "8D 00 00 6E 04 00 00 54 8E 00 00 40 05 00 00 60" + - "8F 00 00 4C 06 00 00 68 90 00 00 54 07 00 00 92" + - "91 00 00 7E 08 00 00 C8 92 00 00 B4 09 00 00 2C" + - "94 00 00 18 0B 00 00 8E 95 00 00 7A 0C 00 00 AA" + - "96 00 00 96 0D 00 00 FA 97 00 00 E6 0E 00 00 3E" + - "99 00 00 2A 10 00 00 54 9A 00 00 40 11 00 00 D4" + - "9B 00 00 C0 12 00 00 C2 9C 00 00 AE 13 00 00 1E" + - "9E 00 00 0A 15 00 00 F4 9E 00 00 E0 15 00 00 E0" + - "9F 00 00 CC 16 00 00 08 A1 00 00 F4 17 00 00 0E" + - "A2 00 00 FA 18 00 00 8A A3 00 00 76 1A 00 00 78" + - "A5 00 00 64 1C 00 00 4E A6 00 00 3A 1D 00 00 42" + - "A7 00 00 2E 1E 00 00 08 A9 00 00 F4 1F 00 00 BE" + - "AA 00 00 8D 01 00 00 34 AC 00 00 03 03 00 00 62" + - "AD 00 00 31 04 00 00 68 AE 00 00 37 05 00 00 52" + - "AF 00 00 21 06 00 00 DE B0 00 00 AD 07 00 00 A8" + - "B1 00 00 77 08 00 00 B6 B2 00 00 85 09 00 00 DA" + - "B3 00 00 A9 0A 00 00 EC B4 00 00 BB 0B 00 00 EA" + - "B5 00 00 B9 0C 00 00 0A B7 00 00 D9 0D 00 00 0A" + - "B8 00 00 D9 0E 00 00 26 B9 00 00 F5 0F 00 00 72" + - "BA 00 00 41 11 00 00 D8 BB 00 00 A7 12 00 00 3A" + - "BD 00 00 09 14 00 00 6C BE 00 00 3B 15 00 00 88" + - "BF 00 00 57 16 00 00 D8 C0 00 00 A7 17 00 00 60" + - "C2 00 00 2F 19 00 00 84 C3 00 00 53 1A 00 00 A8" + - "C4 00 00 77 1B 00 00 CE C5 00 00 9D 1C 00 00 02" + - "C7 00 00 D1 1D 00 00 58 C8 00 00 27 1F 00 00 56" + - "C9 00 00 04 00 00 00 D0 CA 00 00 7E 01 00 00 D4" + - "CB 00 00 82 02 00 00 38 CD 00 00 E6 03 00 00 E4" + - "CF 00 00 92 06 00 00 76 D1 00 00 24 08 00 00 10" + - "D3 00 00 BE 09 00 00 50 D4 00 00 FE 0A 00 00 94" + - "D5 00 00 42 0C 00 00 14 D7 00 00 C2 0D 00 00 92" + - "D8 00 00 40 0F 00 00 EC D9 00 00 9A 10 00 00 20" + - "DC 00 00 CE 12 00 00 7E DD 00 00 2C 14 00 00 5C" + - "DF 00 00 0A 16 00 00 B8 E0 00 00 66 17 00 00 9C" + - "E1 00 00 4A 18 00 00 44 E3 00 00 F2 19 00 00 A6" + - "E4 00 00 54 1B 00 00 F8 E5 00 00 A6 1C 00 00 D4" + - "E7 00 00 82 1E 00 00 2E E9 00 00 DC 1F 00 00 C8" + - "EA 00 00 75 01 00 00 3C EC 00 00 E9 02 00 00 6A" + - "ED 00 00 17 04 00 00 BC EE 00 00 69 05 00 00 18" + - "F0 00 00 C5 06 00 00 D0 F1 00 00 7D 08 00 00 66" + - "F3 00 00 13 0A 00 00 8C F4 00 00 39 0B 00 00 EC" + - "F5 00 00 99 0C 00 00 2A F7 00 00 D7 0D 00 00 84" + - "F8 00 00 31 0F 00 00 A0 F9 00 00 4D 10 00 00 06" + - "FB 00 00 B3 11 00 00 E6 FB 00 00 93 12 00 00 08" + - "FD 00 00 B5 13 00 00 66 FE 00 00 13 15 00 00 DA" + - "FF 00 00 87 16 00 00 52 01 01 00 FF 17 00 00 74" + - "02 01 00 21 19 00 00 96 03 01 00 43 1A 00 00 BC" + - "04 01 00 69 1B 00 00 72 06 01 00 1F 1D 00 00 D4" + - "07 01 00 81 1E 00 00 56 09 01 00 04 00 00 00 FC" + - "0A 01 00 AA 01 00 00 5E 0C 01 00 0C 03 00 00 B6" + - "0D 01 00 64 04 00 00 F4 0E 01 00 A2 05 00 00 74" + - "10 01 00 22 07 00 00 00 12 01 00 AE 08 00 00 4A" + - "13 01 00 F8 09 00 00 40 14 01 00 EE 0A 00 00 66" + - "15 01 00 14 0C 00 00 B8 16 01 00 66 0D 00 00 3E" + - "18 01 00 EC 0E 00 00 58 19 01 00 06 10 00 00 72" + - "1A 01 00 20 11 00 00 4A 1C 01 00 F8 12 00 00 8E" + - "1D 01 00 3C 14 00 00 E8 1E 01 00 96 15 00 00 A8" + - "20 01 00 56 17 00 00 88 23 01 00 36 1A 00 00 00" + - "25 01 00 AE 1B 00 00 AE 26 01 00 5C 1D 00 00 88" + - "28 01 00 36 1F 00 00 96 29 01 00 25 00 00 00 E6" + - "2A 01 00 75 01 00 00 A2 2C 01 00 31 03 00 00 40" + - "2E 01 00 CF 04 00 00 B8 2F 01 00 47 06 00 00 64" + - "31 01 00 F3 07 00 00 C0 32 01 00 4F 09 00 00 1C" + - "34 01 00 AB 0A 00 00 A4 35 01 00 33 0C 00 00 2A" + - "37 01 00 B9 0D 00 00 9A 38 01 00 29 0F 00 00 94" + - "3A 01 00 23 11 00 00 86 3B 01 00 15 12 00 00 44" + - "3D 01 00 D3 13 00 00 6E 3E 01 00 FD 14 00 00 8C" + - "40 01 00 1B 17 00 00 44 42 01 00 D3 18 00 00 0E" + - "44 01 00 9D 1A 00 00 06 45 01 00 95 1B 00 00 BA" + - "46 01 00 49 1D 00 00 24 49 01 00 B3 1F 00 00 A2" + - "4A 01 00 12 01 00 00 2C 4C 01 00 9C 02 00 00 D4" + - "4D 01 00 44 04 00 00 5E 50 01 00 CE 06 00 00 82" + - "51 01 00 F2 07 00 00 9C 52 01 00 0C 09 00 00 9E" + - "54 01 00 0E 0B 00 00 6C 56 01 00 DC 0C 00 00 42" + - "57 01 00 B2 0D 00 00 70 58 01 00 E0 0E 00 00 6E" + - "5A 01 00 DE 10 00 00 86 5C 01 00 F6 12 00 00 F2" + - "5D 01 00 62 14 00 00 A0 5F 01 00 10 16 00 00 6C" + - "61 01 00 DC 17 00 00 6C 64 01 00 DC 1A 00 00 F0" + - "66 01 00 60 1D 00 00 4E 69 01 00 BE 1F 00 00 68" + - "6A 01 00 EA 00 00 00 6E 6C 01 00 F0 02 00 00 B8" + - "6D 01 00 3A 04 00 00 52 6F 01 00 D4 05 00 00 C6" + - "70 01 00 48 07 00 00 80 72 01 00 02 09 00 00 DC" + - "73 01 00 5E 0A 00 00 F2 75 01 00 74 0C 00 00 6C" + - "77 01 00 EE 0D 00 00 46 79 01 00 C8 0F 00 00 CC" + - "7A 01 00 4E 11 00 00 80 7C 01 00 02 13 00 00 08" + - "7E 01 00 8A 14 00 00 80 7F 01 00 02 16 00 00 46" + - "81 01 00 C8 17 00 00 26 83 01 00 A8 19 00 00 A4" + - "84 01 00 26 1B 00 00 02 86 01 00 84 1C 00 00 F4" + - "87 01 00 76 1E 00 00 68 89 01 00 04 00 00 00 4E" + - "8B 01 00 EA 01 00 00 04 8D 01 00 A0 03 00 00 FE" + - "8E 01 00 9A 05 00 00 A2 90 01 00 3E 07 00 00 A6" + - "91 01 00 42 08 00 00 76 93 01 00 12 0A 00 00 72" + - "95 01 00 0E 0C 00 00 36 97 01 00 D2 0D 00 00 50" + - "99 01 00 EC 0F 00 00 E2 9B 01 00 7E 12 00 00 6A" + - "9D 01 00 06 14 00 00 28 9F 01 00 C4 15 00 00 F0" + - "A1 01 00 8C 18 00 00 B8 A3 01 00 54 1A 00 00 14" + - "A6 01 00 B0 1C 00 00 7C A7 01 00 18 1E 00 00 E2" + - "A8 01 00 7E 1F 00 00 8C AA 01 00 2A 01 00 00 8C" + - "AC 01 00 2A 03 00 00 A6 AE 01 00 44 05 00 00 76" + - "B0 01 00 14 07 00 00 A0 B2 01 00 3E 09 00 00 12" + - "B4 01 00 B0 0A 00 00 78 B5 01 00 16 0C 00 00 A4" + - "B6 01 00 42 0D 00 00 5C B7 01 00 FA 0D 00 00 08" + - "B8 01 00 A6 0E 00 00 D0 B9 01 00 6E 10 00 00 D2" + - "BB 01 00 70 12 00 00 6C BD 01 00 0A 14 00 00 78" + - "BF 01 00 16 16 00 00 AE C0 01 00 4C 17 00 00 BA" + - "C1 01 00 58 18 00 00 02 C3 01 00 A0 19 00 00 BA" + - "C3 01 00 58 1A 00 00 F6 C4 01 00 94 1B 00 00 70" + - "C7 01 00 0E 1E 00 00 E8 C8 01 00 86 1F 00 00 AC" + - "CA 01 00 88 01 00 00 88 CC 01 00 64 03 00 00 90" + - "CE 01 00 6C 05 00 00 5C D0 01 00 38 07 00 00 66" + - "D2 01 00 42 09 00 00 F6 D3 01 00 D2 0A 00 00 4E" + - "D5 01 00 2A 0C 00 00 A2 D7 01 00 7E 0E 00 00 BE" + - "D8 01 00 9A 0F 00 00 AE DA 01 00 8A 11 00 00 7E" + - "DC 01 00 5A 13 00 00 F4 DD 01 00 D0 14 00 00 98" + - "DF 01 00 74 16 00 00 AA E1 01 00 86 18 00 00 24" + - "E3 01 00 00 1A 00 00 84 E4 01 00 60 1B 00 00 58" + - "E6 01 00 34 1D 00 00 DA E8 01 00 B6 1F 00 00 A6" + - "EA 01 00 5F 01 00 00 44 EC 01 00 FD 02 00 00 B8" + - "ED 01 00 71 04 00 00 18 EF 01 00 D1 05 00 00 3A" + - "F1 01 00 F3 07 00 00 3E F3 01 00 F7 09 00 00 9C" + - "F4 01 00 55 0B 00 00 74 F7 01 00 2D 0E 00 00 36" + - "F9 01 00 EF 0F 00 00 AA FB 01 00 63 12 00 00 60" + - "FD 01 00 19 14 00 00 60 FF 01 00 19 16 00 00 B2" + - "01 02 00 6B 18 00 00 84 03 02 00 3D 1A 00 00 42" + - "06 02 00 FB 1C 00 00 DE 08 02 00 97 1F 00 00 42" + - "0B 02 00 11 02 00 00 A0 0D 02 00 6F 04 00 00 28" + - "10 02 00 F7 06 00 00 FE 11 02 00 CD 08 00 00 64" + - "13 02 00 33 0A 00 00 4C 14 02 00 1B 0B 00 00 D8" + - "15 02 00 A7 0C 00 00 C6 16 02 00 95 0D 00 00 F8" + - "17 02 00 C7 0E 00 00 C4 19 02 00 93 10 00 00 02" + - "1B 02 00 D1 11 00 00 A4 1C 02 00 73 13 00 00 7A" + - "1D 02 00 49 14 00 00 B2 1E 02 00 81 15 00 00 66" + - "20 02 00 35 17 00 00 B2 21 02 00 81 18 00 00 52" + - "23 02 00 21 1A 00 00 B4 24 02 00 83 1B 00 00 EC" + - "25 02 00 BB 1C 00 00 36 27 02 00 05 1E 00 00 5E" + - "28 02 00 2D 1F 00 00 A8 29 02 00 62 00 00 00 4A" + - "2B 02 00 04 02 00 00 CA 2C 02 00 84 03 00 00 20" + - "2E 02 00 DA 04 00 00 C6 2F 02 00 80 06 00 00 26" + - "31 02 00 E0 07 00 00 3A 32 02 00 F4 08 00 00 6E" + - "33 02 00 28 0A 00 00 F4 34 02 00 AE 0B 00 00 DA" + - "35 02 00 94 0C 00 00 E4 36 02 00 9E 0D 00 00 08" + - "38 02 00 C2 0E 00 00 52 39 02 00 0C 10 00 00 96" + - "3A 02 00 50 11 00 00 3C 3C 02 00 F6 12 00 00 D2" + - "3D 02 00 8C 14 00 00 30 3F 02 00 EA 15 00 00 7A" + - "40 02 00 34 17 00 00 74 41 02 00 2E 18 00 00 F4" + - "42 02 00 AE 19 00 00 64 44 02 00 1E 1B 00 00 B4" + - "45 02 00 6E 1C 00 00 FA 46 02 00 B4 1D 00 00 4A" + - "48 02 00 04 1F 00 00 4C 49 02 00 04 00 00 00 58" + - "4A 02 00 10 01 00 00 98 4B 02 00 50 02 00 00 E0" + - "4C 02 00 98 03 00 00 48 4E 02 00 00 05 00 00 2E" + - "4F 02 00 E6 05 00 00 BE 50 02 00 76 07 00 00 18" + - "52 02 00 D0 08 00 00 66 53 02 00 1E 0A 00 00 BA" + - "54 02 00 72 0B 00 00 F2 55 02 00 AA 0C 00 00 3C" + - "57 02 00 F4 0D 00 00 6A 58 02 00 22 0F 00 00 D4" + - "59 02 00 8C 10 00 00 20 5B 02 00 D8 11 00 00 4C" + - "5C 02 00 04 13 00 00 FC 5C 02 00 B4 13 00 00 7A" + - "5E 02 00 32 15 00 00 B4 5F 02 00 6C 16 00 00 FA" + - "60 02 00 B2 17 00 00 7E 62 02 00 36 19 00 00 3C" + - "63 02 00 F4 19 00 00 CE 64 02 00 86 1B 00 00 F6" + - "65 02 00 AE 1C 00 00 18 67 02 00 D0 1D 00 00 82" + - "68 02 00 3A 1F 00 00 A0 69 02 00 3B 00 00 00 CE" + - "6A 02 00 69 01 00 00 CC 6B 02 00 67 02 00 00 D6" + - "6C 02 00 71 03 00 00 0E 6E 02 00 A9 04 00 00 24" + - "6F 02 00 BF 05 00 00 4A 70 02 00 E5 06 00 00 7A" + - "71 02 00 15 08 00 00 5A 72 02 00 F5 08 00 00 A0" + - "73 02 00 3B 0A 00 00 B6 74 02 00 51 0B 00 00 DA" + - "75 02 00 75 0C 00 00 E4 76 02 00 7F 0D 00 00 20" + - "78 02 00 BB 0E 00 00 00 79 02 00 9B 0F 00 00 F8" + - "79 02 00 93 10 00 00 16 7B 02 00 B1 11 00 00 06" + - "7C 02 00 A1 12 00 00 FA 7C 02 00 95 13 00 00 2A" + - "7E 02 00 C5 14 00 00 5C 7F 02 00 F7 15 00 00 46" + - "80 02 00 E1 16 00 00 54 81 02 00 EF 17 00 00 70" + - "82 02 00 0B 19 00 00 68 83 02 00 03 1A 00 00 40" + - "84 02 00 DB 1A 00 00 16 85 02 00 B1 1B 00 00 28" + - "86 02 00 C3 1C 00 00 DE 86 02 00 79 1D 00 00 08" + - "88 02 00 A3 1E 00 00 CE 88 02 00 69 1F 00 00 F2" + - "89 02 00 7A 00 00 00 C6 8A 02 00 4E 01 00 00 D8" + - "8B 02 00 60 02 00 00 B4 8C 02 00 3C 03 00 00 A2" + - "8D 02 00 2A 04 00 00 EE 8E 02 00 76 05 00 00 06" + - "90 02 00 8E 06 00 00 12 91 02 00 9A 07 00 00 F8" + - "91 02 00 80 08 00 00 20 93 02 00 A8 09 00 00 0A" + - "95 02 00 92 0B 00 00 FE 95 02 00 86 0C 00 00 C6" + - "96 02 00 4E 0D 00 00 92 97 02 00 1A 0E 00 00 36" + - "98 02 00 BE 0E 00 00 02 99 02 00 8A 0F 00 00 28" + - "9A 02 00 B0 10 00 00 5A 9B 02 00 E2 11 00 00 74" + - "9C 02 00 FC 12 00 00 6C 9D 02 00 F4 13 00 00 42" + - "9E 02 00 CA 14 00 00 90 9F 02 00 18 16 00 00 34" + - "A1 02 00 BC 17 00 00 1E A2 02 00 A6 18 00 00 42" + - "A3 02 00 CA 19 00 00 62 A4 02 00 EA 1A 00 00 74" + - "A5 02 00 FC 1B 00 00 B0 A6 02 00 38 1D 00 00 5A" + - "A8 02 00 E2 1E 00 00 86 A9 02 00 04 00 00 00 30" + - "AB 02 00 AE 01 00 00 DA AC 02 00 58 03 00 00 C4" + - "AD 02 00 42 04 00 00 8C AE 02 00 0A 05 00 00 C4" + - "AF 02 00 42 06 00 00 86 B1 02 00 04 08 00 00 54" + - "B2 02 00 D2 08 00 00 8A B3 02 00 08 0A 00 00 54" + - "B4 02 00 D2 0A 00 00 52 B5 02 00 D0 0B 00 00 58" + - "B6 02 00 D6 0C 00 00 68 B7 02 00 E6 0D 00 00 3E" + - "B8 02 00 BC 0E 00 00 2C B9 02 00 AA 0F 00 00 78" + - "BA 02 00 F6 10 00 00 AA BB 02 00 28 12 00 00 D6" + - "BC 02 00 54 13 00 00 CC BD 02 00 4A 14 00 00 F8" + - "BE 02 00 76 15 00 00 42 C0 02 00 C0 16 00 00 5C" + - "C1 02 00 DA 17 00 00 42 C2 02 00 C0 18 00 00 36" + - "C3 02 00 B4 19 00 00 78 C4 02 00 F6 1A 00 00 90" + - "C5 02 00 0E 1C 00 00 BA C6 02 00 38 1D 00 00 1A" + - "C8 02 00 98 1E 00 00 62 C9 02 00 E0 1F 00 00 0E" + - "CA 02 00 77 00 00 00 24 CB 02 00 8D 01 00 00 38" + - "CC 02 00 A1 02 00 00 A6 CD 02 00 0F 04 00 00 84" + - "CE 02 00 ED 04 00 00 50 CF 02 00 B9 05 00 00 2C" + - "D0 02 00 95 06 00 00 3A D1 02 00 A3 07 00 00 22" + - "D3 02 00 8B 09 00 00 14 D4 02 00 7D 0A 00 00 3E" + - "D5 02 00 A7 0B 00 00 68 D6 02 00 D1 0C 00 00 62" + - "D7 02 00 CB 0D 00 00 4C D8 02 00 B5 0E 00 00 6A" + - "D9 02 00 D3 0F 00 00 92 DA 02 00 FB 10 00 00 CC" + - "DB 02 00 35 12 00 00 FC DC 02 00 65 13 00 00 A6" + - "DE 02 00 0F 15 00 00 B2 DF 02 00 1B 16 00 00 9E" + - "E0 02 00 07 17 00 00 A6 E1 02 00 0F 18 00 00 AA" + - "E2 02 00 13 19 00 00 86 E3 02 00 EF 19 00 00 C8" + - "E4 02 00 31 1B 00 00 F0 E5 02 00 59 1C 00 00 C6" + - "E6 02 00 2F 1D 00 00 BA E7 02 00 23 1E 00 00 EC" + - "E8 02 00 55 1F 00 00 02 EA 02 00 6C 00 00 00 64" + - "EB 02 00 CE 01 00 00 F4 EC 02 00 5E 03 00 00 FE" + - "ED 02 00 68 04 00 00 00 EF 02 00 6A 05 00 00 F6" + - "EF 02 00 60 06 00 00 FA F0 02 00 64 07 00 00 CE" + - "F1 02 00 38 08 00 00 2E F3 02 00 98 09 00 00 36" + - "F4 02 00 A0 0A 00 00 46 F5 02 00 B0 0B 00 00 50" + - "F6 02 00 BA 0C 00 00 60 F7 02 00 CA 0D 00 00 7C" + - "F8 02 00 E6 0E 00 00 CC F9 02 00 36 10 00 00 DE" + - "FA 02 00 48 11 00 00 AA FB 02 00 14 12 00 00 2E" + - "FD 02 00 98 13 00 00 54 FE 02 00 BE 14 00 00 6E" + - "FF 02 00 D8 15 00 00 88 00 03 00 F2 16 00 00 D6" + - "01 03 00 40 18 00 00 4A 03 03 00 B4 19 00 00 80" + - "04 03 00 EA 1A 00 00 90 05 03 00 FA 1B 00 00 96" + - "06 03 00 00 1D 00 00 A4 07 03 00 0E 1E 00 00 12" + - "09 03 00 7C 1F 00 00 20 0A 03 00 8B 00 00 00 8E" + - "0B 03 00 F9 01 00 00 B6 0C 03 00 21 03 00 00 D6" + - "0D 03 00 41 04 00 00 D6 0E 03 00 41 05 00 00 28" + - "10 03 00 93 06 00 00 36 11 03 00 A1 07 00 00 84" + - "12 03 00 EF 08 00 00 F2 13 03 00 5D 0A 00 00 44" + - "15 03 00 AF 0B 00 00 F6 16 03 00 61 0D 00 00 26" + - "18 03 00 91 0E 00 00 B8 19 03 00 23 10 00 00 0A" + - "1B 03 00 75 11 00 00 5E 1C 03 00 C9 12 00 00 A4" + - "1D 03 00 0F 14 00 00 CA 1E 03 00 35 15 00 00 3A" + - "20 03 00 A5 16 00 00 C2 21 03 00 2D 18 00 00 A8" + - "22 03 00 13 19 00 00 DA 23 03 00 45 1A 00 00 3A" + - "25 03 00 A5 1B 00 00 2C 26 03 00 97 1C 00 00 96" + - "27 03 00 01 1E 00 00 A2 28 03 00 0D 1F 00 00 B0" + - "29 03 00 04 00 00 00 78 2B 03 00 CC 01 00 00 44" + - "2C 03 00 98 02 00 00 74 2D 03 00 C8 03 00 00 00" + - "2F 03 00 54 05 00 00 18 30 03 00 6C 06 00 00 6C" + - "31 03 00 C0 07 00 00 E8 32 03 00 3C 09 00 00 E6" + - "33 03 00 3A 0A 00 00 5E 35 03 00 B2 0B 00 00 02" + - "37 03 00 56 0D 00 00 56 38 03 00 AA 0E 00 00 82" + - "39 03 00 D6 0F 00 00 C8 3A 03 00 1C 11 00 00 08" + - "3C 03 00 5C 12 00 00 72 3D 03 00 C6 13 00 00 C2" + - "3E 03 00 16 15 00 00 28 40 03 00 7C 16 00 00 AE" + - "41 03 00 02 18 00 00 38 43 03 00 8C 19 00 00 7A" + - "44 03 00 CE 1A 00 00 C4 45 03 00 18 1C 00 00 1E" + - "47 03 00 72 1D 00 00 A2 48 03 00 F6 1E 00 00 1E" + - "4A 03 00 51 00 00 00 7A 4B 03 00 AD 01 00 00 F8" + - "4C 03 00 2B 03 00 00 7C 4E 03 00 AF 04 00 00 6C" + - "50 03 00 9F 06 00 00 B8 51 03 00 EB 07 00 00 30" + - "53 03 00 63 09 00 00 2A 54 03 00 5D 0A 00 00 5C" + - "55 03 00 8F 0B 00 00 D4 56 03 00 07 0D 00 00 DE" + - "57 03 00 11 0E 00 00 E8 58 03 00 1B 0F 00 00 B0" + - "59 03 00 E3 0F 00 00 F4 5A 03 00 27 11 00 00 68" + - "5C 03 00 9B 12 00 00 F6 5D 03 00 29 14 00 00 F4" + - "5E 03 00 27 15 00 00 64 60 03 00 97 16 00 00 9E" + - "61 03 00 D1 17 00 00 CA 62 03 00 FD 18 00 00 3C" + - "64 03 00 6F 1A 00 00 96 65 03 00 C9 1B 00 00 FC" + - "66 03 00 2F 1D 00 00 40 68 03 00 73 1E 00 00 AE" + - "69 03 00 E1 1F 00 00 3E 6B 03 00 73 01 00 00 66" + - "6C 03 00 9B 02 00 00 52 6D 03 00 87 03 00 00 24" + - "6F 03 00 59 05 00 00 AA 70 03 00 DF 06 00 00 E6" + - "71 03 00 1B 08 00 00 82 73 03 00 B7 09 00 00 00" + - "75 03 00 35 0B 00 00 9E 76 03 00 D3 0C 00 00 20" + - "78 03 00 55 0E 00 00 0E 79 03 00 43 0F 00 00 10" + - "7A 03 00 45 10 00 00 02 7B 03 00 37 11 00 00 3C" + - "7C 03 00 71 12 00 00 8E 7D 03 00 C3 13 00 00 F4" + - "7E 03 00 29 15 00 00 96 80 03 00 CB 16 00 00 44" + - "82 03 00 79 18 00 00 76 84 03 00 AB 1A 00 00 92" + - "86 03 00 C7 1C 00 00 2D 88 03 00 62 1E 00 00 19" + - "8A 03 00 88 00 00 00 11 8B 03 00 80 01 00 00 BB" + - "8C 03 00 2A 03 00 00 CB 8D 03 00 3A 04 00 00 CB" + - "8E 03 00 3A 05 00 00 CF 8F 03 00 3E 06 00 00 C5" + - "90 03 00 34 07 00 00 A7 91 03 00 16 08 00 00 C9" + - "92 03 00 38 09 00 00 C5 93 03 00 34 0A 00 00 CD" + - "94 03 00 3C 0B 00 00 C5 96 03 00 34 0D 00 00 BB" + - "98 03 00 2A 0F 00 00 A9 99 03 00 18 10 00 00 C3" + - "9A 03 00 32 11 00 00 53 9C 03 00 C2 12 00 00 51" + - "9D 03 00 C0 13 00 00 AF 9E 03 00 1E 15 00 00 ED" + - "9F 03 00 5C 16 00 00 53 A1 03 00 C2 17 00 00 17" + - "A3 03 00 86 19 00 00 55 A4 03 00 C4 1A 00 00 6B" + - "A5 03 00 DA 1B 00 00 5F A6 03 00 CE 1C 00 00 5F" + - "A7 03 00 CE 1D 00 00 9F A8 03 00 0E 1F 00 00 51" + - "AA 03 00 9E 00 00 00 1F AC 03 00 6C 02 00 00 17" + - "AE 03 00 64 04 00 00 B7 B0 03 00 04 07 00 00 05" + - "B3 03 00 52 09 00 00 97 B4 03 00 E4 0A 00 00 03" + - "B6 03 00 50 0C 00 00 7F B7 03 00 CC 0D 00 00 0B" + - "B9 03 00 58 0F 00 00 41 BB 03 00 8E 11 00 00 23" + - "BD 03 00 70 13 00 00 1D BF 03 00 6A 15 00 00 47" + - "C0 03 00 94 16 00 00 FB C1 03 00 48 18 00 00 45" + - "C3 03 00 92 19 00 00 7F C4 03 00 CC 1A 00 00 19" + - "C6 03 00 66 1C 00 00 55 C7 03 00 A2 1D 00 00 9D" + - "C8 03 00 EA 1E 00 00 FB C9 03 00 58 00 00 00 89" + - "CB 03 00 E6 01 00 00 2B CD 03 00 88 03 00 00 8D" + - "CE 03 00 EA 04 00 00 F9 CF 03 00 56 06 00 00 6D" + - "D1 03 00 CA 07 00 00 EF D3 03 00 4C 0A 00 00 1D" + - "D5 03 00 7A 0B 00 00 C9 D6 03 00 26 0D 00 00 C3" + - "D8 03 00 20 0F 00 00 1D DA 03 00 7A 10 00 00 07" + - "DC 03 00 64 12 00 00 61 DD 03 00 BE 13 00 00 E3" + - "DE 03 00 40 15 00 00 29 E0 03 00 86 16 00 00 5B" + - "E2 03 00 B8 18 00 00 B7 E4 03 00 14 1B 00 00 A7" + - "E6 03 00 04 1D 00 00 E5 E8 03 00 42 1F 00 00 AF" + - "EA 03 00 3D 01 00 00 AD EC 03 00 3B 03 00 00 C1" + - "EE 03 00 4F 05 00 00 C7 F0 03 00 55 07 00 00 0B" + - "F3 03 00 99 09 00 00 E9 F4 03 00 77 0B 00 00 ED" + - "F6 03 00 7B 0D 00 00 53 F9 03 00 E1 0F 00 00 5B" + - "FB 03 00 E9 11 00 00 5F FD 03 00 ED 13 00 00 EF" + - "FF 03 00 7D 16 00 00 AF 01 04 00 3D 18 00 00 B9" + - "02 04 00 47 19 00 00 AD 04 04 00 3B 1B 00 00 51" + - "06 04 00 DF 1C 00 00 6F 07 04 00 FD 1D 00 00 69" + - "08 04 00 F7 1E 00 00 E1 09 04 00 52 00 00 00 81" + - "0B 04 00 F2 01 00 00 51 0C 04 00 C2 02 00 00 39" + - "0D 04 00 AA 03 00 00 5D 0E 04 00 CE 04 00 00 BB" + - "0F 04 00 2C 06 00 00 91 10 04 00 02 07 00 00 1D" + - "12 04 00 8E 08 00 00 2D 13 04 00 9E 09 00 00 7B" + - "14 04 00 EC 0A 00 00 1D 16 04 00 8E 0C 00 00 8B" + - "17 04 00 FC 0D 00 00 B5 18 04 00 26 0F 00 00 6D" + - "1A 04 00 DE 10 00 00 8B 1B 04 00 FC 11 00 00 AB" + - "1C 04 00 1C 13 00 00 E7 1D 04 00 58 14 00 00 37" + - "1F 04 00 A8 15 00 00 69 20 04 00 DA 16 00 00 83" + - "21 04 00 F4 17 00 00 8D 22 04 00 FE 18 00 00 E7" + - "23 04 00 58 1A 00 00 B7 25 04 00 28 1C 00 00 29" + - "28 04 00 9A 1E 00 00 97 29 04 00 04 00 00 00 DB" + - "2A 04 00 48 01 00 00 EF 2B 04 00 5C 02 00 00 5B" + - "2D 04 00 C8 03 00 00 71 2E 04 00 DE 04 00 00 BF" + - "2F 04 00 2C 06 00 00 9D 31 04 00 0A 08 00 00 DD" + - "32 04 00 4A 09 00 00 FB 33 04 00 68 0A 00 00 11" + - "36 04 00 7E 0C 00 00 4D 37 04 00 BA 0D 00 00 01" + - "39 04 00 6E 0F 00 00 67 3A 04 00 D4 10 00 00 0D" + - "3C 04 00 7A 12 00 00 A1 3D 04 00 0E 14 00 00 F3" + - "3E 04 00 60 15 00 00 87 40 04 00 F4 16 00 00 83" + - "42 04 00 F0 18 00 00 F7 43 04 00 64 1A 00 00 F7" + - "45 04 00 64 1C 00 00 FB 47 04 00 68 1E 00 00 3D" + - "49 04 00 AA 1F 00 00 39 4B 04 00 92 01 00 00 8B" + - "4C 04 00 E4 02 00 00 97 4E 04 00 F0 04 00 00 5D" + - "50 04 00 B6 06 00 00 19 52 04 00 72 08 00 00 43" + - "53 04 00 9C 09 00 00 FD 54 04 00 56 0B 00 00 FD" + - "55 04 00 56 0C 00 00 4B 57 04 00 A4 0D 00 00 83" + - "58 04 00 DC 0E 00 00 E9 59 04 00 42 10 00 00 47" + - "5B 04 00 A0 11 00 00 B9 5C 04 00 12 13 00 00 5D" + - "5E 04 00 B6 14 00 00 DB 5F 04 00 34 16 00 00 F1" + - "61 04 00 4A 18 00 00 35 64 04 00 8E 1A 00 00 87" + - "66 04 00 E0 1C 00 00 B9 68 04 00 12 1F 00 00 AD" + - "6A 04 00 FA 00 00 00 EB 6C 04 00 38 03 00 00 0B" + - "6F 04 00 58 05 00 00 49 71 04 00 96 07 00 00 11" + - "73 04 00 5E 09 00 00 A5 75 04 00 F2 0B 00 00 89" + - "77 04 00 D6 0D 00 00 C9 79 04 00 16 10 00 00 C5" + - "7A 04 00 12 11 00 00 15 7C 04 00 62 12 00 00 7F" + - "7D 04 00 CC 13 00 00 83 7F 04 00 D0 15 00 00 AB" + - "81 04 00 F8 17 00 00 2D 83 04 00 7A 19 00 00 7B" + - "84 04 00 C8 1A 00 00 CD 85 04 00 1A 1C 00 00 DF" + - "87 04 00 2C 1E 00 00 65 89 04 00 B2 1F 00 00 BF" + - "8B 04 00 0B 02 00 00 25 8E 04 00 71 04 00 00 F5" + - "8F 04 00 41 06 00 00 79 91 04 00 C5 07 00 00 19" + - "93 04 00 65 09 00 00 5D 94 04 00 A9 0A 00 00 4B" + - "96 04 00 97 0C 00 00 B7 97 04 00 03 0E 00 00 37" + - "99 04 00 83 0F 00 00 EB 9A 04 00 37 11 00 00 E3" + - "9B 04 00 2F 12 00 00 BD 9D 04 00 09 14 00 00 C1" + - "9F 04 00 0D 16 00 00 AB A1 04 00 F7 17 00 00 EB" + - "A2 04 00 37 19 00 00 DF A3 04 00 2B 1A 00 00 CB" + - "A4 04 00 17 1B 00 00 93 A5 04 00 DF 1B 00 00 6F" + - "A6 04 00 BB 1C 00 00 59 A7 04 00 A5 1D 00 00 5B" + - "A8 04 00 A7 1E 00 00 47 A9 04 00 93 1F 00 00 4B" + - "AA 04 00 AE 00 00 00 49 AB 04 00 AC 01 00 00 53" + - "AC 04 00 B6 02 00 00 7B AD 04 00 DE 03 00 00 67" + - "AE 04 00 CA 04 00 00 73 AF 04 00 D6 05 00 00 B3" + - "B0 04 00 16 07 00 00 A7 B1 04 00 0A 08 00 00 7B" + - "B2 04 00 DE 08 00 00 C7 B3 04 00 2A 0A 00 00 B3" + - "B4 04 00 16 0B 00 00 EB B5 04 00 4E 0C 00 00 09" + - "B7 04 00 6C 0D 00 00 11 B8 04 00 74 0E 00 00 37" + - "B9 04 00 9A 0F 00 00 41 BA 04 00 A4 10 00 00 A7" + - "BB 04 00 0A 12 00 00 87 BC 04 00 EA 12 00 00 9D" + - "BD 04 00 00 14 00 00 DF BE 04 00 42 15 00 00 C5" + - "BF 04 00 28 16 00 00 A9 C0 04 00 0C 17 00 00 A1" + - "C1 04 00 04 18 00 00 9B C2 04 00 FE 18 00 00 DD" + - "C3 04 00 40 1A 00 00 AF C4 04 00 12 1B 00 00 D1" + - "C5 04 00 34 1C 00 00 F5 C6 04 00 58 1D 00 00 E5" + - "C7 04 00 48 1E 00 00 2F C9 04 00 92 1F 00 00 11" + - "CA 04 00 63 00 00 00 E5 CA 04 00 37 01 00 00 C3" + - "CB 04 00 15 02 00 00 A9 CC 04 00 FB 02 00 00 B1" + - "CD 04 00 03 04 00 00 A1 CE 04 00 F3 04 00 00 8B" + - "CF 04 00 DD 05 00 00 5D D0 04 00 AF 06 00 00 33" + - "D1 04 00 85 07 00 00 39 D2 04 00 8B 08 00 00 27" + - "D3 04 00 79 09 00 00 21 D4 04 00 73 0A 00 00 EF" + - "D4 04 00 41 0B 00 00 C3 D5 04 00 15 0C 00 00 7D" + - "D6 04 00 CF 0C 00 00 3F D7 04 00 91 0D 00 00 5F" + - "D8 04 00 B1 0E 00 00 3D D9 04 00 8F 0F 00 00 0D" + - "DA 04 00 5F 10 00 00 F7 DA 04 00 49 11 00 00 31" + - "DC 04 00 83 12 00 00 B7 DD 04 00 09 14 00 00 ED" + - "DE 04 00 3F 15 00 00 EF DF 04 00 41 16 00 00 D5" + - "E0 04 00 27 17 00 00 AF E1 04 00 01 18 00 00 C7" + - "E2 04 00 19 19 00 00 B7 E3 04 00 09 1A 00 00 A9" + - "E4 04 00 FB 1A 00 00 B7 E5 04 00 09 1C 00 00 C1" + - "E6 04 00 13 1D 00 00 A9 E7 04 00 FB 1D 00 00 AB" + - "E8 04 00 FD 1E 00 00 93 E9 04 00 E5 1F 00 00 75" + - "EA 04 00 CF 00 00 00 3F EB 04 00 99 01 00 00 63" + - "EC 04 00 BD 02 00 00 67 ED 04 00 C1 03 00 00 83" + - "EE 04 00 DD 04 00 00 8F EF 04 00 E9 05 00 00 79" + - "F0 04 00 D3 06 00 00 4F F1 04 00 A9 07 00 00 3F" + - "F2 04 00 99 08 00 00 41 F3 04 00 9B 09 00 00 11" + - "F4 04 00 6B 0A 00 00 27 F5 04 00 81 0B 00 00 21" + - "F6 04 00 7B 0C 00 00 23 F7 04 00 7D 0D 00 00 5F" + - "F8 04 00 B9 0E 00 00 2D F9 04 00 87 0F 00 00 2F" + - "FA 04 00 89 10 00 00 2B FB 04 00 85 11 00 00 4D" + - "FC 04 00 A7 12 00 00 2B FD 04 00 85 13 00 00 2F" + - "FE 04 00 89 14 00 00 4D FF 04 00 A7 15 00 00 59" + - "00 05 00 B3 16 00 00 7D 01 05 00 D7 17 00 00 AD" + - "02 05 00 07 19 00 00 B7 03 05 00 11 1A 00 00 47" + - "05 05 00 A1 1B 00 00 7D 06 05 00 D7 1C 00 00 0F" + - "08 05 00 69 1E 00 00 5D 09 05 00 B7 1F 00 00 9B" + - "0A 05 00 DE 00 00 00 A1 0B 05 00 E4 01 00 00 91" + - "0C 05 00 D4 02 00 00 09 0E 05 00 4C 04 00 00 A7" + - "0F 05 00 EA 05 00 00 FD 10 05 00 40 07 00 00 93" + - "12 05 00 D6 08 00 00 35 14 05 00 78 0A 00 00 63" + - "15 05 00 A6 0B 00 00 97 17 05 00 DA 0D 00 00 B1" + - "19 05 00 F4 0F 00 00 2B 1C 05 00 6E 12 00 00 69" + - "1D 05 00 AC 13 00 00 8D 1E 05 00 D0 14 00 00 D1" + - "1F 05 00 14 16 00 00 FF 20 05 00 42 17 00 00 93" + - "22 05 00 D6 18 00 00 F1 23 05 00 34 1A 00 00 55" + - "25 05 00 98 1B 00 00 83 26 05 00 C6 1C 00 00 BF" + - "27 05 00 02 1E 00 00 13 29 05 00 56 1F 00 00 7D" + - "2A 05 00 B5 00 00 00 F3 2B 05 00 2B 02 00 00 79" + - "2D 05 00 B1 03 00 00 D7 2E 05 00 0F 05 00 00 11" + - "30 05 00 49 06 00 00 19 32 05 00 51 08 00 00 2B" + - "33 05 00 63 09 00 00 33 34 05 00 6B 0A 00 00 AF" + - "35 05 00 E7 0B 00 00 8F 36 05 00 C7 0C 00 00 01" + - "38 05 00 39 0E 00 00 49 39 05 00 81 0F 00 00 AD" + - "3A 05 00 E5 10 00 00 29 3C 05 00 61 12 00 00 0F" + - "3E 05 00 47 14 00 00 99 3F 05 00 D1 15 00 00 79" + - "41 05 00 B1 17 00 00 E7 43 05 00 1F 1A 00 00 D1" + - "46 05 00 09 1D 00 00 29 49 05 00 61 1F 00 00 CF" + - "4B 05 00 EE 01 00 00 F9 4D 05 00 18 04 00 00 E5" + - "50 05 00 04 07 00 00 51 53 05 00 70 09 00 00 C1" + - "55 05 00 E0 0B 00 00 5F 58 05 00 7E 0E 00 00 9D" + - "59 05 00 BC 0F 00 00 8F 5A 05 00 AE 10 00 00 9D" + - "5C 05 00 BC 12 00 00 CB 5D 05 00 EA 13 00 00 8F" + - "5F 05 00 AE 15 00 00 B1 60 05 00 D0 16 00 00 FB" + - "61 05 00 1A 18 00 00 29 63 05 00 48 19 00 00 BD" + - "64 05 00 DC 1A 00 00 67 66 05 00 86 1C 00 00 21" + - "68 05 00 40 1E 00 00 83 69 05 00 A2 1F 00 00 F9" + - "6A 05 00 0B 01 00 00 EB 6C 05 00 FD 02 00 00 B5" + - "6E 05 00 C7 04 00 00 19 70 05 00 2B 06 00 00 11" + - "72 05 00 23 08 00 00 53 73 05 00 65 09 00 00 99" + - "74 05 00 AB 0A 00 00 23 76 05 00 35 0C 00 00 13" + - "78 05 00 25 0E 00 00 91 79 05 00 A3 0F 00 00 E3" + - "7A 05 00 F5 10 00 00 B7 7B 05 00 C9 11 00 00 B7" + - "7C 05 00 C9 12 00 00 B7 7D 05 00 C9 13 00 00 81" + - "7F 05 00 93 15 00 00 E7 80 05 00 F9 16 00 00 67" + - "82 05 00 79 18 00 00 6B 83 05 00 7D 19 00 00 8B" + - "84 05 00 9D 1A 00 00 71 86 05 00 83 1C 00 00 F5" + - "87 05 00 07 1E 00 00 " + - - //Offset=0x0008DB37(580407) recno=160 sid=0x003C size=0x1048(4168) - " 3C 00 48 10 47 8A 05 00 4E" + - "00 00 00 45 8B 05 00 4C 01 00 00 59 8C 05 00 60" + - "02 00 00 91 8D 05 00 98 03 00 00 77 8F 05 00 7E" + - "05 00 00 B9 90 05 00 C0 06 00 00 D3 91 05 00 DA" + - "07 00 00 75 93 05 00 7C 09 00 00 2F 95 05 00 36" + - "0B 00 00 F1 96 05 00 F8 0C 00 00 DB 98 05 00 E2" + - "0E 00 00 3D 9A 05 00 44 10 00 00 41 9C 05 00 48" + - "12 00 00 A1 9D 05 00 A8 13 00 00 F7 9E 05 00 FE" + - "14 00 00 71 A0 05 00 78 16 00 00 11 A2 05 00 18" + - "18 00 00 0F A3 05 00 16 19 00 00 69 A4 05 00 70" + - "1A 00 00 89 A6 05 00 90 1C 00 00 65 A8 05 00 6C" + - "1E 00 00 E3 AA 05 00 CF 00 00 00 AF AC 05 00 9B" + - "02 00 00 91 AE 05 00 7D 04 00 00 B7 B0 05 00 A3" + - "06 00 00 85 B2 05 00 71 08 00 00 D9 B3 05 00 C5" + - "09 00 00 4F B5 05 00 3B 0B 00 00 BD B6 05 00 A9" + - "0C 00 00 AF B8 05 00 9B 0E 00 00 63 BA 05 00 4F" + - "10 00 00 35 BC 05 00 21 12 00 00 5B BD 05 00 47" + - "13 00 00 53 BE 05 00 3F 14 00 00 9F BF 05 00 8B" + - "15 00 00 17 C2 05 00 03 18 00 00 CB C3 05 00 B7" + - "19 00 00 FB C4 05 00 E7 1A 00 00 89 C6 05 00 75" + - "1C 00 00 67 C7 05 00 53 1D 00 00 D7 C8 05 00 C3" + - "1E 00 00 0B CA 05 00 F7 1F 00 00 0D CB 05 00 EB" + - "00 00 00 F7 CB 05 00 D5 01 00 00 03 CD 05 00 E1" + - "02 00 00 13 CE 05 00 F1 03 00 00 33 CF 05 00 11" + - "05 00 00 51 D0 05 00 2F 06 00 00 49 D1 05 00 27" + - "07 00 00 43 D2 05 00 21 08 00 00 63 D4 05 00 41" + - "0A 00 00 93 D5 05 00 71 0B 00 00 C9 D6 05 00 A7" + - "0C 00 00 FF D7 05 00 DD 0D 00 00 73 D9 05 00 51" + - "0F 00 00 27 DB 05 00 05 11 00 00 8B DC 05 00 69" + - "12 00 00 C3 DD 05 00 A1 13 00 00 3F DF 05 00 1D" + - "15 00 00 E5 E0 05 00 C3 16 00 00 FF E1 05 00 DD" + - "17 00 00 29 E3 05 00 07 19 00 00 3F E4 05 00 1D" + - "1A 00 00 15 E5 05 00 F3 1A 00 00 F9 E5 05 00 D7" + - "1B 00 00 C5 E6 05 00 A3 1C 00 00 C9 E7 05 00 A7" + - "1D 00 00 27 E9 05 00 05 1F 00 00 A1 EA 05 00 73" + - "00 00 00 6B EC 05 00 3D 02 00 00 A3 ED 05 00 75" + - "03 00 00 B5 EE 05 00 87 04 00 00 E9 EF 05 00 BB" + - "05 00 00 77 F1 05 00 49 07 00 00 B9 F2 05 00 8B" + - "08 00 00 C5 F4 05 00 97 0A 00 00 0D F6 05 00 DF" + - "0B 00 00 C3 F7 05 00 95 0D 00 00 E5 F9 05 00 B7" + - "0F 00 00 B5 FB 05 00 87 11 00 00 6B FE 05 00 3D" + - "14 00 00 DD 00 06 00 AF 16 00 00 0B 03 06 00 DD" + - "18 00 00 9F 05 06 00 71 1B 00 00 7B 08 06 00 4D" + - "1E 00 00 A7 0A 06 00 62 00 00 00 59 0D 06 00 14" + - "03 00 00 3D 0F 06 00 F8 04 00 00 9B 10 06 00 56" + - "06 00 00 17 12 06 00 D2 07 00 00 6F 13 06 00 2A" + - "09 00 00 59 14 06 00 14 0A 00 00 1F 16 06 00 DA" + - "0B 00 00 49 17 06 00 04 0D 00 00 D1 18 06 00 8C" + - "0E 00 00 C1 1A 06 00 7C 10 00 00 2B 1C 06 00 E6" + - "11 00 00 9F 1D 06 00 5A 13 00 00 77 1F 06 00 32" + - "15 00 00 CD 20 06 00 88 16 00 00 B7 21 06 00 72" + - "17 00 00 9D 22 06 00 58 18 00 00 61 23 06 00 1C" + - "19 00 00 33 24 06 00 EE 19 00 00 67 25 06 00 22" + - "1B 00 00 4F 26 06 00 0A 1C 00 00 3F 27 06 00 FA" + - "1C 00 00 17 28 06 00 D2 1D 00 00 25 29 06 00 E0" + - "1E 00 00 19 2A 06 00 D4 1F 00 00 DF 2A 06 00 96" + - "00 00 00 CF 2B 06 00 86 01 00 00 9D 2C 06 00 54" + - "02 00 00 CD 2D 06 00 84 03 00 00 9F 2E 06 00 56" + - "04 00 00 7F 2F 06 00 36 05 00 00 49 30 06 00 00" + - "06 00 00 21 31 06 00 D8 06 00 00 17 32 06 00 CE" + - "07 00 00 05 33 06 00 BC 08 00 00 FF 33 06 00 B6" + - "09 00 00 DD 34 06 00 94 0A 00 00 B1 35 06 00 68" + - "0B 00 00 99 36 06 00 50 0C 00 00 73 37 06 00 2A" + - "0D 00 00 95 38 06 00 4C 0E 00 00 8D 39 06 00 44" + - "0F 00 00 A9 3A 06 00 60 10 00 00 F3 3B 06 00 AA" + - "11 00 00 19 3D 06 00 D0 12 00 00 2D 3E 06 00 E4" + - "13 00 00 49 3F 06 00 00 15 00 00 FF 40 06 00 B6" + - "16 00 00 9D 42 06 00 54 18 00 00 4D 44 06 00 04" + - "1A 00 00 9B 46 06 00 52 1C 00 00 BF 48 06 00 76" + - "1E 00 00 19 4B 06 00 D9 00 00 00 DB 4D 06 00 9B" + - "03 00 00 53 4F 06 00 13 05 00 00 EB 50 06 00 AB" + - "06 00 00 25 52 06 00 E5 07 00 00 9B 53 06 00 5B" + - "09 00 00 03 55 06 00 C3 0A 00 00 85 56 06 00 45" + - "0C 00 00 E9 58 06 00 A9 0E 00 00 EF 59 06 00 AF" + - "0F 00 00 61 5B 06 00 21 11 00 00 2B 5D 06 00 EB" + - "12 00 00 57 5F 06 00 17 15 00 00 D1 60 06 00 91" + - "16 00 00 15 63 06 00 D5 18 00 00 97 65 06 00 57" + - "1B 00 00 D3 67 06 00 93 1D 00 00 31 69 06 00 F1" + - "1E 00 00 47 6A 06 00 07 20 00 00 FB 6B 06 00 97" + - "01 00 00 43 6D 06 00 DF 02 00 00 7B 6E 06 00 17" + - "04 00 00 39 70 06 00 D5 05 00 00 BD 71 06 00 59" + - "07 00 00 6B 73 06 00 07 09 00 00 95 74 06 00 31" + - "0A 00 00 59 76 06 00 F5 0B 00 00 C7 77 06 00 63" + - "0D 00 00 BF 79 06 00 5B 0F 00 00 AD 7B 06 00 49" + - "11 00 00 9B 7D 06 00 37 13 00 00 FB 7E 06 00 97" + - "14 00 00 2D 81 06 00 C9 16 00 00 5B 82 06 00 F7" + - "17 00 00 D5 83 06 00 71 19 00 00 B1 85 06 00 4D" + - "1B 00 00 73 87 06 00 0F 1D 00 00 29 89 06 00 C5" + - "1E 00 00 AF 8A 06 00 34 00 00 00 C9 8B 06 00 4E" + - "01 00 00 39 8D 06 00 BE 02 00 00 B1 8E 06 00 36" + - "04 00 00 01 90 06 00 86 05 00 00 6D 91 06 00 F2" + - "06 00 00 C7 92 06 00 4C 08 00 00 21 94 06 00 A6" + - "09 00 00 51 95 06 00 D6 0A 00 00 61 96 06 00 E6" + - "0B 00 00 F1 97 06 00 76 0D 00 00 F5 98 06 00 7A" + - "0E 00 00 37 9A 06 00 BC 0F 00 00 79 9B 06 00 FE" + - "10 00 00 09 9D 06 00 8E 12 00 00 DD 9D 06 00 62" + - "13 00 00 1F 9F 06 00 A4 14 00 00 29 A0 06 00 AE" + - "15 00 00 3B A1 06 00 C0 16 00 00 AF A2 06 00 34" + - "18 00 00 E3 A3 06 00 68 19 00 00 3D A5 06 00 C2" + - "1A 00 00 91 A6 06 00 16 1C 00 00 3F A8 06 00 C4" + - "1D 00 00 1B AA 06 00 A0 1F 00 00 1B AB 06 00 8A" + - "00 00 00 63 AC 06 00 D2 01 00 00 75 AD 06 00 E4" + - "02 00 00 91 AE 06 00 00 04 00 00 E7 AF 06 00 56" + - "05 00 00 41 B1 06 00 B0 06 00 00 85 B2 06 00 F4" + - "07 00 00 83 B3 06 00 F2 08 00 00 CD B4 06 00 3C" + - "0A 00 00 B7 B5 06 00 26 0B 00 00 ED B6 06 00 5C" + - "0C 00 00 D9 B7 06 00 48 0D 00 00 B3 B9 06 00 22" + - "0F 00 00 63 BB 06 00 D2 10 00 00 E3 BC 06 00 52" + - "12 00 00 53 BE 06 00 C2 13 00 00 83 BF 06 00 F2" + - "14 00 00 AF C0 06 00 1E 16 00 00 8F C2 06 00 FE" + - "17 00 00 0F C4 06 00 7E 19 00 00 DF C5 06 00 4E" + - "1B 00 00 77 C7 06 00 E6 1C 00 00 D9 C8 06 00 48" + - "1E 00 00 C5 CA 06 00 35 00 00 00 D9 CB 06 00 49" + - "01 00 00 29 CD 06 00 99 02 00 00 F3 CE 06 00 63" + - "04 00 00 0B D1 06 00 7B 06 00 00 45 D2 06 00 B5" + - "07 00 00 59 D4 06 00 C9 09 00 00 87 D6 06 00 F7" + - "0B 00 00 DD D7 06 00 4D 0D 00 00 2D DA 06 00 9D" + - "0F 00 00 2D DC 06 00 9D 11 00 00 B7 DD 06 00 27" + - "13 00 00 09 DF 06 00 79 14 00 00 FB E0 06 00 6B" + - "16 00 00 E9 E2 06 00 59 18 00 00 47 E4 06 00 B7" + - "19 00 00 21 E6 06 00 91 1B 00 00 03 E8 06 00 73" + - "1D 00 00 D1 E9 06 00 41 1F 00 00 45 EC 06 00 95" + - "01 00 00 63 EE 06 00 B3 03 00 00 C9 F1 06 00 19" + - "07 00 00 BD F4 06 00 0D 0A 00 00 57 F7 06 00 A7" + - "0C 00 00 9B FA 06 00 EB 0F 00 00 37 FD 06 00 87" + - "12 00 00 55 FF 06 00 A5 14 00 00 57 01 07 00 A7" + - "16 00 00 D3 03 07 00 23 19 00 00 BF 05 07 00 0F" + - "1B 00 00 1D 07 07 00 6D 1C 00 00 15 08 07 00 65" + - "1D 00 00 1F 09 07 00 6F 1E 00 00 39 0B 07 00 8E" + - "00 00 00 D5 0C 07 00 2A 02 00 00 21 0E 07 00 76" + - "03 00 00 59 10 07 00 AE 05 00 00 43 12 07 00 98" + - "07 00 00 A1 13 07 00 F6 08 00 00 9B 16 07 00 F0" + - "0B 00 00 99 18 07 00 EE 0D 00 00 43 1A 07 00 98" + - "0F 00 00 D3 1C 07 00 28 12 00 00 4B 1E 07 00 A0" + - "13 00 00 E9 1F 07 00 3E 15 00 00 13 21 07 00 68" + - "16 00 00 65 22 07 00 BA 17 00 00 BF 23 07 00 14" + - "19 00 00 77 25 07 00 CC 1A 00 00 11 27 07 00 66" + - "1C 00 00 1B 28 07 00 70 1D 00 00 89 2A 07 00 DE" + - "1F 00 00 07 2C 07 00 61 01 00 00 4D 2E 07 00 A7" + - "03 00 00 41 31 07 00 9B 06 00 00 F1 33 07 00 4B" + - "09 00 00 8B 36 07 00 E5 0B 00 00 15 39 07 00 6F" + - "0E 00 00 17 3B 07 00 71 10 00 00 2B 3E 07 00 85" + - "13 00 00 61 40 07 00 BB 15 00 00 1D 42 07 00 77" + - "17 00 00 29 43 07 00 83 18 00 00 0D 45 07 00 67" + - "1A 00 00 2D 46 07 00 87 1B 00 00 DF 47 07 00 39" + - "1D 00 00 C7 4A 07 00 04 00 00 00 AB 4D 07 00 E8" + - "02 00 00 55 50 07 00 92 05 00 00 C9 52 07 00 06" + - "08 00 00 91 55 07 00 CE 0A 00 00 9F 57 07 00 DC" + - "0C 00 00 8B 59 07 00 C8 0E 00 00 83 5A 07 00 C0" + - "0F 00 00 03 5C 07 00 40 11 00 00 3F 5D 07 00 7C" + - "12 00 00 7B 5E 07 00 B8 13 00 00 EF 5F 07 00 2C" + - "15 00 00 85 61 07 00 C2 16 00 00 2F 63 07 00 6C" + - "18 00 00 BB 65 07 00 F8 1A 00 00 D9 66 07 00 16" + - "1C 00 00 21 68 07 00 5E 1D 00 00 4D 69 07 00 8A" + - "1E 00 00 E3 6A 07 00 04 00 00 00 CF 6B 07 00 F0" + - "00 00 00 6B 6D 07 00 8C 02 00 00 F1 6E 07 00 12" + - "04 00 00 6D 70 07 00 8E 05 00 00 6F 71 07 00 90" + - "06 00 00 9F 72 07 00 C0 07 00 00 55 74 07 00 76" + - "09 00 00 49 76 07 00 6A 0B 00 00 D3 78 07 00 F4" + - "0D 00 00 5F 7A 07 00 80 0F 00 00 A9 7B 07 00 CA" + - "10 00 00 8F 7D 07 00 B0 12 00 00 B5 7F 07 00 D6" + - "14 00 00 F9 81 07 00 1A 17 00 00 57 83 07 00 78" + - "18 00 00 A5 84 07 00 C6 19 00 00 C3 85 07 00 E4" + - "1A 00 00 FB 86 07 00 1C 1C 00 00 01 89 07 00 22" + - "1E 00 00 2B 8A 07 00 4C 1F 00 00 77 8B 07 00 85" + - "00 00 00 AD 8C 07 00 BB 01 00 00 4F 8E 07 00 5D" + - "03 00 00 99 90 07 00 A7 05 00 00 F9 92 07 00 07" + - "08 00 00 AB 94 07 00 B9 09 00 00 33 96 07 00 41" + - "0B 00 00 CF 97 07 00 DD 0C 00 00 19 9A 07 00 27" + - "0F 00 00 31 9B 07 00 3F 10 00 00 BF 9C 07 00 CD" + - "11 00 00 A1 9E 07 00 AF 13 00 00 BF A0 07 00 CD" + - "15 00 00 A3 A2 07 00 B1 17 00 00 95 A4 07 00 A3" + - "19 00 00 95 A6 07 00 A3 1B 00 00 B7 A8 07 00 C5" + - "1D 00 00 9F AA 07 00 AD 1F 00 00 F5 AC 07 00 F2" + - "01 00 00 8F AE 07 00 8C 03 00 00 DB B0 07 00 D8" + - "05 00 00 8D B2 07 00 8A 07 00 00 11 B4 07 00 0E" + - "09 00 00 95 B5 07 00 92 0A 00 00 D3 B7 07 00 D0" + - "0C 00 00 5D B9 07 00 5A 0E 00 00 63 BB 07 00 60" + - "10 00 00 21 BE 07 00 1E 13 00 00 EB BF 07 00 E8" + - "14 00 00 A3 C2 07 00 A0 17 00 00 25 C4 07 00 22" + - "19 00 00 F7 C4 07 00 F4 19 00 00 29 C6 07 00 26" + - "1B 00 00 BD C7 07 00 BA 1C 00 00 61 C9 07 00 5E" + - "1E 00 00 3B CB 07 00 6D 00 00 00 C7 CC 07 00 F9" + - "01 00 00 4D CE 07 00 7F 03 00 00 93 D0 07 00 C5" + - "05 00 00 53 D2 07 00 85 07 00 00 BF D3 07 00 F1" + - "08 00 00 EF D4 07 00 21 0A 00 00 F7 D6 07 00 29" + - "0C 00 00 8F D8 07 00 C1 0D 00 00 DB D9 07 00 0D" + - "0F 00 00 21 DB 07 00 53 10 00 00 59 DC 07 00 8B" + - "11 00 00 25 DE 07 00 57 13 00 00 AB DF 07 00 DD" + - "14 00 00 5B E1 07 00 8D 16 00 00 91 E3 07 00 C3" + - "18 00 00 03 E5 07 00 35 1A 00 00 29 E6 07 00 5B" + - "1B 00 00 41 E7 07 00 73 1C 00 00 87 E8 07 00 B9" + - "1D 00 00 F1 E9 07 00 23 1F 00 00 33 EB 07 00 5E" + - "00 00 00 37 ED 07 00 62 02 00 00 13 EF 07 00 3E" + - "04 00 00 15 F0 07 00 40 05 00 00 13 F1 07 00 3E" + - "06 00 00 39 F2 07 00 64 07 00 00 41 F3 07 00 6C" + - "08 00 00 25 F4 07 00 50 09 00 00 75 F5 07 00 A0" + - "0A 00 00 83 F7 07 00 AE 0C 00 00 AF F9 07 00 DA" + - "0E 00 00 E1 FB 07 00 0C 11 00 00 3B FE 07 00 66" + - "13 00 00 8B FF 07 00 B6 14 00 00 21 01 08 00 4C" + - "16 00 00 89 03 08 00 B4 18 00 00 7D 04 08 00 A8" + - "19 00 00 0F 06 08 00 3A 1B 00 00 9F 07 08 00 CA" + - "1C 00 00 F3 08 08 00 1E 1E 00 00 19 0A 08 00 44" + - "1F 00 00 3D 0C 08 00 59 01 00 00 61 0D 08 00 7D" + - "02 00 00 11 0F 08 00 2D 04 00 00 45 10 08 00 61" + - "05 00 00 9F 11 08 00 BB 06 00 00 65 13 08 00 81" + - "08 00 00 83 15 08 00 9F 0A 00 00 39 17 08 00 55" + - "0C 00 00 0D 1A 08 00 29 0F 00 00 71 1C 08 00 8D" + - "11 00 00 95 1D 08 00 B1 12 00 00 D9 1E 08 00 F5" + - "13 00 00 35 20 08 00 51 15 00 00 99 21 08 00 B5" + - "16 00 00 09 24 08 00 25 19 00 00 3F 25 08 00 5B" + - "1A 00 00 57 26 08 00 73 1B 00 00 49 27 08 00 65" + - "1C 00 00 69 28 08 00 85 1D 00 00 C3 29 08 00 DF" + - "1E 00 00 9D 2B 08 00 D9 00 00 00 09 2D 08 00 45" + - "02 00 00 29 2E 08 00 65 03 00 00 2F 31 08 00 6B" + - "06 00 00 9D 32 08 00 D9 07 00 00 B1 33 08 00 ED" + - "08 00 00 0D 36 08 00 49 0B 00 00 BB 37 08 00 F7" + - "0C 00 00 19 3A 08 00 55 0F 00 00 79 3C 08 00 B5" + - "11 00 00 E1 3D 08 00 1D 13 00 00 6F 3F 08 00 AB" + - "14 00 00 5F 40 08 00 9B 15 00 00 8D 41 08 00 C9" + - "16 00 00 FF 42 08 00 3B 18 00 00 07 44 08 00 43" + - "19 00 00 27 46 08 00 63 1B 00 00 53 47 08 00 8F" + - "1C 00 00 47 48 08 00 83 1D 00 00 53 49 08 00 8F" + - "1E 00 00 61 4A 08 00 9D 1F 00 00 D7 4B 08 00 1E" + - "01 00 00 57 4D 08 00 9E 02 00 00 CB 4E 08 00 12" + - "04 00 00 7D 50 08 00 C4 05 00 00 A9 51 08 00 F0" + - "06 00 00 41 53 08 00 88 08 00 00 ED 54 08 00 34" + - "0A 00 00 17 57 08 00 5E 0C 00 00 91 58 08 00 D8" + - "0D 00 00 B7 59 08 00 FE 0E 00 00 0F 5B 08 00 56" + - "10 00 00 33 5C 08 00 7A 11 00 00 A7 5D 08 00 EE" + - "12 00 00 25 5F 08 00 6C 14 00 00 D5 61 08 00 1C" + - "17 00 00 EB 63 08 00 32 19 00 00 A5 65 08 00 EC" + - "1A 00 00 E1 67 08 00 28 1D 00 00 9F 69 08 00 E6" + - "1E 00 00 DD 6A 08 00 04 00 00 00 6F 6C 08 00 96" + - "01 00 00 B7 6D 08 00 DE 02 00 00 6D 6F 08 00 94" + - "04 00 00 ED 70 08 00 14 06 00 00 5B 72 08 00 82" + - "07 00 00 09 74 08 00 30 09 00 00 43 75 08 00 6A" + - "0A 00 00 77 76 08 00 9E 0B 00 00 7D 77 08 00 A4" + - "0C 00 00 E3 78 08 00 0A 0E 00 00 87 7B 08 00 AE" + - "10 00 00 DF 7C 08 00 06 12 00 00 DF 7D 08 00 06" + - "13 00 00 3F 7F 08 00 66 14 00 00 71 80 08 00 98" + - "15 00 00 8F 81 08 00 B6 16 00 00 EF 82 08 00 16" + - "18 00 00 AB 84 08 00 D2 19 00 00 8D 86 08 00 B4" + - "1B 00 00 B9 87 08 00 E0 1C 00 00 47 89 08 00 6E" + - "1E 00 00 F7 8A 08 00 04 00 00 00 FB 8B 08 00 08" + - "01 00 00 9B 8D 08 00 A8 02 00 00 DF 8E 08 00 EC" + - "03 00 00 DB 8F 08 00 E8 04 00 00 BB 90 08 00 C8" + - "05 00 00 F3 91 08 00 00 07 00 00 43 93 08 00 50" + - "08 00 00 71 94 08 00 7E 09 00 00 5B 96 08 00 68" + - "0B 00 00 A9 97 08 00 B6 0C 00 00 0F 99 08 00 1C" + - "0E 00 00 C5 9A 08 00 D2 0F 00 00 11 9C 08 00 1E" + - "11 00 00 D1 9C 08 00 DE 11 00 00 DD 9D 08 00 EA" + - "12 00 00 73 9F 08 00 80 14 00 00 05 A1 08 00 12" + - "16 00 00 1D A2 08 00 2A 17 00 00 EB A3 08 00 F8" + - "18 00 00 33 A5 08 00 40 1A 00 00 F5 A6 08 00 02" + - "1C 00 00 6B A8 08 00 78 1D 00 00 77 A9 08 00 84" + - "1E 00 00 A5 AB 08 00 CE 00 00 00 99 AD 08 00 C2" + - "02 00 00 ED AF 08 00 16 05 00 00 CB B1 08 00 F4" + - "06 00 00 B9 B3 08 00 E2 08 00 00 4F B5 08 00 78" + - "0A 00 00 67 B6 08 00 90 0B 00 00 DD B7 08 00 06" + - "0D 00 00 67 B9 08 00 90 0E 00 00 C7 BA 08 00 F0" + - "0F 00 00 "; - - - /** - * deep comparison of two SST records - */ - public static void assertEquals(SSTRecord expected, SSTRecord actual){ - assertEquals("number of strings", expected.getNumStrings(), actual.getNumStrings()); - assertEquals("number of unique strings", expected.getNumUniqueStrings(), actual.getNumUniqueStrings()); - assertEquals("count of strings", expected.countStrings(), actual.countStrings()); - for ( int k = 0; k < expected.countStrings(); k++ ) { - UnicodeString us1 = expected.getString(k); - UnicodeString us2 = actual.getString(k); - - assertEquals("String at idx=" + k, us1, us2); - } - } +public final class TestExtSSTRecord { /** * ExtSSTRecord can be continued. Ensure we properly read the continue remainder. */ - public void test50967() { - byte[] bytes = HexRead.readFromString(data_50967); + @Test + public void test50967() throws IOException { + // hex dump from ISBN_UPD_PL_20100104_1525.xls attached to Bugzilla 50867 + byte[] bytes = RawDataUtil.decompress("H4sIAAAAAAAAACWaBbAVxxZF9/jgrkFDcAvu7hrc3d3dLbhrgBDcXR8OwV2CEz" + + "RIIFhw+4G/Zqiiqrn3zkyvvc/p7tM976sSp/CVOJIUVVJH2sa022lX0e6OLK0zpE9RpKemdCQav9lSlhhSCldqEEuq7EsbYkuLuGdJHG" + + "km90yNJ43ggZETSP/jnuwJpR+4Z0QiqVdMaU5iaTz3NkoiVeGeH5JK8eNKtZJJZbk3SXIpenzpOu0p2l4ppTY8I0sq+uXeBT/Qx3dwpY" + + "aLZ+xMK63h3tjpJfBUOYNUFO4FGbkO7mOZuMaSmmWRajhSnaxSefjn/AiHJ5nZpTfoyJ1DSgf/jzml79H8P9rntF9ySf+iJ00eKWF0fM" + + "iLD+j5lI/+0TOxgDQEDzIVkpKho2BhWNExpIjUDf4eRaVWeDG2mDQAHS2KoxUvZpaQRqNnWEmuQU+vUuhEz5DS3Icno8tI/dA1pCyf8a" + + "JVOQkk9SovlUTfuQrSb+h7VVHaj77rlaQVGLDlJ56JvthVpTvoy1BN+oC+gtWJCfo61eD/6NpdEyZ0xa0t/UWcCtbhd3TlrouP6CpfD7" + + "3EqXx9WvStaQAP8TrQUJqMzkwkyyd09mgiFUdfrWbEEl2xW9Avuh61lLah50Qr6Rf0xG1DP+ip1fZbnJ62IwbouNEeDnQ87yD9io5Wnb" + + "iWOC3rTLzQMbUL8UTHw67SdHSU7S69I9/W9JDqoWNRT/IIHYd64RM6KvchdsQpbj9Y0RG1P/EPcnUA36Oj3kDJh//QIK6Hf+cQfIc/yT" + + "BYiU+j4dwD/84RfE9cHv5Mv+goPYo8Qcf00eglHj+MlWLCP2Sc1AH+iePxB/5hE/AYgTUmwo2OJpOkiuhoM5nv0DF1ijQIHcemEit0ZJ" + + "qOv+iYOIP70bFqJrmBjk+z6BsdhWcTQ3TUmMPz0HFxLvFGx4FfGZ/EI9lvxA0db2jv0N6Z/23c+Av5Dl3RF/EsdI1dTO6gq89SchA9lZ" + + "dJ+dFTfDn5Slz8lVyPrr0M/gnoyrlGsoJxs1bKhp4266Q86Km2XkqJnlsbpLXoWbFR6o2ebZukn9FzfbO0kjx7ukXaha5/tko7gvkgQr" + + "qGrsjbadGVZof0lnzrtlMqhq6ru6Tl6Mq/R4pEfDrslQqgZ/Q+qTZ6ru7nd/Q0OSBlJc9GHJSqo2fFIfonTmcOS/PQZR6VzqOrzjEpLX" + + "pqHf+Wb+dO4Du6Lp4kRsQr72n8Rd/9s8QEPb3OE1N0xLyAB+iocpGxj47pl/AoGCdX8Bz+qVeJA9xPr5G/xCXFDfqGe9BNYgl3g9tohH" + + "f7nW/j/te7jCH8L3mPsQr3svvEEt4PD/g/vBf/hgf/szxmLMB77B+pJ5wFn0qP4Wz3TEqAgN3Ppbb4n/Bf6TC8515KA+Ft9VqKA+f4N1" + + "K+YK5+K82GN8N76Qq8Iz4QP3gXfJQqwet+ljbj90PaaXD7/0lbyaNWX3gOfl//Ko2Cv5ph6Cv8PUxDKYP5yjJUAr9324bawt/NNZQcny" + + "96hoYG4zqSEfr8v8iGVsHfKKqhqPi7LZqhFvzwJrqhRfD3YNB8T94otqF18JePY+gDfheNa+g5OlrFMxQX/u3xDbWCv3BCQ0/JlzqJDL" + + "nwd0tsKEUwLyXhPvgnJjVUEN8fJTM0E/4VKQzVgnt0KkO54VVq+oF3XRpDDYJ5NR3f4/PM9IZYQvQwgxH6vSiToWzwFs1i6Cy827MaKo" + + "PPLbIZeg3v/uyGfoIzSU5Dq+FckstQjsDnPIZ2wDknr6H0+Dw9v6FU8I0sYCgefCULGbqAv50KG/oPzvEsTt/BV7I435MX0ZnM58Hplj" + + "I0A86dpQ2Vg/OHcoY2w7movBFYpUwVDf1KPlysZKgkfI2qGDoD37Cqhl7B92s1/IbvtxqGopMHHWoZugFf8dqGNsHXpY6hO/jYqZ6hW/" + + "g4soGhd/C9amioGVwLGhuKSdw7NOU++Dq0oIXr31aGmsBTua2hvfC0aWeIFFWnDob+hWd7R0P54anW2dBF4nuki6Gy8AzpZsiE50Z3Q4" + + "3w6xUm94CnQ2/iDE/pvoaO4depfoYq49eQAVyPTz6DdCw8QwbzGZ7SQ7kOnjTDDa0gD5eMMJQGn8yRhkYwft6MMtSL/Gsz5lv+VR4HH3" + + "7ZTGILiOeXiYbmwLVosqHCcC2bYqg4eddrGr7C1W0GfsGVe5ahP+CqMpt8g+uvuYYG4U+7eeQdPOnmGzpEfv270NB44rZ9saEa+BN3ma" + + "ENcAxYbighHH+t4D58Gs8gILU0fg0tHMsopkrC0WsD+Q3Hgk3w4E/sLdwPR5+thuLDsWQbfHA0iDD0idbfbmgZcTu3w1An4vbHLkNd4O" + + "qwx1BkuPrs4z58WrffUEV82vm7oTrwmQfRj187aevA+e6Qoen41uUoeuF8dMzQSDjXnDA0Gs7RpxincE4+Y6gDnA3OGcoLZ6s/4IHz3Q" + + "X8gbPyJfTAuegKOuHaexV/8WvddeJGHAfdMFSPOL65aegcfL/cJu7wrbpLf0EteI/O4Blxn7yCp85DQznJr+uPDG2DZxnBIxVV8injJc" + + "ivZ4a6EtiELwydhyv/y2/jsfBrQ+/h+vWNoZrke4/3hjLDk/ujoRfwrPpsqDk+NfnPUCI4mnylhWOTYao9HCMsU4XgKO6a+kz8bvmmZt" + + "F/8SimYtHvgmimOtNvupim3jPOvvDlafKmRRxTOfChYlxT39Hv1XimluPHkfimZhCvDwlMHYXjUCJT04iX+Z2p8/iyJImp7vjSL6mpcv" + + "BsSmZqKPnUKoWpXMRtU0o+w1UtlamUcG35wdRw/Hma2tQu+HKnNeUQt0bpTGWGc0V6U5RcKp/RlA3viUwmmliPspi6DveRrKaGwJ0mmx" + + "nWgfmzm2Gd2ymHGda5b3KaWgf/9VympsN/P7ep34J8y2vqAPzV8pmKCv/M/KaqwF+woBnOF38UMjUe/h+LmPoH/n5FTeUM1oliprLA/6" + + "Y4zyXvWpQ0lQz+LaVMdYL/U2lTW4hz+bLwwl+xnBmO1zrlzbCO+qUC/aDjTkVTv6CjbGU+EO8sP5l6SLuXH3uhI2E1U+eCda86z0fHzh" + + "qmuqHjVU1Tq9BRsDY60dGujqnvyYOLdeEN1un6pq6io2ID+iUO/6PdEsSjkans6NjS2FQH8uNTE1Ob0DOomanc6CjYnOfRnmlhaiR63r" + + "VEH3oStoYDPcPamMqPngVtTbEV0Jl2ppgqdaq9KS7RZYrDruiJ3snUSgT/0NnUPvSU72LqAfHp19VUPPTU62bqLe2C7jwHXdt6mKoaxK" + + "enqZ5BfHqZGoyuFH3IB+Kjvqbmou9D3295Fr+/qY3ocweYWkicPtHOQF+GQaYOB3XJYPIYnaWHmLqLzhpDTb1AZxeKoSjoazPclEXeFR" + + "1h6k/a+D/zPPSmG2nqYDA+aPui1x9tajF5eIa2LbpfjTFFqa0jFPGV0X11nCks1Jbxpgqie9EEUxnQ/Xwi8UO3O9nUxGB/MsXUHOL5gX" + + "YIulNMM7WC8Rx5hqmpwb6LdmQwrmby3KDummUqcTC+fzG1l9acbWos+tPNMbUB/fXmmvoL/T1YJIM6v8M84ob+4mySTqB/8nxTCdGdc6" + + "Gp3ehOtsjUMvK1+GJ+R3+zJeQzunss5X50b1hmKi96660ww33LyJXf8vXH1Wa4L76+xlQd9B1aa6o4P4xfZyoy+g6t5zP6Rm7kenTV2G" + + "TqD9qxm035xLXGFjOcR6ttJX/QWWebqcvobBNBngf1znb40JdpB/mMvj47GXfoW7WLcYuuy7tN1UDXqT2myqPrw158Ja7F95vaj74Gvz" + + "P+0Vf8AJ/Rl/sgeY6+Pod4DvomHzYVPdg3H/mmL/Exxhv6mh1nngj23idM9UbnDyfNcB+Q9xT5RDyXnTYVA50jzph6RlvlrKkd6M10jj" + + "xDb/7z5AXx/P6CqXHEMe5FUwPRWfgS8yM621xmHkRnsyumTqKz4lVTW9HZ7pqpC+icep15GJ2n/mQ+ROf/bphqic5lt+gXfZtuM9+i77" + + "c7pjz0LbvL9+hb9ZepOOgbeY98pj1231Q24vfvA1N10Xnkoams6Nz5t6lU6Hz6yFRNdJr/MN7R2eKJKZY8vXlqqlFQLzwz1SYI9AtT7d" + + "D3jrYJ+j5R7LRA35mX+EY8s7zGN3TmfmNqATpLvyUP0Vnlnamd6GzynrxC54APZriPO/WR+QR9tz6ZKhsrWJ9MxUVnFha5X9BZ4wt5TT" + + "w7fWWeCvY9svQKvZcNS0XRWZ7NWBDHIbYV5ulkx9IndM50gUbfEs8K1/XYkSwNQF+KyJbYmmpiFEssidpGMZ6SSy9Hs1QMfZej0zrB+m" + + "ZpGvpyx7K0EH0jYlt6gb5XcSw1RFfJeJbWo+tdfEtN0ZMmoaUp6NmeyFIq9ET+zlLP8DzH0nH0LElqKQY6TiSzlAsd+VNYWoqOA3SeGR" + + "0rvrfCeF1PZakUOvKn5nd0ZEpjaRbxmpnWkoGOReksRUPHhvRWOO76ZLR0KqgLMlliClCPzJaOoUdZrfBcJ+GPljqgowNF/H50PMpuqS" + + "DxeZjDUn50NMplaRM6zDyWaqGjVl5Lq9AxLJ+ly+TfsfyWkqDDZ9JqgI5uhSwdCc47CluKj450RfE1qLOKWTLRkbeEpfHo6FfS0hl0HC" + + "plKSH8ycpY4fnNorKW3qEjWXlLVcHsV8HSWvg/VLSEFA2ojK8I61DF0ny4t1e19ATuH6tbag53hhrf/G9Q09IkuC/WsuTBfau2pVhwP2" + + "Ly+Q7uDXUt3aN9U89SWvjbNLA0F/53DS2lJw5vSOq08Ldogr/B+Glq6Tzj50QzS/+hoyBFX2f4Z7YkfsThf62scLwUbWOpO/zr2lq6Sx" + + "wKt+cz/K068Hz8r9bR0igrWM8s1cX/VV0s3XaDcxq4yJ9h3S1FoEM9yQP4f+tl6ULUYP2yVBP+6H0tlYA7Zj/yIKiT+lvKE9QZAyx1Df" + + "Z1Ay0dDOrIQeiAf+YQSyfhLznMUl+4e1HsrIZ76khLR/E982hLzeBNNNZi7EixxlkaAu+u8VZYf5+cYIX7lJMTaeE9O8lSYXgPT7aUE9" + + "+XTyHOcB+faikv3Ien8T3+n55uhedlh2fyGf93UZxkgHvlbOIN98E5lrLDXf1XSwfgrjqP/IN7/W+WksH9bD75BHf1hfyO7wkWWxpJ3t" + + "RcYukQ/O2XWrqO742XkUfoaLycFv/nr2A843vVVZZ+Q0/yNVZ4zpRgnRXupyM2MC7gdjZbqgbvrC2W7sNrbbPC87DBEYwXeKPssFQH3m" + + "K7LE2EM9UeS13gS7rPUjv4yuy3NB2+z79bKouvpQ5amgrf4EPcD1+iI5ZawVXzqKVFcM1j0P2Dz5+P81y4xpy0RAmvjKfxHZ8nnOF3+D" + + "6eZZzhb8fzlk7A+eKCpYrwJb1kqR9+Hr9sKQ18B69aSgFf0ut8j5/eDfThY9OblvbCee8W8x+c6e/gG5z1/7K0Hc6I+5bi4tvyh/gA14" + + "NHVngut/4fS2y5tfappQLw/P7c0k/E++i/5B0cUV5bmo1fj99Y6g3Hs3eW+sNR/SN5Dkf9z5Ye41Pj/yw9o/8XXy0NpN/1hq1C9LvDtF" + + "UGf9batgrQf1XX1m386ezZ+g+Otr6t9/hzN5KtavgzNIqtV/BUjWqLJVn5otkipGoY3dYZfNrFopoJn6bEtGXClzS2rYnkYeY4tn6Ds3" + + "9cW08D3+LzPXEdl8AOz9W3JrSVBt6Oie1wPz/uO76He3USW0ng/juprTqM/zzJba3Av7YpbF1Hx/CUdnguOOF7W1/Q83cqO9wfRqS2lQ" + + "4d6dPZmgP/rPR2OO/+SfFWFv4XGW1RMqt+Zjucd7tmoV8u2Jf1G/+8bLYiw30zu63ycH/OYasN3LFy2xoEd6U8tnbCbeSz1Qnu1gzGi3" + + "BHK2irH/FeWMhWdHhfF7bVBN5RReEMeCmu/oXzfQlbLeB8X8oOzy8/l+H5cBYqh5/EPV8FW1PhHFfRFiWAZlXmPvgaVrG1Db5E1Wx1g6" + + "9EdVu/wvdfDVu1iP9/NWnhq1Db1hL4htexdYP56XFdW8XhK1Pf1gJ83dHAVmx8bdiI58H5Z2NbOeF72dQOz/dyMSgnwjeqla078O2giI" + + "gN19p2tj7h45MOtlhyFIVNZR3ysRyb2pnEO1Z3W43gWdqTPIFnTG+bNZrx0ddWfPo/3I/n0H+8Abaa4dPggbZOwTF8sK1z+LR6qM2ek3" + + "wZjo/kZf8RxAeO0z/bSgzH7VHEB59ajrG1CZ5942yxxVXqiXa4r347yVYx/Ok7xdZheBJNs9USnobT7fAct8JMW7PwJ2KWLQtf8sy2NZ" + + "z4PZljh/P1vbm2ssK1Z54dntv+Pt9WNHxZvZBxANeTRVwH1+3FtjLCdXKJrQSMm2lLGTe0nZfZ4f627nJbSxk/9VfYWg5vGTZL0+CtsM" + + "rWOvwrt9rWGuJbfQ3+w99/LfmHn63X2TqBju4sppfxdfMGfAvm843f8rH/Jq6jPbrZVgb0bN7C7/j8ZKutyuiKFGGrA37H2m6rR6Bvhx" + + "2eZxTbST7g//JdPAd9o3bb+od23h46Q+ftveQH/h/ex7hB78r9tqKid+HvjBvyYe6Bb+Pr5kFbRdG9/hBxRO/5w+QNet8eIQ+Ceeso4w" + + "u9WY+Tv+iNhZjm6H1Amwe9B0/aiofeladsUTJq42niAMJCJo/XtOPO2rqJ7obnbK0njjnO2/oZ/fn+sDUO3Wkv2OpLPFNetNUd/S9oi6" + + "H/4CWei/6Bl22dpS1yxdYUfGh81dZGfCh0zdYkfIh23VZjfHhPW454Z7tB/PEh4ua3eD9jEiiCDy9u81x8uHTHVlp8WH/XloH+o3/ZSk" + + "T8I+5xPT6svI+OYL55wGd8+P2hrTj4sPJvvqdd/Yh5FD+mPbb1AD96spicxY8iT2zNxo/mT22x9VFrNiEsWRr+HP34MOmFrcf40JdBfw" + + "EffnpJ/uJDkVfchw/FMGsuPsR6Y6s9PqR9azM348s7W/3Rn+q9rYGB/g+2dqA/80dbo9Cf9ZOtMejP+Blf0V/pf3b4niLjf3xmHGb9wu" + + "/4UOkr3+NDXTnajA8DDUdX8GGt6cgL9FuOYqG7jONoIXkw0OV39MfwHbVFb8NIjiLQO5dN5C30Lozi6D56p0R1xFZKkaI7YmrT8hiO/k" + + "HnfzGd8L3YtNiOLqMvV1xHfdDVPJ6jZeialcDRdfRsTOToDToyJnHUCe62SR2tgXtCMic8nzuf3FFceL+mcML3eNO+53nE7WUqRznhrZ" + + "na0S/wDk/j6Ai8+9I6MuGNk95RLXgHZnC0Fd7XGR1lhLNvZkcbicuVLI5AVawfHZUL5t/sjqrCmTGHE9a3OXI6YRzW53L0N7yTcjs6Sh" + + "yMvI7y4X+5fI6Gwr2WYu0B/qcv6Kgp/DEKOyoD9+wijs7jd182MRvh/ruEo+Twni/tKBJ5lL4c18N3toKj5/j4sZIjlkw9qOKEdVPV6o" + + "66wPF7TUd36L8xk3JwnjmPYnY3/U6q52gd/c5rwGf6PdkQ3/FtUmO+p9+NTfAvqJuaOkqMX+mbOypLnPe0cMJz89atHI3Er5RtiBN+DW" + + "/raBE8H9lURjGC9cAJzze3dkI3XIm64B8+xermKBU+Ve/uhPPw7B5O+L4hVS9HufAnTh9HqeGc0tfRYjjv9XP0Fs6I/o6Ok58RA5xwHx" + + "YxkBbeoYMdTYP37yGOPsLbepgT1s/thzsaCO+4EU74/qHrSEfDg3lpFPkKb0GVjVlmrKPKxLbUOHIP5rrjnfBsZ8oEJzyj6z0Jz4jxjs" + + "mO9sN+YQo5h7c9pzkaAHvWGY5y4+3LmY4+wP7nL47+CuaWOY5KwlzsVzwL1v55jlbA+v43R1+IbdcF5DKssRYRM1hjLHYUH9a2S4gZrG" + + "OWOZoMa8sVjjrAem+VE84R69c44d5kyjq0hTUyHsH18yZHXfH02mZHh+H6aaujAnDt2eZoJVzrt3MfXM13OvoJrly7HaWEq/4ecg2u6n" + + "sdFYFr/j5H4/AywQFHFlwnDzJm4fp8iBwOuI446glX66OOqpODV445OghflBOO3hP7aCcdPYHzPe0l/LROO7oLb5wzjl7iZ46zzBH4Wf" + + "Wco6xwlzvvKC1+lvgDHvibX3RUjFyYdgk9YQ3thGfPX684uslY736NMUZOpP3TkUMujLvB3IKOgywQC9FR5LajpPA/uANXMObvch9jJ/" + + "29b3NUkfv8jo54Dxy9pv1Ie4Wxf/ghPqLr+N/0h660TLQOehYyEXVHT/unjgqhY/EzJ9juaetzR5QdevzC0S709H7JHICOHa+ccE06/M" + + "bRLHREe+fodrAWvXfCs/MHH/ET/q2fuR/+9l94Lr7flKv18EaxXN3E9/mOq65w9fddVcLf5ZHd8Cy8bjRXcem/UAxXTOOaG9MN9yAJYr" + + "v6g/47x3GVgfjXjct19J88vqvr9F8ugSub/s8ndDWePPg9sasBwZyfxNVDOOYndcN3Gr2Tu+FZ8ekUrkbDE5HSVTf8m/e9G75zaZrKVR" + + "J8zPGDq+e0rVO7+h7On9K4iox/RdK6+kSbIB08+Jg6vas7wZ41g6uL+HmbdiY6zjIRjCQ/5lFY18DX05nd8Gx/fhb0oGswyZE7qCF/RB" + + "z/UmZzdTXQmd3VmWBPmMPVbnz+SrsNvTdzupqO3o25XLVB7+zcbrhH7J4HP9A9I6+riuiekM9VyWBvm99VE/S/LuBqFfoTFXJ1jjzKzI" + + "b5Pj6UK0Jn+PC1KM/Hh3nF4UR/pZL4SN7MLe2qWrBWlHXDd3OJKri6FuwlKrmai47qP7mKA/+TKq5W86jU1Vw9gHtudVf14bVqujoI78" + + "8ErxScj+u4Wgnfi7rkAXxN67tKCVfGhq6ewFW7sasE8Jxv4moKPPGau7oEz6yWrmrj/4XWrqbhd7a2rl4GtWU7V14Kxm17V7PwuURHV7" + + "eDmrKTG75rz9eF++Hb09VVXbjad+d6uGb0cJUNrrq9XL3Fx6O9XTXHv3194Q7Wqv5uWCPNHegqDz59HsTzyd/MQ10dD/auw9ywJr40nP" + + "wlPzb+TP7C132UqxjBmjXG1WH41o91w7/1OT7ODc/U801wtTeo/SYSd/iMyeQHfB2nuHqFf0enEj/inXK6q2VwVp3h6jKcTWeSv8H8O4" + + "s4wPn2F1f9ghp3jhuucX3nuvpCnCPNczURH2/SNoM7+XxXS+BOv8AN17oCC93wbHn9Irjw9R6Tahv4Cy11dYB4T1nmKn6Q3ytcHULHd6" + + "tcLSCfvyO4Y9HRfA35jo6ea91wbzZlnRv+UcbfFKy10FFso6sN4Tzt6g1+D9+MLvSc3uKqIDoitrpKE+zV2cg1IB+uRbgqi57NO9zwHU" + + "/zXTwfHfd2k3exg/karmCPtI/noGM9i1My+CcdQC/+xzjkalCwJzmMv/jf+yg+wX/tmBvW4odPuMoF97WTxBPu9KddzYb79RniDXeU86" + + "4ItUr94WorvHUvEl98H3WZ+MJ58wpxhS/zdVfz4Mt8gzZYm2+6SgtXpNuu+sL1+Y6r9nA9/os8w9cy991wPUn5kDyGy3rkqjt+nn/sqh" + + "h+lnrqakZQAz93tZlxdPylq0T0v+eNq2j4VPu9G64Hcz8xLug3z3+uRuFHza+ultJfbcPTcvq7YHlKRT/7HE8x6Cep56kj+uP5nlrSX/" + + "JInjonC/6exNNEfLgU1VMG9KeM7qkX/daN6YklViVie/qF/hfG8fSOeM1l4/VvML8k9MJ3/CUS8zscF5J44buLCsk8LUD/4+SeCpNXcV" + + "J6agNPy+897SQu+1J5igtX79ReePYUi8UvOHv6Lp2nLnCNyeDpFj54mTw1xYdKWdADT7FsnkhlvczhqQJxGJfb0wM44uVDB/meoICnrs" + + "F8XtgLa/amFM676D9pcU+9g/WvhKfh+B+tlKfW9Ju5tKdR+HK7jKd89Hu0vBeehayu5OkRPtSs4mkq+o9X8+Sie0pNT2fwf35tL/ybi3" + + "FMGsfod3g9T/vRbzXwwr/dKtLQ0wB86N/I0/bgbKmxp0xw/NzU0wF8yNrcUwc4drX09AGOa628cFylbOOpERyV2noaG9Q77b7xnG2P38" + + "H629HTeLhedvIUmx86diFu8HXu6ompQvO7eeGZeM0exA9/yvXy1A5/LvTxwneljft5GhLM+/09ncCnSQO98O86tw72dJm8+TjUU2J8qj" + + "3cUx/4lo7wdIQ4HWSjeR/OzyM9JYHTGOPpe/gyjvVUkTj1Hoff8K0dj9/E66eJnhoSr9mTiRt8H6d68vBv9XRPO4I9wUwv3JueneXpJj" + + "4mmuMpLVzZ5noqAte+Xz2dxseFv3laj3/7FvAZ/xYv8sI9wIwlnhbDNWMZLfGLWOHpcHCWusrTWnjervHCs7hJ6/ALjj83eLoKx4RN+B" + + "qcxWzxFD2Y5xnUU4nnhQhP5+BouMNTvaA+3OWF62LKvZ6S0f+TfeQD/iw+QF7Tf+pD6Kf/97TBO+P0R7zwb1X2HCW/8afpceKIPwVOMt" + + "7w5egpL3w3U4lFezA8087BC091ipVgD7/vgqeXfrBn95QSnveXPaWHZ9JVT78Ttz+veYqGPyn/9FQdrro3PI3Dn9S3PNWGb/VtfISv/l" + + "1PE8ivKfc8HSR+FottLuKW/qGn+vAV+9tTd/hGPSIO+PXyMfMDfuV4Ai+ceZ55ahbUqS8Yt+RXvH+98G8b47z0wjP0fK+88N1YsdfkL7" + + "ypmcSr4GPPt174bmz4e+aLoM7+6Ok6Pt797CkqnAW+ML7hHPfVC8/UUhq+KsI5xvK1Bc6Bth/+zU8MBll+OOeTLCfgfO37ShbUFZF9lY" + + "SzUFRfdfGxaTRfA+GMFcNXZjhLxfTF9kzzY/liiVDLOL6Gwjc8nq/5cOVL4KsmXNES++HfbnVN4msCXDOS+tpI/l9L5ustfLlS+KpKns" + + "2mCN8KX6QffKUO6uXUvurjY+00vrrDVy6tr5bwtU3n62d8PJje120452X0w/onUmZfpeBLn4XriHfWbL7aB2en2fkd/zbm8PUMvmi5fZ" + + "VjHOzK4+t9MA7ywxms1wXpH767hXwlhatzEV+r8a1xUV9z4ZtQzA/rjK/FfRXAP6+krxJwpi3tqzl81cv4mgRfmbK+hsNXvRyf4Wta3t" + + "c8fLxSAV/xsXYlP/zb4pOV/XA+GVjFF1scrWQD/y+8xar7Gg3nsxp++I4kQW1fjeCcUsfXVfIyoq6vL8Q5Rn1ftcjLHA189YN7eUNfz/" + + "E1dWNfHeC+1NRXkuCMsLmv7HAubenrKX7ebe0rXTBu2/p6CN/Ndn4433UmuWbCF9HR1y34Onb2NZ0fnnXxRUmv+t18DcPHSD18/Uj+le" + + "jpqx18vXuhBz8H9va1BM57fXxFhm9Ufz/c498e4MuF6/ZA2mCfNNhXq2AfOsTXL/g6iaQJ6twXw3zFx9fVI3z9Ae+EkeQpvu4Y5Ydnvm" + + "XG+OoE7/ux33g/s9nx4Z07gTyG9/ZE9AXzziRfj4Kz/8m+2CLq9RTMDPZ503xhtbpO9zUI/voz/bBeXzmL/uGOMRu/4D48h/7Jh1i/Ei" + + "98PU97K1ZQv/nhGWX3+b6GwO8sJH5wJ13kK0Pg82JfH+DPsdQPzyTfLvNlwt1+ha8++N17pa8R8C9d7esM/LPX+uE7i2fr0Q3nyY2+KD" + + "W0Y7Ovv/xgH+2HZ06tt/maHNQ9EfhH/Fvv4DOcR3eSL3D+HwCCjIRqMAAA"); RecordInputStream in = TestcaseRecordInputStream.create(bytes); assertEquals(ExtSSTRecord.sid, in.getSid()); diff --git a/src/testcases/org/apache/poi/hssf/record/TestExtendedFormatRecord.java b/src/testcases/org/apache/poi/hssf/record/TestExtendedFormatRecord.java index 5ed16ad0f4..d894ceb401 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestExtendedFormatRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestExtendedFormatRecord.java @@ -17,20 +17,22 @@ package org.apache.poi.hssf.record; -import junit.framework.TestCase; -/** - */ -public final class TestExtendedFormatRecord extends TestCase { +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; - private static final byte[] data = new byte[] { - 00, 00, // Font 0 - 00, 00, // Format 0 +import org.junit.Test; + +public final class TestExtendedFormatRecord { + + private static final byte[] data = { + 0, 0, // Font 0 + 0, 0, // Format 0 0xF5 - 256, 0xFF - 256, // Cell opts ... - 0x20, 00, // Alignment 20 - 00, 00, // Ident 0 - 00, 00, // Border 0 - 00, 00, // Palette 0 - 00, 00, 00, 00, // ADTL Palette 0 + 0x20, 0, // Alignment 20 + 0, 0, // Ident 0 + 0, 0, // Border 0 + 0, 0, // Palette 0 + 0, 0, 0, 0, // ADTL Palette 0 0xC0 - 256, 0x20 // Fill Palette 20c0 }; @@ -38,6 +40,7 @@ public final class TestExtendedFormatRecord extends TestCase { return new ExtendedFormatRecord(TestcaseRecordInputStream.create(0x00E0, data)); } + @Test public void testLoad() { ExtendedFormatRecord record = createEFR(); assertEquals(0, record.getFontIndex()); @@ -54,6 +57,7 @@ public final class TestExtendedFormatRecord extends TestCase { } + @Test public void testStore() { // .fontindex = 0 // .formatindex = 0 @@ -113,11 +117,12 @@ public final class TestExtendedFormatRecord extends TestCase { record.setFillBackground((short) 0x41); byte[] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i + 4]); + confirmRecordEncoding(ExtendedFormatRecord.sid, data, recordBytes); } + + + @Test public void testCloneOnto() { ExtendedFormatRecord base = createEFR(); @@ -125,11 +130,10 @@ public final class TestExtendedFormatRecord extends TestCase { other.cloneStyleFrom(base); byte[] recordBytes = other.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i + 4]); + confirmRecordEncoding(ExtendedFormatRecord.sid, data, recordBytes); } - + + @Test public void testRotation() { ExtendedFormatRecord record = createEFR(); assertEquals(0, record.getRotation()); diff --git a/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java b/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java index 8d7b1bee75..e3bbb09fa3 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java @@ -17,17 +17,17 @@ package org.apache.poi.hssf.record; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import org.apache.poi.util.HexDump; import org.apache.poi.util.HexRead; -import org.apache.poi.util.RecordFormatException; +import org.junit.Test; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; -/** - * - * @author Josh Micich - */ -public final class TestExternalNameRecord extends TestCase { +public final class TestExternalNameRecord { private static final byte[] dataFDS = { 0, 0, 0, 0, 0, 0, 3, 0, 70, 68, 83, 0, 0, @@ -36,7 +36,7 @@ public final class TestExternalNameRecord extends TestCase { // data taken from bugzilla 44774 att 21790 private static final byte[] dataAutoDocName = { -22, 127, 0, 0, 0, 0, 29, 0, 39, 49, 57, 49, 50, 49, 57, 65, 87, 52, 32, 67, 111, 114, - 112, 44, 91, 87, 79, 82, 75, 79, 85, 84, 95, 80, 88, 93, 39, + 112, 44, 91, 87, 79, 82, 75, 79, 85, 84, 95, 80, 88, 93, 39, }; // data taken from bugzilla 44774 att 21790 @@ -49,41 +49,30 @@ public final class TestExternalNameRecord extends TestCase { private static ExternalNameRecord createSimpleENR(byte[] data) { return new ExternalNameRecord(TestcaseRecordInputStream.create(0x0023, data)); } + + @Test public void testBasicDeserializeReserialize() { ExternalNameRecord enr = createSimpleENR(dataFDS); assertEquals("FDS", enr.getText()); - try { - TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataFDS, enr.serialize()); - } catch (ArrayIndexOutOfBoundsException e) { - if(e.getMessage().equals("15")) { - throw new AssertionFailedError("Identified bug 44695"); - } - } + // bug 44695 + TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataFDS, enr.serialize()); } + @Test public void testBasicSize() { ExternalNameRecord enr = createSimpleENR(dataFDS); - if(enr.getRecordSize() == 13) { - throw new AssertionFailedError("Identified bug 44695"); - } + assertNotEquals("Identified bug 44695",13, enr.getRecordSize()); assertEquals(17, enr.getRecordSize()); - - assertNotNull(enr.serialize()); + + assertNotNull(enr.serialize()); } + @Test public void testAutoStdDocName() { - ExternalNameRecord enr; - try { - enr = createSimpleENR(dataAutoDocName); - } catch (ArrayIndexOutOfBoundsException e) { - if(e.getMessage() == null) { - throw new AssertionFailedError("Identified bug XXXX"); - } - throw e; - } + ExternalNameRecord enr = createSimpleENR(dataAutoDocName); assertEquals("'191219AW4 Corp,[WORKOUT_PX]'", enr.getText()); assertTrue(enr.isAutomaticLink()); assertFalse(enr.isBuiltInName()); @@ -95,6 +84,7 @@ public final class TestExternalNameRecord extends TestCase { TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataAutoDocName, enr.serialize()); } + @Test public void testPlainName() { ExternalNameRecord enr = createSimpleENR(dataPlainName); @@ -109,8 +99,9 @@ public final class TestExternalNameRecord extends TestCase { TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataPlainName, enr.serialize()); } + @Test public void testDDELink_bug47229() { - /** + /* * Hex dump read directly from text of bugzilla 47229 */ final byte[] dataDDE = HexRead.readFromString( @@ -124,22 +115,16 @@ public final class TestExternalNameRecord extends TestCase { " 01 00 00 " + "02 09 00 00 23 4E 2F 41 20 4E 2E 41 2E " + "02 09 00 00 23 4E 2F 41 20 4E 2E 41 2E"); - ExternalNameRecord enr; - try { - enr = createSimpleENR(dataDDE); - } catch (RecordFormatException e) { - // actual msg reported in bugzilla 47229 is different - // because that seems to be using a version from before svn r646666 - if (e.getMessage().startsWith("Some unread data (is formula present?)")) { - throw new AssertionFailedError("Identified bug 47229 - failed to read ENR with OLE/DDE result data"); - } - throw e; - } + + // actual msg reported in bugzilla 47229 is different + // because that seems to be using a version from before svn r646666 + ExternalNameRecord enr = createSimpleENR(dataDDE); assertEquals("010672AT0 MUNI,[RTG_MOODY_UNDERLYING,RTG_SP_UNDERLYING]", enr.getText()); TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataDDE, enr.serialize()); } + @Test public void testUnicodeName_bug47384() { // data taken from bugzilla 47384 att 23830 at offset 0x13A0 byte[] dataUN = HexRead.readFromString( @@ -150,20 +135,13 @@ public final class TestExternalNameRecord extends TestCase { "00 00"); RecordInputStream in = TestcaseRecordInputStream.create(dataUN); - ExternalNameRecord enr; - try { - enr = new ExternalNameRecord(in); - } catch (RecordFormatException e) { - if (e.getMessage().startsWith("Expected to find a ContinueRecord in order to read remaining 242 of 268 chars")) { - throw new AssertionFailedError("Identified bug 47384 - failed to read ENR with unicode name"); - } - throw e; - } + ExternalNameRecord enr = new ExternalNameRecord(in); assertEquals("\u0159azen\u00ED_Billa", enr.getText()); byte[] ser = enr.serialize(); assertEquals(HexDump.toHex(dataUN), HexDump.toHex(ser)); } + @Test public void test48339() { // data taken from bugzilla 48339 byte[] data = HexRead.readFromString( @@ -175,18 +153,19 @@ public final class TestExternalNameRecord extends TestCase { byte[] ser = enr.serialize(); assertEquals(HexDump.toHex(data), HexDump.toHex(ser)); } - + + @Test public void testNPEWithFileFrom49219() { - // the file at test-data/spreadsheet/49219.xls has ExternalNameRecords without actual data, + // the file at test-data/spreadsheet/49219.xls has ExternalNameRecords without actual data, // we did handle this during reading, but failed during serializing this out, ensure it works now byte[] data = new byte[] { - 2, 127, 0, 0, 0, 0, + 2, 127, 0, 0, 0, 0, 9, 0, 82, 97, 116, 101, 95, 68, 97, 116, 101}; ExternalNameRecord enr = createSimpleENR(data); byte[] ser = enr.serialize(); - assertEquals("[23, 00, 11, 00, 02, 7F, 00, 00, 00, 00, 09, 00, 52, 61, 74, 65, 5F, 44, 61, 74, 65]", + assertEquals("[23, 00, 11, 00, 02, 7F, 00, 00, 00, 00, 09, 00, 52, 61, 74, 65, 5F, 44, 61, 74, 65]", HexDump.toHex(ser)); } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestFeatRecord.java b/src/testcases/org/apache/poi/hssf/record/TestFeatRecord.java index dc884000b0..5cde3d1734 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestFeatRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestFeatRecord.java @@ -17,6 +17,12 @@ package org.apache.poi.hssf.record; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.model.InternalSheet; import org.apache.poi.hssf.model.InternalWorkbook; @@ -24,24 +30,23 @@ import org.apache.poi.hssf.record.common.FeatFormulaErr2; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFTestHelper; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.junit.Test; -import junit.framework.TestCase; /** * Tests for FeatRecord - * - * @author Josh Micich */ -public final class TestFeatRecord extends TestCase { +public final class TestFeatRecord { + @Test public void testWithoutFeatRecord() throws Exception { - HSSFWorkbook hssf = + HSSFWorkbook hssf = HSSFTestDataSamples.openSampleWorkbook("46136-WithWarnings.xls"); InternalWorkbook wb = HSSFTestHelper.getWorkbookForTest(hssf); - + assertEquals(1, hssf.getNumberOfSheets()); - + int countFR = 0; int countFRH = 0; - + // Check on the workbook, but shouldn't be there! for(Record r : wb.getRecords()) { if(r instanceof FeatRecord) { @@ -55,14 +60,14 @@ public final class TestFeatRecord extends TestCase { countFRH++; } } - + assertEquals(0, countFR); assertEquals(0, countFRH); - + // Now check on the sheet HSSFSheet s = hssf.getSheetAt(0); InternalSheet sheet = HSSFTestHelper.getSheetForTest(s); - + for(RecordBase rb : sheet.getRecords()) { if(rb instanceof Record) { Record r = (Record)rb; @@ -78,21 +83,22 @@ public final class TestFeatRecord extends TestCase { } } } - + assertEquals(0, countFR); assertEquals(0, countFRH); } - public void testReadFeatRecord() throws Exception { - HSSFWorkbook hssf = + @Test + public void testReadFeatRecord() { + HSSFWorkbook hssf = HSSFTestDataSamples.openSampleWorkbook("46136-NoWarnings.xls"); InternalWorkbook wb = HSSFTestHelper.getWorkbookForTest(hssf); - + FeatRecord fr = null; FeatHdrRecord fhr = null; - + assertEquals(1, hssf.getNumberOfSheets()); - + // First check it isn't on the Workbook int countFR = 0; int countFRH = 0; @@ -109,14 +115,14 @@ public final class TestFeatRecord extends TestCase { fail("FeatHdrRecord SID found but not created correctly!"); } } - + assertEquals(0, countFR); assertEquals(0, countFRH); - + // Now find it on our sheet HSSFSheet s = hssf.getSheetAt(0); InternalSheet sheet = HSSFTestHelper.getSheetForTest(s); - + for(RecordBase rb : sheet.getRecords()) { if(rb instanceof Record) { Record r = (Record)rb; @@ -134,33 +140,33 @@ public final class TestFeatRecord extends TestCase { } } } - + assertEquals(1, countFR); assertEquals(1, countFRH); assertNotNull(fr); assertNotNull(fhr); - + // Now check the contents are as expected assertEquals( FeatHdrRecord.SHAREDFEATURES_ISFFEC2, fr.getIsf_sharedFeatureType() ); - + // Applies to one cell only assertEquals(1, fr.getCellRefs().length); assertEquals(0, fr.getCellRefs()[0].getFirstRow()); assertEquals(0, fr.getCellRefs()[0].getLastRow()); assertEquals(0, fr.getCellRefs()[0].getFirstColumn()); assertEquals(0, fr.getCellRefs()[0].getLastColumn()); - + // More checking of shared features stuff assertEquals(4, fr.getCbFeatData()); assertEquals(4, fr.getSharedFeature().getDataSize()); assertEquals(FeatFormulaErr2.class, fr.getSharedFeature().getClass()); - + FeatFormulaErr2 fferr2 = (FeatFormulaErr2)fr.getSharedFeature(); assertEquals(0x04, fferr2._getRawErrorCheckValue()); - + assertFalse(fferr2.getCheckCalculationErrors()); assertFalse(fferr2.getCheckDateTimeFormats()); assertFalse(fferr2.getCheckEmptyCellRef()); @@ -172,9 +178,10 @@ public final class TestFeatRecord extends TestCase { } /** - * cloning sheets with feat records + * cloning sheets with feat records */ - public void testCloneSheetWithFeatRecord() throws Exception { + @Test + public void testCloneSheetWithFeatRecord() { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("46136-WithWarnings.xls"); wb.cloneSheet(0); diff --git a/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java b/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java index 7791df3aa6..1e3a19bfb4 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java @@ -18,31 +18,35 @@ package org.apache.poi.hssf.record; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; import org.apache.poi.util.HexRead; +import org.junit.Test; /** * Tests the serialization and deserialization of the {@link FontRecord} * class works correctly. Test data taken directly from a real Excel file. */ -public final class TestFontRecord extends TestCase { +public final class TestFontRecord { private static final int SID = 0x31; private static final byte[] data = { - 0xC8-256, 00, // font height = xc8 - 00, 00, // attrs = 0 + 0xC8-256, 0, // font height = xc8 + 0, 0, // attrs = 0 0xFF-256, 0x7F, // colour palette = x7fff 0x90-256, 0x01, // bold weight = x190 - 00, 00, // supersubscript - 00, 00, // underline, family - 00, 00, // charset, padding - 05, 00, // name length, unicode flag + 0, 0, // supersubscript + 0, 0, // underline, family + 0, 0, // charset, padding + 5, 0, // name length, unicode flag 0x41, 0x72, 0x69, 0x61, 0x6C, // Arial, as unicode }; + @Test public void testLoad() { FontRecord record = new FontRecord(TestcaseRecordInputStream.create(0x31, data)); @@ -63,6 +67,7 @@ public final class TestFontRecord extends TestCase { assertEquals(21 + 4, record.getRecordSize()); } + @Test public void testStore() { // .fontheight = c8 // .attributes = 0 @@ -94,6 +99,7 @@ public final class TestFontRecord extends TestCase { TestcaseRecordInputStream.confirmRecordEncoding(0x31, data, recordBytes); } + @Test public void testCloneOnto() { FontRecord base = new FontRecord(TestcaseRecordInputStream.create(0x31, data)); @@ -106,6 +112,7 @@ public final class TestFontRecord extends TestCase { assertEquals("At offset " + i, data[i], recordBytes[i+4]); } + @Test public void testSameProperties() { FontRecord f1 = new FontRecord(TestcaseRecordInputStream.create(0x31, data)); FontRecord f2 = new FontRecord(TestcaseRecordInputStream.create(0x31, data)); @@ -128,6 +135,7 @@ public final class TestFontRecord extends TestCase { * length is zero. The OOO documentation seems to agree with this and POI had no test data * samples to say otherwise. */ + @Test public void testEmptyName_bug47250() { byte[] emptyNameData = HexRead.readFromString( "C8 00 00 00 FF 7F 90 01 00 00 00 00 00 00 " @@ -137,9 +145,7 @@ public final class TestFontRecord extends TestCase { RecordInputStream in = TestcaseRecordInputStream.create(SID, emptyNameData); FontRecord fr = new FontRecord(in); - if (in.available() == 1) { - throw new AssertionFailedError("Identified bug 47250"); - } + assertNotEquals(1, in.available()); assertEquals(0, in.available()); assertEquals(0, fr.getFontName().length()); diff --git a/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java b/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java index ab80faf510..65b48ff65e 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java @@ -17,6 +17,10 @@ package org.apache.poi.hssf.record; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import org.apache.poi.ss.formula.ptg.AttrPtg; import org.apache.poi.ss.formula.ptg.FuncVarPtg; import org.apache.poi.ss.formula.ptg.IntPtg; @@ -24,17 +28,14 @@ import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.formula.ptg.RefPtg; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.FormulaError; - -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import org.junit.Test; /** * Tests for {@link FormulaRecord} - * - * @author Andrew C. Oliver */ -public final class TestFormulaRecord extends TestCase { +public final class TestFormulaRecord { + @Test public void testCreateFormulaRecord () { FormulaRecord record = new FormulaRecord(); record.setColumn((short)0); @@ -50,6 +51,7 @@ public final class TestFormulaRecord extends TestCase { * Make sure a NAN value is preserved * This formula record is a representation of =1/0 at row 0, column 0 */ + @Test public void testCheckNanPreserve() { byte[] formulaByte = { 0, 0, 0, 0, @@ -95,8 +97,8 @@ public final class TestFormulaRecord extends TestCase { /** * Tests to see if the shared formula cells properly reserialize the expPtg - * */ + @Test public void testExpFormula() { byte[] formulaByte = new byte[27]; @@ -114,6 +116,7 @@ public final class TestFormulaRecord extends TestCase { assertEquals("Offset 22", 1, output[26]); } + @Test public void testWithConcat() { // =CHOOSE(2,A2,A3,A4) byte[] data = { @@ -150,7 +153,8 @@ public final class TestFormulaRecord extends TestCase { FuncVarPtg choose = (FuncVarPtg)ptgs[8]; assertEquals("CHOOSE", choose.getName()); } - + + @Test public void testReserialize() { FormulaRecord formulaRecord = new FormulaRecord(); formulaRecord.setRow(1); @@ -168,15 +172,16 @@ public final class TestFormulaRecord extends TestCase { RefPtg rp = (RefPtg) ptgs[0]; assertEquals("B$5", rp.toFormulaString()); } - + /** * Bug noticed while fixing 46479. Operands of conditional operator ( ? : ) were swapped * inside {@link FormulaRecord} */ + @Test public void testCachedValue_bug46479() { FormulaRecord fr0 = new FormulaRecord(); FormulaRecord fr1 = new FormulaRecord(); - // test some other cached value types + // test some other cached value types fr0.setValue(3.5); assertEquals(3.5, fr0.getValue(), 0.0); fr0.setCachedResultErrorCode(FormulaError.REF.getCode()); @@ -184,9 +189,7 @@ public final class TestFormulaRecord extends TestCase { fr0.setCachedResultBoolean(false); fr1.setCachedResultBoolean(true); - if (fr0.getCachedBooleanValue() && !fr1.getCachedBooleanValue()) { - throw new AssertionFailedError("Identified bug 46479c"); - } + assertFalse("Identified bug 46479c", fr0.getCachedBooleanValue() && !fr1.getCachedBooleanValue()); assertFalse(fr0.getCachedBooleanValue()); assertTrue(fr1.getCachedBooleanValue()); } diff --git a/src/testcases/org/apache/poi/hssf/record/TestFtCblsSubRecord.java b/src/testcases/org/apache/poi/hssf/record/TestFtCblsSubRecord.java index a4ba179be9..1a1204c2f5 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestFtCblsSubRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestFtCblsSubRecord.java @@ -19,29 +19,29 @@ package org.apache.poi.hssf.record; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.junit.Test; /** * Tests the serialization and deserialization of the FtCblsSubRecord * class works correctly. - * - * @author Yegor Kozlov */ -public final class TestFtCblsSubRecord extends TestCase { +public final class TestFtCblsSubRecord { private final byte[] data = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x01, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00 }; + @Test public void testRead() { - FtCblsSubRecord record = new FtCblsSubRecord(TestcaseRecordInputStream.create(FtCblsSubRecord.sid, data), data.length); assertEquals(FtCblsSubRecord.sid, record.getSid()); assertEquals(data.length, record.getDataSize()); } + @Test public void testWrite() { FtCblsSubRecord record = new FtCblsSubRecord(); assertEquals(FtCblsSubRecord.sid, record.getSid()); @@ -49,11 +49,10 @@ public final class TestFtCblsSubRecord extends TestCase { byte [] ser = record.serialize(); assertEquals(ser.length - 4, data.length); - } - public void testClone() - { + @Test + public void testClone() { FtCblsSubRecord record = new FtCblsSubRecord(); byte[] src = record.serialize(); diff --git a/src/testcases/org/apache/poi/hssf/record/TestInterfaceEndRecord.java b/src/testcases/org/apache/poi/hssf/record/TestInterfaceEndRecord.java index 528f8e3644..84d4bd6efd 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestInterfaceEndRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestInterfaceEndRecord.java @@ -18,21 +18,23 @@ package org.apache.poi.hssf.record; -import junit.framework.TestCase; -import org.apache.poi.util.HexRead; -import org.apache.poi.util.HexDump; -import java.util.List; +import static org.junit.Assert.assertEquals; + import java.io.ByteArrayInputStream; +import java.util.List; + +import org.apache.poi.util.HexDump; +import org.apache.poi.util.HexRead; +import org.junit.Test; /** * Tests the serialization and deserialization of the EndSubRecord * class works correctly. Test data taken directly from a real * Excel file. - * - * @author Yegor Kozlov */ -public final class TestInterfaceEndRecord extends TestCase { +public final class TestInterfaceEndRecord { + @Test public void testCreate() { InterfaceEndRecord record = InterfaceEndRecord.instance; assertEquals(0, record.getDataSize()); @@ -43,6 +45,7 @@ public final class TestInterfaceEndRecord extends TestCase { * Although it violates the spec, Excel silently converts this * data to an {@link InterfaceHdrRecord}. */ + @Test public void testUnexpectedBytes_bug47251(){ String hex = "" + "09 08 10 00 00 06 05 00 EC 15 CD 07 C1 C0 00 00 06 03 00 00 " + //BOF diff --git a/src/testcases/org/apache/poi/hssf/record/TestLabelRecord.java b/src/testcases/org/apache/poi/hssf/record/TestLabelRecord.java index 10f363652e..f244a71b26 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestLabelRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestLabelRecord.java @@ -17,25 +17,21 @@ package org.apache.poi.hssf.record; +import java.io.IOException; + import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.junit.Test; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; /** * Tests for LabelRecord - * - * @author Josh Micich */ -public final class TestLabelRecord extends TestCase { +public final class TestLabelRecord { - public void testEmptyString() { - HSSFWorkbook wb; - try { - wb = HSSFTestDataSamples.openSampleWorkbook("ex42570-20305.xls"); - } catch (NullPointerException e) { - throw new AssertionFailedError("Identified bug 42570"); + @Test + public void testEmptyString() throws IOException { + try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex42570-20305.xls")) { + HSSFTestDataSamples.writeOutAndReadBack(wb); } - HSSFTestDataSamples.writeOutAndReadBack(wb); } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestLbsDataSubRecord.java b/src/testcases/org/apache/poi/hssf/record/TestLbsDataSubRecord.java index 5d89e627d9..a7afa8feb1 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestLbsDataSubRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestLbsDataSubRecord.java @@ -19,30 +19,31 @@ package org.apache.poi.hssf.record; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; -import junit.framework.TestCase; - import org.apache.poi.ss.formula.ptg.AreaPtg; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.util.HexRead; import org.apache.poi.util.LittleEndianInputStream; import org.apache.poi.util.LittleEndianOutputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the LbsDataSubRecord class works correctly. - * - * @author Yegor Kozlov */ -public final class TestLbsDataSubRecord extends TestCase { +public final class TestLbsDataSubRecord { /** * test read-write round trip * test data was taken from 47701.xls */ + @Test public void test_47701(){ byte[] data = HexRead.readFromString( "15, 00, 12, 00, 12, 00, 02, 00, 11, 20, " + @@ -76,6 +77,7 @@ public final class TestLbsDataSubRecord extends TestCase { /** * test data was taken from the file attached to Bugzilla 45778 */ + @Test public void test_45778(){ byte[] data = HexRead.readFromString( "15, 00, 12, 00, 14, 00, 01, 00, 01, 00, " + @@ -115,6 +117,7 @@ public final class TestLbsDataSubRecord extends TestCase { * Test data produced by OpenOffice 3.1 by opening and saving 47701.xls * There are 5 padding bytes that are removed by POI */ + @Test public void test_remove_padding(){ byte[] data = HexRead.readFromString( "5D, 00, 4C, 00, " + @@ -148,6 +151,7 @@ public final class TestLbsDataSubRecord extends TestCase { assertArrayEquals(ser, ser2); } + @Test public void test_LbsDropData() throws IOException{ byte[] data = HexRead.readFromString( //LbsDropData diff --git a/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java b/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java index 4694306d34..b100238c1d 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java @@ -17,27 +17,27 @@ package org.apache.poi.hssf.record; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; + import java.util.ArrayList; import java.util.List; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; import org.apache.poi.hssf.model.RecordStream; import org.apache.poi.hssf.record.aggregates.MergedCellsTable; -import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor; import org.apache.poi.ss.util.CellRangeAddress; +import org.junit.Test; /** * Make sure the merge cells record behaves - * @author Danny Mui (dmui at apache dot org) - * */ -public final class TestMergeCellsRecord extends TestCase { +public final class TestMergeCellsRecord { /** * Make sure when a clone is called, we actually clone it. */ + @Test public void testCloneReferences() { CellRangeAddress[] cras = { new CellRangeAddress(0, 1, 0, 2), }; MergeCellsRecord merge = new MergeCellsRecord(cras, 0, cras.length); @@ -56,12 +56,7 @@ public final class TestMergeCellsRecord extends TestCase { assertNotSame(merge.getAreaAt(0), clone.getAreaAt(0)); } - private static final RecordVisitor dummyRecordVisitor = new RecordVisitor() { - @Override - public void visitRecord(Record r) { - // do nothing - } - }; + @Test public void testMCTable_bug46009() { MergedCellsTable mct = new MergedCellsTable(); List recList = new ArrayList<>(); @@ -71,10 +66,6 @@ public final class TestMergeCellsRecord extends TestCase { recList.add(new MergeCellsRecord(cras, 0, 1)); RecordStream rs = new RecordStream(recList, 0); mct.read(rs); - try { - mct.visitContainedRecords(dummyRecordVisitor); - } catch (ArrayStoreException e) { - throw new AssertionFailedError("Identified bug 46009"); - } + mct.visitContainedRecords(r -> {}); } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestNameCommentRecord.java b/src/testcases/org/apache/poi/hssf/record/TestNameCommentRecord.java index f7a29eb466..b21fe7daf8 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestNameCommentRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestNameCommentRecord.java @@ -17,16 +17,16 @@ package org.apache.poi.hssf.record; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; import org.apache.poi.util.HexRead; +import org.junit.Test; /** * Tests the NameCommentRecord serializes/deserializes correctly - * - * @author Andrew Shirley (aks at corefiling.co.uk) */ -public final class TestNameCommentRecord extends TestCase { +public final class TestNameCommentRecord { + @Test public void testReserialize() { final byte[] data = HexRead .readFromString("" diff --git a/src/testcases/org/apache/poi/hssf/record/TestNameRecord.java b/src/testcases/org/apache/poi/hssf/record/TestNameRecord.java index 34397e3726..bdb6ce3253 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestNameRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestNameRecord.java @@ -17,29 +17,34 @@ package org.apache.poi.hssf.record; -import java.io.IOException; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; -import junit.framework.TestCase; +import java.io.IOException; import org.apache.poi.hssf.usermodel.HSSFName; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.poifs.storage.RawDataUtil; import org.apache.poi.ss.formula.ptg.Area3DPtg; import org.apache.poi.ss.formula.ptg.ArrayPtg; import org.apache.poi.ss.formula.ptg.NamePtg; import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.formula.ptg.Ref3DPtg; import org.apache.poi.util.HexRead; +import org.junit.Test; /** * Tests the NameRecord serializes/deserializes correctly - * - * @author Danny Mui (dmui at apache dot org) */ -public final class TestNameRecord extends TestCase { +public final class TestNameRecord { /** * Makes sure that additional name information is parsed properly such as menu/description */ + @Test public void testFillExtras() { byte[] examples = HexRead.readFromString("" @@ -54,6 +59,7 @@ public final class TestNameRecord extends TestCase { assertTrue(description.endsWith("Macro recorded 27-Sep-93 by ALLWOR")); } + @Test public void testReserialize() { byte[] data = HexRead .readFromString("" @@ -65,20 +71,20 @@ public final class TestNameRecord extends TestCase { TestcaseRecordInputStream.confirmRecordEncoding(NameRecord.sid, data, data2); } + @Test public void testFormulaRelAbs_bug46174() throws IOException { // perhaps this testcase belongs on TestHSSFName - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFName name = wb.createName(); - wb.createSheet("Sheet1"); - name.setNameName("test"); - name.setRefersToFormula("Sheet1!$B$3"); - if ("Sheet1!B3".equals(name.getRefersToFormula())) { - fail("Identified bug 46174"); + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFName name = wb.createName(); + wb.createSheet("Sheet1"); + name.setNameName("test"); + name.setRefersToFormula("Sheet1!$B$3"); + assertNotEquals("Sheet1!B3", name.getRefersToFormula()); + assertEquals("Sheet1!$B$3", name.getRefersToFormula()); } - assertEquals("Sheet1!$B$3", name.getRefersToFormula()); - wb.close(); } + @Test public void testFormulaGeneral() throws IOException { // perhaps this testcase belongs on TestHSSFName HSSFWorkbook wb = new HSSFWorkbook(); @@ -89,590 +95,27 @@ public final class TestNameRecord extends TestCase { assertEquals("Sheet1!A1+Sheet1!A2", name.getRefersToFormula()); name.setRefersToFormula("5*6"); assertEquals("5*6", name.getRefersToFormula()); - + wb.close(); } /** * A NameRecord followed by a ContinueRecord. See Bugzilla 50244 */ - public void test50244(){ - String record_0x0018 = - " 18 00 " + - "21 1E 00 00 00 11 08 00 00 00 03 00 00 00 00 00 " + - "00 77 44 61 74 61 47 72 75 70 70 65 53 65 72 69 " + - "65 2E 60 00 B7 02 0C 00 57 03 00 B7 02 02 09 00 " + - "00 31 2E 54 32 30 2E 30 30 31 02 09 00 00 31 2E " + - "54 32 30 2E 30 30 31 02 09 00 00 31 2E 54 32 30 " + - "2E 30 30 31 02 09 00 00 31 2E 54 32 30 2E 30 30 " + - "32 02 09 00 00 31 2E 54 32 30 2E 30 30 32 02 09 " + - "00 00 31 2E 54 32 30 2E 30 30 32 02 09 00 00 31 " + - "2E 54 32 30 2E 30 30 33 02 09 00 00 31 2E 54 32 " + - "30 2E 30 30 33 02 09 00 00 31 2E 54 32 30 2E 30 " + - "30 33 02 09 00 00 31 2E 54 32 30 2E 30 31 33 02 " + - "09 00 00 31 2E 54 32 30 2E 30 31 33 02 09 00 00 " + - "31 2E 54 32 30 2E 30 31 33 02 09 00 00 31 2E 54 " + - "32 30 2E 30 31 34 02 09 00 00 31 2E 54 32 30 2E " + - "30 31 34 02 09 00 00 31 2E 54 32 30 2E 30 31 34 " + - "02 09 00 00 31 2E 54 32 30 2E 30 31 35 02 09 00 " + - "00 31 2E 54 32 30 2E 30 31 35 02 09 00 00 31 2E " + - "54 32 30 2E 30 31 35 02 09 00 00 31 2E 54 32 30 " + - "2E 30 32 35 02 09 00 00 31 2E 54 32 30 2E 30 32 " + - "35 02 09 00 00 31 2E 54 32 30 2E 30 32 35 02 09 " + - "00 00 31 2E 54 32 30 2E 30 32 36 02 09 00 00 31 " + - "2E 54 32 30 2E 30 32 36 02 09 00 00 31 2E 54 32 " + - "30 2E 30 32 36 02 09 00 00 31 2E 54 32 30 2E 30 " + - "32 37 02 09 00 00 31 2E 54 32 30 2E 30 32 37 02 " + - "09 00 00 31 2E 54 32 30 2E 30 32 37 02 09 00 00 " + - "31 2E 54 32 30 2E 30 33 37 02 09 00 00 31 2E 54 " + - "32 30 2E 30 33 37 02 09 00 00 31 2E 54 32 30 2E " + - "30 33 37 02 09 00 00 31 2E 54 32 30 2E 30 33 38 " + - "02 09 00 00 31 2E 54 32 30 2E 30 33 38 02 09 00 " + - "00 31 2E 54 32 30 2E 30 33 38 02 09 00 00 31 2E " + - "54 32 30 2E 30 33 39 02 09 00 00 31 2E 54 32 30 " + - "2E 30 33 39 02 09 00 00 31 2E 54 32 30 2E 30 33 " + - "39 02 09 00 00 31 2E 54 32 30 2E 30 34 39 02 09 " + - "00 00 31 2E 54 32 30 2E 30 34 39 02 09 00 00 31 " + - "2E 54 32 30 2E 30 34 39 02 09 00 00 31 2E 54 32 " + - "30 2E 30 35 30 02 09 00 00 31 2E 54 32 30 2E 30 " + - "35 30 02 09 00 00 31 2E 54 32 30 2E 30 35 30 02 " + - "09 00 00 31 2E 54 32 30 2E 30 35 31 02 09 00 00 " + - "31 2E 54 32 30 2E 30 35 31 02 09 00 00 31 2E 54 " + - "32 30 2E 30 35 31 02 09 00 00 31 2E 54 32 30 2E " + - "30 36 31 02 09 00 00 31 2E 54 32 30 2E 30 36 31 " + - "02 09 00 00 31 2E 54 32 30 2E 30 36 31 02 09 00 " + - "00 31 2E 54 32 30 2E 30 36 32 02 09 00 00 31 2E " + - "54 32 30 2E 30 36 32 02 09 00 00 31 2E 54 32 30 " + - "2E 30 36 32 02 09 00 00 31 2E 54 32 30 2E 30 36 " + - "33 02 09 00 00 31 2E 54 32 30 2E 30 36 33 02 09 " + - "00 00 31 2E 54 32 30 2E 30 36 33 02 09 00 00 31 " + - "2E 54 32 30 2E 30 37 33 02 09 00 00 31 2E 54 32 " + - "30 2E 30 37 33 02 09 00 00 31 2E 54 32 30 2E 30 " + - "37 33 02 09 00 00 31 2E 54 32 30 2E 30 37 34 02 " + - "09 00 00 31 2E 54 32 30 2E 30 37 34 02 09 00 00 " + - "31 2E 54 32 30 2E 30 37 34 02 09 00 00 31 2E 54 " + - "32 30 2E 30 37 35 02 09 00 00 31 2E 54 32 30 2E " + - "30 37 35 02 09 00 00 31 2E 54 32 30 2E 30 37 35 " + - "02 09 00 00 31 2E 54 32 30 2E 30 38 35 02 09 00 " + - "00 31 2E 54 32 30 2E 30 38 35 02 09 00 00 31 2E " + - "54 32 30 2E 30 38 35 02 09 00 00 31 2E 54 32 30 " + - "2E 30 38 36 02 09 00 00 31 2E 54 32 30 2E 30 38 " + - "36 02 09 00 00 31 2E 54 32 30 2E 30 38 36 02 09 " + - "00 00 31 2E 54 32 30 2E 30 38 37 02 09 00 00 31 " + - "2E 54 32 30 2E 30 38 37 02 09 00 00 31 2E 54 32 " + - "30 2E 30 38 37 02 09 00 00 31 2E 54 32 30 2E 30 " + - "39 37 02 09 00 00 31 2E 54 32 30 2E 30 39 37 02 " + - "09 00 00 31 2E 54 32 30 2E 30 39 37 02 09 00 00 " + - "31 2E 54 32 30 2E 30 39 38 02 09 00 00 31 2E 54 " + - "32 30 2E 30 39 38 02 09 00 00 31 2E 54 32 30 2E " + - "30 39 38 02 09 00 00 31 2E 54 32 30 2E 30 39 39 " + - "02 09 00 00 31 2E 54 32 30 2E 30 39 39 02 09 00 " + - "00 31 2E 54 32 30 2E 30 39 39 02 09 00 00 31 2E " + - "54 32 30 2E 31 30 39 02 09 00 00 31 2E 54 32 30 " + - "2E 31 30 39 02 09 00 00 31 2E 54 32 30 2E 31 30 " + - "39 02 09 00 00 31 2E 54 32 30 2E 31 31 30 02 09 " + - "00 00 31 2E 54 32 30 2E 31 31 30 02 09 00 00 31 " + - "2E 54 32 30 2E 31 31 30 02 09 00 00 31 2E 54 32 " + - "30 2E 31 31 31 02 09 00 00 31 2E 54 32 30 2E 31 " + - "31 31 02 09 00 00 31 2E 54 32 30 2E 31 31 31 02 " + - "09 00 00 31 2E 54 32 30 2E 31 32 31 02 09 00 00 " + - "31 2E 54 32 30 2E 31 32 31 02 09 00 00 31 2E 54 " + - "32 30 2E 31 32 31 02 09 00 00 31 2E 54 32 30 2E " + - "31 32 32 02 09 00 00 31 2E 54 32 30 2E 31 32 32 " + - "02 09 00 00 31 2E 54 32 30 2E 31 32 32 02 09 00 " + - "00 31 2E 54 32 30 2E 31 32 33 02 09 00 00 31 2E " + - "54 32 30 2E 31 32 33 02 09 00 00 31 2E 54 32 30 " + - "2E 31 32 33 02 09 00 00 31 2E 54 32 30 2E 31 33 " + - "33 02 09 00 00 31 2E 54 32 30 2E 31 33 33 02 09 " + - "00 00 31 2E 54 32 30 2E 31 33 33 02 09 00 00 31 " + - "2E 54 32 30 2E 31 33 34 02 09 00 00 31 2E 54 32 " + - "30 2E 31 33 34 02 09 00 00 31 2E 54 32 30 2E 31 " + - "33 34 02 09 00 00 31 2E 54 32 30 2E 31 33 35 02 " + - "09 00 00 31 2E 54 32 30 2E 31 33 35 02 09 00 00 " + - "31 2E 54 32 30 2E 31 33 35 02 09 00 00 31 2E 54 " + - "32 30 2E 31 34 35 02 09 00 00 31 2E 54 32 30 2E " + - "31 34 35 02 09 00 00 31 2E 54 32 30 2E 31 34 35 " + - "02 09 00 00 31 2E 54 32 30 2E 31 34 36 02 09 00 " + - "00 31 2E 54 32 30 2E 31 34 36 02 09 00 00 31 2E " + - "54 32 30 2E 31 34 36 02 09 00 00 31 2E 54 32 30 " + - "2E 31 34 37 02 09 00 00 31 2E 54 32 30 2E 31 34 " + - "37 02 09 00 00 31 2E 54 32 30 2E 31 34 37 02 09 " + - "00 00 31 2E 54 32 30 2E 31 35 37 02 09 00 00 31 " + - "2E 54 32 30 2E 31 35 37 02 09 00 00 31 2E 54 32 " + - "30 2E 31 35 37 02 09 00 00 31 2E 54 32 30 2E 31 " + - "35 38 02 09 00 00 31 2E 54 32 30 2E 31 35 38 02 " + - "09 00 00 31 2E 54 32 30 2E 31 35 38 02 09 00 00 " + - "31 2E 54 32 30 2E 31 35 39 02 09 00 00 31 2E 54 " + - "32 30 2E 31 35 39 02 09 00 00 31 2E 54 32 30 2E " + - "31 35 39 02 09 00 00 31 2E 54 32 30 2E 31 36 39 " + - "02 09 00 00 31 2E 54 32 30 2E 31 36 39 02 09 00 " + - "00 31 2E 54 32 30 2E 31 36 39 02 09 00 00 31 2E " + - "54 32 30 2E 31 37 30 02 09 00 00 31 2E 54 32 30 " + - "2E 31 37 30 02 09 00 00 31 2E 54 32 30 2E 31 37 " + - "30 02 09 00 00 31 2E 54 32 30 2E 31 37 31 02 09 " + - "00 00 31 2E 54 32 30 2E 31 37 31 02 09 00 00 31 " + - "2E 54 32 30 2E 31 37 31 02 09 00 00 31 2E 54 36 " + - "30 2E 30 30 39 02 09 00 00 31 2E 54 36 30 2E 30 " + - "30 39 02 09 00 00 31 2E 54 36 30 2E 30 30 39 02 " + - "09 00 00 31 2E 54 36 30 2E 30 31 30 02 09 00 00 " + - "31 2E 54 36 30 2E 30 31 30 02 09 00 00 31 2E 54 " + - "36 30 2E 30 31 30 02 09 00 00 31 2E 54 36 30 2E " + - "30 31 31 02 09 00 00 31 2E 54 36 30 2E 30 31 31 " + - "02 09 00 00 31 2E 54 36 30 2E 30 31 31 02 09 00 " + - "00 31 2E 54 36 30 2E 30 32 31 02 09 00 00 31 2E " + - "54 36 30 2E 30 32 31 02 09 00 00 31 2E 54 36 30 " + - "2E 30 32 31 02 09 00 00 31 2E 54 36 30 2E 30 32 " + - "32 02 09 00 00 31 2E 54 36 30 2E 30 32 32 02 09 " + - "00 00 31 2E 54 36 30 2E 30 32 32 02 09 00 00 31 " + - "2E 54 36 30 2E 30 32 33 02 09 00 00 31 2E 54 36 " + - "30 2E 30 32 33 02 09 00 00 31 2E 54 36 30 2E 30 " + - "32 33 02 09 00 00 31 2E 54 36 30 2E 30 33 33 02 " + - "09 00 00 31 2E 54 36 30 2E 30 33 33 02 09 00 00 " + - "31 2E 54 36 30 2E 30 33 33 02 09 00 00 31 2E 54 " + - "36 30 2E 30 33 34 02 09 00 00 31 2E 54 36 30 2E " + - "30 33 34 02 09 00 00 31 2E 54 36 30 2E 30 33 34 " + - "02 09 00 00 31 2E 54 36 30 2E 30 33 35 02 09 00 " + - "00 31 2E 54 36 30 2E 30 33 35 02 09 00 00 31 2E " + - "54 36 30 2E 30 33 35 02 09 00 00 31 2E 54 36 30 " + - "2E 30 34 35 02 09 00 00 31 2E 54 36 30 2E 30 34 " + - "35 02 09 00 00 31 2E 54 36 30 2E 30 34 35 02 09 " + - "00 00 31 2E 54 36 30 2E 30 34 36 02 09 00 00 31 " + - "2E 54 36 30 2E 30 34 36 02 09 00 00 31 2E 54 36 " + - "30 2E 30 34 36 02 09 00 00 31 2E 54 36 30 2E 30 " + - "34 37 02 09 00 00 31 2E 54 36 30 2E 30 34 37 02 " + - "09 00 00 31 2E 54 36 30 2E 30 34 37 02 09 00 00 " + - "31 2E 54 36 30 2E 30 35 37 02 09 00 00 31 2E 54 " + - "36 30 2E 30 35 37 02 09 00 00 31 2E 54 36 30 2E " + - "30 35 37 02 09 00 00 31 2E 54 36 30 2E 30 35 38 " + - "02 09 00 00 31 2E 54 36 30 2E 30 35 38 02 09 00 " + - "00 31 2E 54 36 30 2E 30 35 38 02 09 00 00 31 2E " + - "54 36 30 2E 30 35 39 02 09 00 00 31 2E 54 36 30 " + - "2E 30 35 39 02 09 00 00 31 2E 54 36 30 2E 30 35 " + - "39 02 09 00 00 31 2E 54 36 30 2E 30 36 30 02 09 " + - "00 00 31 2E 54 36 30 2E 30 36 30 02 09 00 00 31 " + - "2E 54 36 30 2E 30 36 30 02 09 00 00 31 2E 54 36 " + - "30 2E 30 35 30 02 09 00 00 31 2E 54 36 30 2E 30 " + - "35 30 02 09 00 00 31 2E 54 36 30 2E 30 35 30 02 " + - "09 00 00 31 2E 54 36 30 2E 30 34 39 02 09 00 00 " + - "31 2E 54 36 30 2E 30 34 39 02 09 00 00 31 2E 54 " + - "36 30 2E 30 34 39 02 09 00 00 31 2E 54 36 30 2E " + - "30 34 38 02 09 00 00 31 2E 54 36 30 2E 30 34 38 " + - "02 09 00 00 31 2E 54 36 30 2E 30 34 38 02 09 00 " + - "00 31 2E 54 36 30 2E 30 33 38 02 09 00 00 31 2E " + - "54 36 30 2E 30 33 38 02 09 00 00 31 2E 54 36 30 " + - "2E 30 33 38 02 09 00 00 31 2E 54 36 30 2E 30 33 " + - "37 02 09 00 00 31 2E 54 36 30 2E 30 33 37 02 09 " + - "00 00 31 2E 54 36 30 2E 30 33 37 02 09 00 00 31 " + - "2E 54 36 30 2E 30 33 36 02 09 00 00 31 2E 54 36 " + - "30 2E 30 33 36 02 09 00 00 31 2E 54 36 30 2E 30 " + - "33 36 02 09 00 00 31 2E 54 36 30 2E 30 32 36 02 " + - "09 00 00 31 2E 54 36 30 2E 30 32 36 02 09 00 00 " + - "31 2E 54 36 30 2E 30 32 36 02 09 00 00 31 2E 54 " + - "36 30 2E 30 32 35 02 09 00 00 31 2E 54 36 30 2E " + - "30 32 35 02 09 00 00 31 2E 54 36 30 2E 30 32 35 " + - "02 09 00 00 31 2E 54 36 30 2E 30 32 34 02 09 00 " + - "00 31 2E 54 36 30 2E 30 32 34 02 09 00 00 31 2E " + - "54 36 30 2E 30 32 34 02 09 00 00 31 2E 54 36 30 " + - "2E 30 31 34 02 09 00 00 31 2E 54 36 30 2E 30 31 " + - "34 02 09 00 00 31 2E 54 36 30 2E 30 31 34 02 09 " + - "00 00 31 2E 54 36 30 2E 30 31 33 02 09 00 00 31 " + - "2E 54 36 30 2E 30 31 33 02 09 00 00 31 2E 54 36 " + - "30 2E 30 31 33 02 09 00 00 31 2E 54 36 30 2E 30 " + - "31 32 02 09 00 00 31 2E 54 36 30 2E 30 31 32 02 " + - "09 00 00 31 2E 54 36 30 2E 30 31 32 02 09 00 00 " + - "31 2E 54 36 30 2E 30 30 32 02 09 00 00 31 2E 54 " + - "36 30 2E 30 30 32 02 09 00 00 31 2E 54 36 30 2E " + - "30 30 32 02 09 00 00 31 2E 54 36 30 2E 30 30 31 " + - "02 09 00 00 31 2E 54 36 30 2E 30 30 31 02 09 00 " + - "00 31 2E 54 36 30 2E 30 30 31 02 09 00 00 31 2E " + - "54 32 30 2E 31 37 32 02 09 00 00 31 2E 54 32 30 " + - "2E 31 37 32 02 09 00 00 31 2E 54 32 30 2E 31 37 " + - "32 02 09 00 00 31 2E 54 32 30 2E 31 36 32 02 09 " + - "00 00 31 2E 54 32 30 2E 31 36 32 02 09 00 00 31 " + - "2E 54 32 30 2E 31 36 32 02 09 00 00 31 2E 54 32 " + - "30 2E 31 36 31 02 09 00 00 31 2E 54 32 30 2E 31 " + - "36 31 02 09 00 00 31 2E 54 32 30 2E 31 36 31 02 " + - "09 00 00 31 2E 54 32 30 2E 31 36 30 02 09 00 00 " + - "31 2E 54 32 30 2E 31 36 30 02 09 00 00 31 2E 54 " + - "32 30 2E 31 36 30 02 09 00 00 31 2E 54 32 30 2E " + - "31 35 30 02 09 00 00 31 2E 54 32 30 2E 31 35 30 " + - "02 09 00 00 31 2E 54 32 30 2E 31 35 30 02 09 00 " + - "00 31 2E 54 32 30 2E 31 34 39 02 09 00 00 31 2E " + - "54 32 30 2E 31 34 39 02 09 00 00 31 2E 54 32 30 " + - "2E 31 34 39 02 09 00 00 31 2E 54 32 30 2E 31 34 " + - "38 02 09 00 00 31 2E 54 32 30 2E 31 34 38 02 09 " + - "00 00 31 2E 54 32 30 2E 31 34 38 02 09 00 00 31 " + - "2E 54 32 30 2E 31 33 38 02 09 00 00 31 2E 54 32 " + - "30 2E 31 33 38 02 09 00 00 31 2E 54 32 30 2E 31 " + - "33 38 02 09 00 00 31 2E 54 32 30 2E 31 33 37 02 " + - "09 00 00 31 2E 54 32 30 2E 31 33 37 02 09 00 00 " + - "31 2E 54 32 30 2E 31 33 37 02 09 00 00 31 2E 54 " + - "32 30 2E 31 33 36 02 09 00 00 31 2E 54 32 30 2E " + - "31 33 36 02 09 00 00 31 2E 54 32 30 2E 31 33 36 " + - "02 09 00 00 31 2E 54 32 30 2E 31 32 36 02 09 00 " + - "00 31 2E 54 32 30 2E 31 32 36 02 09 00 00 31 2E " + - "54 32 30 2E 31 32 36 02 09 00 00 31 2E 54 32 30 " + - "2E 31 32 35 02 09 00 00 31 2E 54 32 30 2E 31 32 " + - "35 02 09 00 00 31 2E 54 32 30 2E 31 32 35 02 09 " + - "00 00 31 2E 54 32 30 2E 31 32 34 02 09 00 00 31 " + - "2E 54 32 30 2E 31 32 34 02 09 00 00 31 2E 54 32 " + - "30 2E 31 32 34 02 09 00 00 31 2E 54 32 30 2E 31 " + - "31 34 02 09 00 00 31 2E 54 32 30 2E 31 31 34 02 " + - "09 00 00 31 2E 54 32 30 2E 31 31 34 02 09 00 00 " + - "31 2E 54 32 30 2E 31 31 33 02 09 00 00 31 2E 54 " + - "32 30 2E 31 31 33 02 09 00 00 31 2E 54 32 30 2E " + - "31 31 33 02 09 00 00 31 2E 54 32 30 2E 31 31 32 " + - "02 09 00 00 31 2E 54 32 30 2E 31 31 32 02 09 00 " + - "00 31 2E 54 32 30 2E 31 31 32 02 09 00 00 31 2E " + - "54 32 30 2E 31 30 32 02 09 00 00 31 2E 54 32 30 " + - "2E 31 30 32 02 09 00 00 31 2E 54 32 30 2E 31 30 " + - "32 02 09 00 00 31 2E 54 32 30 2E 31 30 31 02 09 " + - "00 00 31 2E 54 32 30 2E 31 30 31 02 09 00 00 31 " + - "2E 54 32 30 2E 31 30 31 02 09 00 00 31 2E 54 32 " + - "30 2E 31 30 30 02 09 00 00 31 2E 54 32 30 2E 31 " + - "30 30 02 09 00 00 31 2E 54 32 30 2E 31 30 30 02 " + - "09 00 00 31 2E 54 32 30 2E 30 39 30 02 09 00 00 " + - "31 2E 54 32 30 2E 30 39 30 02 09 00 00 31 2E 54 " + - "32 30 2E 30 39 30 02 09 00 00 31 2E 54 32 30 2E " + - "30 38 39 02 09 00 00 31 2E 54 32 30 2E 30 38 39 " + - "02 09 00 00 31 2E 54 32 30 2E 30 38 39 02 09 00 " + - "00 31 2E 54 32 30 2E 30 38 38 02 09 00 00 31 2E " + - "54 32 30 2E 30 38 38 02 09 00 00 31 2E 54 32 30 " + - "2E 30 38 38 02 09 00 00 31 2E 54 32 30 2E 30 37 " + - "38 02 09 00 00 31 2E 54 32 30 2E 30 37 38 02 09 " + - "00 00 31 2E 54 32 30 2E 30 37 38 02 09 00 00 31 " + - "2E 54 32 30 2E 30 37 37 02 09 00 00 31 2E 54 32 " + - "30 2E 30 37 37 02 09 00 00 31 2E 54 32 30 2E 30 " + - "37 37 02 09 00 00 31 2E 54 32 30 2E 30 37 36 02 " + - "09 00 00 31 2E 54 32 30 2E 30 37 36 02 09 00 00 " + - "31 2E 54 32 30 2E 30 37 36 02 09 00 00 31 2E 54 " + - "32 30 2E 30 36 36 02 09 00 00 31 2E 54 32 30 2E " + - "30 36 36 02 09 00 00 31 2E 54 32 30 2E 30 36 36 " + - "02 09 00 00 31 2E 54 32 30 2E 30 36 35 02 09 00 " + - "00 31 2E 54 32 30 2E 30 36 35 02 09 00 00 31 2E " + - "54 32 30 2E 30 36 35 02 09 00 00 31 2E 54 32 30 " + - "2E 30 36 34 02 09 00 00 31 2E 54 32 30 2E 30 36 " + - "34 02 09 00 00 31 2E 54 32 30 2E 30 36 34 02 09 " + - "00 00 31 2E 54 32 30 2E 30 35 34 02 09 00 00 31 " + - "2E 54 32 30 2E 30 35 34 02 09 00 00 31 2E 54 32 " + - "30 2E 30 35 34 02 09 00 00 31 2E 54 32 30 2E 30 " + - "35 33 02 09 00 00 31 2E 54 32 30 2E 30 35 33 02 " + - "09 00 00 31 2E 54 32 30 2E 30 35 33 02 09 00 00 " + - "31 2E 54 32 30 2E 30 35 32 02 09 00 00 31 2E 54 " + - "32 30 2E 30 35 32 02 09 00 00 31 2E 54 32 30 2E " + - "30 35 32 02 09 00 00 31 2E 54 32 30 2E 30 34 32 " + - "02 09 00 00 31 2E 54 32 30 2E 30 34 32 02 09 00 " + - "00 31 2E 54 32 30 2E 30 34 32 02 09 00 00 31 2E " + - "54 32 30 2E 30 34 31 02 09 00 00 31 2E 54 32 30 " + - "2E 30 34 31 02 09 00 00 31 2E 54 32 30 2E 30 34 " + - "31 02 09 00 00 31 2E 54 32 30 2E 30 34 30 02 09 " + - "00 00 31 2E 54 32 30 2E 30 34 30 02 09 00 00 31 " + - "2E 54 32 30 2E 30 34 30 02 09 00 00 31 2E 54 32 " + - "30 2E 30 33 30 02 09 00 00 31 2E 54 32 30 2E 30 " + - "33 30 02 09 00 00 31 2E 54 32 30 2E 30 33 30 02 " + - "09 00 00 31 2E 54 32 30 2E 30 32 39 02 09 00 00 " + - "31 2E 54 32 30 2E 30 32 39 02 09 00 00 31 2E 54 " + - "32 30 2E 30 32 39 02 09 00 00 31 2E 54 32 30 2E " + - "30 32 38 02 09 00 00 31 2E 54 32 30 2E 30 32 38 " + - "02 09 00 00 31 2E 54 32 30 2E 30 32 38 02 09 00 " + - "00 31 2E 54 32 30 2E 30 31 38 02 09 00 00 31 2E " + - "54 32 30 2E 30 31 38 02 09 00 00 31 2E 54 32 30 " + - "2E 30 31 38 02 09 00 00 31 2E 54 32 30 2E 30 31 " + - "37 02 09 00 00 31 2E 54 32 30 2E 30 31 37 02 09 " + - "00 00 31 2E 54 32 30 2E 30 31 37 02 09 00 00 31 " + - "2E 54 32 30 2E 30 31 36 02 09 00 00 31 2E 54 32 " + - "30 2E 30 31 36 02 09 00 00 31 2E 54 32 30 2E 30 " + - "31 36 02 09 00 00 31 2E 54 32 30 2E 30 30 36 02 " + - "09 00 00 31 2E 54 32 30 2E 30 30 36 02 09 00 00 " + - "31 2E 54 32 30 2E 30 30 36 02 09 00 00 31 2E 54 " + - "32 30 2E 30 30 35 02 09 00 00 31 2E 54 32 30 2E " + - "30 30 35 02 09 00 00 31 2E 54 32 30 2E 30 30 35 " + - "02 09 00 00 31 2E 54 32 30 2E 30 30 34 02 09 00 " + - "00 31 2E 54 32 30 2E 30 30 34 02 09 00 00 31 2E " + - "54 32 30 2E 30 30 34 02 09 00 00 31 2E 54 32 30 " + - "2E 30 30 37 02 09 00 00 31 2E 54 32 30 2E 30 30 " + - "37 02 09 00 00 31 2E 54 32 30 2E 30 30 37 02 09 " + - "00 00 31 2E 54 32 30 2E 30 30 38 02 09 00 00 31 " + - "2E 54 32 30 2E 30 30 38 02 09 00 00 31 2E 54 32 " + - "30 2E 30 30 38 02 09 00 00 31 2E 54 32 30 2E 30 " + - "30 39 02 09 00 00 31 2E 54 32 30 2E 30 30 39 02 " + - "09 00 00 31 2E 54 32 30 2E 30 30 39 02 09 00 00 " + - "31 2E 54 32 30 2E 30 31 39 02 09 00 00 31 2E 54 " + - "32 30 2E 30 31 39 02 09 00 00 31 2E 54 32 30 2E " + - "30 31 39 02 09 00 00 31 2E 54 32 30 2E 30 32 30 " + - "02 09 00 00 31 2E 54 32 30 2E 30 32 30 02 09 00 " + - "00 31 2E 54 32 30 2E 30 32 30 02 09 00 00 31 2E " + - "54 32 30 2E 30 32 31 02 09 00 00 31 2E 54 32 30 " + - "2E 30 32 31 02 09 00 00 31 2E 54 32 30 2E 30 32 " + - "31 02 09 00 00 31 2E 54 32 30 2E 30 33 31 02 09 " + - "00 00 31 2E 54 32 30 2E 30 33 31 02 09 00 00 31 " + - "2E 54 32 30 2E 30 33 31 02 09 00 00 31 2E 54 32 " + - "30 2E 30 33 32 02 09 00 00 31 2E 54 32 30 2E 30 " + - "33 32 02 09 00 00 31 2E 54 32 30 2E 30 33 32 02 " + - "09 00 00 31 2E 54 32 30 2E 30 33 33 02 09 00 00 " + - "31 2E 54 32 30 2E 30 33 33 02 09 00 00 31 2E 54 " + - "32 30 2E 30 33 33 02 09 00 00 31 2E 54 32 30 2E " + - "30 34 33 02 09 00 00 31 2E 54 32 30 2E 30 34 33 " + - "02 09 00 00 31 2E 54 32 30 2E 30 34 33 02 09 00 " + - "00 31 2E 54 32 30 2E 30 34 34 02 09 00 00 31 2E " + - "54 32 30 2E 30 34 34 02 09 00 00 31 2E 54 32 30 " + - "2E 30 34 34 02 09 00 00 31 2E 54 32 30 2E 30 34 " + - "35 02 09 00 00 31 2E 54 32 30 2E 30 34 35 02 09 " + - "00 00 31 2E 54 32 30 2E 30 34 35 02 09 00 00 31 " + - "2E 54 32 30 2E 30 35 35 02 09 00 00 31 2E 54 32 " + - "30 2E 30 35 35 02 09 00 00 31 2E 54 32 30 2E 30 " + - "35 35 02 09 00 00 31 2E 54 32 30 2E 30 35 36 02 " + - "09 00 00 31 2E 54 32 30 2E 30 35 36 02 09 00 00 " + - "31 2E 54 32 30 2E 30 35 36 02 09 00 00 31 2E 54 " + - "32 30 2E 30 35 37 02 09 00 00 31 2E 54 32 30 2E " + - "30 35 37 02 09 00 00 31 2E 54 32 30 2E 30 35 37 " + - "02 09 00 00 31 2E 54 32 30 2E 30 36 37 02 09 00 " + - "00 31 2E 54 32 30 2E 30 36 37 02 09 00 00 31 2E " + - "54 32 30 2E 30 36 37 02 09 00 00 31 2E 54 32 30 " + - "2E 30 36 38 02 09 00 00 31 2E 54 32 30 2E 30 36 " + - "38 02 09 00 00 31 2E 54 32 30 2E 30 36 38 02 09 " + - "00 00 31 2E 54 32 30 2E 30 36 39 02 09 00 00 31 " + - "2E 54 32 30 2E 30 36 39 02 09 00 00 31 2E 54 32 " + - "30 2E 30 36 39 02 09 00 00 31 2E 54 32 30 2E 30 " + - "37 39 02 09 00 00 31 2E 54 32 30 2E 30 37 39 02 " + - "09 00 00 31 2E 54 32 30 2E 30 37 39 02 09 00 00 " + - "31 2E 54 32 30 2E 30 38 30 02 09 00 00 31 2E 54 " + - "32 30 2E 30 38 30 02 09 00 00 31 2E 54 32 30 2E " + - "30 38 30 02 09 00 00 31 2E 54 32 30 2E 30 38 31 " + - "02 09 00 00 31 2E 54 32 30 2E 30 38 31 02 09 00 " + - "00 31 2E 54 32 30 2E 30 38 31 02 09 00 00 31 2E " + - "54 32 30 2E 30 39 31 02 09 00 00 31 2E 54 32 30 " + - "2E 30 39 31 02 09 00 00 31 2E 54 32 30 2E 30 39 " + - "31 02 09 00 00 31 2E 54 32 30 2E 30 39 32 02 09 " + - "00 00 31 2E 54 32 30 2E 30 39 32 02 09 00 00 31 " + - "2E 54 32 30 2E 30 39 32 02 09 00 00 31 2E 54 32 " + - "30 2E 30 39 33 02 09 00 00 31 2E 54 32 30 2E 30 " + - "39 33 02 09 00 00 31 2E 54 32 30 2E 30 39 33 02 " + - "09 00 00 31 2E 54 32 30 2E 31 30 33 02 09 00 00 " + - "31 2E 54 32 30 2E 31 30 33 02 09 00 00 31 2E 54 " + - "32 30 2E 31 30 33 02 09 00 00 31 2E 54 32 30 2E " + - "31 30 34 02 09 00 00 31 2E 54 32 30 2E 31 30 34 " + - "02 09 00 00 31 2E 54 32 30 2E 31 30 34 02 09 00 " + - "00 31 2E 54 32 30 2E 31 30 35 02 09 00 00 31 2E " + - "54 32 30 2E 31 30 35 02 09 00 00 31 2E 54 32 30 " + - "2E 31 30 35 02 09 00 00 31 2E 54 32 30 2E 31 31 " + - "35 02 09 00 00 31 2E 54 32 30 2E 31 31 35 02 09 " + - "00 00 31 2E 54 32 30 2E 31 31 35 02 09 00 00 31 " + - "2E 54 32 30 2E 31 31 36 02 09 00 00 31 2E 54 32 " + - "30 2E 31 31 36 02 09 00 00 31 2E 54 32 30 2E 31 " + - "31 36 02 09 00 00 31 2E 54 32 30 2E 31 31 37 02 " + - "09 00 00 31 2E 54 32 30 2E 31 31 37 02 09 00 00 " + - "31 2E 54 32 30 2E 31 31 37 02 09 00 00 31 2E 54 " + - "32 30 2E 31 32 37 02 09 00 00 31 2E 54 32 30 2E " + - "31 32 37 02 09 00 00 31 2E 54 32 30 2E 31 32 37 " + - "02 09 00 00 31 2E 54 32 30 2E 31 32 38 02 09 00 " + - "00 31 2E 54 32 30 2E 31 32 38 02 09 00 00 31 2E " + - "54 32 30 2E 31 32 38 02 09 00 00 31 2E 54 32 30 " + - "2E 31 32 39 02 09 00 00 31 2E 54 32 30 2E 31 32 " + - "39 02 09 00 00 31 2E 54 32 30 2E 31 32 39 02 09 " + - "00 00 31 2E 54 32 30 2E 31 33 39 02 09 00 00 31 " + - "2E 54 32 30 2E 31 33 39 02 09 00 00 31 2E 54 32 " + - "30 2E 31 33 39 02 09 00 00 31 2E 54 32 30 2E 31 " + - "34 30 02 09 00 00 31 2E 54 32 30 2E 31 34 30 02 " + - "09 00 00 31 2E 54 32 30 2E 31 34 30 02 09 00 00 " + - "31 2E 54 32 30 2E 31 34 31 02 09 00 00 31 2E 54 " + - "32 30 2E 31 34 31 02 09 00 00 31 2E 54 32 30 2E " + - "31 34 31 02 09 00 00 31 2E 54 32 30 2E 31 35 31 " + - "02 09 00 00 31 2E 54 32 30 2E 31 35 31 02 09 00 " + - "00 31 2E 54 32 30 2E 31 35 31 02 09 00 00 31 2E " + - "54 32 30 2E 31 35 32 02 09 00 00 31 2E 54 32 30 " + - "2E 31 35 32 02 09 00 00 31 2E 54 32 30 2E 31 35 " + - "32 02 09 00 00 31 2E 54 32 30 2E 31 35 33 02 09 " + - "00 00 31 2E 54 32 30 2E 31 35 33 02 09 00 00 31 " + - "2E 54 32 30 2E 31 35 33 02 09 00 00 31 2E 54 32 " + - "30 2E 31 36 33 02 09 00 00 31 2E 54 32 30 2E 31 " + - "36 33 02 09 00 00 31 2E 54 32 30 2E 31 36 33 02 " + - "09 00 00 31 2E 54 32 30 2E 31 36 34 02 09 00 00 " + - "31 2E 54 32 30 2E 31 36 34 02 09 00 00 31 2E 54 " + - "32 30 2E 31 36 34 02 09 00 00 31 2E 54 32 30 2E " + - "31 36 35 02 09 00 00 31 2E 54 32 30 2E 31 36 35 " + - "02 09 00 00 31 2E 54 32 30 2E 31 36 35 02 09 00 " + - "00 31 2E 54 36 30 2E 30 30 33 02 09 00 00 31 2E " + - "54 36 30 2E 30 30 33 02 09 00 00 31 2E 54 36 30 " + - "2E 30 30 33 02 09 00 00 31 2E 54 36 30 2E 30 30 " + - "34 02 09 00 00 31 2E 54 36 30 2E 30 30 34 02 09 " + - "00 00 31 2E 54 36 30 2E 30 30 34 02 09 00 00 31 " + - "2E 54 36 30 2E 30 30 35 02 09 00 00 31 2E 54 36 " + - "30 2E 30 30 35 02 09 00 00 31 2E 54 36 30 2E 30 " + - "30 35 02 09 00 00 31 2E 54 36 30 2E 30 31 35 02 " + - "09 00 00 31 2E 54 36 30 2E 30 31 35 02 09 00 00 " + - "31 2E 54 36 30 2E 30 31 35 02 09 00 00 31 2E 54 " + - "36 30 2E 30 31 36 02 09 00 00 31 2E 54 36 30 2E " + - "30 31 36 02 09 00 00 31 2E 54 36 30 2E 30 31 36 " + - "02 09 00 00 31 2E 54 36 30 2E 30 31 37 02 09 00 " + - "00 31 2E 54 36 30 2E 30 31 37 02 09 00 00 31 2E " + - "54 36 30 2E 30 31 37 02 09 00 00 31 2E 54 36 30 " + - "2E 30 32 37 02 09 00 00 31 2E 54 36 30 2E 30 32 " + - "37 02 09 00 00 31 2E 54 36 30 2E 30 32 37 02 09 " + - "00 00 31 2E 54 36 30 2E 30 32 38 02 09 00 00 31 " + - "2E 54 36 30 2E 30 32 38 02 09 00 00 31 2E 54 36 " + - "30 2E 30 32 38 02 09 00 00 31 2E 54 36 30 2E 30 " + - "32 39 02 09 00 00 31 2E 54 36 30 2E 30 32 39 02 " + - "09 00 00 31 2E 54 36 30 2E 30 32 39 02 09 00 00 " + - "31 2E 54 36 30 2E 30 33 39 02 09 00 00 31 2E 54 " + - "36 30 2E 30 33 39 02 09 00 00 31 2E 54 36 30 2E " + - "30 33 39 02 09 00 00 31 2E 54 36 30 2E 30 34 30 " + - "02 09 00 00 31 2E 54 36 30 2E 30 34 30 02 09 00 " + - "00 31 2E 54 36 30 2E 30 34 30 02 09 00 00 31 2E " + - "54 36 30 2E 30 34 31 02 09 00 00 31 2E 54 36 30 " + - "2E 30 34 31 02 09 00 00 31 2E 54 36 30 2E 30 34 " + - "31 02 09 00 00 31 2E 54 36 30 2E 30 35 31 02 09 " + - "00 00 31 2E 54 36 30 2E 30 35 31 02 09 00 00 31 " + - "2E 54 36 30 2E 30 35 31 02 09 00 00 31 2E 54 36 " + - "30 2E 30 35 32 02 09 00 00 31 2E 54 36 30 2E 30 " + - "35 32 02 09 00 00 31 2E 54 36 30 2E 30 35 32 02 " + - "09 00 00 31 2E 54 36 30 2E 30 35 33 02 09 00 00 " + - "31 2E 54 36 30 2E 30 35 33 02 09 00 00 31 2E 54 " + - "36 30 2E 30 35 33 02 09 00 00 31 2E 54 36 30 2E " + - "30 35 36 02 09 00 00 31 2E 54 36 30 2E 30 35 36 " + - "02 09 00 00 31 2E 54 36 30 2E 30 35 36 02 09 00 " + - "00 31 2E 54 36 30 2E 30 35 35 02 09 00 00 31 2E " + - "54 36 30 2E 30 35 35 02 09 00 00 31 2E 54 36 30 " + - "2E 30 35 35 02 09 00 00 31 2E 54 36 30 2E 30 35 " + - "34 02 09 00 00 31 2E 54 36 30 2E 30 35 34 02 09 " + - "00 00 31 2E 54 36 30 2E 30 35 34 02 09 00 00 31 " + - "2E 54 36 30 2E 30 34 34 02 09 00 00 31 2E 54 36 " + - "30 2E 30 34 34 02 09 00 00 31 2E 54 36 30 2E 30 " + - "34 34 02 09 00 00 31 2E 54 36 30 2E 30 34 33 02 " + - "09 00 00 31 2E 54 36 30 2E 30 34 33 02 09 00 00 " + - "31 2E 54 36 30 2E 30 34 33 02 09 00 00 31 2E 54 " + - "36 30 2E 30 34 32 02 09 00 00 31 2E 54 36 30 2E " + - "30 34 32 02 09 00 00 31 2E 54 36 30 2E 30 34 32 " + - "02 09 00 00 31 2E 54 36 30 2E 30 33 32 02 09 00 " + - "00 31 2E 54 36 30 2E 30 33 32 02 09 00 00 31 2E " + - "54 36 30 2E 30 33 32 02 09 00 00 31 2E 54 36 30 " + - "2E 30 33 31 02 09 00 00 31 2E 54 36 30 2E 30 33 " + - "31 02 09 00 00 31 2E 54 36 30 2E 30 33 31 02 09 " + - "00 00 31 2E 54 36 30 2E 30 33 30 02 09 00 00 31 " + - "2E 54 36 30 2E 30 33 30 02 09 00 00 31 2E 54 36 " + - "30 2E 30 33 30 02 09 00 00 31 2E 54 36 30 2E 30 " + - "32 30 02 09 00 00 31 2E 54 36 30 2E 30 32 30 02 " + - "09 00 00 31 2E 54 36 30 2E 30 32 30 02 09 00 00 " + - "31 2E 54 36 30 2E 30 31 39 02 09 00 00 31 2E 54 " + - "36 30 2E 30 31 39 02 09 00 00 31 2E 54 36 30 2E " + - "30 31 39 02 09 00 00 31 2E 54 36 30 2E 30 31 38 " + - "02 09 00 00 31 2E 54 36 30 2E 30 31 38 02 09 00 " + - "00 31 2E 54 36 30 2E 30 31 38 02 09 00 00 31 2E " + - "54 36 30 2E 30 30 38 02 09 00 00 31 2E 54 36 30 " + - "2E 30 30 38 02 09 00 00 31 2E 54 36 30 2E 30 30 " + - "38 02 09 00 00 31 2E 54 36 30 2E 30 30 37 02 09 " + - "00 00 31 2E 54 36 30 2E 30 30 37 02 09 00 00 31 " + - "2E 54 36 30 2E 30 30 37 02 09 00 00 31 2E 54 36 " + - "30 2E 30 30 36 02 09 00 00 31 2E 54 36 30 2E 30 " + - "30 36 02 09 00 00 31 2E 54 36 30 2E 30 30 36 02 " + - "09 00 00 31 2E 54 32 30 2E 31 36 38 02 09 00 00 " + - "31 2E 54 32 30 2E 31 36 38 02 09 00 00 31 2E 54 " + - "32 30 2E 31 36 38 02 09 00 00 31 2E 54 32 30 2E " + - "31 36 37 02 09 00 00 31 2E 54 32 30 2E 31 36 37 " + - "02 09 00 00 31 2E 54 32 30 2E 31 36 37 02 09 00 " + - "00 31 2E 54 32 30 2E 31 36 36 02 09 00 00 31 2E " + - "54 32 30 2E 31 36 36 02 09 00 00 31 2E 54 32 30 " + - "2E 31 36 36 02 09 00 00 31 2E 54 32 30 2E 31 35 " + - "36 02 09 00 00 31 2E 54 32 30 2E 31 35 36 02 09 " + - "00 00 31 2E 54 32 30 2E 31 35 36 02 09 00 00 31 " + - "2E 54 32 30 2E 31 35 35 02 09 00 00 31 2E 54 32 " + - "30 2E 31 35 35 02 09 00 00 31 2E 54 32 30 2E 31 " + - "35 35 02 09 00 00 31 2E 54 32 30 2E 31 35 34 02 " + - "09 00 00 31 2E 54 32 30 2E 31 35 34 02 09 00 00 " + - "31 2E 54 32 30 2E 31 35 34 02 09 00 00 31 2E 54 " + - "32 30 2E 31 34 34 02 09 00 00 31 2E 54 32 30 2E " + - "31 34 34 "; + @Test + public void test50244() throws IOException { + byte[] data1 = RawDataUtil.decompress( + "H4sIAAAAAAAAAI3Zu2qWQRAA0I8EQcHGzkrwBcLO7B0sBR9AwdYIKdKFoPhovp7xLyQWyX+m2OWw7TIX5u3x/t1xHG9ePhyXxyl+" + + "fbz+cf3p/ufd3c3nm/vbm6tvx++L18fXy4fr4tVxxNWXLFelhCENlRCIZuiERAzDJFTEMmxCM/RiCMJApKESJqIZOmEhhmESNmIZ" + + "tiCKIYohCIlIQyVURDN0QkMMwyR0xDJswjDMYoizGH9Lzib8+6NnEIREpKESKqIZOqEhhmESOmIZNmEUQje0bViEipiGQUhENzRC" + + "IKohCQURZ3FKT0kYiDAUQjc87iCfwyJUxDQMQiK6oRECUQ1JKIgwFEHZhrUNizAR0zAIA9ENjdAR1ZCEhghDIVRDbsMiBGIaBqEg" + + "uqEZpmEZNiEMWQxBqIg0VEJDNEMndMQwTMJALMMmTMMqhiBsRBqqIAqiGTohEMMwCYlYhk2ohlYMQeiINFTCQDRDP4vT/FMNzdAJ" + + "gRiGSUjEMmxCNbRiCEJHpKEahqEbGqEhqiEJFRGGQkhDbMMiFMQ0jLM4padlmIZB6IhuaIT2Pz4c3188+VoNSaiIMBRCGh7PGc9h" + + "EQpiGoagbEQ3NMJCVEMSJiIMhTAMjxdcz2ERGmIaBqEiuqERElENSQhEGMrT+APX2vm3iyMAAA==" + ); - String record_0x03C = - " 3C 00 62 05 02 09 00 00 31 2E 54 32 30 " + - "2E 31 34 34 02 09 00 00 31 2E 54 32 30 2E 31 34 " + - "33 02 09 00 00 31 2E 54 32 30 2E 31 34 33 02 09 " + - "00 00 31 2E 54 32 30 2E 31 34 33 02 09 00 00 31 " + - "2E 54 32 30 2E 31 34 32 02 09 00 00 31 2E 54 32 " + - "30 2E 31 34 32 02 09 00 00 31 2E 54 32 30 2E 31 " + - "34 32 02 09 00 00 31 2E 54 32 30 2E 31 33 32 02 " + - "09 00 00 31 2E 54 32 30 2E 31 33 32 02 09 00 00 " + - "31 2E 54 32 30 2E 31 33 32 02 09 00 00 31 2E 54 " + - "32 30 2E 31 33 31 02 09 00 00 31 2E 54 32 30 2E " + - "31 33 31 02 09 00 00 31 2E 54 32 30 2E 31 33 31 " + - "02 09 00 00 31 2E 54 32 30 2E 31 33 30 02 09 00 " + - "00 31 2E 54 32 30 2E 31 33 30 02 09 00 00 31 2E " + - "54 32 30 2E 31 33 30 02 09 00 00 31 2E 54 32 30 " + - "2E 31 32 30 02 09 00 00 31 2E 54 32 30 2E 31 32 " + - "30 02 09 00 00 31 2E 54 32 30 2E 31 32 30 02 09 " + - "00 00 31 2E 54 32 30 2E 31 31 39 02 09 00 00 31 " + - "2E 54 32 30 2E 31 31 39 02 09 00 00 31 2E 54 32 " + - "30 2E 31 31 39 02 09 00 00 31 2E 54 32 30 2E 31 " + - "31 38 02 09 00 00 31 2E 54 32 30 2E 31 31 38 02 " + - "09 00 00 31 2E 54 32 30 2E 31 31 38 02 09 00 00 " + - "31 2E 54 32 30 2E 31 30 38 02 09 00 00 31 2E 54 " + - "32 30 2E 31 30 38 02 09 00 00 31 2E 54 32 30 2E " + - "31 30 38 02 09 00 00 31 2E 54 32 30 2E 31 30 37 " + - "02 09 00 00 31 2E 54 32 30 2E 31 30 37 02 09 00 " + - "00 31 2E 54 32 30 2E 31 30 37 02 09 00 00 31 2E " + - "54 32 30 2E 31 30 36 02 09 00 00 31 2E 54 32 30 " + - "2E 31 30 36 02 09 00 00 31 2E 54 32 30 2E 31 30 " + - "36 02 09 00 00 31 2E 54 32 30 2E 30 39 36 02 09 " + - "00 00 31 2E 54 32 30 2E 30 39 36 02 09 00 00 31 " + - "2E 54 32 30 2E 30 39 36 02 09 00 00 31 2E 54 32 " + - "30 2E 30 39 35 02 09 00 00 31 2E 54 32 30 2E 30 " + - "39 35 02 09 00 00 31 2E 54 32 30 2E 30 39 35 02 " + - "09 00 00 31 2E 54 32 30 2E 30 39 34 02 09 00 00 " + - "31 2E 54 32 30 2E 30 39 34 02 09 00 00 31 2E 54 " + - "32 30 2E 30 39 34 02 09 00 00 31 2E 54 32 30 2E " + - "30 38 34 02 09 00 00 31 2E 54 32 30 2E 30 38 34 " + - "02 09 00 00 31 2E 54 32 30 2E 30 38 34 02 09 00 " + - "00 31 2E 54 32 30 2E 30 38 33 02 09 00 00 31 2E " + - "54 32 30 2E 30 38 33 02 09 00 00 31 2E 54 32 30 " + - "2E 30 38 33 02 09 00 00 31 2E 54 32 30 2E 30 38 " + - "32 02 09 00 00 31 2E 54 32 30 2E 30 38 32 02 09 " + - "00 00 31 2E 54 32 30 2E 30 38 32 02 09 00 00 31 " + - "2E 54 32 30 2E 30 37 32 02 09 00 00 31 2E 54 32 " + - "30 2E 30 37 32 02 09 00 00 31 2E 54 32 30 2E 30 " + - "37 32 02 09 00 00 31 2E 54 32 30 2E 30 37 31 02 " + - "09 00 00 31 2E 54 32 30 2E 30 37 31 02 09 00 00 " + - "31 2E 54 32 30 2E 30 37 31 02 09 00 00 31 2E 54 " + - "32 30 2E 30 37 30 02 09 00 00 31 2E 54 32 30 2E " + - "30 37 30 02 09 00 00 31 2E 54 32 30 2E 30 37 30 " + - "02 09 00 00 31 2E 54 32 30 2E 30 36 30 02 09 00 " + - "00 31 2E 54 32 30 2E 30 36 30 02 09 00 00 31 2E " + - "54 32 30 2E 30 36 30 02 09 00 00 31 2E 54 32 30 " + - "2E 30 35 39 02 09 00 00 31 2E 54 32 30 2E 30 35 " + - "39 02 09 00 00 31 2E 54 32 30 2E 30 35 39 02 09 " + - "00 00 31 2E 54 32 30 2E 30 35 38 02 09 00 00 31 " + - "2E 54 32 30 2E 30 35 38 02 09 00 00 31 2E 54 32 " + - "30 2E 30 35 38 02 09 00 00 31 2E 54 32 30 2E 30 " + - "34 38 02 09 00 00 31 2E 54 32 30 2E 30 34 38 02 " + - "09 00 00 31 2E 54 32 30 2E 30 34 38 02 09 00 00 " + - "31 2E 54 32 30 2E 30 34 37 02 09 00 00 31 2E 54 " + - "32 30 2E 30 34 37 02 09 00 00 31 2E 54 32 30 2E " + - "30 34 37 02 09 00 00 31 2E 54 32 30 2E 30 34 36 " + - "02 09 00 00 31 2E 54 32 30 2E 30 34 36 02 09 00 " + - "00 31 2E 54 32 30 2E 30 34 36 02 09 00 00 31 2E " + - "54 32 30 2E 30 33 36 02 09 00 00 31 2E 54 32 30 " + - "2E 30 33 36 02 09 00 00 31 2E 54 32 30 2E 30 33 " + - "36 02 09 00 00 31 2E 54 32 30 2E 30 33 35 02 09 " + - "00 00 31 2E 54 32 30 2E 30 33 35 02 09 00 00 31 " + - "2E 54 32 30 2E 30 33 35 02 09 00 00 31 2E 54 32 " + - "30 2E 30 33 34 02 09 00 00 31 2E 54 32 30 2E 30 " + - "33 34 02 09 00 00 31 2E 54 32 30 2E 30 33 34 02 " + - "09 00 00 31 2E 54 32 30 2E 30 32 34 02 09 00 00 " + - "31 2E 54 32 30 2E 30 32 34 02 09 00 00 31 2E 54 " + - "32 30 2E 30 32 34 02 09 00 00 31 2E 54 32 30 2E " + - "30 32 33 02 09 00 00 31 2E 54 32 30 2E 30 32 33 " + - "02 09 00 00 31 2E 54 32 30 2E 30 32 33 02 09 00 " + - "00 31 2E 54 32 30 2E 30 32 32 02 09 00 00 31 2E " + - "54 32 30 2E 30 32 32 02 09 00 00 31 2E 54 32 30 " + - "2E 30 32 32 02 09 00 00 31 2E 54 32 30 2E 30 31 " + - "32 02 09 00 00 31 2E 54 32 30 2E 30 31 32 02 09 " + - "00 00 31 2E 54 32 30 2E 30 31 32 02 09 00 00 31 " + - "2E 54 32 30 2E 30 31 31 02 09 00 00 31 2E 54 32 " + - "30 2E 30 31 31 02 09 00 00 31 2E 54 32 30 2E 30 " + - "31 31 02 09 00 00 31 2E 54 32 30 2E 30 31 30 02 " + - "09 00 00 31 2E 54 32 30 2E 30 31 30 02 09 00 00 " + - "31 2E 54 32 30 2E 30 31 30 "; + assertArrayEquals(data1, data1); - byte[] data1 = HexRead.readFromString(record_0x0018 + record_0x03C); RecordInputStream in1 = TestcaseRecordInputStream.create(data1); NameRecord nr1 = new NameRecord(in1); assert_bug50244(nr1); @@ -697,13 +140,14 @@ public final class TestNameRecord extends TestCase { assertEquals("1.T20.010", vals[vals.length - 1][0]); } + @Test public void testBug57923() { NameRecord record = new NameRecord(); assertEquals(0, record.getExternSheetNumber()); - + record.setNameDefinition(Ptg.EMPTY_PTG_ARRAY); assertEquals(0, record.getExternSheetNumber()); - + record.setNameDefinition(new Ptg[] {new NamePtg(1)}); assertEquals(0, record.getExternSheetNumber()); @@ -713,5 +157,5 @@ public final class TestNameRecord extends TestCase { record.setNameDefinition(new Ptg[] {new Ref3DPtg("A1", 1)}); assertEquals(1, record.getExternSheetNumber()); } - + } diff --git a/src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java b/src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java index 1f2e37709f..ecdce5de84 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java @@ -18,19 +18,20 @@ package org.apache.poi.hssf.record; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; import org.apache.poi.util.HexRead; +import org.junit.Test; /** * Tests the serialization and deserialization of the NoteRecord * class works correctly. Test data taken directly from a real * Excel file. - * - * @author Yegor Kozlov */ -public final class TestNoteRecord extends TestCase { +public final class TestNoteRecord { private final byte[] testData = HexRead.readFromString( "06 00 01 00 02 00 02 04 " + "1A 00 00 " + @@ -38,6 +39,7 @@ public final class TestNoteRecord extends TestCase { "00" // padding byte ); + @Test public void testRead() { NoteRecord record = new NoteRecord(TestcaseRecordInputStream.create(NoteRecord.sid, testData)); @@ -50,6 +52,7 @@ public final class TestNoteRecord extends TestCase { assertEquals("Apache Software Foundation", record.getAuthor()); } + @Test public void testWrite() { NoteRecord record = new NoteRecord(); assertEquals(NoteRecord.sid, record.getSid()); @@ -64,6 +67,7 @@ public final class TestNoteRecord extends TestCase { TestcaseRecordInputStream.confirmRecordEncoding(NoteRecord.sid, testData, ser); } + @Test public void testClone() { NoteRecord record = new NoteRecord(); @@ -86,6 +90,7 @@ public final class TestNoteRecord extends TestCase { assertArrayEquals(src, cln); } + @Test public void testUnicodeAuthor() { // This sample data was created by setting the 'user name' field in the 'Personalize' // section of Excel's options to \u30A2\u30D1\u30C3\u30C1\u65CF, and then @@ -97,9 +102,7 @@ public final class TestNoteRecord extends TestCase { ); RecordInputStream in = TestcaseRecordInputStream.create(NoteRecord.sid, data); NoteRecord nr = new NoteRecord(in); - if ("\u00A2\u0030\u00D1\u0030\u00C3".equals(nr.getAuthor())) { - throw new AssertionFailedError("Identified bug in reading note with unicode author"); - } + assertNotEquals("Identified bug in reading note with unicode author","\u00A2\u0030\u00D1\u0030\u00C3", nr.getAuthor()); assertEquals("\u30A2\u30D1\u30C3\u30C1\u65CF", nr.getAuthor()); assertTrue(nr.authorIsMultibyte()); diff --git a/src/testcases/org/apache/poi/hssf/record/TestNoteStructureSubRecord.java b/src/testcases/org/apache/poi/hssf/record/TestNoteStructureSubRecord.java index 30631243a5..358a1431c6 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestNoteStructureSubRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestNoteStructureSubRecord.java @@ -19,31 +19,31 @@ package org.apache.poi.hssf.record; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.junit.Test; /** * Tests the serialization and deserialization of the NoteRecord * class works correctly. Test data taken directly from a real * Excel file. - * - * @author Yegor Kozlov */ -public final class TestNoteStructureSubRecord extends TestCase { +public final class TestNoteStructureSubRecord { private final byte[] data = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)0x80, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)0x81, 0x01, (byte)0xCC, (byte)0xEC }; + @Test public void testRead() { - NoteStructureSubRecord record = new NoteStructureSubRecord(TestcaseRecordInputStream.create(NoteStructureSubRecord.sid, data), data.length); assertEquals(NoteStructureSubRecord.sid, record.getSid()); assertEquals(data.length, record.getDataSize()); } + @Test public void testWrite() { NoteStructureSubRecord record = new NoteStructureSubRecord(); assertEquals(NoteStructureSubRecord.sid, record.getSid()); @@ -51,11 +51,10 @@ public final class TestNoteStructureSubRecord extends TestCase { byte [] ser = record.serialize(); assertEquals(ser.length - 4, data.length); - } - public void testClone() - { + @Test + public void testClone() { NoteStructureSubRecord record = new NoteStructureSubRecord(); byte[] src = record.serialize(); diff --git a/src/testcases/org/apache/poi/hssf/record/TestPLVRecord.java b/src/testcases/org/apache/poi/hssf/record/TestPLVRecord.java index fce575b1c3..94c8bca18d 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestPLVRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestPLVRecord.java @@ -17,43 +17,39 @@ package org.apache.poi.hssf.record; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import java.io.InputStream; + import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.DVConstraint; import org.apache.poi.hssf.usermodel.HSSFDataValidation; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.DataValidationConstraint; import org.apache.poi.ss.util.CellRangeAddressList; - -import java.io.InputStream; +import org.junit.Test; /** * Verify that presence of PLV record doesn't break data * validation, bug #53972: * https://issues.apache.org/bugzilla/show_bug.cgi?id=53972 - * - * @author Andrew Novikov */ -public final class TestPLVRecord extends TestCase { +public final class TestPLVRecord { private final static String DV_DEFINITION = "$A$1:$A$5"; private final static String XLS_FILENAME = "53972.xls"; private final static String SHEET_NAME = "S2"; + @Test public void testPLVRecord() throws Exception { - InputStream is = HSSFTestDataSamples.openSampleFileStream(XLS_FILENAME); - HSSFWorkbook workbook = new HSSFWorkbook(is); + try (InputStream is = HSSFTestDataSamples.openSampleFileStream(XLS_FILENAME); + HSSFWorkbook workbook = new HSSFWorkbook(is)) { - CellRangeAddressList cellRange = new CellRangeAddressList(0, 0, 1, 1); - DataValidationConstraint constraint = DVConstraint.createFormulaListConstraint(DV_DEFINITION); - HSSFDataValidation dataValidation = new HSSFDataValidation(cellRange, constraint); + CellRangeAddressList cellRange = new CellRangeAddressList(0, 0, 1, 1); + DataValidationConstraint constraint = DVConstraint.createFormulaListConstraint(DV_DEFINITION); + HSSFDataValidation dataValidation = new HSSFDataValidation(cellRange, constraint); - // This used to throw an error before - try { + // This used to throw an IllegalStateException before + // Identified bug 53972, PLV record breaks addDataValidation() workbook.getSheet(SHEET_NAME).addValidationData(dataValidation); - } catch (IllegalStateException ex) { - throw new AssertionFailedError("Identified bug 53972, PLV record breaks addDataValidation()"); } } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestPaneRecord.java b/src/testcases/org/apache/poi/hssf/record/TestPaneRecord.java index 93d1a1f987..6a7cf43e5b 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestPaneRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestPaneRecord.java @@ -18,16 +18,17 @@ package org.apache.poi.hssf.record; -import junit.framework.TestCase; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; /** * Tests the serialization and deserialization of the PaneRecord * class works correctly. Test data taken directly from a real * Excel file. - * - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestPaneRecord extends TestCase { +public final class TestPaneRecord { byte[] data = new byte[] { (byte)0x01, (byte)0x00, (byte)0x02, (byte)0x00, @@ -36,6 +37,7 @@ public final class TestPaneRecord extends TestCase { (byte)0x02, (byte)0x00, }; + @Test public void testLoad() { PaneRecord record = new PaneRecord(TestcaseRecordInputStream.create(0x41, data)); @@ -48,8 +50,8 @@ public final class TestPaneRecord extends TestCase { assertEquals( 14, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { PaneRecord record = new PaneRecord(); record.setX( (short) 1); @@ -59,8 +61,6 @@ public final class TestPaneRecord extends TestCase { record.setActivePane( PaneRecord.ACTIVE_PANE_LOWER_LEFT); byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(PaneRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestRecalcIdRecord.java b/src/testcases/org/apache/poi/hssf/record/TestRecalcIdRecord.java index 0bea0d4108..0a53b899e7 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestRecalcIdRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestRecalcIdRecord.java @@ -18,17 +18,12 @@ package org.apache.poi.hssf.record; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; import org.apache.poi.util.HexRead; -import org.apache.poi.util.RecordFormatException; +import org.junit.Test; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; -/** - * - * @author Josh Micich - */ -public final class TestRecalcIdRecord extends TestCase { +public final class TestRecalcIdRecord { private static RecalcIdRecord create(byte[] data) { RecordInputStream in = TestcaseRecordInputStream.create(RecalcIdRecord.sid, data); @@ -36,8 +31,10 @@ public final class TestRecalcIdRecord extends TestCase { assertEquals(0, in.remaining()); return result; } + + @Test public void testBasicDeserializeReserialize() { - + byte[] data = HexRead.readFromString( "C1 01" + // rt "00 00" + // reserved @@ -47,8 +44,9 @@ public final class TestRecalcIdRecord extends TestCase { TestcaseRecordInputStream.confirmRecordEncoding(RecalcIdRecord.sid, data, r.serialize()); } + @Test public void testBadFirstField_bug48096() { - /** + /* * Data taken from the sample file referenced in Bugzilla 48096, file offset 0x0D45. * The apparent problem is that the first data short field has been written with the * wrong endianness. Excel seems to ignore whatever value is present in this @@ -58,15 +56,10 @@ public final class TestRecalcIdRecord extends TestCase { byte[] goodData = HexRead.readFromString("C1 01 08 00 C1 01 00 00 00 01 69 61"); RecordInputStream in = TestcaseRecordInputStream.create(badData); - RecalcIdRecord r; - try { - r = new RecalcIdRecord(in); - } catch (RecordFormatException e) { - if (e.getMessage().equals("expected 449 but got 49409")) { - throw new AssertionFailedError("Identified bug 48096"); - } - throw e; - } + + // bug 48096 - expected 449 but got 49409 + RecalcIdRecord r = new RecalcIdRecord(in); + assertEquals(0, in.remaining()); assertArrayEquals(r.serialize(), goodData); } diff --git a/src/testcases/org/apache/poi/hssf/record/TestRecordInputStream.java b/src/testcases/org/apache/poi/hssf/record/TestRecordInputStream.java index 2145b4f4af..ebd0db6cf2 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestRecordInputStream.java +++ b/src/testcases/org/apache/poi/hssf/record/TestRecordInputStream.java @@ -17,17 +17,15 @@ package org.apache.poi.hssf.record; -import org.apache.poi.util.HexRead; +import static org.junit.Assert.assertEquals; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import org.apache.poi.util.HexRead; +import org.junit.Test; /** * Tests for {@link RecordInputStream} - * - * @author Josh Micich */ -public final class TestRecordInputStream extends TestCase { +public final class TestRecordInputStream { /** * Data inspired by attachment 22626 of bug 45866
@@ -51,6 +49,9 @@ public final class TestRecordInputStream extends TestCase { + "01" // this bit uncompressed + "1A 59 00 8A 9E 8A " // 3 uncompressed unicode chars ; + + + @Test public void testChangeOfCompressionFlag_bug25866() { byte[] changingFlagSimpleData = HexRead.readFromString("" + "AA AA " // fake SID @@ -58,19 +59,13 @@ public final class TestRecordInputStream extends TestCase { + HED_DUMP1 ); RecordInputStream in = TestcaseRecordInputStream.create(changingFlagSimpleData); - String actual; - try { - actual = in.readUnicodeLEString(18); - } catch (IllegalArgumentException e) { - if ("compressByte in continue records must be 1 while reading unicode LE string".equals(e.getMessage())) { - throw new AssertionFailedError("Identified bug 45866"); - } - - throw e; - } + + // bug 45866 - compressByte in continue records must be 1 while reading unicode LE string + String actual = in.readUnicodeLEString(18); assertEquals("\u591A\u8A00\u8A9E - Multilingual", actual); } + @Test public void testChangeFromUnCompressedToCompressed() { byte[] changingFlagSimpleData = HexRead.readFromString("" + "AA AA " // fake SID @@ -81,7 +76,8 @@ public final class TestRecordInputStream extends TestCase { String actual = in.readCompressedUnicode(18); assertEquals("Multilingual - \u591A\u8A00\u8A9E", actual); } - + + @Test public void testReadString() { byte[] changingFlagFullData = HexRead.readFromString("" + "AA AA " // fake SID @@ -95,6 +91,8 @@ public final class TestRecordInputStream extends TestCase { assertEquals("Multilingual - \u591A\u8A00\u8A9E", actual); } + @SuppressWarnings("ThrowableNotThrown") + @Test public void testLeftoverDataException() { // just ensure that the exception is created correctly, even with unknown sids new RecordInputStream.LeftoverDataException(1, 200); diff --git a/src/testcases/org/apache/poi/hssf/record/TestSCLRecord.java b/src/testcases/org/apache/poi/hssf/record/TestSCLRecord.java index 335b6605d7..24a8b65bdc 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestSCLRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestSCLRecord.java @@ -18,21 +18,22 @@ package org.apache.poi.hssf.record; -import junit.framework.TestCase; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; /** * Tests the serialization and deserialization of the SCLRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Andrew C. Oliver (acoliver at apache.org) */ -public final class TestSCLRecord extends TestCase { +public final class TestSCLRecord { byte[] data = new byte[] { (byte)0x3,(byte)0x0,(byte)0x4,(byte)0x0 }; + @Test public void testLoad() { SCLRecord record = new SCLRecord(TestcaseRecordInputStream.create(0xa0, data)); assertEquals( 3, record.getNumerator()); @@ -41,16 +42,13 @@ public final class TestSCLRecord extends TestCase { assertEquals( 8, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { SCLRecord record = new SCLRecord(); record.setNumerator( (short)3 ); record.setDenominator( (short)4 ); - byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(SCLRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java b/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java index 01f3ded891..96ff3ad6ac 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java @@ -20,7 +20,6 @@ package org.apache.poi.hssf.record; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.BufferedReader; @@ -36,40 +35,33 @@ import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.record.common.UnicodeString; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.poifs.storage.RawDataUtil; import org.apache.poi.util.HexRead; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LocaleUtil; import org.junit.Test; -import junit.framework.AssertionFailedError; - -/** - * @author Marc Johnson (mjohnson at apache dot org) - * @author Glen Stampoultzis (glens at apache.org) - */ public final class TestSSTRecord { /** * decodes hexdump files and concatenates the results * @param hexDumpFileNames names of sample files in the hssf test data directory - * @throws IOException */ private static byte[] concatHexDumps(String... hexDumpFileNames) throws IOException { int nFiles = hexDumpFileNames.length; ByteArrayOutputStream baos = new ByteArrayOutputStream(nFiles * 8228); - for (int i = 0; i < nFiles; i++) { - String sampleFileName = hexDumpFileNames[i]; - InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName); - BufferedReader br = new BufferedReader(new InputStreamReader(is, LocaleUtil.CHARSET_1252)); + for (String sampleFileName : hexDumpFileNames) { + try (InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName)) { + BufferedReader br = new BufferedReader(new InputStreamReader(is, LocaleUtil.CHARSET_1252)); - while (true) { - String line = br.readLine(); - if (line == null) { - break; + while (true) { + String line = br.readLine(); + if (line == null) { + break; + } + baos.write(HexRead.readFromString(line)); } - baos.write(HexRead.readFromString(line)); } - is.close(); } return baos.toByteArray(); @@ -89,7 +81,6 @@ public final class TestSSTRecord { /** * SST is often split over several {@link ContinueRecord}s - * @throws IOException */ @Test public void testContinuedRecord() throws IOException { @@ -120,9 +111,8 @@ public final class TestSSTRecord { // } SSTRecord rec2 = createSSTFromRawData(ser_output); - if (!areSameSSTs(record, rec2)) { - throw new AssertionFailedError("large SST re-serialized incorrectly"); - } + assertRecordEquals(record, rec2); + // if (false) { // // TODO - trivial differences in ContinueRecord break locations // // Sample data should be checked against what most recent Excel version produces. @@ -131,27 +121,8 @@ public final class TestSSTRecord { // } } - private boolean areSameSSTs(SSTRecord a, SSTRecord b) { - - if (a.getNumStrings() != b.getNumStrings()) { - return false; - } - int nElems = a.getNumUniqueStrings(); - if (nElems != b.getNumUniqueStrings()) { - return false; - } - for(int i=0; i> 8 ), - (byte) 8, (byte) 0, (byte) 0, (byte) 0, (byte) 0, - (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 - }; + byte[] expected = { + (byte) record.getSid(), (byte) ( record.getSid() >> 8 ), + (byte) 8, (byte) 0, (byte) 0, (byte) 0, (byte) 0, + (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 + }; - assertEquals( expected.length, output.length ); - for ( int k = 0; k < expected.length; k++ ) - { - assertEquals( String.valueOf( k ), expected[k], output[k] ); - } + assertArrayEquals(expected, output); } /** @@ -345,1118 +311,29 @@ public final class TestSSTRecord { */ @Test public void testReadWriteDuplicatedRichText1() throws Exception { - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("duprich1.xls"); - HSSFSheet sheet = wb.getSheetAt( 1 ); - assertEquals( "01/05 (Wed)", sheet.getRow( 0 ).getCell(8 ).getStringCellValue() ); - assertEquals( "01/05 (Wed)", sheet.getRow( 1 ).getCell(8 ).getStringCellValue() ); + try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("duprich1.xls")) { + HSSFSheet sheet = wb.getSheetAt(1); + assertEquals("01/05 (Wed)", sheet.getRow(0).getCell(8).getStringCellValue()); + assertEquals("01/05 (Wed)", sheet.getRow(1).getCell(8).getStringCellValue()); - HSSFTestDataSamples.writeOutAndReadBack(wb).close(); - - wb.close(); + HSSFTestDataSamples.writeOutAndReadBack(wb).close(); + } - // test the second file. - wb = HSSFTestDataSamples.openSampleWorkbook("duprich2.xls"); - sheet = wb.getSheetAt( 0 ); - int row = 0; - assertEquals( "Testing", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() ); - assertEquals( "rich", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() ); - assertEquals( "text", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() ); - assertEquals( "strings", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() ); - assertEquals( "Testing", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() ); - assertEquals( "Testing", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() ); + // test the second file. + try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("duprich2.xls")) { + HSSFSheet sheet = wb.getSheetAt(0); + int row = 0; + assertEquals("Testing", sheet.getRow(row++).getCell(0).getStringCellValue()); + assertEquals("rich", sheet.getRow(row++).getCell(0).getStringCellValue()); + assertEquals("text", sheet.getRow(row++).getCell(0).getStringCellValue()); + assertEquals("strings", sheet.getRow(row++).getCell(0).getStringCellValue()); + assertEquals("Testing", sheet.getRow(row++).getCell(0).getStringCellValue()); + assertEquals("Testing", sheet.getRow(row).getCell(0).getStringCellValue()); - HSSFTestDataSamples.writeOutAndReadBack(wb).close(); - - wb.close(); + HSSFTestDataSamples.writeOutAndReadBack(wb).close(); + } } - /** - * hex dump from UnicodeStringFailCase1.xls atatched to Bugzilla 50779 - */ - private static final String data_50779_1 = - //Offset=0x00000612(1554) recno=71 sid=0x00FC size=0x2020(8224) - " FC 00 20 20 51 00 00 00 51 00 00 00 32 00" + - "05 10 00 00 00 42 30 44 30 46 30 48 30 4A 30 4B" + - "30 4D 30 4F 30 51 30 53 30 55 30 57 30 59 30 5B" + - "30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B" + - "30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B" + - "30 7E 30 7F 30 80 30 81 30 82 30 84 30 86 30 88" + - "30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93" + - "30 30 00 30 00 30 00 31 00 01 00 0C 00 05 00 35" + - "00 00 00 00 00 00 00 4B 30 32 00 01 42 30 44 30" + - "46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30" + - "55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30" + - "66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30" + - "72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30" + - "82 30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30" + - "8D 30 8F 30 92 30 93 30 30 00 30 00 30 00 32 00" + - "32 00 01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D" + - "30 4F 30 51 30 53 30 55 30 57 30 59 30 5B 30 5D" + - "30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C" + - "30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E" + - "30 7F 30 80 30 81 30 82 30 84 30 86 30 88 30 89" + - "30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30" + - "00 30 00 30 00 33 00 32 00 01 42 30 44 30 46 30" + - "48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30" + - "57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30" + - "68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30" + - "75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30" + - "84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30" + - "8F 30 92 30 93 30 30 00 30 00 30 00 34 00 32 00" + - "01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F" + - "30 51 30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F" + - "30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D" + - "30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F" + - "30 80 30 81 30 82 30 84 30 86 30 88 30 89 30 8A" + - "30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30" + - "00 30 00 35 00 32 00 01 42 30 44 30 46 30 48 30" + - "4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30" + - "59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30" + - "6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30" + - "78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30" + - "86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30" + - "92 30 93 30 30 00 30 00 30 00 36 00 32 00 01 42" + - "30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51" + - "30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61" + - "30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E" + - "30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80" + - "30 81 30 82 30 84 30 86 30 88 30 89 30 8A 30 8B" + - "30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00 30" + - "00 37 00 32 00 01 42 30 44 30 46 30 48 30 4A 30" + - "4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30 59 30" + - "5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30" + - "6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30" + - "7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30 86 30" + - "88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30" + - "93 30 30 00 30 00 30 00 38 00 32 00 01 42 30 44" + - "30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53" + - "30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64" + - "30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F" + - "30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81" + - "30 82 30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C" + - "30 8D 30 8F 30 92 30 93 30 30 00 30 00 30 00 39" + - "00 32 00 01 42 30 44 30 46 30 48 30 4A 30 4B 30" + - "4D 30 4F 30 51 30 53 30 55 30 57 30 59 30 5B 30" + - "5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30" + - "6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30" + - "7E 30 7F 30 80 30 81 30 82 30 84 30 86 30 88 30" + - "89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30" + - "30 00 30 00 31 00 30 00 32 00 01 42 30 44 30 46" + - "30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55" + - "30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66" + - "30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72" + - "30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82" + - "30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D" + - "30 8F 30 92 30 93 30 30 00 30 00 31 00 31 00 32" + - "00 01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30" + - "4F 30 51 30 53 30 55 30 57 30 59 30 5B 30 5D 30" + - "5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30" + - "6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30" + - "7F 30 80 30 81 30 82 30 84 30 86 30 88 30 89 30" + - "8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00" + - "30 00 31 00 32 00 32 00 01 42 30 44 30 46 30 48" + - "30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57" + - "30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68" + - "30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75" + - "30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84" + - "30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F" + - "30 92 30 93 30 30 00 30 00 31 00 33 00 32 00 01" + - "42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30" + - "51 30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30" + - "61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30" + - "6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30" + - "80 30 81 30 82 30 84 30 86 30 88 30 89 30 8A 30" + - "8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00" + - "31 00 34 00 32 00 01 42 30 44 30 46 30 48 30 4A" + - "30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30 59" + - "30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A" + - "30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78" + - "30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30 86" + - "30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92" + - "30 93 30 30 00 30 00 31 00 35 00 32 00 01 42 30" + - "44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30" + - "53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30" + - "64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30" + - "6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30" + - "81 30 82 30 84 30 86 30 88 30 89 30 8A 30 8B 30" + - "8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00 31 00" + - "36 00 32 00 01 42 30 44 30 46 30 48 30 4A 30 4B" + - "30 4D 30 4F 30 51 30 53 30 55 30 57 30 59 30 5B" + - "30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B" + - "30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B" + - "30 7E 30 7F 30 80 30 81 30 82 30 84 30 86 30 88" + - "30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93" + - "30 30 00 30 00 31 00 37 00 32 00 01 42 30 44 30" + - "46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30" + - "55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30" + - "66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30" + - "72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30" + - "82 30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30" + - "8D 30 8F 30 92 30 93 30 30 00 30 00 31 00 38 00" + - "32 00 01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D" + - "30 4F 30 51 30 53 30 55 30 57 30 59 30 5B 30 5D" + - "30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C" + - "30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E" + - "30 7F 30 80 30 81 30 82 30 84 30 86 30 88 30 89" + - "30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30" + - "00 30 00 31 00 39 00 32 00 01 42 30 44 30 46 30" + - "48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30" + - "57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30" + - "68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30" + - "75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30" + - "84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30" + - "8F 30 92 30 93 30 30 00 30 00 32 00 30 00 32 00" + - "01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F" + - "30 51 30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F" + - "30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D" + - "30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F" + - "30 80 30 81 30 82 30 84 30 86 30 88 30 89 30 8A" + - "30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30" + - "00 32 00 31 00 32 00 01 42 30 44 30 46 30 48 30" + - "4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30" + - "59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30" + - "6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30" + - "78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30" + - "86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30" + - "92 30 93 30 30 00 30 00 32 00 32 00 32 00 01 42" + - "30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51" + - "30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61" + - "30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E" + - "30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80" + - "30 81 30 82 30 84 30 86 30 88 30 89 30 8A 30 8B" + - "30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00 32" + - "00 33 00 32 00 01 42 30 44 30 46 30 48 30 4A 30" + - "4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30 59 30" + - "5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30" + - "6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30" + - "7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30 86 30" + - "88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30" + - "93 30 30 00 30 00 32 00 34 00 32 00 01 42 30 44" + - "30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53" + - "30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64" + - "30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F" + - "30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81" + - "30 82 30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C" + - "30 8D 30 8F 30 92 30 93 30 30 00 30 00 32 00 35" + - "00 32 00 01 42 30 44 30 46 30 48 30 4A 30 4B 30" + - "4D 30 4F 30 51 30 53 30 55 30 57 30 59 30 5B 30" + - "5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30" + - "6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30" + - "7E 30 7F 30 80 30 81 30 82 30 84 30 86 30 88 30" + - "89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30" + - "30 00 30 00 32 00 36 00 32 00 01 42 30 44 30 46" + - "30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55" + - "30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66" + - "30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72" + - "30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82" + - "30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D" + - "30 8F 30 92 30 93 30 30 00 30 00 32 00 37 00 32" + - "00 01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30" + - "4F 30 51 30 53 30 55 30 57 30 59 30 5B 30 5D 30" + - "5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30" + - "6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30" + - "7F 30 80 30 81 30 82 30 84 30 86 30 88 30 89 30" + - "8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00" + - "30 00 32 00 38 00 32 00 01 42 30 44 30 46 30 48" + - "30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57" + - "30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68" + - "30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75" + - "30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84" + - "30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F" + - "30 92 30 93 30 30 00 30 00 32 00 39 00 32 00 01" + - "42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30" + - "51 30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30" + - "61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30" + - "6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30" + - "80 30 81 30 82 30 84 30 86 30 88 30 89 30 8A 30" + - "8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00" + - "33 00 30 00 32 00 01 42 30 44 30 46 30 48 30 4A" + - "30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30 59" + - "30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A" + - "30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78" + - "30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30 86" + - "30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92" + - "30 93 30 30 00 30 00 33 00 31 00 32 00 01 42 30" + - "44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30" + - "53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30" + - "64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30" + - "6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30" + - "81 30 82 30 84 30 86 30 88 30 89 30 8A 30 8B 30" + - "8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00 33 00" + - "32 00 32 00 01 42 30 44 30 46 30 48 30 4A 30 4B" + - "30 4D 30 4F 30 51 30 53 30 55 30 57 30 59 30 5B" + - "30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B" + - "30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B" + - "30 7E 30 7F 30 80 30 81 30 82 30 84 30 86 30 88" + - "30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93" + - "30 30 00 30 00 33 00 33 00 32 00 01 42 30 44 30" + - "46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30" + - "55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30" + - "66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30" + - "72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30" + - "82 30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30" + - "8D 30 8F 30 92 30 93 30 30 00 30 00 33 00 34 00" + - "32 00 01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D" + - "30 4F 30 51 30 53 30 55 30 57 30 59 30 5B 30 5D" + - "30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C" + - "30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E" + - "30 7F 30 80 30 81 30 82 30 84 30 86 30 88 30 89" + - "30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30" + - "00 30 00 33 00 35 00 32 00 01 42 30 44 30 46 30" + - "48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30" + - "57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30" + - "68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30" + - "75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30" + - "84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30" + - "8F 30 92 30 93 30 30 00 30 00 33 00 36 00 32 00" + - "01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F" + - "30 51 30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F" + - "30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D" + - "30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F" + - "30 80 30 81 30 82 30 84 30 86 30 88 30 89 30 8A" + - "30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30" + - "00 33 00 37 00 32 00 01 42 30 44 30 46 30 48 30" + - "4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30" + - "59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30" + - "6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30" + - "78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30" + - "86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30" + - "92 30 93 30 30 00 30 00 33 00 38 00 32 00 01 42" + - "30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51" + - "30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61" + - "30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E" + - "30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80" + - "30 81 30 82 30 84 30 86 30 88 30 89 30 8A 30 8B" + - "30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00 33" + - "00 39 00 32 00 01 42 30 44 30 46 30 48 30 4A 30" + - "4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30 59 30" + - "5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30" + - "6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30" + - "7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30 86 30" + - "88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30" + - "93 30 30 00 30 00 34 00 30 00 32 00 01 42 30 44" + - "30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53" + - "30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64" + - "30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F" + - "30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81" + - "30 82 30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C" + - "30 8D 30 8F 30 92 30 93 30 30 00 30 00 34 00 31" + - "00 32 00 01 42 30 44 30 46 30 48 30 4A 30 4B 30" + - "4D 30 4F 30 51 30 53 30 55 30 57 30 59 30 5B 30" + - "5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30" + - "6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30" + - "7E 30 7F 30 80 30 81 30 82 30 84 30 86 30 88 30" + - "89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30" + - "30 00 30 00 34 00 32 00 32 00 01 42 30 44 30 46" + - "30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55" + - "30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66" + - "30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72" + - "30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82" + - "30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D" + - "30 8F 30 92 30 93 30 30 00 30 00 34 00 33 00 32" + - "00 01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30" + - "4F 30 51 30 53 30 55 30 57 30 59 30 5B 30 5D 30" + - "5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30" + - "6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30" + - "7F 30 80 30 81 30 82 30 84 30 86 30 88 30 89 30" + - "8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00" + - "30 00 34 00 34 00 32 00 01 42 30 44 30 46 30 48" + - "30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57" + - "30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68" + - "30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75" + - "30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84" + - "30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F" + - "30 92 30 93 30 30 00 30 00 34 00 35 00 32 00 01" + - "42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30" + - "51 30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30" + - "61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30" + - "6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30" + - "80 30 81 30 82 30 84 30 86 30 88 30 89 30 8A 30" + - "8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00" + - "34 00 36 00 32 00 01 42 30 44 30 46 30 48 30 4A" + - "30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30 59" + - "30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A" + - "30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78" + - "30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30 86" + - "30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92" + - "30 93 30 30 00 30 00 34 00 37 00 32 00 01 42 30" + - "44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30" + - "53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30" + - "64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30" + - "6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30" + - "81 30 82 30 84 30 86 30 88 30 89 30 8A 30 8B 30" + - "8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00 34 00" + - "38 00 32 00 01 42 30 44 30 46 30 48 30 4A 30 4B" + - "30 4D 30 4F 30 51 30 53 30 55 30 57 30 59 30 5B" + - "30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B" + - "30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B" + - "30 7E 30 7F 30 80 30 81 30 82 30 84 30 86 30 88" + - "30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93" + - "30 30 00 30 00 34 00 39 00 32 00 01 42 30 44 30" + - "46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30" + - "55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30" + - "66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30" + - "72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30" + - "82 30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30" + - "8D 30 8F 30 92 30 93 30 30 00 30 00 35 00 30 00" + - "32 00 01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D" + - "30 4F 30 51 30 53 30 55 30 57 30 59 30 5B 30 5D" + - "30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C" + - "30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E" + - "30 7F 30 80 30 81 30 82 30 84 30 86 30 88 30 89" + - "30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30" + - "00 30 00 35 00 31 00 32 00 01 42 30 44 30 46 30" + - "48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30" + - "57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30" + - "68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30" + - "75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30" + - "84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30" + - "8F 30 92 30 93 30 30 00 30 00 35 00 32 00 32 00" + - "01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F" + - "30 51 30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F" + - "30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D" + - "30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F" + - "30 80 30 81 30 82 30 84 30 86 30 88 30 89 30 8A" + - "30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30" + - "00 35 00 33 00 32 00 01 42 30 44 30 46 30 48 30" + - "4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30" + - "59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30" + - "6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30" + - "78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30" + - "86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30" + - "92 30 93 30 30 00 30 00 35 00 34 00 32 00 01 42" + - "30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51" + - "30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61" + - "30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E" + - "30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80" + - "30 81 30 82 30 84 30 86 30 88 30 89 30 8A 30 8B" + - "30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00 35" + - "00 35 00 32 00 01 42 30 44 30 46 30 48 30 4A 30" + - "4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30 59 30" + - "5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30" + - "6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30" + - "7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30 86 30" + - "88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30" + - "93 30 30 00 30 00 35 00 36 00 32 00 01 42 30 44" + - "30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53" + - "30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64" + - "30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F" + - "30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81" + - "30 82 30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C" + - "30 8D 30 8F 30 92 30 93 30 30 00 30 00 35 00 37" + - "00 32 00 01 42 30 44 30 46 30 48 30 4A 30 4B 30" + - "4D 30 4F 30 51 30 53 30 55 30 57 30 59 30 5B 30" + - "5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30" + - "6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30" + - "7E 30 7F 30 80 30 81 30 82 30 84 30 86 30 88 30" + - "89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30" + - "30 00 30 00 35 00 38 00 32 00 01 42 30 44 30 46" + - "30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55" + - "30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66" + - "30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72" + - "30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82" + - "30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D" + - "30 8F 30 92 30 93 30 30 00 30 00 35 00 39 00 32" + - "00 01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30" + - "4F 30 51 30 53 30 55 30 57 30 59 30 5B 30 5D 30" + - "5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30" + - "6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30" + - "7F 30 80 30 81 30 82 30 84 30 86 30 88 30 89 30" + - "8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00" + - "30 00 36 00 30 00 32 00 01 42 30 44 30 46 30 48" + - "30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57" + - "30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68" + - "30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75" + - "30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84" + - "30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F" + - "30 92 30 93 30 30 00 30 00 36 00 31 00 32 00 01" + - "42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30" + - "51 30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30" + - "61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30" + - "6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30" + - "80 30 81 30 82 30 84 30 86 30 88 30 89 30 8A 30" + - "8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00" + - "36 00 32 00 32 00 01 42 30 44 30 46 30 48 30 4A" + - "30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30 59" + - "30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A" + - "30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78" + - "30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30 86" + - "30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92" + - "30 93 30 30 00 30 00 36 00 33 00 32 00 01 42 30" + - "44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30" + - "53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30" + - "64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30" + - "6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30" + - "81 30 82 30 84 30 86 30 88 30 89 30 8A 30 8B 30" + - "8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00 36 00" + - "34 00 32 00 01 42 30 44 30 46 30 48 30 4A 30 4B" + - "30 4D 30 4F 30 51 30 53 30 55 30 57 30 59 30 5B" + - "30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B" + - "30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B" + - "30 7E 30 7F 30 80 30 81 30 82 30 84 30 86 30 88" + - "30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93" + - "30 30 00 30 00 36 00 35 00 32 00 01 42 30 44 30" + - "46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30" + - "55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30" + - "66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30" + - "72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30" + - "82 30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30" + - "8D 30 8F 30 92 30 93 30 30 00 30 00 36 00 36 00" + - "32 00 01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D" + - "30 4F 30 51 30 53 30 55 30 57 30 59 30 5B 30 5D" + - "30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C" + - "30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E" + - "30 7F 30 80 30 81 30 82 30 84 30 86 30 88 30 89" + - "30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30" + - "00 30 00 36 00 37 00 32 00 01 42 30 44 30 46 30" + - "48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30" + - "57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30" + - "68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30" + - "75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30" + - "84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30" + - "8F 30 92 30 93 30 30 00 30 00 36 00 38 00 32 00" + - "01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F" + - "30 51 30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F" + - "30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D" + - "30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F" + - "30 80 30 81 30 82 30 84 30 86 30 88 30 89 30 8A" + - "30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30" + - "00 36 00 39 00 32 00 01 42 30 44 30 46 30 48 30" + - "4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30" + - "59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30" + - "6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30" + - "78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30" + - "86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30" + - "92 30 93 30 30 00 30 00 37 00 30 00 32 00 01 42" + - "30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51" + - "30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61" + - "30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E" + - "30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80" + - "30 81 30 82 30 84 30 86 30 88 30 89 30 8A 30 8B" + - "30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00 37" + - "00 31 00 32 00 01 42 30 44 30 46 30 48 30 4A 30" + - "4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30 59 30" + - "5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30" + - "6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30" + - "7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30 86 30" + - "88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30" + - "93 30 30 00 30 00 37 00 32 00 32 00 01 42 30 44" + - "30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53" + - "30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64" + - "30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F" + - "30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81" + - "30 82 30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C" + - "30 8D 30 8F 30 92 30 93 30 30 00 30 00 37 00 33" + - "00 32 00 01 42 30 44 30 46 30 48 30 4A 30 4B 30" + - "4D 30 4F 30 51 30 53 30 55 30 57 30 59 30 5B 30" + - "5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30" + - "6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30" + - "7E 30 7F 30 80 30 81 30 82 30 84 30 86 30 88 30" + - "89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30" + - "30 00 30 00 37 00 34 00 32 00 01 42 30 44 30 46" + - "30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55" + - "30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66" + - "30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72" + - "30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82" + - "30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D" + - "30 8F 30 92 30 93 30 30 00 30 00 37 00 35 00 32" + - "00 01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30" + - "4F 30 51 30 53 30 55 30 57 30 59 30 5B 30 5D 30" + - "5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30" + - "6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30" + - "7F 30 80 30 81 30 82 30 84 30 86 30 88 30 89 30" + - "8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00" + - "30 00 37 00 36 00 32 00 01 42 30 44 30 46 30 48" + - "30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57" + - "30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68" + - "30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75" + - "30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84" + - "30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F" + - "30 92 30 93 30 30 00 30 00 37 00 37 00 32 00 01" + - "42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30" + - "51 30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30" + - "61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30" + - "6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30" + - "80 30 81 30 82 30 84 30 86 30 88 30 89 30 8A 30" + - "8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00" + - "37 00 38 00 1F 00 05 B8 00 00 00 17 53 77 6D 53" + - "90 52 97 EE 68 0C 77 A9 5C 4B 62 0C 77 8F 79 F6" + - "5C 0C 77 03 68 28 67 0C 77 FC 57 89 73 0C 77 71" + - "67 AC 4E FD 90 43 53 49 84 0C 77 5E 79 48 59 DD" + - "5D 0C 77 77 95 CE 91 0C 77 01 00 B4 00 05 00 35" + - "00 0A 00 37 00 37 00 DB 30 C3 30 AB 30 A4 30 C9" + - "30 A6 30 A2 30 AA 30 E2 30 EA 30 B1 30 F3 30 A4" + - "30 EF 30 C6 30 B1 30 F3 30 D5 30 AF 30 B7 30 DE" + - "30 B1 30 F3 30 C8 30 C1 30 AE 30 B1 30 F3 30 B5" + - "30 A4 30 BF 30 DE 30 B1 30 F3 30 C8 30 A6 30 AD" + - "30 E7 30 A6 30 C8 " + - - // Offset=0x00002636(9782) recno=72 sid=0x003C size=0x0151(337) - " 3C 00 51 01 30 C1 30 D0 30 B1" + - "30 F3 30 AB 30 CA 30 AC 30 EF 30 B1 30 F3 30 CA" + - "30 AC 30 CE 30 B1 30 F3 30 00 00 00 00 03 00 06" + - "00 03 00 03 00 0C 00 06 00 03 00 11 00 09 00 03" + - "00 17 00 0C 00 03 00 1C 00 0F 00 03 00 22 00 12" + - "00 03 00 28 00 15 00 03 00 2C 00 18 00 04 00 32" + - "00 1C 00 03 00 32 00 05 10 00 00 00 42 30 44 30" + - "46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30" + - "55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30" + - "66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30" + - "72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30" + - "82 30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30" + - "8D 30 8F 30 92 30 93 30 30 00 30 00 37 00 39 00" + - "01 00 0C 00 05 00 35 00 00 00 00 00 00 00 00 00" + - "32 00 05 10 00 00 00 42 30 44 30 46 30 48 30 4A" + - "30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30 59" + - "30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A" + - "30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78" + - "30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30 86" + - "30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92" + - "30 93 30 30 00 30 00 38 00 30 00 01 00 0C 00 05" + - "00 35 00 00 00 00 00 00 00 4B 30 "; - - - /** - * hex dump from UnicodeStringFailCase2.xls atatched to Bugzilla 50779 - */ - private static final String data_50779_2 = - //"Offset=0x00000612(1554) recno=71 sid=0x00FC size=0x2020(8224)\n" + - " FC 00 20 20 51 00 00 00 51 00 00 00 32 00" + - "01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F" + - "30 51 30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F" + - "30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D" + - "30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F" + - "30 80 30 81 30 82 30 84 30 86 30 88 30 89 30 8A" + - "30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30" + - "00 30 00 31 00 32 00 01 42 30 44 30 46 30 48 30" + - "4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30" + - "59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30" + - "6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30" + - "78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30" + - "86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30" + - "92 30 93 30 30 00 30 00 30 00 32 00 32 00 01 42" + - "30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51" + - "30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61" + - "30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E" + - "30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80" + - "30 81 30 82 30 84 30 86 30 88 30 89 30 8A 30 8B" + - "30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00 30" + - "00 33 00 32 00 01 42 30 44 30 46 30 48 30 4A 30" + - "4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30 59 30" + - "5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30" + - "6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30" + - "7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30 86 30" + - "88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30" + - "93 30 30 00 30 00 30 00 34 00 32 00 01 42 30 44" + - "30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53" + - "30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64" + - "30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F" + - "30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81" + - "30 82 30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C" + - "30 8D 30 8F 30 92 30 93 30 30 00 30 00 30 00 35" + - "00 32 00 01 42 30 44 30 46 30 48 30 4A 30 4B 30" + - "4D 30 4F 30 51 30 53 30 55 30 57 30 59 30 5B 30" + - "5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30" + - "6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30" + - "7E 30 7F 30 80 30 81 30 82 30 84 30 86 30 88 30" + - "89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30" + - "30 00 30 00 30 00 36 00 32 00 01 42 30 44 30 46" + - "30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55" + - "30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66" + - "30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72" + - "30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82" + - "30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D" + - "30 8F 30 92 30 93 30 30 00 30 00 30 00 37 00 32" + - "00 01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30" + - "4F 30 51 30 53 30 55 30 57 30 59 30 5B 30 5D 30" + - "5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30" + - "6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30" + - "7F 30 80 30 81 30 82 30 84 30 86 30 88 30 89 30" + - "8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00" + - "30 00 30 00 38 00 32 00 01 42 30 44 30 46 30 48" + - "30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57" + - "30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68" + - "30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75" + - "30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84" + - "30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F" + - "30 92 30 93 30 30 00 30 00 30 00 39 00 32 00 01" + - "42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30" + - "51 30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30" + - "61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30" + - "6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30" + - "80 30 81 30 82 30 84 30 86 30 88 30 89 30 8A 30" + - "8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00" + - "31 00 30 00 32 00 01 42 30 44 30 46 30 48 30 4A" + - "30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30 59" + - "30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A" + - "30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78" + - "30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30 86" + - "30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92" + - "30 93 30 30 00 30 00 31 00 31 00 32 00 01 42 30" + - "44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30" + - "53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30" + - "64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30" + - "6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30" + - "81 30 82 30 84 30 86 30 88 30 89 30 8A 30 8B 30" + - "8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00 31 00" + - "32 00 32 00 01 42 30 44 30 46 30 48 30 4A 30 4B" + - "30 4D 30 4F 30 51 30 53 30 55 30 57 30 59 30 5B" + - "30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B" + - "30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B" + - "30 7E 30 7F 30 80 30 81 30 82 30 84 30 86 30 88" + - "30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93" + - "30 30 00 30 00 31 00 33 00 32 00 01 42 30 44 30" + - "46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30" + - "55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30" + - "66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30" + - "72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30" + - "82 30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30" + - "8D 30 8F 30 92 30 93 30 30 00 30 00 31 00 34 00" + - "32 00 01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D" + - "30 4F 30 51 30 53 30 55 30 57 30 59 30 5B 30 5D" + - "30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C" + - "30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E" + - "30 7F 30 80 30 81 30 82 30 84 30 86 30 88 30 89" + - "30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30" + - "00 30 00 31 00 35 00 32 00 01 42 30 44 30 46 30" + - "48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30" + - "57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30" + - "68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30" + - "75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30" + - "84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30" + - "8F 30 92 30 93 30 30 00 30 00 31 00 36 00 32 00" + - "01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F" + - "30 51 30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F" + - "30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D" + - "30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F" + - "30 80 30 81 30 82 30 84 30 86 30 88 30 89 30 8A" + - "30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30" + - "00 31 00 37 00 32 00 01 42 30 44 30 46 30 48 30" + - "4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30" + - "59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30" + - "6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30" + - "78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30" + - "86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30" + - "92 30 93 30 30 00 30 00 31 00 38 00 32 00 01 42" + - "30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51" + - "30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61" + - "30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E" + - "30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80" + - "30 81 30 82 30 84 30 86 30 88 30 89 30 8A 30 8B" + - "30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00 31" + - "00 39 00 32 00 01 42 30 44 30 46 30 48 30 4A 30" + - "4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30 59 30" + - "5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30" + - "6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30" + - "7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30 86 30" + - "88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30" + - "93 30 30 00 30 00 32 00 30 00 32 00 01 42 30 44" + - "30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53" + - "30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64" + - "30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F" + - "30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81" + - "30 82 30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C" + - "30 8D 30 8F 30 92 30 93 30 30 00 30 00 32 00 31" + - "00 32 00 01 42 30 44 30 46 30 48 30 4A 30 4B 30" + - "4D 30 4F 30 51 30 53 30 55 30 57 30 59 30 5B 30" + - "5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30" + - "6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30" + - "7E 30 7F 30 80 30 81 30 82 30 84 30 86 30 88 30" + - "89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30" + - "30 00 30 00 32 00 32 00 32 00 01 42 30 44 30 46" + - "30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55" + - "30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66" + - "30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72" + - "30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82" + - "30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D" + - "30 8F 30 92 30 93 30 30 00 30 00 32 00 33 00 32" + - "00 01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30" + - "4F 30 51 30 53 30 55 30 57 30 59 30 5B 30 5D 30" + - "5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30" + - "6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30" + - "7F 30 80 30 81 30 82 30 84 30 86 30 88 30 89 30" + - "8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00" + - "30 00 32 00 34 00 32 00 01 42 30 44 30 46 30 48" + - "30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57" + - "30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68" + - "30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75" + - "30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84" + - "30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F" + - "30 92 30 93 30 30 00 30 00 32 00 35 00 32 00 01" + - "42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30" + - "51 30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30" + - "61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30" + - "6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30" + - "80 30 81 30 82 30 84 30 86 30 88 30 89 30 8A 30" + - "8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00" + - "32 00 36 00 32 00 01 42 30 44 30 46 30 48 30 4A" + - "30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30 59" + - "30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A" + - "30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78" + - "30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30 86" + - "30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92" + - "30 93 30 30 00 30 00 32 00 37 00 32 00 01 42 30" + - "44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30" + - "53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30" + - "64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30" + - "6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30" + - "81 30 82 30 84 30 86 30 88 30 89 30 8A 30 8B 30" + - "8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00 32 00" + - "38 00 32 00 01 42 30 44 30 46 30 48 30 4A 30 4B" + - "30 4D 30 4F 30 51 30 53 30 55 30 57 30 59 30 5B" + - "30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B" + - "30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B" + - "30 7E 30 7F 30 80 30 81 30 82 30 84 30 86 30 88" + - "30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93" + - "30 30 00 30 00 32 00 39 00 32 00 01 42 30 44 30" + - "46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30" + - "55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30" + - "66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30" + - "72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30" + - "82 30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30" + - "8D 30 8F 30 92 30 93 30 30 00 30 00 33 00 30 00" + - "32 00 01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D" + - "30 4F 30 51 30 53 30 55 30 57 30 59 30 5B 30 5D" + - "30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C" + - "30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E" + - "30 7F 30 80 30 81 30 82 30 84 30 86 30 88 30 89" + - "30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30" + - "00 30 00 33 00 31 00 32 00 01 42 30 44 30 46 30" + - "48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30" + - "57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30" + - "68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30" + - "75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30" + - "84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30" + - "8F 30 92 30 93 30 30 00 30 00 33 00 32 00 32 00" + - "01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F" + - "30 51 30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F" + - "30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D" + - "30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F" + - "30 80 30 81 30 82 30 84 30 86 30 88 30 89 30 8A" + - "30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30" + - "00 33 00 33 00 32 00 01 42 30 44 30 46 30 48 30" + - "4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30" + - "59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30" + - "6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30" + - "78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30" + - "86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30" + - "92 30 93 30 30 00 30 00 33 00 34 00 32 00 01 42" + - "30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51" + - "30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61" + - "30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E" + - "30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80" + - "30 81 30 82 30 84 30 86 30 88 30 89 30 8A 30 8B" + - "30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00 33" + - "00 35 00 32 00 01 42 30 44 30 46 30 48 30 4A 30" + - "4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30 59 30" + - "5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30" + - "6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30" + - "7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30 86 30" + - "88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30" + - "93 30 30 00 30 00 33 00 36 00 32 00 01 42 30 44" + - "30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53" + - "30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64" + - "30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F" + - "30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81" + - "30 82 30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C" + - "30 8D 30 8F 30 92 30 93 30 30 00 30 00 33 00 37" + - "00 32 00 01 42 30 44 30 46 30 48 30 4A 30 4B 30" + - "4D 30 4F 30 51 30 53 30 55 30 57 30 59 30 5B 30" + - "5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30" + - "6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30" + - "7E 30 7F 30 80 30 81 30 82 30 84 30 86 30 88 30" + - "89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30" + - "30 00 30 00 33 00 38 00 32 00 01 42 30 44 30 46" + - "30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55" + - "30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66" + - "30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72" + - "30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82" + - "30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D" + - "30 8F 30 92 30 93 30 30 00 30 00 33 00 39 00 32" + - "00 01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30" + - "4F 30 51 30 53 30 55 30 57 30 59 30 5B 30 5D 30" + - "5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30" + - "6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30" + - "7F 30 80 30 81 30 82 30 84 30 86 30 88 30 89 30" + - "8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00" + - "30 00 34 00 30 00 32 00 01 42 30 44 30 46 30 48" + - "30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57" + - "30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68" + - "30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75" + - "30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84" + - "30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F" + - "30 92 30 93 30 30 00 30 00 34 00 31 00 32 00 01" + - "42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30" + - "51 30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30" + - "61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30" + - "6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30" + - "80 30 81 30 82 30 84 30 86 30 88 30 89 30 8A 30" + - "8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00" + - "34 00 32 00 32 00 01 42 30 44 30 46 30 48 30 4A" + - "30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30 59" + - "30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A" + - "30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78" + - "30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30 86" + - "30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92" + - "30 93 30 30 00 30 00 34 00 33 00 32 00 01 42 30" + - "44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30" + - "53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30" + - "64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30" + - "6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30" + - "81 30 82 30 84 30 86 30 88 30 89 30 8A 30 8B 30" + - "8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00 34 00" + - "34 00 32 00 01 42 30 44 30 46 30 48 30 4A 30 4B" + - "30 4D 30 4F 30 51 30 53 30 55 30 57 30 59 30 5B" + - "30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B" + - "30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B" + - "30 7E 30 7F 30 80 30 81 30 82 30 84 30 86 30 88" + - "30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93" + - "30 30 00 30 00 34 00 35 00 32 00 01 42 30 44 30" + - "46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30" + - "55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30" + - "66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30" + - "72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30" + - "82 30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30" + - "8D 30 8F 30 92 30 93 30 30 00 30 00 34 00 36 00" + - "32 00 01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D" + - "30 4F 30 51 30 53 30 55 30 57 30 59 30 5B 30 5D" + - "30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C" + - "30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E" + - "30 7F 30 80 30 81 30 82 30 84 30 86 30 88 30 89" + - "30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30" + - "00 30 00 34 00 37 00 32 00 01 42 30 44 30 46 30" + - "48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30" + - "57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30" + - "68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30" + - "75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30" + - "84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30" + - "8F 30 92 30 93 30 30 00 30 00 34 00 38 00 32 00" + - "01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F" + - "30 51 30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F" + - "30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D" + - "30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F" + - "30 80 30 81 30 82 30 84 30 86 30 88 30 89 30 8A" + - "30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30" + - "00 34 00 39 00 32 00 01 42 30 44 30 46 30 48 30" + - "4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30" + - "59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30" + - "6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30" + - "78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30" + - "86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30" + - "92 30 93 30 30 00 30 00 35 00 30 00 32 00 01 42" + - "30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51" + - "30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61" + - "30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E" + - "30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80" + - "30 81 30 82 30 84 30 86 30 88 30 89 30 8A 30 8B" + - "30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00 35" + - "00 31 00 32 00 01 42 30 44 30 46 30 48 30 4A 30" + - "4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30 59 30" + - "5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30" + - "6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30" + - "7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30 86 30" + - "88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30" + - "93 30 30 00 30 00 35 00 32 00 32 00 01 42 30 44" + - "30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53" + - "30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64" + - "30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F" + - "30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81" + - "30 82 30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C" + - "30 8D 30 8F 30 92 30 93 30 30 00 30 00 35 00 33" + - "00 32 00 01 42 30 44 30 46 30 48 30 4A 30 4B 30" + - "4D 30 4F 30 51 30 53 30 55 30 57 30 59 30 5B 30" + - "5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30" + - "6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30" + - "7E 30 7F 30 80 30 81 30 82 30 84 30 86 30 88 30" + - "89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30" + - "30 00 30 00 35 00 34 00 32 00 01 42 30 44 30 46" + - "30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55" + - "30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66" + - "30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72" + - "30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82" + - "30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D" + - "30 8F 30 92 30 93 30 30 00 30 00 35 00 35 00 32" + - "00 01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30" + - "4F 30 51 30 53 30 55 30 57 30 59 30 5B 30 5D 30" + - "5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30" + - "6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30" + - "7F 30 80 30 81 30 82 30 84 30 86 30 88 30 89 30" + - "8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00" + - "30 00 35 00 36 00 32 00 01 42 30 44 30 46 30 48" + - "30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57" + - "30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68" + - "30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75" + - "30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84" + - "30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F" + - "30 92 30 93 30 30 00 30 00 35 00 37 00 32 00 01" + - "42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30" + - "51 30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30" + - "61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30" + - "6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30" + - "80 30 81 30 82 30 84 30 86 30 88 30 89 30 8A 30" + - "8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00" + - "35 00 38 00 32 00 01 42 30 44 30 46 30 48 30 4A" + - "30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30 59" + - "30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A" + - "30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78" + - "30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30 86" + - "30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92" + - "30 93 30 30 00 30 00 35 00 39 00 32 00 01 42 30" + - "44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30" + - "53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30" + - "64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30" + - "6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30" + - "81 30 82 30 84 30 86 30 88 30 89 30 8A 30 8B 30" + - "8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00 36 00" + - "30 00 32 00 01 42 30 44 30 46 30 48 30 4A 30 4B" + - "30 4D 30 4F 30 51 30 53 30 55 30 57 30 59 30 5B" + - "30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B" + - "30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B" + - "30 7E 30 7F 30 80 30 81 30 82 30 84 30 86 30 88" + - "30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93" + - "30 30 00 30 00 36 00 31 00 32 00 01 42 30 44 30" + - "46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30" + - "55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30" + - "66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30" + - "72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30" + - "82 30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30" + - "8D 30 8F 30 92 30 93 30 30 00 30 00 36 00 32 00" + - "32 00 01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D" + - "30 4F 30 51 30 53 30 55 30 57 30 59 30 5B 30 5D" + - "30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C" + - "30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E" + - "30 7F 30 80 30 81 30 82 30 84 30 86 30 88 30 89" + - "30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30" + - "00 30 00 36 00 33 00 32 00 01 42 30 44 30 46 30" + - "48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30" + - "57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30" + - "68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30" + - "75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30" + - "84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30" + - "8F 30 92 30 93 30 30 00 30 00 36 00 34 00 32 00" + - "01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F" + - "30 51 30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F" + - "30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D" + - "30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F" + - "30 80 30 81 30 82 30 84 30 86 30 88 30 89 30 8A" + - "30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30" + - "00 36 00 35 00 32 00 01 42 30 44 30 46 30 48 30" + - "4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30" + - "59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30" + - "6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30" + - "78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30" + - "86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30" + - "92 30 93 30 30 00 30 00 36 00 36 00 32 00 01 42" + - "30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51" + - "30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61" + - "30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E" + - "30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80" + - "30 81 30 82 30 84 30 86 30 88 30 89 30 8A 30 8B" + - "30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00 36" + - "00 37 00 32 00 01 42 30 44 30 46 30 48 30 4A 30" + - "4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30 59 30" + - "5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30" + - "6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30" + - "7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30 86 30" + - "88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30" + - "93 30 30 00 30 00 36 00 38 00 32 00 01 42 30 44" + - "30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53" + - "30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64" + - "30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F" + - "30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81" + - "30 82 30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C" + - "30 8D 30 8F 30 92 30 93 30 30 00 30 00 36 00 39" + - "00 32 00 01 42 30 44 30 46 30 48 30 4A 30 4B 30" + - "4D 30 4F 30 51 30 53 30 55 30 57 30 59 30 5B 30" + - "5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30" + - "6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30" + - "7E 30 7F 30 80 30 81 30 82 30 84 30 86 30 88 30" + - "89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30" + - "30 00 30 00 37 00 30 00 32 00 01 42 30 44 30 46" + - "30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55" + - "30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66" + - "30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72" + - "30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82" + - "30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D" + - "30 8F 30 92 30 93 30 30 00 30 00 37 00 31 00 32" + - "00 01 42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30" + - "4F 30 51 30 53 30 55 30 57 30 59 30 5B 30 5D 30" + - "5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30" + - "6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30" + - "7F 30 80 30 81 30 82 30 84 30 86 30 88 30 89 30" + - "8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00" + - "30 00 37 00 32 00 32 00 01 42 30 44 30 46 30 48" + - "30 4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57" + - "30 59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68" + - "30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75" + - "30 78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84" + - "30 86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F" + - "30 92 30 93 30 30 00 30 00 37 00 33 00 32 00 01" + - "42 30 44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30" + - "51 30 53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30" + - "61 30 64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30" + - "6E 30 6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30" + - "80 30 81 30 82 30 84 30 86 30 88 30 89 30 8A 30" + - "8B 30 8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00" + - "37 00 34 00 32 00 01 42 30 44 30 46 30 48 30 4A" + - "30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30 59" + - "30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A" + - "30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78" + - "30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30 86" + - "30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92" + - "30 93 30 30 00 30 00 37 00 35 00 32 00 01 42 30" + - "44 30 46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30" + - "53 30 55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30" + - "64 30 66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30" + - "6F 30 72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30" + - "81 30 82 30 84 30 86 30 88 30 89 30 8A 30 8B 30" + - "8C 30 8D 30 8F 30 92 30 93 30 30 00 30 00 37 00" + - "36 00 32 00 01 42 30 44 30 46 30 48 30 4A 30 4B" + - "30 4D 30 4F 30 51 30 53 30 55 30 57 30 59 30 5B" + - "30 5D 30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B" + - "30 6C 30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B" + - "30 7E 30 7F 30 80 30 81 30 82 30 84 30 86 30 88" + - "30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93" + - "30 30 00 30 00 37 00 37 00 32 00 01 42 30 44 30" + - "46 30 48 30 4A 30 4B 30 4D 30 4F 30 51 30 53 30" + - "55 30 57 30 59 30 5B 30 5D 30 5F 30 61 30 64 30" + - "66 30 68 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30" + - "72 30 75 30 78 30 7B 30 7E 30 7F 30 80 30 81 30" + - "82 30 84 30 86 30 88 30 89 30 8A 30 8B 30 8C 30" + - "8D 30 8F 30 92 30 93 30 30 00 30 00 37 00 38 00" + - "18 00 05 96 00 00 00 17 53 77 6D 53 90 52 97 EE" + - "68 0C 77 A9 5C 4B 62 0C 77 8F 79 F6 5C 0C 77 03" + - "68 28 67 0C 77 FC 57 89 73 0C 77 71 67 AC 4E FD" + - "90 43 53 49 84 0C 77 01 00 92 00 05 00 35 00 08" + - "00 2C 00 2C 00 DB 30 C3 30 AB 30 A4 30 C9 30 A6" + - "30 A2 30 AA 30 E2 30 EA 30 B1 30 F3 30 A4 30 EF" + - "30 C6 30 B1 30 F3 30 D5 30 AF 30 B7 30 DE 30 B1" + - "30 F3 30 C8 30 C1 30 AE 30 B1 30 F3 30 B5 30 A4" + - "30 BF 30 DE 30 B1 30 F3 30 C8 30 A6 30 AD 30 E7" + - "30 A6 30 C8 30 C1 30 D0 30 B1 30 F3 30 00 00 00" + - "00 03 00 06 00 03 00 03 00 0C 00 06 00 03 00 11" + - "00 09 00 03 00 17 " + - - //Offset=0x00002636(9782) recno=72 sid=0x003C size=0x010D(269) - " 3C 00 0D 01 00 0C 00 03 00 1C" + - "00 0F 00 03 00 22 00 12 00 03 00 28 00 15 00 03" + - "00 32 00 05 10 00 00 00 42 30 44 30 46 30 48 30" + - "4A 30 4B 30 4D 30 4F 30 51 30 53 30 55 30 57 30" + - "59 30 5B 30 5D 30 5F 30 61 30 64 30 66 30 68 30" + - "6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 72 30 75 30" + - "78 30 7B 30 7E 30 7F 30 80 30 81 30 82 30 84 30" + - "86 30 88 30 89 30 8A 30 8B 30 8C 30 8D 30 8F 30" + - "92 30 93 30 30 00 30 00 37 00 39 00 01 00 0C 00" + - "05 00 35 00 00 00 00 00 00 00 00 00 32 00 05 10" + - "00 00 00 42 30 44 30 46 30 48 30 4A 30 4B 30 4D" + - "30 4F 30 51 30 53 30 55 30 57 30 59 30 5B 30 5D" + - "30 5F 30 61 30 64 30 66 30 68 30 6A 30 6B 30 6C" + - "30 6D 30 6E 30 6F 30 72 30 75 30 78 30 7B 30 7E" + - "30 7F 30 80 30 81 30 82 30 84 30 86 30 88 30 89" + - "30 8A 30 8B 30 8C 30 8D 30 8F 30 92 30 93 30 30" + - "00 30 00 38 00 30 00 01 00 0C 00 05 00 35 00 00" + - "00 00 00 00 00 4B 30 "; - /** * deep comparison of two SST records @@ -1465,17 +342,25 @@ public final class TestSSTRecord { assertEquals("number of strings", expected.getNumStrings(), actual.getNumStrings()); assertEquals("number of unique strings", expected.getNumUniqueStrings(), actual.getNumUniqueStrings()); assertEquals("count of strings", expected.countStrings(), actual.countStrings()); - for ( int k = 0; k < expected.countStrings(); k++ ) { - org.apache.poi.hssf.record.common.UnicodeString us1 = expected.getString(k); - org.apache.poi.hssf.record.common.UnicodeString us2 = actual.getString(k); - assertEquals("String at idx=" + k, us1, us2); + Iterator iterA = expected.getStrings(); + Iterator iterB = actual.getStrings(); + while (iterA.hasNext()) { + assertEquals(iterA.next(), iterB.next()); } } - + @Test - public void test50779_1(){ - byte[] bytes = HexRead.readFromString(data_50779_1); + public void test50779_1() throws IOException { + byte[] bytes = RawDataUtil.decompress("H4sIAAAAAAAAAL3aO2gVQRQG4HO5XkEZ8AESi4DBKoXFP+8IVioSvahcLxKC" + + "iRIRc9FEUZExCL4IYnyQqIi9SEATFUHRTkSQaBFsrEQLG8EiFgGrCM6uIGiff5c5e3ZY9l8W9mt2FqSjoyEixTBSW5kPm7EV29CNHa" + + "hjJ3ajgSb2oge92Id+HMAADuEwWjiCoxjCMI7hOE7iNM7gLM7hPC7gIi5hFJdxBWO4imu4jhsYxy3cBqTYtVRESU28/NnqMFJZ/Fgj" + + "lBjLiXGcGM+JCZyYyInp4sRsZMTo8sshxGhODEUBzVFAcxTQHAU0RwHNUUBzFNAcBQxHAcNRwHAUMBwFDEcBw1HAcBQwHAUMRwHDUc" + + "ByFLAcBSxHActRwHIUsBwFLEcBy1HAchSwHAUcRwHHUcBxFHAcBRxHAcdRwHEUcBwFHEcBx1HAcxTwHAU8RwHPUcBzFPAcBTxHAc9R" + + "wHMU8BwFAkeBwFEgcBQIHAUCR4HAUSBwFAgcBQJHgcBRIHIUiBwFIkeByFEgchSIHAUiR4HIUSBmBdZJ7aWItDXTcHNiz925lkoP+u" + + "oHVRof+dmnUrXVOajSQs/YKZVODE7v+jWxpbl9VKX9I929n/tVSndmb6pUkWfl//Tl5ZN/whtM4T7eYRL38BBf8R1PMZ9nfuBt2X3E" + + "E7zAl7KfwWs8Lrvn+YpXf2cn8Qjfcp3ZJI1KvuZDOT+F95jO9yn6opstu+IvflWW5lEVVR5XybJc2/JZVdplRa7rZXWunbIm1w2yVp" + + "bkN9yee9Kyg5gp/HfZAW3FQ1ce/694+A14Ha5/eSEAAA=="); RecordInputStream in = TestcaseRecordInputStream.create(bytes); assertEquals(SSTRecord.sid, in.getSid()); @@ -1493,8 +378,15 @@ public final class TestSSTRecord { } @Test - public void test50779_2() { - byte[] bytes = HexRead.readFromString(data_50779_2); + public void test50779_2() throws IOException { + byte[] bytes = RawDataUtil.decompress("H4sIAAAAAAAAAL3Uu2sVQRjG4e9wOKKw4gUkKSyCVQqLd2d2ZhOwiiLqQSUe" + + "JIgRUcQc1ERUZBXBG0GMFxIiaC8S8I6FWIoIop2NlWBhI1hoIVhFcM6Cgn+Avx3m2+HbXd5hYJ9FGxgYNbPedNYY0SZt1hZtU1vbtV" + + "Oj6mi3xrRHe7VP+3VAh3RYXR3RUR3TpKZ0XCd1Wmd0Tud1QRd1SZc1rSu6qhld03Xd0E3Nal63JOuNnIlxTIxnYgomJjAxkYkpmZgh" + + "JmaYiMnrPweIQRTIGQVyRoGcUSBnFMgZBXJGgZxRIGcUcIwCjlHAMQo4RgHHKOAYBRyjgGMUcIwCjlHAMwp4RgHPKOAZBTyjgGcU8I" + + "wCnlHAMwp4RoGCUaBgFCgYBQpGgYJRoGAUKBgFCkaBglGgYBQIjAKBUSAwCgRGgcAoEBgFAqNAYBQIjAKBUSAyCkRGgcgoEBkFIqNA" + + "ZBSIjAKRUSAyCkRGgZJRoGQUKBkFSkaBklGgZBQoGQVKRoEyKdBvrdtm1tepJjtzu+5862bV/fH2wayaPftzPKua3cGJrFocmzmVVS" + + "cmHu34Nbexs3U6qxo2b6105kttfRof9VoPdU/vtKC7eqDP+qpn+pE63/WmXn3QU73Qp3r9Vq/0pF49T2+8/Ntd0GN9SbX3/H3dSxuz" + + "pi1Js2lZfV9ly1Lt22DLG6nTtLW2ItV1tjrVQVuTqrPWyvTZ/z+7YettoXcIfy4oeijNf6Pb+g0SIvVzNSEAAA=="); RecordInputStream in = TestcaseRecordInputStream.create(bytes); assertEquals(SSTRecord.sid, in.getSid()); @@ -1519,6 +411,6 @@ public final class TestSSTRecord { SSTRecord src = new SSTRecord(in); assertEquals(0, src.getNumStrings()); assertEquals(0, src.getNumUniqueStrings()); - + } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestSSTRecordSizeCalculator.java b/src/testcases/org/apache/poi/hssf/record/TestSSTRecordSizeCalculator.java index e024f67af4..e9dd0798fa 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestSSTRecordSizeCalculator.java +++ b/src/testcases/org/apache/poi/hssf/record/TestSSTRecordSizeCalculator.java @@ -17,18 +17,18 @@ package org.apache.poi.hssf.record; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + import org.apache.poi.hssf.record.common.UnicodeString; import org.apache.poi.hssf.record.cont.ContinuableRecordOutput; import org.apache.poi.util.IntMapper; import org.apache.poi.util.LittleEndianConsts; +import org.junit.Test; /** * Tests that records size calculates correctly. - * - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestSSTRecordSizeCalculator extends TestCase { +public final class TestSSTRecordSizeCalculator { private static final String SMALL_STRING = "Small string"; private static final int COMPRESSED_PLAIN_STRING_OVERHEAD = 3; private static final int OPTION_FIELD_SIZE = 1; @@ -53,6 +53,7 @@ public final class TestSSTRecordSizeCalculator extends TestCase { assertEquals(expectedSize, cro.getTotalSize()); } + @Test public void testBasic() { strings.add(makeUnicodeString(SMALL_STRING)); confirmSize(SST_RECORD_OVERHEAD @@ -60,6 +61,7 @@ public final class TestSSTRecordSizeCalculator extends TestCase { + SMALL_STRING.length()); } + @Test public void testBigStringAcrossUnicode() { int bigString = MAX_DATA_SPACE + 100; strings.add(makeUnicodeString(bigString)); @@ -71,6 +73,7 @@ public final class TestSSTRecordSizeCalculator extends TestCase { + 100); } + @Test public void testPerfectFit() { int perfectFit = MAX_DATA_SPACE - COMPRESSED_PLAIN_STRING_OVERHEAD; strings.add(makeUnicodeString(perfectFit)); @@ -79,6 +82,7 @@ public final class TestSSTRecordSizeCalculator extends TestCase { + perfectFit); } + @Test public void testJustOversized() { int tooBig = MAX_DATA_SPACE - COMPRESSED_PLAIN_STRING_OVERHEAD + 1; strings.add(makeUnicodeString(tooBig)); @@ -91,6 +95,7 @@ public final class TestSSTRecordSizeCalculator extends TestCase { } + @Test public void testSecondStringStartsOnNewContinuation() { int perfectFit = MAX_DATA_SPACE - COMPRESSED_PLAIN_STRING_OVERHEAD; strings.add(makeUnicodeString(perfectFit)); @@ -103,6 +108,7 @@ public final class TestSSTRecordSizeCalculator extends TestCase { + SMALL_STRING.length()); } + @Test public void testHeaderCrossesNormalContinuePoint() { int almostPerfectFit = MAX_DATA_SPACE - COMPRESSED_PLAIN_STRING_OVERHEAD - 2; strings.add(makeUnicodeString(almostPerfectFit)); @@ -117,6 +123,7 @@ public final class TestSSTRecordSizeCalculator extends TestCase { + oneCharString.length()); } + private static UnicodeString makeUnicodeString(int size) { String s = new String(new char[size]); return makeUnicodeString(s); diff --git a/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java b/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java index b061221fb4..a5cc315975 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java @@ -17,27 +17,31 @@ package org.apache.poi.hssf.record; -import junit.framework.AssertionFailedError; -import junit.framework.ComparisonFailure; -import junit.framework.TestCase; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import java.util.stream.Stream; import org.apache.poi.hssf.HSSFTestDataSamples; -import org.apache.poi.ss.formula.ptg.Ptg; -import org.apache.poi.ss.formula.ptg.RefPtg; -import org.apache.poi.ss.formula.SharedFormula; -import org.apache.poi.hssf.usermodel.*; -import org.apache.poi.ss.usermodel.CellType; -import org.apache.poi.ss.usermodel.CellValue; +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook; +import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.formula.FormulaParser; import org.apache.poi.ss.formula.FormulaRenderer; import org.apache.poi.ss.formula.FormulaType; -import org.apache.poi.ss.SpreadsheetVersion; +import org.apache.poi.ss.formula.SharedFormula; +import org.apache.poi.ss.formula.ptg.Ptg; +import org.apache.poi.ss.formula.ptg.RefPtg; +import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.CellValue; import org.apache.poi.util.LittleEndianInput; +import org.junit.Test; -/** - * @author Josh Micich - */ -public final class TestSharedFormulaRecord extends TestCase { +public final class TestSharedFormulaRecord { /** * A sample spreadsheet known to have one sheet with 4 shared formula ranges @@ -71,6 +75,7 @@ public final class TestSharedFormulaRecord extends TestCase { * classes are preserved during this transformation, because Excel may not tolerate the * incorrect encoding. The formula here is one such example (Excel displays #VALUE!). */ + @Test public void testConvertSharedFormulasOperandClasses_bug45123() { LittleEndianInput in = TestcaseRecordInputStream.createLittleEndian(SHARED_FORMULA_WITH_REF_ARRAYS_DATA); @@ -82,25 +87,17 @@ public final class TestSharedFormulaRecord extends TestCase { RefPtg refPtg = (RefPtg) convertedFormula[1]; assertEquals("$C101", refPtg.toFormulaString()); - if (refPtg.getPtgClass() == Ptg.CLASS_REF) { - throw new AssertionFailedError("Identified bug 45123"); - } - + assertNotEquals("Identified bug 45123", Ptg.CLASS_REF, refPtg.getPtgClass()); confirmOperandClasses(sharedFormula, convertedFormula); } private static void confirmOperandClasses(Ptg[] originalPtgs, Ptg[] convertedPtgs) { - assertEquals(originalPtgs.length, convertedPtgs.length); - for (int i = 0; i < convertedPtgs.length; i++) { - Ptg originalPtg = originalPtgs[i]; - Ptg convertedPtg = convertedPtgs[i]; - if (originalPtg.getPtgClass() != convertedPtg.getPtgClass()) { - throw new ComparisonFailure("Different operand class for token[" + i + "]", - String.valueOf(originalPtg.getPtgClass()), String.valueOf(convertedPtg.getPtgClass())); - } - } + int[] exp = Stream.of(originalPtgs).map(Ptg::getPtgClass).mapToInt(Byte::intValue).toArray(); + int[] act = Stream.of(convertedPtgs).map(Ptg::getPtgClass).mapToInt(Byte::intValue).toArray(); + assertArrayEquals("Different operand class", exp, act); } + @Test public void testConvertSharedFormulas() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFEvaluationWorkbook fpb = HSSFEvaluationWorkbook.create(wb); @@ -141,6 +138,7 @@ public final class TestSharedFormulaRecord extends TestCase { /** * Make sure that POI preserves {@link SharedFormulaRecord}s */ + @Test public void testPreserveOnReserialize() { HSSFWorkbook wb; HSSFSheet sheet; @@ -168,10 +166,12 @@ public final class TestSharedFormulaRecord extends TestCase { cellB32769 = sheet.getRow(32768).getCell(1); cellC32769 = sheet.getRow(32768).getCell(2); assertEquals("B32770*2", cellB32769.getCellFormula()); + assertEquals("C32770*2", cellC32769.getCellFormula()); confirmCellEvaluation(wb, cellB32769, 4); assertEquals(4, countSharedFormulas(sheet)); } + @Test public void testUnshareFormulaDueToChangeFormula() { HSSFWorkbook wb; HSSFSheet sheet; @@ -192,6 +192,8 @@ public final class TestSharedFormulaRecord extends TestCase { assertEquals("C32770*2", cellC32769.getCellFormula()); confirmCellEvaluation(wb, cellC32769, 6); } + + @Test public void testUnshareFormulaDueToDelete() { HSSFWorkbook wb; HSSFSheet sheet; @@ -236,13 +238,8 @@ public final class TestSharedFormulaRecord extends TestCase { * @return the number of {@link SharedFormulaRecord}s encoded for the specified sheet */ private static int countSharedFormulas(HSSFSheet sheet) { - Record[] records = RecordInspector.getRecords(sheet, 0); - int count = 0; - for (Record rec : records) { - if(rec instanceof SharedFormulaRecord) { - count++; - } - } - return count; + int[] count = { 0 }; + sheet.getSheet().visitContainedRecords(r -> count[0] += r instanceof SharedFormulaRecord ? 1 : 0, 0); + return count[0]; } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestStyleRecord.java b/src/testcases/org/apache/poi/hssf/record/TestStyleRecord.java index 890546c94c..0860d248b3 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestStyleRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestStyleRecord.java @@ -17,30 +17,24 @@ package org.apache.poi.hssf.record; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; import org.apache.poi.util.HexRead; +import org.junit.Test; /** * Tests for {@link StyleRecord} */ -public final class TestStyleRecord extends TestCase { +public final class TestStyleRecord { + @Test public void testUnicodeReadName() { byte[] data = HexRead.readFromString( "11 00 09 00 01 38 5E C4 89 5F 00 53 00 68 00 65 00 65 00 74 00 31 00"); RecordInputStream in = TestcaseRecordInputStream.create(StyleRecord.sid, data); StyleRecord sr = new StyleRecord(in); assertEquals("\u5E38\u89C4_Sheet1", sr.getName()); // "_Sheet1" - byte[] ser; - try { - ser = sr.serialize(); - } catch (IllegalStateException e) { - if (e.getMessage().equals("Incorrect number of bytes written - expected 27 but got 18")) { - throw new AssertionFailedError("Identified bug 46385"); - } - throw e; - } + // bug 46385 - Incorrect number of bytes written - expected 27 but got 18 + byte[] ser = sr.serialize(); TestcaseRecordInputStream.confirmRecordEncoding(StyleRecord.sid, data, ser); } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestSubRecord.java b/src/testcases/org/apache/poi/hssf/record/TestSubRecord.java index edf19f81ef..468a50c3e2 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestSubRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestSubRecord.java @@ -20,21 +20,18 @@ package org.apache.poi.hssf.record; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import org.apache.poi.util.HexRead; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.RecordFormatException; - -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import org.junit.Test; /** * Tests Subrecord components of an OBJ record. Test data taken directly * from a real Excel file. - * - * @author Michael Zalewski (zalewski@optonline.net) */ -public final class TestSubRecord extends TestCase { +public final class TestSubRecord { /* The following is a dump of the OBJ record corresponding to an auto-filter drop-down list. The 3rd subrecord beginning at offset 0x002e (type=0x0013) @@ -51,7 +48,7 @@ public final class TestSubRecord extends TestCase { 00 00 00 00 l..... Type=0x00 Len=0x0000 ftEnd */ - private static final byte[] dataAutoFilter + private static final byte[] dataAutoFilter = HexRead.readFromString("" + "5D 00 46 00 " // ObjRecord.sid, size=70 // ftCmo @@ -71,20 +68,20 @@ public final class TestSubRecord extends TestCase { /** * Make sure that ftLbsData (which has abnormal size info) is parsed correctly. * If the size field is interpreted incorrectly, the resulting ObjRecord becomes way too big. - * At the time of fixing (Oct-2008 svn r707447) {@link RecordInputStream} allowed buffer + * At the time of fixing (Oct-2008 svn r707447) {@link RecordInputStream} allowed buffer * read overruns, so the bug was mostly silent. */ + @Test public void testReadAll_bug45778() { RecordInputStream in = TestcaseRecordInputStream.create(dataAutoFilter); ObjRecord or = new ObjRecord(in); byte[] data2 = or.serialize(); - if (data2.length == 8228) { - throw new AssertionFailedError("Identified bug 45778"); - } + assertNotEquals("Identified bug 45778", 8228, data2.length); assertEquals(74, data2.length); assertArrayEquals(dataAutoFilter, data2); } - + + @Test public void testReadManualComboWithFormula() { byte[] data = HexRead.readFromString("" + "5D 00 66 00 " @@ -96,35 +93,29 @@ public final class TestSubRecord extends TestCase { + "00 02 00 02 00 02 06 00 03 00 08 00 00 00 00 00 " + "08 00 00 00 00 00 00 00 " // TODO sometimes last byte is non-zero ); - + RecordInputStream in = TestcaseRecordInputStream.create(data); ObjRecord or = new ObjRecord(in); byte[] data2 = or.serialize(); - if (data2.length == 8228) { - throw new AssertionFailedError("Identified bug 45778"); - } + assertNotEquals("Identified bug 45778", 8228, data2.length); assertEquals("Encoded length", data.length, data2.length); - for (int i = 0; i < data.length; i++) { - if (data[i] != data2[i]) { - throw new AssertionFailedError("Encoded data differs at index " + i); - } - } - assertArrayEquals(data, data2); + assertArrayEquals("Encoded data differs", data, data2); } /** - * Some versions of POI (e.g. 3.1 - prior to svn r707450 / bug 45778) interpreted the ftLbs - * subrecord second short (0x1FEE) as a length, and hence read lots of extra padding. This + * Some versions of POI (e.g. 3.1 - prior to svn r707450 / bug 45778) interpreted the ftLbs + * subrecord second short (0x1FEE) as a length, and hence read lots of extra padding. This * buffer-overrun in {@link RecordInputStream} happened silently due to problems later fixed - * in svn 707778. When the ObjRecord is written, the extra padding is written too, making the - * record 8224 bytes long instead of 70. + * in svn 707778. When the ObjRecord is written, the extra padding is written too, making the + * record 8224 bytes long instead of 70. * (An aside: It seems more than a coincidence that this problem creates a record of exactly - * {@link RecordInputStream#MAX_RECORD_DATA_SIZE} but not enough is understood about + * {@link RecordInputStream#MAX_RECORD_DATA_SIZE} but not enough is understood about * subrecords to explain this.)
- * + * * Excel reads files with this excessive padding OK. It also truncates the over-sized * ObjRecord back to the proper size. POI should do the same. */ + @Test public void testWayTooMuchPadding_bug46545() { byte[] data = HexRead.readFromString("" + "15 00 12 00 14 00 13 00 01 21 00 00 00" @@ -143,18 +134,11 @@ public final class TestSubRecord extends TestCase { int wrongTotalSize = LBS_START_POS + 4 + WRONG_LBS_SIZE; byte[] wrongData = new byte[wrongTotalSize]; System.arraycopy(data, 0, wrongData, 0, data.length); - // wrongData has the ObjRecord data as would have been written by v3.1 - + // wrongData has the ObjRecord data as would have been written by v3.1 + RecordInputStream in = TestcaseRecordInputStream.create(ObjRecord.sid, wrongData); - ObjRecord or; - try { - or = new ObjRecord(in); - } catch (RecordFormatException e) { - if (e.getMessage().startsWith("Leftover 8154 bytes in subrecord data")) { - throw new AssertionFailedError("Identified bug 46545"); - } - throw e; - } + // bug 46545 - Leftover 8154 bytes in subrecord data + ObjRecord or = new ObjRecord(in); // make sure POI properly truncates the ObjRecord data byte[] data2 = or.serialize(); TestcaseRecordInputStream.confirmRecordEncoding(ObjRecord.sid, data, data2); diff --git a/src/testcases/org/apache/poi/hssf/record/TestSupBookRecord.java b/src/testcases/org/apache/poi/hssf/record/TestSupBookRecord.java index 47926cfe06..ebe818d231 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestSupBookRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestSupBookRecord.java @@ -18,17 +18,24 @@ package org.apache.poi.hssf.record; -import junit.framework.TestCase; +import static org.apache.poi.hssf.record.SupBookRecord.CH_ALT_STARTUP_DIR; +import static org.apache.poi.hssf.record.SupBookRecord.CH_DOWN_DIR; +import static org.apache.poi.hssf.record.SupBookRecord.CH_LIB_DIR; +import static org.apache.poi.hssf.record.SupBookRecord.CH_SAME_VOLUME; +import static org.apache.poi.hssf.record.SupBookRecord.CH_STARTUP_DIR; +import static org.apache.poi.hssf.record.SupBookRecord.CH_UP_DIR; +import static org.apache.poi.hssf.record.SupBookRecord.CH_VOLUME; +import static org.apache.poi.hssf.record.SupBookRecord.PATH_SEPERATOR; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; -import static org.apache.poi.hssf.record.SupBookRecord.*; +import org.junit.Test; /** * Tests the serialization and deserialization of the SupBook record - * class works correctly. - * - * @author Andrew C. Oliver (acoliver at apache dot org) + * class works correctly. */ -public final class TestSupBookRecord extends TestCase { +public final class TestSupBookRecord { /** * This contains a fake data section of a SubBookRecord */ @@ -40,64 +47,66 @@ public final class TestSupBookRecord extends TestCase { }; byte[] dataER = new byte[] { (byte)0x02,(byte)0x00, - (byte)0x07,(byte)0x00, (byte)0x00, - (byte)'t', (byte)'e', (byte)'s', (byte)'t', (byte)'U', (byte)'R', (byte)'L', - (byte)0x06,(byte)0x00, (byte)0x00, - (byte)'S', (byte)'h', (byte)'e', (byte)'e', (byte)'t', (byte)'1', - (byte)0x06,(byte)0x00, (byte)0x00, - (byte)'S', (byte)'h', (byte)'e', (byte)'e', (byte)'t', (byte)'2', + (byte)0x07,(byte)0x00, (byte)0x00, + (byte)'t', (byte)'e', (byte)'s', (byte)'t', (byte)'U', (byte)'R', (byte)'L', + (byte)0x06,(byte)0x00, (byte)0x00, + (byte)'S', (byte)'h', (byte)'e', (byte)'e', (byte)'t', (byte)'1', + (byte)0x06,(byte)0x00, (byte)0x00, + (byte)'S', (byte)'h', (byte)'e', (byte)'e', (byte)'t', (byte)'2', }; /** * tests that we can load the record */ + @Test public void testLoadIR() { - - SupBookRecord record = new SupBookRecord(TestcaseRecordInputStream.create(0x01AE, dataIR)); + SupBookRecord record = new SupBookRecord(TestcaseRecordInputStream.create(0x01AE, dataIR)); assertTrue( record.isInternalReferences() ); //expected flag assertEquals( 0x4, record.getNumberOfSheets() ); //expected # of sheets assertEquals( 8, record.getRecordSize() ); //sid+size+data } + /** * tests that we can load the record */ + @Test public void testLoadER() { - - SupBookRecord record = new SupBookRecord(TestcaseRecordInputStream.create(0x01AE, dataER)); + SupBookRecord record = new SupBookRecord(TestcaseRecordInputStream.create(0x01AE, dataER)); assertTrue( record.isExternalReferences() ); //expected flag assertEquals( 0x2, record.getNumberOfSheets() ); //expected # of sheets assertEquals( 34, record.getRecordSize() ); //sid+size+data - + assertEquals("testURL", record.getURL()); String[] sheetNames = record.getSheetNames(); assertEquals(2, sheetNames.length); assertEquals("Sheet1", sheetNames[0]); assertEquals("Sheet2", sheetNames[1]); } - + /** * tests that we can load the record */ + @Test public void testLoadAIF() { - - SupBookRecord record = new SupBookRecord(TestcaseRecordInputStream.create(0x01AE, dataAIF)); + SupBookRecord record = new SupBookRecord(TestcaseRecordInputStream.create(0x01AE, dataAIF)); assertTrue( record.isAddInFunctions() ); //expected flag assertEquals( 0x1, record.getNumberOfSheets() ); //expected # of sheets assertEquals( 8, record.getRecordSize() ); //sid+size+data } - + /** * Tests that we can store the record - * */ + @Test public void testStoreIR() { SupBookRecord record = SupBookRecord.createInternalReferences((short)4); TestcaseRecordInputStream.confirmRecordEncoding(0x01AE, dataIR, record.serialize()); - } - + } + + @Test public void testStoreER() { String url = "testURL"; String[] sheetNames = { "Sheet1", "Sheet2", }; @@ -106,26 +115,28 @@ public final class TestSupBookRecord extends TestCase { TestcaseRecordInputStream.confirmRecordEncoding(0x01AE, dataER, record.serialize()); } + @Test public void testStoreAIF() { SupBookRecord record = SupBookRecord.createAddInFunctions(); assertEquals(1, record.getNumberOfSheets()); assertTrue(record.isAddInFunctions()); TestcaseRecordInputStream.confirmRecordEncoding(0x01AE, dataAIF, record.serialize()); } - + + @Test public void testExternalReferenceUrl() { String[] sheetNames = new String[]{"SampleSheet"}; final char startMarker = (char)1; - + SupBookRecord record; - + record = new SupBookRecord(startMarker + "test.xls", sheetNames); assertEquals("test.xls", record.getURL()); //UNC path notation record = new SupBookRecord(startMarker + "" + CH_VOLUME + "@servername" + CH_DOWN_DIR + "test.xls", sheetNames); assertEquals("\\\\servername" + PATH_SEPERATOR + "test.xls", record.getURL()); - + //Absolute path notation - different device record = new SupBookRecord(startMarker + "" + CH_VOLUME + "D" + CH_DOWN_DIR + "test.xls", sheetNames); assertEquals("D:" + PATH_SEPERATOR + "test.xls", record.getURL()); @@ -133,11 +144,11 @@ public final class TestSupBookRecord extends TestCase { //Absolute path notation - same device record = new SupBookRecord(startMarker + "" + CH_SAME_VOLUME + "folder" + CH_DOWN_DIR + "test.xls", sheetNames); assertEquals(PATH_SEPERATOR + "folder" + PATH_SEPERATOR + "test.xls", record.getURL()); - + //Relative path notation - down record = new SupBookRecord(startMarker + "folder" + CH_DOWN_DIR + "test.xls", sheetNames); assertEquals("folder" + PATH_SEPERATOR + "test.xls", record.getURL()); - + //Relative path notation - up record = new SupBookRecord(startMarker +""+ CH_UP_DIR + "test.xls", sheetNames); assertEquals(".." + PATH_SEPERATOR + "test.xls", record.getURL()); diff --git a/src/testcases/org/apache/poi/hssf/record/TestTableRecord.java b/src/testcases/org/apache/poi/hssf/record/TestTableRecord.java index 3a2ada6e78..3c7e7469b9 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestTableRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestTableRecord.java @@ -17,21 +17,23 @@ package org.apache.poi.hssf.record; -import org.apache.poi.hssf.util.CellRangeAddress8Bit; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.apache.poi.hssf.util.CellRangeAddress8Bit; +import org.junit.Test; /** * Tests the serialization and deserialization of the TableRecord * class works correctly. Test data taken directly from a real * Excel file. */ -public final class TestTableRecord extends TestCase { +public final class TestTableRecord { byte[] header = new byte[] { 0x36, 02, 0x10, 00, // sid=x236, 16 bytes long }; byte[] data = new byte[] { - 03, 00, // from row 3 + 03, 00, // from row 3 8, 00, // to row 8 04, // from col 4 06, // to col 6 @@ -42,6 +44,7 @@ public final class TestTableRecord extends TestCase { 00, 00 // col inp col 0 }; + @Test public void testLoad() { TableRecord record = new TableRecord(TestcaseRecordInputStream.create(0x236, data)); @@ -60,6 +63,7 @@ public final class TestTableRecord extends TestCase { assertEquals( 16 + 4, record.getRecordSize() ); } + @Test public void testStore() { // Offset 0x3bd9 (15321) @@ -87,8 +91,6 @@ public final class TestTableRecord extends TestCase { record.setColInputCol(0); byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(TableRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestTextObjectBaseRecord.java b/src/testcases/org/apache/poi/hssf/record/TestTextObjectBaseRecord.java index f149636bd0..dd327048b7 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestTextObjectBaseRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestTextObjectBaseRecord.java @@ -18,19 +18,20 @@ package org.apache.poi.hssf.record; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import org.apache.poi.hssf.usermodel.HSSFRichTextString; import org.apache.poi.util.HexRead; - -import junit.framework.TestCase; +import org.junit.Test; /** * Tests the serialization and deserialization of the TextObjectBaseRecord * class works correctly. Test data taken directly from a real * Excel file. - * - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestTextObjectBaseRecord extends TestCase { +public final class TestTextObjectBaseRecord { /** data for one TXO rec and two continue recs */ private static final byte[] data = HexRead.readFromString( "B6 01 " + // TextObjectRecord.sid @@ -51,6 +52,7 @@ public final class TestTextObjectBaseRecord extends TestCase { "02 00 00 00 00 00 00 00 " ); + @Test public void testLoad() { RecordInputStream in = TestcaseRecordInputStream.create(data); TextObjectRecord record = new TextObjectRecord(in); @@ -63,6 +65,7 @@ public final class TestTextObjectBaseRecord extends TestCase { assertEquals(49, record.getRecordSize() ); } + @Test public void testStore() { TextObjectRecord record = new TextObjectRecord(); @@ -77,8 +80,6 @@ public final class TestTextObjectBaseRecord extends TestCase { record.setStr(str); byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i]); + assertArrayEquals(data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java b/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java index 77449ca640..2b57c2fc03 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java @@ -18,15 +18,17 @@ package org.apache.poi.hssf.record; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import java.io.ByteArrayInputStream; -import junit.framework.TestCase; import org.apache.poi.hssf.usermodel.HSSFRichTextString; import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.formula.ptg.RefPtg; import org.apache.poi.util.HexRead; import org.apache.poi.util.LittleEndian; +import org.junit.Test; /** * Tests that serialization and deserialization of the TextObjectRecord . @@ -34,7 +36,7 @@ import org.apache.poi.util.LittleEndian; * * @author Yegor Kozlov */ -public final class TestTextObjectRecord extends TestCase { +public final class TestTextObjectRecord { private static final byte[] simpleData = HexRead.readFromString( "B6 01 12 00 " + @@ -47,7 +49,7 @@ public final class TestTextObjectRecord extends TestCase { "00 0D 00 00 00 00 00 00 00" ); - + @Test public void testRead() { RecordInputStream is =TestcaseRecordInputStream.create(simpleData); @@ -60,6 +62,7 @@ public final class TestTextObjectRecord extends TestCase { assertEquals("Hello, World!", record.getStr().getString()); } + @Test public void testWrite() { HSSFRichTextString str = new HSSFRichTextString("Hello, World!"); @@ -78,11 +81,13 @@ public final class TestTextObjectRecord extends TestCase { //read again RecordInputStream is = TestcaseRecordInputStream.create(simpleData); record = new TextObjectRecord(is); + assertNotNull(record); } /** * Zero {@link ContinueRecord}s follow a {@link TextObjectRecord} if the text is empty */ + @Test public void testWriteEmpty() { HSSFRichTextString str = new HSSFRichTextString(""); @@ -105,6 +110,7 @@ public final class TestTextObjectRecord extends TestCase { /** * Test that TextObjectRecord serializes logs records properly. */ + @Test public void testLongRecords() { int[] lengths = {1024, 2048, 4096, 8192, 16384}; //test against strings of different length for (int length : lengths) { @@ -131,6 +137,7 @@ public final class TestTextObjectRecord extends TestCase { /** * Test cloning */ + @Test public void testClone() { String text = "Hello, World"; HSSFRichTextString str = new HSSFRichTextString(text); @@ -175,7 +182,7 @@ public final class TestTextObjectRecord extends TestCase { "02 00 00 00 00 00 00 00 " ); - + @Test public void testLinkFormula() { RecordInputStream is = new RecordInputStream(new ByteArrayInputStream(linkData)); is.nextRecord(); diff --git a/src/testcases/org/apache/poi/hssf/record/TestUnicodeNameRecord.java b/src/testcases/org/apache/poi/hssf/record/TestUnicodeNameRecord.java index 6ec0803849..03e3a17919 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestUnicodeNameRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestUnicodeNameRecord.java @@ -18,19 +18,23 @@ package org.apache.poi.hssf.record; -import junit.framework.TestCase; +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; import org.apache.poi.hssf.HSSFTestDataSamples; +import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; -/** - * - */ -public final class TestUnicodeNameRecord extends TestCase { +import org.junit.Test; - public void testReadBook() { +public final class TestUnicodeNameRecord { + @Test + public void testReadBook() throws IOException { // This bit used to crash - HSSFWorkbook book = HSSFTestDataSamples.openSampleWorkbook("unicodeNameRecord.xls"); - book.getSheetAt(0); + try (HSSFWorkbook book = HSSFTestDataSamples.openSampleWorkbook("unicodeNameRecord.xls")) { + HSSFSheet sheet = book.getSheetAt(0); + assertNotNull(sheet); + } } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestWriteAccessRecord.java b/src/testcases/org/apache/poi/hssf/record/TestWriteAccessRecord.java index 0cb94c32ec..9672cce6c3 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestWriteAccessRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestWriteAccessRecord.java @@ -17,18 +17,15 @@ package org.apache.poi.hssf.record; -import org.apache.poi.util.HexRead; -import org.apache.poi.util.RecordFormatException; +import static org.junit.Assert.assertEquals; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import org.apache.poi.util.HexRead; +import org.junit.Test; /** * Tests for {@link WriteAccessRecord} - * - * @author Josh Micich */ -public final class TestWriteAccessRecord extends TestCase { +public final class TestWriteAccessRecord { private static final String HEX_SIXTYFOUR_SPACES = "" + "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 " @@ -36,7 +33,7 @@ public final class TestWriteAccessRecord extends TestCase { + "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 " + "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20"; - + @Test public void testMissingStringHeader_bug47001a() { /* * Data taken from offset 0x0224 in @@ -52,15 +49,8 @@ public final class TestWriteAccessRecord extends TestCase { RecordInputStream in = TestcaseRecordInputStream.create(data); - WriteAccessRecord rec; - try { - rec = new WriteAccessRecord(in); - } catch (RecordFormatException e) { - if (e.getMessage().equals("Not enough data (0) to read requested (1) bytes")) { - throw new AssertionFailedError("Identified bug 47001a"); - } - throw e; - } + // bug 47001a - Not enough data (0) to read requested (1) bytes + WriteAccessRecord rec = new WriteAccessRecord(in); assertEquals("Java Excel API v2.6.4", rec.getUsername()); @@ -74,6 +64,7 @@ public final class TestWriteAccessRecord extends TestCase { TestcaseRecordInputStream.confirmRecordEncoding(WriteAccessRecord.sid, expectedEncoding, rec.serialize()); } + @Test public void testShortRecordWrittenByMSAccess() { /* * Data taken from two example files diff --git a/src/testcases/org/apache/poi/hssf/record/TestcaseRecordInputStream.java b/src/testcases/org/apache/poi/hssf/record/TestcaseRecordInputStream.java index 3fc80407e9..f528ddb1e3 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestcaseRecordInputStream.java +++ b/src/testcases/org/apache/poi/hssf/record/TestcaseRecordInputStream.java @@ -17,13 +17,12 @@ package org.apache.poi.hssf.record; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + import java.io.ByteArrayInputStream; import java.io.InputStream; -import junit.framework.Assert; -import junit.framework.AssertionFailedError; - -import org.apache.poi.util.HexDump; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianByteArrayInputStream; import org.apache.poi.util.LittleEndianInput; @@ -74,8 +73,7 @@ public final class TestcaseRecordInputStream { * @param expectedData - just raw data (without sid or size short ints) * @param actualRecordBytes this includes 4 prefix bytes (sid & size) */ - public static void confirmRecordEncoding(int expectedSid, byte[] expectedData, byte[] actualRecordBytes) - throws AssertionFailedError { + public static void confirmRecordEncoding(int expectedSid, byte[] expectedData, byte[] actualRecordBytes) { confirmRecordEncoding(null, expectedSid, expectedData, actualRecordBytes); } /** @@ -84,22 +82,22 @@ public final class TestcaseRecordInputStream { * @param expectedData - just raw data (without ushort sid, ushort size) * @param actualRecordBytes this includes 4 prefix bytes (sid & size) */ - public static void confirmRecordEncoding(String msgPrefix, int expectedSid, byte[] expectedData, byte[] actualRecordBytes) - throws AssertionFailedError { + public static void confirmRecordEncoding(String msgPrefix, int expectedSid, byte[] expectedData, byte[] actualRecordBytes) { int expectedDataSize = expectedData.length; - Assert.assertEquals("Size of encode data mismatch", actualRecordBytes.length - 4, expectedDataSize); - Assert.assertEquals(expectedSid, LittleEndian.getShort(actualRecordBytes, 0)); - Assert.assertEquals(expectedDataSize, LittleEndian.getShort(actualRecordBytes, 2)); - for (int i = 0; i < expectedDataSize; i++) - if (expectedData[i] != actualRecordBytes[i+4]) { - StringBuilder sb = new StringBuilder(64); - if (msgPrefix != null) { - sb.append(msgPrefix).append(": "); - } - sb.append("At offset ").append(i); - sb.append(": expected ").append(HexDump.byteToHex(expectedData[i])); - sb.append(" but found ").append(HexDump.byteToHex(actualRecordBytes[i+4])); - throw new AssertionFailedError(sb.toString()); - } + assertEquals("Size of encode data mismatch", actualRecordBytes.length - 4, expectedDataSize); + assertEquals(expectedSid, LittleEndian.getShort(actualRecordBytes, 0)); + assertEquals(expectedDataSize, LittleEndian.getShort(actualRecordBytes, 2)); + assertArrayEquals(expectedData, cut(actualRecordBytes, 4)); + } + + public static byte[] cut( byte[] data, int fromInclusive ) { + return cut(data, fromInclusive, data.length); + } + + public static byte[] cut(byte[] data, int fromInclusive, int toExclusive) { + int length = toExclusive - fromInclusive; + byte[] result = new byte[length]; + System.arraycopy( data, fromInclusive, result, 0, length); + return result; } } diff --git a/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java b/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java index 26455497b0..7bef9df51d 100644 --- a/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java +++ b/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java @@ -17,14 +17,18 @@ package org.apache.poi.hssf.record.aggregates; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.ArrayList; import java.util.List; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; - import org.apache.poi.hssf.model.RecordStream; import org.apache.poi.hssf.record.CFHeaderBase; import org.apache.poi.hssf.record.CFHeaderRecord; @@ -38,13 +42,15 @@ import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.util.LittleEndian; +import org.junit.Test; /** * Tests the serialization and deserialization of the CFRecordsAggregate - * class works correctly. + * class works correctly. */ @SuppressWarnings("resource") -public final class TestCFRecordsAggregate extends TestCase { +public final class TestCFRecordsAggregate { + @Test public void testCFRecordsAggregate() { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet(); @@ -115,6 +121,7 @@ public final class TestCFRecordsAggregate extends TestCase { /** * Make sure that the CF Header record is properly updated with the number of rules */ + @Test public void testNRules() { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet(); @@ -131,12 +138,11 @@ public final class TestCFRecordsAggregate extends TestCase { agg.serialize(0, serializedRecord); int nRules = LittleEndian.getUShort(serializedRecord, 4); - if (nRules == 0) { - throw new AssertionFailedError("Identified bug 45682 b"); - } + assertNotEquals("Identified bug 45682 b", 0, nRules); assertEquals(rules.length, nRules); } - + + @Test public void testCantMixTypes() { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet(); @@ -154,12 +160,12 @@ public final class TestCFRecordsAggregate extends TestCase { } catch (IllegalArgumentException e) { // expected here } - - + + rules = new CFRuleBase[] { CFRuleRecord.create(sheet, "7") }; CFRecordsAggregate agg = new CFRecordsAggregate(cellRanges, rules); assertTrue(agg.getHeader().getNeedRecalculation()); - + try { agg.addRule(CFRule12Record.create(sheet, "7")); fail("Shouldn't be able to mix between types"); diff --git a/src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java b/src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java index 5ce8df3cd0..6b9e1e62ed 100644 --- a/src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java +++ b/src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java @@ -18,6 +18,7 @@ package org.apache.poi.hssf.record.aggregates; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.List; @@ -25,11 +26,8 @@ import java.util.List; import org.apache.poi.hssf.record.ColumnInfoRecord; import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.RecordBase; -import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor; import org.junit.Test; -import junit.framework.AssertionFailedError; - public final class TestColumnInfoRecordsAggregate { @Test @@ -62,34 +60,19 @@ public final class TestColumnInfoRecordsAggregate { return columnInfoRecord; } - private static final class CIRCollector implements RecordVisitor { - - private final List _list = new ArrayList<>(); - - @Override - public void visitRecord(Record r) { - _list.add(r); - } - - public static ColumnInfoRecord[] getRecords(ColumnInfoRecordsAggregate agg) { - CIRCollector circ = new CIRCollector(); - agg.visitContainedRecords(circ); - return circ._list.toArray(new ColumnInfoRecord[0]); - } - } - @Test public void testGroupColumns_bug45639() { ColumnInfoRecordsAggregate agg = new ColumnInfoRecordsAggregate(); agg.groupColumnRange( 7, 9, true); agg.groupColumnRange( 4, 12, true); - try { - agg.groupColumnRange( 1, 15, true); - } catch (ArrayIndexOutOfBoundsException e) { - throw new AssertionFailedError("Identified bug 45639"); - } - ColumnInfoRecord[] cirs = CIRCollector.getRecords(agg); - assertEquals(5, cirs.length); + + // bug 45639 - ArrayIndexOutOfBoundsException + agg.groupColumnRange( 1, 15, true); + + List cirs = new ArrayList<>(); + agg.visitContainedRecords(cirs::add); + + assertEquals(5, cirs.size()); confirmCIR(cirs, 0, 1, 3, 1, false, false); confirmCIR(cirs, 1, 4, 6, 2, false, false); confirmCIR(cirs, 2, 7, 9, 3, false, false); @@ -106,14 +89,14 @@ public final class TestColumnInfoRecordsAggregate { agg.groupColumnRange(1, 15, true); agg.groupColumnRange(4, 12, true); - ColumnInfoRecord[] cirs; + List cirs = new ArrayList<>(); // collapse both inner and outer groups agg.collapseColumn(6); agg.collapseColumn(3); - cirs = CIRCollector.getRecords(agg); - assertEquals(5, cirs.length); + agg.visitContainedRecords(cirs::add); + assertEquals(5, cirs.size()); confirmCIR(cirs, 0, 1, 3, 1, true, false); confirmCIR(cirs, 1, 4, 12, 2, true, false); confirmCIR(cirs, 2, 13, 13, 1, true, true); @@ -123,19 +106,19 @@ public final class TestColumnInfoRecordsAggregate { // just expand the inner group agg.expandColumn(6); - cirs = CIRCollector.getRecords(agg); - assertEquals(4, cirs.length); - if (!cirs[1].getHidden()) { - throw new AssertionFailedError("Inner group should still be hidden"); - } + cirs.clear(); + agg.visitContainedRecords(cirs::add); + assertEquals(4, cirs.size()); + assertTrue("Inner group should still be hidden", ((ColumnInfoRecord)cirs.get(1)).getHidden()); confirmCIR(cirs, 0, 1, 3, 1, true, false); confirmCIR(cirs, 1, 4, 12, 2, true, false); confirmCIR(cirs, 2, 13, 15, 1, true, false); confirmCIR(cirs, 3, 16, 16, 0, false, true); } - - private static void confirmCIR(ColumnInfoRecord[] cirs, int ix, int startColIx, int endColIx, int level, boolean isHidden, boolean isCollapsed) { - ColumnInfoRecord cir = cirs[ix]; + + private static void confirmCIR(List cirs, int ix, int startColIx, int endColIx, int level, boolean isHidden, boolean isCollapsed) { + assertTrue(cirs.get(ix) instanceof ColumnInfoRecord); + ColumnInfoRecord cir = (ColumnInfoRecord)cirs.get(ix); assertEquals("startColIx", startColIx, cir.getFirstColumn()); assertEquals("endColIx", endColIx, cir.getLastColumn()); assertEquals("level", level, cir.getOutlineLevel()); diff --git a/src/testcases/org/apache/poi/hssf/record/aggregates/TestFormulaRecordAggregate.java b/src/testcases/org/apache/poi/hssf/record/aggregates/TestFormulaRecordAggregate.java index 49d0e8a911..a7f851d9dd 100644 --- a/src/testcases/org/apache/poi/hssf/record/aggregates/TestFormulaRecordAggregate.java +++ b/src/testcases/org/apache/poi/hssf/record/aggregates/TestFormulaRecordAggregate.java @@ -17,27 +17,27 @@ package org.apache.poi.hssf.record.aggregates; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + import org.apache.poi.hssf.model.HSSFFormulaParser; import org.apache.poi.hssf.record.FormulaRecord; import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.StringRecord; -import org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector; import org.apache.poi.ss.formula.FormulaRenderer; import org.apache.poi.ss.formula.FormulaType; import org.apache.poi.ss.formula.ptg.ExpPtg; import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.util.CellRangeAddress; -import org.apache.poi.util.RecordFormatException; +import org.junit.Test; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; - -/** - * - * @author avik - */ -public final class TestFormulaRecordAggregate extends TestCase { +public final class TestFormulaRecordAggregate { + @Test public void testBasic() { FormulaRecord f = new FormulaRecord(); f.setCachedResultTypeString(); @@ -56,29 +56,22 @@ public final class TestFormulaRecordAggregate extends TestCase { * This file seems to open in Excel (2007) with no trouble. When it is re-saved, Excel omits * the extra record. POI should do the same. */ + @Test public void testExtraStringRecord_bug46213() { FormulaRecord fr = new FormulaRecord(); fr.setValue(2.0); StringRecord sr = new StringRecord(); sr.setString("NA"); SharedValueManager svm = SharedValueManager.createEmpty(); - FormulaRecordAggregate fra; - - try { - fra = new FormulaRecordAggregate(fr, sr, svm); - } catch (RecordFormatException e) { - if ("String record was supplied but formula record flag is not set".equals(e.getMessage())) { - throw new AssertionFailedError("Identified bug 46213"); - } - throw e; - } - RecordCollector rc = new RecordCollector(); - fra.visitContainedRecords(rc); - Record[] vraRecs = rc.getRecords(); - assertEquals(1, vraRecs.length); - assertEquals(fr, vraRecs[0]); + // bug 46213 -> String record was supplied but formula record flag is not set + FormulaRecordAggregate fra = new FormulaRecordAggregate(fr, sr, svm); + List vraRecs = new ArrayList<>(); + fra.visitContainedRecords(vraRecs::add); + assertEquals(1, vraRecs.size()); + assertEquals(fr, vraRecs.get(0)); } + @Test public void testArrayFormulas() { int rownum = 4; int colnum = 4; diff --git a/src/testcases/org/apache/poi/hssf/record/aggregates/TestPageSettingsBlock.java b/src/testcases/org/apache/poi/hssf/record/aggregates/TestPageSettingsBlock.java index 0f6caa7589..0252a14206 100644 --- a/src/testcases/org/apache/poi/hssf/record/aggregates/TestPageSettingsBlock.java +++ b/src/testcases/org/apache/poi/hssf/record/aggregates/TestPageSettingsBlock.java @@ -18,29 +18,54 @@ package org.apache.poi.hssf.record.aggregates; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; +import java.util.ArrayList; import java.util.Arrays; - -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import java.util.List; +import java.util.stream.Stream; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.model.InternalSheet; import org.apache.poi.hssf.model.RecordStream; -import org.apache.poi.hssf.record.*; +import org.apache.poi.hssf.record.BOFRecord; +import org.apache.poi.hssf.record.BottomMarginRecord; +import org.apache.poi.hssf.record.ContinueRecord; +import org.apache.poi.hssf.record.DimensionsRecord; +import org.apache.poi.hssf.record.EOFRecord; +import org.apache.poi.hssf.record.FooterRecord; +import org.apache.poi.hssf.record.HCenterRecord; +import org.apache.poi.hssf.record.HeaderFooterRecord; +import org.apache.poi.hssf.record.HeaderRecord; +import org.apache.poi.hssf.record.IndexRecord; +import org.apache.poi.hssf.record.NumberRecord; +import org.apache.poi.hssf.record.Record; +import org.apache.poi.hssf.record.SelectionRecord; +import org.apache.poi.hssf.record.UnknownRecord; +import org.apache.poi.hssf.record.UserSViewBegin; +import org.apache.poi.hssf.record.UserSViewEnd; +import org.apache.poi.hssf.record.VCenterRecord; +import org.apache.poi.hssf.record.WindowTwoRecord; import org.apache.poi.hssf.usermodel.HSSFPrintSetup; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector; import org.apache.poi.util.HexRead; +import org.apache.poi.util.RecordFormatException; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; /** * Tess for {@link PageSettingsBlock} - * - * @author Dmitriy Kumshayev */ -public final class TestPageSettingsBlock extends TestCase { +public final class TestPageSettingsBlock { + @Rule + public ExpectedException thrown = ExpectedException.none(); + @Test public void testPrintSetup_bug46548() { // PageSettingBlock in this file contains PLS (sid=x004D) record @@ -49,18 +74,15 @@ public final class TestPageSettingsBlock extends TestCase { HSSFSheet sheet = wb.getSheetAt(0); HSSFPrintSetup ps = sheet.getPrintSetup(); - try { - ps.getCopies(); - } catch (NullPointerException e) { - e.printStackTrace(); - throw new AssertionFailedError("Identified bug 46548: PageSettingBlock missing PrintSetupRecord record"); - } + // bug 46548: PageSettingBlock missing PrintSetupRecord record + assertEquals(1, ps.getCopies()); } /** * Bug 46840 occurred because POI failed to recognise HEADERFOOTER as part of the * {@link PageSettingsBlock}. */ + @Test public void testHeaderFooter_bug46840() { int rowIx = 5; @@ -86,25 +108,18 @@ public final class TestPageSettingsBlock extends TestCase { EOFRecord.instance, }; RecordStream rs = new RecordStream(Arrays.asList(recs), 0); - InternalSheet sheet; - try { - sheet = InternalSheet.createSheet(rs); - } catch (RuntimeException e) { - if (e.getMessage().equals("two Page Settings Blocks found in the same sheet")) { - throw new AssertionFailedError("Identified bug 46480"); - } - throw e; - } + // bug 46480- two Page Settings Blocks found in the same sheet + InternalSheet sheet = InternalSheet.createSheet(rs); - RecordCollector rv = new RecordCollector(); - sheet.visitContainedRecords(rv, rowIx); - Record[] outRecs = rv.getRecords(); - assertEquals(13, outRecs.length); + List outRecs = new ArrayList<>(); + sheet.visitContainedRecords(outRecs::add, rowIx); + assertEquals(13, outRecs.size()); } /** * Bug 46953 occurred because POI didn't handle late PSB records properly. */ + @Test public void testLateHeaderFooter_bug46953() { int rowIx = 5; @@ -126,22 +141,16 @@ public final class TestPageSettingsBlock extends TestCase { RecordStream rs = new RecordStream(Arrays.asList(recs), 0); InternalSheet sheet = InternalSheet.createSheet(rs); - RecordCollector rv = new RecordCollector(); - sheet.visitContainedRecords(rv, 0); - Record[] outRecs = rv.getRecords(); - if (outRecs[4] == EOFRecord.instance) { - throw new AssertionFailedError("Identified bug 46953 - EOF incorrectly appended to PSB"); - } - assertEquals(recs.length+1, outRecs.length); // +1 for index record + List outRecs = new ArrayList<>(); + sheet.visitContainedRecords(outRecs::add, 0); + // Identified bug 46953 - EOF incorrectly appended to PSB + assertNotEquals(EOFRecord.instance, outRecs.get(4)); + assertEquals(recs.length+1, outRecs.size()); // +1 for index record - assertEquals(BOFRecord.class, outRecs[0].getClass()); - assertEquals(IndexRecord.class, outRecs[1].getClass()); - assertEquals(HeaderRecord.class, outRecs[2].getClass()); - assertEquals(FooterRecord.class, outRecs[3].getClass()); - assertEquals(HeaderFooterRecord.class, outRecs[4].getClass()); - assertEquals(DimensionsRecord.class, outRecs[5].getClass()); - assertEquals(WindowTwoRecord.class, outRecs[6].getClass()); - assertEquals(EOFRecord.instance, outRecs[7]); + Class[] act = outRecs.stream().map(Object::getClass).toArray(Class[]::new); + Class[] exp = { BOFRecord.class, IndexRecord.class, HeaderRecord.class, FooterRecord.class, + HeaderFooterRecord.class, DimensionsRecord.class, WindowTwoRecord.class, EOFRecord.class }; + assertArrayEquals(exp, act); } /** * Bug 47199 was due to the margin records being located well after the initial PSB records. @@ -155,53 +164,41 @@ public final class TestPageSettingsBlock extends TestCase { *

  • BottomMargin(0x0029)
  • * */ + @Test public void testLateMargins_bug47199() { + BottomMarginRecord bottomMargin = new BottomMarginRecord(); + bottomMargin.setMargin(0.787F); + Record[] recs = { BOFRecord.createSheetBOF(), new HeaderRecord("&LSales Figures"), new FooterRecord("&LJanuary"), new DimensionsRecord(), - createBottomMargin(0.787F), + bottomMargin, new WindowTwoRecord(), EOFRecord.instance, }; RecordStream rs = new RecordStream(Arrays.asList(recs), 0); - InternalSheet sheet; - try { - sheet = InternalSheet.createSheet(rs); - } catch (RuntimeException e) { - if (e.getMessage().equals("two Page Settings Blocks found in the same sheet")) { - throw new AssertionFailedError("Identified bug 47199a - failed to process late margings records"); - } - throw e; - } + // bug 47199a - failed to process late margins records + InternalSheet sheet = InternalSheet.createSheet(rs); - RecordCollector rv = new RecordCollector(); - sheet.visitContainedRecords(rv, 0); - Record[] outRecs = rv.getRecords(); - assertEquals(recs.length+1, outRecs.length); // +1 for index record + List outRecs = new ArrayList<>(); + sheet.visitContainedRecords(outRecs::add, 0); + assertEquals(recs.length+1, outRecs.size()); // +1 for index record - assertEquals(BOFRecord.class, outRecs[0].getClass()); - assertEquals(IndexRecord.class, outRecs[1].getClass()); - assertEquals(HeaderRecord.class, outRecs[2].getClass()); - assertEquals(FooterRecord.class, outRecs[3].getClass()); - assertEquals(DimensionsRecord.class, outRecs[5].getClass()); - assertEquals(WindowTwoRecord.class, outRecs[6].getClass()); - assertEquals(EOFRecord.instance, outRecs[7]); - } - - private Record createBottomMargin(float value) { - BottomMarginRecord result = new BottomMarginRecord(); - result.setMargin(value); - return result; + Class[] act = outRecs.stream().map(Object::getClass).toArray(Class[]::new); + Class[] exp = { BOFRecord.class, IndexRecord.class, HeaderRecord.class, FooterRecord.class, + BottomMarginRecord.class, DimensionsRecord.class, WindowTwoRecord.class, EOFRecord.class }; + assertArrayEquals(exp, act); } /** * The PageSettingsBlock should not allow multiple copies of the same record. This extra assertion * was added while fixing bug 47199. All existing POI test samples comply with this requirement. */ + @Test public void testDuplicatePSBRecord_bug47199() { // Hypothetical setup of PSB records which should cause POI to crash Record[] recs = { @@ -210,18 +207,9 @@ public final class TestPageSettingsBlock extends TestCase { }; RecordStream rs = new RecordStream(Arrays.asList(recs), 0); - try { - new PageSettingsBlock(rs); - throw new AssertionFailedError("Identified bug 47199b - duplicate PSB records should not be allowed"); - } catch (org.apache.poi.util.RecordFormatException e) { - if (!e.getMessage().equals("Duplicate PageSettingsBlock record (sid=0x14)")) { - throw new AssertionFailedError("Expected RecordFormatException due to duplicate PSB record"); - } - } - } - - private static UnknownRecord ur(int sid, String hexData) { - return new UnknownRecord(sid, HexRead.readFromString(hexData)); + thrown.expectMessage("Duplicate PageSettingsBlock record (sid=0x14)"); + thrown.expect(RecordFormatException.class); + new PageSettingsBlock(rs); } /** @@ -229,6 +217,7 @@ public final class TestPageSettingsBlock extends TestCase { * This is not critical functionality but it has been decided to keep POI consistent with * Excel in this regard. */ + @Test public void testMissingHeaderFooter() { // initialise PSB with some records, but not the header / footer Record[] recs = { @@ -239,23 +228,19 @@ public final class TestPageSettingsBlock extends TestCase { PageSettingsBlock psb = new PageSettingsBlock(rs); // serialize the PSB to see what records come out - RecordCollector rc = new RecordCollector(); - psb.visitContainedRecords(rc); - Record[] outRecs = rc.getRecords(); + List outRecs = new ArrayList<>(); + psb.visitContainedRecords(outRecs::add); - if (outRecs.length == 2) { - throw new AssertionFailedError("PageSettingsBlock didn't add missing header/footer records"); - } - assertEquals(4, outRecs.length); - assertEquals(HeaderRecord.class, outRecs[0].getClass()); - assertEquals(FooterRecord.class, outRecs[1].getClass()); - assertEquals(HCenterRecord.class, outRecs[2].getClass()); - assertEquals(VCenterRecord.class, outRecs[3].getClass()); + assertNotEquals("PageSettingsBlock didn't add missing header/footer records", 2, outRecs.size()); + + Class[] act = outRecs.stream().map(Object::getClass).toArray(Class[]::new); + Class[] exp = { HeaderRecord.class, FooterRecord.class, HCenterRecord.class, VCenterRecord.class}; + assertArrayEquals(exp, act); // make sure the added header / footer records are empty - HeaderRecord hr = (HeaderRecord) outRecs[0]; + HeaderRecord hr = (HeaderRecord) outRecs.get(0); assertEquals("", hr.getText()); - FooterRecord fr = (FooterRecord) outRecs[1]; + FooterRecord fr = (FooterRecord) outRecs.get(1); assertEquals("", fr.getText()); } @@ -268,9 +253,10 @@ public final class TestPageSettingsBlock extends TestCase { * * As of June 2009, PLS is still uninterpreted by POI */ + @Test public void testDuplicatePLS_bug47415() { - Record plsA = ur(UnknownRecord.PLS_004D, "BA AD F0 0D"); - Record plsB = ur(UnknownRecord.PLS_004D, "DE AD BE EF"); + Record plsA = new UnknownRecord(UnknownRecord.PLS_004D, HexRead.readFromString("BA AD F0 0D")); + Record plsB = new UnknownRecord(UnknownRecord.PLS_004D, HexRead.readFromString("DE AD BE EF")); Record contB1 = new ContinueRecord(HexRead.readFromString("FE ED")); Record contB2 = new ContinueRecord(HexRead.readFromString("FA CE")); Record[] recs = { @@ -282,25 +268,18 @@ public final class TestPageSettingsBlock extends TestCase { plsB, contB1, contB2, // make sure continuing PLS is still OK }; RecordStream rs = new RecordStream(Arrays.asList(recs), 0); - PageSettingsBlock psb; - try { - psb = new PageSettingsBlock(rs); - } catch (org.apache.poi.util.RecordFormatException e) { - if ("Duplicate PageSettingsBlock record (sid=0x4d)".equals(e.getMessage())) { - throw new AssertionFailedError("Identified bug 47415"); - } - throw e; - } + // bug 47415 - Duplicate PageSettingsBlock record (sid=0x4d) + PageSettingsBlock psb = new PageSettingsBlock(rs); // serialize the PSB to see what records come out - RecordCollector rc = new RecordCollector(); - psb.visitContainedRecords(rc); - Record[] outRecs = rc.getRecords(); + List outRecs = new ArrayList<>(); + psb.visitContainedRecords(outRecs::add); // records were assembled in standard order, so this simple check is OK - assertArrayEquals(recs, outRecs); + assertArrayEquals(recs, outRecs.toArray(new Record[0])); } + @Test public void testDuplicateHeaderFooter_bug48026() { Record[] recs = { @@ -327,21 +306,13 @@ public final class TestPageSettingsBlock extends TestCase { EOFRecord.instance, }; RecordStream rs = new RecordStream(Arrays.asList(recs), 0); - InternalSheet sheet; - try { - sheet = InternalSheet.createSheet(rs); - } catch (RuntimeException e) { - if (e.getMessage().equals("Duplicate PageSettingsBlock record (sid=0x89c)")) { - throw new AssertionFailedError("Identified bug 48026"); - } - throw e; - } + // bug 48026 - Duplicate PageSettingsBlock record (sid=0x89c) + InternalSheet sheet = InternalSheet.createSheet(rs); - RecordCollector rv = new RecordCollector(); - sheet.visitContainedRecords(rv, 0); - Record[] outRecs = rv.getRecords(); + List outRecs = new ArrayList<>(); + sheet.visitContainedRecords(outRecs::add, 0); - assertEquals(recs.length, outRecs.length); + assertEquals(recs.length, outRecs.size()); //expected order of records: Record[] expectedRecs = { recs[0], //BOFRecord @@ -362,9 +333,12 @@ public final class TestPageSettingsBlock extends TestCase { recs[11], //EOFRecord }; - for(int i=0; i < expectedRecs.length; i++){ - assertEquals("Record mismatch at index " + i, expectedRecs[i].getClass(), outRecs[i].getClass()); - } + + assertArrayEquals( + Stream.of(expectedRecs).map(Object::getClass).toArray(Class[]::new), + outRecs.stream().map(Object::getClass).toArray(Class[]::new) + ); + HeaderFooterRecord hd1 = (HeaderFooterRecord)expectedRecs[4]; //GUID is zero assertArrayEquals(new byte[16], hd1.getGuid()); @@ -377,6 +351,7 @@ public final class TestPageSettingsBlock extends TestCase { assertArrayEquals(svb.getGuid(), hd2.getGuid()); } + @Test public void testDuplicateHeaderFooterInside_bug48026() { Record[] recs = { @@ -404,21 +379,13 @@ public final class TestPageSettingsBlock extends TestCase { EOFRecord.instance, }; RecordStream rs = new RecordStream(Arrays.asList(recs), 0); - InternalSheet sheet; - try { - sheet = InternalSheet.createSheet(rs); - } catch (RuntimeException e) { - if (e.getMessage().equals("Duplicate PageSettingsBlock record (sid=0x89c)")) { - throw new AssertionFailedError("Identified bug 48026"); - } - throw e; - } + // Bug 48026 : Duplicate PageSettingsBlock record (sid=0x89c) + InternalSheet sheet = InternalSheet.createSheet(rs); - RecordCollector rv = new RecordCollector(); - sheet.visitContainedRecords(rv, 0); - Record[] outRecs = rv.getRecords(); + List outRecs = new ArrayList<>(); + sheet.visitContainedRecords(outRecs::add, 0); - assertEquals(recs.length+1, outRecs.length); + assertEquals(recs.length+1, outRecs.size()); //expected order of records: Record[] expectedRecs = { recs[0], //BOFRecord @@ -441,9 +408,12 @@ public final class TestPageSettingsBlock extends TestCase { recs[11], //EOFRecord }; - for(int i=0; i < expectedRecs.length; i++){ - assertEquals("Record mismatch at index " + i, expectedRecs[i].getClass(), outRecs[i].getClass()); - } + + assertArrayEquals( + Stream.of(expectedRecs).map(Object::getClass).toArray(Class[]::new), + outRecs.stream().map(Object::getClass).toArray(Class[]::new) + ); + HeaderFooterRecord hd1 = (HeaderFooterRecord)expectedRecs[10]; //GUID is zero assertArrayEquals(new byte[16], hd1.getGuid()); diff --git a/src/testcases/org/apache/poi/hssf/record/aggregates/TestRowRecordsAggregate.java b/src/testcases/org/apache/poi/hssf/record/aggregates/TestRowRecordsAggregate.java index 750e5b9427..a5fe0f0ea6 100644 --- a/src/testcases/org/apache/poi/hssf/record/aggregates/TestRowRecordsAggregate.java +++ b/src/testcases/org/apache/poi/hssf/record/aggregates/TestRowRecordsAggregate.java @@ -20,10 +20,11 @@ package org.apache.poi.hssf.record.aggregates; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.model.RecordStream; @@ -38,8 +39,6 @@ import org.apache.poi.hssf.record.SharedValueRecordBase; import org.apache.poi.hssf.record.TableRecord; import org.apache.poi.hssf.record.UnknownRecord; import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.hssf.usermodel.RecordInspector; -import org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector; import org.apache.poi.hssf.util.CellRangeAddress8Bit; import org.apache.poi.util.LocaleUtil; import org.junit.Test; @@ -71,18 +70,19 @@ public final class TestRowRecordsAggregate { */ @Test public void testArraysAndTables() throws Exception { - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("testArraysAndTables.xls"); - Record[] sheetRecs = RecordInspector.getRecords(wb.getSheetAt(0), 0); + try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("testArraysAndTables.xls")) { + final List sheetRecs = new ArrayList<>(); + wb.getSheetAt(0).getSheet().visitContainedRecords(sheetRecs::add, 0); - int countArrayFormulas = verifySharedValues(sheetRecs, ArrayRecord.class); - assertEquals(5, countArrayFormulas); - int countTableFormulas = verifySharedValues(sheetRecs, TableRecord.class); - assertEquals(3, countTableFormulas); + int countArrayFormulas = verifySharedValues(sheetRecs, ArrayRecord.class); + assertEquals(5, countArrayFormulas); + int countTableFormulas = verifySharedValues(sheetRecs, TableRecord.class); + assertEquals(3, countTableFormulas); - // Note - SharedFormulaRecords are currently not re-serialized by POI (each is extracted - // into many non-shared formulas), but if they ever were, the same rules would apply. - int countSharedFormulas = verifySharedValues(sheetRecs, SharedFormulaRecord.class); - assertEquals(0, countSharedFormulas); + // Note - SharedFormulaRecords are currently not re-serialized by POI (each is extracted + // into many non-shared formulas), but if they ever were, the same rules would apply. + int countSharedFormulas = verifySharedValues(sheetRecs, SharedFormulaRecord.class); + assertEquals(0, countSharedFormulas); // if (false) { // set true to observe re-serialized file @@ -96,18 +96,18 @@ public final class TestRowRecordsAggregate { // } // System.out.println("Output file to " + f.getAbsolutePath()); // } - - wb.close(); + + } } - private static int verifySharedValues(Record[] recs, Class shfClass) { + private static int verifySharedValues(List recs, Class shfClass) { int result =0; - for(int i=0; i outRecs = new ArrayList<>(); + rra.visitContainedRecords(outRecs::add); + assertEquals(5, outRecs.size()); } } diff --git a/src/testcases/org/apache/poi/hssf/record/aggregates/TestSharedValueManager.java b/src/testcases/org/apache/poi/hssf/record/aggregates/TestSharedValueManager.java index c3c01d8fb5..8c2a47e14c 100644 --- a/src/testcases/org/apache/poi/hssf/record/aggregates/TestSharedValueManager.java +++ b/src/testcases/org/apache/poi/hssf/record/aggregates/TestSharedValueManager.java @@ -17,27 +17,23 @@ package org.apache.poi.hssf.record.aggregates; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + import java.util.Collection; import java.util.HashMap; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; - -import org.apache.poi.POITestCase; import org.apache.poi.hssf.HSSFTestDataSamples; -import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.SharedFormulaRecord; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.hssf.usermodel.RecordInspector; +import org.junit.Test; /** * Tests for {@link SharedValueManager} - * - * @author Josh Micich */ -public final class TestSharedValueManager extends TestCase { +public final class TestSharedValueManager { /** * This Excel workbook contains two sheets that each have a pair of overlapping shared formula @@ -66,61 +62,43 @@ public final class TestSharedValueManager extends TestCase { * This bug happened when there were two or more shared formula ranges that overlapped. POI * would sometimes associate formulas in the overlapping region with the wrong shared formula */ + @Test public void testPartiallyOverlappingRanges() { - Record[] records; - int attempt=1; - do { + + for (int attempt=1; attempt < MAX_ATTEMPTS; attempt++) { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook(SAMPLE_FILE_NAME); HSSFSheet sheet = wb.getSheetAt(0); - RecordInspector.getRecords(sheet, 0); assertEquals("1+1", sheet.getRow(2).getCell(0).getCellFormula()); - if ("1+1".equals(sheet.getRow(3).getCell(0).getCellFormula())) { - throw new AssertionFailedError("Identified bug - wrong shared formula record chosen" - + " (attempt " + attempt + ")"); - } - assertEquals("2+2", sheet.getRow(3).getCell(0).getCellFormula()); - records = RecordInspector.getRecords(sheet, 0); - } while (attempt++ < MAX_ATTEMPTS); + String act = sheet.getRow(3).getCell(0).getCellFormula(); + assertNotEquals("wrong shared formula record chosen", "1+1", act); + act = sheet.getRow(3).getCell(0).getCellFormula(); + assertEquals("2+2", act); - int count=0; - for (Record record : records) { - if (record instanceof SharedFormulaRecord) { - count++; - } + int[] count = { 0 }; + sheet.getSheet().visitContainedRecords(r -> count[0] += r instanceof SharedFormulaRecord ? 1 : 0, 0); + assertEquals(2, count[0]); } - assertEquals(2, count); } /** * This bug occurs for similar reasons to the bug in {@link #testPartiallyOverlappingRanges()} * but the symptoms are much uglier - serialization fails with {@link NullPointerException}.
    */ + @Test public void testCompletelyOverlappedRanges() { - Record[] records; - - int attempt=1; - do { + for (int attempt=1; attempt < MAX_ATTEMPTS; attempt++) { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook(SAMPLE_FILE_NAME); HSSFSheet sheet = wb.getSheetAt(1); - try { - records = RecordInspector.getRecords(sheet, 0); - } catch (NullPointerException e) { - throw new AssertionFailedError("Identified bug " + - "- cannot reserialize completely overlapped shared formula" - + " (attempt " + attempt + ")"); - } - } while (attempt++ < MAX_ATTEMPTS); - int count=0; - for (Record record : records) { - if (record instanceof SharedFormulaRecord) { - count++; - } + int[] count = { 0 }; + + // NullPointerException -> cannot reserialize completely overlapped shared formula + sheet.getSheet().visitContainedRecords(r -> count[0] += r instanceof SharedFormulaRecord ? 1 : 0, 0); + assertEquals(2, count[0]); } - assertEquals(2, count); } /** @@ -133,6 +111,7 @@ public final class TestSharedValueManager extends TestCase { * Two existing sample files (15228.xls and ex45046-21984.xls) had similar issues. * These were not explored fully, but seem to be fixed now. */ + @Test public void testRecalculateFormulas47747() { /* @@ -155,30 +134,13 @@ public final class TestSharedValueManager extends TestCase { // pick out a cell from within the second shared formula group HSSFCell cell = wb.getSheetAt(0).getRow(23).getCell(0); - String formulaText; - try { - formulaText = cell.getCellFormula(); - // succeeds if the formula record has been associated - // with the second shared formula group - } catch (RuntimeException e) { - // bug occurs if the formula record has been associated - // with the first shared formula group - if ("Shared Formula Conversion: Coding Error".equals(e.getMessage())) { - throw new AssertionFailedError("Identified bug 47747"); - } - throw e; - } + // bug occurs if the formula record has been associated + // with the first (and not the second) shared formula group + String formulaText = cell.getCellFormula(); assertEquals("$AF24*A$7", formulaText); } - /** - * Convenience test method for digging the {@link SharedValueManager} out of a - * {@link RowRecordsAggregate}. - */ - public static SharedValueManager extractFromRRA(RowRecordsAggregate rra) { - return POITestCase.getFieldValue(RowRecordsAggregate.class, rra, SharedValueManager.class, "_sharedValueManager"); - } - + @Test public void testBug52527() { HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("52527.xls"); HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1); diff --git a/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java b/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java index e63e8167bb..61984e1295 100644 --- a/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java +++ b/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java @@ -17,7 +17,11 @@ package org.apache.poi.hssf.record.aggregates; -import static org.junit.Assert.*; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.io.IOException; import java.io.InputStream; @@ -42,15 +46,13 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.util.HexRead; import org.junit.Test; -import junit.framework.AssertionFailedError; - /** * Tests for {@link ValueRecordsAggregate} */ public final class TestValueRecordsAggregate { private static final String ABNORMAL_SHARED_FORMULA_FLAG_TEST_FILE = "AbnormalSharedFormulaFlag.xls"; private final ValueRecordsAggregate valueRecord = new ValueRecordsAggregate(); - + private List getValueRecords() { List list = new ArrayList<>(); for ( CellValueRecordInterface rec : valueRecord ) { @@ -263,7 +265,7 @@ public final class TestValueRecordsAggregate { assertNotEquals("found bug 44449 (Wrong SharedFormulaRecord was used).", "\"second formula\"", cellFormula); assertEquals("Something else wrong with this test case", "\"first formula\"", cellFormula); - + wb.close(); } private static String getFormulaFromFirstCell(HSSFSheet s, int rowIx) { @@ -310,21 +312,15 @@ public final class TestValueRecordsAggregate { return crc.getValue(); } - + @Test public void testRemoveNewRow_bug46312() { // To make bug occur, rowIndex needs to be >= ValueRecordsAggregate.records.length int rowIndex = 30; ValueRecordsAggregate vra = new ValueRecordsAggregate(); - try { - vra.removeAllCellsValuesForRow(rowIndex); - } catch (IllegalArgumentException e) { - if (e.getMessage().equals("Specified rowIndex 30 is outside the allowable range (0..30)")) { - throw new AssertionFailedError("Identified bug 46312"); - } - throw e; - } + // bug 46312 - Specified rowIndex 30 is outside the allowable range (0..30) + vra.removeAllCellsValuesForRow(rowIndex); // if (false) { // same bug as demonstrated through usermodel API // @@ -395,18 +391,14 @@ public final class TestValueRecordsAggregate { } final BlankStats bs = new BlankStats(); - RecordVisitor rv = new RecordVisitor() { - - @Override - public void visitRecord(Record r) { - if (r instanceof MulBlankRecord) { - MulBlankRecord mbr = (MulBlankRecord) r; - bs.countMulBlankRecords++; - bs.countBlankCells += mbr.getNumColumns(); - } else if (r instanceof BlankRecord) { - bs.countSingleBlankRecords++; - bs.countBlankCells++; - } + RecordVisitor rv = r -> { + if (r instanceof MulBlankRecord) { + MulBlankRecord mbr = (MulBlankRecord) r; + bs.countMulBlankRecords++; + bs.countBlankCells += mbr.getNumColumns(); + } else if (r instanceof BlankRecord) { + bs.countSingleBlankRecords++; + bs.countBlankCells++; } }; diff --git a/src/testcases/org/apache/poi/hssf/record/cf/TestCellRange.java b/src/testcases/org/apache/poi/hssf/record/cf/TestCellRange.java index 54f1702e23..639edca2b3 100644 --- a/src/testcases/org/apache/poi/hssf/record/cf/TestCellRange.java +++ b/src/testcases/org/apache/poi/hssf/record/cf/TestCellRange.java @@ -17,19 +17,20 @@ limitations under the License. package org.apache.poi.hssf.record.cf; -import java.util.Arrays; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import java.util.Arrays; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeUtil; +import org.junit.Test; /** * Tests CellRange operations. */ -public final class TestCellRange extends TestCase -{ +public final class TestCellRange { private static final CellRangeAddress biggest = createCR( 0, -1, 0,-1); private static final CellRangeAddress tenthColumn = createCR( 0, -1,10,10); private static final CellRangeAddress tenthRow = createCR(10, 10, 0,-1); @@ -41,33 +42,34 @@ public final class TestCellRange extends TestCase private static final CellRangeAddress[] sampleRanges = { biggest, tenthColumn, tenthRow, box10x10, box9x9, box10to20c, oneCell, }; - + /** cross-reference of contains() operations for sampleRanges against itself */ - private static final boolean [][] containsExpectedResults = + private static final boolean [][] containsExpectedResults = { // biggest, tenthColumn, tenthRow, box10x10, box9x9, box10to20c, oneCell - /*biggest */ {true, true , true , true , true , true , true}, - /*tenthColumn*/ {false, true , false, false, false, false, true}, - /*tenthRow */ {false, false, true , false, false, false, true}, - /*box10x10 */ {false, false, false, true , true , false, true}, - /*box9x9 */ {false, false, false, false, true , false, false}, - /*box10to20c */ {false, false, false, false, false, true , true}, - /*oneCell */ {false, false, false, false, false, false, true}, + /*biggest */ {true, true , true , true , true , true , true}, + /*tenthColumn*/ {false, true , false, false, false, false, true}, + /*tenthRow */ {false, false, true , false, false, false, true}, + /*box10x10 */ {false, false, false, true , true , false, true}, + /*box9x9 */ {false, false, false, false, true , false, false}, + /*box10to20c */ {false, false, false, false, false, true , true}, + /*oneCell */ {false, false, false, false, false, false, true}, } ; /** - * @param lastRow pass -1 for max row index + * @param lastRow pass -1 for max row index * @param lastCol pass -1 for max col index */ private static CellRangeAddress createCR(int firstRow, int lastRow, int firstCol, int lastCol) { // max row & max col limit as per BIFF8 return new CellRangeAddress( - firstRow, - lastRow == -1 ? 0xFFFF : lastRow, + firstRow, + lastRow == -1 ? 0xFFFF : lastRow, firstCol, lastCol == -1 ? 0x00FF : lastCol); } - + + @Test public void testContainsMethod() { CellRangeAddress [] ranges = sampleRanges; @@ -93,8 +95,8 @@ public final class TestCellRange extends TestCase private static final CellRangeAddress box4 = createCR( 2, 3, 2,3); private static final CellRangeAddress box5 = createCR( 1, 3, 1,3); - public void testHasSharedBorderMethod() - { + @Test + public void testHasSharedBorderMethod() { assertFalse(CellRangeUtil.hasExactSharedBorder(col1, col1)); assertFalse(CellRangeUtil.hasExactSharedBorder(col2, col2)); assertTrue(CellRangeUtil.hasExactSharedBorder(col1, col2)); @@ -104,7 +106,7 @@ public final class TestCellRange extends TestCase assertFalse(CellRangeUtil.hasExactSharedBorder(row2, row2)); assertTrue(CellRangeUtil.hasExactSharedBorder(row1, row2)); assertTrue(CellRangeUtil.hasExactSharedBorder(row2, row1)); - + assertFalse(CellRangeUtil.hasExactSharedBorder(row1, col1)); assertFalse(CellRangeUtil.hasExactSharedBorder(row1, col2)); assertFalse(CellRangeUtil.hasExactSharedBorder(col1, row1)); @@ -114,30 +116,30 @@ public final class TestCellRange extends TestCase assertFalse(CellRangeUtil.hasExactSharedBorder(col1, row2)); assertFalse(CellRangeUtil.hasExactSharedBorder(col2, row2)); assertTrue(CellRangeUtil.hasExactSharedBorder(col2, col1)); - + assertFalse(CellRangeUtil.hasExactSharedBorder(box1, box1)); assertTrue(CellRangeUtil.hasExactSharedBorder(box1, box2)); assertTrue(CellRangeUtil.hasExactSharedBorder(box1, box3)); assertFalse(CellRangeUtil.hasExactSharedBorder(box1, box4)); - + assertTrue(CellRangeUtil.hasExactSharedBorder(box2, box1)); assertFalse(CellRangeUtil.hasExactSharedBorder(box2, box2)); assertFalse(CellRangeUtil.hasExactSharedBorder(box2, box3)); assertTrue(CellRangeUtil.hasExactSharedBorder(box2, box4)); - + assertTrue(CellRangeUtil.hasExactSharedBorder(box3, box1)); assertFalse(CellRangeUtil.hasExactSharedBorder(box3, box2)); assertFalse(CellRangeUtil.hasExactSharedBorder(box3, box3)); assertTrue(CellRangeUtil.hasExactSharedBorder(box3, box4)); - + assertFalse(CellRangeUtil.hasExactSharedBorder(box4, box1)); assertTrue(CellRangeUtil.hasExactSharedBorder(box4, box2)); assertTrue(CellRangeUtil.hasExactSharedBorder(box4, box3)); assertFalse(CellRangeUtil.hasExactSharedBorder(box4, box4)); } - public void testIntersectMethod() - { + @Test + public void testIntersectMethod() { assertEquals(CellRangeUtil.OVERLAP, CellRangeUtil.intersect(box0, box5)); assertEquals(CellRangeUtil.OVERLAP, CellRangeUtil.intersect(box5, box0)); assertEquals(CellRangeUtil.NO_INTERSECTION, CellRangeUtil.intersect(box1, box4)); @@ -153,45 +155,40 @@ public final class TestCellRange extends TestCase assertEquals(CellRangeUtil.OVERLAP, CellRangeUtil.intersect(tenthRow, tenthColumn)); assertEquals(CellRangeUtil.INSIDE, CellRangeUtil.intersect(tenthColumn, tenthColumn)); assertEquals(CellRangeUtil.INSIDE, CellRangeUtil.intersect(tenthRow, tenthRow)); - + // Bug 55380 assertEquals(CellRangeUtil.OVERLAP, CellRangeUtil.intersect( CellRangeAddress.valueOf("C1:D2"), CellRangeAddress.valueOf("C2:C3"))); } - + /** * Cell ranges like the following are valid * =$C:$IV,$B$1:$B$8,$B$10:$B$65536,$A:$A */ + @Test public void testCreate() { - CellRangeAddress cr; - - cr = createCR(0, -1, 2, 255); // $C:$IV - confirmRange(cr, false, true); - cr = createCR(0, 7, 1, 1); // $B$1:$B$8 - - try { - cr = createCR(9, -1, 1, 1); // $B$65536 - } catch (IllegalArgumentException e) { - if(e.getMessage().startsWith("invalid cell range")) { - throw new AssertionFailedError("Identified bug 44739"); - } - throw e; - } - cr = createCR(0, -1, 0, 0); // $A:$A + CellRangeAddress cr = createCR(0, -1, 2, 255); // $C:$IV + + assertFalse("isFullRowRange", cr.isFullRowRange()); + assertTrue("isFullColumnRange", cr.isFullColumnRange()); + + createCR(0, 7, 1, 1); // $B$1:$B$8 + + // bug 44739 - invalid cell range + createCR(9, -1, 1, 1); // $B$65536 + + createCR(0, -1, 0, 0); // $A:$A } - private static void confirmRange(CellRangeAddress cr, boolean isFullRow, boolean isFullColumn) { - assertEquals("isFullRowRange", isFullRow, cr.isFullRowRange()); - assertEquals("isFullColumnRange", isFullColumn, cr.isFullColumnRange()); - } - + @Test public void testNumberOfCells() { assertEquals(1, oneCell.getNumberOfCells()); assertEquals(100, box9x9.getNumberOfCells()); assertEquals(121, box10to20c.getNumberOfCells()); } + @SuppressWarnings("RedundantArrayCreation") + @Test public void testMergeCellRanges() { // no result on empty cellRangeTest(new String[]{ }); @@ -202,11 +199,11 @@ public final class TestCellRange extends TestCase cellRangeTest(new String[]{"A1:B2", "A2:B2"}, "A1:B2"); cellRangeTest(new String[]{"A1:B3", "A2:B2"}, "A1:B3"); cellRangeTest(new String[]{"A1:C1", "A2:B2"}, new String[] {"A1:C1", "A2:B2"}); - + // cases with three ranges cellRangeTest(new String[]{"A1:A1", "A2:B2", "A1:C1"}, new String[] {"A1:C1", "A2:B2"}); cellRangeTest(new String[]{"A1:C1", "A2:B2", "A1:A1"}, new String[] {"A1:C1", "A2:B2"}); - + // "standard" cases // enclose cellRangeTest(new String[]{"A1:D4", "B2:C3"}, new String[] {"A1:D4"}); @@ -223,16 +220,18 @@ public final class TestCellRange extends TestCase cellRangeTest(new String[]{"A1:C3", "B1:D1"}, new String[] {"A1:C3", "B1:D1"}); // could be one region "A1:D3" } + @SuppressWarnings("RedundantArrayCreation") + @Test public void testMergeCellRanges55380() { cellRangeTest(new String[]{"C1:D2", "C2:C3"}, new String[] {"C1:D2", "C2:C3"}); cellRangeTest(new String[]{"A1:C3", "B2:D2"}, new String[] {"A1:C3", "B2:D2"}); cellRangeTest(new String[]{"C9:D30", "C7:C31"}, new String[] {"C9:D30", "C7:C31"}); } - + // public void testResolveRangeOverlap() { // resolveRangeOverlapTest("C1:D2", "C2:C3"); // } - + private void cellRangeTest(String[] input, String... expectedOutput) { CellRangeAddress[] inputArr = new CellRangeAddress[input.length]; for(int i = 0;i < input.length;i++) { @@ -248,16 +247,17 @@ public final class TestCellRange extends TestCase // CellRangeAddress[] result = CellRangeUtil.resolveRangeOverlap(rangeA, rangeB); // verifyExpectedResult(result, expectedOutput); // } - + private void verifyExpectedResult(CellRangeAddress[] result, String... expectedOutput) { - assertEquals("\nExpected: " + Arrays.toString(expectedOutput) + "\nHad: " + Arrays.toString(result), + assertEquals("\nExpected: " + Arrays.toString(expectedOutput) + "\nHad: " + Arrays.toString(result), expectedOutput.length, result.length); for(int i = 0;i < expectedOutput.length;i++) { assertEquals("\nExpected: " + Arrays.toString(expectedOutput) + "\nHad: " + Arrays.toString(result), expectedOutput[i], result[i].formatAsString()); } } - + + @Test public void testValueOf() { CellRangeAddress cr1 = CellRangeAddress.valueOf("A1:B1"); assertEquals(0, cr1.getFirstColumn()); diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestAreaFormatRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestAreaFormatRecord.java index 1a1041cf7d..ad88292845 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestAreaFormatRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestAreaFormatRecord.java @@ -18,19 +18,20 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the AreaFormatRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestAreaFormatRecord extends TestCase { +public final class TestAreaFormatRecord { byte[] data = new byte[] { (byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0x00, // forecolor (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, // backcolor @@ -41,8 +42,8 @@ public final class TestAreaFormatRecord extends TestCase { }; + @Test public void testLoad() { - AreaFormatRecord record = new AreaFormatRecord(TestcaseRecordInputStream.create(0x100a, data)); assertEquals( 0xFFFFFF, record.getForegroundColor()); assertEquals( 0x000000, record.getBackgroundColor()); @@ -57,8 +58,8 @@ public final class TestAreaFormatRecord extends TestCase { assertEquals( 20, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { AreaFormatRecord record = new AreaFormatRecord(); record.setForegroundColor( 0xFFFFFF ); record.setBackgroundColor( 0x000000 ); @@ -70,8 +71,6 @@ public final class TestAreaFormatRecord extends TestCase { byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(AreaFormatRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestAreaRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestAreaRecord.java index 4d5f30e783..f434376902 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestAreaRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestAreaRecord.java @@ -18,23 +18,25 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the AreaRecord * class works correctly. Test data taken directly from a real * Excel file. - * - * - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestAreaRecord extends TestCase { +public final class TestAreaRecord { byte[] data = new byte[] { (byte)0x02,(byte)0x00 // format flags }; + @Test public void testLoad() { AreaRecord record = new AreaRecord(TestcaseRecordInputStream.create(0x101A, data)); @@ -43,21 +45,17 @@ public final class TestAreaRecord extends TestCase { assertTrue(record.isDisplayAsPercentage()); assertFalse(record.isShadow()); - assertEquals( 6, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { AreaRecord record = new AreaRecord(); record.setStacked( false ); record.setDisplayAsPercentage( true ); record.setShadow( false ); - byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(AreaRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestAxisLineFormatRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestAxisLineFormatRecord.java index ae80fe2b30..67d1a76ebf 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestAxisLineFormatRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestAxisLineFormatRecord.java @@ -18,23 +18,23 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the AxisLineFormatRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestAxisLineFormatRecord extends TestCase { +public final class TestAxisLineFormatRecord { byte[] data = new byte[] { (byte)0x01,(byte)0x00 }; + @Test public void testLoad() { AxisLineFormatRecord record = new AxisLineFormatRecord(TestcaseRecordInputStream.create(0x1021, data)); assertEquals( AxisLineFormatRecord.AXIS_TYPE_MAJOR_GRID_LINE, record.getAxisType()); @@ -42,15 +42,12 @@ public final class TestAxisLineFormatRecord extends TestCase { assertEquals( 6, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { AxisLineFormatRecord record = new AxisLineFormatRecord(); record.setAxisType( AxisLineFormatRecord.AXIS_TYPE_MAJOR_GRID_LINE ); - byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(AxisLineFormatRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestAxisOptionsRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestAxisOptionsRecord.java index ebb5ba4637..d83e2eac55 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestAxisOptionsRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestAxisOptionsRecord.java @@ -18,19 +18,20 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the AxisOptionsRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Andrew C. Oliver(acoliver at apache.org) */ -public final class TestAxisOptionsRecord extends TestCase { +public final class TestAxisOptionsRecord { 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, @@ -38,6 +39,7 @@ public final class TestAxisOptionsRecord extends TestCase { (byte)0x00,(byte)0xEF,(byte)0x00 }; + @Test public void testLoad() { AxisOptionsRecord record = new AxisOptionsRecord(TestcaseRecordInputStream.create(0x1062, data)); assertEquals( 0, record.getMinimumCategory()); @@ -61,8 +63,8 @@ public final class TestAxisOptionsRecord extends TestCase { assertEquals( 22, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { AxisOptionsRecord record = new AxisOptionsRecord(); record.setMinimumCategory( (short)0 ); record.setMaximumCategory( (short)0 ); @@ -84,8 +86,6 @@ public final class TestAxisOptionsRecord extends TestCase { byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(AxisOptionsRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestAxisParentRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestAxisParentRecord.java index 323f7f3c05..25fcc7695d 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestAxisParentRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestAxisParentRecord.java @@ -18,18 +18,18 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the AxisParentRecord * class works correctly. Test data taken directly from a real * Excel file. - * - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestAxisParentRecord extends TestCase { +public final class TestAxisParentRecord { byte[] data = new byte[] { (byte)0x00,(byte)0x00, // axis type (byte)0x1D,(byte)0x02,(byte)0x00,(byte)0x00, // x @@ -38,6 +38,7 @@ public final class TestAxisParentRecord extends TestCase { (byte)0x56,(byte)0x0B,(byte)0x00,(byte)0x00 // height }; + @Test public void testLoad() { AxisParentRecord record = new AxisParentRecord(TestcaseRecordInputStream.create(0x1041, data)); assertEquals( AxisParentRecord.AXIS_TYPE_MAIN, record.getAxisType()); @@ -49,8 +50,8 @@ public final class TestAxisParentRecord extends TestCase { assertEquals( 22, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { AxisParentRecord record = new AxisParentRecord(); record.setAxisType( AxisParentRecord.AXIS_TYPE_MAIN ); record.setX( 0x021d ); @@ -60,8 +61,6 @@ public final class TestAxisParentRecord extends TestCase { byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(AxisParentRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestAxisRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestAxisRecord.java index e8ebf322f5..f862dcc595 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestAxisRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestAxisRecord.java @@ -18,19 +18,18 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the AxisRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestAxisRecord extends TestCase { +public final class TestAxisRecord { byte[] data = new byte[] { (byte)0x00,(byte)0x00, // type (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, @@ -39,8 +38,8 @@ public final class TestAxisRecord extends TestCase { (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00 }; + @Test public void testLoad() { - AxisRecord record = new AxisRecord(TestcaseRecordInputStream.create(0x101d, data)); assertEquals( AxisRecord.AXIS_TYPE_CATEGORY_OR_X_AXIS, record.getAxisType()); assertEquals( 0, record.getReserved1()); @@ -51,8 +50,8 @@ public final class TestAxisRecord extends TestCase { assertEquals( 4 + 18, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { AxisRecord record = new AxisRecord(); record.setAxisType( AxisRecord.AXIS_TYPE_CATEGORY_OR_X_AXIS ); record.setReserved1( 0 ); @@ -60,10 +59,7 @@ public final class TestAxisRecord extends TestCase { record.setReserved3( 0 ); record.setReserved4( 0 ); - byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(AxisRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestAxisUsedRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestAxisUsedRecord.java index f421b4ffc6..0b3525b541 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestAxisUsedRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestAxisUsedRecord.java @@ -18,23 +18,23 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the AxisUsedRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestAxisUsedRecord extends TestCase { +public final class TestAxisUsedRecord { byte[] data = new byte[] { (byte)0x01,(byte)0x00, }; + @Test public void testLoad() { AxisUsedRecord record = new AxisUsedRecord(TestcaseRecordInputStream.create(0x1046, data)); assertEquals( 1, record.getNumAxis()); @@ -42,15 +42,12 @@ public final class TestAxisUsedRecord extends TestCase { assertEquals( 6, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { AxisUsedRecord record = new AxisUsedRecord(); record.setNumAxis( (short)1 ); - - byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + byte[] recordBytes = record.serialize(); + confirmRecordEncoding(AxisUsedRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestBarRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestBarRecord.java index 90d2f81bb8..16b919ee92 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestBarRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestBarRecord.java @@ -18,27 +18,27 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the BarRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestBarRecord extends TestCase { +public final class TestBarRecord { byte[] data = new byte[] { (byte)0x00,(byte)0x00, // bar space (byte)0x96,(byte)0x00, // category space (byte)0x00,(byte)0x00 // format flags }; + @Test public void testLoad() { - BarRecord record = new BarRecord(TestcaseRecordInputStream.create(0x1017, data)); assertEquals( 0, record.getBarSpace()); assertEquals( 0x96, record.getCategorySpace()); @@ -51,8 +51,8 @@ public final class TestBarRecord extends TestCase { assertEquals( 10, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { BarRecord record = new BarRecord(); record.setBarSpace( (short)0 ); record.setCategorySpace( (short)0x96 ); @@ -63,8 +63,6 @@ public final class TestBarRecord extends TestCase { byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(BarRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestCategorySeriesAxisRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestCategorySeriesAxisRecord.java index 68f5333618..b5bcdf9e38 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestCategorySeriesAxisRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestCategorySeriesAxisRecord.java @@ -18,19 +18,20 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the CategorySeriesAxisRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestCategorySeriesAxisRecord extends TestCase { +public final class TestCategorySeriesAxisRecord { byte[] data = new byte[] { (byte)0x01,(byte)0x00, // crossing point (byte)0x01,(byte)0x00, // label frequency @@ -38,8 +39,8 @@ public final class TestCategorySeriesAxisRecord extends TestCase { (byte)0x01,(byte)0x00 // options }; + @Test public void testLoad() { - CategorySeriesAxisRecord record = new CategorySeriesAxisRecord(TestcaseRecordInputStream.create(0x1020, data)); assertEquals( 1, record.getCrossingPoint()); assertEquals( 1, record.getLabelFrequency()); @@ -52,8 +53,8 @@ public final class TestCategorySeriesAxisRecord extends TestCase { assertEquals( 4 + 8, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { CategorySeriesAxisRecord record = new CategorySeriesAxisRecord(); record.setCrossingPoint( (short)1 ); record.setLabelFrequency( (short)1 ); @@ -64,8 +65,6 @@ public final class TestCategorySeriesAxisRecord extends TestCase { byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(CategorySeriesAxisRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestChartFormatRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestChartFormatRecord.java index 15c2090885..8d497e8699 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestChartFormatRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestChartFormatRecord.java @@ -18,20 +18,19 @@ package org.apache.poi.hssf.record.chart; import static org.junit.Assert.assertArrayEquals; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.TestcaseRecordInputStream; import org.apache.poi.util.HexRead; +import org.junit.Test; /** * Tests for {@link ChartFormatRecord} Test data taken directly from a real * Excel file. - * - * @author Josh Micich */ -public final class TestChartFormatRecord extends TestCase { +public final class TestChartFormatRecord { /** * This rather uninteresting data came from attachment 23347 of bug 46693 at * offsets 0x6BB2 and 0x7BAF @@ -45,12 +44,11 @@ public final class TestChartFormatRecord extends TestCase { /** * The correct size of a {@link ChartFormatRecord} is 20 bytes (not including header). */ + @Test public void testLoad() { RecordInputStream in = TestcaseRecordInputStream.create(data); ChartFormatRecord record = new ChartFormatRecord(in); - if (in.remaining() == 2) { - throw new AssertionFailedError("Identified bug 44693d"); - } + assertNotEquals("Identified bug 44693d", 2, in.remaining()); assertEquals(0, in.remaining()); assertEquals(24, record.getRecordSize()); diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestChartRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestChartRecord.java index c423d1b9a2..24fbc51966 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestChartRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestChartRecord.java @@ -18,19 +18,18 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the ChartRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestChartRecord extends TestCase { +public final class TestChartRecord { byte[] data = new byte[] { (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, @@ -38,8 +37,8 @@ public final class TestChartRecord extends TestCase { (byte)0xC8,(byte)0xCC,(byte)0xE5,(byte)0x00 }; + @Test public void testLoad() { - ChartRecord record = new ChartRecord(TestcaseRecordInputStream.create(0x1002, data)); assertEquals( 0, record.getX()); assertEquals( 0, record.getY()); @@ -49,8 +48,8 @@ public final class TestChartRecord extends TestCase { assertEquals( 20, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { ChartRecord record = new ChartRecord(); record.setX( 0 ); record.setY( 0 ); @@ -59,8 +58,6 @@ public final class TestChartRecord extends TestCase { byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(ChartRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestDatRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestDatRecord.java index ce2f581b17..970a6ba977 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestDatRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestDatRecord.java @@ -18,25 +18,26 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the DatRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestDatRecord extends TestCase { +public final class TestDatRecord { byte[] data = new byte[] { (byte)0x0D,(byte)0x00 // options }; + @Test public void testLoad() { - DatRecord record = new DatRecord(TestcaseRecordInputStream.create(0x1063, data)); assertEquals( 0xD, record.getOptions()); assertTrue(record.isHorizontalBorder()); @@ -47,8 +48,8 @@ public final class TestDatRecord extends TestCase { assertEquals( 6, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { DatRecord record = new DatRecord(); record.setHorizontalBorder( true ); record.setVerticalBorder( false ); @@ -57,8 +58,6 @@ public final class TestDatRecord extends TestCase { byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(DatRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestDataFormatRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestDataFormatRecord.java index 34a9534ff1..0ae90d7bcb 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestDataFormatRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestDataFormatRecord.java @@ -18,19 +18,19 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the DataFormatRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestDataFormatRecord extends TestCase { +public final class TestDataFormatRecord { byte[] data = new byte[] { (byte)0xFF,(byte)0xFF, // point number (byte)0x00,(byte)0x00, // series index @@ -38,8 +38,8 @@ public final class TestDataFormatRecord extends TestCase { (byte)0x00,(byte)0x00 // format flags }; + @Test public void testLoad() { - DataFormatRecord record = new DataFormatRecord(TestcaseRecordInputStream.create(0x1006, data)); assertEquals( (short)0xFFFF, record.getPointNumber()); assertEquals( 0, record.getSeriesIndex()); @@ -50,8 +50,8 @@ public final class TestDataFormatRecord extends TestCase { assertEquals( 12, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { DataFormatRecord record = new DataFormatRecord(); record.setPointNumber( (short)0xFFFF ); record.setSeriesIndex( (short)0 ); @@ -61,8 +61,6 @@ public final class TestDataFormatRecord extends TestCase { byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(DataFormatRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestDefaultDataLabelTextPropertiesRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestDefaultDataLabelTextPropertiesRecord.java index 32bddd81a1..f72055c44c 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestDefaultDataLabelTextPropertiesRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestDefaultDataLabelTextPropertiesRecord.java @@ -18,23 +18,23 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the DefaultDataLabelTextPropertiesRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestDefaultDataLabelTextPropertiesRecord extends TestCase { +public final class TestDefaultDataLabelTextPropertiesRecord { byte[] data = new byte[] { (byte)0x02,(byte)0x00 }; + @Test public void testLoad() { DefaultDataLabelTextPropertiesRecord record = new DefaultDataLabelTextPropertiesRecord(TestcaseRecordInputStream.create(0x1024, data)); @@ -43,15 +43,12 @@ public final class TestDefaultDataLabelTextPropertiesRecord extends TestCase { assertEquals( 6, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { DefaultDataLabelTextPropertiesRecord record = new DefaultDataLabelTextPropertiesRecord(); record.setCategoryDataType( (short)2 ); - byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(DefaultDataLabelTextPropertiesRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestFontBasisRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestFontBasisRecord.java index c783a34e6f..e9054e5f1a 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestFontBasisRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestFontBasisRecord.java @@ -14,23 +14,22 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the FontBasisRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestFontBasisRecord extends TestCase { +public final class TestFontBasisRecord { byte[] data = new byte[] { (byte)0x28,(byte)0x1A, // x basis (byte)0x9C,(byte)0x0F, // y basis @@ -39,8 +38,8 @@ public final class TestFontBasisRecord extends TestCase { (byte)0x05,(byte)0x00 // index to font table }; + @Test public void testLoad() { - FontBasisRecord record = new FontBasisRecord(TestcaseRecordInputStream.create(0x1060, data)); assertEquals( 0x1a28, record.getXBasis()); assertEquals( 0x0f9c, record.getYBasis()); @@ -51,8 +50,8 @@ public final class TestFontBasisRecord extends TestCase { assertEquals( 14, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { FontBasisRecord record = new FontBasisRecord(); record.setXBasis( (short)0x1a28 ); record.setYBasis( (short)0x0f9c ); @@ -61,8 +60,6 @@ public final class TestFontBasisRecord extends TestCase { record.setIndexToFontTable( (short)0x05 ); byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(FontBasisRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestFontIndexRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestFontIndexRecord.java index fb09d30dc6..3a2bb44417 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestFontIndexRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestFontIndexRecord.java @@ -18,23 +18,23 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the FontIndexRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestFontIndexRecord extends TestCase { +public final class TestFontIndexRecord { byte[] data = new byte[] { (byte)0x05,(byte)0x00 }; + @Test public void testLoad() { FontIndexRecord record = new FontIndexRecord(TestcaseRecordInputStream.create(0x1026, data)); @@ -43,15 +43,12 @@ public final class TestFontIndexRecord extends TestCase { assertEquals( 6, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { FontIndexRecord record = new FontIndexRecord(); record.setFontIndex( (short)5 ); - byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(FontIndexRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestFrameRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestFrameRecord.java index 512b46816d..6e42e8e1ff 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestFrameRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestFrameRecord.java @@ -18,26 +18,27 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the FrameRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestFrameRecord extends TestCase { +public final class TestFrameRecord { byte[] data = new byte[] { (byte)0x00,(byte)0x00, // border type (byte)0x02,(byte)0x00 // options }; + @Test public void testLoad() { - FrameRecord record = new FrameRecord(TestcaseRecordInputStream.create(0x1032, data)); assertEquals( FrameRecord.BORDER_TYPE_REGULAR, record.getBorderType()); assertEquals( 2, record.getOptions()); @@ -47,8 +48,8 @@ public final class TestFrameRecord extends TestCase { assertEquals( 8, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { FrameRecord record = new FrameRecord(); record.setBorderType( FrameRecord.BORDER_TYPE_REGULAR ); record.setOptions( (short)2 ); @@ -57,8 +58,6 @@ public final class TestFrameRecord extends TestCase { byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(FrameRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestLegendRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestLegendRecord.java index 3523a0b44b..1adf85a12f 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestLegendRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestLegendRecord.java @@ -17,23 +17,25 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the LegendRecord class works * correctly. Test data taken directly from a real Excel file. - * - * - * @author Andrew C. Oliver (acoliver at apache.org) */ -public final class TestLegendRecord extends TestCase { +public final class TestLegendRecord { byte[] data = new byte[] { (byte) 0x76, (byte) 0x0E, (byte) 0x00, (byte) 0x00, (byte) 0x86, (byte) 0x07, (byte) 0x00, (byte) 0x00, (byte) 0x19, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x8B, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x01, (byte) 0x1F, (byte) 0x00 }; + @Test public void testLoad() { LegendRecord record = new LegendRecord(TestcaseRecordInputStream.create(0x1015, data)); @@ -60,6 +62,7 @@ public final class TestLegendRecord extends TestCase { assertEquals(24, record.getRecordSize()); } + @Test public void testStore() { LegendRecord record = new LegendRecord(); @@ -84,8 +87,6 @@ public final class TestLegendRecord extends TestCase { record.setDataTable(false); byte[] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i + 4]); + confirmRecordEncoding(LegendRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestLineFormatRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestLineFormatRecord.java index f4230cdab3..2945a81c0c 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestLineFormatRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestLineFormatRecord.java @@ -18,19 +18,20 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the LineFormatRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestLineFormatRecord extends TestCase { +public final class TestLineFormatRecord { byte[] data = new byte[] { (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, // colour (byte)0x00,(byte)0x00, // pattern @@ -39,6 +40,7 @@ public final class TestLineFormatRecord extends TestCase { (byte)0x4D,(byte)0x00 // index }; + @Test public void testLoad() { LineFormatRecord record = new LineFormatRecord(TestcaseRecordInputStream.create(0x1007, data)); assertEquals( 0, record.getLineColor()); @@ -52,8 +54,8 @@ public final class TestLineFormatRecord extends TestCase { assertEquals( 16, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { LineFormatRecord record = new LineFormatRecord(); record.setLineColor( 0 ); record.setLinePattern( (short)0 ); @@ -64,8 +66,6 @@ public final class TestLineFormatRecord extends TestCase { byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(LineFormatRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestLinkedDataRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestLinkedDataRecord.java index 02e9483928..ce9476906c 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestLinkedDataRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestLinkedDataRecord.java @@ -18,20 +18,21 @@ package org.apache.poi.hssf.record.chart; -import junit.framework.TestCase; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import org.apache.poi.hssf.record.TestcaseRecordInputStream; import org.apache.poi.ss.formula.ptg.Area3DPtg; import org.apache.poi.ss.formula.ptg.Ptg; +import org.junit.Test; /** * Tests the serialization and deserialization of the LinkedDataRecord * class works correctly. Test data taken directly from a real * Excel file. - * - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestLinkedDataRecord extends TestCase { +public final class TestLinkedDataRecord { /* The records below are records that would appear in a simple bar chart @@ -156,8 +157,8 @@ recordid = 0x1051, size =8 (byte)0x00,(byte)0x00, // index to last column and relative flags }; + @Test public void testLoad() { - LinkedDataRecord record = new LinkedDataRecord(TestcaseRecordInputStream.create(0x1051, data)); assertEquals( LinkedDataRecord.LINK_TYPE_VALUES, record.getLinkType()); assertEquals( LinkedDataRecord.REFERENCE_TYPE_WORKSHEET, record.getReferenceType()); @@ -167,13 +168,14 @@ recordid = 0x1051, size =8 Area3DPtg ptgExpected = new Area3DPtg(0, 7936, 0, 0, false, false, false, false, 0); - + Ptg ptgActual = record.getFormulaOfLink()[0]; assertEquals(ptgExpected.toString(), ptgActual.toString()); assertEquals( data.length + 4, record.getRecordSize() ); } + @Test public void testStore() { LinkedDataRecord record = new LinkedDataRecord(); record.setLinkType( LinkedDataRecord.LINK_TYPE_VALUES ); @@ -186,8 +188,6 @@ recordid = 0x1051, size =8 record.setFormulaOfLink(new Ptg[] { ptg, } ); byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(LinkedDataRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestNumberFormatIndexRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestNumberFormatIndexRecord.java index d06f646c58..052c861bc6 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestNumberFormatIndexRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestNumberFormatIndexRecord.java @@ -18,40 +18,36 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the NumberFormatIndexRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestNumberFormatIndexRecord extends TestCase { +public final class TestNumberFormatIndexRecord { byte[] data = new byte[] { 0x05,0x00 }; + @Test public void testLoad() { - NumberFormatIndexRecord record = new NumberFormatIndexRecord(TestcaseRecordInputStream.create(0x104e, data)); assertEquals( 5, record.getFormatIndex()); assertEquals( 6, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { NumberFormatIndexRecord record = new NumberFormatIndexRecord(); record.setFormatIndex( (short)5 ); - byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(NumberFormatIndexRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestObjectLinkRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestObjectLinkRecord.java index f12babe136..f1ab4a1461 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestObjectLinkRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestObjectLinkRecord.java @@ -18,26 +18,26 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the ObjectLinkRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Andrew C. Oliver (acoliver at apache.org) */ -public final class TestObjectLinkRecord extends TestCase { +public final class TestObjectLinkRecord { byte[] data = new byte[] { (byte)0x03,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00 }; + @Test public void testLoad() { ObjectLinkRecord record = new ObjectLinkRecord(TestcaseRecordInputStream.create(0x1027, data)); - + assertEquals( (short)3, record.getAnchorId()); assertEquals( (short)0x00, record.getLink1()); assertEquals( (short)0x00, record.getLink2()); @@ -45,6 +45,7 @@ public final class TestObjectLinkRecord extends TestCase { assertEquals( 10, record.getRecordSize() ); } + @Test public void testStore() { ObjectLinkRecord record = new ObjectLinkRecord(); @@ -54,8 +55,6 @@ public final class TestObjectLinkRecord extends TestCase { byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(ObjectLinkRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestPlotAreaRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestPlotAreaRecord.java index bfd678b305..ece7eefd91 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestPlotAreaRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestPlotAreaRecord.java @@ -18,35 +18,33 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the PlotAreaRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Andrew C. Oliver (acoliver at apache.org) */ -public final class TestPlotAreaRecord extends TestCase { +public final class TestPlotAreaRecord { byte[] data = new byte[] { - + }; + @Test public void testLoad() { PlotAreaRecord record = new PlotAreaRecord(TestcaseRecordInputStream.create(0x1035, data)); assertEquals( 4, record.getRecordSize() ); } + @Test public void testStore() { PlotAreaRecord record = new PlotAreaRecord(); byte [] recordBytes = record.serialize(); assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestPlotGrowthRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestPlotGrowthRecord.java index cb7de70b0e..65b007d792 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestPlotGrowthRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestPlotGrowthRecord.java @@ -18,23 +18,24 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the PlotGrowthRecord * class works correctly. Test data taken directly from a real * Excel file. - * - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestPlotGrowthRecord extends TestCase { +public final class TestPlotGrowthRecord { byte[] data = new byte[] { (byte)0x00,(byte)0x00,(byte)0x01,(byte)0x00, // horizontal (byte)0x00,(byte)0x00,(byte)0x01,(byte)0x00 // vertical }; + @Test public void testLoad() { PlotGrowthRecord record = new PlotGrowthRecord(TestcaseRecordInputStream.create(0x1064, data)); @@ -44,16 +45,14 @@ public final class TestPlotGrowthRecord extends TestCase { assertEquals( 12, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { PlotGrowthRecord record = new PlotGrowthRecord(); record.setHorizontalScale( 65536 ); record.setVerticalScale( 65536 ); byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(PlotGrowthRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesChartGroupIndexRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesChartGroupIndexRecord.java index d216cc2f2c..a8c6cdb716 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesChartGroupIndexRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesChartGroupIndexRecord.java @@ -18,22 +18,23 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the SeriesChartGroupIndexRecord * class works correctly. Test data taken directly from a real * Excel file. - * - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestSeriesChartGroupIndexRecord extends TestCase { +public final class TestSeriesChartGroupIndexRecord { byte[] data = new byte[] { (byte)0x00,(byte)0x00 }; + @Test public void testLoad() { SeriesChartGroupIndexRecord record = new SeriesChartGroupIndexRecord(TestcaseRecordInputStream.create(0x1045, data)); assertEquals( 0, record.getChartGroupIndex()); @@ -41,15 +42,13 @@ public final class TestSeriesChartGroupIndexRecord extends TestCase { assertEquals( 6, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { SeriesChartGroupIndexRecord record = new SeriesChartGroupIndexRecord(); record.setChartGroupIndex( (short)0 ); byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(SeriesChartGroupIndexRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesIndexRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesIndexRecord.java index 86f24a38bc..af82aff3cb 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesIndexRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesIndexRecord.java @@ -18,42 +18,37 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the SeriesIndexRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Andrew C. Oliver (acoliver at apache.org) */ -public final class TestSeriesIndexRecord extends TestCase { +public final class TestSeriesIndexRecord { byte[] data = new byte[] { (byte)0x03,(byte)0x00 }; + @Test public void testLoad() { SeriesIndexRecord record = new SeriesIndexRecord(TestcaseRecordInputStream.create(0x1065, data)); - + assertEquals( (short)3, record.getIndex()); assertEquals( 6, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { SeriesIndexRecord record = new SeriesIndexRecord(); - - - record.setIndex( (short)3 ); byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(SeriesIndexRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesLabelsRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesLabelsRecord.java index 9d0c52daee..91c809d1f4 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesLabelsRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesLabelsRecord.java @@ -18,23 +18,25 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the SeriesLabelsRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestSeriesLabelsRecord extends TestCase { +public final class TestSeriesLabelsRecord { byte[] data = new byte[] { (byte)0x03,(byte)0x00 }; + @Test public void testLoad() { SeriesLabelsRecord record = new SeriesLabelsRecord(TestcaseRecordInputStream.create(0x100c, data)); assertEquals( 3, record.getFormatFlags()); @@ -45,12 +47,11 @@ public final class TestSeriesLabelsRecord extends TestCase { assertFalse(record.isShowLabel()); assertFalse(record.isShowBubbleSizes()); - assertEquals( 2+4, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { SeriesLabelsRecord record = new SeriesLabelsRecord(); record.setShowActual( true ); record.setShowPercent( true ); @@ -61,8 +62,6 @@ public final class TestSeriesLabelsRecord extends TestCase { byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(SeriesLabelsRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesListRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesListRecord.java index c049de4f30..c35178a7c5 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesListRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesListRecord.java @@ -18,23 +18,23 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the SeriesListRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestSeriesListRecord extends TestCase { +public final class TestSeriesListRecord { private static final byte[] data = { (byte)0x02,(byte)0x00,(byte)0x01,(byte)0x20,(byte)0xff,(byte)0xf0 }; + @Test public void testLoad() { SeriesListRecord record = new SeriesListRecord(TestcaseRecordInputStream.create(0x1016, data)); @@ -45,12 +45,11 @@ public final class TestSeriesListRecord extends TestCase { assertEquals( 4 + 6, record.getRecordSize() ); } + @Test public void testStore() { SeriesListRecord record = new SeriesListRecord(new short[] { (short)0x2001, (short)0xf0ff } ); byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(SeriesListRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesRecord.java index dacaae10d1..cff843b8a5 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesRecord.java @@ -18,18 +18,18 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the SeriesRecord * class works correctly. Test data taken directly from a real * Excel file. - * - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestSeriesRecord extends TestCase { +public final class TestSeriesRecord { byte[] data = new byte[] { (byte)0x01,(byte)0x00, // category data type (byte)0x01,(byte)0x00, // values data type @@ -39,8 +39,8 @@ public final class TestSeriesRecord extends TestCase { (byte)0x00,(byte)0x00 // num bubble values }; + @Test public void testLoad() { - SeriesRecord record = new SeriesRecord(TestcaseRecordInputStream.create(0x1003, data)); assertEquals( SeriesRecord.CATEGORY_DATA_TYPE_NUMERIC, record.getCategoryDataType()); assertEquals( SeriesRecord.VALUES_DATA_TYPE_NUMERIC, record.getValuesDataType()); @@ -53,8 +53,8 @@ public final class TestSeriesRecord extends TestCase { assertEquals( 16, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { SeriesRecord record = new SeriesRecord(); record.setCategoryDataType( SeriesRecord.CATEGORY_DATA_TYPE_NUMERIC ); record.setValuesDataType( SeriesRecord.VALUES_DATA_TYPE_NUMERIC ); @@ -64,8 +64,6 @@ public final class TestSeriesRecord extends TestCase { record.setNumBubbleValues( (short)0 ); byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(SeriesRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesTextRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesTextRecord.java index e05252d972..c705e3b798 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesTextRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesTextRecord.java @@ -17,25 +17,23 @@ package org.apache.poi.hssf.record.chart; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.TestcaseRecordInputStream; import org.apache.poi.util.HexRead; -import org.apache.poi.util.RecordFormatException; - -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import org.junit.Test; /** * Tests the serialization and deserialization of the SeriesTextRecord class * works correctly. Test data taken directly from a real Excel file. - * - * - * @author Andrew C. Oliver (acoliver at apache.org) */ -public final class TestSeriesTextRecord extends TestCase { +public final class TestSeriesTextRecord { private static final byte[] SIMPLE_DATA = HexRead .readFromString("00 00 0C 00 56 61 6C 75 65 20 4E 75 6D 62 65 72"); + @Test public void testLoad() { SeriesTextRecord record = new SeriesTextRecord(TestcaseRecordInputStream.create(0x100d, SIMPLE_DATA)); @@ -45,6 +43,7 @@ public final class TestSeriesTextRecord extends TestCase { assertEquals(SIMPLE_DATA.length + 4, record.getRecordSize()); } + @Test public void testStore() { SeriesTextRecord record = new SeriesTextRecord(); @@ -52,10 +51,10 @@ public final class TestSeriesTextRecord extends TestCase { record.setText("Value Number"); byte[] recordBytes = record.serialize(); - TestcaseRecordInputStream.confirmRecordEncoding(SeriesTextRecord.sid, SIMPLE_DATA, - recordBytes); + TestcaseRecordInputStream.confirmRecordEncoding(SeriesTextRecord.sid, SIMPLE_DATA, recordBytes); } + @Test public void testReserializeLongTitle() { // Hex dump from bug 45784 attachment 22560 streamOffset=0x0CD1 byte[] data = HexRead.readFromString( @@ -81,28 +80,14 @@ public final class TestSeriesTextRecord extends TestCase { + "62 00 63 00"); RecordInputStream in = TestcaseRecordInputStream.create(SeriesTextRecord.sid, data); - SeriesTextRecord str; - try { - str = new SeriesTextRecord(in); - } catch (RecordFormatException e) { - if (e.getCause() instanceof IllegalArgumentException) { - // 'would be' error msg changed at svn r703620 - // "Illegal length - asked for -126 but only 130 left!" - // "Bad requested string length (-126)" - throw new AssertionFailedError("Identified bug 45784a"); - } - throw e; - } + // Identified bug 45784a + // 'would be' error msg changed at svn r703620 + // "Illegal length - asked for -126 but only 130 left!" + // "Bad requested string length (-126)" + SeriesTextRecord str = new SeriesTextRecord(in); - if (str.getRecordSize() < 0) { - throw new AssertionFailedError("Identified bug 45784b"); - } - byte[] ser; - try { - ser = str.serialize(); - } catch (Exception e) { - throw new RuntimeException(e); - } + assertTrue("Identified bug 45784b", str.getRecordSize() >= 0); + byte[] ser = str.serialize(); TestcaseRecordInputStream.confirmRecordEncoding(SeriesTextRecord.sid, data, ser); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesToChartGroupRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesToChartGroupRecord.java index 22ad685c2b..fcec0025dc 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesToChartGroupRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesToChartGroupRecord.java @@ -18,23 +18,23 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the SeriesToChartGroupRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Andrew C. Oliver (acoliver at apache.org) */ -public final class TestSeriesToChartGroupRecord extends TestCase { +public final class TestSeriesToChartGroupRecord { byte[] data = new byte[] { (byte)0x0, (byte)0x0 }; + @Test public void testLoad() { SeriesToChartGroupRecord record = new SeriesToChartGroupRecord(TestcaseRecordInputStream.create(0x1045, data)); assertEquals( 0x0, record.getChartGroupIndex()); @@ -42,15 +42,12 @@ public final class TestSeriesToChartGroupRecord extends TestCase { assertEquals( 0x6, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { SeriesToChartGroupRecord record = new SeriesToChartGroupRecord(); record.setChartGroupIndex( (short)0x0 ); - byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(SeriesToChartGroupRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestSheetPropertiesRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestSheetPropertiesRecord.java index 9c9059f8f5..b8faa10d40 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestSheetPropertiesRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestSheetPropertiesRecord.java @@ -18,31 +18,32 @@ package org.apache.poi.hssf.record.chart; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.TestcaseRecordInputStream; - -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import org.junit.Test; /** * Tests for {@link SheetPropertiesRecord} * Test data taken directly from a real Excel file. - * - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestSheetPropertiesRecord extends TestCase { +public final class TestSheetPropertiesRecord { private static final byte[] data = { (byte)0x0A,(byte)0x00, (byte)0x00, (byte)0x00, // not sure where that last byte comes from }; + @Test public void testLoad() { RecordInputStream in = TestcaseRecordInputStream.create(0x1044, data); SheetPropertiesRecord record = new SheetPropertiesRecord(in); - if (in.remaining() == 1) { - throw new AssertionFailedError("Identified bug 44693c"); - } + assertNotEquals("Identified bug 44693c", 1, in.remaining()); assertEquals(0, in.remaining()); assertEquals( 10, record.getFlags()); assertFalse(record.isChartTypeManuallyFormatted()); @@ -55,6 +56,7 @@ public final class TestSheetPropertiesRecord extends TestCase { assertEquals( 8, record.getRecordSize() ); } + @Test public void testStore() { SheetPropertiesRecord record = new SheetPropertiesRecord(); record.setChartTypeManuallyFormatted( false ); @@ -66,6 +68,6 @@ public final class TestSheetPropertiesRecord extends TestCase { byte [] recordBytes = record.serialize(); - TestcaseRecordInputStream.confirmRecordEncoding(SheetPropertiesRecord.sid, data, recordBytes); + confirmRecordEncoding(SheetPropertiesRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestTextRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestTextRecord.java index cdca0f82b8..a46fddc112 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestTextRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestTextRecord.java @@ -18,18 +18,20 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the TextRecord * class works correctly. Test data taken directly from a real * Excel file. - * - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestTextRecord extends TestCase { +public final class TestTextRecord { byte[] data = new byte[] { (byte)0x02, // horiz align (byte)0x02, // vert align @@ -45,8 +47,8 @@ public final class TestTextRecord extends TestCase { (byte)0x00,(byte)0x00 // text rotation }; + @Test public void testLoad() { - TextRecord record = new TextRecord(TestcaseRecordInputStream.create(0x1025, data)); assertEquals( TextRecord.HORIZONTAL_ALIGNMENT_CENTER, record.getHorizontalAlignment()); assertEquals( TextRecord.VERTICAL_ALIGNMENT_CENTER, record.getVerticalAlignment()); @@ -79,8 +81,8 @@ public final class TestTextRecord extends TestCase { assertEquals( 36, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { TextRecord record = new TextRecord(); record.setHorizontalAlignment( TextRecord.HORIZONTAL_ALIGNMENT_CENTER ); record.setVerticalAlignment( TextRecord.VERTICAL_ALIGNMENT_CENTER ); @@ -110,8 +112,6 @@ public final class TestTextRecord extends TestCase { byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(TextRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestTickRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestTickRecord.java index 0f2b1353bb..efd8a0383e 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestTickRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestTickRecord.java @@ -18,18 +18,19 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the TickRecord * 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 { +public final class TestTickRecord { private static final byte[] data = { (byte)0x02, (byte)0x00, (byte)0x03, (byte)0x01, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, @@ -40,6 +41,7 @@ public final class TestTickRecord extends TestCase { (byte)0x4D, (byte)0x00, (byte)0x00, (byte)0x00 }; + @Test public void testLoad() { TickRecord record = new TickRecord(TestcaseRecordInputStream.create(0x101e, data)); assertEquals( (byte)2, record.getMajorTickType()); @@ -61,6 +63,7 @@ public final class TestTickRecord extends TestCase { assertEquals( 34, record.getRecordSize() ); } + @Test public void testStore() { TickRecord record = new TickRecord(); record.setMajorTickType( (byte)2 ); @@ -80,8 +83,6 @@ public final class TestTickRecord extends TestCase { byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(TickRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestUnitsRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestUnitsRecord.java index 4c142bdb05..450cc93316 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestUnitsRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestUnitsRecord.java @@ -18,23 +18,23 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the UnitsRecord * class works correctly. Test data taken directly from a real * Excel file. - * - - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestUnitsRecord extends TestCase { +public final class TestUnitsRecord { byte[] data = new byte[] { (byte)0x00, (byte)0x00 }; + @Test public void testLoad() { UnitsRecord record = new UnitsRecord(TestcaseRecordInputStream.create(0x1001, data)); @@ -43,15 +43,13 @@ public final class TestUnitsRecord extends TestCase { assertEquals( 6, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { UnitsRecord record = new UnitsRecord(); record.setUnits( (short)0 ); byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(UnitsRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestValueRangeRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestValueRangeRecord.java index abd3badc44..bd4d16af71 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestValueRangeRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestValueRangeRecord.java @@ -18,19 +18,20 @@ package org.apache.poi.hssf.record.chart; -import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; -import junit.framework.TestCase; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Tests the serialization and deserialization of the ValueRangeRecord * class works correctly. Test data taken directly from a real * Excel file. - * - * - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestValueRangeRecord extends TestCase { +public final class TestValueRangeRecord { byte[] data = new byte[] { (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, // min axis value (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, // max axis value @@ -40,6 +41,7 @@ public final class TestValueRangeRecord extends TestCase { (byte)0x1F,(byte)0x01 // options }; + @Test public void testLoad() { ValueRangeRecord record = new ValueRangeRecord(TestcaseRecordInputStream.create(0x101f, data)); @@ -62,8 +64,8 @@ public final class TestValueRangeRecord extends TestCase { assertEquals( 42+4, record.getRecordSize() ); } - public void testStore() - { + @Test + public void testStore() { ValueRangeRecord record = new ValueRangeRecord(); record.setMinimumAxisValue( 0 ); record.setMaximumAxisValue( 0 ); @@ -81,8 +83,6 @@ public final class TestValueRangeRecord extends TestCase { record.setReserved( true ); byte [] recordBytes = record.serialize(); - assertEquals(recordBytes.length - 4, data.length); - for (int i = 0; i < data.length; i++) - assertEquals("At offset " + i, data[i], recordBytes[i+4]); + confirmRecordEncoding(ValueRangeRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/pivot/AllPivotRecordTests.java b/src/testcases/org/apache/poi/hssf/record/pivot/AllPivotRecordTests.java index 1787317b80..3f25e99398 100644 --- a/src/testcases/org/apache/poi/hssf/record/pivot/AllPivotRecordTests.java +++ b/src/testcases/org/apache/poi/hssf/record/pivot/AllPivotRecordTests.java @@ -17,22 +17,17 @@ package org.apache.poi.hssf.record.pivot; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; /** * Collects all tests for org.apache.poi.hssf.record.pivot. - * - * @author Josh Micich */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ + TestExtendedPivotTableViewFieldsRecord.class, + TestPageItemRecord.class, + TestViewFieldsRecord.class +}) public final class AllPivotRecordTests { - - public static Test suite() { - TestSuite result = new TestSuite(AllPivotRecordTests.class.getName()); - - result.addTestSuite(TestExtendedPivotTableViewFieldsRecord.class); - result.addTestSuite(TestPageItemRecord.class); - result.addTestSuite(TestViewFieldsRecord.class); - return result; - } } diff --git a/src/testcases/org/apache/poi/hssf/record/pivot/TestExtendedPivotTableViewFieldsRecord.java b/src/testcases/org/apache/poi/hssf/record/pivot/TestExtendedPivotTableViewFieldsRecord.java index bf79bcb0d7..8418388c54 100644 --- a/src/testcases/org/apache/poi/hssf/record/pivot/TestExtendedPivotTableViewFieldsRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/pivot/TestExtendedPivotTableViewFieldsRecord.java @@ -17,60 +17,46 @@ package org.apache.poi.hssf.record.pivot; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; + import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.TestcaseRecordInputStream; import org.apache.poi.hssf.record.pivottable.ExtendedPivotTableViewFieldsRecord; import org.apache.poi.util.HexRead; -import org.apache.poi.util.RecordFormatException; - -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import org.junit.Test; /** * Tests for {@link ExtendedPivotTableViewFieldsRecord} - * - * @author Josh Micich */ -public final class TestExtendedPivotTableViewFieldsRecord extends TestCase { - +public final class TestExtendedPivotTableViewFieldsRecord { + + @Test public void testSubNameNotPresent_bug46693() { // This data came from attachment 23347 of bug 46693 at offset 0xAA43 byte[] data = HexRead.readFromString( "00 01 14 00" + // BIFF header "1E 14 00 0A FF FF FF FF 00 00 FF FF 00 00 00 00 00 00 00 00"); RecordInputStream in = TestcaseRecordInputStream.create(data); - ExtendedPivotTableViewFieldsRecord rec; - try { - rec = new ExtendedPivotTableViewFieldsRecord(in); - } catch (RecordFormatException e) { - if (e.getMessage().equals("Expected to find a ContinueRecord in order to read remaining 65535 of 65535 chars")) { - throw new AssertionFailedError("Identified bug 46693a"); - } - throw e; - } - + // bug 46693a - Expected to find a ContinueRecord in order to read remaining 65535 of 65535 chars + ExtendedPivotTableViewFieldsRecord rec = new ExtendedPivotTableViewFieldsRecord(in); + assertEquals(data.length, rec.getRecordSize()); } - + + @Test public void testOlderFormat_bug46918() { // There are 10 SXVDEX records in the file (not uploaded) that originated bugzilla 46918 // They all had the following hex encoding: byte[] data = HexRead.readFromString("00 01 0A 00 1E 14 00 0A FF FF FF FF 00 00"); RecordInputStream in = TestcaseRecordInputStream.create(data); - ExtendedPivotTableViewFieldsRecord rec; - try { - rec = new ExtendedPivotTableViewFieldsRecord(in); - } catch (RecordFormatException e) { - if (e.getMessage().equals("Not enough data (0) to read requested (2) bytes")) { - throw new AssertionFailedError("Identified bug 46918"); - } - throw e; - } + // bug 46918 - Not enough data (0) to read requested (2) bytes + ExtendedPivotTableViewFieldsRecord rec = new ExtendedPivotTableViewFieldsRecord(in); byte[] expReserData = HexRead.readFromString("1E 14 00 0A FF FF FF FF 00 00" + "FF FF 00 00 00 00 00 00 00 00"); - - TestcaseRecordInputStream.confirmRecordEncoding(ExtendedPivotTableViewFieldsRecord.sid, expReserData, rec.serialize()); + + confirmRecordEncoding(ExtendedPivotTableViewFieldsRecord.sid, expReserData, rec.serialize()); } } diff --git a/src/testcases/org/apache/poi/hssf/record/pivot/TestPageItemRecord.java b/src/testcases/org/apache/poi/hssf/record/pivot/TestPageItemRecord.java index 7cf3b49299..1468fc1401 100644 --- a/src/testcases/org/apache/poi/hssf/record/pivot/TestPageItemRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/pivot/TestPageItemRecord.java @@ -17,47 +17,45 @@ package org.apache.poi.hssf.record.pivot; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.TestcaseRecordInputStream; import org.apache.poi.hssf.record.pivottable.PageItemRecord; import org.apache.poi.util.HexRead; +import org.junit.Test; /** * Tests for {@link PageItemRecord} - * - * @author Josh Micich */ -public final class TestPageItemRecord extends TestCase { - +public final class TestPageItemRecord { + @Test public void testMoreThanOneInfoItem_bug46917() { byte[] data = HexRead.readFromString("01 02 03 04 05 06 07 08 09 0A 0B 0C"); RecordInputStream in = TestcaseRecordInputStream.create(PageItemRecord.sid, data); PageItemRecord rec = new PageItemRecord(in); - if (in.remaining() == 6) { - throw new AssertionFailedError("Identified bug 46917"); - } + assertNotEquals("Identified bug 46917", 6, in.remaining()); assertEquals(0, in.remaining()); - + assertEquals(4+data.length, rec.getRecordSize()); } - + + @Test public void testSerialize() { confirmSerialize("01 02 03 04 05 06"); confirmSerialize("01 02 03 04 05 06 07 08 09 0A 0B 0C"); confirmSerialize("01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12"); } - private static PageItemRecord confirmSerialize(String hexDump) { + private static void confirmSerialize(String hexDump) { byte[] data = HexRead.readFromString(hexDump); RecordInputStream in = TestcaseRecordInputStream.create(PageItemRecord.sid, data); PageItemRecord rec = new PageItemRecord(in); assertEquals(0, in.remaining()); assertEquals(4+data.length, rec.getRecordSize()); byte[] data2 = rec.serialize(); - TestcaseRecordInputStream.confirmRecordEncoding(PageItemRecord.sid, data, data2); - return rec; + confirmRecordEncoding(PageItemRecord.sid, data, data2); } } diff --git a/src/testcases/org/apache/poi/hssf/record/pivot/TestViewFieldsRecord.java b/src/testcases/org/apache/poi/hssf/record/pivot/TestViewFieldsRecord.java index 448a2acb3d..3ab92651b3 100644 --- a/src/testcases/org/apache/poi/hssf/record/pivot/TestViewFieldsRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/pivot/TestViewFieldsRecord.java @@ -17,48 +17,47 @@ package org.apache.poi.hssf.record.pivot; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.TestcaseRecordInputStream; import org.apache.poi.hssf.record.pivottable.ViewFieldsRecord; import org.apache.poi.util.HexRead; +import org.junit.Test; /** * Tests for {@link ViewFieldsRecord} - * - * @author Josh Micich */ -public final class TestViewFieldsRecord extends TestCase { - +public final class TestViewFieldsRecord { + + @Test public void testUnicodeFlag_bug46693() { byte[] data = HexRead.readFromString("01 00 01 00 01 00 04 00 05 00 00 6D 61 72 63 6F"); RecordInputStream in = TestcaseRecordInputStream.create(ViewFieldsRecord.sid, data); ViewFieldsRecord rec = new ViewFieldsRecord(in); - if (in.remaining() == 1) { - throw new AssertionFailedError("Identified bug 46693b"); - } + assertNotEquals("Identified bug 46693b", 1, in.remaining()); assertEquals(0, in.remaining()); assertEquals(4+data.length, rec.getRecordSize()); } - + + @Test public void testSerialize() { - // This hex data was produced by changing the 'Custom Name' property, + // This hex data was produced by changing the 'Custom Name' property, // available under 'Field Settings' from the 'PivotTable Field List' (Excel 2007) confirmSerialize("00 00 01 00 01 00 00 00 FF FF"); confirmSerialize("01 00 01 00 01 00 04 00 05 00 00 6D 61 72 63 6F"); confirmSerialize("01 00 01 00 01 00 04 00 0A 00 01 48 00 69 00 73 00 74 00 6F 00 72 00 79 00 2D 00 82 69 81 89"); } - private static ViewFieldsRecord confirmSerialize(String hexDump) { + private static void confirmSerialize(String hexDump) { byte[] data = HexRead.readFromString(hexDump); RecordInputStream in = TestcaseRecordInputStream.create(ViewFieldsRecord.sid, data); ViewFieldsRecord rec = new ViewFieldsRecord(in); assertEquals(0, in.remaining()); assertEquals(4+data.length, rec.getRecordSize()); byte[] data2 = rec.serialize(); - TestcaseRecordInputStream.confirmRecordEncoding(ViewFieldsRecord.sid, data, data2); - return rec; + confirmRecordEncoding(ViewFieldsRecord.sid, data, data2); } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/RecordInspector.java b/src/testcases/org/apache/poi/hssf/usermodel/RecordInspector.java deleted file mode 100644 index 2a49b7d250..0000000000 --- a/src/testcases/org/apache/poi/hssf/usermodel/RecordInspector.java +++ /dev/null @@ -1,68 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hssf.usermodel; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.poi.hssf.record.Record; -import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor; - -/** - * Test utility class to get {@link Record}s out of HSSF objects - * - * @author Josh Micich - */ -public final class RecordInspector { - - private RecordInspector() { - // no instances of this class - } - - public static final class RecordCollector implements RecordVisitor { - - private final List _list; - - public RecordCollector() { - _list = new ArrayList<>(128); - } - - @Override - public void visitRecord(Record r) { - _list.add(r); - } - - public Record[] getRecords() { - Record[] result = new Record[_list.size()]; - _list.toArray(result); - return result; - } - } - - /** - * @param streamOffset start position for serialization. This affects values in some - * records such as INDEX, but most callers will be OK to pass zero. - * @return the {@link Record}s (in order) which will be output when the - * specified sheet is serialized - */ - public static Record[] getRecords(HSSFSheet hSheet, int streamOffset) { - RecordCollector rc = new RecordCollector(); - hSheet.getSheet().visitContainedRecords(rc, streamOffset); - return rc.getRecords(); - } -} diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java b/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java index bd03399c28..1bac320643 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java @@ -17,6 +17,14 @@ package org.apache.poi.hssf.usermodel; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -39,13 +47,11 @@ import org.apache.poi.util.LocaleUtil; import org.apache.poi.util.TempFile; import org.junit.Test; -import junit.framework.TestCase; - /** * Class to test cell styling functionality */ -public final class TestCellStyle extends TestCase { +public final class TestCellStyle { private static HSSFWorkbook openSample(String sampleFileName) { return HSSFTestDataSamples.openSampleWorkbook(sampleFileName); @@ -61,39 +67,39 @@ public final class TestCellStyle extends TestCase { * HSSFSheet last row or first row is incorrect.

    * */ + @Test public void testWriteSheetFont() throws IOException{ - File file = TempFile.createTempFile("testWriteSheetFont", - ".xls"); - FileOutputStream out = new FileOutputStream(file); - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet s = wb.createSheet(); - HSSFRow r = null; - HSSFCell c = null; - HSSFFont fnt = wb.createFont(); - HSSFCellStyle cs = wb.createCellStyle(); + File file = TempFile.createTempFile("testWriteSheetFont", ".xls"); + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet s = wb.createSheet(); + HSSFFont fnt = wb.createFont(); + HSSFCellStyle cs = wb.createCellStyle(); - fnt.setColor(HSSFFont.COLOR_RED); - fnt.setBold(true); - cs.setFont(fnt); - for (int rownum = 0; rownum < 100; rownum++) { - r = s.createRow(rownum); + fnt.setColor(HSSFFont.COLOR_RED); + fnt.setBold(true); + cs.setFont(fnt); + for (int rownum = 0; rownum < 100; rownum++) { + HSSFRow r = s.createRow(rownum); - for (int cellnum = 0; cellnum < 50; cellnum += 2) { - c = r.createCell(cellnum); - c.setCellValue(rownum * 10000 + cellnum - + ((( double ) rownum / 1000) - + (( double ) cellnum / 10000))); - c = r.createCell(cellnum + 1); - c.setCellValue("TEST"); - c.setCellStyle(cs); + for (int cellnum = 0; cellnum < 50; cellnum += 2) { + HSSFCell c = r.createCell(cellnum); + c.setCellValue(rownum * 10000 + cellnum + + (((double) rownum / 1000) + + ((double) cellnum / 10000))); + c = r.createCell(cellnum + 1); + c.setCellValue("TEST"); + c.setCellStyle(cs); + } } + try (FileOutputStream out = new FileOutputStream(file)) { + wb.write(out); + } + + SanityChecker sanityChecker = new SanityChecker(); + sanityChecker.checkHSSFWorkbook(wb); + assertEquals("LAST ROW == 99", 99, s.getLastRowNum()); + assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum()); } - wb.write(out); - out.close(); - SanityChecker sanityChecker = new SanityChecker(); - sanityChecker.checkHSSFWorkbook(wb); - assertEquals("LAST ROW == 99", 99, s.getLastRowNum()); - assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum()); // assert((s.getLastRowNum() == 99)); } @@ -101,66 +107,67 @@ public final class TestCellStyle extends TestCase { /** * Tests that is creating a file with a date or an calendar works correctly. */ + @Test public void testDataStyle() throws IOException { - File file = TempFile.createTempFile("testWriteSheetStyleDate", - ".xls"); - FileOutputStream out = new FileOutputStream(file); - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet s = wb.createSheet(); - HSSFCellStyle cs = wb.createCellStyle(); - HSSFRow row = s.createRow(0); + File file = TempFile.createTempFile("testWriteSheetStyleDate", ".xls"); + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet s = wb.createSheet(); + HSSFCellStyle cs = wb.createCellStyle(); + HSSFRow row = s.createRow(0); - // with Date: - HSSFCell cell = row.createCell(1); - cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); - cell.setCellStyle(cs); - cell.setCellValue(new Date()); + // with Date: + HSSFCell cell = row.createCell(1); + cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); + cell.setCellStyle(cs); + cell.setCellValue(new Date()); - // with Calendar: - cell = row.createCell(2); - cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); - cell.setCellStyle(cs); - Calendar cal = LocaleUtil.getLocaleCalendar(); - cell.setCellValue(cal); + // with Calendar: + cell = row.createCell(2); + cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); + cell.setCellStyle(cs); + Calendar cal = LocaleUtil.getLocaleCalendar(); + cell.setCellValue(cal); - wb.write(out); - out.close(); - SanityChecker sanityChecker = new SanityChecker(); - sanityChecker.checkHSSFWorkbook(wb); + try (FileOutputStream out = new FileOutputStream(file)) { + wb.write(out); + } + SanityChecker sanityChecker = new SanityChecker(); + sanityChecker.checkHSSFWorkbook(wb); - assertEquals("LAST ROW ", 0, s.getLastRowNum()); - assertEquals("FIRST ROW ", 0, s.getFirstRowNum()); + assertEquals("LAST ROW ", 0, s.getLastRowNum()); + assertEquals("FIRST ROW ", 0, s.getFirstRowNum()); + } } - + + @Test public void testHashEquals() throws IOException { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet s = wb.createSheet(); - HSSFCellStyle cs1 = wb.createCellStyle(); - HSSFCellStyle cs2 = wb.createCellStyle(); - HSSFRow row = s.createRow(0); - HSSFCell cell1 = row.createCell(1); - HSSFCell cell2 = row.createCell(2); - - cs1.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); - cs2.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/dd/yy")); - - cell1.setCellStyle(cs1); - cell1.setCellValue(new Date()); - - cell2.setCellStyle(cs2); - cell2.setCellValue(new Date()); - - assertEquals(cs1.hashCode(), cs1.hashCode()); - assertEquals(cs2.hashCode(), cs2.hashCode()); - assertEquals(cs1, cs1); - assertEquals(cs2, cs2); - - // Change cs1, hash will alter - int hash1 = cs1.hashCode(); - cs1.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/dd/yy")); - assertFalse(hash1 == cs1.hashCode()); - - wb.close(); + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet s = wb.createSheet(); + HSSFCellStyle cs1 = wb.createCellStyle(); + HSSFCellStyle cs2 = wb.createCellStyle(); + HSSFRow row = s.createRow(0); + HSSFCell cell1 = row.createCell(1); + HSSFCell cell2 = row.createCell(2); + + cs1.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); + cs2.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/dd/yy")); + + cell1.setCellStyle(cs1); + cell1.setCellValue(new Date()); + + cell2.setCellStyle(cs2); + cell2.setCellValue(new Date()); + + assertEquals(cs1.hashCode(), cs1.hashCode()); + assertEquals(cs2.hashCode(), cs2.hashCode()); + assertEquals(cs1, cs1); + assertEquals(cs2, cs2); + + // Change cs1, hash will alter + int hash1 = cs1.hashCode(); + cs1.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/dd/yy")); + assertNotEquals(hash1, cs1.hashCode()); + } } /** @@ -173,252 +180,265 @@ public final class TestCellStyle extends TestCase { * HSSFSheet last row or first row is incorrect.

    * */ + @Test public void testWriteSheetStyle() throws IOException { - File file = TempFile.createTempFile("testWriteSheetStyle", - ".xls"); - FileOutputStream out = new FileOutputStream(file); - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet s = wb.createSheet(); - HSSFRow r = null; - HSSFCell c = null; - HSSFFont fnt = wb.createFont(); - HSSFCellStyle cs = wb.createCellStyle(); - HSSFCellStyle cs2 = wb.createCellStyle(); + File file = TempFile.createTempFile("testWriteSheetStyle", ".xls"); + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet s = wb.createSheet(); + HSSFRow r = null; + HSSFCell c = null; + HSSFFont fnt = wb.createFont(); + HSSFCellStyle cs = wb.createCellStyle(); + HSSFCellStyle cs2 = wb.createCellStyle(); - cs.setBorderBottom(BorderStyle.THIN); - cs.setBorderLeft(BorderStyle.THIN); - cs.setBorderRight(BorderStyle.THIN); - cs.setBorderTop(BorderStyle.THIN); - cs.setFillForegroundColor(( short ) 0xA); - cs.setFillPattern(FillPatternType.DIAMONDS); - fnt.setColor(( short ) 0xf); - fnt.setItalic(true); - cs2.setFillForegroundColor(( short ) 0x0); - cs2.setFillPattern(FillPatternType.DIAMONDS); - cs2.setFont(fnt); - for (int rownum = 0; rownum < 100; rownum++) { - r = s.createRow(rownum); + cs.setBorderBottom(BorderStyle.THIN); + cs.setBorderLeft(BorderStyle.THIN); + cs.setBorderRight(BorderStyle.THIN); + cs.setBorderTop(BorderStyle.THIN); + cs.setFillForegroundColor((short) 0xA); + cs.setFillPattern(FillPatternType.DIAMONDS); + fnt.setColor((short) 0xf); + fnt.setItalic(true); + cs2.setFillForegroundColor((short) 0x0); + cs2.setFillPattern(FillPatternType.DIAMONDS); + cs2.setFont(fnt); + for (int rownum = 0; rownum < 100; rownum++) { + r = s.createRow(rownum); - for (int cellnum = 0; cellnum < 50; cellnum += 2) { - c = r.createCell(cellnum); - c.setCellValue(rownum * 10000 + cellnum - + ((( double ) rownum / 1000) - + (( double ) cellnum / 10000))); - c.setCellStyle(cs); - c = r.createCell(cellnum + 1); - c.setCellValue("TEST"); - c.setCellStyle(cs2); + for (int cellnum = 0; cellnum < 50; cellnum += 2) { + c = r.createCell(cellnum); + c.setCellValue(rownum * 10000 + cellnum + + (((double) rownum / 1000) + + ((double) cellnum / 10000))); + c.setCellStyle(cs); + c = r.createCell(cellnum + 1); + c.setCellValue("TEST"); + c.setCellStyle(cs2); + } } + try (FileOutputStream out = new FileOutputStream(file)) { + wb.write(out); + } + SanityChecker sanityChecker = new SanityChecker(); + sanityChecker.checkHSSFWorkbook(wb); + assertEquals("LAST ROW == 99", 99, s.getLastRowNum()); + assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum()); } - wb.write(out); - out.close(); - SanityChecker sanityChecker = new SanityChecker(); - sanityChecker.checkHSSFWorkbook(wb); - assertEquals("LAST ROW == 99", 99, s.getLastRowNum()); - assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum()); } - + /** * Cloning one HSSFCellStyle onto Another, same * HSSFWorkbook */ - public void testCloneStyleSameWB() { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFFont fnt = wb.createFont(); - fnt.setFontName("TestingFont"); - assertEquals(5, wb.getNumberOfFonts()); - - HSSFCellStyle orig = wb.createCellStyle(); - orig.setAlignment(HorizontalAlignment.JUSTIFY); - orig.setFont(fnt); - orig.setDataFormat((short)18); - - assertEquals(HorizontalAlignment.JUSTIFY, orig.getAlignment()); - assertEquals(fnt, orig.getFont(wb)); - assertEquals(18, orig.getDataFormat()); - - HSSFCellStyle clone = wb.createCellStyle(); - assertNotSame(HorizontalAlignment.RIGHT, clone.getAlignment()); - assertNotSame(fnt, clone.getFont(wb)); - assertFalse(18 == clone.getDataFormat()); - - clone.cloneStyleFrom(orig); - assertEquals(HorizontalAlignment.JUSTIFY, clone.getAlignment()); - assertEquals(fnt, clone.getFont(wb)); - assertEquals(18, clone.getDataFormat()); - assertEquals(5, wb.getNumberOfFonts()); + @Test + public void testCloneStyleSameWB() throws IOException { + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFFont fnt = wb.createFont(); + fnt.setFontName("TestingFont"); + assertEquals(5, wb.getNumberOfFonts()); + + HSSFCellStyle orig = wb.createCellStyle(); + orig.setAlignment(HorizontalAlignment.JUSTIFY); + orig.setFont(fnt); + orig.setDataFormat((short) 18); + + assertEquals(HorizontalAlignment.JUSTIFY, orig.getAlignment()); + assertEquals(fnt, orig.getFont(wb)); + assertEquals(18, orig.getDataFormat()); + + HSSFCellStyle clone = wb.createCellStyle(); + assertNotSame(HorizontalAlignment.RIGHT, clone.getAlignment()); + assertNotSame(fnt, clone.getFont(wb)); + assertNotEquals(18, clone.getDataFormat()); + + clone.cloneStyleFrom(orig); + assertEquals(HorizontalAlignment.JUSTIFY, clone.getAlignment()); + assertEquals(fnt, clone.getFont(wb)); + assertEquals(18, clone.getDataFormat()); + assertEquals(5, wb.getNumberOfFonts()); + } } - + /** * Cloning one HSSFCellStyle onto Another, across * two different HSSFWorkbooks */ - public void testCloneStyleDiffWB() { - HSSFWorkbook wbOrig = new HSSFWorkbook(); - - HSSFFont fnt = wbOrig.createFont(); - fnt.setFontName("TestingFont"); - assertEquals(5, wbOrig.getNumberOfFonts()); - - HSSFDataFormat fmt = wbOrig.createDataFormat(); - fmt.getFormat("MadeUpOne"); - fmt.getFormat("MadeUpTwo"); - - HSSFCellStyle orig = wbOrig.createCellStyle(); - orig.setAlignment(HorizontalAlignment.RIGHT); - orig.setFont(fnt); - orig.setDataFormat(fmt.getFormat("Test##")); - - assertEquals(HorizontalAlignment.RIGHT, orig.getAlignment()); - assertEquals(fnt, orig.getFont(wbOrig)); - assertEquals(fmt.getFormat("Test##"), orig.getDataFormat()); - - // Now a style on another workbook - HSSFWorkbook wbClone = new HSSFWorkbook(); - assertEquals(4, wbClone.getNumberOfFonts()); - HSSFDataFormat fmtClone = wbClone.createDataFormat(); - - HSSFCellStyle clone = wbClone.createCellStyle(); - assertEquals(4, wbClone.getNumberOfFonts()); + @Test + public void testCloneStyleDiffWB() throws IOException { + try (HSSFWorkbook wbOrig = new HSSFWorkbook()) { - assertNotSame(HorizontalAlignment.RIGHT, clone.getAlignment()); - assertNotSame("TestingFont", clone.getFont(wbClone).getFontName()); - - clone.cloneStyleFrom(orig); - assertEquals(HorizontalAlignment.RIGHT, clone.getAlignment()); - assertEquals("TestingFont", clone.getFont(wbClone).getFontName()); - assertEquals(fmtClone.getFormat("Test##"), clone.getDataFormat()); - assertFalse(fmtClone.getFormat("Test##") == fmt.getFormat("Test##")); - assertEquals(5, wbClone.getNumberOfFonts()); - } - - public void testStyleNames() { - HSSFWorkbook wb = openSample("WithExtendedStyles.xls"); - HSSFSheet s = wb.getSheetAt(0); - HSSFCell c1 = s.getRow(0).getCell(0); - HSSFCell c2 = s.getRow(1).getCell(0); - HSSFCell c3 = s.getRow(2).getCell(0); - - HSSFCellStyle cs1 = c1.getCellStyle(); - HSSFCellStyle cs2 = c2.getCellStyle(); - HSSFCellStyle cs3 = c3.getCellStyle(); - - assertNotNull(cs1); - assertNotNull(cs2); - assertNotNull(cs3); - - // Check we got the styles we'd expect - assertEquals(10, cs1.getFont(wb).getFontHeightInPoints()); - assertEquals(9, cs2.getFont(wb).getFontHeightInPoints()); - assertEquals(12, cs3.getFont(wb).getFontHeightInPoints()); - - assertEquals(15, cs1.getIndex()); - assertEquals(23, cs2.getIndex()); - assertEquals(24, cs3.getIndex()); - - assertNull(cs1.getParentStyle()); - assertNotNull(cs2.getParentStyle()); - assertNotNull(cs3.getParentStyle()); - - assertEquals(21, cs2.getParentStyle().getIndex()); - assertEquals(22, cs3.getParentStyle().getIndex()); - - // Now check we can get style records for - // the parent ones - assertNull(wb.getWorkbook().getStyleRecord(15)); - assertNull(wb.getWorkbook().getStyleRecord(23)); - assertNull(wb.getWorkbook().getStyleRecord(24)); - - assertNotNull(wb.getWorkbook().getStyleRecord(21)); - assertNotNull(wb.getWorkbook().getStyleRecord(22)); - - // Now check the style names - assertNull(cs1.getUserStyleName()); - assertNull(cs2.getUserStyleName()); - assertNull(cs3.getUserStyleName()); - assertEquals("style1", cs2.getParentStyle().getUserStyleName()); - assertEquals("style2", cs3.getParentStyle().getUserStyleName()); + HSSFFont fnt = wbOrig.createFont(); + fnt.setFontName("TestingFont"); + assertEquals(5, wbOrig.getNumberOfFonts()); - // now apply a named style to a new cell - HSSFCell c4 = s.getRow(0).createCell(1); - c4.setCellStyle(cs2); - assertEquals("style1", c4.getCellStyle().getParentStyle().getUserStyleName()); - } - - public void testGetSetBorderHair() { - HSSFWorkbook wb = openSample("55341_CellStyleBorder.xls"); - HSSFSheet s = wb.getSheetAt(0); - HSSFCellStyle cs; + HSSFDataFormat fmt = wbOrig.createDataFormat(); + fmt.getFormat("MadeUpOne"); + fmt.getFormat("MadeUpTwo"); - cs = s.getRow(0).getCell(0).getCellStyle(); - assertEquals(BorderStyle.HAIR, cs.getBorderRight()); + HSSFCellStyle orig = wbOrig.createCellStyle(); + orig.setAlignment(HorizontalAlignment.RIGHT); + orig.setFont(fnt); + orig.setDataFormat(fmt.getFormat("Test##")); - cs = s.getRow(1).getCell(1).getCellStyle(); - assertEquals(BorderStyle.DOTTED, cs.getBorderRight()); + assertEquals(HorizontalAlignment.RIGHT, orig.getAlignment()); + assertEquals(fnt, orig.getFont(wbOrig)); + assertEquals(fmt.getFormat("Test##"), orig.getDataFormat()); - cs = s.getRow(2).getCell(2).getCellStyle(); - assertEquals(BorderStyle.DASH_DOT_DOT, cs.getBorderRight()); + // Now a style on another workbook + try (HSSFWorkbook wbClone = new HSSFWorkbook()) { + assertEquals(4, wbClone.getNumberOfFonts()); + HSSFDataFormat fmtClone = wbClone.createDataFormat(); - cs = s.getRow(3).getCell(3).getCellStyle(); - assertEquals(BorderStyle.DASHED, cs.getBorderRight()); + HSSFCellStyle clone = wbClone.createCellStyle(); + assertEquals(4, wbClone.getNumberOfFonts()); - cs = s.getRow(4).getCell(4).getCellStyle(); - assertEquals(BorderStyle.THIN, cs.getBorderRight()); + assertNotSame(HorizontalAlignment.RIGHT, clone.getAlignment()); + assertNotSame("TestingFont", clone.getFont(wbClone).getFontName()); - cs = s.getRow(5).getCell(5).getCellStyle(); - assertEquals(BorderStyle.MEDIUM_DASH_DOT_DOT, cs.getBorderRight()); - - cs = s.getRow(6).getCell(6).getCellStyle(); - assertEquals(BorderStyle.SLANTED_DASH_DOT, cs.getBorderRight()); - - cs = s.getRow(7).getCell(7).getCellStyle(); - assertEquals(BorderStyle.MEDIUM_DASH_DOT, cs.getBorderRight()); - - cs = s.getRow(8).getCell(8).getCellStyle(); - assertEquals(BorderStyle.MEDIUM_DASHED, cs.getBorderRight()); - - cs = s.getRow(9).getCell(9).getCellStyle(); - assertEquals(BorderStyle.MEDIUM, cs.getBorderRight()); - - cs = s.getRow(10).getCell(10).getCellStyle(); - assertEquals(BorderStyle.THICK, cs.getBorderRight()); - - cs = s.getRow(11).getCell(11).getCellStyle(); - assertEquals(BorderStyle.DOUBLE, cs.getBorderRight()); + clone.cloneStyleFrom(orig); + assertEquals(HorizontalAlignment.RIGHT, clone.getAlignment()); + assertEquals("TestingFont", clone.getFont(wbClone).getFontName()); + assertEquals(fmtClone.getFormat("Test##"), clone.getDataFormat()); + assertNotEquals(fmtClone.getFormat("Test##"), fmt.getFormat("Test##")); + assertEquals(5, wbClone.getNumberOfFonts()); + } + } } - public void testShrinkToFit() { + @Test + public void testStyleNames() throws IOException { + try (HSSFWorkbook wb = openSample("WithExtendedStyles.xls")) { + HSSFSheet s = wb.getSheetAt(0); + HSSFCell c1 = s.getRow(0).getCell(0); + HSSFCell c2 = s.getRow(1).getCell(0); + HSSFCell c3 = s.getRow(2).getCell(0); + + HSSFCellStyle cs1 = c1.getCellStyle(); + HSSFCellStyle cs2 = c2.getCellStyle(); + HSSFCellStyle cs3 = c3.getCellStyle(); + + assertNotNull(cs1); + assertNotNull(cs2); + assertNotNull(cs3); + + // Check we got the styles we'd expect + assertEquals(10, cs1.getFont(wb).getFontHeightInPoints()); + assertEquals(9, cs2.getFont(wb).getFontHeightInPoints()); + assertEquals(12, cs3.getFont(wb).getFontHeightInPoints()); + + assertEquals(15, cs1.getIndex()); + assertEquals(23, cs2.getIndex()); + assertEquals(24, cs3.getIndex()); + + assertNull(cs1.getParentStyle()); + assertNotNull(cs2.getParentStyle()); + assertNotNull(cs3.getParentStyle()); + + assertEquals(21, cs2.getParentStyle().getIndex()); + assertEquals(22, cs3.getParentStyle().getIndex()); + + // Now check we can get style records for the parent ones + assertNull(wb.getWorkbook().getStyleRecord(15)); + assertNull(wb.getWorkbook().getStyleRecord(23)); + assertNull(wb.getWorkbook().getStyleRecord(24)); + + assertNotNull(wb.getWorkbook().getStyleRecord(21)); + assertNotNull(wb.getWorkbook().getStyleRecord(22)); + + // Now check the style names + assertNull(cs1.getUserStyleName()); + assertNull(cs2.getUserStyleName()); + assertNull(cs3.getUserStyleName()); + assertEquals("style1", cs2.getParentStyle().getUserStyleName()); + assertEquals("style2", cs3.getParentStyle().getUserStyleName()); + + // now apply a named style to a new cell + HSSFCell c4 = s.getRow(0).createCell(1); + c4.setCellStyle(cs2); + assertEquals("style1", c4.getCellStyle().getParentStyle().getUserStyleName()); + } + } + + @Test + public void testGetSetBorderHair() throws IOException { + try (HSSFWorkbook wb = openSample("55341_CellStyleBorder.xls")) { + HSSFSheet s = wb.getSheetAt(0); + HSSFCellStyle cs; + + cs = s.getRow(0).getCell(0).getCellStyle(); + assertEquals(BorderStyle.HAIR, cs.getBorderRight()); + + cs = s.getRow(1).getCell(1).getCellStyle(); + assertEquals(BorderStyle.DOTTED, cs.getBorderRight()); + + cs = s.getRow(2).getCell(2).getCellStyle(); + assertEquals(BorderStyle.DASH_DOT_DOT, cs.getBorderRight()); + + cs = s.getRow(3).getCell(3).getCellStyle(); + assertEquals(BorderStyle.DASHED, cs.getBorderRight()); + + cs = s.getRow(4).getCell(4).getCellStyle(); + assertEquals(BorderStyle.THIN, cs.getBorderRight()); + + cs = s.getRow(5).getCell(5).getCellStyle(); + assertEquals(BorderStyle.MEDIUM_DASH_DOT_DOT, cs.getBorderRight()); + + cs = s.getRow(6).getCell(6).getCellStyle(); + assertEquals(BorderStyle.SLANTED_DASH_DOT, cs.getBorderRight()); + + cs = s.getRow(7).getCell(7).getCellStyle(); + assertEquals(BorderStyle.MEDIUM_DASH_DOT, cs.getBorderRight()); + + cs = s.getRow(8).getCell(8).getCellStyle(); + assertEquals(BorderStyle.MEDIUM_DASHED, cs.getBorderRight()); + + cs = s.getRow(9).getCell(9).getCellStyle(); + assertEquals(BorderStyle.MEDIUM, cs.getBorderRight()); + + cs = s.getRow(10).getCell(10).getCellStyle(); + assertEquals(BorderStyle.THICK, cs.getBorderRight()); + + cs = s.getRow(11).getCell(11).getCellStyle(); + assertEquals(BorderStyle.DOUBLE, cs.getBorderRight()); + } + } + + @Test + public void testShrinkToFit() throws IOException { // Existing file - HSSFWorkbook wb = openSample("ShrinkToFit.xls"); - HSSFSheet s = wb.getSheetAt(0); - HSSFRow r = s.getRow(0); - HSSFCellStyle cs = r.getCell(0).getCellStyle(); + try (HSSFWorkbook wb1 = openSample("ShrinkToFit.xls")) { + HSSFSheet s = wb1.getSheetAt(0); + HSSFRow r = s.getRow(0); + HSSFCellStyle cs = r.getCell(0).getCellStyle(); - assertTrue(cs.getShrinkToFit()); + assertTrue(cs.getShrinkToFit()); + } - // New file - HSSFWorkbook wbOrig = new HSSFWorkbook(); - s = wbOrig.createSheet(); - r = s.createRow(0); + // New file + try (HSSFWorkbook wbOrig = new HSSFWorkbook()) { + HSSFSheet s = wbOrig.createSheet(); + HSSFRow r = s.createRow(0); - cs = wbOrig.createCellStyle(); - cs.setShrinkToFit(false); - r.createCell(0).setCellStyle(cs); + HSSFCellStyle cs = wbOrig.createCellStyle(); + cs.setShrinkToFit(false); + r.createCell(0).setCellStyle(cs); - cs = wbOrig.createCellStyle(); - cs.setShrinkToFit(true); - r.createCell(1).setCellStyle(cs); + cs = wbOrig.createCellStyle(); + cs.setShrinkToFit(true); + r.createCell(1).setCellStyle(cs); - // Write out, read, and check - wb = HSSFTestDataSamples.writeOutAndReadBack(wbOrig); - s = wb.getSheetAt(0); - r = s.getRow(0); - assertFalse(r.getCell(0).getCellStyle().getShrinkToFit()); - assertTrue(r.getCell(1).getCellStyle().getShrinkToFit()); + // Write out, read, and check + try (HSSFWorkbook wb = HSSFTestDataSamples.writeOutAndReadBack(wbOrig)) { + s = wb.getSheetAt(0); + r = s.getRow(0); + assertFalse(r.getCell(0).getCellStyle().getShrinkToFit()); + assertTrue(r.getCell(1).getCellStyle().getShrinkToFit()); + } + } } - - - + + + private static class CellFormatBugExample extends Thread { private final String fileName; private Throwable exception; @@ -431,18 +451,17 @@ public final class TestCellStyle extends TestCase { public void run() { try { for(int i = 0;i< 10;i++) { - Workbook wb = HSSFTestDataSamples.openSampleWorkbook(fileName); - Sheet sheet = wb.getSheetAt(0); - - for (Row row : sheet) { - for (Integer idxCell = 0; idxCell < row.getLastCellNum(); idxCell++) { - - Cell cell = row.getCell(idxCell); - cell.getCellStyle().getDataFormatString(); - if (cell.getCellType() == CellType.NUMERIC) { - boolean isDate = DateUtil.isCellDateFormatted(cell); - if (idxCell > 0 && isDate) { - fail("cell " + idxCell + " is not a date: " + idxCell); + try (Workbook wb = HSSFTestDataSamples.openSampleWorkbook(fileName)) { + Sheet sheet = wb.getSheetAt(0); + + for (Row row : sheet) { + for (Integer idxCell = 0; idxCell < row.getLastCellNum(); idxCell++) { + + Cell cell = row.getCell(idxCell); + cell.getCellStyle().getDataFormatString(); + if (cell.getCellType() == CellType.NUMERIC) { + boolean isDate = DateUtil.isCellDateFormatted(cell); + assertFalse("cell " + idxCell + " is not a date.", idxCell > 0 && isDate); } } } @@ -458,15 +477,16 @@ public final class TestCellStyle extends TestCase { } } + @Test public void test56563() throws Throwable { CellFormatBugExample threadA = new CellFormatBugExample("56563a.xls"); threadA.start(); CellFormatBugExample threadB = new CellFormatBugExample("56563b.xls"); threadB.start(); - + threadA.join(); threadB.join(); - + if(threadA.getException() != null) { throw threadA.getException(); } @@ -474,79 +494,73 @@ public final class TestCellStyle extends TestCase { throw threadB.getException(); } } - - public void test56959() throws IOException { - Workbook wb = new HSSFWorkbook(); - Sheet sheet = wb.createSheet("somesheet"); - - Row row = sheet.createRow(0); - - // Create a new font and alter it. - Font font = wb.createFont(); - font.setFontHeightInPoints((short)24); - font.setFontName("Courier New"); - font.setItalic(true); - font.setStrikeout(true); - font.setColor(Font.COLOR_RED); - - CellStyle style = wb.createCellStyle(); - style.setBorderBottom(BorderStyle.DOTTED); - style.setFont(font); - - Cell cell = row.createCell(0); - cell.setCellStyle(style); - cell.setCellValue("testtext"); - - Cell newCell = row.createCell(1); - - newCell.setCellStyle(style); - newCell.setCellValue("2testtext2"); - CellStyle newStyle = newCell.getCellStyle(); - assertEquals(BorderStyle.DOTTED, newStyle.getBorderBottom()); - assertEquals(Font.COLOR_RED, ((HSSFCellStyle)newStyle).getFont(wb).getColor()); - -// OutputStream out = new FileOutputStream("/tmp/56959.xls"); -// try { -// wb.write(out); -// } finally { -// out.close(); -// } + @Test + public void test56959() throws IOException { + try (Workbook wb = new HSSFWorkbook()) { + Sheet sheet = wb.createSheet("somesheet"); + + Row row = sheet.createRow(0); + + // Create a new font and alter it. + Font font = wb.createFont(); + font.setFontHeightInPoints((short) 24); + font.setFontName("Courier New"); + font.setItalic(true); + font.setStrikeout(true); + font.setColor(Font.COLOR_RED); + + CellStyle style = wb.createCellStyle(); + style.setBorderBottom(BorderStyle.DOTTED); + style.setFont(font); + + Cell cell = row.createCell(0); + cell.setCellStyle(style); + cell.setCellValue("testtext"); + + Cell newCell = row.createCell(1); + + newCell.setCellStyle(style); + newCell.setCellValue("2testtext2"); + + CellStyle newStyle = newCell.getCellStyle(); + assertEquals(BorderStyle.DOTTED, newStyle.getBorderBottom()); + assertEquals(Font.COLOR_RED, ((HSSFCellStyle) newStyle).getFont(wb).getColor()); + } } @Test public void test58043() throws IOException { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFCellStyle cellStyle = wb.createCellStyle(); + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFCellStyle cellStyle = wb.createCellStyle(); - assertEquals(0, cellStyle.getRotation()); + assertEquals(0, cellStyle.getRotation()); - cellStyle.setRotation((short)89); - assertEquals(89, cellStyle.getRotation()); - - cellStyle.setRotation((short)90); - assertEquals(90, cellStyle.getRotation()); - - cellStyle.setRotation((short)-1); - assertEquals(-1, cellStyle.getRotation()); - - cellStyle.setRotation((short)-89); - assertEquals(-89, cellStyle.getRotation()); - - cellStyle.setRotation((short)-90); - assertEquals(-90, cellStyle.getRotation()); - - cellStyle.setRotation((short)-89); - assertEquals(-89, cellStyle.getRotation()); + cellStyle.setRotation((short) 89); + assertEquals(89, cellStyle.getRotation()); - // values above 90 are mapped to the correct values for compatibility between HSSF and XSSF - cellStyle.setRotation((short)179); - assertEquals(-89, cellStyle.getRotation()); - - cellStyle.setRotation((short)180); - assertEquals(-90, cellStyle.getRotation()); - - wb.close(); + cellStyle.setRotation((short) 90); + assertEquals(90, cellStyle.getRotation()); + + cellStyle.setRotation((short) -1); + assertEquals(-1, cellStyle.getRotation()); + + cellStyle.setRotation((short) -89); + assertEquals(-89, cellStyle.getRotation()); + + cellStyle.setRotation((short) -90); + assertEquals(-90, cellStyle.getRotation()); + + cellStyle.setRotation((short) -89); + assertEquals(-89, cellStyle.getRotation()); + + // values above 90 are mapped to the correct values for compatibility between HSSF and XSSF + cellStyle.setRotation((short) 179); + assertEquals(-89, cellStyle.getRotation()); + + cellStyle.setRotation((short) 180); + assertEquals(-90, cellStyle.getRotation()); + } } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestEmbeddedObjects.java b/src/testcases/org/apache/poi/hssf/usermodel/TestEmbeddedObjects.java index 7d9fadaa84..51a5c64847 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestEmbeddedObjects.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestEmbeddedObjects.java @@ -17,46 +17,55 @@ package org.apache.poi.hssf.usermodel; -import junit.framework.TestCase; -import org.apache.poi.hssf.HSSFTestDataSamples; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import java.io.IOException; import java.util.List; +import org.apache.poi.hssf.HSSFTestDataSamples; +import org.junit.Test; + /** * Tests for the embedded object fetching support in HSSF */ -public class TestEmbeddedObjects extends TestCase{ +public class TestEmbeddedObjects { + @Test public void testReadExistingObject() throws IOException { - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("drawings.xls"); - List list = wb.getAllEmbeddedObjects(); - assertEquals(list.size(), 1); - HSSFObjectData obj = list.get(0); - assertNotNull(obj.getObjectData()); - assertNotNull(obj.getDirectory()); - assertNotNull(obj.getOLE2ClassName()); + try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("drawings.xls")) { + List list = wb.getAllEmbeddedObjects(); + assertEquals(list.size(), 1); + HSSFObjectData obj = list.get(0); + assertNotNull(obj.getObjectData()); + assertNotNull(obj.getDirectory()); + assertNotNull(obj.getOLE2ClassName()); + } } - + /** * Need to recurse into the shapes to find this one * See https://github.com/apache/poi/pull/2 */ + @Test public void testReadNestedObject() throws IOException { - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("WithCheckBoxes.xls"); - List list = wb.getAllEmbeddedObjects(); - assertEquals(list.size(), 1); - HSSFObjectData obj = list.get(0); - assertNotNull(obj.getObjectData()); - assertNotNull(obj.getOLE2ClassName()); + try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("WithCheckBoxes.xls")) { + List list = wb.getAllEmbeddedObjects(); + assertEquals(list.size(), 1); + HSSFObjectData obj = list.get(0); + assertNotNull(obj.getObjectData()); + assertNotNull(obj.getOLE2ClassName()); + } } - + /** * One with large numbers of recursivly embedded resources * See https://github.com/apache/poi/pull/2 */ + @Test public void testReadManyNestedObjects() throws IOException { - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("45538_form_Header.xls"); - List list = wb.getAllEmbeddedObjects(); - assertEquals(list.size(), 40); + try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("45538_form_Header.xls")) { + List list = wb.getAllEmbeddedObjects(); + assertEquals(list.size(), 40); + } } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestExternalReferenceChange.java b/src/testcases/org/apache/poi/hssf/usermodel/TestExternalReferenceChange.java index 86d59d8c74..39d7e13d90 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestExternalReferenceChange.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestExternalReferenceChange.java @@ -16,53 +16,52 @@ ==================================================================== */ package org.apache.poi.hssf.usermodel; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.ss.usermodel.CellType; +import org.junit.Test; -import junit.framework.TestCase; - -public class TestExternalReferenceChange extends TestCase { +public class TestExternalReferenceChange { private static final String MAIN_WORKBOOK_FILENAME = "52575_main.xls"; private static final String SOURCE_DUMMY_WORKBOOK_FILENAME = "source_dummy.xls"; private static final String SOURCE_WORKBOOK_FILENAME = "52575_source.xls"; - - private HSSFWorkbook mainWorkbook; - private HSSFWorkbook sourceWorkbook; - - @Override - protected void setUp() throws Exception { - mainWorkbook = HSSFTestDataSamples.openSampleWorkbook(MAIN_WORKBOOK_FILENAME); - sourceWorkbook = HSSFTestDataSamples.openSampleWorkbook(SOURCE_WORKBOOK_FILENAME); - - assertNotNull(mainWorkbook); - assertNotNull(sourceWorkbook); - } - + + @Test public void testDummyToSource() throws IOException { - boolean changed = mainWorkbook.changeExternalReference("DOESNOTEXIST", SOURCE_WORKBOOK_FILENAME); - assertFalse(changed); - - changed = mainWorkbook.changeExternalReference(SOURCE_DUMMY_WORKBOOK_FILENAME, SOURCE_WORKBOOK_FILENAME); - assertTrue(changed); + try (HSSFWorkbook mainWorkbook = HSSFTestDataSamples.openSampleWorkbook(MAIN_WORKBOOK_FILENAME); + HSSFWorkbook sourceWorkbook = HSSFTestDataSamples.openSampleWorkbook(SOURCE_WORKBOOK_FILENAME)) { - HSSFSheet lSheet = mainWorkbook.getSheetAt(0); - HSSFCell lA1Cell = lSheet.getRow(0).getCell(0); - - assertEquals(CellType.FORMULA, lA1Cell.getCellType()); - - HSSFFormulaEvaluator lMainWorkbookEvaluator = new HSSFFormulaEvaluator(mainWorkbook); - HSSFFormulaEvaluator lSourceEvaluator = new HSSFFormulaEvaluator(sourceWorkbook); - HSSFFormulaEvaluator.setupEnvironment( - new String[]{MAIN_WORKBOOK_FILENAME, SOURCE_WORKBOOK_FILENAME}, - new HSSFFormulaEvaluator[] {lMainWorkbookEvaluator, lSourceEvaluator}); - - assertEquals(CellType.NUMERIC, lMainWorkbookEvaluator.evaluateFormulaCell(lA1Cell)); + assertNotNull(mainWorkbook); + assertNotNull(sourceWorkbook); - assertEquals(20.0d, lA1Cell.getNumericCellValue(), 0.00001d); + boolean changed = mainWorkbook.changeExternalReference("DOESNOTEXIST", SOURCE_WORKBOOK_FILENAME); + assertFalse(changed); + changed = mainWorkbook.changeExternalReference(SOURCE_DUMMY_WORKBOOK_FILENAME, SOURCE_WORKBOOK_FILENAME); + assertTrue(changed); + + HSSFSheet lSheet = mainWorkbook.getSheetAt(0); + HSSFCell lA1Cell = lSheet.getRow(0).getCell(0); + + assertEquals(CellType.FORMULA, lA1Cell.getCellType()); + + HSSFFormulaEvaluator lMainWorkbookEvaluator = new HSSFFormulaEvaluator(mainWorkbook); + HSSFFormulaEvaluator lSourceEvaluator = new HSSFFormulaEvaluator(sourceWorkbook); + HSSFFormulaEvaluator.setupEnvironment( + new String[]{MAIN_WORKBOOK_FILENAME, SOURCE_WORKBOOK_FILENAME}, + new HSSFFormulaEvaluator[]{lMainWorkbookEvaluator, lSourceEvaluator}); + + assertEquals(CellType.NUMERIC, lMainWorkbookEvaluator.evaluateFormulaCell(lA1Cell)); + + assertEquals(20.0d, lA1Cell.getNumericCellValue(), 0.00001d); + } } - + } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestFontDetails.java b/src/testcases/org/apache/poi/hssf/usermodel/TestFontDetails.java index 724d26432a..724ffb29d0 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestFontDetails.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestFontDetails.java @@ -17,38 +17,41 @@ package org.apache.poi.hssf.usermodel; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; import java.util.Properties; +import org.junit.Before; +import org.junit.Test; + /** * Tests the implementation of the FontDetails class. - * - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestFontDetails extends TestCase { - private Properties properties; +public final class TestFontDetails { private FontDetails fontDetails; - @Override - protected void setUp() { - properties = new Properties(); + @Before + public void setUp() { + Properties properties = new Properties(); properties.setProperty("font.Arial.height", "13"); properties.setProperty("font.Arial.characters", "a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "); - properties.setProperty("font.Arial.widths", "6, 6, 6, 6, 6, 3, 6, 6, 3, 4, 6, 3, 9, 6, 6, 6, 6, 4, 6, 3, 6, 7, 9, 6, 5, 5, 7, 7, 7, 7, 7, 6, 8, 7, 3, 6, 7, 6, 9, 7, 8, 7, 8, 7, 7, 5, 7, 7, 9, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, "); + properties.setProperty("font.Arial.widths", "6, 6, 6, 6, 6, 3, 6, 6, 3, 4, 6, 3, 9, 6, 6, 6, 6, 4, 6, 3, 6, 7, 9, 6, 5, 5, 7, 7, 7, 7, 7, 6, 8, 7, 3, 6, 7, 6, 9, 7, 8, 7, 8, 7, 7, 5, 7, 7, 9, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, "); fontDetails = FontDetails.create("Arial", properties); } + @Test public void testCreate() { assertEquals(13, fontDetails.getHeight()); assertEquals(6, fontDetails.getCharWidth('a')); assertEquals(3, fontDetails.getCharWidth('f')); } + @Test public void testGetStringWidth() { assertEquals(9, fontDetails.getStringWidth("af")); } + @Test public void testGetCharWidth() { assertEquals(6, fontDetails.getCharWidth('a')); assertEquals(9, fontDetails.getCharWidth('=')); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java index 10726fc27c..d2f26ffec7 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java @@ -17,107 +17,112 @@ package org.apache.poi.hssf.usermodel; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; - -import junit.framework.TestCase; +import org.junit.Test; /** * Tests to show that our documentation at * http://poi.apache.org/hssf/eval.html * all actually works as we'd expect them to */ -public final class TestFormulaEvaluatorDocs extends TestCase { +public final class TestFormulaEvaluatorDocs { /** * http://poi.apache.org/hssf/eval.html#EvaluateAll */ - public void testEvaluateAll() { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet s1 = wb.createSheet(); - HSSFSheet s2 = wb.createSheet(); - wb.setSheetName(0, "S1"); - wb.setSheetName(1, "S2"); - - HSSFRow s1r1 = s1.createRow(0); - HSSFRow s1r2 = s1.createRow(1); - HSSFRow s2r1 = s2.createRow(0); - - HSSFCell s1r1c1 = s1r1.createCell(0); - HSSFCell s1r1c2 = s1r1.createCell(1); - HSSFCell s1r1c3 = s1r1.createCell(2); - s1r1c1.setCellValue(22.3); - s1r1c2.setCellValue(33.4); - s1r1c3.setCellFormula("SUM(A1:B1)"); - - HSSFCell s1r2c1 = s1r2.createCell(0); - HSSFCell s1r2c2 = s1r2.createCell(1); - HSSFCell s1r2c3 = s1r2.createCell(2); - s1r2c1.setCellValue(-1.2); - s1r2c2.setCellValue(-3.4); - s1r2c3.setCellFormula("SUM(A2:B2)"); - - HSSFCell s2r1c1 = s2r1.createCell(0); - s2r1c1.setCellFormula("S1!A1"); - - // Not evaluated yet - assertEquals(0.0, s1r1c3.getNumericCellValue(), 0); - assertEquals(0.0, s1r2c3.getNumericCellValue(), 0); - assertEquals(0.0, s2r1c1.getNumericCellValue(), 0); - - // Do a full evaluate, as per our docs - // uses evaluateFormulaCell() - for(Sheet sheet : wb) { - HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb); - for(Row r : sheet) { - for(Cell c : r) { - if(c.getCellType() == CellType.FORMULA) { - evaluator.evaluateFormulaCell(c); - - // For testing - all should be numeric - assertEquals(CellType.NUMERIC, evaluator.evaluateFormulaCell(c)); - } - } - } - } - - // Check now as expected - assertEquals(55.7, wb.getSheetAt(0).getRow(0).getCell(2).getNumericCellValue(), 0); - assertEquals("SUM(A1:B1)", wb.getSheetAt(0).getRow(0).getCell(2).getCellFormula()); - assertEquals(CellType.FORMULA, wb.getSheetAt(0).getRow(0).getCell(2).getCellType()); - - assertEquals(-4.6, wb.getSheetAt(0).getRow(1).getCell(2).getNumericCellValue(), 0); - assertEquals("SUM(A2:B2)", wb.getSheetAt(0).getRow(1).getCell(2).getCellFormula()); - assertEquals(CellType.FORMULA, wb.getSheetAt(0).getRow(1).getCell(2).getCellType()); - - assertEquals(22.3, wb.getSheetAt(1).getRow(0).getCell(0).getNumericCellValue(), 0); - assertEquals("'S1'!A1", wb.getSheetAt(1).getRow(0).getCell(0).getCellFormula()); - assertEquals(CellType.FORMULA, wb.getSheetAt(1).getRow(0).getCell(0).getCellType()); - - - // Now do the alternate call, which zaps the formulas - // uses evaluateInCell() - for(Sheet sheet : wb) { - HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb); + @Test + public void testEvaluateAll() throws IOException { + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet s1 = wb.createSheet(); + HSSFSheet s2 = wb.createSheet(); + wb.setSheetName(0, "S1"); + wb.setSheetName(1, "S2"); - for(Row r : sheet) { - for(Cell c : r) { - if(c.getCellType() == CellType.FORMULA) { - evaluator.evaluateInCell(c); + HSSFRow s1r1 = s1.createRow(0); + HSSFRow s1r2 = s1.createRow(1); + HSSFRow s2r1 = s2.createRow(0); + + HSSFCell s1r1c1 = s1r1.createCell(0); + HSSFCell s1r1c2 = s1r1.createCell(1); + HSSFCell s1r1c3 = s1r1.createCell(2); + s1r1c1.setCellValue(22.3); + s1r1c2.setCellValue(33.4); + s1r1c3.setCellFormula("SUM(A1:B1)"); + + HSSFCell s1r2c1 = s1r2.createCell(0); + HSSFCell s1r2c2 = s1r2.createCell(1); + HSSFCell s1r2c3 = s1r2.createCell(2); + s1r2c1.setCellValue(-1.2); + s1r2c2.setCellValue(-3.4); + s1r2c3.setCellFormula("SUM(A2:B2)"); + + HSSFCell s2r1c1 = s2r1.createCell(0); + s2r1c1.setCellFormula("S1!A1"); + + // Not evaluated yet + assertEquals(0.0, s1r1c3.getNumericCellValue(), 0); + assertEquals(0.0, s1r2c3.getNumericCellValue(), 0); + assertEquals(0.0, s2r1c1.getNumericCellValue(), 0); + + // Do a full evaluate, as per our docs + // uses evaluateFormulaCell() + for (Sheet sheet : wb) { + HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb); + for (Row r : sheet) { + for (Cell c : r) { + if (c.getCellType() == CellType.FORMULA) { + evaluator.evaluateFormulaCell(c); + + // For testing - all should be numeric + assertEquals(CellType.NUMERIC, evaluator.evaluateFormulaCell(c)); + } } } } + + // Check now as expected + assertEquals(55.7, wb.getSheetAt(0).getRow(0).getCell(2).getNumericCellValue(), 0); + assertEquals("SUM(A1:B1)", wb.getSheetAt(0).getRow(0).getCell(2).getCellFormula()); + assertEquals(CellType.FORMULA, wb.getSheetAt(0).getRow(0).getCell(2).getCellType()); + + assertEquals(-4.6, wb.getSheetAt(0).getRow(1).getCell(2).getNumericCellValue(), 0); + assertEquals("SUM(A2:B2)", wb.getSheetAt(0).getRow(1).getCell(2).getCellFormula()); + assertEquals(CellType.FORMULA, wb.getSheetAt(0).getRow(1).getCell(2).getCellType()); + + assertEquals(22.3, wb.getSheetAt(1).getRow(0).getCell(0).getNumericCellValue(), 0); + assertEquals("'S1'!A1", wb.getSheetAt(1).getRow(0).getCell(0).getCellFormula()); + assertEquals(CellType.FORMULA, wb.getSheetAt(1).getRow(0).getCell(0).getCellType()); + + + // Now do the alternate call, which zaps the formulas + // uses evaluateInCell() + for (Sheet sheet : wb) { + HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb); + + for (Row r : sheet) { + for (Cell c : r) { + if (c.getCellType() == CellType.FORMULA) { + evaluator.evaluateInCell(c); + } + } + } + } + + assertEquals(55.7, wb.getSheetAt(0).getRow(0).getCell(2).getNumericCellValue(), 0); + assertEquals(CellType.NUMERIC, wb.getSheetAt(0).getRow(0).getCell(2).getCellType()); + + assertEquals(-4.6, wb.getSheetAt(0).getRow(1).getCell(2).getNumericCellValue(), 0); + assertEquals(CellType.NUMERIC, wb.getSheetAt(0).getRow(1).getCell(2).getCellType()); + + assertEquals(22.3, wb.getSheetAt(1).getRow(0).getCell(0).getNumericCellValue(), 0); + assertEquals(CellType.NUMERIC, wb.getSheetAt(1).getRow(0).getCell(0).getCellType()); } - - assertEquals(55.7, wb.getSheetAt(0).getRow(0).getCell(2).getNumericCellValue(), 0); - assertEquals(CellType.NUMERIC, wb.getSheetAt(0).getRow(0).getCell(2).getCellType()); - - assertEquals(-4.6, wb.getSheetAt(0).getRow(1).getCell(2).getNumericCellValue(), 0); - assertEquals(CellType.NUMERIC, wb.getSheetAt(0).getRow(1).getCell(2).getCellType()); - - assertEquals(22.3, wb.getSheetAt(1).getRow(0).getCell(0).getNumericCellValue(), 0); - assertEquals(CellType.NUMERIC, wb.getSheetAt(1).getRow(0).getCell(0).getCellType()); } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java index f6e5afbd81..95cbdb7992 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java @@ -20,13 +20,15 @@ package org.apache.poi.hssf.usermodel; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; import java.io.IOException; +import java.util.ArrayList; import java.util.Calendar; import java.util.Date; +import java.util.List; +import java.util.ListIterator; import org.apache.poi.hssf.HSSFITestDataProvider; import org.apache.poi.hssf.HSSFTestDataSamples; @@ -67,22 +69,22 @@ public final class TestHSSFCell extends BaseTestCell { Date date = cal.getTime(); // first check a file with 1900 Date Windowing - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("1900DateWindowing.xls"); - HSSFSheet sheet = wb.getSheetAt(0); + try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("1900DateWindowing.xls")) { + HSSFSheet sheet = wb.getSheetAt(0); - assertEquals("Date from file using 1900 Date Windowing", - date.getTime(), - sheet.getRow(0).getCell(0).getDateCellValue().getTime()); - wb.close(); + assertEquals("Date from file using 1900 Date Windowing", + date.getTime(), + sheet.getRow(0).getCell(0).getDateCellValue().getTime()); + } // now check a file with 1904 Date Windowing - wb = HSSFTestDataSamples.openSampleWorkbook("1904DateWindowing.xls"); - sheet = wb.getSheetAt(0); + try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("1904DateWindowing.xls")) { + HSSFSheet sheet = wb.getSheetAt(0); - assertEquals("Date from file using 1904 Date Windowing", - date.getTime(), - sheet.getRow(0).getCell(0).getDateCellValue().getTime()); - wb.close(); + assertEquals("Date from file using 1904 Date Windowing", + date.getTime(), + sheet.getRow(0).getCell(0).getDateCellValue().getTime()); + } } @@ -99,26 +101,26 @@ public final class TestHSSFCell extends BaseTestCell { Date date = cal.getTime(); // first check a file with 1900 Date Windowing - HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("1900DateWindowing.xls"); + try (HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("1900DateWindowing.xls")) { - setCell(wb1, 0, 1, date); - HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1); + setCell(wb1, 0, 1, date); + try (HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1)) { - assertEquals("Date from file using 1900 Date Windowing", - date.getTime(), - readCell(wb2, 0, 1).getTime()); - wb1.close(); - wb2.close(); + assertEquals("Date from file using 1900 Date Windowing", + date.getTime(), + readCell(wb2, 0, 1).getTime()); + } + } // now check a file with 1904 Date Windowing - wb1 = HSSFTestDataSamples.openSampleWorkbook("1904DateWindowing.xls"); - setCell(wb1, 0, 1, date); - wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1); - assertEquals("Date from file using 1900 Date Windowing", - date.getTime(), - readCell(wb2, 0, 1).getTime()); - wb1.close(); - wb2.close(); + try (HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("1904DateWindowing.xls")) { + setCell(wb1, 0, 1, date); + try (HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1)) { + assertEquals("Date from file using 1900 Date Windowing", + date.getTime(), + readCell(wb2, 0, 1).getTime()); + } + } } private static void setCell(HSSFWorkbook workbook, int rowIdx, int colIdx, Date date) { @@ -145,93 +147,75 @@ public final class TestHSSFCell extends BaseTestCell { @Test public void testActiveCell() throws IOException { //read in sample - HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("Simple.xls"); + try (HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("Simple.xls")) { - //check initial position - HSSFSheet umSheet = wb1.getSheetAt(0); - InternalSheet s = umSheet.getSheet(); - assertEquals("Initial active cell should be in col 0", - (short) 0, s.getActiveCellCol()); - assertEquals("Initial active cell should be on row 1", - 1, s.getActiveCellRow()); + //check initial position + HSSFSheet umSheet = wb1.getSheetAt(0); + InternalSheet s = umSheet.getSheet(); + assertEquals("Initial active cell should be in col 0", + (short) 0, s.getActiveCellCol()); + assertEquals("Initial active cell should be on row 1", + 1, s.getActiveCellRow()); - //modify position through HSSFCell - HSSFCell cell = umSheet.createRow(3).createCell(2); - cell.setAsActiveCell(); - assertEquals("After modify, active cell should be in col 2", - (short) 2, s.getActiveCellCol()); - assertEquals("After modify, active cell should be on row 3", - 3, s.getActiveCellRow()); + //modify position through HSSFCell + HSSFCell cell = umSheet.createRow(3).createCell(2); + cell.setAsActiveCell(); + assertEquals("After modify, active cell should be in col 2", + (short) 2, s.getActiveCellCol()); + assertEquals("After modify, active cell should be on row 3", + 3, s.getActiveCellRow()); - //write book to temp file; read and verify that position is serialized - HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1); - wb1.close(); + //write book to temp file; read and verify that position is serialized + try (HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1)) { + umSheet = wb2.getSheetAt(0); + s = umSheet.getSheet(); - umSheet = wb2.getSheetAt(0); - s = umSheet.getSheet(); - - assertEquals("After serialize, active cell should be in col 2", - (short) 2, s.getActiveCellCol()); - assertEquals("After serialize, active cell should be on row 3", - 3, s.getActiveCellRow()); - - wb2.close(); + assertEquals("After serialize, active cell should be in col 2", + (short) 2, s.getActiveCellCol()); + assertEquals("After serialize, active cell should be on row 3", + 3, s.getActiveCellRow()); + } + } } @Test public void testActiveCellBug56114() throws IOException { - Workbook wb = new HSSFWorkbook(); - Sheet sh = wb.createSheet(); + try (Workbook wb = new HSSFWorkbook()) { + Sheet sh = wb.createSheet(); - sh.createRow(0); - sh.createRow(1); - sh.createRow(2); - sh.createRow(3); + sh.createRow(0); + sh.createRow(1); + sh.createRow(2); + sh.createRow(3); - Cell cell = sh.getRow(1).createCell(3); - sh.getRow(3).createCell(3); - - assertEquals(0, ((HSSFSheet)wb.getSheetAt(0)).getSheet().getActiveCellRow()); - assertEquals(0, ((HSSFSheet)wb.getSheetAt(0)).getSheet().getActiveCellCol()); + Cell cell = sh.getRow(1).createCell(3); + sh.getRow(3).createCell(3); - cell.setAsActiveCell(); - cell.setCellValue("this should be active"); - - assertEquals(1, ((HSSFSheet)wb.getSheetAt(0)).getSheet().getActiveCellRow()); - assertEquals(3, ((HSSFSheet)wb.getSheetAt(0)).getSheet().getActiveCellCol()); + assertEquals(0, ((HSSFSheet) wb.getSheetAt(0)).getSheet().getActiveCellRow()); + assertEquals(0, ((HSSFSheet) wb.getSheetAt(0)).getSheet().getActiveCellCol()); - /*OutputStream fos = new FileOutputStream("c:/temp/56114.xls"); - try { - wb.write(fos); - } finally { - fos.close(); - }*/ - - Workbook wbBack = _testDataProvider.writeOutAndReadBack(wb); - wb.close(); + cell.setAsActiveCell(); + cell.setCellValue("this should be active"); - assertEquals(1, ((HSSFSheet)wbBack.getSheetAt(0)).getSheet().getActiveCellRow()); - assertEquals(3, ((HSSFSheet)wbBack.getSheetAt(0)).getSheet().getActiveCellCol()); - - wbBack.getSheetAt(0).getRow(3).getCell(3).setAsActiveCell(); - - assertEquals(3, ((HSSFSheet)wbBack.getSheetAt(0)).getSheet().getActiveCellRow()); - assertEquals(3, ((HSSFSheet)wbBack.getSheetAt(0)).getSheet().getActiveCellCol()); + assertEquals(1, ((HSSFSheet) wb.getSheetAt(0)).getSheet().getActiveCellRow()); + assertEquals(3, ((HSSFSheet) wb.getSheetAt(0)).getSheet().getActiveCellCol()); - /*fos = new FileOutputStream("c:/temp/56114a.xls"); - try { - wb.write(fos); - } finally { - fos.close(); - }*/ - - Workbook wbBack2 = _testDataProvider.writeOutAndReadBack(wbBack); - wbBack.close(); - - assertEquals(3, ((HSSFSheet)wbBack2.getSheetAt(0)).getSheet().getActiveCellRow()); - assertEquals(3, ((HSSFSheet)wbBack2.getSheetAt(0)).getSheet().getActiveCellCol()); - wbBack2.close(); + try (Workbook wbBack = _testDataProvider.writeOutAndReadBack(wb)) { + assertEquals(1, ((HSSFSheet) wbBack.getSheetAt(0)).getSheet().getActiveCellRow()); + assertEquals(3, ((HSSFSheet) wbBack.getSheetAt(0)).getSheet().getActiveCellCol()); + + wbBack.getSheetAt(0).getRow(3).getCell(3).setAsActiveCell(); + + assertEquals(3, ((HSSFSheet) wbBack.getSheetAt(0)).getSheet().getActiveCellRow()); + assertEquals(3, ((HSSFSheet) wbBack.getSheetAt(0)).getSheet().getActiveCellCol()); + + try (Workbook wbBack2 = _testDataProvider.writeOutAndReadBack(wbBack)) { + assertEquals(3, ((HSSFSheet) wbBack2.getSheetAt(0)).getSheet().getActiveCellRow()); + assertEquals(3, ((HSSFSheet) wbBack2.getSheetAt(0)).getSheet().getActiveCellCol()); + } + } + } } /** @@ -239,20 +223,18 @@ public final class TestHSSFCell extends BaseTestCell { */ @Test public void testWithHyperlink() throws IOException { + try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("WithHyperlink.xls")) { - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("WithHyperlink.xls"); + HSSFSheet sheet = wb.getSheetAt(0); + HSSFCell cell = sheet.getRow(4).getCell(0); + HSSFHyperlink link = cell.getHyperlink(); + assertNotNull(link); - HSSFSheet sheet = wb.getSheetAt(0); - HSSFCell cell = sheet.getRow(4).getCell(0); - HSSFHyperlink link = cell.getHyperlink(); - assertNotNull(link); - - assertEquals("Foo", link.getLabel()); - assertEquals("http://poi.apache.org/", link.getAddress()); - assertEquals(4, link.getFirstRow()); - assertEquals(0, link.getFirstColumn()); - - wb.close(); + assertEquals("Foo", link.getLabel()); + assertEquals("http://poi.apache.org/", link.getAddress()); + assertEquals(4, link.getFirstRow()); + assertEquals(0, link.getFirstColumn()); + } } /** @@ -260,28 +242,26 @@ public final class TestHSSFCell extends BaseTestCell { */ @Test public void testWithTwoHyperlinks() throws IOException { + try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("WithTwoHyperLinks.xls")) { - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("WithTwoHyperLinks.xls"); + HSSFSheet sheet = wb.getSheetAt(0); - HSSFSheet sheet = wb.getSheetAt(0); + HSSFCell cell1 = sheet.getRow(4).getCell(0); + HSSFHyperlink link1 = cell1.getHyperlink(); + assertNotNull(link1); + assertEquals("Foo", link1.getLabel()); + assertEquals("http://poi.apache.org/", link1.getAddress()); + assertEquals(4, link1.getFirstRow()); + assertEquals(0, link1.getFirstColumn()); - HSSFCell cell1 = sheet.getRow(4).getCell(0); - HSSFHyperlink link1 = cell1.getHyperlink(); - assertNotNull(link1); - assertEquals("Foo", link1.getLabel()); - assertEquals("http://poi.apache.org/", link1.getAddress()); - assertEquals(4, link1.getFirstRow()); - assertEquals(0, link1.getFirstColumn()); - - HSSFCell cell2 = sheet.getRow(8).getCell(1); - HSSFHyperlink link2 = cell2.getHyperlink(); - assertNotNull(link2); - assertEquals("Bar", link2.getLabel()); - assertEquals("http://poi.apache.org/hssf/", link2.getAddress()); - assertEquals(8, link2.getFirstRow()); - assertEquals(1, link2.getFirstColumn()); - - wb.close(); + HSSFCell cell2 = sheet.getRow(8).getCell(1); + HSSFHyperlink link2 = cell2.getHyperlink(); + assertNotNull(link2); + assertEquals("Bar", link2.getLabel()); + assertEquals("http://poi.apache.org/hssf/", link2.getAddress()); + assertEquals(8, link2.getFirstRow()); + assertEquals(1, link2.getFirstColumn()); + } } /** @@ -290,47 +270,45 @@ public final class TestHSSFCell extends BaseTestCell { */ @Test public void testCellStyleWorkbookMatch() throws IOException { - HSSFWorkbook wbA = new HSSFWorkbook(); - HSSFWorkbook wbB = new HSSFWorkbook(); + try (HSSFWorkbook wbA = new HSSFWorkbook(); + HSSFWorkbook wbB = new HSSFWorkbook()) { - HSSFCellStyle styA = wbA.createCellStyle(); - HSSFCellStyle styB = wbB.createCellStyle(); + HSSFCellStyle styA = wbA.createCellStyle(); + HSSFCellStyle styB = wbB.createCellStyle(); - styA.verifyBelongsToWorkbook(wbA); - styB.verifyBelongsToWorkbook(wbB); - try { - styA.verifyBelongsToWorkbook(wbB); - fail("expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected during successful test - } - try { - styB.verifyBelongsToWorkbook(wbA); - fail("expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected during successful test - } + styA.verifyBelongsToWorkbook(wbA); + styB.verifyBelongsToWorkbook(wbB); + try { + styA.verifyBelongsToWorkbook(wbB); + fail("expected IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // expected during successful test + } + try { + styB.verifyBelongsToWorkbook(wbA); + fail("expected IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // expected during successful test + } - Cell cellA = wbA.createSheet().createRow(0).createCell(0); - Cell cellB = wbB.createSheet().createRow(0).createCell(0); + Cell cellA = wbA.createSheet().createRow(0).createCell(0); + Cell cellB = wbB.createSheet().createRow(0).createCell(0); - cellA.setCellStyle(styA); - cellB.setCellStyle(styB); - try { - cellA.setCellStyle(styB); - fail("expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected during successful test + cellA.setCellStyle(styA); + cellB.setCellStyle(styB); + try { + cellA.setCellStyle(styB); + fail("expected IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // expected during successful test + } + try { + cellB.setCellStyle(styA); + fail("expected IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // expected during successful test + } } - try { - cellB.setCellStyle(styA); - fail("expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected during successful test - } - - wbB.close(); - wbA.close(); } /** @@ -341,47 +319,44 @@ public final class TestHSSFCell extends BaseTestCell { */ @Test public void testCachedTypeChange() throws IOException { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet sheet = wb.createSheet("Sheet1"); - Cell cell = sheet.createRow(0).createCell(0); - cell.setCellFormula("A1"); - cell.setCellValue("abc"); - confirmStringRecord(sheet, true); - cell.setCellValue(123); - Record[] recs = RecordInspector.getRecords(sheet, 0); - if (recs.length == 28 && recs[23] instanceof StringRecord) { - wb.close(); - fail("Identified bug - leftover StringRecord"); + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet sheet = wb.createSheet("Sheet1"); + Cell cell = sheet.createRow(0).createCell(0); + cell.setCellFormula("A1"); + cell.setCellValue("abc"); + confirmStringRecord(sheet, true); + cell.setCellValue(123); + + final List recs = new ArrayList<>(); + sheet.getSheet().visitContainedRecords(recs::add, 0); + assertFalse("Identified bug - leftover StringRecord", recs.size() == 28 && recs.get(23) instanceof StringRecord); + confirmStringRecord(sheet, false); + + // string to error code + cell.setCellValue("abc"); + confirmStringRecord(sheet, true); + cell.setCellErrorValue(FormulaError.REF.getCode()); + confirmStringRecord(sheet, false); + + // string to boolean + cell.setCellValue("abc"); + confirmStringRecord(sheet, true); + cell.setCellValue(false); + confirmStringRecord(sheet, false); } - confirmStringRecord(sheet, false); - - // string to error code - cell.setCellValue("abc"); - confirmStringRecord(sheet, true); - cell.setCellErrorValue(FormulaError.REF.getCode()); - confirmStringRecord(sheet, false); - - // string to boolean - cell.setCellValue("abc"); - confirmStringRecord(sheet, true); - cell.setCellValue(false); - confirmStringRecord(sheet, false); - wb.close(); } private static void confirmStringRecord(HSSFSheet sheet, boolean isPresent) { - Record[] recs = RecordInspector.getRecords(sheet, 0); - assertEquals(isPresent ? 28 : 27, recs.length); - int index = 22; - Record fr = recs[index++]; - assertEquals(FormulaRecord.class, fr.getClass()); + List recs = new ArrayList<>(); + sheet.getSheet().visitContainedRecords(recs::add, 0); + assertEquals(isPresent ? 28 : 27, recs.size()); + + ListIterator iter = recs.listIterator(22); + assertEquals(FormulaRecord.class, iter.next().getClass()); if (isPresent) { - assertEquals(StringRecord.class, recs[index++].getClass()); - } else { - assertNotSame(StringRecord.class, recs[index].getClass()); + assertEquals(StringRecord.class, iter.next().getClass()); } - Record dbcr = recs[index]; - assertEquals(DBCellRecord.class, dbcr.getClass()); + assertEquals(DBCellRecord.class, iter.next().getClass()); } /** @@ -389,86 +364,87 @@ public final class TestHSSFCell extends BaseTestCell { */ @Test public void testReadNaN() throws IOException { - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("49761.xls"); - assertNotNull(wb); - wb.close(); + try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("49761.xls")) { + assertNotNull(wb); + } } @Test public void testHSSFCell() throws IOException { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet sheet = wb.createSheet(); - HSSFRow row = sheet.createRow(0); - row.createCell(0); - HSSFCell cell = new HSSFCell(wb, sheet, 0, (short)0); - assertNotNull(cell); - wb.close(); + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet sheet = wb.createSheet(); + HSSFRow row = sheet.createRow(0); + row.createCell(0); + HSSFCell cell = new HSSFCell(wb, sheet, 0, (short) 0); + assertNotNull(cell); + } } @Test public void testDeprecatedMethods() throws IOException { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet sheet = wb.createSheet(); - HSSFRow row = sheet.createRow(0); - HSSFCell cell = row.createCell(0); + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet sheet = wb.createSheet(); + HSSFRow row = sheet.createRow(0); + HSSFCell cell = row.createCell(0); - // cover some deprecated methods and other smaller stuff... - assertEquals(wb.getWorkbook(), cell.getBoundWorkbook()); + // cover some deprecated methods and other smaller stuff... + assertEquals(wb.getWorkbook(), cell.getBoundWorkbook()); - try { - cell.getCachedFormulaResultType(); - fail("Should catch exception"); - } catch (IllegalStateException e) { - // expected here - } - - cell.removeCellComment(); - cell.removeCellComment(); - - wb.close(); + try { + cell.getCachedFormulaResultType(); + fail("Should catch exception"); + } catch (IllegalStateException e) { + // expected here + } + + cell.removeCellComment(); + cell.removeCellComment(); + } } @Test public void testCellType() throws IOException { - Workbook wb = _testDataProvider.createWorkbook(); - Sheet sheet = wb.createSheet(); - Row row = sheet.createRow(0); - Cell cell = row.createCell(0); + try (Workbook wb = _testDataProvider.createWorkbook()) { + Sheet sheet = wb.createSheet(); + Row row = sheet.createRow(0); + Cell cell = row.createCell(0); - cell.setBlank(); - assertNull(null, cell.getDateCellValue()); - assertFalse(cell.getBooleanCellValue()); - assertEquals("", cell.toString()); - - cell.setCellType(CellType.STRING); - assertEquals("", cell.toString()); - cell.setCellValue(1.2); - assertEquals("1.2", cell.toString()); - cell.setCellType(CellType.BOOLEAN); - assertEquals("TRUE", cell.toString()); - cell.setCellType(CellType.BOOLEAN); - cell.setCellValue("" + FormulaError.VALUE.name()); - assertEquals(CellType.STRING, cell.getCellType()); - cell.setCellType(CellType.BOOLEAN); - assertEquals("FALSE", cell.toString()); - cell.setCellValue(1.2); - assertEquals("1.2", cell.toString()); - cell.setCellType(CellType.BOOLEAN); - cell.setCellType(CellType.STRING); - cell.setCellType(CellType.ERROR); - cell.setCellType(CellType.STRING); - cell.setCellValue(1.2); - cell.setCellType(CellType.STRING); - assertEquals("1.2", cell.toString()); - - cell.setCellValue((String)null); - cell.setCellValue((RichTextString)null); - wb.close(); + cell.setBlank(); + assertNull(null, cell.getDateCellValue()); + assertFalse(cell.getBooleanCellValue()); + assertEquals("", cell.toString()); + + cell.setCellType(CellType.STRING); + assertEquals("", cell.toString()); + cell.setCellValue(1.2); + assertEquals("1.2", cell.toString()); + cell.setCellType(CellType.BOOLEAN); + assertEquals("TRUE", cell.toString()); + cell.setCellType(CellType.BOOLEAN); + cell.setCellValue("" + FormulaError.VALUE.name()); + assertEquals(CellType.STRING, cell.getCellType()); + cell.setCellType(CellType.BOOLEAN); + assertEquals("FALSE", cell.toString()); + cell.setCellValue(1.2); + assertEquals("1.2", cell.toString()); + cell.setCellType(CellType.BOOLEAN); + cell.setCellType(CellType.STRING); + cell.setCellType(CellType.ERROR); + cell.setCellType(CellType.STRING); + cell.setCellValue(1.2); + cell.setCellType(CellType.STRING); + assertEquals("1.2", cell.toString()); + + cell.setCellValue((String) null); + cell.setCellValue((RichTextString) null); + } } @Test(expected = IllegalStateException.class) - public void getErrorCellValue_throwsISE_onABlankCell() { - Cell cell = new HSSFWorkbook().createSheet().createRow(0).createCell(0); - cell.getErrorCellValue(); + public void getErrorCellValue_throwsISE_onABlankCell() throws IOException { + try (HSSFWorkbook wb = new HSSFWorkbook()) { + Cell cell = wb.createSheet().createRow(0).createCell(0); + cell.getErrorCellValue(); + } } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java index 96c2d9220d..30c6fce97a 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java @@ -17,46 +17,48 @@ package org.apache.poi.hssf.usermodel; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + import org.apache.poi.ddf.EscherClientAnchorRecord; import org.apache.poi.hssf.model.ConvertAnchor; +import org.junit.Test; /** * Various tests for HSSFClientAnchor. - * - * @author Glen Stampoultzis (glens at apache.org) - * @author Yegor Kozlov (yegor at apache.org) */ -public final class TestHSSFClientAnchor extends TestCase { - public void testGetAnchorHeightInPoints() { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet sheet = wb.createSheet("test"); - HSSFClientAnchor a = new HSSFClientAnchor(0,0,1023,255,(short)0,0,(short)0,0); - float p = a.getAnchorHeightInPoints(sheet); - assertEquals(12.7,p,0.001); +public final class TestHSSFClientAnchor { + @Test + public void testGetAnchorHeightInPoints() throws IOException { + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet sheet = wb.createSheet("test"); + HSSFClientAnchor a = new HSSFClientAnchor(0, 0, 1023, 255, (short) 0, 0, (short) 0, 0); + float p = a.getAnchorHeightInPoints(sheet); + assertEquals(12.7, p, 0.001); - sheet.createRow(0).setHeightInPoints(14); - a = new HSSFClientAnchor(0,0,1023,255,(short)0,0,(short)0,0); - p = a.getAnchorHeightInPoints(sheet); - assertEquals(13.945,p,0.001); + sheet.createRow(0).setHeightInPoints(14); + a = new HSSFClientAnchor(0, 0, 1023, 255, (short) 0, 0, (short) 0, 0); + p = a.getAnchorHeightInPoints(sheet); + assertEquals(13.945, p, 0.001); - a = new HSSFClientAnchor(0,0,1023,127,(short)0,0,(short)0,0); - p = a.getAnchorHeightInPoints(sheet); - assertEquals(6.945,p,0.001); + a = new HSSFClientAnchor(0, 0, 1023, 127, (short) 0, 0, (short) 0, 0); + p = a.getAnchorHeightInPoints(sheet); + assertEquals(6.945, p, 0.001); - a = new HSSFClientAnchor(0,126,1023,127,(short)0,0,(short)0,0); - p = a.getAnchorHeightInPoints(sheet); - assertEquals(0.054,p,0.001); + a = new HSSFClientAnchor(0, 126, 1023, 127, (short) 0, 0, (short) 0, 0); + p = a.getAnchorHeightInPoints(sheet); + assertEquals(0.054, p, 0.001); - a = new HSSFClientAnchor(0,0,1023,0,(short)0,0,(short)0,1); - p = a.getAnchorHeightInPoints(sheet); - assertEquals(14.0,p,0.001); - - sheet.createRow(0).setHeightInPoints(12); - a = new HSSFClientAnchor(0,127,1023,127,(short)0,0,(short)0,1); - p = a.getAnchorHeightInPoints(sheet); - assertEquals(12.372,p,0.001); + a = new HSSFClientAnchor(0, 0, 1023, 0, (short) 0, 0, (short) 0, 1); + p = a.getAnchorHeightInPoints(sheet); + assertEquals(14.0, p, 0.001); + sheet.createRow(0).setHeightInPoints(12); + a = new HSSFClientAnchor(0, 127, 1023, 127, (short) 0, 0, (short) 0, 1); + p = a.getAnchorHeightInPoints(sheet); + assertEquals(12.372, p, 0.001); + } } /** @@ -64,6 +66,7 @@ public final class TestHSSFClientAnchor extends TestCase { * check that dx1, dx2, dy1 and dy2 are written "as is". * (Bug 42999 reported that dx1 and dx2 are swapped if dx1>dx2. It doesn't make sense for client anchors.) */ + @Test public void testConvertAnchor() { HSSFClientAnchor[] anchors = { new HSSFClientAnchor( 0 , 0 , 0 , 0 ,(short)0, 1,(short)1,3), @@ -83,26 +86,29 @@ public final class TestHSSFClientAnchor extends TestCase { } } - public void testAnchorHeightInPoints(){ - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet sheet = wb.createSheet(); + @Test + public void testAnchorHeightInPoints() throws IOException { + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet sheet = wb.createSheet(); - HSSFClientAnchor[] anchor = { - new HSSFClientAnchor( 0 , 0, 0 , 0 ,(short)0, 1,(short)1, 3), - new HSSFClientAnchor( 0 , 254 , 0 , 126 ,(short)0, 1,(short)1, 3), - new HSSFClientAnchor( 0 , 128 , 0 , 128 ,(short)0, 1,(short)1, 3), - new HSSFClientAnchor( 0 , 0 , 0 , 128 ,(short)0, 1,(short)1, 3), - }; - float[] ref = {25.5f, 19.125f, 25.5f, 31.875f}; - for (int i = 0; i < anchor.length; i++) { - float height = anchor[i].getAnchorHeightInPoints(sheet); - assertEquals(ref[i], height, 0); + HSSFClientAnchor[] anchor = { + new HSSFClientAnchor(0, 0, 0, 0, (short) 0, 1, (short) 1, 3), + new HSSFClientAnchor(0, 254, 0, 126, (short) 0, 1, (short) 1, 3), + new HSSFClientAnchor(0, 128, 0, 128, (short) 0, 1, (short) 1, 3), + new HSSFClientAnchor(0, 0, 0, 128, (short) 0, 1, (short) 1, 3), + }; + float[] ref = {25.5f, 19.125f, 25.5f, 31.875f}; + for (int i = 0; i < anchor.length; i++) { + float height = anchor[i].getAnchorHeightInPoints(sheet); + assertEquals(ref[i], height, 0); + } } } /** * Check {@link HSSFClientAnchor} constructor does not treat 32768 as -32768. */ + @Test public void testCanHaveRowGreaterThan32767() { // Maximum permitted row number should be 65535. HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) 0, 32768, (short) 0, 32768); @@ -114,6 +120,7 @@ public final class TestHSSFClientAnchor extends TestCase { /** * Check the maximum is not set at 255*256 instead of 256*256 - 1. */ + @Test public void testCanHaveRowUpTo65535() { HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) 0, 65535, (short) 0, 65535); @@ -121,18 +128,15 @@ public final class TestHSSFClientAnchor extends TestCase { assertEquals(65535, anchor.getRow2()); } + @Test(expected = IllegalArgumentException.class) public void testCannotHaveRowGreaterThan65535() { - try { - new HSSFClientAnchor(0, 0, 0, 0, (short) 0, 65536, (short) 0, 65536); - fail("Expected IllegalArgumentException to be thrown"); - } catch (IllegalArgumentException ex) { - // pass - } + new HSSFClientAnchor(0, 0, 0, 0, (short) 0, 65536, (short) 0, 65536); } /** * Check the same maximum value enforced when using {@link HSSFClientAnchor#setRow1}. */ + @Test public void testCanSetRowUpTo65535() { HSSFClientAnchor anchor = new HSSFClientAnchor(); anchor.setRow1(65535); @@ -142,20 +146,13 @@ public final class TestHSSFClientAnchor extends TestCase { assertEquals(65535, anchor.getRow2()); } + @Test(expected = IllegalArgumentException.class) public void testCannotSetRow1GreaterThan65535() { - try { - new HSSFClientAnchor().setRow1(65536); - fail("Expected IllegalArgumentException to be thrown"); - } catch (IllegalArgumentException ex) { - // pass - } + new HSSFClientAnchor().setRow1(65536); } + + @Test(expected = IllegalArgumentException.class) public void testCannotSetRow2GreaterThan65535() { - try { - new HSSFClientAnchor().setRow2(65536); - fail("Expected IllegalArgumentException to be thrown"); - } catch (IllegalArgumentException ex) { - // pass - } + new HSSFClientAnchor().setRow2(65536); } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHeaderFooter.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHeaderFooter.java index d2e8200132..a8e8b33ae9 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHeaderFooter.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHeaderFooter.java @@ -17,34 +17,36 @@ package org.apache.poi.hssf.usermodel; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import static org.apache.poi.hssf.HSSFTestDataSamples.openSampleWorkbook; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; import org.apache.poi.hssf.HSSFTestDataSamples; +import org.junit.Test; /** * Tests for {@link HSSFHeader} / {@link HSSFFooter} - * - * @author Shawn Laubach (slaubach at apache dot com) */ -public final class TestHSSFHeaderFooter extends TestCase { +public final class TestHSSFHeaderFooter { /** * Tests that get header retrieves the proper values. - * - * @author Shawn Laubach (slaubach at apache dot org) */ - public void testRetrieveCorrectHeader() { + @Test + public void testRetrieveCorrectHeader() throws IOException { - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("EmbeddedChartHeaderTest.xls"); - HSSFSheet s = wb.getSheetAt( 0 ); - HSSFHeader head = s.getHeader(); + try (HSSFWorkbook wb = openSampleWorkbook("EmbeddedChartHeaderTest.xls")) { + HSSFSheet s = wb.getSheetAt(0); + HSSFHeader head = s.getHeader(); - assertEquals("Top Left", head.getLeft()); - assertEquals("Top Center", head.getCenter()); - assertEquals("Top Right", head.getRight()); + assertEquals("Top Left", head.getLeft()); + assertEquals("Top Center", head.getCenter()); + assertEquals("Top Right", head.getRight()); + } } + @Test public void testSpecialChars() { assertEquals("&U", HSSFHeader.startUnderline()); assertEquals("&U", HSSFHeader.endUnderline()); @@ -54,7 +56,8 @@ public final class TestHSSFHeaderFooter extends TestCase { assertEquals("&\"Arial,bold\"", HSSFFooter.font("Arial", "bold")); } - public void testStripFields() { + @Test + public void testStripFields() throws IOException { String simple = "I am a test header"; String withPage = "I am a&P test header"; String withLots = "I&A am&N a&P test&T header&U"; @@ -70,117 +73,123 @@ public final class TestHSSFHeaderFooter extends TestCase { assertEquals(simple + "&a&b", HSSFHeader.stripFields(withOtherAnds2)); // Now test the default strip flag - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("EmbeddedChartHeaderTest.xls"); - HSSFSheet s = wb.getSheetAt( 0 ); - HSSFHeader head = s.getHeader(); + try (HSSFWorkbook wb = openSampleWorkbook("EmbeddedChartHeaderTest.xls")) { + HSSFSheet s = wb.getSheetAt(0); + HSSFHeader head = s.getHeader(); - assertEquals("Top Left", head.getLeft()); - assertEquals("Top Center", head.getCenter()); - assertEquals("Top Right", head.getRight()); + assertEquals("Top Left", head.getLeft()); + assertEquals("Top Center", head.getCenter()); + assertEquals("Top Right", head.getRight()); - head.setLeft("Top &P&F&D Left"); - assertEquals("Top &P&F&D Left", head.getLeft()); + head.setLeft("Top &P&F&D Left"); + assertEquals("Top &P&F&D Left", head.getLeft()); - assertEquals("Top Left", HeaderFooter.stripFields(head.getLeft())); + assertEquals("Top Left", HeaderFooter.stripFields(head.getLeft())); - // Now even more complex - head.setCenter("HEADER TEXT &P&N&D&T&Z&F&F&A&G&X END"); - assertEquals("HEADER TEXT END", HeaderFooter.stripFields(head.getCenter())); + // Now even more complex + head.setCenter("HEADER TEXT &P&N&D&T&Z&F&F&A&G&X END"); + assertEquals("HEADER TEXT END", HeaderFooter.stripFields(head.getCenter())); + } } /** * Tests that get header retrieves the proper values. - * - * @author Shawn Laubach (slaubach at apache dot org) */ - public void testRetrieveCorrectFooter() { + @Test + public void testRetrieveCorrectFooter() throws IOException { + try (HSSFWorkbook wb = openSampleWorkbook("EmbeddedChartHeaderTest.xls")) { + HSSFSheet s = wb.getSheetAt(0); + HSSFFooter foot = s.getFooter(); - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("EmbeddedChartHeaderTest.xls"); - HSSFSheet s = wb.getSheetAt(0); - HSSFFooter foot = s.getFooter(); - - assertEquals("Bottom Left", foot.getLeft()); - assertEquals("Bottom Center", foot.getCenter()); - assertEquals("Bottom Right", foot.getRight()); + assertEquals("Bottom Left", foot.getLeft()); + assertEquals("Bottom Center", foot.getCenter()); + assertEquals("Bottom Right", foot.getRight()); + } } /** * Testcase for Bug 17039 HSSFHeader does not support DBCS */ - public void testHeaderHas16bitCharacter() { - HSSFWorkbook b = new HSSFWorkbook(); - HSSFSheet s = b.createSheet("Test"); - HSSFHeader h = s.getHeader(); - h.setLeft("\u0391"); - h.setCenter("\u0392"); - h.setRight("\u0393"); + @Test + public void testHeaderHas16bitCharacter() throws IOException { + try (HSSFWorkbook b = new HSSFWorkbook()) { + HSSFSheet s = b.createSheet("Test"); + HSSFHeader h = s.getHeader(); + h.setLeft("\u0391"); + h.setCenter("\u0392"); + h.setRight("\u0393"); - HSSFWorkbook b2 = HSSFTestDataSamples.writeOutAndReadBack(b); - HSSFHeader h2 = b2.getSheet("Test").getHeader(); + try (HSSFWorkbook b2 = HSSFTestDataSamples.writeOutAndReadBack(b)) { + HSSFHeader h2 = b2.getSheet("Test").getHeader(); - assertEquals(h2.getLeft(),"\u0391"); - assertEquals(h2.getCenter(),"\u0392"); - assertEquals(h2.getRight(),"\u0393"); + assertEquals(h2.getLeft(), "\u0391"); + assertEquals(h2.getCenter(), "\u0392"); + assertEquals(h2.getRight(), "\u0393"); + } + } } /** * Testcase for Bug 17039 HSSFFooter does not support DBCS */ - public void testFooterHas16bitCharacter() { - HSSFWorkbook b = new HSSFWorkbook(); - HSSFSheet s = b.createSheet("Test"); - HSSFFooter f = s.getFooter(); - f.setLeft("\u0391"); - f.setCenter("\u0392"); - f.setRight("\u0393"); + @Test + public void testFooterHas16bitCharacter() throws IOException { + try (HSSFWorkbook b = new HSSFWorkbook()) { + HSSFSheet s = b.createSheet("Test"); + HSSFFooter f = s.getFooter(); + f.setLeft("\u0391"); + f.setCenter("\u0392"); + f.setRight("\u0393"); - HSSFWorkbook b2 = HSSFTestDataSamples.writeOutAndReadBack(b); - HSSFFooter f2 = b2.getSheet("Test").getFooter(); + try (HSSFWorkbook b2 = HSSFTestDataSamples.writeOutAndReadBack(b)) { + HSSFFooter f2 = b2.getSheet("Test").getFooter(); - assertEquals(f2.getLeft(),"\u0391"); - assertEquals(f2.getCenter(),"\u0392"); - assertEquals(f2.getRight(),"\u0393"); + assertEquals(f2.getLeft(), "\u0391"); + assertEquals(f2.getCenter(), "\u0392"); + assertEquals(f2.getRight(), "\u0393"); + } + } } - public void testReadDBCSHeaderFooter() { - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("DBCSHeader.xls"); - HSSFSheet s = wb.getSheetAt(0); - HSSFHeader h = s.getHeader(); - assertEquals("Header Left " ,h.getLeft(),"\u090f\u0915"); - assertEquals("Header Center " ,h.getCenter(),"\u0939\u094b\u0917\u093e"); - assertEquals("Header Right " ,h.getRight(),"\u091c\u093e"); + @Test + public void testReadDBCSHeaderFooter() throws IOException { + try (HSSFWorkbook wb = openSampleWorkbook("DBCSHeader.xls")) { + HSSFSheet s = wb.getSheetAt(0); + HSSFHeader h = s.getHeader(); + assertEquals("Header Left ", h.getLeft(), "\u090f\u0915"); + assertEquals("Header Center ", h.getCenter(), "\u0939\u094b\u0917\u093e"); + assertEquals("Header Right ", h.getRight(), "\u091c\u093e"); - HSSFFooter f = s.getFooter(); - assertEquals("Footer Left " ,f.getLeft(),"\u091c\u093e"); - assertEquals("Footer Center " ,f.getCenter(),"\u091c\u093e"); - assertEquals("Footer Right " ,f.getRight(),"\u091c\u093e"); + HSSFFooter f = s.getFooter(); + assertEquals("Footer Left ", f.getLeft(), "\u091c\u093e"); + assertEquals("Footer Center ", f.getCenter(), "\u091c\u093e"); + assertEquals("Footer Right ", f.getRight(), "\u091c\u093e"); + } } /** * Excel tolerates files with missing HEADER/FOOTER records. POI should do the same. */ - public void testMissingHeaderFooterRecord_bug47244() { + @Test + public void testMissingHeaderFooterRecord_bug47244() throws IOException { // noHeaderFooter47244.xls was created by a slightly modified POI // which omitted the HEADER/FOOTER records - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("noHeaderFooter47244.xls"); - HSSFSheet sheet = wb.getSheetAt(0); - HSSFFooter footer; - try { - footer = sheet.getFooter(); - } catch (NullPointerException e) { - throw new AssertionFailedError("Identified bug 47244a"); + try (HSSFWorkbook wb = openSampleWorkbook("noHeaderFooter47244.xls")) { + HSSFSheet sheet = wb.getSheetAt(0); + // bug 47244a - NullPointerException + HSSFFooter footer = sheet.getFooter(); + assertEquals("", footer.getRawText()); + HSSFHeader header = sheet.getHeader(); + assertEquals("", header.getRawText()); + + // make sure header / footer is properly linked to underlying data + HSSFHeader header2 = sheet.getHeader(); + header.setCenter("foo"); + assertEquals("foo", header2.getCenter()); + + HSSFFooter footer2 = sheet.getFooter(); + footer.setCenter("bar"); + assertEquals("bar", footer2.getCenter()); } - assertEquals("", footer.getRawText()); - HSSFHeader header = sheet.getHeader(); - assertEquals("", header.getRawText()); - - // make sure header / footer is properly linked to underlying data - HSSFHeader header2 = sheet.getHeader(); - header.setCenter("foo"); - assertEquals("foo", header2.getCenter()); - - HSSFFooter footer2 = sheet.getFooter(); - footer.setCenter("bar"); - assertEquals("bar", footer2.getCenter()); } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPatriarch.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPatriarch.java index e3428cc920..ff65cbe113 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPatriarch.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPatriarch.java @@ -17,53 +17,48 @@ package org.apache.poi.hssf.usermodel; +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; + import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType; +import org.junit.Test; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +public final class TestHSSFPatriarch { -/** - * @author Josh Micich - */ -public final class TestHSSFPatriarch extends TestCase { + @Test + public void testBasic() throws IOException { + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet sheet = wb.createSheet(); - public void testBasic() { - - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet sheet = wb.createSheet(); - - HSSFPatriarch patr = sheet.createDrawingPatriarch(); - assertNotNull(patr); - - // assert something more interesting + HSSFPatriarch patr = sheet.createDrawingPatriarch(); + assertNotNull(patr); + } } - public void test44916() { + @Test + public void test44916() throws IOException { + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet sheet = wb.createSheet(); - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet sheet = wb.createSheet(); + // 1. Create drawing patriarch + HSSFPatriarch patr = sheet.createDrawingPatriarch(); - // 1. Create drawing patriarch - HSSFPatriarch patr = sheet.createDrawingPatriarch(); + // 2. Try to re-get the patriarch + // bug 44916 - NullPointerException + HSSFPatriarch existingPatr = sheet.getDrawingPatriarch(); - // 2. Try to re-get the patriarch - HSSFPatriarch existingPatr; - try { + // 3. Use patriarch + HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 600, 245, (short) 1, 1, (short) 1, 2); + anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE); + byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("logoKarmokar4.png"); + int idx1 = wb.addPicture(pictureData, HSSFWorkbook.PICTURE_TYPE_PNG); + patr.createPicture(anchor, idx1); + + // 4. Try to re-use patriarch later existingPatr = sheet.getDrawingPatriarch(); - } catch (NullPointerException e) { - throw new AssertionFailedError("Identified bug 44916"); + assertNotNull(existingPatr); } - - // 3. Use patriarch - HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 600, 245, (short) 1, 1, (short) 1, 2); - anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE); - byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("logoKarmokar4.png"); - int idx1 = wb.addPicture(pictureData, HSSFWorkbook.PICTURE_TYPE_PNG); - patr.createPicture(anchor, idx1); - - // 4. Try to re-use patriarch later - existingPatr = sheet.getDrawingPatriarch(); - assertNotNull(existingPatr); } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java index 1a330f0b38..986bad978d 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java @@ -17,6 +17,10 @@ package org.apache.poi.hssf.usermodel; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; + import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.File; @@ -26,18 +30,15 @@ import java.util.List; import javax.imageio.IIOException; import javax.imageio.ImageIO; -import junit.framework.TestCase; import org.apache.poi.hssf.HSSFTestDataSamples; import org.junit.BeforeClass; +import org.junit.Test; /** * Test HSSFPictureData. * The code to retrieve images from a workbook provided by Trejkaz (trejkaz at trypticon dot org) in Bug 41223. - * - * @author Yegor Kozlov (yegor at apache dot org) - * @author Trejkaz (trejkaz at trypticon dot org) */ -public final class TestHSSFPictureData extends TestCase{ +public final class TestHSSFPictureData { @BeforeClass public static void setUpClass() { final String tmpDirProperty = System.getProperty("java.io.tmpdir"); @@ -52,6 +53,7 @@ public final class TestHSSFPictureData extends TestCase{ ImageIO.setCacheDirectory(tmpDir); } + @Test public void testPictures() throws IOException { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleWithImages.xls"); @@ -88,6 +90,7 @@ public final class TestHSSFPictureData extends TestCase{ } } + @Test public void testMacPicture() throws IOException { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("53446.xls"); @@ -112,6 +115,7 @@ public final class TestHSSFPictureData extends TestCase{ } } + @Test public void testNotNullPictures() { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SheetWithDrawing.xls"); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java index 8ce707d9aa..442bf7e8c5 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java @@ -17,11 +17,13 @@ package org.apache.poi.hssf.usermodel; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; -public final class TestHSSFRichTextString extends TestCase { +import org.junit.Test; + +public final class TestHSSFRichTextString { + @Test public void testApplyFont() { - HSSFRichTextString r = new HSSFRichTextString("testing"); assertEquals(0,r.numFormattingRuns()); r.applyFont(2,4, new HSSFFont((short)1, null)); @@ -59,11 +61,10 @@ public final class TestHSSFRichTextString extends TestCase { assertEquals(1, r.getFontAtIndex(4)); assertEquals(1, r.getFontAtIndex(5)); assertEquals(1, r.getFontAtIndex(6)); - } + @Test public void testClearFormatting() { - HSSFRichTextString r = new HSSFRichTextString("testing"); assertEquals(0, r.numFormattingRuns()); r.applyFont(2, 4, new HSSFFont( (short) 1, null)); @@ -76,8 +77,8 @@ public final class TestHSSFRichTextString extends TestCase { /** * Test case proposed in Bug 40520: formated twice => will format whole String */ + @Test public void test40520_1() { - short font = 3; HSSFRichTextString r = new HSSFRichTextString("f0_123456789012345678901234567890123456789012345678901234567890"); @@ -93,8 +94,8 @@ public final class TestHSSFRichTextString extends TestCase { /** * Test case proposed in Bug 40520: overlapped range => will format whole String */ + @Test public void test40520_2() { - short font = 3; HSSFRichTextString r = new HSSFRichTextString("f0_123456789012345678901234567890123456789012345678901234567890"); @@ -110,8 +111,8 @@ public final class TestHSSFRichTextString extends TestCase { /** * Test case proposed in Bug 40520: formated twice => will format whole String */ + @Test public void test40520_3() { - short font = 3; HSSFRichTextString r = new HSSFRichTextString("f0_123456789012345678901234567890123456789012345678901234567890"); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java index 6bcbcfa332..78d6756cb4 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java @@ -17,6 +17,8 @@ package org.apache.poi.hssf.usermodel; +import static org.apache.poi.hssf.HSSFTestDataSamples.writeOutAndReadBack; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; @@ -27,6 +29,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import org.apache.poi.ddf.EscherDgRecord; @@ -35,27 +38,8 @@ import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.model.DrawingManager2; import org.apache.poi.hssf.model.InternalSheet; import org.apache.poi.hssf.model.InternalWorkbook; -import org.apache.poi.hssf.record.AutoFilterInfoRecord; -import org.apache.poi.hssf.record.CommonObjectDataSubRecord; -import org.apache.poi.hssf.record.DimensionsRecord; -import org.apache.poi.hssf.record.FtCblsSubRecord; -import org.apache.poi.hssf.record.GridsetRecord; -import org.apache.poi.hssf.record.HCenterRecord; -import org.apache.poi.hssf.record.LbsDataSubRecord; -import org.apache.poi.hssf.record.NameRecord; -import org.apache.poi.hssf.record.ObjRecord; -import org.apache.poi.hssf.record.ObjectProtectRecord; -import org.apache.poi.hssf.record.PasswordRecord; -import org.apache.poi.hssf.record.ProtectRecord; -import org.apache.poi.hssf.record.Record; -import org.apache.poi.hssf.record.SCLRecord; -import org.apache.poi.hssf.record.ScenarioProtectRecord; -import org.apache.poi.hssf.record.SubRecord; -import org.apache.poi.hssf.record.VCenterRecord; -import org.apache.poi.hssf.record.WSBoolRecord; -import org.apache.poi.hssf.record.WindowTwoRecord; +import org.apache.poi.hssf.record.*; import org.apache.poi.hssf.record.aggregates.WorksheetProtectionBlock; -import org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector; import org.apache.poi.ss.formula.ptg.Area3DPtg; import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.usermodel.AutoFilter; @@ -71,10 +55,6 @@ import org.junit.Test; /** * Tests HSSFSheet. This test case is very incomplete at the moment. - * - * - * @author Glen Stampoultzis (glens at apache.org) - * @author Andrew C. Oliver (acoliver apache org) */ public final class TestHSSFSheet extends BaseTestSheet { @@ -88,14 +68,14 @@ public final class TestHSSFSheet extends BaseTestSheet { */ @Test public void setRepeatingRowsAndColumnsBug29747() throws IOException { - HSSFWorkbook wb = new HSSFWorkbook(); - wb.createSheet(); - wb.createSheet(); - HSSFSheet sheet2 = wb.createSheet(); - sheet2.setRepeatingRows(CellRangeAddress.valueOf("1:2")); - NameRecord nameRecord = wb.getWorkbook().getNameRecord(0); - assertEquals(3, nameRecord.getSheetNumber()); - wb.close(); + try (HSSFWorkbook wb = new HSSFWorkbook()) { + wb.createSheet(); + wb.createSheet(); + HSSFSheet sheet2 = wb.createSheet(); + sheet2.setRepeatingRows(CellRangeAddress.valueOf("1:2")); + NameRecord nameRecord = wb.getWorkbook().getNameRecord(0); + assertEquals(3, nameRecord.getSheetNumber()); + } } @Test @@ -108,13 +88,13 @@ public final class TestHSSFSheet extends BaseTestSheet { */ @Test public void backupRecord() throws IOException { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet s = wb.createSheet(); - GridsetRecord gridsetRec = s.getSheet().getGridsetRecord(); - assertTrue(gridsetRec.getGridset()); - s.setGridsPrinted(true); - assertFalse(gridsetRec.getGridset()); - wb.close(); + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet s = wb.createSheet(); + GridsetRecord gridsetRec = s.getSheet().getGridsetRecord(); + assertTrue(gridsetRec.getGridset()); + s.setGridsPrinted(true); + assertFalse(gridsetRec.getGridset()); + } } /** @@ -122,17 +102,16 @@ public final class TestHSSFSheet extends BaseTestSheet { */ @Test public void verticallyCenter() throws IOException { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet s = wb.createSheet(); - VCenterRecord record = s.getSheet().getPageSettings().getVCenter(); + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet s = wb.createSheet(); + VCenterRecord record = s.getSheet().getPageSettings().getVCenter(); - assertFalse(record.getVCenter()); - assertFalse(s.getVerticallyCenter()); - s.setVerticallyCenter(true); - assertTrue(record.getVCenter()); - assertTrue(s.getVerticallyCenter()); - - wb.close(); + assertFalse(record.getVCenter()); + assertFalse(s.getVerticallyCenter()); + s.setVerticallyCenter(true); + assertTrue(record.getVCenter()); + assertTrue(s.getVerticallyCenter()); + } } /** @@ -140,17 +119,16 @@ public final class TestHSSFSheet extends BaseTestSheet { */ @Test public void horizontallyCenter() throws IOException { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet s = wb.createSheet(); - HCenterRecord record = s.getSheet().getPageSettings().getHCenter(); + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet s = wb.createSheet(); + HCenterRecord record = s.getSheet().getPageSettings().getHCenter(); - assertFalse(record.getHCenter()); - assertFalse(s.getHorizontallyCenter()); - s.setHorizontallyCenter(true); - assertTrue(record.getHCenter()); - assertTrue(s.getHorizontallyCenter()); - - wb.close(); + assertFalse(record.getHCenter()); + assertFalse(s.getHorizontallyCenter()); + s.setHorizontallyCenter(true); + assertTrue(record.getHCenter()); + assertTrue(s.getHorizontallyCenter()); + } } @@ -159,51 +137,49 @@ public final class TestHSSFSheet extends BaseTestSheet { */ @Test public void wsBool() throws IOException { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet s = wb.createSheet(); - WSBoolRecord record = - (WSBoolRecord) s.getSheet().findFirstRecordBySid(WSBoolRecord.sid); + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet s = wb.createSheet(); + WSBoolRecord record = (WSBoolRecord) s.getSheet().findFirstRecordBySid(WSBoolRecord.sid); - // Check defaults - assertNotNull(record); - assertTrue(record.getAlternateExpression()); - assertTrue(record.getAlternateFormula()); - assertFalse(record.getAutobreaks()); - assertFalse(record.getDialog()); - assertFalse(record.getDisplayGuts()); - assertTrue(record.getFitToPage()); - assertFalse(record.getRowSumsBelow()); - assertFalse(record.getRowSumsRight()); + // Check defaults + assertNotNull(record); + assertTrue(record.getAlternateExpression()); + assertTrue(record.getAlternateFormula()); + assertFalse(record.getAutobreaks()); + assertFalse(record.getDialog()); + assertFalse(record.getDisplayGuts()); + assertTrue(record.getFitToPage()); + assertFalse(record.getRowSumsBelow()); + assertFalse(record.getRowSumsRight()); - // Alter - s.setAlternativeExpression(false); - s.setAlternativeFormula(false); - s.setAutobreaks(true); - s.setDialog(true); - s.setDisplayGuts(true); - s.setFitToPage(false); - s.setRowSumsBelow(true); - s.setRowSumsRight(true); + // Alter + s.setAlternativeExpression(false); + s.setAlternativeFormula(false); + s.setAutobreaks(true); + s.setDialog(true); + s.setDisplayGuts(true); + s.setFitToPage(false); + s.setRowSumsBelow(true); + s.setRowSumsRight(true); - // Check - assertTrue(record.getAlternateExpression()); //sheet.setRowSumsBelow alters this field too - assertFalse(record.getAlternateFormula()); - assertTrue(record.getAutobreaks()); - assertTrue(record.getDialog()); - assertTrue(record.getDisplayGuts()); - assertFalse(record.getFitToPage()); - assertTrue(record.getRowSumsBelow()); - assertTrue(record.getRowSumsRight()); - assertTrue(s.getAlternateExpression()); - assertFalse(s.getAlternateFormula()); - assertTrue(s.getAutobreaks()); - assertTrue(s.getDialog()); - assertTrue(s.getDisplayGuts()); - assertFalse(s.getFitToPage()); - assertTrue(s.getRowSumsBelow()); - assertTrue(s.getRowSumsRight()); - - wb.close(); + // Check + assertTrue(record.getAlternateExpression()); //sheet.setRowSumsBelow alters this field too + assertFalse(record.getAlternateFormula()); + assertTrue(record.getAutobreaks()); + assertTrue(record.getDialog()); + assertTrue(record.getDisplayGuts()); + assertFalse(record.getFitToPage()); + assertTrue(record.getRowSumsBelow()); + assertTrue(record.getRowSumsRight()); + assertTrue(s.getAlternateExpression()); + assertFalse(s.getAlternateFormula()); + assertTrue(s.getAutobreaks()); + assertTrue(s.getDialog()); + assertTrue(s.getDisplayGuts()); + assertFalse(s.getFitToPage()); + assertTrue(s.getRowSumsBelow()); + assertTrue(s.getRowSumsRight()); + } } /** @@ -211,184 +187,174 @@ public final class TestHSSFSheet extends BaseTestSheet { */ @Test public void printSetupLandscapeExisting() throws IOException { - HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPageBreaks.xls"); + try (HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPageBreaks.xls")) { - assertEquals(3, wb1.getNumberOfSheets()); + assertEquals(3, wb1.getNumberOfSheets()); - HSSFSheet sheetL = wb1.getSheetAt(0); - HSSFSheet sheetPM = wb1.getSheetAt(1); - HSSFSheet sheetLS = wb1.getSheetAt(2); + HSSFSheet sheetL = wb1.getSheetAt(0); + HSSFSheet sheetPM = wb1.getSheetAt(1); + HSSFSheet sheetLS = wb1.getSheetAt(2); - // Check two aspects of the print setup - assertFalse(sheetL.getPrintSetup().getLandscape()); - assertTrue(sheetPM.getPrintSetup().getLandscape()); - assertTrue(sheetLS.getPrintSetup().getLandscape()); - assertEquals(1, sheetL.getPrintSetup().getCopies()); - assertEquals(1, sheetPM.getPrintSetup().getCopies()); - assertEquals(1, sheetLS.getPrintSetup().getCopies()); + // Check two aspects of the print setup + assertFalse(sheetL.getPrintSetup().getLandscape()); + assertTrue(sheetPM.getPrintSetup().getLandscape()); + assertTrue(sheetLS.getPrintSetup().getLandscape()); + assertEquals(1, sheetL.getPrintSetup().getCopies()); + assertEquals(1, sheetPM.getPrintSetup().getCopies()); + assertEquals(1, sheetLS.getPrintSetup().getCopies()); - // Change one on each - sheetL.getPrintSetup().setLandscape(true); - sheetPM.getPrintSetup().setLandscape(false); - sheetPM.getPrintSetup().setCopies((short)3); + // Change one on each + sheetL.getPrintSetup().setLandscape(true); + sheetPM.getPrintSetup().setLandscape(false); + sheetPM.getPrintSetup().setCopies((short) 3); - // Check taken - assertTrue(sheetL.getPrintSetup().getLandscape()); - assertFalse(sheetPM.getPrintSetup().getLandscape()); - assertTrue(sheetLS.getPrintSetup().getLandscape()); - assertEquals(1, sheetL.getPrintSetup().getCopies()); - assertEquals(3, sheetPM.getPrintSetup().getCopies()); - assertEquals(1, sheetLS.getPrintSetup().getCopies()); + // Check taken + assertTrue(sheetL.getPrintSetup().getLandscape()); + assertFalse(sheetPM.getPrintSetup().getLandscape()); + assertTrue(sheetLS.getPrintSetup().getLandscape()); + assertEquals(1, sheetL.getPrintSetup().getCopies()); + assertEquals(3, sheetPM.getPrintSetup().getCopies()); + assertEquals(1, sheetLS.getPrintSetup().getCopies()); - // Save and re-load, and check still there - Workbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1); - wb1.close(); + // Save and re-load, and check still there + try (HSSFWorkbook wb2 = writeOutAndReadBack(wb1)) { + sheetL = wb2.getSheetAt(0); + sheetPM = wb2.getSheetAt(1); + sheetLS = wb2.getSheetAt(2); - sheetL = wb1.getSheetAt(0); - sheetPM = wb1.getSheetAt(1); - sheetLS = wb1.getSheetAt(2); - - assertTrue(sheetL.getPrintSetup().getLandscape()); - assertFalse(sheetPM.getPrintSetup().getLandscape()); - assertTrue(sheetLS.getPrintSetup().getLandscape()); - assertEquals(1, sheetL.getPrintSetup().getCopies()); - assertEquals(3, sheetPM.getPrintSetup().getCopies()); - assertEquals(1, sheetLS.getPrintSetup().getCopies()); - - wb2.close(); + assertTrue(sheetL.getPrintSetup().getLandscape()); + assertFalse(sheetPM.getPrintSetup().getLandscape()); + assertTrue(sheetLS.getPrintSetup().getLandscape()); + assertEquals(1, sheetL.getPrintSetup().getCopies()); + assertEquals(3, sheetPM.getPrintSetup().getCopies()); + assertEquals(1, sheetLS.getPrintSetup().getCopies()); + } + } } @Test public void groupRows() throws IOException { - HSSFWorkbook wb1 = new HSSFWorkbook(); - HSSFSheet s = wb1.createSheet(); - HSSFRow r1 = s.createRow(0); - HSSFRow r2 = s.createRow(1); - HSSFRow r3 = s.createRow(2); - HSSFRow r4 = s.createRow(3); - HSSFRow r5 = s.createRow(4); + try (HSSFWorkbook wb1 = new HSSFWorkbook()) { + HSSFSheet s = wb1.createSheet(); + HSSFRow r1 = s.createRow(0); + HSSFRow r2 = s.createRow(1); + HSSFRow r3 = s.createRow(2); + HSSFRow r4 = s.createRow(3); + HSSFRow r5 = s.createRow(4); - assertEquals(0, r1.getOutlineLevel()); - assertEquals(0, r2.getOutlineLevel()); - assertEquals(0, r3.getOutlineLevel()); - assertEquals(0, r4.getOutlineLevel()); - assertEquals(0, r5.getOutlineLevel()); + assertEquals(0, r1.getOutlineLevel()); + assertEquals(0, r2.getOutlineLevel()); + assertEquals(0, r3.getOutlineLevel()); + assertEquals(0, r4.getOutlineLevel()); + assertEquals(0, r5.getOutlineLevel()); - s.groupRow(2,3); + s.groupRow(2, 3); - assertEquals(0, r1.getOutlineLevel()); - assertEquals(0, r2.getOutlineLevel()); - assertEquals(1, r3.getOutlineLevel()); - assertEquals(1, r4.getOutlineLevel()); - assertEquals(0, r5.getOutlineLevel()); + assertEquals(0, r1.getOutlineLevel()); + assertEquals(0, r2.getOutlineLevel()); + assertEquals(1, r3.getOutlineLevel()); + assertEquals(1, r4.getOutlineLevel()); + assertEquals(0, r5.getOutlineLevel()); - // Save and re-open - HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1); - wb1.close(); + // Save and re-open + try (HSSFWorkbook wb2 = writeOutAndReadBack(wb1)) { + s = wb2.getSheetAt(0); + r1 = s.getRow(0); + r2 = s.getRow(1); + r3 = s.getRow(2); + r4 = s.getRow(3); + r5 = s.getRow(4); - s = wb2.getSheetAt(0); - r1 = s.getRow(0); - r2 = s.getRow(1); - r3 = s.getRow(2); - r4 = s.getRow(3); - r5 = s.getRow(4); - - assertEquals(0, r1.getOutlineLevel()); - assertEquals(0, r2.getOutlineLevel()); - assertEquals(1, r3.getOutlineLevel()); - assertEquals(1, r4.getOutlineLevel()); - assertEquals(0, r5.getOutlineLevel()); - wb2.close(); + assertEquals(0, r1.getOutlineLevel()); + assertEquals(0, r2.getOutlineLevel()); + assertEquals(1, r3.getOutlineLevel()); + assertEquals(1, r4.getOutlineLevel()); + assertEquals(0, r5.getOutlineLevel()); + } + } } @Test public void groupRowsExisting() throws IOException { - HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("NoGutsRecords.xls"); + try (HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("NoGutsRecords.xls")) { - HSSFSheet s = wb1.getSheetAt(0); - HSSFRow r1 = s.getRow(0); - HSSFRow r2 = s.getRow(1); - HSSFRow r3 = s.getRow(2); - HSSFRow r4 = s.getRow(3); - HSSFRow r5 = s.getRow(4); - HSSFRow r6 = s.getRow(5); + HSSFSheet s = wb1.getSheetAt(0); + HSSFRow r1 = s.getRow(0); + HSSFRow r2 = s.getRow(1); + HSSFRow r3 = s.getRow(2); + HSSFRow r4 = s.getRow(3); + HSSFRow r5 = s.getRow(4); + HSSFRow r6 = s.getRow(5); - assertEquals(0, r1.getOutlineLevel()); - assertEquals(0, r2.getOutlineLevel()); - assertEquals(0, r3.getOutlineLevel()); - assertEquals(0, r4.getOutlineLevel()); - assertEquals(0, r5.getOutlineLevel()); - assertEquals(0, r6.getOutlineLevel()); + assertEquals(0, r1.getOutlineLevel()); + assertEquals(0, r2.getOutlineLevel()); + assertEquals(0, r3.getOutlineLevel()); + assertEquals(0, r4.getOutlineLevel()); + assertEquals(0, r5.getOutlineLevel()); + assertEquals(0, r6.getOutlineLevel()); - // This used to complain about lacking guts records - s.groupRow(2, 4); + // This used to complain about lacking guts records + s.groupRow(2, 4); - assertEquals(0, r1.getOutlineLevel()); - assertEquals(0, r2.getOutlineLevel()); - assertEquals(1, r3.getOutlineLevel()); - assertEquals(1, r4.getOutlineLevel()); - assertEquals(1, r5.getOutlineLevel()); - assertEquals(0, r6.getOutlineLevel()); + assertEquals(0, r1.getOutlineLevel()); + assertEquals(0, r2.getOutlineLevel()); + assertEquals(1, r3.getOutlineLevel()); + assertEquals(1, r4.getOutlineLevel()); + assertEquals(1, r5.getOutlineLevel()); + assertEquals(0, r6.getOutlineLevel()); - // Save and re-open - HSSFWorkbook wb2 = null; - try { - wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1); - } catch (OutOfMemoryError e) { - fail("Identified bug 39903"); + // Save and re-open + try (HSSFWorkbook wb2 = writeOutAndReadBack(wb1)) { + // OutOfMemoryError -> Identified bug 39903 + s = wb2.getSheetAt(0); + r1 = s.getRow(0); + r2 = s.getRow(1); + r3 = s.getRow(2); + r4 = s.getRow(3); + r5 = s.getRow(4); + r6 = s.getRow(5); + + assertEquals(0, r1.getOutlineLevel()); + assertEquals(0, r2.getOutlineLevel()); + assertEquals(1, r3.getOutlineLevel()); + assertEquals(1, r4.getOutlineLevel()); + assertEquals(1, r5.getOutlineLevel()); + assertEquals(0, r6.getOutlineLevel()); + } } - - s = wb2.getSheetAt(0); - r1 = s.getRow(0); - r2 = s.getRow(1); - r3 = s.getRow(2); - r4 = s.getRow(3); - r5 = s.getRow(4); - r6 = s.getRow(5); - - assertEquals(0, r1.getOutlineLevel()); - assertEquals(0, r2.getOutlineLevel()); - assertEquals(1, r3.getOutlineLevel()); - assertEquals(1, r4.getOutlineLevel()); - assertEquals(1, r5.getOutlineLevel()); - assertEquals(0, r6.getOutlineLevel()); - - wb2.close(); - wb1.close(); } @Test public void createDrawings() throws IOException { - HSSFWorkbook workbook = new HSSFWorkbook(); - HSSFSheet sheet = workbook.createSheet(); - HSSFPatriarch p1 = sheet.createDrawingPatriarch(); - HSSFPatriarch p2 = sheet.createDrawingPatriarch(); - assertSame(p1, p2); - workbook.close(); + try (HSSFWorkbook workbook = new HSSFWorkbook()) { + HSSFSheet sheet = workbook.createSheet(); + HSSFPatriarch p1 = sheet.createDrawingPatriarch(); + HSSFPatriarch p2 = sheet.createDrawingPatriarch(); + assertSame(p1, p2); + } } @Test public void getDrawings() throws IOException { - HSSFWorkbook wb1c = HSSFTestDataSamples.openSampleWorkbook("WithChart.xls"); - HSSFWorkbook wb2c = HSSFTestDataSamples.openSampleWorkbook("WithTwoCharts.xls"); + try (HSSFWorkbook wb1c = HSSFTestDataSamples.openSampleWorkbook("WithChart.xls"); + HSSFWorkbook wb2c = HSSFTestDataSamples.openSampleWorkbook("WithTwoCharts.xls")) { - // 1 chart sheet -> data on 1st, chart on 2nd - assertNotNull(wb1c.getSheetAt(0).getDrawingPatriarch()); - assertSame(wb1c.getSheetAt(0).getDrawingPatriarch(), wb1c.getSheetAt(0).getDrawingPatriarch()); - assertNotNull(wb1c.getSheetAt(1).getDrawingPatriarch()); - assertSame(wb1c.getSheetAt(1).getDrawingPatriarch(), wb1c.getSheetAt(1).getDrawingPatriarch()); - assertFalse(wb1c.getSheetAt(0).getDrawingPatriarch().containsChart()); - assertTrue(wb1c.getSheetAt(1).getDrawingPatriarch().containsChart()); + // 1 chart sheet -> data on 1st, chart on 2nd + assertNotNull(wb1c.getSheetAt(0).getDrawingPatriarch()); + assertSame(wb1c.getSheetAt(0).getDrawingPatriarch(), wb1c.getSheetAt(0).getDrawingPatriarch()); + assertNotNull(wb1c.getSheetAt(1).getDrawingPatriarch()); + assertSame(wb1c.getSheetAt(1).getDrawingPatriarch(), wb1c.getSheetAt(1).getDrawingPatriarch()); + assertFalse(wb1c.getSheetAt(0).getDrawingPatriarch().containsChart()); + assertTrue(wb1c.getSheetAt(1).getDrawingPatriarch().containsChart()); - // 2 chart sheet -> data on 1st, chart on 2nd+3rd - assertNotNull(wb2c.getSheetAt(0).getDrawingPatriarch()); - assertNotNull(wb2c.getSheetAt(1).getDrawingPatriarch()); - assertNotNull(wb2c.getSheetAt(2).getDrawingPatriarch()); - assertFalse(wb2c.getSheetAt(0).getDrawingPatriarch().containsChart()); - assertTrue(wb2c.getSheetAt(1).getDrawingPatriarch().containsChart()); - assertTrue(wb2c.getSheetAt(2).getDrawingPatriarch().containsChart()); - wb2c.close(); - wb1c.close(); + // 2 chart sheet -> data on 1st, chart on 2nd+3rd + assertNotNull(wb2c.getSheetAt(0).getDrawingPatriarch()); + assertNotNull(wb2c.getSheetAt(1).getDrawingPatriarch()); + assertNotNull(wb2c.getSheetAt(2).getDrawingPatriarch()); + assertFalse(wb2c.getSheetAt(0).getDrawingPatriarch().containsChart()); + assertTrue(wb2c.getSheetAt(1).getDrawingPatriarch().containsChart()); + assertTrue(wb2c.getSheetAt(2).getDrawingPatriarch().containsChart()); + } } /** @@ -400,42 +366,43 @@ public final class TestHSSFSheet extends BaseTestSheet { int expectedHashA = -6810; String passwordB = "admin"; int expectedHashB = -14556; - HSSFWorkbook workbook = new HSSFWorkbook(); - HSSFSheet hssfSheet = workbook.createSheet(); - assertFalse(hssfSheet.getObjectProtect()); - hssfSheet.protectSheet(passwordA); - assertTrue(hssfSheet.getObjectProtect()); - assertEquals(expectedHashA, hssfSheet.getPassword()); - assertEquals(expectedHashA, hssfSheet.getSheet().getProtectionBlock().getPasswordHash()); + try (HSSFWorkbook workbook = new HSSFWorkbook()) { + HSSFSheet hssfSheet = workbook.createSheet(); + assertFalse(hssfSheet.getObjectProtect()); + hssfSheet.protectSheet(passwordA); + assertTrue(hssfSheet.getObjectProtect()); + assertEquals(expectedHashA, hssfSheet.getPassword()); - // Clone the sheet, and make sure the password hash is preserved - HSSFSheet sheet2 = workbook.cloneSheet(0); - assertTrue(hssfSheet.getObjectProtect()); - assertEquals(expectedHashA, sheet2.getSheet().getProtectionBlock().getPasswordHash()); + assertEquals(expectedHashA, hssfSheet.getSheet().getProtectionBlock().getPasswordHash()); - // change the password on the first sheet - hssfSheet.protectSheet(passwordB); - assertTrue(hssfSheet.getObjectProtect()); - assertEquals(expectedHashB, hssfSheet.getSheet().getProtectionBlock().getPasswordHash()); - assertEquals(expectedHashB, hssfSheet.getPassword()); - // but the cloned sheet's password should remain unchanged - assertEquals(expectedHashA, sheet2.getSheet().getProtectionBlock().getPasswordHash()); - workbook.close(); + // Clone the sheet, and make sure the password hash is preserved + HSSFSheet sheet2 = workbook.cloneSheet(0); + assertTrue(hssfSheet.getObjectProtect()); + assertEquals(expectedHashA, sheet2.getSheet().getProtectionBlock().getPasswordHash()); + + // change the password on the first sheet + hssfSheet.protectSheet(passwordB); + assertTrue(hssfSheet.getObjectProtect()); + assertEquals(expectedHashB, hssfSheet.getSheet().getProtectionBlock().getPasswordHash()); + assertEquals(expectedHashB, hssfSheet.getPassword()); + // but the cloned sheet's password should remain unchanged + assertEquals(expectedHashA, sheet2.getSheet().getProtectionBlock().getPasswordHash()); + } } @Test public void protectSheetA() throws IOException { int expectedHash = (short)0xfef1; - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet s = wb.createSheet(); - s.protectSheet("abcdefghij"); - WorksheetProtectionBlock pb = s.getSheet().getProtectionBlock(); - assertTrue("protection should be on", pb.isSheetProtected()); - assertTrue("object protection should be on",pb.isObjectProtected()); - assertTrue("scenario protection should be on",pb.isScenarioProtected()); - assertEquals("well known value for top secret hash should be "+Integer.toHexString(expectedHash).substring(4), expectedHash, pb.getPasswordHash()); - wb.close(); + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet s = wb.createSheet(); + s.protectSheet("abcdefghij"); + WorksheetProtectionBlock pb = s.getSheet().getProtectionBlock(); + assertTrue("protection should be on", pb.isSheetProtected()); + assertTrue("object protection should be on", pb.isObjectProtected()); + assertTrue("scenario protection should be on", pb.isScenarioProtected()); + assertEquals("well known value for top secret hash should be " + Integer.toHexString(expectedHash).substring(4), expectedHash, pb.getPasswordHash()); + } } /** @@ -444,32 +411,21 @@ public final class TestHSSFSheet extends BaseTestSheet { */ @Test public void protectSheetRecordOrder_bug47363a() throws IOException { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet s = wb.createSheet(); - s.protectSheet("secret"); - RecordCollector rc = new RecordCollector(); - s.getSheet().visitContainedRecords(rc, 0); - Record[] recs = rc.getRecords(); - int nRecs = recs.length; - if (recs[nRecs-2] instanceof PasswordRecord && recs[nRecs-5] instanceof DimensionsRecord) { - fail("Identified bug 47363a - PASSWORD after DIMENSION"); - } - // Check that protection block is together, and before DIMENSION - confirmRecordClass(recs, nRecs-4, DimensionsRecord.class); - confirmRecordClass(recs, nRecs-9, ProtectRecord.class); - confirmRecordClass(recs, nRecs-8, ObjectProtectRecord.class); - confirmRecordClass(recs, nRecs-7, ScenarioProtectRecord.class); - confirmRecordClass(recs, nRecs-6, PasswordRecord.class); - - wb.close(); - } + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet s = wb.createSheet(); + s.protectSheet("secret"); + List recs = new ArrayList<>(); + s.getSheet().visitContainedRecords(recs::add, 0); + int nRecs = recs.size(); - private static void confirmRecordClass(Record[] recs, int index, Class cls) { - if (recs.length <= index) { - fail("Expected (" + cls.getName() + ") at index " - + index + " but array length is " + recs.length + "."); + // Check that protection block is together, and before DIMENSION + // PASSWORD must be before DIMENSION + Class[] exp = {ProtectRecord.class, ObjectProtectRecord.class, ScenarioProtectRecord.class, + PasswordRecord.class, DefaultColWidthRecord.class, DimensionsRecord.class, WindowTwoRecord.class, + SelectionRecord.class, EOFRecord.class }; + Class[] act = recs.subList(nRecs - 9, nRecs).stream().map(Object::getClass).toArray(Class[]::new); + assertArrayEquals(exp, act); } - assertEquals(cls, recs[index].getClass()); } /** @@ -477,82 +433,71 @@ public final class TestHSSFSheet extends BaseTestSheet { */ @Test public void dvProtectionOrder_bug47363b() throws IOException { - HSSFWorkbook workbook = new HSSFWorkbook(); - HSSFSheet sheet = workbook.createSheet("Sheet1"); - sheet.protectSheet("secret"); + try (HSSFWorkbook workbook = new HSSFWorkbook()) { + HSSFSheet sheet = workbook.createSheet("Sheet1"); + sheet.protectSheet("secret"); - DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper(); - DataValidationConstraint dvc = dataValidationHelper.createIntegerConstraint(DataValidationConstraint.OperatorType.BETWEEN, "10", "100"); - CellRangeAddressList numericCellAddressList = new CellRangeAddressList(0, 0, 1, 1); - DataValidation dv = dataValidationHelper.createValidation(dvc,numericCellAddressList); - try { + DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper(); + DataValidationConstraint dvc = dataValidationHelper.createIntegerConstraint(DataValidationConstraint.OperatorType.BETWEEN, "10", "100"); + CellRangeAddressList numericCellAddressList = new CellRangeAddressList(0, 0, 1, 1); + DataValidation dv = dataValidationHelper.createValidation(dvc, numericCellAddressList); + + // bug 47363b: Unexpected (org.apache.poi.hssf.record.PasswordRecord) while looking for DV Table insert pos sheet.addValidationData(dv); - } catch (IllegalStateException e) { - String expMsg = "Unexpected (org.apache.poi.hssf.record.PasswordRecord) while looking for DV Table insert pos"; - if (expMsg.equals(e.getMessage())) { - fail("Identified bug 47363b"); - } - workbook.close(); - throw e; + + int[] nRecsWithProtection = { 0 }; + sheet.getSheet().visitContainedRecords(r -> nRecsWithProtection[0]++, 0); + + sheet.protectSheet(null); + int[] nRecsWithoutProtection = { 0 }; + sheet.getSheet().visitContainedRecords(r -> nRecsWithoutProtection[0]++, 0); + + assertEquals(4, nRecsWithProtection[0] - nRecsWithoutProtection[0]); } - RecordCollector rc; - rc = new RecordCollector(); - sheet.getSheet().visitContainedRecords(rc, 0); - int nRecsWithProtection = rc.getRecords().length; - - sheet.protectSheet(null); - rc = new RecordCollector(); - sheet.getSheet().visitContainedRecords(rc, 0); - int nRecsWithoutProtection = rc.getRecords().length; - - assertEquals(4, nRecsWithProtection - nRecsWithoutProtection); - - workbook.close(); } @Test public void zoom() throws IOException { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet sheet = wb.createSheet(); - assertEquals(-1, sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid)); - sheet.setZoom(75); - assertTrue(sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid) > 0); - SCLRecord sclRecord = (SCLRecord) sheet.getSheet().findFirstRecordBySid(SCLRecord.sid); - assertNotNull(sclRecord); - short numerator = sclRecord.getNumerator(); - assertEquals(75, 100* numerator /sclRecord.getDenominator()); + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet sheet = wb.createSheet(); + assertEquals(-1, sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid)); + sheet.setZoom(75); + assertTrue(sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid) > 0); + SCLRecord sclRecord = (SCLRecord) sheet.getSheet().findFirstRecordBySid(SCLRecord.sid); + assertNotNull(sclRecord); + short numerator = sclRecord.getNumerator(); + assertEquals(75, 100 * numerator / sclRecord.getDenominator()); - int sclLoc = sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid); - int window2Loc = sheet.getSheet().findFirstRecordLocBySid(WindowTwoRecord.sid); - assertEquals(sclLoc, window2Loc + 1); - - // verify limits - try { - sheet.setZoom(0); - fail("Should catch Exception here"); - } catch (IllegalArgumentException e) { - assertEquals("Numerator must be greater than 0 and less than 65536", e.getMessage()); + int sclLoc = sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid); + int window2Loc = sheet.getSheet().findFirstRecordLocBySid(WindowTwoRecord.sid); + assertEquals(sclLoc, window2Loc + 1); + + // verify limits + try { + sheet.setZoom(0); + fail("Should catch Exception here"); + } catch (IllegalArgumentException e) { + assertEquals("Numerator must be greater than 0 and less than 65536", e.getMessage()); + } + try { + sheet.setZoom(65536); + fail("Should catch Exception here"); + } catch (IllegalArgumentException e) { + assertEquals("Numerator must be greater than 0 and less than 65536", e.getMessage()); + } + try { + sheet.setZoom(2, 0); + fail("Should catch Exception here"); + } catch (IllegalArgumentException e) { + assertEquals("Denominator must be greater than 0 and less than 65536", e.getMessage()); + } + try { + sheet.setZoom(2, 65536); + fail("Should catch Exception here"); + } catch (IllegalArgumentException e) { + assertEquals("Denominator must be greater than 0 and less than 65536", e.getMessage()); + } } - try { - sheet.setZoom(65536); - fail("Should catch Exception here"); - } catch (IllegalArgumentException e) { - assertEquals("Numerator must be greater than 0 and less than 65536", e.getMessage()); - } - try { - sheet.setZoom(2, 0); - fail("Should catch Exception here"); - } catch (IllegalArgumentException e) { - assertEquals("Denominator must be greater than 0 and less than 65536", e.getMessage()); - } - try { - sheet.setZoom(2, 65536); - fail("Should catch Exception here"); - } catch (IllegalArgumentException e) { - assertEquals("Denominator must be greater than 0 and less than 65536", e.getMessage()); - } - - wb.close(); } @@ -562,43 +507,42 @@ public final class TestHSSFSheet extends BaseTestSheet { */ @Test public void pageBreakFiles() throws IOException { - HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPageBreaks.xls"); + try (HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPageBreaks.xls")) { - HSSFSheet sheet = wb1.getSheetAt(0); - assertNotNull(sheet); + HSSFSheet sheet = wb1.getSheetAt(0); + assertNotNull(sheet); - assertEquals("1 row page break", 1, sheet.getRowBreaks().length); - assertEquals("1 column page break", 1, sheet.getColumnBreaks().length); + assertEquals("1 row page break", 1, sheet.getRowBreaks().length); + assertEquals("1 column page break", 1, sheet.getColumnBreaks().length); - assertTrue("No row page break", sheet.isRowBroken(22)); - assertTrue("No column page break", sheet.isColumnBroken((short)4)); + assertTrue("No row page break", sheet.isRowBroken(22)); + assertTrue("No column page break", sheet.isColumnBroken((short) 4)); - sheet.setRowBreak(10); - sheet.setColumnBreak((short)13); + sheet.setRowBreak(10); + sheet.setColumnBreak((short) 13); - assertEquals("row breaks number", 2, sheet.getRowBreaks().length); - assertEquals("column breaks number", 2, sheet.getColumnBreaks().length); + assertEquals("row breaks number", 2, sheet.getRowBreaks().length); + assertEquals("column breaks number", 2, sheet.getColumnBreaks().length); - HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1); - wb1.close(); - sheet = wb2.getSheetAt(0); + try (HSSFWorkbook wb2 = writeOutAndReadBack(wb1)) { + sheet = wb2.getSheetAt(0); - assertTrue("No row page break", sheet.isRowBroken(22)); - assertTrue("No column page break", sheet.isColumnBroken((short)4)); + assertTrue("No row page break", sheet.isRowBroken(22)); + assertTrue("No column page break", sheet.isColumnBroken((short) 4)); - assertEquals("row breaks number", 2, sheet.getRowBreaks().length); - assertEquals("column breaks number", 2, sheet.getColumnBreaks().length); - - wb2.close(); + assertEquals("row breaks number", 2, sheet.getRowBreaks().length); + assertEquals("column breaks number", 2, sheet.getColumnBreaks().length); + } + } } @Test public void dbcsName () throws IOException { - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("DBCSSheetName.xls"); - wb.getSheetAt(1); - assertEquals ("DBCS Sheet Name 2", wb.getSheetName(1),"\u090f\u0915" ); - assertEquals("DBCS Sheet Name 1", wb.getSheetName(0),"\u091c\u093e"); - wb.close(); + try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("DBCSSheetName.xls")) { + wb.getSheetAt(1); + assertEquals("DBCS Sheet Name 2", wb.getSheetName(1), "\u090f\u0915"); + assertEquals("DBCS Sheet Name 1", wb.getSheetName(0), "\u091c\u093e"); + } } /** @@ -608,87 +552,84 @@ public final class TestHSSFSheet extends BaseTestSheet { */ @Test public void topRow() throws IOException { - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPageBreaks.xls"); + try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPageBreaks.xls")) { + HSSFSheet sheet = wb.getSheetAt(0); + assertNotNull(sheet); - HSSFSheet sheet = wb.getSheetAt(0); - assertNotNull(sheet); - - short toprow = (short) 100; - short leftcol = (short) 50; - sheet.showInPane(toprow,leftcol); - assertEquals("HSSFSheet.getTopRow()", toprow, sheet.getTopRow()); - assertEquals("HSSFSheet.getLeftCol()", leftcol, sheet.getLeftCol()); - - wb.close(); + short toprow = (short) 100; + short leftcol = (short) 50; + sheet.showInPane(toprow, leftcol); + assertEquals("HSSFSheet.getTopRow()", toprow, sheet.getTopRow()); + assertEquals("HSSFSheet.getLeftCol()", leftcol, sheet.getLeftCol()); + } } @Test public void addEmptyRow() throws IOException { //try to add 5 empty rows to a new sheet - HSSFWorkbook wb1 = new HSSFWorkbook(); - HSSFSheet sheet = wb1.createSheet(); - for (int i = 0; i < 5; i++) { - sheet.createRow(i); + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet sheet = wb.createSheet(); + for (int i = 0; i < 5; i++) { + sheet.createRow(i); + } + + writeOutAndReadBack(wb).close(); } - HSSFTestDataSamples.writeOutAndReadBack(wb1).close(); - wb1.close(); + //try adding empty rows in an existing worksheet + try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("Simple.xls")) { - //try adding empty rows in an existing worksheet - HSSFWorkbook wb2 = HSSFTestDataSamples.openSampleWorkbook("Simple.xls"); + HSSFSheet sheet = wb.getSheetAt(0); + for (int i = 3; i < 10; i++) sheet.createRow(i); - sheet = wb2.getSheetAt(0); - for (int i = 3; i < 10; i++) sheet.createRow(i); - - HSSFTestDataSamples.writeOutAndReadBack(wb2).close(); - wb2.close(); + writeOutAndReadBack(wb).close(); + } } @Test public void autoSizeColumn() throws IOException { - HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("43902.xls"); - String sheetName = "my sheet"; - HSSFSheet sheet = wb1.getSheet(sheetName); + try (HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("43902.xls")) { + String sheetName = "my sheet"; + HSSFSheet sheet = wb1.getSheet(sheetName); - // Can't use literal numbers for column sizes, as - // will come out with different values on different - // machines based on the fonts available. - // So, we use ranges, which are pretty large, but - // thankfully don't overlap! - int minWithRow1And2 = 6400; - int maxWithRow1And2 = 7800; - int minWithRow1Only = 2750; - int maxWithRow1Only = 3400; + // Can't use literal numbers for column sizes, as + // will come out with different values on different + // machines based on the fonts available. + // So, we use ranges, which are pretty large, but + // thankfully don't overlap! + int minWithRow1And2 = 6400; + int maxWithRow1And2 = 7800; + int minWithRow1Only = 2750; + int maxWithRow1Only = 3400; - // autoSize the first column and check its size before the merged region (1,0,1,1) is set: - // it has to be based on the 2nd row width - sheet.autoSizeColumn((short)0); - assertTrue("Column autosized with only one row: wrong width", sheet.getColumnWidth(0) >= minWithRow1And2); - assertTrue("Column autosized with only one row: wrong width", sheet.getColumnWidth(0) <= maxWithRow1And2); + // autoSize the first column and check its size before the merged region (1,0,1,1) is set: + // it has to be based on the 2nd row width + sheet.autoSizeColumn((short) 0); + assertTrue("Column autosized with only one row: wrong width", sheet.getColumnWidth(0) >= minWithRow1And2); + assertTrue("Column autosized with only one row: wrong width", sheet.getColumnWidth(0) <= maxWithRow1And2); - //create a region over the 2nd row and auto size the first column - assertEquals(1, sheet.addMergedRegion(new CellRangeAddress(1,1,0,1))); - assertNotNull(sheet.getMergedRegion(0)); - sheet.autoSizeColumn((short)0); - HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1); + //create a region over the 2nd row and auto size the first column + assertEquals(1, sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 1))); + assertNotNull(sheet.getMergedRegion(0)); + sheet.autoSizeColumn((short) 0); + try (HSSFWorkbook wb2 = writeOutAndReadBack(wb1)) { - // check that the autoSized column width has ignored the 2nd row - // because it is included in a merged region (Excel like behavior) - HSSFSheet sheet2 = wb2.getSheet(sheetName); - assertTrue(sheet2.getColumnWidth(0) >= minWithRow1Only); - assertTrue(sheet2.getColumnWidth(0) <= maxWithRow1Only); + // check that the autoSized column width has ignored the 2nd row + // because it is included in a merged region (Excel like behavior) + HSSFSheet sheet2 = wb2.getSheet(sheetName); + assertTrue(sheet2.getColumnWidth(0) >= minWithRow1Only); + assertTrue(sheet2.getColumnWidth(0) <= maxWithRow1Only); - // remove the 2nd row merged region and check that the 2nd row value is used to the autoSizeColumn width - sheet2.removeMergedRegion(1); - sheet2.autoSizeColumn((short)0); - HSSFWorkbook wb3 = HSSFTestDataSamples.writeOutAndReadBack(wb2); - HSSFSheet sheet3 = wb3.getSheet(sheetName); - assertTrue(sheet3.getColumnWidth(0) >= minWithRow1And2); - assertTrue(sheet3.getColumnWidth(0) <= maxWithRow1And2); - - wb3.close(); - wb2.close(); - wb1.close(); + // remove the 2nd row merged region and check that the 2nd row value is used to the autoSizeColumn width + sheet2.removeMergedRegion(1); + sheet2.autoSizeColumn((short) 0); + try (HSSFWorkbook wb3 = writeOutAndReadBack(wb2)) { + HSSFSheet sheet3 = wb3.getSheet(sheetName); + assertTrue(sheet3.getColumnWidth(0) >= minWithRow1And2); + assertTrue(sheet3.getColumnWidth(0) <= maxWithRow1And2); + } + } + } } /** @@ -696,148 +637,144 @@ public final class TestHSSFSheet extends BaseTestSheet { */ @Test public void forceRecalculation() throws IOException { - HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("UncalcedRecord.xls"); + try (HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("UncalcedRecord.xls")) { - HSSFSheet sheet = wb1.getSheetAt(0); - HSSFSheet sheet2 = wb1.getSheetAt(0); - HSSFRow row = sheet.getRow(0); - row.createCell(0).setCellValue(5); - row.createCell(1).setCellValue(8); - assertFalse(sheet.getForceFormulaRecalculation()); - assertFalse(sheet2.getForceFormulaRecalculation()); + HSSFSheet sheet = wb1.getSheetAt(0); + HSSFSheet sheet2 = wb1.getSheetAt(0); + HSSFRow row = sheet.getRow(0); + row.createCell(0).setCellValue(5); + row.createCell(1).setCellValue(8); + assertFalse(sheet.getForceFormulaRecalculation()); + assertFalse(sheet2.getForceFormulaRecalculation()); - // Save and manually verify that on column C we have 0, value in template - HSSFTestDataSamples.writeOutAndReadBack(wb1).close(); - sheet.setForceFormulaRecalculation(true); - assertTrue(sheet.getForceFormulaRecalculation()); + // Save and manually verify that on column C we have 0, value in template + writeOutAndReadBack(wb1).close(); + sheet.setForceFormulaRecalculation(true); + assertTrue(sheet.getForceFormulaRecalculation()); - // Save and manually verify that on column C we have now 13, calculated value - // Try it can be opened - HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1); - wb1.close(); + // Save and manually verify that on column C we have now 13, calculated value + // Try it can be opened + try (HSSFWorkbook wb2 = writeOutAndReadBack(wb1)) { + // And check correct sheet settings found + sheet = wb2.getSheetAt(0); + sheet2 = wb2.getSheetAt(1); + assertTrue(sheet.getForceFormulaRecalculation()); + assertFalse(sheet2.getForceFormulaRecalculation()); - // And check correct sheet settings found - sheet = wb2.getSheetAt(0); - sheet2 = wb2.getSheetAt(1); - assertTrue(sheet.getForceFormulaRecalculation()); - assertFalse(sheet2.getForceFormulaRecalculation()); + // Now turn if back off again + sheet.setForceFormulaRecalculation(false); - // Now turn if back off again - sheet.setForceFormulaRecalculation(false); + try (HSSFWorkbook wb3 = writeOutAndReadBack(wb2)) { + assertFalse(wb3.getSheetAt(0).getForceFormulaRecalculation()); + assertFalse(wb3.getSheetAt(1).getForceFormulaRecalculation()); + assertFalse(wb3.getSheetAt(2).getForceFormulaRecalculation()); - HSSFWorkbook wb3 = HSSFTestDataSamples.writeOutAndReadBack(wb2); - wb2.close(); + // Now add a new sheet, and check things work + // with old ones unset, new one set + HSSFSheet s4 = wb3.createSheet(); + s4.setForceFormulaRecalculation(true); - assertFalse(wb3.getSheetAt(0).getForceFormulaRecalculation()); - assertFalse(wb3.getSheetAt(1).getForceFormulaRecalculation()); - assertFalse(wb3.getSheetAt(2).getForceFormulaRecalculation()); + assertFalse(sheet.getForceFormulaRecalculation()); + assertFalse(sheet2.getForceFormulaRecalculation()); + assertTrue(s4.getForceFormulaRecalculation()); - // Now add a new sheet, and check things work - // with old ones unset, new one set - HSSFSheet s4 = wb3.createSheet(); - s4.setForceFormulaRecalculation(true); - - assertFalse(sheet.getForceFormulaRecalculation()); - assertFalse(sheet2.getForceFormulaRecalculation()); - assertTrue(s4.getForceFormulaRecalculation()); - - HSSFWorkbook wb4 = HSSFTestDataSamples.writeOutAndReadBack(wb3); - wb3.close(); - - assertFalse(wb4.getSheetAt(0).getForceFormulaRecalculation()); - assertFalse(wb4.getSheetAt(1).getForceFormulaRecalculation()); - assertFalse(wb4.getSheetAt(2).getForceFormulaRecalculation()); - assertTrue(wb4.getSheetAt(3).getForceFormulaRecalculation()); - wb4.close(); + try (HSSFWorkbook wb4 = writeOutAndReadBack(wb3)) { + assertFalse(wb4.getSheetAt(0).getForceFormulaRecalculation()); + assertFalse(wb4.getSheetAt(1).getForceFormulaRecalculation()); + assertFalse(wb4.getSheetAt(2).getForceFormulaRecalculation()); + assertTrue(wb4.getSheetAt(3).getForceFormulaRecalculation()); + } + } + } + } } @Test public void columnWidthA() throws IOException { - //check we can correctly read column widths from a reference workbook - HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("colwidth.xls"); + // check we can correctly read column widths from a reference workbook + try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("colwidth.xls")) { - //reference values - int[] ref = {365, 548, 731, 914, 1097, 1280, 1462, 1645, 1828, 2011, 2194, 2377, 2560, 2742, 2925, 3108, 3291, 3474, 3657}; + //reference values + int[] ref = {365, 548, 731, 914, 1097, 1280, 1462, 1645, 1828, 2011, 2194, 2377, 2560, 2742, 2925, 3108, 3291, 3474, 3657}; - HSSFSheet sh = wb1.getSheetAt(0); - for (char i = 'A'; i <= 'S'; i++) { - int idx = i - 'A'; - int w = sh.getColumnWidth(idx); - assertEquals(ref[idx], w); + HSSFSheet sh = wb.getSheetAt(0); + for (char i = 'A'; i <= 'S'; i++) { + int idx = i - 'A'; + int w = sh.getColumnWidth(idx); + assertEquals(ref[idx], w); + } + + //the second sheet doesn't have overridden column widths + sh = wb.getSheetAt(1); + int def_width = sh.getDefaultColumnWidth(); + for (char i = 'A'; i <= 'S'; i++) { + int idx = i - 'A'; + int w = sh.getColumnWidth(idx); + //getDefaultColumnWidth returns width measured in characters + //getColumnWidth returns width measured in 1/256th units + assertEquals(def_width * 256, w); + } } - //the second sheet doesn't have overridden column widths - sh = wb1.getSheetAt(1); - int def_width = sh.getDefaultColumnWidth(); - for (char i = 'A'; i <= 'S'; i++) { - int idx = i - 'A'; - int w = sh.getColumnWidth(idx); - //getDefaultColumnWidth returns width measured in characters - //getColumnWidth returns width measured in 1/256th units - assertEquals(def_width*256, w); + // test new workbook + try (HSSFWorkbook wb1 = new HSSFWorkbook()) { + HSSFSheet sh = wb1.createSheet(); + sh.setDefaultColumnWidth(10); + assertEquals(10, sh.getDefaultColumnWidth()); + assertEquals(256 * 10, sh.getColumnWidth(0)); + assertEquals(256 * 10, sh.getColumnWidth(1)); + assertEquals(256 * 10, sh.getColumnWidth(2)); + for (char i = 'D'; i <= 'F'; i++) { + short w = (256 * 12); + sh.setColumnWidth(i, w); + assertEquals(w, sh.getColumnWidth(i)); + } + + //serialize and read again + try (HSSFWorkbook wb2 = writeOutAndReadBack(wb1)) { + sh = wb2.getSheetAt(0); + assertEquals(10, sh.getDefaultColumnWidth()); + //columns A-C have default width + assertEquals(256 * 10, sh.getColumnWidth(0)); + assertEquals(256 * 10, sh.getColumnWidth(1)); + assertEquals(256 * 10, sh.getColumnWidth(2)); + //columns D-F have custom width + for (char i = 'D'; i <= 'F'; i++) { + short w = (256 * 12); + assertEquals(w, sh.getColumnWidth(i)); + } + + // check for 16-bit signed/unsigned error: + sh.setColumnWidth(0, 40000); + assertEquals(40000, sh.getColumnWidth(0)); + } } - wb1.close(); - - //test new workbook - HSSFWorkbook wb2 = new HSSFWorkbook(); - sh = wb2.createSheet(); - sh.setDefaultColumnWidth(10); - assertEquals(10, sh.getDefaultColumnWidth()); - assertEquals(256*10, sh.getColumnWidth(0)); - assertEquals(256*10, sh.getColumnWidth(1)); - assertEquals(256*10, sh.getColumnWidth(2)); - for (char i = 'D'; i <= 'F'; i++) { - short w = (256*12); - sh.setColumnWidth(i, w); - assertEquals(w, sh.getColumnWidth(i)); - } - - //serialize and read again - HSSFWorkbook wb3 = HSSFTestDataSamples.writeOutAndReadBack(wb2); - wb2.close(); - - sh = wb3.getSheetAt(0); - assertEquals(10, sh.getDefaultColumnWidth()); - //columns A-C have default width - assertEquals(256*10, sh.getColumnWidth(0)); - assertEquals(256*10, sh.getColumnWidth(1)); - assertEquals(256*10, sh.getColumnWidth(2)); - //columns D-F have custom width - for (char i = 'D'; i <= 'F'; i++) { - short w = (256*12); - assertEquals(w, sh.getColumnWidth(i)); - } - - // check for 16-bit signed/unsigned error: - sh.setColumnWidth(0, 40000); - assertEquals(40000, sh.getColumnWidth(0)); - wb3.close(); } @Test public void defaultColumnWidth() throws IOException { - HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook( "12843-1.xls" ); - HSSFSheet sheet = wb1.getSheetAt( 7 ); - // shall not be NPE - assertEquals(8, sheet.getDefaultColumnWidth()); - assertEquals(8*256, sheet.getColumnWidth(0)); - - assertEquals(0xFF, sheet.getDefaultRowHeight()); - - wb1.close(); - - HSSFWorkbook wb2 = HSSFTestDataSamples.openSampleWorkbook( "34775.xls" ); - // second and third sheets miss DefaultColWidthRecord - for(int i = 1; i <= 2; i++){ - int dw = wb2.getSheetAt( i ).getDefaultColumnWidth(); - assertEquals(8, dw); - int cw = wb2.getSheetAt( i ).getColumnWidth(0); - assertEquals(8*256, cw); + try (HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook( "12843-1.xls" )) { + HSSFSheet sheet = wb1.getSheetAt(7); + // shall not be NPE + assertEquals(8, sheet.getDefaultColumnWidth()); + assertEquals(8 * 256, sheet.getColumnWidth(0)); assertEquals(0xFF, sheet.getDefaultRowHeight()); } - wb2.close(); + + try (HSSFWorkbook wb2 = HSSFTestDataSamples.openSampleWorkbook( "34775.xls" )) { + // second and third sheets miss DefaultColWidthRecord + for (int i = 1; i <= 2; i++) { + HSSFSheet sheet = wb2.getSheetAt(i); + int dw = sheet.getDefaultColumnWidth(); + assertEquals(8, dw); + int cw = sheet.getColumnWidth(0); + assertEquals(8 * 256, cw); + + assertEquals(0xFF, sheet.getDefaultRowHeight()); + } + } } /** @@ -847,21 +784,19 @@ public final class TestHSSFSheet extends BaseTestSheet { */ @Test public void missingRowRecords_bug41187() throws IOException { - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex41187-19267.xls"); + try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex41187-19267.xls")) { + HSSFSheet sheet = wb.getSheetAt(0); + HSSFRow row = sheet.getRow(0); + assertNotNull("Identified bug 41187 a", row); - HSSFSheet sheet = wb.getSheetAt(0); - HSSFRow row = sheet.getRow(0); - assertNotNull("Identified bug 41187 a", row); + assertNotEquals("Identified bug 41187 b", (short) 0, row.getHeight()); - assertNotEquals("Identified bug 41187 b", (short)0, row.getHeight()); + assertEquals("Hi Excel!", row.getCell(0).getRichStringCellValue().getString()); + // check row height for 'default' flag + assertEquals((short) 0xFF, row.getHeight()); - assertEquals("Hi Excel!", row.getCell(0).getRichStringCellValue().getString()); - // check row height for 'default' flag - assertEquals((short)0xFF, row.getHeight()); - - HSSFTestDataSamples.writeOutAndReadBack(wb).close(); - - wb.close(); + writeOutAndReadBack(wb).close(); + } } /** @@ -872,34 +807,32 @@ public final class TestHSSFSheet extends BaseTestSheet { */ @Test public void cloneSheetWithDrawings() throws IOException { - HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("45720.xls"); + try (HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("45720.xls")) { + HSSFSheet sheet1 = wb1.getSheetAt(0); - HSSFSheet sheet1 = wb1.getSheetAt(0); + DrawingManager2 dm1 = wb1.getWorkbook().findDrawingGroup(); + int maxDrawingGroupId1 = dm1.getDgg().getMaxDrawingGroupId(); + wb1.cloneSheet(0); - DrawingManager2 dm1 = wb1.getWorkbook().findDrawingGroup(); - int maxDrawingGroupId1 = dm1.getDgg().getMaxDrawingGroupId(); - wb1.cloneSheet(0); + //check EscherDggRecord - a workbook-level registry of drawing objects + assertEquals(maxDrawingGroupId1 + 1, dm1.getDgg().getMaxDrawingGroupId()); - //check EscherDggRecord - a workbook-level registry of drawing objects - assertEquals(maxDrawingGroupId1 + 1, dm1.getDgg().getMaxDrawingGroupId()); + try (HSSFWorkbook wb2 = writeOutAndReadBack(wb1)) { + DrawingManager2 dm2 = wb2.getWorkbook().findDrawingGroup(); + assertEquals(maxDrawingGroupId1 + 1, dm2.getDgg().getMaxDrawingGroupId()); - HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1); - wb1.close(); - - DrawingManager2 dm2 = wb2.getWorkbook().findDrawingGroup(); - assertEquals(maxDrawingGroupId1 + 1, dm2.getDgg().getMaxDrawingGroupId()); + HSSFSheet sheet2 = wb2.getSheetAt(1); - HSSFSheet sheet2 = wb2.getSheetAt(1); + //check that id of the drawing group was updated + EscherDgRecord dg1 = (EscherDgRecord) sheet1.getDrawingPatriarch().getBoundAggregate().findFirstWithId(EscherDgRecord.RECORD_ID); + EscherDgRecord dg2 = (EscherDgRecord) sheet2.getDrawingPatriarch().getBoundAggregate().findFirstWithId(EscherDgRecord.RECORD_ID); + int dg_id_1 = dg1.getOptions() >> 4; + int dg_id_2 = dg2.getOptions() >> 4; + assertEquals(dg_id_1 + 1, dg_id_2); - //check that id of the drawing group was updated - EscherDgRecord dg1 = (EscherDgRecord)sheet1.getDrawingPatriarch().getBoundAggregate().findFirstWithId(EscherDgRecord.RECORD_ID); - EscherDgRecord dg2 = (EscherDgRecord)sheet2.getDrawingPatriarch().getBoundAggregate().findFirstWithId(EscherDgRecord.RECORD_ID); - int dg_id_1 = dg1.getOptions() >> 4; - int dg_id_2 = dg2.getOptions() >> 4; - assertEquals(dg_id_1 + 1, dg_id_2); - - //TODO: check shapeId in the cloned sheet - wb2.close(); + //TODO: check shapeId in the cloned sheet + } + } } /** @@ -909,18 +842,18 @@ public final class TestHSSFSheet extends BaseTestSheet { */ @Test public void longSheetNames() throws IOException { - HSSFWorkbook wb = new HSSFWorkbook(); - final String SAME_PREFIX = "A123456789B123456789C123456789"; // 30 chars + try (HSSFWorkbook wb = new HSSFWorkbook()) { + final String SAME_PREFIX = "A123456789B123456789C123456789"; // 30 chars - wb.createSheet(SAME_PREFIX + "Dxxxx"); - try { - wb.createSheet(SAME_PREFIX + "Dyyyy"); // identical up to the 32nd char - fail("Expected exception not thrown"); - } catch (IllegalArgumentException e) { - assertEquals("The workbook already contains a sheet named 'A123456789B123456789C123456789Dyyyy'", e.getMessage()); + wb.createSheet(SAME_PREFIX + "Dxxxx"); + try { + wb.createSheet(SAME_PREFIX + "Dyyyy"); // identical up to the 32nd char + fail("Expected exception not thrown"); + } catch (IllegalArgumentException e) { + assertEquals("The workbook already contains a sheet named 'A123456789B123456789C123456789Dyyyy'", e.getMessage()); + } + wb.createSheet(SAME_PREFIX + "Exxxx"); // OK - differs in the 31st char } - wb.createSheet(SAME_PREFIX + "Exxxx"); // OK - differs in the 31st char - wb.close(); } /** @@ -928,45 +861,42 @@ public final class TestHSSFSheet extends BaseTestSheet { */ @Test public void readColumnStyles() throws IOException { - HSSFWorkbook wbNone = HSSFTestDataSamples.openSampleWorkbook("ColumnStyleNone.xls"); - HSSFWorkbook wbSimple = HSSFTestDataSamples.openSampleWorkbook("ColumnStyle1dp.xls"); - HSSFWorkbook wbComplex = HSSFTestDataSamples.openSampleWorkbook("ColumnStyle1dpColoured.xls"); + try (HSSFWorkbook wbNone = HSSFTestDataSamples.openSampleWorkbook("ColumnStyleNone.xls"); + HSSFWorkbook wbSimple = HSSFTestDataSamples.openSampleWorkbook("ColumnStyle1dp.xls"); + HSSFWorkbook wbComplex = HSSFTestDataSamples.openSampleWorkbook("ColumnStyle1dpColoured.xls")) { - // Presence / absence checks - assertNull(wbNone.getSheetAt(0).getColumnStyle(0)); - assertNull(wbNone.getSheetAt(0).getColumnStyle(1)); + // Presence / absence checks + assertNull(wbNone.getSheetAt(0).getColumnStyle(0)); + assertNull(wbNone.getSheetAt(0).getColumnStyle(1)); - assertNull(wbSimple.getSheetAt(0).getColumnStyle(0)); - assertNotNull(wbSimple.getSheetAt(0).getColumnStyle(1)); + assertNull(wbSimple.getSheetAt(0).getColumnStyle(0)); + assertNotNull(wbSimple.getSheetAt(0).getColumnStyle(1)); - assertNull(wbComplex.getSheetAt(0).getColumnStyle(0)); - assertNotNull(wbComplex.getSheetAt(0).getColumnStyle(1)); + assertNull(wbComplex.getSheetAt(0).getColumnStyle(0)); + assertNotNull(wbComplex.getSheetAt(0).getColumnStyle(1)); - // Details checks - HSSFCellStyle bs = wbSimple.getSheetAt(0).getColumnStyle(1); - assertNotNull(bs); - assertEquals(62, bs.getIndex()); - assertEquals("#,##0.0_ ;\\-#,##0.0\\ ", bs.getDataFormatString()); - assertEquals("Calibri", bs.getFont(wbSimple).getFontName()); - assertEquals(11*20, bs.getFont(wbSimple).getFontHeight()); - assertEquals(8, bs.getFont(wbSimple).getColor()); - assertFalse(bs.getFont(wbSimple).getItalic()); - assertFalse(bs.getFont(wbSimple).getBold()); + // Details checks + HSSFCellStyle bs = wbSimple.getSheetAt(0).getColumnStyle(1); + assertNotNull(bs); + assertEquals(62, bs.getIndex()); + assertEquals("#,##0.0_ ;\\-#,##0.0\\ ", bs.getDataFormatString()); + assertEquals("Calibri", bs.getFont(wbSimple).getFontName()); + assertEquals(11 * 20, bs.getFont(wbSimple).getFontHeight()); + assertEquals(8, bs.getFont(wbSimple).getColor()); + assertFalse(bs.getFont(wbSimple).getItalic()); + assertFalse(bs.getFont(wbSimple).getBold()); - HSSFCellStyle cs = wbComplex.getSheetAt(0).getColumnStyle(1); - assertNotNull(cs); - assertEquals(62, cs.getIndex()); - assertEquals("#,##0.0_ ;\\-#,##0.0\\ ", cs.getDataFormatString()); - assertEquals("Arial", cs.getFont(wbComplex).getFontName()); - assertEquals(8*20, cs.getFont(wbComplex).getFontHeight()); - assertEquals(10, cs.getFont(wbComplex).getColor()); - assertFalse(cs.getFont(wbComplex).getItalic()); - assertTrue(cs.getFont(wbComplex).getBold()); - - wbComplex.close(); - wbSimple.close(); - wbNone.close(); + HSSFCellStyle cs = wbComplex.getSheetAt(0).getColumnStyle(1); + assertNotNull(cs); + assertEquals(62, cs.getIndex()); + assertEquals("#,##0.0_ ;\\-#,##0.0\\ ", cs.getDataFormatString()); + assertEquals("Arial", cs.getFont(wbComplex).getFontName()); + assertEquals(8 * 20, cs.getFont(wbComplex).getFontHeight()); + assertEquals(10, cs.getFont(wbComplex).getColor()); + assertFalse(cs.getFont(wbComplex).getItalic()); + assertTrue(cs.getFont(wbComplex).getBold()); + } } /** @@ -974,227 +904,224 @@ public final class TestHSSFSheet extends BaseTestSheet { */ @Test public void arabic() throws IOException { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet s = wb.createSheet(); + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet s = wb.createSheet(); - assertFalse(s.isRightToLeft()); - s.setRightToLeft(true); - assertTrue(s.isRightToLeft()); - wb.close(); + assertFalse(s.isRightToLeft()); + s.setRightToLeft(true); + assertTrue(s.isRightToLeft()); + } } @Test public void autoFilter() throws IOException { - HSSFWorkbook wb1 = new HSSFWorkbook(); - HSSFSheet sh = wb1.createSheet(); - InternalWorkbook iwb = wb1.getWorkbook(); - InternalSheet ish = sh.getSheet(); + try (HSSFWorkbook wb1 = new HSSFWorkbook()) { + HSSFSheet sh = wb1.createSheet(); + InternalWorkbook iwb = wb1.getWorkbook(); + InternalSheet ish = sh.getSheet(); - assertNull( iwb.getSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, 1) ); - assertNull( ish.findFirstRecordBySid(AutoFilterInfoRecord.sid) ); + assertNull(iwb.getSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, 1)); + assertNull(ish.findFirstRecordBySid(AutoFilterInfoRecord.sid)); - CellRangeAddress range = CellRangeAddress.valueOf("A1:B10"); - sh.setAutoFilter(range); + CellRangeAddress range = CellRangeAddress.valueOf("A1:B10"); + sh.setAutoFilter(range); - NameRecord name = iwb.getSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, 1); - assertNotNull( name ); + NameRecord name = iwb.getSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, 1); + assertNotNull(name); - // The built-in name for auto-filter must consist of a single Area3d Ptg. - Ptg[] ptg = name.getNameDefinition(); - assertEquals("The built-in name for auto-filter must consist of a single Area3d Ptg", 1, ptg.length); - assertTrue("The built-in name for auto-filter must consist of a single Area3d Ptg", ptg[0] instanceof Area3DPtg); + // The built-in name for auto-filter must consist of a single Area3d Ptg. + Ptg[] ptg = name.getNameDefinition(); + assertEquals("The built-in name for auto-filter must consist of a single Area3d Ptg", 1, ptg.length); + assertTrue("The built-in name for auto-filter must consist of a single Area3d Ptg", ptg[0] instanceof Area3DPtg); - Area3DPtg aref = (Area3DPtg)ptg[0]; - assertEquals(range.getFirstColumn(), aref.getFirstColumn()); - assertEquals(range.getFirstRow(), aref.getFirstRow()); - assertEquals(range.getLastColumn(), aref.getLastColumn()); - assertEquals(range.getLastRow(), aref.getLastRow()); + Area3DPtg aref = (Area3DPtg) ptg[0]; + assertEquals(range.getFirstColumn(), aref.getFirstColumn()); + assertEquals(range.getFirstRow(), aref.getFirstRow()); + assertEquals(range.getLastColumn(), aref.getLastColumn()); + assertEquals(range.getLastRow(), aref.getLastRow()); - // verify AutoFilterInfoRecord - AutoFilterInfoRecord afilter = (AutoFilterInfoRecord)ish.findFirstRecordBySid(AutoFilterInfoRecord.sid); - assertNotNull(afilter ); - assertEquals(2, afilter.getNumEntries()); //filter covers two columns + // verify AutoFilterInfoRecord + AutoFilterInfoRecord afilter = (AutoFilterInfoRecord) ish.findFirstRecordBySid(AutoFilterInfoRecord.sid); + assertNotNull(afilter); + assertEquals(2, afilter.getNumEntries()); //filter covers two columns - HSSFPatriarch dr = sh.getDrawingPatriarch(); - assertNotNull(dr); - HSSFSimpleShape comboBoxShape = (HSSFSimpleShape)dr.getChildren().get(0); - assertEquals(comboBoxShape.getShapeType(), HSSFSimpleShape.OBJECT_TYPE_COMBO_BOX); + HSSFPatriarch dr = sh.getDrawingPatriarch(); + assertNotNull(dr); + HSSFSimpleShape comboBoxShape = (HSSFSimpleShape) dr.getChildren().get(0); + assertEquals(comboBoxShape.getShapeType(), HSSFSimpleShape.OBJECT_TYPE_COMBO_BOX); - assertNull( ish.findFirstRecordBySid(ObjRecord.sid) ); // ObjRecord will appear after serializetion + assertNull(ish.findFirstRecordBySid(ObjRecord.sid)); // ObjRecord will appear after serializetion - HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1); - wb1.close(); - sh = wb2.getSheetAt(0); - ish = sh.getSheet(); - ObjRecord objRecord = (ObjRecord)ish.findFirstRecordBySid(ObjRecord.sid); - assertNotNull(objRecord); - List subRecords = objRecord.getSubRecords(); - assertEquals(3, subRecords.size()); - assertTrue(subRecords.get(0) instanceof CommonObjectDataSubRecord ); - assertTrue(subRecords.get(1) instanceof FtCblsSubRecord ); // must be present, see Bug 51481 - assertTrue(subRecords.get(2) instanceof LbsDataSubRecord ); - wb2.close(); + try (HSSFWorkbook wb2 = writeOutAndReadBack(wb1)) { + sh = wb2.getSheetAt(0); + ish = sh.getSheet(); + ObjRecord objRecord = (ObjRecord) ish.findFirstRecordBySid(ObjRecord.sid); + assertNotNull(objRecord); + List subRecords = objRecord.getSubRecords(); + assertEquals(3, subRecords.size()); + assertTrue(subRecords.get(0) instanceof CommonObjectDataSubRecord); + assertTrue(subRecords.get(1) instanceof FtCblsSubRecord); // must be present, see Bug 51481 + assertTrue(subRecords.get(2) instanceof LbsDataSubRecord); + } + } } @Test public void getSetColumnHiddenShort() throws IOException { - Workbook workbook = new HSSFWorkbook(); - Sheet sheet = workbook.createSheet("Sheet 1"); - sheet.setColumnHidden((short)2, true); - assertTrue(sheet.isColumnHidden((short)2)); - workbook.close(); + try (Workbook workbook = new HSSFWorkbook()) { + Sheet sheet = workbook.createSheet("Sheet 1"); + sheet.setColumnHidden((short) 2, true); + assertTrue(sheet.isColumnHidden((short) 2)); + } } @Test public void columnWidthShort() throws IOException { - HSSFWorkbook wb1 = new HSSFWorkbook(); - Sheet sheet = wb1.createSheet(); + try (HSSFWorkbook wb1 = new HSSFWorkbook()) { + Sheet sheet = wb1.createSheet(); - //default column width measured in characters - sheet.setDefaultColumnWidth((short)10); - assertEquals(10, sheet.getDefaultColumnWidth()); - //columns A-C have default width - assertEquals(256*10, sheet.getColumnWidth((short)0)); - assertEquals(256*10, sheet.getColumnWidth((short)1)); - assertEquals(256*10, sheet.getColumnWidth((short)2)); + //default column width measured in characters + sheet.setDefaultColumnWidth((short) 10); + assertEquals(10, sheet.getDefaultColumnWidth()); + //columns A-C have default width + assertEquals(256 * 10, sheet.getColumnWidth((short) 0)); + assertEquals(256 * 10, sheet.getColumnWidth((short) 1)); + assertEquals(256 * 10, sheet.getColumnWidth((short) 2)); - //set custom width for D-F - for (char i = 'D'; i <= 'F'; i++) { - //Sheet#setColumnWidth accepts the width in units of 1/256th of a character width - int w = 256*12; - sheet.setColumnWidth((short)i, w); - assertEquals(w, sheet.getColumnWidth((short)i)); + //set custom width for D-F + for (char i = 'D'; i <= 'F'; i++) { + //Sheet#setColumnWidth accepts the width in units of 1/256th of a character width + int w = 256 * 12; + sheet.setColumnWidth((short) i, w); + assertEquals(w, sheet.getColumnWidth((short) i)); + } + //reset the default column width, columns A-C change, D-F still have custom width + sheet.setDefaultColumnWidth((short) 20); + assertEquals(20, sheet.getDefaultColumnWidth()); + assertEquals(256 * 20, sheet.getColumnWidth((short) 0)); + assertEquals(256 * 20, sheet.getColumnWidth((short) 1)); + assertEquals(256 * 20, sheet.getColumnWidth((short) 2)); + for (char i = 'D'; i <= 'F'; i++) { + int w = 256 * 12; + assertEquals(w, sheet.getColumnWidth((short) i)); + } + + // check for 16-bit signed/unsigned error: + sheet.setColumnWidth((short) 10, 40000); + assertEquals(40000, sheet.getColumnWidth((short) 10)); + + //The maximum column width for an individual cell is 255 characters + try { + sheet.setColumnWidth((short) 9, 256 * 256); + fail("expected exception"); + } catch (IllegalArgumentException e) { + assertEquals("The maximum column width for an individual cell is 255 characters.", e.getMessage()); + } + + //serialize and read again + try (HSSFWorkbook wb2 = writeOutAndReadBack(wb1)) { + sheet = wb2.getSheetAt(0); + assertEquals(20, sheet.getDefaultColumnWidth()); + //columns A-C have default width + assertEquals(256 * 20, sheet.getColumnWidth((short) 0)); + assertEquals(256 * 20, sheet.getColumnWidth((short) 1)); + assertEquals(256 * 20, sheet.getColumnWidth((short) 2)); + //columns D-F have custom width + for (char i = 'D'; i <= 'F'; i++) { + short w = (256 * 12); + assertEquals(w, sheet.getColumnWidth((short) i)); + } + assertEquals(40000, sheet.getColumnWidth((short) 10)); + } } - //reset the default column width, columns A-C change, D-F still have custom width - sheet.setDefaultColumnWidth((short)20); - assertEquals(20, sheet.getDefaultColumnWidth()); - assertEquals(256*20, sheet.getColumnWidth((short)0)); - assertEquals(256*20, sheet.getColumnWidth((short)1)); - assertEquals(256*20, sheet.getColumnWidth((short)2)); - for (char i = 'D'; i <= 'F'; i++) { - int w = 256*12; - assertEquals(w, sheet.getColumnWidth((short)i)); - } - - // check for 16-bit signed/unsigned error: - sheet.setColumnWidth((short)10, 40000); - assertEquals(40000, sheet.getColumnWidth((short)10)); - - //The maximum column width for an individual cell is 255 characters - try { - sheet.setColumnWidth((short)9, 256*256); - fail("expected exception"); - } catch(IllegalArgumentException e){ - assertEquals("The maximum column width for an individual cell is 255 characters.", e.getMessage()); - } - - //serialize and read again - HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1); - wb1.close(); - - sheet = wb2.getSheetAt(0); - assertEquals(20, sheet.getDefaultColumnWidth()); - //columns A-C have default width - assertEquals(256*20, sheet.getColumnWidth((short)0)); - assertEquals(256*20, sheet.getColumnWidth((short)1)); - assertEquals(256*20, sheet.getColumnWidth((short)2)); - //columns D-F have custom width - for (char i = 'D'; i <= 'F'; i++) { - short w = (256*12); - assertEquals(w, sheet.getColumnWidth((short)i)); - } - assertEquals(40000, sheet.getColumnWidth((short)10)); - - wb2.close(); } @Test public void showInPane() throws IOException { - Workbook wb = new HSSFWorkbook(); - Sheet sheet = wb.createSheet(); - sheet.showInPane(2, 3); - - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Maximum row number is 65535"); - sheet.showInPane(Integer.MAX_VALUE, 3); - wb.close(); + try (Workbook wb = new HSSFWorkbook()) { + Sheet sheet = wb.createSheet(); + sheet.showInPane(2, 3); + + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Maximum row number is 65535"); + sheet.showInPane(Integer.MAX_VALUE, 3); + } } - + @Test public void drawingRecords() throws IOException { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet sheet = wb.createSheet(); + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet sheet = wb.createSheet(); - /* TODO: NPE? - sheet.dumpDrawingRecords(false); - sheet.dumpDrawingRecords(true);*/ - assertNull(sheet.getDrawingEscherAggregate()); - wb.close(); + /* TODO: NPE? + sheet.dumpDrawingRecords(false); + sheet.dumpDrawingRecords(true);*/ + assertNull(sheet.getDrawingEscherAggregate()); + } } @Test public void bug55723b() throws IOException { - HSSFWorkbook wb = new HSSFWorkbook(); - Sheet sheet = wb.createSheet(); + try (HSSFWorkbook wb = new HSSFWorkbook()) { + Sheet sheet = wb.createSheet(); - // stored with a special name - assertNull(wb.getWorkbook().getSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, 1)); + // stored with a special name + assertNull(wb.getWorkbook().getSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, 1)); - CellRangeAddress range = CellRangeAddress.valueOf("A:B"); - AutoFilter filter = sheet.setAutoFilter(range); - assertNotNull(filter); - - // stored with a special name - NameRecord record = wb.getWorkbook().getSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, 1); - assertNotNull(record); - wb.close(); + CellRangeAddress range = CellRangeAddress.valueOf("A:B"); + AutoFilter filter = sheet.setAutoFilter(range); + assertNotNull(filter); + + // stored with a special name + NameRecord record = wb.getWorkbook().getSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, 1); + assertNotNull(record); + } } - + @Test public void test58746() throws IOException { - HSSFWorkbook wb = new HSSFWorkbook(); - - HSSFSheet first = wb.createSheet("first"); - first.createRow(0).createCell(0).setCellValue(1); - - HSSFSheet second = wb.createSheet("second"); - second.createRow(0).createCell(0).setCellValue(2); - - HSSFSheet third = wb.createSheet("third"); - HSSFRow row = third.createRow(0); - row.createCell(0).setCellFormula("first!A1"); - row.createCell(1).setCellFormula("second!A1"); + try (HSSFWorkbook wb = new HSSFWorkbook()) { - // re-order for sheet "third" - wb.setSheetOrder("third", 0); - - // verify results - assertEquals("third", wb.getSheetAt(0).getSheetName()); - assertEquals("first", wb.getSheetAt(1).getSheetName()); - assertEquals("second", wb.getSheetAt(2).getSheetName()); - - assertEquals("first!A1", wb.getSheetAt(0).getRow(0).getCell(0).getCellFormula()); - assertEquals("second!A1", wb.getSheetAt(0).getRow(0).getCell(1).getCellFormula()); - - wb.close(); + HSSFSheet first = wb.createSheet("first"); + first.createRow(0).createCell(0).setCellValue(1); + + HSSFSheet second = wb.createSheet("second"); + second.createRow(0).createCell(0).setCellValue(2); + + HSSFSheet third = wb.createSheet("third"); + HSSFRow row = third.createRow(0); + row.createCell(0).setCellFormula("first!A1"); + row.createCell(1).setCellFormula("second!A1"); + + // re-order for sheet "third" + wb.setSheetOrder("third", 0); + + // verify results + assertEquals("third", wb.getSheetAt(0).getSheetName()); + assertEquals("first", wb.getSheetAt(1).getSheetName()); + assertEquals("second", wb.getSheetAt(2).getSheetName()); + + assertEquals("first!A1", wb.getSheetAt(0).getRow(0).getCell(0).getCellFormula()); + assertEquals("second!A1", wb.getSheetAt(0).getRow(0).getCell(1).getCellFormula()); + } } @Test public void bug59135() throws IOException { - HSSFWorkbook wb1 = new HSSFWorkbook(); - wb1.createSheet().protectSheet("1111.2222.3333.1234"); - HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1); - wb1.close(); - - assertEquals((short)0xb86b, wb2.getSheetAt(0).getPassword()); - wb2.close(); + try (HSSFWorkbook wb1 = new HSSFWorkbook()) { + wb1.createSheet().protectSheet("1111.2222.3333.1234"); + try (HSSFWorkbook wb2 = writeOutAndReadBack(wb1)) { - HSSFWorkbook wb3 = new HSSFWorkbook(); - wb3.createSheet().protectSheet("1111.2222.3333.12345"); - HSSFWorkbook wb4 = HSSFTestDataSamples.writeOutAndReadBack(wb3); - wb3.close(); - - assertEquals((short)0xbecc, wb4.getSheetAt(0).getPassword()); - wb4.close(); + assertEquals((short) 0xb86b, wb2.getSheetAt(0).getPassword()); + } + } + + try (HSSFWorkbook wb1 = new HSSFWorkbook()) { + wb1.createSheet().protectSheet("1111.2222.3333.12345"); + try (HSSFWorkbook wb2 = writeOutAndReadBack(wb1)) { + + assertEquals((short) 0xbecc, wb2.getSheetAt(0).getPassword()); + } + } } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheetUpdateArrayFormulas.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheetUpdateArrayFormulas.java index dfa2bae701..ac8df385cf 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheetUpdateArrayFormulas.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheetUpdateArrayFormulas.java @@ -17,13 +17,19 @@ package org.apache.poi.hssf.usermodel; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.apache.poi.POITestCase; import org.apache.poi.hssf.HSSFITestDataProvider; import org.apache.poi.hssf.record.ArrayRecord; import org.apache.poi.hssf.record.FormulaRecord; @@ -31,7 +37,6 @@ import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate; import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate; import org.apache.poi.hssf.record.aggregates.SharedValueManager; -import org.apache.poi.hssf.record.aggregates.TestSharedValueManager; import org.apache.poi.ss.usermodel.BaseTestSheetUpdateArrayFormulas; import org.apache.poi.ss.usermodel.CellRange; import org.apache.poi.ss.util.CellRangeAddress; @@ -39,9 +44,6 @@ import org.junit.Test; /** * Test array formulas in HSSF - * - * @author Yegor Kozlov - * @author Josh Micich */ public final class TestHSSFSheetUpdateArrayFormulas extends BaseTestSheetUpdateArrayFormulas { @@ -53,27 +55,26 @@ public final class TestHSSFSheetUpdateArrayFormulas extends BaseTestSheetUpdateA // Local methods here test HSSF-specific details of updating array formulas @Test public void testHSSFSetArrayFormula_singleCell() throws IOException { - HSSFWorkbook workbook = new HSSFWorkbook(); - HSSFSheet sheet = workbook.createSheet("Sheet1"); + try (HSSFWorkbook workbook = new HSSFWorkbook()) { + HSSFSheet sheet = workbook.createSheet("Sheet1"); - CellRangeAddress range = new CellRangeAddress(2, 2, 2, 2); - HSSFCell[] cells = sheet.setArrayFormula("SUM(C11:C12*D11:D12)", range).getFlattenedCells(); - assertEquals(1, cells.length); + CellRangeAddress range = new CellRangeAddress(2, 2, 2, 2); + HSSFCell[] cells = sheet.setArrayFormula("SUM(C11:C12*D11:D12)", range).getFlattenedCells(); + assertEquals(1, cells.length); - // sheet.setArrayFormula creates rows and cells for the designated range - assertNotNull(sheet.getRow(2)); - HSSFCell cell = sheet.getRow(2).getCell(2); - assertNotNull(cell); + // sheet.setArrayFormula creates rows and cells for the designated range + assertNotNull(sheet.getRow(2)); + HSSFCell cell = sheet.getRow(2).getCell(2); + assertNotNull(cell); - assertTrue(cell.isPartOfArrayFormulaGroup()); - //retrieve the range and check it is the same - assertEquals(range.formatAsString(), cell.getArrayFormulaRange().formatAsString()); + assertTrue(cell.isPartOfArrayFormulaGroup()); + //retrieve the range and check it is the same + assertEquals(range.formatAsString(), cell.getArrayFormulaRange().formatAsString()); - FormulaRecordAggregate agg = (FormulaRecordAggregate)cell.getCellValueRecord(); - assertEquals(range.formatAsString(), agg.getArrayFormulaRange().formatAsString()); - assertTrue(agg.isPartOfArrayFormula()); - - workbook.close(); + FormulaRecordAggregate agg = (FormulaRecordAggregate) cell.getCellValueRecord(); + assertEquals(range.formatAsString(), agg.getArrayFormulaRange().formatAsString()); + assertTrue(agg.isPartOfArrayFormula()); + } } /** @@ -81,53 +82,38 @@ public final class TestHSSFSheetUpdateArrayFormulas extends BaseTestSheetUpdateA */ @Test public void testAddRemoveArrayFormulas_recordUpdates() throws IOException { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet s = wb.createSheet("Sheet1"); + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet s = wb.createSheet("Sheet1"); - CellRange cr = s.setArrayFormula("123", CellRangeAddress.valueOf("B5:C6")); - Record[] recs; - int ix; - recs = RecordInspector.getRecords(s, 0); - ix = findRecordOfType(recs, ArrayRecord.class, 0); - confirmRecordClass(recs, ix-1, FormulaRecord.class); - confirmRecordClass(recs, ix+1, FormulaRecord.class); - confirmRecordClass(recs, ix+2, FormulaRecord.class); - confirmRecordClass(recs, ix+3, FormulaRecord.class); - // just one array record - assertTrue(findRecordOfType(recs, ArrayRecord.class, ix+1) < 0); + CellRange cr = s.setArrayFormula("123", CellRangeAddress.valueOf("B5:C6")); + List recs = new ArrayList<>(); + s.getSheet().visitContainedRecords(recs::add, 0); - s.removeArrayFormula(cr.getTopLeftCell()); - - // Make sure the array formula has been removed properly - - recs = RecordInspector.getRecords(s, 0); - assertTrue(findRecordOfType(recs, ArrayRecord.class, 0) < 0); - assertTrue(findRecordOfType(recs, FormulaRecord.class, 0) < 0); - RowRecordsAggregate rra = s.getSheet().getRowsAggregate(); - SharedValueManager svm = TestSharedValueManager.extractFromRRA(rra); - if (svm.getArrayRecord(4, 1) != null) { - fail("Array record was not cleaned up properly."); - } - - wb.close(); - } - - private static void confirmRecordClass(Record[] recs, int index, Class cls) { - if (recs.length <= index) { - fail("Expected (" + cls.getName() + ") at index " - + index + " but array length is " + recs.length + "."); - } - assertEquals(cls, recs[index].getClass()); - } - /** - * @return -1 if not found - */ - private static int findRecordOfType(Record[] recs, Class type, int fromIndex) { - for (int i=fromIndex; i[] act = recs.subList(ix-1, ix+4).stream().map(Object::getClass).toArray(Class[]::new); + Class[] exp = { FormulaRecord.class, ArrayRecord.class, FormulaRecord.class, FormulaRecord.class, FormulaRecord.class }; + assertArrayEquals(exp, act); + + // just one array record + assertFalse(recs.subList(ix + 1, recs.size()).stream().anyMatch(r -> r instanceof ArrayRecord)); + + s.removeArrayFormula(cr.getTopLeftCell()); + + // Make sure the array formula has been removed properly + recs.clear(); + s.getSheet().visitContainedRecords(recs::add, 0); + + assertFalse(recs.stream().anyMatch(r -> r instanceof ArrayRecord || r instanceof FormulaRecord)); + RowRecordsAggregate rra = s.getSheet().getRowsAggregate(); + + SharedValueManager svm = POITestCase.getFieldValue(RowRecordsAggregate.class, rra, SharedValueManager.class, "_sharedValueManager"); + assertNull("Array record was not cleaned up properly.", svm.getArrayRecord(4, 1)); } - return -1; } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFTextbox.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFTextbox.java index ab32e99c02..e727e321bd 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFTextbox.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFTextbox.java @@ -17,49 +17,55 @@ package org.apache.poi.hssf.usermodel; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.junit.Test; /** * Test HSSFTextbox. - * - * @author Yegor Kozlov (yegor at apache.org) */ -public final class TestHSSFTextbox extends TestCase{ +public final class TestHSSFTextbox { /** * Test that accessors to horizontal and vertical alignment work properly */ - public void testAlignment() { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet sh1 = wb.createSheet(); - HSSFPatriarch patriarch = sh1.createDrawingPatriarch(); + @Test + public void testAlignment() throws IOException { + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet sh1 = wb.createSheet(); + HSSFPatriarch patriarch = sh1.createDrawingPatriarch(); - HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor(0, 0, 0, 0, (short) 1, 1, (short) 6, 4)); - HSSFRichTextString str = new HSSFRichTextString("Hello, World"); - textbox.setString(str); - textbox.setHorizontalAlignment(HSSFTextbox.HORIZONTAL_ALIGNMENT_CENTERED); - textbox.setVerticalAlignment(HSSFTextbox.VERTICAL_ALIGNMENT_CENTER); + HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor(0, 0, 0, 0, (short) 1, 1, (short) 6, 4)); + HSSFRichTextString str = new HSSFRichTextString("Hello, World"); + textbox.setString(str); + textbox.setHorizontalAlignment(HSSFTextbox.HORIZONTAL_ALIGNMENT_CENTERED); + textbox.setVerticalAlignment(HSSFTextbox.VERTICAL_ALIGNMENT_CENTER); - assertEquals(HSSFTextbox.HORIZONTAL_ALIGNMENT_CENTERED, textbox.getHorizontalAlignment()); - assertEquals(HSSFTextbox.VERTICAL_ALIGNMENT_CENTER, textbox.getVerticalAlignment()); + assertEquals(HSSFTextbox.HORIZONTAL_ALIGNMENT_CENTERED, textbox.getHorizontalAlignment()); + assertEquals(HSSFTextbox.VERTICAL_ALIGNMENT_CENTER, textbox.getVerticalAlignment()); + } } /** * Excel requires at least one format run in HSSFTextbox. * When inserting text make sure that if font is not set we must set the default one. */ - public void testSetDeafultTextFormat() { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet sheet = wb.createSheet(); - HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); + @Test + public void testSetDeafultTextFormat() throws IOException { + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet sheet = wb.createSheet(); + HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); - HSSFTextbox textbox1 = patriarch.createTextbox(new HSSFClientAnchor(0,0,0,0,(short)1,1,(short)3,3)); - HSSFRichTextString rt1 = new HSSFRichTextString("Hello, World!"); - assertEquals(0, rt1.numFormattingRuns()); - textbox1.setString(rt1); + HSSFTextbox textbox1 = patriarch.createTextbox(new HSSFClientAnchor(0, 0, 0, 0, (short) 1, 1, (short) 3, 3)); + HSSFRichTextString rt1 = new HSSFRichTextString("Hello, World!"); + assertEquals(0, rt1.numFormattingRuns()); + textbox1.setString(rt1); - HSSFRichTextString rt2 = textbox1.getString(); - assertEquals(1, rt2.numFormattingRuns()); - assertEquals(HSSFRichTextString.NO_FONT, rt2.getFontOfFormattingRun(0)); + HSSFRichTextString rt2 = textbox1.getString(); + assertEquals(1, rt2.numFormattingRuns()); + assertEquals(HSSFRichTextString.NO_FONT, rt2.getFontOfFormattingRun(0)); + } } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java index f3bb535b12..be7dda1f34 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java @@ -18,6 +18,7 @@ package org.apache.poi.hssf.usermodel; import static org.apache.poi.POITestCase.assertContains; +import static org.apache.poi.hssf.HSSFTestDataSamples.openSampleWorkbook; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -36,7 +37,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import junit.framework.AssertionFailedError; import org.apache.poi.POIDataSamples; import org.apache.poi.ddf.EscherBSERecord; import org.apache.poi.hpsf.ClassID; @@ -66,8 +66,6 @@ import org.apache.poi.ss.usermodel.SheetConditionalFormatting; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.util.IOUtils; -import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.RecordFormatException; import org.apache.poi.util.TempFile; import org.junit.Ignore; import org.junit.Test; @@ -125,7 +123,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { Sheet s; // Single chart, two sheets - HSSFWorkbook b1 = HSSFTestDataSamples.openSampleWorkbook("44010-SingleChart.xls"); + HSSFWorkbook b1 = openSampleWorkbook("44010-SingleChart.xls"); assertEquals(2, b1.getNumberOfSheets()); assertEquals("Graph2", b1.getSheetName(1)); s = b1.getSheetAt(1); @@ -142,7 +140,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { // We've now called getDrawingPatriarch() so // everything will be all screwy // So, start again - HSSFWorkbook b2 = HSSFTestDataSamples.openSampleWorkbook("44010-SingleChart.xls"); + HSSFWorkbook b2 = openSampleWorkbook("44010-SingleChart.xls"); HSSFWorkbook b3 = HSSFTestDataSamples.writeOutAndReadBack(b2); b2.close(); @@ -154,7 +152,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { b3.close(); // Two charts, three sheets - HSSFWorkbook b4 = HSSFTestDataSamples.openSampleWorkbook("44010-TwoCharts.xls"); + HSSFWorkbook b4 = openSampleWorkbook("44010-TwoCharts.xls"); assertEquals(3, b4.getNumberOfSheets()); s = b4.getSheetAt(1); @@ -175,7 +173,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { // We've now called getDrawingPatriarch() so // everything will be all screwy // So, start again - HSSFWorkbook b5 = HSSFTestDataSamples.openSampleWorkbook("44010-TwoCharts.xls"); + HSSFWorkbook b5 = openSampleWorkbook("44010-TwoCharts.xls"); Workbook b6 = HSSFTestDataSamples.writeOutAndReadBack(b5); b5.close(); @@ -404,7 +402,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { */ @Test public void namesToDeleteSheets() throws IOException { - HSSFWorkbook b = HSSFTestDataSamples.openSampleWorkbook("30978-deleted.xls"); + HSSFWorkbook b = openSampleWorkbook("30978-deleted.xls"); assertEquals(3, b.getNumberOfNames()); // Sheet 2 is deleted @@ -515,13 +513,10 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { * The sample file provided with bug 45582 seems to have one extra byte after the EOFRecord */ @Test - public void extraDataAfterEOFRecord() { - try { - HSSFTestDataSamples.openSampleWorkbook("ex45582-22397.xls"); - } catch (RecordFormatException e) { - if (e.getCause() instanceof LittleEndian.BufferUnderrunException) { - throw new AssertionFailedError("Identified bug 45582"); - } + public void extraDataAfterEOFRecord() throws IOException { + // bug 45582 - RecordFormatException - getCause() instanceof LittleEndian.BufferUnderrunException + try (HSSFWorkbook wb = openSampleWorkbook("ex45582-22397.xls")) { + assertNotNull(wb); } } @@ -533,7 +528,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { public void findBuiltInNameRecord() throws IOException { // testRRaC has multiple (3) built-in name records // The second print titles name record has getSheetNumber()==4 - HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("testRRaC.xls"); + HSSFWorkbook wb1 = openSampleWorkbook("testRRaC.xls"); NameRecord nr; assertEquals(3, wb1.getWorkbook().getNumNames()); nr = wb1.getWorkbook().getNameRecord(2); @@ -793,7 +788,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { @Test public void clonePictures() throws IOException { - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleWithImages.xls"); + HSSFWorkbook wb = openSampleWorkbook("SimpleWithImages.xls"); InternalWorkbook iwb = wb.getWorkbook(); iwb.findDrawingGroup(); @@ -937,7 +932,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { @Test public void bug50298() throws Exception { - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("50298.xls"); + HSSFWorkbook wb = openSampleWorkbook("50298.xls"); assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received"); @@ -972,7 +967,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { @Test public void bug50298a() throws Exception { - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("50298.xls"); + HSSFWorkbook wb = openSampleWorkbook("50298.xls"); assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received"); @@ -1017,7 +1012,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { public void bug54500() throws Exception { String nameName = "AName"; String sheetName = "ASheet"; - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("54500.xls"); + HSSFWorkbook wb = openSampleWorkbook("54500.xls"); assertSheetOrder(wb, "Sheet1", "Sheet2", "Sheet3"); @@ -1071,7 +1066,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { @Test public void test49423() throws Exception { - HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("49423.xls"); + HSSFWorkbook workbook = openSampleWorkbook("49423.xls"); boolean found = false; int numSheets = workbook.getNumberOfSheets(); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestMatrixFormulasFromBinarySpreadsheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestMatrixFormulasFromBinarySpreadsheet.java index a28060c1b4..8d337e0888 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestMatrixFormulasFromBinarySpreadsheet.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestMatrixFormulasFromBinarySpreadsheet.java @@ -45,8 +45,6 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import junit.framework.AssertionFailedError; - @RunWith(Parameterized.class) public final class TestMatrixFormulasFromBinarySpreadsheet { @@ -57,16 +55,16 @@ public final class TestMatrixFormulasFromBinarySpreadsheet { private static Sheet sheet; private static FormulaEvaluator evaluator; private static Locale userLocale; - + /* * Unlike TestFormulaFromSpreadsheet which this class is modified from, there is no * differentiation between operators and functions, if more functionality is implemented with * array formulas then it might be worth it to separate operators from functions - * + * * Also, output matrices are statically 3x3, if larger matrices wanted to be tested * then adding matrix size parameter would be useful and parsing would be based off that. */ - + private static interface Navigator { /** * Name of the test spreadsheet (found in the standard test data folder) @@ -96,21 +94,21 @@ public final class TestMatrixFormulasFromBinarySpreadsheet { * Used to indicate when there are no more operations left */ String END_OF_TESTS = ""; - + } - + /* Parameters for test case */ @Parameter(0) public String targetFunctionName; @Parameter(1) public int formulasRowIdx; - + @AfterClass public static void closeResource() throws Exception { LocaleUtil.setUserLocale(userLocale); workbook.close(); } - + /* generating parameter instances */ @Parameters(name="{0}") public static Collection data() throws Exception { @@ -119,18 +117,18 @@ public final class TestMatrixFormulasFromBinarySpreadsheet { // already set, when we would try to change the locale by then userLocale = LocaleUtil.getUserLocale(); LocaleUtil.setUserLocale(Locale.ROOT); - + workbook = HSSFTestDataSamples.openSampleWorkbook(Navigator.FILENAME); sheet = workbook.getSheetAt(0); evaluator = new HSSFFormulaEvaluator(workbook); - + List data = new ArrayList(); - + processFunctionGroup(data, Navigator.START_OPERATORS_ROW_INDEX, null); - + return data; } - + /** * @param startRowIndex row index in the spreadsheet where the first function/operator is found * @param testFocusFunctionName name of a single function/operator to test alone. @@ -152,7 +150,7 @@ public final class TestMatrixFormulasFromBinarySpreadsheet { } } } - + @Test public void processFunctionRow() { @@ -161,27 +159,27 @@ public final class TestMatrixFormulasFromBinarySpreadsheet { for (int rowNum = formulasRowIdx; rowNum < formulasRowIdx + Navigator.ROW_OFF_NEXT_OP - 1; rowNum++) { for (int colNum = Navigator.START_RESULT_COL_INDEX; colNum < endColNum; colNum++) { Row r = sheet.getRow(rowNum); - + /* mainly to escape row failures on MDETERM which only returns a scalar */ if (r == null) { continue; } - + Cell c = sheet.getRow(rowNum).getCell(colNum); - + if (c == null || c.getCellType() != CellType.FORMULA) { continue; } - + CellValue actValue = evaluator.evaluate(c); Cell expValue = sheet.getRow(rowNum).getCell(colNum + Navigator.COL_OFF_EXPECTED_RESULT); - + String msg = String.format(Locale.ROOT, "Function '%s': Formula: %s @ %d:%d" , targetFunctionName, c.getCellFormula(), rowNum, colNum); - + assertNotNull(msg + " - Bad setup data expected value is null", expValue); assertNotNull(msg + " - actual value was null", actValue); - + final CellType cellType = expValue.getCellType(); switch (cellType) { case BLANK: @@ -211,7 +209,7 @@ public final class TestMatrixFormulasFromBinarySpreadsheet { } } } - + /** * @return null if cell is missing, empty or blank */ @@ -235,13 +233,13 @@ public final class TestMatrixFormulasFromBinarySpreadsheet { return cell.getRichStringCellValue().getString(); } - throw new AssertionFailedError("Bad cell type for 'function name' column: (" - + cell.getCellType() + ") row (" + (r.getRowNum() +1) + ")"); + fail("Bad cell type for 'function name' column: (" + cell.getCellType() + ") row (" + (r.getRowNum() +1) + ")"); + return ""; } - - - - - + + + + + } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestPatriarch.java b/src/testcases/org/apache/poi/hssf/usermodel/TestPatriarch.java index d7ce833063..6ca0acda0f 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestPatriarch.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestPatriarch.java @@ -17,17 +17,18 @@ package org.apache.poi.hssf.usermodel; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; + import org.apache.poi.ddf.EscherDgRecord; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.record.EscherAggregate; +import org.junit.Test; -/** - * @author Evgeniy Berlog - * @date 01.08.12 - */ -public class TestPatriarch extends TestCase { - +public class TestPatriarch { + @Test public void testGetPatriarch(){ HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.createSheet(); @@ -43,15 +44,17 @@ public class TestPatriarch extends TestCase { EscherAggregate agg = patriarch.getBoundAggregate(); EscherDgRecord dg = agg.getEscherContainer().getChildById(EscherDgRecord.RECORD_ID); + assertNotNull(dg); int lastId = dg.getLastMSOSPID(); - + assertSame(patriarch, sh.createDrawingPatriarch()); - + wb = HSSFTestDataSamples.writeOutAndReadBack(wb); sh = wb.getSheetAt(0); patriarch = sh.createDrawingPatriarch(); dg = patriarch.getBoundAggregate().getEscherContainer().getChildById(EscherDgRecord.RECORD_ID); + assertNotNull(dg); assertEquals(lastId, dg.getLastMSOSPID()); } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java b/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java index 7e674281fa..1977ef0caa 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java @@ -14,22 +14,23 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.hssf.usermodel; -import org.apache.poi.hssf.HSSFTestDataSamples; +import static org.apache.poi.hssf.HSSFTestDataSamples.writeOutAndReadBack; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; + import org.apache.poi.ss.usermodel.BorderStyle; import org.apache.poi.ss.usermodel.FillPatternType; -import org.apache.poi.util.IOUtils; - -import junit.framework.TestCase; +import org.junit.Test; /** * Class to test row styling functionality - * - * @author Amol S. Deshmukh < amolweb at ya hoo dot com > */ -public final class TestRowStyle extends TestCase { +public final class TestRowStyle { /** * TEST NAME: Test Write Sheet Font

    @@ -39,62 +40,60 @@ public final class TestRowStyle extends TestCase { * FAILURE: HSSF does not create a sheet or excepts. Filesize does not match the known good. * HSSFSheet last row or first row is incorrect.

    */ - public void testWriteSheetFont() { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet s = wb.createSheet(); - HSSFRow r = null; - HSSFFont fnt = wb.createFont(); - HSSFCellStyle cs = wb.createCellStyle(); + @Test + public void testWriteSheetFont() throws IOException { + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet s = wb.createSheet(); + HSSFFont fnt = wb.createFont(); + HSSFCellStyle cs = wb.createCellStyle(); - fnt.setColor(HSSFFont.COLOR_RED); - fnt.setBold(true); - cs.setFont(fnt); - for (int rownum = 0; rownum < 100; rownum++) - { - r = s.createRow(rownum); - r.setRowStyle(cs); - r.createCell(0); + fnt.setColor(HSSFFont.COLOR_RED); + fnt.setBold(true); + cs.setFont(fnt); + for (int rownum = 0; rownum < 100; rownum++) { + HSSFRow r = s.createRow(rownum); + r.setRowStyle(cs); + r.createCell(0); + } + try (HSSFWorkbook wb2 = writeOutAndReadBack(wb)) { + SanityChecker sanityChecker = new SanityChecker(); + sanityChecker.checkHSSFWorkbook(wb2); + assertEquals("LAST ROW == 99", 99, s.getLastRowNum()); + assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum()); + } } - HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb); - IOUtils.closeQuietly(wb); - - SanityChecker sanityChecker = new SanityChecker(); - sanityChecker.checkHSSFWorkbook(wb2); - assertEquals("LAST ROW == 99", 99, s.getLastRowNum()); - assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum()); - IOUtils.closeQuietly(wb2); } /** * Tests that is creating a file with a date or an calendar works correctly. */ - public void testDataStyle() { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet s = wb.createSheet(); - HSSFCellStyle cs = wb.createCellStyle(); - HSSFRow row = s.createRow(0); + @Test + public void testDataStyle() throws IOException { + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet s = wb.createSheet(); + HSSFCellStyle cs = wb.createCellStyle(); + HSSFRow row = s.createRow(0); - // with Date: - cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); - row.setRowStyle(cs); - row.createCell(0); + // with Date: + cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); + row.setRowStyle(cs); + row.createCell(0); - // with Calendar: - row = s.createRow(1); - cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); - row.setRowStyle(cs); - row.createCell(0); + // with Calendar: + row = s.createRow(1); + cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); + row.setRowStyle(cs); + row.createCell(0); - HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb); - IOUtils.closeQuietly(wb); - - SanityChecker sanityChecker = new SanityChecker(); - sanityChecker.checkHSSFWorkbook(wb2); + try (HSSFWorkbook wb2 = writeOutAndReadBack(wb)) { + SanityChecker sanityChecker = new SanityChecker(); + sanityChecker.checkHSSFWorkbook(wb2); - assertEquals("LAST ROW ", 1, s.getLastRowNum()); - assertEquals("FIRST ROW ", 0, s.getFirstRowNum()); - IOUtils.closeQuietly(wb2); + assertEquals("LAST ROW ", 1, s.getLastRowNum()); + assertEquals("FIRST ROW ", 0, s.getFirstRowNum()); + } + } } /** @@ -106,71 +105,71 @@ public final class TestRowStyle extends TestCase { * FAILURE: HSSF does not create a sheet or excepts. Filesize does not match the known good. * HSSFSheet last row or first row is incorrect.

    */ - public void testWriteSheetStyle() { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet s = wb.createSheet(); - HSSFRow r = null; - HSSFFont fnt = wb.createFont(); - HSSFCellStyle cs = wb.createCellStyle(); - HSSFCellStyle cs2 = wb.createCellStyle(); + @Test + public void testWriteSheetStyle() throws IOException { + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet s = wb.createSheet(); + HSSFRow r = null; + HSSFFont fnt = wb.createFont(); + HSSFCellStyle cs = wb.createCellStyle(); + HSSFCellStyle cs2 = wb.createCellStyle(); - cs.setBorderBottom(BorderStyle.THIN); - cs.setBorderLeft(BorderStyle.THIN); - cs.setBorderRight(BorderStyle.THIN); - cs.setBorderTop(BorderStyle.THIN); - cs.setFillForegroundColor(( short ) 0xA); - cs.setFillPattern(FillPatternType.BRICKS); - fnt.setColor(( short ) 0xf); - fnt.setItalic(true); - cs2.setFillForegroundColor(( short ) 0x0); - cs2.setFillPattern(FillPatternType.BRICKS); - cs2.setFont(fnt); - for (int rownum = 0; rownum < 100; rownum++) - { - r = s.createRow(rownum); - r.setRowStyle(cs); - r.createCell(0); + cs.setBorderBottom(BorderStyle.THIN); + cs.setBorderLeft(BorderStyle.THIN); + cs.setBorderRight(BorderStyle.THIN); + cs.setBorderTop(BorderStyle.THIN); + cs.setFillForegroundColor((short) 0xA); + cs.setFillPattern(FillPatternType.BRICKS); + fnt.setColor((short) 0xf); + fnt.setItalic(true); + cs2.setFillForegroundColor((short) 0x0); + cs2.setFillPattern(FillPatternType.BRICKS); + cs2.setFont(fnt); + for (int rownum = 0; rownum < 100; rownum++) { + r = s.createRow(rownum); + r.setRowStyle(cs); + r.createCell(0); - rownum++; - if (rownum >= 100) break; // I feel too lazy to check if this isreqd :-/ - - r = s.createRow(rownum); - r.setRowStyle(cs2); - r.createCell(0); + rownum++; + if (rownum >= 100) break; // I feel too lazy to check if this isreqd :-/ + + r = s.createRow(rownum); + r.setRowStyle(cs2); + r.createCell(0); + } + try (HSSFWorkbook wb2 = writeOutAndReadBack(wb)) { + SanityChecker sanityChecker = new SanityChecker(); + sanityChecker.checkHSSFWorkbook(wb2); + assertEquals("LAST ROW == 99", 99, s.getLastRowNum()); + assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum()); + + s = wb2.getSheetAt(0); + assertNotNull("Sheet is not null", s); + + for (int rownum = 0; rownum < 100; rownum++) { + r = s.getRow(rownum); + assertNotNull("Row is not null", r); + + cs = r.getRowStyle(); + assertNotNull(cs); + assertEquals("Bottom Border Style for row:", BorderStyle.THIN, cs.getBorderBottom()); + assertEquals("Left Border Style for row:", BorderStyle.THIN, cs.getBorderLeft()); + assertEquals("Right Border Style for row:", BorderStyle.THIN, cs.getBorderRight()); + assertEquals("Top Border Style for row:", BorderStyle.THIN, cs.getBorderTop()); + assertEquals("FillForegroundColor for row:", 0xA, cs.getFillForegroundColor()); + assertEquals("FillPattern for row:", FillPatternType.BRICKS, cs.getFillPattern()); + + rownum++; + if (rownum >= 100) break; // I feel too lazy to check if this isreqd :-/ + + r = s.getRow(rownum); + assertNotNull("Row is not null", r); + cs2 = r.getRowStyle(); + assertNotNull(cs2); + assertEquals("FillForegroundColor for row: ", cs2.getFillForegroundColor(), (short) 0x0); + assertEquals("FillPattern for row: ", cs2.getFillPattern(), FillPatternType.BRICKS); + } + } } - HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb); - IOUtils.closeQuietly(wb); - - SanityChecker sanityChecker = new SanityChecker(); - sanityChecker.checkHSSFWorkbook(wb2); - assertEquals("LAST ROW == 99", 99, s.getLastRowNum()); - assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum()); - - s = wb2.getSheetAt(0); - assertNotNull("Sheet is not null", s); - - for (int rownum = 0; rownum < 100; rownum++) - { - r = s.getRow(rownum); - assertNotNull("Row is not null", r); - - cs = r.getRowStyle(); - assertEquals("Bottom Border Style for row:", BorderStyle.THIN, cs.getBorderBottom()); - assertEquals("Left Border Style for row:", BorderStyle.THIN, cs.getBorderLeft()); - assertEquals("Right Border Style for row:", BorderStyle.THIN, cs.getBorderRight()); - assertEquals("Top Border Style for row:", BorderStyle.THIN, cs.getBorderTop()); - assertEquals("FillForegroundColor for row:", 0xA, cs.getFillForegroundColor()); - assertEquals("FillPattern for row:", FillPatternType.BRICKS, cs.getFillPattern()); - - rownum++; - if (rownum >= 100) break; // I feel too lazy to check if this isreqd :-/ - - r = s.getRow(rownum); - assertNotNull("Row is not null", r); - cs2 = r.getRowStyle(); - assertEquals("FillForegroundColor for row: ", cs2.getFillForegroundColor(), (short) 0x0); - assertEquals("FillPattern for row: ", cs2.getFillPattern(), FillPatternType.BRICKS); - } - IOUtils.closeQuietly(wb2); } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestUnicodeWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestUnicodeWorkbook.java index b0efff9c6d..6535246725 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestUnicodeWorkbook.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestUnicodeWorkbook.java @@ -17,36 +17,44 @@ package org.apache.poi.hssf.usermodel; -import junit.framework.TestCase; -import org.apache.poi.hssf.HSSFTestDataSamples; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; -public final class TestUnicodeWorkbook extends TestCase { +import java.io.IOException; + +import org.apache.poi.hssf.HSSFTestDataSamples; +import org.junit.Test; + +public final class TestUnicodeWorkbook { /** * Tests Bug38230 * That a Umlat is written and then read back. * It should have been written as a compressed unicode. */ - public void testUmlatReadWrite() { - HSSFWorkbook wb = new HSSFWorkbook(); + @Test + public void testUmlatReadWrite() throws IOException { + try (HSSFWorkbook wb1 = new HSSFWorkbook()) { - //Create a unicode sheet name (euro symbol) - HSSFSheet s = wb.createSheet("test"); + //Create a unicode sheet name (euro symbol) + HSSFSheet s = wb1.createSheet("test"); - HSSFRow r = s.createRow(0); - HSSFCell c = r.createCell(1); - c.setCellValue(new HSSFRichTextString("\u00e4")); + HSSFRow r = s.createRow(0); + HSSFCell c = r.createCell(1); + c.setCellValue(new HSSFRichTextString("\u00e4")); - //Confirm that the sring will be compressed - assertEquals(c.getRichStringCellValue().getUnicodeString().getOptionFlags(), 0); + //Confirm that the sring will be compressed + assertEquals(c.getRichStringCellValue().getUnicodeString().getOptionFlags(), 0); - wb = HSSFTestDataSamples.writeOutAndReadBack(wb); + try (HSSFWorkbook wb = HSSFTestDataSamples.writeOutAndReadBack(wb1)) { - //Test the sheetname - s = wb.getSheet("test"); - assertNotNull(s); + //Test the sheetname + s = wb.getSheet("test"); + assertNotNull(s); - c = r.getCell(1); - assertEquals(c.getRichStringCellValue().getString(), "\u00e4"); + c = r.getCell(1); + assertEquals(c.getRichStringCellValue().getString(), "\u00e4"); + } + } } } diff --git a/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java b/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java index 4594cf5655..6c2c8829c6 100644 --- a/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java +++ b/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java @@ -17,19 +17,19 @@ package org.apache.poi.hssf.util; -import java.io.InputStream; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; -import junit.framework.TestCase; +import java.io.InputStream; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.model.HSSFFormulaParser; import org.apache.poi.hssf.model.InternalWorkbook; import org.apache.poi.hssf.record.NameRecord; -import org.apache.poi.ss.SpreadsheetVersion; -import org.apache.poi.ss.formula.ptg.Area3DPtg; -import org.apache.poi.ss.formula.ptg.MemFuncPtg; -import org.apache.poi.ss.formula.ptg.Ptg; -import org.apache.poi.ss.formula.ptg.UnionPtg; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook; import org.apache.poi.hssf.usermodel.HSSFName; @@ -37,11 +37,18 @@ import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.TestHSSFWorkbook; +import org.apache.poi.ss.SpreadsheetVersion; +import org.apache.poi.ss.formula.ptg.Area3DPtg; +import org.apache.poi.ss.formula.ptg.MemFuncPtg; +import org.apache.poi.ss.formula.ptg.Ptg; +import org.apache.poi.ss.formula.ptg.UnionPtg; import org.apache.poi.ss.util.AreaReference; import org.apache.poi.ss.util.CellReference; +import org.junit.Test; -public final class TestAreaReference extends TestCase { +public final class TestAreaReference { + @Test public void testAreaRef1() { AreaReference ar = new AreaReference("$A$1:$B$2", SpreadsheetVersion.EXCEL97); assertFalse("Two cells expected", ar.isSingleCell()); @@ -83,6 +90,7 @@ public final class TestAreaReference extends TestCase { * References failed when sheet names were being used * Reported by Arne.Clauss@gedas.de */ + @Test public void testReferenceWithSheet() { AreaReference ar; @@ -107,6 +115,7 @@ public final class TestAreaReference extends TestCase { TestCellReference.confirmCell(allCells[2], "Tabelle1", 6, 1, true, true, "Tabelle1!$B$7"); } + @Test public void testContiguousReferences() { String refSimple = "$C$10:$C$10"; String ref2D = "$C$10:$D$11"; @@ -186,69 +195,72 @@ public final class TestAreaReference extends TestCase { assertEquals("Tabelle1", refs[1].getLastCell().getSheetName()); } + @Test public void testDiscontinousReference() throws Exception { - InputStream is = HSSFTestDataSamples.openSampleFileStream("44167.xls"); - HSSFWorkbook wb = new HSSFWorkbook(is); - InternalWorkbook workbook = TestHSSFWorkbook.getInternalWorkbook(wb); - HSSFEvaluationWorkbook eb = HSSFEvaluationWorkbook.create(wb); + try (InputStream is = HSSFTestDataSamples.openSampleFileStream("44167.xls"); + HSSFWorkbook wb = new HSSFWorkbook(is)) { + InternalWorkbook workbook = TestHSSFWorkbook.getInternalWorkbook(wb); + HSSFEvaluationWorkbook eb = HSSFEvaluationWorkbook.create(wb); - assertEquals(1, wb.getNumberOfNames()); - String sheetName = "Tabelle1"; - String rawRefA = "$C$10:$C$14"; - String rawRefB = "$C$16:$C$18"; - String refA = sheetName + "!" + rawRefA; - String refB = sheetName + "!" + rawRefB; - String ref = refA + "," + refB; + assertEquals(1, wb.getNumberOfNames()); + String sheetName = "Tabelle1"; + String rawRefA = "$C$10:$C$14"; + String rawRefB = "$C$16:$C$18"; + String refA = sheetName + "!" + rawRefA; + String refB = sheetName + "!" + rawRefB; + String ref = refA + "," + refB; - // Check the low level record - NameRecord nr = workbook.getNameRecord(0); - assertNotNull(nr); - assertEquals("test", nr.getNameText()); + // Check the low level record + NameRecord nr = workbook.getNameRecord(0); + assertNotNull(nr); + assertEquals("test", nr.getNameText()); - Ptg[] def =nr.getNameDefinition(); - assertEquals(4, def.length); + Ptg[] def = nr.getNameDefinition(); + assertEquals(4, def.length); - MemFuncPtg ptgA = (MemFuncPtg)def[0]; - Area3DPtg ptgB = (Area3DPtg)def[1]; - Area3DPtg ptgC = (Area3DPtg)def[2]; - UnionPtg ptgD = (UnionPtg)def[3]; - assertEquals("", ptgA.toFormulaString()); - assertEquals(refA, ptgB.toFormulaString(eb)); - assertEquals(refB, ptgC.toFormulaString(eb)); - assertEquals(",", ptgD.toFormulaString()); + MemFuncPtg ptgA = (MemFuncPtg) def[0]; + Area3DPtg ptgB = (Area3DPtg) def[1]; + Area3DPtg ptgC = (Area3DPtg) def[2]; + UnionPtg ptgD = (UnionPtg) def[3]; + assertEquals("", ptgA.toFormulaString()); + assertEquals(refA, ptgB.toFormulaString(eb)); + assertEquals(refB, ptgC.toFormulaString(eb)); + assertEquals(",", ptgD.toFormulaString()); - assertEquals(ref, HSSFFormulaParser.toFormulaString(wb, nr.getNameDefinition())); + assertEquals(ref, HSSFFormulaParser.toFormulaString(wb, nr.getNameDefinition())); - // Check the high level definition - int idx = wb.getNameIndex("test"); - assertEquals(0, idx); - HSSFName aNamedCell = wb.getNameAt(idx); + // Check the high level definition + int idx = wb.getNameIndex("test"); + assertEquals(0, idx); + HSSFName aNamedCell = wb.getNameAt(idx); - // Should have 2 references - String formulaRefs = aNamedCell.getRefersToFormula(); - assertNotNull(formulaRefs); - assertEquals(ref, formulaRefs); + // Should have 2 references + String formulaRefs = aNamedCell.getRefersToFormula(); + assertNotNull(formulaRefs); + assertEquals(ref, formulaRefs); - // Check the parsing of the reference into cells - assertFalse(AreaReference.isContiguous(formulaRefs)); - AreaReference[] arefs = AreaReference.generateContiguous(SpreadsheetVersion.EXCEL97, formulaRefs); - assertEquals(2, arefs.length); - assertEquals(refA, arefs[0].formatAsString()); - assertEquals(refB, arefs[1].formatAsString()); + // Check the parsing of the reference into cells + assertFalse(AreaReference.isContiguous(formulaRefs)); + AreaReference[] arefs = AreaReference.generateContiguous(SpreadsheetVersion.EXCEL97, formulaRefs); + assertEquals(2, arefs.length); + assertEquals(refA, arefs[0].formatAsString()); + assertEquals(refB, arefs[1].formatAsString()); - for (AreaReference ar : arefs) { - confirmResolveCellRef(wb, ar.getFirstCell()); - confirmResolveCellRef(wb, ar.getLastCell()); + for (AreaReference ar : arefs) { + confirmResolveCellRef(wb, ar.getFirstCell()); + confirmResolveCellRef(wb, ar.getLastCell()); + } } } private static void confirmResolveCellRef(HSSFWorkbook wb, CellReference cref) { HSSFSheet s = wb.getSheet(cref.getSheetName()); HSSFRow r = s.getRow(cref.getRow()); - HSSFCell c = r.getCell((int)cref.getCol()); + HSSFCell c = r.getCell(cref.getCol()); assertNotNull(c); } + @Test public void testSpecialSheetNames() { AreaReference ar; ar = new AreaReference("'Sheet A'!A1:A1", SpreadsheetVersion.EXCEL97); @@ -270,20 +282,20 @@ public final class TestAreaReference extends TestCase { assertEquals(expectedFullText, ar.formatAsString()); } + @Test public void testWholeColumnRefs() { confirmWholeColumnRef("A:A", 0, 0, false, false); confirmWholeColumnRef("$C:D", 2, 3, true, false); confirmWholeColumnRef("AD:$AE", 29, 30, false, true); } - + private static void confirmWholeColumnRef(String ref, int firstCol, int lastCol, boolean firstIsAbs, boolean lastIsAbs) { AreaReference ar = new AreaReference(ref, SpreadsheetVersion.EXCEL97); confirmCell(ar.getFirstCell(), 0, firstCol, true, firstIsAbs); confirmCell(ar.getLastCell(), 0xFFFF, lastCol, true, lastIsAbs); } - private static void confirmCell(CellReference cell, int row, int col, boolean isRowAbs, - boolean isColAbs) { + private static void confirmCell(CellReference cell, int row, int col, boolean isRowAbs, boolean isColAbs) { assertEquals(row, cell.getRow()); assertEquals(col, cell.getCol()); assertEquals(isRowAbs, cell.isRowAbsolute()); diff --git a/src/testcases/org/apache/poi/hssf/util/TestRKUtil.java b/src/testcases/org/apache/poi/hssf/util/TestRKUtil.java index 5b845775fe..09fcaa40cf 100644 --- a/src/testcases/org/apache/poi/hssf/util/TestRKUtil.java +++ b/src/testcases/org/apache/poi/hssf/util/TestRKUtil.java @@ -17,24 +17,26 @@ package org.apache.poi.hssf.util; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; /** * Tests the {@link RKUtil} class. */ -public final class TestRKUtil extends TestCase { +public final class TestRKUtil { /** * Check we can decode correctly. */ + @Test public void testDecode() { - int[] values = { 1074266112, 1081384961, 1081397249, + int[] values = { 1074266112, 1081384961, 1081397249, 0x3FF00000, 0x405EC001, 0x02F1853A, 0x02F1853B, 0xFCDD699A, }; double[] rvalues = { 3.0, 3.3, 3.33, - 1, 1.23, 12345678, 123456.78, -13149594, + 1, 1.23, 12345678, 123456.78, -13149594, }; for (int j = 0; j < values.length; j++) { @@ -42,10 +44,7 @@ public final class TestRKUtil extends TestCase { int intBits = values[j]; double expectedValue = rvalues[j]; double actualValue = RKUtil.decodeNumber(intBits); - if (expectedValue != actualValue) { - throw new AssertionFailedError("0x" + Integer.toHexString(intBits) - + " should decode to " + expectedValue + " but got " + actualValue); - } + assertEquals(expectedValue, actualValue, 0); } } } diff --git a/src/testcases/org/apache/poi/poifs/crypt/TestBiff8DecryptingStream.java b/src/testcases/org/apache/poi/poifs/crypt/TestBiff8DecryptingStream.java index d8a78582f5..ca109ec0ca 100644 --- a/src/testcases/org/apache/poi/poifs/crypt/TestBiff8DecryptingStream.java +++ b/src/testcases/org/apache/poi/poifs/crypt/TestBiff8DecryptingStream.java @@ -17,11 +17,11 @@ package org.apache.poi.poifs.crypt; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import java.io.InputStream; -import java.util.Arrays; import javax.crypto.spec.SecretKeySpec; @@ -30,9 +30,6 @@ import org.apache.poi.util.HexDump; import org.apache.poi.util.HexRead; import org.junit.Test; -import junit.framework.AssertionFailedError; -import junit.framework.ComparisonFailure; - /** * Tests for {@link Biff8DecryptingStream} */ @@ -58,25 +55,19 @@ public final class TestBiff8DecryptingStream { } private static final class StreamTester { - private static final boolean ONLY_LOG_ERRORS = true; - - private final MockStream _ms; private final Biff8DecryptingStream _bds; - private boolean _errorsOccurred; /** * @param expectedFirstInt expected value of the first int read from the decrypted stream */ public StreamTester(MockStream ms, String keyDigestHex, int expectedFirstInt) { - _ms = ms; byte[] keyDigest = HexRead.readFromString(keyDigestHex); EncryptionInfo ei = new EncryptionInfo(EncryptionMode.binaryRC4); Decryptor dec = ei.getDecryptor(); dec.setSecretKey(new SecretKeySpec(keyDigest, "RC4")); - - _bds = new Biff8DecryptingStream(_ms, 0, ei); + + _bds = new Biff8DecryptingStream(ms, 0, ei); assertEquals(expectedFirstInt, _bds.readInt()); - _errorsOccurred = false; } public Biff8DecryptingStream getBDS() { @@ -106,7 +97,7 @@ public final class TestBiff8DecryptingStream { public void confirmUShort(int expVal) { assertEquals(HexDump.shortToHex(expVal), HexDump.shortToHex(_bds.readUShort())); } - + public short readShort() { return _bds.readShort(); } @@ -122,32 +113,13 @@ public final class TestBiff8DecryptingStream { public void confirmLong(long expVal) { assertEquals(HexDump.longToHex(expVal), HexDump.longToHex(_bds.readLong())); } - + public void confirmData(String expHexData) { byte[] expData = HexRead.readFromString(expHexData); byte[] actData = new byte[expData.length]; _bds.readFully(actData); - if (Arrays.equals(expData, actData)) { - return; - } - _errorsOccurred = true; - if (ONLY_LOG_ERRORS) { - logErr(2, "Data mismatch " + HexDump.toHex(expData) + " - " - + HexDump.toHex(actData)); - return; - } - throw new ComparisonFailure("Data mismatch", HexDump.toHex(expData), HexDump.toHex(actData)); - } - - private static void logErr(int stackFrameCount, String msg) { - StackTraceElement ste = new Exception().getStackTrace()[stackFrameCount]; - System.err.print("(" + ste.getFileName() + ":" + ste.getLineNumber() + ") "); - System.err.println(msg); - } - - public void assertNoErrors() { - assertFalse("Some values decrypted incorrectly", _errorsOccurred); + assertArrayEquals("Data mismatch", expData, actData); } } @@ -156,7 +128,7 @@ public final class TestBiff8DecryptingStream { */ @Test public void readsAlignedWithBoundary() { - StreamTester st = createStreamTester(0x50, "BA AD F0 0D 00", 0x96C66829); + StreamTester st = createStreamTester(); st.rollForward(0x0004, 0x03FF); st.confirmByte(0x3E); @@ -179,7 +151,6 @@ public final class TestBiff8DecryptingStream { assertEquals(0xFFFF, st.readUShort()); st.rollForward(0x37D9B, 0x4A6F2); assertEquals(-1, st.readShort()); - st.assertNoErrors(); } /** @@ -187,7 +158,7 @@ public final class TestBiff8DecryptingStream { */ @Test public void readsSpanningBoundary() { - StreamTester st = createStreamTester(0x50, "BA AD F0 0D 00", 0x96C66829); + StreamTester st = createStreamTester(); st.rollForward(0x0004, 0x03FC); st.confirmLong(0x885243283E2A5EEFL); @@ -195,7 +166,6 @@ public final class TestBiff8DecryptingStream { st.confirmInt(0xD83E76CC); st.rollForward(0x0802, 0x0BFF); st.confirmShort(0x9B25); - st.assertNoErrors(); } /** @@ -204,28 +174,22 @@ public final class TestBiff8DecryptingStream { */ @Test public void readHeaderUShort() { - StreamTester st = createStreamTester(0x50, "BA AD F0 0D 00", 0x96C66829); + StreamTester st = createStreamTester(); st.rollForward(0x0004, 0x03FF); Biff8DecryptingStream bds = st.getBDS(); int hval = bds.readDataSize(); // unencrypted int nextInt = bds.readInt(); - if (nextInt == 0x8F534029) { - throw new AssertionFailedError( - "Indentified bug in key alignment after call to readHeaderUShort()"); - } + assertNotEquals("Indentified bug in key alignment after call to readHeaderUShort()",0x8F534029, nextInt); assertEquals(0x16885243, nextInt); - if (hval == 0x283E) { - throw new AssertionFailedError("readHeaderUShort() incorrectly decrypted result"); - } + assertNotEquals("readHeaderUShort() incorrectly decrypted result", 0x283E, hval); assertEquals(0x504F, hval); // confirm next key change st.rollForward(0x0405, 0x07FC); st.confirmInt(0x76CC1223); st.confirmInt(0x4842D83E); - st.assertNoErrors(); } /** @@ -233,17 +197,16 @@ public final class TestBiff8DecryptingStream { */ @Test public void readByteArrays() { - StreamTester st = createStreamTester(0x50, "BA AD F0 0D 00", 0x96C66829); + StreamTester st = createStreamTester(); st.rollForward(0x0004, 0x2FFC); st.confirmData("66 A1 20 B1 04 A3 35 F5"); // 4 bytes on either side of boundary st.rollForward(0x3004, 0x33F8); st.confirmData("F8 97 59 36"); // last 4 bytes in block st.confirmData("01 C2 4E 55"); // first 4 bytes in next block - st.assertNoErrors(); } - private static StreamTester createStreamTester(int mockStreamStartVal, String keyDigestHex, int expectedFirstInt) { - return new StreamTester(new MockStream(mockStreamStartVal), keyDigestHex, expectedFirstInt); + private static StreamTester createStreamTester() { + return new StreamTester(new MockStream(0x50), "BA AD F0 0D 00", 0x96C66829); } } diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestDirectoryNode.java b/src/testcases/org/apache/poi/poifs/filesystem/TestDirectoryNode.java index 366bc4387e..b3363b9cae 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestDirectoryNode.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestDirectoryNode.java @@ -18,6 +18,12 @@ package org.apache.poi.poifs.filesystem; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.ByteArrayInputStream; import java.io.FileNotFoundException; import java.io.IOException; @@ -25,76 +31,71 @@ import java.util.Iterator; import org.apache.poi.poifs.property.DirectoryProperty; import org.apache.poi.poifs.property.DocumentProperty; - -import junit.framework.TestCase; +import org.junit.Test; /** * Class to test DirectoryNode functionality - * - * @author Marc Johnson */ -public final class TestDirectoryNode extends TestCase { +public final class TestDirectoryNode { /** * test trivial constructor (a DirectoryNode with no children) */ - public void testEmptyConstructor() { - POIFSFileSystem fs = new POIFSFileSystem(); - DirectoryProperty property1 = new DirectoryProperty("parent"); - DirectoryProperty property2 = new DirectoryProperty("child"); - DirectoryNode parent = new DirectoryNode(property1, fs, null); - DirectoryNode node = new DirectoryNode(property2, fs, - parent); + @Test + public void testEmptyConstructor() throws IOException { + try (POIFSFileSystem fs = new POIFSFileSystem()) { + DirectoryProperty property1 = new DirectoryProperty("parent"); + DirectoryProperty property2 = new DirectoryProperty("child"); + DirectoryNode parent = new DirectoryNode(property1, fs, null); + DirectoryNode node = new DirectoryNode(property2, fs, parent); - assertEquals(0, parent.getPath().length()); - assertEquals(1, node.getPath().length()); - assertEquals("child", node.getPath().getComponent(0)); + assertEquals(0, parent.getPath().length()); + assertEquals(1, node.getPath().length()); + assertEquals("child", node.getPath().getComponent(0)); - // verify that getEntries behaves correctly - int count = 0; - Iterator iter = node.getEntries(); + // verify that getEntries behaves correctly + int count = 0; + Iterator iter = node.getEntries(); - while (iter.hasNext()) - { - count++; - iter.next(); + while (iter.hasNext()) { + count++; + iter.next(); + } + assertEquals(0, count); + + // verify behavior of isEmpty + assertTrue(node.isEmpty()); + + // verify behavior of getEntryCount + assertEquals(0, node.getEntryCount()); + + // verify behavior of getEntry + try { + node.getEntry("foo"); + fail("should have caught FileNotFoundException"); + } catch (FileNotFoundException ignored) { + + // as expected + } + + // verify behavior of isDirectoryEntry + assertTrue(node.isDirectoryEntry()); + + // verify behavior of getName + assertEquals(property2.getName(), node.getName()); + + // verify behavior of isDocumentEntry + assertFalse(node.isDocumentEntry()); + + // verify behavior of getParent + assertEquals(parent, node.getParent()); } - assertEquals(0, count); - - // verify behavior of isEmpty - assertTrue(node.isEmpty()); - - // verify behavior of getEntryCount - assertEquals(0, node.getEntryCount()); - - // verify behavior of getEntry - try - { - node.getEntry("foo"); - fail("should have caught FileNotFoundException"); - } - catch (FileNotFoundException ignored) - { - - // as expected - } - - // verify behavior of isDirectoryEntry - assertTrue(node.isDirectoryEntry()); - - // verify behavior of getName - assertEquals(property2.getName(), node.getName()); - - // verify behavior of isDocumentEntry - assertFalse(node.isDocumentEntry()); - - // verify behavior of getParent - assertEquals(parent, node.getParent()); } /** * test non-trivial constructor (a DirectoryNode with children) */ + @Test public void testNonEmptyConstructor() throws IOException { DirectoryProperty property1 = new DirectoryProperty("parent"); DirectoryProperty property2 = new DirectoryProperty("child1"); @@ -102,119 +103,118 @@ public final class TestDirectoryNode extends TestCase { property1.addChild(property2); property1.addChild(new DocumentProperty("child2", 2000)); property2.addChild(new DocumentProperty("child3", 30000)); - DirectoryNode node = new DirectoryNode(property1, - new POIFSFileSystem(), null); - // verify that getEntries behaves correctly - int count = 0; - Iterator iter = node.getEntries(); + try (POIFSFileSystem fs = new POIFSFileSystem()) { + DirectoryNode node = new DirectoryNode(property1, fs, null); - while (iter.hasNext()) - { - count++; - iter.next(); + // verify that getEntries behaves correctly + int count = 0; + Iterator iter = node.getEntries(); + + while (iter.hasNext()) { + count++; + iter.next(); + } + assertEquals(2, count); + + // verify behavior of isEmpty + assertFalse(node.isEmpty()); + + // verify behavior of getEntryCount + assertEquals(2, node.getEntryCount()); + + // verify behavior of getEntry + DirectoryNode child1 = (DirectoryNode) node.getEntry("child1"); + + child1.getEntry("child3"); + node.getEntry("child2"); + try { + node.getEntry("child3"); + fail("should have caught FileNotFoundException"); + } catch (FileNotFoundException ignored) { + + // as expected + } + + // verify behavior of isDirectoryEntry + assertTrue(node.isDirectoryEntry()); + + // verify behavior of getName + assertEquals(property1.getName(), node.getName()); + + // verify behavior of isDocumentEntry + assertFalse(node.isDocumentEntry()); + + // verify behavior of getParent + assertNull(node.getParent()); } - assertEquals(2, count); - - // verify behavior of isEmpty - assertFalse(node.isEmpty()); - - // verify behavior of getEntryCount - assertEquals(2, node.getEntryCount()); - - // verify behavior of getEntry - DirectoryNode child1 = ( DirectoryNode ) node.getEntry("child1"); - - child1.getEntry("child3"); - node.getEntry("child2"); - try - { - node.getEntry("child3"); - fail("should have caught FileNotFoundException"); - } - catch (FileNotFoundException ignored) - { - - // as expected - } - - // verify behavior of isDirectoryEntry - assertTrue(node.isDirectoryEntry()); - - // verify behavior of getName - assertEquals(property1.getName(), node.getName()); - - // verify behavior of isDocumentEntry - assertFalse(node.isDocumentEntry()); - - // verify behavior of getParent - assertNull(node.getParent()); } /** * test deletion methods */ + @Test public void testDeletion() throws IOException { - POIFSFileSystem fs = new POIFSFileSystem(); - DirectoryEntry root = fs.getRoot(); + try (POIFSFileSystem fs = new POIFSFileSystem()) { + DirectoryEntry root = fs.getRoot(); - // verify cannot delete the root directory - assertFalse(root.delete()); - assertTrue(root.isEmpty()); + // verify cannot delete the root directory + assertFalse(root.delete()); + assertTrue(root.isEmpty()); - DirectoryEntry dir = fs.createDirectory("myDir"); + DirectoryEntry dir = fs.createDirectory("myDir"); - assertFalse(root.isEmpty()); - assertTrue(dir.isEmpty()); + assertFalse(root.isEmpty()); + assertTrue(dir.isEmpty()); - // verify can delete empty directory - assertFalse(root.delete()); - assertTrue(dir.delete()); + // verify can delete empty directory + assertFalse(root.delete()); + assertTrue(dir.delete()); - // Now look at a non-empty one - dir = fs.createDirectory("NextDir"); - DocumentEntry doc = - dir.createDocument("foo", - new ByteArrayInputStream(new byte[ 1 ])); + // Now look at a non-empty one + dir = fs.createDirectory("NextDir"); + DocumentEntry doc = + dir.createDocument("foo", + new ByteArrayInputStream(new byte[1])); - assertFalse(root.isEmpty()); - assertFalse(dir.isEmpty()); + assertFalse(root.isEmpty()); + assertFalse(dir.isEmpty()); - // verify cannot delete non-empty directory - assertFalse(dir.delete()); + // verify cannot delete non-empty directory + assertFalse(dir.delete()); - // but we can delete it if we remove the document - assertTrue(doc.delete()); - assertTrue(dir.isEmpty()); - assertTrue(dir.delete()); + // but we can delete it if we remove the document + assertTrue(doc.delete()); + assertTrue(dir.isEmpty()); + assertTrue(dir.delete()); - // It's really gone! - assertTrue(root.isEmpty()); + // It's really gone! + assertTrue(root.isEmpty()); - fs.close(); + } } /** * test change name methods */ + @Test public void testRename() throws IOException { - POIFSFileSystem fs = new POIFSFileSystem(); - DirectoryEntry root = fs.getRoot(); + try (POIFSFileSystem fs = new POIFSFileSystem()) { + DirectoryEntry root = fs.getRoot(); - // verify cannot rename the root directory - assertFalse(root.renameTo("foo")); - DirectoryEntry dir = fs.createDirectory("myDir"); + // verify cannot rename the root directory + assertFalse(root.renameTo("foo")); + DirectoryEntry dir = fs.createDirectory("myDir"); - assertTrue(dir.renameTo("foo")); - assertEquals("foo", dir.getName()); - DirectoryEntry dir2 = fs.createDirectory("myDir"); + assertTrue(dir.renameTo("foo")); + assertEquals("foo", dir.getName()); + DirectoryEntry dir2 = fs.createDirectory("myDir"); - assertFalse(dir2.renameTo("foo")); - assertEquals("myDir", dir2.getName()); - assertTrue(dir.renameTo("FirstDir")); - assertTrue(dir2.renameTo("foo")); - assertEquals("foo", dir2.getName()); - - fs.close(); + assertFalse(dir2.renameTo("foo")); + assertEquals("myDir", dir2.getName()); + assertTrue(dir.renameTo("FirstDir")); + assertTrue(dir2.renameTo("foo")); + assertEquals("foo", dir2.getName()); + } } } diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentDescriptor.java b/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentDescriptor.java index 8a6e7da480..0081a43181 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentDescriptor.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentDescriptor.java @@ -17,18 +17,20 @@ package org.apache.poi.poifs.filesystem; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import org.junit.Test; /** * Class to test DocumentDescriptor functionality - * - * @author Marc Johnson */ -public final class TestDocumentDescriptor extends TestCase { +public final class TestDocumentDescriptor { /** * test equality */ + @Test public void testEquality() { String[] names = { "c1", "c2", "c3", "c4", "c5" }; POIFSDocumentPath a1 = new POIFSDocumentPath(); @@ -39,131 +41,67 @@ public final class TestDocumentDescriptor extends TestCase { new String[ 0 ]); POIFSDocumentPath[] paths = { a1, a2, a3, a4, a5 }; - for (int j = 0; j < paths.length; j++) - { - for (int k = 0; k < paths.length; k++) - { - for (int m = 0; m < names.length; m++) - { - DocumentDescriptor d1 = new DocumentDescriptor(paths[ j ], - names[ m ]); + for (int j = 0; j < paths.length; j++) { + for (int k = 0; k < paths.length; k++) { + for (int m = 0; m < names.length; m++) { + DocumentDescriptor d1 = new DocumentDescriptor(paths[ j ], names[ m ]); - for (int n = 0; n < names.length; n++) - { - DocumentDescriptor d2 = - new DocumentDescriptor(paths[ k ], names[ n ]); + for (int n = 0; n < names.length; n++) { + DocumentDescriptor d2 = new DocumentDescriptor(paths[ k ], names[ n ]); - if (m == n) - { - assertEquals("" + j + "," + k + "," + m + "," - + n, d1, d2); - } - else - { - assertFalse(d1.equals(d2)); + if (m == n) { + assertEquals("" + j + "," + k + "," + m + "," + n, d1, d2); + } else { + assertNotEquals(d1, d2); } } } } } - a2 = new POIFSDocumentPath(a1, new String[] - { - "foo" - }); - a3 = new POIFSDocumentPath(a2, new String[] - { - "bar" - }); - a4 = new POIFSDocumentPath(a3, new String[] - { - "fubar" - }); - a5 = new POIFSDocumentPath(a4, new String[] - { - "foobar" - }); - POIFSDocumentPath[] builtUpPaths = - { - a1, a2, a3, a4, a5 - }; - POIFSDocumentPath[] fullPaths = - { - new POIFSDocumentPath(), new POIFSDocumentPath(new String[] - { - "foo" - }), new POIFSDocumentPath(new String[] - { - "foo", "bar" - }), new POIFSDocumentPath(new String[] - { - "foo", "bar", "fubar" - }), new POIFSDocumentPath(new String[] - { - "foo", "bar", "fubar", "foobar" - }) + a2 = new POIFSDocumentPath(a1, new String[]{"foo"}); + a3 = new POIFSDocumentPath(a2, new String[]{"bar"}); + a4 = new POIFSDocumentPath(a3, new String[]{"fubar"}); + a5 = new POIFSDocumentPath(a4, new String[]{"foobar"}); + POIFSDocumentPath[] builtUpPaths = {a1, a2, a3, a4, a5}; + POIFSDocumentPath[] fullPaths = { + new POIFSDocumentPath(), + new POIFSDocumentPath(new String[]{"foo"}), + new POIFSDocumentPath(new String[]{"foo", "bar"}), + new POIFSDocumentPath(new String[]{"foo", "bar", "fubar"}), + new POIFSDocumentPath(new String[]{"foo", "bar", "fubar", "foobar"}) }; - for (int k = 0; k < builtUpPaths.length; k++) - { - for (int j = 0; j < fullPaths.length; j++) - { - for (int m = 0; m < names.length; m++) - { - DocumentDescriptor d1 = - new DocumentDescriptor(fullPaths[ j ], names[ m ]); + for (int k = 0; k < builtUpPaths.length; k++) { + for (int j = 0; j < fullPaths.length; j++) { + for (int m = 0; m < names.length; m++) { + DocumentDescriptor d1 = new DocumentDescriptor(fullPaths[ j ], names[ m ]); - for (int n = 0; n < names.length; n++) - { - DocumentDescriptor d2 = - new DocumentDescriptor(builtUpPaths[ k ], - names[ n ]); + for (int n = 0; n < names.length; n++) { + DocumentDescriptor d2 = new DocumentDescriptor(builtUpPaths[ k ], names[ n ]); - if ((k == j) && (m == n)) - { - assertEquals("" + j + "," + k + "," + m + "," - + n, d1, d2); - } - else - { - assertFalse(d1.equals(d2)); + if ((k == j) && (m == n)) { + assertEquals("" + j + "," + k + "," + m + "," + n, d1, d2); + } else { + assertNotEquals(d1, d2); } } } } } - POIFSDocumentPath[] badPaths = - { - new POIFSDocumentPath(new String[] - { - "_foo" - }), new POIFSDocumentPath(new String[] - { - "foo", "_bar" - }), new POIFSDocumentPath(new String[] - { - "foo", "bar", "_fubar" - }), new POIFSDocumentPath(new String[] - { - "foo", "bar", "fubar", "_foobar" - }) + POIFSDocumentPath[] badPaths = { + new POIFSDocumentPath(new String[]{"_foo"}), + new POIFSDocumentPath(new String[]{"foo", "_bar"}), + new POIFSDocumentPath(new String[]{"foo", "bar", "_fubar"}), + new POIFSDocumentPath(new String[]{"foo", "bar", "fubar", "_foobar"}) }; - for (int k = 0; k < builtUpPaths.length; k++) - { - for (int j = 0; j < badPaths.length; j++) - { - for (int m = 0; m < names.length; m++) - { - DocumentDescriptor d1 = - new DocumentDescriptor(badPaths[ j ], names[ m ]); - - for (int n = 0; n < names.length; n++) - { - DocumentDescriptor d2 = - new DocumentDescriptor(builtUpPaths[ k ], - names[ n ]); - - assertFalse(d1.equals(d2)); + for (POIFSDocumentPath builtUpPath : builtUpPaths) { + for (POIFSDocumentPath badPath : badPaths) { + for (String s : names) { + DocumentDescriptor d1 = new DocumentDescriptor(badPath, s); + for (String name : names) { + DocumentDescriptor d2 = new DocumentDescriptor(builtUpPath, name); + assertNotEquals(d1, d2); } } } diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestNotOLE2Exception.java b/src/testcases/org/apache/poi/poifs/filesystem/TestNotOLE2Exception.java index cb61e98ed8..ef0798a4c7 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestNotOLE2Exception.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestNotOLE2Exception.java @@ -18,33 +18,32 @@ package org.apache.poi.poifs.filesystem; import static org.apache.poi.POITestCase.assertContains; +import static org.junit.Assert.fail; import java.io.IOException; import java.io.InputStream; -import junit.framework.TestCase; - import org.apache.poi.POIDataSamples; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.OldExcelFormatException; +import org.junit.Test; /** * Class to test that POIFS complains when given older non-OLE2 * formats. See also {@link TestOfficeXMLException} for OOXML - * checks + * checks */ -public class TestNotOLE2Exception extends TestCase { +public class TestNotOLE2Exception { private static InputStream openXLSSampleStream(String sampleFileName) { return HSSFTestDataSamples.openSampleFileStream(sampleFileName); } private static InputStream openDOCSampleStream(String sampleFileName) { return POIDataSamples.getDocumentInstance().openResourceAsStream(sampleFileName); } - - public void testRawXMLException() throws IOException { - InputStream in = openXLSSampleStream("SampleSS.xml"); - try { + @Test + public void testRawXMLException() throws IOException { + try (InputStream in = openXLSSampleStream("SampleSS.xml")) { new POIFSFileSystem(in).close(); fail("expected exception was not thrown"); } catch(NotOLE2FileException e) { @@ -53,11 +52,10 @@ public class TestNotOLE2Exception extends TestCase { assertContains(e.getMessage(), "Formats such as Office 2003 XML"); } } - - public void testMSWriteException() throws IOException { - InputStream in = openDOCSampleStream("MSWriteOld.wri"); - try { + @Test + public void testMSWriteException() throws IOException { + try (InputStream in = openDOCSampleStream("MSWriteOld.wri")) { new POIFSFileSystem(in).close(); fail("expected exception was not thrown"); } catch(NotOLE2FileException e) { @@ -66,11 +64,10 @@ public class TestNotOLE2Exception extends TestCase { assertContains(e.getMessage(), "doesn't currently support"); } } - - public void testBiff3Exception() throws IOException { - InputStream in = openXLSSampleStream("testEXCEL_3.xls"); - try { + @Test + public void testBiff3Exception() throws IOException { + try (InputStream in = openXLSSampleStream("testEXCEL_3.xls")) { new POIFSFileSystem(in).close(); fail("expected exception was not thrown"); } catch(OldExcelFormatException e) { @@ -80,10 +77,9 @@ public class TestNotOLE2Exception extends TestCase { } } + @Test public void testBiff4Exception() throws IOException { - InputStream in = openXLSSampleStream("testEXCEL_4.xls"); - - try { + try (InputStream in = openXLSSampleStream("testEXCEL_4.xls")) { new POIFSFileSystem(in).close(); fail("expected exception was not thrown"); } catch(OldExcelFormatException e) { diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestOfficeXMLException.java b/src/testcases/org/apache/poi/poifs/filesystem/TestOfficeXMLException.java index 4c1a741cfb..4e235b66c7 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestOfficeXMLException.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestOfficeXMLException.java @@ -17,7 +17,6 @@ package org.apache.poi.poifs.filesystem; -import static org.apache.poi.POITestCase.assertContains; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; @@ -26,11 +25,8 @@ import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.util.Arrays; import org.apache.poi.hssf.HSSFTestDataSamples; - -import junit.framework.TestCase; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java b/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java index cc91dd602a..3a20b607a3 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java @@ -17,19 +17,24 @@ package org.apache.poi.poifs.filesystem; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import org.junit.Test; /** * Class to test POIFSDocumentPath functionality - * - * @author Marc Johnson */ -public final class TestPOIFSDocumentPath extends TestCase { +public final class TestPOIFSDocumentPath { /** * Test default constructor */ + @Test public void testDefaultConstructor() { POIFSDocumentPath path = new POIFSDocumentPath(); @@ -39,36 +44,28 @@ public final class TestPOIFSDocumentPath extends TestCase { /** * Test full path constructor */ + @Test public void testFullPathConstructor() { - String[] components = - { - "foo", "bar", "foobar", "fubar" - }; + String[] components = {"foo", "bar", "foobar", "fubar"}; - for (int j = 0; j < components.length; j++) - { + for (int j = 0; j < components.length; j++) { String[] params = new String[ j ]; System.arraycopy(components, 0, params, 0, j); POIFSDocumentPath path = new POIFSDocumentPath(params); assertEquals(j, path.length()); - for (int k = 0; k < j; k++) - { + for (int k = 0; k < j; k++) { assertEquals(components[ k ], path.getComponent(k)); } - if (j == 0) - { + if (j == 0) { assertNull(path.getParent()); - } - else - { + } else { POIFSDocumentPath parent = path.getParent(); assertNotNull(parent); assertEquals(j - 1, parent.length()); - for (int k = 0; k < j - 1; k++) - { + for (int k = 0; k < j - 1; k++) { assertEquals(components[ k ], parent.getComponent(k)); } } @@ -76,227 +73,132 @@ public final class TestPOIFSDocumentPath extends TestCase { // test weird variants assertEquals(0, new POIFSDocumentPath(null).length()); - try - { - new POIFSDocumentPath(new String[] - { - "fu", "" - }); + try { + new POIFSDocumentPath(new String[]{"fu", ""}); fail("should have caught IllegalArgumentException"); - } - catch (IllegalArgumentException ignored) - { - } - try - { - new POIFSDocumentPath(new String[] - { - "fu", null - }); + } catch (IllegalArgumentException ignored) { } + try { + new POIFSDocumentPath(new String[]{"fu", null}); fail("should have caught IllegalArgumentException"); - } - catch (IllegalArgumentException ignored) - { - } + } catch (IllegalArgumentException ignored) { } } /** * Test relative path constructor */ + @Test public void testRelativePathConstructor() { - String[] initialComponents = - { - "a", "b", "c" - }; + String[] initialComponents = {"a", "b", "c"}; - for (int n = 0; n < initialComponents.length; n++) - { + for (int n = 0; n < initialComponents.length; n++) { String[] initialParams = new String[ n ]; System.arraycopy(initialComponents, 0, initialParams, 0, n); - POIFSDocumentPath base = - new POIFSDocumentPath(initialParams); - String[] components = - { - "foo", "bar", "foobar", "fubar" - }; + POIFSDocumentPath base = new POIFSDocumentPath(initialParams); + String[] components = {"foo", "bar", "foobar", "fubar"}; - for (int j = 0; j < components.length; j++) - { + for (int j = 0; j < components.length; j++) { String[] params = new String[ j ]; System.arraycopy(components, 0, params, 0, j); POIFSDocumentPath path = new POIFSDocumentPath(base, params); assertEquals(j + n, path.length()); - for (int k = 0; k < n; k++) - { - assertEquals(initialComponents[ k ], - path.getComponent(k)); + for (int k = 0; k < n; k++) { + assertEquals(initialComponents[ k ], path.getComponent(k)); } - for (int k = 0; k < j; k++) - { + for (int k = 0; k < j; k++) { assertEquals(components[ k ], path.getComponent(k + n)); } - if ((j + n) == 0) - { + if ((j + n) == 0) { assertNull(path.getParent()); - } - else - { + } else { POIFSDocumentPath parent = path.getParent(); assertNotNull(parent); assertEquals(j + n - 1, parent.length()); - for (int k = 0; k < (j + n - 1); k++) - { - assertEquals(path.getComponent(k), - parent.getComponent(k)); + for (int k = 0; k < (j + n - 1); k++) { + assertEquals(path.getComponent(k), parent.getComponent(k)); } } } // Test weird variants - + // This one is allowed, even if it's really odd assertEquals(n, new POIFSDocumentPath(base, null).length()); - new POIFSDocumentPath(base, new String[] - { - "fu", "" - }); - + new POIFSDocumentPath(base, new String[]{"fu", ""}); + // This one is allowed too - new POIFSDocumentPath(base, new String[] - { - "", "fu" - }); - + new POIFSDocumentPath(base, new String[]{"", "fu"}); + // This one shouldn't be allowed - try - { - new POIFSDocumentPath(base, new String[] - { - "fu", null - }); + try { + new POIFSDocumentPath(base, new String[]{"fu", null}); fail("should have caught IllegalArgumentException"); - } - catch (IllegalArgumentException ignored) - { - } - + } catch (IllegalArgumentException ignored) { } + // Ditto - try - { - new POIFSDocumentPath(base, new String[] - { - null, "fu" - }); + try { + new POIFSDocumentPath(base, new String[]{null, "fu"}); fail("should have caught IllegalArgumentException"); - } - catch (IllegalArgumentException ignored) - { - } + } catch (IllegalArgumentException ignored) { } } } /** * test equality */ + @Test public void testEquality() { 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 a5 = new POIFSDocumentPath(a1, new String[ 0 ]); - for (int j = 0; j < paths.length; j++) - { - for (int k = 0; k < paths.length; k++) - { - assertEquals(j + "<>" + k, - paths[ j ], paths[ k ]); + POIFSDocumentPath[] paths = {a1, a2, a3, a4, a5}; + + for (int j = 0; j < paths.length; j++) { + for (int k = 0; k < paths.length; k++) { + assertEquals(j + "<>" + k, paths[ j ], paths[ k ]); } } - a2 = new POIFSDocumentPath(a1, new String[] - { - "foo" - }); - a3 = new POIFSDocumentPath(a2, new String[] - { - "bar" - }); - a4 = new POIFSDocumentPath(a3, new String[] - { - "fubar" - }); - a5 = new POIFSDocumentPath(a4, new String[] - { - "foobar" - }); + a2 = new POIFSDocumentPath(a1, new String[]{"foo"}); + a3 = new POIFSDocumentPath(a2, new String[]{"bar"}); + a4 = new POIFSDocumentPath(a3, new String[]{"fubar"}); + a5 = new POIFSDocumentPath(a4, new String[]{"foobar"}); POIFSDocumentPath[] builtUpPaths = { a1, a2, a3, a4, a5 }; - POIFSDocumentPath[] fullPaths = - { - new POIFSDocumentPath(), new POIFSDocumentPath(new String[] - { - "foo" - }), new POIFSDocumentPath(new String[] - { - "foo", "bar" - }), new POIFSDocumentPath(new String[] - { - "foo", "bar", "fubar" - }), new POIFSDocumentPath(new String[] - { - "foo", "bar", "fubar", "foobar" - }) + POIFSDocumentPath[] fullPaths = { + new POIFSDocumentPath(), new POIFSDocumentPath(new String[]{"foo"}), + new POIFSDocumentPath(new String[]{"foo", "bar"}), + new POIFSDocumentPath(new String[]{"foo", "bar", "fubar"}), + new POIFSDocumentPath(new String[]{"foo", "bar", "fubar", "foobar"}) }; - for (int k = 0; k < builtUpPaths.length; k++) - { - for (int j = 0; j < fullPaths.length; j++) - { - if (k == j) - { - assertEquals(j + "<>" - + k, fullPaths[ j ], - builtUpPaths[ k ]); - } - else - { - assertFalse(fullPaths[j].equals(builtUpPaths[k])); + for (int k = 0; k < builtUpPaths.length; k++) { + for (int j = 0; j < fullPaths.length; j++) { + if (k == j) { + assertEquals(j + "<>" + k, fullPaths[ j ], builtUpPaths[ k ]); + } else { + assertNotEquals(fullPaths[j], builtUpPaths[k]); } } } - POIFSDocumentPath[] badPaths = - { - new POIFSDocumentPath(new String[] - { - "_foo" - }), new POIFSDocumentPath(new String[] - { - "foo", "_bar" - }), new POIFSDocumentPath(new String[] - { - "foo", "bar", "_fubar" - }), new POIFSDocumentPath(new String[] - { - "foo", "bar", "fubar", "_foobar" - }) + POIFSDocumentPath[] badPaths = { + new POIFSDocumentPath(new String[]{"_foo"}), + new POIFSDocumentPath(new String[]{"foo", "_bar"}), + new POIFSDocumentPath(new String[]{"foo", "bar", "_fubar"}), + new POIFSDocumentPath(new String[]{"foo", "bar", "fubar", "_foobar"}) }; for (int k = 0; k < builtUpPaths.length; k++) { - for (int j = 0; j < badPaths.length; j++) - { - assertFalse(fullPaths[k].equals(badPaths[j])); + for (POIFSDocumentPath badPath : badPaths) { + assertNotEquals(fullPaths[k], badPath); } } } diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSStream.java b/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSStream.java index 0f0eeba31f..7819b4d1c4 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSStream.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSStream.java @@ -37,7 +37,6 @@ import java.io.OutputStream; import java.nio.ByteBuffer; import java.util.Iterator; -import junit.framework.TestCase; import org.apache.poi.POIDataSamples; import org.apache.poi.hpsf.DocumentSummaryInformation; import org.apache.poi.hpsf.PropertySet; @@ -79,7 +78,7 @@ public final class TestPOIFSStream { assertFalse(i.hasNext()); assertFalse(i.hasNext()); assertFalse(i.hasNext()); - + // Check the contents assertEquals((byte)0x81, b.get()); assertEquals((byte)0x00, b.get()); @@ -89,17 +88,17 @@ public final class TestPOIFSStream { assertEquals((byte)0x00, b.get()); assertEquals((byte)0x00, b.get()); assertEquals((byte)0x00, b.get()); - + fs.close(); } /** - * Read a stream with only two blocks in it + * Read a stream with only two blocks in it */ @Test public void testReadShortStream() throws Exception { POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi")); - + // 97 -> 98 -> end POIFSStream stream = new POIFSStream(fs, 97); Iterator i = stream.getBlockIterator(); @@ -113,7 +112,7 @@ public final class TestPOIFSStream { assertFalse(i.hasNext()); assertFalse(i.hasNext()); assertFalse(i.hasNext()); - + // Check the contents of the 1st block assertEquals((byte)0x01, b97.get()); assertEquals((byte)0x00, b97.get()); @@ -123,7 +122,7 @@ public final class TestPOIFSStream { assertEquals((byte)0x00, b97.get()); assertEquals((byte)0x00, b97.get()); assertEquals((byte)0x00, b97.get()); - + // Check the contents of the 2nd block assertEquals((byte)0x81, b98.get()); assertEquals((byte)0x00, b98.get()); @@ -133,21 +132,21 @@ public final class TestPOIFSStream { assertEquals((byte)0x00, b98.get()); assertEquals((byte)0x00, b98.get()); assertEquals((byte)0x00, b98.get()); - + fs.close(); } - + /** - * Read a stream with many blocks + * Read a stream with many blocks */ @Test public void testReadLongerStream() throws Exception { POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi")); - + ByteBuffer b0 = null; ByteBuffer b1 = null; ByteBuffer b22 = null; - + // The stream at 0 has 23 blocks in it POIFSStream stream = new POIFSStream(fs, 0); Iterator i = stream.getBlockIterator(); @@ -163,24 +162,24 @@ public final class TestPOIFSStream { if(count == 22) { b22 = b; } - + count++; } assertEquals(23, count); - + // Check the contents // 1st block is at 0 assertEquals((byte)0x9e, b0.get()); assertEquals((byte)0x75, b0.get()); assertEquals((byte)0x97, b0.get()); assertEquals((byte)0xf6, b0.get()); - + // 2nd block is at 1 assertEquals((byte)0x86, b1.get()); assertEquals((byte)0x09, b1.get()); assertEquals((byte)0x22, b1.get()); assertEquals((byte)0xfb, b1.get()); - + // last block is at 89 assertEquals((byte)0xfe, b22.get()); assertEquals((byte)0xff, b22.get()); @@ -190,17 +189,17 @@ public final class TestPOIFSStream { assertEquals((byte)0x01, b22.get()); assertEquals((byte)0x02, b22.get()); assertEquals((byte)0x00, b22.get()); - + fs.close(); } /** - * Read a stream with several blocks in a 4096 byte block file + * Read a stream with several blocks in a 4096 byte block file */ @Test public void testReadStream4096() throws Exception { POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("BlockSize4096.zvi")); - + // 0 -> 1 -> 2 -> end POIFSStream stream = new POIFSStream(fs, 0); Iterator i = stream.getBlockIterator(); @@ -217,7 +216,7 @@ public final class TestPOIFSStream { assertFalse(i.hasNext()); assertFalse(i.hasNext()); assertFalse(i.hasNext()); - + // Check the contents of the 1st block assertEquals((byte)0x9E, b0.get()); assertEquals((byte)0x75, b0.get()); @@ -227,7 +226,7 @@ public final class TestPOIFSStream { assertEquals((byte)0x21, b0.get()); assertEquals((byte)0xD2, b0.get()); assertEquals((byte)0x11, b0.get()); - + // Check the contents of the 2nd block assertEquals((byte)0x00, b1.get()); assertEquals((byte)0x00, b1.get()); @@ -237,7 +236,7 @@ public final class TestPOIFSStream { assertEquals((byte)0x00, b1.get()); assertEquals((byte)0x00, b1.get()); assertEquals((byte)0x00, b1.get()); - + // Check the contents of the 3rd block assertEquals((byte)0x6D, b2.get()); assertEquals((byte)0x00, b2.get()); @@ -247,39 +246,39 @@ public final class TestPOIFSStream { assertEquals((byte)0x00, b2.get()); assertEquals((byte)0x46, b2.get()); assertEquals((byte)0x00, b2.get()); - + fs.close(); } - + /** * Craft a nasty file with a loop, and ensure we don't get stuck */ @Test public void testReadFailsOnLoop() throws Exception { POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi")); - + // Hack the FAT so that it goes 0->1->2->0 fs.setNextBlock(0, 1); fs.setNextBlock(1, 2); fs.setNextBlock(2, 0); - + // Now try to read POIFSStream stream = new POIFSStream(fs, 0); Iterator i = stream.getBlockIterator(); assertTrue(i.hasNext()); - + // 1st read works i.next(); assertTrue(i.hasNext()); - + // 2nd read works i.next(); assertTrue(i.hasNext()); - + // 3rd read works i.next(); assertTrue(i.hasNext()); - + // 4th read blows up as it loops back to 0 try { i.next(); @@ -288,7 +287,7 @@ public final class TestPOIFSStream { // Good, it was detected } assertTrue(i.hasNext()); - + fs.close(); } @@ -300,7 +299,7 @@ public final class TestPOIFSStream { public void testReadMiniStreams() throws Exception { POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi")); POIFSMiniStore ministore = fs.getMiniStore(); - + // 178 -> 179 -> 180 -> end POIFSStream stream = new POIFSStream(ministore, 178); Iterator i = stream.getBlockIterator(); @@ -316,7 +315,7 @@ public final class TestPOIFSStream { assertFalse(i.hasNext()); assertFalse(i.hasNext()); assertFalse(i.hasNext()); - + // Check the contents of the 1st block assertEquals((byte)0xfe, b178.get()); assertEquals((byte)0xff, b178.get()); @@ -326,7 +325,7 @@ public final class TestPOIFSStream { assertEquals((byte)0x01, b178.get()); assertEquals((byte)0x02, b178.get()); assertEquals((byte)0x00, b178.get()); - + // And the 2nd assertEquals((byte)0x6c, b179.get()); assertEquals((byte)0x00, b179.get()); @@ -336,7 +335,7 @@ public final class TestPOIFSStream { assertEquals((byte)0x00, b179.get()); assertEquals((byte)0x00, b179.get()); assertEquals((byte)0x00, b179.get()); - + // And the 3rd assertEquals((byte)0x30, b180.get()); assertEquals((byte)0x00, b180.get()); @@ -346,7 +345,7 @@ public final class TestPOIFSStream { assertEquals((byte)0x00, b180.get()); assertEquals((byte)0x00, b180.get()); assertEquals((byte)0x80, b180.get()); - + fs.close(); } @@ -356,22 +355,22 @@ public final class TestPOIFSStream { @Test public void testReplaceStream() throws Exception { POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi")); - + byte[] data = new byte[512]; for(int i=0; i it = stream.getBlockIterator(); assertTrue(it.hasNext()); ByteBuffer b = it.next(); assertFalse(it.hasNext()); - + // Now check the contents data = new byte[512]; b.get(data); @@ -379,10 +378,10 @@ public final class TestPOIFSStream { byte exp = (byte)(i%256); assertEquals(exp, data[i]); } - + fs.close(); } - + /** * Writes less data than before, some blocks will need * to be freed @@ -424,7 +423,7 @@ public final class TestPOIFSStream { } } } - + /** * Writes more data than before, new blocks will be needed */ @@ -471,14 +470,14 @@ public final class TestPOIFSStream { assertEquals(3, count); } } - + /** * Writes to a new stream in the file */ @Test public void testWriteNewStream() throws Exception { POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi")); - + // 100 is our first free one assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(99)); assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(100)); @@ -486,17 +485,17 @@ public final class TestPOIFSStream { assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(102)); assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(103)); assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(104)); - - + + // Add a single block one byte[] data = new byte[512]; for(int i=0; i it = stream.getBlockIterator(); int count = 0; @@ -519,17 +518,17 @@ public final class TestPOIFSStream { count++; } assertEquals(1, count); - - + + // And a multi block one data = new byte[512*3]; for(int i=0; i 1 -> 2 -> end assertEquals(1, fs.getNextBlock(0)); assertEquals(2, fs.getNextBlock(1)); assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2)); assertEquals(4, fs.getNextBlock(3)); - + // First free one is at 15 assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(14)); assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(15)); - - - // Write a 5 block file + + + // Write a 5 block file byte[] data = new byte[4096*5]; for(int i=0; iDirectoryProperty . @@ -40,10 +43,8 @@ import org.apache.poi.poifs.property.Property; * In particular it is important to serialize ROOT._VBA_PROJECT_CUR.VBA node. * See bug 39234 in bugzilla. Thanks to Bill Seddon for providing the solution. *

    - * - * @author Yegor Kozlov */ -public final class TestPropertySorter extends TestCase { +public final class TestPropertySorter { //the correct order of entries in the test file private static final String[] _entries = { @@ -64,6 +65,7 @@ public final class TestPropertySorter extends TestCase { /** * Test sorting of properties in DirectoryProperty */ + @Test public void testSortProperties() throws IOException { POIFSFileSystem fs = openSampleFS(); Property[] props = getVBAProperties(fs); @@ -71,27 +73,31 @@ public final class TestPropertySorter extends TestCase { assertEquals(_entries.length, props.length); // (1). See that there is a problem with the old case-sensitive property comparator - Arrays.sort(props, OldCaseSensitivePropertyComparator); - try { - for (int i = 0; i < props.length; i++) { - assertEquals(_entries[i], props[i].getName()); - } - fail("expected old case-sensitive property comparator to return properties in wrong order"); - } catch (ComparisonFailure e){ - // expected during successful test - assertNotNull(e.getMessage()); - } + Arrays.sort(props, TestPropertySorter::oldCaseSensitivePropertyCompareTo); + + String exp = String.join("", _entries); + String actOld = Stream.of(props).map(Property::getName).collect(Collectors.joining()); + + assertNotEquals("expected old case-sensitive property comparator to return properties in wrong order", exp, actOld); // (2) Verify that the fixed property comparator works right Arrays.sort(props, new DirectoryProperty.PropertyComparator()); - for (int i = 0; i < props.length; i++) { - assertEquals(_entries[i], props[i].getName()); - } + String[] actNew = Stream.of(props).map(Property::getName).toArray(String[]::new); + + assertArrayEquals(_entries, actNew); + } + + private static int oldCaseSensitivePropertyCompareTo(Property o1, Property o2) { + String name1 = o1.getName(); + String name2 = o2.getName(); + int result = name1.length() - name2.length(); + return (result != 0) ? result : name1.compareTo(name2); } /** * Serialize file system and verify that the order of properties is the same as in the original file. */ + @Test public void testSerialization() throws IOException { POIFSFileSystem fs = openSampleFS(); @@ -104,16 +110,14 @@ public final class TestPropertySorter extends TestCase { Property[] props = getVBAProperties(fs); Arrays.sort(props, new DirectoryProperty.PropertyComparator()); - assertEquals(_entries.length, props.length); - for (int i = 0; i < props.length; i++) { - assertEquals(_entries[i], props[i].getName()); - } + String[] act = Stream.of(props).map(Property::getName).toArray(String[]::new); + assertArrayEquals(_entries, act); } /** * @return array of properties read from ROOT._VBA_PROJECT_CUR.VBA node */ - protected Property[] getVBAProperties(POIFSFileSystem fs) throws IOException { + private Property[] getVBAProperties(POIFSFileSystem fs) throws IOException { String _VBA_PROJECT_CUR = "_VBA_PROJECT_CUR"; String VBA = "VBA"; @@ -130,22 +134,4 @@ public final class TestPropertySorter extends TestCase { } return lst.toArray(new Property[ 0 ]); } - - /** - * Old version of case-sensitive PropertyComparator to demonstrate the problem - */ - private static final Comparator OldCaseSensitivePropertyComparator = new Comparator() { - - @Override - public int compare(Property o1, Property o2) { - String name1 = o1.getName(); - String name2 = o2.getName(); - int result = name1.length() - name2.length(); - - if (result == 0) { - result = name1.compareTo(name2); - } - return result; - } - }; } diff --git a/src/testcases/org/apache/poi/poifs/nio/TestDataSource.java b/src/testcases/org/apache/poi/poifs/nio/TestDataSource.java index 4b3932bad1..bb549f7a14 100644 --- a/src/testcases/org/apache/poi/poifs/nio/TestDataSource.java +++ b/src/testcases/org/apache/poi/poifs/nio/TestDataSource.java @@ -15,104 +15,115 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.poifs.nio; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.BufferUnderflowException; +import java.nio.ByteBuffer; + import org.apache.poi.POIDataSamples; import org.apache.poi.util.IOUtils; import org.apache.poi.util.TempFile; - -import java.io.*; -import java.nio.BufferUnderflowException; -import java.nio.ByteBuffer; +import org.junit.Test; /** * Tests for the datasource implementations */ -public class TestDataSource extends TestCase -{ - private static POIDataSamples data = POIDataSamples.getPOIFSInstance(); - - public void testFile() throws Exception { - File f = data.getFile("Notes.ole2"); - - FileBackedDataSource ds = new FileBackedDataSource(f); - try { - checkDataSource(ds, false); - } finally { - ds.close(); - } - - // try a second time - ds = new FileBackedDataSource(f); - try { - checkDataSource(ds, false); - } finally { - ds.close(); - } - } +public class TestDataSource { + private static POIDataSamples data = POIDataSamples.getPOIFSInstance(); - public void testFileWritable() throws Exception { - File temp = TempFile.createTempFile("TestDataSource", ".test"); - try { - writeDataToFile(temp); - - FileBackedDataSource ds = new FileBackedDataSource(temp, false); - try { - checkDataSource(ds, true); - } finally { - ds.close(); - } - - // try a second time - ds = new FileBackedDataSource(temp, false); - try { - checkDataSource(ds, true); - } finally { - ds.close(); - } + @Test + public void testFile() throws Exception { + File f = data.getFile("Notes.ole2"); - writeDataToFile(temp); - } finally { - assertTrue(temp.exists()); - assertTrue("Could not delete file " + temp, temp.delete()); - } + FileBackedDataSource ds = new FileBackedDataSource(f); + try { + checkDataSource(ds, false); + } finally { + ds.close(); + } + + // try a second time + ds = new FileBackedDataSource(f); + try { + checkDataSource(ds, false); + } finally { + ds.close(); + } + } + + @Test + public void testFileWritable() throws Exception { + File temp = TempFile.createTempFile("TestDataSource", ".test"); + try { + writeDataToFile(temp); + + FileBackedDataSource ds = new FileBackedDataSource(temp, false); + try { + checkDataSource(ds, true); + } finally { + ds.close(); + } + + // try a second time + ds = new FileBackedDataSource(temp, false); + try { + checkDataSource(ds, true); + } finally { + ds.close(); + } + + writeDataToFile(temp); + } finally { + assertTrue(temp.exists()); + assertTrue("Could not delete file " + temp, temp.delete()); + } } - public void testRewritableFile() throws Exception { - File temp = TempFile.createTempFile("TestDataSource", ".test"); - try { - writeDataToFile(temp); - - FileBackedDataSource ds = new FileBackedDataSource(temp, true); - try { - ByteBuffer buf = ds.read(0, 10); - assertNotNull(buf); - buf = ds.read(8, 0x400); - assertNotNull(buf); - } finally { - ds.close(); - } - - // try a second time - ds = new FileBackedDataSource(temp, true); - try { - ByteBuffer buf = ds.read(0, 10); - assertNotNull(buf); - buf = ds.read(8, 0x400); - assertNotNull(buf); - } finally { - ds.close(); - } - - writeDataToFile(temp); - } finally { - assertTrue(temp.exists()); - assertTrue(temp.delete()); - } + @Test + public void testRewritableFile() throws Exception { + File temp = TempFile.createTempFile("TestDataSource", ".test"); + try { + writeDataToFile(temp); + + FileBackedDataSource ds = new FileBackedDataSource(temp, true); + try { + ByteBuffer buf = ds.read(0, 10); + assertNotNull(buf); + buf = ds.read(8, 0x400); + assertNotNull(buf); + } finally { + ds.close(); + } + + // try a second time + ds = new FileBackedDataSource(temp, true); + try { + ByteBuffer buf = ds.read(0, 10); + assertNotNull(buf); + buf = ds.read(8, 0x400); + assertNotNull(buf); + } finally { + ds.close(); + } + + writeDataToFile(temp); + } finally { + assertTrue(temp.exists()); + assertTrue(temp.delete()); + } } private void writeDataToFile(File temp) throws IOException { @@ -122,14 +133,14 @@ public class TestDataSource extends TestCase } } } - + private void checkDataSource(FileBackedDataSource ds, boolean writeable) throws IOException { assertEquals(writeable, ds.isWriteable()); assertNotNull(ds.getChannel()); - + // rewriting changes the size - if(writeable) { - assertTrue("Had: " + ds.size(), ds.size() == 8192 || ds.size() == 8198); + if (writeable) { + assertTrue("Had: " + ds.size(), ds.size() == 8192 || ds.size() == 8198); } else { assertEquals(8192, ds.size()); } @@ -168,7 +179,7 @@ public class TestDataSource extends TestCase // Can't go off the end try { ds.read(4, 8192); - if(!writeable) { + if (!writeable) { fail("Shouldn't be able to read off the end of the file"); } } catch (IndexOutOfBoundsException e) { @@ -176,93 +187,94 @@ public class TestDataSource extends TestCase } } - public void testByteArray() throws Exception { - byte[] data = new byte[256]; - byte b; - for(int i=0; i { @@ -307,8 +311,8 @@ public class TestEvaluationCache extends TestCase { return ms; } + @Test public void testMediumComplex() { - MySheet ms = createMediumComplex(); // completely fresh evaluation confirmEvaluate(ms, "A1", 46); @@ -385,8 +389,8 @@ public class TestEvaluationCache extends TestCase { }); } + @Test public void testMediumComplexWithDependencyChange() { - // Changing an intermediate formula MySheet ms = createMediumComplex(); confirmEvaluate(ms, "A1", 46); @@ -444,6 +448,7 @@ public class TestEvaluationCache extends TestCase { * verifies that when updating a plain cell, depending (formula) cell cached values are cleared * only when the plain cell's value actually changes */ + @Test public void testRedundantUpdate() { MySheet ms = new MySheet(); @@ -487,8 +492,8 @@ public class TestEvaluationCache extends TestCase { * and VLOOKUP the effect can be subtle. The presence of error values can also produce this * effect in almost every function and operator. */ + @Test public void testSimpleWithDependencyChange() { - MySheet ms = new MySheet(); ms.setCellFormula("A1", "INDEX(C1:E1,1,B1)"); @@ -537,9 +542,8 @@ public class TestEvaluationCache extends TestCase { }); } + @Test public void testBlankCells() { - - MySheet ms = new MySheet(); ms.setCellFormula("A1", "sum(B1:D4,B5:E6)"); @@ -588,6 +592,7 @@ public class TestEvaluationCache extends TestCase { * Make sure that when blank cells are changed to value/formula cells, any dependent formulas * have their cached results cleared. */ + @Test public void testBlankCellChangedToValueCell_bug46053() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Sheet1"); @@ -614,16 +619,16 @@ public class TestEvaluationCache extends TestCase { cellB1.setCellValue(0.4); // changing B1, so A1 cached result should be cleared fe.notifyUpdateCell(cellB1); cv = fe.evaluate(cellA1); - if (cv.getNumberValue() == 2.2) { - // looks like left-over cached result from before change to B1 - throw new AssertionFailedError("Identified bug 46053"); - } + + // looks like left-over cached result from before change to B1 + assertNotEquals("Identified bug 46053", 2.2, cv.getNumberValue()); assertEquals(2.6, cv.getNumberValue(), 0.0); } /** * same use-case as the test for bug 46053, but checking trace values too */ + @Test public void testBlankCellChangedToValueCell() { MySheet ms = new MySheet(); @@ -661,87 +666,10 @@ public class TestEvaluationCache extends TestCase { private static void confirmLog(MySheet ms, String[] expectedLog) { String[] actualLog = ms.getAndClearLog(); - int endIx = actualLog.length; - PrintStream ps = System.err; - if (endIx != expectedLog.length) { - ps.println("Log lengths mismatch"); - dumpCompare(ps, expectedLog, actualLog); - throw new AssertionFailedError("Log lengths mismatch"); - } - for (int i=0; i< endIx; i++) { - if (!actualLog[i].equals(expectedLog[i])) { - String msg = "Log entry mismatch at index " + i; - ps.println(msg); - dumpCompare(ps, expectedLog, actualLog); - throw new AssertionFailedError(msg); - } - } - + assertArrayEquals("Log entry mismatch", expectedLog, actualLog); } - private static void dumpCompare(PrintStream ps, String[] expectedLog, String[] actualLog) { - int max = Math.max(actualLog.length, expectedLog.length); - ps.println("Index\tExpected\tActual"); - for(int i=0; i ErrorEval.NA); + CellValue cv = fe.evaluate(cellA); assertEquals(ErrorEval.NA.getErrorCode(), cv.getErrorValue()); + } + @Test + public void testRegisterInRuntimeC() { HSSFCell cellB = row.createCell(1); cellB.setCellFormula("CUBEMEMBERPROPERTY(A5)"); - try { - cv = fe.evaluate(cellB); - fail("expectecd exception"); - } catch (NotImplementedException e) { - } + thrown.expect(NotImplementedException.class); + fe.evaluate(cellB); + } - AnalysisToolPak.registerFunction("CUBEMEMBERPROPERTY", new FreeRefFunction() { - @Override - public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) { - return ErrorEval.NUM_ERROR; - } - }); + @Test + public void testRegisterInRuntimeD() { + HSSFCell cellB = row.createCell(1); + cellB.setCellFormula("CUBEMEMBERPROPERTY(A5)"); - cv = fe.evaluate(cellB); + AnalysisToolPak.registerFunction("CUBEMEMBERPROPERTY", (args, ec) -> ErrorEval.NUM_ERROR); + + CellValue cv = fe.evaluate(cellB); assertEquals(ErrorEval.NUM_ERROR.getErrorCode(), cv.getErrorValue()); } - public void testExceptions() { - Function func = new Function() { - @Override - public ValueEval evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex) { - return ErrorEval.NA; - } - }; - try { - FunctionEval.registerFunction("SUM", func); - fail("expectecd exception"); - } catch (IllegalArgumentException e){ - assertEquals("POI already implememts SUM" + - ". You cannot override POI's implementations of Excel functions", e.getMessage()); - } - try { - FunctionEval.registerFunction("SUMXXX", func); - fail("expectecd exception"); - } catch (IllegalArgumentException e){ - assertEquals("Unknown function: SUMXXX", e.getMessage()); - } - try { - FunctionEval.registerFunction("ISODD", func); - fail("expectecd exception"); - } catch (IllegalArgumentException e){ - assertEquals("ISODD is a function from the Excel Analysis Toolpack. " + - "Use AnalysisToolpack.registerFunction(String name, FreeRefFunction func) instead.", e.getMessage()); - } + private static ValueEval na(ValueEval[] args, int srcRowIndex, int srcColumnIndex) { + return ErrorEval.NA; + } - FreeRefFunction atpFunc = new FreeRefFunction() { - @Override - public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) { - return ErrorEval.NUM_ERROR; - } - }; - try { - AnalysisToolPak.registerFunction("ISODD", atpFunc); - fail("expectecd exception"); - } catch (IllegalArgumentException e){ - assertEquals("POI already implememts ISODD" + - ". You cannot override POI's implementations of Excel functions", e.getMessage()); - } - try { - AnalysisToolPak.registerFunction("ISODDXXX", atpFunc); - fail("expectecd exception"); - } catch (IllegalArgumentException e){ - assertEquals("ISODDXXX is not a function from the Excel Analysis Toolpack.", e.getMessage()); - } - try { - AnalysisToolPak.registerFunction("SUM", atpFunc); - fail("expectecd exception"); - } catch (IllegalArgumentException e){ - assertEquals("SUM is a built-in Excel function. " + - "Use FunctoinEval.registerFunction(String name, Function func) instead.", e.getMessage()); - } + @Test + public void testExceptionsA() { + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("POI already implememts SUM. You cannot override POI's implementations of Excel functions"); + FunctionEval.registerFunction("SUM", TestFunctionRegistry::na); + } + + @Test + public void testExceptionsB() { + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Unknown function: SUMXXX"); + FunctionEval.registerFunction("SUMXXX", TestFunctionRegistry::na); + } + + @Test + public void testExceptionsC() { + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("ISODD is a function from the Excel Analysis Toolpack. " + + "Use AnalysisToolpack.registerFunction(String name, FreeRefFunction func) instead."); + FunctionEval.registerFunction("ISODD", TestFunctionRegistry::na); + } + + private static ValueEval atpFunc(ValueEval[] args, OperationEvaluationContext ec) { + return ErrorEval.NUM_ERROR; + } + + @Test + public void testExceptionsD() { + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("POI already implememts ISODD. You cannot override POI's implementations of Excel functions"); + AnalysisToolPak.registerFunction("ISODD", TestFunctionRegistry::atpFunc); + } + + @Test + public void testExceptionsE() { + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("ISODDXXX is not a function from the Excel Analysis Toolpack."); + AnalysisToolPak.registerFunction("ISODDXXX", TestFunctionRegistry::atpFunc); + } + + @Test + public void testExceptionsF() { + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("SUM is a built-in Excel function. " + + "Use FunctoinEval.registerFunction(String name, Function func) instead."); + AnalysisToolPak.registerFunction("SUM", TestFunctionRegistry::atpFunc); } } diff --git a/src/testcases/org/apache/poi/ss/formula/TestPlainCellCache.java b/src/testcases/org/apache/poi/ss/formula/TestPlainCellCache.java index 1abe548430..bc89b8dc8a 100644 --- a/src/testcases/org/apache/poi/ss/formula/TestPlainCellCache.java +++ b/src/testcases/org/apache/poi/ss/formula/TestPlainCellCache.java @@ -19,18 +19,17 @@ package org.apache.poi.ss.formula; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; + import org.apache.poi.ss.formula.PlainCellCache.Loc; -import org.apache.poi.ss.formula.eval.*; +import org.apache.poi.ss.formula.eval.NumberEval; +import org.junit.Test; -/** - * @author Yegor Kozlov - */ -public class TestPlainCellCache extends TestCase { +public class TestPlainCellCache { - /** - * - */ + @Test public void testLoc(){ PlainCellCache cache = new PlainCellCache(); for (int bookIndex = 0; bookIndex < 0x1000; bookIndex += 0x100) { diff --git a/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java b/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java index 825a07e0d1..7ac623ac86 100644 --- a/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java +++ b/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java @@ -16,6 +16,10 @@ ==================================================================== */ package org.apache.poi.ss.formula.atp; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; @@ -24,73 +28,72 @@ import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.CellReference; - -import junit.framework.TestCase; +import org.junit.Test; /** * Testcase for 'Analysis Toolpak' function IFERROR() - * - * @author Johan Karlsteen */ -public class TestIfError extends TestCase { +public class TestIfError { /** * =IFERROR(210/35,\"Error in calculation\")" Divides 210 by 35 and returns 6.0 * =IFERROR(55/0,\"Error in calculation\")" Divides 55 by 0 and returns the error text * =IFERROR(C1,\"Error in calculation\")" References the result of dividing 55 by 0 and returns the error text */ - public static void testEvaluate(){ - Workbook wb = new HSSFWorkbook(); - Sheet sh = wb.createSheet(); - Row row1 = sh.createRow(0); - Row row2 = sh.createRow(1); + @Test + public void testEvaluate() throws IOException { + try (Workbook wb = new HSSFWorkbook()) { + Sheet sh = wb.createSheet(); + Row row1 = sh.createRow(0); + Row row2 = sh.createRow(1); - // Create cells - row1.createCell(0, CellType.NUMERIC); - row1.createCell(1, CellType.NUMERIC); - row1.createCell(2, CellType.NUMERIC); - row2.createCell(0, CellType.NUMERIC); - row2.createCell(1, CellType.NUMERIC); + // Create cells + row1.createCell(0, CellType.NUMERIC); + row1.createCell(1, CellType.NUMERIC); + row1.createCell(2, CellType.NUMERIC); + row2.createCell(0, CellType.NUMERIC); + row2.createCell(1, CellType.NUMERIC); - // Create references - CellReference a1 = new CellReference("A1"); - CellReference a2 = new CellReference("A2"); - CellReference b1 = new CellReference("B1"); - CellReference b2 = new CellReference("B2"); - CellReference c1 = new CellReference("C1"); - - // Set values - sh.getRow(a1.getRow()).getCell(a1.getCol()).setCellValue(210); - sh.getRow(a2.getRow()).getCell(a2.getCol()).setCellValue(55); - sh.getRow(b1.getRow()).getCell(b1.getCol()).setCellValue(35); - sh.getRow(b2.getRow()).getCell(b2.getCol()).setCellValue(0); - sh.getRow(c1.getRow()).getCell(c1.getCol()).setCellFormula("A1/B2"); - - Cell cell1 = sh.createRow(3).createCell(0); - cell1.setCellFormula("IFERROR(A1/B1,\"Error in calculation\")"); - Cell cell2 = sh.createRow(3).createCell(0); - cell2.setCellFormula("IFERROR(A2/B2,\"Error in calculation\")"); - Cell cell3 = sh.createRow(3).createCell(0); - cell3.setCellFormula("IFERROR(C1,\"error\")"); - - double accuracy = 1E-9; + // Create references + CellReference a1 = new CellReference("A1"); + CellReference a2 = new CellReference("A2"); + CellReference b1 = new CellReference("B1"); + CellReference b2 = new CellReference("B2"); + CellReference c1 = new CellReference("C1"); - FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); + // Set values + sh.getRow(a1.getRow()).getCell(a1.getCol()).setCellValue(210); + sh.getRow(a2.getRow()).getCell(a2.getCol()).setCellValue(55); + sh.getRow(b1.getRow()).getCell(b1.getCol()).setCellValue(35); + sh.getRow(b2.getRow()).getCell(b2.getCol()).setCellValue(0); + sh.getRow(c1.getRow()).getCell(c1.getCol()).setCellFormula("A1/B2"); - assertEquals("Checks that the cell is numeric", - CellType.NUMERIC, evaluator.evaluate(cell1).getCellType()); - assertEquals("Divides 210 by 35 and returns 6.0", - 6.0, evaluator.evaluate(cell1).getNumberValue(), accuracy); - - - assertEquals("Checks that the cell is numeric", - CellType.STRING, evaluator.evaluate(cell2).getCellType()); - assertEquals("Rounds -10 to a nearest multiple of -3 (-9)", - "Error in calculation", evaluator.evaluate(cell2).getStringValue()); - - assertEquals("Check that C1 returns string", - CellType.STRING, evaluator.evaluate(cell3).getCellType()); - assertEquals("Check that C1 returns string \"error\"", - "error", evaluator.evaluate(cell3).getStringValue()); + Cell cell1 = sh.createRow(3).createCell(0); + cell1.setCellFormula("IFERROR(A1/B1,\"Error in calculation\")"); + Cell cell2 = sh.createRow(3).createCell(0); + cell2.setCellFormula("IFERROR(A2/B2,\"Error in calculation\")"); + Cell cell3 = sh.createRow(3).createCell(0); + cell3.setCellFormula("IFERROR(C1,\"error\")"); + + double accuracy = 1E-9; + + FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); + + assertEquals("Checks that the cell is numeric", + CellType.NUMERIC, evaluator.evaluate(cell1).getCellType()); + assertEquals("Divides 210 by 35 and returns 6.0", + 6.0, evaluator.evaluate(cell1).getNumberValue(), accuracy); + + + assertEquals("Checks that the cell is numeric", + CellType.STRING, evaluator.evaluate(cell2).getCellType()); + assertEquals("Rounds -10 to a nearest multiple of -3 (-9)", + "Error in calculation", evaluator.evaluate(cell2).getStringValue()); + + assertEquals("Check that C1 returns string", + CellType.STRING, evaluator.evaluate(cell3).getCellType()); + assertEquals("Check that C1 returns string \"error\"", + "error", evaluator.evaluate(cell3).getStringValue()); + } } } diff --git a/src/testcases/org/apache/poi/ss/formula/atp/TestMRound.java b/src/testcases/org/apache/poi/ss/formula/atp/TestMRound.java index 2338fbbe6d..b9aa6f1663 100644 --- a/src/testcases/org/apache/poi/ss/formula/atp/TestMRound.java +++ b/src/testcases/org/apache/poi/ss/formula/atp/TestMRound.java @@ -16,25 +16,29 @@ ==================================================================== */ package org.apache.poi.ss.formula.atp; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.formula.eval.ErrorEval; -import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.FormulaEvaluator; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.junit.Test; /** * Testcase for 'Analysis Toolpak' function MROUND() - * - * @author Yegor Kozlov */ -public class TestMRound extends TestCase { +public class TestMRound { /** -=MROUND(10, 3) Rounds 10 to a nearest multiple of 3 (9) -=MROUND(-10, -3) Rounds -10 to a nearest multiple of -3 (-9) -=MROUND(1.3, 0.2) Rounds 1.3 to a nearest multiple of 0.2 (1.4) -=MROUND(5, -2) Returns an error, because -2 and 5 have different signs (#NUM!) * + =MROUND(10, 3) Rounds 10 to a nearest multiple of 3 (9) + =MROUND(-10, -3) Rounds -10 to a nearest multiple of -3 (-9) + =MROUND(1.3, 0.2) Rounds 1.3 to a nearest multiple of 0.2 (1.4) + =MROUND(5, -2) Returns an error, because -2 and 5 have different signs (#NUM!) * */ - public static void testEvaluate(){ + @Test + public void testEvaluate(){ Workbook wb = new HSSFWorkbook(); Sheet sh = wb.createSheet(); Cell cell1 = sh.createRow(0).createCell(0); @@ -65,6 +69,6 @@ public class TestMRound extends TestCase { ErrorEval.NUM_ERROR.getErrorCode(), evaluator.evaluate(cell4).getErrorValue()); assertEquals("Returns 0 because the multiple is 0", - 0.0, evaluator.evaluate(cell5).getNumberValue()); + 0.0, evaluator.evaluate(cell5).getNumberValue(), 0); } } diff --git a/src/testcases/org/apache/poi/ss/formula/atp/TestNetworkdaysFunction.java b/src/testcases/org/apache/poi/ss/formula/atp/TestNetworkdaysFunction.java index 678b766fe8..4c6dc8b048 100644 --- a/src/testcases/org/apache/poi/ss/formula/atp/TestNetworkdaysFunction.java +++ b/src/testcases/org/apache/poi/ss/formula/atp/TestNetworkdaysFunction.java @@ -19,6 +19,7 @@ package org.apache.poi.ss.formula.atp; import static org.apache.poi.ss.formula.eval.ErrorEval.NAME_INVALID; import static org.apache.poi.ss.formula.eval.ErrorEval.VALUE_INVALID; +import static org.junit.Assert.assertEquals; import java.util.ArrayList; import java.util.List; @@ -30,10 +31,9 @@ import org.apache.poi.ss.formula.eval.AreaEvalBase; import org.apache.poi.ss.formula.eval.NumericValueEval; import org.apache.poi.ss.formula.eval.StringEval; import org.apache.poi.ss.formula.eval.ValueEval; +import org.junit.Test; -import junit.framework.TestCase; - -public class TestNetworkdaysFunction extends TestCase { +public class TestNetworkdaysFunction { private static final String STARTING_DATE = "2008/10/01"; private static final String END_DATE = "2009/03/01"; @@ -43,46 +43,54 @@ public class TestNetworkdaysFunction extends TestCase { private static final OperationEvaluationContext EC = new OperationEvaluationContext(null, null, 1, 1, 1, null); + @Test public void testFailWhenNoArguments() { assertEquals(VALUE_INVALID, NetworkdaysFunction.instance.evaluate(new ValueEval[0], null)); } + @Test public void testFailWhenLessThan2Arguments() { assertEquals(VALUE_INVALID, NetworkdaysFunction.instance.evaluate(new ValueEval[1], null)); } + @Test public void testFailWhenMoreThan3Arguments() { assertEquals(VALUE_INVALID, NetworkdaysFunction.instance.evaluate(new ValueEval[4], null)); } + @Test public void testFailWhenArgumentsAreNotDates() { assertEquals(VALUE_INVALID, NetworkdaysFunction.instance.evaluate(new ValueEval[]{ new StringEval("Potato"), new StringEval("Cucumber") }, EC)); } + @Test public void testFailWhenStartDateAfterEndDate() { assertEquals(NAME_INVALID, NetworkdaysFunction.instance.evaluate(new ValueEval[]{ new StringEval(END_DATE), new StringEval(STARTING_DATE) }, EC)); } + @Test public void testReturnNetworkdays() { assertEquals(108, (int) ((NumericValueEval) NetworkdaysFunction.instance.evaluate(new ValueEval[]{ new StringEval(STARTING_DATE), new StringEval(END_DATE) }, EC)).getNumberValue()); } + @Test public void testReturnNetworkdaysWithAHoliday() { assertEquals(107, (int) ((NumericValueEval) NetworkdaysFunction.instance.evaluate(new ValueEval[]{ new StringEval(STARTING_DATE), new StringEval(END_DATE), new StringEval(FIRST_HOLIDAY) }, EC)).getNumberValue()); } + @Test public void testReturnNetworkdaysWithManyHolidays() { assertEquals(105, (int) ((NumericValueEval) NetworkdaysFunction.instance.evaluate(new ValueEval[]{ new StringEval(STARTING_DATE), new StringEval(END_DATE), - new MockAreaEval(FIRST_HOLIDAY, SECOND_HOLIDAY, THIRD_HOLIDAY) }, EC)).getNumberValue()); + new MockAreaEval(FIRST_HOLIDAY, SECOND_HOLIDAY, THIRD_HOLIDAY)}, EC)).getNumberValue()); } - private class MockAreaEval extends AreaEvalBase { + private static class MockAreaEval extends AreaEvalBase { private List holidays; diff --git a/src/testcases/org/apache/poi/ss/formula/atp/TestPercentile.java b/src/testcases/org/apache/poi/ss/formula/atp/TestPercentile.java index 8107d97e70..367109b61e 100644 --- a/src/testcases/org/apache/poi/ss/formula/atp/TestPercentile.java +++ b/src/testcases/org/apache/poi/ss/formula/atp/TestPercentile.java @@ -16,6 +16,8 @@ ==================================================================== */ package org.apache.poi.ss.formula.atp; +import static org.junit.Assert.assertEquals; + import org.apache.poi.ss.formula.eval.AreaEval; import org.apache.poi.ss.formula.eval.BlankEval; import org.apache.poi.ss.formula.eval.BoolEval; @@ -24,24 +26,12 @@ import org.apache.poi.ss.formula.eval.NumberEval; import org.apache.poi.ss.formula.eval.ValueEval; import org.apache.poi.ss.formula.functions.AggregateFunction; import org.apache.poi.ss.formula.functions.EvalFactory; - -import junit.framework.TestCase; +import org.junit.Test; /** * Testcase for Excel function PERCENTILE() - * - * @author T. Gordon */ -public class TestPercentile extends TestCase { - - public void testPercentile() { - testBasic(); - testUnusualArgs(); - testUnusualArgs2(); - testUnusualArgs3(); - testErrors(); - testErrors2(); - } +public class TestPercentile { private static ValueEval invokePercentile(ValueEval[] args, ValueEval percentile) { AreaEval aeA = EvalFactory.createAreaEval("A1:A" + args.length, args); @@ -62,6 +52,7 @@ public class TestPercentile extends TestCase { assertEquals(expectedError.getErrorCode(), ((ErrorEval) result).getErrorCode()); } + @Test public void testBasic() { ValueEval[] values = { new NumberEval(210.128), new NumberEval(65.2182), new NumberEval(32.231), new NumberEval(12.123), new NumberEval(45.32) }; @@ -69,6 +60,7 @@ public class TestPercentile extends TestCase { confirmPercentile(percentile, values, 181.14604); } + @Test public void testBlanks() { ValueEval[] values = { new NumberEval(210.128), new NumberEval(65.2182), new NumberEval(32.231), BlankEval.instance, new NumberEval(45.32) }; @@ -76,6 +68,7 @@ public class TestPercentile extends TestCase { confirmPercentile(percentile, values, 188.39153); } + @Test public void testUnusualArgs() { ValueEval[] values = { new NumberEval(1), new NumberEval(2), BoolEval.TRUE, BoolEval.FALSE }; ValueEval percentile = new NumberEval(0.95); @@ -83,6 +76,7 @@ public class TestPercentile extends TestCase { } //percentile has to be between 0 and 1 - here we test less than zero + @Test public void testUnusualArgs2() { ValueEval[] values = { new NumberEval(1), new NumberEval(2), }; ValueEval percentile = new NumberEval(-0.1); @@ -90,6 +84,7 @@ public class TestPercentile extends TestCase { } //percentile has to be between 0 and 1 - here we test more than 1 + @Test public void testUnusualArgs3() { ValueEval[] values = { new NumberEval(1), new NumberEval(2) }; ValueEval percentile = new NumberEval(1.1); @@ -97,6 +92,7 @@ public class TestPercentile extends TestCase { } //here we test where there are errors as part of inputs + @Test public void testErrors() { ValueEval[] values = { new NumberEval(1), ErrorEval.NAME_INVALID, new NumberEval(3), ErrorEval.DIV_ZERO, }; ValueEval percentile = new NumberEval(0.95); @@ -104,6 +100,7 @@ public class TestPercentile extends TestCase { } //here we test where there are errors as part of inputs + @Test public void testErrors2() { ValueEval[] values = { new NumberEval(1), new NumberEval(2), new NumberEval(3), ErrorEval.DIV_ZERO, }; ValueEval percentile = new NumberEval(0.95); diff --git a/src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java b/src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java index 5a922080c0..a4d387f5d9 100644 --- a/src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java +++ b/src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java @@ -16,7 +16,8 @@ ==================================================================== */ package org.apache.poi.ss.formula.atp; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.ss.formula.eval.ErrorEval; @@ -26,38 +27,37 @@ import org.apache.poi.ss.usermodel.FormulaEvaluator; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; +import org.junit.Before; +import org.junit.Test; /** * Testcase for 'Analysis Toolpak' function RANDBETWEEN() - * - * @author Brendan Nolan */ -public class TestRandBetween extends TestCase { +public class TestRandBetween { private Workbook wb; private FormulaEvaluator evaluator; private Cell bottomValueCell; private Cell topValueCell; private Cell formulaCell; - - @Override - protected void setUp() throws Exception { - super.setUp(); + + @Before + public void setUp() throws Exception { wb = HSSFTestDataSamples.openSampleWorkbook("TestRandBetween.xls"); evaluator = wb.getCreationHelper().createFormulaEvaluator(); - + Sheet sheet = wb.createSheet("RandBetweenSheet"); Row row = sheet.createRow(0); bottomValueCell = row.createCell(0); topValueCell = row.createCell(1); formulaCell = row.createCell(2, CellType.FORMULA); } - + /** * Check where values are the same */ + @Test public void testRandBetweenSameValues() { - evaluator.clearAllCachedResultValues(); formulaCell.setCellFormula("RANDBETWEEN(1,1)"); evaluator.evaluateFormulaCell(formulaCell); @@ -69,6 +69,7 @@ public class TestRandBetween extends TestCase { } + @Test public void testRandBetweenLargeLongs() { for (int i = 0; i < 100; i++) { evaluator.clearAllCachedResultValues(); @@ -79,70 +80,70 @@ public class TestRandBetween extends TestCase { assertTrue("rand is less than or equal to upperbound", value <= 9999999999.0); } } - + /** - * Check special case where rounded up bottom value is greater than + * Check special case where rounded up bottom value is greater than * top value. */ + @Test public void testRandBetweenSpecialCase() { - - - bottomValueCell.setCellValue(0.05); + bottomValueCell.setCellValue(0.05); topValueCell.setCellValue(0.1); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); evaluator.clearAllCachedResultValues(); evaluator.evaluateFormulaCell(formulaCell); assertEquals(1, formulaCell.getNumericCellValue(), 0); - bottomValueCell.setCellValue(-0.1); + bottomValueCell.setCellValue(-0.1); topValueCell.setCellValue(-0.05); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); evaluator.clearAllCachedResultValues(); evaluator.evaluateFormulaCell(formulaCell); assertEquals(0, formulaCell.getNumericCellValue(), 0); - bottomValueCell.setCellValue(-1.1); + bottomValueCell.setCellValue(-1.1); topValueCell.setCellValue(-1.05); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); evaluator.clearAllCachedResultValues(); evaluator.evaluateFormulaCell(formulaCell); assertEquals(-1, formulaCell.getNumericCellValue(), 0); - bottomValueCell.setCellValue(-1.1); + bottomValueCell.setCellValue(-1.1); topValueCell.setCellValue(-1.1); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); evaluator.clearAllCachedResultValues(); evaluator.evaluateFormulaCell(formulaCell); assertEquals(-1, formulaCell.getNumericCellValue(), 0); } - + /** * Check top value of BLANK which Excel will evaluate as 0 */ + @Test public void testRandBetweenTopBlank() { - - bottomValueCell.setCellValue(-1); + bottomValueCell.setCellValue(-1); topValueCell.setBlank(); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); evaluator.clearAllCachedResultValues(); evaluator.evaluateFormulaCell(formulaCell); assertTrue(formulaCell.getNumericCellValue() == 0 || formulaCell.getNumericCellValue() == -1); - + } /** * Check where input values are of wrong type */ + @Test public void testRandBetweenWrongInputTypes() { // Check case where bottom input is of the wrong type - bottomValueCell.setCellValue("STRING"); + bottomValueCell.setCellValue("STRING"); topValueCell.setCellValue(1); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); evaluator.clearAllCachedResultValues(); evaluator.evaluateFormulaCell(formulaCell); assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultType()); assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), formulaCell.getErrorCellValue()); - - + + // Check case where top input is of the wrong type bottomValueCell.setCellValue(1); - topValueCell.setCellValue("STRING"); + topValueCell.setCellValue("STRING"); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); evaluator.clearAllCachedResultValues(); evaluator.evaluateFormulaCell(formulaCell); @@ -151,29 +152,28 @@ public class TestRandBetween extends TestCase { // Check case where both inputs are of wrong type bottomValueCell.setCellValue("STRING"); - topValueCell.setCellValue("STRING"); + topValueCell.setCellValue("STRING"); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); evaluator.clearAllCachedResultValues(); evaluator.evaluateFormulaCell(formulaCell); assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultType()); assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), formulaCell.getErrorCellValue()); - } - + /** * Check case where bottom is greater than top */ + @Test public void testRandBetweenBottomGreaterThanTop() { - // Check case where bottom is greater than top - bottomValueCell.setCellValue(1); + bottomValueCell.setCellValue(1); topValueCell.setCellValue(0); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); evaluator.clearAllCachedResultValues(); evaluator.evaluateFormulaCell(formulaCell); assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultType()); - assertEquals(ErrorEval.NUM_ERROR.getErrorCode(), formulaCell.getErrorCellValue()); - bottomValueCell.setCellValue(1); + assertEquals(ErrorEval.NUM_ERROR.getErrorCode(), formulaCell.getErrorCellValue()); + bottomValueCell.setCellValue(1); topValueCell.setBlank(); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); evaluator.clearAllCachedResultValues(); @@ -181,19 +181,17 @@ public class TestRandBetween extends TestCase { assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultType()); assertEquals(ErrorEval.NUM_ERROR.getErrorCode(), formulaCell.getErrorCellValue()); } - + /** * Boundary check of Double MIN and MAX values */ + @Test public void testRandBetweenBoundaryCheck() { - - bottomValueCell.setCellValue(Double.MIN_VALUE); + bottomValueCell.setCellValue(Double.MIN_VALUE); topValueCell.setCellValue(Double.MAX_VALUE); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); evaluator.clearAllCachedResultValues(); evaluator.evaluateFormulaCell(formulaCell); - assertTrue(formulaCell.getNumericCellValue() >= Double.MIN_VALUE && formulaCell.getNumericCellValue() <= Double.MAX_VALUE); - + assertTrue(formulaCell.getNumericCellValue() >= Double.MIN_VALUE && formulaCell.getNumericCellValue() <= Double.MAX_VALUE); } - } diff --git a/src/testcases/org/apache/poi/ss/formula/eval/BaseTestCircularReferences.java b/src/testcases/org/apache/poi/ss/formula/eval/BaseTestCircularReferences.java index 21fdce4bfd..fc499d2277 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/BaseTestCircularReferences.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/BaseTestCircularReferences.java @@ -18,8 +18,9 @@ package org.apache.poi.ss.formula.eval; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.IOException; @@ -33,8 +34,6 @@ import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.junit.Test; -import junit.framework.AssertionFailedError; - /** * Common superclass for testing cases of circular references * both for HSSF and XSSF @@ -54,13 +53,13 @@ public abstract class BaseTestCircularReferences { /** * Translates StackOverflowError into AssertionFailedError */ - private CellValue evaluateWithCycles(Workbook wb, Cell testCell) - throws AssertionFailedError { + private CellValue evaluateWithCycles(Workbook wb, Cell testCell) { FormulaEvaluator evaluator = _testDataProvider.createFormulaEvaluator(wb); try { return evaluator.evaluate(testCell); } catch (StackOverflowError e) { - throw new AssertionFailedError( "circular reference caused stack overflow error"); + fail( "circular reference caused stack overflow error"); + return null; } } /** @@ -78,28 +77,28 @@ public abstract class BaseTestCircularReferences { */ @Test public void testIndexFormula() throws IOException { - Workbook wb = _testDataProvider.createWorkbook(); - Sheet sheet = wb.createSheet("Sheet1"); + try (Workbook wb = _testDataProvider.createWorkbook()) { + Sheet sheet = wb.createSheet("Sheet1"); - int colB = 1; - sheet.createRow(0).createCell(colB).setCellValue(1); - sheet.createRow(1).createCell(colB).setCellValue(2); - sheet.createRow(2).createCell(colB).setCellValue(3); - Row row4 = sheet.createRow(3); - Cell testCell = row4.createCell(0); - // This formula should evaluate to the contents of B2, - testCell.setCellFormula("INDEX(A1:B4,2,2)"); - // However the range A1:B4 also includes the current cell A4. If the other parameters - // were 4 and 1, this would represent a circular reference. Prior to v3.2 POI would - // 'fully' evaluate ref arguments before invoking operators, which raised the possibility of - // cycles / StackOverflowErrors. + int colB = 1; + sheet.createRow(0).createCell(colB).setCellValue(1); + sheet.createRow(1).createCell(colB).setCellValue(2); + sheet.createRow(2).createCell(colB).setCellValue(3); + Row row4 = sheet.createRow(3); + Cell testCell = row4.createCell(0); + // This formula should evaluate to the contents of B2, + testCell.setCellFormula("INDEX(A1:B4,2,2)"); + // However the range A1:B4 also includes the current cell A4. If the other parameters + // were 4 and 1, this would represent a circular reference. Prior to v3.2 POI would + // 'fully' evaluate ref arguments before invoking operators, which raised the possibility of + // cycles / StackOverflowErrors. - CellValue cellValue = evaluateWithCycles(wb, testCell); - - assertSame(cellValue.getCellType(), CellType.NUMERIC); - assertEquals(2, cellValue.getNumberValue(), 0); - wb.close(); + CellValue cellValue = evaluateWithCycles(wb, testCell); + assertNotNull(cellValue); + assertSame(cellValue.getCellType(), CellType.NUMERIC); + assertEquals(2, cellValue.getNumberValue(), 0); + } } /** @@ -107,18 +106,18 @@ public abstract class BaseTestCircularReferences { */ @Test public void testSimpleCircularReference() throws IOException { - Workbook wb = _testDataProvider.createWorkbook(); - Sheet sheet = wb.createSheet("Sheet1"); + try (Workbook wb = _testDataProvider.createWorkbook()) { + Sheet sheet = wb.createSheet("Sheet1"); - Row row = sheet.createRow(0); - Cell testCell = row.createCell(0); - testCell.setCellFormula("A1"); + Row row = sheet.createRow(0); + Cell testCell = row.createCell(0); + testCell.setCellFormula("A1"); - CellValue cellValue = evaluateWithCycles(wb, testCell); + CellValue cellValue = evaluateWithCycles(wb, testCell); + assertNotNull(cellValue); + confirmCycleErrorCode(cellValue); - confirmCycleErrorCode(cellValue); - - wb.close(); + } } /** @@ -126,67 +125,66 @@ public abstract class BaseTestCircularReferences { */ @Test public void testMultiLevelCircularReference() throws IOException { - Workbook wb = _testDataProvider.createWorkbook(); - Sheet sheet = wb.createSheet("Sheet1"); + try (Workbook wb = _testDataProvider.createWorkbook()) { + Sheet sheet = wb.createSheet("Sheet1"); - Row row = sheet.createRow(0); - row.createCell(0).setCellFormula("B1"); - row.createCell(1).setCellFormula("C1"); - row.createCell(2).setCellFormula("D1"); - Cell testCell = row.createCell(3); - testCell.setCellFormula("A1"); + Row row = sheet.createRow(0); + row.createCell(0).setCellFormula("B1"); + row.createCell(1).setCellFormula("C1"); + row.createCell(2).setCellFormula("D1"); + Cell testCell = row.createCell(3); + testCell.setCellFormula("A1"); - CellValue cellValue = evaluateWithCycles(wb, testCell); - - confirmCycleErrorCode(cellValue); - - wb.close(); + CellValue cellValue = evaluateWithCycles(wb, testCell); + assertNotNull(cellValue); + confirmCycleErrorCode(cellValue); + } } @Test public void testIntermediateCircularReferenceResults_bug46898() throws IOException { - Workbook wb = _testDataProvider.createWorkbook(); - Sheet sheet = wb.createSheet("Sheet1"); + try (Workbook wb = _testDataProvider.createWorkbook()) { + Sheet sheet = wb.createSheet("Sheet1"); - Row row = sheet.createRow(0); + Row row = sheet.createRow(0); - Cell cellA1 = row.createCell(0); - Cell cellB1 = row.createCell(1); - Cell cellC1 = row.createCell(2); - Cell cellD1 = row.createCell(3); - Cell cellE1 = row.createCell(4); + Cell cellA1 = row.createCell(0); + Cell cellB1 = row.createCell(1); + Cell cellC1 = row.createCell(2); + Cell cellD1 = row.createCell(3); + Cell cellE1 = row.createCell(4); - cellA1.setCellFormula("IF(FALSE, 1+B1, 42)"); - cellB1.setCellFormula("1+C1"); - cellC1.setCellFormula("1+D1"); - cellD1.setCellFormula("1+E1"); - cellE1.setCellFormula("1+A1"); + cellA1.setCellFormula("IF(FALSE, 1+B1, 42)"); + cellB1.setCellFormula("1+C1"); + cellC1.setCellFormula("1+D1"); + cellD1.setCellFormula("1+E1"); + cellE1.setCellFormula("1+A1"); - FormulaEvaluator fe = _testDataProvider.createFormulaEvaluator(wb); - CellValue cv; + FormulaEvaluator fe = _testDataProvider.createFormulaEvaluator(wb); + CellValue cv; - // Happy day flow - evaluate A1 first - cv = fe.evaluate(cellA1); - assertEquals(CellType.NUMERIC, cv.getCellType()); - assertEquals(42.0, cv.getNumberValue(), 0.0); - cv = fe.evaluate(cellB1); // no circ-ref-error because A1 result is cached - assertEquals(CellType.NUMERIC, cv.getCellType()); - assertEquals(46.0, cv.getNumberValue(), 0.0); + // Happy day flow - evaluate A1 first + cv = fe.evaluate(cellA1); + assertEquals(CellType.NUMERIC, cv.getCellType()); + assertEquals(42.0, cv.getNumberValue(), 0.0); + cv = fe.evaluate(cellB1); // no circ-ref-error because A1 result is cached + assertEquals(CellType.NUMERIC, cv.getCellType()); + assertEquals(46.0, cv.getNumberValue(), 0.0); - // Show the bug - evaluate another cell from the loop first - fe.clearAllCachedResultValues(); - cv = fe.evaluate(cellB1); - // Identified bug 46898 - assertNotEquals(cv.getCellType(), ErrorEval.CIRCULAR_REF_ERROR.getErrorCode()); - assertEquals(CellType.NUMERIC, cv.getCellType()); - assertEquals(46.0, cv.getNumberValue(), 0.0); + // Show the bug - evaluate another cell from the loop first + fe.clearAllCachedResultValues(); + cv = fe.evaluate(cellB1); + // Identified bug 46898 + assertNotEquals(cv.getCellType(), ErrorEval.CIRCULAR_REF_ERROR.getErrorCode()); + assertEquals(CellType.NUMERIC, cv.getCellType()); + assertEquals(46.0, cv.getNumberValue(), 0.0); - // start evaluation on another cell - fe.clearAllCachedResultValues(); - cv = fe.evaluate(cellE1); - assertEquals(CellType.NUMERIC, cv.getCellType()); - assertEquals(43.0, cv.getNumberValue(), 0.0); - - wb.close(); + // start evaluation on another cell + fe.clearAllCachedResultValues(); + cv = fe.evaluate(cellE1); + assertEquals(CellType.NUMERIC, cv.getCellType()); + assertEquals(43.0, cv.getNumberValue(), 0.0); + + } } } diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestAreaEval.java b/src/testcases/org/apache/poi/ss/formula/eval/TestAreaEval.java index 8df7ced332..f7f65231f2 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/TestAreaEval.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/TestAreaEval.java @@ -17,21 +17,22 @@ package org.apache.poi.ss.formula.eval; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import org.apache.poi.ss.SpreadsheetVersion; -import org.apache.poi.ss.formula.ptg.AreaPtg; import org.apache.poi.ss.formula.functions.EvalFactory; +import org.apache.poi.ss.formula.ptg.AreaPtg; import org.apache.poi.ss.util.AreaReference; +import org.junit.Test; /** * Tests for AreaEval - * - * @author Josh Micich */ -public final class TestAreaEval extends TestCase { +public final class TestAreaEval { + @Test public void testGetValue_bug44950() { // TODO - this test probably isn't testing much anymore AreaPtg ptg = new AreaPtg(new AreaReference("B2:D3", SpreadsheetVersion.EXCEL97)); @@ -45,9 +46,7 @@ public final class TestAreaEval extends TestCase { new NumberEval(6), }; AreaEval ae = EvalFactory.createAreaEval(ptg, values); - if (one == ae.getAbsoluteValue(1, 2)) { - throw new AssertionFailedError("Identified bug 44950 a"); - } + assertNotEquals("Identified bug 44950 a", one, ae.getAbsoluteValue(1, 2)); confirm(1, ae, 1, 1); confirm(2, ae, 1, 2); confirm(3, ae, 1, 3); diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestDivideEval.java b/src/testcases/org/apache/poi/ss/formula/eval/TestDivideEval.java index 11c661d9fa..a0d4d96497 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/TestDivideEval.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/TestDivideEval.java @@ -17,17 +17,16 @@ package org.apache.poi.ss.formula.eval; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; import org.apache.poi.ss.formula.functions.EvalFactory; import org.apache.poi.ss.formula.functions.NumericFunctionInvoker; +import org.junit.Test; /** * Test for divide operator evaluator. - * - * @author Josh Micich */ -public final class TestDivideEval extends TestCase { +public final class TestDivideEval { private static void confirm(ValueEval arg0, ValueEval arg1, double expectedResult) { ValueEval[] args = { @@ -39,6 +38,7 @@ public final class TestDivideEval extends TestCase { assertEquals(expectedResult, result, 0); } + @Test public void testBasic() { confirm(new NumberEval(5), new NumberEval(2), 2.5); confirm(new NumberEval(3), new NumberEval(16), 0.1875); @@ -47,11 +47,14 @@ public final class TestDivideEval extends TestCase { confirm(BoolEval.TRUE, new StringEval("-0.2"), -5.0); } + @Test public void test1x1Area() { AreaEval ae0 = EvalFactory.createAreaEval("B2:B2", new ValueEval[] { new NumberEval(50), }); AreaEval ae1 = EvalFactory.createAreaEval("C2:C2", new ValueEval[] { new NumberEval(10), }); confirm(ae0, ae1, 5); } + + @Test public void testDivZero() { ValueEval[] args = { new NumberEval(5), NumberEval.ZERO, diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestEqualEval.java b/src/testcases/org/apache/poi/ss/formula/eval/TestEqualEval.java index 25690f15f6..22dfd56338 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/TestEqualEval.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/TestEqualEval.java @@ -17,25 +17,23 @@ package org.apache.poi.ss.formula.eval; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; import org.apache.poi.ss.formula.functions.EvalFactory; import org.apache.poi.ss.formula.functions.Function; +import org.junit.Test; /** - * Test for {@link EqualEval} - * - * @author Josh Micich + * Test for EqualEval */ -public final class TestEqualEval extends TestCase { - // convenient access to namepace - private static final EvalInstances EI = null; - +public final class TestEqualEval { /** * Test for bug observable at svn revision 692218 (Sep 2008)
    * The value from a 1x1 area should be taken immediately, regardless of srcRow and srcCol */ + @Test public void test1x1AreaOperand() { ValueEval[] values = { BoolEval.FALSE, }; @@ -44,17 +42,15 @@ public final class TestEqualEval extends TestCase { BoolEval.FALSE, }; ValueEval result = evaluate(EvalInstances.Equal, args, 10, 10); - if (result instanceof ErrorEval) { - if (result == ErrorEval.VALUE_INVALID) { - throw new AssertionFailedError("Identified bug in evaluation of 1x1 area"); - } - } - assertEquals(BoolEval.class, result.getClass()); + assertNotEquals("Identified bug in evaluation of 1x1 area", ErrorEval.VALUE_INVALID, result); + assertTrue(result instanceof BoolEval); assertTrue(((BoolEval)result).getBooleanValue()); } + /** * Empty string is equal to blank */ + @Test public void testBlankEqualToEmptyString() { ValueEval[] args = { @@ -64,19 +60,14 @@ public final class TestEqualEval extends TestCase { ValueEval result = evaluate(EvalInstances.Equal, args, 10, 10); assertEquals(BoolEval.class, result.getClass()); BoolEval be = (BoolEval) result; - if (!be.getBooleanValue()) { - throw new AssertionFailedError("Identified bug blank/empty string equality"); - } - assertTrue(be.getBooleanValue()); + assertTrue("Identified bug blank/empty string equality", be.getBooleanValue()); } /** * Test for bug 46613 (observable at svn r737248) */ + @Test public void testStringInsensitive_bug46613() { - if (!evalStringCmp("abc", "aBc", EvalInstances.Equal)) { - throw new AssertionFailedError("Identified bug 46613"); - } assertTrue(evalStringCmp("abc", "aBc", EvalInstances.Equal)); assertTrue(evalStringCmp("ABC", "azz", EvalInstances.LessThan)); assertTrue(evalStringCmp("abc", "AZZ", EvalInstances.LessThan)); @@ -95,6 +86,7 @@ public final class TestEqualEval extends TestCase { return be.getBooleanValue(); } + @Test public void testBooleanCompares() { confirmCompares(BoolEval.TRUE, new StringEval("TRUE"), +1); confirmCompares(BoolEval.TRUE, new NumberEval(1.0), +1); @@ -106,6 +98,7 @@ public final class TestEqualEval extends TestCase { confirmCompares(BoolEval.FALSE, new NumberEval(0.0), +1); confirmCompares(BoolEval.FALSE, BoolEval.FALSE, 0); } + private static void confirmCompares(ValueEval a, ValueEval b, int expRes) { confirm(a, b, expRes>0, EvalInstances.GreaterThan); confirm(a, b, expRes>=0, EvalInstances.GreaterEqual); @@ -119,6 +112,7 @@ public final class TestEqualEval extends TestCase { confirm(b, a, expRes>=0, EvalInstances.LessEqual); confirm(b, a, expRes>0, EvalInstances.LessThan); } + private static void confirm(ValueEval a, ValueEval b, boolean expectedResult, Function cmpOp) { ValueEval[] args = { a, b, }; ValueEval result = evaluate(cmpOp, args, 10, 20); @@ -135,22 +129,21 @@ public final class TestEqualEval extends TestCase { * "Excel considers -0.0 to be equal to 0.0" which is NQR * See {@link TestMinusZeroResult} for more specific tests regarding -0.0. */ + @Test public void testZeroEquality_bug47198() { NumberEval zero = new NumberEval(0.0); NumberEval mZero = (NumberEval) evaluate(UnaryMinusEval.instance, new ValueEval[] { zero, }, 0, 0); - if (Double.doubleToLongBits(mZero.getNumberValue()) == 0x8000000000000000L) { - throw new AssertionFailedError("Identified bug 47198: unary minus should convert -0.0 to 0.0"); - } + assertNotEquals("Identified bug 47198: unary minus should convert -0.0 to 0.0", + 0x8000000000000000L, Double.doubleToLongBits(mZero.getNumberValue())); ValueEval[] args = { zero, mZero, }; BoolEval result = (BoolEval) evaluate(EvalInstances.Equal, args, 0, 0); - if (!result.getBooleanValue()) { - throw new AssertionFailedError("Identified bug 47198: -0.0 != 0.0"); - } + assertTrue("Identified bug 47198: -0.0 != 0.0", result.getBooleanValue()); } + @Test public void testRounding_bug47598() { double x = 1+1.0028-0.9973; // should be 1.0055, but has IEEE rounding - assertFalse(x == 1.0055); + assertNotEquals(1.0055, x, 0.0); NumberEval a = new NumberEval(x); NumberEval b = new NumberEval(1.0055); @@ -158,9 +151,7 @@ public final class TestEqualEval extends TestCase { ValueEval[] args = { a, b, }; BoolEval result = (BoolEval) evaluate(EvalInstances.Equal, args, 0, 0); - if (!result.getBooleanValue()) { - throw new AssertionFailedError("Identified bug 47598: 1+1.0028-0.9973 != 1.0055"); - } + assertTrue("Identified bug 47598: 1+1.0028-0.9973 != 1.0055", result.getBooleanValue()); } private static ValueEval evaluate(Function oper, ValueEval[] args, int srcRowIx, int srcColIx) { diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestExternalFunction.java b/src/testcases/org/apache/poi/ss/formula/eval/TestExternalFunction.java index 7a153e597d..9f86c1eadc 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/TestExternalFunction.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/TestExternalFunction.java @@ -17,81 +17,67 @@ package org.apache.poi.ss.formula.eval; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; import org.apache.poi.hssf.HSSFTestDataSamples; -import org.apache.poi.ss.formula.functions.FreeRefFunction; -import org.apache.poi.ss.formula.udf.DefaultUDFFinder; -import org.apache.poi.ss.formula.udf.AggregatingUDFFinder; -import org.apache.poi.ss.formula.udf.UDFFinder; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.formula.OperationEvaluationContext; +import org.apache.poi.ss.formula.functions.FreeRefFunction; +import org.apache.poi.ss.formula.udf.AggregatingUDFFinder; +import org.apache.poi.ss.formula.udf.DefaultUDFFinder; +import org.apache.poi.ss.formula.udf.UDFFinder; +import org.junit.Test; -/** - * @author Josh Micich - * @author Petr Udalau - registering UDFs in workbook and using ToolPacks. - */ -public final class TestExternalFunction extends TestCase { +public final class TestExternalFunction { - private static class MyFunc implements FreeRefFunction { - public MyFunc() { - // - } - - @Override - public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) { - if (args.length != 1 || !(args[0] instanceof StringEval)) { - return ErrorEval.VALUE_INVALID; - } - StringEval input = (StringEval) args[0]; - return new StringEval(input.getStringValue() + "abc"); + private static ValueEval myFunc1(ValueEval[] args, OperationEvaluationContext ec) { + if (args.length != 1 || !(args[0] instanceof StringEval)) { + return ErrorEval.VALUE_INVALID; } + StringEval input = (StringEval) args[0]; + return new StringEval(input.getStringValue() + "abc"); } - private static class MyFunc2 implements FreeRefFunction { - public MyFunc2() { - // - } - - @Override - public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) { - if (args.length != 1 || !(args[0] instanceof StringEval)) { - return ErrorEval.VALUE_INVALID; - } - StringEval input = (StringEval) args[0]; - return new StringEval(input.getStringValue() + "abc2"); + private static ValueEval myFunc2(ValueEval[] args, OperationEvaluationContext ec) { + if (args.length != 1 || !(args[0] instanceof StringEval)) { + return ErrorEval.VALUE_INVALID; } + StringEval input = (StringEval) args[0]; + return new StringEval(input.getStringValue() + "abc2"); } /** - * Checks that an external function can get invoked from the formula - * evaluator. + * Checks that an external function can get invoked from the formula evaluator. */ - public void testInvoke() { - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("testNames.xls"); - HSSFSheet sheet = wb.getSheetAt(0); + @Test + public void testInvoke() throws IOException { + try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("testNames.xls")) { + HSSFSheet sheet = wb.getSheetAt(0); - /** - * register the two test UDFs in a UDF finder, to be passed to the evaluator - */ - UDFFinder udff1 = new DefaultUDFFinder(new String[] { "myFunc", }, - new FreeRefFunction[] { new MyFunc(), }); - UDFFinder udff2 = new DefaultUDFFinder(new String[] { "myFunc2", }, - new FreeRefFunction[] { new MyFunc2(), }); - UDFFinder udff = new AggregatingUDFFinder(udff1, udff2); + /* + * register the two test UDFs in a UDF finder, to be passed to the evaluator + */ + UDFFinder udff1 = new DefaultUDFFinder(new String[]{"myFunc",}, + new FreeRefFunction[]{TestExternalFunction::myFunc1}); + UDFFinder udff2 = new DefaultUDFFinder(new String[]{"myFunc2",}, + new FreeRefFunction[]{TestExternalFunction::myFunc2,}); + UDFFinder udff = new AggregatingUDFFinder(udff1, udff2); - HSSFRow row = sheet.getRow(0); - HSSFCell myFuncCell = row.getCell(1); // =myFunc("_") + HSSFRow row = sheet.getRow(0); + HSSFCell myFuncCell = row.getCell(1); // =myFunc("_") - HSSFCell myFunc2Cell = row.getCell(2); // =myFunc2("_") + HSSFCell myFunc2Cell = row.getCell(2); // =myFunc2("_") - HSSFFormulaEvaluator fe = HSSFFormulaEvaluator.create(wb, null, udff); - assertEquals("_abc", fe.evaluate(myFuncCell).getStringValue()); - assertEquals("_abc2", fe.evaluate(myFunc2Cell).getStringValue()); + HSSFFormulaEvaluator fe = HSSFFormulaEvaluator.create(wb, null, udff); + assertEquals("_abc", fe.evaluate(myFuncCell).getStringValue()); + assertEquals("_abc2", fe.evaluate(myFunc2Cell).getStringValue()); + } } } diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java index 811ec649af..a3062efc36 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java @@ -43,8 +43,6 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import junit.framework.AssertionFailedError; - /** * Tests formulas and operators as loaded from a test data spreadsheet.

    * This class does not test implementors of Function and OperationEval in @@ -60,11 +58,11 @@ public final class TestFormulasFromSpreadsheet { private static Sheet sheet; private static HSSFFormulaEvaluator evaluator; private static Locale userLocale; - + /** * This class defines constants for navigating around the test data spreadsheet used for these tests. */ - private static interface SS { + private interface SS { /** * Name of the test spreadsheet (found in the standard test data folder) @@ -99,6 +97,7 @@ public final class TestFormulasFromSpreadsheet { int NUMBER_OF_ROWS_PER_FUNCTION = 4; } + @SuppressWarnings("DefaultAnnotationParam") @Parameter(value = 0) public String targetFunctionName; @Parameter(value = 1) @@ -113,7 +112,7 @@ public final class TestFormulasFromSpreadsheet { } @Parameters(name="{0}") - public static Collection data() throws Exception { + public static Collection data() { // Function "Text" uses custom-formats which are locale specific // can't set the locale on a per-testrun execution, as some settings have been // already set, when we would try to change the locale by then @@ -123,24 +122,23 @@ public final class TestFormulasFromSpreadsheet { workbook = HSSFTestDataSamples.openSampleWorkbook(SS.FILENAME); sheet = workbook.getSheetAt( 0 ); evaluator = new HSSFFormulaEvaluator(workbook); - + List data = new ArrayList<>(); - - processFunctionGroup(data, SS.START_OPERATORS_ROW_INDEX, null); - processFunctionGroup(data, SS.START_FUNCTIONS_ROW_INDEX, null); + + processFunctionGroup(data, SS.START_OPERATORS_ROW_INDEX); + processFunctionGroup(data, SS.START_FUNCTIONS_ROW_INDEX); // example for debugging individual functions/operators: // processFunctionGroup(data, SS.START_OPERATORS_ROW_INDEX, "ConcatEval"); // processFunctionGroup(data, SS.START_FUNCTIONS_ROW_INDEX, "Text"); return data; } - + /** * @param startRowIndex row index in the spreadsheet where the first function/operator is found - * @param testFocusFunctionName name of a single function/operator to test alone. * Typically pass null to test all functions */ - private static void processFunctionGroup(List data, int startRowIndex, String testFocusFunctionName) { + private static void processFunctionGroup(List data, int startRowIndex) { for (int rowIndex = startRowIndex; true; rowIndex += SS.NUMBER_OF_ROWS_PER_FUNCTION) { Row r = sheet.getRow(rowIndex); String targetFunctionName = getTargetFunctionName(r); @@ -151,16 +149,14 @@ public final class TestFormulasFromSpreadsheet { // found end of functions list break; } - if(testFocusFunctionName == null || targetFunctionName.equalsIgnoreCase(testFocusFunctionName)) { - // expected results are on the row below - Row expectedValuesRow = sheet.getRow(rowIndex + 1); - int missingRowNum = rowIndex + 2; //+1 for 1-based, +1 for next row - assertNotNull("Missing expected values row for function '" - + targetFunctionName + " (row " + missingRowNum + ")", expectedValuesRow); + // expected results are on the row below + Row expectedValuesRow = sheet.getRow(rowIndex + 1); + int missingRowNum = rowIndex + 2; //+1 for 1-based, +1 for next row + assertNotNull("Missing expected values row for function '" + + targetFunctionName + " (row " + missingRowNum + ")", expectedValuesRow); - data.add(new Object[]{targetFunctionName, rowIndex, rowIndex + 1}); - } + data.add(new Object[]{targetFunctionName, rowIndex, rowIndex + 1}); } } @@ -235,7 +231,7 @@ public final class TestFormulasFromSpreadsheet { return cell.getRichStringCellValue().getString(); } - throw new AssertionFailedError("Bad cell type for 'function name' column: (" - + cell.getCellType() + ") row (" + (r.getRowNum() +1) + ")"); + fail("Bad cell type for 'function name' column: (" + cell.getCellType() + ") row (" + (r.getRowNum() +1) + ")"); + return null; } } diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestMinusZeroResult.java b/src/testcases/org/apache/poi/ss/formula/eval/TestMinusZeroResult.java index 8ddead517f..e725bf7746 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/TestMinusZeroResult.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/TestMinusZeroResult.java @@ -17,11 +17,12 @@ package org.apache.poi.ss.formula.eval; -import junit.framework.ComparisonFailure; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import org.apache.poi.ss.formula.functions.Function; -import org.apache.poi.util.HexDump; +import org.junit.Test; /** * IEEE 754 defines a quantity '-0.0' which is distinct from '0.0'. @@ -35,11 +36,11 @@ import org.apache.poi.util.HexDump; *

  • For most operation results '-0.0' is converted to '0.0'.
  • *
  • Comparison operators have slightly different rules regarding '-0.0'.
  • * - * @author Josh Micich */ -public final class TestMinusZeroResult extends TestCase { +public final class TestMinusZeroResult { private static final double MINUS_ZERO = -0.0; + @Test public void testSimpleOperators() { // unary plus is a no-op @@ -61,12 +62,14 @@ public final class TestMinusZeroResult extends TestCase { * These results are hard to see in Excel (since -0.0 is usually converted to +0.0 before it * gets to the comparison operator) */ + @Test public void testComparisonOperators() { checkEval(false, EvalInstances.Equal, 0.0, MINUS_ZERO); checkEval(true, EvalInstances.GreaterThan, 0.0, MINUS_ZERO); checkEval(true, EvalInstances.LessThan, MINUS_ZERO, 0.0); } + @Test public void testTextRendering() { confirmTextRendering(MINUS_ZERO); // sub-normal negative numbers also display as '-0' @@ -103,6 +106,7 @@ public final class TestMinusZeroResult extends TestCase { /** * Not really a POI test - just shows similar behaviour of '-0.0' in Java. */ + @Test public void testJava() { assertEquals(0x8000000000000000L, Double.doubleToLongBits(MINUS_ZERO)); @@ -141,9 +145,6 @@ public final class TestMinusZeroResult extends TestCase { private static void assertDouble(double a, double b) { long bitsA = Double.doubleToLongBits(a); long bitsB = Double.doubleToLongBits(b); - if (bitsA != bitsB) { - throw new ComparisonFailure("value different to expected", - HexDump.longToHex(bitsA), HexDump.longToHex(bitsB)); - } + assertEquals(bitsA, bitsB); } } diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestMissingArgEval.java b/src/testcases/org/apache/poi/ss/formula/eval/TestMissingArgEval.java index 2bef73c810..e99c8e1cce 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/TestMissingArgEval.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/TestMissingArgEval.java @@ -17,58 +17,56 @@ package org.apache.poi.ss.formula.eval; -import java.util.EmptyStackException; +import static org.junit.Assert.assertEquals; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import java.io.IOException; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.CellValue; +import org.junit.Test; /** * Tests for {@link MissingArgEval} - * - * @author Josh Micich */ -public final class TestMissingArgEval extends TestCase { - - public void testEvaluateMissingArgs() { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); - HSSFSheet sheet = wb.createSheet("Sheet1"); - HSSFCell cell = sheet.createRow(0).createCell(0); - - cell.setCellFormula("if(true,)"); - fe.clearAllCachedResultValues(); - CellValue cv; - try { - cv = fe.evaluate(cell); - } catch (EmptyStackException e) { - throw new AssertionFailedError("Missing args evaluation not implemented (bug 43354"); - } - // MissingArg -> BlankEval -> zero (as formula result) - assertEquals(0.0, cv.getNumberValue(), 0.0); - - // MissingArg -> BlankEval -> empty string (in concatenation) - cell.setCellFormula("\"abc\"&if(true,)"); - fe.clearAllCachedResultValues(); - assertEquals("abc", fe.evaluate(cell).getStringValue()); - } - - public void testCountFuncs() { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); - HSSFSheet sheet = wb.createSheet("Sheet1"); - HSSFCell cell = sheet.createRow(0).createCell(0); - - cell.setCellFormula("COUNT(C5,,,,)"); // 4 missing args, C5 is blank - assertEquals(4.0, fe.evaluate(cell).getNumberValue(), 0.0); +public final class TestMissingArgEval { - cell.setCellFormula("COUNTA(C5,,)"); // 2 missing args, C5 is blank - fe.clearAllCachedResultValues(); - assertEquals(2.0, fe.evaluate(cell).getNumberValue(), 0.0); + @Test + public void testEvaluateMissingArgs() throws IOException { + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); + HSSFSheet sheet = wb.createSheet("Sheet1"); + HSSFCell cell = sheet.createRow(0).createCell(0); + + cell.setCellFormula("if(true,)"); + fe.clearAllCachedResultValues(); + // EmptyStackException -> Missing args evaluation not implemented (bug 43354) + CellValue cv = fe.evaluate(cell); + // MissingArg -> BlankEval -> zero (as formula result) + assertEquals(0.0, cv.getNumberValue(), 0.0); + + // MissingArg -> BlankEval -> empty string (in concatenation) + cell.setCellFormula("\"abc\"&if(true,)"); + fe.clearAllCachedResultValues(); + assertEquals("abc", fe.evaluate(cell).getStringValue()); + } + } + + @Test + public void testCountFuncs() throws IOException { + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); + HSSFSheet sheet = wb.createSheet("Sheet1"); + HSSFCell cell = sheet.createRow(0).createCell(0); + + cell.setCellFormula("COUNT(C5,,,,)"); // 4 missing args, C5 is blank + assertEquals(4.0, fe.evaluate(cell).getNumberValue(), 0.0); + + cell.setCellFormula("COUNTA(C5,,)"); // 2 missing args, C5 is blank + fe.clearAllCachedResultValues(); + assertEquals(2.0, fe.evaluate(cell).getNumberValue(), 0.0); + } } } diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestMultiSheetEval.java b/src/testcases/org/apache/poi/ss/formula/eval/TestMultiSheetEval.java index c82fa6a57f..1c3350f6c0 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/TestMultiSheetEval.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/TestMultiSheetEval.java @@ -17,13 +17,15 @@ package org.apache.poi.ss.formula.eval; -import java.io.PrintStream; -import java.util.Collection; -import java.util.Locale; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; -import junit.framework.Assert; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Locale; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; @@ -34,21 +36,16 @@ import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellValue; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; /** * Tests formulas for multi sheet reference (i.e. SUM(Sheet1:Sheet5!A1)) */ -public final class TestMultiSheetEval extends TestCase { - private static final POILogger logger = POILogFactory.getLogger(TestFormulasFromSpreadsheet.class); - - private static final class Result { - public static final int SOME_EVALUATIONS_FAILED = -1; - public static final int ALL_EVALUATIONS_SUCCEEDED = +1; - public static final int NO_EVALUATIONS_FOUND = 0; - } - +@RunWith(Parameterized.class) +public final class TestMultiSheetEval { /** * This class defines constants for navigating around the test data spreadsheet used for these tests. */ @@ -89,250 +86,116 @@ public final class TestMultiSheetEval extends TestCase { public static final String TEST_SHEET_NAME = "test"; } - private HSSFWorkbook workbook; - private Sheet sheet; - // Note - multiple failures are aggregated before ending. - // If one or more functions fail, a single AssertionFailedError is thrown at the end - private int _functionFailureCount; - private int _functionSuccessCount; - private int _evaluationFailureCount; - private int _evaluationSuccessCount; + private static HSSFFormulaEvaluator evaluator; + private static Collection funcs; - private static void confirmExpectedResult(String msg, Cell expected, CellValue actual) { - if (expected == null) { - throw new AssertionFailedError(msg + " - Bad setup data expected value is null"); + @SuppressWarnings("DefaultAnnotationParam") + @Parameter(value = 0) + public String testName; + + @Parameter(value = 1) + public String functionName; + + @Parameter(value = 2) + public Cell expected; + + @Parameter(value = 3) + public Row testRow; + + @Parameterized.Parameters(name="{0}") + public static Collection data() { + HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook(SS.FILENAME); + Sheet sheet = workbook.getSheet(SS.TEST_SHEET_NAME); + evaluator = new HSSFFormulaEvaluator(workbook); + funcs = FunctionEval.getSupportedFunctionNames(); + + List data = new ArrayList<>(); + for (int rowIndex = SS.START_FUNCTIONS_ROW_INDEX;true;rowIndex++) { + Row r = sheet.getRow(rowIndex); + + // only evaluate non empty row + if (r == null) { + continue; + } + + String targetFunctionName = getTargetFunctionName(r); + assertNotNull("Expected function name or '" + SS.FUNCTION_NAMES_END_SENTINEL + "'", targetFunctionName); + if (targetFunctionName.equals(SS.FUNCTION_NAMES_END_SENTINEL)) { + // found end of functions list + break; + } + String targetTestName = getTargetTestName(r); + + // expected results are on the row below + Cell expectedValueCell = r.getCell(SS.COLUMN_INDEX_EXPECTED_VALUE); + assertNotNull("Missing expected values cell for function '" + targetFunctionName, expectedValueCell); + + data.add(new Object[]{ targetTestName, targetFunctionName, expectedValueCell, r }); } - if(actual == null) { - throw new AssertionFailedError(msg + " - actual value was null"); + + return data; + } + + @Test + public void testFunction() { + + Cell c = testRow.getCell(SS.COLUMN_INDEX_ACTUAL_VALUE); + if (c == null || c.getCellType() != CellType.FORMULA) { + // missing test data + assertTrue(testRow.getRowNum() >= SS.START_FUNCTIONS_ROW_INDEX); + assertTrue("unsupported function", funcs.contains(functionName.toUpperCase(Locale.ROOT))); + return; } - + + CellValue actual = evaluator.evaluate(c); + + assertNotNull("Bad setup data expected value is null", expected); + assertNotNull("actual value was null", actual); + final CellType cellType = expected.getCellType(); switch (cellType) { case BLANK: - assertEquals(msg, CellType.BLANK, actual.getCellType()); + assertEquals(CellType.BLANK, actual.getCellType()); break; case BOOLEAN: - assertEquals(msg, CellType.BOOLEAN, actual.getCellType()); - assertEquals(msg, expected.getBooleanCellValue(), actual.getBooleanValue()); + assertEquals(CellType.BOOLEAN, actual.getCellType()); + assertEquals(expected.getBooleanCellValue(), actual.getBooleanValue()); break; case ERROR: - assertEquals(msg, CellType.ERROR, actual.getCellType()); - assertEquals(msg, ErrorEval.getText(expected.getErrorCellValue()), ErrorEval.getText(actual.getErrorValue())); + assertEquals(CellType.ERROR, actual.getCellType()); + assertEquals(ErrorEval.getText(expected.getErrorCellValue()), ErrorEval.getText(actual.getErrorValue())); break; case FORMULA: // will never be used, since we will call method after formula evaluation - throw new AssertionFailedError("Cannot expect formula as result of formula evaluation: " + msg); + fail("Cannot expect formula as result of formula evaluation."); + break; case NUMERIC: - assertEquals(msg, CellType.NUMERIC, actual.getCellType()); - TestMathX.assertEquals(msg, expected.getNumericCellValue(), actual.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR); + assertEquals(CellType.NUMERIC, actual.getCellType()); + TestMathX.assertEquals("", expected.getNumericCellValue(), actual.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR); break; case STRING: - assertEquals(msg, CellType.STRING, actual.getCellType()); - assertEquals(msg, expected.getRichStringCellValue().getString(), actual.getStringValue()); + assertEquals(CellType.STRING, actual.getCellType()); + assertEquals(expected.getRichStringCellValue().getString(), actual.getStringValue()); break; default: - throw new AssertionFailedError("Unexpected cell type: " + cellType); - } - } - - - @Override - protected void setUp() { - if (workbook == null) { - workbook = HSSFTestDataSamples.openSampleWorkbook(SS.FILENAME); - sheet = workbook.getSheet( SS.TEST_SHEET_NAME ); - } - _functionFailureCount = 0; - _functionSuccessCount = 0; - _evaluationFailureCount = 0; - _evaluationSuccessCount = 0; - } - - public void testFunctionsFromTestSpreadsheet() { - - processFunctionGroup(SS.START_FUNCTIONS_ROW_INDEX, null); - - // confirm results - String successMsg = "There were " - + _evaluationSuccessCount + " successful evaluation(s) and " - + _functionSuccessCount + " function(s) without error"; - if(_functionFailureCount > 0) { - String msg = _functionFailureCount + " function(s) failed in " - + _evaluationFailureCount + " evaluation(s). " + successMsg; - throw new AssertionFailedError(msg); - } - logger.log(POILogger.INFO, getClass().getName() + ": " + successMsg); - } - - /** - * @param startRowIndex row index in the spreadsheet where the first function/operator is found - * @param testFocusFunctionName name of a single function/operator to test alone. - * Typically pass null to test all functions - */ - private void processFunctionGroup(int startRowIndex, String testFocusFunctionName) { - HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(workbook); - Collection funcs = FunctionEval.getSupportedFunctionNames(); - - int rowIndex = startRowIndex; - while (true) { - Row r = sheet.getRow(rowIndex); - - // only evaluate non empty row - if( r != null ) - { - String targetFunctionName = getTargetFunctionName(r); - String targetTestName = getTargetTestName(r); - if(targetFunctionName == null) { - throw new AssertionFailedError("Test spreadsheet cell empty on row (" - + (rowIndex+1) + "). Expected function name or '" - + SS.FUNCTION_NAMES_END_SENTINEL + "'"); - } - if(targetFunctionName.equals(SS.FUNCTION_NAMES_END_SENTINEL)) { - // found end of functions list - break; - } - if(testFocusFunctionName == null || targetFunctionName.equalsIgnoreCase(testFocusFunctionName)) { - - // expected results are on the row below - Cell expectedValueCell = r.getCell(SS.COLUMN_INDEX_EXPECTED_VALUE); - if(expectedValueCell == null) { - int missingRowNum = rowIndex + 1; - throw new AssertionFailedError("Missing expected values cell for function '" - + targetFunctionName + ", test" + targetTestName + " (row " + - missingRowNum + ")"); - } - - switch(processFunctionRow(evaluator, targetFunctionName, targetTestName, r, expectedValueCell)) { - case Result.ALL_EVALUATIONS_SUCCEEDED: _functionSuccessCount++; break; - case Result.SOME_EVALUATIONS_FAILED: _functionFailureCount++; break; - default: - throw new RuntimeException("unexpected result"); - case Result.NO_EVALUATIONS_FOUND: // do nothing - String uname = targetFunctionName.toUpperCase(Locale.ROOT); - if(startRowIndex >= SS.START_FUNCTIONS_ROW_INDEX && - funcs.contains(uname)) { - logger.log(POILogger.WARN, uname + ": function is supported but missing test data"); - } - break; - } - } - } - rowIndex ++; - } - } - - /** - * - * @return a constant from the local Result class denoting whether there were any evaluation - * cases, and whether they all succeeded. - */ - private int processFunctionRow(HSSFFormulaEvaluator evaluator, String targetFunctionName, - String targetTestName, Row formulasRow, Cell expectedValueCell) { - - int result = Result.NO_EVALUATIONS_FOUND; // so far - - Cell c = formulasRow.getCell(SS.COLUMN_INDEX_ACTUAL_VALUE); - if (c == null || c.getCellType() != CellType.FORMULA) { - return result; - } - - CellValue actualValue = evaluator.evaluate(c); - - try { - confirmExpectedResult("Function '" + targetFunctionName + "': Test: '" + targetTestName + "' Formula: " + c.getCellFormula() - + " @ " + formulasRow.getRowNum() + ":" + SS.COLUMN_INDEX_ACTUAL_VALUE, - expectedValueCell, actualValue); - _evaluationSuccessCount ++; - if(result != Result.SOME_EVALUATIONS_FAILED) { - result = Result.ALL_EVALUATIONS_SUCCEEDED; - } - } catch (AssertionFailedError e) { - _evaluationFailureCount ++; - printShortStackTrace(System.err, e); - result = Result.SOME_EVALUATIONS_FAILED; - } - - return result; - } - - /** - * Useful to keep output concise when expecting many failures to be reported by this test case - */ - private static void printShortStackTrace(PrintStream ps, AssertionFailedError e) { - StackTraceElement[] stes = e.getStackTrace(); - - int startIx = 0; - // skip any top frames inside junit.framework.Assert - while(startIx= endIx) { - // something went wrong. just print the whole stack trace - e.printStackTrace(ps); - } - endIx -= 4; // skip 4 frames of reflection invocation - ps.println(e); - for(int i=startIx; inull if cell is missing, empty or blank - */ private static String getTargetFunctionName(Row r) { - if(r == null) { - System.err.println("Warning - given null row, can't figure out function name"); - return null; - } + assertNotNull("given null row, can't figure out function name", r); Cell cell = r.getCell(SS.COLUMN_INDEX_FUNCTION_NAME); - if(cell == null) { - System.err.println("Warning - Row " + r.getRowNum() + " has no cell " + SS.COLUMN_INDEX_FUNCTION_NAME + ", can't figure out function name"); - return null; - } - if(cell.getCellType() == CellType.BLANK) { - return null; - } - if(cell.getCellType() == CellType.STRING) { - return cell.getRichStringCellValue().getString(); - } - - throw new AssertionFailedError("Bad cell type for 'function name' column: (" - + cell.getCellType() + ") row (" + (r.getRowNum() +1) + ")"); + assertNotNull("Row " + r.getRowNum() + " has no cell " + SS.COLUMN_INDEX_FUNCTION_NAME + ", can't figure out function name", cell); + assertEquals(CellType.STRING, cell.getCellType()); + return cell.getRichStringCellValue().getString(); } - /** - * @return null if cell is missing, empty or blank - */ + private static String getTargetTestName(Row r) { - if(r == null) { - System.err.println("Warning - given null row, can't figure out test name"); - return null; - } + assertNotNull("Given null row, can't figure out test name", r); Cell cell = r.getCell(SS.COLUMN_INDEX_TEST_NAME); - if(cell == null) { - System.err.println("Warning - Row " + r.getRowNum() + " has no cell " + SS.COLUMN_INDEX_TEST_NAME + ", can't figure out test name"); - return null; - } - if(cell.getCellType() == CellType.BLANK) { - return null; - } - if(cell.getCellType() == CellType.STRING) { - return cell.getRichStringCellValue().getString(); - } - - throw new AssertionFailedError("Bad cell type for 'test name' column: (" - + cell.getCellType() + ") row (" + (r.getRowNum() +1) + ")"); + assertNotNull("Row " + r.getRowNum() + " has no cell " + SS.COLUMN_INDEX_TEST_NAME + ", can't figure out test name", cell); + assertEquals(CellType.STRING, cell.getCellType()); + return cell.getRichStringCellValue().getString(); } - } diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestOperandResolver.java b/src/testcases/org/apache/poi/ss/formula/eval/TestOperandResolver.java index c329672265..6aa0370f07 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/TestOperandResolver.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/TestOperandResolver.java @@ -17,67 +17,62 @@ package org.apache.poi.ss.formula.eval; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import java.util.LinkedHashMap; import java.util.Map; +import org.junit.Test; + /** * Tests for OperandResolver - * - * @author Brendan Nolan */ -public final class TestOperandResolver extends TestCase { - +public final class TestOperandResolver { + @Test public void testParseDouble_bug48472() { - final Double resolvedValue; - - try { - resolvedValue = OperandResolver.parseDouble("-"); - } catch (StringIndexOutOfBoundsException e) { - throw new AssertionFailedError("Identified bug 48472"); - } - + // bug 48472 - StringIndexOutOfBoundsException + Double resolvedValue = OperandResolver.parseDouble("-"); assertNull(resolvedValue); } - + + @Test public void testParseDouble_bug49723() { String value = ".1"; - Double resolvedValue = OperandResolver.parseDouble(value); - + assertNotNull("Identified bug 49723", resolvedValue); } - + /** - * * Tests that a list of valid strings all return a non null value from {@link OperandResolver#parseDouble(String)} - * */ + @Test public void testParseDoubleValidStrings() { String[] values = new String[]{".19", "0.19", "1.9", "1E4", "-.19", "-0.19", "8.5","-1E4", ".5E6","+1.5","+1E5", " +1E5 ", " 123 ", "1E4", "-123" }; for (String value : values) { - assertNotNull(OperandResolver.parseDouble(value)); - assertEquals(OperandResolver.parseDouble(value), Double.parseDouble(value)); + Double act = OperandResolver.parseDouble(value); + assertNotNull(act); + assertEquals(act, Double.parseDouble(value), 0); } } - + /** - * * Tests that a list of invalid strings all return null from {@link OperandResolver#parseDouble(String)} - * */ + @Test public void testParseDoubleInvalidStrings() { String[] values = new String[]{"-", "ABC", "-X", "1E5a", "Infinity", "NaN", ".5F", "1,000"}; - + for (String value : values) { assertNull(OperandResolver.parseDouble(value)); } } + @Test public void testCoerceDateStringToNumber() throws EvaluationException { Map values = new LinkedHashMap<>(); values.put("2019/1/18", 43483.); @@ -90,6 +85,7 @@ public final class TestOperandResolver extends TestCase { } } + @Test public void testCoerceTimeStringToNumber() throws EvaluationException { Map values = new LinkedHashMap<>(); values.put("00:00", 0.0); diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestPercentEval.java b/src/testcases/org/apache/poi/ss/formula/eval/TestPercentEval.java index c3a5eec233..26bd6bf5dc 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/TestPercentEval.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/TestPercentEval.java @@ -17,25 +17,25 @@ package org.apache.poi.ss.formula.eval; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; -import org.apache.poi.ss.formula.functions.EvalFactory; -import org.apache.poi.ss.formula.functions.NumericFunctionInvoker; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.formula.functions.EvalFactory; +import org.apache.poi.ss.formula.functions.NumericFunctionInvoker; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellValue; +import org.junit.Test; /** * Test for percent operator evaluator. - * - * @author Josh Micich */ -public final class TestPercentEval extends TestCase { +public final class TestPercentEval { private static void confirm(ValueEval arg, double expectedResult) { ValueEval[] args = { @@ -47,6 +47,7 @@ public final class TestPercentEval extends TestCase { assertEquals(expectedResult, result, 0); } + @Test public void testBasic() { confirm(new NumberEval(5), 0.05); confirm(new NumberEval(3000), 30.0); @@ -55,30 +56,27 @@ public final class TestPercentEval extends TestCase { confirm(BoolEval.TRUE, 0.01); } + @Test public void test1x1Area() { AreaEval ae = EvalFactory.createAreaEval("B2:B2", new ValueEval[] { new NumberEval(50), }); confirm(ae, 0.5); } - public void testInSpreadSheet() { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet sheet = wb.createSheet("Sheet1"); - HSSFRow row = sheet.createRow(0); - HSSFCell cell = row.createCell(0); - cell.setCellFormula("B1%"); - row.createCell(1).setCellValue(50.0); - HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); - CellValue cv; - try { - cv = fe.evaluate(cell); - } catch (RuntimeException e) { - if(e.getCause() instanceof NullPointerException) { - throw new AssertionFailedError("Identified bug 44608"); - } - // else some other unexpected error - throw e; + @Test + public void testInSpreadSheet() throws IOException { + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet sheet = wb.createSheet("Sheet1"); + HSSFRow row = sheet.createRow(0); + HSSFCell cell = row.createCell(0); + cell.setCellFormula("B1%"); + row.createCell(1).setCellValue(50.0); + + HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); + + // bug 44608 - NullPointerException + CellValue cv = fe.evaluate(cell); + assertEquals(CellType.NUMERIC, cv.getCellType()); + assertEquals(0.5, cv.getNumberValue(), 0.0); } - assertEquals(CellType.NUMERIC, cv.getCellType()); - assertEquals(0.5, cv.getNumberValue(), 0.0); } } diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestPowerEval.java b/src/testcases/org/apache/poi/ss/formula/eval/TestPowerEval.java index eb7e367914..1139cfac24 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/TestPowerEval.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/TestPowerEval.java @@ -17,29 +17,29 @@ package org.apache.poi.ss.formula.eval; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.ss.formula.functions.Function; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellValue; +import org.junit.Test; /** * Tests for power operator evaluator. - * - * @author Bob van den Berge */ -public final class TestPowerEval extends TestCase { - +public final class TestPowerEval { + @Test public void testPositiveValues() { confirm(0, 0, 1); confirm(1, 1, 0); confirm(9, 3, 2); } + @Test public void testNegativeValues() { confirm(-1, -1, 1); confirm(1, 1, -1); @@ -47,18 +47,22 @@ public final class TestPowerEval extends TestCase { confirm((1.0/3), 3, -1); } + @Test public void testPositiveDecimalValues() { confirm(3, 27, (1/3.0)); } + @Test public void testNegativeDecimalValues() { confirm(-3, -27, (1/3.0)); } + @Test public void testErrorValues() { confirmError(-1.00001, 1.1); } + @Test public void testInSpreadSheet() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Sheet1"); @@ -72,27 +76,27 @@ public final class TestPowerEval extends TestCase { CellValue cv = fe.evaluate(cell); assertEquals(CellType.NUMERIC, cv.getCellType()); - assertEquals(-3.0, cv.getNumberValue()); + assertEquals(-3.0, cv.getNumberValue(), 0); } private void confirm(double expected, double a, double b) { - NumberEval result = (NumberEval) evaluate(EvalInstances.Power, a, b); + NumberEval result = (NumberEval) evaluate(a, b); - assertEquals(expected, result.getNumberValue()); + assertEquals(expected, result.getNumberValue(), 0); } private void confirmError(double a, double b) { - ErrorEval result = (ErrorEval) evaluate(EvalInstances.Power, a, b); + ErrorEval result = (ErrorEval) evaluate(a, b); assertEquals("#NUM!", result.getErrorString()); } - private static ValueEval evaluate(Function instance, double... dArgs) { + private static ValueEval evaluate(double... dArgs) { ValueEval[] evalArgs; evalArgs = new ValueEval[dArgs.length]; for (int i = 0; i < evalArgs.length; i++) { evalArgs[i] = new NumberEval(dArgs[i]); } - return instance.evaluate(evalArgs, -1, (short) -1); + return EvalInstances.Power.evaluate(evalArgs, -1, (short) -1); } } diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestRangeEval.java b/src/testcases/org/apache/poi/ss/formula/eval/TestRangeEval.java index 0a06627e38..c1becf6cf3 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/TestRangeEval.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/TestRangeEval.java @@ -17,8 +17,8 @@ package org.apache.poi.ss.formula.eval; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.util.Arrays; import java.util.List; @@ -34,14 +34,13 @@ import org.apache.poi.ss.formula.ptg.AreaI.OffsetArea; import org.apache.poi.ss.usermodel.CellValue; import org.apache.poi.ss.util.AreaReference; import org.apache.poi.ss.util.CellReference; +import org.junit.Test; /** * Test for unary plus operator evaluator. - * - * @author Josh Micich */ -public final class TestRangeEval extends TestCase { - +public final class TestRangeEval { + @Test public void testPermutations() { confirm("B3", "D7", "B3:D7"); @@ -58,7 +57,7 @@ public final class TestRangeEval extends TestCase { createRefEval(refA), createRefEval(refB), }; - List versions = Arrays.asList(new SpreadsheetVersion[] {SpreadsheetVersion.EXCEL97, SpreadsheetVersion.EXCEL2007}); + List versions = Arrays.asList(SpreadsheetVersion.EXCEL97, SpreadsheetVersion.EXCEL2007); for(SpreadsheetVersion version : versions) { AreaReference ar = new AreaReference(expectedAreaRef, version); ValueEval result = EvalInstances.Range.evaluate(args, 0, (short)0); @@ -136,6 +135,7 @@ public final class TestRangeEval extends TestCase { } } + @Test public void testRangeUsingOffsetFunc_bug46948() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFRow row = wb.createSheet("Sheet1").createRow(0); @@ -151,15 +151,8 @@ public final class TestRangeEval extends TestCase { cellB1.setCellValue(1.0); // range will be C1:D1 HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); - CellValue cv; - try { - cv = fe.evaluate(cellA1); - } catch (IllegalArgumentException e) { - if (e.getMessage().equals("Unexpected ref arg class (org.apache.poi.ss.formula.LazyAreaEval)")) { - throw new AssertionFailedError("Identified bug 46948"); - } - throw e; - } + // bug 46948 - Unexpected ref arg class (org.apache.poi.ss.formula.LazyAreaEval) + CellValue cv = fe.evaluate(cellA1); assertEquals(12.0, cv.getNumberValue(), 0.0); diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestUnaryPlusEval.java b/src/testcases/org/apache/poi/ss/formula/eval/TestUnaryPlusEval.java index d060352c1e..d85332067f 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/TestUnaryPlusEval.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/TestUnaryPlusEval.java @@ -17,23 +17,23 @@ package org.apache.poi.ss.formula.eval; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; -import org.apache.poi.ss.formula.ptg.AreaPtg; import org.apache.poi.ss.formula.functions.EvalFactory; import org.apache.poi.ss.formula.functions.NumericFunctionInvoker; +import org.apache.poi.ss.formula.ptg.AreaPtg; +import org.junit.Test; /** * Test for unary plus operator evaluator. - * - * @author Josh Micich */ -public final class TestUnaryPlusEval extends TestCase { +public final class TestUnaryPlusEval { /** * Test for bug observable at svn revision 618865 (5-Feb-2008)
    * The code for handling column operands had been copy-pasted from the row handling code. */ + @Test public void testColumnOperand() { short firstRow = (short)8; diff --git a/src/testcases/org/apache/poi/ss/formula/function/TestFunctionMetadataRegistry.java b/src/testcases/org/apache/poi/ss/formula/function/TestFunctionMetadataRegistry.java index b050401d99..dcf2277796 100644 --- a/src/testcases/org/apache/poi/ss/formula/function/TestFunctionMetadataRegistry.java +++ b/src/testcases/org/apache/poi/ss/formula/function/TestFunctionMetadataRegistry.java @@ -17,14 +17,13 @@ package org.apache.poi.ss.formula.function; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; -/** - * - * @author Josh Micich - */ -public final class TestFunctionMetadataRegistry extends TestCase { +import org.junit.Test; +public final class TestFunctionMetadataRegistry { + @Test public void testWellKnownFunctions() { confirmFunction(0, "COUNT"); confirmFunction(1, "IF"); diff --git a/src/testcases/org/apache/poi/ss/formula/function/TestParseMissingBuiltInFuncs.java b/src/testcases/org/apache/poi/ss/formula/function/TestParseMissingBuiltInFuncs.java index 38afaaa9cb..554afa9751 100644 --- a/src/testcases/org/apache/poi/ss/formula/function/TestParseMissingBuiltInFuncs.java +++ b/src/testcases/org/apache/poi/ss/formula/function/TestParseMissingBuiltInFuncs.java @@ -18,6 +18,7 @@ package org.apache.poi.ss.formula.function; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import java.io.IOException; @@ -29,7 +30,6 @@ import org.apache.poi.ss.formula.ptg.FuncVarPtg; import org.apache.poi.ss.formula.ptg.Ptg; import org.junit.Test; -import junit.framework.AssertionFailedError; /** * Tests parsing of some built-in functions that were not properly * registered in POI as of bug #44675, #44733 (March/April 2008). @@ -42,33 +42,30 @@ public final class TestParseMissingBuiltInFuncs { book.close(); return ptgs; } - + private static void confirmFunc(String formula, int expPtgArraySize, boolean isVarArgFunc, int funcIx) throws IOException { Ptg[] ptgs = parse(formula); Ptg ptgF = ptgs[ptgs.length-1]; // func is last RPN token in all these formulas - + // Check critical things in the Ptg array encoding. if(!(ptgF instanceof AbstractFunctionPtg)) { throw new RuntimeException("function token missing"); } AbstractFunctionPtg func = (AbstractFunctionPtg) ptgF; - if(func.getFunctionIndex() == 255) { - throw new AssertionFailedError("Failed to recognise built-in function in formula '" - + formula + "'"); - } + assertNotEquals("Failed to recognise built-in function in formula", 255, func.getFunctionIndex()); assertEquals(expPtgArraySize, ptgs.length); assertEquals(funcIx, func.getFunctionIndex()); Class expCls = isVarArgFunc ? FuncVarPtg.class : FuncPtg.class; assertEquals(expCls, ptgF.getClass()); - + // check that parsed Ptg array converts back to formula text OK HSSFWorkbook book = new HSSFWorkbook(); String reRenderedFormula = HSSFFormulaParser.toFormulaString(book, ptgs); assertEquals(formula, reRenderedFormula); book.close(); } - + @Test public void testDatedif() throws IOException { int expSize = 4; // NB would be 5 if POI added tAttrVolatile properly @@ -79,12 +76,12 @@ public final class TestParseMissingBuiltInFuncs { public void testDdb() throws IOException { confirmFunc("DDB(1,1,1,1,1)", 6, true, 144); } - + @Test public void testAtan() throws IOException { confirmFunc("ATAN(1)", 2, false, 18); } - + @Test public void testUsdollar() throws IOException { confirmFunc("USDOLLAR(1)", 2, true, 204); @@ -94,12 +91,12 @@ public final class TestParseMissingBuiltInFuncs { public void testDBCS() throws IOException { confirmFunc("DBCS(\"abc\")", 2, false, 215); } - + @Test public void testIsnontext() throws IOException { confirmFunc("ISNONTEXT(\"abc\")", 2, false, 190); } - + @Test public void testDproduct() throws IOException { confirmFunc("DPRODUCT(C1:E5,\"HarvestYield\",G1:H2)", 4, false, 189); diff --git a/src/testcases/org/apache/poi/ss/formula/functions/NumericFunctionInvoker.java b/src/testcases/org/apache/poi/ss/formula/functions/NumericFunctionInvoker.java index 8dc432eb49..e53f88e1fb 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/NumericFunctionInvoker.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/NumericFunctionInvoker.java @@ -17,17 +17,15 @@ package org.apache.poi.ss.formula.functions; -import junit.framework.AssertionFailedError; +import static org.junit.Assert.fail; import org.apache.poi.ss.formula.eval.ErrorEval; +import org.apache.poi.ss.formula.eval.NotImplementedException; import org.apache.poi.ss.formula.eval.NumericValueEval; import org.apache.poi.ss.formula.eval.ValueEval; -import org.apache.poi.ss.formula.eval.NotImplementedException; /** * Test helper class for invoking functions with numeric results. - * - * @author Josh Micich */ public final class NumericFunctionInvoker { @@ -64,8 +62,8 @@ public final class NumericFunctionInvoker { try { return invokeInternal(f, args, srcCellRow, srcCellCol); } catch (NumericEvalEx e) { - throw new AssertionFailedError("Evaluation of function (" + f.getClass().getName() - + ") failed: " + e.getMessage()); + fail("Evaluation of function (" + f.getClass().getName() + ") failed: " + e.getMessage()); + return -1; } } /** @@ -96,16 +94,9 @@ public final class NumericFunctionInvoker { NumericValueEval result = (NumericValueEval) evalResult; return result.getNumberValue(); } + private static String formatErrorMessage(ErrorEval ee) { - if(errorCodesAreEqual(ee, ErrorEval.VALUE_INVALID)) { - return "Error code: #VALUE! (invalid value)"; - } - return "Error code=" + ee.getErrorCode(); - } - private static boolean errorCodesAreEqual(ErrorEval a, ErrorEval b) { - if(a==b) { - return true; - } - return a.getErrorCode() == b.getErrorCode(); + boolean b = (ee == ErrorEval.VALUE_INVALID || ee.getErrorCode() == ErrorEval.VALUE_INVALID.getErrorCode()); + return b ? "Error code: #VALUE! (invalid value)" : "Error code=" + ee.getErrorCode(); } } diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestCalendarFieldFunction.java b/src/testcases/org/apache/poi/ss/formula/functions/TestCalendarFieldFunction.java index 2fa92b0b16..1180c2dbcd 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestCalendarFieldFunction.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestCalendarFieldFunction.java @@ -19,7 +19,6 @@ package org.apache.poi.ss.formula.functions; import static org.junit.Assert.assertEquals; -import junit.framework.AssertionFailedError; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; import org.apache.poi.hssf.usermodel.HSSFSheet; @@ -109,9 +108,7 @@ public final class TestCalendarFieldFunction { cell11.setCellFormula(formulaText); evaluator.clearAllCachedResultValues(); CellValue cv = evaluator.evaluate(cell11); - if (cv.getCellType() != CellType.NUMERIC) { - throw new AssertionFailedError("Wrong result type: " + cv.formatAsString()); - } + assertEquals("Wrong result type", CellType.NUMERIC, cv.getCellType()); double actualValue = cv.getNumberValue(); assertEquals(expectedResult, actualValue, 0); } diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestCountFuncs.java b/src/testcases/org/apache/poi/ss/formula/functions/TestCountFuncs.java index 409888031b..36a6f8dfa1 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestCountFuncs.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestCountFuncs.java @@ -22,7 +22,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import junit.framework.AssertionFailedError; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; @@ -152,9 +151,7 @@ public final class TestCountFuncs { assertNotNull(mp); StringEval seA = new StringEval("aa"); // this should not match the criteria '<>aa' StringEval seB = new StringEval("bb"); // this should match - if (mp.matches(seA) && !mp.matches(seB)) { - throw new AssertionFailedError("Identified bug 46647"); - } + assertFalse("Identified bug 46647", mp.matches(seA) && !mp.matches(seB)); assertFalse(mp.matches(seA)); assertTrue(mp.matches(seB)); @@ -280,16 +277,19 @@ public final class TestCountFuncs { I_MatchPredicate mp; mp = Countif.createCriteriaPredicate(ev, 9, srcColIx); + assertNotNull(mp); confirmPredicate(true, mp, srcColIx); confirmPredicate(false, mp, "abc"); confirmPredicate(false, mp, ErrorEval.DIV_ZERO); mp = Countif.createCriteriaPredicate(ev, 10, srcColIx); + assertNotNull(mp); confirmPredicate(false, mp, srcColIx); confirmPredicate(true, mp, "abc"); confirmPredicate(false, mp, ErrorEval.DIV_ZERO); mp = Countif.createCriteriaPredicate(ev, 11, srcColIx); + assertNotNull(mp); confirmPredicate(false, mp, srcColIx); confirmPredicate(false, mp, "abc"); confirmPredicate(true, mp, ErrorEval.DIV_ZERO); @@ -298,6 +298,7 @@ public final class TestCountFuncs { // tricky: indexing outside of A10:A12 // even this #VALUE! error gets used by COUNTIF as valid criteria mp = Countif.createCriteriaPredicate(ev, 12, srcColIx); + assertNotNull(mp); confirmPredicate(false, mp, srcColIx); confirmPredicate(false, mp, "abc"); confirmPredicate(false, mp, ErrorEval.DIV_ZERO); @@ -396,7 +397,7 @@ public final class TestCountFuncs { * and NEQ cases */ @Test - public void testCountifBug51498() throws Exception { + public void testCountifBug51498() { final int REF_COL = 4; final int EVAL_COL = 3; @@ -588,9 +589,6 @@ public final class TestCountFuncs { } } - if (failureCount > 0) { - throw new AssertionFailedError(failureCount + " " + functionName - + " evaluations failed. See stderr for more details"); - } + assertEquals(failureCount + " " + functionName + " evaluations failed.", 0, failureCount); } } diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestDate.java b/src/testcases/org/apache/poi/ss/formula/functions/TestDate.java index 536697170c..f1b528d2c9 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestDate.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestDate.java @@ -19,7 +19,6 @@ package org.apache.poi.ss.formula.functions; import static org.junit.Assert.assertEquals; -import junit.framework.AssertionFailedError; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; import org.apache.poi.hssf.usermodel.HSSFSheet; @@ -50,6 +49,7 @@ public final class TestDate { * Test disabled pending a fix in the formula evaluator * TODO - create MissingArgEval and modify the formula evaluator to handle this */ + @Test @Ignore public void testSomeArgumentsMissing() { confirm("DATE(, 1, 0)", 0.0); @@ -58,7 +58,6 @@ public final class TestDate { @Test public void testValid() { - confirm("DATE(1900, 1, 1)", 1); confirm("DATE(1900, 1, 32)", 32); confirm("DATE(1900, 222, 1)", 6727); @@ -88,9 +87,7 @@ public final class TestDate { cell11.setCellFormula(formulaText); evaluator.clearAllCachedResultValues(); CellValue cv = evaluator.evaluate(cell11); - if (cv.getCellType() != CellType.NUMERIC) { - throw new AssertionFailedError("Wrong result type: " + cv.formatAsString()); - } + assertEquals("Wrong result type", CellType.NUMERIC, cv.getCellType()); double actualValue = cv.getNumberValue(); assertEquals(expectedResult, actualValue, 0); } diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestIndex.java b/src/testcases/org/apache/poi/ss/formula/functions/TestIndex.java index 04ed1e7223..fbb63dc0bd 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestIndex.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestIndex.java @@ -22,7 +22,6 @@ import static org.junit.Assert.assertTrue; import java.util.Arrays; -import junit.framework.AssertionFailedError; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.formula.WorkbookEvaluator; @@ -45,8 +44,6 @@ import org.junit.Test; * with minimum overhead.
    * Another test: {@link TestIndexFunctionFromSpreadsheet} operates from a higher level * and has far greater coverage of input permutations.
    - * - * @author Josh Micich */ public final class TestIndex { @@ -121,15 +118,8 @@ public final class TestIndex { }; AreaEval arg0 = EvalFactory.createAreaEval("A10:C10", values); ValueEval[] args = new ValueEval[] { arg0, MissingArgEval.instance, new NumberEval(2), }; - ValueEval actualResult; - try { - actualResult = FUNC_INST.evaluate(args, -1, -1); - } catch (RuntimeException e) { - if (e.getMessage().equals("Unexpected arg eval type (org.apache.poi.hssf.record.formula.eval.MissingArgEval")) { - throw new AssertionFailedError("Identified bug 47048b - INDEX() should support missing-arg"); - } - throw e; - } + // Identified bug 47048b - INDEX() should support missing-arg + ValueEval actualResult = FUNC_INST.evaluate(args, -1, -1); // result should be an area eval "B10:B10" AreaEval ae = confirmAreaEval("B10:B10", actualResult); actualResult = ae.getValue(0, 0); diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestIrr.java b/src/testcases/org/apache/poi/ss/formula/functions/TestIrr.java index ec01268fa8..9dc7558485 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestIrr.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestIrr.java @@ -19,7 +19,6 @@ package org.apache.poi.ss.formula.functions; import static org.junit.Assert.assertEquals; -import junit.framework.AssertionFailedError; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; @@ -32,8 +31,6 @@ import org.junit.Test; /** * Tests for {@link Irr} - * - * @author Marcel May */ public final class TestIrr { @@ -123,10 +120,7 @@ public final class TestIrr { } } - if(failures.length() > 0) { - throw new AssertionFailedError(failureCount + " IRR assertions failed:\n" + failures); - } - + assertEquals("IRR assertions failed", 0, failures.length()); } private static void assertFormulaResult(CellValue cv, HSSFCell cell){ diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestMirr.java b/src/testcases/org/apache/poi/ss/formula/functions/TestMirr.java index a8bdd77097..5a5d123fff 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestMirr.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestMirr.java @@ -18,8 +18,8 @@ package org.apache.poi.ss.formula.functions; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; -import junit.framework.AssertionFailedError; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; @@ -42,48 +42,36 @@ import org.junit.Test; public final class TestMirr { @Test - public void testMirr() { + public void testMirr() throws EvaluationException { Mirr mirr = new Mirr(); double mirrValue; double financeRate = 0.12; double reinvestRate = 0.1; double[] values = {-120000d, 39000d, 30000d, 21000d, 37000d, 46000d, reinvestRate, financeRate}; - try { - mirrValue = mirr.evaluate(values); - } catch (EvaluationException e) { - throw new AssertionFailedError("MIRR should not failed with these parameters" + e); - } + // MIRR should not failed with these parameters + mirrValue = mirr.evaluate(values); assertEquals("mirr", 0.126094130366, mirrValue, 0.0000000001); reinvestRate = 0.05; financeRate = 0.08; values = new double[]{-7500d, 3000d, 5000d, 1200d, 4000d, reinvestRate, financeRate}; - try { - mirrValue = mirr.evaluate(values); - } catch (EvaluationException e) { - throw new AssertionFailedError("MIRR should not failed with these parameters" + e); - } + // MIRR should not failed with these parameters + mirrValue = mirr.evaluate(values); assertEquals("mirr", 0.18736225093, mirrValue, 0.0000000001); reinvestRate = 0.065; financeRate = 0.1; values = new double[]{-10000, 3400d, 6500d, 1000d, reinvestRate, financeRate}; - try { - mirrValue = mirr.evaluate(values); - } catch (EvaluationException e) { - throw new AssertionFailedError("MIRR should not failed with these parameters" + e); - } + // MIRR should not failed with these parameters + mirrValue = mirr.evaluate(values); assertEquals("mirr", 0.07039493966, mirrValue, 0.0000000001); reinvestRate = 0.07; financeRate = 0.01; values = new double[]{-10000d, -3400d, -6500d, -1000d, reinvestRate, financeRate}; - try { - mirrValue = mirr.evaluate(values); - } catch (EvaluationException e) { - throw new AssertionFailedError("MIRR should not failed with these parameters" + e); - } + // MIRR should not failed with these parameters + mirrValue = mirr.evaluate(values); assertEquals("mirr", -1, mirrValue, 0.0); } @@ -101,7 +89,7 @@ public final class TestMirr { assertEquals(ErrorEval.DIV_ZERO, e.getErrorEval()); return; } - throw new AssertionFailedError("MIRR should failed with all these positives values"); + fail("MIRR should failed with all these positives values"); } @Test @@ -134,7 +122,6 @@ public final class TestMirr { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("mirrTest.xls"); HSSFSheet sheet = wb.getSheet("Mirr"); HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); - StringBuilder failures = new StringBuilder(); int failureCount = 0; int[] resultRows = {9, 19, 29, 45}; @@ -145,9 +132,6 @@ public final class TestMirr { CellValue cv = fe.evaluate(cellA); assertFormulaResult(cv, cellA); } catch (Throwable e) { - if (failures.length() > 0) failures.append('\n'); - failures.append("Row[").append(cellA.getRowIndex() + 1).append("]: ").append(cellA.getCellFormula()).append(" "); - failures.append(e.getMessage()); failureCount++; } } @@ -157,10 +141,7 @@ public final class TestMirr { CellValue cv = fe.evaluate(cellA); assertEquals(ErrorEval.DIV_ZERO.getErrorCode(), cv.getErrorValue()); - if (failures.length() > 0) { - throw new AssertionFailedError(failureCount + " IRR assertions failed:\n" + failures); - } - + assertEquals("IRR assertions failed", 0, failureCount); } private static void assertFormulaResult(CellValue cv, HSSFCell cell) { diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestNpv.java b/src/testcases/org/apache/poi/ss/formula/functions/TestNpv.java index 8d3f6c287b..4df5bc898d 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestNpv.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestNpv.java @@ -19,7 +19,6 @@ package org.apache.poi.ss.formula.functions; import static org.junit.Assert.assertEquals; -import junit.framework.AssertionFailedError; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; @@ -32,7 +31,6 @@ import org.junit.Test; /** * Tests for {@link Npv} * - * @author Marcel May * @see Excel Help */ public final class TestNpv { @@ -79,7 +77,6 @@ public final class TestNpv { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("IrrNpvTestCaseData.xls"); HSSFSheet sheet = wb.getSheet("IRR-NPV"); HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); - StringBuilder failures = new StringBuilder(); int failureCount = 0; // TODO YK: Formulas in rows 16 and 17 operate with ArrayPtg which isn't yet supported // FormulaEvaluator as of r1041407 throws "Unexpected ptg class (org.apache.poi.ss.formula.ptg.ArrayPtg)" @@ -90,16 +87,11 @@ public final class TestNpv { CellValue cv = fe.evaluate(cellB); assertFormulaResult(cv, cellB); } catch (Throwable e){ - if(failures.length() > 0) failures.append('\n'); - failures.append("Row[" + (cellB.getRowIndex() + 1)+ "]: " + cellB.getCellFormula() + " "); - failures.append(e.getMessage()); failureCount++; } } - if(failures.length() > 0) { - throw new AssertionFailedError(failureCount + " IRR evaluations failed:\n" + failures); - } + assertEquals("IRR evaluations failed", 0, failureCount); } private static void assertFormulaResult(CellValue cv, HSSFCell cell){ diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java b/src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java index 3c3536a273..b489cdcb4b 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java @@ -20,23 +20,21 @@ */ package org.apache.poi.ss.formula.functions; -import junit.framework.AssertionFailedError; +import static org.junit.Assert.assertNotNull; + import org.apache.poi.ss.formula.eval.ErrorEval; import org.apache.poi.ss.formula.eval.EvaluationException; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; -/** - * @author Amol S. Deshmukh < amolweb at ya hoo dot com > - * - */ public class TestStatsLib extends AbstractNumericTestCase { @Test public void testDevsq() { - double[] v = null; - double d, x = 0; + double[] v; + double d, x; v = new double[] {1,2,3,4,5,6,7,8,9,10}; d = StatsLib.devsq(v); @@ -71,8 +69,8 @@ public class TestStatsLib extends AbstractNumericTestCase { @Test public void testKthLargest() { - double[] v = null; - double d, x = 0; + double[] v; + double d, x; v = new double[] {1,2,3,4,5,6,7,8,9,10}; d = StatsLib.kthLargest(v, 3); @@ -105,13 +103,15 @@ public class TestStatsLib extends AbstractNumericTestCase { assertEquals("kthLargest ", x, d); } + @Test + @Ignore("... implement ...") public void testKthSmallest() { } @Test public void testAvedev() { - double[] v = null; - double d, x = 0; + double[] v; + double d, x; v = new double[] {1,2,3,4,5,6,7,8,9,10}; d = StatsLib.avedev(v); @@ -146,8 +146,8 @@ public class TestStatsLib extends AbstractNumericTestCase { @Test public void testMedian() { - double[] v = null; - double d, x = 0; + double[] v; + double d, x; v = new double[] {1,2,3,4,5,6,7,8,9,10}; d = StatsLib.median(v); @@ -193,7 +193,6 @@ public class TestStatsLib extends AbstractNumericTestCase { @Test public void testMode() { double[] v; - double d, x = 0; v = new double[] {1,2,3,4,5,6,7,8,9,10}; confirmMode(v, null); @@ -228,9 +227,7 @@ public class TestStatsLib extends AbstractNumericTestCase { double actual; try { actual = Mode.evaluate(v); - if (expectedResult == null) { - throw new AssertionFailedError("Expected N/A exception was not thrown"); - } + assertNotNull("Expected N/A exception was not thrown", expectedResult); } catch (EvaluationException e) { if (expectedResult == null) { Assert.assertEquals(ErrorEval.NA, e.getErrorEval()); @@ -243,8 +240,8 @@ public class TestStatsLib extends AbstractNumericTestCase { @Test public void testStddev() { - double[] v = null; - double d, x = 0; + double[] v; + double d, x; v = new double[] {1,2,3,4,5,6,7,8,9,10}; d = StatsLib.stdev(v); @@ -279,8 +276,8 @@ public class TestStatsLib extends AbstractNumericTestCase { @Test public void testVar() { - double[] v = null; - double d, x = 0; + double[] v; + double d, x; v = new double[] {3.50, 5.00, 7.23, 2.99}; d = StatsLib.var(v); @@ -305,8 +302,8 @@ public class TestStatsLib extends AbstractNumericTestCase { @Test public void testVarp() { - double[] v = null; - double d, x = 0; + double[] v; + double d, x; v = new double[] {3.50, 5.00, 7.23, 2.99}; d = StatsLib.varp(v); diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestSumif.java b/src/testcases/org/apache/poi/ss/formula/functions/TestSumif.java index b0d1483e54..7f5aabcbd5 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestSumif.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestSumif.java @@ -18,8 +18,9 @@ package org.apache.poi.ss.formula.functions; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; -import junit.framework.AssertionFailedError; import org.apache.poi.ss.formula.eval.AreaEval; import org.apache.poi.ss.formula.eval.BlankEval; import org.apache.poi.ss.formula.eval.ErrorEval; @@ -31,8 +32,6 @@ import org.junit.Test; /** * Test cases for SUMPRODUCT() - * - * @author Josh Micich */ public final class TestSumif { private static final NumberEval _30 = new NumberEval(30); @@ -45,9 +44,7 @@ public final class TestSumif { } private static void confirmDouble(double expected, ValueEval actualEval) { - if(!(actualEval instanceof NumericValueEval)) { - throw new AssertionFailedError("Expected numeric result"); - } + assertTrue("Expected numeric result", actualEval instanceof NumericValueEval); NumericValueEval nve = (NumericValueEval)actualEval; assertEquals(expected, nve.getNumberValue(), 0); } @@ -99,9 +96,7 @@ public final class TestSumif { ve = invokeSumif(0, 2, arg0, arg1); // invoking from cell C1 if (ve instanceof NumberEval) { NumberEval ne = (NumberEval) ve; - if (ne.getNumberValue() == 30.0) { - throw new AssertionFailedError("identified error in SUMIF - criteria arg not evaluated properly"); - } + assertNotEquals("identified error in SUMIF - criteria arg not evaluated properly", 30.0, ne.getNumberValue()); } confirmDouble(200, ve); diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestSumifs.java b/src/testcases/org/apache/poi/ss/formula/functions/TestSumifs.java index c9d640f91f..4e441a066e 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestSumifs.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestSumifs.java @@ -22,7 +22,6 @@ package org.apache.poi.ss.formula.functions; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import junit.framework.AssertionFailedError; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; @@ -38,27 +37,23 @@ import org.junit.Test; /** * Test cases for SUMIFS() - * - * @author Yegor Kozlov */ public final class TestSumifs { private static final OperationEvaluationContext EC = new OperationEvaluationContext(null, null, 0, 1, 0, null); - private static ValueEval invokeSumifs(ValueEval[] args, OperationEvaluationContext ec) { + private static ValueEval invokeSumifs(ValueEval[] args) { return new Sumifs().evaluate(args, EC); } private static void confirmDouble(double expected, ValueEval actualEval) { - if(!(actualEval instanceof NumericValueEval)) { - throw new AssertionFailedError("Expected numeric result"); - } + assertTrue("Expected numeric result", actualEval instanceof NumericValueEval); NumericValueEval nve = (NumericValueEval)actualEval; assertEquals(expected, nve.getNumberValue(), 0); } private static void confirm(double expectedResult, ValueEval[] args) { - confirmDouble(expectedResult, invokeSumifs(args, EC)); + confirmDouble(expectedResult, invokeSumifs(args)); } /** @@ -140,7 +135,7 @@ public final class TestSumifs { EvalFactory.createAreaEval("C2:C9", c2c9), new NumberEval(1), }; - assertEquals(ErrorEval.VALUE_INVALID, invokeSumifs(args, EC)); + assertEquals(ErrorEval.VALUE_INVALID, invokeSumifs(args)); } @@ -189,6 +184,8 @@ public final class TestSumifs { new StringEval(">0.03"), // 3% in the MSFT example EvalFactory.createAreaEval("B4:E4", b4e4), new StringEval(">=0.02"), // 2% in the MSFT example + EvalFactory.createAreaEval("B5:E5", b5e5), + new StringEval(">=0.01"), // 1% in the MSFT example }; confirm(500.0, args); } @@ -299,7 +296,7 @@ public final class TestSumifs { new StringEval("A*"), }; - ValueEval result = invokeSumifs(args, EC); + ValueEval result = invokeSumifs(args); assertTrue("Expect to have an error when an input is an invalid value, but had: " + result.getClass(), result instanceof ErrorEval); args = new ValueEval[]{ @@ -308,7 +305,7 @@ public final class TestSumifs { ErrorEval.VALUE_INVALID, }; - result = invokeSumifs(args, EC); + result = invokeSumifs(args); assertTrue("Expect to have an error when an input is an invalid value, but had: " + result.getClass(), result instanceof ErrorEval); } @@ -332,7 +329,7 @@ public final class TestSumifs { ErrorEval.VALUE_INVALID }; - ValueEval result = invokeSumifs(args, EC); + ValueEval result = invokeSumifs(args); assertTrue("Expect to have an error when an input is an invalid value, but had: " + result.getClass(), result instanceof ErrorEval); assertEquals(ErrorEval.VALUE_INVALID, result); } @@ -357,7 +354,7 @@ public final class TestSumifs { ErrorEval.NAME_INVALID }; - ValueEval result = invokeSumifs(args, EC); + ValueEval result = invokeSumifs(args); assertTrue("Expect to have an error when an input is an invalid value, but had: " + result.getClass(), result instanceof ErrorEval); assertEquals(ErrorEval.NAME_INVALID, result); } diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/AbstractPtgTestCase.java b/src/testcases/org/apache/poi/ss/formula/ptg/AbstractPtgTestCase.java index 1e4abfae08..d03a4e269a 100644 --- a/src/testcases/org/apache/poi/ss/formula/ptg/AbstractPtgTestCase.java +++ b/src/testcases/org/apache/poi/ss/formula/ptg/AbstractPtgTestCase.java @@ -17,18 +17,14 @@ package org.apache.poi.ss.formula.ptg; -import junit.framework.TestCase; - import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFWorkbook; /** * Convenient abstract class to reduce the amount of boilerplate code needed * in ptg-related unit tests. - * - * @author Daniel Noll (daniel at nuix dot com dot au) */ -public abstract class AbstractPtgTestCase extends TestCase { +public abstract class AbstractPtgTestCase { /** * Loads a workbook from the given filename in the test data dir. diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestArea3DPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestArea3DPtg.java index bb11807e57..c06f7f7b35 100644 --- a/src/testcases/org/apache/poi/ss/formula/ptg/TestArea3DPtg.java +++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestArea3DPtg.java @@ -17,32 +17,37 @@ package org.apache.poi.ss.formula.ptg; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.junit.Test; /** * Tests for Area3DPtg - * - * @author Josh Micich */ public final class TestArea3DPtg extends AbstractPtgTestCase { /** * confirms that sheet names get properly escaped */ - public void testToFormulaString() { + @Test + public void testToFormulaString() throws IOException { Area3DPtg target = new Area3DPtg("A1:B1", (short)0); String sheetName = "my sheet"; - HSSFWorkbook wb = createWorkbookWithSheet(sheetName); - HSSFEvaluationWorkbook book = HSSFEvaluationWorkbook.create(wb); - assertEquals("'my sheet'!A1:B1", target.toFormulaString(book)); + try (HSSFWorkbook wb = createWorkbookWithSheet(sheetName)) { + HSSFEvaluationWorkbook book = HSSFEvaluationWorkbook.create(wb); + assertEquals("'my sheet'!A1:B1", target.toFormulaString(book)); - wb.setSheetName(0, "Sheet1"); - assertEquals("Sheet1!A1:B1", target.toFormulaString(book)); + wb.setSheetName(0, "Sheet1"); + assertEquals("Sheet1!A1:B1", target.toFormulaString(book)); - wb.setSheetName(0, "C64"); - assertEquals("'C64'!A1:B1", target.toFormulaString(book)); + wb.setSheetName(0, "C64"); + assertEquals("'C64'!A1:B1", target.toFormulaString(book)); + } } } diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestAreaErrPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestAreaErrPtg.java index e8032cb23c..028ed03d3f 100644 --- a/src/testcases/org/apache/poi/ss/formula/ptg/TestAreaErrPtg.java +++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestAreaErrPtg.java @@ -17,20 +17,25 @@ package org.apache.poi.ss.formula.ptg; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.junit.Test; /** * Tests for {@link AreaErrPtg}. - * - * @author Daniel Noll (daniel at nuix dot com dot au) */ public final class TestAreaErrPtg extends AbstractPtgTestCase { /** * Tests reading a file containing this ptg. */ - public void testReading() { - HSSFWorkbook workbook = loadWorkbook("AreaErrPtg.xls"); - assertEquals("Wrong formula string for area error", "SUM(#REF!)", - workbook.getSheetAt(0).getRow(0).getCell(2).getCellFormula()); + @Test + public void testReading() throws IOException { + try (HSSFWorkbook workbook = loadWorkbook("AreaErrPtg.xls")) { + assertEquals("Wrong formula string for area error", "SUM(#REF!)", + workbook.getSheetAt(0).getRow(0).getCell(2).getCellFormula()); + } } } diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestAreaPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestAreaPtg.java index 1192b7ed9b..d0cdb507c1 100644 --- a/src/testcases/org/apache/poi/ss/formula/ptg/TestAreaPtg.java +++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestAreaPtg.java @@ -1,4 +1,4 @@ - + /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -18,25 +18,25 @@ package org.apache.poi.ss.formula.ptg; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; import org.apache.poi.hssf.model.HSSFFormulaParser; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.util.AreaReference; +import org.junit.Before; +import org.junit.Test; /** * Tests for {@link AreaPtg}. - * - * @author Dmitriy Kumshayev */ -public final class TestAreaPtg extends TestCase { +public final class TestAreaPtg { AreaPtg relative; AreaPtg absolute; - - @Override - protected void setUp() { + + @Before + public void setUp() { short firstRow=5; short lastRow=13; short firstCol=7; @@ -44,8 +44,9 @@ public final class TestAreaPtg extends TestCase { relative = new AreaPtg(firstRow,lastRow,firstCol,lastCol,true,true,true,true); absolute = new AreaPtg(firstRow,lastRow,firstCol,lastCol,false,false,false,false); } - - public static void testSortTopLeftToBottomRight() { + + @Test + public void testSortTopLeftToBottomRight() { AreaPtg ptg = new AreaPtg(new AreaReference("A$1:$B5", SpreadsheetVersion.EXCEL2007)); assertEquals("A$1:$B5", ptg.toFormulaString()); ptg.setFirstColumn(3); @@ -56,19 +57,19 @@ public final class TestAreaPtg extends TestCase { "$B$1:D5", ptg.toFormulaString()); } - public void testSetColumnsAbsolute() - { + @Test + public void testSetColumnsAbsolute() { resetColumns(absolute); validateReference(true, absolute); } - public void testSetColumnsRelative() - { + + @Test + public void testSetColumnsRelative() { resetColumns(relative); validateReference(false, relative); } - private void validateReference(boolean abs, AreaPtg ref) - { + private void validateReference(boolean abs, AreaPtg ref) { assertEquals("First column reference is not "+(abs?"absolute":"relative"),abs,!ref.isFirstColRelative()); assertEquals("Last column reference is not "+(abs?"absolute":"relative"),abs,!ref.isLastColRelative()); assertEquals("First row reference is not "+(abs?"absolute":"relative"),abs,!ref.isFirstRowRelative()); @@ -84,7 +85,8 @@ public final class TestAreaPtg extends TestCase { assertEquals(fc , aptg.getFirstColumn() ); assertEquals(lc , aptg.getLastColumn() ); } - + + @Test public void testAbsoluteRelativeRefs() { AreaPtg sca1 = new AreaPtg(4, 5, 6, 7, true, false, true, false); AreaPtg sca2 = new AreaPtg(4, 5, 6, 7, false, true, false, true); @@ -106,27 +108,27 @@ public final class TestAreaPtg extends TestCase { assertEquals("first rel., last abs.", "H6:$H$6", cla3.toFormulaString()); assertEquals("first abs., last rel.", "$H$6:H6", cla4.toFormulaString()); } - private AreaPtg cloneArea(AreaPtg a) - { + + private AreaPtg cloneArea(AreaPtg a) { return new AreaPtg( a.getFirstRow(), a.getLastRow(), a.getFirstColumn(), a.getLastColumn(), a.isFirstRowRelative(), a.isLastRowRelative(), a.isFirstColRelative(), a.isLastColRelative() ); } - - public void testFormulaParser() - { + + @Test + public void testFormulaParser() { String formula1="SUM($E$5:$E$6)"; String expectedFormula1="SUM($F$5:$F$6)"; String newFormula1 = shiftAllColumnsBy1(formula1); assertEquals("Absolute references changed", expectedFormula1, newFormula1); - + String formula2="SUM(E5:E6)"; String expectedFormula2="SUM(F5:F6)"; String newFormula2 = shiftAllColumnsBy1(formula2); assertEquals("Relative references changed", expectedFormula2, newFormula2); } - + private static String shiftAllColumnsBy1(String formula) { int letUsShiftColumn1By1Column=1; HSSFWorkbook wb = null; diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestArrayPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestArrayPtg.java index 36783a4c50..d59e0c1866 100644 --- a/src/testcases/org/apache/poi/ss/formula/ptg/TestArrayPtg.java +++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestArrayPtg.java @@ -18,20 +18,20 @@ package org.apache.poi.ss.formula.ptg; import static org.junit.Assert.assertArrayEquals; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.record.TestcaseRecordInputStream; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.util.LittleEndianByteArrayOutputStream; import org.apache.poi.util.LittleEndianInput; +import org.junit.Test; + /** * Tests for ArrayPtg - * - * @author Josh Micich */ -public final class TestArrayPtg extends TestCase { +public final class TestArrayPtg { private static final byte[] ENCODED_PTG_DATA = { 0x40, @@ -56,6 +56,7 @@ public final class TestArrayPtg extends TestCase { /** * Lots of problems with ArrayPtg's decoding and encoding of the element value data */ + @Test public void testReadWriteTokenValueBytes() { ArrayPtg ptg = create(ENCODED_PTG_DATA, ENCODED_CONSTANT_DATA); assertEquals(3, ptg.getColumnCount()); @@ -73,9 +74,7 @@ public final class TestArrayPtg extends TestCase { byte[] outBuf = new byte[ENCODED_CONSTANT_DATA.length]; ptg.writeTokenValueBytes(new LittleEndianByteArrayOutputStream(outBuf, 0)); - if(outBuf[0] == 4) { - throw new AssertionFailedError("Identified bug 42564b"); - } + assertNotEquals("Identified bug 42564b", 4, outBuf[0]); assertArrayEquals(ENCODED_CONSTANT_DATA, outBuf); } @@ -83,6 +82,7 @@ public final class TestArrayPtg extends TestCase { /** * Excel stores array elements column by column. This test makes sure POI does the same. */ + @Test public void testElementOrdering() { ArrayPtg ptg = create(ENCODED_PTG_DATA, ENCODED_CONSTANT_DATA); assertEquals(3, ptg.getColumnCount()); @@ -100,35 +100,29 @@ public final class TestArrayPtg extends TestCase { * Test for a bug which was temporarily introduced by the fix for bug 42564. * A spreadsheet was added to make the ordering clearer. */ + @Test public void testElementOrderingInSpreadsheet() { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex42564-elementOrder.xls"); // The formula has an array with 3 rows and 5 columns String formula = wb.getSheetAt(0).getRow(0).getCell(0).getCellFormula(); - if (formula.equals("SUM({1,6,11;2,7,12;3,8,13;4,9,14;5,10,15})")) { - throw new AssertionFailedError("Identified bug 42564 b"); - } + assertNotEquals("Identified bug 42564 b", "SUM({1,6,11;2,7,12;3,8,13;4,9,14;5,10,15})", formula); assertEquals("SUM({1,2,3,4,5;6,7,8,9,10;11,12,13,14,15})", formula); } + @Test public void testToFormulaString() { ArrayPtg ptg = create(ENCODED_PTG_DATA, ENCODED_CONSTANT_DATA); - String actualFormula; - try { - actualFormula = ptg.toFormulaString(); - } catch (IllegalArgumentException e) { - if (e.getMessage().equals("Unexpected constant class (java.lang.Boolean)")) { - throw new AssertionFailedError("Identified bug 45380"); - } - throw e; - } + // bug 45380 - Unexpected constant class (java.lang.Boolean) + String actualFormula = ptg.toFormulaString(); assertEquals("{TRUE,\"ABCD\",\"E\";0,FALSE,\"FG\"}", actualFormula); } /** * worth checking since AttrPtg.sid=0x20 and Ptg.CLASS_* = (0x00, 0x20, and 0x40) */ + @Test public void testOperandClassDecoding() { confirmOperandClassDecoding(Ptg.CLASS_REF); confirmOperandClassDecoding(Ptg.CLASS_VALUE); diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestAttrPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestAttrPtg.java index 6146449fcc..b7b058007a 100644 --- a/src/testcases/org/apache/poi/ss/formula/ptg/TestAttrPtg.java +++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestAttrPtg.java @@ -18,32 +18,28 @@ package org.apache.poi.ss.formula.ptg; import static org.junit.Assert.assertArrayEquals; -import junit.framework.AssertionFailedError; import org.apache.poi.hssf.record.TestcaseRecordInputStream; import org.apache.poi.util.HexRead; import org.apache.poi.util.LittleEndianInput; +import org.junit.Test; /** * Tests for {@link AttrPtg}. - * - * @author Josh Micich */ public final class TestAttrPtg extends AbstractPtgTestCase { /** * Fix for bug visible around svn r706772. */ + @Test public void testReserializeAttrChoose() { byte[] data = HexRead.readFromString("19, 04, 03, 00, 08, 00, 11, 00, 1A, 00, 23, 00"); LittleEndianInput in = TestcaseRecordInputStream.createLittleEndian(data); Ptg[] ptgs = Ptg.readTokens(data.length, in); byte[] data2 = new byte[data.length]; - try { - Ptg.serializePtgs(ptgs, data2, 0); - } catch (ArrayIndexOutOfBoundsException e) { - throw new AssertionFailedError("incorrect re-serialization of tAttrChoose"); - } + // ArrayIndexOutOfBoundsException -> incorrect re-serialization of tAttrChoose + Ptg.serializePtgs(ptgs, data2, 0); assertArrayEquals(data, data2); } } diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestErrPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestErrPtg.java index 735ba393e5..5f9af47846 100644 --- a/src/testcases/org/apache/poi/ss/formula/ptg/TestErrPtg.java +++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestErrPtg.java @@ -17,22 +17,27 @@ package org.apache.poi.ss.formula.ptg; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.junit.Test; /** * Tests for {@link ErrPtg}. - * - * @author Daniel Noll (daniel at nuix dot com dot au) */ public final class TestErrPtg extends AbstractPtgTestCase { /** * Tests reading a file containing this ptg. */ - public void testReading() { - HSSFWorkbook workbook = loadWorkbook("ErrPtg.xls"); - HSSFCell cell = workbook.getSheetAt(0).getRow(3).getCell(0); - assertEquals("Wrong cell value", 4.0, cell.getNumericCellValue(), 0.0); - assertEquals("Wrong cell formula", "ERROR.TYPE(#REF!)", cell.getCellFormula()); + @Test + public void testReading() throws IOException { + try (HSSFWorkbook workbook = loadWorkbook("ErrPtg.xls")) { + HSSFCell cell = workbook.getSheetAt(0).getRow(3).getCell(0); + assertEquals("Wrong cell value", 4.0, cell.getNumericCellValue(), 0.0); + assertEquals("Wrong cell formula", "ERROR.TYPE(#REF!)", cell.getCellFormula()); + } } } diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestExternalNameReference.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestExternalNameReference.java index 2fc93ec9c7..c70e5d63c9 100644 --- a/src/testcases/org/apache/poi/ss/formula/ptg/TestExternalNameReference.java +++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestExternalNameReference.java @@ -18,70 +18,87 @@ package org.apache.poi.ss.formula.ptg; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; +import org.apache.poi.hssf.usermodel.HSSFName; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.util.CellReference; +import org.junit.Test; + /** * Tests for proper calculation of named ranges from external workbooks. - * - * - * @author Stephen Wolke (smwolke at geistig.com) */ -public final class TestExternalNameReference extends TestCase { - double MARKUP_COST = 1.9d; +public final class TestExternalNameReference { double MARKUP_COST_1 = 1.8d; double MARKUP_COST_2 = 1.5d; double PART_COST = 12.3d; double NEW_QUANT = 7.0d; double NEW_PART_COST = 15.3d; /** - * tests NameXPtg for external cell reference by name and logic in Workbook below that + * tests NameXPtg for external cell reference by name and logic in Workbook below that */ + @Test public void testReadCalcSheet() { - try{ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("XRefCalc.xls"); - assertEquals("Sheet1!$A$2", wb.getName("QUANT").getRefersToFormula()); - assertEquals("Sheet1!$B$2", wb.getName("PART").getRefersToFormula()); + HSSFName name = wb.getName("QUANT"); + assertNotNull(name); + assertEquals("Sheet1!$A$2", name.getRefersToFormula()); + name = wb.getName("PART"); + assertNotNull(name); + assertEquals("Sheet1!$B$2", name.getRefersToFormula()); assertEquals("x123",wb.getSheet("Sheet1").getRow(1).getCell(1).getStringCellValue()); - assertEquals("Sheet1!$C$2", wb.getName("UNITCOST").getRefersToFormula()); - CellReference cellRef = new CellReference(wb.getName("UNITCOST").getRefersToFormula()); + name = wb.getName("UNITCOST"); + assertNotNull(name); + assertEquals("Sheet1!$C$2", name.getRefersToFormula()); + name = wb.getName("UNITCOST"); + assertNotNull(name); + CellReference cellRef = new CellReference(name.getRefersToFormula()); HSSFCell cell = wb.getSheet(cellRef.getSheetName()).getRow(cellRef.getRow()).getCell(cellRef.getCol()); assertEquals("VLOOKUP(PART,COSTS,2,FALSE)",cell.getCellFormula()); - assertEquals("Sheet1!$D$2", wb.getName("COST").getRefersToFormula()); - cellRef = new CellReference(wb.getName("COST").getRefersToFormula()); + name = wb.getName("COST"); + assertNotNull(name); + assertEquals("Sheet1!$D$2", name.getRefersToFormula()); + name = wb.getName("COST"); + assertNotNull(name); + cellRef = new CellReference(name.getRefersToFormula()); cell = wb.getSheet(cellRef.getSheetName()).getRow(cellRef.getRow()).getCell(cellRef.getCol()); assertEquals("UNITCOST*Quant",cell.getCellFormula()); - assertEquals("Sheet1!$E$2", wb.getName("TOTALCOST").getRefersToFormula()); - cellRef = new CellReference(wb.getName("TOTALCOST").getRefersToFormula()); + name = wb.getName("TOTALCOST"); + assertNotNull(name); + assertEquals("Sheet1!$E$2", name.getRefersToFormula()); + name = wb.getName("TOTALCOST"); + assertNotNull(name); + cellRef = new CellReference(name.getRefersToFormula()); cell = wb.getSheet(cellRef.getSheetName()).getRow(cellRef.getRow()).getCell(cellRef.getCol()); assertEquals("Cost*Markup_Cost",cell.getCellFormula()); - }catch(Exception e){ - fail(); - } } - + + @Test public void testReadReferencedSheet() { - try{ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("XRefCalcData.xls"); - assertEquals("CostSheet!$A$2:$B$3", wb.getName("COSTS").getRefersToFormula()); + HSSFName name = wb.getName("COSTS"); + assertNotNull(name); + assertEquals("CostSheet!$A$2:$B$3", name.getRefersToFormula()); assertEquals("x123",wb.getSheet("CostSheet").getRow(1).getCell(0).getStringCellValue()); - assertEquals(PART_COST,wb.getSheet("CostSheet").getRow(1).getCell(1).getNumericCellValue()); - assertEquals("MarkupSheet!$B$1", wb.getName("Markup_Cost").getRefersToFormula()); - assertEquals(MARKUP_COST_1,wb.getSheet("MarkupSheet").getRow(0).getCell(1).getNumericCellValue()); - }catch(Exception e){ - fail(); - } + assertEquals(PART_COST,wb.getSheet("CostSheet").getRow(1).getCell(1).getNumericCellValue(), 0); + name = wb.getName("Markup_Cost"); + assertNotNull(name); + assertEquals("MarkupSheet!$B$1", name.getRefersToFormula()); + assertEquals(MARKUP_COST_1,wb.getSheet("MarkupSheet").getRow(0).getCell(1).getNumericCellValue(), 0); } - - public void testEvaluate() throws Exception { + + @Test + public void testEvaluate() { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("XRefCalc.xls"); HSSFWorkbook wb2 = HSSFTestDataSamples.openSampleWorkbook("XRefCalcData.xls"); - CellReference cellRef = new CellReference(wb.getName("QUANT").getRefersToFormula()); - HSSFCell cell = wb.getSheet(cellRef.getSheetName()).getRow(cellRef.getRow()).getCell((int)cellRef.getCol()); + HSSFName name = wb.getName("QUANT"); + assertNotNull(name); + CellReference cellRef = new CellReference(name.getRefersToFormula()); + HSSFCell cell = wb.getSheet(cellRef.getSheetName()).getRow(cellRef.getRow()).getCell(cellRef.getCol()); cell.setCellValue(NEW_QUANT); cell = wb2.getSheet("CostSheet").getRow(1).getCell(1); cell.setCellValue(NEW_PART_COST); @@ -90,17 +107,23 @@ public final class TestExternalNameReference extends TestCase { String[] bookNames = { "XRefCalc.xls", "XRefCalcData.xls" }; HSSFFormulaEvaluator[] evaluators = { evaluator, evaluatorCost, }; HSSFFormulaEvaluator.setupEnvironment(bookNames, evaluators); - cellRef = new CellReference(wb.getName("UNITCOST").getRefersToFormula()); + name = wb.getName("UNITCOST"); + assertNotNull(name); + cellRef = new CellReference(name.getRefersToFormula()); HSSFCell uccell = wb.getSheet(cellRef.getSheetName()).getRow(cellRef.getRow()).getCell(cellRef.getCol()); - cellRef = new CellReference(wb.getName("COST").getRefersToFormula()); + name = wb.getName("COST"); + assertNotNull(name); + cellRef = new CellReference(name.getRefersToFormula()); HSSFCell ccell = wb.getSheet(cellRef.getSheetName()).getRow(cellRef.getRow()).getCell(cellRef.getCol()); - cellRef = new CellReference(wb.getName("TOTALCOST").getRefersToFormula()); + name = wb.getName("TOTALCOST"); + assertNotNull(name); + cellRef = new CellReference(name.getRefersToFormula()); HSSFCell tccell = wb.getSheet(cellRef.getSheetName()).getRow(cellRef.getRow()).getCell(cellRef.getCol()); evaluator.evaluateFormulaCell(uccell); evaluator.evaluateFormulaCell(ccell); evaluator.evaluateFormulaCell(tccell); - assertEquals(NEW_PART_COST, uccell.getNumericCellValue()); - assertEquals(NEW_PART_COST*NEW_QUANT, ccell.getNumericCellValue()); - assertEquals(NEW_PART_COST*NEW_QUANT*MARKUP_COST_2, tccell.getNumericCellValue()); + assertEquals(NEW_PART_COST, uccell.getNumericCellValue(), 0); + assertEquals(NEW_PART_COST*NEW_QUANT, ccell.getNumericCellValue(), 0); + assertEquals(NEW_PART_COST*NEW_QUANT*MARKUP_COST_2, tccell.getNumericCellValue(), 0); } } diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestFuncPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestFuncPtg.java index fd1af26dd2..fdd9a8c574 100644 --- a/src/testcases/org/apache/poi/ss/formula/ptg/TestFuncPtg.java +++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestFuncPtg.java @@ -17,16 +17,17 @@ package org.apache.poi.ss.formula.ptg; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.junit.Test; /** * Make sure the FuncPtg performs as expected - * - * @author Danny Mui (dmui at apache dot org) */ -public final class TestFuncPtg extends TestCase { +public final class TestFuncPtg { + @Test public void testRead() { // This function index represents the LEN() function byte[] fakeData = { 0x20, 0x00,}; @@ -38,6 +39,7 @@ public final class TestFuncPtg extends TestCase { assertEquals( "Ptg Size", 3, ptg.getSize() ); } + @Test public void testNumberOfOperands() { FuncPtg funcPtg = FuncPtg.create(27); // ROUND() - takes 2 args assertEquals(2, funcPtg.getNumberOfOperands()); diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestFuncVarPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestFuncVarPtg.java index ecc07aac45..62c5a125f0 100644 --- a/src/testcases/org/apache/poi/ss/formula/ptg/TestFuncVarPtg.java +++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestFuncVarPtg.java @@ -17,15 +17,17 @@ package org.apache.poi.ss.formula.ptg; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import org.apache.poi.hssf.model.HSSFFormulaParser; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.junit.Test; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; /** * @author Josh Micich */ -public final class TestFuncVarPtg extends TestCase { +public final class TestFuncVarPtg { /** * The first fix for bugzilla 44675 broke the encoding of SUM formulas (and probably others). @@ -34,20 +36,23 @@ public final class TestFuncVarPtg extends TestCase { * wrong. In other cases Excel seems to tolerate bad operand classes.

    * This functionality is related to the setParameterRVA() methods of FormulaParser */ + @Test public void testOperandClass() { HSSFWorkbook book = new HSSFWorkbook(); Ptg[] ptgs = HSSFFormulaParser.parse("sum(A1:A2)", book); assertEquals(2, ptgs.length); assertEquals(AreaPtg.class, ptgs[0].getClass()); - + switch(ptgs[0].getPtgClass()) { case Ptg.CLASS_REF: // correct behaviour break; case Ptg.CLASS_VALUE: - throw new AssertionFailedError("Identified bug 44675b"); + fail("Identified bug 44675b"); + break; default: - throw new RuntimeException("Unexpected operand class"); + fail("Unexpected operand class"); + break; } } } diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestIntersectionPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestIntersectionPtg.java index c06b80e381..c13bf638a9 100644 --- a/src/testcases/org/apache/poi/ss/formula/ptg/TestIntersectionPtg.java +++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestIntersectionPtg.java @@ -17,22 +17,27 @@ package org.apache.poi.ss.formula.ptg; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.junit.Test; /** * Tests for {@link IntersectionPtg}. - * - * @author Daniel Noll (daniel at nuix dot com dot au) */ public final class TestIntersectionPtg extends AbstractPtgTestCase { /** * Tests reading a file containing this ptg. */ - public void testReading() { - HSSFWorkbook workbook = loadWorkbook("IntersectionPtg.xls"); - HSSFCell cell = workbook.getSheetAt(0).getRow(4).getCell(2); - assertEquals("Wrong cell value", 5.0, cell.getNumericCellValue(), 0.0); - assertEquals("Wrong cell formula", "SUM(A1:B2 B2:C3)", cell.getCellFormula()); + @Test + public void testReading() throws IOException { + try (HSSFWorkbook workbook = loadWorkbook("IntersectionPtg.xls")) { + HSSFCell cell = workbook.getSheetAt(0).getRow(4).getCell(2); + assertEquals("Wrong cell value", 5.0, cell.getNumericCellValue(), 0.0); + assertEquals("Wrong cell formula", "SUM(A1:B2 B2:C3)", cell.getCellFormula()); + } } } diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestPercentPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestPercentPtg.java index 79d34530af..84ede5baa6 100644 --- a/src/testcases/org/apache/poi/ss/formula/ptg/TestPercentPtg.java +++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestPercentPtg.java @@ -17,27 +17,32 @@ package org.apache.poi.ss.formula.ptg; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.junit.Test; /** * Tests for {@link PercentPtg}. - * - * @author Daniel Noll (daniel at nuix dot com dot au) */ public final class TestPercentPtg extends AbstractPtgTestCase { /** * Tests reading a file containing this ptg. */ - public void testReading() { - HSSFWorkbook workbook = loadWorkbook("PercentPtg.xls"); - HSSFSheet sheet = workbook.getSheetAt(0); + @Test + public void testReading() throws IOException { + try (HSSFWorkbook workbook = loadWorkbook("PercentPtg.xls")) { + HSSFSheet sheet = workbook.getSheetAt(0); - assertEquals("Wrong numeric value for original number", 53000.0, - sheet.getRow(0).getCell(0).getNumericCellValue(), 0.0); - assertEquals("Wrong numeric value for percent formula result", 5300.0, - sheet.getRow(1).getCell(0).getNumericCellValue(), 0.0); - assertEquals("Wrong formula string for percent formula", "A1*10%", - sheet.getRow(1).getCell(0).getCellFormula()); + assertEquals("Wrong numeric value for original number", 53000.0, + sheet.getRow(0).getCell(0).getNumericCellValue(), 0.0); + assertEquals("Wrong numeric value for percent formula result", 5300.0, + sheet.getRow(1).getCell(0).getNumericCellValue(), 0.0); + assertEquals("Wrong formula string for percent formula", "A1*10%", + sheet.getRow(1).getCell(0).getCellFormula()); + } } } diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestRangePtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestRangePtg.java index 3b02684bb0..55438777fa 100644 --- a/src/testcases/org/apache/poi/ss/formula/ptg/TestRangePtg.java +++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestRangePtg.java @@ -17,22 +17,27 @@ package org.apache.poi.ss.formula.ptg; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.junit.Test; /** * Tests for {@link RangePtg}. - * - * @author Daniel Noll (daniel at nuix dot com dot au) */ public final class TestRangePtg extends AbstractPtgTestCase { /** * Tests reading a file containing this ptg. */ - public void testReading() { - HSSFWorkbook workbook = loadWorkbook("RangePtg.xls"); - HSSFCell cell = workbook.getSheetAt(0).getRow(3).getCell(1); - assertEquals("Wrong cell value", 10.0, cell.getNumericCellValue(), 0.0); - assertEquals("Wrong cell formula", "SUM(pineapple:B2)", cell.getCellFormula()); + @Test + public void testReading() throws IOException { + try (HSSFWorkbook workbook = loadWorkbook("RangePtg.xls")) { + HSSFCell cell = workbook.getSheetAt(0).getRow(3).getCell(1); + assertEquals("Wrong cell value", 10.0, cell.getNumericCellValue(), 0.0); + assertEquals("Wrong cell formula", "SUM(pineapple:B2)", cell.getCellFormula()); + } } } diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestRef3DPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestRef3DPtg.java index 3aca4c4e0c..2bea126dab 100644 --- a/src/testcases/org/apache/poi/ss/formula/ptg/TestRef3DPtg.java +++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestRef3DPtg.java @@ -17,28 +17,32 @@ package org.apache.poi.ss.formula.ptg; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.junit.Test; /** * Tests for Ref3DPtg - * - * @author Josh Micich */ public final class TestRef3DPtg extends AbstractPtgTestCase { - - public void testToFormulaString() { + @Test + public void testToFormulaString() throws IOException { Ref3DPtg target = new Ref3DPtg("A1", (short)0); - HSSFWorkbook wb = createWorkbookWithSheet("my sheet"); - HSSFEvaluationWorkbook book = HSSFEvaluationWorkbook.create(wb); - assertEquals("'my sheet'!A1", target.toFormulaString(book)); + try (HSSFWorkbook wb = createWorkbookWithSheet("my sheet")) { + HSSFEvaluationWorkbook book = HSSFEvaluationWorkbook.create(wb); + assertEquals("'my sheet'!A1", target.toFormulaString(book)); - wb.setSheetName(0, "ProfitAndLoss"); - assertEquals("ProfitAndLoss!A1", target.toFormulaString(book)); + wb.setSheetName(0, "ProfitAndLoss"); + assertEquals("ProfitAndLoss!A1", target.toFormulaString(book)); - wb.setSheetName(0, "profit+loss"); - assertEquals("'profit+loss'!A1", target.toFormulaString(book)); + wb.setSheetName(0, "profit+loss"); + assertEquals("'profit+loss'!A1", target.toFormulaString(book)); + } } } diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestReferencePtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestReferencePtg.java index 7167c2ec09..00c225be15 100644 --- a/src/testcases/org/apache/poi/ss/formula/ptg/TestReferencePtg.java +++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestReferencePtg.java @@ -18,22 +18,26 @@ package org.apache.poi.ss.formula.ptg; import static org.junit.Assert.assertArrayEquals; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import java.io.IOException; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.record.TestcaseRecordInputStream; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.util.LittleEndianInput; +import org.junit.Test; /** * Tests for {@link RefPtg}. */ -public final class TestReferencePtg extends TestCase { +public final class TestReferencePtg { /** * Tests reading a file containing this ptg. */ + @Test public void testReading() { HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ReferencePtg.xls"); HSSFSheet sheet = workbook.getSheetAt(0); @@ -45,7 +49,7 @@ public final class TestReferencePtg extends TestCase { sheet.getRow(0).getCell(1).getNumericCellValue(), 0.0); assertEquals("Wrong formula string for reference", "A1", sheet.getRow(0).getCell(1).getCellFormula()); - + // Now moving over the 2**15 boundary // (Remember that excel row (n) is poi row (n-1) assertEquals("Wrong numeric value for original number", 32767.0, @@ -54,21 +58,21 @@ public final class TestReferencePtg extends TestCase { sheet.getRow(32766).getCell(1).getNumericCellValue(), 0.0); assertEquals("Wrong formula string for reference", "A32767", sheet.getRow(32766).getCell(1).getCellFormula()); - + assertEquals("Wrong numeric value for original number", 32768.0, sheet.getRow(32767).getCell(0).getNumericCellValue(), 0.0); assertEquals("Wrong numeric value for referemce", 32768.0, sheet.getRow(32767).getCell(1).getNumericCellValue(), 0.0); assertEquals("Wrong formula string for reference", "A32768", sheet.getRow(32767).getCell(1).getCellFormula()); - + assertEquals("Wrong numeric value for original number", 32769.0, sheet.getRow(32768).getCell(0).getNumericCellValue(), 0.0); assertEquals("Wrong numeric value for referemce", 32769.0, sheet.getRow(32768).getCell(1).getNumericCellValue(), 0.0); assertEquals("Wrong formula string for reference", "A32769", sheet.getRow(32768).getCell(1).getCellFormula()); - + assertEquals("Wrong numeric value for original number", 32770.0, sheet.getRow(32769).getCell(0).getNumericCellValue(), 0.0); assertEquals("Wrong numeric value for referemce", 32770.0, @@ -76,30 +80,25 @@ public final class TestReferencePtg extends TestCase { assertEquals("Wrong formula string for reference", "A32770", sheet.getRow(32769).getCell(1).getCellFormula()); } - - public void testBug44921() { - HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex44921-21902.xls"); - - try { - HSSFTestDataSamples.writeOutAndReadBack(wb); - } catch (RuntimeException e) { - if(e.getMessage().equals("Coding Error: This method should never be called. This ptg should be converted")) { - throw new AssertionFailedError("Identified bug 44921"); - } - throw e; + + @Test + public void testBug44921() throws IOException { + try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex44921-21902.xls")) { + HSSFTestDataSamples.writeOutAndReadBack(wb).close(); } } + private static final byte[] tRefN_data = { 0x2C, 33, 44, 55, 66, }; + + @Test public void testReadWrite_tRefN_bug45091() { LittleEndianInput in = TestcaseRecordInputStream.createLittleEndian(tRefN_data); Ptg[] ptgs = Ptg.readTokens(tRefN_data.length, in); byte[] outData = new byte[5]; Ptg.serializePtgs(ptgs, outData, 0); - if (outData[0] == 0x24) { - throw new AssertionFailedError("Identified bug 45091"); - } + assertNotEquals("Identified bug 45091", 0x24, outData[0]); assertArrayEquals(tRefN_data, outData); } @@ -107,6 +106,7 @@ public final class TestReferencePtg extends TestCase { * test that RefPtgBase can handle references with column index greater than 255, * see Bugzilla 50096 */ + @Test public void testColumnGreater255() { RefPtgBase ptg; ptg = new RefPtg("IW1"); diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestUnionPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestUnionPtg.java index 9ea756061a..7d6fc3151c 100644 --- a/src/testcases/org/apache/poi/ss/formula/ptg/TestUnionPtg.java +++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestUnionPtg.java @@ -17,22 +17,27 @@ package org.apache.poi.ss.formula.ptg; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.junit.Test; /** * Tests for {@link UnionPtg}. - * - * @author Daniel Noll (daniel at nuix dot com dot au) */ public final class TestUnionPtg extends AbstractPtgTestCase { /** * Tests reading a file containing this ptg. */ - public void testReading() { - HSSFWorkbook workbook = loadWorkbook("UnionPtg.xls"); - HSSFCell cell = workbook.getSheetAt(0).getRow(4).getCell(2); - assertEquals("Wrong cell value", 24.0, cell.getNumericCellValue(), 0.0); - assertEquals("Wrong cell formula", "SUM(A1:B2,B2:C3)", cell.getCellFormula()); + @Test + public void testReading() throws IOException { + try (HSSFWorkbook workbook = loadWorkbook("UnionPtg.xls")) { + HSSFCell cell = workbook.getSheetAt(0).getRow(4).getCell(2); + assertEquals("Wrong cell value", 24.0, cell.getNumericCellValue(), 0.0); + assertEquals("Wrong cell formula", "SUM(A1:B2,B2:C3)", cell.getCellFormula()); + } } } diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java index 0d784a6b3f..89c4796de7 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java @@ -32,11 +32,9 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.time.LocalDate; import java.time.LocalDateTime; -import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; -import java.util.List; import java.util.Locale; import java.util.TimeZone; @@ -46,13 +44,13 @@ import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.util.LocaleUtil; -import org.junit.After; import org.junit.Test; /** * Common superclass for testing implementations of * {@link org.apache.poi.ss.usermodel.Cell} */ +@SuppressWarnings("deprecation") public abstract class BaseTestCell { protected final ITestDataProvider _testDataProvider; @@ -66,82 +64,81 @@ public abstract class BaseTestCell { @Test public void testSetValues() throws Exception { - Workbook book = _testDataProvider.createWorkbook(); - Sheet sheet = book.createSheet("test"); - Row row = sheet.createRow(0); + try (Workbook book = _testDataProvider.createWorkbook()) { + Sheet sheet = book.createSheet("test"); + Row row = sheet.createRow(0); - CreationHelper factory = book.getCreationHelper(); - Cell cell = row.createCell(0); + CreationHelper factory = book.getCreationHelper(); + Cell cell = row.createCell(0); - cell.setCellValue(1.2); - assertEquals(1.2, cell.getNumericCellValue(), 0.0001); - assertEquals(CellType.NUMERIC, cell.getCellType()); - assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING, - CellType.FORMULA, CellType.ERROR); + cell.setCellValue(1.2); + assertEquals(1.2, cell.getNumericCellValue(), 0.0001); + assertEquals(CellType.NUMERIC, cell.getCellType()); + assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING, + CellType.FORMULA, CellType.ERROR); - cell.setCellValue(false); - assertFalse(cell.getBooleanCellValue()); - assertEquals(CellType.BOOLEAN, cell.getCellType()); - cell.setCellValue(true); - assertTrue(cell.getBooleanCellValue()); - assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.STRING, CellType.BOOLEAN, - CellType.FORMULA, CellType.ERROR); + cell.setCellValue(false); + assertFalse(cell.getBooleanCellValue()); + assertEquals(CellType.BOOLEAN, cell.getCellType()); + cell.setCellValue(true); + assertTrue(cell.getBooleanCellValue()); + assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.STRING, CellType.BOOLEAN, + CellType.FORMULA, CellType.ERROR); - cell.setCellValue(factory.createRichTextString("Foo")); - assertEquals("Foo", cell.getRichStringCellValue().getString()); - assertEquals("Foo", cell.getStringCellValue()); - assertEquals(CellType.STRING, cell.getCellType()); - assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.BOOLEAN, - CellType.FORMULA, CellType.ERROR); + cell.setCellValue(factory.createRichTextString("Foo")); + assertEquals("Foo", cell.getRichStringCellValue().getString()); + assertEquals("Foo", cell.getStringCellValue()); + assertEquals(CellType.STRING, cell.getCellType()); + assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.BOOLEAN, + CellType.FORMULA, CellType.ERROR); - cell.setCellValue("345"); - assertEquals("345", cell.getRichStringCellValue().getString()); - assertEquals("345", cell.getStringCellValue()); - assertEquals(CellType.STRING, cell.getCellType()); - assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.BOOLEAN, - CellType.FORMULA, CellType.ERROR); + cell.setCellValue("345"); + assertEquals("345", cell.getRichStringCellValue().getString()); + assertEquals("345", cell.getStringCellValue()); + assertEquals(CellType.STRING, cell.getCellType()); + assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.BOOLEAN, + CellType.FORMULA, CellType.ERROR); - Calendar c = LocaleUtil.getLocaleCalendar(); - c.setTimeInMillis(123456789); - cell.setCellValue(c.getTime()); - assertEquals(c.getTime().getTime(), cell.getDateCellValue().getTime()); - assertEquals(CellType.NUMERIC, cell.getCellType()); - assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING, - CellType.FORMULA, CellType.ERROR); + Calendar c = LocaleUtil.getLocaleCalendar(); + c.setTimeInMillis(123456789); + cell.setCellValue(c.getTime()); + assertEquals(c.getTime().getTime(), cell.getDateCellValue().getTime()); + assertEquals(CellType.NUMERIC, cell.getCellType()); + assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING, + CellType.FORMULA, CellType.ERROR); - cell.setCellValue(c); - assertEquals(c.getTime().getTime(), cell.getDateCellValue().getTime()); - assertEquals(CellType.NUMERIC, cell.getCellType()); - assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING, - CellType.FORMULA, CellType.ERROR); + cell.setCellValue(c); + assertEquals(c.getTime().getTime(), cell.getDateCellValue().getTime()); + assertEquals(CellType.NUMERIC, cell.getCellType()); + assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING, + CellType.FORMULA, CellType.ERROR); - cell.setCellErrorValue(FormulaError.NA.getCode()); - assertEquals(FormulaError.NA.getCode(), cell.getErrorCellValue()); - assertEquals(CellType.ERROR, cell.getCellType()); - assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.BOOLEAN, - CellType.FORMULA, CellType.STRING); + cell.setCellErrorValue(FormulaError.NA.getCode()); + assertEquals(FormulaError.NA.getCode(), cell.getErrorCellValue()); + assertEquals(CellType.ERROR, cell.getCellType()); + assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.BOOLEAN, + CellType.FORMULA, CellType.STRING); - LocalDateTime ldt = DateUtil.toLocalDateTime(c); - cell.setCellValue(ldt); - assertEquals(ldt, cell.getLocalDateTimeCellValue()); - assertEquals(CellType.NUMERIC, cell.getCellType()); - assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING, - CellType.FORMULA, CellType.ERROR); + LocalDateTime ldt = DateUtil.toLocalDateTime(c); + cell.setCellValue(ldt); + assertEquals(ldt, cell.getLocalDateTimeCellValue()); + assertEquals(CellType.NUMERIC, cell.getCellType()); + assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING, + CellType.FORMULA, CellType.ERROR); - LocalDate ld = ldt.toLocalDate(); - cell.setCellValue(ld); - assertEquals(ld, cell.getLocalDateTimeCellValue().toLocalDate()); - assertEquals(CellType.NUMERIC, cell.getCellType()); - assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING, - CellType.FORMULA, CellType.ERROR); + LocalDate ld = ldt.toLocalDate(); + cell.setCellValue(ld); + assertEquals(ld, cell.getLocalDateTimeCellValue().toLocalDate()); + assertEquals(CellType.NUMERIC, cell.getCellType()); + assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING, + CellType.FORMULA, CellType.ERROR); - cell.setCellErrorValue(FormulaError.NA.getCode()); - assertEquals(FormulaError.NA.getCode(), cell.getErrorCellValue()); - assertEquals(CellType.ERROR, cell.getCellType()); - assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.BOOLEAN, - CellType.FORMULA, CellType.STRING); - - book.close(); + cell.setCellErrorValue(FormulaError.NA.getCode()); + assertEquals(FormulaError.NA.getCode(), cell.getErrorCellValue()); + assertEquals(CellType.ERROR, cell.getCellType()); + assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.BOOLEAN, + CellType.FORMULA, CellType.STRING); + } } private static void assertProhibitedValueAccess(Cell cell, CellType ... types) { @@ -166,7 +163,7 @@ public abstract class BaseTestCell { default: fail("Should get exception when reading cell type (" + type + ")."); } - + } catch (IllegalStateException e){ // expected during successful test assertTrue(e.getMessage().startsWith("Cannot get a")); @@ -179,49 +176,46 @@ public abstract class BaseTestCell { */ @Test public void testBool() throws IOException { + try (Workbook wb1 = _testDataProvider.createWorkbook()) { + Sheet s = wb1.createSheet("testSheet1"); + Row r; + Cell c; + // B1 + r = s.createRow(0); + c = r.createCell(1); + assertEquals(0, c.getRowIndex()); + assertEquals(1, c.getColumnIndex()); + c.setCellValue(true); + assertTrue("B1 value", c.getBooleanCellValue()); - Workbook wb1 = _testDataProvider.createWorkbook(); - Sheet s = wb1.createSheet("testSheet1"); - Row r; - Cell c; - // B1 - r = s.createRow(0); - c=r.createCell(1); - assertEquals(0, c.getRowIndex()); - assertEquals(1, c.getColumnIndex()); - c.setCellValue(true); - assertTrue("B1 value", c.getBooleanCellValue()); + // C1 + c = r.createCell(2); + assertEquals(0, c.getRowIndex()); + assertEquals(2, c.getColumnIndex()); + c.setCellValue(false); + assertFalse("C1 value", c.getBooleanCellValue()); - // C1 - c=r.createCell(2); - assertEquals(0, c.getRowIndex()); - assertEquals(2, c.getColumnIndex()); - c.setCellValue(false); - assertFalse("C1 value", c.getBooleanCellValue()); + // Make sure values are saved and re-read correctly. + try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) { + s = wb2.getSheet("testSheet1"); + r = s.getRow(0); + assertEquals("Row 1 should have 2 cells", 2, r.getPhysicalNumberOfCells()); - // Make sure values are saved and re-read correctly. - Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1); - wb1.close(); - - s = wb2.getSheet("testSheet1"); - r = s.getRow(0); - assertEquals("Row 1 should have 2 cells", 2, r.getPhysicalNumberOfCells()); - - c = r.getCell(1); - assertEquals(0, c.getRowIndex()); - assertEquals(1, c.getColumnIndex()); - assertEquals(CellType.BOOLEAN, c.getCellType()); - assertTrue("B1 value", c.getBooleanCellValue()); - - c = r.getCell(2); - assertEquals(0, c.getRowIndex()); - assertEquals(2, c.getColumnIndex()); - assertEquals(CellType.BOOLEAN, c.getCellType()); - assertFalse("C1 value", c.getBooleanCellValue()); - - wb2.close(); + c = r.getCell(1); + assertEquals(0, c.getRowIndex()); + assertEquals(1, c.getColumnIndex()); + assertEquals(CellType.BOOLEAN, c.getCellType()); + assertTrue("B1 value", c.getBooleanCellValue()); + + c = r.getCell(2); + assertEquals(0, c.getRowIndex()); + assertEquals(2, c.getColumnIndex()); + assertEquals(CellType.BOOLEAN, c.getCellType()); + assertFalse("C1 value", c.getBooleanCellValue()); + } + } } - + /** * test that Error types (BoolErrRecord) are supported properly. * @see #testBool @@ -229,47 +223,45 @@ public abstract class BaseTestCell { @Test public void testErr() throws IOException { - Workbook wb1 = _testDataProvider.createWorkbook(); - Sheet s = wb1.createSheet("testSheet1"); - Row r; - Cell c; + try (Workbook wb1 = _testDataProvider.createWorkbook()) { + Sheet s = wb1.createSheet("testSheet1"); + Row r; + Cell c; - // B1 - r = s.createRow(0); - c=r.createCell(1); - assertEquals(0, c.getRowIndex()); - assertEquals(1, c.getColumnIndex()); - c.setCellErrorValue(FormulaError.NULL.getCode()); - assertEquals("B1 value == #NULL!", FormulaError.NULL.getCode(), c.getErrorCellValue()); + // B1 + r = s.createRow(0); + c = r.createCell(1); + assertEquals(0, c.getRowIndex()); + assertEquals(1, c.getColumnIndex()); + c.setCellErrorValue(FormulaError.NULL.getCode()); + assertEquals("B1 value == #NULL!", FormulaError.NULL.getCode(), c.getErrorCellValue()); - // C1 - c=r.createCell(2); - assertEquals(0, c.getRowIndex()); - assertEquals(2, c.getColumnIndex()); - c.setCellErrorValue(FormulaError.DIV0.getCode()); - assertEquals("C1 value == #DIV/0!", FormulaError.DIV0.getCode(), c.getErrorCellValue()); + // C1 + c = r.createCell(2); + assertEquals(0, c.getRowIndex()); + assertEquals(2, c.getColumnIndex()); + c.setCellErrorValue(FormulaError.DIV0.getCode()); + assertEquals("C1 value == #DIV/0!", FormulaError.DIV0.getCode(), c.getErrorCellValue()); - Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1); - wb1.close(); + try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) { + s = wb2.getSheet("testSheet1"); - s = wb2.getSheet("testSheet1"); + r = s.getRow(0); + assertEquals("Row 1 should have 2 cells", 2, r.getPhysicalNumberOfCells()); - r = s.getRow(0); - assertEquals("Row 1 should have 2 cells", 2, r.getPhysicalNumberOfCells()); + c = r.getCell(1); + assertEquals(0, c.getRowIndex()); + assertEquals(1, c.getColumnIndex()); + assertEquals(CellType.ERROR, c.getCellType()); + assertEquals("B1 value == #NULL!", FormulaError.NULL.getCode(), c.getErrorCellValue()); - c = r.getCell(1); - assertEquals(0, c.getRowIndex()); - assertEquals(1, c.getColumnIndex()); - assertEquals(CellType.ERROR, c.getCellType()); - assertEquals("B1 value == #NULL!", FormulaError.NULL.getCode(), c.getErrorCellValue()); - - c = r.getCell(2); - assertEquals(0, c.getRowIndex()); - assertEquals(2, c.getColumnIndex()); - assertEquals(CellType.ERROR, c.getCellType()); - assertEquals("C1 value == #DIV/0!", FormulaError.DIV0.getCode(), c.getErrorCellValue()); - - wb2.close(); + c = r.getCell(2); + assertEquals(0, c.getRowIndex()); + assertEquals(2, c.getColumnIndex()); + assertEquals(CellType.ERROR, c.getCellType()); + assertEquals("C1 value == #DIV/0!", FormulaError.DIV0.getCode(), c.getErrorCellValue()); + } + } } /** @@ -277,99 +269,97 @@ public abstract class BaseTestCell { */ @Test public void testFormulaStyle() throws Exception { + try (Workbook wb1 = _testDataProvider.createWorkbook()) { + Sheet s = wb1.createSheet("testSheet1"); + Row r; + Cell c; + CellStyle cs = wb1.createCellStyle(); + Font f = wb1.createFont(); + f.setFontHeightInPoints((short) 20); + f.setColor(IndexedColors.RED.getIndex()); + f.setBold(true); + f.setFontName("Arial Unicode MS"); + cs.setFillBackgroundColor((short) 3); + cs.setFont(f); + cs.setBorderTop(BorderStyle.THIN); + cs.setBorderRight(BorderStyle.THIN); + cs.setBorderLeft(BorderStyle.THIN); + cs.setBorderBottom(BorderStyle.THIN); - Workbook wb1 = _testDataProvider.createWorkbook(); - Sheet s = wb1.createSheet("testSheet1"); - Row r; - Cell c; - CellStyle cs = wb1.createCellStyle(); - Font f = wb1.createFont(); - f.setFontHeightInPoints((short) 20); - f.setColor(IndexedColors.RED.getIndex()); - f.setBold(true); - f.setFontName("Arial Unicode MS"); - cs.setFillBackgroundColor((short)3); - cs.setFont(f); - cs.setBorderTop(BorderStyle.THIN); - cs.setBorderRight(BorderStyle.THIN); - cs.setBorderLeft(BorderStyle.THIN); - cs.setBorderBottom(BorderStyle.THIN); + r = s.createRow(0); + c = r.createCell(0); + c.setCellStyle(cs); + c.setCellFormula("2*3"); - r = s.createRow(0); - c=r.createCell(0); - c.setCellStyle(cs); - c.setCellFormula("2*3"); + try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) { + s = wb2.getSheetAt(0); + r = s.getRow(0); + c = r.getCell(0); - Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1); - wb1.close(); - s = wb2.getSheetAt(0); - r = s.getRow(0); - c = r.getCell(0); + assertEquals("Formula Cell at 0,0", CellType.FORMULA, c.getCellType()); + cs = c.getCellStyle(); - assertEquals("Formula Cell at 0,0", CellType.FORMULA, c.getCellType()); - cs = c.getCellStyle(); - - assertNotNull("Formula Cell Style", cs); - assertEquals("Font Index Matches", f.getIndexAsInt(), cs.getFontIndexAsInt()); - assertEquals("Top Border", BorderStyle.THIN, cs.getBorderTop()); - assertEquals("Left Border", BorderStyle.THIN, cs.getBorderLeft()); - assertEquals("Right Border", BorderStyle.THIN, cs.getBorderRight()); - assertEquals("Bottom Border", BorderStyle.THIN, cs.getBorderBottom()); - wb2.close(); + assertNotNull("Formula Cell Style", cs); + assertEquals("Font Index Matches", f.getIndexAsInt(), cs.getFontIndexAsInt()); + assertEquals("Top Border", BorderStyle.THIN, cs.getBorderTop()); + assertEquals("Left Border", BorderStyle.THIN, cs.getBorderLeft()); + assertEquals("Right Border", BorderStyle.THIN, cs.getBorderRight()); + assertEquals("Bottom Border", BorderStyle.THIN, cs.getBorderBottom()); + } + } } /**tests the toString() method of HSSFCell*/ @Test public void testToString() throws Exception { - Workbook wb1 = _testDataProvider.createWorkbook(); - Row r = wb1.createSheet("Sheet1").createRow(0); - CreationHelper factory = wb1.getCreationHelper(); + try (Workbook wb1 = _testDataProvider.createWorkbook()) { + Row r = wb1.createSheet("Sheet1").createRow(0); + CreationHelper factory = wb1.getCreationHelper(); - r.createCell(0).setCellValue(false); - r.createCell(1).setCellValue(true); - r.createCell(2).setCellValue(1.5); - r.createCell(3).setCellValue(factory.createRichTextString("Astring")); - r.createCell(4).setCellErrorValue(FormulaError.DIV0.getCode()); - r.createCell(5).setCellFormula("A1+B1"); - r.createCell(6); // blank + r.createCell(0).setCellValue(false); + r.createCell(1).setCellValue(true); + r.createCell(2).setCellValue(1.5); + r.createCell(3).setCellValue(factory.createRichTextString("Astring")); + r.createCell(4).setCellErrorValue(FormulaError.DIV0.getCode()); + r.createCell(5).setCellFormula("A1+B1"); + r.createCell(6); // blank - // create date-formatted cell - Calendar c = LocaleUtil.getLocaleCalendar(); - c.set(2010, Calendar.FEBRUARY, 2, 0, 0, 0); - r.createCell(7).setCellValue(c); - CellStyle dateStyle = wb1.createCellStyle(); - short formatId = wb1.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm"); // any date format will do - dateStyle.setDataFormat(formatId); - r.getCell(7).setCellStyle(dateStyle); + // create date-formatted cell + Calendar c = LocaleUtil.getLocaleCalendar(); + c.set(2010, Calendar.FEBRUARY, 2, 0, 0, 0); + r.createCell(7).setCellValue(c); + CellStyle dateStyle = wb1.createCellStyle(); + short formatId = wb1.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm"); // any date format will do + dateStyle.setDataFormat(formatId); + r.getCell(7).setCellStyle(dateStyle); - assertEquals("Boolean", "FALSE", r.getCell(0).toString()); - assertEquals("Boolean", "TRUE", r.getCell(1).toString()); - assertEquals("Numeric", "1.5", r.getCell(2).toString()); - assertEquals("String", "Astring", r.getCell(3).toString()); - assertEquals("Error", "#DIV/0!", r.getCell(4).toString()); - assertEquals("Formula", "A1+B1", r.getCell(5).toString()); - assertEquals("Blank", "", r.getCell(6).toString()); - // toString on a date-formatted cell displays dates as dd-MMM-yyyy, which has locale problems with the month - String dateCell1 = r.getCell(7).toString(); - assertTrue("Date (Day)", dateCell1.startsWith("02-")); - assertTrue("Date (Year)", dateCell1.endsWith("-2010")); + assertEquals("Boolean", "FALSE", r.getCell(0).toString()); + assertEquals("Boolean", "TRUE", r.getCell(1).toString()); + assertEquals("Numeric", "1.5", r.getCell(2).toString()); + assertEquals("String", "Astring", r.getCell(3).toString()); + assertEquals("Error", "#DIV/0!", r.getCell(4).toString()); + assertEquals("Formula", "A1+B1", r.getCell(5).toString()); + assertEquals("Blank", "", r.getCell(6).toString()); + // toString on a date-formatted cell displays dates as dd-MMM-yyyy, which has locale problems with the month + String dateCell1 = r.getCell(7).toString(); + assertTrue("Date (Day)", dateCell1.startsWith("02-")); + assertTrue("Date (Year)", dateCell1.endsWith("-2010")); - //Write out the file, read it in, and then check cell values - Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1); - wb1.close(); - - r = wb2.getSheetAt(0).getRow(0); - assertEquals("Boolean", "FALSE", r.getCell(0).toString()); - assertEquals("Boolean", "TRUE", r.getCell(1).toString()); - assertEquals("Numeric", "1.5", r.getCell(2).toString()); - assertEquals("String", "Astring", r.getCell(3).toString()); - assertEquals("Error", "#DIV/0!", r.getCell(4).toString()); - assertEquals("Formula", "A1+B1", r.getCell(5).toString()); - assertEquals("Blank", "", r.getCell(6).toString()); - String dateCell2 = r.getCell(7).toString(); - assertEquals("Date", dateCell1, dateCell2); - wb2.close(); + //Write out the file, read it in, and then check cell values + try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) { + r = wb2.getSheetAt(0).getRow(0); + assertEquals("Boolean", "FALSE", r.getCell(0).toString()); + assertEquals("Boolean", "TRUE", r.getCell(1).toString()); + assertEquals("Numeric", "1.5", r.getCell(2).toString()); + assertEquals("String", "Astring", r.getCell(3).toString()); + assertEquals("Error", "#DIV/0!", r.getCell(4).toString()); + assertEquals("Formula", "A1+B1", r.getCell(5).toString()); + assertEquals("Blank", "", r.getCell(6).toString()); + String dateCell2 = r.getCell(7).toString(); + assertEquals("Date", dateCell1, dateCell2); + } + } } /** @@ -377,67 +367,61 @@ public abstract class BaseTestCell { */ @Test public void testSetFormulaValue() throws Exception { - Workbook wb = _testDataProvider.createWorkbook(); - Sheet s = wb.createSheet(); - Row r = s.createRow(0); + try (Workbook wb = _testDataProvider.createWorkbook()) { + Sheet s = wb.createSheet(); + Row r = s.createRow(0); - Cell c1 = r.createCell(0); - c1.setCellFormula("NA()"); - assertEquals(0.0, c1.getNumericCellValue(), 0.0); - assertEquals(CellType.NUMERIC, c1.getCachedFormulaResultType()); - c1.setCellValue(10); - assertEquals(10.0, c1.getNumericCellValue(), 0.0); - assertEquals(CellType.FORMULA, c1.getCellType()); - assertEquals(CellType.NUMERIC, c1.getCachedFormulaResultType()); + Cell c1 = r.createCell(0); + c1.setCellFormula("NA()"); + assertEquals(0.0, c1.getNumericCellValue(), 0.0); + assertEquals(CellType.NUMERIC, c1.getCachedFormulaResultType()); + c1.setCellValue(10); + assertEquals(10.0, c1.getNumericCellValue(), 0.0); + assertEquals(CellType.FORMULA, c1.getCellType()); + assertEquals(CellType.NUMERIC, c1.getCachedFormulaResultType()); - Cell c2 = r.createCell(1); - c2.setCellFormula("NA()"); - assertEquals(0.0, c2.getNumericCellValue(), 0.0); - assertEquals(CellType.NUMERIC, c2.getCachedFormulaResultType()); - c2.setCellValue("I changed!"); - assertEquals("I changed!", c2.getStringCellValue()); - assertEquals(CellType.FORMULA, c2.getCellType()); - assertEquals(CellType.STRING, c2.getCachedFormulaResultType()); + Cell c2 = r.createCell(1); + c2.setCellFormula("NA()"); + assertEquals(0.0, c2.getNumericCellValue(), 0.0); + assertEquals(CellType.NUMERIC, c2.getCachedFormulaResultType()); + c2.setCellValue("I changed!"); + assertEquals("I changed!", c2.getStringCellValue()); + assertEquals(CellType.FORMULA, c2.getCellType()); + assertEquals(CellType.STRING, c2.getCachedFormulaResultType()); - //calglin Cell.setCellFormula(null) for a non-formula cell - Cell c3 = r.createCell(2); - c3.setCellFormula(null); - assertEquals(CellType.BLANK, c3.getCellType()); - wb.close(); + //calglin Cell.setCellFormula(null) for a non-formula cell + Cell c3 = r.createCell(2); + c3.setCellFormula(null); + assertEquals(CellType.BLANK, c3.getCellType()); + } } private Cell createACell(Workbook wb) { return wb.createSheet("Sheet1").createRow(0).createCell(0); } - + /** * bug 58452: Copy cell formulas containing unregistered function names * Make sure that formulas with unknown/unregistered UDFs can be written to and read back from a file. */ @Test public void testFormulaWithUnknownUDF() throws IOException { - final Workbook wb1 = _testDataProvider.createWorkbook(); - final FormulaEvaluator evaluator1 = wb1.getCreationHelper().createFormulaEvaluator(); - try { + try (final Workbook wb1 = _testDataProvider.createWorkbook()) { + final FormulaEvaluator evaluator1 = wb1.getCreationHelper().createFormulaEvaluator(); final Cell cell1 = wb1.createSheet().createRow(0).createCell(0); final String formula = "myFunc(\"arg\")"; cell1.setCellFormula(formula); confirmFormulaWithUnknownUDF(formula, cell1, evaluator1); - - final Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1); - final FormulaEvaluator evaluator2 = wb2.getCreationHelper().createFormulaEvaluator(); - try { + + try (final Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) { + final FormulaEvaluator evaluator2 = wb2.getCreationHelper().createFormulaEvaluator(); final Cell cell2 = wb2.getSheetAt(0).getRow(0).getCell(0); confirmFormulaWithUnknownUDF(formula, cell2, evaluator2); - } finally { - wb2.close(); } - } finally { - wb1.close(); } } - + private static void confirmFormulaWithUnknownUDF(String expectedFormula, Cell cell, FormulaEvaluator evaluator) { assertEquals(expectedFormula, cell.getCellFormula()); try { @@ -450,59 +434,50 @@ public abstract class BaseTestCell { @Test public void testChangeTypeStringToBool() throws IOException { - Workbook wb = _testDataProvider.createWorkbook(); + try (Workbook wb = _testDataProvider.createWorkbook()) { + Cell cell = createACell(wb); - Cell cell = createACell(wb); + cell.setCellValue("TRUE"); + assertEquals(CellType.STRING, cell.getCellType()); + // test conversion of cell from text to boolean + cell.setCellType(CellType.BOOLEAN); - cell.setCellValue("TRUE"); - assertEquals(CellType.STRING, cell.getCellType()); - // test conversion of cell from text to boolean - cell.setCellType(CellType.BOOLEAN); + assertEquals(CellType.BOOLEAN, cell.getCellType()); + assertTrue(cell.getBooleanCellValue()); + cell.setCellType(CellType.STRING); + assertEquals("TRUE", cell.getRichStringCellValue().getString()); - assertEquals(CellType.BOOLEAN, cell.getCellType()); - assertTrue(cell.getBooleanCellValue()); - cell.setCellType(CellType.STRING); - assertEquals("TRUE", cell.getRichStringCellValue().getString()); - - // 'false' text to bool and back - cell.setCellValue("FALSE"); - cell.setCellType(CellType.BOOLEAN); - assertEquals(CellType.BOOLEAN, cell.getCellType()); - assertFalse(cell.getBooleanCellValue()); - cell.setCellType(CellType.STRING); - assertEquals("FALSE", cell.getRichStringCellValue().getString()); - - wb.close(); + // 'false' text to bool and back + cell.setCellValue("FALSE"); + cell.setCellType(CellType.BOOLEAN); + assertEquals(CellType.BOOLEAN, cell.getCellType()); + assertFalse(cell.getBooleanCellValue()); + cell.setCellType(CellType.STRING); + assertEquals("FALSE", cell.getRichStringCellValue().getString()); + } } @Test public void testChangeTypeBoolToString() throws IOException { - Workbook wb = _testDataProvider.createWorkbook(); + try (Workbook wb = _testDataProvider.createWorkbook()) { + Cell cell = createACell(wb); - Cell cell = createACell(wb); - - cell.setCellValue(true); - // test conversion of cell from boolean to text - cell.setCellType(CellType.STRING); - assertEquals("TRUE", cell.getRichStringCellValue().getString()); - - wb.close(); + cell.setCellValue(true); + // test conversion of cell from boolean to text + cell.setCellType(CellType.STRING); + assertEquals("TRUE", cell.getRichStringCellValue().getString()); + } } @Test public void testChangeTypeErrorToNumber() throws IOException { - Workbook wb = _testDataProvider.createWorkbook(); - - Cell cell = createACell(wb); - cell.setCellErrorValue(FormulaError.NAME.getCode()); - try { + try (Workbook wb = _testDataProvider.createWorkbook()) { + Cell cell = createACell(wb); + cell.setCellErrorValue(FormulaError.NAME.getCode()); + // ClassCastException -> Identified bug 46479b cell.setCellValue(2.5); - } catch (ClassCastException e) { - fail("Identified bug 46479b"); + assertEquals(2.5, cell.getNumericCellValue(), 0.0); } - assertEquals(2.5, cell.getNumericCellValue(), 0.0); - - wb.close(); } @Test @@ -514,7 +489,7 @@ public abstract class BaseTestCell { cell.setCellValue(true); // Identify bug 46479c assertTrue(cell.getBooleanCellValue()); - + wb.close(); } @@ -525,69 +500,65 @@ public abstract class BaseTestCell { */ @Test public void testConvertStringFormulaCell() throws IOException { - Workbook wb = _testDataProvider.createWorkbook(); + try (Workbook wb = _testDataProvider.createWorkbook()) { + Cell cellA1 = createACell(wb); + cellA1.setCellFormula("\"abc\""); - Cell cellA1 = createACell(wb); - cellA1.setCellFormula("\"abc\""); + // default cached formula result is numeric zero + assertEquals(0.0, cellA1.getNumericCellValue(), 0.0); - // default cached formula result is numeric zero - assertEquals(0.0, cellA1.getNumericCellValue(), 0.0); + FormulaEvaluator fe = cellA1.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator(); - FormulaEvaluator fe = cellA1.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator(); + fe.evaluateFormulaCell(cellA1); + assertEquals("abc", cellA1.getStringCellValue()); - fe.evaluateFormulaCell(cellA1); - assertEquals("abc", cellA1.getStringCellValue()); - - fe.evaluateInCell(cellA1); - assertFalse("Identified bug with writing back formula result of type string", cellA1.getStringCellValue().isEmpty()); - assertEquals("abc", cellA1.getStringCellValue()); - - wb.close(); + fe.evaluateInCell(cellA1); + assertFalse("Identified bug with writing back formula result of type string", cellA1.getStringCellValue().isEmpty()); + assertEquals("abc", cellA1.getStringCellValue()); + } } - + /** * similar to {@link #testConvertStringFormulaCell()} but checks at a * lower level that {#link {@link Cell#setCellType(CellType)} works properly */ @Test public void testSetTypeStringOnFormulaCell() throws IOException { - Workbook wb = _testDataProvider.createWorkbook(); + try (Workbook wb = _testDataProvider.createWorkbook()) { + Cell cellA1 = createACell(wb); + FormulaEvaluator fe = cellA1.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator(); - Cell cellA1 = createACell(wb); - FormulaEvaluator fe = cellA1.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator(); + cellA1.setCellFormula("\"DEF\""); + fe.clearAllCachedResultValues(); + fe.evaluateFormulaCell(cellA1); + assertEquals("DEF", cellA1.getStringCellValue()); + cellA1.setCellType(CellType.STRING); + assertEquals("DEF", cellA1.getStringCellValue()); - cellA1.setCellFormula("\"DEF\""); - fe.clearAllCachedResultValues(); - fe.evaluateFormulaCell(cellA1); - assertEquals("DEF", cellA1.getStringCellValue()); - cellA1.setCellType(CellType.STRING); - assertEquals("DEF", cellA1.getStringCellValue()); + cellA1.setCellFormula("25.061"); + fe.clearAllCachedResultValues(); + fe.evaluateFormulaCell(cellA1); + confirmCannotReadString(cellA1); + assertEquals(25.061, cellA1.getNumericCellValue(), 0.0); + cellA1.setCellType(CellType.STRING); + assertEquals("25.061", cellA1.getStringCellValue()); - cellA1.setCellFormula("25.061"); - fe.clearAllCachedResultValues(); - fe.evaluateFormulaCell(cellA1); - confirmCannotReadString(cellA1); - assertEquals(25.061, cellA1.getNumericCellValue(), 0.0); - cellA1.setCellType(CellType.STRING); - assertEquals("25.061", cellA1.getStringCellValue()); + cellA1.setCellFormula("TRUE"); + fe.clearAllCachedResultValues(); + fe.evaluateFormulaCell(cellA1); + confirmCannotReadString(cellA1); + assertTrue(cellA1.getBooleanCellValue()); + cellA1.setCellType(CellType.STRING); + assertEquals("TRUE", cellA1.getStringCellValue()); - cellA1.setCellFormula("TRUE"); - fe.clearAllCachedResultValues(); - fe.evaluateFormulaCell(cellA1); - confirmCannotReadString(cellA1); - assertTrue(cellA1.getBooleanCellValue()); - cellA1.setCellType(CellType.STRING); - assertEquals("TRUE", cellA1.getStringCellValue()); - - cellA1.setCellFormula("#NAME?"); - fe.clearAllCachedResultValues(); - fe.evaluateFormulaCell(cellA1); - confirmCannotReadString(cellA1); - assertEquals(FormulaError.NAME, forInt(cellA1.getErrorCellValue())); - cellA1.setCellType(CellType.STRING); - assertEquals("#NAME?", cellA1.getStringCellValue()); - - wb.close(); + cellA1.setCellFormula("#NAME?"); + fe.clearAllCachedResultValues(); + fe.evaluateFormulaCell(cellA1); + confirmCannotReadString(cellA1); + assertEquals(FormulaError.NAME, forInt(cellA1.getErrorCellValue())); + cellA1.setCellType(CellType.STRING); + assertEquals("#NAME?", cellA1.getStringCellValue()); + } } private static void confirmCannotReadString(Cell cell) { @@ -599,16 +570,14 @@ public abstract class BaseTestCell { */ @Test public void testChangeTypeFormulaToBoolean() throws IOException { - Workbook wb = _testDataProvider.createWorkbook(); - - Cell cell = createACell(wb); - cell.setCellFormula("1=1"); - cell.setCellValue(true); - cell.setCellType(CellType.BOOLEAN); - assertTrue("Identified bug 46479d", cell.getBooleanCellValue()); - assertTrue(cell.getBooleanCellValue()); - - wb.close(); + try (Workbook wb = _testDataProvider.createWorkbook()) { + Cell cell = createACell(wb); + cell.setCellFormula("1=1"); + cell.setCellValue(true); + cell.setCellType(CellType.BOOLEAN); + assertTrue("Identified bug 46479d", cell.getBooleanCellValue()); + assertTrue(cell.getBooleanCellValue()); + } } /** @@ -617,53 +586,53 @@ public abstract class BaseTestCell { */ @Test public void test40296() throws Exception { - Workbook wb1 = _testDataProvider.createWorkbook(); - Sheet workSheet = wb1.createSheet("Sheet1"); - Cell cell; - Row row = workSheet.createRow(0); + try (Workbook wb1 = _testDataProvider.createWorkbook()) { + Sheet workSheet = wb1.createSheet("Sheet1"); + Cell cell; + Row row = workSheet.createRow(0); - cell = row.createCell(0, CellType.NUMERIC); - cell.setCellValue(1.0); - assertEquals(CellType.NUMERIC, cell.getCellType()); - assertEquals(1.0, cell.getNumericCellValue(), 0.0); + cell = row.createCell(0, CellType.NUMERIC); + cell.setCellValue(1.0); + assertEquals(CellType.NUMERIC, cell.getCellType()); + assertEquals(1.0, cell.getNumericCellValue(), 0.0); - cell = row.createCell(1, CellType.NUMERIC); - cell.setCellValue(2.0); - assertEquals(CellType.NUMERIC, cell.getCellType()); - assertEquals(2.0, cell.getNumericCellValue(), 0.0); + cell = row.createCell(1, CellType.NUMERIC); + cell.setCellValue(2.0); + assertEquals(CellType.NUMERIC, cell.getCellType()); + assertEquals(2.0, cell.getNumericCellValue(), 0.0); - cell = row.createCell(2, CellType.FORMULA); - cell.setCellFormula("SUM(A1:B1)"); - assertEquals(CellType.FORMULA, cell.getCellType()); - assertEquals("SUM(A1:B1)", cell.getCellFormula()); + cell = row.createCell(2, CellType.FORMULA); + cell.setCellFormula("SUM(A1:B1)"); + assertEquals(CellType.FORMULA, cell.getCellType()); + assertEquals("SUM(A1:B1)", cell.getCellFormula()); - //serialize and check again - Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1); - wb1.close(); - row = wb2.getSheetAt(0).getRow(0); - cell = row.getCell(0); - assertEquals(CellType.NUMERIC, cell.getCellType()); - assertEquals(1.0, cell.getNumericCellValue(), 0.0); + //serialize and check again + try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) { + row = wb2.getSheetAt(0).getRow(0); + cell = row.getCell(0); + assertEquals(CellType.NUMERIC, cell.getCellType()); + assertEquals(1.0, cell.getNumericCellValue(), 0.0); - cell = row.getCell(1); - assertEquals(CellType.NUMERIC, cell.getCellType()); - assertEquals(2.0, cell.getNumericCellValue(), 0.0); + cell = row.getCell(1); + assertEquals(CellType.NUMERIC, cell.getCellType()); + assertEquals(2.0, cell.getNumericCellValue(), 0.0); - cell = row.getCell(2); - assertEquals(CellType.FORMULA, cell.getCellType()); - assertEquals("SUM(A1:B1)", cell.getCellFormula()); - wb2.close(); + cell = row.getCell(2); + assertEquals(CellType.FORMULA, cell.getCellType()); + assertEquals("SUM(A1:B1)", cell.getCellFormula()); + } + } } @Test public void testSetStringInFormulaCell_bug44606() throws Exception { - Workbook wb = _testDataProvider.createWorkbook(); - Cell cell = wb.createSheet("Sheet1").createRow(0).createCell(0); - cell.setCellFormula("B1&C1"); - assertEquals(CellType.FORMULA, cell.getCellType()); - cell.setCellValue(wb.getCreationHelper().createRichTextString("hello")); - assertEquals(CellType.FORMULA, cell.getCellType()); - wb.close(); + try (Workbook wb = _testDataProvider.createWorkbook()) { + Cell cell = wb.createSheet("Sheet1").createRow(0).createCell(0); + cell.setCellFormula("B1&C1"); + assertEquals(CellType.FORMULA, cell.getCellType()); + cell.setCellValue(wb.getCreationHelper().createRichTextString("hello")); + assertEquals(CellType.FORMULA, cell.getCellType()); + } } /** @@ -671,15 +640,15 @@ public abstract class BaseTestCell { */ @Test public void testSetBlank_bug47028() throws Exception { - Workbook wb = _testDataProvider.createWorkbook(); - CellStyle style = wb.createCellStyle(); - Cell cell = wb.createSheet("Sheet1").createRow(0).createCell(0); - cell.setCellStyle(style); - int i1 = cell.getCellStyle().getIndex(); - cell.setBlank(); - int i2 = cell.getCellStyle().getIndex(); - assertEquals(i1, i2); - wb.close(); + try (Workbook wb = _testDataProvider.createWorkbook()) { + CellStyle style = wb.createCellStyle(); + Cell cell = wb.createSheet("Sheet1").createRow(0).createCell(0); + cell.setCellStyle(style); + int i1 = cell.getCellStyle().getIndex(); + cell.setBlank(); + int i2 = cell.getCellStyle().getIndex(); + assertEquals(i1, i2); + } } /** @@ -694,7 +663,7 @@ public abstract class BaseTestCell { * *
  • * Not-a-Number (NaN): - * NaN is used to represent invalid operations (such as infinity/infinity, + * NaN is used to represent invalid operations (such as infinity/infinity, * infinity-infinity, or the square root of -1). NaNs allow a program to * continue past an invalid operation. Excel instead immediately generates * an error such as #NUM! or #DIV/0!. @@ -703,143 +672,142 @@ public abstract class BaseTestCell { */ @Test public void testNanAndInfinity() throws Exception { - Workbook wb1 = _testDataProvider.createWorkbook(); - Sheet workSheet = wb1.createSheet("Sheet1"); - Row row = workSheet.createRow(0); + try (Workbook wb1 = _testDataProvider.createWorkbook()) { + Sheet workSheet = wb1.createSheet("Sheet1"); + Row row = workSheet.createRow(0); - Cell cell0 = row.createCell(0); - cell0.setCellValue(Double.NaN); - assertEquals("Double.NaN should change cell type to CellType#ERROR", CellType.ERROR, cell0.getCellType()); - assertEquals("Double.NaN should change cell value to #NUM!", FormulaError.NUM, forInt(cell0.getErrorCellValue())); + Cell cell0 = row.createCell(0); + cell0.setCellValue(Double.NaN); + assertEquals("Double.NaN should change cell type to CellType#ERROR", CellType.ERROR, cell0.getCellType()); + assertEquals("Double.NaN should change cell value to #NUM!", FormulaError.NUM, forInt(cell0.getErrorCellValue())); - Cell cell1 = row.createCell(1); - cell1.setCellValue(Double.POSITIVE_INFINITY); - assertEquals("Double.POSITIVE_INFINITY should change cell type to CellType#ERROR", CellType.ERROR, cell1.getCellType()); - assertEquals("Double.POSITIVE_INFINITY should change cell value to #DIV/0!", FormulaError.DIV0, forInt(cell1.getErrorCellValue())); + Cell cell1 = row.createCell(1); + cell1.setCellValue(Double.POSITIVE_INFINITY); + assertEquals("Double.POSITIVE_INFINITY should change cell type to CellType#ERROR", CellType.ERROR, cell1.getCellType()); + assertEquals("Double.POSITIVE_INFINITY should change cell value to #DIV/0!", FormulaError.DIV0, forInt(cell1.getErrorCellValue())); - Cell cell2 = row.createCell(2); - cell2.setCellValue(Double.NEGATIVE_INFINITY); - assertEquals("Double.NEGATIVE_INFINITY should change cell type to CellType#ERROR", CellType.ERROR, cell2.getCellType()); - assertEquals("Double.NEGATIVE_INFINITY should change cell value to #DIV/0!", FormulaError.DIV0, forInt(cell2.getErrorCellValue())); + Cell cell2 = row.createCell(2); + cell2.setCellValue(Double.NEGATIVE_INFINITY); + assertEquals("Double.NEGATIVE_INFINITY should change cell type to CellType#ERROR", CellType.ERROR, cell2.getCellType()); + assertEquals("Double.NEGATIVE_INFINITY should change cell value to #DIV/0!", FormulaError.DIV0, forInt(cell2.getErrorCellValue())); - Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1); - wb1.close(); - row = wb2.getSheetAt(0).getRow(0); + try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) { + row = wb2.getSheetAt(0).getRow(0); - cell0 = row.getCell(0); - assertEquals(CellType.ERROR, cell0.getCellType()); - assertEquals(FormulaError.NUM, forInt(cell0.getErrorCellValue())); + cell0 = row.getCell(0); + assertEquals(CellType.ERROR, cell0.getCellType()); + assertEquals(FormulaError.NUM, forInt(cell0.getErrorCellValue())); - cell1 = row.getCell(1); - assertEquals(CellType.ERROR, cell1.getCellType()); - assertEquals(FormulaError.DIV0, forInt(cell1.getErrorCellValue())); + cell1 = row.getCell(1); + assertEquals(CellType.ERROR, cell1.getCellType()); + assertEquals(FormulaError.DIV0, forInt(cell1.getErrorCellValue())); - cell2 = row.getCell(2); - assertEquals(CellType.ERROR, cell2.getCellType()); - assertEquals(FormulaError.DIV0, forInt(cell2.getErrorCellValue())); - wb2.close(); + cell2 = row.getCell(2); + assertEquals(CellType.ERROR, cell2.getCellType()); + assertEquals(FormulaError.DIV0, forInt(cell2.getErrorCellValue())); + } + } } @Test public void testDefaultStyleProperties() throws Exception { - Workbook wb1 = _testDataProvider.createWorkbook(); + try (Workbook wb1 = _testDataProvider.createWorkbook()) { - Cell cell = wb1.createSheet("Sheet1").createRow(0).createCell(0); - CellStyle style = cell.getCellStyle(); + Cell cell = wb1.createSheet("Sheet1").createRow(0).createCell(0); + CellStyle style = cell.getCellStyle(); - assertTrue(style.getLocked()); - assertFalse(style.getHidden()); - assertEquals(0, style.getIndention()); - assertEquals(0, style.getFontIndexAsInt()); - assertEquals(HorizontalAlignment.GENERAL, style.getAlignment()); - assertEquals(0, style.getDataFormat()); - assertFalse(style.getWrapText()); + assertTrue(style.getLocked()); + assertFalse(style.getHidden()); + assertEquals(0, style.getIndention()); + assertEquals(0, style.getFontIndexAsInt()); + assertEquals(HorizontalAlignment.GENERAL, style.getAlignment()); + assertEquals(0, style.getDataFormat()); + assertFalse(style.getWrapText()); - CellStyle style2 = wb1.createCellStyle(); - assertTrue(style2.getLocked()); - assertFalse(style2.getHidden()); - style2.setLocked(false); - style2.setHidden(true); - assertFalse(style2.getLocked()); - assertTrue(style2.getHidden()); + CellStyle style2 = wb1.createCellStyle(); + assertTrue(style2.getLocked()); + assertFalse(style2.getHidden()); + style2.setLocked(false); + style2.setHidden(true); + assertFalse(style2.getLocked()); + assertTrue(style2.getHidden()); - Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1); - wb1.close(); - cell = wb2.getSheetAt(0).getRow(0).getCell(0); - style = cell.getCellStyle(); - assertFalse(style2.getLocked()); - assertTrue(style2.getHidden()); - assertTrue(style.getLocked()); - assertFalse(style.getHidden()); + try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) { + cell = wb2.getSheetAt(0).getRow(0).getCell(0); + style = cell.getCellStyle(); + assertFalse(style2.getLocked()); + assertTrue(style2.getHidden()); + assertTrue(style.getLocked()); + assertFalse(style.getHidden()); - style2.setLocked(true); - style2.setHidden(false); - assertTrue(style2.getLocked()); - assertFalse(style2.getHidden()); - wb2.close(); + style2.setLocked(true); + style2.setHidden(false); + assertTrue(style2.getLocked()); + assertFalse(style2.getHidden()); + } + } } @Test public void testBug55658SetNumericValue() throws Exception { - Workbook wb1 = _testDataProvider.createWorkbook(); - Sheet sh = wb1.createSheet(); - Row row = sh.createRow(0); - Cell cell = row.createCell(0); - cell.setCellValue(Integer.valueOf(23)); - - cell.setCellValue("some"); + try (Workbook wb1 = _testDataProvider.createWorkbook()) { + Sheet sh = wb1.createSheet(); + Row row = sh.createRow(0); + Cell cell = row.createCell(0); + cell.setCellValue(Integer.valueOf(23)); - cell = row.createCell(1); - cell.setCellValue(Integer.valueOf(23)); - - cell.setCellValue("24"); + cell.setCellValue("some"); - Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1); - wb1.close(); + cell = row.createCell(1); + cell.setCellValue(Integer.valueOf(23)); - assertEquals("some", wb2.getSheetAt(0).getRow(0).getCell(0).getStringCellValue()); - assertEquals("24", wb2.getSheetAt(0).getRow(0).getCell(1).getStringCellValue()); - wb2.close(); + cell.setCellValue("24"); + + try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) { + assertEquals("some", wb2.getSheetAt(0).getRow(0).getCell(0).getStringCellValue()); + assertEquals("24", wb2.getSheetAt(0).getRow(0).getCell(1).getStringCellValue()); + } + } } @Test public void testRemoveHyperlink() throws Exception { - Workbook wb1 = _testDataProvider.createWorkbook(); - Sheet sh = wb1.createSheet("test"); - Row row = sh.createRow(0); - CreationHelper helper = wb1.getCreationHelper(); + try (Workbook wb1 = _testDataProvider.createWorkbook()) { + Sheet sh = wb1.createSheet("test"); + Row row = sh.createRow(0); + CreationHelper helper = wb1.getCreationHelper(); - Cell cell1 = row.createCell(1); - Hyperlink link1 = helper.createHyperlink(HyperlinkType.URL); - cell1.setHyperlink(link1); - assertNotNull(cell1.getHyperlink()); - cell1.removeHyperlink(); - assertNull(cell1.getHyperlink()); + Cell cell1 = row.createCell(1); + Hyperlink link1 = helper.createHyperlink(HyperlinkType.URL); + cell1.setHyperlink(link1); + assertNotNull(cell1.getHyperlink()); + cell1.removeHyperlink(); + assertNull(cell1.getHyperlink()); - Cell cell2 = row.createCell(0); - Hyperlink link2 = helper.createHyperlink(HyperlinkType.URL); - cell2.setHyperlink(link2); - assertNotNull(cell2.getHyperlink()); - cell2.setHyperlink(null); - assertNull(cell2.getHyperlink()); + Cell cell2 = row.createCell(0); + Hyperlink link2 = helper.createHyperlink(HyperlinkType.URL); + cell2.setHyperlink(link2); + assertNotNull(cell2.getHyperlink()); + cell2.setHyperlink(null); + assertNull(cell2.getHyperlink()); - Cell cell3 = row.createCell(2); - Hyperlink link3 = helper.createHyperlink(HyperlinkType.URL); - link3.setAddress("http://poi.apache.org/"); - cell3.setHyperlink(link3); - assertNotNull(cell3.getHyperlink()); + Cell cell3 = row.createCell(2); + Hyperlink link3 = helper.createHyperlink(HyperlinkType.URL); + link3.setAddress("http://poi.apache.org/"); + cell3.setHyperlink(link3); + assertNotNull(cell3.getHyperlink()); - Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1); - wb1.close(); - assertNotNull(wb2); - - cell1 = wb2.getSheet("test").getRow(0).getCell(1); - assertNull(cell1.getHyperlink()); - cell2 = wb2.getSheet("test").getRow(0).getCell(0); - assertNull(cell2.getHyperlink()); - cell3 = wb2.getSheet("test").getRow(0).getCell(2); - assertNotNull(cell3.getHyperlink()); - wb2.close(); + try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) { + assertNotNull(wb2); + + cell1 = wb2.getSheet("test").getRow(0).getCell(1); + assertNull(cell1.getHyperlink()); + cell2 = wb2.getSheet("test").getRow(0).getCell(0); + assertNull(cell2.getHyperlink()); + cell3 = wb2.getSheet("test").getRow(0).getCell(2); + assertNotNull(cell3.getHyperlink()); + } + } } /** @@ -857,45 +825,44 @@ public abstract class BaseTestCell { assertEquals(36, cell.getErrorCellValue()); } } - + @Test public void testSetRemoveStyle() throws Exception { - Workbook wb = _testDataProvider.createWorkbook(); - Sheet sheet = wb.createSheet(); - Row row = sheet.createRow(0); - Cell cell = row.createCell(0); - - // different default style indexes for HSSF and XSSF/SXSSF - CellStyle defaultStyle = wb.getCellStyleAt(wb instanceof HSSFWorkbook ? (short)15 : (short)0); - - // Starts out with the default style - assertEquals(defaultStyle, cell.getCellStyle()); - - // Create some styles, no change - CellStyle style1 = wb.createCellStyle(); - CellStyle style2 = wb.createCellStyle(); - style1.setDataFormat((short)2); - style2.setDataFormat((short)3); - - assertEquals(defaultStyle, cell.getCellStyle()); - - // Apply one, changes - cell.setCellStyle(style1); - assertEquals(style1, cell.getCellStyle()); - - // Apply the other, changes - cell.setCellStyle(style2); - assertEquals(style2, cell.getCellStyle()); - - // Remove, goes back to default - cell.setCellStyle(null); - assertEquals(defaultStyle, cell.getCellStyle()); - - // Add back, returns - cell.setCellStyle(style2); - assertEquals(style2, cell.getCellStyle()); - - wb.close(); + try (Workbook wb = _testDataProvider.createWorkbook()) { + Sheet sheet = wb.createSheet(); + Row row = sheet.createRow(0); + Cell cell = row.createCell(0); + + // different default style indexes for HSSF and XSSF/SXSSF + CellStyle defaultStyle = wb.getCellStyleAt(wb instanceof HSSFWorkbook ? (short) 15 : (short) 0); + + // Starts out with the default style + assertEquals(defaultStyle, cell.getCellStyle()); + + // Create some styles, no change + CellStyle style1 = wb.createCellStyle(); + CellStyle style2 = wb.createCellStyle(); + style1.setDataFormat((short) 2); + style2.setDataFormat((short) 3); + + assertEquals(defaultStyle, cell.getCellStyle()); + + // Apply one, changes + cell.setCellStyle(style1); + assertEquals(style1, cell.getCellStyle()); + + // Apply the other, changes + cell.setCellStyle(style2); + assertEquals(style2, cell.getCellStyle()); + + // Remove, goes back to default + cell.setCellStyle(null); + assertEquals(defaultStyle, cell.getCellStyle()); + + // Add back, returns + cell.setCellStyle(style2); + assertEquals(style2, cell.getCellStyle()); + } } @Test @@ -954,11 +921,11 @@ public abstract class BaseTestCell { } private void checkUnicodeValues(Workbook wb) { - assertEquals((wb instanceof HSSFWorkbook ? "row 0, cell 0 _x0046_ without changes" : "row 0, cell 0 F without changes"), + assertEquals((wb instanceof HSSFWorkbook ? "row 0, cell 0 _x0046_ without changes" : "row 0, cell 0 F without changes"), wb.getSheetAt(0).getRow(0).getCell(0).toString()); - assertEquals((wb instanceof HSSFWorkbook ? "row 0, cell 1 _x005fx0046_ with changes" : "row 0, cell 1 _x005fx0046_ with changes"), + assertEquals((wb instanceof HSSFWorkbook ? "row 0, cell 1 _x005fx0046_ with changes" : "row 0, cell 1 _x005fx0046_ with changes"), wb.getSheetAt(0).getRow(0).getCell(1).toString()); - assertEquals((wb instanceof HSSFWorkbook ? "hgh_x0041_**_x0100_*_x0101_*_x0190_*_x0200_*_x0300_*_x0427_*" : "hghA**\u0100*\u0101*\u0190*\u0200*\u0300*\u0427*"), + assertEquals((wb instanceof HSSFWorkbook ? "hgh_x0041_**_x0100_*_x0101_*_x0190_*_x0200_*_x0300_*_x0427_*" : "hghA**\u0100*\u0101*\u0190*\u0200*\u0300*\u0427*"), wb.getSheetAt(0).getRow(0).getCell(2).toString()); } @@ -1237,205 +1204,215 @@ public abstract class BaseTestCell { @Test(expected = IllegalArgumentException.class) public void setCellType_null_throwsIAE() throws IOException { - Cell cell = getInstance(); - try { + try (Workbook wb = _testDataProvider.createWorkbook()) { + Cell cell = getInstance(wb); cell.setCellType(null); - } finally { - cell.getSheet().getWorkbook().close(); } } @Test(expected = IllegalArgumentException.class) - public void setCellType_NONE_throwsIAE() { - Cell cell = getInstance(); - cell.setCellType(CellType._NONE); + public void setCellType_NONE_throwsIAE() throws IOException { + try (Workbook wb = _testDataProvider.createWorkbook()) { + Cell cell = getInstance(wb); + cell.setCellType(CellType._NONE); + } } @Test - public void setBlank_removesArrayFormula_ifCellIsPartOfAnArrayFormulaGroupContainingOnlyThisCell() { - Cell cell = getInstance(); + public void setBlank_removesArrayFormula_ifCellIsPartOfAnArrayFormulaGroupContainingOnlyThisCell() throws IOException { + try (Workbook wb = _testDataProvider.createWorkbook()) { + Cell cell = getInstance(wb); - cell.getSheet().setArrayFormula("1", CellRangeAddress.valueOf("A1")); - cell.setCellValue("foo"); - assertTrue(cell.isPartOfArrayFormulaGroup()); - assertEquals("1", cell.getCellFormula()); + cell.getSheet().setArrayFormula("1", CellRangeAddress.valueOf("A1")); + cell.setCellValue("foo"); + assertTrue(cell.isPartOfArrayFormulaGroup()); + assertEquals("1", cell.getCellFormula()); - cell.setBlank(); + cell.setBlank(); - assertEquals(CellType.BLANK, cell.getCellType()); - assertFalse(cell.isPartOfArrayFormulaGroup()); + assertEquals(CellType.BLANK, cell.getCellType()); + assertFalse(cell.isPartOfArrayFormulaGroup()); + } } @Test(expected = IllegalStateException.class) - public void setBlank_throwsISE_ifCellIsPartOfAnArrayFormulaGroupContainingOtherCells() { - Cell cell = getInstance(); - cell.getSheet().setArrayFormula("1", CellRangeAddress.valueOf("A1:B1")); - cell.setCellValue("foo"); - cell.setBlank(); + public void setBlank_throwsISE_ifCellIsPartOfAnArrayFormulaGroupContainingOtherCells() throws IOException { + try (Workbook wb = _testDataProvider.createWorkbook()) { + Cell cell = getInstance(wb); + cell.getSheet().setArrayFormula("1", CellRangeAddress.valueOf("A1:B1")); + cell.setCellValue("foo"); + cell.setBlank(); + } } @Test(expected = IllegalStateException.class) public void setCellFormula_throwsISE_ifCellIsPartOfAnArrayFormulaGroupContainingOtherCells() throws IOException { - Cell cell = getInstance(); + try (Workbook wb = _testDataProvider.createWorkbook()) { + Cell cell = getInstance(wb); - try { cell.getSheet().setArrayFormula("1", CellRangeAddress.valueOf("A1:B1")); assertTrue(cell.isPartOfArrayFormulaGroup()); assertEquals(CellType.FORMULA, cell.getCellType()); cell.setCellFormula("1"); - } finally { - cell.getSheet().getWorkbook().close(); } } @Test - public void removeFormula_preservesValue() { - Cell cell = getInstance(); + public void removeFormula_preservesValue() throws IOException { + try (Workbook wb = _testDataProvider.createWorkbook()) { + Cell cell = getInstance(wb); - cell.setCellFormula("#DIV/0!"); - cell.setCellValue(true); - cell.removeFormula(); - assertEquals(CellType.BOOLEAN, cell.getCellType()); - assertTrue(cell.getBooleanCellValue()); + cell.setCellFormula("#DIV/0!"); + cell.setCellValue(true); + cell.removeFormula(); + assertEquals(CellType.BOOLEAN, cell.getCellType()); + assertTrue(cell.getBooleanCellValue()); - cell.setCellFormula("#DIV/0!"); - cell.setCellValue(2); - cell.removeFormula(); - assertEquals(CellType.NUMERIC, cell.getCellType()); - assertEquals(2, cell.getNumericCellValue(), 0); + cell.setCellFormula("#DIV/0!"); + cell.setCellValue(2); + cell.removeFormula(); + assertEquals(CellType.NUMERIC, cell.getCellType()); + assertEquals(2, cell.getNumericCellValue(), 0); - cell.setCellFormula("#DIV/0!"); - cell.setCellValue("foo"); - cell.removeFormula(); - assertEquals(CellType.STRING, cell.getCellType()); - assertEquals("foo", cell.getStringCellValue()); + cell.setCellFormula("#DIV/0!"); + cell.setCellValue("foo"); + cell.removeFormula(); + assertEquals(CellType.STRING, cell.getCellType()); + assertEquals("foo", cell.getStringCellValue()); - cell.setCellFormula("#DIV/0!"); - cell.setCellErrorValue(FormulaError.NUM.getCode()); - cell.removeFormula(); - assertEquals(CellType.ERROR, cell.getCellType()); - assertEquals(FormulaError.NUM.getCode(), cell.getErrorCellValue()); + cell.setCellFormula("#DIV/0!"); + cell.setCellErrorValue(FormulaError.NUM.getCode()); + cell.removeFormula(); + assertEquals(CellType.ERROR, cell.getCellType()); + assertEquals(FormulaError.NUM.getCode(), cell.getErrorCellValue()); + } } @Test - public void removeFormula_turnsCellToBlank_whenFormulaWasASingleCellArrayFormula() { - Cell cell = getInstance(); + public void removeFormula_turnsCellToBlank_whenFormulaWasASingleCellArrayFormula() throws IOException { + try (Workbook wb = _testDataProvider.createWorkbook()) { + Cell cell = getInstance(wb); - cell.getSheet().setArrayFormula("#DIV/0!", CellRangeAddress.valueOf("A1")); - cell.setCellValue(true); - cell.removeFormula(); - assertEquals(CellType.BLANK, cell.getCellType()); + cell.getSheet().setArrayFormula("#DIV/0!", CellRangeAddress.valueOf("A1")); + cell.setCellValue(true); + cell.removeFormula(); + assertEquals(CellType.BLANK, cell.getCellType()); - cell.getSheet().setArrayFormula("#DIV/0!", CellRangeAddress.valueOf("A1")); - cell.setCellValue(2); - cell.removeFormula(); - assertEquals(CellType.BLANK, cell.getCellType()); + cell.getSheet().setArrayFormula("#DIV/0!", CellRangeAddress.valueOf("A1")); + cell.setCellValue(2); + cell.removeFormula(); + assertEquals(CellType.BLANK, cell.getCellType()); - cell.getSheet().setArrayFormula("#DIV/0!", CellRangeAddress.valueOf("A1")); - cell.setCellValue(true); - cell.removeFormula(); - assertEquals(CellType.BLANK, cell.getCellType()); + cell.getSheet().setArrayFormula("#DIV/0!", CellRangeAddress.valueOf("A1")); + cell.setCellValue(true); + cell.removeFormula(); + assertEquals(CellType.BLANK, cell.getCellType()); - cell.getSheet().setArrayFormula("#DIV/0!", CellRangeAddress.valueOf("A1")); - cell.setCellErrorValue(FormulaError.NUM.getCode()); - cell.removeFormula(); - assertEquals(CellType.BLANK, cell.getCellType()); + cell.getSheet().setArrayFormula("#DIV/0!", CellRangeAddress.valueOf("A1")); + cell.setCellErrorValue(FormulaError.NUM.getCode()); + cell.removeFormula(); + assertEquals(CellType.BLANK, cell.getCellType()); + } } @Test public void setCellFormula_onABlankCell_setsValueToZero() throws IOException { - Cell cell = getInstance(); - cell.setCellFormula("\"foo\""); - assertEquals(CellType.FORMULA, cell.getCellType()); - assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType()); - assertEquals(0, cell.getNumericCellValue(), 0); - cell.getSheet().getWorkbook().close(); + try (Workbook wb = _testDataProvider.createWorkbook()) { + Cell cell = getInstance(wb); + cell.setCellFormula("\"foo\""); + assertEquals(CellType.FORMULA, cell.getCellType()); + assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType()); + assertEquals(0, cell.getNumericCellValue(), 0); + } } @Test public void setCellFormula_onANonBlankCell_preservesTheValue() throws IOException { - Cell cell = getInstance(); - cell.setCellValue(true); - cell.setCellFormula("\"foo\""); - assertEquals(CellType.FORMULA, cell.getCellType()); - assertEquals(CellType.BOOLEAN, cell.getCachedFormulaResultType()); - assertTrue(cell.getBooleanCellValue()); - cell.getSheet().getWorkbook().close(); + try (Workbook wb = _testDataProvider.createWorkbook()) { + Cell cell = getInstance(wb); + cell.setCellValue(true); + cell.setCellFormula("\"foo\""); + assertEquals(CellType.FORMULA, cell.getCellType()); + assertEquals(CellType.BOOLEAN, cell.getCachedFormulaResultType()); + assertTrue(cell.getBooleanCellValue()); + } } @Test - public void setCellFormula_onAFormulaCell_changeFormula_preservesTheValue() { - Cell cell = getInstance(); - cell.setCellFormula("\"foo\""); - cell.setCellValue(true); - assertEquals(CellType.FORMULA, cell.getCellType()); - assertEquals(CellType.BOOLEAN, cell.getCachedFormulaResultType()); - assertTrue(cell.getBooleanCellValue()); + public void setCellFormula_onAFormulaCell_changeFormula_preservesTheValue() throws IOException { + try (Workbook wb = _testDataProvider.createWorkbook()) { + Cell cell = getInstance(wb); + cell.setCellFormula("\"foo\""); + cell.setCellValue(true); + assertEquals(CellType.FORMULA, cell.getCellType()); + assertEquals(CellType.BOOLEAN, cell.getCachedFormulaResultType()); + assertTrue(cell.getBooleanCellValue()); - cell.setCellFormula("\"bar\""); - assertEquals(CellType.FORMULA, cell.getCellType()); - assertEquals(CellType.BOOLEAN, cell.getCachedFormulaResultType()); - assertTrue(cell.getBooleanCellValue()); + cell.setCellFormula("\"bar\""); + assertEquals(CellType.FORMULA, cell.getCellType()); + assertEquals(CellType.BOOLEAN, cell.getCachedFormulaResultType()); + assertTrue(cell.getBooleanCellValue()); + } } @Test - public void setCellFormula_onASingleCellArrayFormulaCell_preservesTheValue() { - Cell cell = getInstance(); - cell.getSheet().setArrayFormula("\"foo\"", CellRangeAddress.valueOf("A1")); - cell.setCellValue(true); + public void setCellFormula_onASingleCellArrayFormulaCell_preservesTheValue() throws IOException { + try (Workbook wb = _testDataProvider.createWorkbook()) { + Cell cell = getInstance(wb); + cell.getSheet().setArrayFormula("\"foo\"", CellRangeAddress.valueOf("A1")); + cell.setCellValue(true); - assertTrue(cell.isPartOfArrayFormulaGroup()); - assertEquals(CellType.FORMULA, cell.getCellType()); - assertEquals(CellType.BOOLEAN, cell.getCachedFormulaResultType()); - assertTrue(cell.getBooleanCellValue()); + assertTrue(cell.isPartOfArrayFormulaGroup()); + assertEquals(CellType.FORMULA, cell.getCellType()); + assertEquals(CellType.BOOLEAN, cell.getCachedFormulaResultType()); + assertTrue(cell.getBooleanCellValue()); - cell.getSheet().setArrayFormula("\"bar\"", CellRangeAddress.valueOf("A1")); - assertEquals(CellType.FORMULA, cell.getCellType()); - assertEquals(CellType.BOOLEAN, cell.getCachedFormulaResultType()); - assertTrue(cell.getBooleanCellValue()); + cell.getSheet().setArrayFormula("\"bar\"", CellRangeAddress.valueOf("A1")); + assertEquals(CellType.FORMULA, cell.getCellType()); + assertEquals(CellType.BOOLEAN, cell.getCachedFormulaResultType()); + assertTrue(cell.getBooleanCellValue()); + } } @Test(expected = IllegalArgumentException.class) public void setCellType_FORMULA_onANonFormulaCell_throwsIllegalArgumentException() throws IOException { - Cell cell = getInstance(); - try { + try (Workbook wb = _testDataProvider.createWorkbook()) { + Cell cell = getInstance(wb); cell.setCellType(CellType.FORMULA); - } finally { - cell.getSheet().getWorkbook().close(); } } @Test public void setCellType_FORMULA_onAFormulaCell_doesNothing() throws IOException { - Cell cell = getInstance(); - try { + try (Workbook wb = _testDataProvider.createWorkbook()) { + Cell cell = getInstance(wb); cell.setCellFormula("3"); cell.setCellValue("foo"); - + cell.setCellType(CellType.FORMULA); - + assertEquals(CellType.FORMULA, cell.getCellType()); assertEquals(CellType.STRING, cell.getCachedFormulaResultType()); assertEquals("foo", cell.getStringCellValue()); - } finally { - cell.getSheet().getWorkbook().close(); } } @Test - public void setCellType_FORMULA_onAnArrayFormulaCell_doesNothing() { - Cell cell = getInstance(); - cell.getSheet().setArrayFormula("3", CellRangeAddress.valueOf("A1:A2")); - cell.setCellValue("foo"); + public void setCellType_FORMULA_onAnArrayFormulaCell_doesNothing() throws IOException { + try (Workbook wb = _testDataProvider.createWorkbook()) { + Cell cell = getInstance(wb); + cell.getSheet().setArrayFormula("3", CellRangeAddress.valueOf("A1:A2")); + cell.setCellValue("foo"); - cell.setCellType(CellType.FORMULA); + cell.setCellType(CellType.FORMULA); - assertEquals(CellType.FORMULA, cell.getCellType()); - assertEquals(CellType.STRING, cell.getCachedFormulaResultType()); - assertEquals("foo", cell.getStringCellValue()); + assertEquals(CellType.FORMULA, cell.getCellType()); + assertEquals(CellType.STRING, cell.getCachedFormulaResultType()); + assertEquals("foo", cell.getStringCellValue()); + } } @Test @@ -1448,17 +1425,7 @@ public abstract class BaseTestCell { verify(cell).setBlank(); } - private List workbooksToClose = new ArrayList<>(); - - @After - public void closeWorkbooks() throws IOException { - for (Workbook workbook : workbooksToClose) { - workbook.close(); - } - } - private Cell getInstance() { - Workbook workbookToClose = _testDataProvider.createWorkbook(); - workbooksToClose.add(workbookToClose); - return workbookToClose.createSheet().createRow(0).createCell(0); + private Cell getInstance(Workbook wb) { + return wb.createSheet().createRow(0).createCell(0); } } diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java index 7f499cdad4..0c81191b1a 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java @@ -24,8 +24,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; import java.io.IOException; import java.util.Arrays; @@ -40,9 +40,6 @@ import org.junit.Test; /** * Common superclass for testing usermodel API for array formulas.
    * Formula evaluation is not tested here. - * - * @author Yegor Kozlov - * @author Josh Micich */ public abstract class BaseTestSheetUpdateArrayFormulas { protected final ITestDataProvider _testDataProvider; @@ -53,23 +50,22 @@ public abstract class BaseTestSheetUpdateArrayFormulas { @Test public final void testAutoCreateOtherCells() throws IOException { - Workbook workbook = _testDataProvider.createWorkbook(); - Sheet sheet = workbook.createSheet("Sheet1"); + try (Workbook workbook = _testDataProvider.createWorkbook()) { + Sheet sheet = workbook.createSheet("Sheet1"); - Row row1 = sheet.createRow(0); - Cell cellA1 = row1.createCell(0); - Cell cellB1 = row1.createCell(1); - String formula = "42"; - sheet.setArrayFormula(formula, CellRangeAddress.valueOf("A1:B2")); + Row row1 = sheet.createRow(0); + Cell cellA1 = row1.createCell(0); + Cell cellB1 = row1.createCell(1); + String formula = "42"; + sheet.setArrayFormula(formula, CellRangeAddress.valueOf("A1:B2")); - assertEquals(formula, cellA1.getCellFormula()); - assertEquals(formula, cellB1.getCellFormula()); - Row row2 = sheet.getRow(1); - assertNotNull(row2); - assertEquals(formula, row2.getCell(0).getCellFormula()); - assertEquals(formula, row2.getCell(1).getCellFormula()); - - workbook.close(); + assertEquals(formula, cellA1.getCellFormula()); + assertEquals(formula, cellB1.getCellFormula()); + Row row2 = sheet.getRow(1); + assertNotNull(row2); + assertEquals(formula, row2.getCell(0).getCellFormula()); + assertEquals(formula, row2.getCell(1).getCellFormula()); + } } /** @@ -77,36 +73,33 @@ public abstract class BaseTestSheetUpdateArrayFormulas { */ @Test public final void testSetArrayFormula_singleCell() throws IOException { - Cell[] cells; + try (Workbook workbook = _testDataProvider.createWorkbook()) { + Sheet sheet = workbook.createSheet(); + Cell cell = sheet.createRow(0).createCell(0); + assertFalse(cell.isPartOfArrayFormulaGroup()); + try { + cell.getArrayFormulaRange(); + fail("expected exception"); + } catch (IllegalStateException e) { + assertEquals("Cell Sheet0!A1 is not part of an array formula.", e.getMessage()); + } - Workbook workbook = _testDataProvider.createWorkbook(); - Sheet sheet = workbook.createSheet(); - Cell cell = sheet.createRow(0).createCell(0); - assertFalse(cell.isPartOfArrayFormulaGroup()); - try { - cell.getArrayFormulaRange(); - fail("expected exception"); - } catch (IllegalStateException e){ - assertEquals("Cell Sheet0!A1 is not part of an array formula.", e.getMessage()); + // row 3 does not yet exist + assertNull(sheet.getRow(2)); + CellRangeAddress range = new CellRangeAddress(2, 2, 2, 2); + Cell[] cells = sheet.setArrayFormula("SUM(C11:C12*D11:D12)", range).getFlattenedCells(); + assertEquals(1, cells.length); + // sheet.setArrayFormula creates rows and cells for the designated range + assertNotNull(sheet.getRow(2)); + cell = sheet.getRow(2).getCell(2); + assertNotNull(cell); + + assertTrue(cell.isPartOfArrayFormulaGroup()); + //retrieve the range and check it is the same + assertEquals(range.formatAsString(), cell.getArrayFormulaRange().formatAsString()); + //check the formula + assertEquals("SUM(C11:C12*D11:D12)", cell.getCellFormula()); } - - // row 3 does not yet exist - assertNull(sheet.getRow(2)); - CellRangeAddress range = new CellRangeAddress(2, 2, 2, 2); - cells = sheet.setArrayFormula("SUM(C11:C12*D11:D12)", range).getFlattenedCells(); - assertEquals(1, cells.length); - // sheet.setArrayFormula creates rows and cells for the designated range - assertNotNull(sheet.getRow(2)); - cell = sheet.getRow(2).getCell(2); - assertNotNull(cell); - - assertTrue(cell.isPartOfArrayFormulaGroup()); - //retrieve the range and check it is the same - assertEquals(range.formatAsString(), cell.getArrayFormulaRange().formatAsString()); - //check the formula - assertEquals("SUM(C11:C12*D11:D12)", cell.getCellFormula()); - - workbook.close(); } /** @@ -114,53 +107,45 @@ public abstract class BaseTestSheetUpdateArrayFormulas { */ @Test public final void testSetArrayFormula_multiCell() throws IOException { - Workbook workbook = _testDataProvider.createWorkbook(); - Sheet sheet = workbook.createSheet(); + try (Workbook workbook = _testDataProvider.createWorkbook()) { + Sheet sheet = workbook.createSheet(); - // multi-cell formula - // rows 3-5 don't exist yet - assertNull(sheet.getRow(3)); - assertNull(sheet.getRow(4)); - assertNull(sheet.getRow(5)); + // multi-cell formula + // rows 3-5 don't exist yet + assertNull(sheet.getRow(3)); + assertNull(sheet.getRow(4)); + assertNull(sheet.getRow(5)); - CellRangeAddress range = CellRangeAddress.valueOf("C4:C6"); - Cell[] cells = sheet.setArrayFormula("SUM(A1:A3*B1:B3)", range).getFlattenedCells(); - assertEquals(3, cells.length); + CellRangeAddress range = CellRangeAddress.valueOf("C4:C6"); + Cell[] cells = sheet.setArrayFormula("SUM(A1:A3*B1:B3)", range).getFlattenedCells(); + assertEquals(3, cells.length); - // sheet.setArrayFormula creates rows and cells for the designated range - assertSame(cells[0], sheet.getRow(3).getCell(2)); - assertSame(cells[1], sheet.getRow(4).getCell(2)); - assertSame(cells[2], sheet.getRow(5).getCell(2)); + // sheet.setArrayFormula creates rows and cells for the designated range + assertSame(cells[0], sheet.getRow(3).getCell(2)); + assertSame(cells[1], sheet.getRow(4).getCell(2)); + assertSame(cells[2], sheet.getRow(5).getCell(2)); - for(Cell acell : cells){ - assertTrue(acell.isPartOfArrayFormulaGroup()); - assertEquals(CellType.FORMULA, acell.getCellType()); - assertEquals("SUM(A1:A3*B1:B3)", acell.getCellFormula()); - //retrieve the range and check it is the same - assertEquals(range.formatAsString(), acell.getArrayFormulaRange().formatAsString()); + for (Cell acell : cells) { + assertTrue(acell.isPartOfArrayFormulaGroup()); + assertEquals(CellType.FORMULA, acell.getCellType()); + assertEquals("SUM(A1:A3*B1:B3)", acell.getCellFormula()); + //retrieve the range and check it is the same + assertEquals(range.formatAsString(), acell.getArrayFormulaRange().formatAsString()); + } } - - workbook.close(); } /** * Passing an incorrect formula to sheet.setArrayFormula * should throw FormulaParseException */ - @Test + @Test(expected = FormulaParseException.class) public final void testSetArrayFormula_incorrectFormula() throws IOException { - Workbook workbook = _testDataProvider.createWorkbook(); - Sheet sheet = workbook.createSheet(); - - try { - sheet.setArrayFormula("incorrect-formula(C11_C12*D11_D12)", - new CellRangeAddress(10, 10, 10, 10)); - fail("expected exception"); - } catch (FormulaParseException e){ - //expected exception + try (Workbook workbook = _testDataProvider.createWorkbook()) { + Sheet sheet = workbook.createSheet(); + CellRangeAddress cra = new CellRangeAddress(10, 10, 10, 10); + sheet.setArrayFormula("incorrect-formula(C11_C12*D11_D12)", cra); } - - workbook.close(); } /** @@ -169,26 +154,25 @@ public abstract class BaseTestSheetUpdateArrayFormulas { */ @Test public final void testArrayFormulas_illegalCalls() throws IOException { - Workbook workbook = _testDataProvider.createWorkbook(); - Sheet sheet = workbook.createSheet(); + try (Workbook workbook = _testDataProvider.createWorkbook()) { + Sheet sheet = workbook.createSheet(); - Cell cell = sheet.createRow(0).createCell(0); - assertFalse(cell.isPartOfArrayFormulaGroup()); - try { - cell.getArrayFormulaRange(); - fail("expected exception"); - } catch (IllegalStateException e){ - assertEquals("Cell Sheet0!A1 is not part of an array formula.", e.getMessage()); - } + Cell cell = sheet.createRow(0).createCell(0); + assertFalse(cell.isPartOfArrayFormulaGroup()); + try { + cell.getArrayFormulaRange(); + fail("expected exception"); + } catch (IllegalStateException e) { + assertEquals("Cell Sheet0!A1 is not part of an array formula.", e.getMessage()); + } - try { - sheet.removeArrayFormula(cell); - fail("expected exception"); - } catch (IllegalArgumentException e){ - assertEquals("Cell Sheet0!A1 is not part of an array formula.", e.getMessage()); + try { + sheet.removeArrayFormula(cell); + fail("expected exception"); + } catch (IllegalArgumentException e) { + assertEquals("Cell Sheet0!A1 is not part of an array formula.", e.getMessage()); + } } - - workbook.close(); } /** @@ -196,37 +180,36 @@ public abstract class BaseTestSheetUpdateArrayFormulas { */ @Test public final void testRemoveArrayFormula() throws IOException { - Workbook workbook = _testDataProvider.createWorkbook(); - Sheet sheet = workbook.createSheet(); + try (Workbook workbook = _testDataProvider.createWorkbook()) { + Sheet sheet = workbook.createSheet(); - CellRangeAddress range = new CellRangeAddress(3, 5, 2, 2); - assertEquals("C4:C6", range.formatAsString()); - CellRange cr = sheet.setArrayFormula("SUM(A1:A3*B1:B3)", range); - assertEquals(3, cr.size()); + CellRangeAddress range = new CellRangeAddress(3, 5, 2, 2); + assertEquals("C4:C6", range.formatAsString()); + CellRange cr = sheet.setArrayFormula("SUM(A1:A3*B1:B3)", range); + assertEquals(3, cr.size()); - // remove the formula cells in C4:C6 - CellRange dcells = sheet.removeArrayFormula(cr.getTopLeftCell()); - // removeArrayFormula should return the same cells as setArrayFormula - assertArrayEquals(cr.getFlattenedCells(), dcells.getFlattenedCells()); + // remove the formula cells in C4:C6 + CellRange dcells = sheet.removeArrayFormula(cr.getTopLeftCell()); + // removeArrayFormula should return the same cells as setArrayFormula + assertArrayEquals(cr.getFlattenedCells(), dcells.getFlattenedCells()); - for(Cell acell : cr){ - assertFalse(acell.isPartOfArrayFormulaGroup()); - assertEquals(CellType.BLANK, acell.getCellType()); - } + for (Cell acell : cr) { + assertFalse(acell.isPartOfArrayFormulaGroup()); + assertEquals(CellType.BLANK, acell.getCellType()); + } - // cells C4:C6 are not included in array formula, - // invocation of sheet.removeArrayFormula on any of them throws IllegalArgumentException - for(Cell acell : cr){ - try { - sheet.removeArrayFormula(acell); - fail("expected exception"); - } catch (IllegalArgumentException e){ - String ref = new CellReference(acell).formatAsString(); - assertEquals("Cell " + ref + " is not part of an array formula.", e.getMessage()); + // cells C4:C6 are not included in array formula, + // invocation of sheet.removeArrayFormula on any of them throws IllegalArgumentException + for (Cell acell : cr) { + try { + sheet.removeArrayFormula(acell); + fail("expected exception"); + } catch (IllegalArgumentException e) { + String ref = new CellReference(acell).formatAsString(); + assertEquals("Cell " + ref + " is not part of an array formula.", e.getMessage()); + } } } - - workbook.close(); } /** @@ -234,38 +217,35 @@ public abstract class BaseTestSheetUpdateArrayFormulas { */ @Test public final void testReadArrayFormula() throws IOException { - Cell[] cells; + try (Workbook workbook1 = _testDataProvider.createWorkbook()) { + Sheet sheet1 = workbook1.createSheet(); + Cell[] cells = sheet1.setArrayFormula("SUM(A1:A3*B1:B3)", CellRangeAddress.valueOf("C4:C6")).getFlattenedCells(); + assertEquals(3, cells.length); - Workbook workbook1 = _testDataProvider.createWorkbook(); - Sheet sheet1 = workbook1.createSheet(); - cells = sheet1.setArrayFormula("SUM(A1:A3*B1:B3)", CellRangeAddress.valueOf("C4:C6")).getFlattenedCells(); - assertEquals(3, cells.length); + cells = sheet1.setArrayFormula("MAX(A1:A3*B1:B3)", CellRangeAddress.valueOf("A4:A6")).getFlattenedCells(); + assertEquals(3, cells.length); - cells = sheet1.setArrayFormula("MAX(A1:A3*B1:B3)", CellRangeAddress.valueOf("A4:A6")).getFlattenedCells(); - assertEquals(3, cells.length); + Sheet sheet2 = workbook1.createSheet(); + cells = sheet2.setArrayFormula("MIN(A1:A3*B1:B3)", CellRangeAddress.valueOf("D2:D4")).getFlattenedCells(); + assertEquals(3, cells.length); - Sheet sheet2 = workbook1.createSheet(); - cells = sheet2.setArrayFormula("MIN(A1:A3*B1:B3)", CellRangeAddress.valueOf("D2:D4")).getFlattenedCells(); - assertEquals(3, cells.length); + try (Workbook workbook2 = _testDataProvider.writeOutAndReadBack(workbook1)) { + sheet1 = workbook2.getSheetAt(0); + for (int rownum = 3; rownum <= 5; rownum++) { + Cell cell1 = sheet1.getRow(rownum).getCell(2); + assertTrue(cell1.isPartOfArrayFormulaGroup()); - Workbook workbook2 = _testDataProvider.writeOutAndReadBack(workbook1); - workbook1.close(); - sheet1 = workbook2.getSheetAt(0); - for(int rownum=3; rownum <= 5; rownum++) { - Cell cell1 = sheet1.getRow(rownum).getCell(2); - assertTrue( cell1.isPartOfArrayFormulaGroup()); + Cell cell2 = sheet1.getRow(rownum).getCell(0); + assertTrue(cell2.isPartOfArrayFormulaGroup()); + } - Cell cell2 = sheet1.getRow(rownum).getCell(0); - assertTrue( cell2.isPartOfArrayFormulaGroup()); + sheet2 = workbook2.getSheetAt(1); + for (int rownum = 1; rownum <= 3; rownum++) { + Cell cell1 = sheet2.getRow(rownum).getCell(3); + assertTrue(cell1.isPartOfArrayFormulaGroup()); + } + } } - - sheet2 = workbook2.getSheetAt(1); - for(int rownum=1; rownum <= 3; rownum++) { - Cell cell1 = sheet2.getRow(rownum).getCell(3); - assertTrue( cell1.isPartOfArrayFormulaGroup()); - } - - workbook2.close(); } /** @@ -273,293 +253,291 @@ public abstract class BaseTestSheetUpdateArrayFormulas { */ @Test public void testModifyArrayCells_setFormulaResult() throws IOException { - Workbook workbook = _testDataProvider.createWorkbook(); - Sheet sheet = workbook.createSheet(); + try (Workbook workbook = _testDataProvider.createWorkbook()) { + Sheet sheet = workbook.createSheet(); - //single-cell array formula - CellRange srange = - sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5")); - Cell scell = srange.getTopLeftCell(); - assertEquals(CellType.FORMULA, scell.getCellType()); - assertEquals(0.0, scell.getNumericCellValue(), 0); - scell.setCellValue(1.1); - assertEquals(1.1, scell.getNumericCellValue(), 0); + //single-cell array formula + CellRange srange = + sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5")); + Cell scell = srange.getTopLeftCell(); + assertEquals(CellType.FORMULA, scell.getCellType()); + assertEquals(0.0, scell.getNumericCellValue(), 0); + scell.setCellValue(1.1); + assertEquals(1.1, scell.getNumericCellValue(), 0); - //multi-cell array formula - CellRange mrange = - sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3")); - for(Cell mcell : mrange){ - assertEquals(CellType.FORMULA, mcell.getCellType()); - assertEquals(0.0, mcell.getNumericCellValue(), 0); - double fmlaResult = 1.2; - mcell.setCellValue(fmlaResult); - assertEquals(fmlaResult, mcell.getNumericCellValue(), 0); + //multi-cell array formula + CellRange mrange = + sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3")); + for (Cell mcell : mrange) { + assertEquals(CellType.FORMULA, mcell.getCellType()); + assertEquals(0.0, mcell.getNumericCellValue(), 0); + double fmlaResult = 1.2; + mcell.setCellValue(fmlaResult); + assertEquals(fmlaResult, mcell.getNumericCellValue(), 0); + } } - workbook.close(); } @Test public void testModifyArrayCells_setCellType() throws IOException { - Workbook workbook = _testDataProvider.createWorkbook(); - Sheet sheet = workbook.createSheet(); + try (Workbook workbook = _testDataProvider.createWorkbook()) { + Sheet sheet = workbook.createSheet(); - // single-cell array formulas behave just like normal cells - - // changing cell type removes the array formula and associated cached result - CellRange srange = - sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5")); - Cell scell = srange.getTopLeftCell(); - assertEquals(CellType.FORMULA, scell.getCellType()); - assertEquals(0.0, scell.getNumericCellValue(), 0); - scell.setCellType(CellType.STRING); - assertEquals(CellType.STRING, scell.getCellType()); - scell.setCellValue("string cell"); - assertEquals("string cell", scell.getStringCellValue()); + // single-cell array formulas behave just like normal cells - + // changing cell type removes the array formula and associated cached result + CellRange srange = + sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5")); + Cell scell = srange.getTopLeftCell(); + assertEquals(CellType.FORMULA, scell.getCellType()); + assertEquals(0.0, scell.getNumericCellValue(), 0); + scell.setCellType(CellType.STRING); + assertEquals(CellType.STRING, scell.getCellType()); + scell.setCellValue("string cell"); + assertEquals("string cell", scell.getStringCellValue()); - //once you create a multi-cell array formula, you cannot change the type of its cells - CellRange mrange = - sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3")); - for(Cell mcell : mrange){ - try { + //once you create a multi-cell array formula, you cannot change the type of its cells + CellRange mrange = + sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3")); + for (Cell mcell : mrange) { + try { + assertEquals(CellType.FORMULA, mcell.getCellType()); + mcell.setCellType(CellType.NUMERIC); + fail("expected exception"); + } catch (IllegalStateException e) { + CellReference ref = new CellReference(mcell); + String msg = "Cell " + ref.formatAsString() + " is part of a multi-cell array formula. You cannot change part of an array."; + assertEquals(msg, e.getMessage()); + } + // a failed invocation of Cell.setCellType leaves the cell + // in the state that it was in prior to the invocation assertEquals(CellType.FORMULA, mcell.getCellType()); - mcell.setCellType(CellType.NUMERIC); - fail("expected exception"); - } catch (IllegalStateException e){ - CellReference ref = new CellReference(mcell); - String msg = "Cell "+ref.formatAsString()+" is part of a multi-cell array formula. You cannot change part of an array."; - assertEquals(msg, e.getMessage()); + assertTrue(mcell.isPartOfArrayFormulaGroup()); } - // a failed invocation of Cell.setCellType leaves the cell - // in the state that it was in prior to the invocation - assertEquals(CellType.FORMULA, mcell.getCellType()); - assertTrue(mcell.isPartOfArrayFormulaGroup()); } - workbook.close(); } @Test public void testModifyArrayCells_setCellFormula() throws IOException { - Workbook workbook = _testDataProvider.createWorkbook(); - Sheet sheet = workbook.createSheet(); + try (Workbook workbook = _testDataProvider.createWorkbook()) { + Sheet sheet = workbook.createSheet(); - CellRange srange = - sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5")); - Cell scell = srange.getTopLeftCell(); - assertEquals("SUM(A4:A6,B4:B6)", scell.getCellFormula()); - assertEquals(CellType.FORMULA, scell.getCellType()); - assertTrue(scell.isPartOfArrayFormulaGroup()); - scell.setCellFormula("SUM(A4,A6)"); - //we are now a normal formula cell - assertEquals("SUM(A4,A6)", scell.getCellFormula()); - assertFalse(scell.isPartOfArrayFormulaGroup()); - assertEquals(CellType.FORMULA, scell.getCellType()); - //check that setting formula result works - assertEquals(0.0, scell.getNumericCellValue(), 0); - scell.setCellValue(33.0); - assertEquals(33.0, scell.getNumericCellValue(), 0); + CellRange srange = + sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5")); + Cell scell = srange.getTopLeftCell(); + assertEquals("SUM(A4:A6,B4:B6)", scell.getCellFormula()); + assertEquals(CellType.FORMULA, scell.getCellType()); + assertTrue(scell.isPartOfArrayFormulaGroup()); + scell.setCellFormula("SUM(A4,A6)"); + //we are now a normal formula cell + assertEquals("SUM(A4,A6)", scell.getCellFormula()); + assertFalse(scell.isPartOfArrayFormulaGroup()); + assertEquals(CellType.FORMULA, scell.getCellType()); + //check that setting formula result works + assertEquals(0.0, scell.getNumericCellValue(), 0); + scell.setCellValue(33.0); + assertEquals(33.0, scell.getNumericCellValue(), 0); - //multi-cell array formula - CellRange mrange = - sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3")); - for(Cell mcell : mrange){ - //we cannot set individual formulas for cells included in an array formula - try { + //multi-cell array formula + CellRange mrange = + sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3")); + for (Cell mcell : mrange) { + //we cannot set individual formulas for cells included in an array formula + try { + assertEquals("A1:A3*B1:B3", mcell.getCellFormula()); + mcell.setCellFormula("A1+A2"); + fail("expected exception"); + } catch (IllegalStateException e) { + CellReference ref = new CellReference(mcell); + String msg = "Cell " + ref.formatAsString() + " is part of a multi-cell array formula. You cannot change part of an array."; + assertEquals(msg, e.getMessage()); + } + // a failed invocation of Cell.setCellFormula leaves the cell + // in the state that it was in prior to the invocation assertEquals("A1:A3*B1:B3", mcell.getCellFormula()); - mcell.setCellFormula("A1+A2"); - fail("expected exception"); - } catch (IllegalStateException e){ - CellReference ref = new CellReference(mcell); - String msg = "Cell "+ref.formatAsString()+" is part of a multi-cell array formula. You cannot change part of an array."; - assertEquals(msg, e.getMessage()); + assertTrue(mcell.isPartOfArrayFormulaGroup()); } - // a failed invocation of Cell.setCellFormula leaves the cell - // in the state that it was in prior to the invocation - assertEquals("A1:A3*B1:B3", mcell.getCellFormula()); - assertTrue(mcell.isPartOfArrayFormulaGroup()); } - workbook.close(); } @Test public void testModifyArrayCells_removeCell() throws IOException { - Workbook workbook = _testDataProvider.createWorkbook(); - Sheet sheet = workbook.createSheet(); + try (Workbook workbook = _testDataProvider.createWorkbook()) { + Sheet sheet = workbook.createSheet(); - //single-cell array formulas behave just like normal cells - CellRangeAddress cra = CellRangeAddress.valueOf("B5"); - CellRange srange = - sheet.setArrayFormula("SUM(A4:A6,B4:B6)", cra); - Cell scell = srange.getTopLeftCell(); + //single-cell array formulas behave just like normal cells + CellRangeAddress cra = CellRangeAddress.valueOf("B5"); + CellRange srange = + sheet.setArrayFormula("SUM(A4:A6,B4:B6)", cra); + Cell scell = srange.getTopLeftCell(); - Row srow = sheet.getRow(cra.getFirstRow()); - assertSame(srow, scell.getRow()); - srow.removeCell(scell); - assertNull(srow.getCell(cra.getFirstColumn())); + Row srow = sheet.getRow(cra.getFirstRow()); + assertSame(srow, scell.getRow()); + srow.removeCell(scell); + assertNull(srow.getCell(cra.getFirstColumn())); - //re-create the removed cell - scell = srow.createCell(cra.getFirstColumn()); - assertEquals(CellType.BLANK, scell.getCellType()); - assertFalse(scell.isPartOfArrayFormulaGroup()); + //re-create the removed cell + scell = srow.createCell(cra.getFirstColumn()); + assertEquals(CellType.BLANK, scell.getCellType()); + assertFalse(scell.isPartOfArrayFormulaGroup()); - //we cannot remove cells included in a multi-cell array formula - CellRange mrange = - sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3")); - for(Cell mcell : mrange){ - int columnIndex = mcell.getColumnIndex(); - Row mrow = mcell.getRow(); - try { - mrow.removeCell(mcell); - fail("expected exception"); - } catch (IllegalStateException e){ - CellReference ref = new CellReference(mcell); - String msg = "Cell "+ref.formatAsString()+" is part of a multi-cell array formula. You cannot change part of an array."; - assertEquals(msg, e.getMessage()); + //we cannot remove cells included in a multi-cell array formula + CellRange mrange = + sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3")); + for (Cell mcell : mrange) { + int columnIndex = mcell.getColumnIndex(); + Row mrow = mcell.getRow(); + try { + mrow.removeCell(mcell); + fail("expected exception"); + } catch (IllegalStateException e) { + CellReference ref = new CellReference(mcell); + String msg = "Cell " + ref.formatAsString() + " is part of a multi-cell array formula. You cannot change part of an array."; + assertEquals(msg, e.getMessage()); + } + // a failed invocation of Row.removeCell leaves the row + // in the state that it was in prior to the invocation + assertSame(mcell, mrow.getCell(columnIndex)); + assertTrue(mcell.isPartOfArrayFormulaGroup()); + assertEquals(CellType.FORMULA, mcell.getCellType()); } - // a failed invocation of Row.removeCell leaves the row - // in the state that it was in prior to the invocation - assertSame(mcell, mrow.getCell(columnIndex)); - assertTrue(mcell.isPartOfArrayFormulaGroup()); - assertEquals(CellType.FORMULA, mcell.getCellType()); + } - - workbook.close(); } @Test public void testModifyArrayCells_removeRow() throws IOException { - Workbook workbook = _testDataProvider.createWorkbook(); - Sheet sheet = workbook.createSheet(); + try (Workbook workbook = _testDataProvider.createWorkbook()) { + Sheet sheet = workbook.createSheet(); - //single-cell array formulas behave just like normal cells - CellRangeAddress cra = CellRangeAddress.valueOf("B5"); - CellRange srange = - sheet.setArrayFormula("SUM(A4:A6,B4:B6)", cra); - Cell scell = srange.getTopLeftCell(); - assertEquals(CellType.FORMULA, scell.getCellType()); + //single-cell array formulas behave just like normal cells + CellRangeAddress cra = CellRangeAddress.valueOf("B5"); + CellRange srange = + sheet.setArrayFormula("SUM(A4:A6,B4:B6)", cra); + Cell scell = srange.getTopLeftCell(); + assertEquals(CellType.FORMULA, scell.getCellType()); - Row srow = scell.getRow(); - assertSame(srow, sheet.getRow(cra.getFirstRow())); - sheet.removeRow(srow); - assertNull(sheet.getRow(cra.getFirstRow())); + Row srow = scell.getRow(); + assertSame(srow, sheet.getRow(cra.getFirstRow())); + sheet.removeRow(srow); + assertNull(sheet.getRow(cra.getFirstRow())); - //re-create the removed row and cell - scell = sheet.createRow(cra.getFirstRow()).createCell(cra.getFirstColumn()); - assertEquals(CellType.BLANK, scell.getCellType()); - assertFalse(scell.isPartOfArrayFormulaGroup()); + //re-create the removed row and cell + scell = sheet.createRow(cra.getFirstRow()).createCell(cra.getFirstColumn()); + assertEquals(CellType.BLANK, scell.getCellType()); + assertFalse(scell.isPartOfArrayFormulaGroup()); - //we cannot remove rows with cells included in a multi-cell array formula - CellRange mrange = - sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3")); - for(Cell mcell : mrange){ - int columnIndex = mcell.getColumnIndex(); - Row mrow = mcell.getRow(); - try { - sheet.removeRow(mrow); - fail("expected exception"); - } catch (IllegalStateException e){ - // String msg = "Row[rownum="+mrow.getRowNum()+"] contains cell(s) included in a multi-cell array formula. You cannot change part of an array."; - // assertEquals(msg, e.getMessage()); + //we cannot remove rows with cells included in a multi-cell array formula + CellRange mrange = + sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3")); + for (Cell mcell : mrange) { + int columnIndex = mcell.getColumnIndex(); + Row mrow = mcell.getRow(); + try { + sheet.removeRow(mrow); + fail("expected exception"); + } catch (IllegalStateException e) { + // String msg = "Row[rownum="+mrow.getRowNum()+"] contains cell(s) included in a multi-cell array formula. You cannot change part of an array."; + // assertEquals(msg, e.getMessage()); + } + // a failed invocation of Row.removeCell leaves the row + // in the state that it was in prior to the invocation + assertSame(mrow, sheet.getRow(mrow.getRowNum())); + assertSame(mcell, mrow.getCell(columnIndex)); + assertTrue(mcell.isPartOfArrayFormulaGroup()); + assertEquals(CellType.FORMULA, mcell.getCellType()); } - // a failed invocation of Row.removeCell leaves the row - // in the state that it was in prior to the invocation - assertSame(mrow, sheet.getRow(mrow.getRowNum())); - assertSame(mcell, mrow.getCell(columnIndex)); - assertTrue(mcell.isPartOfArrayFormulaGroup()); - assertEquals(CellType.FORMULA, mcell.getCellType()); } - - workbook.close(); } @Test public void testModifyArrayCells_mergeCellsSingle() throws IOException { - Workbook workbook = _testDataProvider.createWorkbook(); - Sheet sheet = workbook.createSheet(); - assertEquals(0, sheet.getNumMergedRegions()); + try (Workbook workbook = _testDataProvider.createWorkbook()) { + Sheet sheet = workbook.createSheet(); + assertEquals(0, sheet.getNumMergedRegions()); - //single-cell array formulas behave just like normal cells - CellRange srange = - sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5")); - Cell scell = srange.getTopLeftCell(); - assertEquals(0, sheet.addMergedRegion(CellRangeAddress.valueOf("B5:C6"))); - //we are still an array formula - assertEquals(CellType.FORMULA, scell.getCellType()); - assertTrue(scell.isPartOfArrayFormulaGroup()); - assertEquals(1, sheet.getNumMergedRegions()); - - workbook.close(); + //single-cell array formulas behave just like normal cells + CellRange srange = + sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5")); + Cell scell = srange.getTopLeftCell(); + assertEquals(0, sheet.addMergedRegion(CellRangeAddress.valueOf("B5:C6"))); + //we are still an array formula + assertEquals(CellType.FORMULA, scell.getCellType()); + assertTrue(scell.isPartOfArrayFormulaGroup()); + assertEquals(1, sheet.getNumMergedRegions()); + } } - + @Test public void testModifyArrayCells_mergeCellsMulti() throws IOException { - Workbook workbook = _testDataProvider.createWorkbook(); - Sheet sheet = workbook.createSheet(); - int expectedNumMergedRegions = 0; - assertEquals(expectedNumMergedRegions, sheet.getNumMergedRegions()); + try (Workbook workbook = _testDataProvider.createWorkbook()) { + Sheet sheet = workbook.createSheet(); + int expectedNumMergedRegions = 0; + assertEquals(expectedNumMergedRegions, sheet.getNumMergedRegions()); - // we cannot merge cells included in an array formula - sheet.setArrayFormula("A1:A4*B1:B4", CellRangeAddress.valueOf("C2:F5")); - for (String ref : Arrays.asList( - "C2:F5", // identity - "D3:E4", "B1:G6", // contains - "B1:C2", "F1:G2", "F5:G6", "B5:C6", // 1x1 corner intersection - "B1:C6", "B1:G2", "F1:G6", "B5:G6", // 1-row/1-column intersection - "B1:D3", "E1:G3", "E4:G6", "B4:D6", // 2x2 corner intersection - "B1:D6", "B1:G3", "E1:G6", "B4:G6" // 2-row/2-column intersection - )) { - CellRangeAddress cra = CellRangeAddress.valueOf(ref); - try { - sheet.addMergedRegion(cra); - fail("expected exception with ref " + ref); - } catch (IllegalStateException e) { - String msg = "The range "+cra.formatAsString()+" intersects with a multi-cell array formula. You cannot merge cells of an array."; - assertEquals(msg, e.getMessage()); + // we cannot merge cells included in an array formula + sheet.setArrayFormula("A1:A4*B1:B4", CellRangeAddress.valueOf("C2:F5")); + for (String ref : Arrays.asList( + "C2:F5", // identity + "D3:E4", "B1:G6", // contains + "B1:C2", "F1:G2", "F5:G6", "B5:C6", // 1x1 corner intersection + "B1:C6", "B1:G2", "F1:G6", "B5:G6", // 1-row/1-column intersection + "B1:D3", "E1:G3", "E4:G6", "B4:D6", // 2x2 corner intersection + "B1:D6", "B1:G3", "E1:G6", "B4:G6" // 2-row/2-column intersection + )) { + CellRangeAddress cra = CellRangeAddress.valueOf(ref); + try { + sheet.addMergedRegion(cra); + fail("expected exception with ref " + ref); + } catch (IllegalStateException e) { + String msg = "The range " + cra.formatAsString() + " intersects with a multi-cell array formula. You cannot merge cells of an array."; + assertEquals(msg, e.getMessage()); + } } - } - //the number of merged regions remains the same - assertEquals(expectedNumMergedRegions, sheet.getNumMergedRegions()); - - // we can merge non-intersecting cells - for (String ref : Arrays.asList( - "C1:F1", //above - "G2:G5", //right - "C6:F6", //bottom - "B2:B5", "H7:J9")) { - CellRangeAddress cra = CellRangeAddress.valueOf(ref); - try { - sheet.addMergedRegion(cra); - expectedNumMergedRegions++; - assertEquals(expectedNumMergedRegions, sheet.getNumMergedRegions()); - } catch (IllegalStateException e) { - fail("did not expect exception with ref: " + ref + "\n" + e.getMessage()); + //the number of merged regions remains the same + assertEquals(expectedNumMergedRegions, sheet.getNumMergedRegions()); + + // we can merge non-intersecting cells + for (String ref : Arrays.asList( + "C1:F1", //above + "G2:G5", //right + "C6:F6", //bottom + "B2:B5", "H7:J9")) { + CellRangeAddress cra = CellRangeAddress.valueOf(ref); + try { + sheet.addMergedRegion(cra); + expectedNumMergedRegions++; + assertEquals(expectedNumMergedRegions, sheet.getNumMergedRegions()); + } catch (IllegalStateException e) { + fail("did not expect exception with ref: " + ref + "\n" + e.getMessage()); + } } + } - - workbook.close(); } @Test public void testModifyArrayCells_shiftRows() throws IOException { - Workbook workbook = _testDataProvider.createWorkbook(); - Sheet sheet = workbook.createSheet(); + try (Workbook workbook = _testDataProvider.createWorkbook()) { + Sheet sheet = workbook.createSheet(); - //single-cell array formulas behave just like normal cells - we can change the cell type - CellRange srange = - sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5")); - Cell scell = srange.getTopLeftCell(); - assertEquals("SUM(A4:A6,B4:B6)", scell.getCellFormula()); - sheet.shiftRows(0, 0, 1); - sheet.shiftRows(0, 1, 1); - - //we cannot set individual formulas for cells included in an array formula - sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3")); - - try { + //single-cell array formulas behave just like normal cells - we can change the cell type + CellRange srange = + sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5")); + Cell scell = srange.getTopLeftCell(); + assertEquals("SUM(A4:A6,B4:B6)", scell.getCellFormula()); sheet.shiftRows(0, 0, 1); - fail("expected exception"); - } catch (IllegalStateException e){ - String msg = "Row[rownum=0] contains cell(s) included in a multi-cell array formula. You cannot change part of an array."; - assertEquals(msg, e.getMessage()); - } + sheet.shiftRows(0, 1, 1); + + //we cannot set individual formulas for cells included in an array formula + sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3")); + + try { + sheet.shiftRows(0, 0, 1); + fail("expected exception"); + } catch (IllegalStateException e) { + String msg = "Row[rownum=0] contains cell(s) included in a multi-cell array formula. You cannot change part of an array."; + assertEquals(msg, e.getMessage()); + } /* TODO: enable shifting the whole array @@ -575,37 +553,32 @@ public abstract class BaseTestSheetUpdateArrayFormulas { } */ - workbook.close(); + } } @Ignore("See bug 59728") - @Test + @Test(expected = IllegalStateException.class) public void shouldNotBeAbleToCreateArrayFormulaOnPreexistingMergedRegion() throws IOException { /* * m = merged region * f = array formula * fm = cell belongs to a merged region and an array formula (illegal, that's what this tests for) - * + * * A B C * 1 f f * 2 fm fm * 3 f f */ - Workbook workbook = _testDataProvider.createWorkbook(); - Sheet sheet = workbook.createSheet(); - - CellRangeAddress mergedRegion = CellRangeAddress.valueOf("B2:C2"); - assertEquals(0, sheet.addMergedRegion(mergedRegion)); - CellRangeAddress arrayFormula = CellRangeAddress.valueOf("C1:C3"); - assumeTrue(mergedRegion.intersects(arrayFormula)); - assumeTrue(arrayFormula.intersects(mergedRegion)); - try { - sheet.setArrayFormula("SUM(A1:A3)", arrayFormula); - fail("expected exception: should not be able to create an array formula that intersects with a merged region"); - } catch (IllegalStateException e) { - // expected + try (Workbook workbook = _testDataProvider.createWorkbook()) { + Sheet sheet = workbook.createSheet(); + + CellRangeAddress mergedRegion = CellRangeAddress.valueOf("B2:C2"); + assertEquals(0, sheet.addMergedRegion(mergedRegion)); + CellRangeAddress arrayFormula = CellRangeAddress.valueOf("C1:C3"); + assumeTrue(mergedRegion.intersects(arrayFormula)); + assumeTrue(arrayFormula.intersects(mergedRegion)); + // expected exception: should not be able to create an array formula that intersects with a merged region + sheet.setArrayFormula("SUM(A1:A3)", arrayFormula); } - - workbook.close(); } } diff --git a/src/testcases/org/apache/poi/ss/usermodel/charts/TestDataSources.java b/src/testcases/org/apache/poi/ss/usermodel/charts/TestDataSources.java index 6bf3551286..a21be43eda 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/charts/TestDataSources.java +++ b/src/testcases/org/apache/poi/ss/usermodel/charts/TestDataSources.java @@ -16,19 +16,24 @@ ==================================================================== */ package org.apache.poi.ss.usermodel.charts; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.SheetBuilder; +import org.junit.Test; /** * Tests for {@link org.apache.poi.ss.usermodel.charts.DataSources}. - * - * @author Roman Kashitsyn */ -public class TestDataSources extends TestCase { +@SuppressWarnings("deprecation") +public class TestDataSources { private static final Object[][] numericCells = { {0.0, 1.0, 2.0, 3.0, 4.0}, @@ -44,6 +49,7 @@ public class TestDataSources extends TestCase { {1.0, "2.0", 3.0, "4.0", 5.0, "6.0"} }; + @Test public void testNumericArrayDataSource() { Double[] doubles = new Double[]{1.0, 2.0, 3.0, 4.0, 5.0}; ChartDataSource doubleDataSource = DataSources.fromArray(doubles); @@ -52,6 +58,7 @@ public class TestDataSources extends TestCase { assertDataSourceIsEqualToArray(doubleDataSource, doubles); } + @Test public void testStringArrayDataSource() { String[] strings = new String[]{"one", "two", "three", "four", "five"}; ChartDataSource stringDataSource = DataSources.fromArray(strings); @@ -60,6 +67,7 @@ public class TestDataSources extends TestCase { assertDataSourceIsEqualToArray(stringDataSource, strings); } + @Test public void testNumericCellDataSource() { Workbook wb = new HSSFWorkbook(); Sheet sheet = new SheetBuilder(wb, numericCells).build(); @@ -74,6 +82,7 @@ public class TestDataSources extends TestCase { } } + @Test public void testStringCellDataSource() { Workbook wb = new HSSFWorkbook(); Sheet sheet = new SheetBuilder(wb, stringCells).build(); @@ -87,6 +96,7 @@ public class TestDataSources extends TestCase { } } + @Test public void testMixedCellDataSource() { Workbook wb = new HSSFWorkbook(); Sheet sheet = new SheetBuilder(wb, mixedCells).build(); @@ -105,6 +115,7 @@ public class TestDataSources extends TestCase { } } + @Test public void testIOBExceptionOnInvalidIndex() { Workbook wb = new HSSFWorkbook(); Sheet sheet = new SheetBuilder(wb, numericCells).build(); diff --git a/src/testcases/org/apache/poi/ss/util/TestExpandedDouble.java b/src/testcases/org/apache/poi/ss/util/TestExpandedDouble.java index 6ae092a4f5..c02f58dd2f 100644 --- a/src/testcases/org/apache/poi/ss/util/TestExpandedDouble.java +++ b/src/testcases/org/apache/poi/ss/util/TestExpandedDouble.java @@ -18,19 +18,15 @@ package org.apache.poi.ss.util; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; -import java.math.BigDecimal; import java.math.BigInteger; -import java.math.RoundingMode; -import org.apache.poi.util.HexDump; import org.junit.Test; -import junit.framework.AssertionFailedError; /** * Tests for {@link ExpandedDouble} - * - * @author Josh Micich */ public final class TestExpandedDouble { private static final BigInteger BIG_POW_10 = BigInteger.valueOf(1000000000); @@ -38,10 +34,7 @@ public final class TestExpandedDouble { @Test public void testNegative() { ExpandedDouble hd = new ExpandedDouble(0xC010000000000000L); - - if (hd.getBinaryExponent() == -2046) { - throw new AssertionFailedError("identified bug - sign bit not masked out of exponent"); - } + assertNotEquals("identified bug - sign bit not masked out of exponent", -2046, hd.getBinaryExponent()); assertEquals(2, hd.getBinaryExponent()); BigInteger frac = hd.getSignificand(); assertEquals(64, frac.bitLength()); @@ -51,10 +44,7 @@ public final class TestExpandedDouble { @Test public void testSubnormal() { ExpandedDouble hd = new ExpandedDouble(0x0000000000000001L); - - if (hd.getBinaryExponent() == -1023) { - throw new AssertionFailedError("identified bug - subnormal numbers not decoded properly"); - } + assertNotEquals("identified bug - subnormal numbers not decoded properly", -1023, hd.getBinaryExponent()); assertEquals(-1086, hd.getBinaryExponent()); BigInteger frac = hd.getSignificand(); assertEquals(64, frac.bitLength()); @@ -85,115 +75,36 @@ public final class TestExpandedDouble { 0x403CE0FFFFFFFFF0L, // has single digit round trip error 0x2B2BFFFF10001079L, }; - boolean success = true; for (int i = 0; i < rawValues.length; i++) { - success &= confirmRoundTrip(i, rawValues[i]); - } - if (!success) { - throw new AssertionFailedError("One or more test examples failed. See stderr."); + confirmRoundTrip(i, rawValues[i]); } } - - public static boolean confirmRoundTrip(int i, long rawBitsA) { + + public static void confirmRoundTrip(int i, long rawBitsA) { double a = Double.longBitsToDouble(rawBitsA); if (a == 0.0) { // Can't represent 0.0 or -0.0 with NormalisedDecimal - return true; + return; } - ExpandedDouble ed1; - NormalisedDecimal nd2; - ExpandedDouble ed3; - try { - ed1 = new ExpandedDouble(rawBitsA); - nd2 = ed1.normaliseBaseTen(); - checkNormaliseBaseTenResult(ed1, nd2); + ExpandedDouble ed1 = new ExpandedDouble(rawBitsA); + NormalisedDecimal nd2 = ed1.normaliseBaseTen(); + checkNormaliseBaseTenResult(ed1, nd2); + + ExpandedDouble ed3 = nd2.normaliseBaseTwo(); + assertEquals("bin exp mismatch", ed3.getBinaryExponent(), ed1.getBinaryExponent()); - ed3 = nd2.normaliseBaseTwo(); - } catch (RuntimeException e) { - System.err.println("example[" + i + "] (" - + formatDoubleAsHex(a) + ") exception:"); - e.printStackTrace(); - return false; - } - if (ed3.getBinaryExponent() != ed1.getBinaryExponent()) { - System.err.println("example[" + i + "] (" - + formatDoubleAsHex(a) + ") bin exp mismatch"); - return false; - } BigInteger diff = ed3.getSignificand().subtract(ed1.getSignificand()).abs(); if (diff.signum() == 0) { - return true; + return; } // original quantity only has 53 bits of precision // these quantities may have errors in the 64th bit, which hopefully don't make any difference - if (diff.bitLength() < 2) { - // errors in the 64th bit happen from time to time - // this is well below the 53 bits of precision required - return true; - } - - // but bigger errors are a concern - System.out.println("example[" + i + "] (" - + formatDoubleAsHex(a) + ") frac mismatch: " + diff); - - for (int j=-2; j<3; j++) { - System.out.println((j<0?"":"+") + j + ": " + getNearby(ed1, j)); - } - for (int j=-2; j<3; j++) { - System.out.println((j<0?"":"+") + j + ": " + getNearby(nd2, j)); - } - - - return false; + // errors in the 64th bit happen from time to time + // this is well below the 53 bits of precision required + assertTrue(diff.bitLength() < 2); } - public static String getBaseDecimal(ExpandedDouble hd) { - int gg = 64 - hd.getBinaryExponent() - 1; - BigDecimal bd = new BigDecimal(hd.getSignificand()).divide(new BigDecimal(BigInteger.ONE.shiftLeft(gg))); - int excessPrecision = bd.precision() - 23; - if (excessPrecision > 0) { - bd = bd.setScale(bd.scale() - excessPrecision, RoundingMode.HALF_UP); - } - return bd.unscaledValue().toString(); - } - - public static BigInteger getNearby(NormalisedDecimal md, int offset) { - BigInteger frac = md.composeFrac(); - int be = frac.bitLength() - 24 - 1; - int sc = frac.bitLength() - 64; - return getNearby(frac.shiftRight(sc), be, offset); - } - - public static BigInteger getNearby(ExpandedDouble hd, int offset) { - return getNearby(hd.getSignificand(), hd.getBinaryExponent(), offset); - } - - private static BigInteger getNearby(BigInteger significand, int binExp, int offset) { - int nExtraBits = 1; - int nDec = (int) Math.round(3.0 + (64+nExtraBits) * Math.log10(2.0)); - BigInteger newFrac = significand.shiftLeft(nExtraBits).add(BigInteger.valueOf(offset)); - - int gg = 64 + nExtraBits - binExp - 1; - - BigDecimal bd = new BigDecimal(newFrac); - if (gg > 0) { - bd = bd.divide(new BigDecimal(BigInteger.ONE.shiftLeft(gg))); - } else { - BigInteger frac = newFrac; - while (frac.bitLength() + binExp < 180) { - frac = frac.multiply(BigInteger.TEN); - } - int binaryExp = binExp - newFrac.bitLength() + frac.bitLength(); - - bd = new BigDecimal( frac.shiftRight(frac.bitLength()-binaryExp-1)); - } - int excessPrecision = bd.precision() - nDec; - if (excessPrecision > 0) { - bd = bd.setScale(bd.scale() - excessPrecision, RoundingMode.HALF_UP); - } - return bd.unscaledValue(); - } private static void checkNormaliseBaseTenResult(ExpandedDouble orig, NormalisedDecimal result) { String sigDigs = result.getSignificantDecimalDigits(); @@ -204,10 +115,7 @@ public final class TestExpandedDouble { int binaryExp = orig.getBinaryExponent() - orig.getSignificand().bitLength(); String origDigs = frac.shiftLeft(binaryExp+1).toString(10); - - if (!origDigs.startsWith(sigDigs)) { - throw new AssertionFailedError("Expected '" + origDigs + "' but got '" + sigDigs + "'."); - } + assertTrue(origDigs.startsWith(sigDigs)); double dO = Double.parseDouble("0." + origDigs.substring(sigDigs.length())); double d1 = Double.parseDouble(result.getFractionalPart().toPlainString()); @@ -218,14 +126,7 @@ public final class TestExpandedDouble { return; } BigInteger diff = subDigsB.subtract(subDigsO).abs(); - if (diff.intValue() > 100) { - // 100/32768 ~= 0.003 - throw new AssertionFailedError("minor mistake"); - } - } - - private static String formatDoubleAsHex(double d) { - long l = Double.doubleToLongBits(d); - return HexDump.longToHex(l)+'L'; + // 100/32768 ~= 0.003 + assertTrue("minor mistake", diff.intValue() <= 100); } } diff --git a/src/testcases/org/apache/poi/ss/util/TestNumberComparer.java b/src/testcases/org/apache/poi/ss/util/TestNumberComparer.java index 206194fccc..66e357b753 100644 --- a/src/testcases/org/apache/poi/ss/util/TestNumberComparer.java +++ b/src/testcases/org/apache/poi/ss/util/TestNumberComparer.java @@ -18,7 +18,6 @@ package org.apache.poi.ss.util; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; @@ -27,8 +26,6 @@ import org.apache.poi.util.HexDump; import org.junit.Test; /** * Tests for {@link NumberComparer} - * - * @author Josh Micich */ public final class TestNumberComparer { @@ -44,27 +41,24 @@ public final class TestNumberComparer { success &= confirm(i, ce.getNegA(), ce.getNegB(), -ce.getExpectedResult()); success &= confirm(i, ce.getNegB(), ce.getNegA(), +ce.getExpectedResult()); } - + assertTrue("One or more cases failed. See stderr", success); } @Test public void testRoundTripOnComparisonExamples() { ComparisonExample[] examples = NumberComparisonExamples.getComparisonExamples(); - boolean success = true; for(int i=0;iExcelNumberToTextConverter.toText(d)
    produces the right results. * As part of preparing this test class, the ExampleConversion instances should be set * up to contain the rendering as produced by Excel. */ + @Test public void testAll() { - int failureCount = 0; - ExampleConversion[] examples = NumberToTextConversionExamples.getExampleConversions(); - for (int i = 0; i < examples.length; i++) { - ExampleConversion example = examples[i]; - try { - if (example.isNaN()) { - confirmNaN(example.getRawDoubleBits(), example.getExcelRendering()); - continue; - } - String actual = NumberToTextConverter.toText(example.getDoubleValue()); - if (!example.getExcelRendering().equals(actual)) { - failureCount++; - String msg = "Error rendering for examples[" + i + "] " - + formatExample(example) + " " - + " bad-result='" + actual + "' " - + new ComparisonFailure(null, example.getExcelRendering(), actual).getMessage(); - System.err.println(msg); - continue; - } - } catch (RuntimeException e) { - failureCount++; - System.err.println("Error in excel rendering for examples[" + i + "] " - + formatExample(example) + "':" + e.getMessage()); - e.printStackTrace(); + for (ExampleConversion example : examples) { + if (example.isNaN()) { + confirmNaN(example.getRawDoubleBits(), example.getExcelRendering()); + continue; } + String actual = NumberToTextConverter.toText(example.getDoubleValue()); + assertEquals(example.getExcelRendering(), actual); } - if (failureCount > 0) { - throw new AssertionFailedError(failureCount - + " error(s) in excel number to text conversion (see std-err)"); - } - } - - private static String formatExample(ExampleConversion example) { - String hexLong = Long.toHexString(example.getRawDoubleBits()).toUpperCase(Locale.ROOT); - String longRep = "0x" + "0000000000000000".substring(hexLong.length()) + hexLong+ "L"; - return "ec(" + longRep + ", \"" + example.getJavaRendering() + "\", \"" + example.getExcelRendering() + "\")"; } /** @@ -86,43 +54,42 @@ public final class TestNumberToTextConverter extends TestCase { * general, Excel does not attempt to use raw NaN in the IEEE sense. In {@link FormulaRecord}s, * Excel uses the NaN bit pattern to flag non-numeric (text, boolean, error) cached results. * If the formula result actually evaluates to raw NaN, Excel transforms it to #NUM!. - * In other places (e.g. {@link NumberRecord}, {@link NumberPtg}, array items (via {@link - * ConstantValueParser}), there seems to be no special NaN translation scheme. If a NaN bit - * pattern is somehow encoded into any of these places Excel actually attempts to render the - * values as a plain number. That is the unusual functionality that this method is testing.

    - * + * In other places (e.g. {@link NumberRecord}, {@link NumberPtg}, array items (via {@link + * ConstantValueParser}), there seems to be no special NaN translation scheme. If a NaN bit + * pattern is somehow encoded into any of these places Excel actually attempts to render the + * values as a plain number. That is the unusual functionality that this method is testing.

    + * * There are multiple encodings (bit patterns) for NaN, and CPUs and applications can convert - * to a preferred NaN encoding (Java prefers 0x7FF8000000000000L). Besides the - * special encoding in {@link FormulaRecord.SpecialCachedValue}, it is not known how/whether + * to a preferred NaN encoding (Java prefers 0x7FF8000000000000L). Besides the + * special encoding in {@link FormulaRecord.SpecialCachedValue}, it is not known how/whether * Excel attempts to encode NaN values. - * + * * Observed NaN behaviour on HotSpot/Windows: * Double.longBitsToDouble() will set one bit 51 (the NaN signaling flag) if it isn't - * already. Double.doubleToLongBits() will return a double with bit pattern + * already. Double.doubleToLongBits() will return a double with bit pattern * 0x7FF8000000000000L for any NaN bit pattern supplied.
    * Differences are likely to be observed with other architectures.

    - * + * *

    - * The few test case examples calling this method represent functionality which may not be + * The few test case examples calling this method represent functionality which may not be * important for POI to support. */ private void confirmNaN(long l, String excelRep) { double d = Double.longBitsToDouble(l); assertEquals("NaN", Double.toString(d)); - + String strExcel = NumberToTextConverter.rawDoubleBitsToText(l); - + assertEquals(excelRep, strExcel); } - + + @Test public void testSimpleRendering_bug56156() { double dResult = 0.05+0.01; // values chosen to produce rounding anomaly String actualText = NumberToTextConverter.toText(dResult); String jdkText = Double.toString(dResult); - if (jdkText.equals(actualText)) { - // "0.060000000000000005" - throw new AssertionFailedError("Should not use default JDK IEEE double rendering"); - } + // "0.060000000000000005" + assertNotEquals("Should not use default JDK IEEE double rendering", jdkText, actualText); assertEquals("0.06", actualText); } } diff --git a/src/testcases/org/apache/poi/ss/util/TestSheetBuilder.java b/src/testcases/org/apache/poi/ss/util/TestSheetBuilder.java index 7a668b016d..cae0407ab7 100644 --- a/src/testcases/org/apache/poi/ss/util/TestSheetBuilder.java +++ b/src/testcases/org/apache/poi/ss/util/TestSheetBuilder.java @@ -5,9 +5,9 @@ The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - + http://www.apache.org/licenses/LICENSE-2.0 - + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,6 +17,11 @@ package org.apache.poi.ss.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.io.IOException; import java.util.Date; import org.apache.poi.hssf.usermodel.HSSFWorkbook; @@ -25,15 +30,14 @@ import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; - -import junit.framework.TestCase; +import org.junit.Test; /** * Tests SheetBuilder. * * @see org.apache.poi.ss.util.SheetBuilder */ -public final class TestSheetBuilder extends TestCase { +public final class TestSheetBuilder { private static Object[][] testData = new Object[][]{ {1, 2, 3}, @@ -41,45 +45,51 @@ public final class TestSheetBuilder extends TestCase { {"one", "two", "=A1+B2"} }; - public void testNotCreateEmptyCells() { - Workbook wb = new HSSFWorkbook(); - Sheet sheet = new SheetBuilder(wb, testData).build(); + @Test + public void testNotCreateEmptyCells() throws IOException { + try (Workbook wb = new HSSFWorkbook()) { + Sheet sheet = new SheetBuilder(wb, testData).build(); - assertEquals(sheet.getPhysicalNumberOfRows(), 3); + assertEquals(sheet.getPhysicalNumberOfRows(), 3); - Row firstRow = sheet.getRow(0); - Cell firstCell = firstRow.getCell(0); + Row firstRow = sheet.getRow(0); + Cell firstCell = firstRow.getCell(0); - assertEquals(firstCell.getCellType(), CellType.NUMERIC); - assertEquals(1.0, firstCell.getNumericCellValue(), 0.00001); + assertEquals(firstCell.getCellType(), CellType.NUMERIC); + assertEquals(1.0, firstCell.getNumericCellValue(), 0.00001); - Row secondRow = sheet.getRow(1); - assertNotNull(secondRow.getCell(0)); - assertNull(secondRow.getCell(2)); + Row secondRow = sheet.getRow(1); + assertNotNull(secondRow.getCell(0)); + assertNull(secondRow.getCell(2)); - Row thirdRow = sheet.getRow(2); - assertEquals(CellType.STRING, thirdRow.getCell(0).getCellType()); - String cellValue = thirdRow.getCell(0).getStringCellValue(); - assertEquals(testData[2][0].toString(), cellValue); + Row thirdRow = sheet.getRow(2); + assertEquals(CellType.STRING, thirdRow.getCell(0).getCellType()); + String cellValue = thirdRow.getCell(0).getStringCellValue(); + assertEquals(testData[2][0].toString(), cellValue); - assertEquals(CellType.FORMULA, thirdRow.getCell(2).getCellType()); - assertEquals("A1+B2", thirdRow.getCell(2).getCellFormula()); + assertEquals(CellType.FORMULA, thirdRow.getCell(2).getCellType()); + assertEquals("A1+B2", thirdRow.getCell(2).getCellFormula()); + } } - public void testEmptyCells() { - Workbook wb = new HSSFWorkbook(); - Sheet sheet = new SheetBuilder(wb, testData).setCreateEmptyCells(true).build(); + @Test + public void testEmptyCells() throws IOException { + try (Workbook wb = new HSSFWorkbook()) { + Sheet sheet = new SheetBuilder(wb, testData).setCreateEmptyCells(true).build(); - Cell emptyCell = sheet.getRow(1).getCell(1); - assertNotNull(emptyCell); - assertEquals(CellType.BLANK, emptyCell.getCellType()); + Cell emptyCell = sheet.getRow(1).getCell(1); + assertNotNull(emptyCell); + assertEquals(CellType.BLANK, emptyCell.getCellType()); + } } - public void testSheetName() { + @Test + public void testSheetName() throws IOException { final String sheetName = "TEST SHEET NAME"; - Workbook wb = new HSSFWorkbook(); - Sheet sheet = new SheetBuilder(wb, testData).setSheetName(sheetName).build(); - assertEquals(sheetName, sheet.getSheetName()); + try (Workbook wb = new HSSFWorkbook()) { + Sheet sheet = new SheetBuilder(wb, testData).setSheetName(sheetName).build(); + assertEquals(sheetName, sheet.getSheetName()); + } } } \ No newline at end of file diff --git a/src/testcases/org/apache/poi/ss/util/TestWorkbookUtil.java b/src/testcases/org/apache/poi/ss/util/TestWorkbookUtil.java index 2bd305c433..30c080e40b 100644 --- a/src/testcases/org/apache/poi/ss/util/TestWorkbookUtil.java +++ b/src/testcases/org/apache/poi/ss/util/TestWorkbookUtil.java @@ -17,67 +17,70 @@ package org.apache.poi.ss.util; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; /** * Tests WorkbookUtil. * * @see org.apache.poi.ss.util.WorkbookUtil */ -public final class TestWorkbookUtil extends TestCase { +public final class TestWorkbookUtil { /** - * borrowed test cases from + * borrowed test cases from * {@link org.apache.poi.hssf.record.TestBoundSheetRecord#testValidNames()} */ + @Test public void testCreateSafeNames() { - + String p = "Sheet1"; String actual = WorkbookUtil.createSafeSheetName(p); assertEquals(p, actual); - + p = "O'Brien's sales"; actual = WorkbookUtil.createSafeSheetName(p); assertEquals(p, actual); - + p = " data # "; actual = WorkbookUtil.createSafeSheetName(p); assertEquals(p, actual); - + p = "data $1.00"; actual = WorkbookUtil.createSafeSheetName(p); assertEquals(p, actual); - + // now the replaced versions ... actual = WorkbookUtil.createSafeSheetName("data?"); assertEquals("data ", actual); - + actual = WorkbookUtil.createSafeSheetName("abc/def"); assertEquals("abc def", actual); - + actual = WorkbookUtil.createSafeSheetName("data[0]"); assertEquals("data 0 ", actual); - + actual = WorkbookUtil.createSafeSheetName("data*"); assertEquals("data ", actual); - + actual = WorkbookUtil.createSafeSheetName("abc\\def"); assertEquals("abc def", actual); - + actual = WorkbookUtil.createSafeSheetName("'data"); assertEquals(" data", actual); - + actual = WorkbookUtil.createSafeSheetName("data'"); assertEquals("data ", actual); - + actual = WorkbookUtil.createSafeSheetName("d'at'a"); assertEquals("d'at'a", actual); - + actual = WorkbookUtil.createSafeSheetName(null); assertEquals("null", actual); - + actual = WorkbookUtil.createSafeSheetName(""); assertEquals("empty", actual); - + actual = WorkbookUtil.createSafeSheetName("1234567890123456789012345678901TOOLONG"); assertEquals("1234567890123456789012345678901", actual); diff --git a/src/testcases/org/apache/poi/ss/util/cellwalk/TestCellWalk.java b/src/testcases/org/apache/poi/ss/util/cellwalk/TestCellWalk.java index f9ec43425f..c553d0cc60 100644 --- a/src/testcases/org/apache/poi/ss/util/cellwalk/TestCellWalk.java +++ b/src/testcases/org/apache/poi/ss/util/cellwalk/TestCellWalk.java @@ -5,9 +5,9 @@ The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - + http://www.apache.org/licenses/LICENSE-2.0 - + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,64 +16,41 @@ ==================================================================== */ package org.apache.poi.ss.util.cellwalk; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; import java.util.Date; -import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.SheetBuilder; +import org.junit.Test; -public class TestCellWalk extends TestCase { +public class TestCellWalk { - private static Object[][] testData = new Object[][] { - { 1, 2, null}, - {null, new Date(), null}, - {null, null, "str"} + private static Object[][] testData = new Object[][]{ + {1, 2, null}, + {null, new Date(), null}, + {null, null, "str"} }; - private final CountCellHandler countCellHandler = new CountCellHandler(); - + @Test public void testNotTraverseEmptyCells() { - Workbook wb = new HSSFWorkbook(); - Sheet sheet = new SheetBuilder(wb, testData).build(); - CellRangeAddress range = CellRangeAddress.valueOf("A1:C3"); - - CellWalk cellWalk = new CellWalk(sheet, range); - countCellHandler.reset(); - cellWalk.traverse(countCellHandler); + Workbook wb = new HSSFWorkbook(); + Sheet sheet = new SheetBuilder(wb, testData).build(); + CellRangeAddress range = CellRangeAddress.valueOf("A1:C3"); - assertEquals(4, countCellHandler.getVisitedCellsNumber()); - /* 1 + 2 + 5 + 9 */ - assertEquals(17L, countCellHandler.getOrdinalNumberSum()); - } + CellWalk cellWalk = new CellWalk(sheet, range); + int[] cellsVisited = { 0 }; + long[] ordinalNumberSum = { 0 }; + cellWalk.traverse((cell,ctx) -> { + cellsVisited[0]++; + ordinalNumberSum[0] += ctx.getOrdinalNumber(); + }); - - private static class CountCellHandler implements CellHandler { - - private int cellsVisited; - private long ordinalNumberSum; - - @Override - public void onCell(Cell cell, CellWalkContext ctx) { - ++cellsVisited; - ordinalNumberSum += ctx.getOrdinalNumber(); - } - - public int getVisitedCellsNumber() { - return cellsVisited; - } - - public long getOrdinalNumberSum() { - return ordinalNumberSum; - } - - public void reset() { - cellsVisited = 0; - ordinalNumberSum = 0L; - } + assertEquals(4, cellsVisited[0]); + /* 1 + 2 + 5 + 9 */ + assertEquals(17L, ordinalNumberSum[0]); } } \ No newline at end of file diff --git a/src/testcases/org/apache/poi/util/TestArrayUtil.java b/src/testcases/org/apache/poi/util/TestArrayUtil.java index 2af0481513..d3470e7c27 100644 --- a/src/testcases/org/apache/poi/util/TestArrayUtil.java +++ b/src/testcases/org/apache/poi/util/TestArrayUtil.java @@ -18,17 +18,21 @@ package org.apache.poi.util; -import junit.framework.TestCase; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.fail; + +import java.util.Arrays; + +import org.junit.Test; /** * Unit test for ArrayUtil - * - * @author Nick Burch */ -public class TestArrayUtil extends TestCase { +public class TestArrayUtil { /** * Test to ensure that our own arraycopy behaves as it should do */ + @Test public void testarraycopy() { byte[] bytes = new byte[] { 0x01, 0x02, 0x03, 0x04 }; @@ -36,11 +40,7 @@ public class TestArrayUtil extends TestCase { byte[] dest = new byte[4]; ArrayUtil.arraycopy(bytes, 0, dest, 0, 4); - assertEquals(dest.length, bytes.length); - for(int i=0; i> 8) % 256); array[ 2 ] = ( byte ) ((_test_array[ j ] >> 16) % 256); @@ -147,12 +130,12 @@ public final class TestIntegerField extends TestCase { } } + @Test public void testReadFromStream() throws IOException { IntegerField field = new IntegerField(0); byte[] buffer = new byte[ _test_array.length * 4 ]; - for (int j = 0; j < _test_array.length; j++) - { + for (int j = 0; j < _test_array.length; j++) { buffer[ (j * 4) + 0 ] = ( byte ) (_test_array[ j ] % 256); buffer[ (j * 4) + 1 ] = ( byte ) ((_test_array[ j ] >> 8) % 256); buffer[ (j * 4) + 2 ] = ( byte ) ((_test_array[ j ] >> 16) % 256); @@ -160,13 +143,13 @@ public final class TestIntegerField extends TestCase { } ByteArrayInputStream stream = new ByteArrayInputStream(buffer); - for (int j = 0; j < buffer.length / 4; j++) - { + for (int j = 0; j < buffer.length / 4; j++) { field.readFromStream(stream); assertEquals("Testing " + j, _test_array[ j ], field.get()); } } + @Test public void testWriteToBytes() { IntegerField field = new IntegerField(0); byte[] array = new byte[ 4 ]; diff --git a/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java b/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java index 32373c2be7..e0df851a6f 100644 --- a/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java +++ b/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java @@ -18,43 +18,47 @@ package org.apache.poi.util; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; /** * Class to test {@link LittleEndianInputStream} and {@link LittleEndianOutputStream} - * - * @author Josh Micich */ -public final class TestLittleEndianStreams extends TestCase { +public final class TestLittleEndianStreams { + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test public void testRead() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - LittleEndianOutput leo = new LittleEndianOutputStream(baos); - leo.writeInt(12345678); - leo.writeShort(12345); - leo.writeByte(123); - leo.writeShort(40000); - leo.writeByte(200); - leo.writeLong(1234567890123456789L); - leo.writeDouble(123.456); - ((LittleEndianOutputStream)leo).close(); + try (LittleEndianOutputStream leo = new LittleEndianOutputStream(baos)) { + leo.writeInt(12345678); + leo.writeShort(12345); + leo.writeByte(123); + leo.writeShort(40000); + leo.writeByte(200); + leo.writeLong(1234567890123456789L); + leo.writeDouble(123.456); + } - LittleEndianInput lei = new LittleEndianInputStream(new ByteArrayInputStream(baos.toByteArray())); - - assertEquals(12345678, lei.readInt()); - assertEquals(12345, lei.readShort()); - assertEquals(123, lei.readByte()); - assertEquals(40000, lei.readUShort()); - assertEquals(200, lei.readUByte()); - assertEquals(1234567890123456789L, lei.readLong()); - assertEquals(123.456, lei.readDouble(), 0.0); - ((LittleEndianInputStream)lei).close(); + try (LittleEndianInputStream lei = new LittleEndianInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertEquals(12345678, lei.readInt()); + assertEquals(12345, lei.readShort()); + assertEquals(123, lei.readByte()); + assertEquals(40000, lei.readUShort()); + assertEquals(200, lei.readUByte()); + assertEquals(1234567890123456789L, lei.readLong()); + assertEquals(123.456, lei.readDouble(), 0.0); + } } /** @@ -62,6 +66,7 @@ public final class TestLittleEndianStreams extends TestCase { * had an error which resulted in the data being read and written back to the source byte * array. */ + @Test public void testReadFully() { byte[] srcBuf = HexRead.readFromString("99 88 77 66 55 44 33"); LittleEndianInput lei = new LittleEndianByteArrayInputStream(srcBuf); @@ -72,9 +77,8 @@ public final class TestLittleEndianStreams extends TestCase { byte[] actBuf = new byte[4]; lei.readFully(actBuf); - if (actBuf[0] == 0x00 && srcBuf[0] == 0x77 && srcBuf[3] == 0x44) { - throw new AssertionFailedError("Identified bug in readFully() - source buffer was modified"); - } + assertFalse("Identified bug in readFully() - source buffer was modified", + actBuf[0] == 0x00 && srcBuf[0] == 0x77 && srcBuf[3] == 0x44); byte[] expBuf = HexRead.readFromString("77 66 55 44"); assertArrayEquals(actBuf, expBuf); @@ -82,6 +86,7 @@ public final class TestLittleEndianStreams extends TestCase { assertEquals(0, lei.available()); } + @Test public void testBufferOverrun() { byte[] srcBuf = HexRead.readFromString("99 88 77"); LittleEndianInput lei = new LittleEndianByteArrayInputStream(srcBuf); @@ -90,37 +95,30 @@ public final class TestLittleEndianStreams extends TestCase { assertEquals(0x8899, lei.readUShort()); // only one byte left, so this should fail - try { - lei.readFully(new byte[4]); - fail("Should catch exception here"); - } catch (RuntimeException e) { - assertTrue(e.getMessage().contains("Buffer overrun")); - } + thrown.expect(RuntimeException.class); + thrown.expectMessage("Buffer overrun"); + lei.readFully(new byte[4]); } + @Test public void testBufferOverrunStartOffset() { byte[] srcBuf = HexRead.readFromString("99 88 77 88 99"); LittleEndianInput lei = new LittleEndianByteArrayInputStream(srcBuf, 2); // only one byte left, so this should fail - try { - lei.readFully(new byte[4]); - fail("Should catch exception here"); - } catch (RuntimeException e) { - assertTrue(e.getMessage().contains("Buffer overrun")); - } + thrown.expect(RuntimeException.class); + thrown.expectMessage("Buffer overrun"); + lei.readFully(new byte[4]); } + @Test public void testBufferOverrunStartOffset2() { byte[] srcBuf = HexRead.readFromString("99 88 77 88 99"); LittleEndianInput lei = new LittleEndianByteArrayInputStream(srcBuf, 2, 2); // only one byte left, so this should fail - try { - lei.readFully(new byte[4]); - fail("Should catch exception here"); - } catch (RuntimeException e) { - assertTrue(e.getMessage().contains("Buffer overrun")); - } + thrown.expect(RuntimeException.class); + thrown.expectMessage("Buffer overrun"); + lei.readFully(new byte[4]); } } diff --git a/src/testcases/org/apache/poi/util/TestLongField.java b/src/testcases/org/apache/poi/util/TestLongField.java index f613bae1c9..7f50bd97cd 100644 --- a/src/testcases/org/apache/poi/util/TestLongField.java +++ b/src/testcases/org/apache/poi/util/TestLongField.java @@ -17,59 +17,50 @@ package org.apache.poi.util; -import junit.framework.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; + +import org.junit.Test; /** * Test LongField code - * - * @author Marc Johnson (mjohnson at apache dot org) */ -public final class TestLongField extends TestCase { +public final class TestLongField { static private final long[] _test_array = { Long.MIN_VALUE, -1L, 0L, 1L, Long.MAX_VALUE }; - public void testConstructors() - { - try - { + @Test + public void testConstructors() { + try { new LongField(-1); fail("Should have caught ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } LongField field = new LongField(2); assertEquals(0L, field.get()); - try - { + try { new LongField(-1, 1L); fail("Should have caught ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } field = new LongField(2, 0x123456789ABCDEF0L); assertEquals(0x123456789ABCDEF0L, field.get()); byte[] array = new byte[ 10 ]; - try - { + try { new LongField(-1, 1L, array); fail("Should have caught ArrayIndexOutOfBoundsException"); } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } field = new LongField(2, 0x123456789ABCDEF0L, array); @@ -83,14 +74,10 @@ public final class TestLongField extends TestCase { assertEquals(( byte ) 0x34, array[ 8 ]); assertEquals(( byte ) 0x12, array[ 9 ]); array = new byte[ 9 ]; - try - { + try { new LongField(2, 5L, array); fail("should have gotten ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } for (long element : _test_array) { @@ -100,13 +87,12 @@ public final class TestLongField extends TestCase { } } - public void testSet() - { + @Test + public void testSet() { LongField field = new LongField(0); byte[] array = new byte[ 8 ]; - for (int j = 0; j < _test_array.length; j++) - { + for (int j = 0; j < _test_array.length; j++) { field.set(_test_array[ j ]); assertEquals("testing _1 " + j, _test_array[ j ], field.get()); field = new LongField(0); @@ -138,24 +124,19 @@ public final class TestLongField extends TestCase { } } - public void testReadFromBytes() - { + @Test + public void testReadFromBytes() { LongField field = new LongField(1); byte[] array = new byte[ 8 ]; - try - { + try { field.readFromBytes(array); fail("should have caught ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } field = new LongField(0); - for (int j = 0; j < _test_array.length; j++) - { + for (int j = 0; j < _test_array.length; j++) { array[ 0 ] = ( byte ) (_test_array[ j ] % 256); array[ 1 ] = ( byte ) ((_test_array[ j ] >> 8) % 256); array[ 2 ] = ( byte ) ((_test_array[ j ] >> 16) % 256); @@ -169,15 +150,13 @@ public final class TestLongField extends TestCase { } } - public void testReadFromStream() - throws IOException - { + @Test + public void testReadFromStream() throws IOException { LongField field = new LongField(0); byte[] buffer = new byte[ _test_array.length * 8 ]; - for (int j = 0; j < _test_array.length; j++) - { - buffer[ (j * 8) + 0 ] = ( byte ) ((_test_array[ j ] >> 0) % 256); + for (int j = 0; j < _test_array.length; j++) { + buffer[ (j * 8) ] = ( byte ) ((_test_array[ j ] ) % 256); buffer[ (j * 8) + 1 ] = ( byte ) ((_test_array[ j ] >> 8) % 256); buffer[ (j * 8) + 2 ] = ( byte ) ((_test_array[ j ] >> 16) % 256); buffer[ (j * 8) + 3 ] = ( byte ) ((_test_array[ j ] >> 24) % 256); @@ -188,15 +167,14 @@ public final class TestLongField extends TestCase { } ByteArrayInputStream stream = new ByteArrayInputStream(buffer); - for (int j = 0; j < buffer.length / 8; j++) - { + for (int j = 0; j < buffer.length / 8; j++) { field.readFromStream(stream); assertEquals("Testing " + j, _test_array[ j ], field.get()); } } - public void testWriteToBytes() - { + @Test + public void testWriteToBytes() { LongField field = new LongField(0); byte[] array = new byte[ 8 ]; diff --git a/src/testcases/org/apache/poi/util/TestPOILogFactory.java b/src/testcases/org/apache/poi/util/TestPOILogFactory.java index 115ec733e7..666d1d9b2f 100644 --- a/src/testcases/org/apache/poi/util/TestPOILogFactory.java +++ b/src/testcases/org/apache/poi/util/TestPOILogFactory.java @@ -17,19 +17,15 @@ package org.apache.poi.util; -import junit.framework.TestCase; +import org.junit.Test; -/** - * @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 final class TestPOILogFactory { /** * test log creation */ + @Test public void testLog() { //NKB Testing only that logging classes use gives no exception // Since logging can be disabled, no checking of logging diff --git a/src/testcases/org/apache/poi/util/TestShortField.java b/src/testcases/org/apache/poi/util/TestShortField.java index 9e1fec64b5..c31202f2cc 100644 --- a/src/testcases/org/apache/poi/util/TestShortField.java +++ b/src/testcases/org/apache/poi/util/TestShortField.java @@ -17,59 +17,46 @@ package org.apache.poi.util; -import junit.framework.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; + +import org.junit.Test; /** * Test ShortField code - * - * @author Marc Johnson (mjohnson at apache dot org) */ -public final class TestShortField extends TestCase { +public final class TestShortField { - private static final short[] _test_array = - { - Short.MIN_VALUE, ( short ) -1, ( short ) 0, ( short ) 1, - Short.MAX_VALUE - }; + private static final short[] _test_array = {Short.MIN_VALUE, -1, 0, 1, Short.MAX_VALUE}; + @Test public void testConstructors() { - try - { + try { new ShortField(-1); fail("Should have caught ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } ShortField field = new ShortField(2); assertEquals(0, field.get()); - try - { + try { new ShortField(-1, ( short ) 1); fail("Should have caught ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } field = new ShortField(2, ( short ) 0x1234); assertEquals(0x1234, field.get()); byte[] array = new byte[ 4 ]; - try - { + try { new ShortField(-1, ( short ) 1, array); fail("Should have caught ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } field = new ShortField(2, ( short ) 0x1234, array); @@ -77,14 +64,10 @@ public final class TestShortField extends TestCase { assertEquals(( byte ) 0x34, array[ 2 ]); assertEquals(( byte ) 0x12, array[ 3 ]); array = new byte[ 3 ]; - try - { + try { new ShortField(2, ( short ) 5, array); fail("should have gotten ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } for (short element : _test_array) { @@ -94,12 +77,12 @@ public final class TestShortField extends TestCase { } } + @Test public void testSet() { ShortField field = new ShortField(0); byte[] array = new byte[ 2 ]; - for (int j = 0; j < _test_array.length; j++) - { + for (int j = 0; j < _test_array.length; j++) { field.set(_test_array[ j ]); assertEquals("testing _1 " + j, _test_array[ j ], field.get()); field = new ShortField(0); @@ -113,18 +96,15 @@ public final class TestShortField extends TestCase { } } + @Test public void testReadFromBytes() { ShortField field = new ShortField(1); byte[] array = new byte[ 2 ]; - try - { + try { field.readFromBytes(array); fail("should have caught ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } field = new ShortField(0); @@ -137,13 +117,14 @@ public final class TestShortField extends TestCase { } } + @Test public void testReadFromStream() throws IOException { ShortField field = new ShortField(0); byte[] buffer = new byte[ _test_array.length * 2 ]; for (int j = 0; j < _test_array.length; j++) { - buffer[ (j * 2) + 0 ] = ( byte ) (_test_array[ j ] % 256); + buffer[ (j * 2) ] = ( byte ) (_test_array[ j ] % 256); buffer[ (j * 2) + 1 ] = ( byte ) ((_test_array[ j ] >> 8) % 256); } ByteArrayInputStream stream = new ByteArrayInputStream(buffer); @@ -155,6 +136,7 @@ public final class TestShortField extends TestCase { } } + @Test public void testWriteToBytes() { ShortField field = new ShortField(0); byte[] array = new byte[ 2 ];