xref: /trunk/test/testuno/source/fvt/uno/sd/animation/TextAnimation.java (revision 42a976b737d4e2b88cfbe2fe1cd610fe957bdc84)
1b832fe9eSHerbert Dürr /**************************************************************
2b832fe9eSHerbert Dürr  *
3b832fe9eSHerbert Dürr  * Licensed to the Apache Software Foundation (ASF) under one
4b832fe9eSHerbert Dürr  * or more contributor license agreements.  See the NOTICE file
5b832fe9eSHerbert Dürr  * distributed with this work for additional information
6b832fe9eSHerbert Dürr  * regarding copyright ownership.  The ASF licenses this file
7b832fe9eSHerbert Dürr  * to you under the Apache License, Version 2.0 (the
8b832fe9eSHerbert Dürr  * "License"); you may not use this file except in compliance
9b832fe9eSHerbert Dürr  * with the License.  You may obtain a copy of the License at
10b832fe9eSHerbert Dürr  *
11b832fe9eSHerbert Dürr  *   http://www.apache.org/licenses/LICENSE-2.0
12b832fe9eSHerbert Dürr  *
13b832fe9eSHerbert Dürr  * Unless required by applicable law or agreed to in writing,
14b832fe9eSHerbert Dürr  * software distributed under the License is distributed on an
15b832fe9eSHerbert Dürr  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b832fe9eSHerbert Dürr  * KIND, either express or implied.  See the License for the
17b832fe9eSHerbert Dürr  * specific language governing permissions and limitations
18b832fe9eSHerbert Dürr  * under the License.
19b832fe9eSHerbert Dürr  *
20b832fe9eSHerbert Dürr  *************************************************************/
2122a547feSLi Feng Wang package fvt.uno.sd.animation;
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.ShapeUtil;
3322a547feSLi Feng Wang 
3422a547feSLi Feng Wang import com.sun.star.awt.Point;
3522a547feSLi Feng Wang import com.sun.star.awt.Size;
3622a547feSLi Feng Wang import com.sun.star.beans.PropertyValue;
3722a547feSLi Feng Wang import com.sun.star.beans.XPropertySet;
3822a547feSLi Feng Wang import com.sun.star.container.XIndexContainer;
3922a547feSLi Feng Wang import com.sun.star.container.XNameContainer;
4022a547feSLi Feng Wang import com.sun.star.container.XNamed;
4122a547feSLi Feng Wang import com.sun.star.drawing.XDrawPage;
4222a547feSLi Feng Wang import com.sun.star.drawing.XDrawPages;
4322a547feSLi Feng Wang import com.sun.star.drawing.XDrawPagesSupplier;
4422a547feSLi Feng Wang import com.sun.star.drawing.XShape;
4522a547feSLi Feng Wang import com.sun.star.drawing.XShapes;
4622a547feSLi Feng Wang import com.sun.star.frame.XStorable;
4722a547feSLi Feng Wang import com.sun.star.lang.XComponent;
4822a547feSLi Feng Wang import com.sun.star.lang.XSingleServiceFactory;
4922a547feSLi Feng Wang import com.sun.star.presentation.AnimationEffect;
5022a547feSLi Feng Wang import com.sun.star.presentation.XCustomPresentationSupplier;
5122a547feSLi Feng Wang import com.sun.star.presentation.XPresentation;
5222a547feSLi Feng Wang import com.sun.star.presentation.XPresentationSupplier;
5322a547feSLi Feng Wang import com.sun.star.text.ControlCharacter;
5422a547feSLi Feng Wang import com.sun.star.text.XText;
5522a547feSLi Feng Wang import com.sun.star.text.XTextCursor;
5622a547feSLi Feng Wang import com.sun.star.text.XTextRange;
5722a547feSLi Feng Wang import com.sun.star.uno.UnoRuntime;
5822a547feSLi Feng Wang 
5922a547feSLi Feng Wang public class TextAnimation {
6022a547feSLi Feng Wang     XPresentationSupplier sdDocument = null;
6122a547feSLi Feng Wang     XPresentation pre = null;
6222a547feSLi Feng Wang     XComponent precomp = null;
6322a547feSLi Feng Wang     XComponent impressDocument = null;
6422a547feSLi Feng Wang     XComponent reLoadFile = null;
6522a547feSLi Feng Wang     XDrawPagesSupplier drawsupplier = null;
6622a547feSLi Feng Wang     XDrawPages drawpages = null;
6722a547feSLi Feng Wang 
6822a547feSLi Feng Wang     String filePath = null;
6922a547feSLi Feng Wang 
7022a547feSLi Feng Wang     UnoApp unoApp = new UnoApp();
7122a547feSLi Feng Wang 
7222a547feSLi Feng Wang     /**
7322a547feSLi Feng Wang      * @throws java.lang.Exception
7422a547feSLi Feng Wang      */
7522a547feSLi Feng Wang     @Before
setUp()7622a547feSLi Feng Wang     public void setUp() throws Exception {
7722a547feSLi Feng Wang         unoApp.start();
7822a547feSLi Feng Wang         createDocumentAndSlide();
7922a547feSLi Feng Wang     }
8022a547feSLi Feng Wang 
8122a547feSLi Feng Wang     @After
tearDown()8222a547feSLi Feng Wang     public void tearDown() throws Exception {
8322a547feSLi Feng Wang         unoApp.closeDocument(impressDocument);
8422a547feSLi Feng Wang         unoApp.closeDocument(reLoadFile);
8522a547feSLi Feng Wang         unoApp.close();
8622a547feSLi Feng Wang     }
8722a547feSLi Feng Wang 
8822a547feSLi Feng Wang     @Test
testTextAnimation()8922a547feSLi Feng Wang     public void testTextAnimation() throws Exception {
9022a547feSLi Feng Wang 
9122a547feSLi Feng Wang         XShapes xShapes;
9222a547feSLi Feng Wang         XPropertySet xShapePropSet;
9322a547feSLi Feng Wang         Point po = new Point(5000, 5000);
9422a547feSLi Feng Wang 
9522a547feSLi Feng Wang         // create pages, so that three are available
9622a547feSLi Feng Wang         drawpages.insertNewByIndex(0);
9722a547feSLi Feng Wang         // get the shape container for page one
9822a547feSLi Feng Wang         xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class,
9922a547feSLi Feng Wang                 drawpages.getByIndex(0));
10022a547feSLi Feng Wang         // create a rectangle that is placed on the top left of the page
10122a547feSLi Feng Wang         XShape xRectangle = ShapeUtil.createShape(impressDocument, po,
10222a547feSLi Feng Wang                 new Size(21000, 12500), "com.sun.star.drawing.RectangleShape");
10322a547feSLi Feng Wang         xShapes.add(xRectangle);
10422a547feSLi Feng Wang 
10522a547feSLi Feng Wang         XPropertySet xTextPropSet = addPortion(xRectangle, "Text Animation",
10622a547feSLi Feng Wang                 false);
10722a547feSLi Feng Wang 
10822a547feSLi Feng Wang         xTextPropSet.setPropertyValue("TextEffect",
10922a547feSLi Feng Wang                 AnimationEffect.MOVE_FROM_RIGHT);
11022a547feSLi Feng Wang 
11122a547feSLi Feng Wang         saveAndLoadSlide();
11222a547feSLi Feng Wang 
11322a547feSLi Feng Wang         // assert if Text Animation is set
11422a547feSLi Feng Wang         Assert.assertEquals("Text Animation Effect is MOVE_FROM_RIGHT",
11522a547feSLi Feng Wang                 AnimationEffect.MOVE_FROM_RIGHT,
11622a547feSLi Feng Wang                 xTextPropSet.getPropertyValue("TextEffect"));
11722a547feSLi Feng Wang 
11822a547feSLi Feng Wang     }
11922a547feSLi Feng Wang 
addPortion(XShape xShape, String sText, boolean bNewParagraph)12022a547feSLi Feng Wang     public XPropertySet addPortion(XShape xShape, String sText,
12122a547feSLi Feng Wang             boolean bNewParagraph)
12222a547feSLi Feng Wang             throws com.sun.star.lang.IllegalArgumentException {
12322a547feSLi Feng Wang         XText xText = (XText) UnoRuntime.queryInterface(XText.class, xShape);
12422a547feSLi Feng Wang 
12522a547feSLi Feng Wang         XTextCursor xTextCursor = xText.createTextCursor();
12622a547feSLi Feng Wang         xTextCursor.gotoEnd(false);
12722a547feSLi Feng Wang         if (bNewParagraph == true) {
12822a547feSLi Feng Wang             xText.insertControlCharacter(xTextCursor,
12922a547feSLi Feng Wang                     ControlCharacter.PARAGRAPH_BREAK, false);
13022a547feSLi Feng Wang             xTextCursor.gotoEnd(false);
13122a547feSLi Feng Wang         }
13222a547feSLi Feng Wang         XTextRange xTextRange = (XTextRange) UnoRuntime.queryInterface(
13322a547feSLi Feng Wang                 XTextRange.class, xTextCursor);
13422a547feSLi Feng Wang         xTextRange.setString(sText);
13522a547feSLi Feng Wang         xTextCursor.gotoEnd(true);
13622a547feSLi Feng Wang         XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
13722a547feSLi Feng Wang                 XPropertySet.class, xText);
13822a547feSLi Feng Wang         return xPropSet;
13922a547feSLi Feng Wang     }
14022a547feSLi Feng Wang 
14122a547feSLi Feng Wang     /**
14222a547feSLi Feng Wang      * create a new presentation document and insert a new slide.
14322a547feSLi Feng Wang      *
14422a547feSLi Feng Wang      * @throws Exception
14522a547feSLi Feng Wang      */
createDocumentAndSlide()14622a547feSLi Feng Wang     public void createDocumentAndSlide() throws Exception {
14722a547feSLi Feng Wang         impressDocument = (XComponent) UnoRuntime.queryInterface(
14822a547feSLi Feng Wang                 XComponent.class, unoApp.newDocument("simpress"));
14922a547feSLi Feng Wang         drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
15022a547feSLi Feng Wang                 XDrawPagesSupplier.class, impressDocument);
15122a547feSLi Feng Wang         drawpages = drawsupplier.getDrawPages();
15222a547feSLi Feng Wang 
15322a547feSLi Feng Wang         sdDocument = (XPresentationSupplier) UnoRuntime.queryInterface(
15422a547feSLi Feng Wang                 XPresentationSupplier.class, impressDocument);
15522a547feSLi Feng Wang         pre = sdDocument.getPresentation();
15622a547feSLi Feng Wang     }
15722a547feSLi Feng Wang 
15822a547feSLi Feng Wang     /**
15922a547feSLi Feng Wang      * Save presentation and reLoad the slide.
16022a547feSLi Feng Wang      *
16122a547feSLi Feng Wang      * @param no
16222a547feSLi Feng Wang      * @return void
16322a547feSLi Feng Wang      * @throws Exception
16422a547feSLi Feng Wang      */
saveAndLoadSlide()16522a547feSLi Feng Wang     public void saveAndLoadSlide() throws Exception {
16622a547feSLi Feng Wang         reLoadFile = saveAndReloadDoc(impressDocument,
16722a547feSLi Feng Wang                 "StarOffice XML (Impress)", "odp");
16822a547feSLi Feng Wang         drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
16922a547feSLi Feng Wang                 XDrawPagesSupplier.class, reLoadFile);
17022a547feSLi Feng Wang         drawpages = drawsupplier.getDrawPages();
17122a547feSLi Feng Wang 
17222a547feSLi Feng Wang         sdDocument = (XPresentationSupplier) UnoRuntime.queryInterface(
17322a547feSLi Feng Wang                 XPresentationSupplier.class, reLoadFile);
17422a547feSLi Feng Wang         pre = sdDocument.getPresentation();
17522a547feSLi Feng Wang     }
17622a547feSLi Feng Wang 
17722a547feSLi Feng Wang     /**
17822a547feSLi Feng Wang      * save and reload Presentation document.
17922a547feSLi Feng Wang      *
18022a547feSLi Feng Wang      * @param presentationDocument
18122a547feSLi Feng Wang      * @param sFilter
18222a547feSLi Feng Wang      * @param sExtension
18322a547feSLi Feng Wang      * @return
18422a547feSLi Feng Wang      * @throws Exception
18522a547feSLi Feng Wang      */
saveAndReloadDoc(XComponent presentationDocument, String sFilter, String sExtension)18622a547feSLi Feng Wang     private XComponent saveAndReloadDoc(XComponent presentationDocument,
18722a547feSLi Feng Wang             String sFilter, String sExtension) throws Exception {
18822a547feSLi Feng Wang         filePath = Testspace.getPath("tmp/customshow." + sExtension);
18922a547feSLi Feng Wang         PropertyValue[] aStoreProperties = new PropertyValue[2];
19022a547feSLi Feng Wang         aStoreProperties[0] = new PropertyValue();
19122a547feSLi Feng Wang         aStoreProperties[1] = new PropertyValue();
19222a547feSLi Feng Wang         aStoreProperties[0].Name = "Override";
19322a547feSLi Feng Wang         aStoreProperties[0].Value = true;
19422a547feSLi Feng Wang         aStoreProperties[1].Name = "FilterName";
19522a547feSLi Feng Wang         aStoreProperties[1].Value = sFilter;
19622a547feSLi Feng Wang         XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
19722a547feSLi Feng Wang                 XStorable.class, presentationDocument);
19822a547feSLi Feng Wang         xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties);
19922a547feSLi Feng Wang 
200*27723ce4SLinyi Li         return (XComponent)UnoRuntime.queryInterface(XComponent.class,
20122a547feSLi Feng Wang                 unoApp.loadDocument(filePath));
20222a547feSLi Feng Wang     }
20322a547feSLi Feng Wang }
204