1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 package fvt.uno.sw.frame;
22 
23 import static org.junit.Assert.*;
24 
25 import java.util.Arrays;
26 import java.util.Collection;
27 
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.junit.runners.Parameterized;
33 import org.junit.runners.Parameterized.Parameters;
34 import org.openoffice.test.common.Testspace;
35 import org.openoffice.test.uno.UnoApp;
36 
37 import testlib.uno.SWUtil;
38 import com.sun.star.beans.XPropertySet;
39 import com.sun.star.container.XNameAccess;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.text.XText;
42 import com.sun.star.text.XTextCursor;
43 import com.sun.star.text.XTextDocument;
44 import com.sun.star.text.XTextFrame;
45 import com.sun.star.text.XTextFramesSupplier;
46 import com.sun.star.uno.UnoRuntime;
47 @RunWith(value = Parameterized.class)
48 public class FramePosition {
49 	private static final UnoApp app = new UnoApp();
50 	private XTextDocument xTextDocument=null;
51 	private XMultiServiceFactory xWriterFactory=null;
52 	private XText xText=null;
53 	private short HoriOrient;
54 	private short HoriOrientRelation;
55 	private short VertOrient;
56 	private short VertOrientRelation;
FramePosition(short HoriOrient,short HoriOrientRelation,short VertOrient,short VertOrientRelation)57 	public FramePosition(short HoriOrient,short HoriOrientRelation,short VertOrient,short VertOrientRelation){
58 		this.HoriOrient=HoriOrient;
59 		this.HoriOrientRelation = HoriOrientRelation;
60 		this.VertOrient=VertOrient;
61 		this.VertOrientRelation = VertOrientRelation;
62 	}
63 	@Parameters
data()64     public static Collection<Object[]> data(){
65     	Object[][] params = new Object[][]{
66     			{(short)0,(short)0,(short)0,(short)0},
67     			{(short)1,(short)1,(short)1,(short)1},
68     			{(short)2,(short)2,(short)2,(short)2},
69     			{(short)3,(short)3,(short)3,(short)2},
70     			{(short)0,(short)4,(short)2,(short)0},
71     			{(short)1,(short)5,(short)2,(short)2},
72     			};
73     	return Arrays.asList(params);
74     }
75 	@Before
setUp()76 	public void setUp() throws Exception {
77 		app.start();
78 	}
79 
80 	@After
tearDown()81 	public void tearDown() throws Exception {
82 		app.close();
83 	}
84 
85 	@Test
testFramePosition()86 	public void testFramePosition() throws Exception {
87 		xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));
88 		xText=xTextDocument.getText();
89 		XTextCursor xTextCursor = xText.createTextCursor();
90 		// get internal service factory of the document
91 		xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
92 		// Create a new table from the document's factory
93 		XTextFrame xTextFrame = (XTextFrame)UnoRuntime.queryInterface(XTextFrame.class, xWriterFactory.createInstance("com.sun.star.text.TextFrame"));
94 		xText.insertTextContent(xTextCursor,xTextFrame,false);
95 		XPropertySet xFrameProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextFrame);
96 		xFrameProps.setPropertyValue("HoriOrient", HoriOrient);
97 		xFrameProps.setPropertyValue("HoriOrientRelation", HoriOrientRelation);
98 		xFrameProps.setPropertyValue("VertOrient", VertOrient);
99 		xFrameProps.setPropertyValue("VertOrientRelation", VertOrientRelation);
100 
101 		//reopen the odt document
102 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "writer8",Testspace.getPath("output/test.odt"), app));
103 		XTextFramesSupplier xTFS_odt = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_odt);
104 		XNameAccess xTextFrames_odt = xTFS_odt.getTextFrames();
105 		Object xTextFrame_obj_odt=xTextFrames_odt.getByName("Frame1");
106 		XTextFrame xTextFrame_Assert_odt=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xTextFrame_obj_odt);
107 		XPropertySet xFramProps_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextFrame_Assert_odt);
108 		assertEquals("verify Frame position",HoriOrient,xFramProps_odt.getPropertyValue("HoriOrient"));
109 		assertEquals("verify Frame position",HoriOrientRelation,xFramProps_odt.getPropertyValue("HoriOrientRelation"));
110 		assertEquals("verify Frame position",VertOrient,xFramProps_odt.getPropertyValue("VertOrient"));
111 		assertEquals("verify Frame position",VertOrientRelation,xFramProps_odt.getPropertyValue("VertOrientRelation"));
112 	}
113 }
114