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 testlib.uno.PageUtil;
3322a547feSLi Feng Wang import testlib.uno.ShapeUtil;
3422a547feSLi Feng Wang 
3522a547feSLi Feng Wang import com.sun.star.awt.Point;
3622a547feSLi Feng Wang import com.sun.star.awt.Size;
3722a547feSLi Feng Wang import com.sun.star.beans.PropertyValue;
3822a547feSLi Feng Wang import com.sun.star.beans.XPropertySet;
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.presentation.XPresentation;
4722a547feSLi Feng Wang import com.sun.star.presentation.XPresentationSupplier;
4822a547feSLi Feng Wang import com.sun.star.uno.UnoRuntime;
4922a547feSLi Feng Wang 
5022a547feSLi Feng Wang public class SlideShow {
5122a547feSLi Feng Wang 	XPresentationSupplier sdDocument = null;
5222a547feSLi Feng Wang 	XPresentation pre = null;
5322a547feSLi Feng Wang 	XComponent precomp = null;
5422a547feSLi Feng Wang 	XComponent impressDocument = null;
5522a547feSLi Feng Wang 	XComponent reLoadFile = null;
5622a547feSLi Feng Wang 	XDrawPagesSupplier drawsupplier = null;
5722a547feSLi Feng Wang 	XDrawPages drawpages = null;
5822a547feSLi Feng Wang 
5922a547feSLi Feng Wang 	String filePath = null;
6022a547feSLi Feng Wang 
6122a547feSLi Feng Wang 	UnoApp unoApp = new UnoApp();
6222a547feSLi Feng Wang 
6322a547feSLi Feng Wang 	/**
6422a547feSLi Feng Wang 	 * @throws java.lang.Exception
6522a547feSLi Feng Wang 	 */
6622a547feSLi Feng Wang 	@Before
setUp()6722a547feSLi Feng Wang 	public void setUp() throws Exception {
6822a547feSLi Feng Wang 		unoApp.start();
6922a547feSLi Feng Wang 		createDocumentAndSlide();
7022a547feSLi Feng Wang 	}
7122a547feSLi Feng Wang 
7222a547feSLi Feng Wang 	@After
tearDown()7322a547feSLi Feng Wang 	public void tearDown() throws Exception {
7422a547feSLi Feng Wang 		unoApp.closeDocument(impressDocument);
7522a547feSLi Feng Wang 		unoApp.closeDocument(reLoadFile);
7622a547feSLi Feng Wang 		unoApp.close();
7722a547feSLi Feng Wang 	}
7822a547feSLi Feng Wang 
7922a547feSLi Feng Wang 	@Test
testSlideShow()8022a547feSLi Feng Wang 	public void testSlideShow() throws Exception {
8122a547feSLi Feng Wang 		Point po = new Point(5000, 5000);
8222a547feSLi Feng Wang 
8322a547feSLi Feng Wang 		XDrawPage xPage1 = createSlide(0);
8422a547feSLi Feng Wang 		XShapes xShapes1 = (XShapes) UnoRuntime.queryInterface(XShapes.class,
8522a547feSLi Feng Wang 				xPage1);
8622a547feSLi Feng Wang 		XShape xRectangle1 = ShapeUtil.createShape(impressDocument, po,
8722a547feSLi Feng Wang 				new Size(21000, 12500), "com.sun.star.drawing.RectangleShape");
8822a547feSLi Feng Wang 		xShapes1.add(xRectangle1);
8922a547feSLi Feng Wang 		ShapeUtil.addPortion(xRectangle1, "Page1", false);
9022a547feSLi Feng Wang 
9122a547feSLi Feng Wang 		XDrawPage xPage2 = createSlide(1);
9222a547feSLi Feng Wang 		XShapes xShapes2 = (XShapes) UnoRuntime.queryInterface(XShapes.class,
9322a547feSLi Feng Wang 				xPage2);
9422a547feSLi Feng Wang 		XShape xRectangle2 = ShapeUtil.createShape(impressDocument, po,
9522a547feSLi Feng Wang 				new Size(21000, 12500), "com.sun.star.drawing.RectangleShape");
9622a547feSLi Feng Wang 		xShapes2.add(xRectangle2);
9722a547feSLi Feng Wang 		ShapeUtil.addPortion(xRectangle2, "Page2", false);
9822a547feSLi Feng Wang 
9922a547feSLi Feng Wang 		XDrawPage xPage3 = createSlide(2);
10022a547feSLi Feng Wang 		XShapes xShapes3 = (XShapes) UnoRuntime.queryInterface(XShapes.class,
10122a547feSLi Feng Wang 				xPage3);
10222a547feSLi Feng Wang 		XShape xRectangle3 = ShapeUtil.createShape(impressDocument, po,
10322a547feSLi Feng Wang 				new Size(21000, 12500), "com.sun.star.drawing.RectangleShape");
10422a547feSLi Feng Wang 		xShapes3.add(xRectangle3);
10522a547feSLi Feng Wang 		ShapeUtil.addPortion(xRectangle3, "Page3", false);
10622a547feSLi Feng Wang 
10722a547feSLi Feng Wang 		XPropertySet xPresPropSet = (XPropertySet) UnoRuntime.queryInterface(
10822a547feSLi Feng Wang 				XPropertySet.class, pre);
10922a547feSLi Feng Wang 		xPresPropSet.setPropertyValue("IsEndless", Boolean.FALSE);
11022a547feSLi Feng Wang 		xPresPropSet.setPropertyValue("IsFullScreen", Boolean.TRUE);
11122a547feSLi Feng Wang 		xPresPropSet.setPropertyValue("Pause", new Integer(0));
11222a547feSLi Feng Wang 
11322a547feSLi Feng Wang 		saveAndLoadSlide();
11422a547feSLi Feng Wang 
11522a547feSLi Feng Wang 		Assert.assertEquals("IsEndless set to false",
11622a547feSLi Feng Wang 				xPresPropSet.getPropertyValue("IsEndless"), Boolean.FALSE);
11722a547feSLi Feng Wang 		Assert.assertEquals("IsFullScreen set to true",
11822a547feSLi Feng Wang 				xPresPropSet.getPropertyValue("IsFullScreen"), Boolean.TRUE);
11922a547feSLi Feng Wang 		Assert.assertEquals("Pause set to 0",
12022a547feSLi Feng Wang 				xPresPropSet.getPropertyValue("Pause"), 0);
12122a547feSLi Feng Wang 	}
12222a547feSLi Feng Wang 
createSlide(int index)12322a547feSLi Feng Wang 	public XDrawPage createSlide(int index) throws Exception {
12422a547feSLi Feng Wang 		drawpages.insertNewByIndex(index);
12522a547feSLi Feng Wang 		XDrawPage xPage = PageUtil.getDrawPageByIndex(impressDocument, index);
12622a547feSLi Feng Wang 		return xPage;
12722a547feSLi Feng Wang 	}
12822a547feSLi Feng Wang 
12922a547feSLi Feng Wang 	/**
13022a547feSLi Feng Wang 	 * create a new presentation document and insert a new slide.
13122a547feSLi Feng Wang 	 *
13222a547feSLi Feng Wang 	 * @throws Exception
13322a547feSLi Feng Wang 	 */
createDocumentAndSlide()13422a547feSLi Feng Wang 	public void createDocumentAndSlide() throws Exception {
13522a547feSLi Feng Wang 		impressDocument = (XComponent) UnoRuntime.queryInterface(
13622a547feSLi Feng Wang 				XComponent.class, unoApp.newDocument("simpress"));
13722a547feSLi Feng Wang 		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
13822a547feSLi Feng Wang 				XDrawPagesSupplier.class, impressDocument);
13922a547feSLi Feng Wang 		drawpages = drawsupplier.getDrawPages();
14022a547feSLi Feng Wang 		sdDocument = (XPresentationSupplier) UnoRuntime.queryInterface(
14122a547feSLi Feng Wang 				XPresentationSupplier.class, impressDocument);
14222a547feSLi Feng Wang 		pre = sdDocument.getPresentation();
14322a547feSLi Feng Wang 	}
14422a547feSLi Feng Wang 
14522a547feSLi Feng Wang 	/**
14622a547feSLi Feng Wang 	 * Save presentation and reLoad the slide.
14722a547feSLi Feng Wang 	 *
14822a547feSLi Feng Wang 	 * @param no
14922a547feSLi Feng Wang 	 * @return void
15022a547feSLi Feng Wang 	 * @throws Exception
15122a547feSLi Feng Wang 	 */
saveAndLoadSlide()15222a547feSLi Feng Wang 	public void saveAndLoadSlide() throws Exception {
15322a547feSLi Feng Wang 		reLoadFile = saveAndReloadDoc(impressDocument,
15422a547feSLi Feng Wang 				"StarOffice XML (Impress)", "odp");
15522a547feSLi Feng Wang 		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
15622a547feSLi Feng Wang 				XDrawPagesSupplier.class, reLoadFile);
15722a547feSLi Feng Wang 		drawpages = drawsupplier.getDrawPages();
15822a547feSLi Feng Wang 
15922a547feSLi Feng Wang 		sdDocument = (XPresentationSupplier) UnoRuntime.queryInterface(
16022a547feSLi Feng Wang 				XPresentationSupplier.class, reLoadFile);
16122a547feSLi Feng Wang 		pre = sdDocument.getPresentation();
16222a547feSLi Feng Wang 	}
16322a547feSLi Feng Wang 
16422a547feSLi Feng Wang 	/**
16522a547feSLi Feng Wang 	 * save and reload Presentation document.
16622a547feSLi Feng Wang 	 *
16722a547feSLi Feng Wang 	 * @param presentationDocument
16822a547feSLi Feng Wang 	 * @param sFilter
16922a547feSLi Feng Wang 	 * @param sExtension
17022a547feSLi Feng Wang 	 * @return
17122a547feSLi Feng Wang 	 * @throws Exception
17222a547feSLi Feng Wang 	 */
saveAndReloadDoc(XComponent presentationDocument, String sFilter, String sExtension)17322a547feSLi Feng Wang 	private XComponent saveAndReloadDoc(XComponent presentationDocument,
17422a547feSLi Feng Wang 			String sFilter, String sExtension) throws Exception {
17522a547feSLi Feng Wang 		filePath = Testspace.getPath("tmp/slideshow." + sExtension);
17622a547feSLi Feng Wang 		PropertyValue[] aStoreProperties = new PropertyValue[2];
17722a547feSLi Feng Wang 		aStoreProperties[0] = new PropertyValue();
17822a547feSLi Feng Wang 		aStoreProperties[1] = new PropertyValue();
17922a547feSLi Feng Wang 		aStoreProperties[0].Name = "Override";
18022a547feSLi Feng Wang 		aStoreProperties[0].Value = true;
18122a547feSLi Feng Wang 		aStoreProperties[1].Name = "FilterName";
18222a547feSLi Feng Wang 		aStoreProperties[1].Value = sFilter;
18322a547feSLi Feng Wang 		XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
18422a547feSLi Feng Wang 				XStorable.class, presentationDocument);
18522a547feSLi Feng Wang 		xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties);
18622a547feSLi Feng Wang 
18722a547feSLi Feng Wang 		return (XComponent) UnoRuntime.queryInterface(XComponent.class,
18822a547feSLi Feng Wang 				unoApp.loadDocument(filePath));
18922a547feSLi Feng Wang 	}
19022a547feSLi Feng Wang }
191