1 package fvt.uno.sw.frame; 2 3 import static org.junit.Assert.*; 4 5 import org.junit.After; 6 import org.junit.AfterClass; 7 import org.junit.Before; 8 import org.junit.Test; 9 import org.openoffice.test.common.Testspace; 10 import org.openoffice.test.uno.UnoApp; 11 12 import testlib.uno.SWUtil; 13 14 import com.sun.star.awt.Size; 15 import com.sun.star.container.XNameAccess; 16 import com.sun.star.drawing.XShape; 17 import com.sun.star.lang.XMultiServiceFactory; 18 import com.sun.star.text.XText; 19 import com.sun.star.text.XTextCursor; 20 import com.sun.star.text.XTextDocument; 21 import com.sun.star.text.XTextFrame; 22 import com.sun.star.text.XTextFramesSupplier; 23 import com.sun.star.uno.UnoRuntime; 24 25 public class FrameSize { 26 private static final UnoApp app = new UnoApp(); 27 private XTextDocument xTextDocument=null; 28 private XMultiServiceFactory xWriterFactory=null; 29 private XText xText=null; 30 @Before 31 public void setUp() throws Exception { 32 app.start(); 33 } 34 35 @After 36 public void tearDown() throws Exception { 37 app.closeDocument(xTextDocument); 38 } 39 @AfterClass 40 public static void tearDownConnection() throws Exception { 41 app.close(); 42 } 43 44 @Test 45 public void testFrameSize() throws Exception { 46 xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); 47 xText=xTextDocument.getText(); 48 XTextCursor xTextCursor = xText.createTextCursor(); 49 // get internal service factory of the document 50 xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 51 // Create a new table from the document's factory 52 XTextFrame xTextFrame = (XTextFrame)UnoRuntime.queryInterface(XTextFrame.class, xWriterFactory.createInstance("com.sun.star.text.TextFrame")); 53 xText.insertTextContent(xTextCursor,xTextFrame,false); 54 // Access the XShape interface of the TextFrame 55 XShape xShape = (XShape) UnoRuntime.queryInterface(XShape.class, xTextFrame); 56 // Set the size of the new Text Frame using the XShape's 'setSize' method 57 Size aSize = new Size(); 58 aSize.Height = 41; 59 aSize.Width = 15000; 60 xShape.setSize(aSize); 61 62 //reopen the odt document 63 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "writer8",Testspace.getPath("output/test.odt"), app)); 64 XTextFramesSupplier xTFS_odt = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_odt); 65 XNameAccess xTextFrames_odt = xTFS_odt.getTextFrames(); 66 Object xTextFrame_obj_odt=xTextFrames_odt.getByName("Frame1"); 67 XTextFrame xTextFrame_Assert_odt=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xTextFrame_obj_odt); 68 XShape xShape_odt = (XShape) UnoRuntime.queryInterface(XShape.class, xTextFrame_Assert_odt); 69 assertEquals("verify Frame height size",41,xShape_odt.getSize().Height); 70 assertEquals("verify Frame width size",15000,xShape_odt.getSize().Width); 71 72 //reopen the doc document 73 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "MS Word 97",Testspace.getPath("output/test.doc"), app)); 74 XTextFramesSupplier xTFS_doc = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_doc); 75 XNameAccess xTextFrames_doc = xTFS_doc.getTextFrames(); 76 Object xTextFrame_obj_doc=xTextFrames_doc.getByName("Frame1"); 77 XTextFrame xTextFrame_Assert_doc=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xTextFrame_obj_doc); 78 XShape xShape_doc = (XShape) UnoRuntime.queryInterface(XShape.class, xTextFrame_Assert_doc); 79 assertEquals("verify Frame height size",788,xShape_doc.getSize().Height); 80 assertEquals("verify Frame width size",14998,xShape_doc.getSize().Width); 81 } 82 } 83