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