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.

RowGroupBuilderTestCase.java 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 static org.junit.Assert.assertFalse;
  21. import static org.junit.Assert.assertNull;
  22. import static org.junit.Assert.assertTrue;
  23. import java.util.Iterator;
  24. import java.util.List;
  25. import org.junit.Test;
  26. /**
  27. * Tests that RowGroupBuilder returns, for each part of a table, the expected number of
  28. * row-groups with the expected number or rows in each.
  29. */
  30. public class RowGroupBuilderTestCase extends AbstractTableTestCase {
  31. public RowGroupBuilderTestCase() throws Exception {
  32. super();
  33. }
  34. /**
  35. * Checks that the given table-body(header,footer) will return row groups as expected.
  36. * More precisely, checks that the number of row groups corresponds to the size of the
  37. * given array, and that the number of rows inside each row group is equal to the
  38. * corresponding integer in the array.
  39. *
  40. * @param part a table part whose row groups are to be checked
  41. * @param expectedRowLengths expected lengths of all the row groups of this part of
  42. * the table
  43. */
  44. private void checkTablePartRowGroups(TablePart part, int[] expectedRowLengths) {
  45. Iterator rowGroupIter = part.getRowGroups().iterator();
  46. for (int i = 0; i < expectedRowLengths.length; i++) {
  47. assertTrue(rowGroupIter.hasNext());
  48. List rowGroup = (List) rowGroupIter.next();
  49. assertEquals(expectedRowLengths[i], rowGroup.size());
  50. }
  51. assertFalse(rowGroupIter.hasNext());
  52. }
  53. /**
  54. * Gets the next table and checks its row-groups.
  55. * @param tableIter an iterator over the tables to check
  56. * @param expectedHeaderRowLengths expected row-group sizes for the header. If null
  57. * the table is not expected to have a header
  58. * @param expectedFooterRowLengths expected row-group sizes for the footer. If null
  59. * the table is not expected to have a footer
  60. * @param expectedBodyRowLengths expected row-group sizes for the body(-ies)
  61. */
  62. private void checkNextTableRowGroups(Iterator tableIter,
  63. int[] expectedHeaderRowLengths, int[] expectedFooterRowLengths, int[][] expectedBodyRowLengths) {
  64. Table table = (Table) tableIter.next();
  65. if (expectedHeaderRowLengths == null) {
  66. assertNull(table.getTableHeader());
  67. } else {
  68. checkTablePartRowGroups(table.getTableHeader(), expectedHeaderRowLengths);
  69. }
  70. if (expectedFooterRowLengths == null) {
  71. assertNull(table.getTableFooter());
  72. } else {
  73. checkTablePartRowGroups(table.getTableFooter(), expectedFooterRowLengths);
  74. }
  75. Iterator bodyIter = table.getChildNodes();
  76. for (int i = 0; i < expectedBodyRowLengths.length; i++) {
  77. assertTrue(bodyIter.hasNext());
  78. checkTablePartRowGroups((TableBody) bodyIter.next(), expectedBodyRowLengths[i]);
  79. }
  80. }
  81. public void checkSimple(String filename) throws Exception {
  82. setUp(filename);
  83. Iterator tableIter = getTableIterator();
  84. // Table 1: no header, no footer, one body (1 row)
  85. checkNextTableRowGroups(tableIter, null, null, new int[][] {{1}});
  86. // Table 2: no header, no footer, one body (2 rows)
  87. checkNextTableRowGroups(tableIter, null, null, new int[][] {{1, 1}});
  88. // Table 3: no header, no footer, two bodies (1 row, 1 row)
  89. checkNextTableRowGroups(tableIter, null, null, new int[][] {{1}, {1}});
  90. // Table 4: no header, no footer, two bodies (2 rows, 3 rows)
  91. checkNextTableRowGroups(tableIter, null, null, new int[][] {{1, 1}, {1, 1, 1}});
  92. // Table 5: one header (1 row), no footer, one body (1 row)
  93. checkNextTableRowGroups(tableIter, new int[] {1}, null, new int[][] {{1}});
  94. // Table 6: no header, one footer (1 row), one body (1 row)
  95. checkNextTableRowGroups(tableIter, null, new int[] {1}, new int[][] {{1}});
  96. // Table 7: one header (1 row), one footer (1 row), one body (1 row)
  97. checkNextTableRowGroups(tableIter, new int[] {1}, new int[] {1}, new int[][] {{1}});
  98. // Table 8: one header (2 rows), one footer (3 rows), one body (2 rows)
  99. checkNextTableRowGroups(tableIter, new int[] {1, 1}, new int[] {1, 1, 1}, new int[][] {{1, 1}});
  100. // Table 9: one header (3 rows), one footer (2 rows), three bodies (2 rows, 1 row, 3 rows)
  101. checkNextTableRowGroups(tableIter, new int[] {1, 1, 1}, new int[] {1, 1}, new int[][] {{1, 1}, {1}, {1, 1, 1}});
  102. }
  103. public void checkSpans(String filename) throws Exception {
  104. setUp(filename);
  105. Iterator tableIter = getTableIterator();
  106. // Table 1: no header, no footer, one body (1 row with column-span)
  107. checkNextTableRowGroups(tableIter, null, null, new int[][] {{1}});
  108. // Table 2: no header, no footer, one body (1 row-group of 2 rows)
  109. checkNextTableRowGroups(tableIter, null, null, new int[][] {{2}});
  110. // Table 3: no header, no footer, one body (1 row-group of 2 rows, 1 row)
  111. checkNextTableRowGroups(tableIter, null, null, new int[][] {{2, 1}});
  112. // Table 4: no header, no footer, one body (1 row, 1 row-group of 2 rows)
  113. checkNextTableRowGroups(tableIter, null, null, new int[][] {{1, 2}});
  114. // Table 5: no header, no footer, one body (1 row, 1 row-group of 3 rows, 1 row)
  115. checkNextTableRowGroups(tableIter, null, null, new int[][] {{1, 3, 1}});
  116. // Table 6: one header (1 row-group of 2 rows), one footer (1 row, 1 row-group of 3 rows),
  117. // one body (1 row-group of 2 rows, 1 row, 1 row-group of 3 rows)
  118. checkNextTableRowGroups(tableIter, new int[] {2}, new int[] {1, 3}, new int[][] {{2, 1, 3}});
  119. }
  120. @Test
  121. public void testWithRowsSimple() throws Exception {
  122. checkSimple("table/RowGroupBuilder_simple.fo");
  123. }
  124. @Test
  125. public void testWithRowsSpans() throws Exception {
  126. checkSpans("table/RowGroupBuilder_spans.fo");
  127. }
  128. @Test
  129. public void testNoRowSimple() throws Exception {
  130. checkSimple("table/RowGroupBuilder_no-row_simple.fo");
  131. }
  132. @Test
  133. public void testNoRowSpans() throws Exception {
  134. checkSpans("table/RowGroupBuilder_no-row_spans.fo");
  135. }
  136. @Test
  137. public void testNoColWithRowsSimple() throws Exception {
  138. checkSimple("table/RowGroupBuilder_no-col_simple.fo");
  139. }
  140. @Test
  141. public void testNoColWithRowsSpans() throws Exception {
  142. checkSpans("table/RowGroupBuilder_no-col_spans.fo");
  143. }
  144. @Test
  145. public void testNoColNoRowSimple() throws Exception {
  146. checkSimple("table/RowGroupBuilder_no-col_no-row_simple.fo");
  147. }
  148. @Test
  149. public void testNoColNoRowSpans() throws Exception {
  150. checkSpans("table/RowGroupBuilder_no-col_no-row_spans.fo");
  151. }
  152. }