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.4KB

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