1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package ifc.text;
29 
30 import lib.MultiMethodTest;
31 
32 import com.sun.star.text.XTextContent;
33 import com.sun.star.text.XTextRange;
34 
35 /**
36  * Testing <code>com.sun.star.text.XTextContent</code>
37  * interface methods :
38  * <ul>
39  *  <li><code> attach()</code></li>
40  *  <li><code> getAnchor()</code></li>
41  * </ul> <p>
42  * This test needs the following object relations :
43  * <ul>
44  *  <li> <code>'CONTENT'</code> <b>optional</b>
45  *  (of type <code>XTextContent</code>):
46  *   if this relation exists than it is used as the
47  *   tested object. </li>
48  *  <li> <code>'TEXT'</code> <b>optional</b>
49  *  (of type <code>XText</code>):
50  *   the relation must be specified if the 'CONTENT'
51  *   relation exists. From this relation an anchor
52  *   for <code>attach()</code> method is obtained.</li>
53  * <ul> <p>
54  * Test is <b> NOT </b> multithread compilant. <p>
55  * @see com.sun.star.text.XTextContent
56  */
57 public class _XTextContent extends MultiMethodTest {
58     public XTextContent oObj = null;
59     public XTextRange oAnchor = null;
60 
61     /**
62      * Tries to get the anchor of the text content
63      * an XTextRange is returned. <p>
64      * The test is OK if an not null text range is returned
65      */
66     public void _getAnchor() {
67         log.println("getAnchor()");
68         oAnchor = oObj.getAnchor();
69         tRes.tested("getAnchor()", oAnchor != null ) ;
70 
71     } // end getAnchor()
72 
73     /**
74      * Tries to attach the text content to the test range
75      * gotten with getAnchor(). If relations are found
76      * then they are are used for testing. <p>
77      *
78      * The test is OK if the method works without error.
79      * @see #_getAnchor()
80      */
81     public void _attach() {
82         requiredMethod("getAnchor()");
83         try {
84             XTextContent aContent = (XTextContent) tEnv.getObjRelation("CONTENT");
85             XTextRange aRange = (XTextRange) tEnv.getObjRelation("RANGE");
86 
87             if ( aContent !=null) {
88                 aContent.attach(aRange);
89             } else {
90                 oObj.attach(aRange);
91             }
92             tRes.tested("attach()", true ) ;
93         }
94         catch (com.sun.star.lang.IllegalArgumentException ex) {
95             String noAttach = (String) tEnv.getObjRelation("NoAttach");
96             if (noAttach != null) {
97                 log.println("Exception expected for "+noAttach);
98                 log.println("This Component doesn't support attach");
99                 tRes.tested("attach()",true);
100             } else {
101                 ex.printStackTrace(log);
102                 tRes.tested("attach()",false);
103             }
104         } catch (com.sun.star.uno.RuntimeException re) {
105             String noAttach = (String) tEnv.getObjRelation("NoAttach");
106             if (noAttach != null) {
107                 log.println("Exception expected for "+noAttach);
108                 log.println("This Component doesn't support attach");
109                 tRes.tested("attach()",true);
110             } else {
111                 re.printStackTrace(log);
112                 tRes.tested("attach()",false);
113             }
114         }
115     }
116 }
117 
118