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 org.junit.After;
26 import org.junit.AfterClass;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.openoffice.test.common.Testspace;
30 import org.openoffice.test.uno.UnoApp;
31 
32 import testlib.uno.SWUtil;
33 
34 import com.sun.star.awt.Size;
35 import com.sun.star.container.XNameAccess;
36 import com.sun.star.drawing.XShape;
37 import com.sun.star.lang.XMultiServiceFactory;
38 import com.sun.star.text.XText;
39 import com.sun.star.text.XTextCursor;
40 import com.sun.star.text.XTextDocument;
41 import com.sun.star.text.XTextFrame;
42 import com.sun.star.text.XTextFramesSupplier;
43 import com.sun.star.uno.UnoRuntime;
44 
45 public class FrameSize {
46 	private static final UnoApp app = new UnoApp();
47 	private XTextDocument xTextDocument=null;
48 	private XMultiServiceFactory xWriterFactory=null;
49 	private XText xText=null;
50 	@Before
setUp()51 	public void setUp() throws Exception {
52 		app.start();
53 	}
54 
55 	@After
tearDown()56 	public void tearDown() throws Exception {
57 		app.closeDocument(xTextDocument);
58 	}
59 	@AfterClass
tearDownConnection()60 	public static void tearDownConnection() throws Exception {
61 		app.close();
62 	}
63 
64 	@Test
testFrameSize()65 	public void testFrameSize() throws Exception {
66 		xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));
67 		xText=xTextDocument.getText();
68 		XTextCursor xTextCursor = xText.createTextCursor();
69 		// get internal service factory of the document
70 		xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
71 		// Create a new table from the document's factory
72 		XTextFrame xTextFrame = (XTextFrame)UnoRuntime.queryInterface(XTextFrame.class, xWriterFactory.createInstance("com.sun.star.text.TextFrame"));
73 		xText.insertTextContent(xTextCursor,xTextFrame,false);
74 		// Access the XShape interface of the TextFrame
75         XShape xShape = (XShape) UnoRuntime.queryInterface(XShape.class, xTextFrame);
76         // Set the size of the new Text Frame using the XShape's 'setSize' method
77         Size aSize = new Size();
78         aSize.Height = 41;
79         aSize.Width = 15000;
80         xShape.setSize(aSize);
81 
82 		//reopen the odt document
83 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "writer8",Testspace.getPath("output/test.odt"), app));
84 		XTextFramesSupplier xTFS_odt = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_odt);
85 		XNameAccess xTextFrames_odt = xTFS_odt.getTextFrames();
86 		Object xTextFrame_obj_odt=xTextFrames_odt.getByName("Frame1");
87 		XTextFrame xTextFrame_Assert_odt=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xTextFrame_obj_odt);
88 		XShape xShape_odt = (XShape) UnoRuntime.queryInterface(XShape.class, xTextFrame_Assert_odt);
89 		assertEquals("verify Frame height size",41,xShape_odt.getSize().Height);
90 		assertEquals("verify Frame width size",15000,xShape_odt.getSize().Width);
91 
92 		//reopen the doc document
93 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "MS Word 97",Testspace.getPath("output/test.doc"), app));
94 		XTextFramesSupplier xTFS_doc = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_doc);
95 		XNameAccess xTextFrames_doc = xTFS_doc.getTextFrames();
96 		Object xTextFrame_obj_doc=xTextFrames_doc.getByName("Frame1");
97 		XTextFrame xTextFrame_Assert_doc=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xTextFrame_obj_doc);
98 		XShape xShape_doc = (XShape) UnoRuntime.queryInterface(XShape.class, xTextFrame_Assert_doc);
99 		assertEquals("verify Frame height size",788,xShape_doc.getSize().Height);
100 		assertEquals("verify Frame width size",14998,xShape_doc.getSize().Width);
101 	}
102 }
103