01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
17: package org.apache.poi.hdgf;
18:
19: import java.io.FileInputStream;
20:
21: import org.apache.poi.hdgf.streams.PointerContainingStream;
22: import org.apache.poi.hdgf.streams.TrailerStream;
23: import org.apache.poi.poifs.filesystem.POIFSFileSystem;
24:
25: import junit.framework.TestCase;
26:
27: public class TestHDGFCore extends TestCase {
28: private POIFSFileSystem fs;
29: private String dirname;
30: private String filename;
31:
32: protected void setUp() throws Exception {
33: dirname = System.getProperty("HDGF.testdata.path");
34: filename = dirname + "/Test_Visio-Some_Random_Text.vsd";
35: fs = new POIFSFileSystem(new FileInputStream(filename));
36: }
37:
38: public void testCreate() throws Exception {
39: new HDGFDiagram(fs);
40: }
41:
42: public void testTrailer() throws Exception {
43: HDGFDiagram hdgf = new HDGFDiagram(fs);
44: assertNotNull(hdgf);
45: assertNotNull(hdgf.getTrailerStream());
46:
47: // Check it has what we'd expect
48: TrailerStream trailer = hdgf.getTrailerStream();
49: assertEquals(0x8a94, trailer.getPointer().getOffset());
50:
51: assertNotNull(trailer.getPointedToStreams());
52: assertEquals(20, trailer.getPointedToStreams().length);
53:
54: assertEquals(20, hdgf.getTopLevelStreams().length);
55:
56: // 9th one should have children
57: assertNotNull(trailer.getPointedToStreams()[8]);
58: assertNotNull(trailer.getPointedToStreams()[8].getPointer());
59: PointerContainingStream ps8 = (PointerContainingStream) trailer
60: .getPointedToStreams()[8];
61: assertNotNull(ps8.getPointedToStreams());
62: assertEquals(8, ps8.getPointedToStreams().length);
63: }
64:
65: /**
66: * Tests that we can open a problematic file, that initially
67: * appears to have a negative chunk length
68: */
69: public void DISABLEDtestNegativeChunkLength() throws Exception {
70: filename = dirname + "/NegativeChunkLength.vsd";
71: fs = new POIFSFileSystem(new FileInputStream(filename));
72:
73: HDGFDiagram hdgf = new HDGFDiagram(fs);
74: assertNotNull(hdgf);
75: }
76: }
|