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.

TestUnfixedBugs.java 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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.hssf.usermodel;
  16. import static org.junit.Assert.assertEquals;
  17. import java.io.IOException;
  18. import junit.framework.AssertionFailedError;
  19. import junit.framework.TestCase;
  20. import org.apache.poi.hssf.HSSFTestDataSamples;
  21. import org.apache.poi.hssf.record.RecordFormatException;
  22. import org.apache.poi.hssf.util.HSSFColor;
  23. import org.apache.poi.ss.usermodel.Cell;
  24. import org.apache.poi.ss.usermodel.Row;
  25. import org.apache.poi.ss.usermodel.Sheet;
  26. import org.apache.poi.ss.usermodel.Workbook;
  27. import org.junit.Test;
  28. /**
  29. * @author aviks
  30. *
  31. * This testcase contains tests for bugs that are yet to be fixed. Therefore,
  32. * the standard ant test target does not run these tests. Run this testcase with
  33. * the single-test target. The names of the tests usually correspond to the
  34. * Bugzilla id's PLEASE MOVE tests from this class to TestBugs once the bugs are
  35. * fixed, so that they are then run automatically.
  36. */
  37. public final class TestUnfixedBugs extends TestCase {
  38. public void test43493() {
  39. // Has crazy corrupt sub-records on
  40. // a EmbeddedObjectRefSubRecord
  41. try {
  42. HSSFTestDataSamples.openSampleWorkbook("43493.xls");
  43. } catch (RecordFormatException e) {
  44. if (e.getCause().getCause() instanceof ArrayIndexOutOfBoundsException) {
  45. throw new AssertionFailedError("Identified bug 43493");
  46. }
  47. throw e;
  48. }
  49. }
  50. /**
  51. * Note - some parts of this bug have been fixed, and have been
  52. * transfered over to {@link TestBugs#bug49612_part()}
  53. */
  54. public void test49612() throws IOException {
  55. HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("49612.xls");
  56. HSSFSheet sh = wb.getSheetAt(0);
  57. HSSFRow row = sh.getRow(0);
  58. HSSFCell c1 = row.getCell(2);
  59. HSSFCell d1 = row.getCell(3);
  60. HSSFCell e1 = row.getCell(2);
  61. assertEquals("SUM(BOB+JIM)", c1.getCellFormula());
  62. // Problem 1: Filename missing, see bug #56742
  63. assertEquals("SUM('49612.xls'!BOB+'49612.xls'!JIM)", d1.getCellFormula());
  64. //Problem 2: Filename missing, see bug #56742
  65. //junit.framework.ComparisonFailure:
  66. //Expected :SUM('49612.xls'!BOB+'49612.xls'!JIM)
  67. //Actual :SUM(BOB+JIM)
  68. assertEquals("SUM('49612.xls'!BOB+'49612.xls'!JIM)", e1.getCellFormula());
  69. // Problem 3 - fixed and transfered
  70. }
  71. public void testFormulaRecordAggregate_1() throws Exception {
  72. // fails at formula "=MEHRFACH.OPERATIONEN(E$3;$B$5;$D4)"
  73. Workbook wb = HSSFTestDataSamples.openSampleWorkbook("44958_1.xls");
  74. for(int i = 0;i < wb.getNumberOfSheets();i++) {
  75. Sheet sheet = wb.getSheetAt(i);
  76. assertNotNull(wb.getSheet(sheet.getSheetName()));
  77. sheet.groupColumn((short) 4, (short) 5);
  78. sheet.setColumnGroupCollapsed(4, true);
  79. sheet.setColumnGroupCollapsed(4, false);
  80. for(Row row : sheet) {
  81. for(Cell cell : row) {
  82. try {
  83. cell.toString();
  84. } catch (Exception e) {
  85. throw new Exception("While handling: " + sheet.getSheetName() + "/" + row.getRowNum() + "/" + cell.getColumnIndex(), e);
  86. }
  87. }
  88. }
  89. }
  90. }
  91. public void testFormulaRecordAggregate() throws Exception {
  92. // fails at formula "=MEHRFACH.OPERATIONEN(E$3;$B$5;$D4)"
  93. Workbook wb = HSSFTestDataSamples.openSampleWorkbook("44958.xls");
  94. for(int i = 0;i < wb.getNumberOfSheets();i++) {
  95. Sheet sheet = wb.getSheetAt(i);
  96. assertNotNull(wb.getSheet(sheet.getSheetName()));
  97. sheet.groupColumn((short) 4, (short) 5);
  98. sheet.setColumnGroupCollapsed(4, true);
  99. sheet.setColumnGroupCollapsed(4, false);
  100. for(Row row : sheet) {
  101. for(Cell cell : row) {
  102. try {
  103. cell.toString();
  104. } catch (Exception e) {
  105. throw new Exception("While handling: " + sheet.getSheetName() + "/" + row.getRowNum() + "/" + cell.getColumnIndex(), e);
  106. }
  107. }
  108. }
  109. }
  110. }
  111. @Test
  112. public void testBug57074() {
  113. Workbook wb = HSSFTestDataSamples.openSampleWorkbook("57074.xls");
  114. Sheet sheet = wb.getSheet("Sheet1");
  115. Row row = sheet.getRow(0);
  116. Cell cell = row.getCell(0);
  117. HSSFColor bgColor = (HSSFColor) cell.getCellStyle().getFillBackgroundColorColor();
  118. String bgColorStr = bgColor.getTriplet()[0]+", "+bgColor.getTriplet()[1]+", "+bgColor.getTriplet()[2];
  119. //System.out.println(bgColorStr);
  120. assertEquals("215, 228, 188", bgColorStr);
  121. HSSFColor fontColor = (HSSFColor) cell.getCellStyle().getFillForegroundColorColor();
  122. String fontColorStr = fontColor.getTriplet()[0]+", "+fontColor.getTriplet()[1]+", "+fontColor.getTriplet()[2];
  123. //System.out.println(fontColorStr);
  124. assertEquals("0, 128, 128", fontColorStr);
  125. }
  126. }