1 package fvt.uno.sw.frame; 2 3 import static org.junit.Assert.*; 4 5 import java.util.Arrays; 6 import java.util.Collection; 7 8 import org.junit.After; 9 import org.junit.Before; 10 import org.junit.Test; 11 import org.junit.runner.RunWith; 12 import org.junit.runners.Parameterized; 13 import org.junit.runners.Parameterized.Parameters; 14 import org.openoffice.test.common.FileUtil; 15 import org.openoffice.test.common.Testspace; 16 import org.openoffice.test.uno.UnoApp; 17 18 import com.sun.star.beans.XPropertySet; 19 import com.sun.star.container.XNameAccess; 20 import com.sun.star.lang.XMultiServiceFactory; 21 import com.sun.star.style.GraphicLocation; 22 import com.sun.star.text.XText; 23 import com.sun.star.text.XTextCursor; 24 import com.sun.star.text.XTextDocument; 25 import com.sun.star.text.XTextFrame; 26 import com.sun.star.text.XTextFramesSupplier; 27 import com.sun.star.uno.UnoRuntime; 28 import testlib.uno.SWUtil; 29 @RunWith(value = Parameterized.class) 30 public class FrameBackGraphic { 31 private static final UnoApp app = new UnoApp(); 32 private XTextDocument xTextDocument=null; 33 private XMultiServiceFactory xWriterFactory=null; 34 private XText xText=null; 35 private int backGraphicLocation; 36 private String graphicURL=null; 37 private String graphicName=null; 38 public FrameBackGraphic(String graphicURL,String graphicName,int backGraphicLocation){ 39 this.graphicURL=graphicURL; 40 this.graphicName=graphicName; 41 this.backGraphicLocation = backGraphicLocation; 42 } 43 @Parameters 44 public static Collection<Object[]> data(){ 45 Object[][] params = new Object[][]{ 46 {FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),"draw_jpg_Export",1}, 47 {FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),"draw_jpg_Export",2}, 48 {FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),"draw_jpg_Export",3}, 49 {FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),"draw_jpg_Export",4}, 50 {FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),"draw_jpg_Export",5}, 51 {FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),"draw_jpg_Export",6}, 52 {FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),"draw_jpg_Export",7}, 53 {FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),"draw_jpg_Export",8}, 54 {FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),"draw_jpg_Export",9}, 55 {FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),"draw_jpg_Export",10}, 56 {FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),"draw_jpg_Export",11} 57 }; 58 return Arrays.asList(params); 59 } 60 61 @Before 62 public void setUp() throws Exception { 63 app.start(); 64 } 65 66 @After 67 public void tearDown() throws Exception { 68 app.close(); 69 } 70 @Test 71 public void testFrameBackGraphic() throws Exception { 72 xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); 73 xText=xTextDocument.getText(); 74 XTextCursor xTextCursor = xText.createTextCursor(); 75 // get internal service factory of the document 76 xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 77 // Create a new Frame from the document's factory 78 XTextFrame xTextFrame1 = (XTextFrame)UnoRuntime.queryInterface(XTextFrame.class, xWriterFactory.createInstance("com.sun.star.text.TextFrame")); 79 xText.insertTextContent(xTextCursor,xTextFrame1,false); 80 XPropertySet xFrameProps1 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextFrame1); 81 xFrameProps1.setPropertyValue("BackGraphicURL",graphicURL); 82 xFrameProps1.setPropertyValue("BackGraphicFilter",graphicName); 83 xFrameProps1.setPropertyValue("BackGraphicLocation",backGraphicLocation); 84 XTextDocument xTextDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "writer8",Testspace.getPath("output/test.odt"), app)); 85 XTextFramesSupplier xTFS_odt = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class,xTextDocument_odt); 86 XNameAccess xTextFrames_odt = xTFS_odt.getTextFrames(); 87 Object xFrame_obj1=xTextFrames_odt.getByName("Frame1"); 88 XTextFrame xFrame_Assert1=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xFrame_obj1); 89 XPropertySet xFrameProps1_assert = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xFrame_Assert1); 90 GraphicLocation graphiclocation=(GraphicLocation)xFrameProps1_assert.getPropertyValue("BackGraphicLocation"); 91 assertEquals("verify Frame backgraphic location",backGraphicLocation,graphiclocation.getValue()); 92 assertEquals("verify Frame backgraphic fileter",graphicName,xFrameProps1_assert.getPropertyValue("BackGraphicFilter")); 93 assertEquals("verify Frame backgraphic URL",graphicURL,xFrameProps1_assert.getPropertyValue("BackGraphicURL")); 94 } 95 } 96