From fc34b198fd486c5db87e4982b118ba558dcbbedd Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Wed, 31 Oct 2007 15:06:35 +0000 Subject: - Enforced check for proper number of columns in a table. Now if a table has explicit table-columns, those fix the total number of columns and any row having more columns will lead to an error. - Set up a framework for unit-testing classes from the FO tree, and added some first testcases for the number of columns in tables. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@590705 13f79535-47bb-0310-9956-ffa450edef68 --- test/fotree/testcases/column-number_cells_body2.fo | 34 +++----- .../unittests/table/too-many-columns_body_1.fo | 48 +++++++++++ .../unittests/table/too-many-columns_body_2.fo | 51 ++++++++++++ .../unittests/table/too-many-columns_body_3.fo | 56 +++++++++++++ test/java/org/apache/fop/fo/flow/TableHandler.java | 45 ++++++++++ .../apache/fop/fo/flow/TooManyColumnsTestCase.java | 60 ++++++++++++++ .../org/apache/fop/fotreetest/FOTreeTestSuite.java | 14 +++- .../apache/fop/fotreetest/FOTreeUnitTester.java | 95 ++++++++++++++++++++++ .../table-cell_starts-row_ends-row.xml | 1 + .../standard-testcases/table-column_missing.xml | 75 ----------------- .../table-stepper_colspan_border-before.xml | 2 +- .../table_border-collapse_collapse_1r2c.xml | 12 ++- .../table_border-collapse_collapse_nrnc.xml | 3 +- .../table_border-collapse_collapse_spans_1.xml | 14 ++-- 14 files changed, 400 insertions(+), 110 deletions(-) create mode 100644 test/fotree/unittests/table/too-many-columns_body_1.fo create mode 100644 test/fotree/unittests/table/too-many-columns_body_2.fo create mode 100644 test/fotree/unittests/table/too-many-columns_body_3.fo create mode 100644 test/java/org/apache/fop/fo/flow/TableHandler.java create mode 100644 test/java/org/apache/fop/fo/flow/TooManyColumnsTestCase.java create mode 100644 test/java/org/apache/fop/fotreetest/FOTreeUnitTester.java delete mode 100644 test/layoutengine/standard-testcases/table-column_missing.xml (limited to 'test') diff --git a/test/fotree/testcases/column-number_cells_body2.fo b/test/fotree/testcases/column-number_cells_body2.fo index d5d1e2e44..ef9d9ad75 100644 --- a/test/fotree/testcases/column-number_cells_body2.fo +++ b/test/fotree/testcases/column-number_cells_body2.fo @@ -41,63 +41,55 @@ - cell1 + cell 1.1 - cell2 + cell 1.2 - cell3 + cell 1.3 - cell4 - - - - cell5 - - - - cell5b + cell 1.4 - cell6 + cell 2.1 - cell7 + cell 2.2 - cell8 + cell 2.3 - cell9 + cell 3.1 - cell10 + cell 3.2 - cell11 + cell 3.3 - cell12 + cell 3.4 - cell13 + cell 4.1 - cell14 + cell 5.1 diff --git a/test/fotree/unittests/table/too-many-columns_body_1.fo b/test/fotree/unittests/table/too-many-columns_body_1.fo new file mode 100644 index 000000000..4691c3b7a --- /dev/null +++ b/test/fotree/unittests/table/too-many-columns_body_1.fo @@ -0,0 +1,48 @@ + + + + + + + + + + + + The following table has a row which contains too many + columns. + + + + + Cell 1.1 + + + Cell 1.2 + + + Cell 1.3 + + + Cell 2.1 + + + + + + diff --git a/test/fotree/unittests/table/too-many-columns_body_2.fo b/test/fotree/unittests/table/too-many-columns_body_2.fo new file mode 100644 index 000000000..9fe26ab9e --- /dev/null +++ b/test/fotree/unittests/table/too-many-columns_body_2.fo @@ -0,0 +1,51 @@ + + + + + + + + + + + + The following table has a row which contains too many + columns. + + + + + Cell 1.1 + + + Cell 1.2 + + + Cell 2.1 + + + Cell 2.2 + + + Cell 2.3 + + + + + + diff --git a/test/fotree/unittests/table/too-many-columns_body_3.fo b/test/fotree/unittests/table/too-many-columns_body_3.fo new file mode 100644 index 000000000..4ed0098fc --- /dev/null +++ b/test/fotree/unittests/table/too-many-columns_body_3.fo @@ -0,0 +1,56 @@ + + + + + + + + + + + + The following table has a row which contains too many + columns. + + + + + + Cell 1.1 + + + + + Cell 1.2 + + + + + Cell 2.1 + + + + + Cell 2.3 + + + + + + + diff --git a/test/java/org/apache/fop/fo/flow/TableHandler.java b/test/java/org/apache/fop/fo/flow/TableHandler.java new file mode 100644 index 000000000..c29c33d73 --- /dev/null +++ b/test/java/org/apache/fop/fo/flow/TableHandler.java @@ -0,0 +1,45 @@ +/* + * 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. + */ + +/* $Id$ */ + +package org.apache.fop.fo.flow; + +import java.util.LinkedList; +import java.util.List; + +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.fo.FOEventHandler; +import org.apache.fop.fo.flow.Table; + +public class TableHandler extends FOEventHandler { + + /** All the tables encountered in the FO file. List of Table objects. */ + private List tables = new LinkedList(); + + TableHandler(FOUserAgent foUserAgent) { + super(foUserAgent); + } + + public void endTable(Table tbl) { + tables.add(tbl); + } + + List getTables() { + return tables; + } +} diff --git a/test/java/org/apache/fop/fo/flow/TooManyColumnsTestCase.java b/test/java/org/apache/fop/fo/flow/TooManyColumnsTestCase.java new file mode 100644 index 000000000..8c08ddf10 --- /dev/null +++ b/test/java/org/apache/fop/fo/flow/TooManyColumnsTestCase.java @@ -0,0 +1,60 @@ +/* + * 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. + */ + +/* $Id$ */ + +package org.apache.fop.fo.flow; + +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.fo.FOEventHandler; +import org.apache.fop.fo.ValidationException; +import org.apache.fop.fotreetest.FOTreeUnitTester; + +public class TooManyColumnsTestCase extends FOTreeUnitTester { + + private FOTreeUnitTester.FOEventHandlerFactory tableHandlerFactory; + + public TooManyColumnsTestCase() throws Exception { + super(); + tableHandlerFactory = new FOTreeUnitTester.FOEventHandlerFactory() { + public FOEventHandler createFOEventHandler(FOUserAgent ua) { + return new TableHandler(ua); + } + }; + } + + private void launchTest(String filename) throws Exception { + try { + setUp(filename, tableHandlerFactory); + fail(); + } catch (ValidationException e) { + // TODO check location + } + } + + public void testBody1() throws Exception { + launchTest("table/too-many-columns_body_1.fo"); + } + + public void testBody2() throws Exception { + launchTest("table/too-many-columns_body_2.fo"); + } + + public void testBody3() throws Exception { + launchTest("table/too-many-columns_body_3.fo"); + } +} diff --git a/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java b/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java index 0b46a5c66..6ae786439 100644 --- a/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java +++ b/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java @@ -32,6 +32,7 @@ import org.apache.commons.io.filefilter.PrefixFileFilter; import org.apache.commons.io.filefilter.SuffixFileFilter; import org.apache.commons.io.filefilter.TrueFileFilter; import org.apache.fop.DebugHelper; +import org.apache.fop.fo.flow.TooManyColumnsTestCase; import org.apache.fop.layoutengine.LayoutEngineTestSuite; import junit.framework.Test; @@ -57,7 +58,12 @@ public final class FOTreeTestSuite { */ public static Test suite() throws IOException { TestSuite suite = new TestSuite(); + addXMLTestCases(suite); + addUnitTestCases(suite); + return suite; + } + private static void addXMLTestCases(TestSuite suite) throws IOException { File mainDir = new File("test/fotree"); final FOTreeTester tester = new FOTreeTester(); @@ -88,8 +94,6 @@ public final class FOTreeTestSuite { File f = (File)i.next(); addTestCase(suite, tester, f); } - - return suite; } private static void addTestCase(TestSuite suite, @@ -102,7 +106,11 @@ public final class FOTreeTestSuite { } }); } - + + private static void addUnitTestCases(TestSuite suite) { + suite.addTestSuite(TooManyColumnsTestCase.class); + } + private static class FOTreeTestCase extends TestCase { private FOTreeTester tester; diff --git a/test/java/org/apache/fop/fotreetest/FOTreeUnitTester.java b/test/java/org/apache/fop/fotreetest/FOTreeUnitTester.java new file mode 100644 index 000000000..e19547345 --- /dev/null +++ b/test/java/org/apache/fop/fotreetest/FOTreeUnitTester.java @@ -0,0 +1,95 @@ +/* + * 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. + */ + +/* $Id$ */ + +package org.apache.fop.fotreetest; + +import java.io.File; + +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import junit.framework.TestCase; + +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.apps.Fop; +import org.apache.fop.apps.FopFactory; +import org.apache.fop.fo.FOEventHandler; +import org.xml.sax.XMLReader; + + +/** + * Base class for unit-testing the FO tree building code. It performs the necessary setup + * to parse an FO file and register a proper {@link FOEventHandler}. That handler will be + * the entry point to test classes from the FObj hierarchy. + */ +public abstract class FOTreeUnitTester extends TestCase { + + private XMLReader foReader; + + private FopFactory fopFactory; + + /** + * Should be implemented by children testcases for properly setting up the custom + * FOEventHandler needed to test FObj classes. + */ + public abstract static class FOEventHandlerFactory { + + /** + * This method is called by FOTreeUnitTester when creating a {@link Fop} instance. + * That lets pass to the custom FOEventHandler the proper user agent that will be + * used by this instance. + * + * @param foUserAgent the user agent needed by the Fop instance that will be used + * to create the FO tree + * @return the appropriate FOEventHandler for performing the tests + */ + public abstract FOEventHandler createFOEventHandler(FOUserAgent foUserAgent); + } + + public FOTreeUnitTester() throws Exception { + // Stuff that needs to be set up only once and will be re-used for each test + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + spf.setValidating(false); + SAXParser parser; + parser = spf.newSAXParser(); + foReader = parser.getXMLReader(); + fopFactory = FopFactory.newInstance(); + } + + /** + * Launches FOP on the given FO file. + * + * @param filename path to the test FO file + * @param factory to create the appropriate FOEventHandler for performing tests + */ + public void setUp(String filename, FOEventHandlerFactory factory) throws Exception { + FOUserAgent ua = fopFactory.newFOUserAgent(); + ua.setFOEventHandlerOverride(factory.createFOEventHandler(ua)); + + Fop fop = fopFactory.newFop(ua); + + foReader.setContentHandler(fop.getDefaultHandler()); + foReader.setDTDHandler(fop.getDefaultHandler()); + foReader.setErrorHandler(fop.getDefaultHandler()); + foReader.setEntityResolver(fop.getDefaultHandler()); + + foReader.parse(new File("test/fotree/unittests/" + filename).toURL().toExternalForm()); + } +} diff --git a/test/layoutengine/standard-testcases/table-cell_starts-row_ends-row.xml b/test/layoutengine/standard-testcases/table-cell_starts-row_ends-row.xml index 721a7e32a..b22f3e427 100644 --- a/test/layoutengine/standard-testcases/table-cell_starts-row_ends-row.xml +++ b/test/layoutengine/standard-testcases/table-cell_starts-row_ends-row.xml @@ -36,6 +36,7 @@ + cell1 diff --git a/test/layoutengine/standard-testcases/table-column_missing.xml b/test/layoutengine/standard-testcases/table-column_missing.xml deleted file mode 100644 index 01521bf7b..000000000 --- a/test/layoutengine/standard-testcases/table-column_missing.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - - - -

- This test checks if FOP can handle the case where more columns are actually used than - specified. -

-

- Note: This test case is technically wrong since in fixed table layout all - column-widths must be specified. But we don't want to have FOP crash - with an IndexOutOfBoundsException either. -

-
- - - - - - - - - - - - - - - cell 1/1 - - - - - cell 2/1 - - - cell 2/2 - - - cell 2/3 - - - - - - - - - - - - - - - - - - -
diff --git a/test/layoutengine/standard-testcases/table-stepper_colspan_border-before.xml b/test/layoutengine/standard-testcases/table-stepper_colspan_border-before.xml index 623252acc..1a1755c06 100644 --- a/test/layoutengine/standard-testcases/table-stepper_colspan_border-before.xml +++ b/test/layoutengine/standard-testcases/table-stepper_colspan_border-before.xml @@ -36,7 +36,7 @@ Before the table - diff --git a/test/layoutengine/standard-testcases/table_border-collapse_collapse_1r2c.xml b/test/layoutengine/standard-testcases/table_border-collapse_collapse_1r2c.xml index f7f544dd3..816e3f67c 100644 --- a/test/layoutengine/standard-testcases/table_border-collapse_collapse_1r2c.xml +++ b/test/layoutengine/standard-testcases/table_border-collapse_collapse_1r2c.xml @@ -35,7 +35,8 @@ - + @@ -51,7 +52,8 @@ - + @@ -67,7 +69,8 @@ - + - + - + Before the tables - + Between tables - + Between tables - + Between tables - + - + -- cgit v1.2.3