1*22a547feSLi Feng Wang package fvt.uno.sd.slideshow; 2*22a547feSLi Feng Wang 3*22a547feSLi Feng Wang import junit.framework.Assert; 4*22a547feSLi Feng Wang 5*22a547feSLi Feng Wang import org.junit.After; 6*22a547feSLi Feng Wang import org.junit.Before; 7*22a547feSLi Feng Wang import org.junit.Test; 8*22a547feSLi Feng Wang import org.openoffice.test.common.FileUtil; 9*22a547feSLi Feng Wang import org.openoffice.test.common.Testspace; 10*22a547feSLi Feng Wang import org.openoffice.test.uno.UnoApp; 11*22a547feSLi Feng Wang 12*22a547feSLi Feng Wang import testlib.uno.PageUtil; 13*22a547feSLi Feng Wang import testlib.uno.ShapeUtil; 14*22a547feSLi Feng Wang 15*22a547feSLi Feng Wang import com.sun.star.awt.Point; 16*22a547feSLi Feng Wang import com.sun.star.awt.Size; 17*22a547feSLi Feng Wang import com.sun.star.beans.PropertyValue; 18*22a547feSLi Feng Wang import com.sun.star.beans.XPropertySet; 19*22a547feSLi Feng Wang import com.sun.star.drawing.XDrawPage; 20*22a547feSLi Feng Wang import com.sun.star.drawing.XDrawPages; 21*22a547feSLi Feng Wang import com.sun.star.drawing.XDrawPagesSupplier; 22*22a547feSLi Feng Wang import com.sun.star.drawing.XShape; 23*22a547feSLi Feng Wang import com.sun.star.drawing.XShapes; 24*22a547feSLi Feng Wang import com.sun.star.frame.XStorable; 25*22a547feSLi Feng Wang import com.sun.star.lang.XComponent; 26*22a547feSLi Feng Wang import com.sun.star.presentation.XPresentation; 27*22a547feSLi Feng Wang import com.sun.star.presentation.XPresentationSupplier; 28*22a547feSLi Feng Wang import com.sun.star.uno.UnoRuntime; 29*22a547feSLi Feng Wang 30*22a547feSLi Feng Wang public class SlideShow { 31*22a547feSLi Feng Wang XPresentationSupplier sdDocument = null; 32*22a547feSLi Feng Wang XPresentation pre = null; 33*22a547feSLi Feng Wang XComponent precomp = null; 34*22a547feSLi Feng Wang XComponent impressDocument = null; 35*22a547feSLi Feng Wang XComponent reLoadFile = null; 36*22a547feSLi Feng Wang XDrawPagesSupplier drawsupplier = null; 37*22a547feSLi Feng Wang XDrawPages drawpages = null; 38*22a547feSLi Feng Wang 39*22a547feSLi Feng Wang String filePath = null; 40*22a547feSLi Feng Wang 41*22a547feSLi Feng Wang UnoApp unoApp = new UnoApp(); 42*22a547feSLi Feng Wang 43*22a547feSLi Feng Wang /** 44*22a547feSLi Feng Wang * @throws java.lang.Exception 45*22a547feSLi Feng Wang */ 46*22a547feSLi Feng Wang @Before 47*22a547feSLi Feng Wang public void setUp() throws Exception { 48*22a547feSLi Feng Wang unoApp.start(); 49*22a547feSLi Feng Wang createDocumentAndSlide(); 50*22a547feSLi Feng Wang } 51*22a547feSLi Feng Wang 52*22a547feSLi Feng Wang @After 53*22a547feSLi Feng Wang public void tearDown() throws Exception { 54*22a547feSLi Feng Wang unoApp.closeDocument(impressDocument); 55*22a547feSLi Feng Wang unoApp.closeDocument(reLoadFile); 56*22a547feSLi Feng Wang unoApp.close(); 57*22a547feSLi Feng Wang } 58*22a547feSLi Feng Wang 59*22a547feSLi Feng Wang @Test 60*22a547feSLi Feng Wang public void testSlideShow() throws Exception { 61*22a547feSLi Feng Wang Point po = new Point(5000, 5000); 62*22a547feSLi Feng Wang 63*22a547feSLi Feng Wang XDrawPage xPage1 = createSlide(0); 64*22a547feSLi Feng Wang XShapes xShapes1 = (XShapes) UnoRuntime.queryInterface(XShapes.class, 65*22a547feSLi Feng Wang xPage1); 66*22a547feSLi Feng Wang XShape xRectangle1 = ShapeUtil.createShape(impressDocument, po, 67*22a547feSLi Feng Wang new Size(21000, 12500), "com.sun.star.drawing.RectangleShape"); 68*22a547feSLi Feng Wang xShapes1.add(xRectangle1); 69*22a547feSLi Feng Wang ShapeUtil.addPortion(xRectangle1, "Page1", false); 70*22a547feSLi Feng Wang 71*22a547feSLi Feng Wang XDrawPage xPage2 = createSlide(1); 72*22a547feSLi Feng Wang XShapes xShapes2 = (XShapes) UnoRuntime.queryInterface(XShapes.class, 73*22a547feSLi Feng Wang xPage2); 74*22a547feSLi Feng Wang XShape xRectangle2 = ShapeUtil.createShape(impressDocument, po, 75*22a547feSLi Feng Wang new Size(21000, 12500), "com.sun.star.drawing.RectangleShape"); 76*22a547feSLi Feng Wang xShapes2.add(xRectangle2); 77*22a547feSLi Feng Wang ShapeUtil.addPortion(xRectangle2, "Page2", false); 78*22a547feSLi Feng Wang 79*22a547feSLi Feng Wang XDrawPage xPage3 = createSlide(2); 80*22a547feSLi Feng Wang XShapes xShapes3 = (XShapes) UnoRuntime.queryInterface(XShapes.class, 81*22a547feSLi Feng Wang xPage3); 82*22a547feSLi Feng Wang XShape xRectangle3 = ShapeUtil.createShape(impressDocument, po, 83*22a547feSLi Feng Wang new Size(21000, 12500), "com.sun.star.drawing.RectangleShape"); 84*22a547feSLi Feng Wang xShapes3.add(xRectangle3); 85*22a547feSLi Feng Wang ShapeUtil.addPortion(xRectangle3, "Page3", false); 86*22a547feSLi Feng Wang 87*22a547feSLi Feng Wang XPropertySet xPresPropSet = (XPropertySet) UnoRuntime.queryInterface( 88*22a547feSLi Feng Wang XPropertySet.class, pre); 89*22a547feSLi Feng Wang xPresPropSet.setPropertyValue("IsEndless", Boolean.FALSE); 90*22a547feSLi Feng Wang xPresPropSet.setPropertyValue("IsFullScreen", Boolean.TRUE); 91*22a547feSLi Feng Wang xPresPropSet.setPropertyValue("Pause", new Integer(0)); 92*22a547feSLi Feng Wang 93*22a547feSLi Feng Wang saveAndLoadSlide(); 94*22a547feSLi Feng Wang 95*22a547feSLi Feng Wang Assert.assertEquals("IsEndless set to false", 96*22a547feSLi Feng Wang xPresPropSet.getPropertyValue("IsEndless"), Boolean.FALSE); 97*22a547feSLi Feng Wang Assert.assertEquals("IsFullScreen set to true", 98*22a547feSLi Feng Wang xPresPropSet.getPropertyValue("IsFullScreen"), Boolean.TRUE); 99*22a547feSLi Feng Wang Assert.assertEquals("Pause set to 0", 100*22a547feSLi Feng Wang xPresPropSet.getPropertyValue("Pause"), 0); 101*22a547feSLi Feng Wang } 102*22a547feSLi Feng Wang 103*22a547feSLi Feng Wang public XDrawPage createSlide(int index) throws Exception { 104*22a547feSLi Feng Wang drawpages.insertNewByIndex(index); 105*22a547feSLi Feng Wang XDrawPage xPage = PageUtil.getDrawPageByIndex(impressDocument, index); 106*22a547feSLi Feng Wang return xPage; 107*22a547feSLi Feng Wang } 108*22a547feSLi Feng Wang 109*22a547feSLi Feng Wang /** 110*22a547feSLi Feng Wang * create a new presentation document and insert a new slide. 111*22a547feSLi Feng Wang * 112*22a547feSLi Feng Wang * @throws Exception 113*22a547feSLi Feng Wang */ 114*22a547feSLi Feng Wang public void createDocumentAndSlide() throws Exception { 115*22a547feSLi Feng Wang impressDocument = (XComponent) UnoRuntime.queryInterface( 116*22a547feSLi Feng Wang XComponent.class, unoApp.newDocument("simpress")); 117*22a547feSLi Feng Wang drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface( 118*22a547feSLi Feng Wang XDrawPagesSupplier.class, impressDocument); 119*22a547feSLi Feng Wang drawpages = drawsupplier.getDrawPages(); 120*22a547feSLi Feng Wang sdDocument = (XPresentationSupplier) UnoRuntime.queryInterface( 121*22a547feSLi Feng Wang XPresentationSupplier.class, impressDocument); 122*22a547feSLi Feng Wang pre = sdDocument.getPresentation(); 123*22a547feSLi Feng Wang } 124*22a547feSLi Feng Wang 125*22a547feSLi Feng Wang /** 126*22a547feSLi Feng Wang * Save presentation and reLoad the slide. 127*22a547feSLi Feng Wang * 128*22a547feSLi Feng Wang * @param no 129*22a547feSLi Feng Wang * @return void 130*22a547feSLi Feng Wang * @throws Exception 131*22a547feSLi Feng Wang */ 132*22a547feSLi Feng Wang public void saveAndLoadSlide() throws Exception { 133*22a547feSLi Feng Wang reLoadFile = saveAndReloadDoc(impressDocument, 134*22a547feSLi Feng Wang "StarOffice XML (Impress)", "odp"); 135*22a547feSLi Feng Wang drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface( 136*22a547feSLi Feng Wang XDrawPagesSupplier.class, reLoadFile); 137*22a547feSLi Feng Wang drawpages = drawsupplier.getDrawPages(); 138*22a547feSLi Feng Wang 139*22a547feSLi Feng Wang sdDocument = (XPresentationSupplier) UnoRuntime.queryInterface( 140*22a547feSLi Feng Wang XPresentationSupplier.class, reLoadFile); 141*22a547feSLi Feng Wang pre = sdDocument.getPresentation(); 142*22a547feSLi Feng Wang } 143*22a547feSLi Feng Wang 144*22a547feSLi Feng Wang /** 145*22a547feSLi Feng Wang * save and reload Presentation document. 146*22a547feSLi Feng Wang * 147*22a547feSLi Feng Wang * @param presentationDocument 148*22a547feSLi Feng Wang * @param sFilter 149*22a547feSLi Feng Wang * @param sExtension 150*22a547feSLi Feng Wang * @return 151*22a547feSLi Feng Wang * @throws Exception 152*22a547feSLi Feng Wang */ 153*22a547feSLi Feng Wang private XComponent saveAndReloadDoc(XComponent presentationDocument, 154*22a547feSLi Feng Wang String sFilter, String sExtension) throws Exception { 155*22a547feSLi Feng Wang filePath = Testspace.getPath("tmp/slideshow." + sExtension); 156*22a547feSLi Feng Wang PropertyValue[] aStoreProperties = new PropertyValue[2]; 157*22a547feSLi Feng Wang aStoreProperties[0] = new PropertyValue(); 158*22a547feSLi Feng Wang aStoreProperties[1] = new PropertyValue(); 159*22a547feSLi Feng Wang aStoreProperties[0].Name = "Override"; 160*22a547feSLi Feng Wang aStoreProperties[0].Value = true; 161*22a547feSLi Feng Wang aStoreProperties[1].Name = "FilterName"; 162*22a547feSLi Feng Wang aStoreProperties[1].Value = sFilter; 163*22a547feSLi Feng Wang XStorable xStorable = (XStorable) UnoRuntime.queryInterface( 164*22a547feSLi Feng Wang XStorable.class, presentationDocument); 165*22a547feSLi Feng Wang xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties); 166*22a547feSLi Feng Wang 167*22a547feSLi Feng Wang return (XComponent) UnoRuntime.queryInterface(XComponent.class, 168*22a547feSLi Feng Wang unoApp.loadDocument(filePath)); 169*22a547feSLi Feng Wang } 170*22a547feSLi Feng Wang } 171