1*b832fe9eSHerbert Dürr /************************************************************** 2*b832fe9eSHerbert Dürr * 3*b832fe9eSHerbert Dürr * Licensed to the Apache Software Foundation (ASF) under one 4*b832fe9eSHerbert Dürr * or more contributor license agreements. See the NOTICE file 5*b832fe9eSHerbert Dürr * distributed with this work for additional information 6*b832fe9eSHerbert Dürr * regarding copyright ownership. The ASF licenses this file 7*b832fe9eSHerbert Dürr * to you under the Apache License, Version 2.0 (the 8*b832fe9eSHerbert Dürr * "License"); you may not use this file except in compliance 9*b832fe9eSHerbert Dürr * with the License. You may obtain a copy of the License at 10*b832fe9eSHerbert Dürr * 11*b832fe9eSHerbert Dürr * http://www.apache.org/licenses/LICENSE-2.0 12*b832fe9eSHerbert Dürr * 13*b832fe9eSHerbert Dürr * Unless required by applicable law or agreed to in writing, 14*b832fe9eSHerbert Dürr * software distributed under the License is distributed on an 15*b832fe9eSHerbert Dürr * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b832fe9eSHerbert Dürr * KIND, either express or implied. See the License for the 17*b832fe9eSHerbert Dürr * specific language governing permissions and limitations 18*b832fe9eSHerbert Dürr * under the License. 19*b832fe9eSHerbert Dürr * 20*b832fe9eSHerbert Dürr *************************************************************/ 2122a547feSLi Feng Wang package fvt.uno.sd.slideshow; 2222a547feSLi Feng Wang 2322a547feSLi Feng Wang import junit.framework.Assert; 2422a547feSLi Feng Wang 2522a547feSLi Feng Wang import org.junit.After; 2622a547feSLi Feng Wang import org.junit.Before; 2722a547feSLi Feng Wang import org.junit.Test; 2822a547feSLi Feng Wang import org.openoffice.test.common.FileUtil; 2922a547feSLi Feng Wang import org.openoffice.test.common.Testspace; 3022a547feSLi Feng Wang import org.openoffice.test.uno.UnoApp; 3122a547feSLi Feng Wang 3222a547feSLi Feng Wang import com.sun.star.awt.Point; 3322a547feSLi Feng Wang import com.sun.star.awt.Size; 3422a547feSLi Feng Wang import com.sun.star.beans.PropertyValue; 3522a547feSLi Feng Wang import com.sun.star.beans.XPropertySet; 3622a547feSLi Feng Wang import com.sun.star.container.XIndexContainer; 3722a547feSLi Feng Wang import com.sun.star.container.XNameContainer; 3822a547feSLi Feng Wang import com.sun.star.container.XNamed; 3922a547feSLi Feng Wang import com.sun.star.drawing.XDrawPage; 4022a547feSLi Feng Wang import com.sun.star.drawing.XDrawPages; 4122a547feSLi Feng Wang import com.sun.star.drawing.XDrawPagesSupplier; 4222a547feSLi Feng Wang import com.sun.star.drawing.XShape; 4322a547feSLi Feng Wang import com.sun.star.drawing.XShapes; 4422a547feSLi Feng Wang import com.sun.star.frame.XStorable; 4522a547feSLi Feng Wang import com.sun.star.lang.XComponent; 4622a547feSLi Feng Wang import com.sun.star.lang.XSingleServiceFactory; 4722a547feSLi Feng Wang import com.sun.star.presentation.XCustomPresentationSupplier; 4822a547feSLi Feng Wang import com.sun.star.presentation.XPresentation; 4922a547feSLi Feng Wang import com.sun.star.presentation.XPresentationSupplier; 5022a547feSLi Feng Wang import com.sun.star.uno.UnoRuntime; 5122a547feSLi Feng Wang 5222a547feSLi Feng Wang import testlib.uno.ShapeUtil; 5322a547feSLi Feng Wang 5422a547feSLi Feng Wang public class CustomShow { 5522a547feSLi Feng Wang XPresentationSupplier sdDocument = null; 5622a547feSLi Feng Wang XPresentation pre = null; 5722a547feSLi Feng Wang XComponent precomp = null; 5822a547feSLi Feng Wang XComponent impressDocument = null; 5922a547feSLi Feng Wang XComponent reLoadFile = null; 6022a547feSLi Feng Wang XDrawPagesSupplier drawsupplier = null; 6122a547feSLi Feng Wang XDrawPages drawpages = null; 6222a547feSLi Feng Wang 6322a547feSLi Feng Wang String filePath = null; 6422a547feSLi Feng Wang 6522a547feSLi Feng Wang UnoApp unoApp = new UnoApp(); 6622a547feSLi Feng Wang 6722a547feSLi Feng Wang /** 6822a547feSLi Feng Wang * @throws java.lang.Exception 6922a547feSLi Feng Wang */ 7022a547feSLi Feng Wang @Before setUp()7122a547feSLi Feng Wang public void setUp() throws Exception { 7222a547feSLi Feng Wang unoApp.start(); 7322a547feSLi Feng Wang createDocumentAndSlide(); 7422a547feSLi Feng Wang } 7522a547feSLi Feng Wang 7622a547feSLi Feng Wang @After tearDown()7722a547feSLi Feng Wang public void tearDown() throws Exception { 7822a547feSLi Feng Wang unoApp.closeDocument(impressDocument); 7922a547feSLi Feng Wang unoApp.closeDocument(reLoadFile); 8022a547feSLi Feng Wang unoApp.close(); 8122a547feSLi Feng Wang } 8222a547feSLi Feng Wang 8322a547feSLi Feng Wang @Test testCustomShow()8422a547feSLi Feng Wang public void testCustomShow() throws Exception { 8522a547feSLi Feng Wang 8622a547feSLi Feng Wang String aNameArray[] = { "Page 1", "Page 2", "Page 3", "Page 4", "Page 5"}; 8722a547feSLi Feng Wang 8822a547feSLi Feng Wang //insert five pages 8922a547feSLi Feng Wang while (drawpages.getCount() < aNameArray.length) 9022a547feSLi Feng Wang drawpages.insertNewByIndex(0); 9122a547feSLi Feng Wang 9222a547feSLi Feng Wang //add text shape to each page 9322a547feSLi Feng Wang for (int i = 0; i < aNameArray.length; i++) { 9422a547feSLi Feng Wang XDrawPage xDrawPage = (XDrawPage) UnoRuntime.queryInterface( 9522a547feSLi Feng Wang XDrawPage.class, drawpages.getByIndex(i)); 9622a547feSLi Feng Wang XNamed xPageName = (XNamed) UnoRuntime.queryInterface(XNamed.class, 9722a547feSLi Feng Wang xDrawPage); 9822a547feSLi Feng Wang xPageName.setName(aNameArray[i]); 9922a547feSLi Feng Wang 10022a547feSLi Feng Wang XShape xTextObj = ShapeUtil.createShape(impressDocument, new Point( 10122a547feSLi Feng Wang 10000, 9000), new Size(10000, 5000), 10222a547feSLi Feng Wang "com.sun.star.drawing.TextShape"); 10322a547feSLi Feng Wang XShapes xShapes = (XShapes) UnoRuntime.queryInterface( 10422a547feSLi Feng Wang XShapes.class, xDrawPage); 10522a547feSLi Feng Wang xShapes.add(xTextObj); 10622a547feSLi Feng Wang ShapeUtil.addPortion(xTextObj, aNameArray[i], true); 10722a547feSLi Feng Wang } 10822a547feSLi Feng Wang 10922a547feSLi Feng Wang 11022a547feSLi Feng Wang //create two custom shows 11122a547feSLi Feng Wang //one will play slide 3 to 5 and is named "Part" 11222a547feSLi Feng Wang //the other one will play slide 1 t0 5 and is named "All" 11322a547feSLi Feng Wang XCustomPresentationSupplier xCustPresSupplier = (XCustomPresentationSupplier) UnoRuntime 11422a547feSLi Feng Wang .queryInterface(XCustomPresentationSupplier.class, impressDocument); 11522a547feSLi Feng Wang 11622a547feSLi Feng Wang 11722a547feSLi Feng Wang // the following container is a container for further container which 11822a547feSLi Feng Wang // includes the list of pages that are to play within a custom show 11922a547feSLi Feng Wang XNameContainer xNameContainer = xCustPresSupplier 12022a547feSLi Feng Wang .getCustomPresentations(); 12122a547feSLi Feng Wang XSingleServiceFactory xFactory = (XSingleServiceFactory) UnoRuntime 12222a547feSLi Feng Wang .queryInterface(XSingleServiceFactory.class, xNameContainer); 12322a547feSLi Feng Wang 12422a547feSLi Feng Wang Object xObj; 12522a547feSLi Feng Wang XIndexContainer xContainer; 12622a547feSLi Feng Wang 12722a547feSLi Feng Wang //instantiate an IndexContainer that will take a list of draw pages for 12822a547feSLi Feng Wang //the first custom show 12922a547feSLi Feng Wang xObj = xFactory.createInstance(); 13022a547feSLi Feng Wang xContainer = (XIndexContainer) UnoRuntime.queryInterface( 13122a547feSLi Feng Wang XIndexContainer.class, xObj); 13222a547feSLi Feng Wang for (int i = 3; i < 5; i++) 13322a547feSLi Feng Wang xContainer.insertByIndex(xContainer.getCount(), 13422a547feSLi Feng Wang drawpages.getByIndex(i)); 13522a547feSLi Feng Wang xNameContainer.insertByName("Part", xContainer); 13622a547feSLi Feng Wang 13722a547feSLi Feng Wang 13822a547feSLi Feng Wang //instantiate an IndexContainer that will take a list of draw page for 13922a547feSLi Feng Wang //the second custom show 14022a547feSLi Feng Wang xObj = xFactory.createInstance(); 14122a547feSLi Feng Wang xContainer = (XIndexContainer) UnoRuntime.queryInterface( 14222a547feSLi Feng Wang XIndexContainer.class, xObj); 14322a547feSLi Feng Wang for (int i = 1; i < 5; i++) 14422a547feSLi Feng Wang xContainer.insertByIndex(xContainer.getCount(), 14522a547feSLi Feng Wang drawpages.getByIndex(i)); 14622a547feSLi Feng Wang xNameContainer.insertByName("All", xContainer); 14722a547feSLi Feng Wang 14822a547feSLi Feng Wang 14922a547feSLi Feng Wang //set which custom show is to used 15022a547feSLi Feng Wang XPresentationSupplier xPresSupplier = (XPresentationSupplier) UnoRuntime 15122a547feSLi Feng Wang .queryInterface(XPresentationSupplier.class, impressDocument); 15222a547feSLi Feng Wang XPresentation xPresentation = xPresSupplier.getPresentation(); 15322a547feSLi Feng Wang XPropertySet xPresPropSet = (XPropertySet) UnoRuntime.queryInterface( 15422a547feSLi Feng Wang XPropertySet.class, xPresentation); 15522a547feSLi Feng Wang xPresPropSet.setPropertyValue("CustomShow", "Part"); 15622a547feSLi Feng Wang 15722a547feSLi Feng Wang saveAndLoadSlide(); 15822a547feSLi Feng Wang 15922a547feSLi Feng Wang //assert if custom show is set 16022a547feSLi Feng Wang Assert.assertEquals("Set Part as CustomSHow", xPresPropSet.getPropertyValue("CustomShow"), "Part"); 16122a547feSLi Feng Wang } 16222a547feSLi Feng Wang 16322a547feSLi Feng Wang /** 16422a547feSLi Feng Wang * create a new presentation document and insert a new slide. 16522a547feSLi Feng Wang * 16622a547feSLi Feng Wang * @throws Exception 16722a547feSLi Feng Wang */ createDocumentAndSlide()16822a547feSLi Feng Wang public void createDocumentAndSlide() throws Exception { 16922a547feSLi Feng Wang impressDocument = (XComponent) UnoRuntime.queryInterface( 17022a547feSLi Feng Wang XComponent.class, unoApp.newDocument("simpress")); 17122a547feSLi Feng Wang drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface( 17222a547feSLi Feng Wang XDrawPagesSupplier.class, impressDocument); 17322a547feSLi Feng Wang drawpages = drawsupplier.getDrawPages(); 17422a547feSLi Feng Wang 17522a547feSLi Feng Wang sdDocument = (XPresentationSupplier) UnoRuntime.queryInterface( 17622a547feSLi Feng Wang XPresentationSupplier.class, impressDocument); 17722a547feSLi Feng Wang pre = sdDocument.getPresentation(); 17822a547feSLi Feng Wang } 17922a547feSLi Feng Wang 18022a547feSLi Feng Wang /** 18122a547feSLi Feng Wang * Save presentation and reLoad the slide. 18222a547feSLi Feng Wang * 18322a547feSLi Feng Wang * @param no 18422a547feSLi Feng Wang * @return void 18522a547feSLi Feng Wang * @throws Exception 18622a547feSLi Feng Wang */ saveAndLoadSlide()18722a547feSLi Feng Wang public void saveAndLoadSlide() throws Exception { 18822a547feSLi Feng Wang reLoadFile = saveAndReloadDoc(impressDocument, 18922a547feSLi Feng Wang "StarOffice XML (Impress)", "odp"); 19022a547feSLi Feng Wang drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface( 19122a547feSLi Feng Wang XDrawPagesSupplier.class, reLoadFile); 19222a547feSLi Feng Wang drawpages = drawsupplier.getDrawPages(); 19322a547feSLi Feng Wang 19422a547feSLi Feng Wang sdDocument = (XPresentationSupplier) UnoRuntime.queryInterface( 19522a547feSLi Feng Wang XPresentationSupplier.class, reLoadFile); 19622a547feSLi Feng Wang pre = sdDocument.getPresentation(); 19722a547feSLi Feng Wang } 19822a547feSLi Feng Wang 19922a547feSLi Feng Wang /** 20022a547feSLi Feng Wang * save and reload Presentation document. 20122a547feSLi Feng Wang * 20222a547feSLi Feng Wang * @param presentationDocument 20322a547feSLi Feng Wang * @param sFilter 20422a547feSLi Feng Wang * @param sExtension 20522a547feSLi Feng Wang * @return 20622a547feSLi Feng Wang * @throws Exception 20722a547feSLi Feng Wang */ saveAndReloadDoc(XComponent presentationDocument, String sFilter, String sExtension)20822a547feSLi Feng Wang private XComponent saveAndReloadDoc(XComponent presentationDocument, 20922a547feSLi Feng Wang String sFilter, String sExtension) throws Exception { 21022a547feSLi Feng Wang filePath = Testspace.getPath("tmp/customshow." + sExtension); 21122a547feSLi Feng Wang PropertyValue[] aStoreProperties = new PropertyValue[2]; 21222a547feSLi Feng Wang aStoreProperties[0] = new PropertyValue(); 21322a547feSLi Feng Wang aStoreProperties[1] = new PropertyValue(); 21422a547feSLi Feng Wang aStoreProperties[0].Name = "Override"; 21522a547feSLi Feng Wang aStoreProperties[0].Value = true; 21622a547feSLi Feng Wang aStoreProperties[1].Name = "FilterName"; 21722a547feSLi Feng Wang aStoreProperties[1].Value = sFilter; 21822a547feSLi Feng Wang XStorable xStorable = (XStorable) UnoRuntime.queryInterface( 21922a547feSLi Feng Wang XStorable.class, presentationDocument); 22022a547feSLi Feng Wang xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties); 22122a547feSLi Feng Wang 22222a547feSLi Feng Wang return (XComponent) UnoRuntime.queryInterface(XComponent.class, 22322a547feSLi Feng Wang unoApp.loadDocument(filePath)); 22422a547feSLi Feng Wang } 22522a547feSLi Feng Wang } 226