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.Testspace;
15*1ff9903bSLi Feng Wang import org.openoffice.test.uno.UnoApp;
16*1ff9903bSLi Feng Wang 
17*1ff9903bSLi Feng Wang import testlib.uno.SWUtil;
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.text.XText;
22*1ff9903bSLi Feng Wang import com.sun.star.text.XTextCursor;
23*1ff9903bSLi Feng Wang import com.sun.star.text.XTextDocument;
24*1ff9903bSLi Feng Wang import com.sun.star.text.XTextFrame;
25*1ff9903bSLi Feng Wang import com.sun.star.text.XTextFramesSupplier;
26*1ff9903bSLi Feng Wang import com.sun.star.uno.UnoRuntime;
27*1ff9903bSLi Feng Wang @RunWith(value = Parameterized.class)
28*1ff9903bSLi Feng Wang public class FramePosition {
29*1ff9903bSLi Feng Wang 	private static final UnoApp app = new UnoApp();
30*1ff9903bSLi Feng Wang 	private XTextDocument xTextDocument=null;
31*1ff9903bSLi Feng Wang 	private XMultiServiceFactory xWriterFactory=null;
32*1ff9903bSLi Feng Wang 	private XText xText=null;
33*1ff9903bSLi Feng Wang 	private short HoriOrient;
34*1ff9903bSLi Feng Wang 	private short HoriOrientRelation;
35*1ff9903bSLi Feng Wang 	private short VertOrient;
36*1ff9903bSLi Feng Wang 	private short VertOrientRelation;
37*1ff9903bSLi Feng Wang 	public FramePosition(short HoriOrient,short HoriOrientRelation,short VertOrient,short VertOrientRelation){
38*1ff9903bSLi Feng Wang 		this.HoriOrient=HoriOrient;
39*1ff9903bSLi Feng Wang 		this.HoriOrientRelation = HoriOrientRelation;
40*1ff9903bSLi Feng Wang 		this.VertOrient=VertOrient;
41*1ff9903bSLi Feng Wang 		this.VertOrientRelation = VertOrientRelation;
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     			{(short)0,(short)0,(short)0,(short)0},
47*1ff9903bSLi Feng Wang     			{(short)1,(short)1,(short)1,(short)1},
48*1ff9903bSLi Feng Wang     			{(short)2,(short)2,(short)2,(short)2},
49*1ff9903bSLi Feng Wang     			{(short)3,(short)3,(short)3,(short)2},
50*1ff9903bSLi Feng Wang     			{(short)0,(short)4,(short)2,(short)0},
51*1ff9903bSLi Feng Wang     			{(short)1,(short)5,(short)2,(short)2},
52*1ff9903bSLi Feng Wang     			};
53*1ff9903bSLi Feng Wang     	return Arrays.asList(params);
54*1ff9903bSLi Feng Wang     }
55*1ff9903bSLi Feng Wang 	@Before
56*1ff9903bSLi Feng Wang 	public void setUp() throws Exception {
57*1ff9903bSLi Feng Wang 		app.start();
58*1ff9903bSLi Feng Wang 	}
59*1ff9903bSLi Feng Wang 
60*1ff9903bSLi Feng Wang 	@After
61*1ff9903bSLi Feng Wang 	public void tearDown() throws Exception {
62*1ff9903bSLi Feng Wang 		app.close();
63*1ff9903bSLi Feng Wang 	}
64*1ff9903bSLi Feng Wang 
65*1ff9903bSLi Feng Wang 	@Test
66*1ff9903bSLi Feng Wang 	public void testFramePosition() throws Exception {
67*1ff9903bSLi Feng Wang 		xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));
68*1ff9903bSLi Feng Wang 		xText=xTextDocument.getText();
69*1ff9903bSLi Feng Wang 		XTextCursor xTextCursor = xText.createTextCursor();
70*1ff9903bSLi Feng Wang 		// get internal service factory of the document
71*1ff9903bSLi Feng Wang 		xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
72*1ff9903bSLi Feng Wang 		// Create a new table from the document's factory
73*1ff9903bSLi Feng Wang 		XTextFrame xTextFrame = (XTextFrame)UnoRuntime.queryInterface(XTextFrame.class, xWriterFactory.createInstance("com.sun.star.text.TextFrame"));
74*1ff9903bSLi Feng Wang 		xText.insertTextContent(xTextCursor,xTextFrame,false);
75*1ff9903bSLi Feng Wang 		XPropertySet xFrameProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextFrame);
76*1ff9903bSLi Feng Wang 		xFrameProps.setPropertyValue("HoriOrient", HoriOrient);
77*1ff9903bSLi Feng Wang 		xFrameProps.setPropertyValue("HoriOrientRelation", HoriOrientRelation);
78*1ff9903bSLi Feng Wang 		xFrameProps.setPropertyValue("VertOrient", VertOrient);
79*1ff9903bSLi Feng Wang 		xFrameProps.setPropertyValue("VertOrientRelation", VertOrientRelation);
80*1ff9903bSLi Feng Wang 
81*1ff9903bSLi Feng Wang 		//reopen the odt document
82*1ff9903bSLi Feng Wang 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "writer8",Testspace.getPath("output/test.odt"), app));
83*1ff9903bSLi Feng Wang 		XTextFramesSupplier xTFS_odt = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_odt);
84*1ff9903bSLi Feng Wang 		XNameAccess xTextFrames_odt = xTFS_odt.getTextFrames();
85*1ff9903bSLi Feng Wang 		Object xTextFrame_obj_odt=xTextFrames_odt.getByName("Frame1");
86*1ff9903bSLi Feng Wang 		XTextFrame xTextFrame_Assert_odt=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xTextFrame_obj_odt);
87*1ff9903bSLi Feng Wang 		XPropertySet xFramProps_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextFrame_Assert_odt);
88*1ff9903bSLi Feng Wang 		assertEquals("verify Frame position",HoriOrient,xFramProps_odt.getPropertyValue("HoriOrient"));
89*1ff9903bSLi Feng Wang 		assertEquals("verify Frame position",HoriOrientRelation,xFramProps_odt.getPropertyValue("HoriOrientRelation"));
90*1ff9903bSLi Feng Wang 		assertEquals("verify Frame position",VertOrient,xFramProps_odt.getPropertyValue("VertOrient"));
91*1ff9903bSLi Feng Wang 		assertEquals("verify Frame position",VertOrientRelation,xFramProps_odt.getPropertyValue("VertOrientRelation"));
92*1ff9903bSLi Feng Wang 	}
93*1ff9903bSLi Feng Wang }
94