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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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.xssf.usermodel;
  16. import java.io.IOException;
  17. import java.io.UnsupportedEncodingException;
  18. import java.util.Date;
  19. import junit.framework.TestCase;
  20. import org.apache.poi.hssf.HSSFTestDataSamples;
  21. import org.apache.poi.ss.usermodel.Cell;
  22. import org.apache.poi.ss.usermodel.DataFormatter;
  23. import org.apache.poi.ss.usermodel.Row;
  24. import org.apache.poi.ss.usermodel.Sheet;
  25. import org.apache.poi.ss.usermodel.Workbook;
  26. import org.apache.poi.xssf.SXSSFITestDataProvider;
  27. import org.apache.poi.xssf.XSSFTestDataSamples;
  28. import org.apache.poi.xssf.streaming.SXSSFWorkbook;
  29. /**
  30. * @author centic
  31. *
  32. * This testcase contains tests for bugs that are yet to be fixed. Therefore,
  33. * the standard ant test target does not run these tests. Run this testcase with
  34. * the single-test target. The names of the tests usually correspond to the
  35. * Bugzilla id's PLEASE MOVE tests from this class to TestBugs once the bugs are
  36. * fixed, so that they are then run automatically.
  37. */
  38. public final class TestUnfixedBugs extends TestCase {
  39. public void testBug54084Unicode() throws IOException {
  40. // sample XLSX with the same text-contents as the text-file above
  41. XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("54084 - Greek - beyond BMP.xlsx");
  42. verifyBug54084Unicode(wb);
  43. // OutputStream baos = new FileOutputStream("/tmp/test.xlsx");
  44. // try {
  45. // wb.write(baos);
  46. // } finally {
  47. // baos.close();
  48. // }
  49. // now write the file and read it back in
  50. XSSFWorkbook wbWritten = XSSFTestDataSamples.writeOutAndReadBack(wb);
  51. verifyBug54084Unicode(wbWritten);
  52. // finally also write it out via the streaming interface and verify that we still can read it back in
  53. Workbook wbStreamingWritten = SXSSFITestDataProvider.instance.writeOutAndReadBack(new SXSSFWorkbook(wb));
  54. verifyBug54084Unicode(wbStreamingWritten);
  55. }
  56. private void verifyBug54084Unicode(Workbook wb) throws UnsupportedEncodingException {
  57. // expected data is stored in UTF-8 in a text-file
  58. String testData = new String(HSSFTestDataSamples.getTestDataFileContent("54084 - Greek - beyond BMP.txt"), "UTF-8").trim();
  59. Sheet sheet = wb.getSheetAt(0);
  60. Row row = sheet.getRow(0);
  61. Cell cell = row.getCell(0);
  62. String value = cell.getStringCellValue();
  63. //System.out.println(value);
  64. assertEquals("The data in the text-file should exactly match the data that we read from the workbook", testData, value);
  65. }
  66. public void test54071() {
  67. Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("54071.xlsx");
  68. Sheet sheet = workbook.getSheetAt(0);
  69. int rows = sheet.getPhysicalNumberOfRows();
  70. System.out.println(">> file rows is:"+(rows-1)+" <<");
  71. Row title = sheet.getRow(0);
  72. Date prev = null;
  73. for (int row = 1; row < rows; row++) {
  74. Row rowObj = sheet.getRow(row);
  75. for (int col = 0; col < 1; col++) {
  76. String titleName = title.getCell(col).toString();
  77. Cell cell = rowObj.getCell(col);
  78. if (titleName.startsWith("time")) {
  79. // here the output will produce ...59 or ...58 for the rows, probably POI is
  80. // doing some different rounding or some other small difference...
  81. System.out.println("==Time:"+cell.getDateCellValue());
  82. if(prev != null) {
  83. assertEquals(prev, cell.getDateCellValue());
  84. }
  85. prev = cell.getDateCellValue();
  86. }
  87. }
  88. }
  89. }
  90. public void test57236() {
  91. // Having very small numbers leads to different formatting, Excel uses the scientific notation, but POI leads to "0"
  92. /*
  93. DecimalFormat format = new DecimalFormat("#.##########", new DecimalFormatSymbols(Locale.getDefault()));
  94. double d = 3.0E-104;
  95. assertEquals("3.0E-104", format.format(d));
  96. */
  97. DataFormatter formatter = new DataFormatter(true);
  98. XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("57236.xlsx");
  99. for(int sheetNum = 0;sheetNum < wb.getNumberOfSheets();sheetNum++) {
  100. Sheet sheet = wb.getSheetAt(sheetNum);
  101. for(int rowNum = sheet.getFirstRowNum();rowNum < sheet.getLastRowNum();rowNum++) {
  102. Row row = sheet.getRow(rowNum);
  103. for(int cellNum = row.getFirstCellNum();cellNum < row.getLastCellNum();cellNum++) {
  104. Cell cell = row.getCell(cellNum);
  105. String fmtCellValue = formatter.formatCellValue(cell);
  106. System.out.println("Cell: " + fmtCellValue);
  107. assertNotNull(fmtCellValue);
  108. assertFalse(fmtCellValue.equals("0"));
  109. }
  110. }
  111. }
  112. }
  113. }