You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TableColumnColumnNumberTestCase.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.fo.flow.table;
  19. import java.util.Iterator;
  20. import org.junit.Test;
  21. import static org.junit.Assert.assertEquals;
  22. import org.apache.fop.datatypes.PercentBaseContext;
  23. import org.apache.fop.fo.FObj;
  24. public class TableColumnColumnNumberTestCase extends AbstractTableTest {
  25. /**
  26. * A percentBaseContext that mimics the behaviour of TableLM for computing the widths
  27. * of columns. All what needs to be known is the width of a table unit (as in
  28. * proportional-column-width()).
  29. */
  30. private class TablePercentBaseContext implements PercentBaseContext {
  31. private int unitaryWidth;
  32. void setUnitaryWidth(int unitaryWidth) {
  33. this.unitaryWidth = unitaryWidth;
  34. }
  35. public int getBaseLength(int lengthBase, FObj fobj) {
  36. return unitaryWidth;
  37. }
  38. }
  39. private TablePercentBaseContext percentBaseContext = new TablePercentBaseContext();
  40. private void checkColumn(Table t, int number, boolean isImplicit, int spans, int repeated, int width) {
  41. TableColumn c = t.getColumn(number - 1);
  42. // TODO a repeated column has a correct number only for its first occurrence
  43. // assertEquals(number, c.getColumnNumber());
  44. assertEquals(isImplicit, c.isImplicitColumn());
  45. assertEquals(spans, c.getNumberColumnsSpanned());
  46. assertEquals(repeated, c.getNumberColumnsRepeated());
  47. assertEquals(width, c.getColumnWidth().getValue(percentBaseContext));
  48. }
  49. @Test
  50. public void testColumnNumber() throws Exception {
  51. setUp("table/table-column_column-number.fo");
  52. Iterator tableIter = getTableIterator();
  53. Table t = (Table) tableIter.next();
  54. assertEquals(2, t.getNumberOfColumns());
  55. checkColumn(t, 1, false, 1, 2, 100000);
  56. checkColumn(t, 2, false, 1, 2, 100000);
  57. t = (Table) tableIter.next();
  58. assertEquals(2, t.getNumberOfColumns());
  59. checkColumn(t, 1, false, 1, 1, 200000);
  60. checkColumn(t, 2, false, 1, 1, 100000);
  61. t = (Table) tableIter.next();
  62. assertEquals(3, t.getNumberOfColumns());
  63. checkColumn(t, 1, false, 1, 1, 100000);
  64. checkColumn(t, 2, false, 1, 1, 150000);
  65. checkColumn(t, 3, false, 1, 1, 200000);
  66. t = (Table) tableIter.next();
  67. percentBaseContext.setUnitaryWidth(125000);
  68. assertEquals(4, t.getNumberOfColumns());
  69. checkColumn(t, 1, false, 1, 1, 100000);
  70. checkColumn(t, 2, true, 1, 1, 125000);
  71. checkColumn(t, 3, false, 1, 1, 150000);
  72. checkColumn(t, 4, false, 1, 1, 175000);
  73. }
  74. private void checkImplicitColumns(Iterator tableIter, int columnNumber) {
  75. Table t = (Table) tableIter.next();
  76. assertEquals(columnNumber, t.getNumberOfColumns());
  77. for (int i = 1; i <= columnNumber; i++) {
  78. checkColumn(t, i, true, 1, 1, 100000);
  79. }
  80. }
  81. @Test
  82. public void testImplicitColumns() throws Exception {
  83. setUp("table/implicit_columns_column-number.fo");
  84. percentBaseContext.setUnitaryWidth(100000);
  85. Iterator tableIter = getTableIterator();
  86. checkImplicitColumns(tableIter, 2);
  87. checkImplicitColumns(tableIter, 2);
  88. checkImplicitColumns(tableIter, 2);
  89. checkImplicitColumns(tableIter, 2);
  90. checkImplicitColumns(tableIter, 3);
  91. checkImplicitColumns(tableIter, 4);
  92. checkImplicitColumns(tableIter, 3);
  93. }
  94. }