merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sw / SwXTextPortion.java
blob0c4328b8704c3d545f021c227b7e6bcc0114391e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXTextPortion.java,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._sw;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.SOfficeFactory;
41 import com.sun.star.beans.XPropertySet;
42 import com.sun.star.container.XEnumeration;
43 import com.sun.star.container.XEnumerationAccess;
44 import com.sun.star.lang.XMultiServiceFactory;
45 import com.sun.star.text.ControlCharacter;
46 import com.sun.star.text.XText;
47 import com.sun.star.text.XTextCursor;
48 import com.sun.star.text.XTextDocument;
49 import com.sun.star.uno.AnyConverter;
50 import com.sun.star.uno.Type;
51 import com.sun.star.uno.UnoRuntime;
52 import com.sun.star.uno.XInterface;
54 /**
56 * initial description
57 * @see com.sun.star.text.TextPortion
60 public class SwXTextPortion extends TestCase {
61 XTextDocument xTextDoc;
63 protected void initialize( TestParameters tParam, PrintWriter log ) {
64 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
66 try {
67 log.println( "creating a textdocument" );
68 xTextDoc = SOF.createTextDoc( null );
69 } catch ( com.sun.star.uno.Exception e ) {
70 // Some exception occures.FAILED
71 e.printStackTrace( log );
72 throw new StatusException( "Couldn't create document", e );
76 protected void cleanup( TestParameters tParam, PrintWriter log ) {
77 log.println( " disposing xTextDoc " );
78 util.DesktopTools.closeDoc(xTextDoc);
81 /**
82 * * creating a Testenvironment for the interfaces to be tested
84 * @param tParam class which contains additional test parameters
85 * @param log class to log the test state and result
87 * @return Status class
89 * @see TestParameters
90 * * @see PrintWriter
92 protected synchronized TestEnvironment createTestEnvironment
93 (TestParameters tParam, PrintWriter log) {
95 XInterface oObj = null;
96 XInterface param = null;
97 XPropertySet paraP = null;
98 XPropertySet portP = null;
100 // creation of testobject here
101 // first we write what we are intend to do to log file
102 log.println( "creating a test environment" );
104 // create testobject here
106 XText oText = xTextDoc.getText();
107 XTextCursor oCursor = oText.createTextCursor();
109 log.println( "inserting Strings" );
110 log.println( "inserting ControlCharacter" );
112 try{
113 for (int i =0; i < 5; i++){
114 oText.insertString( oCursor,"Paragraph Number: " + i, false);
115 oText.insertControlCharacter(
116 oCursor, ControlCharacter.LINE_BREAK, false );
117 oText.insertString( oCursor,
118 "The quick brown fox jumps over the lazy Dog: SwXParagraph\n",
119 false);
120 oText.insertControlCharacter(
121 oCursor, ControlCharacter.LINE_BREAK, false );
122 oText.insertString( oCursor,
123 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph",
124 false);
125 oText.insertControlCharacter(
126 oCursor, ControlCharacter.PARAGRAPH_BREAK, false );
128 }catch(Exception e){
129 log.println("Couldn't insert Text");
130 e.printStackTrace(log);
131 throw new StatusException( "Couldn't insert Text", e );
134 // Enumeration
135 XEnumerationAccess oEnumA = (XEnumerationAccess)
136 UnoRuntime.queryInterface( XEnumerationAccess.class, oText );
137 XEnumeration oEnum = oEnumA.createEnumeration();
139 int n = 0;
140 while ( (oEnum.hasMoreElements()) ) {
141 try {
142 param = (XInterface) AnyConverter.toObject(
143 new Type(XInterface.class),oEnum.nextElement());
144 log.println("Element Nr.: " + n );
145 } catch ( Exception e) {
146 log.println("Couldn't get Paragraph");
147 e.printStackTrace(log);
148 throw new StatusException( "Couldn't get Paragraph", e );
150 n++;
153 XEnumerationAccess oEnumP = (XEnumerationAccess)
154 UnoRuntime.queryInterface( XEnumerationAccess.class, param );
155 XEnumeration oEnum2 = oEnumP.createEnumeration();
156 try {
157 oObj = (XInterface)AnyConverter.toObject(
158 new Type(XInterface.class),oEnum2.nextElement());
159 } catch ( Exception e) {
160 log.println("Couldn't get TextPortion");
161 e.printStackTrace(log);
162 throw new StatusException( "Couldn't get TextPortion", e );
165 portP = (XPropertySet)
166 UnoRuntime.queryInterface(XPropertySet.class, oObj);
167 paraP = (XPropertySet)
168 UnoRuntime.queryInterface(XPropertySet.class, param);
171 log.println( "creating a new environment for Paragraph object" );
172 TestEnvironment tEnv = new TestEnvironment( oObj );
174 log.println("adding ObjRelation TRO for TextContent");
175 tEnv.addObjRelation("TRO", new Boolean(true));
177 log.println("adding ObjectRelation 'PARA' for CharacterProperties");
178 tEnv.addObjRelation("PARA", paraP);
180 log.println("adding ObjectRelation 'PORTION' for CharacterProperties");
181 tEnv.addObjRelation("PORTION", portP);
183 tEnv.addObjRelation("XTEXT", oText);
185 return tEnv;
186 } // finish method getTestEnvironment
189 } // finish class SwXTextPortion