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.

TestBiffViewer.java 4.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.dev;
  16. import java.io.File;
  17. import java.io.IOException;
  18. import java.io.InputStream;
  19. import java.io.OutputStreamWriter;
  20. import java.io.PrintWriter;
  21. import org.apache.poi.EncryptedDocumentException;
  22. import org.apache.poi.POIDataSamples;
  23. import org.apache.poi.hssf.OldExcelFormatException;
  24. import org.apache.poi.hssf.record.RecordInputStream;
  25. import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
  26. import org.apache.poi.util.LocaleUtil;
  27. import org.apache.poi.util.RecordFormatException;
  28. import org.junit.BeforeClass;
  29. import org.junit.Ignore;
  30. import org.junit.Test;
  31. public class TestBiffViewer extends BaseXLSIteratingTest {
  32. @BeforeClass
  33. public static void setup() {
  34. EXCLUDED.clear();
  35. EXCLUDED.put("35897-type4.xls", EncryptedDocumentException.class); // unsupported crypto api header
  36. EXCLUDED.put("51832.xls", EncryptedDocumentException.class);
  37. EXCLUDED.put("xor-encryption-abc.xls", EncryptedDocumentException.class);
  38. EXCLUDED.put("password.xls", EncryptedDocumentException.class);
  39. EXCLUDED.put("46904.xls", OldExcelFormatException.class);
  40. EXCLUDED.put("59074.xls", OldExcelFormatException.class);
  41. EXCLUDED.put("testEXCEL_2.xls", OldExcelFormatException.class); // Biff 2 / Excel 2, pre-OLE2
  42. EXCLUDED.put("testEXCEL_3.xls", OldExcelFormatException.class); // Biff 3 / Excel 3, pre-OLE2
  43. EXCLUDED.put("testEXCEL_4.xls", OldExcelFormatException.class); // Biff 4 / Excel 4, pre-OLE2
  44. EXCLUDED.put("testEXCEL_5.xls", OldExcelFormatException.class); // Biff 5 / Excel 5
  45. EXCLUDED.put("60284.xls", OldExcelFormatException.class); // Biff 5 / Excel 5
  46. EXCLUDED.put("testEXCEL_95.xls", OldExcelFormatException.class); // Biff 5 / Excel 95
  47. EXCLUDED.put("60284.xls", OldExcelFormatException.class); // Biff 5 / Excel 95
  48. EXCLUDED.put("43493.xls", RecordInputStream.LeftoverDataException.class); // HSSFWorkbook cannot open it as well
  49. // EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
  50. EXCLUDED.put("50833.xls", IllegalArgumentException.class); // "Name is too long" when setting username
  51. EXCLUDED.put("XRefCalc.xls", RuntimeException.class); // "Buffer overrun"
  52. EXCLUDED.put("61300.xls", RecordFormatException.class);
  53. }
  54. @Override
  55. void runOneFile(File fileIn) throws IOException {
  56. NPOIFSFileSystem fs = new NPOIFSFileSystem(fileIn, true);
  57. try {
  58. InputStream is = BiffViewer.getPOIFSInputStream(fs);
  59. try {
  60. // use a NullOutputStream to not write the bytes anywhere for best runtime
  61. PrintWriter dummy = new PrintWriter(new OutputStreamWriter(NULL_OUTPUT_STREAM, LocaleUtil.CHARSET_1252));
  62. BiffViewer.runBiffViewer(dummy, is, true, true, true, false);
  63. } finally {
  64. is.close();
  65. }
  66. } finally {
  67. fs.close();
  68. }
  69. }
  70. @Test
  71. @Ignore("only used for manual tests")
  72. public void testOneFile() throws Exception {
  73. POIDataSamples samples = POIDataSamples.getSpreadSheetInstance();
  74. runOneFile(samples.getFile("43493.xls"));
  75. }
  76. }