aboutsummaryrefslogtreecommitdiffstats
path: root/src/scratchpad/testcases/org/apache/poi/hdgf/streams/TestStreamBugs.java
blob: 66c3907082cf75786524a97acca0f79a9bfb3568 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* ====================================================================
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
==================================================================== */

package org.apache.poi.hdgf.streams;

import java.io.FileInputStream;

import org.apache.poi.hdgf.HDGFDiagram;
import org.apache.poi.hdgf.chunks.ChunkFactory;
import org.apache.poi.hdgf.pointers.Pointer;
import org.apache.poi.hdgf.pointers.PointerFactory;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

/**
 * Tests for bugs with streams
 */
public final class TestStreamBugs extends StreamTest {
	private byte[] contents;
	private ChunkFactory chunkFactory;
	private PointerFactory ptrFactory;
	private POIFSFileSystem filesystem;

	protected void setUp() throws Exception {
		String dirname = System.getProperty("HDGF.testdata.path");
		String filename = dirname + "/44594.vsd";
		ptrFactory = new PointerFactory(11);
		chunkFactory = new ChunkFactory(11);

		FileInputStream fin = new FileInputStream(filename);
		filesystem = new POIFSFileSystem(fin);

		DocumentEntry docProps =
			(DocumentEntry)filesystem.getRoot().getEntry("VisioDocument");

		// Grab the document stream
		contents = new byte[docProps.getSize()];
		filesystem.createDocumentInputStream("VisioDocument").read(contents);
	}

	public void testGetTrailer() {
		Pointer trailerPointer = ptrFactory.createPointer(contents, 0x24);
		Stream.createStream(trailerPointer, contents, chunkFactory, ptrFactory);
	}

	public void TOIMPLEMENTtestGetCertainChunks() {
		int offsetA = 3708;
		int offsetB = 3744;
	}

	public void testGetChildren() {
		Pointer trailerPointer = ptrFactory.createPointer(contents, 0x24);
		TrailerStream trailer = (TrailerStream)
			Stream.createStream(trailerPointer, contents, chunkFactory, ptrFactory);

		// Get without recursing
		Pointer[] ptrs = trailer.getChildPointers();
		for(int i=0; i<ptrs.length; i++) {
			Stream.createStream(ptrs[i], contents, chunkFactory, ptrFactory);
		}

		// Get with recursing into chunks
		for(int i=0; i<ptrs.length; i++) {
			Stream stream =
				Stream.createStream(ptrs[i], contents, chunkFactory, ptrFactory);
			if(stream instanceof ChunkStream) {
				ChunkStream cStream = (ChunkStream)stream;
				cStream.findChunks();
			}
		}

		// Get with recursing into chunks and pointers
		for(int i=0; i<ptrs.length; i++) {
			Stream stream =
				Stream.createStream(ptrs[i], contents, chunkFactory, ptrFactory);
			if(stream instanceof PointerContainingStream) {
				PointerContainingStream pStream =
					(PointerContainingStream)stream;
				pStream.findChildren(contents);
			}
		}

		trailer.findChildren(contents);
	}

	public void testOpen() throws Exception {
		HDGFDiagram dg = new HDGFDiagram(filesystem);
	}
}