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.XEnumeration; 35 import com.sun.star.container.XEnumerationAccess; 36 import com.sun.star.lang.XMultiServiceFactory; 37 import com.sun.star.text.ControlCharacter; 38 import com.sun.star.text.XText; 39 import com.sun.star.text.XTextCursor; 40 import com.sun.star.text.XTextDocument; 41 import com.sun.star.uno.AnyConverter; 42 import com.sun.star.uno.Type; 43 import com.sun.star.uno.UnoRuntime; 44 import com.sun.star.uno.XInterface; 45 46 /** 47 * 48 * initial description 49 * @see com.sun.star.text.TextPortion 50 * 51 */ 52 public class SwXTextPortionEnumeration extends TestCase { 53 54 XTextDocument xTextDoc; 55 initialize( TestParameters tParam, PrintWriter log )56 protected void initialize( TestParameters tParam, PrintWriter log ) { 57 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 58 59 try { 60 log.println( "creating a textdocument" ); 61 xTextDoc = SOF.createTextDoc( null ); 62 } catch ( com.sun.star.uno.Exception e ) { 63 // Some exception occured.FAILED 64 e.printStackTrace( log ); 65 throw new StatusException( "Couldn't create document", e ); 66 } 67 } 68 cleanup( TestParameters tParam, PrintWriter log )69 protected void cleanup( TestParameters tParam, PrintWriter log ) { 70 log.println( " disposing xTextDoc " ); 71 util.DesktopTools.closeDoc(xTextDoc); 72 } 73 74 /** 75 * creating a Testenvironment for the interfaces to be tested 76 * 77 * @param tParam class which contains additional test parameters 78 * @param log class to log the test state and result 79 * 80 * @return Status class 81 * 82 * @see TestParameters 83 * @see PrintWriter 84 */ createTestEnvironment(TestParameters tParam, PrintWriter log)85 protected synchronized TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { 86 87 XInterface param = null; 88 89 // creation of testobject here 90 // first we write what we are intend to do to log file 91 log.println( "creating a test environment" ); 92 93 // create testobject here 94 95 XText oText = xTextDoc.getText(); 96 XTextCursor oCursor = oText.createTextCursor(); 97 98 log.println( "inserting Strings" ); 99 log.println( "inserting ControlCharacter" ); 100 101 102 try{ 103 for (int i =0; i < 5; i++){ 104 oText.insertString( oCursor,"Paragraph Number: " + i, false); 105 oText.insertControlCharacter( 106 oCursor, ControlCharacter.LINE_BREAK, false ); 107 oText.insertString( oCursor, 108 "The quick brown fox jumps over the lazy Dog: SwXParagraph\n", 109 false); 110 oText.insertControlCharacter( 111 oCursor, ControlCharacter.LINE_BREAK, false ); 112 oText.insertString( oCursor, 113 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph", 114 false); 115 oText.insertControlCharacter( 116 oCursor, ControlCharacter.PARAGRAPH_BREAK, false ); 117 } 118 }catch(Exception e){ 119 log.println("Couldn't insert Text"); 120 e.printStackTrace(); 121 throw new StatusException( "Couldn't insert Text", e ); 122 } 123 124 // Enumeration 125 XEnumerationAccess oEnumA = (XEnumerationAccess) 126 UnoRuntime.queryInterface( XEnumerationAccess.class, oText ); 127 XEnumeration oEnum = oEnumA.createEnumeration(); 128 129 int n = 0; 130 while ( (oEnum.hasMoreElements()) ) { 131 try { 132 param = (XInterface) AnyConverter.toObject( 133 new Type(XInterface.class),oEnum.nextElement()); 134 } catch ( Exception e) { 135 log.println("Couldn't get Paragraph"); 136 e.printStackTrace(); 137 throw new StatusException( "Couldn't get Paragraph", e ); 138 } 139 n++; 140 } 141 142 XEnumerationAccess oEnumP = (XEnumerationAccess) 143 UnoRuntime.queryInterface( XEnumerationAccess.class, param ); 144 XEnumeration oEnum2 = oEnumP.createEnumeration(); 145 146 log.println( "creating a new environment for TextPortionEnumeration object" ); 147 TestEnvironment tEnv = new TestEnvironment( oEnum2 ); 148 149 log.println("adding ObjRelation ENUM for XEnumeration"); 150 tEnv.addObjRelation("ENUM", oEnumP); 151 152 return tEnv; 153 } // finish method getTestEnvironment 154 155 156 } // finish class SwXTextPortionEnumeration 157 158