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.

CollapsedConditionalBorderTestCase.java 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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.awt.Color;
  21. import java.util.Iterator;
  22. import java.util.List;
  23. import org.apache.fop.fo.Constants;
  24. import org.apache.fop.fo.FONode.FONodeIterator;
  25. import org.apache.fop.fo.properties.CommonBorderPaddingBackground.BorderInfo;
  26. import org.junit.Test;
  27. /**
  28. * A testcase for the resolution of collapsed borders in the FO tree, taking
  29. * conditionality into account. The resolved borders are generated by the
  30. * collapsed-conditional-borders_test-generator.py Python script.
  31. */
  32. public class CollapsedConditionalBorderTestCase extends AbstractTableTest {
  33. private final Integer border0pt = new Integer(0);
  34. private final Integer border4pt = new Integer(4000);
  35. private final Integer border6pt = new Integer(6000);
  36. private final Integer border8pt = new Integer(8000);
  37. /**
  38. * Resolved borders for tables without headers and footers, generated from the Python
  39. * script.
  40. */
  41. private Object[][][] resolvedBorders = {
  42. {{border0pt, Color.black}, {border8pt, Color.black}},
  43. {{border6pt, Color.red}, {border6pt, Color.magenta}},
  44. {{border6pt, Color.blue}, {border6pt, Color.yellow}},
  45. {{border8pt, Color.black}, {border8pt, Color.black}},
  46. {{border8pt, Color.black}, {border8pt, Color.black}},
  47. {{border6pt, Color.red}, {border6pt, Color.magenta}},
  48. {{border8pt, Color.black}, {border8pt, Color.black}},
  49. {{border6pt, Color.red}, {border6pt, Color.blue}},
  50. {{border6pt, Color.magenta}, {border6pt, Color.blue}},
  51. {{border8pt, Color.black}, {border8pt, Color.black}},
  52. {{border6pt, Color.red}, {border6pt, Color.yellow}},
  53. {{border6pt, Color.magenta}, {border6pt, Color.yellow}},
  54. {{border6pt, Color.blue}, {border6pt, Color.yellow}},
  55. {{border8pt, Color.black}, {border8pt, Color.black}},
  56. {{border8pt, Color.black}, {border8pt, Color.black}},
  57. {{border8pt, Color.black}, {border8pt, Color.black}},
  58. {{border8pt, Color.black}, {border8pt, Color.black}},
  59. {{border8pt, Color.black}, {border6pt, Color.red}},
  60. {{border6pt, Color.magenta}, {border6pt, Color.blue}},
  61. {{border8pt, Color.black}, {border8pt, Color.black}},
  62. {{border8pt, Color.black}, {border8pt, Color.black}},
  63. {{border8pt, Color.black}, {border8pt, Color.black}},
  64. {{border6pt, Color.red}, {border6pt, Color.magenta}},
  65. {{border6pt, Color.yellow}, {border8pt, Color.black}},
  66. {{border8pt, Color.black}, {border8pt, Color.black}},
  67. {{border6pt, Color.red}, {border6pt, Color.blue}},
  68. {{border6pt, Color.yellow}, {border6pt, Color.magenta}},
  69. {{border6pt, Color.blue}, {border6pt, Color.yellow}},
  70. {{border8pt, Color.black}, {border8pt, Color.black}},
  71. {{border8pt, Color.black}, {border8pt, Color.black}},
  72. {{border8pt, Color.black}, {border8pt, Color.black}},
  73. {{border8pt, Color.black}, {border8pt, Color.black}},
  74. {{border8pt, Color.black}, {border8pt, Color.black}},
  75. {{border8pt, Color.black}, {border8pt, Color.black}},
  76. {{border8pt, Color.black}, {border8pt, Color.black}},
  77. {{border8pt, Color.black}, {border8pt, Color.black}},
  78. {{border6pt, Color.red}, {border6pt, Color.magenta}},
  79. {{border6pt, Color.blue}, {border6pt, Color.yellow}},
  80. {{border8pt, Color.black}, {border8pt, Color.black}},
  81. {{border8pt, Color.black}, {border8pt, Color.black}}
  82. };
  83. /**
  84. * Resolved borders for tables with headers and footers, generated from the Python
  85. * script.
  86. */
  87. private Object[][][] resolvedBordersHF = {
  88. {{border8pt, Color.black}, {border6pt, Color.black}, {border8pt, Color.black}, {border6pt, Color.black}, {border4pt, Color.black}, {border4pt, Color.black}, {border4pt, Color.red}, {border8pt, Color.blue}, {border6pt, Color.black}, {border4pt, Color.magenta}, {border8pt, Color.blue}, {border8pt, Color.blue}, {border4pt, Color.red}, {border4pt, Color.blue}, {border4pt, Color.blue}, {border4pt, Color.magenta}},
  89. {{border8pt, Color.black}, {border6pt, Color.blue}, {border8pt, Color.black}, {border6pt, Color.blue}, {border4pt, Color.black}, {border4pt, Color.black}, {border4pt, Color.red}, {border8pt, Color.blue}, {border6pt, Color.black}, {border6pt, Color.black}, {border8pt, Color.blue}, {border8pt, Color.blue}, {border4pt, Color.red}, {border4pt, Color.blue}, {border4pt, Color.blue}, {border4pt, Color.magenta}},
  90. {{border8pt, Color.black}, {border6pt, Color.blue}, {border8pt, Color.black}, {border6pt, Color.blue}, {border8pt, Color.red}, {border8pt, Color.red}, {border8pt, Color.red}, {border6pt, Color.blue}, {border4pt, Color.black}, {border4pt, Color.black}, {border6pt, Color.blue}, {border8pt, Color.red}, {border8pt, Color.red}, {border4pt, Color.blue}, {border4pt, Color.blue}, {border4pt, Color.magenta}},
  91. {{border8pt, Color.black}, {border6pt, Color.blue}, {border8pt, Color.black}, {border6pt, Color.blue}, {border8pt, Color.red}, {border8pt, Color.red}, {border8pt, Color.red}, {border6pt, Color.blue}, {border4pt, Color.black}, {border4pt, Color.magenta}, {border6pt, Color.blue}, {border8pt, Color.red}, {border8pt, Color.red}, {border4pt, Color.blue}, {border4pt, Color.blue}, {border4pt, Color.magenta}},
  92. {{border8pt, Color.black}, {border6pt, Color.black}, {border8pt, Color.black}, {border6pt, Color.black}, {border4pt, Color.black}, {border4pt, Color.black}, {border4pt, Color.red}, {border8pt, Color.black}, {border8pt, Color.black}, {border4pt, Color.magenta}, {border8pt, Color.black}, {border6pt, Color.blue}, {border4pt, Color.red}, {border4pt, Color.blue}, {border4pt, Color.blue}, {border4pt, Color.magenta}},
  93. {{border8pt, Color.black}, {border6pt, Color.blue}, {border8pt, Color.black}, {border6pt, Color.blue}, {border4pt, Color.black}, {border4pt, Color.black}, {border4pt, Color.red}, {border8pt, Color.black}, {border8pt, Color.black}, {border4pt, Color.magenta}, {border8pt, Color.black}, {border6pt, Color.blue}, {border6pt, Color.blue}, {border4pt, Color.blue}, {border4pt, Color.blue}, {border4pt, Color.magenta}},
  94. {{border8pt, Color.black}, {border6pt, Color.blue}, {border8pt, Color.black}, {border6pt, Color.blue}, {border4pt, Color.black}, {border4pt, Color.black}, {border4pt, Color.red}, {border6pt, Color.black}, {border8pt, Color.magenta}, {border8pt, Color.magenta}, {border6pt, Color.black}, {border4pt, Color.blue}, {border4pt, Color.red}, {border8pt, Color.magenta}, {border8pt, Color.magenta}, {border8pt, Color.magenta}},
  95. {{border8pt, Color.black}, {border6pt, Color.blue}, {border8pt, Color.black}, {border6pt, Color.blue}, {border4pt, Color.black}, {border4pt, Color.black}, {border4pt, Color.red}, {border8pt, Color.black}, {border8pt, Color.black}, {border8pt, Color.black}, {border8pt, Color.black}, {border4pt, Color.blue}, {border4pt, Color.red}, {border6pt, Color.magenta}, {border6pt, Color.magenta}, {border6pt, Color.magenta}}
  96. };
  97. public CollapsedConditionalBorderTestCase() throws Exception {
  98. super();
  99. }
  100. private static GridUnit getGridUnit(TablePart part) {
  101. return (GridUnit) ((List) ((List) part.getRowGroups().get(0)).get(0)).get(0);
  102. }
  103. private static void checkBorder(String errorMsge, BorderSpecification border,
  104. int expectedLength, Color expectedColor) {
  105. BorderInfo borderInfo = border.getBorderInfo();
  106. if (expectedLength == 0) {
  107. assertEquals(errorMsge, Constants.EN_NONE, borderInfo.getStyle());
  108. } else {
  109. assertEquals(errorMsge, expectedLength, borderInfo.getWidth().getLengthValue());
  110. assertEquals(errorMsge, expectedColor, borderInfo.getColor());
  111. }
  112. }
  113. private static void checkBorder(String errorMsge, BorderSpecification border,
  114. Object[] resolvedBorder) {
  115. checkBorder(errorMsge, border,
  116. ((Integer) resolvedBorder[0]).intValue(),
  117. (Color) resolvedBorder[1]);
  118. }
  119. @Test
  120. public void testCollapsedConditionalBorders() throws Exception {
  121. setUp("table/collapsed-conditional-borders.fo");
  122. int tableNum = 0;
  123. Iterator tableIterator = getTableIterator();
  124. do {
  125. String baseErrorMsge = "table " + Integer.toString(tableNum) + " (0-based), ";
  126. Table table = (Table) tableIterator.next();
  127. TablePart part = (TablePart) table.getChildNodes().nextNode();
  128. GridUnit gu = getGridUnit(part);
  129. String errorMsge = baseErrorMsge + "border-before";
  130. checkBorder(errorMsge, gu.borderBefore.normal, 8000, Color.black);
  131. checkBorder(errorMsge, gu.borderBefore.leadingTrailing, 8000, Color.black);
  132. checkBorder(errorMsge, gu.borderBefore.rest, resolvedBorders[tableNum][0]);
  133. errorMsge = baseErrorMsge + "border-after";
  134. checkBorder(errorMsge, gu.borderAfter.normal, 8000, Color.black);
  135. checkBorder(errorMsge, gu.borderAfter.leadingTrailing, 8000, Color.black);
  136. checkBorder(errorMsge, gu.borderAfter.rest, resolvedBorders[tableNum][1]);
  137. tableNum++;
  138. } while (tableIterator.hasNext());
  139. }
  140. @Test
  141. public void testCollapsedConditionalBordersHeaderFooter() throws Exception {
  142. setUp("table/collapsed-conditional-borders_header-footer.fo");
  143. int tableNum = 0;
  144. Iterator tableIterator = getTableIterator();
  145. do {
  146. String errorMsge = "table " + Integer.toString(tableNum) + " (0-based)";
  147. int borderNum = 0;
  148. Table table = (Table) tableIterator.next();
  149. TableHeader header = table.getTableHeader();
  150. GridUnit gu = getGridUnit(header);
  151. checkBorder(errorMsge, gu.borderBefore.normal,
  152. resolvedBordersHF[tableNum][borderNum++]);
  153. checkBorder(errorMsge, gu.borderBefore.rest,
  154. resolvedBordersHF[tableNum][borderNum++]);
  155. TableFooter footer = table.getTableFooter();
  156. gu = getGridUnit(footer);
  157. checkBorder(errorMsge, gu.borderAfter.normal,
  158. resolvedBordersHF[tableNum][borderNum++]);
  159. checkBorder(errorMsge, gu.borderAfter.rest,
  160. resolvedBordersHF[tableNum][borderNum++]);
  161. FONodeIterator bodyIter = table.getChildNodes();
  162. TableBody body = (TableBody) bodyIter.nextNode();
  163. gu = getGridUnit(body);
  164. checkBorder(errorMsge, gu.borderBefore.normal,
  165. resolvedBordersHF[tableNum][borderNum++]);
  166. checkBorder(errorMsge, gu.borderBefore.leadingTrailing,
  167. resolvedBordersHF[tableNum][borderNum++]);
  168. checkBorder(errorMsge, gu.borderBefore.rest,
  169. resolvedBordersHF[tableNum][borderNum++]);
  170. checkBorder(errorMsge, gu.borderAfter.normal,
  171. resolvedBordersHF[tableNum][borderNum++]);
  172. checkBorder(errorMsge, gu.borderAfter.leadingTrailing,
  173. resolvedBordersHF[tableNum][borderNum++]);
  174. checkBorder(errorMsge, gu.borderAfter.rest,
  175. resolvedBordersHF[tableNum][borderNum++]);
  176. body = (TableBody) bodyIter.nextNode();
  177. gu = getGridUnit(body);
  178. checkBorder(errorMsge, gu.borderBefore.normal,
  179. resolvedBordersHF[tableNum][borderNum++]);
  180. checkBorder(errorMsge, gu.borderBefore.leadingTrailing,
  181. resolvedBordersHF[tableNum][borderNum++]);
  182. checkBorder(errorMsge, gu.borderBefore.rest,
  183. resolvedBordersHF[tableNum][borderNum++]);
  184. checkBorder(errorMsge, gu.borderAfter.normal,
  185. resolvedBordersHF[tableNum][borderNum++]);
  186. checkBorder(errorMsge, gu.borderAfter.leadingTrailing,
  187. resolvedBordersHF[tableNum][borderNum++]);
  188. checkBorder(errorMsge, gu.borderAfter.rest,
  189. resolvedBordersHF[tableNum][borderNum++]);
  190. tableNum++;
  191. } while (tableIterator.hasNext());
  192. }
  193. }