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 
22 
23 
24 package ifc.text;
25 
26 import lib.MultiMethodTest;
27 import util.XInstCreator;
28 
29 import com.sun.star.text.XRelativeTextContentInsert;
30 import com.sun.star.text.XText;
31 import com.sun.star.text.XTextContent;
32 import com.sun.star.text.XTextCursor;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.XInterface;
35 
36 /**
37  * Testing <code>com.sun.star.text.XRelativeTextContentInsert</code>
38  * interface methods :
39  * <ul>
40  *  <li><code> insertTextContentBefore()</code></li>
41  *  <li><code> insertTextContentAfter()</code></li>
42  * </ul> <p>
43  * This test needs the following object relations :
44  * <ul>
45  *  <li> <code>'PARA'</code> (of type <code>XInstCreator</code>):
46  *   the creator which can create instances of
47  *   <code>com.sun.star.text.Paragraph</code> service. </li>
48  *  <li> <code>'XTEXTINFO'</code> (of type <code>XInstCreator</code>):
49  *   the creator which can create instances of soem text content
50  *   service (objects which implement <code>XTextContent</code>).
51  *  </li>
52  * <ul> <p>
53  *
54  * Tested component <b>must implement</b> <code>XText</code>
55  * interface for proper testing. <p>
56  *
57  * Test is <b> NOT </b> multithread compilant. <p>
58  * @see com.sun.star.text.XRelativeTextContentInsert
59  */
60 public class _XRelativeTextContentInsert extends MultiMethodTest {
61 
62     public XRelativeTextContentInsert oObj = null;
63     public XTextContent content = null;
64 
65     /**
66      * First an instance of <code>Paragraph</code> service created
67      * using relation and inserted into text. Then an instance
68      * of text content is created and inserted after the paragraph. <p>
69      *
70      * Has <b>OK</b> status if no exceptions occured.
71      */
72     public void _insertTextContentAfter() {
73 
74         try {
75             XInstCreator para = (XInstCreator)tEnv.getObjRelation( "PARA" );
76             XInterface oInt = para.createInstance();
77             XTextContent new_content = (XTextContent) oInt;
78             XText theText = (XText)
79                 UnoRuntime.queryInterface(XText.class,oObj);
80             XTextCursor oCursor = theText.createTextCursor();
81             XInstCreator info = (XInstCreator)
82                 tEnv.getObjRelation( "XTEXTINFO" );
83             oInt = info.createInstance();
84             content = (XTextContent) oInt;
85             theText.insertTextContent(oCursor, content, false);
86             oObj.insertTextContentAfter(new_content,content);
87             tRes.tested("insertTextContentAfter()",true);
88         }
89         catch (com.sun.star.lang.IllegalArgumentException ex) {
90             log.println("Exception occured while checking "+
91                 "insertTextContentAfter()");
92             ex.printStackTrace(log);
93             tRes.tested("insertTextContentAfter()",false);
94         }
95 
96 
97     } // end _insertTextContentAfter()
98 
99     /**
100      * An instance of text content is created using relation
101      * and inserted before the paragraph which was added into
102      * text in <code>insertTextContentAfter</code> method test. <p>
103      *
104      * Has <b>OK</b> status if no exceptions occured. <p>
105      *
106      * The following method tests are to be completed successfully before :
107      * <ul>
108      *  <li> <code> insertTextContentAfter() </code> : here the
109      *  <code>Paragraph</code> instance is inserted. </li>
110      * </ul>
111      */
112     public void _insertTextContentBefore() {
113         requiredMethod("insertTextContentAfter()");
114         try {
115             XInstCreator para = (XInstCreator)tEnv.getObjRelation( "PARA" );
116             XInterface oInt = para.createInstance();
117             XTextContent new_content = (XTextContent) oInt;
118             oObj.insertTextContentBefore(new_content,content);
119             tRes.tested("insertTextContentBefore()",true);
120         }
121         catch (com.sun.star.lang.IllegalArgumentException ex) {
122             log.println("Exception occured while checking "+
123                 "insertTextContentBefore()");
124             ex.printStackTrace(log);
125             tRes.tested("insertTextContentBefore()",false);
126         }
127 
128 
129     } // end _insertTextContentBefore()
130 
131 }
132 
133