Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

TableColumnColumnNumberTestCase.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 static org.junit.Assert.assertEquals;
  20. import java.util.Iterator;
  21. import org.apache.fop.datatypes.PercentBaseContext;
  22. import org.apache.fop.fo.FObj;
  23. import org.junit.Test;
  24. public class TableColumnColumnNumberTestCase extends AbstractTableTestCase {
  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. public TableColumnColumnNumberTestCase() throws Exception {
  41. super();
  42. }
  43. private void checkColumn(Table t, int number, boolean isImplicit, int spans, int repeated, int width) {
  44. TableColumn c = t.getColumn(number - 1);
  45. // TODO a repeated column has a correct number only for its first occurrence
  46. // assertEquals(number, c.getColumnNumber());
  47. assertEquals(isImplicit, c.isImplicitColumn());
  48. assertEquals(spans, c.getNumberColumnsSpanned());
  49. assertEquals(repeated, c.getNumberColumnsRepeated());
  50. assertEquals(width, c.getColumnWidth().getValue(percentBaseContext));
  51. }
  52. @Test
  53. public void testColumnNumber() throws Exception {
  54. setUp("table/table-column_column-number.fo");
  55. Iterator tableIter = getTableIterator();
  56. Table t = (Table) tableIter.next();
  57. assertEquals(2, t.getNumberOfColumns());
  58. checkColumn(t, 1, false, 1, 2, 100000);
  59. checkColumn(t, 2, false, 1, 2, 100000);
  60. t = (Table) tableIter.next();
  61. assertEquals(2, t.getNumberOfColumns());
  62. checkColumn(t, 1, false, 1, 1, 200000);
  63. checkColumn(t, 2, false, 1, 1, 100000);
  64. t = (Table) tableIter.next();
  65. assertEquals(3, t.getNumberOfColumns());
  66. checkColumn(t, 1, false, 1, 1, 100000);
  67. checkColumn(t, 2, false, 1, 1, 150000);
  68. checkColumn(t, 3, false, 1, 1, 200000);
  69. t = (Table) tableIter.next();
  70. percentBaseContext.setUnitaryWidth(125000);
  71. assertEquals(4, t.getNumberOfColumns());
  72. checkColumn(t, 1, false, 1, 1, 100000);
  73. checkColumn(t, 2, true, 1, 1, 125000);
  74. checkColumn(t, 3, false, 1, 1, 150000);
  75. checkColumn(t, 4, false, 1, 1, 175000);
  76. }
  77. private void checkImplicitColumns(Iterator tableIter, int columnNumber) {
  78. Table t = (Table) tableIter.next();
  79. assertEquals(columnNumber, t.getNumberOfColumns());
  80. for (int i = 1; i <= columnNumber; i++) {
  81. checkColumn(t, i, true, 1, 1, 100000);
  82. }
  83. }
  84. @Test
  85. public void testImplicitColumns() throws Exception {
  86. setUp("table/implicit_columns_column-number.fo");
  87. percentBaseContext.setUnitaryWidth(100000);
  88. Iterator tableIter = getTableIterator();
  89. checkImplicitColumns(tableIter, 2);
  90. checkImplicitColumns(tableIter, 2);
  91. checkImplicitColumns(tableIter, 2);
  92. checkImplicitColumns(tableIter, 2);
  93. checkImplicitColumns(tableIter, 3);
  94. checkImplicitColumns(tableIter, 4);
  95. checkImplicitColumns(tableIter, 3);
  96. }
  97. }