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