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