Browse Source

Testcases for fo:table-column


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@591063 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-0_95beta
Vincent Hennebert 16 years ago
parent
commit
a3d7ceee3d

+ 131
- 0
test/fotree/unittests/table/table-column_column-number.fo View File

@@ -0,0 +1,131 @@
<?xml version="1.0" standalone="no"?>
<!--
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$ -->
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="page" page-height="29.7cm" page-width="21cm" margin="10pt">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="page">
<fo:flow flow-name="xsl-region-body">
<fo:block space-after="10pt">Several configurations of tables for testing the setup of
columns.</fo:block>
<fo:block space-after="10pt">A simple table to begin.</fo:block>
<fo:table table-layout="fixed" border-collapse="separate" width="200pt">
<fo:table-column number-columns-repeated="2" column-width="100pt"/>
<fo:table-header>
<fo:table-cell border="1pt solid black"><fo:block>Header 1.1</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Header 1.2</fo:block></fo:table-cell>
</fo:table-header>
<fo:table-footer>
<fo:table-cell border="1pt solid black"><fo:block>Footer 1.1</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Footer 1.2</fo:block></fo:table-cell>
</fo:table-footer>
<fo:table-body>
<fo:table-cell border="1pt solid black"><fo:block>Cell 1.1</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Cell 1.2</fo:block></fo:table-cell>
<fo:table-cell starts-row="true"
border="1pt solid black"><fo:block>Cell 2.1</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Cell 2.2</fo:block></fo:table-cell>
</fo:table-body>
</fo:table>

<fo:block space-before="20pt" space-after="10pt">2 columns, resp. 200pt and 100pt
wide.</fo:block>
<fo:table table-layout="fixed" border-collapse="separate" width="300pt">
<fo:table-column column-width="200pt"/>
<fo:table-column column-width="100pt"/>
<fo:table-header>
<fo:table-cell border="1pt solid black"><fo:block>Header 1.1</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Header 1.2</fo:block></fo:table-cell>
</fo:table-header>
<fo:table-footer>
<fo:table-cell border="1pt solid black"><fo:block>Footer 1.1</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Footer 1.2</fo:block></fo:table-cell>
</fo:table-footer>
<fo:table-body>
<fo:table-cell border="1pt solid black"><fo:block>Cell 1.1</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Cell 1.2</fo:block></fo:table-cell>
<fo:table-cell starts-row="true"
border="1pt solid black"><fo:block>Cell 2.1</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Cell 2.2</fo:block></fo:table-cell>
</fo:table-body>
</fo:table>

<fo:block space-before="20pt" space-after="10pt">3 unordered columns, resp. 100, 150 and
200pt wide.</fo:block>
<fo:table table-layout="fixed" border-collapse="separate" width="450">
<fo:table-column column-number="2" column-width="150pt"/>
<fo:table-column column-width="200pt"/>
<fo:table-column column-number="1" column-width="100pt"/>
<fo:table-header>
<fo:table-cell border="1pt solid black"><fo:block>Header 1.1</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Header 1.2</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Header 1.3</fo:block></fo:table-cell>
</fo:table-header>
<fo:table-footer>
<fo:table-cell border="1pt solid black"><fo:block>Footer 1.1</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Footer 1.2</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Footer 1.3</fo:block></fo:table-cell>
</fo:table-footer>
<fo:table-body>
<fo:table-cell border="1pt solid black"><fo:block>Cell 1.1</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Cell 1.2</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Cell 1.3</fo:block></fo:table-cell>
<fo:table-cell starts-row="true"
border="1pt solid black"><fo:block>Cell 2.1</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Cell 2.2</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Cell 2.3</fo:block></fo:table-cell>
</fo:table-body>
</fo:table>

<fo:block space-before="20pt" space-after="10pt">4 unordered columns, 2nd column implicit,
resp. 100, 125, 150 and 175 pt wide.</fo:block>
<fo:table table-layout="fixed" border-collapse="separate" width="550">
<fo:table-column column-number="3" column-width="150pt"/>
<fo:table-column column-width="175pt"/>
<fo:table-column column-number="1" column-width="100pt"/>
<fo:table-header>
<fo:table-cell border="1pt solid black"><fo:block>Header 1.1</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Header 1.2</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Header 1.3</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Header 1.4</fo:block></fo:table-cell>
</fo:table-header>
<fo:table-footer>
<fo:table-cell border="1pt solid black"><fo:block>Footer 1.1</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Footer 1.2</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Footer 1.3</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Footer 1.4</fo:block></fo:table-cell>
</fo:table-footer>
<fo:table-body>
<fo:table-cell border="1pt solid black"><fo:block>Cell 1.1</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Cell 1.2</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Cell 1.3</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Cell 1.4</fo:block></fo:table-cell>
<fo:table-cell starts-row="true"
border="1pt solid black"><fo:block>Cell 2.1</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Cell 2.2</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Cell 2.3</fo:block></fo:table-cell>
<fo:table-cell border="1pt solid black"><fo:block>Cell 2.4</fo:block></fo:table-cell>
</fo:table-body>
</fo:table>

</fo:flow>
</fo:page-sequence>
</fo:root>

+ 52
- 0
test/java/org/apache/fop/fo/flow/AbstractTableTestCase.java View File

@@ -0,0 +1,52 @@
/*
* 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.fotreetest.FOTreeUnitTester;

/**
* Superclass for testcases related to tables, factoring the common stuff.
*/
abstract class AbstractTableTestCase extends FOTreeUnitTester {

private FOTreeUnitTester.FOEventHandlerFactory tableHandlerFactory;

private TableHandler tableHandler;

public AbstractTableTestCase() throws Exception {
super();
tableHandlerFactory = new FOEventHandlerFactory() {
public FOEventHandler createFOEventHandler(FOUserAgent foUserAgent) {
tableHandler = new TableHandler(foUserAgent);
return tableHandler;
}
};
}

protected void setUp(String filename) throws Exception {
setUp(filename, tableHandlerFactory);
}

protected TableHandler getTableHandler() {
return tableHandler;
}
}

+ 91
- 0
test/java/org/apache/fop/fo/flow/TableColumnColumnNumberTestCase.java View File

@@ -0,0 +1,91 @@
/*
* 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.Iterator;

import org.apache.fop.datatypes.PercentBaseContext;
import org.apache.fop.fo.FObj;


public class TableColumnColumnNumberTestCase extends AbstractTableTestCase {

/**
* A percentBaseContext that mimics the behaviour of TableLM for computing the widths
* of columns. All what needs to be known is the width of a table unit (as in
* proportional-column-width()).
*/
private class TablePercentBaseContext implements PercentBaseContext {

private int unitaryWidth;

void setUnitaryWidth(int unitaryWidth) {
this.unitaryWidth = unitaryWidth;
}

public int getBaseLength(int lengthBase, FObj fobj) {
return unitaryWidth;
}
}

private TablePercentBaseContext percentBaseContext = new TablePercentBaseContext();

public TableColumnColumnNumberTestCase() throws Exception {
super();
}

private void checkColumn(Table t, int number, boolean isDefault, int spans, int repeated, int width) {
TableColumn c = t.getColumn(number - 1);
// TODO a repeated column has a correct number only for its first occurrence
// assertEquals(number, c.getColumnNumber());
assertEquals(isDefault, c.isDefaultColumn());
assertEquals(spans, c.getNumberColumnsSpanned());
assertEquals(repeated, c.getNumberColumnsRepeated());
assertEquals(width, c.getColumnWidth().getValue(percentBaseContext));
}

public void testColumnNumber() throws Exception {
setUp("table/table-column_column-number.fo");
Iterator tableIter = getTableHandler().getTables().iterator();
Table t = (Table) tableIter.next();
assertEquals(2, t.getNumberOfColumns());
checkColumn(t, 1, false, 1, 2, 100000);
checkColumn(t, 2, false, 1, 2, 100000);

t = (Table) tableIter.next();
assertEquals(2, t.getNumberOfColumns());
checkColumn(t, 1, false, 1, 1, 200000);
checkColumn(t, 2, false, 1, 1, 100000);

t = (Table) tableIter.next();
assertEquals(3, t.getNumberOfColumns());
checkColumn(t, 1, false, 1, 1, 100000);
checkColumn(t, 2, false, 1, 1, 150000);
checkColumn(t, 3, false, 1, 1, 200000);

t = (Table) tableIter.next();
percentBaseContext.setUnitaryWidth(125000);
assertEquals(4, t.getNumberOfColumns());
checkColumn(t, 1, false, 1, 1, 100000);
checkColumn(t, 2, true, 1, 1, 125000);
checkColumn(t, 3, false, 1, 1, 150000);
checkColumn(t, 4, false, 1, 1, 175000);
}
}

+ 2
- 12
test/java/org/apache/fop/fo/flow/TooManyColumnsTestCase.java View File

@@ -19,27 +19,17 @@

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 class TooManyColumnsTestCase extends AbstractTableTestCase {

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);
setUp(filename);
fail();
} catch (ValidationException e) {
// TODO check location

Loading…
Cancel
Save