001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017: package org.apache.poi.hslf.model;
018:
019: import junit.framework.TestCase;
020:
021: import java.io.FileInputStream;
022: import java.io.File;
023:
024: import org.apache.poi.hslf.HSLFSlideShow;
025: import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException;
026: import org.apache.poi.hslf.record.ColorSchemeAtom;
027: import org.apache.poi.hslf.record.PPDrawing;
028: import org.apache.poi.hslf.usermodel.SlideShow;
029:
030: /**
031: * Test common functionality of the <code>Sheet</code> object.
032: * For each ppt in the test directory check that all sheets are properly initialized
033: *
034: * @author Yegor Kozlov
035: */
036: public class TestSheet extends TestCase {
037:
038: /**
039: * For each ppt in the test directory check that all sheets are properly initialized
040: */
041: public void testSheet() throws Exception {
042: File home = new File(System.getProperty("HSLF.testdata.path"));
043: File[] files = home.listFiles();
044: for (int i = 0; i < files.length; i++) {
045: if (!files[i].getName().endsWith(".ppt"))
046: continue;
047: try {
048: FileInputStream is = new FileInputStream(files[i]);
049: HSLFSlideShow hslf = new HSLFSlideShow(is);
050: is.close();
051:
052: SlideShow ppt = new SlideShow(hslf);
053: doSlideShow(ppt);
054: } catch (EncryptedPowerPointFileException e) {
055: ; //skip encrypted ppt
056: }
057: }
058: }
059:
060: private void doSlideShow(SlideShow ppt) throws Exception {
061: Slide[] slide = ppt.getSlides();
062: for (int i = 0; i < slide.length; i++) {
063: verify(slide[i]);
064:
065: Notes notes = slide[i].getNotesSheet();
066: if (notes != null)
067: verify(notes);
068:
069: MasterSheet master = slide[i].getMasterSheet();
070: assertNotNull(master);
071: verify(master);
072: }
073: }
074:
075: private void verify(Sheet sheet) {
076: assertNotNull(sheet.getSlideShow());
077:
078: ColorSchemeAtom colorscheme = sheet.getColorScheme();
079: assertNotNull(colorscheme);
080:
081: PPDrawing ppdrawing = sheet.getPPDrawing();
082: assertNotNull(ppdrawing);
083:
084: Background background = sheet.getBackground();
085: assertNotNull(background);
086:
087: assertTrue(sheet._getSheetNumber() != 0);
088: assertTrue(sheet._getSheetRefId() != 0);
089:
090: TextRun[] txt = sheet.getTextRuns();
091: assertTrue(txt != null);
092: for (int i = 0; i < txt.length; i++) {
093: assertNotNull(txt[i].getSheet());
094: }
095:
096: Shape[] shape = sheet.getShapes();
097: assertTrue(shape != null);
098: for (int i = 0; i < shape.length; i++) {
099: assertNotNull(shape[i].getSpContainer());
100: assertNotNull(shape[i].getSheet());
101: assertNotNull(shape[i].getShapeName());
102: assertNotNull(shape[i].getAnchor());
103: }
104:
105: }
106: }
|