xref: /AOO41X/test/testuno/source/fvt/uno/sw/frame/FrameSize.java (revision 47148b3bc50811ceb41802e4cc50a5db21535900)
1*f5a7bb7cSJürgen Schmidt /**************************************************************
2*f5a7bb7cSJürgen Schmidt  *
3*f5a7bb7cSJürgen Schmidt  * Licensed to the Apache Software Foundation (ASF) under one
4*f5a7bb7cSJürgen Schmidt  * or more contributor license agreements.  See the NOTICE file
5*f5a7bb7cSJürgen Schmidt  * distributed with this work for additional information
6*f5a7bb7cSJürgen Schmidt  * regarding copyright ownership.  The ASF licenses this file
7*f5a7bb7cSJürgen Schmidt  * to you under the Apache License, Version 2.0 (the
8*f5a7bb7cSJürgen Schmidt  * "License"); you may not use this file except in compliance
9*f5a7bb7cSJürgen Schmidt  * with the License.  You may obtain a copy of the License at
10*f5a7bb7cSJürgen Schmidt  *
11*f5a7bb7cSJürgen Schmidt  *   http://www.apache.org/licenses/LICENSE-2.0
12*f5a7bb7cSJürgen Schmidt  *
13*f5a7bb7cSJürgen Schmidt  * Unless required by applicable law or agreed to in writing,
14*f5a7bb7cSJürgen Schmidt  * software distributed under the License is distributed on an
15*f5a7bb7cSJürgen Schmidt  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f5a7bb7cSJürgen Schmidt  * KIND, either express or implied.  See the License for the
17*f5a7bb7cSJürgen Schmidt  * specific language governing permissions and limitations
18*f5a7bb7cSJürgen Schmidt  * under the License.
19*f5a7bb7cSJürgen Schmidt  *
20*f5a7bb7cSJürgen Schmidt  *************************************************************/
211ff9903bSLi Feng Wang package fvt.uno.sw.frame;
221ff9903bSLi Feng Wang 
231ff9903bSLi Feng Wang import static org.junit.Assert.*;
241ff9903bSLi Feng Wang 
251ff9903bSLi Feng Wang import org.junit.After;
261ff9903bSLi Feng Wang import org.junit.AfterClass;
271ff9903bSLi Feng Wang import org.junit.Before;
281ff9903bSLi Feng Wang import org.junit.Test;
291ff9903bSLi Feng Wang import org.openoffice.test.common.Testspace;
301ff9903bSLi Feng Wang import org.openoffice.test.uno.UnoApp;
311ff9903bSLi Feng Wang 
321ff9903bSLi Feng Wang import testlib.uno.SWUtil;
331ff9903bSLi Feng Wang 
341ff9903bSLi Feng Wang import com.sun.star.awt.Size;
351ff9903bSLi Feng Wang import com.sun.star.container.XNameAccess;
361ff9903bSLi Feng Wang import com.sun.star.drawing.XShape;
371ff9903bSLi Feng Wang import com.sun.star.lang.XMultiServiceFactory;
381ff9903bSLi Feng Wang import com.sun.star.text.XText;
391ff9903bSLi Feng Wang import com.sun.star.text.XTextCursor;
401ff9903bSLi Feng Wang import com.sun.star.text.XTextDocument;
411ff9903bSLi Feng Wang import com.sun.star.text.XTextFrame;
421ff9903bSLi Feng Wang import com.sun.star.text.XTextFramesSupplier;
431ff9903bSLi Feng Wang import com.sun.star.uno.UnoRuntime;
441ff9903bSLi Feng Wang 
451ff9903bSLi Feng Wang public class FrameSize {
461ff9903bSLi Feng Wang 	private static final UnoApp app = new UnoApp();
471ff9903bSLi Feng Wang 	private XTextDocument xTextDocument=null;
481ff9903bSLi Feng Wang 	private XMultiServiceFactory xWriterFactory=null;
491ff9903bSLi Feng Wang 	private XText xText=null;
501ff9903bSLi Feng Wang 	@Before
setUp()511ff9903bSLi Feng Wang 	public void setUp() throws Exception {
521ff9903bSLi Feng Wang 		app.start();
531ff9903bSLi Feng Wang 	}
541ff9903bSLi Feng Wang 
551ff9903bSLi Feng Wang 	@After
tearDown()561ff9903bSLi Feng Wang 	public void tearDown() throws Exception {
571ff9903bSLi Feng Wang 		app.closeDocument(xTextDocument);
581ff9903bSLi Feng Wang 	}
591ff9903bSLi Feng Wang 	@AfterClass
tearDownConnection()601ff9903bSLi Feng Wang 	public static void tearDownConnection() throws Exception {
611ff9903bSLi Feng Wang 		app.close();
621ff9903bSLi Feng Wang 	}
631ff9903bSLi Feng Wang 
641ff9903bSLi Feng Wang 	@Test
testFrameSize()651ff9903bSLi Feng Wang 	public void testFrameSize() throws Exception {
661ff9903bSLi Feng Wang 		xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));
671ff9903bSLi Feng Wang 		xText=xTextDocument.getText();
681ff9903bSLi Feng Wang 		XTextCursor xTextCursor = xText.createTextCursor();
691ff9903bSLi Feng Wang 		// get internal service factory of the document
701ff9903bSLi Feng Wang 		xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
711ff9903bSLi Feng Wang 		// Create a new table from the document's factory
721ff9903bSLi Feng Wang 		XTextFrame xTextFrame = (XTextFrame)UnoRuntime.queryInterface(XTextFrame.class, xWriterFactory.createInstance("com.sun.star.text.TextFrame"));
731ff9903bSLi Feng Wang 		xText.insertTextContent(xTextCursor,xTextFrame,false);
741ff9903bSLi Feng Wang 		// Access the XShape interface of the TextFrame
751ff9903bSLi Feng Wang         XShape xShape = (XShape) UnoRuntime.queryInterface(XShape.class, xTextFrame);
761ff9903bSLi Feng Wang         // Set the size of the new Text Frame using the XShape's 'setSize' method
771ff9903bSLi Feng Wang         Size aSize = new Size();
781ff9903bSLi Feng Wang         aSize.Height = 41;
791ff9903bSLi Feng Wang         aSize.Width = 15000;
801ff9903bSLi Feng Wang         xShape.setSize(aSize);
811ff9903bSLi Feng Wang 
821ff9903bSLi Feng Wang 		//reopen the odt document
831ff9903bSLi Feng Wang 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "writer8",Testspace.getPath("output/test.odt"), app));
841ff9903bSLi Feng Wang 		XTextFramesSupplier xTFS_odt = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_odt);
851ff9903bSLi Feng Wang 		XNameAccess xTextFrames_odt = xTFS_odt.getTextFrames();
861ff9903bSLi Feng Wang 		Object xTextFrame_obj_odt=xTextFrames_odt.getByName("Frame1");
871ff9903bSLi Feng Wang 		XTextFrame xTextFrame_Assert_odt=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xTextFrame_obj_odt);
881ff9903bSLi Feng Wang 		XShape xShape_odt = (XShape) UnoRuntime.queryInterface(XShape.class, xTextFrame_Assert_odt);
891ff9903bSLi Feng Wang 		assertEquals("verify Frame height size",41,xShape_odt.getSize().Height);
901ff9903bSLi Feng Wang 		assertEquals("verify Frame width size",15000,xShape_odt.getSize().Width);
911ff9903bSLi Feng Wang 
921ff9903bSLi Feng Wang 		//reopen the doc document
931ff9903bSLi Feng Wang 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "MS Word 97",Testspace.getPath("output/test.doc"), app));
941ff9903bSLi Feng Wang 		XTextFramesSupplier xTFS_doc = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_doc);
951ff9903bSLi Feng Wang 		XNameAccess xTextFrames_doc = xTFS_doc.getTextFrames();
961ff9903bSLi Feng Wang 		Object xTextFrame_obj_doc=xTextFrames_doc.getByName("Frame1");
971ff9903bSLi Feng Wang 		XTextFrame xTextFrame_Assert_doc=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xTextFrame_obj_doc);
981ff9903bSLi Feng Wang 		XShape xShape_doc = (XShape) UnoRuntime.queryInterface(XShape.class, xTextFrame_Assert_doc);
991ff9903bSLi Feng Wang 		assertEquals("verify Frame height size",788,xShape_doc.getSize().Height);
1001ff9903bSLi Feng Wang 		assertEquals("verify Frame width size",14998,xShape_doc.getSize().Width);
1011ff9903bSLi Feng Wang 	}
1021ff9903bSLi Feng Wang }
103