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.container.XNameAccess;
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.text.XText;
37 import com.sun.star.text.XTextCursor;
38 import com.sun.star.text.XTextDocument;
39 import com.sun.star.text.XTextFrame;
40 import com.sun.star.text.XTextFramesSupplier;
41 import com.sun.star.uno.UnoRuntime;
42 
43 public class InsertFrame {
44 	private static final UnoApp app = new UnoApp();
45 	private XTextDocument xTextDocument=null;
46 	private XMultiServiceFactory xWriterFactory=null;
47 	private XText xText=null;
48 	@Before
setUp()49 	public void setUp() throws Exception {
50 		app.start();
51 	}
52 
53 	@After
tearDown()54 	public void tearDown() throws Exception {
55 		app.closeDocument(xTextDocument);
56 	}
57 	@AfterClass
tearDownConnection()58 	public static void tearDownConnection() throws Exception {
59 		app.close();
60 	}
61 
62 	@Test
testInsertFrame()63 	public void testInsertFrame() throws Exception {
64 		xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));
65 		xText=xTextDocument.getText();
66 		XTextCursor xTextCursor = xText.createTextCursor();
67 		// get internal service factory of the document
68 		xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
69 		// Create a new table from the document's factory
70 		XTextFrame xTextFrame = (XTextFrame)UnoRuntime.queryInterface(XTextFrame.class, xWriterFactory.createInstance("com.sun.star.text.TextFrame"));
71 		xText.insertTextContent(xTextCursor,xTextFrame,false);
72 
73 		//save and reopen the document
74 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "writer8",Testspace.getPath("output/test.odt"), app));
75 		XTextFramesSupplier xTFS_odt = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_odt);
76 		XNameAccess xTextFrames_odt = xTFS_odt.getTextFrames();
77 		assertTrue("Has text frame named Frame1", xTextFrames_odt.hasByName("Frame1"));
78 		//save and reopen the document
79 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "MS Word 97",Testspace.getPath("output/test.doc"), app));
80 		XTextFramesSupplier xTFS_doc = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_doc);
81 		XNameAccess xTextFrames_doc = xTFS_doc.getTextFrames();
82 		assertTrue("Has text frame named Frame1", xTextFrames_doc.hasByName("Frame1"));
83 	}
84 }
85