merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / text / _XRelativeTextContentInsert.java
blob7cd2528e1944784ee96b5b0f3384aad48f7ad649
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XRelativeTextContentInsert.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.text;
33 import lib.MultiMethodTest;
34 import util.XInstCreator;
36 import com.sun.star.text.XRelativeTextContentInsert;
37 import com.sun.star.text.XText;
38 import com.sun.star.text.XTextContent;
39 import com.sun.star.text.XTextCursor;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
43 /**
44 * Testing <code>com.sun.star.text.XRelativeTextContentInsert</code>
45 * interface methods :
46 * <ul>
47 * <li><code> insertTextContentBefore()</code></li>
48 * <li><code> insertTextContentAfter()</code></li>
49 * </ul> <p>
50 * This test needs the following object relations :
51 * <ul>
52 * <li> <code>'PARA'</code> (of type <code>XInstCreator</code>):
53 * the creator which can create instances of
54 * <code>com.sun.star.text.Paragraph</code> service. </li>
55 * <li> <code>'XTEXTINFO'</code> (of type <code>XInstCreator</code>):
56 * the creator which can create instances of soem text content
57 * service (objects which implement <code>XTextContent</code>).
58 * </li>
59 * <ul> <p>
61 * Tested component <b>must implement</b> <code>XText</code>
62 * interface for proper testing. <p>
64 * Test is <b> NOT </b> multithread compilant. <p>
65 * @see com.sun.star.text.XRelativeTextContentInsert
67 public class _XRelativeTextContentInsert extends MultiMethodTest {
69 public XRelativeTextContentInsert oObj = null;
70 public XTextContent content = null;
72 /**
73 * First an instance of <code>Paragraph</code> service created
74 * using relation and inserted into text. Then an instance
75 * of text content is created and inserted after the paragraph. <p>
77 * Has <b>OK</b> status if no exceptions occured.
79 public void _insertTextContentAfter() {
81 try {
82 XInstCreator para = (XInstCreator)tEnv.getObjRelation( "PARA" );
83 XInterface oInt = para.createInstance();
84 XTextContent new_content = (XTextContent) oInt;
85 XText theText = (XText)
86 UnoRuntime.queryInterface(XText.class,oObj);
87 XTextCursor oCursor = theText.createTextCursor();
88 XInstCreator info = (XInstCreator)
89 tEnv.getObjRelation( "XTEXTINFO" );
90 oInt = info.createInstance();
91 content = (XTextContent) oInt;
92 theText.insertTextContent(oCursor, content, false);
93 oObj.insertTextContentAfter(new_content,content);
94 tRes.tested("insertTextContentAfter()",true);
96 catch (com.sun.star.lang.IllegalArgumentException ex) {
97 log.println("Exception occured while checking "+
98 "insertTextContentAfter()");
99 ex.printStackTrace(log);
100 tRes.tested("insertTextContentAfter()",false);
104 } // end _insertTextContentAfter()
107 * An instance of text content is created using relation
108 * and inserted before the paragraph which was added into
109 * text in <code>insertTextContentAfter</code> method test. <p>
111 * Has <b>OK</b> status if no exceptions occured. <p>
113 * The following method tests are to be completed successfully before :
114 * <ul>
115 * <li> <code> insertTextContentAfter() </code> : here the
116 * <code>Paragraph</code> instance is inserted. </li>
117 * </ul>
119 public void _insertTextContentBefore() {
120 requiredMethod("insertTextContentAfter()");
121 try {
122 XInstCreator para = (XInstCreator)tEnv.getObjRelation( "PARA" );
123 XInterface oInt = para.createInstance();
124 XTextContent new_content = (XTextContent) oInt;
125 oObj.insertTextContentBefore(new_content,content);
126 tRes.tested("insertTextContentBefore()",true);
128 catch (com.sun.star.lang.IllegalArgumentException ex) {
129 log.println("Exception occured while checking "+
130 "insertTextContentBefore()");
131 ex.printStackTrace(log);
132 tRes.tested("insertTextContentBefore()",false);
136 } // end _insertTextContentBefore()