PageRenderTime 74ms CodeModel.GetById 22ms RepoModel.GetById 4ms app.codeStats 1ms

/ppt/scratchpad/testcases/org/apache/poi/hdgf/streams/TestStreamBugs.java

https://github.com/minstrelsy/POI-Android
Java | 102 lines | 63 code | 16 blank | 23 comment | 5 complexity | 3eb320077de8a4bc1854a83f8ac115d8 MD5 | raw file
  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.hdgf.streams;
  16. import java.io.InputStream;
  17. import org.apache.poi.hdgf.HDGFDiagram;
  18. import org.apache.poi.hdgf.chunks.ChunkFactory;
  19. import org.apache.poi.hdgf.pointers.Pointer;
  20. import org.apache.poi.hdgf.pointers.PointerFactory;
  21. import org.apache.poi.poifs.filesystem.DocumentEntry;
  22. import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  23. import org.apache.poi.POIDataSamples;
  24. /**
  25. * Tests for bugs with streams
  26. */
  27. public final class TestStreamBugs extends StreamTest {
  28. private byte[] contents;
  29. private ChunkFactory chunkFactory;
  30. private PointerFactory ptrFactory;
  31. private POIFSFileSystem filesystem;
  32. protected void setUp() throws Exception {
  33. ptrFactory = new PointerFactory(11);
  34. chunkFactory = new ChunkFactory(11);
  35. InputStream is = POIDataSamples.getDiagramInstance().openResourceAsStream("44594.vsd");
  36. filesystem = new POIFSFileSystem(is);
  37. DocumentEntry docProps =
  38. (DocumentEntry)filesystem.getRoot().getEntry("VisioDocument");
  39. // Grab the document stream
  40. contents = new byte[docProps.getSize()];
  41. filesystem.createDocumentInputStream("VisioDocument").read(contents);
  42. }
  43. public void testGetTrailer() {
  44. Pointer trailerPointer = ptrFactory.createPointer(contents, 0x24);
  45. Stream.createStream(trailerPointer, contents, chunkFactory, ptrFactory);
  46. }
  47. public void TOIMPLEMENTtestGetCertainChunks() {
  48. int offsetA = 3708;
  49. int offsetB = 3744;
  50. }
  51. public void testGetChildren() {
  52. Pointer trailerPointer = ptrFactory.createPointer(contents, 0x24);
  53. TrailerStream trailer = (TrailerStream)
  54. Stream.createStream(trailerPointer, contents, chunkFactory, ptrFactory);
  55. // Get without recursing
  56. Pointer[] ptrs = trailer.getChildPointers();
  57. for(int i=0; i<ptrs.length; i++) {
  58. Stream.createStream(ptrs[i], contents, chunkFactory, ptrFactory);
  59. }
  60. // Get with recursing into chunks
  61. for(int i=0; i<ptrs.length; i++) {
  62. Stream stream =
  63. Stream.createStream(ptrs[i], contents, chunkFactory, ptrFactory);
  64. if(stream instanceof ChunkStream) {
  65. ChunkStream cStream = (ChunkStream)stream;
  66. cStream.findChunks();
  67. }
  68. }
  69. // Get with recursing into chunks and pointers
  70. for(int i=0; i<ptrs.length; i++) {
  71. Stream stream =
  72. Stream.createStream(ptrs[i], contents, chunkFactory, ptrFactory);
  73. if(stream instanceof PointerContainingStream) {
  74. PointerContainingStream pStream =
  75. (PointerContainingStream)stream;
  76. pStream.findChildren(contents);
  77. }
  78. }
  79. trailer.findChildren(contents);
  80. }
  81. public void testOpen() throws Exception {
  82. HDGFDiagram dg = new HDGFDiagram(filesystem);
  83. }
  84. }