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 mod._sw; 25 26 import java.io.PrintWriter; 27 28 import lib.StatusException; 29 import lib.TestCase; 30 import lib.TestEnvironment; 31 import lib.TestParameters; 32 import util.SOfficeFactory; 33 34 import com.sun.star.container.XNamed; 35 import com.sun.star.lang.XMultiServiceFactory; 36 import com.sun.star.text.XText; 37 import com.sun.star.text.XTextContent; 38 import com.sun.star.text.XTextCursor; 39 import com.sun.star.text.XTextDocument; 40 import com.sun.star.uno.UnoRuntime; 41 import com.sun.star.uno.XInterface; 42 43 /** 44 * Test for object which is represented by service 45 * <code>com.sun.star.text.ReferenceMark</code>. <p> 46 * Object implements the following interfaces : 47 * <ul> 48 * <li> <code>com::sun::star::container::XNamed</code></li> 49 * <li> <code>com::sun::star::lang::XComponent</code></li> 50 * <li> <code>com::sun::star::text::XTextContent</code></li> 51 * </ul> <p> 52 * This object test <b> is NOT </b> designed to be run in several 53 * threads concurently. 54 * @see com.sun.star.container.XNamed 55 * @see com.sun.star.lang.XComponent 56 * @see com.sun.star.text.XTextContent 57 * @see com.sun.star.text.ReferenceMark 58 * @see ifc.container._XNamed 59 * @see ifc.lang._XComponent 60 * @see ifc.text._XTextContent 61 */ 62 public class SwXReferenceMark extends TestCase { 63 XTextDocument xTextDoc; 64 65 /** 66 * Creates text document. 67 */ initialize( TestParameters tParam, PrintWriter log )68 protected void initialize( TestParameters tParam, PrintWriter log ) { 69 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 70 try { 71 log.println( "creating a textdocument" ); 72 xTextDoc = SOF.createTextDoc( null ); 73 } catch ( com.sun.star.uno.Exception e ) { 74 e.printStackTrace( log ); 75 throw new StatusException( "Couldn't create document", e ); 76 } 77 } 78 79 /** 80 * Disposes text document. 81 */ cleanup( TestParameters tParam, PrintWriter log )82 protected void cleanup( TestParameters tParam, PrintWriter log ) { 83 log.println( " disposing xTextDoc " ); 84 util.DesktopTools.closeDoc(xTextDoc); 85 } 86 87 /** 88 * Creating a Testenvironment for the interfaces to be tested. 89 * Creates an instance of the service 90 * <code>com.sun.star.text.ReferenceMark</code>, then sets new 91 * name of created ReferenceMark using <code>XNamed</code> interface. 92 * Finally, renamed ReferenceMark is inserted to a major text of text 93 * document as a text content. 94 */ createTestEnvironment(TestParameters Param, PrintWriter log)95 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 96 XInterface oObj = null; 97 XText oText = null; 98 String Name = "SwXReferenceMark"; 99 100 log.println( "creating a test environment" ); 101 oText = xTextDoc.getText(); 102 XMultiServiceFactory oDocMSF = (XMultiServiceFactory) 103 UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc); 104 Object instance = null; 105 try { 106 oObj = (XInterface) oDocMSF.createInstance 107 ("com.sun.star.text.ReferenceMark"); 108 instance = (XInterface) oDocMSF.createInstance 109 ("com.sun.star.text.ReferenceMark"); 110 } catch ( com.sun.star.uno.Exception e ) { 111 e.printStackTrace( log ); 112 throw new StatusException( "Couldn't get ReferenceMark", e); 113 } 114 115 XNamed oObjN = (XNamed) UnoRuntime.queryInterface(XNamed.class, oObj); 116 oObjN.setName(Name); 117 XTextContent oObjTC = (XTextContent) 118 UnoRuntime.queryInterface(XTextContent.class, oObj); 119 120 XTextCursor oCursor = oText.createTextCursor(); 121 try { 122 oText.insertTextContent(oCursor, oObjTC, false); 123 } catch ( com.sun.star.lang.IllegalArgumentException e ){ 124 e.printStackTrace( log ); 125 throw new StatusException(" Couldn't insert ReferenceMark", e); 126 } 127 128 TestEnvironment tEnv = new TestEnvironment( oObj ); 129 130 tEnv.addObjRelation("CONTENT", (XTextContent) 131 UnoRuntime.queryInterface(XTextContent.class,instance)); 132 tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor()); 133 134 return tEnv; 135 } // finish method getTestEnvironment 136 137 } // finish class SwXReferenceMark 138 139