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

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