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.container.XNameAccess; 15 import com.sun.star.lang.XMultiServiceFactory; 16 import com.sun.star.text.XText; 17 import com.sun.star.text.XTextCursor; 18 import com.sun.star.text.XTextDocument; 19 import com.sun.star.text.XTextFrame; 20 import com.sun.star.text.XTextFramesSupplier; 21 import com.sun.star.uno.UnoRuntime; 22 23 public class InsertFrame { 24 private static final UnoApp app = new UnoApp(); 25 private XTextDocument xTextDocument=null; 26 private XMultiServiceFactory xWriterFactory=null; 27 private XText xText=null; 28 @Before 29 public void setUp() throws Exception { 30 app.start(); 31 } 32 33 @After 34 public void tearDown() throws Exception { 35 app.closeDocument(xTextDocument); 36 } 37 @AfterClass 38 public static void tearDownConnection() throws Exception { 39 app.close(); 40 } 41 42 @Test 43 public void testInsertFrame() throws Exception { 44 xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); 45 xText=xTextDocument.getText(); 46 XTextCursor xTextCursor = xText.createTextCursor(); 47 // get internal service factory of the document 48 xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 49 // Create a new table from the document's factory 50 XTextFrame xTextFrame = (XTextFrame)UnoRuntime.queryInterface(XTextFrame.class, xWriterFactory.createInstance("com.sun.star.text.TextFrame")); 51 xText.insertTextContent(xTextCursor,xTextFrame,false); 52 53 //save and reopen the document 54 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "writer8",Testspace.getPath("output/test.odt"), app)); 55 XTextFramesSupplier xTFS_odt = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_odt); 56 XNameAccess xTextFrames_odt = xTFS_odt.getTextFrames(); 57 assertTrue("Has text frame named Frame1", xTextFrames_odt.hasByName("Frame1")); 58 //save and reopen the document 59 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "MS Word 97",Testspace.getPath("output/test.doc"), app)); 60 XTextFramesSupplier xTFS_doc = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_doc); 61 XNameAccess xTextFrames_doc = xTFS_doc.getTextFrames(); 62 assertTrue("Has text frame named Frame1", xTextFrames_doc.hasByName("Frame1")); 63 } 64 } 65