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:
018: package org.apache.poi.hslf.usermodel;
019:
020: import junit.framework.TestCase;
021: import org.apache.poi.hslf.*;
022: import org.apache.poi.hslf.model.*;
023:
024: /**
025: * Tests that SlideShow returns Sheets in the right order
026: *
027: * @author Nick Burch (nick at torchbox dot com)
028: */
029: public class TestSlideOrdering extends TestCase {
030: // Simple slideshow, record order matches slide order
031: private SlideShow ssA;
032: // Complex slideshow, record order doesn't match slide order
033: private SlideShow ssB;
034:
035: public TestSlideOrdering() throws Exception {
036: String dirname = System.getProperty("HSLF.testdata.path");
037:
038: String filenameA = dirname + "/basic_test_ppt_file.ppt";
039: HSLFSlideShow hssA = new HSLFSlideShow(filenameA);
040: ssA = new SlideShow(hssA);
041:
042: String filenameB = dirname + "/incorrect_slide_order.ppt";
043: HSLFSlideShow hssB = new HSLFSlideShow(filenameB);
044: ssB = new SlideShow(hssB);
045: }
046:
047: /**
048: * Test the simple case - record order matches slide order
049: */
050: public void testSimpleCase() throws Exception {
051: assertEquals(2, ssA.getSlides().length);
052:
053: Slide s1 = ssA.getSlides()[0];
054: Slide s2 = ssA.getSlides()[1];
055:
056: String[] firstTRs = new String[] { "This is a test title",
057: "This is the title on page 2" };
058:
059: assertEquals(firstTRs[0], s1.getTextRuns()[0].getText());
060: assertEquals(firstTRs[1], s2.getTextRuns()[0].getText());
061: }
062:
063: /**
064: * Test the complex case - record order differs from slide order
065: */
066: public void testComplexCase() throws Exception {
067: assertEquals(3, ssB.getSlides().length);
068:
069: Slide s1 = ssB.getSlides()[0];
070: Slide s2 = ssB.getSlides()[1];
071: Slide s3 = ssB.getSlides()[2];
072:
073: String[] firstTRs = new String[] { "Slide 1", "Slide 2",
074: "Slide 3" };
075:
076: assertEquals(firstTRs[0], s1.getTextRuns()[0].getText());
077: assertEquals(firstTRs[1], s2.getTextRuns()[0].getText());
078: assertEquals(firstTRs[2], s3.getTextRuns()[0].getText());
079: }
080:
081: /**
082: * Assert that the order of slides is correct.
083: *
084: * @param filename file name of the slide show to assert
085: * @param titles array of reference slide titles
086: */
087: protected void assertSlideOrdering(String filename, String[] titles)
088: throws Exception {
089: SlideShow ppt = new SlideShow(new HSLFSlideShow(filename));
090: Slide[] slide = ppt.getSlides();
091:
092: assertEquals(titles.length, slide.length);
093: for (int i = 0; i < slide.length; i++) {
094: String title = slide[i].getTitle();
095: assertEquals("Wrong slide title in " + filename, titles[i],
096: title);
097: }
098: }
099:
100: public void testTitles() throws Exception {
101: String dirname = System.getProperty("HSLF.testdata.path");
102:
103: assertSlideOrdering(dirname + "/basic_test_ppt_file.ppt",
104: new String[] { "This is a test title",
105: "This is the title on page 2" });
106:
107: assertSlideOrdering(dirname + "/incorrect_slide_order.ppt",
108: new String[] { "Slide 1", "Slide 2", "Slide 3" });
109:
110: assertSlideOrdering(dirname + "/next_test_ppt_file.ppt",
111: new String[] { "This is a test title",
112: "This is the title on page 2" });
113:
114: assertSlideOrdering(dirname + "/Single_Coloured_Page.ppt",
115: new String[] { "This is a title, it" + (char) 0x2019
116: + "s in black" });
117:
118: assertSlideOrdering(
119: dirname
120: + "/Single_Coloured_Page_With_Fonts_and_Alignments.ppt",
121: new String[] { "This is a title, it" + (char) 0x2019
122: + "s in black" });
123:
124: assertSlideOrdering(
125: dirname + "/ParagraphStylesShorterThanCharStyles.ppt",
126: new String[] {
127: "ROMANCE: AN ANALYSIS",
128: "AGENDA",
129: "You are an important supplier of various items that I need",
130: (char) 0x0B
131: + "Although The Psycho set back my relationship process, recovery is luckily enough under way",
132: "Since the time that we seriously go out together, you rank highly among existing relationships",
133: "Although our personal interests are mostly compatible, the greatest gap exists in Sex and Shopping",
134: "Your physical characteristics are strong when compared with your competition",
135: "The combination of your high physical appearance and personality rank you highly, although your sister is also a top prospect",
136: "When people found out that we were going out, their responses have been mixed",
137: "The benchmark of relationship lifecycles, suggests that we are on schedule",
138: "In summary we can say that we are on the right track, but we must remain aware of possible roadblocks ",
139: "THE ANSWER",
140: "Unfortunately a huge disconnect exists between my needs and your existing service",
141: "SUMMARY", });
142: }
143: }
|