bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXTextPortionEnumeration.java
blob0a96111a7d74366c6e0004c4f2f53007774f907e
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.container.XEnumeration;
30 import com.sun.star.container.XEnumerationAccess;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.text.ControlCharacter;
33 import com.sun.star.text.XText;
34 import com.sun.star.text.XTextCursor;
35 import com.sun.star.text.XTextDocument;
36 import com.sun.star.uno.AnyConverter;
37 import com.sun.star.uno.Type;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
41 /**
43 * initial description
44 * @see com.sun.star.text.TextPortion
47 public class SwXTextPortionEnumeration 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(TestParameters tParam, PrintWriter log) {
82 XInterface param = null;
84 // creation of testobject here
85 // first we write what we are intend to do to log file
86 log.println( "creating a test environment" );
88 // create testobject here
90 XText oText = xTextDoc.getText();
91 XTextCursor oCursor = oText.createTextCursor();
93 log.println( "inserting Strings" );
94 log.println( "inserting ControlCharacter" );
97 try{
98 for (int i =0; i < 5; i++){
99 oText.insertString( oCursor,"Paragraph Number: " + i, false);
100 oText.insertControlCharacter(
101 oCursor, ControlCharacter.LINE_BREAK, false );
102 oText.insertString( oCursor,
103 "The quick brown fox jumps over the lazy Dog: SwXParagraph\n",
104 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",
109 false);
110 oText.insertControlCharacter(
111 oCursor, ControlCharacter.PARAGRAPH_BREAK, false );
113 }catch(Exception e){
114 log.println("Couldn't insert Text");
115 e.printStackTrace();
116 throw new StatusException( "Couldn't insert Text", e );
119 // Enumeration
120 XEnumerationAccess oEnumA = UnoRuntime.queryInterface( XEnumerationAccess.class, oText );
121 XEnumeration oEnum = oEnumA.createEnumeration();
123 while ( (oEnum.hasMoreElements()) ) {
124 try {
125 param = (XInterface) AnyConverter.toObject(
126 new Type(XInterface.class),oEnum.nextElement());
127 } catch ( Exception e) {
128 log.println("Couldn't get Paragraph");
129 e.printStackTrace();
130 throw new StatusException( "Couldn't get Paragraph", e );
134 XEnumerationAccess oEnumP = UnoRuntime.queryInterface( XEnumerationAccess.class, param );
135 XEnumeration oEnum2 = oEnumP.createEnumeration();
137 log.println( "creating a new environment for TextPortionEnumeration object" );
138 TestEnvironment tEnv = new TestEnvironment( oEnum2 );
140 log.println("adding ObjRelation ENUM for XEnumeration");
141 tEnv.addObjRelation("ENUM", oEnumP);
143 return tEnv;
144 } // finish method getTestEnvironment
147 } // finish class SwXTextPortionEnumeration