bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXTextPortion.java
blobdb07f4796d24445ce74ab28a69eb63e10dee8909
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package mod._sw;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
29 import com.sun.star.beans.XPropertySet;
30 import com.sun.star.container.XEnumeration;
31 import com.sun.star.container.XEnumerationAccess;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.text.ControlCharacter;
34 import com.sun.star.text.XText;
35 import com.sun.star.text.XTextCursor;
36 import com.sun.star.text.XTextDocument;
37 import com.sun.star.uno.AnyConverter;
38 import com.sun.star.uno.Type;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
42 /**
44 * initial description
45 * @see com.sun.star.text.TextPortion
48 public class SwXTextPortion extends TestCase {
49 XTextDocument xTextDoc;
51 protected void initialize( TestParameters tParam, PrintWriter log ) {
52 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
54 try {
55 log.println( "creating a textdocument" );
56 xTextDoc = SOF.createTextDoc( null );
57 } catch ( com.sun.star.uno.Exception e ) {
58 // Some exception occurs.FAILED
59 e.printStackTrace( log );
60 throw new StatusException( "Couldn't create document", e );
64 protected void cleanup( TestParameters tParam, PrintWriter log ) {
65 log.println( " disposing xTextDoc " );
66 util.DesktopTools.closeDoc(xTextDoc);
69 /**
70 * * creating a Testenvironment for the interfaces to be tested
72 * @param tParam class which contains additional test parameters
73 * @param log class to log the test state and result
75 * @return Status class
77 * @see TestParameters
78 * * @see PrintWriter
80 protected synchronized TestEnvironment createTestEnvironment
81 (TestParameters tParam, PrintWriter log) {
83 XInterface oObj = null;
84 XInterface param = null;
85 XPropertySet paraP = null;
86 XPropertySet portP = null;
88 // creation of testobject here
89 // first we write what we are intend to do to log file
90 log.println( "creating a test environment" );
92 // create testobject here
94 XText oText = xTextDoc.getText();
95 XTextCursor oCursor = oText.createTextCursor();
97 log.println( "inserting Strings" );
98 log.println( "inserting ControlCharacter" );
100 try{
101 for (int i =0; i < 5; i++){
102 oText.insertString( oCursor,"Paragraph Number: " + i, false);
103 oText.insertControlCharacter(
104 oCursor, ControlCharacter.LINE_BREAK, false );
105 oText.insertString( oCursor,
106 "The quick brown fox jumps over the lazy Dog: SwXParagraph\n",
107 false);
108 oText.insertControlCharacter(
109 oCursor, ControlCharacter.LINE_BREAK, false );
110 oText.insertString( oCursor,
111 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph",
112 false);
113 oText.insertControlCharacter(
114 oCursor, ControlCharacter.PARAGRAPH_BREAK, false );
116 }catch(Exception e){
117 log.println("Couldn't insert Text");
118 e.printStackTrace(log);
119 throw new StatusException( "Couldn't insert Text", e );
122 // Enumeration
123 XEnumerationAccess oEnumA = UnoRuntime.queryInterface( XEnumerationAccess.class, oText );
124 XEnumeration oEnum = oEnumA.createEnumeration();
126 int n = 0;
127 while ( (oEnum.hasMoreElements()) ) {
128 try {
129 param = (XInterface) AnyConverter.toObject(
130 new Type(XInterface.class),oEnum.nextElement());
131 log.println("Element Nr.: " + n );
132 } catch ( Exception e) {
133 log.println("Couldn't get Paragraph");
134 e.printStackTrace(log);
135 throw new StatusException( "Couldn't get Paragraph", e );
137 n++;
140 XEnumerationAccess oEnumP = UnoRuntime.queryInterface( XEnumerationAccess.class, param );
141 XEnumeration oEnum2 = oEnumP.createEnumeration();
142 try {
143 oObj = (XInterface)AnyConverter.toObject(
144 new Type(XInterface.class),oEnum2.nextElement());
145 } catch ( Exception e) {
146 log.println("Couldn't get TextPortion");
147 e.printStackTrace(log);
148 throw new StatusException( "Couldn't get TextPortion", e );
151 portP = UnoRuntime.queryInterface(XPropertySet.class, oObj);
152 paraP = UnoRuntime.queryInterface(XPropertySet.class, param);
155 log.println( "creating a new environment for Paragraph object" );
156 TestEnvironment tEnv = new TestEnvironment( oObj );
158 log.println("adding ObjRelation TRO for TextContent");
159 tEnv.addObjRelation("TRO", new Boolean(true));
161 log.println("adding ObjectRelation 'PARA' for CharacterProperties");
162 tEnv.addObjRelation("PARA", paraP);
164 log.println("adding ObjectRelation 'PORTION' for CharacterProperties");
165 tEnv.addObjRelation("PORTION", portP);
167 tEnv.addObjRelation("XTEXT", oText);
169 return tEnv;
170 } // finish method getTestEnvironment
173 } // finish class SwXTextPortion