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:
18: package org.apache.poi.hssf.usermodel;
19:
20: import java.io.File;
21: import java.io.FileInputStream;
22: import java.util.List;
23:
24: import junit.framework.TestCase;
25:
26: public class TestOLE2Embeding extends TestCase {
27: public void testEmbeding() throws Exception {
28: String dirname = System.getProperty("HSSF.testdata.path");
29: String filename = dirname + "/ole2-embedding.xls";
30:
31: File file = new File(filename);
32: FileInputStream in = new FileInputStream(file);
33: HSSFWorkbook workbook;
34:
35: // This used to break, until bug #43116 was fixed
36: workbook = new HSSFWorkbook(in);
37:
38: in.close();
39:
40: // Check we can get at the Escher layer still
41: workbook.getAllPictures();
42: }
43:
44: public void testEmbeddedObjects() throws Exception {
45: String dirname = System.getProperty("HSSF.testdata.path");
46: String filename = dirname + "/ole2-embedding.xls";
47:
48: File file = new File(filename);
49: HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(
50: file));
51: List objects = workbook.getAllEmbeddedObjects();
52: assertEquals("Wrong number of objects", 2, objects.size());
53: assertEquals("Wrong name for first object", "MBD06CAB431",
54: ((HSSFObjectData) objects.get(0)).getDirectory()
55: .getName());
56: assertEquals("Wrong name for second object", "MBD06CAC85A",
57: ((HSSFObjectData) objects.get(1)).getDirectory()
58: .getName());
59: }
60:
61: }
|