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.

TestEscherDump.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.ddf;
  16. import static org.junit.Assert.assertTrue;
  17. import java.io.ByteArrayInputStream;
  18. import java.io.InputStream;
  19. import java.io.PrintStream;
  20. import java.io.UnsupportedEncodingException;
  21. import org.apache.poi.POIDataSamples;
  22. import org.apache.poi.hssf.HSSFTestDataSamples;
  23. import org.apache.poi.util.IOUtils;
  24. import org.apache.poi.util.LocaleUtil;
  25. import org.apache.poi.util.NullOutputStream;
  26. import org.junit.BeforeClass;
  27. import org.junit.Test;
  28. public class TestEscherDump {
  29. static NullPrinterStream nullPS;
  30. @BeforeClass
  31. public static void init() throws UnsupportedEncodingException {
  32. nullPS = new NullPrinterStream();
  33. }
  34. @Test
  35. public void testSimple() throws Exception {
  36. // simple test to at least cover some parts of the class
  37. EscherDump.main(new String[] {}, nullPS);
  38. new EscherDump().dump(0, new byte[] {}, nullPS);
  39. new EscherDump().dump(new byte[] {}, 0, 0, nullPS);
  40. new EscherDump().dumpOld(0, new ByteArrayInputStream(new byte[] {}), nullPS);
  41. }
  42. @Test
  43. public void testWithData() throws Exception {
  44. new EscherDump().dumpOld(8, new ByteArrayInputStream(new byte[] { 00, 00, 00, 00, 00, 00, 00, 00 }), nullPS);
  45. }
  46. @Test
  47. public void testWithSamplefile() throws Exception {
  48. //InputStream stream = HSSFTestDataSamples.openSampleFileStream(")
  49. byte[] data = POIDataSamples.getDDFInstance().readFile("Container.dat");
  50. new EscherDump().dump(data.length, data, nullPS);
  51. //new EscherDump().dumpOld(data.length, new ByteArrayInputStream(data), System.out);
  52. data = new byte[2586114];
  53. InputStream stream = HSSFTestDataSamples.openSampleFileStream("44593.xls");
  54. try {
  55. int bytes = IOUtils.readFully(stream, data);
  56. assertTrue(bytes != -1);
  57. //new EscherDump().dump(bytes, data, System.out);
  58. //new EscherDump().dumpOld(bytes, new ByteArrayInputStream(data), System.out);
  59. } finally {
  60. stream.close();
  61. }
  62. }
  63. /**
  64. * Implementation of an OutputStream which does nothing, used
  65. * to redirect stdout to avoid spamming the console with output
  66. */
  67. private static class NullPrinterStream extends PrintStream {
  68. @SuppressWarnings("resource")
  69. private NullPrinterStream() throws UnsupportedEncodingException {
  70. super(new NullOutputStream(),true,LocaleUtil.CHARSET_1252.name());
  71. }
  72. }
  73. }