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