1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.text;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import lib.MultiMethodTest;
27cdf0e10cSrcweir import util.XInstCreator;
28cdf0e10cSrcweir 
29cdf0e10cSrcweir import com.sun.star.text.XRelativeTextContentInsert;
30cdf0e10cSrcweir import com.sun.star.text.XText;
31cdf0e10cSrcweir import com.sun.star.text.XTextContent;
32cdf0e10cSrcweir import com.sun.star.text.XTextCursor;
33cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
34cdf0e10cSrcweir import com.sun.star.uno.XInterface;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir /**
37cdf0e10cSrcweir  * Testing <code>com.sun.star.text.XRelativeTextContentInsert</code>
38cdf0e10cSrcweir  * interface methods :
39cdf0e10cSrcweir  * <ul>
40cdf0e10cSrcweir  *  <li><code> insertTextContentBefore()</code></li>
41cdf0e10cSrcweir  *  <li><code> insertTextContentAfter()</code></li>
42cdf0e10cSrcweir  * </ul> <p>
43cdf0e10cSrcweir  * This test needs the following object relations :
44cdf0e10cSrcweir  * <ul>
45cdf0e10cSrcweir  *  <li> <code>'PARA'</code> (of type <code>XInstCreator</code>):
46cdf0e10cSrcweir  *   the creator which can create instances of
47cdf0e10cSrcweir  *   <code>com.sun.star.text.Paragraph</code> service. </li>
48cdf0e10cSrcweir  *  <li> <code>'XTEXTINFO'</code> (of type <code>XInstCreator</code>):
49cdf0e10cSrcweir  *   the creator which can create instances of soem text content
50cdf0e10cSrcweir  *   service (objects which implement <code>XTextContent</code>).
51cdf0e10cSrcweir  *  </li>
52cdf0e10cSrcweir  * <ul> <p>
53cdf0e10cSrcweir  *
54cdf0e10cSrcweir  * Tested component <b>must implement</b> <code>XText</code>
55cdf0e10cSrcweir  * interface for proper testing. <p>
56cdf0e10cSrcweir  *
57cdf0e10cSrcweir  * Test is <b> NOT </b> multithread compilant. <p>
58cdf0e10cSrcweir  * @see com.sun.star.text.XRelativeTextContentInsert
59cdf0e10cSrcweir  */
60cdf0e10cSrcweir public class _XRelativeTextContentInsert extends MultiMethodTest {
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     public XRelativeTextContentInsert oObj = null;
63cdf0e10cSrcweir     public XTextContent content = null;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     /**
66cdf0e10cSrcweir      * First an instance of <code>Paragraph</code> service created
67cdf0e10cSrcweir      * using relation and inserted into text. Then an instance
68cdf0e10cSrcweir      * of text content is created and inserted after the paragraph. <p>
69cdf0e10cSrcweir      *
70cdf0e10cSrcweir      * Has <b>OK</b> status if no exceptions occured.
71cdf0e10cSrcweir      */
_insertTextContentAfter()72cdf0e10cSrcweir     public void _insertTextContentAfter() {
73cdf0e10cSrcweir 
74cdf0e10cSrcweir         try {
75cdf0e10cSrcweir             XInstCreator para = (XInstCreator)tEnv.getObjRelation( "PARA" );
76cdf0e10cSrcweir             XInterface oInt = para.createInstance();
77cdf0e10cSrcweir             XTextContent new_content = (XTextContent) oInt;
78cdf0e10cSrcweir             XText theText = (XText)
79cdf0e10cSrcweir                 UnoRuntime.queryInterface(XText.class,oObj);
80cdf0e10cSrcweir             XTextCursor oCursor = theText.createTextCursor();
81cdf0e10cSrcweir             XInstCreator info = (XInstCreator)
82cdf0e10cSrcweir                 tEnv.getObjRelation( "XTEXTINFO" );
83cdf0e10cSrcweir             oInt = info.createInstance();
84cdf0e10cSrcweir             content = (XTextContent) oInt;
85cdf0e10cSrcweir             theText.insertTextContent(oCursor, content, false);
86cdf0e10cSrcweir             oObj.insertTextContentAfter(new_content,content);
87cdf0e10cSrcweir             tRes.tested("insertTextContentAfter()",true);
88cdf0e10cSrcweir         }
89cdf0e10cSrcweir         catch (com.sun.star.lang.IllegalArgumentException ex) {
90cdf0e10cSrcweir             log.println("Exception occured while checking "+
91cdf0e10cSrcweir                 "insertTextContentAfter()");
92cdf0e10cSrcweir             ex.printStackTrace(log);
93cdf0e10cSrcweir             tRes.tested("insertTextContentAfter()",false);
94cdf0e10cSrcweir         }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     } // end _insertTextContentAfter()
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     /**
100cdf0e10cSrcweir      * An instance of text content is created using relation
101cdf0e10cSrcweir      * and inserted before the paragraph which was added into
102cdf0e10cSrcweir      * text in <code>insertTextContentAfter</code> method test. <p>
103cdf0e10cSrcweir      *
104cdf0e10cSrcweir      * Has <b>OK</b> status if no exceptions occured. <p>
105cdf0e10cSrcweir      *
106cdf0e10cSrcweir      * The following method tests are to be completed successfully before :
107cdf0e10cSrcweir      * <ul>
108cdf0e10cSrcweir      *  <li> <code> insertTextContentAfter() </code> : here the
109cdf0e10cSrcweir      *  <code>Paragraph</code> instance is inserted. </li>
110cdf0e10cSrcweir      * </ul>
111cdf0e10cSrcweir      */
_insertTextContentBefore()112cdf0e10cSrcweir     public void _insertTextContentBefore() {
113cdf0e10cSrcweir         requiredMethod("insertTextContentAfter()");
114cdf0e10cSrcweir         try {
115cdf0e10cSrcweir             XInstCreator para = (XInstCreator)tEnv.getObjRelation( "PARA" );
116cdf0e10cSrcweir             XInterface oInt = para.createInstance();
117cdf0e10cSrcweir             XTextContent new_content = (XTextContent) oInt;
118cdf0e10cSrcweir             oObj.insertTextContentBefore(new_content,content);
119cdf0e10cSrcweir             tRes.tested("insertTextContentBefore()",true);
120cdf0e10cSrcweir         }
121cdf0e10cSrcweir         catch (com.sun.star.lang.IllegalArgumentException ex) {
122cdf0e10cSrcweir             log.println("Exception occured while checking "+
123cdf0e10cSrcweir                 "insertTextContentBefore()");
124cdf0e10cSrcweir             ex.printStackTrace(log);
125cdf0e10cSrcweir             tRes.tested("insertTextContentBefore()",false);
126cdf0e10cSrcweir         }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     } // end _insertTextContentBefore()
130cdf0e10cSrcweir 
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
133