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 
28 import com.sun.star.text.XTextContent;
29 import com.sun.star.text.XTextRange;
30 
31 /**
32  * Testing <code>com.sun.star.text.XTextContent</code>
33  * interface methods :
34  * <ul>
35  *  <li><code> attach()</code></li>
36  *  <li><code> getAnchor()</code></li>
37  * </ul> <p>
38  * This test needs the following object relations :
39  * <ul>
40  *  <li> <code>'CONTENT'</code> <b>optional</b>
41  *  (of type <code>XTextContent</code>):
42  *   if this relation exists than it is used as the
43  *   tested object. </li>
44  *  <li> <code>'TEXT'</code> <b>optional</b>
45  *  (of type <code>XText</code>):
46  *   the relation must be specified if the 'CONTENT'
47  *   relation exists. From this relation an anchor
48  *   for <code>attach()</code> method is obtained.</li>
49  * <ul> <p>
50  * Test is <b> NOT </b> multithread compilant. <p>
51  * @see com.sun.star.text.XTextContent
52  */
53 public class _XTextContent extends MultiMethodTest {
54     public XTextContent oObj = null;
55     public XTextRange oAnchor = null;
56 
57     /**
58      * Tries to get the anchor of the text content
59      * an XTextRange is returned. <p>
60      * The test is OK if an not null text range is returned
61      */
_getAnchor()62     public void _getAnchor() {
63         log.println("getAnchor()");
64         oAnchor = oObj.getAnchor();
65         tRes.tested("getAnchor()", oAnchor != null ) ;
66 
67     } // end getAnchor()
68 
69     /**
70      * Tries to attach the text content to the test range
71      * gotten with getAnchor(). If relations are found
72      * then they are are used for testing. <p>
73      *
74      * The test is OK if the method works without error.
75      * @see #_getAnchor()
76      */
_attach()77     public void _attach() {
78         requiredMethod("getAnchor()");
79         try {
80             XTextContent aContent = (XTextContent) tEnv.getObjRelation("CONTENT");
81             XTextRange aRange = (XTextRange) tEnv.getObjRelation("RANGE");
82 
83             if ( aContent !=null) {
84                 aContent.attach(aRange);
85             } else {
86                 oObj.attach(aRange);
87             }
88             tRes.tested("attach()", true ) ;
89         }
90         catch (com.sun.star.lang.IllegalArgumentException ex) {
91             String noAttach = (String) tEnv.getObjRelation("NoAttach");
92             if (noAttach != null) {
93                 log.println("Exception expected for "+noAttach);
94                 log.println("This Component doesn't support attach");
95                 tRes.tested("attach()",true);
96             } else {
97                 ex.printStackTrace(log);
98                 tRes.tested("attach()",false);
99             }
100         } catch (com.sun.star.uno.RuntimeException re) {
101             String noAttach = (String) tEnv.getObjRelation("NoAttach");
102             if (noAttach != null) {
103                 log.println("Exception expected for "+noAttach);
104                 log.println("This Component doesn't support attach");
105                 tRes.tested("attach()",true);
106             } else {
107                 re.printStackTrace(log);
108                 tRes.tested("attach()",false);
109             }
110         }
111     }
112 }
113 
114