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