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.

TestXSLFTableRow.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.xslf.usermodel;
  16. import static org.junit.Assert.assertEquals;
  17. import static org.junit.Assert.assertFalse;
  18. import static org.junit.Assert.assertNotNull;
  19. import static org.junit.Assert.assertSame;
  20. import static org.junit.Assert.assertTrue;
  21. import static org.junit.Assert.fail;
  22. import java.io.IOException;
  23. import java.util.List;
  24. import org.apache.poi.xslf.XSLFTestDataSamples;
  25. import org.junit.After;
  26. import org.junit.Before;
  27. import org.junit.Test;
  28. import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCell;
  29. import org.openxmlformats.schemas.drawingml.x2006.main.CTTableRow;
  30. public class TestXSLFTableRow {
  31. private static XMLSlideShow ppt;
  32. private static XSLFTable tbl;
  33. private static XSLFTableRow row;
  34. /** Copied from {@link TestXSLFTable#testRead()} */
  35. @Before
  36. public void setUp() throws IOException {
  37. ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
  38. XSLFSlide slide = ppt.getSlides().get(3);
  39. List<XSLFShape> shapes = slide.getShapes();
  40. tbl = (XSLFTable)shapes.get(0);
  41. List<XSLFTableRow> rows = tbl.getRows();
  42. row = rows.get(0);
  43. }
  44. @After
  45. public void tearDown() throws IOException {
  46. ppt.getPackage().revert();
  47. ppt.close();
  48. }
  49. @Test
  50. public void constructor() {
  51. XSLFTableRow row2 = new XSLFTableRow(row.getXmlObject(), tbl);
  52. assertSame(row.getXmlObject(), row2.getXmlObject());
  53. assertEquals(row.getHeight(), row2.getHeight(), 1e-16);
  54. }
  55. @Test
  56. public void testHeight() {
  57. final double h = 10.0;
  58. row.setHeight(h);
  59. assertEquals(h, row.getHeight(), 1e-16);
  60. }
  61. /** copied from {@link TestXSLFTable#testCreate()} */
  62. @Test
  63. public void getCells() {
  64. List<XSLFTableCell> cells = row.getCells();
  65. assertNotNull(cells);
  66. assertEquals(3, cells.size());
  67. }
  68. @Test
  69. public void testIterator() {
  70. int i = 0;
  71. for (XSLFTableCell cell : row) {
  72. i++;
  73. assertEquals("header"+i, cell.getText());
  74. }
  75. assertEquals(3, i);
  76. }
  77. /** copied from {@link TestXSLFTable#testCreate()} */
  78. @Test
  79. public void addCell() {
  80. XSLFTableCell cell = row.addCell();
  81. assertNotNull(cell);
  82. assertNotNull(cell.getXmlObject());
  83. // by default table cell has no borders
  84. CTTableCell tc = (CTTableCell)cell.getXmlObject();
  85. assertTrue(tc.getTcPr().getLnB().isSetNoFill());
  86. assertTrue(tc.getTcPr().getLnT().isSetNoFill());
  87. assertTrue(tc.getTcPr().getLnL().isSetNoFill());
  88. assertTrue(tc.getTcPr().getLnR().isSetNoFill());
  89. }
  90. @Test
  91. public void mergeCells() {
  92. try {
  93. row.mergeCells(0, 0);
  94. fail("expected IllegalArgumentException when merging fewer than 2 columns");
  95. } catch (final IllegalArgumentException e) {
  96. // expected
  97. }
  98. row.mergeCells(0, 1);
  99. List<XSLFTableCell> cells = row.getCells();
  100. //the top-left cell of a merged region is not regarded as merged
  101. assertFalse("top-left cell of merged region", cells.get(0).isMerged());
  102. assertTrue("inside merged region", cells.get(1).isMerged());
  103. assertFalse("outside merged region", cells.get(2).isMerged());
  104. }
  105. @Test
  106. public void getXmlObject() {
  107. CTTableRow ctrow = row.getXmlObject();
  108. assertNotNull(ctrow);
  109. }
  110. }