aboutsummaryrefslogtreecommitdiffstats
path: root/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java
blob: 9c8f3e18cfe4ff474d47f8c141dc0d14c624544e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* ====================================================================
   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.
==================================================================== */

package org.apache.poi.hslf.usermodel;

import static org.junit.Assert.assertEquals;

import java.util.List;

import org.apache.poi.POIDataSamples;
import org.junit.Before;
import org.junit.Test;

/**
 * Tests that SlideShow returns Sheets which have the right text in them
 *
 * @author Nick Burch (nick at torchbox dot com)
 */
public final class TestSheetText {
	// SlideShow primed on the test data
	private HSLFSlideShow ss;

	@Before
	public void init() throws Exception {
        POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
		HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
		ss = new HSLFSlideShow(hss);
	}

	@Test
	public void testSheetOne() {
		HSLFSheet slideOne = ss.getSlides().get(0);

		String[] expectText = new String[] {"This is a test title","This is a test subtitle\rThis is on page 1"};
		assertEquals(expectText.length, slideOne.getTextParagraphs().size());
		int i = 0;
		for(List<HSLFTextParagraph> textParas : slideOne.getTextParagraphs()) {
			assertEquals(expectText[i++], HSLFTextParagraph.getRawText(textParas));
		}
	}

	public void testSheetTwo() {
		HSLFSheet slideTwo = ss.getSlides().get(1);
		String[] expectText = new String[] {"This is the title on page 2","This is page two\rIt has several blocks of text\rNone of them have formatting"};
		assertEquals(expectText.length, slideTwo.getTextParagraphs().size());
        int i = 0;
        for(List<HSLFTextParagraph> textParas : slideTwo.getTextParagraphs()) {
            assertEquals(expectText[i++], HSLFTextParagraph.getRawText(textParas));
        }
	}

	/**
	 * Check we can still get the text from a file where the
	 *  TextProps don't have enough data.
	 * (Make sure we don't screw up / throw an exception etc)
	 */
	public void testWithShortTextPropData() throws Exception {
        POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
		HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("iisd_report.ppt"));
		HSLFSlideShow sss = new HSLFSlideShow(hss);

		// Should come out with 10 slides, no notes
		assertEquals(10, sss.getSlides().size());
		assertEquals(0, sss.getNotes().size());

		// Check text on first slide
		HSLFSlide s = sss.getSlides().get(0);
		String exp =
			"Realizing the Development Dividend:\n" +
			"Community Capacity Building and CDM.\n" +
			"Can they co-exist?\n\n" +
			"Gay Harley\n" +
			"Clean Development Alliance\n" +
			"COP 11 \u2013 MOP 1\n" + // special long hyphen
			"December 5, 2005\n";

		assertEquals(1, s.getTextParagraphs().size());
		assertEquals(exp, HSLFTextParagraph.getRawText(s.getTextParagraphs().get(0)));
	}
}