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