2007-06-18 18:44:56 -04:00
|
|
|
/* ====================================================================
|
|
|
|
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.
|
|
|
|
==================================================================== */
|
2009-05-21 14:12:22 -04:00
|
|
|
|
2007-06-18 18:44:56 -04:00
|
|
|
package org.apache.poi.hdgf;
|
|
|
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
|
|
|
import org.apache.poi.hdgf.streams.PointerContainingStream;
|
|
|
|
import org.apache.poi.hdgf.streams.TrailerStream;
|
|
|
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
2009-08-23 08:34:24 -04:00
|
|
|
import org.apache.poi.POIDataSamples;
|
2007-06-18 18:44:56 -04:00
|
|
|
|
|
|
|
import junit.framework.TestCase;
|
|
|
|
|
2009-05-21 14:12:22 -04:00
|
|
|
public final class TestHDGFCore extends TestCase {
|
2009-08-23 08:34:24 -04:00
|
|
|
private static POIDataSamples _dgTests = POIDataSamples.getDiagramInstance();
|
|
|
|
|
2007-10-28 16:56:34 -04:00
|
|
|
private POIFSFileSystem fs;
|
2009-05-21 14:12:22 -04:00
|
|
|
|
2007-06-18 18:44:56 -04:00
|
|
|
protected void setUp() throws Exception {
|
2009-08-23 08:34:24 -04:00
|
|
|
fs = new POIFSFileSystem(_dgTests.openResourceAsStream("Test_Visio-Some_Random_Text.vsd"));
|
2007-06-18 18:44:56 -04:00
|
|
|
}
|
2009-05-21 14:12:22 -04:00
|
|
|
|
2007-06-18 18:44:56 -04:00
|
|
|
public void testCreate() throws Exception {
|
|
|
|
new HDGFDiagram(fs);
|
|
|
|
}
|
2009-05-21 14:12:22 -04:00
|
|
|
|
2007-06-18 18:44:56 -04:00
|
|
|
public void testTrailer() throws Exception {
|
|
|
|
HDGFDiagram hdgf = new HDGFDiagram(fs);
|
|
|
|
assertNotNull(hdgf);
|
|
|
|
assertNotNull(hdgf.getTrailerStream());
|
2009-05-21 14:12:22 -04:00
|
|
|
|
2007-06-18 18:44:56 -04:00
|
|
|
// Check it has what we'd expect
|
|
|
|
TrailerStream trailer = hdgf.getTrailerStream();
|
|
|
|
assertEquals(0x8a94, trailer.getPointer().getOffset());
|
2009-05-21 14:12:22 -04:00
|
|
|
|
2007-06-18 18:44:56 -04:00
|
|
|
assertNotNull(trailer.getPointedToStreams());
|
|
|
|
assertEquals(20, trailer.getPointedToStreams().length);
|
2009-05-21 14:12:22 -04:00
|
|
|
|
2007-06-18 18:44:56 -04:00
|
|
|
assertEquals(20, hdgf.getTopLevelStreams().length);
|
2009-05-21 14:12:22 -04:00
|
|
|
|
2007-06-18 18:44:56 -04:00
|
|
|
// 9th one should have children
|
|
|
|
assertNotNull(trailer.getPointedToStreams()[8]);
|
|
|
|
assertNotNull(trailer.getPointedToStreams()[8].getPointer());
|
|
|
|
PointerContainingStream ps8 = (PointerContainingStream)
|
|
|
|
trailer.getPointedToStreams()[8];
|
|
|
|
assertNotNull(ps8.getPointedToStreams());
|
|
|
|
assertEquals(8, ps8.getPointedToStreams().length);
|
|
|
|
}
|
2009-05-21 14:12:22 -04:00
|
|
|
|
2007-10-28 16:56:34 -04:00
|
|
|
/**
|
2010-01-28 07:05:13 -05:00
|
|
|
* Tests that we can open a problematic file, that used to
|
|
|
|
* break with a negative chunk length
|
2007-10-28 16:56:34 -04:00
|
|
|
*/
|
2010-01-28 07:05:13 -05:00
|
|
|
public void testNegativeChunkLength() throws Exception {
|
2009-08-23 08:34:24 -04:00
|
|
|
fs = new POIFSFileSystem(_dgTests.openResourceAsStream("NegativeChunkLength.vsd"));
|
2009-05-21 14:12:22 -04:00
|
|
|
|
2007-10-28 16:56:34 -04:00
|
|
|
HDGFDiagram hdgf = new HDGFDiagram(fs);
|
|
|
|
assertNotNull(hdgf);
|
2010-01-28 07:05:13 -05:00
|
|
|
|
|
|
|
// And another file
|
|
|
|
fs = new POIFSFileSystem(_dgTests.openResourceAsStream("NegativeChunkLength2.vsd"));
|
|
|
|
hdgf = new HDGFDiagram(fs);
|
|
|
|
assertNotNull(hdgf);
|
2007-10-28 16:56:34 -04:00
|
|
|
}
|
2007-06-18 18:44:56 -04:00
|
|
|
}
|