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.hslf.usermodel;
19:
20: import junit.framework.TestCase;
21: import org.apache.poi.hslf.*;
22: import org.apache.poi.hslf.model.*;
23:
24: /**
25: * Tests that SlideShow returns Sheets which have the right text in them
26: *
27: * @author Nick Burch (nick at torchbox dot com)
28: */
29: public class TestSheetText extends TestCase {
30: // SlideShow primed on the test data
31: private SlideShow ss;
32:
33: public TestSheetText() throws Exception {
34: String dirname = System.getProperty("HSLF.testdata.path");
35: String filename = dirname + "/basic_test_ppt_file.ppt";
36: HSLFSlideShow hss = new HSLFSlideShow(filename);
37: ss = new SlideShow(hss);
38: }
39:
40: public void testSheetOne() throws Exception {
41: Sheet slideOne = ss.getSlides()[0];
42:
43: String[] expectText = new String[] { "This is a test title",
44: "This is a test subtitle\nThis is on page 1" };
45: assertEquals(expectText.length, slideOne.getTextRuns().length);
46: for (int i = 0; i < expectText.length; i++) {
47: assertEquals(expectText[i], slideOne.getTextRuns()[i]
48: .getText());
49: }
50: }
51:
52: public void testSheetTwo() throws Exception {
53: Sheet slideTwo = ss.getSlides()[1];
54: String[] expectText = new String[] {
55: "This is the title on page 2",
56: "This is page two\nIt has several blocks of text\nNone of them have formatting" };
57: assertEquals(expectText.length, slideTwo.getTextRuns().length);
58: for (int i = 0; i < expectText.length; i++) {
59: assertEquals(expectText[i], slideTwo.getTextRuns()[i]
60: .getText());
61: }
62: }
63:
64: /**
65: * Check we can still get the text from a file where the
66: * TextProps don't have enough data.
67: * (Make sure we don't screw up / throw an exception etc)
68: */
69: public void testWithShortTextPropData() throws Exception {
70: String dirname = System.getProperty("HSLF.testdata.path");
71: String filename = dirname + "/iisd_report.ppt";
72: HSLFSlideShow hss = new HSLFSlideShow(filename);
73: SlideShow sss = new SlideShow(hss);
74:
75: // Should come out with 10 slides, no notes
76: assertEquals(10, sss.getSlides().length);
77: assertEquals(0, sss.getNotes().length);
78:
79: // Check text on first slide
80: Slide s = sss.getSlides()[0];
81: String exp = "Realizing the Development Dividend:\n"
82: + "Community Capacity Building and CDM.\n"
83: + "Can they co-exist?\n\n" + "Gay Harley\n"
84: + "Clean Development Alliance\n"
85: + "COP 11 \u2013 MOP 1\n" + // special long hyphon
86: "December 5, 2005\n";
87:
88: assertEquals(1, s.getTextRuns().length);
89: assertEquals(exp, s.getTextRuns()[0].getText());
90: }
91: }
|