diff options
author | Nick Burch <nick@apache.org> | 2008-04-05 13:07:22 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2008-04-05 13:07:22 +0000 |
commit | 92396054a43e3625005ba45228d29b5dace44421 (patch) | |
tree | edf451e767628423730b5bd150a2790e22777885 /src/testcases/org | |
parent | 595525a03c83954bdf4ccc9cef009c120f7d6f6c (diff) | |
download | poi-92396054a43e3625005ba45228d29b5dace44421.tar.gz poi-92396054a43e3625005ba45228d29b5dace44421.zip |
Merged revisions 642878-642946 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r642878 | josh | 2008-03-31 06:10:35 +0100 (Mon, 31 Mar 2008) | 1 line
More work on Conditional Formatting (bug 30311) junit and fixes from Dmitriy. Some other clean-up.
........
r642880 | josh | 2008-03-31 06:19:00 +0100 (Mon, 31 Mar 2008) | 1 line
removed incorrect test case methods
........
r642891 | josh | 2008-03-31 06:56:11 +0100 (Mon, 31 Mar 2008) | 1 line
silenced noisy tests
........
r642904 | josh | 2008-03-31 07:55:04 +0100 (Mon, 31 Mar 2008) | 1 line
changes/status for #44675, #44695, #44691
........
r642946 | yegor | 2008-03-31 10:58:27 +0100 (Mon, 31 Mar 2008) | 1 line
Implement Sheet.removeShape(Shape shape) in HSLF
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@645088 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org')
19 files changed, 726 insertions, 581 deletions
diff --git a/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java b/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java index 3b98aed0ae..2589aa90dd 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java +++ b/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.hssf.model; import junit.framework.AssertionFailedError; @@ -54,7 +54,7 @@ import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; /** - * Test the low level formula parser functionality. High level tests are to + * Test the low level formula parser functionality. High level tests are to * be done via usermodel/HSSFCell.setFormulaValue() . * Some tests are also done in scratchpad, if they need * HSSFFormulaEvaluator, which is there @@ -71,7 +71,7 @@ public final class TestFormulaParser extends TestCase { assertNotNull("Ptg array should not be null", result); return result; } - + public void testSimpleFormula() { FormulaParser fp = new FormulaParser("2+2",null); fp.parse(); @@ -86,9 +86,9 @@ public final class TestFormulaParser extends TestCase { assertTrue("",(ptgs[0] instanceof IntPtg)); assertTrue("",(ptgs[1] instanceof IntPtg)); assertTrue("",(ptgs[2] instanceof AddPtg)); - + } - + public void testFormulaWithSpace2() { Ptg[] ptgs; FormulaParser fp; @@ -97,7 +97,7 @@ public final class TestFormulaParser extends TestCase { ptgs = fp.getRPNPtg(); assertTrue("five tokens expected, got "+ptgs.length,ptgs.length == 5); } - + public void testFormulaWithSpaceNRef() { Ptg[] ptgs; FormulaParser fp; @@ -106,7 +106,7 @@ public final class TestFormulaParser extends TestCase { ptgs = fp.getRPNPtg(); assertTrue("two tokens expected, got "+ptgs.length,ptgs.length == 2); } - + public void testFormulaWithString() { Ptg[] ptgs; FormulaParser fp; @@ -172,7 +172,7 @@ public final class TestFormulaParser extends TestCase { } - + /** * Make sure the ptgs are generated properly with two functions embedded * @@ -225,7 +225,7 @@ public final class TestFormulaParser extends TestCase { assertEquals("4 Ptgs expected", 4, asts.length); } - + /** * Bug Reported by xt-jens.riis@nokia.com (Jens Riis) * Refers to Bug <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=17582">#17582</a> @@ -247,7 +247,7 @@ public final class TestFormulaParser extends TestCase { } - + public void testSimpleLogical() { FormulaParser fp=new FormulaParser("IF(A1<A2,B1,B2)",null); fp.parse(); @@ -255,10 +255,10 @@ public final class TestFormulaParser extends TestCase { assertTrue("Ptg array should not be null", ptgs !=null); assertEquals("Ptg array length", 9, ptgs.length); assertEquals("3rd Ptg is less than",LessThanPtg.class,ptgs[2].getClass()); - - + + } - + public void testParenIf() { FormulaParser fp=new FormulaParser("IF((A1+A2)<=3,\"yes\",\"no\")",null); fp.parse(); @@ -281,7 +281,7 @@ public final class TestFormulaParser extends TestCase { assertEquals("15th Ptg is not the inner IF variable function ptg",FuncVarPtg.class,ptgs[14].getClass()); } - + public void testMacroFunction() { Workbook w = Workbook.createWorkbook(); FormulaParser fp = new FormulaParser("FOO()", w); @@ -291,7 +291,7 @@ public final class TestFormulaParser extends TestCase { // the name gets encoded as the first arg NamePtg tname = (NamePtg) ptg[0]; assertEquals("FOO", tname.toFormulaString(w)); - + AbstractFunctionPtg tfunc = (AbstractFunctionPtg) ptg[1]; assertTrue(tfunc.isExternalFunction()); } @@ -302,9 +302,9 @@ public final class TestFormulaParser extends TestCase { Ptg[] ptg = fp.getRPNPtg(); assertTrue("first ptg is string",ptg[0] instanceof StringPtg); assertTrue("second ptg is string",ptg[1] instanceof StringPtg); - + } - + public void testConcatenate(){ FormulaParser fp = new FormulaParser("CONCATENATE(\"first\",\"second\")",null); fp.parse(); @@ -312,7 +312,7 @@ public final class TestFormulaParser extends TestCase { assertTrue("first ptg is string",ptg[0] instanceof StringPtg); assertTrue("second ptg is string",ptg[1] instanceof StringPtg); } - + public void testWorksheetReferences() { HSSFWorkbook wb = new HSSFWorkbook(); @@ -330,7 +330,7 @@ public final class TestFormulaParser extends TestCase { cell = row.createCell((short)1); cell.setCellFormula("'Quotes Needed Here &#$@'!A1"); } - + public void testUnaryMinus() { FormulaParser fp = new FormulaParser("-A1", null); @@ -340,7 +340,7 @@ public final class TestFormulaParser extends TestCase { assertTrue("first ptg is reference",ptg[0] instanceof ReferencePtg); assertTrue("second ptg is Minus",ptg[1] instanceof UnaryMinusPtg); } - + public void testUnaryPlus() { FormulaParser fp = new FormulaParser("+A1", null); @@ -350,14 +350,14 @@ public final class TestFormulaParser extends TestCase { assertTrue("first ptg is reference",ptg[0] instanceof ReferencePtg); assertTrue("second ptg is Plus",ptg[1] instanceof UnaryPlusPtg); } - + public void testLeadingSpaceInString() { String value = " hi "; FormulaParser fp = new FormulaParser("\"" + value + "\"", null); fp.parse(); Ptg[] ptg = fp.getRPNPtg(); - + assertTrue("got 1 ptg", ptg.length == 1); assertTrue("ptg0 is a StringPtg", ptg[0] instanceof StringPtg); assertTrue("ptg0 contains exact value", ((StringPtg)ptg[0]).getValue().equals(value)); @@ -368,14 +368,14 @@ public final class TestFormulaParser extends TestCase { FormulaParser fp = new FormulaParser("lookup(A1, A3:A52, B3:B52)", null); fp.parse(); Ptg[] ptg = fp.getRPNPtg(); - + assertTrue("got 4 ptg", ptg.length == 4); assertTrue("ptg0 has Value class", ptg[0].getPtgClass() == Ptg.CLASS_VALUE); fp = new FormulaParser("match(A1, A3:A52)", null); fp.parse(); ptg = fp.getRPNPtg(); - + assertTrue("got 3 ptg", ptg.length == 3); assertTrue("ptg0 has Value class", ptg[0].getPtgClass() == Ptg.CLASS_VALUE); } @@ -521,77 +521,77 @@ public final class TestFormulaParser extends TestCase { System.out.println("Testing org.apache.poi.hssf.record.formula.FormulaParser"); junit.textui.TestRunner.run(TestFormulaParser.class); } - + public void testNumbers() { HSSFWorkbook wb = new HSSFWorkbook(); - + wb.createSheet("Cash_Flow"); - + HSSFSheet sheet = wb.createSheet("Test"); HSSFRow row = sheet.createRow(0); HSSFCell cell = row.createCell((short)0); String formula = null; - + // starts from decimal point - + cell.setCellFormula(".1"); formula = cell.getCellFormula(); assertEquals("0.1", formula); - + cell.setCellFormula("+.1"); formula = cell.getCellFormula(); assertEquals("+0.1", formula); - + cell.setCellFormula("-.1"); formula = cell.getCellFormula(); assertEquals("-0.1", formula); - + // has exponent - + cell.setCellFormula("10E1"); formula = cell.getCellFormula(); assertEquals("100.0", formula); - + cell.setCellFormula("10E+1"); formula = cell.getCellFormula(); assertEquals("100.0", formula); - + cell.setCellFormula("10E-1"); formula = cell.getCellFormula(); assertEquals("1.0", formula); } - + public void testRanges() { HSSFWorkbook wb = new HSSFWorkbook(); - + wb.createSheet("Cash_Flow"); - + HSSFSheet sheet = wb.createSheet("Test"); HSSFRow row = sheet.createRow(0); HSSFCell cell = row.createCell((short)0); String formula = null; - + cell.setCellFormula("A1.A2"); formula = cell.getCellFormula(); assertEquals("A1:A2", formula); - + cell.setCellFormula("A1..A2"); formula = cell.getCellFormula(); assertEquals("A1:A2", formula); - + cell.setCellFormula("A1...A2"); formula = cell.getCellFormula(); assertEquals("A1:A2", formula); } - + /** * Test for bug observable at svn revision 618865 (5-Feb-2008)<br/> * a formula consisting of a single no-arg function got rendered without the function braces */ public void testToFormulaStringZeroArgFunction() { - + Workbook book = Workbook.createWorkbook(); // not really used in this test - + Ptg[] ptgs = { new FuncPtg(10, 0), }; @@ -610,21 +610,21 @@ public final class TestFormulaParser extends TestCase { assertEquals(2, ptgs.length); assertEquals(ptgs[0].getClass(), IntPtg.class); assertEquals(ptgs[1].getClass(), PercentPtg.class); - - - // double percent OK + + + // double percent OK ptgs = parseFormula("12345.678%%"); assertEquals(3, ptgs.length); assertEquals(ptgs[0].getClass(), NumberPtg.class); assertEquals(ptgs[1].getClass(), PercentPtg.class); assertEquals(ptgs[2].getClass(), PercentPtg.class); - + // percent of a bracketed expression ptgs = parseFormula("(A1+35)%*B1%"); assertEquals(8, ptgs.length); assertEquals(ptgs[4].getClass(), PercentPtg.class); assertEquals(ptgs[6].getClass(), PercentPtg.class); - + // percent of a text quantity ptgs = parseFormula("\"8.75\"%"); assertEquals(2, ptgs.length); @@ -641,64 +641,64 @@ public final class TestFormulaParser extends TestCase { // // things that parse OK but would *evaluate* to an error - + ptgs = parseFormula("\"abc\"%"); assertEquals(2, ptgs.length); assertEquals(ptgs[0].getClass(), StringPtg.class); assertEquals(ptgs[1].getClass(), PercentPtg.class); - + ptgs = parseFormula("#N/A%"); assertEquals(2, ptgs.length); assertEquals(ptgs[0].getClass(), ErrPtg.class); assertEquals(ptgs[1].getClass(), PercentPtg.class); } - + /** * Tests combinations of various operators in the absence of brackets */ public void testPrecedenceAndAssociativity() { Class[] expClss; - + // TRUE=TRUE=2=2 evaluates to FALSE - expClss = new Class[] { BoolPtg.class, BoolPtg.class, EqualPtg.class, + expClss = new Class[] { BoolPtg.class, BoolPtg.class, EqualPtg.class, IntPtg.class, EqualPtg.class, IntPtg.class, EqualPtg.class, }; confirmTokenClasses("TRUE=TRUE=2=2", expClss); - + // 2^3^2 evaluates to 64 not 512 - expClss = new Class[] { IntPtg.class, IntPtg.class, PowerPtg.class, + expClss = new Class[] { IntPtg.class, IntPtg.class, PowerPtg.class, IntPtg.class, PowerPtg.class, }; confirmTokenClasses("2^3^2", expClss); - + // "abc" & 2 + 3 & "def" evaluates to "abc5def" - expClss = new Class[] { StringPtg.class, IntPtg.class, IntPtg.class, + expClss = new Class[] { StringPtg.class, IntPtg.class, IntPtg.class, AddPtg.class, ConcatPtg.class, StringPtg.class, ConcatPtg.class, }; confirmTokenClasses("\"abc\"&2+3&\"def\"", expClss); - - + + // (1 / 2) - (3 * 4) - expClss = new Class[] { IntPtg.class, IntPtg.class, DividePtg.class, + expClss = new Class[] { IntPtg.class, IntPtg.class, DividePtg.class, IntPtg.class, IntPtg.class, MultiplyPtg.class, SubtractPtg.class, }; confirmTokenClasses("1/2-3*4", expClss); - + // 2 * (2^2) expClss = new Class[] { IntPtg.class, IntPtg.class, IntPtg.class, PowerPtg.class, MultiplyPtg.class, }; // NOT: (2 *2) ^ 2 -> int int multiply int power confirmTokenClasses("2*2^2", expClss); - + // 2^200% -> 2 not 1.6E58 expClss = new Class[] { IntPtg.class, IntPtg.class, PercentPtg.class, PowerPtg.class, }; confirmTokenClasses("2^200%", expClss); } - + private static void confirmTokenClasses(String formula, Class[] expectedClasses) { Ptg[] ptgs = parseFormula(formula); assertEquals(expectedClasses.length, ptgs.length); for (int i = 0; i < expectedClasses.length; i++) { if(expectedClasses[i] != ptgs[i].getClass()) { fail("difference at token[" + i + "]: expected (" - + expectedClasses[i].getName() + ") but got (" + + expectedClasses[i].getName() + ") but got (" + ptgs[i].getClass().getName() + ")"); } } @@ -718,38 +718,38 @@ public final class TestFormulaParser extends TestCase { public void testParseNumber() { IntPtg ip; - + // bug 33160 ip = (IntPtg) parseSingleToken("40", IntPtg.class); assertEquals(40, ip.getValue()); ip = (IntPtg) parseSingleToken("40000", IntPtg.class); assertEquals(40000, ip.getValue()); - + // check the upper edge of the IntPtg range: ip = (IntPtg) parseSingleToken("65535", IntPtg.class); assertEquals(65535, ip.getValue()); NumberPtg np = (NumberPtg) parseSingleToken("65536", NumberPtg.class); assertEquals(65536, np.getValue(), 0); - + np = (NumberPtg) parseSingleToken("65534.6", NumberPtg.class); assertEquals(65534.6, np.getValue(), 0); } - + public void testMissingArgs() { - + Class[] expClss; - - expClss = new Class[] { ReferencePtg.class, MissingArgPtg.class, ReferencePtg.class, + + expClss = new Class[] { ReferencePtg.class, MissingArgPtg.class, ReferencePtg.class, FuncVarPtg.class, }; confirmTokenClasses("if(A1, ,C1)", expClss); - + expClss = new Class[] { MissingArgPtg.class, AreaPtg.class, MissingArgPtg.class, FuncVarPtg.class, }; confirmTokenClasses("counta( , A1:B2, )", expClss); } public void testParseErrorLiterals() { - + confirmParseErrorLiteral(ErrPtg.NULL_INTERSECTION, "#NULL!"); confirmParseErrorLiteral(ErrPtg.DIV_ZERO, "#DIV/0!"); confirmParseErrorLiteral(ErrPtg.VALUE_INVALID, "#VALUE!"); @@ -762,7 +762,7 @@ public final class TestFormulaParser extends TestCase { private static void confirmParseErrorLiteral(ErrPtg expectedToken, String formula) { assertEquals(expectedToken, parseSingleToken(formula, ErrPtg.class)); } - + /** * To aid readability the parameters have been encoded with single quotes instead of double * quotes. This method converts single quotes to double quotes before performing the parse @@ -772,23 +772,23 @@ public final class TestFormulaParser extends TestCase { // formula: internal quotes become double double, surround with double quotes String formula = '"' + singleQuotedValue.replaceAll("'", "\"\"") + '"'; String expectedValue = singleQuotedValue.replace('\'', '"'); - + StringPtg sp = (StringPtg) parseSingleToken(formula, StringPtg.class); assertEquals(expectedValue, sp.getValue()); } - + public void testPaseStringLiterals() { confirmStringParse("goto considered harmful"); - + confirmStringParse("goto 'considered' harmful"); - + confirmStringParse(""); confirmStringParse("'"); confirmStringParse("''"); confirmStringParse("' '"); confirmStringParse(" ' "); } - + public void testParseSumIfSum() { String formulaString; Ptg[] ptgs; @@ -809,14 +809,14 @@ public final class TestFormulaParser extends TestCase { parseExpectedException("1 + #N / A * 2"); parseExpectedException("#value?"); parseExpectedException("#DIV/ 0+2"); - - + + if (false) { // TODO - add functionality to detect func arg count mismatch parseExpectedException("IF(TRUE)"); parseExpectedException("countif(A1:B5, C1, D1)"); } } - + private static void parseExpectedException(String formula) { try { parseFormula(formula); @@ -831,11 +831,11 @@ public final class TestFormulaParser extends TestCase { } public void testSetFormulaWithRowBeyond32768_Bug44539() { - + HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(); wb.setSheetName(0, "Sheet1"); - + HSSFRow row = sheet.createRow(0); HSSFCell cell = row.createCell((short)0); cell.setCellFormula("SUM(A32769:A32770)"); @@ -862,11 +862,11 @@ public final class TestFormulaParser extends TestCase { throw e; } // FormulaParser strips spaces anyway - assertEquals("4", formulaString); + assertEquals("4", formulaString); ptgs = new Ptg[] { new IntPtg(3), spacePtg, new IntPtg(4), spacePtg, new AddPtg()}; formulaString = FormulaParser.toFormulaString(null, ptgs); - assertEquals("3+4", formulaString); + assertEquals("3+4", formulaString); } /** @@ -875,7 +875,7 @@ public final class TestFormulaParser extends TestCase { public void testTooFewOperandArgs() { // Simulating badly encoded cell formula of "=/1" // Not sure if Excel could ever produce this - Ptg[] ptgs = { + Ptg[] ptgs = { // Excel would probably have put tMissArg here new IntPtg(1), new DividePtg(), diff --git a/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java b/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java index 9da8f45ebc..32b16cf656 100755 --- a/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java +++ b/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java @@ -17,7 +17,9 @@ package org.apache.poi.hssf.record; +import org.apache.poi.hssf.record.aggregates.AllRecordAggregateTests; import org.apache.poi.hssf.record.formula.AllFormulaTests; +import org.apache.poi.hssf.record.formula.functions.AllIndividualFunctionEvaluationTests; import junit.framework.Test; import junit.framework.TestSuite; @@ -33,7 +35,8 @@ public final class AllRecordTests { TestSuite result = new TestSuite(AllRecordTests.class.getName()); result.addTest(AllFormulaTests.suite()); - + result.addTest(AllRecordAggregateTests.suite()); + result.addTestSuite(TestAreaFormatRecord.class); result.addTestSuite(TestAreaRecord.class); result.addTestSuite(TestAxisLineFormatRecord.class); @@ -45,6 +48,8 @@ public final class AllRecordTests { result.addTestSuite(TestBarRecord.class); result.addTestSuite(TestBoundSheetRecord.class); result.addTestSuite(TestCategorySeriesAxisRecord.class); + result.addTestSuite(TestCFHeaderRecord.class); + result.addTestSuite(TestCFRuleRecord.class); result.addTestSuite(TestChartRecord.class); result.addTestSuite(TestChartTitleFormatRecord.class); result.addTestSuite(TestCommonObjectDataSubRecord.class); diff --git a/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java b/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java index c3e5684798..2a6faaccdd 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java @@ -17,9 +17,6 @@ package org.apache.poi.hssf.record; -import java.util.ArrayList; -import java.util.List; - import junit.framework.TestCase; import org.apache.poi.hssf.record.cf.CellRange; @@ -30,116 +27,114 @@ import org.apache.poi.hssf.record.cf.CellRange; * * @author Dmitriy Kumshayev */ -public class TestCFHeaderRecord - extends TestCase +public final class TestCFHeaderRecord extends TestCase { - public TestCFHeaderRecord(String name) - { - super(name); - } + public void testCreateCFHeaderRecord () + { + CFHeaderRecord record = new CFHeaderRecord(); + CellRange[] ranges = { + new CellRange(0,-1,5,5), + new CellRange(0,-1,6,6), + new CellRange(0,1,0,1), + new CellRange(0,1,2,3), + new CellRange(2,3,0,1), + new CellRange(2,3,2,3), + }; + record.setCellRanges(ranges); + ranges = record.getCellRanges(); + assertEquals(6,ranges.length); + CellRange enclosingCellRange = record.getEnclosingCellRange(); + assertEquals(0, enclosingCellRange.getFirstRow()); + assertEquals(-1, enclosingCellRange.getLastRow()); + assertEquals(0, enclosingCellRange.getFirstColumn()); + assertEquals(6, enclosingCellRange.getLastColumn()); + record.setNeedRecalculation(true); + assertTrue(record.getNeedRecalculation()); + record.setNeedRecalculation(false); + assertFalse(record.getNeedRecalculation()); + } + + public void testSerialization() { + byte[] recordData = new byte[] + { + (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, + + (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, + (byte)0x03, (byte)0x00, + }; + + CFHeaderRecord record = new CFHeaderRecord(new TestcaseRecordInputStream(CFHeaderRecord.sid, (short)recordData.length, recordData)); + + assertEquals("#CFRULES", 3, record.getNumberOfConditionalFormats()); + assertTrue(record.getNeedRecalculation()); + CellRange enclosingCellRange = record.getEnclosingCellRange(); + assertEquals(0, enclosingCellRange.getFirstRow()); + assertEquals(3, enclosingCellRange.getLastRow()); + assertEquals(0, enclosingCellRange.getFirstColumn()); + assertEquals(3, enclosingCellRange.getLastColumn()); + CellRange[] ranges = record.getCellRanges(); + CellRange range0 = ranges[0]; + assertEquals(0, range0.getFirstRow()); + assertEquals(1, range0.getLastRow()); + assertEquals(0, range0.getFirstColumn()); + assertEquals(1, range0.getLastColumn()); + CellRange range1 = ranges[1]; + assertEquals(0, range1.getFirstRow()); + assertEquals(1, range1.getLastRow()); + assertEquals(2, range1.getFirstColumn()); + assertEquals(3, range1.getLastColumn()); + CellRange range2 = ranges[2]; + assertEquals(2, range2.getFirstRow()); + assertEquals(3, range2.getLastRow()); + assertEquals(0, range2.getFirstColumn()); + assertEquals(1, range2.getLastColumn()); + CellRange range3 = ranges[3]; + assertEquals(2, range3.getFirstRow()); + assertEquals(3, range3.getLastRow()); + assertEquals(2, range3.getFirstColumn()); + assertEquals(3, range3.getLastColumn()); + assertEquals(recordData.length+4, record.getRecordSize()); - public void testCreateCFHeaderRecord () - { - CFHeaderRecord record = new CFHeaderRecord(); - List ranges = new ArrayList(); - ranges.add(new CellRange(0,-1,(short)5,(short)5)); - ranges.add(new CellRange(0,-1,(short)6,(short)6)); - ranges.add(new CellRange(0,1,(short)0,(short)1)); - ranges.add(new CellRange(0,1,(short)2,(short)3)); - ranges.add(new CellRange(2,3,(short)0,(short)1)); - ranges.add(new CellRange(2,3,(short)2,(short)3)); - record.setCellRanges(ranges); - ranges = record.getCellRanges(); - assertEquals(6,ranges.size()); - CellRange enclosingCellRange = record.getEnclosingCellRange(); - assertEquals(0, enclosingCellRange.getFirstRow()); - assertEquals(-1, enclosingCellRange.getLastRow()); - assertEquals(0, enclosingCellRange.getFirstColumn()); - assertEquals(6, enclosingCellRange.getLastColumn()); - record.setNeedRecalculation(true); - assertTrue(record.getNeedRecalculation()); - record.setNeedRecalculation(false); - assertFalse(record.getNeedRecalculation()); - } - - public void testSerialization() { - byte[] recordData = new byte[] - { - (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, - - (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, - (byte)0x03, (byte)0x00, - }; - - CFHeaderRecord record = new CFHeaderRecord(new TestcaseRecordInputStream(CFHeaderRecord.sid, (short)recordData.length, recordData)); - - assertEquals("#CFRULES", 3, record.getNumberOfConditionalFormats()); - assertTrue(record.getNeedRecalculation()); - CellRange enclosingCellRange = record.getEnclosingCellRange(); - assertEquals(0, enclosingCellRange.getFirstRow()); - assertEquals(3, enclosingCellRange.getLastRow()); - assertEquals(0, enclosingCellRange.getFirstColumn()); - assertEquals(3, enclosingCellRange.getLastColumn()); - List ranges = record.getCellRanges(); - assertEquals(0, ((CellRange)ranges.get(0)).getFirstRow()); - assertEquals(1, ((CellRange)ranges.get(0)).getLastRow()); - assertEquals(0, ((CellRange)ranges.get(0)).getFirstColumn()); - assertEquals(1, ((CellRange)ranges.get(0)).getLastColumn()); - assertEquals(0, ((CellRange)ranges.get(1)).getFirstRow()); - assertEquals(1, ((CellRange)ranges.get(1)).getLastRow()); - assertEquals(2, ((CellRange)ranges.get(1)).getFirstColumn()); - assertEquals(3, ((CellRange)ranges.get(1)).getLastColumn()); - assertEquals(2, ((CellRange)ranges.get(2)).getFirstRow()); - assertEquals(3, ((CellRange)ranges.get(2)).getLastRow()); - assertEquals(0, ((CellRange)ranges.get(2)).getFirstColumn()); - assertEquals(1, ((CellRange)ranges.get(2)).getLastColumn()); - assertEquals(2, ((CellRange)ranges.get(3)).getFirstRow()); - assertEquals(3, ((CellRange)ranges.get(3)).getLastRow()); - assertEquals(2, ((CellRange)ranges.get(3)).getFirstColumn()); - assertEquals(3, ((CellRange)ranges.get(3)).getLastColumn()); - 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]); } - } - - - public static void main(String[] ignored_args) + } + + + public static void main(String[] ignored_args) { System.out.println("Testing org.apache.poi.hssf.record.CFHeaderRecord"); junit.textui.TestRunner.run(TestCFHeaderRecord.class); } - } diff --git a/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java b/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java index 77731d7812..e65025a31d 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java @@ -19,109 +19,107 @@ package org.apache.poi.hssf.record; import junit.framework.TestCase; +import org.apache.poi.hssf.model.Workbook; +import org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator; import org.apache.poi.hssf.record.cf.BorderFormatting; import org.apache.poi.hssf.record.cf.FontFormatting; import org.apache.poi.hssf.record.cf.PatternFormatting; import org.apache.poi.hssf.util.HSSFColor; +import org.apache.poi.util.LittleEndian; /** * Tests the serialization and deserialization of the TestCFRuleRecord - * class works correctly. + * class works correctly. * * @author Dmitriy Kumshayev */ -public class TestCFRuleRecord - extends TestCase +public final class TestCFRuleRecord extends TestCase { - public TestCFRuleRecord(String name) - { - super(name); - } - - public void testCreateCFRuleRecord () - { - CFRuleRecord record = new CFRuleRecord(); - testCFRuleRecord(record); - - // Serialize - byte [] serializedRecord = record.serialize(); - - // Strip header - byte [] recordData = new byte[serializedRecord.length-4]; - System.arraycopy(serializedRecord, 4, recordData, 0, recordData.length); - - // Deserialize - record = new CFRuleRecord(new TestcaseRecordInputStream(CFRuleRecord.sid, (short)recordData.length, recordData)); - - // Serialize again + public void testCreateCFRuleRecord () + { + Workbook workbook = Workbook.createWorkbook(); + CFRuleRecord record = CFRuleRecord.create(workbook, "7"); + testCFRuleRecord(record); + + // Serialize + byte [] serializedRecord = record.serialize(); + + // Strip header + byte [] recordData = new byte[serializedRecord.length-4]; + System.arraycopy(serializedRecord, 4, recordData, 0, recordData.length); + + // Deserialize + record = new CFRuleRecord(new TestcaseRecordInputStream(CFRuleRecord.sid, (short)recordData.length, 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]); } - } + } private void testCFRuleRecord(CFRuleRecord record) { FontFormatting fontFormatting = new FontFormatting(); - testFontFormattingAccessors(fontFormatting); - assertFalse(record.containsFontFormattingBlock()); - record.setFontFormatting(fontFormatting); - assertTrue(record.containsFontFormattingBlock()); - - BorderFormatting borderFormatting = new BorderFormatting(); - testBorderFormattingAccessors(borderFormatting); - assertFalse(record.containsBorderFormattingBlock()); - record.setBorderFormatting(borderFormatting); - assertTrue(record.containsBorderFormattingBlock()); - - assertFalse(record.isLeftBorderModified()); - record.setLeftBorderModified(true); - assertTrue(record.isLeftBorderModified()); - - assertFalse(record.isRightBorderModified()); - record.setRightBorderModified(true); - assertTrue(record.isRightBorderModified()); - - assertFalse(record.isTopBorderModified()); - record.setTopBorderModified(true); - assertTrue(record.isTopBorderModified()); - - assertFalse(record.isBottomBorderModified()); - record.setBottomBorderModified(true); - assertTrue(record.isBottomBorderModified()); - - assertFalse(record.isTopLeftBottomRightBorderModified()); - record.setTopLeftBottomRightBorderModified(true); - assertTrue(record.isTopLeftBottomRightBorderModified()); - - assertFalse(record.isBottomLeftTopRightBorderModified()); - record.setBottomLeftTopRightBorderModified(true); - assertTrue(record.isBottomLeftTopRightBorderModified()); - - - PatternFormatting patternFormatting = new PatternFormatting(); - testPatternFormattingAccessors(patternFormatting); - assertFalse(record.containsPatternFormattingBlock()); - record.setPatternFormatting(patternFormatting); - assertTrue(record.containsPatternFormattingBlock()); - - assertFalse(record.isPatternBackgroundColorModified()); - record.setPatternBackgroundColorModified(true); - assertTrue(record.isPatternBackgroundColorModified()); - - assertFalse(record.isPatternColorModified()); - record.setPatternColorModified(true); - assertTrue(record.isPatternColorModified()); - - assertFalse(record.isPatternStyleModified()); - record.setPatternStyleModified(true); - assertTrue(record.isPatternStyleModified()); + testFontFormattingAccessors(fontFormatting); + assertFalse(record.containsFontFormattingBlock()); + record.setFontFormatting(fontFormatting); + assertTrue(record.containsFontFormattingBlock()); + + BorderFormatting borderFormatting = new BorderFormatting(); + testBorderFormattingAccessors(borderFormatting); + assertFalse(record.containsBorderFormattingBlock()); + record.setBorderFormatting(borderFormatting); + assertTrue(record.containsBorderFormattingBlock()); + + assertFalse(record.isLeftBorderModified()); + record.setLeftBorderModified(true); + assertTrue(record.isLeftBorderModified()); + + assertFalse(record.isRightBorderModified()); + record.setRightBorderModified(true); + assertTrue(record.isRightBorderModified()); + + assertFalse(record.isTopBorderModified()); + record.setTopBorderModified(true); + assertTrue(record.isTopBorderModified()); + + assertFalse(record.isBottomBorderModified()); + record.setBottomBorderModified(true); + assertTrue(record.isBottomBorderModified()); + + assertFalse(record.isTopLeftBottomRightBorderModified()); + record.setTopLeftBottomRightBorderModified(true); + assertTrue(record.isTopLeftBottomRightBorderModified()); + + assertFalse(record.isBottomLeftTopRightBorderModified()); + record.setBottomLeftTopRightBorderModified(true); + assertTrue(record.isBottomLeftTopRightBorderModified()); + + + PatternFormatting patternFormatting = new PatternFormatting(); + testPatternFormattingAccessors(patternFormatting); + assertFalse(record.containsPatternFormattingBlock()); + record.setPatternFormatting(patternFormatting); + assertTrue(record.containsPatternFormattingBlock()); + + assertFalse(record.isPatternBackgroundColorModified()); + record.setPatternBackgroundColorModified(true); + assertTrue(record.isPatternBackgroundColorModified()); + + assertFalse(record.isPatternColorModified()); + record.setPatternColorModified(true); + assertTrue(record.isPatternColorModified()); + + assertFalse(record.isPatternStyleModified()); + record.setPatternStyleModified(true); + assertTrue(record.isPatternStyleModified()); } private void testPatternFormattingAccessors(PatternFormatting patternFormatting) @@ -131,10 +129,9 @@ public class TestCFRuleRecord patternFormatting.setFillForegroundColor(HSSFColor.INDIGO.index); assertEquals(HSSFColor.INDIGO.index,patternFormatting.getFillForegroundColor()); - + patternFormatting.setFillPattern(PatternFormatting.DIAMONDS); assertEquals(PatternFormatting.DIAMONDS,patternFormatting.getFillPattern()); - } private void testBorderFormattingAccessors(BorderFormatting borderFormatting) @@ -143,13 +140,13 @@ public class TestCFRuleRecord assertFalse(borderFormatting.isBackwardDiagonalOn()); borderFormatting.setBackwardDiagonalOn(true); assertTrue(borderFormatting.isBackwardDiagonalOn()); - + borderFormatting.setBorderBottom(BorderFormatting.BORDER_DOTTED); assertEquals(BorderFormatting.BORDER_DOTTED, borderFormatting.getBorderBottom()); - + borderFormatting.setBorderDiagonal(BorderFormatting.BORDER_MEDIUM); assertEquals(BorderFormatting.BORDER_MEDIUM, borderFormatting.getBorderDiagonal()); - + borderFormatting.setBorderLeft(BorderFormatting.BORDER_MEDIUM_DASH_DOT_DOT); assertEquals(BorderFormatting.BORDER_MEDIUM_DASH_DOT_DOT, borderFormatting.getBorderLeft()); @@ -178,119 +175,137 @@ public class TestCFRuleRecord borderFormatting.setTopBorderColor(HSSFColor.GOLD.index); assertEquals(HSSFColor.GOLD.index, borderFormatting.getTopBorderColor()); } - - + + private void testFontFormattingAccessors(FontFormatting fontFormatting) { // Check for defaults - assertFalse(fontFormatting.isEscapementTypeModified()); - assertFalse(fontFormatting.isFontCancellationModified()); - assertFalse(fontFormatting.isFontCondenseModified()); - assertFalse(fontFormatting.isFontOutlineModified()); - assertFalse(fontFormatting.isFontShadowModified()); - assertFalse(fontFormatting.isFontStyleModified()); - assertFalse(fontFormatting.isUnderlineTypeModified()); - - assertFalse(fontFormatting.isBold()); - assertFalse(fontFormatting.isCondenseOn()); - assertFalse(fontFormatting.isItalic()); - assertFalse(fontFormatting.isOutlineOn()); - assertFalse(fontFormatting.isShadowOn()); - assertFalse(fontFormatting.isStruckout()); - - assertEquals(0, fontFormatting.getEscapementType()); - assertEquals(-1, fontFormatting.getFontColorIndex()); - assertEquals(-1, fontFormatting.getFontHeight()); - assertEquals(400, fontFormatting.getFontWeight()); - assertEquals(0, fontFormatting.getUnderlineType()); - - fontFormatting.setBold(true); - assertTrue(fontFormatting.isBold()); - fontFormatting.setBold(false); - assertFalse(fontFormatting.isBold()); - - fontFormatting.setCondense(true); - assertTrue(fontFormatting.isCondenseOn()); - fontFormatting.setCondense(false); - assertFalse(fontFormatting.isCondenseOn()); - - fontFormatting.setEscapementType(FontFormatting.SS_SUB); - assertEquals(FontFormatting.SS_SUB, fontFormatting.getEscapementType()); - fontFormatting.setEscapementType(FontFormatting.SS_SUPER); - assertEquals(FontFormatting.SS_SUPER, fontFormatting.getEscapementType()); - fontFormatting.setEscapementType(FontFormatting.SS_NONE); - assertEquals(FontFormatting.SS_NONE, fontFormatting.getEscapementType()); - - fontFormatting.setEscapementTypeModified(false); - assertFalse(fontFormatting.isEscapementTypeModified()); - fontFormatting.setEscapementTypeModified(true); - assertTrue(fontFormatting.isEscapementTypeModified()); - - fontFormatting.setFontCancellationModified(false); - assertFalse(fontFormatting.isFontCancellationModified()); - fontFormatting.setFontCancellationModified(true); - assertTrue(fontFormatting.isFontCancellationModified()); - - fontFormatting.setFontColorIndex((short)10); - assertEquals(10,fontFormatting.getFontColorIndex()); - - fontFormatting.setFontCondenseModified(false); - assertFalse(fontFormatting.isFontCondenseModified()); - fontFormatting.setFontCondenseModified(true); - assertTrue(fontFormatting.isFontCondenseModified()); - - fontFormatting.setFontHeight((short)100); - assertEquals(100,fontFormatting.getFontHeight()); - - fontFormatting.setFontOutlineModified(false); - assertFalse(fontFormatting.isFontOutlineModified()); - fontFormatting.setFontOutlineModified(true); - assertTrue(fontFormatting.isFontOutlineModified()); - - fontFormatting.setFontShadowModified(false); - assertFalse(fontFormatting.isFontShadowModified()); - fontFormatting.setFontShadowModified(true); - assertTrue(fontFormatting.isFontShadowModified()); - - fontFormatting.setFontStyleModified(false); - assertFalse(fontFormatting.isFontStyleModified()); - fontFormatting.setFontStyleModified(true); - assertTrue(fontFormatting.isFontStyleModified()); - - fontFormatting.setItalic(false); - assertFalse(fontFormatting.isItalic()); - fontFormatting.setItalic(true); - assertTrue(fontFormatting.isItalic()); - - fontFormatting.setOutline(false); - assertFalse(fontFormatting.isOutlineOn()); - fontFormatting.setOutline(true); - assertTrue(fontFormatting.isOutlineOn()); - - fontFormatting.setShadow(false); - assertFalse(fontFormatting.isShadowOn()); - fontFormatting.setShadow(true); - assertTrue(fontFormatting.isShadowOn()); - - fontFormatting.setStrikeout(false); - assertFalse(fontFormatting.isStruckout()); - fontFormatting.setStrikeout(true); - assertTrue(fontFormatting.isStruckout()); - - fontFormatting.setUnderlineType(FontFormatting.U_DOUBLE_ACCOUNTING); - assertEquals(FontFormatting.U_DOUBLE_ACCOUNTING, fontFormatting.getUnderlineType()); - - fontFormatting.setUnderlineTypeModified(false); - assertFalse(fontFormatting.isUnderlineTypeModified()); - fontFormatting.setUnderlineTypeModified(true); - assertTrue(fontFormatting.isUnderlineTypeModified()); + assertFalse(fontFormatting.isEscapementTypeModified()); + assertFalse(fontFormatting.isFontCancellationModified()); + assertFalse(fontFormatting.isFontCondenseModified()); + assertFalse(fontFormatting.isFontOutlineModified()); + assertFalse(fontFormatting.isFontShadowModified()); + assertFalse(fontFormatting.isFontStyleModified()); + assertFalse(fontFormatting.isUnderlineTypeModified()); + + assertFalse(fontFormatting.isBold()); + assertFalse(fontFormatting.isCondenseOn()); + assertFalse(fontFormatting.isItalic()); + assertFalse(fontFormatting.isOutlineOn()); + assertFalse(fontFormatting.isShadowOn()); + assertFalse(fontFormatting.isStruckout()); + + assertEquals(0, fontFormatting.getEscapementType()); + assertEquals(-1, fontFormatting.getFontColorIndex()); + assertEquals(-1, fontFormatting.getFontHeight()); + assertEquals(400, fontFormatting.getFontWeight()); + assertEquals(0, fontFormatting.getUnderlineType()); + + fontFormatting.setBold(true); + assertTrue(fontFormatting.isBold()); + fontFormatting.setBold(false); + assertFalse(fontFormatting.isBold()); + + fontFormatting.setCondense(true); + assertTrue(fontFormatting.isCondenseOn()); + fontFormatting.setCondense(false); + assertFalse(fontFormatting.isCondenseOn()); + + fontFormatting.setEscapementType(FontFormatting.SS_SUB); + assertEquals(FontFormatting.SS_SUB, fontFormatting.getEscapementType()); + fontFormatting.setEscapementType(FontFormatting.SS_SUPER); + assertEquals(FontFormatting.SS_SUPER, fontFormatting.getEscapementType()); + fontFormatting.setEscapementType(FontFormatting.SS_NONE); + assertEquals(FontFormatting.SS_NONE, fontFormatting.getEscapementType()); + + fontFormatting.setEscapementTypeModified(false); + assertFalse(fontFormatting.isEscapementTypeModified()); + fontFormatting.setEscapementTypeModified(true); + assertTrue(fontFormatting.isEscapementTypeModified()); + + fontFormatting.setFontCancellationModified(false); + assertFalse(fontFormatting.isFontCancellationModified()); + fontFormatting.setFontCancellationModified(true); + assertTrue(fontFormatting.isFontCancellationModified()); + + fontFormatting.setFontColorIndex((short)10); + assertEquals(10,fontFormatting.getFontColorIndex()); + + fontFormatting.setFontCondenseModified(false); + assertFalse(fontFormatting.isFontCondenseModified()); + fontFormatting.setFontCondenseModified(true); + assertTrue(fontFormatting.isFontCondenseModified()); + + fontFormatting.setFontHeight((short)100); + assertEquals(100,fontFormatting.getFontHeight()); + + fontFormatting.setFontOutlineModified(false); + assertFalse(fontFormatting.isFontOutlineModified()); + fontFormatting.setFontOutlineModified(true); + assertTrue(fontFormatting.isFontOutlineModified()); + + fontFormatting.setFontShadowModified(false); + assertFalse(fontFormatting.isFontShadowModified()); + fontFormatting.setFontShadowModified(true); + assertTrue(fontFormatting.isFontShadowModified()); + + fontFormatting.setFontStyleModified(false); + assertFalse(fontFormatting.isFontStyleModified()); + fontFormatting.setFontStyleModified(true); + assertTrue(fontFormatting.isFontStyleModified()); + + fontFormatting.setItalic(false); + assertFalse(fontFormatting.isItalic()); + fontFormatting.setItalic(true); + assertTrue(fontFormatting.isItalic()); + + fontFormatting.setOutline(false); + assertFalse(fontFormatting.isOutlineOn()); + fontFormatting.setOutline(true); + assertTrue(fontFormatting.isOutlineOn()); + + fontFormatting.setShadow(false); + assertFalse(fontFormatting.isShadowOn()); + fontFormatting.setShadow(true); + assertTrue(fontFormatting.isShadowOn()); + + fontFormatting.setStrikeout(false); + assertFalse(fontFormatting.isStruckout()); + fontFormatting.setStrikeout(true); + assertTrue(fontFormatting.isStruckout()); + + fontFormatting.setUnderlineType(FontFormatting.U_DOUBLE_ACCOUNTING); + assertEquals(FontFormatting.U_DOUBLE_ACCOUNTING, fontFormatting.getUnderlineType()); + + fontFormatting.setUnderlineTypeModified(false); + assertFalse(fontFormatting.isUnderlineTypeModified()); + fontFormatting.setUnderlineTypeModified(true); + assertTrue(fontFormatting.isUnderlineTypeModified()); } - - - public static void main(String[] ignored_args) + + public void testWrite() { + Workbook workbook = Workbook.createWorkbook(); + CFRuleRecord rr = CFRuleRecord.create(workbook, ComparisonOperator.BETWEEN, "5", "10"); + + 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)); + + 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 + assertEquals(0xA03FFFFF, flags); + } + + + public static void main(String[] ignored_args) { System.out.println("Testing org.apache.poi.hssf.record.CFRuleRecord"); junit.textui.TestRunner.run(TestCFRuleRecord.class); } - } diff --git a/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java b/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java index 960627a39b..3c35b29a26 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java @@ -44,7 +44,7 @@ public final class TestExternalNameRecord extends TestCase { }
}
}
-
+
public void testBasicSize() {
ExternalNameRecord enr = createSimpleENR();
if(enr.getRecordSize() == 13) {
diff --git a/src/testcases/org/apache/poi/hssf/record/aggregates/AllRecordAggregateTests.java b/src/testcases/org/apache/poi/hssf/record/aggregates/AllRecordAggregateTests.java new file mode 100644 index 0000000000..862fe6715f --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/aggregates/AllRecordAggregateTests.java @@ -0,0 +1,40 @@ +/* ====================================================================
+ 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.record.aggregates;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Collects all tests for package <tt>org.apache.poi.hssf.record.aggregates</tt>.
+ *
+ * @author Josh Micich
+ */
+public final class AllRecordAggregateTests {
+
+ public static Test suite() {
+ TestSuite result = new TestSuite(AllRecordAggregateTests.class.getName());
+
+ result.addTestSuite(TestCFRecordsAggregate.class);
+ result.addTestSuite(TestColumnInfoRecordsAggregate.class);
+ result.addTestSuite(TestFormulaRecordAggregate.class);
+ result.addTestSuite(TestRowRecordsAggregate.class);
+ result.addTestSuite(TestValueRecordsAggregate.class);
+ 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 332c99209f..f605097768 100644 --- a/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java +++ b/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java @@ -24,9 +24,11 @@ import java.util.List; import junit.framework.TestCase; +import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.record.CFHeaderRecord; import org.apache.poi.hssf.record.CFRuleRecord; import org.apache.poi.hssf.record.RecordFactory; +import org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator; import org.apache.poi.hssf.record.cf.CellRange; /** @@ -35,77 +37,71 @@ import org.apache.poi.hssf.record.cf.CellRange; * * @author Dmitriy Kumshayev */ -public class TestCFRecordsAggregate - extends TestCase +public final class TestCFRecordsAggregate extends TestCase { - public TestCFRecordsAggregate(String name) - { - super(name); - } - - public void testCFRecordsAggregate() - { - CFRecordsAggregate record = new CFRecordsAggregate(); - List recs = new ArrayList(); - CFHeaderRecord header = new CFHeaderRecord(); - CFRuleRecord rule1 = new CFRuleRecord(); - CFRuleRecord rule2 = new CFRuleRecord(); - CFRuleRecord rule3 = new CFRuleRecord(); - header.setNumberOfConditionalFormats(3); - CellRange range1 = new CellRange(0,1,(short)0,(short)0); - CellRange range2 = new CellRange(0,1,(short)2,(short)2); - List cellRanges = new ArrayList(); - cellRanges.add(range1); - cellRanges.add(range2); - header.setCellRanges(cellRanges); - recs.add(header); - recs.add(rule1); - recs.add(rule2); - recs.add(rule3); - record = CFRecordsAggregate.createCFAggregate(recs, 0); - - // Serialize - byte [] serializedRecord = record.serialize(); - InputStream in = new ByteArrayInputStream(serializedRecord); - - //Parse - recs = RecordFactory.createRecords(in); - - // Verify - assertNotNull(recs); - assertEquals(4, recs.size()); - - header = (CFHeaderRecord)recs.get(0); - rule1 = (CFRuleRecord)recs.get(1); - rule2 = (CFRuleRecord)recs.get(2); - rule3 = (CFRuleRecord)recs.get(3); - cellRanges = header.getCellRanges(); - - assertEquals(2, cellRanges.size()); - assertEquals(3, header.getNumberOfConditionalFormats()); - - record = CFRecordsAggregate.createCFAggregate(recs, 0); - - record = record.cloneCFAggregate(); - - assertNotNull(record.getHeader()); - assertEquals(3,record.getRules().size()); - - header = record.getHeader(); - rule1 = (CFRuleRecord)record.getRules().get(0); - rule2 = (CFRuleRecord)record.getRules().get(1); - rule3 = (CFRuleRecord)record.getRules().get(2); - cellRanges = header.getCellRanges(); - - assertEquals(2, cellRanges.size()); - assertEquals(3, header.getNumberOfConditionalFormats()); - } - - public static void main(String[] ignored_args) + public void testCFRecordsAggregate() + { + Workbook workbook = Workbook.createWorkbook(); + List recs = new ArrayList(); + CFHeaderRecord header = new CFHeaderRecord(); + CFRuleRecord rule1 = CFRuleRecord.create(workbook, "7"); + CFRuleRecord rule2 = CFRuleRecord.create(workbook, ComparisonOperator.BETWEEN, "2", "5"); + CFRuleRecord rule3 = CFRuleRecord.create(workbook, ComparisonOperator.GE, "100", null); + header.setNumberOfConditionalFormats(3); + CellRange[] cellRanges = { + new CellRange(0,1,0,0), + new CellRange(0,1,2,2), + }; + header.setCellRanges(cellRanges); + recs.add(header); + recs.add(rule1); + recs.add(rule2); + recs.add(rule3); + CFRecordsAggregate record; + record = CFRecordsAggregate.createCFAggregate(recs, 0); + + // Serialize + byte [] serializedRecord = record.serialize(); + InputStream in = new ByteArrayInputStream(serializedRecord); + + //Parse + recs = RecordFactory.createRecords(in); + + // Verify + assertNotNull(recs); + assertEquals(4, recs.size()); + + header = (CFHeaderRecord)recs.get(0); + rule1 = (CFRuleRecord)recs.get(1); + rule2 = (CFRuleRecord)recs.get(2); + rule3 = (CFRuleRecord)recs.get(3); + cellRanges = header.getCellRanges(); + + assertEquals(2, cellRanges.length); + assertEquals(3, header.getNumberOfConditionalFormats()); + + record = CFRecordsAggregate.createCFAggregate(recs, 0); + + record = record.cloneCFAggregate(); + + assertNotNull(record.getHeader()); + assertEquals(3,record.getNumberOfRules()); + + header = record.getHeader(); + rule1 = record.getRule(0); + rule2 = record.getRule(1); + rule3 = record.getRule(2); + cellRanges = header.getCellRanges(); + + assertEquals(2, cellRanges.length); + assertEquals(3, header.getNumberOfConditionalFormats()); + } + + public static void main(String[] ignored_args) { System.out.println("Testing org.apache.poi.hssf.record.aggregates.CFRecordsAggregate"); junit.textui.TestRunner.run(TestCFRecordsAggregate.class); } - + } 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 d0095c18cb..20fded35e9 100644 --- a/src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java +++ b/src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java @@ -23,7 +23,7 @@ import org.apache.poi.hssf.record.ColumnInfoRecord; /** * @author Glen Stampoultzis */ -public class TestColumnInfoRecordsAggregate extends TestCase +public final class TestColumnInfoRecordsAggregate extends TestCase { ColumnInfoRecordsAggregate columnInfoRecordsAggregate; @@ -35,7 +35,7 @@ public class TestColumnInfoRecordsAggregate extends TestCase columnInfoRecordsAggregate.insertColumn( createColumn( (short)8, (short)8 )); // columnInfoRecordsAggregate.setColumn( (short)2, new Short( (short)200 ), new Integer( 1 ), new Boolean( true ), null); columnInfoRecordsAggregate.groupColumnRange( (short)2, (short)5, true ); - System.out.println( "columnInfoRecordsAggregate = " + columnInfoRecordsAggregate.getNumColumns() ); + assertEquals(6, columnInfoRecordsAggregate.getNumColumns()); assertEquals(columnInfoRecordsAggregate.getRecordSize(), columnInfoRecordsAggregate.serialize().length); 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 f9857fb248..ade097e697 100644 --- a/src/testcases/org/apache/poi/hssf/record/cf/TestCellRange.java +++ b/src/testcases/org/apache/poi/hssf/record/cf/TestCellRange.java @@ -24,13 +24,13 @@ import junit.framework.TestCase; */ public class TestCellRange extends TestCase { - private static final CellRange biggest = new CellRange(0, -1,(short) 0,(short)-1); - private static final CellRange tenthColumn = new CellRange(0, -1,(short)10,(short)10); - private static final CellRange tenthRow = new CellRange(10,10,(short) 0,(short)-1); - private static final CellRange box10x10 = new CellRange(0, 10,(short) 0,(short)10); - private static final CellRange box9x9 = new CellRange(0, 9,(short) 0,(short) 9); - private static final CellRange box10to20c = new CellRange(0, 10,(short)10,(short)20); - private static final CellRange oneCell = new CellRange(10,10,(short)10,(short)10); + private static final CellRange biggest = new CellRange( 0, -1, 0,-1); + private static final CellRange tenthColumn = new CellRange( 0, -1,10,10); + private static final CellRange tenthRow = new CellRange(10, 10, 0,-1); + private static final CellRange box10x10 = new CellRange( 0, 10, 0,10); + private static final CellRange box9x9 = new CellRange( 0, 9, 0, 9); + private static final CellRange box10to20c = new CellRange( 0, 10,10,20); + private static final CellRange oneCell = new CellRange(10, 10,10,10); boolean [][] contanis = new boolean[][] { @@ -61,62 +61,62 @@ public class TestCellRange extends TestCase } } } - - private static final CellRange col1 = new CellRange(0, -1,(short) 1,(short)1); - private static final CellRange col2 = new CellRange(0, -1,(short) 2,(short)2); - private static final CellRange row1 = new CellRange(1, 1,(short) 0,(short)-1); - private static final CellRange row2 = new CellRange(2, 2,(short) 0,(short)-1); - private static final CellRange box0 = new CellRange( 0, 2,(short) 0,(short)2); - private static final CellRange box1 = new CellRange( 0, 1,(short) 0,(short)1); - private static final CellRange box2 = new CellRange( 0, 1,(short) 2,(short)3); - private static final CellRange box3 = new CellRange( 2, 3,(short) 0,(short)1); - private static final CellRange box4 = new CellRange( 2, 3,(short) 2,(short)3); - private static final CellRange box5 = new CellRange( 1, 3,(short) 1,(short)3); + private static final CellRange col1 = new CellRange( 0, -1, 1,1); + private static final CellRange col2 = new CellRange( 0, -1, 2,2); + private static final CellRange row1 = new CellRange( 1, 1, 0,-1); + private static final CellRange row2 = new CellRange( 2, 2, 0,-1); + + private static final CellRange box0 = new CellRange( 0, 2, 0,2); + private static final CellRange box1 = new CellRange( 0, 1, 0,1); + private static final CellRange box2 = new CellRange( 0, 1, 2,3); + private static final CellRange box3 = new CellRange( 2, 3, 0,1); + private static final CellRange box4 = new CellRange( 2, 3, 2,3); + private static final CellRange box5 = new CellRange( 1, 3, 1,3); public void testHasSharedBorderMethod() { - assertFalse(col1.hasSharedBorder(col1)); - assertFalse(col2.hasSharedBorder(col2)); - assertTrue(col1.hasSharedBorder(col2)); - assertTrue(col2.hasSharedBorder(col1)); + assertFalse(col1.hasExactSharedBorder(col1)); + assertFalse(col2.hasExactSharedBorder(col2)); + assertTrue(col1.hasExactSharedBorder(col2)); + assertTrue(col2.hasExactSharedBorder(col1)); - assertFalse(row1.hasSharedBorder(row1)); - assertFalse(row2.hasSharedBorder(row2)); - assertTrue(row1.hasSharedBorder(row2)); - assertTrue(row2.hasSharedBorder(row1)); + assertFalse(row1.hasExactSharedBorder(row1)); + assertFalse(row2.hasExactSharedBorder(row2)); + assertTrue(row1.hasExactSharedBorder(row2)); + assertTrue(row2.hasExactSharedBorder(row1)); - assertFalse(row1.hasSharedBorder(col1)); - assertFalse(row1.hasSharedBorder(col2)); - assertFalse(col1.hasSharedBorder(row1)); - assertFalse(col2.hasSharedBorder(row1)); - assertFalse(row2.hasSharedBorder(col1)); - assertFalse(row2.hasSharedBorder(col2)); - assertFalse(col1.hasSharedBorder(row2)); - assertFalse(col2.hasSharedBorder(row2)); - assertTrue(col2.hasSharedBorder(col1)); + assertFalse(row1.hasExactSharedBorder(col1)); + assertFalse(row1.hasExactSharedBorder(col2)); + assertFalse(col1.hasExactSharedBorder(row1)); + assertFalse(col2.hasExactSharedBorder(row1)); + assertFalse(row2.hasExactSharedBorder(col1)); + assertFalse(row2.hasExactSharedBorder(col2)); + assertFalse(col1.hasExactSharedBorder(row2)); + assertFalse(col2.hasExactSharedBorder(row2)); + assertTrue(col2.hasExactSharedBorder(col1)); - assertFalse(box1.hasSharedBorder(box1)); - assertTrue(box1.hasSharedBorder(box2)); - assertTrue(box1.hasSharedBorder(box3)); - assertFalse(box1.hasSharedBorder(box4)); + assertFalse(box1.hasExactSharedBorder(box1)); + assertTrue(box1.hasExactSharedBorder(box2)); + assertTrue(box1.hasExactSharedBorder(box3)); + assertFalse(box1.hasExactSharedBorder(box4)); - assertTrue(box2.hasSharedBorder(box1)); - assertFalse(box2.hasSharedBorder(box2)); - assertFalse(box2.hasSharedBorder(box3)); - assertTrue(box2.hasSharedBorder(box4)); + assertTrue(box2.hasExactSharedBorder(box1)); + assertFalse(box2.hasExactSharedBorder(box2)); + assertFalse(box2.hasExactSharedBorder(box3)); + assertTrue(box2.hasExactSharedBorder(box4)); - assertTrue(box3.hasSharedBorder(box1)); - assertFalse(box3.hasSharedBorder(box2)); - assertFalse(box3.hasSharedBorder(box3)); - assertTrue(box3.hasSharedBorder(box4)); + assertTrue(box3.hasExactSharedBorder(box1)); + assertFalse(box3.hasExactSharedBorder(box2)); + assertFalse(box3.hasExactSharedBorder(box3)); + assertTrue(box3.hasExactSharedBorder(box4)); - assertFalse(box4.hasSharedBorder(box1)); - assertTrue(box4.hasSharedBorder(box2)); - assertTrue(box4.hasSharedBorder(box3)); - assertFalse(box4.hasSharedBorder(box4)); + assertFalse(box4.hasExactSharedBorder(box1)); + assertTrue(box4.hasExactSharedBorder(box2)); + assertTrue(box4.hasExactSharedBorder(box3)); + assertFalse(box4.hasExactSharedBorder(box4)); } - + public void testIntersectMethod() { assertEquals( CellRange.OVERLAP,box0.intersect(box5)); @@ -135,5 +135,4 @@ public class TestCellRange extends TestCase assertEquals(CellRange.INSIDE,tenthColumn.intersect(tenthColumn)); assertEquals(CellRange.INSIDE,tenthRow.intersect(tenthRow)); } - } diff --git a/src/testcases/org/apache/poi/hssf/record/formula/AllFormulaTests.java b/src/testcases/org/apache/poi/hssf/record/formula/AllFormulaTests.java index b50e95fa86..645709bb6e 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/AllFormulaTests.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/AllFormulaTests.java @@ -17,13 +17,15 @@ package org.apache.poi.hssf.record.formula; +import org.apache.poi.hssf.record.formula.eval.AllFormulaEvalTests; import org.apache.poi.hssf.record.formula.function.AllFormulaFunctionTests; +import org.apache.poi.hssf.record.formula.functions.AllIndividualFunctionEvaluationTests; import junit.framework.Test; import junit.framework.TestSuite; /** - * Collects all tests for this package. + * Collects all tests for <tt>org.apache.poi.hssf.record.formula</tt>. * * @author Josh Micich */ @@ -31,6 +33,10 @@ public class AllFormulaTests { public static Test suite() { TestSuite result = new TestSuite(AllFormulaTests.class.getName()); + result.addTest(AllFormulaEvalTests.suite()); + result.addTest(AllFormulaFunctionTests.suite()); + result.addTest(AllIndividualFunctionEvaluationTests.suite()); + result.addTestSuite(TestArea3DPtg.class); result.addTestSuite(TestAreaErrPtg.class); result.addTestSuite(TestAreaPtg.class); diff --git a/src/testcases/org/apache/poi/hssf/record/formula/function/AllFormulaFunctionTests.java b/src/testcases/org/apache/poi/hssf/record/formula/function/AllFormulaFunctionTests.java index 8a59095e46..01f88bd069 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/function/AllFormulaFunctionTests.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/function/AllFormulaFunctionTests.java @@ -21,7 +21,7 @@ import junit.framework.Test; import junit.framework.TestSuite; /** - * Collects all tests for this package. + * Collects all tests for this <tt>org.apache.poi.hssf.record.formula.function</tt>. * * @author Josh Micich */ diff --git a/src/testcases/org/apache/poi/hssf/record/formula/function/ExcelFileFormatDocFunctionExtractor.java b/src/testcases/org/apache/poi/hssf/record/formula/function/ExcelFileFormatDocFunctionExtractor.java index c7d74b6f75..48a76e31d8 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/function/ExcelFileFormatDocFunctionExtractor.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/function/ExcelFileFormatDocFunctionExtractor.java @@ -49,14 +49,14 @@ import org.xml.sax.XMLReader; import org.xml.sax.helpers.XMLReaderFactory; /** - * This class is not used during normal POI run-time but is used at development time to generate + * This class is not used during normal POI run-time but is used at development time to generate * the file 'functionMetadata.txt'. There are more than 300 built-in functions in Excel and the * intention of this class is to make it easier to maintain the metadata, by extracting it from * a reliable source. * * @author Josh Micich */ -public class ExcelFileFormatDocFunctionExtractor { +public final class ExcelFileFormatDocFunctionExtractor { private static final String SOURCE_DOC_FILE_NAME = "excelfileformat.odt"; @@ -195,19 +195,19 @@ public class ExcelFileFormatDocFunctionExtractor { "table:table-row", "table:table-cell", "text:p", "text:span", "text:note-ref", }; - + private final Stack _elemNameStack; /** <code>true</code> only when parsing the target tables */ private boolean _isInsideTable; - + private final List _rowData; private final StringBuffer _textNodeBuffer; private final List _rowNoteFlags; private boolean _cellHasNote; - + private final FunctionDataCollector _fdc; private String _lastHeadingText; - + public EFFDocHandler(FunctionDataCollector fdc) { _fdc = fdc; _elemNameStack = new Stack(); @@ -216,7 +216,7 @@ public class ExcelFileFormatDocFunctionExtractor { _textNodeBuffer = new StringBuffer(); _rowNoteFlags = new ArrayList(); } - + private boolean matchesTargetPath() { return matchesPath(0, TABLE_BASE_PATH_NAMES); } @@ -365,7 +365,7 @@ public class ExcelFileFormatDocFunctionExtractor { xr.setContentHandler(new EFFDocHandler(fdc)); InputSource inSrc = new InputSource(is); - + try { xr.parse(inSrc); is.close(); @@ -407,30 +407,30 @@ public class ExcelFileFormatDocFunctionExtractor { } private static void outputLicenseHeader(PrintStream ps) { - String[] lines= { - "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.", - }; - for (int i = 0; i < lines.length; i++) { - ps.print("# "); - ps.println(lines[i]); - } - ps.println(); - } - - /** + String[] lines= { + "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.", + }; + for (int i = 0; i < lines.length; i++) { + ps.print("# "); + ps.println(lines[i]); + } + ps.println(); + } + + /** * Helps identify the source file */ private static String getFileCRC(File f) { @@ -451,10 +451,10 @@ public class ExcelFileFormatDocFunctionExtractor { } return "0x" + Long.toHexString(crc.getValue()).toUpperCase(); } - + private static File getSourceFile() { - if (true) { - File dir = new File("c:/josh/ref-docs"); + if (false) { + File dir = new File("c:/temp"); File effDocFile = new File(dir, SOURCE_DOC_FILE_NAME); return effDocFile; } @@ -464,7 +464,7 @@ public class ExcelFileFormatDocFunctionExtractor { } catch (MalformedURLException e) { throw new RuntimeException(e); } - + File result; byte[]buf = new byte[2048]; try { @@ -488,16 +488,15 @@ public class ExcelFileFormatDocFunctionExtractor { System.out.println("file downloaded ok"); return result; } - + public static void main(String[] args) { - + File effDocFile = getSourceFile(); if(!effDocFile.exists()) { throw new RuntimeException("file '" + effDocFile.getAbsolutePath() + "' does not exist"); } - + File outFile = new File("functionMetadata-asGenerated.txt"); processFile(effDocFile, outFile); } - } diff --git a/src/testcases/org/apache/poi/hssf/record/formula/function/TestFunctionMetadataRegistry.java b/src/testcases/org/apache/poi/hssf/record/formula/function/TestFunctionMetadataRegistry.java index edb215ec50..c175c473bf 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/function/TestFunctionMetadataRegistry.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/function/TestFunctionMetadataRegistry.java @@ -18,26 +18,27 @@ package org.apache.poi.hssf.record.formula.function; import junit.framework.TestCase; + /** * * @author Josh Micich */ public final class TestFunctionMetadataRegistry extends TestCase { - public void testWellKnownFunctions() { - confirmFunction(0, "COUNT"); - confirmFunction(1, "IF"); - - } - - private static void confirmFunction(int index, String funcName) { - FunctionMetadata fm; - fm = FunctionMetadataRegistry.getFunctionByIndex(index); - assertNotNull(fm); - assertEquals(funcName, fm.getName()); - - fm = FunctionMetadataRegistry.getFunctionByName(funcName); - assertNotNull(fm); - assertEquals(index, fm.getIndex()); - } + public void testWellKnownFunctions() { + confirmFunction(0, "COUNT"); + confirmFunction(1, "IF"); + + } + + private static void confirmFunction(int index, String funcName) { + FunctionMetadata fm; + fm = FunctionMetadataRegistry.getFunctionByIndex(index); + assertNotNull(fm); + assertEquals(funcName, fm.getName()); + + fm = FunctionMetadataRegistry.getFunctionByName(funcName); + assertNotNull(fm); + assertEquals(index, fm.getIndex()); + } } diff --git a/src/testcases/org/apache/poi/hssf/record/formula/function/TestParseMissingBuiltInFuncs.java b/src/testcases/org/apache/poi/hssf/record/formula/function/TestParseMissingBuiltInFuncs.java index fe1b8fccc8..3671d37c1a 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/function/TestParseMissingBuiltInFuncs.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/function/TestParseMissingBuiltInFuncs.java @@ -44,8 +44,8 @@ public final class TestParseMissingBuiltInFuncs extends TestCase { } AbstractFunctionPtg func = (AbstractFunctionPtg) ptgF; if(func.getFunctionIndex() == 255) { - throw new AssertionFailedError("Failed to recognise built-in function in formula '" - + formula + "'"); + throw new AssertionFailedError("Failed to recognise built-in function in formula '" + + formula + "'"); } assertEquals(expPtgArraySize, ptgs.length); diff --git a/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java b/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java index 7e1d0317ec..f1e6bcfacf 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java @@ -48,7 +48,7 @@ public final class TestReadMissingBuiltInFuncs extends TestCase { } sht = wb.getSheetAt(0); } - + public void testDatedif() { String formula; @@ -56,9 +56,9 @@ public final class TestReadMissingBuiltInFuncs extends TestCase { formula = getCellFormula(0); } catch (IllegalStateException e) { if(e.getMessage().startsWith("Too few arguments")) { - if(e.getMessage().indexOf("AttrPtg") > 0) { - throw afe("tAttrVolatile not supported in FormulaParser.toFormulaString"); - } + if(e.getMessage().indexOf("AttrPtg") > 0) { + throw afe("tAttrVolatile not supported in FormulaParser.toFormulaString"); + } throw afe("NOW() registered with 1 arg instead of 0"); } if(e.getMessage().startsWith("too much stuff")) { @@ -70,7 +70,7 @@ public final class TestReadMissingBuiltInFuncs extends TestCase { assertEquals("DATEDIF(NOW(),NOW(),\"d\")", formula); } public void testDdb() { - + String formula = getCellFormula(1); if("externalflag(1,1,1,1,1)".equals(formula)) { throw afe("DDB() not registered"); @@ -78,14 +78,14 @@ public final class TestReadMissingBuiltInFuncs extends TestCase { assertEquals("DDB(1,1,1,1,1)", formula); } public void testAtan() { - + String formula = getCellFormula(2); if(formula.equals("ARCTAN(1)")) { throw afe("func ix 18 registered as ARCTAN() instead of ATAN()"); } assertEquals("ATAN(1)", formula); } - + public void testUsdollar() { String formula = getCellFormula(3); @@ -128,7 +128,7 @@ public final class TestReadMissingBuiltInFuncs extends TestCase { } assertEquals("ISNONTEXT(\"abc\")", formula); } - + private String getCellFormula(int rowIx) { String result = sht.getRow(rowIx).getCell((short)0).getCellFormula(); if (false) { diff --git a/src/testcases/org/apache/poi/hssf/record/formula/functions/AllIndividualFunctionEvaluationTests.java b/src/testcases/org/apache/poi/hssf/record/formula/functions/AllIndividualFunctionEvaluationTests.java index 66d2a1d270..5973d7cb2d 100755 --- a/src/testcases/org/apache/poi/hssf/record/formula/functions/AllIndividualFunctionEvaluationTests.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/functions/AllIndividualFunctionEvaluationTests.java @@ -27,9 +27,8 @@ import junit.framework.TestSuite; */ public final class AllIndividualFunctionEvaluationTests { - // TODO - have this suite incorporated into a higher level one public static Test suite() { - TestSuite result = new TestSuite("Tests for org.apache.poi.hssf.record.formula.functions"); + TestSuite result = new TestSuite(AllIndividualFunctionEvaluationTests.class.getName()); result.addTestSuite(TestAverage.class); result.addTestSuite(TestCountFuncs.class); result.addTestSuite(TestDate.class); diff --git a/src/testcases/org/apache/poi/hssf/record/formula/functions/TestPmt.java b/src/testcases/org/apache/poi/hssf/record/formula/functions/TestPmt.java index 935615acae..2fecef7046 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/functions/TestPmt.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/functions/TestPmt.java @@ -30,7 +30,7 @@ import org.apache.poi.hssf.usermodel.HSSFErrorConstants; * @author Josh Micich */ public final class TestPmt extends TestCase { - + private static void confirm(double expected, NumberEval ne) { // only asserting accuracy to 4 fractional digits assertEquals(expected, ne.getNumberValue(), 0.00005); @@ -61,12 +61,12 @@ public final class TestPmt extends TestCase { confirm(expected, invokeNormal(args)); } - + public void testBasic() { confirm(-1037.0321, (0.08/12), 10, 10000, 0, false); confirm(-1030.1643, (0.08/12), 10, 10000, 0, true); } - + public void test3args() { Eval[] args = { diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index 94c19cbc04..f05c1d1157 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -357,14 +357,14 @@ extends TestCase { book.createSheet("TEST"); HSSFSheet sheet = book.cloneSheet(0); book.setSheetName(1,"CLONE"); - sheet.createRow(0).createCell((short)0).setCellValue("Test"); + sheet.createRow(0).createCell((short)0).setCellValue(new HSSFRichTextString("Test")); book.write(out); book = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray())); sheet = book.getSheet("CLONE"); HSSFRow row = sheet.getRow(0); HSSFCell cell = row.getCell((short)0); - System.out.println(cell.getStringCellValue()); + assertEquals("Test", cell.getRichStringCellValue().getString()); } /** diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConfditionalFormatting.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConfditionalFormatting.java new file mode 100644 index 0000000000..6186d227ef --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConfditionalFormatting.java @@ -0,0 +1,90 @@ +/* ==================================================================== + 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 junit.framework.TestCase; + +import org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator; +import org.apache.poi.hssf.util.HSSFColor; +import org.apache.poi.hssf.util.Region; +/** + * + * @author Dmitriy Kumshayev + */ +public final class TestHSSFConfditionalFormatting extends TestCase +{ + public void testLastAndFirstColumns() + { + HSSFWorkbook workbook = new HSSFWorkbook(); + HSSFSheet sheet = workbook.createSheet(); + String formula = "7"; + + HSSFFontFormatting fontFmt = new HSSFFontFormatting(); + fontFmt.setFontStyle(true, false); + + HSSFBorderFormatting bordFmt = new HSSFBorderFormatting(); + bordFmt.setBorderBottom(HSSFBorderFormatting.BORDER_THIN); + bordFmt.setBorderTop(HSSFBorderFormatting.BORDER_THICK); + bordFmt.setBorderLeft(HSSFBorderFormatting.BORDER_DASHED); + bordFmt.setBorderRight(HSSFBorderFormatting.BORDER_DOTTED); + + HSSFPatternFormatting patternFmt = new HSSFPatternFormatting(); + patternFmt.setFillBackgroundColor(HSSFColor.RED.index); + + HSSFConditionalFormattingRule [] cfRules = + { + sheet.createConditionalFormattingRule(formula, fontFmt, bordFmt, patternFmt), + sheet.createConditionalFormattingRule(ComparisonOperator.BETWEEN, "1", "2", fontFmt, bordFmt, patternFmt) + }; + + short col = 1; + Region [] regions = + { + new Region(0,col,-1,col) + }; + + sheet.addConditionalFormatting(regions, cfRules); + sheet.addConditionalFormatting(regions, cfRules); + + // Verification + assertEquals(2, sheet.getNumConditionalFormattings()); + sheet.removeConditionalFormatting(1); + assertEquals(1, sheet.getNumConditionalFormattings()); + HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(0); + assertNotNull(cf); + + regions = cf.getFormattingRegions(); + assertNotNull(regions); + assertEquals(1, regions.length); + Region r = regions[0]; + assertEquals(1, r.getColumnFrom()); + assertEquals(1, r.getColumnTo()); + assertEquals(0, r.getRowFrom()); + assertEquals(-1, r.getRowTo()); + + assertEquals(2, cf.getNumberOfRules()); + + HSSFConditionalFormattingRule rule1 = cf.getRule(0); + assertEquals("7",rule1.getFormula1()); + assertNull(rule1.getFormula2()); + + HSSFConditionalFormattingRule rule2 = cf.getRule(1); + assertEquals("2",rule2.getFormula2()); + assertEquals("1",rule2.getFormula1()); + } +} |